From 81fcc83bdcafc49372047fb1210f5fece8f12e53 Mon Sep 17 00:00:00 2001 From: defnax Date: Thu, 7 Feb 2008 16:36:30 +0000 Subject: [PATCH] added new xProgressBar, thanks to xesk git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@338 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/RetroShare.pro | 2 + retroshare-gui/src/gui/DLListDelegate.cpp | 24 +-- retroshare-gui/src/gui/DLListDelegate.h | 4 +- retroshare-gui/src/gui/HelpDialog.ui | 159 +++++++++++++---- retroshare-gui/src/gui/xprogressbar.cpp | 200 ++++++++++++++++++++++ retroshare-gui/src/gui/xprogressbar.h | 67 ++++++++ 6 files changed, 405 insertions(+), 51 deletions(-) create mode 100644 retroshare-gui/src/gui/xprogressbar.cpp create mode 100644 retroshare-gui/src/gui/xprogressbar.h diff --git a/retroshare-gui/src/RetroShare.pro b/retroshare-gui/src/RetroShare.pro index 0dd1cfd70..2a319892e 100644 --- a/retroshare-gui/src/RetroShare.pro +++ b/retroshare-gui/src/RetroShare.pro @@ -68,6 +68,7 @@ HEADERS += rshare.h \ gui/StatisticDialog.h \ gui/HelpDialog.h \ gui/LogoBar.h \ + gui/xprogressbar.h \ lang/languagesupport.h \ util/process.h \ util/registry.h \ @@ -218,6 +219,7 @@ SOURCES += main.cpp \ gui/MessagesDialog.cpp \ gui/HelpDialog.cpp \ gui/LogoBar.cpp \ + gui/xprogressbar.cpp \ lang/languagesupport.cpp \ util/process.cpp \ util/registry.cpp \ diff --git a/retroshare-gui/src/gui/DLListDelegate.cpp b/retroshare-gui/src/gui/DLListDelegate.cpp index ef9f2cf08..40588e463 100644 --- a/retroshare-gui/src/gui/DLListDelegate.cpp +++ b/retroshare-gui/src/gui/DLListDelegate.cpp @@ -145,25 +145,17 @@ void DLListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti painter->drawText(option.rect, Qt::AlignRight, temp); break; case PROGRESS: + { progress = index.data().toDouble(); - temp.clear(); - temp.sprintf("%.2f", progress); - temp += "%"; - newopt.rect = opt.rect; - //newopt.text = temp; - newopt.maximum = 100; - newopt.minimum = 0; - newopt.progress = (int)progress; - newopt.state |= QStyle::State_Enabled; - newopt.textVisible = false; - QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, - painter); - //We prefer to display text manually to control color/font/boldness - if (option.state & QStyle::State_Selected){ - opt.palette.setColor(QPalette::Text, QColor("grey")); - painter->setPen(opt.palette.color(cg, QPalette::Text)); + // create a xProgressBar + xProgressBar progressBar(option.rect, painter); // the 3rd param is the color schema (0 is the default value) + progressBar.setDisplayText(false); // should display % text? + progressBar.setValue(progress); // set the progress value + progressBar.setVerticalSpan(1); + progressBar.paint(); // paint the progress bar } painter->drawText(option.rect, Qt::AlignCenter, newopt.text); + painter->drawText(option.rect, Qt::AlignCenter, newopt.text); break; case NAME: // decoration diff --git a/retroshare-gui/src/gui/DLListDelegate.h b/retroshare-gui/src/gui/DLListDelegate.h index a5dfff2e5..26044334c 100644 --- a/retroshare-gui/src/gui/DLListDelegate.h +++ b/retroshare-gui/src/gui/DLListDelegate.h @@ -1,7 +1,7 @@ /**************************************************************** * RetroShare is distributed under the following license: * - * Copyright (C) 2006,2007 crypton + * Copyright (C) 2006,2007,2008 crypton * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -23,6 +23,8 @@ #define DLLISTDELEGATE_H #include +#include "xprogressbar.h" + // Defines for download list list columns #define NAME 0 diff --git a/retroshare-gui/src/gui/HelpDialog.ui b/retroshare-gui/src/gui/HelpDialog.ui index 13f084104..013416111 100644 --- a/retroshare-gui/src/gui/HelpDialog.ui +++ b/retroshare-gui/src/gui/HelpDialog.ui @@ -10,9 +10,7 @@ - - 7 - 7 + 0 0 @@ -501,10 +499,22 @@ Qt::NoContextMenu - + 0 - + + 0 + + + 0 + + + 0 + + + 0 + + 0 @@ -517,10 +527,22 @@ About - + 9 - + + 9 + + + 9 + + + 9 + + + 6 + + 6 @@ -541,12 +563,12 @@ <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Arial'; font-size:8pt; font-weight:400; font-style:normal; text-decoration:none;"> +</style></head><body style=" font-family:'Arial'; font-size:8pt; font-weight:400; font-style:normal;"> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="http://retroshare.wiki.sourceforge.net/help_tab"><span style=" text-decoration: underline; color:#0000ff;">This Page in the retroshare Wiki</span></a><br /><br />The About/Help Tab is regularly updated from the Wiki page.<br /><br />External Links to more information:<br /></p> -<ul style="-qt-list-indent: 1;"><li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="http://retroshare.sourceforge.net"><span style=" text-decoration: underline; color:#0000ff;">Retroshare Webpage</span></a></li> -<li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="http://retroshare.wiki.sourceforge.net/"><span style=" text-decoration: underline; color:#0000ff;">Retroshare Wiki</span></a></li> -<li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="http://sourceforge.net/projects/retroshare/"><span style=" text-decoration: underline; color:#0000ff;">Retroshare Project Page</span></a></li> -<li style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="http://www.lunamutt.com"><span style=" text-decoration: underline; color:#0000ff;">Lunamutt Homepage.</span></a></li></ul></body></html> +<ul style="-qt-list-indent: 1;"><li style="" style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="http://retroshare.sourceforge.net"><span style=" text-decoration: underline; color:#0000ff;">Retroshare Webpage</span></a></li> +<li style="" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="http://retroshare.wiki.sourceforge.net/"><span style=" text-decoration: underline; color:#0000ff;">Retroshare Wiki</span></a></li> +<li style="" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="http://sourceforge.net/projects/retroshare/"><span style=" text-decoration: underline; color:#0000ff;">Retroshare Project Page</span></a></li> +<li style="" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="http://www.lunamutt.com"><span style=" text-decoration: underline; color:#0000ff;">Lunamutt Homepage.</span></a></li></ul></body></html> true @@ -581,12 +603,21 @@ p, li { white-space: pre-wrap; } Authors - - 9 - 6 + + 9 + + + 9 + + + 9 + + + 9 + @@ -601,7 +632,7 @@ p, li { white-space: pre-wrap; } <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Arial'; font-size:8pt; font-weight:400; font-style:normal; text-decoration:none;"> +</style></head><body style=" font-family:'Arial'; font-size:8pt; font-weight:400; font-style:normal;"> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /><span style=" font-size:19pt; font-weight:600; color:#0000ff;">The RetroShare Team:</span><br /> <br /><span style=" font-size:9pt; color:#0000ff;">defnax</span>: Lead GUI developer <br /><span style=" font-size:9pt; color:#0000ff;">drbob7</span>: Lead Core developer. <br /> <br /><span style=" font-size:9pt; color:#0000ff;">bmeck</span> : Our new web-developer. Joined retroshare a couple <br />of weeks ago, and already starting on an exciting new <br />design for the web-page. <br /> <br /><span style=" font-size:9pt; color:#0000ff;">noragen</span> : Developer from the SIM-IM project. Working on a retroshare plugin to SIM-IM. <br /></p> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:9pt; color:#0000ff;">kernelpanix</span> : Gui and skin developer</p> <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"></p> @@ -618,7 +649,7 @@ p, li { white-space: pre-wrap; } false - Qt::TextBrowserInteraction + Qt::TextBrowserInteraction @@ -629,12 +660,21 @@ p, li { white-space: pre-wrap; } Thanks to - - 9 - 6 + + 9 + + + 9 + + + 9 + + + 9 + @@ -646,11 +686,20 @@ p, li { white-space: pre-wrap; } true + + <html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Arial'; font-size:8pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Sans Serif'; font-size:10pt; font-weight:600;">xEsk</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:9pt;"> xProgressBar: A custom progress bar for Qt 4.</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:9pt;"> xEsk (Xesc &amp; Technology 2008)</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:9pt;"> ProgressBar</p></body></html> + false - Qt::TextBrowserInteraction + Qt::TextBrowserInteraction @@ -661,12 +710,21 @@ p, li { white-space: pre-wrap; } Translation - - 9 - 6 + + 9 + + + 9 + + + 9 + + + 9 + @@ -678,7 +736,7 @@ p, li { white-space: pre-wrap; } <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Arial'; font-size:8pt; font-weight:400; font-style:normal; text-decoration:none;"> +</style></head><body style=" font-family:'Arial'; font-size:8pt; font-weight:400; font-style:normal;"> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Translators:</span></p> <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"></p> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">French</span>:Temet</p> @@ -690,7 +748,7 @@ p, li { white-space: pre-wrap; } false - Qt::TextSelectableByMouse + Qt::TextSelectableByMouse @@ -701,12 +759,21 @@ p, li { white-space: pre-wrap; } License Agreement - - 9 - 6 + + 9 + + + 9 + + + 9 + + + 9 + @@ -719,7 +786,7 @@ p, li { white-space: pre-wrap; } false - Qt::TextBrowserInteraction + Qt::TextBrowserInteraction @@ -729,10 +796,22 @@ p, li { white-space: pre-wrap; } - + 0 - + + 0 + + + 0 + + + 0 + + + 0 + + 0 @@ -750,10 +829,22 @@ p, li { white-space: pre-wrap; } - + 0 - + + 0 + + + 0 + + + 0 + + + 6 + + 6 diff --git a/retroshare-gui/src/gui/xprogressbar.cpp b/retroshare-gui/src/gui/xprogressbar.cpp new file mode 100644 index 000000000..c1a944e05 --- /dev/null +++ b/retroshare-gui/src/gui/xprogressbar.cpp @@ -0,0 +1,200 @@ +/* + * xProgressBar: A custom progress bar for Qt 4. + * Author: xEsk (Xesc & Technology 2008) + * + * Changelog: + * + * v1.0: + * ----- + * - First release + * + * 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. + ****************************************************************/ + +#include "xprogressbar.h" + +xProgressBar::xProgressBar(QRect rect, QPainter *painter, int schemaIndex) +{ + // assign internal data + this->schemaIndex = schemaIndex; + this->rect = rect; + this->painter = painter; + this->progressValue = 0.00; + // set the progress bar colors + setColor(); + // configure span + vSpan = 0; + hSpan = 0; + // text color + textColor = QColor("white"); +} + +void xProgressBar::setColor() +{ + /* TEMPORAL SCHEMA DEFINITION */ + + switch (schemaIndex) + { + /* blue schema */ + case 0: + // background + backgroundBorderColor.setRgb(143, 180, 219); + backgroundColor.setRgb(198, 209, 221); + // progress + gradBorderColor.setRgb(35, 96, 167); + gradColor1.setRgb(100, 136, 252); + gradColor2.setRgb(165, 183, 240); + // ok + break; + + /* green schema */ + case 1: + // background + backgroundBorderColor.setRgb(3, 194, 26); + backgroundColor.setRgb(76, 214, 93); + // progress + gradBorderColor.setRgb(8, 77, 16); + gradColor1.setRgb(0, 137, 16); + gradColor2.setRgb(78, 194, 81); + // ok + break; + + /* red schema */ + case 2: + // background + backgroundBorderColor.setRgb(255, 62, 62); + backgroundColor.setRgb(248, 175, 175); + // progress + gradBorderColor.setRgb(151, 0, 0); + gradColor1.setRgb(251, 54, 54); + gradColor2.setRgb(246, 118, 118); + // ok + break; + + /* gray schema */ + case 3: + // background + backgroundBorderColor.setRgb(116, 177, 160); + backgroundColor.setRgb(178, 215, 205); + // progress + gradBorderColor.setRgb(106, 106, 106); + gradColor1.setRgb(168, 168, 168); + gradColor2.setRgb(197, 197, 197); + // ok + break; + + /* yellow schema */ + case 4: + // background + backgroundBorderColor.setRgb(227, 204, 79); + backgroundColor.setRgb(255, 236, 130); + // progress + gradBorderColor.setRgb(215, 182, 0); + gradColor1.setRgb(233, 197, 0); + gradColor2.setRgb(255, 236, 130); + // ok + break; + + /* black schema */ + case 5: + // background + backgroundBorderColor.setRgb(99, 99, 99); + backgroundColor.setRgb(134, 134, 134); + // progress + gradBorderColor.setRgb(0, 0, 0); + gradColor1.setRgb(38, 38, 38); + gradColor2.setRgb(113, 113, 113); + // ok + break; + + /* purple schema */ + case 6: + // background + backgroundBorderColor.setRgb(234, 127, 223); + backgroundColor.setRgb(255, 164, 246); + // progress + gradBorderColor.setRgb(150, 0, 134); + gradColor1.setRgb(218, 0, 195); + gradColor2.setRgb(255, 121, 241); + // ok + break; + + /* maroon schema */ + case 7: + // background + backgroundBorderColor.setRgb(255, 174, 49); + backgroundColor.setRgb(255, 204, 132); + // progress + gradBorderColor.setRgb(159, 94, 0); + gradColor1.setRgb(223, 134, 6); + gradColor2.setRgb(248, 170, 59); + // ok + break; + } +} + +void xProgressBar::paint() +{ + // paint the progressBar background + painter->setBrush(backgroundColor); + painter->setPen(backgroundBorderColor); + painter->drawRect(rect.x() + hSpan, rect.y() + vSpan, rect.width() - 1 - hSpan, rect.height() - 1 - vSpan * 2); + + // define gradient + QLinearGradient linearGrad(rect.x(), rect.y(), rect.x(), rect.y() + rect.height() - 1); + + linearGrad.setColorAt(0.00, gradColor1); + linearGrad.setColorAt(0.16, gradColor2); + linearGrad.setColorAt(1.00, gradColor1); + painter->setPen(gradBorderColor); + + // calculate progress value + int preWidth = static_cast((rect.width() - 1 - hSpan)*(progressValue/100)); + int progressWidth = rect.width() - preWidth; + if (progressWidth == rect.width() - hSpan) return; + + // paint the progress + painter->setBrush(linearGrad); + painter->drawRect(rect.x() + hSpan, rect.y() + vSpan, rect.width() - progressWidth - hSpan, rect.height() - 1 - vSpan * 2); + + // paint text? + if (displayText) + { + QLocale locale; + painter->setPen(textColor); + painter->drawText(rect, Qt::AlignCenter, locale.toString(progressValue, 'f', 2) + "%"); + } +} + +void xProgressBar::setValue(const float value) +{ + progressValue = value < 0 ? 0 : value > 100 ? 100 : value; +} + +void xProgressBar::setDisplayText(const bool display) +{ + displayText = display; +} + +void xProgressBar::setVerticalSpan(const int value) +{ + vSpan = value; +} + +void xProgressBar::setHorizontalSpan(const int value) +{ + hSpan = value; +} diff --git a/retroshare-gui/src/gui/xprogressbar.h b/retroshare-gui/src/gui/xprogressbar.h new file mode 100644 index 000000000..c33c482c7 --- /dev/null +++ b/retroshare-gui/src/gui/xprogressbar.h @@ -0,0 +1,67 @@ +/* + * xProgressBar: A custom progress bar for Qt 4. + * Author: xEsk (Xesc & Technology 2008) + * + * Changelog: + * + * v1.0: + * ----- + * - First release + * + * 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. + ****************************************************************/ + +#ifndef XPROGRESSBAR_H +#define XPROGRESSBAR_H +// +#include +#include +#include +#include +#include +// +class xProgressBar : public QObject +{ +Q_OBJECT + private: + // progress vlues + float progressValue; + int schemaIndex; + bool displayText; + int vSpan; + int hSpan; + // painter config + QRect rect; + QPainter *painter; + // text color + QColor textColor; + // progress colors + QColor backgroundBorderColor; + QColor backgroundColor; + QColor gradBorderColor; + QColor gradColor1; + QColor gradColor2; + // configure the color + void setColor(); + public: + xProgressBar(QRect rect, QPainter *painter, int schemaIndex = 0); + void paint(); + void setValue(const float value); + void setDisplayText(const bool display); + void setVerticalSpan(const int value); + void setHorizontalSpan(const int value); +}; +#endif