Changeset 14389


Ignore:
Timestamp:
Dec 18, 2014, 1:30:50 AM (8 years ago)
Author:
mikedld
Message:

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
Location:
trunk/qt
Files:
7 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/qt/CMakeLists.txt

    r14387 r14389  
    5757    tracker-model-filter.cc
    5858    tracker-model.cc
    59     triconpushbutton.cc
     59    tricontoolbutton.cc
    6060    utils.cc
    6161    watchdir.cc
     
    9595    tracker-model-filter.h
    9696    tracker-model.h
    97     triconpushbutton.h
     97    tricontoolbutton.h
    9898    types.h
    9999    utils.h
  • trunk/qt/mainwin.cc

    r14386 r14389  
    4444#include "torrent-filter.h"
    4545#include "torrent-model.h"
    46 #include "triconpushbutton.h"
    47 #include "ui_mainwin.h"
    4846
    4947#define PREFS_KEY "prefs-key";
     
    9593  myPrefs (prefs),
    9694  myModel (model),
    97   mySpeedModeOffIcon (":/icons/alt-limit-off.png"),
    98   mySpeedModeOnIcon (":/icons/alt-limit-on.png"),
    9995  myLastSendTime (0),
    10096  myLastReadTime (0),
     
    217213
    218214  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);
    220217  connect (myAltSpeedAction, SIGNAL (triggered ()), this, SLOT (toggleSpeedMode ()));
    221218
     
    244241  ui.action_TrayIcon->setChecked (minimized || prefs.getBool (Prefs::SHOW_TRAY_ICON));
    245242
    246   ui.verticalLayout->addWidget (createStatusBar ());
     243  initStatusBar ();
    247244  ui.verticalLayout->insertWidget (0, myFilterBar = new FilterBar (myPrefs, myModel, myFilterModel));
    248245
     
    277274  if (mySession.isServer ())
    278275    {
    279       myNetworkLabel->hide ();
     276      ui.networkLabel->hide ();
    280277    }
    281278  else
     
    342339#define SHOW_KEY "show-mode"
    343340
    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;
     341void
     342TrMainWindow::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 ()));
    420353}
    421354
     
    504437}
    505438
     439QMenu *
     440TrMainWindow::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
    506462/****
    507463*****
     
    732688  myModel.getTransferSpeed (upSpeed, upCount, downSpeed, downCount);
    733689
    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 ());
    740696
    741697  const QString mode (myPrefs.getString (Prefs::STATUSBAR_STATS));
     
    763719    }
    764720
    765   myStatsLabel->setText (str);
     721  ui.statsLabel->setText (str);
    766722}
    767723
     
    952908  myPrefs.toggleBool (Prefs::ALT_SPEED_LIMIT_ENABLED);
    953909  const bool mode = myPrefs.get<bool> (Prefs::ALT_SPEED_LIMIT_ENABLED);
    954   myAltSpeedAction->setIcon (mode ? mySpeedModeOnIcon : mySpeedModeOffIcon);
     910  myAltSpeedAction->setChecked (mode);
    955911}
    956912void
     
    10721028      case Prefs::STATUSBAR:
    10731029        b = myPrefs.getBool (key);
    1074         myStatusBar->setVisible (b);
     1030        ui.statusBar->setVisible (b);
    10751031        ui.action_Statusbar->setChecked (b);
    10761032        break;
     
    11191075        {
    11201076          b = myPrefs.getBool (Prefs::ALT_SPEED_LIMIT_ENABLED);
    1121           myAltSpeedButton->setChecked (b);
    1122           myAltSpeedButton->setIcon (b ? mySpeedModeOnIcon : mySpeedModeOffIcon);
     1077          myAltSpeedAction->setChecked (b);
     1078          ui.altSpeedButton->setChecked (b);
    11231079          const QString fmt = b ? tr ("Click to disable Temporary Speed Limits\n (%1 down, %2 up)")
    11241080                                : tr ("Click to enable Temporary Speed Limits\n (%1 down, %2 up)");
    11251081          const Speed d = Speed::fromKBps (myPrefs.getInt (Prefs::ALT_SPEED_LIMIT_DOWN));
    11261082          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)));
    11291085          break;
    11301086        }
     
    13671323    tip = tr ("%1 is not responding").arg (url);
    13681324
    1369   myNetworkLabel->setPixmap (pixmap);
    1370   myNetworkLabel->setToolTip (tip);
     1325  ui.networkLabel->setPixmap (pixmap);
     1326  ui.networkLabel->setToolTip (tip);
    13711327}
    13721328
  • trunk/qt/mainwin.h

    r14385 r14389  
    7070    TorrentModel& myModel;
    7171    Ui_MainWindow ui;
    72     QIcon mySpeedModeOffIcon;
    73     QIcon mySpeedModeOnIcon;
    7472    time_t myLastSendTime;
    7573    time_t myLastReadTime;
     
    147145  private:
    148146    QMenu * createOptionsMenu ();
    149     QWidget * createStatusBar ();
    150     QWidget * myStatusBar;
    151     QPushButton * myAltSpeedButton;
     147    QMenu * createStatsModeMenu ();
     148    void initStatusBar ();
     149
    152150    QAction * myAltSpeedAction;
    153     QPushButton * myOptionsButton;
    154     QPushButton * myStatsModeButton;
    155     QLabel * myStatsLabel;
    156     QLabel * myDownloadSpeedLabel;
    157     QLabel * myUploadSpeedLabel;
    158     QLabel * myNetworkLabel;
    159151    QString myErrorMessage;
    160152
  • trunk/qt/mainwin.ui

    r13385 r14389  
    77    <x>0</x>
    88    <y>0</y>
    9     <width>792</width>
    10     <height>390</height>
     9    <width>472</width>
     10    <height>427</height>
    1111   </rect>
    1212  </property>
     
    4444     </widget>
    4545    </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>
    46146   </layout>
    47147  </widget>
     
    51151     <x>0</x>
    52152     <y>0</y>
    53      <width>792</width>
    54      <height>20</height>
     153     <width>472</width>
     154     <height>24</height>
    55155    </rect>
    56156   </property>
     
    644744  </action>
    645745 </widget>
     746 <customwidgets>
     747  <customwidget>
     748   <class>TrIconToolButton</class>
     749   <extends>QToolButton</extends>
     750   <header>tricontoolbutton.h</header>
     751  </customwidget>
     752 </customwidgets>
    646753 <resources>
    647754  <include location="application.qrc"/>
  • trunk/qt/qtr.pro

    r14387 r14389  
    8080           tracker-model.cc \
    8181           tracker-model-filter.cc \
    82            triconpushbutton.cc \
     82           tricontoolbutton.cc \
    8383           utils.cc \
    8484           watchdir.cc
  • trunk/qt/tricontoolbutton.cc

    r14388 r14389  
    88 */
    99
    10 #include <iostream>
    11 #include <QIcon>
    1210#include <QStyleOption>
    13 #include <QStyleOptionButton>
     11#include <QStyleOptionToolButton>
    1412#include <QStylePainter>
    1513
    16 #include "hig.h"
    17 #include "triconpushbutton.h"
     14#include "tricontoolbutton.h"
    1815
    19 TrIconPushButton::TrIconPushButton (QWidget * parent):
    20   QPushButton (parent)
     16TrIconToolButton::TrIconToolButton (QWidget * parent):
     17  QToolButton (parent)
    2118{
    2219}
    2320
    24 TrIconPushButton::TrIconPushButton (const QIcon& icon, QWidget * parent):
    25   QPushButton (parent)
     21void TrIconToolButton::paintEvent (QPaintEvent * /*event*/)
    2622{
    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);
    2828}
    29 
    30 QSize
    31 TrIconPushButton::sizeHint () const
    32 {
    33   QSize s = iconSize ();
    34   s.rwidth() += HIG::PAD_SMALL*2;
    35   return s;
    36 }
    37 
    38 void
    39 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  
    88 */
    99
    10 #ifndef QTR_IconPushButton_H
    11 #define QTR_IconPushButton_H
     10#ifndef QTR_ICON_TOOL_BUTTON_H
     11#define QTR_ICON_TOOL_BUTTON_H
    1212
    13 #include <QPushButton>
     13#include <QToolButton>
    1414
    15 class QIcon;
    16 
    17 class TrIconPushButton: public QPushButton
     15class TrIconToolButton: public QToolButton
    1816{
    1917    Q_OBJECT
    2018
    2119  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);
    2621
    2722  protected:
    28     void paintEvent (QPaintEvent * event);
     23    virtual void paintEvent (QPaintEvent * event);
    2924};
    3025
    31 #endif // QTR_IconPushButton_H
     26#endif // QTR_ICON_TOOL_BUTTON_H
Note: See TracChangeset for help on using the changeset viewer.