Commit b3170d23 authored by Jens Bache-Wiig's avatar Jens Bache-Wiig
Browse files

New progressbars for the sidebar

parent 72c165fe
...@@ -150,8 +150,8 @@ static void verticalGradientHelper(QPainter *p, const QRect &spanRect, const QRe ...@@ -150,8 +150,8 @@ static void verticalGradientHelper(QPainter *p, const QRect &spanRect, const QRe
QColor highlight = StyleHelper::highlightColor(lightColored); QColor highlight = StyleHelper::highlightColor(lightColored);
QColor shadow = StyleHelper::shadowColor(lightColored); QColor shadow = StyleHelper::shadowColor(lightColored);
QLinearGradient grad(spanRect.topRight(), spanRect.topLeft()); QLinearGradient grad(spanRect.topRight(), spanRect.topLeft());
grad.setColorAt(0, highlight.lighter(106)); grad.setColorAt(0, highlight.lighter(112));
grad.setColorAt(1, shadow.darker(106)); grad.setColorAt(1, shadow.darker(109));
p->fillRect(rect, grad); p->fillRect(rect, grad);
QColor light(255, 255, 255, 80); QColor light(255, 255, 255, 80);
......
...@@ -44,5 +44,6 @@ ...@@ -44,5 +44,6 @@
<file>images/extension.png</file> <file>images/extension.png</file>
<file>images/darkclosebutton.png</file> <file>images/darkclosebutton.png</file>
<file>editormanager/BinFiles.mimetypes.xml</file> <file>editormanager/BinFiles.mimetypes.xml</file>
<file>images/progressbar.png</file>
</qresource> </qresource>
</RCC> </RCC>
...@@ -51,7 +51,7 @@ SOURCES += mainwindow.cpp \ ...@@ -51,7 +51,7 @@ SOURCES += mainwindow.cpp \
dialogs/openwithdialog.cpp \ dialogs/openwithdialog.cpp \
progressmanager/progressmanager.cpp \ progressmanager/progressmanager.cpp \
progressmanager/progressview.cpp \ progressmanager/progressview.cpp \
progressmanager/progresspie.cpp \ progressmanager/progressbar.cpp \
progressmanager/futureprogress.cpp \ progressmanager/futureprogress.cpp \
scriptmanager/scriptmanager.cpp \ scriptmanager/scriptmanager.cpp \
scriptmanager/qworkbench_wrapper.cpp \ scriptmanager/qworkbench_wrapper.cpp \
...@@ -119,7 +119,7 @@ HEADERS += mainwindow.h \ ...@@ -119,7 +119,7 @@ HEADERS += mainwindow.h \
dialogs/ioptionspage.h \ dialogs/ioptionspage.h \
progressmanager/progressmanager_p.h \ progressmanager/progressmanager_p.h \
progressmanager/progressview.h \ progressmanager/progressview.h \
progressmanager/progresspie.h \ progressmanager/progressbar.h \
progressmanager/futureprogress.h \ progressmanager/futureprogress.h \
progressmanager/progressmanager.h \ progressmanager/progressmanager.h \
icontext.h \ icontext.h \
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
**************************************************************************/ **************************************************************************/
#include "futureprogress.h" #include "futureprogress.h"
#include "progresspie.h" #include "progressbar.h"
#include <QtGui/QColor> #include <QtGui/QColor>
#include <QtGui/QVBoxLayout> #include <QtGui/QVBoxLayout>
...@@ -86,7 +86,7 @@ FutureProgress::FutureProgress(QWidget *parent) ...@@ -86,7 +86,7 @@ FutureProgress::FutureProgress(QWidget *parent)
layout->setMargin(0); layout->setMargin(0);
layout->setSpacing(0); layout->setSpacing(0);
layout->addLayout(m_widgetLayout); layout->addLayout(m_widgetLayout);
m_widgetLayout->setContentsMargins(7, 0, 7, 0); m_widgetLayout->setContentsMargins(7, 0, 7, 2);
m_widgetLayout->setSpacing(0); m_widgetLayout->setSpacing(0);
connect(&m_watcher, SIGNAL(started()), this, SLOT(setStarted())); connect(&m_watcher, SIGNAL(started()), this, SLOT(setStarted()));
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
** **
**************************************************************************/ **************************************************************************/
#include "progresspie.h" #include "progressbar.h"
#include <utils/stylehelper.h> #include <utils/stylehelper.h>
...@@ -36,7 +36,9 @@ ...@@ -36,7 +36,9 @@
#include <QtGui/QBrush> #include <QtGui/QBrush>
#include <QtGui/QColor> #include <QtGui/QColor>
#include <QtDebug> #include <QtDebug>
#define PROGRESSBAR_HEIGHT 11
#define PROGRESSBAR_HEIGHT 13
#define CANCEL_WIDTH 12
ProgressBar::ProgressBar(QWidget *parent) ProgressBar::ProgressBar(QWidget *parent)
: QWidget(parent), m_error(false), m_minimum(1), m_maximum(100), m_value(1) : QWidget(parent), m_error(false), m_minimum(1), m_maximum(100), m_value(1)
...@@ -101,11 +103,11 @@ QSize ProgressBar::sizeHint() const ...@@ -101,11 +103,11 @@ QSize ProgressBar::sizeHint() const
{ {
QSize s; QSize s;
s.setWidth(50); s.setWidth(50);
s.setHeight(fontMetrics().height() + PROGRESSBAR_HEIGHT + 7); s.setHeight(fontMetrics().height() + PROGRESSBAR_HEIGHT + 9);
return s; return s;
} }
namespace { const int INDENT = 7; } namespace { const int INDENT = 6; }
void ProgressBar::mousePressEvent(QMouseEvent *event) void ProgressBar::mousePressEvent(QMouseEvent *event)
{ {
...@@ -128,6 +130,9 @@ void ProgressBar::paintEvent(QPaintEvent *) ...@@ -128,6 +130,9 @@ void ProgressBar::paintEvent(QPaintEvent *)
// TODO move font into Utils::StyleHelper // TODO move font into Utils::StyleHelper
// TODO use Utils::StyleHelper white // TODO use Utils::StyleHelper white
if (bar.isNull())
bar.load(QLatin1String(":/core/images/progressbar.png"));
double range = maximum() - minimum(); double range = maximum() - minimum();
double percent = 0.50; double percent = 0.50;
if (range != 0) if (range != 0)
...@@ -152,29 +157,37 @@ void ProgressBar::paintEvent(QPaintEvent *) ...@@ -152,29 +157,37 @@ void ProgressBar::paintEvent(QPaintEvent *)
p.setPen(Utils::StyleHelper::sidebarHighlight()); p.setPen(Utils::StyleHelper::sidebarHighlight());
p.drawLine(1, 1, size().width(), 1); p.drawLine(1, 1, size().width(), 1);
QRect textRect = rect().adjusted(0, 0, -1, 0); QRect textBounds = fontMetrics().boundingRect(m_title);
textBounds.moveCenter(rect().center());
int alignment = Qt::AlignHCenter;
// If there is not enough room when centered, we left align the text
if (value() < maximum() && !m_error && textBounds.right() > rect().right() - CANCEL_WIDTH)
alignment = Qt::AlignLeft;
QRect textRect = rect().adjusted(INDENT + 1, 1, -INDENT - 1, 0);
textRect.setHeight(h+5); textRect.setHeight(h+5);
p.setPen(QColor(30, 30, 30, 80)); p.setPen(QColor(30, 30, 30, 80));
p.drawText(textRect, Qt::AlignHCenter | Qt::AlignBottom, m_title); p.drawText(textRect, alignment | Qt::AlignBottom, m_title);
p.translate(0, -1); p.translate(0, -1);
p.setPen(Utils::StyleHelper::panelTextColor()); p.setPen(Utils::StyleHelper::panelTextColor());
p.drawText(textRect, Qt::AlignHCenter | Qt::AlignBottom, m_title); p.drawText(textRect, alignment | Qt::AlignBottom, m_title);
p.translate(0, 1); p.translate(0, 1);
m_progressHeight = PROGRESSBAR_HEIGHT; m_progressHeight = PROGRESSBAR_HEIGHT;
m_progressHeight += ((m_progressHeight % 2) + 1) % 2; // make odd m_progressHeight += ((m_progressHeight % 2) + 1) % 2; // make odd
// draw outer rect // draw outer rect
QRect rect(INDENT - 1, h+6, size().width()-2*INDENT, m_progressHeight-1); QRect rect(INDENT - 1, h+8, size().width()-2*INDENT + 1, m_progressHeight-1);
p.setPen(Utils::StyleHelper::panelTextColor()); p.setPen(Utils::StyleHelper::panelTextColor());
p.drawRect(rect); Utils::StyleHelper::drawCornerImage(bar, &p, rect, 2, 2, 2, 2);
// draw inner rect // draw inner rect
QColor c = Utils::StyleHelper::panelTextColor(); QColor c = Utils::StyleHelper::panelTextColor();
c.setAlpha(180); c.setAlpha(180);
p.setPen(Qt::NoPen); p.setPen(Qt::NoPen);
QRect inner = rect.adjusted(2, 2, -1, -1); QRect inner = rect.adjusted(3, 2, -2, -2);
inner.adjust(0, 0, qRound((percent - 1) * inner.width()), 0); inner.adjust(0, 0, qRound((percent - 1) * inner.width()), 0);
if (m_error) { if (m_error) {
QColor red(255, 60, 0, 210); QColor red(255, 60, 0, 210);
...@@ -183,35 +196,45 @@ void ProgressBar::paintEvent(QPaintEvent *) ...@@ -183,35 +196,45 @@ void ProgressBar::paintEvent(QPaintEvent *)
if (inner.width() < 10) if (inner.width() < 10)
inner.adjust(0, 0, 10 - inner.width(), 0); inner.adjust(0, 0, 10 - inner.width(), 0);
} else if (value() == maximum()) { } else if (value() == maximum()) {
c = QColor(120, 245, 90, 180); c = QColor(90, 170, 60);
} }
// Draw line and shadow after the gradient fill
if (value() > 0 && value() < maximum()) {
p.fillRect(QRect(inner.right() + 1, inner.top(), 2, inner.height()), QColor(0, 0, 0, 20));
p.fillRect(QRect(inner.right() + 1, inner.top(), 1, inner.height()), QColor(0, 0, 0, 60));
}
QLinearGradient grad(inner.topLeft(), inner.bottomLeft()); QLinearGradient grad(inner.topLeft(), inner.bottomLeft());
grad.setColorAt(0, c.lighter(114)); grad.setColorAt(0, c.lighter(130));
grad.setColorAt(0.5, c.lighter(104)); grad.setColorAt(0.5, c.lighter(106));
grad.setColorAt(0.51, c.darker(108)); grad.setColorAt(0.51, c.darker(106));
grad.setColorAt(1, c.darker(120)); grad.setColorAt(1, c.darker(130));
p.setPen(Qt::NoPen);
p.setBrush(grad); p.setBrush(grad);
p.drawRect(inner); p.drawRect(inner);
p.setBrush(Qt::NoBrush);
p.setPen(QPen(QColor(0, 0, 0, 60), 1));
p.drawLine(inner.topLeft(), inner.topRight());
p.drawLine(inner.topLeft(), inner.bottomLeft());
p.drawLine(inner.topRight(), inner.bottomRight());
p.drawPoint(inner.bottomLeft());
p.drawPoint(inner.bottomRight());
// Draw cancel button
if (value() < maximum() && !m_error) { if (value() < maximum() && !m_error) {
QColor cancelOutline = Utils::StyleHelper::panelTextColor(); QRect parentRect = parentWidget()->rect(); // ### Move to parent
p.setPen(cancelOutline); QRect cancelRect(parentRect.right() - CANCEL_WIDTH - 2,
QRect cancelRect(rect.right() - m_progressHeight + 2, rect.top(), m_progressHeight-1, rect.height()); parentRect.top() + 5, CANCEL_WIDTH, CANCEL_WIDTH);
if (cancelRect.contains(mapFromGlobal(QCursor::pos())))
p.setBrush(QColor(230, 90, 40, 190)); bool hover = cancelRect.contains(mapFromGlobal(QCursor::pos()));
else p.setPen(QPen(QColor(0, 0, 0, 20), 4));
p.setBrush(Qt::NoBrush); p.drawLine(cancelRect.center()+QPoint(-2,-2), cancelRect.center()+QPoint(+4,+4));
p.drawLine(cancelRect.center()+QPoint(+4,-2), cancelRect.center()+QPoint(-2,+4));
p.drawRect(cancelRect);
p.setPen(QPen(hover ? Utils::StyleHelper::panelTextColor() : QColor(200, 200, 200), 1));
p.setPen(QPen(QColor(0, 0, 0, 70), 3)); p.setRenderHint(QPainter::Antialiasing);
p.drawLine(cancelRect.center()+QPoint(-1,-1), cancelRect.center()+QPoint(+3,+3)); p.translate(0.5, 0.5);
p.drawLine(cancelRect.center()+QPoint(+3,-1), cancelRect.center()+QPoint(-1,+3)); p.drawLine(cancelRect.center()+QPoint(-2,-2), cancelRect.center()+QPoint(+4,+4));
p.drawLine(cancelRect.center()+QPoint(+4,-2), cancelRect.center()+QPoint(-2,+4));
p.setPen(Utils::StyleHelper::panelTextColor());
p.drawLine(cancelRect.center()+QPoint(-1,-1), cancelRect.center()+QPoint(+3,+3));
p.drawLine(cancelRect.center()+QPoint(+3,-1), cancelRect.center()+QPoint(-1,+3));
} }
} }
...@@ -64,6 +64,7 @@ protected: ...@@ -64,6 +64,7 @@ protected:
void mousePressEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event);
private: private:
QImage bar;
QString m_text; QString m_text;
QString m_title; QString m_title;
bool m_error; bool m_error;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment