From beeb4521c0fd2d470f24c9bc199fa3ac2a938e1e Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Wed, 21 Jan 2015 21:14:00 +0000 Subject: [PATCH] Rework forms layout to workaround some stylesheet issues (Qt client) --- qt/CMakeLists.txt | 2 + qt/column-resizer.cc | 82 +++ qt/column-resizer.h | 41 ++ qt/details.cc | 13 + qt/details.ui | 1198 +++++++++++++++++++++--------------------- qt/make-dialog.cc | 10 +- qt/make-dialog.ui | 274 +++++----- qt/qtr.pro | 1 + qt/relocate.ui | 102 ++-- qt/session-dialog.ui | 226 ++++---- qt/stats-dialog.cc | 6 + qt/stats-dialog.ui | 292 +++++----- 12 files changed, 1168 insertions(+), 1079 deletions(-) create mode 100644 qt/column-resizer.cc create mode 100644 qt/column-resizer.h diff --git a/qt/CMakeLists.txt b/qt/CMakeLists.txt index 21682393d..d099d571d 100644 --- a/qt/CMakeLists.txt +++ b/qt/CMakeLists.txt @@ -28,6 +28,7 @@ set(${PROJECT_NAME}_SOURCES about.cc add-data.cc app.cc + column-resizer.cc dbus-adaptor.cc details.cc favicon.cc @@ -67,6 +68,7 @@ set(${PROJECT_NAME}_HEADERS about.h add-data.h app.h + column-resizer.h dbus-adaptor.h details.h favicon.h diff --git a/qt/column-resizer.cc b/qt/column-resizer.cc new file mode 100644 index 000000000..b227a4b8b --- /dev/null +++ b/qt/column-resizer.cc @@ -0,0 +1,82 @@ +/* + * This file Copyright (C) 2015 Mnemosyne LLC + * + * It may be used under the GNU GPL versions 2 or 3 + * or any future license endorsed by Mnemosyne LLC. + * + * $Id$ + */ + +#include +#include +#include + +#include "column-resizer.h" + +namespace +{ + int + itemColumnSpan (QGridLayout * layout, const QLayoutItem * item) + { + for (int i = 0, count = layout->count (); i < count; ++i) + { + if (layout->itemAt (i) != item) + continue; + + int row, column, rowSpan, columnSpan; + layout->getItemPosition (i, &row, &column, &rowSpan, &columnSpan); + return columnSpan; + } + + return 0; + } +} + +ColumnResizer::ColumnResizer (QObject * parent): + QObject (parent), + myTimer (new QTimer (this)), + myLayouts () +{ + myTimer->setSingleShot (true); + connect (myTimer, SIGNAL (timeout ()), SLOT (update ())); +} + +void +ColumnResizer::addLayout (QGridLayout * layout) +{ + myLayouts << layout; + scheduleUpdate (); +} + +bool +ColumnResizer::eventFilter (QObject * object, QEvent * event) +{ + if (event->type () == QEvent::Resize) + scheduleUpdate (); + return QObject::eventFilter (object, event); +} + +void +ColumnResizer::update () +{ + int maxWidth = 0; + foreach (QGridLayout * layout, myLayouts) + { + for (int i = 0, count = layout->rowCount (); i < count; ++i) + { + QLayoutItem * item = layout->itemAtPosition (i, 0); + if (item == nullptr || itemColumnSpan (layout, item) > 1) + continue; + maxWidth = qMax (maxWidth, item->sizeHint ().width ()); + } + } + + foreach (QGridLayout * layout, myLayouts) + layout->setColumnMinimumWidth (0, maxWidth); +} + +void +ColumnResizer::scheduleUpdate () +{ + myTimer->start (0); +} diff --git a/qt/column-resizer.h b/qt/column-resizer.h new file mode 100644 index 000000000..24eba3c5f --- /dev/null +++ b/qt/column-resizer.h @@ -0,0 +1,41 @@ +/* + * This file Copyright (C) 2015 Mnemosyne LLC + * + * It may be used under the GNU GPL versions 2 or 3 + * or any future license endorsed by Mnemosyne LLC. + * + * $Id$ + */ + +#ifndef QTR_COLUMN_RESIZER_H +#define QTR_COLUMN_RESIZER_H + +#include +#include + +class QGridLayout; +class QTimer; + +class ColumnResizer: public QObject +{ + Q_OBJECT + + public: + ColumnResizer (QObject * parent = nullptr); + + void addLayout (QGridLayout * layout); + + virtual bool eventFilter (QObject * object, QEvent * event); + + public slots: + void update (); + + private: + void scheduleUpdate (); + + private: + QTimer * myTimer; + QSet myLayouts; +}; + +#endif diff --git a/qt/details.cc b/qt/details.cc index 222fadb87..85c6fecaf 100644 --- a/qt/details.cc +++ b/qt/details.cc @@ -32,6 +32,7 @@ #include #include // tr_getRatio () +#include "column-resizer.h" #include "details.h" #include "file-tree.h" #include "formatter.h" @@ -959,6 +960,11 @@ Details::initInfoTab () { const int h = QFontMetrics (ui.commentBrowser->font ()).lineSpacing () * 4; ui.commentBrowser->setFixedHeight (h); + + ColumnResizer * cr (new ColumnResizer (this)); + cr->addLayout (ui.activitySectionLayout); + cr->addLayout (ui.detailsSectionLayout); + cr->update (); } /*** @@ -1177,6 +1183,13 @@ Details::initOptionsTab () ui.idleCombo->addItem (tr ("Seed regardless of activity"), TR_IDLELIMIT_UNLIMITED); ui.idleCombo->addItem (tr ("Stop seeding if idle for:"), TR_IDLELIMIT_SINGLE); + ColumnResizer * cr (new ColumnResizer (this)); + cr->addLayout (ui.speedSectionLayout); + cr->addLayout (ui.seedingLimitsSectionRatioLayout); + cr->addLayout (ui.seedingLimitsSectionIdleLayout); + cr->addLayout (ui.peerConnectionsSectionLayout); + cr->update (); + connect (ui.sessionLimitCheck, SIGNAL (clicked (bool)), SLOT (onHonorsSessionLimitsToggled (bool))); connect (ui.singleDownCheck, SIGNAL (clicked (bool)), SLOT (onDownloadLimitedToggled (bool))); connect (ui.singleDownSpin, SIGNAL (editingFinished ()), SLOT (onSpinBoxEditingFinished ())); diff --git a/qt/details.ui b/qt/details.ui index 9c0f0ecc6..2ed0e516f 100644 --- a/qt/details.ui +++ b/qt/details.ui @@ -7,28 +7,12 @@ 0 0 505 - 579 + 581 Torrent Properties - - [tr-style~="form-section"] -{ - font-weight: bold; - margin-top: 12px; - margin-bottom: 1px; -} -[tr-style~="form-section"][tr-style~="first"] -{ - margin-top: 0; -} -[tr-style~="form-label"] -{ - margin-left: 18px; -} - @@ -39,452 +23,437 @@ Information - - + + - - Activity - - - form-section first - - - - - - - Have: - - - form-label - - - - - - - - 0 - 0 - - - - ... - - - Qt::PlainText + + font-weight:bold - - Qt::NoTextInteraction - - - - - - Availability: - - - form-label - - - - - - - - 0 - 0 - - - - ... - - - Qt::PlainText - - - Qt::NoTextInteraction - - - - - - - Uploaded: - - - form-label - - - - - - - - 0 - 0 - - - - ... - - - Qt::PlainText - - - Qt::NoTextInteraction - - - - - - - Downloaded: - - - form-label - - - - - - - - 0 - 0 - - - - ... - - - Qt::PlainText - - - Qt::NoTextInteraction - - - - - - - State: - - - form-label - - - - - - - - 0 - 0 - - - - ... - - - Qt::PlainText - - - Qt::NoTextInteraction - - - - - - - Running time: - - - form-label - - - - - - - - 0 - 0 - - - - ... - - - Qt::PlainText - - - Qt::NoTextInteraction - - - - - - - Remaining time: - - - form-label - - - - - - - - 0 - 0 - - - - ... - - - Qt::PlainText - - - Qt::NoTextInteraction - - - - - - - Last activity: - - - form-label - - - - - - - - 0 - 0 - - - - ... - - - Qt::PlainText - - - Qt::NoTextInteraction + Activity - - - - Error: - - - form-label - - + + + + 18 + + + + + Have: + + + + + + + + 0 + 0 + + + + ... + + + Qt::PlainText + + + Qt::NoTextInteraction + + + + + + + Availability: + + + + + + + + 0 + 0 + + + + ... + + + Qt::PlainText + + + Qt::NoTextInteraction + + + + + + + Uploaded: + + + + + + + + 0 + 0 + + + + ... + + + Qt::PlainText + + + Qt::NoTextInteraction + + + + + + + Downloaded: + + + + + + + + 0 + 0 + + + + ... + + + Qt::PlainText + + + Qt::NoTextInteraction + + + + + + + State: + + + + + + + + 0 + 0 + + + + ... + + + Qt::PlainText + + + Qt::NoTextInteraction + + + + + + + Running time: + + + + + + + + 0 + 0 + + + + ... + + + Qt::PlainText + + + Qt::NoTextInteraction + + + + + + + Remaining time: + + + + + + + + 0 + 0 + + + + ... + + + Qt::PlainText + + + Qt::NoTextInteraction + + + + + + + Last activity: + + + + + + + + 0 + 0 + + + + ... + + + Qt::PlainText + + + Qt::NoTextInteraction + + + + + + + Error: + + + + + + + + 0 + 0 + + + + ... + + + Qt::PlainText + + + Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + - - - - - 0 - 0 - - - - ... + + + + Qt::Vertical - - Qt::PlainText + + QSizePolicy::Fixed - - Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + 1 + 10 + - + - + - - Details - - - form-section - - - - - - - Size: - - - form-label - - - - - - - - 0 - 0 - - - - ... - - - Qt::PlainText - - - Qt::NoTextInteraction - - - - - - - Location: - - - form-label - - - - - - - - 0 - 0 - - - - ... - - - Qt::PlainText - - - Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - Hash: - - - form-label - - - - - - - - 0 - 0 - - - - ... - - - Qt::PlainText - - - Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - Privacy: - - - form-label - - - - - - - - 0 - 0 - - - - ... + + font-weight:bold - - Qt::PlainText - - - Qt::NoTextInteraction - - - - - - Origin: - - - form-label - - - - - - - - 0 - 0 - - - - ... - - - Qt::PlainText - - - Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - Comment: - - - commentBrowser - - - form-label + Details - - - - Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - + + + + 18 + + + + + + 0 + 0 + + + + ... + + + Qt::PlainText + + + Qt::NoTextInteraction + + + + + + + + 0 + 0 + + + + ... + + + Qt::PlainText + + + Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + Hash: + + + + + + + Privacy: + + + + + + + Origin: + + + + + + + + 0 + 0 + + + + ... + + + Qt::PlainText + + + Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + + 0 + 0 + + + + ... + + + Qt::PlainText + + + Qt::NoTextInteraction + + + + + + + Size: + + + + + + + Location: + + + + + + + + 0 + 0 + + + + ... + + + Qt::PlainText + + + Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + Comment: + + + commentBrowser + + + + + + + Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + @@ -608,118 +577,129 @@ Options - - + + - - Speed - - - form-section first - - - - - - - Honor global &limits - - - form-label + + font-weight:bold - - - - - - Limit &download speed: - - - form-label - - - - - - - false - - - 999999999 - - - 5 - - - - - - Limit &upload speed: - - - form-label + Speed - - - - false - - - 999999999 - - - 5 - - + + + + 18 + + + + + Honor global &limits + + + + + + + Limit &download speed: + + + + + + + false + + + 999999999 + + + 5 + + + + + + + Limit &upload speed: + + + + + + + false + + + 999999999 + + + 5 + + + + + + + Torrent &priority: + + + bandwidthPriorityCombo + + + + + + + - - - - Torrent &priority: + + + + Qt::Vertical - - bandwidthPriorityCombo + + QSizePolicy::Fixed - - form-label + + + 1 + 10 + - - - - + - + - - Seeding Limits - - - form-section + + font-weight:bold - - - - - &Ratio: - - - ratioCombo - - - form-label + Seeding Limits - - - + + + + 18 + + + + + &Ratio: + + + ratioCombo + + + + - + 0.500000000000000 @@ -731,25 +711,25 @@ - - - - &Idle: - - - idleCombo - - - form-label - - - - - - + + + + 18 + + + + + &Idle: + + + idleCombo + + + + - + minute(s) @@ -767,43 +747,63 @@ - - - - Peer Connections - - - form-section - - - - - - - &Maximum peers: + + + + Qt::Vertical - - peerLimitSpin + + QSizePolicy::Fixed - - form-label + + + 1 + 10 + - + - - - - 1 - - - 300 + + + + font-weight:bold - - 5 + + Peer Connections - + + + + 18 + + + + + &Maximum peers: + + + peerLimitSpin + + + + + + + 1 + + + 300 + + + 5 + + + + + + Qt::Vertical @@ -844,34 +844,6 @@
file-tree.h
- - tabs - errorValueLabel - locationValueLabel - hashValueLabel - originValueLabel - commentBrowser - peersView - trackersView - addTrackerButton - editTrackerButton - removeTrackerButton - showTrackerScrapesCheck - showBackupTrackersCheck - filesView - sessionLimitCheck - singleDownCheck - singleDownSpin - singleUpCheck - singleUpSpin - bandwidthPriorityCombo - ratioCombo - ratioSpin - idleCombo - idleSpin - peerLimitSpin - dialogButtons - diff --git a/qt/make-dialog.cc b/qt/make-dialog.cc index a89ee252c..d8463553d 100644 --- a/qt/make-dialog.cc +++ b/qt/make-dialog.cc @@ -17,6 +17,7 @@ #include #include +#include "column-resizer.h" #include "formatter.h" #include "make-dialog.h" #include "session.h" @@ -220,14 +221,19 @@ MakeDialog::MakeDialog (Session& session, QWidget * parent): { ui.setupUi (this); - resize (minimumSizeHint ()); - ui.destinationButton->setMode (TrPathButton::DirectoryMode); ui.destinationButton->setPath (QDir::homePath ()); ui.sourceFolderButton->setMode (TrPathButton::DirectoryMode); ui.sourceFileButton->setMode (TrPathButton::FileMode); + ColumnResizer * cr (new ColumnResizer (this)); + cr->addLayout (ui.filesSectionLayout); + cr->addLayout (ui.propertiesSectionLayout); + cr->update (); + + resize (minimumSizeHint ()); + connect (ui.sourceFolderRadio, SIGNAL (toggled (bool)), this, SLOT (onSourceChanged ())); connect (ui.sourceFolderButton, SIGNAL (pathChanged (QString)), this, SLOT (onSourceChanged ())); connect (ui.sourceFileRadio, SIGNAL (toggled (bool)), this, SLOT (onSourceChanged ())); diff --git a/qt/make-dialog.ui b/qt/make-dialog.ui index a2b24a676..1a520a422 100644 --- a/qt/make-dialog.ui +++ b/qt/make-dialog.ui @@ -7,7 +7,7 @@ 0 0 566 - 417 + 426
@@ -16,161 +16,157 @@ New Torrent - - [tr-style~="form-section"] -{ - font-weight: bold; - margin-top: 12px; - margin-bottom: 1px; -} -[tr-style~="form-section"][tr-style~="first"] -{ - margin-top: 0; -} -[tr-style~="form-label"] -{ - margin-left: 18px; -} - - - + + - - Files - - - form-section first - - - - - - - Sa&ve to: - - - destinationButton + + font-weight:bold - - form-label - - - - - - - - - Source f&older: - - - form-label - - - - - - - false + Files - - - - Source &file: - - - true + + + + 18 + + + + + Sa&ve to: + + + destinationButton + + + + + + + + + + Source f&older: + + + + + + + false + + + + + + + Source &file: + + + true + + + + + + + + + + ... + + + + + + + + + Qt::Vertical - - form-label + + QSizePolicy::Fixed - - - - - - - - - ... + + + 1 + 10 + - +
- + - - Properties + + font-weight:bold - - form-section - - - - - - &Trackers: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - trackersEdit - - - form-label - - - - - - - true - - - QPlainTextEdit::NoWrap + Properties - - - - To add a backup URL, add it on the line after the primary URL. + + + + 18 + + + + + &Trackers: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + trackersEdit + + + + + + + true + + + QPlainTextEdit::NoWrap + + + + + + + To add a backup URL, add it on the line after the primary URL. To add another primary URL, add it after a blank line. - - - - - - - Co&mment: - - - form-label - - - - - - - false - - - - - - - &Private torrent - - - form-label - - - - + + + + + + + Co&mment: + + + + + + + false + + + + + + + &Private torrent + + + +
+
+ Qt::Horizontal diff --git a/qt/qtr.pro b/qt/qtr.pro index ad6c4b8b6..92a3c8a94 100644 --- a/qt/qtr.pro +++ b/qt/qtr.pro @@ -63,6 +63,7 @@ win32|macx:RESOURCES += icons/Faenza/Faenza.qrc SOURCES += about.cc \ add-data.cc \ app.cc \ + column-resizer.cc \ dbus-adaptor.cc \ details.cc \ favicon.cc \ diff --git a/qt/relocate.ui b/qt/relocate.ui index 63227d17c..5e133b954 100644 --- a/qt/relocate.ui +++ b/qt/relocate.ui @@ -6,84 +6,62 @@ 0 0 - 339 - 151 + 333 + 155 Set Torrent Location - - [tr-style~="form-section"] -{ - font-weight: bold; - margin-top: 12px; - margin-bottom: 1px; -} -[tr-style~="form-section"][tr-style~="first"] -{ - margin-top: 0; -} -[tr-style~="form-label"] -{ - margin-left: 18px; -} -#newLocationStack -{ - min-width: 15em; -} - - + QLayout::SetFixedSize - + - - Set Location - - - form-section first - - - - - - - New &location: - - - form-label + + font-weight:bold - - - - - - - - - - - &Move from the current folder - - - form-label + Set Location - - - - Local data is &already there + + + + 18 - - form-label - - + + + + New &location: + + + + + + + + + + + + + &Move from the current folder + + + + + + + Local data is &already there + + + + - + Qt::Horizontal diff --git a/qt/session-dialog.ui b/qt/session-dialog.ui index 1a42aa52d..e9849d1c9 100644 --- a/qt/session-dialog.ui +++ b/qt/session-dialog.ui @@ -6,149 +6,119 @@ 0 0 - 248 - 263 + 250 + 265 Change Session - - [tr-style~="form-section"] -{ - font-weight: bold; - margin-top: 12px; - margin-bottom: 1px; -} -[tr-style~="form-section"][tr-style~="first"] -{ - margin-top: 0; -} -[tr-style~="form-label"] -{ - margin-left: 18px; -} - - + QLayout::SetFixedSize - + - - Source - - - form-section first - - - - - - - Start &Local Session - - - form-label - - - - - - - Connect to &Remote Session - - - form-label - - - - - - - &Host: - - - hostEdit - - - form-label - - - - - - - - - - &Port: + + font-weight:bold - - portSpin - - - form-label - - - - - - - 1 - - - 65535 - - - - - - - &Authentication required - - - form-label - - - - - - &Username: - - - usernameEdit - - - form-label - - - - - - - - - - Pass&word: - - - passwordEdit - - - form-label + Source - - - - QLineEdit::Password - - + + + + 18 + + + + + Start &Local Session + + + + + + + Connect to &Remote Session + + + + + + + &Host: + + + hostEdit + + + + + + + + + + &Port: + + + portSpin + + + + + + + 1 + + + 65535 + + + + + + + &Authentication required + + + + + + + &Username: + + + usernameEdit + + + + + + + + + + Pass&word: + + + passwordEdit + + + + + + + QLineEdit::Password + + + + - + Qt::Horizontal diff --git a/qt/stats-dialog.cc b/qt/stats-dialog.cc index fe836b7bf..8463a55af 100644 --- a/qt/stats-dialog.cc +++ b/qt/stats-dialog.cc @@ -9,6 +9,7 @@ #include +#include "column-resizer.h" #include "formatter.h" #include "session.h" #include "stats-dialog.h" @@ -25,6 +26,11 @@ StatsDialog::StatsDialog (Session& session, QWidget * parent): { ui.setupUi (this); + ColumnResizer * cr (new ColumnResizer (this)); + cr->addLayout (ui.currentSessionSectionLayout); + cr->addLayout (ui.totalSectionLayout); + cr->update (); + myTimer->setSingleShot (false); connect (myTimer, SIGNAL (timeout ()), &mySession, SLOT (refreshSessionStats ())); diff --git a/qt/stats-dialog.ui b/qt/stats-dialog.ui index f627e07ec..ccdb324cc 100644 --- a/qt/stats-dialog.ui +++ b/qt/stats-dialog.ui @@ -6,165 +6,187 @@ 0 0 - 139 - 303 + 138 + 315 Statistics - - [tr-style~="form-section"] -{ - font-weight: bold; - margin-top: 12px; - margin-bottom: 1px; -} -[tr-style~="form-section"][tr-style~="first"] -{ - margin-top: 0; -} -[tr-style~="form-label"] -{ - margin-left: 18px; -} - - + QLayout::SetFixedSize - + - - Current Session - - - form-section first - - - - - - - Uploaded: - - - form-label + + font-weight:bold - - - - - - - - Downloaded: - - - form-label + Current Session - - - - - - - Ratio: + + + + 18 + + + + + Uploaded: + + + + + + + ... + + + + + + + Downloaded: + + + + + + + ... + + + + + + + Ratio: + + + + + + + ... + + + + + + + Duration: + + + + + + + ... + + + + + + + + + Qt::Vertical - - form-label + + QSizePolicy::Fixed - - - - - - - - - Duration: + + + 1 + 10 + - - form-label - - - - - + - + - - Total - - - form-section + + font-weight:bold - - - - - - form-label - - - - - - - Uploaded: - - - form-label - - - - - - - - - - Downloaded: - - - form-label - - - - - - - - - Ratio: - - - form-label - - - - - - - - - - Duration: - - - form-label + Total - - - - + + + + 18 + + + + + ... + + + + + + + Uploaded: + + + + + + + ... + + + + + + + Downloaded: + + + + + + + ... + + + + + + + Ratio: + + + + + + + ... + + + + + + + Duration: + + + + + + + ... + + + + + + Qt::Horizontal -- 2.40.0