24#include "KProperty_p.h" 
   25#include "KPropertyEditorView.h" 
   26#include "KPropertyUtils.h" 
   27#include "KPropertyUtils_p.h" 
   28#include "KPropertyWidgetsFactory.h" 
   29#include "kproperty_debug.h" 
   44static QString cssForSpinBox(
const char *_class, 
const QFont& font, 
int itemHeight)
 
   47            "%5 { border-left: 0; border-right: 0; font-size: %3; } " 
   48            "%5::down-button { height: %1px; %4 } " 
   49            "%5::up-button { height: %2px; } " 
   50            "QLineEdit { border-width:0px;  } " 
   52        .
arg(itemHeight/2 - 1).
arg(itemHeight - itemHeight/2 - 1)
 
   53        .
arg(fontSizeForCSS(font))
 
   64    *min = 
property.option(
"min");
 
   65    *max = 
property.option(
"max");
 
   79        switch (property.
type()) {
 
   94int fixIntValue(
const QVariant &value, 
int min, 
int max, 
bool warn)
 
   96    if (value.
toInt() < min) {
 
   98            kprWarning() << 
"Could not assign value" << value.
toInt() << 
"smaller than minimum" << min
 
   99                         << 
"-- setting to" << min;
 
  103    if (value.
toInt() > max) {
 
  105            kprWarning() << 
"Could not assign value" << value.
toInt() << 
"larger than maximum" << max
 
  106                         << 
"-- setting to" << max;
 
  110    return value.
toInt();
 
  118    explicit Private(
const KProperty& prop) : property(&prop)
 
  122    const KProperty * 
const property;
 
  125KPropertyIntSpinBox::KPropertyIntSpinBox(
const KProperty& prop, 
QWidget *parent, 
int itemHeight)
 
  127        , d(new Private(prop))
 
  130    setContentsMargins(0,0,0,0);
 
  136    QString css = cssForSpinBox(
"QSpinBox", font(), itemHeight);
 
  137    KPropertyWidgetsFactory::setTopAndBottomBordersUsingStyleSheet(
this, css);
 
  142    intRangeValue(prop, &minVal, &maxVal);
 
  144    const KPropertyUtilsPrivate::ValueOptionsHandler options(prop);
 
  145    if (!options.minValueText.isNull()) {
 
  146        setSpecialValueText(options.minValueText.toString());
 
  148    if (!options.prefix.isEmpty()) {
 
  151    if (!options.suffix.isEmpty()) {
 
  154    connect(
this, SIGNAL(valueChanged(
int)), 
this, SLOT(slotValueChanged(
int)));
 
  157KPropertyIntSpinBox::~KPropertyIntSpinBox()
 
  162QVariant KPropertyIntSpinBox::value()
 const 
  164    if (d->property->type() == KProperty::UInt) {
 
  170void KPropertyIntSpinBox::setValue(
const QVariant& value)
 
  174    intRangeValue(*d->property, &minVal, &maxVal);
 
  178void KPropertyIntSpinBox::slotValueChanged(
int value)
 
  181    emit commitData(
this);
 
  189    explicit Private(
const KProperty& prop) : property(&prop)
 
  193    const KProperty * 
const property;
 
  202    *min = 
property.option(
"min");
 
  203    *max = 
property.option(
"max");
 
  220        *max = KPROPERTY_MAX_PRECISE_DOUBLE;
 
  226double fixDoubleValue(
const QVariant &value, 
double min, 
double max, 
bool warn)
 
  230            kprWarning() << 
"Could not assign value" << value.
toDouble() << 
"smaller than minimum" << min
 
  231                         << 
"-- setting to" << min;
 
  237            kprWarning() << 
"Could not assign value" << value.
toDouble() << 
"larger than maximum" << max
 
  238                         << 
"-- setting to" << max;
 
  247    QVariant result = 
property.option(
"precision", KPROPERTY_DEFAULT_DOUBLE_VALUE_PRECISION);
 
  258        , d(new Private(prop))
 
  274    QString css = cssForSpinBox(
"QDoubleSpinBox", 
font(), itemHeight);
 
  275    KPropertyWidgetsFactory::setTopAndBottomBordersUsingStyleSheet(
this, css);
 
  280    doubleRangeValue(prop, &minVal, &maxVal);
 
  282    QVariant step = prop.
option(
"step", KPROPERTY_DEFAULT_DOUBLE_VALUE_STEP);
 
  286    const QVariant precision = precisionValue(prop);
 
  292    const KPropertyUtilsPrivate::ValueOptionsHandler options(prop);
 
  293    if (!options.minValueText.isNull()) {
 
  296    if (!options.prefix.isEmpty()) {
 
  299    if (!options.suffix.isEmpty()) {
 
 
  305KPropertyDoubleSpinBox::~KPropertyDoubleSpinBox()
 
  310void KPropertyDoubleSpinBox::resizeEvent( 
QResizeEvent * event )
 
  315void KPropertyDoubleSpinBox::setValue(
const QVariant& value)
 
  319    doubleRangeValue(*d->property, &minVal, &maxVal);
 
  323void KPropertyDoubleSpinBox::slotValueChanged(
double value)
 
  326    emit commitData(
this);
 
  331KPropertyIntSpinBoxDelegate::KPropertyIntSpinBoxDelegate()
 
  335QString KPropertyIntSpinBoxDelegate::propertyValueToString(
const KProperty* prop,
 
  339    const KPropertyUtilsPrivate::ValueOptionsHandler 
options(*prop);
 
  342    intRangeValue(*prop, &minVal, &maxVal);
 
  343    const int fixedValue = fixIntValue(prop->
value(), minVal.
toInt(), maxVal.
toInt(), 
false);
 
  346        return options.minValueText.toString();
 
  348    return options.valueWithPrefixAndSuffix(valueToString(fixedValue, locale), locale);
 
  356QWidget* KPropertyIntSpinBoxDelegate::createEditor( 
int type, 
QWidget *parent,
 
  361    KProperty *prop = KPropertyUtils::propertyForIndex(index);
 
  365    return new KPropertyIntSpinBox(*prop, parent, option.rect.height() - 2);
 
  370KPropertyDoubleSpinBoxDelegate::KPropertyDoubleSpinBoxDelegate()
 
  374QString KPropertyDoubleSpinBoxDelegate::propertyValueToString(
const KProperty* prop,
 
  380    const KPropertyUtilsPrivate::ValueOptionsHandler 
options(*prop);
 
  381    doubleRangeValue(*prop, &minVal, &maxVal);
 
  382    const double fixedValue = fixDoubleValue(prop->
value(), minVal.
toDouble(), maxVal.
toDouble(), 
false);
 
  385        return options.minValueText.toString();
 
  388    const QVariant precision = precisionValue(*prop);
 
  390        valueString = locale.
toString(fixedValue, 
'f', precision.
toInt());
 
  392        valueString = valueToString(fixedValue, locale);
 
  394    return options.valueWithPrefixAndSuffix(valueString, locale);
 
  402QWidget* KPropertyDoubleSpinBoxDelegate::createEditor( 
int type, 
QWidget *parent,
 
  407    KProperty *prop = KPropertyUtils::propertyForIndex(index);
 
  411    return new KPropertyDoubleSpinBox(*prop, parent, option.rect.height() - 2 - 1);
 
KPropertyDoubleSpinBox(const KProperty &prop, QWidget *parent, int itemHeight)
 
const KPropertyEditorCreatorOptions * options() const
Options for editor creating.
 
A delegate supporting Int and UInt types.
 
The base class representing a single property.
 
QVariant option(const char *name, const QVariant &defaultValue=QVariant()) const
Returns value of given option Option is set if returned value is not null. If there is no option for ...
 
virtual bool event(QEvent *event) override
 
virtual void resizeEvent(QResizeEvent *event) override
 
void setSpecialValueText(const QString &txt)
 
QDoubleSpinBox(QWidget *parent)
 
void setDecimals(int prec)
 
void setPrefix(const QString &prefix)
 
void setRange(double minimum, double maximum)
 
void setSingleStep(double val)
 
void setSuffix(const QString &suffix)
 
void setValue(double val)
 
void valueChanged(double d)
 
int pixelSize() const const
 
int pointSize() const const
 
void setAlignment(Qt::Alignment flag)
 
QString toString(QDate date, FormatType format) const const
 
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
T findChild(const QString &name, Qt::FindChildOptions options) const const
 
QObject * parent() const const
 
QString arg(Args &&... args) const const
 
QString fromLatin1(QByteArrayView str)
 
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
 
bool canConvert() const const
 
bool isNull() const const
 
bool isValid() const const
 
double toDouble(bool *ok) const const
 
int toInt(bool *ok) const const
 
qreal toReal(bool *ok) const const
 
void setContentsMargins(const QMargins &margins)