From 59b2a85654af0a4852c0369ca21604c6b13f34e5 Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig Date: Tue, 26 Mar 2013 16:04:29 +0100 Subject: Fix tickmark painting on Fusion style The problem seems to be that Fusion assumed that tickmarckoffset was a fixed size, which probably changed when we moved the inheritance from Windows to CommonStyle. I also had to modify the paint order Task-number: QTBUG-30294 Change-Id: Ie7320c39fd572d39b641b6bd5a9db05f494f6b74 Reviewed-by: Gabriel de Dietrich --- src/widgets/styles/qfusionstyle.cpp | 96 +++++++++++++++++++------------------ 1 file changed, 49 insertions(+), 47 deletions(-) (limited to 'src/widgets/styles/qfusionstyle.cpp') diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp index 652d092652..bfc22807a0 100644 --- a/src/widgets/styles/qfusionstyle.cpp +++ b/src/widgets/styles/qfusionstyle.cpp @@ -2798,53 +2798,6 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption painter->restore(); } - // draw handle - if ((option->subControls & SC_SliderHandle) ) { - QString handlePixmapName = QStyleHelper::uniqueName(QLatin1String("slider_handle"), option, handle.size()); - if (!QPixmapCache::find(handlePixmapName, cache)) { - cache = styleCachePixmap(handle.size()); - cache.fill(Qt::transparent); - QRect pixmapRect(0, 0, handle.width(), handle.height()); - QPainter handlePainter(&cache); - QRect gradRect = pixmapRect.adjusted(2, 2, -2, -2); - - // gradient fill - QRect r = pixmapRect.adjusted(1, 1, -2, -2); - QLinearGradient gradient = qt_fusion_gradient(gradRect, d->buttonColor(option->palette),horizontal ? TopDown : FromLeft); - - handlePainter.setRenderHint(QPainter::Antialiasing, true); - handlePainter.translate(0.5, 0.5); - - handlePainter.setPen(Qt::NoPen); - handlePainter.setBrush(QColor(0, 0, 0, 40)); - handlePainter.drawRect(r.adjusted(-1, 2, 1, -2)); - - handlePainter.setPen(QPen(d->outline(option->palette))); - if (option->state & State_HasFocus && option->state & State_KeyboardFocusChange) - handlePainter.setPen(QPen(d->highlightedOutline(option->palette))); - - handlePainter.setBrush(gradient); - handlePainter.drawRoundedRect(r, 2, 2); - handlePainter.setBrush(Qt::NoBrush); - handlePainter.setPen(d->innerContrastLine()); - handlePainter.drawRoundedRect(r.adjusted(1, 1, -1, -1), 2, 2); - - QColor cornerAlpha = outline.darker(120); - cornerAlpha.setAlpha(80); - - //handle shadow - handlePainter.setPen(shadowAlpha); - handlePainter.drawLine(QPoint(r.left() + 2, r.bottom() + 1), QPoint(r.right() - 2, r.bottom() + 1)); - handlePainter.drawLine(QPoint(r.right() + 1, r.bottom() - 3), QPoint(r.right() + 1, r.top() + 4)); - handlePainter.drawLine(QPoint(r.right() - 1, r.bottom()), QPoint(r.right() + 1, r.bottom() - 2)); - - handlePainter.end(); - QPixmapCache::insert(handlePixmapName, cache); - } - - painter->drawPixmap(handle.topLeft(), cache); - - } if (option->subControls & SC_SliderTickmarks) { painter->setPen(outline); int tickSize = proxy()->pixelMetric(PM_SliderTickmarkOffset, option, widget); @@ -2900,6 +2853,53 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption v = nextInterval; } } + // draw handle + if ((option->subControls & SC_SliderHandle) ) { + QString handlePixmapName = QStyleHelper::uniqueName(QLatin1String("slider_handle"), option, handle.size()); + if (!QPixmapCache::find(handlePixmapName, cache)) { + cache = styleCachePixmap(handle.size()); + cache.fill(Qt::transparent); + QRect pixmapRect(0, 0, handle.width(), handle.height()); + QPainter handlePainter(&cache); + QRect gradRect = pixmapRect.adjusted(2, 2, -2, -2); + + // gradient fill + QRect r = pixmapRect.adjusted(1, 1, -2, -2); + QLinearGradient gradient = qt_fusion_gradient(gradRect, d->buttonColor(option->palette),horizontal ? TopDown : FromLeft); + + handlePainter.setRenderHint(QPainter::Antialiasing, true); + handlePainter.translate(0.5, 0.5); + + handlePainter.setPen(Qt::NoPen); + handlePainter.setBrush(QColor(0, 0, 0, 40)); + handlePainter.drawRect(r.adjusted(-1, 2, 1, -2)); + + handlePainter.setPen(QPen(d->outline(option->palette))); + if (option->state & State_HasFocus && option->state & State_KeyboardFocusChange) + handlePainter.setPen(QPen(d->highlightedOutline(option->palette))); + + handlePainter.setBrush(gradient); + handlePainter.drawRoundedRect(r, 2, 2); + handlePainter.setBrush(Qt::NoBrush); + handlePainter.setPen(d->innerContrastLine()); + handlePainter.drawRoundedRect(r.adjusted(1, 1, -1, -1), 2, 2); + + QColor cornerAlpha = outline.darker(120); + cornerAlpha.setAlpha(80); + + //handle shadow + handlePainter.setPen(shadowAlpha); + handlePainter.drawLine(QPoint(r.left() + 2, r.bottom() + 1), QPoint(r.right() - 2, r.bottom() + 1)); + handlePainter.drawLine(QPoint(r.right() + 1, r.bottom() - 3), QPoint(r.right() + 1, r.top() + 4)); + handlePainter.drawLine(QPoint(r.right() - 1, r.bottom()), QPoint(r.right() + 1, r.bottom() - 2)); + + handlePainter.end(); + QPixmapCache::insert(handlePixmapName, cache); + } + + painter->drawPixmap(handle.topLeft(), cache); + + } painter->setBrush(oldBrush); painter->setPen(oldPen); } @@ -2920,6 +2920,8 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption int QFusionStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const { switch (metric) { + case PM_SliderTickmarkOffset: + return 4; case PM_HeaderMargin: return 2; case PM_ToolTipLabelFrameWidth: -- cgit v1.2.3