From f46e6606793eaf49aae672b842efceedc11133e7 Mon Sep 17 00:00:00 2001 From: Gabriele Date: Sun, 2 Nov 2014 22:44:24 +0100 Subject: [PATCH 1/2] Adjust the size of the elements in the statusbar Use the same height for all the elements and try to prevent variations of the speed labels. --- src/statusbar.cpp | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/statusbar.cpp b/src/statusbar.cpp index 408f2a2bd..20045de4d 100644 --- a/src/statusbar.cpp +++ b/src/statusbar.cpp @@ -55,12 +55,10 @@ StatusBar::StatusBar(QStatusBar *bar) connecStatusLblIcon = new QPushButton(bar); connecStatusLblIcon->setFlat(true); connecStatusLblIcon->setFocusPolicy(Qt::NoFocus); - connecStatusLblIcon->setFixedWidth(32); connecStatusLblIcon->setCursor(Qt::PointingHandCursor); connecStatusLblIcon->setIcon(QIcon(":/Icons/skin/firewalled.png")); connecStatusLblIcon->setToolTip(QString::fromUtf8("")+tr("Connection status:")+QString::fromUtf8("
")+QString::fromUtf8("")+tr("No direct connections. This may indicate network configuration problems.")+QString::fromUtf8("")); dlSpeedLbl = new QPushButton(bar); - dlSpeedLbl->setIconSize(QSize(16,16)); dlSpeedLbl->setIcon(QIcon(":/Icons/skin/download.png")); //dlSpeedLbl->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); connect(dlSpeedLbl, SIGNAL(clicked()), this, SLOT(capDownloadSpeed())); @@ -69,8 +67,6 @@ StatusBar::StatusBar(QStatusBar *bar) dlSpeedLbl->setCursor(Qt::PointingHandCursor); altSpeedsBtn = new QPushButton(bar); - altSpeedsBtn->setFixedWidth(36); - altSpeedsBtn->setIconSize(QSize(32,32)); altSpeedsBtn->setFlat(true); altSpeedsBtn->setFocusPolicy(Qt::NoFocus); altSpeedsBtn->setCursor(Qt::PointingHandCursor); @@ -79,7 +75,6 @@ StatusBar::StatusBar(QStatusBar *bar) connect(altSpeedsBtn, SIGNAL(clicked()), this, SLOT(toggleAlternativeSpeeds())); upSpeedLbl = new QPushButton(bar); - upSpeedLbl->setIconSize(QSize(16,16)); upSpeedLbl->setIcon(QIcon(":/Icons/skin/seeding.png")); //upSpeedLbl->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); connect(upSpeedLbl, SIGNAL(clicked()), this, SLOT(capUploadSpeed())); @@ -88,20 +83,32 @@ StatusBar::StatusBar(QStatusBar *bar) upSpeedLbl->setCursor(Qt::PointingHandCursor); DHTLbl = new QLabel(tr("DHT: %1 nodes").arg(0), bar); DHTLbl->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); + + QRect labelRect = dlSpeedLbl->fontMetrics().boundingRect(" XX 0.000,00 XiX/s (000,0 XiX) "); + if (labelRect.height() < 26) + labelRect.setHeight(26); + dlSpeedLbl->setIconSize(QSize(16,16)); + upSpeedLbl->setIconSize(QSize(16,16)); + connecStatusLblIcon->setFixedHeight(labelRect.height()); + altSpeedsBtn->setIconSize(QSize(30,30)); // cut out blank parts + altSpeedsBtn->setFixedHeight(labelRect.height()); + dlSpeedLbl->setMinimumSize(labelRect.width(), labelRect.height()); + upSpeedLbl->setMinimumSize(labelRect.width(), labelRect.height()); + statusSep1 = new QFrame(bar); - statusSep1->setFixedSize(3, dlSpeedLbl->fontMetrics().height()); + statusSep1->setFixedSize(3, labelRect.height()); statusSep1->setFrameStyle(QFrame::VLine); statusSep1->setFrameShadow(QFrame::Raised); statusSep2 = new QFrame(bar); - statusSep2->setFixedSize(3, dlSpeedLbl->fontMetrics().height()); + statusSep2->setFixedSize(3, labelRect.height()); statusSep2->setFrameStyle(QFrame::VLine); statusSep2->setFrameShadow(QFrame::Raised); statusSep3 = new QFrame(bar); - statusSep3->setFixedSize(3, dlSpeedLbl->fontMetrics().height()); + statusSep3->setFixedSize(3, labelRect.height()); statusSep3->setFrameStyle(QFrame::VLine); statusSep3->setFrameShadow(QFrame::Raised); statusSep4 = new QFrame(bar); - statusSep4->setFixedSize(3, dlSpeedLbl->fontMetrics().height()); + statusSep4->setFixedSize(3, labelRect.height()); statusSep4->setFrameStyle(QFrame::VLine); statusSep4->setFrameShadow(QFrame::Raised); layout->addWidget(DHTLbl); @@ -116,11 +123,9 @@ StatusBar::StatusBar(QStatusBar *bar) bar->addPermanentWidget(container); container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); - //bar->setStyleSheet("QWidget {padding-top: 0; padding-bottom: 0; margin-top: 0; margin-bottom: 0;}\n"); - container->setContentsMargins(0, 0, 0, 1); - bar->setContentsMargins(0, 0, 0, 0); - container->setFixedHeight(dlSpeedLbl->fontMetrics().height()+7); - bar->setFixedHeight(dlSpeedLbl->fontMetrics().height()+9); + bar->setStyleSheet("QWidget {padding: 0; margin: 0;}\n QPushButton {padding: 3px;}\n"); + container->adjustSize(); + bar->adjustSize(); // Is DHT enabled DHTLbl->setVisible(pref->isDHTEnabled()); refreshTimer = new QTimer(bar); From 8cc7a3573eca8d89b855fd98b8447db02124da5b Mon Sep 17 00:00:00 2001 From: Gabriele Date: Tue, 21 Oct 2014 17:00:26 +0100 Subject: [PATCH 2/2] Show current speed limits in the status bar Closes #1316. --- src/statusbar.cpp | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/statusbar.cpp b/src/statusbar.cpp index 20045de4d..6073ed98c 100644 --- a/src/statusbar.cpp +++ b/src/statusbar.cpp @@ -66,14 +66,6 @@ StatusBar::StatusBar(QStatusBar *bar) dlSpeedLbl->setFocusPolicy(Qt::NoFocus); dlSpeedLbl->setCursor(Qt::PointingHandCursor); - altSpeedsBtn = new QPushButton(bar); - altSpeedsBtn->setFlat(true); - altSpeedsBtn->setFocusPolicy(Qt::NoFocus); - altSpeedsBtn->setCursor(Qt::PointingHandCursor); - updateAltSpeedsBtn(pref->isAltBandwidthEnabled()); - - connect(altSpeedsBtn, SIGNAL(clicked()), this, SLOT(toggleAlternativeSpeeds())); - upSpeedLbl = new QPushButton(bar); upSpeedLbl->setIcon(QIcon(":/Icons/skin/seeding.png")); //upSpeedLbl->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); @@ -84,7 +76,14 @@ StatusBar::StatusBar(QStatusBar *bar) DHTLbl = new QLabel(tr("DHT: %1 nodes").arg(0), bar); DHTLbl->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); - QRect labelRect = dlSpeedLbl->fontMetrics().boundingRect(" XX 0.000,00 XiX/s (000,0 XiX) "); + altSpeedsBtn = new QPushButton(bar); + altSpeedsBtn->setFlat(true); + altSpeedsBtn->setFocusPolicy(Qt::NoFocus); + altSpeedsBtn->setCursor(Qt::PointingHandCursor); + updateAltSpeedsBtn(pref->isAltBandwidthEnabled()); + connect(altSpeedsBtn, SIGNAL(clicked()), this, SLOT(toggleAlternativeSpeeds())); + + QRect labelRect = dlSpeedLbl->fontMetrics().boundingRect(" XX [0.000,0 XiX/s] 0.000,00 XiX/s (000,0 XiX) "); if (labelRect.height() < 26) labelRect.setHeight(26); dlSpeedLbl->setIconSize(QSize(16,16)); @@ -187,8 +186,16 @@ void StatusBar::refreshStatusBar() { //statusSep1->setVisible(false); } // Update speed labels - dlSpeedLbl->setText(tr("%1/s", "Per second").arg(misc::friendlyUnit(sessionStatus.payload_download_rate))+" ("+misc::friendlyUnit(sessionStatus.total_payload_download)+")"); - upSpeedLbl->setText(tr("%1/s", "Per second").arg(misc::friendlyUnit(sessionStatus.payload_upload_rate))+" ("+misc::friendlyUnit(sessionStatus.total_payload_upload)+")"); + QString speedLbl = misc::friendlyUnit(sessionStatus.payload_download_rate, true)+" ("+misc::friendlyUnit(sessionStatus.total_payload_download)+")"; + int speedLimit = QBtSession::instance()->getSession()->settings().download_rate_limit; + if (speedLimit) + speedLbl = "["+misc::friendlyUnit(speedLimit, true)+"] " + speedLbl; + dlSpeedLbl->setText(speedLbl); + speedLimit = QBtSession::instance()->getSession()->settings().upload_rate_limit; + speedLbl = misc::friendlyUnit(sessionStatus.payload_upload_rate, true)+" ("+misc::friendlyUnit(sessionStatus.total_payload_upload)+")"; + if (speedLimit) + speedLbl = "["+misc::friendlyUnit(speedLimit, true)+"] " + speedLbl; + upSpeedLbl->setText(speedLbl); } void StatusBar::updateAltSpeedsBtn(bool alternative) { @@ -201,6 +208,7 @@ void StatusBar::updateAltSpeedsBtn(bool alternative) { altSpeedsBtn->setToolTip(tr("Click to switch to alternative speed limits")); altSpeedsBtn->setDown(false); } + refreshStatusBar(); } void StatusBar::toggleAlternativeSpeeds() { @@ -230,6 +238,7 @@ void StatusBar::capDownloadSpeed() { if (!alt) pref->setGlobalDownloadLimit(new_limit/1024.); } + refreshStatusBar(); } } @@ -251,5 +260,6 @@ void StatusBar::capUploadSpeed() { if (!alt) Preferences::instance()->setGlobalUploadLimit(new_limit/1024.); } + refreshStatusBar(); } }