void Style::drawSlider(const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const { ASSURE_OPTION(slider, Slider); OPT_SUNKEN OPT_ENABLED OPT_HOVER if (isEnabled && slider->subControls & SC_SliderTickmarks) { int ticks = slider->tickPosition; if (ticks != QSlider::NoTicks) { int available = pixelMetric(PM_SliderSpaceAvailable, slider, widget); int interval = slider->tickInterval; if (interval < 1) interval = slider->pageStep; if (interval) { // const int thickness = pixelMetric(PM_SliderControlThickness, slider, widget); const int len = pixelMetric(PM_SliderLength, slider, widget); const int fudge = len / 2; int pos, v = slider->minimum, nextInterval; // Since there is no subrect for tickmarks do a translation here. painter->save(); painter->translate(RECT.x(), RECT.y()); #define DRAW_TICKS(_X1_, _Y1_, _X2_, _Y2_) \ while (v <= slider->maximum) { \ pos = sliderPositionFromValue(slider->minimum, slider->maximum, v, available) + fudge;\ painter->drawLine(_X1_, _Y1_, _X2_, _Y2_);\ nextInterval = v + interval;\ if (nextInterval < v) break;\ v = nextInterval; \ } // skip semicolon painter->setPen(Colors::mid(BGCOLOR, FGCOLOR, 3,1)); if (slider->orientation == Qt::Horizontal) { const int y = RECT.height()/2; if (ticks == QSlider::TicksAbove) { DRAW_TICKS(pos, 0, pos, y); } else if (ticks == QSlider::TicksBelow) { DRAW_TICKS(pos, y, pos, RECT.height()); } else { DRAW_TICKS(pos, RECT.y(), pos, RECT.height()); } } else { const int x = RECT.width()/2; if (ticks == QSlider::TicksAbove) { DRAW_TICKS(0, pos, x, pos); } else if (ticks == QSlider::TicksBelow) { DRAW_TICKS(x, pos, RECT.width(), pos); } else { DRAW_TICKS(0, pos, RECT.width(), pos); } } painter->restore(); } } } QRect groove = subControlRect(CC_Slider, slider, SC_SliderGroove, widget); QRect handle = subControlRect(CC_Slider, slider, SC_SliderHandle, widget); isEnabled = isEnabled && (slider->maximum > slider->minimum); hover = isEnabled && (appType == GTK || (hover && (slider->activeSubControls & SC_SliderHandle))); sunken = sunken && (slider->activeSubControls & SC_SliderHandle); // const int ground = 0; // groove if ((slider->subControls & SC_SliderGroove) && groove.isValid()) { QStyleOption grooveOpt = *option; grooveOpt.rect = groove; const Groove::Mode gType = config.scroll.groove; if (gType) config.scroll.groove = Groove::Groove; drawScrollBarGroove(&grooveOpt, painter, widget); config.scroll.groove = gType; #if 1 // thermometer, #2 if (slider->minimum > -1 && (slider->maximum - slider->minimum) > 20 && slider->sliderPosition != slider->minimum) { SAVE_PEN; bool hadAntiAlias = painter->testRenderHint(QPainter::Antialiasing); painter->setRenderHint( QPainter::Antialiasing, gType ); painter->setPen(QPen(CCOLOR(scroll._, Fg), gType ? F(3) : F(1), Qt::SolidLine, Qt::RoundCap)); if ( slider->orientation == Qt::Horizontal ) { const int y = groove.center().y() + (gType ? 1 : 0); bool ltr = slider->direction == Qt::LeftToRight; if (slider->upsideDown) ltr = !ltr; const int x2 = ltr ? groove.left() + F(5) : groove.right() - F(5); painter->drawLine(handle.center().x(), y, x2, y); } else { const int x = groove.center().x(); const int y2 = slider->upsideDown ? groove.bottom() - F(5) : groove.top() + F(5); painter->drawLine(x, handle.center().y(), x, y2); } painter->setRenderHint( QPainter::Antialiasing, hadAntiAlias ); RESTORE_PEN; } #endif } // int direction = 0; // if (slider->orientation == Qt::Vertical) // ++direction; // handle ====================================== if (slider->subControls & SC_SliderHandle) { int step = 0; if (sunken) step = 6; else if (isEnabled) { const Animator::ComplexInfo *info = Animator::HoverComplex::info(widget, slider->activeSubControls & SC_SliderHandle); if (info && ( info->fades[Animator::In] & SC_SliderHandle || info->fades[Animator::Out] & SC_SliderHandle )) step = info->step(SC_SliderHandle); if (hover && !step) step = 6; } drawSliderHandle(handle, option, painter, step); } }
void Style::drawSlider(const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const { ASSURE_OPTION(slider, Slider); SAVE_PAINTER(Pen|Brush|Alias); OPT_SUNKEN OPT_ENABLED OPT_HOVER OPT_FOCUS QRect groove = subControlRect(CC_Slider, slider, SC_SliderGroove, widget); QRect handle = subControlRect(CC_Slider, slider, SC_SliderHandle, widget); isEnabled = isEnabled && (slider->maximum > slider->minimum); hover = isEnabled && (appType == GTK || (hover && (slider->activeSubControls & SC_SliderHandle))); sunken = sunken && (slider->activeSubControls & SC_SliderHandle); int radius; // groove if ((slider->subControls & SC_SliderGroove) && groove.isValid()) { painter->setPen(Qt::NoPen); painter->setRenderHint(QPainter::Antialiasing, true); // thermometer if (slider->minimum > -1 && slider->sliderPosition != slider->minimum) { painter->setBrush(THERMOMETER_COLOR); QRect thermometer = groove; if (slider->orientation == Qt::Horizontal) thermometer.adjust(0, thermometer.height()/THERMOMETER_FACTOR, 0, -thermometer.height()/THERMOMETER_FACTOR); else thermometer.adjust(thermometer.width()/THERMOMETER_FACTOR, 0, -thermometer.width()/THERMOMETER_FACTOR, 0); radius = qMin(thermometer.width(), thermometer.height())/2; const QPoint c = handle.center(); if ( slider->orientation == Qt::Horizontal ) { bool ltr = slider->direction == Qt::LeftToRight; if (slider->upsideDown) ltr = !ltr; if (ltr) { groove.setLeft(c.x()); thermometer.setRight(c.x()); } else { groove.setRight(c.x()); thermometer.setLeft(handle.left()); } } else { if (slider->upsideDown) { groove.setBottom(c.y()); thermometer.setTop(c.y()); } else { groove.setTop(c.y()); thermometer.setBottom(handle.bottom()); } } painter->drawRoundedRect(thermometer, radius, radius); } if (slider->sliderPosition != slider->maximum || slider->minimum < 0 ) { radius = qMin(groove.width(), groove.height())/2; painter->setBrush(GROOVE_COLOR); painter->drawRoundedRect(groove, radius, radius); } painter->setRenderHint(QPainter::Antialiasing, false); } // tickmarks - we paint a centered dotline, no stupid above/below/both nonsense if (isEnabled && (slider->subControls & SC_SliderTickmarks) && slider->tickPosition != QSlider::NoTicks) { int interval = slider->tickInterval; if (interval < 1) interval = slider->pageStep; if (interval > 0) { QPen oldPen = painter->pen(); const qreal pw = F(1); QPen pen(FCOLOR(Window), pw); interval = (slider->maximum - slider->minimum) / interval; const int s = (slider->orientation == Qt::Horizontal) ? RECT.width() - handle.width() : RECT.height() - handle.height(); qreal space = s/(pw*interval) - 1.0f; pen.setDashPattern(QVector<qreal>() << 1.0f << space); space /= 2.0f; pen.setDashOffset(space - 0.5f + handle.width()*0.5f); painter->setPen(pen); QPoint c = groove.center(); if (slider->orientation == Qt::Horizontal) painter->drawLine(RECT.x() + space, c.y(), RECT.right() - space, c.y()); else painter->drawLine(c.x(), RECT.y() + space, c.x(), RECT.bottom() - space); painter->setPen(oldPen); } } // handle ====================================== if (isEnabled && (slider->subControls & SC_SliderHandle)) { int step = 0; if (sunken) step = 6; else if (isEnabled) { const Animator::ComplexInfo *info = Animator::HoverComplex::info(widget, slider->activeSubControls & SC_SliderHandle); if (info && ( info->fades[Animator::In] & SC_SliderHandle || info->fades[Animator::Out] & SC_SliderHandle )) step = info->step(SC_SliderHandle); if (hover && !step) step = 6; } drawSliderHandle(handle, option, painter, step); } RESTORE_PAINTER }
void Style::drawDial(const QStyleOptionComplex *option, QPainter *painter, const QWidget *) const { ASSURE_OPTION(dial, Slider); OPT_ENABLED OPT_HOVER OPT_FOCUS painter->save(); QRect rect = RECT; if (rect.width() > rect.height()) { rect.setLeft(rect.x()+(rect.width()-rect.height())/2); rect.setWidth(rect.height()); } else { rect.setTop(rect.y()+(rect.height()-rect.width())/2); rect.setHeight(rect.width()); } int d = qMin(2*rect.width()/5, Dpi::target.SliderThickness); int r; // angle calculation from qcommonstyle.cpp (c) Trolltech 1992-2007, ASA. float a; if (dial->maximum == dial->minimum) a = M_PI / 2; else if (dial->dialWrapping) a = M_PI * 3 / 2 - (dial->sliderValue - dial->minimum) * 2 * M_PI / (dial->maximum - dial->minimum); else a = (M_PI * 8 - (dial->sliderValue - dial->minimum) * 10 * M_PI / (dial->maximum - dial->minimum)) / 6; QPoint cp = rect.center(); // fallback for small dials ============================ bool small(rect.width() < 8*Dpi::target.SliderThickness/3); if ( small ) { painter->setRenderHint( QPainter::Antialiasing ); painter->setPen(Qt::NoPen); painter->setBrush(QColor(0,0,0,50)); painter->drawEllipse(rect); rect.adjust(F(2), F(1), -F(2), -F(2)); painter->setBrushOrigin(rect.topLeft()); const QPixmap &fill = Gradients::pix(FCOLOR(Window), rect.height(), Qt::Vertical, GRAD(scroll)); painter->setBrush(fill); painter->drawEllipse(rect); QColor c = hasFocus ? FCOLOR(Highlight) : FCOLOR(WindowText); if (!hover) c = Colors::mid(FCOLOR(Window), c, 1, 1+isEnabled); d = qMax(F(3), d/4); r = (rect.width()-d)/2; cp += QPoint((int)(r * cos(a)), -(int)(r * sin(a))); painter->setPen(QPen(c, d, Qt::SolidLine, Qt::RoundCap)); painter->drawPoint(cp); } // the value ============================================== QFont fnt = painter->font(); int h = rect.height()/2; h -= 2 * (h - qMin(h, painter->fontMetrics().xHeight())) / 3; fnt.setPixelSize( h ); painter->setFont(fnt); painter->setBrush(Qt::NoBrush); painter->setPen(Colors::mid(PAL.background().color(), PAL.foreground().color(),!hasFocus,2)); drawItemText(painter, rect, Qt::AlignCenter, PAL, isEnabled, QString::number(dial->sliderValue)); if (small) { painter->restore(); return; } r = (rect.width()-d)/2; cp += QPoint((int)(r * cos(a)), -(int)(r * sin(a))); // the huge ring ======================================= r = d/2; rect.adjust(r,r,-r,-r); painter->setPen(FCOLOR(Window).dark(115)); painter->setRenderHint( QPainter::Antialiasing ); painter->drawEllipse(rect); rect.translate(0, 1); painter->setPen(FCOLOR(Window).light(108)); painter->drawEllipse(rect); // the drop =========================== rect = QRect(0,0,d,d); rect.moveCenter(cp); drawSliderHandle(rect, option, painter, hover * 6); painter->restore(); }
void Style::drawDial(const QStyleOptionComplex *option, QPainter *painter, const QWidget *) const { ASSURE_OPTION(dial, Slider); OPT_ENABLED OPT_HOVER OPT_FOCUS SAVE_PAINTER(Pen|Brush|Alias|Font); QRect rect = RECT; if (rect.width() > rect.height()) { rect.setLeft(rect.x()+(rect.width()-rect.height())/2); rect.setWidth(rect.height()); } else { rect.setTop(rect.y()+(rect.height()-rect.width())/2); rect.setHeight(rect.width()); } int d = qMin(2*rect.width()/5, config.slider.thickness); int r = (rect.width()-d)/2; // angle calculation from qcommonstyle.cpp (c) Trolltech 1992-2007, ASA. float a; if (dial->maximum == dial->minimum) a = M_PI / 2; else if (dial->dialWrapping) a = M_PI * 3 / 2 - (dial->sliderValue - dial->minimum) * 2 * M_PI / (dial->maximum - dial->minimum); else a = (M_PI * 8 - (dial->sliderValue - dial->minimum) * 10 * M_PI / (dial->maximum - dial->minimum)) / 6; QPoint cp = rect.center() + QPoint(qRound(r * cos(a)), -qRound(r * sin(a))); // the huge ring ======================================= r = d/2+1; rect.adjust(r,r,-r,-r); painter->setBrush(Qt::NoBrush); painter->setRenderHint( QPainter::Antialiasing ); const int start = -(dial->dialWrapping ? 90 : 120)*16; const int span = -16*(dial->dialWrapping ? 360 : 300)*(dial->sliderValue - dial->minimum)/(dial->maximum - dial->minimum); QPen pen; if (dial->sliderValue != dial->maximum) { QPen pen(GROOVE_COLOR, d); pen.setCapStyle(Qt::RoundCap); painter->setPen(pen); painter->drawArc(rect, start + span, -((dial->dialWrapping ? 360 : 300)*16 + span)); } if (dial->sliderValue != dial->minimum) { QPen pen(THERMOMETER_COLOR, d - 2*(d/THERMOMETER_FACTOR)); pen.setCapStyle(Qt::RoundCap); painter->setPen(pen); painter->drawArc(rect, start, span); } // the value ============================================== QFont fnt = painter->font(); int h = rect.height()/2; h -= 2 * (h - qMin(h, painter->fontMetrics().xHeight())) / 3; fnt.setPixelSize( h ); painter->setFont(fnt); painter->setPen(FX::blend(PAL.background().color(), PAL.foreground().color(),!hasFocus,2)); drawItemText(painter, rect, Qt::AlignCenter, PAL, isEnabled, QString::number(dial->sliderValue)); // the drop =========================== if (isEnabled) { rect = QRect(0,0,d,d); rect.moveCenter(cp); drawSliderHandle(rect, option, painter, hover * 6); } RESTORE_PAINTER }