From dee7bc9b6a2970fcdf9de34dcef0e44999d5c9ab Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Thu, 18 Dec 2014 01:30:50 +0000 Subject: [PATCH] Move status bar creation to mainwin.ui Among other things, * fix turtle icons size (20x14 -> 16x16) * use QIcon states instead of changing the turtle icon ourselves each time (unchecked - off, checked - on) * make speed limit action in tray menu checkable * simplify status bar buttons drawing and use QToolButton instead of QPushButton --- qt/CMakeLists.txt | 4 +- qt/icons/turtle-blue.png | Bin 269 -> 298 bytes qt/icons/turtle-grey.png | Bin 207 -> 310 bytes qt/mainwin.cc | 142 ++++++++++++++------------------------- qt/mainwin.h | 14 +--- qt/mainwin.ui | 115 +++++++++++++++++++++++++++++-- qt/qtr.pro | 2 +- qt/triconpushbutton.cc | 61 ----------------- qt/triconpushbutton.h | 31 --------- qt/tricontoolbutton.cc | 28 ++++++++ qt/tricontoolbutton.h | 26 +++++++ 11 files changed, 220 insertions(+), 203 deletions(-) delete mode 100644 qt/triconpushbutton.cc delete mode 100644 qt/triconpushbutton.h create mode 100644 qt/tricontoolbutton.cc create mode 100644 qt/tricontoolbutton.h diff --git a/qt/CMakeLists.txt b/qt/CMakeLists.txt index 11870504e..54edceff2 100644 --- a/qt/CMakeLists.txt +++ b/qt/CMakeLists.txt @@ -56,7 +56,7 @@ set(${PROJECT_NAME}_SOURCES tracker-delegate.cc tracker-model-filter.cc tracker-model.cc - triconpushbutton.cc + tricontoolbutton.cc utils.cc watchdir.cc ) @@ -94,7 +94,7 @@ set(${PROJECT_NAME}_HEADERS tracker-delegate.h tracker-model-filter.h tracker-model.h - triconpushbutton.h + tricontoolbutton.h types.h utils.h watchdir.h diff --git a/qt/icons/turtle-blue.png b/qt/icons/turtle-blue.png index fa7fe15b5ecd382e1911fe9a21f593ed048bc132..51e84de556d6c1d9ebf8cdf0116ddb8ed8b3e1a1 100644 GIT binary patch literal 298 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|I14-?iy0WW zg+Z8+Vb&Z8px}8=7sn8b({Cs2gwcVX= z?Pk%kv!kMB&)(hr?tw|f1joSL?B{;W5x*C;_L1@|x9vAm)~?d1=M5Egy}px!(aB*s z^IEZ+=aVl#QB%EP#?x*f;jo^)EzrfJcd5XIy#21Ct-Ge&kzsdJp5eoFJh|YmQby#5 z9(^$xZ^qM)9_)HhDZr9iD}QK0_Pouki`wr7F-*ujRcF@xbI+R+uEH~%88v?oW*t@Y swAdfh*^sea`LoT7@AWllN9*q}W_(!YZFkMd8t63!Pgg&ebxsLQ00*>n&;S4c literal 269 zcmV+o0rLKdP)$hfi`8s)7rld5=ed4!ADJF__OeDM8oe=y?zX5Jly}5aO6y zp0foK8MYDx#BRr7I)&M++++f2${DD=_2F{KX1(SDB+u>lWI+Hzkg37X`giaS?@ApD TsePe-00000NkvXXu0mjf$z*V_ diff --git a/qt/icons/turtle-grey.png b/qt/icons/turtle-grey.png index edfaa300e3cebfe510a72c202631dfdc783f94a5..c03f5a7f69336a005ae4b77975a61139bcfc71a2 100644 GIT binary patch literal 310 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|I14-?iy0WW zg+Z8+Vb&Z8px|v!7sn8b)5!@EtUnrLnd8U5&u?x{ zw!1j1wWY&zd#s|JJQr z12;^YcCFspdiU($Wj-%|{{LSuC1Slmf(&wi-}Qqw$L978G?lYjWDENOO1W533v z#;n46L&QkBVE*&}=l{=tZ~wf;hAWb%#lGYJ^nd!F<6rH6Q7^Y3=o`zw|1qC0iWqTr z)KB=m{!hFpN9aFoCex0;(-|hY-M%Q&l^gPF{m*!5uC4!W-=A~qvpp||?1i;ut78`Y zzt6z+_22HdKlM8g_sTt0bpOBHG2w2_+5e9|2Z{addAction (ui.action_SortByState); myAltSpeedAction = new QAction (tr ("Speed Limits"), this); - myAltSpeedAction->setIcon (myPrefs.get (Prefs::ALT_SPEED_LIMIT_ENABLED) ? mySpeedModeOnIcon : mySpeedModeOffIcon); + myAltSpeedAction->setIcon (ui.altSpeedButton->icon ()); + myAltSpeedAction->setCheckable (true); connect (myAltSpeedAction, SIGNAL (triggered ()), this, SLOT (toggleSpeedMode ())); QMenu * menu = new QMenu (this); @@ -243,7 +240,7 @@ TrMainWindow::TrMainWindow (Session& session, Prefs& prefs, TorrentModel& model, toggleWindows (!minimized); ui.action_TrayIcon->setChecked (minimized || prefs.getBool (Prefs::SHOW_TRAY_ICON)); - ui.verticalLayout->addWidget (createStatusBar ()); + initStatusBar (); ui.verticalLayout->insertWidget (0, myFilterBar = new FilterBar (myPrefs, myModel, myFilterModel)); QList initKeys; @@ -276,7 +273,7 @@ TrMainWindow::TrMainWindow (Session& session, Prefs& prefs, TorrentModel& model, if (mySession.isServer ()) { - myNetworkLabel->hide (); + ui.networkLabel->hide (); } else { @@ -341,82 +338,18 @@ TrMainWindow::onSetPrefs (bool isChecked) #define SHOW_KEY "show-mode" -QWidget * -TrMainWindow::createStatusBar () +void +TrMainWindow::initStatusBar () { - QMenu * m; - QLabel * l; - QHBoxLayout * h; - QPushButton * p; - QActionGroup * a; - const int i = style ()->pixelMetric (QStyle::PM_SmallIconSize, 0, this); - const QSize smallIconSize (i, i); + ui.optionsButton->setMenu (createOptionsMenu ()); - QWidget * top = myStatusBar = new QWidget; - h = new QHBoxLayout (top); - h->setContentsMargins (HIG::PAD_SMALL, HIG::PAD_SMALL, HIG::PAD_SMALL, HIG::PAD_SMALL); - h->setSpacing (HIG::PAD_SMALL); + const int minimumSpeedWidth = ui.downloadSpeedLabel->fontMetrics ().width (Formatter::uploadSpeedToString (Speed::fromKBps (999.99))); + ui.downloadSpeedLabel->setMinimumWidth (minimumSpeedWidth); + ui.uploadSpeedLabel->setMinimumWidth (minimumSpeedWidth); - p = myOptionsButton = new TrIconPushButton (this); - p->setIcon (QIcon (":/icons/utilities.png")); - p->setIconSize (QPixmap (":/icons/utilities.png").size ()); - p->setFlat (true); - p->setMenu (createOptionsMenu ()); - h->addWidget (p); + ui.statsModeButton->setMenu (createStatsModeMenu ()); - p = myAltSpeedButton = new QPushButton (this); - p->setIcon (myPrefs.get (Prefs::ALT_SPEED_LIMIT_ENABLED) ? mySpeedModeOnIcon : mySpeedModeOffIcon); - p->setIconSize (QPixmap (":/icons/alt-limit-on.png").size ()); - p->setCheckable (true); - p->setFixedWidth (p->height ()); - p->setFlat (true); - h->addWidget (p); - connect (p, SIGNAL (clicked ()), this, SLOT (toggleSpeedMode ())); - - l = myNetworkLabel = new QLabel; - h->addWidget (l); - - h->addStretch (1); - - l = myDownloadSpeedLabel = new QLabel (this); - const int minimumSpeedWidth = l->fontMetrics ().width (Formatter::uploadSpeedToString (Speed::fromKBps (999.99))); - l->setMinimumWidth (minimumSpeedWidth); - l->setAlignment (Qt::AlignRight|Qt::AlignVCenter); - h->addWidget (l); - - h->addSpacing (HIG::PAD); - - l = myUploadSpeedLabel = new QLabel; - l->setMinimumWidth (minimumSpeedWidth); - l->setAlignment (Qt::AlignRight|Qt::AlignVCenter); - h->addWidget (l); - - h->addSpacing (HIG::PAD); - - l = myStatsLabel = new QLabel (this); - h->addWidget (l); - a = new QActionGroup (this); - a->addAction (ui.action_TotalRatio); - a->addAction (ui.action_TotalTransfer); - a->addAction (ui.action_SessionRatio); - a->addAction (ui.action_SessionTransfer); - m = new QMenu (this); - m->addAction (ui.action_TotalRatio); - m->addAction (ui.action_TotalTransfer); - m->addAction (ui.action_SessionRatio); - m->addAction (ui.action_SessionTransfer); - connect (ui.action_TotalRatio, SIGNAL (triggered ()), this, SLOT (showTotalRatio ())); - connect (ui.action_TotalTransfer, SIGNAL (triggered ()), this, SLOT (showTotalTransfer ())); - connect (ui.action_SessionRatio, SIGNAL (triggered ()), this, SLOT (showSessionRatio ())); - connect (ui.action_SessionTransfer, SIGNAL (triggered ()), this, SLOT (showSessionTransfer ())); - p = myStatsModeButton = new TrIconPushButton (this); - p->setIcon (QIcon (":/icons/ratio.png")); - p->setIconSize (QPixmap (":/icons/ratio.png").size ()); - p->setFlat (true); - p->setMenu (m); - h->addWidget (p); - - return top; + connect (ui.altSpeedButton, SIGNAL (clicked ()), this, SLOT (toggleSpeedMode ())); } QMenu * @@ -503,6 +436,29 @@ TrMainWindow::createOptionsMenu () return menu; } +QMenu * +TrMainWindow::createStatsModeMenu () +{ + QActionGroup * a = new QActionGroup (this); + a->addAction (ui.action_TotalRatio); + a->addAction (ui.action_TotalTransfer); + a->addAction (ui.action_SessionRatio); + a->addAction (ui.action_SessionTransfer); + + QMenu * m = new QMenu (this); + m->addAction (ui.action_TotalRatio); + m->addAction (ui.action_TotalTransfer); + m->addAction (ui.action_SessionRatio); + m->addAction (ui.action_SessionTransfer); + + connect (ui.action_TotalRatio, SIGNAL (triggered ()), this, SLOT (showTotalRatio ())); + connect (ui.action_TotalTransfer, SIGNAL (triggered ()), this, SLOT (showTotalTransfer ())); + connect (ui.action_SessionRatio, SIGNAL (triggered ()), this, SLOT (showSessionRatio ())); + connect (ui.action_SessionTransfer, SIGNAL (triggered ()), this, SLOT (showSessionTransfer ())); + + return m; +} + /**** ***** ****/ @@ -731,12 +687,12 @@ TrMainWindow::refreshStatusBar () size_t upCount, downCount; myModel.getTransferSpeed (upSpeed, upCount, downSpeed, downCount); - myUploadSpeedLabel->setText (Formatter::uploadSpeedToString(upSpeed)); - myUploadSpeedLabel->setVisible (downCount || upCount); - myDownloadSpeedLabel->setText (Formatter::downloadSpeedToString(downSpeed)); - myDownloadSpeedLabel->setVisible (downCount); + ui.uploadSpeedLabel->setText (Formatter::uploadSpeedToString (upSpeed)); + ui.uploadSpeedLabel->setVisible (downCount || upCount); + ui.downloadSpeedLabel->setText (Formatter::downloadSpeedToString (downSpeed)); + ui.downloadSpeedLabel->setVisible (downCount); - myNetworkLabel->setVisible (!mySession.isServer ()); + ui.networkLabel->setVisible (!mySession.isServer ()); const QString mode (myPrefs.getString (Prefs::STATUSBAR_STATS)); QString str; @@ -762,7 +718,7 @@ TrMainWindow::refreshStatusBar () str = tr ("Ratio: %1").arg (Formatter:: ratioToString (mySession.getCumulativeStats ().ratio)); } - myStatsLabel->setText (str); + ui.statsLabel->setText (str); } @@ -951,7 +907,7 @@ TrMainWindow::toggleSpeedMode () { myPrefs.toggleBool (Prefs::ALT_SPEED_LIMIT_ENABLED); const bool mode = myPrefs.get (Prefs::ALT_SPEED_LIMIT_ENABLED); - myAltSpeedAction->setIcon (mode ? mySpeedModeOnIcon : mySpeedModeOffIcon); + myAltSpeedAction->setChecked (mode); } void TrMainWindow::setToolbarVisible (bool visible) @@ -1071,7 +1027,7 @@ TrMainWindow::refreshPref (int key) case Prefs::STATUSBAR: b = myPrefs.getBool (key); - myStatusBar->setVisible (b); + ui.statusBar->setVisible (b); ui.action_Statusbar->setChecked (b); break; @@ -1118,14 +1074,14 @@ TrMainWindow::refreshPref (int key) case Prefs::ALT_SPEED_LIMIT_DOWN: { b = myPrefs.getBool (Prefs::ALT_SPEED_LIMIT_ENABLED); - myAltSpeedButton->setChecked (b); - myAltSpeedButton->setIcon (b ? mySpeedModeOnIcon : mySpeedModeOffIcon); + myAltSpeedAction->setChecked (b); + ui.altSpeedButton->setChecked (b); const QString fmt = b ? tr ("Click to disable Temporary Speed Limits\n (%1 down, %2 up)") : tr ("Click to enable Temporary Speed Limits\n (%1 down, %2 up)"); const Speed d = Speed::fromKBps (myPrefs.getInt (Prefs::ALT_SPEED_LIMIT_DOWN)); const Speed u = Speed::fromKBps (myPrefs.getInt (Prefs::ALT_SPEED_LIMIT_UP)); - myAltSpeedButton->setToolTip (fmt.arg (Formatter::speedToString (d)) - .arg (Formatter::speedToString (u))); + ui.altSpeedButton->setToolTip (fmt.arg (Formatter::speedToString (d)) + .arg (Formatter::speedToString (u))); break; } @@ -1366,8 +1322,8 @@ TrMainWindow::updateNetworkIcon () else tip = tr ("%1 is not responding").arg (url); - myNetworkLabel->setPixmap (pixmap); - myNetworkLabel->setToolTip (tip); + ui.networkLabel->setPixmap (pixmap); + ui.networkLabel->setToolTip (tip); } void diff --git a/qt/mainwin.h b/qt/mainwin.h index d5a81cf5b..da51f5859 100644 --- a/qt/mainwin.h +++ b/qt/mainwin.h @@ -69,8 +69,6 @@ class TrMainWindow: public QMainWindow Prefs& myPrefs; TorrentModel& myModel; Ui_MainWindow ui; - QIcon mySpeedModeOffIcon; - QIcon mySpeedModeOnIcon; time_t myLastSendTime; time_t myLastReadTime; QTimer myNetworkTimer; @@ -146,16 +144,10 @@ class TrMainWindow: public QMainWindow private: QMenu * createOptionsMenu (); - QWidget * createStatusBar (); - QWidget * myStatusBar; - QPushButton * myAltSpeedButton; + QMenu * createStatsModeMenu (); + void initStatusBar (); + QAction * myAltSpeedAction; - QPushButton * myOptionsButton; - QPushButton * myStatsModeButton; - QLabel * myStatsLabel; - QLabel * myDownloadSpeedLabel; - QLabel * myUploadSpeedLabel; - QLabel * myNetworkLabel; QString myErrorMessage; public slots: diff --git a/qt/mainwin.ui b/qt/mainwin.ui index e8f97499c..d27abb475 100644 --- a/qt/mainwin.ui +++ b/qt/mainwin.ui @@ -6,8 +6,8 @@ 0 0 - 792 - 390 + 472 + 427 @@ -43,6 +43,106 @@ + + + + QLabel { margin: 3px 0; } + + + + 3 + + + 3 + + + + + + :/icons/utilities.png:/icons/utilities.png + + + QToolButton::InstantPopup + + + Qt::ToolButtonIconOnly + + + true + + + + + + + + :/icons/alt-limit-off.png + :/icons/alt-limit-on.png:/icons/alt-limit-off.png + + + true + + + Qt::ToolButtonIconOnly + + + true + + + + + + + + + + Qt::Horizontal + + + + 1 + 1 + + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + :/icons/ratio.png:/icons/ratio.png + + + QToolButton::InstantPopup + + + Qt::ToolButtonIconOnly + + + true + + + + + + @@ -50,8 +150,8 @@ 0 0 - 792 - 20 + 472 + 24 @@ -643,6 +743,13 @@ + + + TrIconToolButton + QToolButton +
tricontoolbutton.h
+
+
diff --git a/qt/qtr.pro b/qt/qtr.pro index 66134e04b..043f671b6 100644 --- a/qt/qtr.pro +++ b/qt/qtr.pro @@ -79,7 +79,7 @@ SOURCES += about.cc \ tracker-delegate.cc \ tracker-model.cc \ tracker-model-filter.cc \ - triconpushbutton.cc \ + tricontoolbutton.cc \ utils.cc \ watchdir.cc HEADERS += $$replace(SOURCES, .cc, .h) diff --git a/qt/triconpushbutton.cc b/qt/triconpushbutton.cc deleted file mode 100644 index c79d0a06c..000000000 --- a/qt/triconpushbutton.cc +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This file Copyright (C) 2009-2014 Mnemosyne LLC - * - * It may be used under the GNU Public License v2 or v3 licenses, - * or any future license endorsed by Mnemosyne LLC. - * - * $Id$ - */ - -#include -#include -#include -#include -#include - -#include "hig.h" -#include "triconpushbutton.h" - -TrIconPushButton::TrIconPushButton (QWidget * parent): - QPushButton (parent) -{ -} - -TrIconPushButton::TrIconPushButton (const QIcon& icon, QWidget * parent): - QPushButton (parent) -{ - setIcon (icon); -} - -QSize -TrIconPushButton::sizeHint () const -{ - QSize s = iconSize (); - s.rwidth() += HIG::PAD_SMALL*2; - return s; -} - -void -TrIconPushButton::paintEvent (QPaintEvent *) -{ - QStylePainter p (this); - QStyleOptionButton opt; - initStyleOption (&opt); - - QIcon::Mode mode = opt.state & QStyle::State_Enabled ? QIcon::Normal : QIcon::Disabled; - if ((mode == QIcon::Normal) && (opt.state & QStyle::State_HasFocus)) - mode = QIcon::Active; - QPixmap pixmap = opt.icon.pixmap (opt.iconSize, QIcon::Active, QIcon::On); - QRect iconRect (opt.rect.x() + HIG::PAD_SMALL, - opt.rect.y() + (opt.rect.height() - pixmap.height())/2, - pixmap.width(), - pixmap.height()); - if (opt.state & (QStyle::State_On | QStyle::State_Sunken)) - iconRect.translate (style()->pixelMetric (QStyle::PM_ButtonShiftHorizontal, &opt, this), - style()->pixelMetric (QStyle::PM_ButtonShiftVertical, &opt, this)); - - p.drawPixmap(iconRect, pixmap); - - if (opt.state & QStyle::State_HasFocus) - p.drawPrimitive (QStyle::PE_FrameFocusRect, opt); -} diff --git a/qt/triconpushbutton.h b/qt/triconpushbutton.h deleted file mode 100644 index cd3f950ff..000000000 --- a/qt/triconpushbutton.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * This file Copyright (C) 2009-2014 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_IconPushButton_H -#define QTR_IconPushButton_H - -#include - -class QIcon; - -class TrIconPushButton: public QPushButton -{ - Q_OBJECT - - public: - TrIconPushButton (QWidget * parent = 0); - TrIconPushButton (const QIcon&, QWidget * parent = 0); - virtual ~TrIconPushButton () {} - QSize sizeHint () const; - - protected: - void paintEvent (QPaintEvent * event); -}; - -#endif // QTR_IconPushButton_H diff --git a/qt/tricontoolbutton.cc b/qt/tricontoolbutton.cc new file mode 100644 index 000000000..6ef9e7517 --- /dev/null +++ b/qt/tricontoolbutton.cc @@ -0,0 +1,28 @@ +/* + * This file Copyright (C) 2009-2014 Mnemosyne LLC + * + * It may be used under the GNU Public License v2 or v3 licenses, + * or any future license endorsed by Mnemosyne LLC. + * + * $Id$ + */ + +#include +#include +#include + +#include "tricontoolbutton.h" + +TrIconToolButton::TrIconToolButton (QWidget * parent): + QToolButton (parent) +{ +} + +void TrIconToolButton::paintEvent (QPaintEvent * /*event*/) +{ + QStylePainter painter(this); + QStyleOptionToolButton option; + initStyleOption (&option); + option.features &= ~QStyleOptionToolButton::HasMenu; + painter.drawComplexControl(QStyle::CC_ToolButton, option); +} diff --git a/qt/tricontoolbutton.h b/qt/tricontoolbutton.h new file mode 100644 index 000000000..714cadd88 --- /dev/null +++ b/qt/tricontoolbutton.h @@ -0,0 +1,26 @@ +/* + * This file Copyright (C) 2009-2014 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_ICON_TOOL_BUTTON_H +#define QTR_ICON_TOOL_BUTTON_H + +#include + +class TrIconToolButton: public QToolButton +{ + Q_OBJECT + + public: + TrIconToolButton (QWidget * parent = nullptr); + + protected: + virtual void paintEvent (QPaintEvent * event); +}; + +#endif // QTR_ICON_TOOL_BUTTON_H