QStyleOptionSpinBox KisAbstractSliderSpinBox::spinBoxOptions() const { const Q_D(KisAbstractSliderSpinBox); QStyleOptionSpinBox opts; opts.initFrom(this); opts.frame = false; opts.buttonSymbols = QAbstractSpinBox::UpDownArrows; opts.subControls = QStyle::SC_SpinBoxUp | QStyle::SC_SpinBoxDown; //Disable non-logical buttons if (d->value == d->minimum) { opts.stepEnabled = QAbstractSpinBox::StepUpEnabled; } else if (d->value == d->maximum) { opts.stepEnabled = QAbstractSpinBox::StepDownEnabled; } else { opts.stepEnabled = QAbstractSpinBox::StepUpEnabled | QAbstractSpinBox::StepDownEnabled; } //Deal with depressed buttons if (d->upButtonDown) { opts.activeSubControls = QStyle::SC_SpinBoxUp; } else if (d->downButtonDown) { opts.activeSubControls = QStyle::SC_SpinBoxDown; } else { opts.activeSubControls = 0; } return opts; }
/*! \reimp */ QRect QAccessibleDoubleSpinBox::rect(int child) const { QRect rect; if (!doubleSpinBox()->isVisible()) return rect; QStyleOptionSpinBox spinBoxOption; spinBoxOption.initFrom(doubleSpinBox()); switch (child) { case Editor: rect = doubleSpinBox()->style()->subControlRect(QStyle::CC_SpinBox, &spinBoxOption, QStyle::SC_SpinBoxEditField, doubleSpinBox()); break; case ValueUp: rect = doubleSpinBox()->style()->subControlRect(QStyle::CC_SpinBox, &spinBoxOption, QStyle::SC_SpinBoxUp, doubleSpinBox()); break; case ValueDown: rect = doubleSpinBox()->style()->subControlRect(QStyle::CC_SpinBox, &spinBoxOption, QStyle::SC_SpinBoxDown, doubleSpinBox()); break; default: rect = spinBoxOption.rect; break; } const QPoint globalPos = doubleSpinBox()->mapToGlobal(QPoint(0, 0)); return QRect(globalPos.x() + rect.x(), globalPos.y() + rect.y(), rect.width(), rect.height()); }
QStyleOptionSpinBox SliderDoubleSpinBoxPrivate::spinBoxOptions() const { QStyleOptionSpinBox opts; opts.initFrom(q); opts.frame = false; opts.subControls &= ~0x4; // SC_SpinBoxFrame opts.subControls &= ~0x8; // SC_SpinBoxEditField if (q->value() == q->minimum()) { opts.stepEnabled = QAbstractSpinBox::StepUpEnabled; } else if (q->value() == q->maximum()) { opts.stepEnabled = QAbstractSpinBox::StepDownEnabled; } else { opts.stepEnabled = QAbstractSpinBox::StepUpEnabled | QAbstractSpinBox::StepDownEnabled; } //Deal with depressed buttons QPoint mousePos = q->mapFromGlobal(QCursor::pos()); if (upButtonRect(opts).contains(mousePos)) { opts.activeSubControls = QStyle::SC_SpinBoxUp; } else if (downButtonRect(opts).contains(mousePos)) { opts.activeSubControls = QStyle::SC_SpinBoxDown; } else { opts.activeSubControls = 0; } return opts; }
/****************************************************************************** * Paint event handler. ******************************************************************************/ void SpinnerWidget::paintEvent(QPaintEvent* event) { QStylePainter p(this); QStyleOptionSpinBox sboption; sboption.initFrom(this); sboption.state |= _upperBtnPressed ? QStyle::State_Sunken : QStyle::State_Raised; sboption.rect.setHeight(sboption.rect.height() / 2); p.drawPrimitive(QStyle::PE_PanelButtonTool, sboption); p.drawPrimitive(QStyle::PE_IndicatorSpinUp, sboption); sboption.initFrom(this); sboption.state |= _lowerBtnPressed ? QStyle::State_Sunken : QStyle::State_Raised; sboption.rect.setTop(sboption.rect.top() + sboption.rect.height() / 2); p.drawPrimitive(QStyle::PE_PanelButtonTool, sboption); p.drawPrimitive(QStyle::PE_IndicatorSpinDown, sboption); }
void SpinBox::resizeEvent(QGraphicsSceneResizeEvent *event) { QGraphicsProxyWidget::resizeEvent(event); QStyleOptionSpinBox spinOpt; spinOpt.initFrom(nativeWidget()); QRect controlrect = nativeWidget()->style()->subControlRect(QStyle::CC_SpinBox, &spinOpt, QStyle::SC_SpinBoxFrame, nativeWidget()); if (d->focusIndicator) { d->focusIndicator->setCustomGeometry(controlrect); } }
void SpinMirror::setFrame() { // Paint the left hand frame of the main spinbox. // Use the part to the left of the edit field, plus a slice at // the left of the edit field stretched for the rest of the width. // This avoids possibly grabbing text and displaying it in the // spin button area. QGraphicsScene* c = scene(); QStyleOptionSpinBox option; option.initFrom(mMainSpinbox); QRect r = spinBoxEditFieldRect(mMainSpinbox, option); bool rtl = QApplication::isRightToLeft(); QPixmap p; if (mMirrored) { int x = rtl ? 0 : mMainSpinbox->width() - width(); p = grabWidget(mMainSpinbox, QRect(x, 0, width(), height())); } else { // Grab a single pixel wide vertical slice through the main spinbox, between the // frame and edit field. bool oxygen = mMainSpinbox->style()->inherits("Oxygen::Style"); // KDE >= 4.4 Oxygen style bool oxygen1 = mMainSpinbox->style()->inherits("OxygenStyle"); // KDE <= 4.3 Oxygen style int editOffsetY = oxygen ? 5 : oxygen1 ? 6 : 2; // offset to edit field int editOffsetX = (oxygen || oxygen1) ? 4 : 2; // offset to edit field int x = rtl ? r.right() - editOffsetX : r.left() + editOffsetX; p = grabWidget(mMainSpinbox, QRect(x, 0, 1, height())); // Blot out edit field stuff from the middle of the slice QPixmap dot = grabWidget(mMainSpinbox, QRect(x, editOffsetY, 1, 1)); QPainter painter(&p); painter.drawTiledPixmap(0, editOffsetY, 1, height() - 2*editOffsetY, dot, 0, 0); painter.end(); // Horizontally fill the mirror widget with the vertical slice p = p.scaled(size()); // Grab the left hand border of the main spinbox, and draw it into the mirror widget. QRect endr = rect(); if (rtl) { int mr = mMainSpinbox->width() - 1; endr.setWidth(mr - r.right() + editOffsetX); endr.moveRight(mr); } else endr.setWidth(r.left() + editOffsetX); x = rtl ? width() - endr.width() : 0; mMainSpinbox->render(&p, QPoint(x, 0), endr, QWidget::DrawWindowBackground | QWidget::DrawChildren | QWidget::IgnoreMask); } c->setBackgroundBrush(p); }