#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";
mySession (session),
myPrefs (prefs),
myModel (model),
- mySpeedModeOffIcon (":/icons/alt-limit-off.png"),
- mySpeedModeOnIcon (":/icons/alt-limit-on.png"),
myLastSendTime (0),
myLastReadTime (0),
myNetworkTimer (this),
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);
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;
if (mySession.isServer ())
{
- myNetworkLabel->hide ();
+ ui.networkLabel->hide ();
}
else
{
#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 ());
+
+ const int minimumSpeedWidth = ui.downloadSpeedLabel->fontMetrics ().width (Formatter::uploadSpeedToString (Speed::fromKBps (999.99)));
+ ui.downloadSpeedLabel->setMinimumWidth (minimumSpeedWidth);
+ ui.uploadSpeedLabel->setMinimumWidth (minimumSpeedWidth);
- 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);
-
- 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);
-
- 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;
+ ui.statsModeButton->setMenu (createStatsModeMenu ());
+
+ connect (ui.altSpeedButton, SIGNAL (clicked ()), this, SLOT (toggleSpeedMode ()));
}
QMenu *
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;
+}
+
/****
*****
****/
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;
str = tr ("Ratio: %1").arg (Formatter:: ratioToString (mySession.getCumulativeStats ().ratio));
}
- myStatsLabel->setText (str);
+ ui.statsLabel->setText (str);
}
{
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)
case Prefs::STATUSBAR:
b = myPrefs.getBool (key);
- myStatusBar->setVisible (b);
+ ui.statusBar->setVisible (b);
ui.action_Statusbar->setChecked (b);
break;
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;
}
else
tip = tr ("%1 is not responding").arg (url);
- myNetworkLabel->setPixmap (pixmap);
- myNetworkLabel->setToolTip (tip);
+ ui.networkLabel->setPixmap (pixmap);
+ ui.networkLabel->setToolTip (tip);
}
void
<rect>
<x>0</x>
<y>0</y>
- <width>792</width>
- <height>390</height>
+ <width>472</width>
+ <height>427</height>
</rect>
</property>
<property name="windowTitle">
</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">
<rect>
<x>0</x>
<y>0</y>
- <width>792</width>
- <height>20</height>
+ <width>472</width>
+ <height>24</height>
</rect>
</property>
<property name="sizePolicy">
</property>
</action>
</widget>
+ <customwidgets>
+ <customwidget>
+ <class>TrIconToolButton</class>
+ <extends>QToolButton</extends>
+ <header>tricontoolbutton.h</header>
+ </customwidget>
+ </customwidgets>
<resources>
<include location="application.qrc"/>
</resources>
+++ /dev/null
-/*
- * 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);
-}