From 6ed565a06b94b3a87817c07e6fb76da73ec6bd91 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sat, 13 Oct 2007 08:32:31 +0000 Subject: [PATCH] - COSMETIC: Improved progress bar text rendering --- TODO | 5 ++- src/DLListDelegate.h | 5 +-- src/FinishedListDelegate.h | 5 +-- src/PreviewListDelegate.h | 5 +-- src/PropListDelegate.h | 5 +-- src/bittorrent.cpp | 3 +- src/main.cpp | 4 +- src/options_imp.cpp | 4 +- src/qgnomelook.h | 87 ++++++++++++++++++++++++++++++++++++++ src/src.pro | 2 +- 10 files changed, 100 insertions(+), 25 deletions(-) create mode 100644 src/qgnomelook.h diff --git a/TODO b/TODO index 309e456d9..477b28390 100644 --- a/TODO +++ b/TODO @@ -56,7 +56,7 @@ - Translations update (IN PROGRESS) - add qt4-qtconfig as package dependency RC5 -- wait for Ticket #182 Fix +- Make use of this: added option to delete files from disk as a torrent is removed (libtorrent) rc4->rc5 changelog: - BUGFIX: Now filtered don't appear on hard drive anymore (libtorrent >= r1659) @@ -65,4 +65,5 @@ rc4->rc5 changelog: - BUGFIX: Fixed possible overflow in ETA calculation - BUGFIX: Fixed "Missing Input path" error when creating a torrent - BUGFIX: Fixed some notification messages for torrent addition dialog -- BUGFIX: Fixed "Automatically start seeding" feature in torrent creation tool \ No newline at end of file +- BUGFIX: Fixed "Automatically start seeding" feature in torrent creation tool +- COSMETIC: Improved progress bar text rendering \ No newline at end of file diff --git a/src/DLListDelegate.h b/src/DLListDelegate.h index 7125f15ab..a019fc22e 100644 --- a/src/DLListDelegate.h +++ b/src/DLListDelegate.h @@ -83,12 +83,9 @@ class DLListDelegate: public QItemDelegate { newopt.maximum = 100; newopt.minimum = 0; newopt.state |= QStyle::State_Enabled; - newopt.textVisible = false; + newopt.textVisible = true; QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter); - QPalette::ColorGroup cg = opt.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled; - painter->setPen(opt.palette.color(cg, QPalette::WindowText)); - painter->drawText(opt.rect, Qt::AlignCenter, newopt.text); break; } default: diff --git a/src/FinishedListDelegate.h b/src/FinishedListDelegate.h index d5074966e..09bf12345 100644 --- a/src/FinishedListDelegate.h +++ b/src/FinishedListDelegate.h @@ -76,12 +76,9 @@ class FinishedListDelegate: public QItemDelegate { newopt.maximum = 100; newopt.minimum = 0; newopt.state |= QStyle::State_Enabled; - newopt.textVisible = false; + newopt.textVisible = true; QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter); - QPalette::ColorGroup cg = opt.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled; - painter->setPen(opt.palette.color(cg, QPalette::WindowText)); - painter->drawText(opt.rect, Qt::AlignCenter, newopt.text); break; } default: diff --git a/src/PreviewListDelegate.h b/src/PreviewListDelegate.h index 96fc0086c..8df80b69b 100644 --- a/src/PreviewListDelegate.h +++ b/src/PreviewListDelegate.h @@ -61,11 +61,8 @@ class PreviewListDelegate: public QItemDelegate { newopt.maximum = 100; newopt.minimum = 0; newopt.state |= QStyle::State_Enabled; - newopt.textVisible = false; + newopt.textVisible = true; QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter); - QPalette::ColorGroup cg = opt.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled; - painter->setPen(opt.palette.color(cg, QPalette::WindowText)); - painter->drawText(opt.rect, Qt::AlignCenter, newopt.text); break; } default: diff --git a/src/PropListDelegate.h b/src/PropListDelegate.h index c2759d2ea..adf81daef 100644 --- a/src/PropListDelegate.h +++ b/src/PropListDelegate.h @@ -75,11 +75,8 @@ class PropListDelegate: public QItemDelegate { newopt.maximum = 100; newopt.minimum = 0; newopt.state |= QStyle::State_Enabled; - newopt.textVisible = false; + newopt.textVisible = true; QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter); - QPalette::ColorGroup cg = opt.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled; - painter->setPen(opt.palette.color(cg, QPalette::WindowText)); - painter->drawText(opt.rect, Qt::AlignCenter, newopt.text); break; } case PRIORITY:{ diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 7eaebc8c8..b055ff7a5 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -1138,8 +1138,7 @@ void bittorrent::readAlerts() { QTorrentHandle h(p->handle); if(h.is_valid()){ qDebug("/!\\ Fast resume failed for %s, reason: %s", h.name().toUtf8().data(), p->msg().c_str()); - // TODO: uncomment this when #182 in libtorrent is fixed - //emit fastResumeDataRejected(h.name()); + emit fastResumeDataRejected(h.name()); } } else if (url_seed_alert* p = dynamic_cast(a.get())) { diff --git a/src/main.cpp b/src/main.cpp index 49001f0fc..4250ac527 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,7 +29,7 @@ #include #include #include -#include +#include "qgnomelook.h" #include #include #ifdef Q_WS_WIN @@ -50,7 +50,7 @@ void useStyle(QApplication *app, int style){ app->setStyle(new QPlastiqueStyle()); break; case 2: - app->setStyle(new QCleanlooksStyle()); + app->setStyle(new QGnomeLookStyle()); break; case 3: app->setStyle(new QMotifStyle()); diff --git a/src/options_imp.cpp b/src/options_imp.cpp index fe2d581bd..6bb252db3 100644 --- a/src/options_imp.cpp +++ b/src/options_imp.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include "qgnomelook.h" #include #include #include @@ -222,7 +222,7 @@ void options_imp::useStyle(){ QApplication::setStyle(new QPlastiqueStyle()); break; case 2: - QApplication::setStyle(new QCleanlooksStyle()); + QApplication::setStyle(new QGnomeLookStyle()); break; case 3: QApplication::setStyle(new QMotifStyle()); diff --git a/src/qgnomelook.h b/src/qgnomelook.h new file mode 100644 index 000000000..8700d410d --- /dev/null +++ b/src/qgnomelook.h @@ -0,0 +1,87 @@ +/* + * Bittorrent Client using Qt4 and libtorrent. + * Copyright (C) 2006 Christophe Dumez + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contact : chris@qbittorrent.org + */ + +#ifndef QGNOMELOOK +#define QGNOMELOOK + +#include +#include +#include +#include +#include +#include + +class QGnomeLookStyle : public QCleanlooksStyle { + public: + QGnomeLookStyle() : QCleanlooksStyle() {} + + void drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const { + switch(element) { + case CE_ProgressBarLabel: + if (const QStyleOptionProgressBar *pb = qstyleoption_cast(option)) { + bool vertical = false; + if (const QStyleOptionProgressBarV2 *pb2 = qstyleoption_cast(option)) { + vertical = (pb2->orientation == Qt::Vertical); + } + if (!vertical) { + QPalette::ColorRole textRole = QPalette::Dark;/* + if ((pb->textAlignment & Qt::AlignCenter) && pb->textVisible + && ((qint64(pb->progress) - qint64(pb->minimum)) * 2 >= (qint64(pb->maximum) - qint64(pb->minimum)))) { + textRole = QPalette::HighlightedText; + //Draw text shadow, This will increase readability when the background of same color + QRect shadowRect(pb->rect); + shadowRect.translate(1,1); + QColor shadowColor = (pb->palette.color(textRole).value() <= 128) ? QColor(255,255,255,160) : QColor(0,0,0,160); + QPalette shadowPalette = pb->palette; + shadowPalette.setColor(textRole, shadowColor); + drawItemText(painter, shadowRect, Qt::AlignCenter | Qt::TextSingleLine, shadowPalette, pb->state, pb->text, textRole); + } + QPalette shadowPalette = pb->palette; + shadowPalette.setColor(textRole, QColor(0,0,0,160));*/ + drawItemText(painter, pb->rect, Qt::AlignCenter | Qt::TextSingleLine, pb->palette, pb->state, pb->text, textRole); + } + } + break; + default: + QCleanlooksStyle::drawControl(element, option, painter, widget); + } + } + + QRect subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget=0) const + { + QRect rect; + switch (element) { +#ifndef QT_NO_PROGRESSBAR + case SE_ProgressBarLabel: + case SE_ProgressBarContents: + case SE_ProgressBarGroove: + return option->rect; +#endif // QT_NO_PROGRESSBAR + default: + return QCleanlooksStyle::subElementRect(element, option, widget); + } + + return visualRect(option->direction, option->rect, rect); + } + +}; + +#endif diff --git a/src/src.pro b/src/src.pro index 999f74e73..4ff226f88 100644 --- a/src/src.pro +++ b/src/src.pro @@ -142,7 +142,7 @@ HEADERS += GUI.h misc.h options_imp.h about_imp.h \ allocationDlg.h FinishedListDelegate.h \ qtorrenthandle.h downloadingTorrents.h \ engineSelectDlg.h pluginSource.h \ - arborescence.h + arborescence.h qgnomelook.h FORMS += MainWindow.ui options.ui about.ui \ properties.ui createtorrent.ui preview.ui \ login.ui downloadFromURL.ui addTorrentDialog.ui \