plasma: proxy QDoubleSpinBox from Plasma::SpinBox

rounding via qRound() and other methods is always possible anyway

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-05-20 12:23:29 +03:00
parent 0ca4db3298
commit 92ff7de73c
3 changed files with 72 additions and 145 deletions

View file

@ -21,7 +21,7 @@
#include "style_p.h"
#include <QPainter>
#include <QtGui/qstyleoption.h>
#include <QStyleOption>
#include <QSpinBox>
#include <QComboBox>
#include <QApplication>
@ -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<const QStyleOptionSpinBox *>(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<const QSpinBox *>(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<const QComboBox *>(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,7 +275,6 @@ 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();
@ -363,10 +295,11 @@ int Style::pixelMetric(PixelMetric metric, const QStyleOption *option, const QWi
}
}
}
default:
default: {
return qApp->style()->pixelMetric(metric, option, widget);
}
}
}
QRect Style::subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const
{
@ -378,22 +311,16 @@ QRect Style::subElementRect(SubElement element, const QStyleOption *option, cons
d->textBox->getMargins(left, top, right, bottom);
return option->rect.adjusted(left + 2, top + 2, -(right + 2), -(bottom + 2));
}
default:
default: {
return qApp->style()->subElementRect(element, option, widget);
}
}
}
QSize Style::sizeFromContents(ContentsType type, const QStyleOption *option,
const QSize &contentsSize, const QWidget *widget) const
{
switch (type) {
case CT_SpinBox: {
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();
@ -401,10 +328,11 @@ QSize Style::sizeFromContents(ContentsType type, const QStyleOption *option,
d->textBox->getMargins(left, top, right, bottom);
return contentsSize + QSize(left + right + 4, top + bottom + 4);
}
default:
default: {
return qApp->style()->sizeFromContents(type, option, contentsSize, widget);
}
}
}
}

View file

@ -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<KIntSpinBox*>(widget())->setMaximum(max);
nativeWidget()->setMaximum(max);
}
int SpinBox::maximum() const
double SpinBox::maximum() const
{
return static_cast<KIntSpinBox*>(widget())->maximum();
return nativeWidget()->maximum();
}
void SpinBox::setMinimum(int min)
void SpinBox::setMinimum(double min)
{
static_cast<KIntSpinBox*>(widget())->setMinimum(min);
nativeWidget()->setMinimum(min);
}
int SpinBox::minimum() const
double SpinBox::minimum() const
{
return static_cast<KIntSpinBox*>(widget())->minimum();
return nativeWidget()->minimum();
}
void SpinBox::setRange(int min, int max)
void SpinBox::setRange(double min, double max)
{
static_cast<KIntSpinBox*>(widget())->setRange(min, max);
nativeWidget()->setRange(min, max);
}
void SpinBox::setValue(int value)
void SpinBox::setValue(double value)
{
static_cast<KIntSpinBox*>(widget())->setValue(value);
nativeWidget()->setValue(value);
}
int SpinBox::value() const
double SpinBox::value() const
{
return static_cast<KIntSpinBox*>(widget())->value();
return nativeWidget()->value();
}
KIntSpinBox *SpinBox::nativeWidget() const
QDoubleSpinBox *SpinBox::nativeWidget() const
{
return static_cast<KIntSpinBox*>(widget());
return static_cast<QDoubleSpinBox*>(widget());
}
void SpinBox::changeEvent(QEvent *event)

View file

@ -21,12 +21,11 @@
#ifndef PLASMA_SPINBOX_H
#define PLASMA_SPINBOX_H
#include <QtGui/QGraphicsProxyWidget>
#include <QDoubleSpinBox>
#include <QGraphicsProxyWidget>
#include <plasma/plasma_export.h>
class KIntSpinBox;
namespace Plasma
{
@ -35,14 +34,14 @@ class SpinBoxPrivate;
/**
* @class SpinBox plasma/widgets/slider.h <Plasma/Widgets/SpinBox>
*
* @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.