Commit b07e5eaf authored by Alessandro Portale's avatar Alessandro Portale

ProgressBar: Make it really flat for flat themes

Change-Id: I3964492e4b07dcba594d5bebc1b74d9458578e88
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
parent c70af100
......@@ -91,7 +91,7 @@ PanelTextColorMid=ffa0a0a0
PanelTextColorLight=text
ProgressBarColorError=error
ProgressBarColorFinished=ff5aaa3c
ProgressBarColorNormal=hoverBackground
ProgressBarColorNormal=ff808080
ProgressBarTitleColor=text
SplitterColor=ff313131
TextColorDisabled=textDisabled
......@@ -168,7 +168,6 @@ ClangCodeModel_Warning_TextMarkColor=ffceff40
ComboBoxDrawTextShadow=false
DerivePaletteFromTheme=true
DrawIndicatorBranch=true
DrawProgressBarSunken=false
DrawSearchResultWidgetFrame=false
DrawTargetSelectorBottom=false
DrawToolBarHighlights=true
......
......@@ -91,9 +91,9 @@ PanelsWidgetSeparatorLineColor=0
PanelTextColorDark=text
PanelTextColorMid=ff666666
PanelTextColorLight=toolBarItem
ProgressBarColorError=error
ProgressBarColorFinished=ff5aaa3c
ProgressBarColorNormal=hoverBackground
ProgressBarColorError=ffdb6f71
ProgressBarColorFinished=dda4d576
ProgressBarColorNormal=ff999999
ProgressBarTitleColor=toolBarItem
SplitterColor=splitter
TextColorDisabled=textDisabled
......@@ -170,7 +170,6 @@ ClangCodeModel_Warning_TextMarkColor=ffc6c132
ComboBoxDrawTextShadow=false
DerivePaletteFromTheme=false
DrawIndicatorBranch=true
DrawProgressBarSunken=false
DrawSearchResultWidgetFrame=false
DrawTargetSelectorBottom=false
DrawToolBarHighlights=false
......
......@@ -162,7 +162,6 @@ ClangCodeModel_Warning_TextMarkColor=ffc6c132
ComboBoxDrawTextShadow=true
DerivePaletteFromTheme=false
DrawIndicatorBranch=false
DrawProgressBarSunken=true
DrawSearchResultWidgetFrame=true
DrawTargetSelectorBottom=true
DrawToolBarHighlights=true
......
......@@ -254,7 +254,6 @@ public:
enum Flag {
DrawTargetSelectorBottom,
DrawSearchResultWidgetFrame,
DrawProgressBarSunken,
DrawIndicatorBranch,
DrawToolBarHighlights,
ComboBoxDrawTextShadow,
......
......@@ -182,11 +182,11 @@ void ProgressBar::setError(bool on)
QSize ProgressBar::sizeHint() const
{
int width = 50;
int height = PROGRESSBAR_HEIGHT + 6;
int height = PROGRESSBAR_HEIGHT + 5;
if (m_titleVisible) {
QFontMetrics fm(titleFont());
width = qMax(width, fm.width(m_title) + 16);
height += fm.height() + 4;
height += fm.height() + 5;
}
if (m_separatorVisible)
height += SEPARATOR_HEIGHT;
......@@ -226,12 +226,9 @@ void ProgressBar::paintEvent(QPaintEvent *)
// TODO move font into Utils::StyleHelper
// TODO use Utils::StyleHelper white
if (bar.isNull())
bar.load(StyleHelper::dpiSpecificImageFile(QLatin1String(":/core/images/progressbar.png")));
double range = maximum() - minimum();
double percent = 0.;
if (range != 0)
if (!qFuzzyIsNull(range))
percent = (value() - minimum()) / range;
if (percent > 1)
percent = 1;
......@@ -282,18 +279,13 @@ void ProgressBar::paintEvent(QPaintEvent *)
m_progressHeight = PROGRESSBAR_HEIGHT;
m_progressHeight += ((m_progressHeight % 2) + 1) % 2; // make odd
// draw outer rect
const QRect rect(INDENT - 1, titleHeight + separatorHeight + (m_titleVisible ? 4 : 3),
const QRect rect(INDENT - 1, titleHeight + separatorHeight + (m_titleVisible ? 5 : 4),
size().width() - 2 * INDENT + 1, m_progressHeight);
if (creatorTheme()->flag(Theme::DrawProgressBarSunken))
StyleHelper::drawCornerImage(bar, &p, rect, 3, 3, 3, 3);
// draw inner rect
QColor c = creatorTheme()->color(Theme::ProgressBarColorNormal);
p.setPen(Qt::NoPen);
QRectF inner = rect.adjusted(2, 2, -2, -2);
inner.adjust(0, 0, qRound((percent - 1) * inner.width()), 0);
QColor c;
if (m_error) {
c = creatorTheme()->color(Theme::ProgressBarColorError);
// avoid too small red bar
......@@ -301,33 +293,42 @@ void ProgressBar::paintEvent(QPaintEvent *)
inner.adjust(0, 0, 10 - inner.width(), 0);
} else if (m_finished) {
c = creatorTheme()->color(Theme::ProgressBarColorFinished);
} else {
c = creatorTheme()->color(Theme::ProgressBarColorNormal);
}
// Draw line and shadow after the gradient fill
if (value() > 0 && value() < maximum()) {
p.fillRect(QRect(inner.right(), inner.top(), 2, inner.height()), QColor(0, 0, 0, 20));
p.fillRect(QRect(inner.right(), inner.top(), 1, inner.height()), QColor(0, 0, 0, 60));
}
p.setPen(Qt::NoPen);
//draw the progress bar
if (creatorTheme()->widgetStyle() == Theme::StyleFlat) {
//draw the progress bar
p.setBrush (c);
p.fillRect(rect.adjusted(2, 2, -2, -2),
creatorTheme()->color(Theme::FancyToolButtonHoverColor));
p.fillRect(inner, c);
} else {
const static QImage bar(StyleHelper::dpiSpecificImageFile(
QLatin1String(":/core/images/progressbar.png")));
StyleHelper::drawCornerImage(bar, &p, rect, 3, 3, 3, 3);
// Draw line and shadow after the gradient fill
if (value() > 0 && value() < maximum()) {
p.fillRect(QRect(inner.right(), inner.top(), 2, inner.height()), QColor(0, 0, 0, 20));
p.fillRect(QRect(inner.right(), inner.top(), 1, inner.height()), QColor(0, 0, 0, 60));
}
QLinearGradient grad(inner.topLeft(), inner.bottomLeft());
grad.setColorAt(0, c.lighter(130));
grad.setColorAt(0.4, c.lighter(106));
grad.setColorAt(0.41, 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, 30), 1));
p.drawLine(inner.topLeft() + QPointF(0.5, 0.5), inner.topRight() + QPointF(-0.5, 0.5));
p.drawLine(inner.topLeft() + QPointF(0.5, 0.5), inner.bottomLeft() + QPointF(0.5, -0.5));
p.drawLine(inner.topRight() + QPointF(-0.5, 0.5), inner.bottomRight() + QPointF(-0.5, -0.5));
p.drawLine(inner.bottomLeft() + QPointF(0.5, -0.5), inner.bottomRight() + QPointF(-0.5, -0.5));
}
p.drawRect(inner);
p.setBrush(Qt::NoBrush);
p.setPen(QPen(QColor(0, 0, 0, 30), 1));
p.drawLine(inner.topLeft() + QPointF(0.5, 0.5), inner.topRight() + QPointF(-0.5, 0.5));
p.drawLine(inner.topLeft() + QPointF(0.5, 0.5), inner.bottomLeft() + QPointF(0.5, -0.5));
p.drawLine(inner.topRight() + QPointF(-0.5, 0.5), inner.bottomRight() + QPointF(-0.5, -0.5));
p.drawLine(inner.bottomLeft() + QPointF(0.5, -0.5), inner.bottomRight() + QPointF(-0.5, -0.5));
if (m_cancelEnabled) {
// Draw cancel button
......@@ -337,21 +338,23 @@ void ProgressBar::paintEvent(QPaintEvent *)
m_cancelRect = QRect(rect.adjusted(rect.width() - CANCELBUTTON_WIDTH + 2, 1, 0, 0));
const bool hover = m_cancelRect.contains(mapFromGlobal(QCursor::pos()));
const QRectF cancelVisualRect(m_cancelRect.adjusted(0, 1, -2, -2));
QLinearGradient grad(cancelVisualRect.topLeft(), cancelVisualRect.bottomLeft());
int intensity = hover ? 90 : 70;
QColor buttonColor(intensity, intensity, intensity, 255);
grad.setColorAt(0, buttonColor.lighter(130));
grad.setColorAt(1, buttonColor.darker(130));
p.setPen(Qt::NoPen);
p.setBrush(grad);
p.drawRect(cancelVisualRect);
p.setPen(QPen(QColor(0, 0, 0, 30)));
p.drawLine(cancelVisualRect.topLeft() + QPointF(-0.5, 0.5), cancelVisualRect.bottomLeft() + QPointF(-0.5, -0.5));
p.setPen(QPen(QColor(0, 0, 0, 120)));
p.drawLine(cancelVisualRect.topLeft() + QPointF(0.5, 0.5), cancelVisualRect.bottomLeft() + QPointF(0.5, -0.5));
p.setPen(QPen(QColor(255, 255, 255, 30)));
p.drawLine(cancelVisualRect.topLeft() + QPointF(1.5, 0.5), cancelVisualRect.bottomLeft() + QPointF(1.5, -0.5));
if (creatorTheme()->widgetStyle() != Theme::StyleFlat) {
QLinearGradient grad(cancelVisualRect.topLeft(), cancelVisualRect.bottomLeft());
QColor buttonColor(intensity, intensity, intensity, 255);
grad.setColorAt(0, buttonColor.lighter(130));
grad.setColorAt(1, buttonColor.darker(130));
p.setPen(Qt::NoPen);
p.setBrush(grad);
p.drawRect(cancelVisualRect);
p.setPen(QPen(QColor(0, 0, 0, 30)));
p.drawLine(cancelVisualRect.topLeft() + QPointF(-0.5, 0.5), cancelVisualRect.bottomLeft() + QPointF(-0.5, -0.5));
p.setPen(QPen(QColor(0, 0, 0, 120)));
p.drawLine(cancelVisualRect.topLeft() + QPointF(0.5, 0.5), cancelVisualRect.bottomLeft() + QPointF(0.5, -0.5));
p.setPen(QPen(QColor(255, 255, 255, 30)));
p.drawLine(cancelVisualRect.topLeft() + QPointF(1.5, 0.5), cancelVisualRect.bottomLeft() + QPointF(1.5, -0.5));
}
p.setPen(QPen(hover ? StyleHelper::panelTextColor() : QColor(180, 180, 180), 1.2, Qt::SolidLine, Qt::FlatCap));
p.setRenderHint(QPainter::Antialiasing, true);
p.drawLine(cancelVisualRect.topLeft() + QPointF(4.0, 2.0), cancelVisualRect.bottomRight() + QPointF(-3.0, -2.0));
......
......@@ -76,7 +76,6 @@ protected:
private:
QFont titleFont() const;
QImage bar;
QString m_text;
QString m_title;
bool m_titleVisible;
......
......@@ -313,7 +313,7 @@ void ProgressManagerPrivate::init()
m_summaryProgressWidget->setVisible(!m_progressViewPinned);
m_summaryProgressWidget->setGraphicsEffect(m_opacityEffect);
m_summaryProgressLayout = new QHBoxLayout(m_summaryProgressWidget);
m_summaryProgressLayout->setContentsMargins(0, 0, 0, 0);
m_summaryProgressLayout->setContentsMargins(0, 0, 0, 2);
m_summaryProgressLayout->setSpacing(0);
m_summaryProgressWidget->setLayout(m_summaryProgressLayout);
m_summaryProgressBar = new ProgressBar(m_summaryProgressWidget);
......
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