From 92ff7de73c4316a29a1821733c7107a6a407696d Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Mon, 20 May 2024 12:23:29 +0300 Subject: [PATCH] plasma: proxy QDoubleSpinBox from Plasma::SpinBox rounding via qRound() and other methods is always possible anyway Signed-off-by: Ivailo Monev --- plasma/private/style.cpp | 146 ++++++++++--------------------------- plasma/widgets/spinbox.cpp | 36 ++++----- plasma/widgets/spinbox.h | 35 +++++---- 3 files changed, 72 insertions(+), 145 deletions(-) diff --git a/plasma/private/style.cpp b/plasma/private/style.cpp index 47a0a5c9..df3a82ea 100644 --- a/plasma/private/style.cpp +++ b/plasma/private/style.cpp @@ -21,7 +21,7 @@ #include "style_p.h" #include -#include +#include #include #include #include @@ -194,73 +194,6 @@ void Style::drawComplexControl(ComplexControl control, painter->restore(); break; } - case CC_SpinBox: { - d->createTextBox(); - - d->textBox->resizeFrame(option->rect.size()); - d->textBox->paintFrame(painter); - - const QStyleOptionSpinBox *spinOpt = qstyleoption_cast(option); - bool upSunken = (spinOpt->activeSubControls & SC_SpinBoxUp) && - (spinOpt->state & (State_Sunken | State_On)); - bool downSunken = (spinOpt->activeSubControls & SC_SpinBoxDown) && - (spinOpt->state & (State_Sunken | State_On)); - - const QSpinBox *spin = qobject_cast(widget); - PrimitiveElement pe; - if (spin->buttonSymbols() == QSpinBox::PlusMinus) { - pe = PE_IndicatorSpinPlus; - } else { - pe = PE_IndicatorArrowUp; - } - - QStyleOption upOpt; - upOpt = *option; - upOpt.rect = subControlRect(CC_SpinBox, option, SC_SpinBoxUp, widget); - - if (upSunken) { - upOpt.state = State_Sunken|State_Enabled; - } else { - upOpt.state = State_Enabled; - } - - qApp->style()->drawPrimitive(pe, &upOpt, painter, widget); - - if (spin->buttonSymbols() == QSpinBox::PlusMinus) { - pe = PE_IndicatorSpinMinus; - } else { - pe = PE_IndicatorArrowDown; - } - - QStyleOption downOpt; - downOpt= *option; - downOpt.rect = subControlRect(CC_SpinBox, option, SC_SpinBoxDown, widget); - - if (downSunken) { - downOpt.state = State_Sunken|State_Enabled; - } else { - downOpt.state = State_Enabled; - } - - qApp->style()->drawPrimitive(pe, &downOpt, painter, widget); - break; - } - case CC_ComboBox: { - const QComboBox *combo = qobject_cast(widget); - if (!combo->isEditable()) { - qApp->style()->drawComplexControl(control, option, painter, widget); - } else { - d->createTextBox(); - d->textBox->resizeFrame(option->rect.size()); - d->textBox->paintFrame(painter); - - QStyleOption arrowOpt; - arrowOpt = *option; - arrowOpt.rect = subControlRect(CC_ComboBox, option, SC_ComboBoxArrow, widget); - qApp->style()->drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, painter, widget); - } - break; - } default: { qApp->style()->drawComplexControl(control, option, painter, widget); } @@ -342,44 +275,45 @@ int Style::pixelMetric(PixelMetric metric, const QStyleOption *option, const QWi if (Theme::defaultTheme()->useNativeWidgetStyle()) { return qApp->style()->pixelMetric(metric, option, widget); } - switch (metric) { - case PM_ScrollBarExtent: { - d->createScrollbar(); - const QSizeF hintSize = d->scrollbar->elementSize("hint-scrollbar-size"); - const QStyleOptionSlider *scrollOption = qstyleoption_cast(option); + case PM_ScrollBarExtent: { + d->createScrollbar(); + const QSizeF hintSize = d->scrollbar->elementSize("hint-scrollbar-size"); + const QStyleOptionSlider *scrollOption = qstyleoption_cast(option); - if (scrollOption && scrollOption->orientation == Qt::Vertical) { - if (hintSize.isEmpty()) { - return d->scrollbar->elementSize("arrow-down").width() + 2; + if (scrollOption && scrollOption->orientation == Qt::Vertical) { + if (hintSize.isEmpty()) { + return d->scrollbar->elementSize("arrow-down").width() + 2; + } else { + return hintSize.width(); + } } else { - return hintSize.width(); - } - } else { - if (hintSize.isEmpty()) { - return d->scrollbar->elementSize("arrow-left").height() + 2; - } else { - return hintSize.height(); + if (hintSize.isEmpty()) { + return d->scrollbar->elementSize("arrow-left").height() + 2; + } else { + return hintSize.height(); + } } } - } - default: - return qApp->style()->pixelMetric(metric, option, widget); + default: { + return qApp->style()->pixelMetric(metric, option, widget); + } } } QRect Style::subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const { switch (element) { - case SE_LineEditContents: { - d->createTextBox(); + case SE_LineEditContents: { + d->createTextBox(); - qreal left, top, right, bottom; - d->textBox->getMargins(left, top, right, bottom); - return option->rect.adjusted(left + 2, top + 2, -(right + 2), -(bottom + 2)); - } - default: - return qApp->style()->subElementRect(element, option, widget); + qreal left, top, right, bottom; + d->textBox->getMargins(left, top, right, bottom); + return option->rect.adjusted(left + 2, top + 2, -(right + 2), -(bottom + 2)); + } + default: { + return qApp->style()->subElementRect(element, option, widget); + } } } @@ -387,22 +321,16 @@ QSize Style::sizeFromContents(ContentsType type, const QStyleOption *option, const QSize &contentsSize, const QWidget *widget) const { switch (type) { - case CT_SpinBox: { - d->createTextBox(); + case CT_LineEdit: { + d->createTextBox(); - qreal left, top, right, bottom; - d->textBox->getMargins(left, top, right, bottom); - return contentsSize + QSize(left + right - 2, top + bottom - 2); - } - case CT_LineEdit: { - d->createTextBox(); - - qreal left, top, right, bottom; - d->textBox->getMargins(left, top, right, bottom); - return contentsSize + QSize(left + right + 4, top + bottom + 4); - } - default: - return qApp->style()->sizeFromContents(type, option, contentsSize, widget); + qreal left, top, right, bottom; + d->textBox->getMargins(left, top, right, bottom); + return contentsSize + QSize(left + right + 4, top + bottom + 4); + } + default: { + return qApp->style()->sizeFromContents(type, option, contentsSize, widget); + } } } diff --git a/plasma/widgets/spinbox.cpp b/plasma/widgets/spinbox.cpp index 5f141a89..2dc3d123 100644 --- a/plasma/widgets/spinbox.cpp +++ b/plasma/widgets/spinbox.cpp @@ -48,9 +48,9 @@ SpinBox::SpinBox(QGraphicsWidget *parent) : QGraphicsProxyWidget(parent), d(new SpinBoxPrivate(this)) { - KIntSpinBox *native = new KIntSpinBox(); + QDoubleSpinBox *native = new QDoubleSpinBox(); - connect(native, SIGNAL(valueChanged(int)), this, SIGNAL(valueChanged(int))); + connect(native, SIGNAL(valueChanged(double)), this, SIGNAL(valueChanged(double))); connect(native, SIGNAL(editingFinished()), this, SIGNAL(editingFinished())); d->setWidget(native); @@ -69,44 +69,44 @@ SpinBox::~SpinBox() Plasma::Style::doneWithSharedStyle(); } -void SpinBox::setMaximum(int max) +void SpinBox::setMaximum(double max) { - static_cast(widget())->setMaximum(max); + nativeWidget()->setMaximum(max); } -int SpinBox::maximum() const +double SpinBox::maximum() const { - return static_cast(widget())->maximum(); + return nativeWidget()->maximum(); } -void SpinBox::setMinimum(int min) +void SpinBox::setMinimum(double min) { - static_cast(widget())->setMinimum(min); + nativeWidget()->setMinimum(min); } -int SpinBox::minimum() const +double SpinBox::minimum() const { - return static_cast(widget())->minimum(); + return nativeWidget()->minimum(); } -void SpinBox::setRange(int min, int max) +void SpinBox::setRange(double min, double max) { - static_cast(widget())->setRange(min, max); + nativeWidget()->setRange(min, max); } -void SpinBox::setValue(int value) +void SpinBox::setValue(double value) { - static_cast(widget())->setValue(value); + nativeWidget()->setValue(value); } -int SpinBox::value() const +double SpinBox::value() const { - return static_cast(widget())->value(); + return nativeWidget()->value(); } -KIntSpinBox *SpinBox::nativeWidget() const +QDoubleSpinBox *SpinBox::nativeWidget() const { - return static_cast(widget()); + return static_cast(widget()); } void SpinBox::changeEvent(QEvent *event) diff --git a/plasma/widgets/spinbox.h b/plasma/widgets/spinbox.h index ab95f59e..f63dfe87 100644 --- a/plasma/widgets/spinbox.h +++ b/plasma/widgets/spinbox.h @@ -21,12 +21,11 @@ #ifndef PLASMA_SPINBOX_H #define PLASMA_SPINBOX_H -#include +#include +#include #include -class KIntSpinBox; - namespace Plasma { @@ -35,14 +34,14 @@ class SpinBoxPrivate; /** * @class SpinBox plasma/widgets/slider.h * - * @short Provides a plasma-themed KIntSpinBox. + * @short Provides a plasma-themed KDoubleNumInput. */ class PLASMA_EXPORT SpinBox : public QGraphicsProxyWidget { Q_OBJECT - Q_PROPERTY(int maximum READ maximum WRITE setMinimum) - Q_PROPERTY(int minimum READ minimum WRITE setMinimum) - Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged) + Q_PROPERTY(double maximum READ maximum WRITE setMinimum) + Q_PROPERTY(double minimum READ minimum WRITE setMinimum) + Q_PROPERTY(double value READ value WRITE setValue NOTIFY valueChanged) public: explicit SpinBox(QGraphicsWidget *parent = 0); @@ -51,22 +50,22 @@ public: /** * @return the maximum value */ - int maximum() const; + double maximum() const; /** * @return the minimum value */ - int minimum() const; + double minimum() const; /** * @return the current value */ - int value() const; + double value() const; /** * @return the native widget wrapped by this SpinBox */ - KIntSpinBox *nativeWidget() const; + QDoubleSpinBox *nativeWidget() const; protected: void changeEvent(QEvent *event); @@ -76,17 +75,17 @@ public Q_SLOTS: /** * Sets the maximum value the slider can take. */ - void setMaximum(int maximum); + void setMaximum(double maximum); /** * Sets the minimum value the slider can take. */ - void setMinimum(int minimum); + void setMinimum(double minimum); /** * Sets the minimum and maximum values the slider can take. */ - void setRange(int minimum, int maximum); + void setRange(double minimum, double maximum); /** * Sets the value of the slider. @@ -94,23 +93,23 @@ public Q_SLOTS: * If it is outside the range specified by minimum() and maximum(), * it will be adjusted to fit. */ - void setValue(int value); + void setValue(double value); Q_SIGNALS: /** * This signal is emitted when the user drags the slider. * - * In fact, it is emitted whenever the sliderMoved(int) signal + * In fact, it is emitted whenever the sliderMoved(double) signal * of KIntSpinBox would be emitted. See the Qt documentation for * more information. */ - void sliderMoved(int value); + void sliderMoved(double value); /** * This signal is emitted when the slider value has changed, * with the new slider value as argument. */ - void valueChanged(int value); + void valueChanged(double value); /** * This signal is emitted when editing is finished.