Skip to content
Snippets Groups Projects
Commit b3170d23 authored by Jens Bache-Wiig's avatar Jens Bache-Wiig
Browse files

New progressbars for the sidebar

parent 72c165fe
No related branches found
No related tags found
No related merge requests found
......@@ -150,8 +150,8 @@ static void verticalGradientHelper(QPainter *p, const QRect &spanRect, const QRe
QColor highlight = StyleHelper::highlightColor(lightColored);
QColor shadow = StyleHelper::shadowColor(lightColored);
QLinearGradient grad(spanRect.topRight(), spanRect.topLeft());
grad.setColorAt(0, highlight.lighter(106));
grad.setColorAt(1, shadow.darker(106));
grad.setColorAt(0, highlight.lighter(112));
grad.setColorAt(1, shadow.darker(109));
p->fillRect(rect, grad);
QColor light(255, 255, 255, 80);
......
......@@ -44,5 +44,6 @@
<file>images/extension.png</file>
<file>images/darkclosebutton.png</file>
<file>editormanager/BinFiles.mimetypes.xml</file>
<file>images/progressbar.png</file>
</qresource>
</RCC>
......@@ -51,7 +51,7 @@ SOURCES += mainwindow.cpp \
dialogs/openwithdialog.cpp \
progressmanager/progressmanager.cpp \
progressmanager/progressview.cpp \
progressmanager/progresspie.cpp \
progressmanager/progressbar.cpp \
progressmanager/futureprogress.cpp \
scriptmanager/scriptmanager.cpp \
scriptmanager/qworkbench_wrapper.cpp \
......@@ -119,7 +119,7 @@ HEADERS += mainwindow.h \
dialogs/ioptionspage.h \
progressmanager/progressmanager_p.h \
progressmanager/progressview.h \
progressmanager/progresspie.h \
progressmanager/progressbar.h \
progressmanager/futureprogress.h \
progressmanager/progressmanager.h \
icontext.h \
......
src/plugins/coreplugin/images/progressbar.png

420 B

......@@ -28,7 +28,7 @@
**************************************************************************/
#include "futureprogress.h"
#include "progresspie.h"
#include "progressbar.h"
#include <QtGui/QColor>
#include <QtGui/QVBoxLayout>
......@@ -86,7 +86,7 @@ FutureProgress::FutureProgress(QWidget *parent)
layout->setMargin(0);
layout->setSpacing(0);
layout->addLayout(m_widgetLayout);
m_widgetLayout->setContentsMargins(7, 0, 7, 0);
m_widgetLayout->setContentsMargins(7, 0, 7, 2);
m_widgetLayout->setSpacing(0);
connect(&m_watcher, SIGNAL(started()), this, SLOT(setStarted()));
......
......@@ -27,7 +27,7 @@
**
**************************************************************************/
#include "progresspie.h"
#include "progressbar.h"
#include <utils/stylehelper.h>
......@@ -36,7 +36,9 @@
#include <QtGui/QBrush>
#include <QtGui/QColor>
#include <QtDebug>
#define PROGRESSBAR_HEIGHT 11
#define PROGRESSBAR_HEIGHT 13
#define CANCEL_WIDTH 12
ProgressBar::ProgressBar(QWidget *parent)
: QWidget(parent), m_error(false), m_minimum(1), m_maximum(100), m_value(1)
......@@ -101,11 +103,11 @@ QSize ProgressBar::sizeHint() const
{
QSize s;
s.setWidth(50);
s.setHeight(fontMetrics().height() + PROGRESSBAR_HEIGHT + 7);
s.setHeight(fontMetrics().height() + PROGRESSBAR_HEIGHT + 9);
return s;
}
namespace { const int INDENT = 7; }
namespace { const int INDENT = 6; }
void ProgressBar::mousePressEvent(QMouseEvent *event)
{
......@@ -128,6 +130,9 @@ void ProgressBar::paintEvent(QPaintEvent *)
// TODO move font into Utils::StyleHelper
// TODO use Utils::StyleHelper white
if (bar.isNull())
bar.load(QLatin1String(":/core/images/progressbar.png"));
double range = maximum() - minimum();
double percent = 0.50;
if (range != 0)
......@@ -152,29 +157,37 @@ void ProgressBar::paintEvent(QPaintEvent *)
p.setPen(Utils::StyleHelper::sidebarHighlight());
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);
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.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);
m_progressHeight = PROGRESSBAR_HEIGHT;
m_progressHeight += ((m_progressHeight % 2) + 1) % 2; // make odd
// 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.drawRect(rect);
Utils::StyleHelper::drawCornerImage(bar, &p, rect, 2, 2, 2, 2);
// draw inner rect
QColor c = Utils::StyleHelper::panelTextColor();
c.setAlpha(180);
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);
if (m_error) {
QColor red(255, 60, 0, 210);
......@@ -183,35 +196,45 @@ void ProgressBar::paintEvent(QPaintEvent *)
if (inner.width() < 10)
inner.adjust(0, 0, 10 - inner.width(), 0);
} 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());
grad.setColorAt(0, c.lighter(114));
grad.setColorAt(0.5, c.lighter(104));
grad.setColorAt(0.51, c.darker(108));
grad.setColorAt(1, c.darker(120));
grad.setColorAt(0, c.lighter(130));
grad.setColorAt(0.5, c.lighter(106));
grad.setColorAt(0.51, c.darker(106));
grad.setColorAt(1, c.darker(130));
p.setPen(Qt::NoPen);
p.setBrush(grad);
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) {
QColor cancelOutline = Utils::StyleHelper::panelTextColor();
p.setPen(cancelOutline);
QRect cancelRect(rect.right() - m_progressHeight + 2, rect.top(), m_progressHeight-1, rect.height());
if (cancelRect.contains(mapFromGlobal(QCursor::pos())))
p.setBrush(QColor(230, 90, 40, 190));
else
p.setBrush(Qt::NoBrush);
p.drawRect(cancelRect);
p.setPen(QPen(QColor(0, 0, 0, 70), 3));
p.drawLine(cancelRect.center()+QPoint(-1,-1), cancelRect.center()+QPoint(+3,+3));
p.drawLine(cancelRect.center()+QPoint(+3,-1), cancelRect.center()+QPoint(-1,+3));
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));
QRect parentRect = parentWidget()->rect(); // ### Move to parent
QRect cancelRect(parentRect.right() - CANCEL_WIDTH - 2,
parentRect.top() + 5, CANCEL_WIDTH, CANCEL_WIDTH);
bool hover = cancelRect.contains(mapFromGlobal(QCursor::pos()));
p.setPen(QPen(QColor(0, 0, 0, 20), 4));
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(QPen(hover ? Utils::StyleHelper::panelTextColor() : QColor(200, 200, 200), 1));
p.setRenderHint(QPainter::Antialiasing);
p.translate(0.5, 0.5);
p.drawLine(cancelRect.center()+QPoint(-2,-2), cancelRect.center()+QPoint(+4,+4));
p.drawLine(cancelRect.center()+QPoint(+4,-2), cancelRect.center()+QPoint(-2,+4));
}
}
......@@ -64,6 +64,7 @@ protected:
void mousePressEvent(QMouseEvent *event);
private:
QImage bar;
QString m_text;
QString m_title;
bool m_error;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment