int ScrollBar::extent() const { QStyleOptionSlider opt; opt.init(this); opt.subControls = QStyle::SC_None; opt.activeSubControls = QStyle::SC_None; opt.orientation = orientation(); opt.minimum = minimum(); opt.maximum = maximum(); opt.sliderPosition = sliderPosition(); opt.sliderValue = value(); opt.singleStep = singleStep(); opt.pageStep = pageStep(); opt.upsideDown = invertedAppearance(); if (orientation() == Qt::Horizontal) opt.state |= QStyle::State_Horizontal; return style()->pixelMetric(QStyle::PM_ScrollBarExtent, &opt, this); }
void CustomDial::paintEvent(QPaintEvent*) { QPainter p(this); QStyleOptionSlider tab; tab.init(this); bool hover = tab.state & QStyle::State_MouseOver; p.setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing); QBrush brush("#333"); if(hover) brush.setColor("#393939"); p.setPen(Qt::NoPen); p.setBrush(brush); p.drawPie(20, 20, width()-20*2, height()-20*2, (220)*16, -(360-100)*16); if(hover) p.setPen(QPen(color.lighter(120), 15)); else p.setPen(QPen(color, 15)); p.drawArc(10, 10, width()-10*2, height()-10*2, 220*16, -(360-100)*16*value()/100); }
void KoSliderCombo::KoSliderComboPrivate::showPopup() { if(firstShowOfSlider) { container->show(); //show container a bit early so the slider can be layout'ed firstShowOfSlider = false; } QStyleOptionSlider opt; opt.init(slider); opt.maximum=256; opt.sliderPosition = opt.sliderValue = slider->value(); int hdlPos = thePublic->style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle).center().x(); QStyleOptionComboBox optThis; optThis.init(thePublic); optThis.subControls = QStyle::SC_All; optThis.editable = true; int arrowPos = thePublic->style()->subControlRect(QStyle::CC_ComboBox, &optThis, QStyle::SC_ComboBoxArrow).center().x(); QSize popSize = container->size(); QRect popupRect(thePublic->mapToGlobal(QPoint(arrowPos - hdlPos - slider->x(), thePublic->size().height())), popSize); // Make sure the popup is not drawn outside the screen area QRect screenRect = QApplication::desktop()->availableGeometry(thePublic); if (popupRect.right() > screenRect.right()) popupRect.translate(screenRect.right() - popupRect.right(), 0); if (popupRect.left() < screenRect.left()) popupRect.translate(screenRect.left() - popupRect.left(), 0); if (popupRect.bottom() > screenRect.bottom()) popupRect.translate(0, -(thePublic->height() + container->height())); container->setGeometry(popupRect); container->raise(); container->show(); slider->setFocus(); }
void DiffZoomWidget::paintEvent(QPaintEvent *) { const QScrollBar* scrollBar = diffview->scrollBar(); if (!scrollBar) return; const QColor diffChangeColor(CervisiaSettings::diffChangeColor()); const QColor diffInsertColor(CervisiaSettings::diffInsertColor()); const QColor diffDeleteColor(CervisiaSettings::diffDeleteColor()); // only y and height are important QStyleOptionSlider option; option.init(scrollBar); const QRect scrollBarGroove(scrollBar->isVisible() ? style()->subControlRect(QStyle::CC_ScrollBar, &option, QStyle::SC_ScrollBarGroove, scrollBar) : rect()); // draw rectangles at the positions of the differences const QByteArray& lineTypes(diffview->compressedContent()); QPainter p(this); p.fillRect(0, scrollBarGroove.y(), width(), scrollBarGroove.height(), KColorScheme(QPalette::Active, KColorScheme::View).background().color()); if (const unsigned int numberOfLines = lineTypes.size()) { const double scale(((double) scrollBarGroove.height()) / numberOfLines); for (unsigned int index(0); index < numberOfLines;) { const char lineType(lineTypes[index]); // don't use qRound() to avoid painting outside of the pixmap // (yPos1 must be lesser than scrollBarGroove.height()) const int yPos1(static_cast<int>(index * scale)); // search next line with different lineType for (++index; index < numberOfLines && lineType == lineTypes[index]; ++index) ; QColor color; switch (lineType) { case 'C': color = diffChangeColor; break; case 'I': color = diffInsertColor; break; case 'D': color = diffDeleteColor; break; case ' ': case 'N': color = KColorScheme(QPalette::Active, KColorScheme::View).background(KColorScheme::AlternateBackground).color(); break; } if (color.isValid()) { const int yPos2(qRound(index * scale)); const int areaHeight((yPos2 != yPos1) ? yPos2 - yPos1 : 1); p.fillRect(0, yPos1 + scrollBarGroove.y(), width(), areaHeight, QBrush(color)); } } } }