mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 10:22:48 +00:00
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:
parent
0ca4db3298
commit
92ff7de73c
3 changed files with 72 additions and 145 deletions
|
@ -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,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<const QStyleOptionSlider *>(option);
|
||||
case PM_ScrollBarExtent: {
|
||||
d->createScrollbar();
|
||||
const QSizeF hintSize = d->scrollbar->elementSize("hint-scrollbar-size");
|
||||
const QStyleOptionSlider *scrollOption = qstyleoption_cast<const QStyleOptionSlider *>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Reference in a new issue