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
This commit is contained in:
parent
172f875691
commit
dee7bc9b6a
|
@ -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
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 269 B After Width: | Height: | Size: 298 B |
Binary file not shown.
Before Width: | Height: | Size: 207 B After Width: | Height: | Size: 310 B |
142
qt/mainwin.cc
142
qt/mainwin.cc
|
@ -43,8 +43,6 @@
|
|||
#include "torrent-delegate-min.h"
|
||||
#include "torrent-filter.h"
|
||||
#include "torrent-model.h"
|
||||
#include "triconpushbutton.h"
|
||||
#include "ui_mainwin.h"
|
||||
|
||||
#define PREFS_KEY "prefs-key";
|
||||
|
||||
|
@ -94,8 +92,6 @@ TrMainWindow::TrMainWindow (Session& session, Prefs& prefs, TorrentModel& model,
|
|||
mySession (session),
|
||||
myPrefs (prefs),
|
||||
myModel (model),
|
||||
mySpeedModeOffIcon (":/icons/alt-limit-off.png"),
|
||||
mySpeedModeOnIcon (":/icons/alt-limit-on.png"),
|
||||
myLastSendTime (0),
|
||||
myLastReadTime (0),
|
||||
myNetworkTimer (this),
|
||||
|
@ -216,7 +212,8 @@ TrMainWindow::TrMainWindow (Session& session, Prefs& prefs, TorrentModel& model,
|
|||
actionGroup->addAction (ui.action_SortByState);
|
||||
|
||||
myAltSpeedAction = new QAction (tr ("Speed Limits"), this);
|
||||
myAltSpeedAction->setIcon (myPrefs.get<bool> (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<int> 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<bool> (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<bool> (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
|
||||
|
|
14
qt/mainwin.h
14
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:
|
||||
|
|
115
qt/mainwin.ui
115
qt/mainwin.ui
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>792</width>
|
||||
<height>390</height>
|
||||
<width>472</width>
|
||||
<height>427</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -43,6 +43,106 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="statusBar" native="true">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QLabel { margin: 3px 0; }</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="statusBarLayout">
|
||||
<property name="spacing">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="TrIconToolButton" name="optionsButton">
|
||||
<property name="icon">
|
||||
<iconset resource="application.qrc">
|
||||
<normaloff>:/icons/utilities.png</normaloff>:/icons/utilities.png</iconset>
|
||||
</property>
|
||||
<property name="popupMode">
|
||||
<enum>QToolButton::InstantPopup</enum>
|
||||
</property>
|
||||
<property name="toolButtonStyle">
|
||||
<enum>Qt::ToolButtonIconOnly</enum>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="altSpeedButton">
|
||||
<property name="icon">
|
||||
<iconset resource="application.qrc">
|
||||
<normaloff>:/icons/alt-limit-off.png</normaloff>
|
||||
<normalon>:/icons/alt-limit-on.png</normalon>:/icons/alt-limit-off.png</iconset>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="toolButtonStyle">
|
||||
<enum>Qt::ToolButtonIconOnly</enum>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="networkLabel"/>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>1</width>
|
||||
<height>1</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="downloadSpeedLabel">
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="uploadSpeedLabel">
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="statsLabel"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="TrIconToolButton" name="statsModeButton">
|
||||
<property name="icon">
|
||||
<iconset resource="application.qrc">
|
||||
<normaloff>:/icons/ratio.png</normaloff>:/icons/ratio.png</iconset>
|
||||
</property>
|
||||
<property name="popupMode">
|
||||
<enum>QToolButton::InstantPopup</enum>
|
||||
</property>
|
||||
<property name="toolButtonStyle">
|
||||
<enum>Qt::ToolButtonIconOnly</enum>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
|
@ -50,8 +150,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>792</width>
|
||||
<height>20</height>
|
||||
<width>472</width>
|
||||
<height>24</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
|
@ -643,6 +743,13 @@
|
|||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>TrIconToolButton</class>
|
||||
<extends>QToolButton</extends>
|
||||
<header>tricontoolbutton.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="application.qrc"/>
|
||||
</resources>
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 <iostream>
|
||||
#include <QIcon>
|
||||
#include <QStyleOption>
|
||||
#include <QStyleOptionButton>
|
||||
#include <QStylePainter>
|
||||
|
||||
#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);
|
||||
}
|
|
@ -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 <QPushButton>
|
||||
|
||||
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
|
|
@ -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 <QStyleOption>
|
||||
#include <QStyleOptionToolButton>
|
||||
#include <QStylePainter>
|
||||
|
||||
#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);
|
||||
}
|
|
@ -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 <QToolButton>
|
||||
|
||||
class TrIconToolButton: public QToolButton
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TrIconToolButton (QWidget * parent = nullptr);
|
||||
|
||||
protected:
|
||||
virtual void paintEvent (QPaintEvent * event);
|
||||
};
|
||||
|
||||
#endif // QTR_ICON_TOOL_BUTTON_H
|
Loading…
Reference in New Issue