KProperty

sizefedit.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2008-2017 Jarosław Staniek <staniek@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "sizefedit.h"
21#include "KPropertyUtils_p.h"
22
23#include <QSize>
24
25KPropertySizeFDelegate::KPropertySizeFDelegate()
26{
27}
28
29QString KPropertySizeFDelegate::propertyValueToString(const KProperty *property,
30 const QLocale &locale) const
31{
32 const KPropertyUtilsPrivate::ValueOptionsHandler options(*property);
33 return options.valueWithPrefixAndSuffix(valueToString(property->value(), locale), locale);
34}
35
36QString KPropertySizeFDelegate::valueToString(const QVariant& value, const QLocale &locale) const
37{
38 const QSizeF s(value.toSizeF());
39 if (locale.language() == QLocale::C) {
40 return QString::fromLatin1("%1x%2").arg(s.width()).arg(s.height());
41 }
42 return QObject::tr("%1x%2", "Size")
43 .arg(locale.toString(s.width()))
44 .arg(locale.toString(s.height()));
45}
46
47//------------
48
49KSizeFComposedProperty::KSizeFComposedProperty(KProperty *property)
51{
52 (void)new KProperty("width",
53 QVariant(), QObject::tr("Width"), QObject::tr("Width"), KProperty::Double, property);
54 (void)new KProperty("height",
55 QVariant(), QObject::tr("Height"), QObject::tr("Height"), KProperty::Double, property);
56}
57
58void KSizeFComposedProperty::setValue(KProperty *property,
59 const QVariant &value, KProperty::ValueOptions valueOptions)
60{
61 const QSizeF s( value.toSizeF() );
62 property->child("width")->setValue(s.width(), valueOptions);
63 property->child("height")->setValue(s.height(), valueOptions);
64}
65
66void KSizeFComposedProperty::childValueChanged(KProperty *child,
67 const QVariant &value, KProperty::ValueOptions valueOptions)
68{
69 QSizeF s( child->parent()->value().toSizeF() );
70 if (child->name() == "width")
71 s.setWidth(value.toDouble());
72 else if (child->name() == "height")
73 s.setHeight(value.toDouble());
74
75 child->parent()->setValue(s, valueOptions);
76}
An interface for for composed property handlers.
const KPropertyEditorCreatorOptions * options() const
Options for editor creating.
The base class representing a single property.
Definition KProperty.h:96
QVariant value() const
bool setValue(const QVariant &value, ValueOptions options=ValueOptions())
Sets value of the property.
QByteArray name() const
KProperty * parent() const
QLocale::Language language() const const
QString toString(qlonglong i) const const
QString tr(const char *sourceText, const char *disambiguation, int n)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString fromLatin1(const char *str, int size)
double toDouble(bool *ok) const const
QSizeF toSizeF() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sun Feb 25 2024 18:41:55 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.