Changeset 14389
- Timestamp:
- Dec 18, 2014, 1:30:50 AM (8 years ago)
- Location:
- trunk/qt
- Files:
-
- 7 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/qt/CMakeLists.txt
r14387 r14389 57 57 tracker-model-filter.cc 58 58 tracker-model.cc 59 tricon pushbutton.cc59 tricontoolbutton.cc 60 60 utils.cc 61 61 watchdir.cc … … 95 95 tracker-model-filter.h 96 96 tracker-model.h 97 tricon pushbutton.h97 tricontoolbutton.h 98 98 types.h 99 99 utils.h -
trunk/qt/mainwin.cc
r14386 r14389 44 44 #include "torrent-filter.h" 45 45 #include "torrent-model.h" 46 #include "triconpushbutton.h"47 #include "ui_mainwin.h"48 46 49 47 #define PREFS_KEY "prefs-key"; … … 95 93 myPrefs (prefs), 96 94 myModel (model), 97 mySpeedModeOffIcon (":/icons/alt-limit-off.png"),98 mySpeedModeOnIcon (":/icons/alt-limit-on.png"),99 95 myLastSendTime (0), 100 96 myLastReadTime (0), … … 217 213 218 214 myAltSpeedAction = new QAction (tr ("Speed Limits"), this); 219 myAltSpeedAction->setIcon (myPrefs.get<bool> (Prefs::ALT_SPEED_LIMIT_ENABLED) ? mySpeedModeOnIcon : mySpeedModeOffIcon); 215 myAltSpeedAction->setIcon (ui.altSpeedButton->icon ()); 216 myAltSpeedAction->setCheckable (true); 220 217 connect (myAltSpeedAction, SIGNAL (triggered ()), this, SLOT (toggleSpeedMode ())); 221 218 … … 244 241 ui.action_TrayIcon->setChecked (minimized || prefs.getBool (Prefs::SHOW_TRAY_ICON)); 245 242 246 ui.verticalLayout->addWidget (createStatusBar ());243 initStatusBar (); 247 244 ui.verticalLayout->insertWidget (0, myFilterBar = new FilterBar (myPrefs, myModel, myFilterModel)); 248 245 … … 277 274 if (mySession.isServer ()) 278 275 { 279 myNetworkLabel->hide ();276 ui.networkLabel->hide (); 280 277 } 281 278 else … … 342 339 #define SHOW_KEY "show-mode" 343 340 344 QWidget * 345 TrMainWindow::createStatusBar () 346 { 347 QMenu * m; 348 QLabel * l; 349 QHBoxLayout * h; 350 QPushButton * p; 351 QActionGroup * a; 352 const int i = style ()->pixelMetric (QStyle::PM_SmallIconSize, 0, this); 353 const QSize smallIconSize (i, i); 354 355 QWidget * top = myStatusBar = new QWidget; 356 h = new QHBoxLayout (top); 357 h->setContentsMargins (HIG::PAD_SMALL, HIG::PAD_SMALL, HIG::PAD_SMALL, HIG::PAD_SMALL); 358 h->setSpacing (HIG::PAD_SMALL); 359 360 p = myOptionsButton = new TrIconPushButton (this); 361 p->setIcon (QIcon (":/icons/utilities.png")); 362 p->setIconSize (QPixmap (":/icons/utilities.png").size ()); 363 p->setFlat (true); 364 p->setMenu (createOptionsMenu ()); 365 h->addWidget (p); 366 367 p = myAltSpeedButton = new QPushButton (this); 368 p->setIcon (myPrefs.get<bool> (Prefs::ALT_SPEED_LIMIT_ENABLED) ? mySpeedModeOnIcon : mySpeedModeOffIcon); 369 p->setIconSize (QPixmap (":/icons/alt-limit-on.png").size ()); 370 p->setCheckable (true); 371 p->setFixedWidth (p->height ()); 372 p->setFlat (true); 373 h->addWidget (p); 374 connect (p, SIGNAL (clicked ()), this, SLOT (toggleSpeedMode ())); 375 376 l = myNetworkLabel = new QLabel; 377 h->addWidget (l); 378 379 h->addStretch (1); 380 381 l = myDownloadSpeedLabel = new QLabel (this); 382 const int minimumSpeedWidth = l->fontMetrics ().width (Formatter::uploadSpeedToString (Speed::fromKBps (999.99))); 383 l->setMinimumWidth (minimumSpeedWidth); 384 l->setAlignment (Qt::AlignRight|Qt::AlignVCenter); 385 h->addWidget (l); 386 387 h->addSpacing (HIG::PAD); 388 389 l = myUploadSpeedLabel = new QLabel; 390 l->setMinimumWidth (minimumSpeedWidth); 391 l->setAlignment (Qt::AlignRight|Qt::AlignVCenter); 392 h->addWidget (l); 393 394 h->addSpacing (HIG::PAD); 395 396 l = myStatsLabel = new QLabel (this); 397 h->addWidget (l); 398 a = new QActionGroup (this); 399 a->addAction (ui.action_TotalRatio); 400 a->addAction (ui.action_TotalTransfer); 401 a->addAction (ui.action_SessionRatio); 402 a->addAction (ui.action_SessionTransfer); 403 m = new QMenu (this); 404 m->addAction (ui.action_TotalRatio); 405 m->addAction (ui.action_TotalTransfer); 406 m->addAction (ui.action_SessionRatio); 407 m->addAction (ui.action_SessionTransfer); 408 connect (ui.action_TotalRatio, SIGNAL (triggered ()), this, SLOT (showTotalRatio ())); 409 connect (ui.action_TotalTransfer, SIGNAL (triggered ()), this, SLOT (showTotalTransfer ())); 410 connect (ui.action_SessionRatio, SIGNAL (triggered ()), this, SLOT (showSessionRatio ())); 411 connect (ui.action_SessionTransfer, SIGNAL (triggered ()), this, SLOT (showSessionTransfer ())); 412 p = myStatsModeButton = new TrIconPushButton (this); 413 p->setIcon (QIcon (":/icons/ratio.png")); 414 p->setIconSize (QPixmap (":/icons/ratio.png").size ()); 415 p->setFlat (true); 416 p->setMenu (m); 417 h->addWidget (p); 418 419 return top; 341 void 342 TrMainWindow::initStatusBar () 343 { 344 ui.optionsButton->setMenu (createOptionsMenu ()); 345 346 const int minimumSpeedWidth = ui.downloadSpeedLabel->fontMetrics ().width (Formatter::uploadSpeedToString (Speed::fromKBps (999.99))); 347 ui.downloadSpeedLabel->setMinimumWidth (minimumSpeedWidth); 348 ui.uploadSpeedLabel->setMinimumWidth (minimumSpeedWidth); 349 350 ui.statsModeButton->setMenu (createStatsModeMenu ()); 351 352 connect (ui.altSpeedButton, SIGNAL (clicked ()), this, SLOT (toggleSpeedMode ())); 420 353 } 421 354 … … 504 437 } 505 438 439 QMenu * 440 TrMainWindow::createStatsModeMenu () 441 { 442 QActionGroup * a = new QActionGroup (this); 443 a->addAction (ui.action_TotalRatio); 444 a->addAction (ui.action_TotalTransfer); 445 a->addAction (ui.action_SessionRatio); 446 a->addAction (ui.action_SessionTransfer); 447 448 QMenu * m = new QMenu (this); 449 m->addAction (ui.action_TotalRatio); 450 m->addAction (ui.action_TotalTransfer); 451 m->addAction (ui.action_SessionRatio); 452 m->addAction (ui.action_SessionTransfer); 453 454 connect (ui.action_TotalRatio, SIGNAL (triggered ()), this, SLOT (showTotalRatio ())); 455 connect (ui.action_TotalTransfer, SIGNAL (triggered ()), this, SLOT (showTotalTransfer ())); 456 connect (ui.action_SessionRatio, SIGNAL (triggered ()), this, SLOT (showSessionRatio ())); 457 connect (ui.action_SessionTransfer, SIGNAL (triggered ()), this, SLOT (showSessionTransfer ())); 458 459 return m; 460 } 461 506 462 /**** 507 463 ***** … … 732 688 myModel.getTransferSpeed (upSpeed, upCount, downSpeed, downCount); 733 689 734 myUploadSpeedLabel->setText (Formatter::uploadSpeedToString(upSpeed));735 myUploadSpeedLabel->setVisible (downCount || upCount);736 myDownloadSpeedLabel->setText (Formatter::downloadSpeedToString(downSpeed));737 myDownloadSpeedLabel->setVisible (downCount);738 739 myNetworkLabel->setVisible (!mySession.isServer ());690 ui.uploadSpeedLabel->setText (Formatter::uploadSpeedToString (upSpeed)); 691 ui.uploadSpeedLabel->setVisible (downCount || upCount); 692 ui.downloadSpeedLabel->setText (Formatter::downloadSpeedToString (downSpeed)); 693 ui.downloadSpeedLabel->setVisible (downCount); 694 695 ui.networkLabel->setVisible (!mySession.isServer ()); 740 696 741 697 const QString mode (myPrefs.getString (Prefs::STATUSBAR_STATS)); … … 763 719 } 764 720 765 myStatsLabel->setText (str);721 ui.statsLabel->setText (str); 766 722 } 767 723 … … 952 908 myPrefs.toggleBool (Prefs::ALT_SPEED_LIMIT_ENABLED); 953 909 const bool mode = myPrefs.get<bool> (Prefs::ALT_SPEED_LIMIT_ENABLED); 954 myAltSpeedAction->set Icon (mode ? mySpeedModeOnIcon : mySpeedModeOffIcon);910 myAltSpeedAction->setChecked (mode); 955 911 } 956 912 void … … 1072 1028 case Prefs::STATUSBAR: 1073 1029 b = myPrefs.getBool (key); 1074 myStatusBar->setVisible (b);1030 ui.statusBar->setVisible (b); 1075 1031 ui.action_Statusbar->setChecked (b); 1076 1032 break; … … 1119 1075 { 1120 1076 b = myPrefs.getBool (Prefs::ALT_SPEED_LIMIT_ENABLED); 1121 myAltSpeed Button->setChecked (b);1122 myAltSpeedButton->setIcon (b ? mySpeedModeOnIcon : mySpeedModeOffIcon);1077 myAltSpeedAction->setChecked (b); 1078 ui.altSpeedButton->setChecked (b); 1123 1079 const QString fmt = b ? tr ("Click to disable Temporary Speed Limits\n (%1 down, %2 up)") 1124 1080 : tr ("Click to enable Temporary Speed Limits\n (%1 down, %2 up)"); 1125 1081 const Speed d = Speed::fromKBps (myPrefs.getInt (Prefs::ALT_SPEED_LIMIT_DOWN)); 1126 1082 const Speed u = Speed::fromKBps (myPrefs.getInt (Prefs::ALT_SPEED_LIMIT_UP)); 1127 myAltSpeedButton->setToolTip (fmt.arg (Formatter::speedToString (d))1128 .arg (Formatter::speedToString (u)));1083 ui.altSpeedButton->setToolTip (fmt.arg (Formatter::speedToString (d)) 1084 .arg (Formatter::speedToString (u))); 1129 1085 break; 1130 1086 } … … 1367 1323 tip = tr ("%1 is not responding").arg (url); 1368 1324 1369 myNetworkLabel->setPixmap (pixmap);1370 myNetworkLabel->setToolTip (tip);1325 ui.networkLabel->setPixmap (pixmap); 1326 ui.networkLabel->setToolTip (tip); 1371 1327 } 1372 1328 -
trunk/qt/mainwin.h
r14385 r14389 70 70 TorrentModel& myModel; 71 71 Ui_MainWindow ui; 72 QIcon mySpeedModeOffIcon;73 QIcon mySpeedModeOnIcon;74 72 time_t myLastSendTime; 75 73 time_t myLastReadTime; … … 147 145 private: 148 146 QMenu * createOptionsMenu (); 149 Q Widget * createStatusBar();150 QWidget * myStatusBar;151 QPushButton * myAltSpeedButton; 147 QMenu * createStatsModeMenu (); 148 void initStatusBar (); 149 152 150 QAction * myAltSpeedAction; 153 QPushButton * myOptionsButton;154 QPushButton * myStatsModeButton;155 QLabel * myStatsLabel;156 QLabel * myDownloadSpeedLabel;157 QLabel * myUploadSpeedLabel;158 QLabel * myNetworkLabel;159 151 QString myErrorMessage; 160 152 -
trunk/qt/mainwin.ui
r13385 r14389 7 7 <x>0</x> 8 8 <y>0</y> 9 <width> 792</width>10 <height> 390</height>9 <width>472</width> 10 <height>427</height> 11 11 </rect> 12 12 </property> … … 44 44 </widget> 45 45 </item> 46 <item> 47 <widget class="QWidget" name="statusBar" native="true"> 48 <property name="styleSheet"> 49 <string notr="true">QLabel { margin: 3px 0; }</string> 50 </property> 51 <layout class="QHBoxLayout" name="statusBarLayout"> 52 <property name="spacing"> 53 <number>3</number> 54 </property> 55 <property name="margin"> 56 <number>3</number> 57 </property> 58 <item> 59 <widget class="TrIconToolButton" name="optionsButton"> 60 <property name="icon"> 61 <iconset resource="application.qrc"> 62 <normaloff>:/icons/utilities.png</normaloff>:/icons/utilities.png</iconset> 63 </property> 64 <property name="popupMode"> 65 <enum>QToolButton::InstantPopup</enum> 66 </property> 67 <property name="toolButtonStyle"> 68 <enum>Qt::ToolButtonIconOnly</enum> 69 </property> 70 <property name="autoRaise"> 71 <bool>true</bool> 72 </property> 73 </widget> 74 </item> 75 <item> 76 <widget class="QToolButton" name="altSpeedButton"> 77 <property name="icon"> 78 <iconset resource="application.qrc"> 79 <normaloff>:/icons/alt-limit-off.png</normaloff> 80 <normalon>:/icons/alt-limit-on.png</normalon>:/icons/alt-limit-off.png</iconset> 81 </property> 82 <property name="checkable"> 83 <bool>true</bool> 84 </property> 85 <property name="toolButtonStyle"> 86 <enum>Qt::ToolButtonIconOnly</enum> 87 </property> 88 <property name="autoRaise"> 89 <bool>true</bool> 90 </property> 91 </widget> 92 </item> 93 <item> 94 <widget class="QLabel" name="networkLabel"/> 95 </item> 96 <item> 97 <spacer name="horizontalSpacer"> 98 <property name="orientation"> 99 <enum>Qt::Horizontal</enum> 100 </property> 101 <property name="sizeHint" stdset="0"> 102 <size> 103 <width>1</width> 104 <height>1</height> 105 </size> 106 </property> 107 </spacer> 108 </item> 109 <item> 110 <widget class="QLabel" name="downloadSpeedLabel"> 111 <property name="alignment"> 112 <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> 113 </property> 114 </widget> 115 </item> 116 <item> 117 <widget class="QLabel" name="uploadSpeedLabel"> 118 <property name="alignment"> 119 <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> 120 </property> 121 </widget> 122 </item> 123 <item> 124 <widget class="QLabel" name="statsLabel"/> 125 </item> 126 <item> 127 <widget class="TrIconToolButton" name="statsModeButton"> 128 <property name="icon"> 129 <iconset resource="application.qrc"> 130 <normaloff>:/icons/ratio.png</normaloff>:/icons/ratio.png</iconset> 131 </property> 132 <property name="popupMode"> 133 <enum>QToolButton::InstantPopup</enum> 134 </property> 135 <property name="toolButtonStyle"> 136 <enum>Qt::ToolButtonIconOnly</enum> 137 </property> 138 <property name="autoRaise"> 139 <bool>true</bool> 140 </property> 141 </widget> 142 </item> 143 </layout> 144 </widget> 145 </item> 46 146 </layout> 47 147 </widget> … … 51 151 <x>0</x> 52 152 <y>0</y> 53 <width> 792</width>54 <height>2 0</height>153 <width>472</width> 154 <height>24</height> 55 155 </rect> 56 156 </property> … … 644 744 </action> 645 745 </widget> 746 <customwidgets> 747 <customwidget> 748 <class>TrIconToolButton</class> 749 <extends>QToolButton</extends> 750 <header>tricontoolbutton.h</header> 751 </customwidget> 752 </customwidgets> 646 753 <resources> 647 754 <include location="application.qrc"/> -
trunk/qt/qtr.pro
r14387 r14389 80 80 tracker-model.cc \ 81 81 tracker-model-filter.cc \ 82 tricon pushbutton.cc \82 tricontoolbutton.cc \ 83 83 utils.cc \ 84 84 watchdir.cc -
trunk/qt/tricontoolbutton.cc
r14388 r14389 8 8 */ 9 9 10 #include <iostream>11 #include <QIcon>12 10 #include <QStyleOption> 13 #include <QStyleOption Button>11 #include <QStyleOptionToolButton> 14 12 #include <QStylePainter> 15 13 16 #include "hig.h" 17 #include "triconpushbutton.h" 14 #include "tricontoolbutton.h" 18 15 19 TrIcon PushButton::TrIconPushButton (QWidget * parent):20 Q PushButton (parent)16 TrIconToolButton::TrIconToolButton (QWidget * parent): 17 QToolButton (parent) 21 18 { 22 19 } 23 20 24 TrIconPushButton::TrIconPushButton (const QIcon& icon, QWidget * parent): 25 QPushButton (parent) 21 void TrIconToolButton::paintEvent (QPaintEvent * /*event*/) 26 22 { 27 setIcon (icon); 23 QStylePainter painter(this); 24 QStyleOptionToolButton option; 25 initStyleOption (&option); 26 option.features &= ~QStyleOptionToolButton::HasMenu; 27 painter.drawComplexControl(QStyle::CC_ToolButton, option); 28 28 } 29 30 QSize31 TrIconPushButton::sizeHint () const32 {33 QSize s = iconSize ();34 s.rwidth() += HIG::PAD_SMALL*2;35 return s;36 }37 38 void39 TrIconPushButton::paintEvent (QPaintEvent *)40 {41 QStylePainter p (this);42 QStyleOptionButton opt;43 initStyleOption (&opt);44 45 QIcon::Mode mode = opt.state & QStyle::State_Enabled ? QIcon::Normal : QIcon::Disabled;46 if ((mode == QIcon::Normal) && (opt.state & QStyle::State_HasFocus))47 mode = QIcon::Active;48 QPixmap pixmap = opt.icon.pixmap (opt.iconSize, QIcon::Active, QIcon::On);49 QRect iconRect (opt.rect.x() + HIG::PAD_SMALL,50 opt.rect.y() + (opt.rect.height() - pixmap.height())/2,51 pixmap.width(),52 pixmap.height());53 if (opt.state & (QStyle::State_On | QStyle::State_Sunken))54 iconRect.translate (style()->pixelMetric (QStyle::PM_ButtonShiftHorizontal, &opt, this),55 style()->pixelMetric (QStyle::PM_ButtonShiftVertical, &opt, this));56 57 p.drawPixmap(iconRect, pixmap);58 59 if (opt.state & QStyle::State_HasFocus)60 p.drawPrimitive (QStyle::PE_FrameFocusRect, opt);61 } -
trunk/qt/tricontoolbutton.h
r14388 r14389 8 8 */ 9 9 10 #ifndef QTR_I conPushButton_H11 #define QTR_I conPushButton_H10 #ifndef QTR_ICON_TOOL_BUTTON_H 11 #define QTR_ICON_TOOL_BUTTON_H 12 12 13 #include <Q PushButton>13 #include <QToolButton> 14 14 15 class QIcon; 16 17 class TrIconPushButton: public QPushButton 15 class TrIconToolButton: public QToolButton 18 16 { 19 17 Q_OBJECT 20 18 21 19 public: 22 TrIconPushButton (QWidget * parent = 0); 23 TrIconPushButton (const QIcon&, QWidget * parent = 0); 24 virtual ~TrIconPushButton () {} 25 QSize sizeHint () const; 20 TrIconToolButton (QWidget * parent = nullptr); 26 21 27 22 protected: 28 v oid paintEvent (QPaintEvent * event);23 virtual void paintEvent (QPaintEvent * event); 29 24 }; 30 25 31 #endif // QTR_I conPushButton_H26 #endif // QTR_ICON_TOOL_BUTTON_H
Note: See TracChangeset
for help on using the changeset viewer.