KProperty

KPropertyRectFEditor.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2015-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 "KPropertyRectFEditor.h"
21#include "KPropertyUtils_p.h"
22
23#include <QRectF>
24
25KPropertyRectFDelegate::KPropertyRectFDelegate()
26{
27}
28
29QString KPropertyRectFDelegate::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 KPropertyRectFDelegate::valueToString(const QVariant& value, const QLocale &locale) const
37{
38 const QRectF r(value.toRectF());
39 if (locale.language() == QLocale::C) {
40 return QString::fromLatin1("%1, %2, %3x%4").arg(r.x()).arg(r.y()).arg(r.width()).arg(r.height());
41 }
42 return QObject::tr("%1, %2, %3x%4", "Rectangle")
43 .arg(locale.toString(r.x()))
44 .arg(locale.toString(r.y()))
45 .arg(locale.toString(r.width()))
46 .arg(locale.toString(r.height()));
47}
48
49//------------
50
51KRectFComposedProperty::KRectFComposedProperty(KProperty *property)
53{
54 (void)new KProperty("x",
55 QVariant(), QObject::tr("X", "Property: X coordinate"),
56 QObject::tr("X Coordinate", "Property: X coordinate"), KProperty::Double, property);
57 (void)new KProperty("y",
58 QVariant(), QObject::tr("Y", "Property: Y coordinate"),
59 QObject::tr("Y Coordinate", "Property: Y coordinate"), KProperty::Double, property);
60 (void)new KProperty("width",
61 QVariant(), QObject::tr("Width", "Property: width of rectangle"),
62 QObject::tr("Width", "Property: width of rectangle"), KProperty::Double, property);
63 (void)new KProperty("height",
64 QVariant(), QObject::tr("Height", "Property: height of rectangle"),
65 QObject::tr("Height", "Property: height of rectangle"), KProperty::Double, property);
66}
67
68void KRectFComposedProperty::setValue(KProperty *property,
69 const QVariant &value, KProperty::ValueOptions valueOptions)
70{
71 const QRectF r(value.toRectF());
72 property->child("x")->setValue(r.x(), valueOptions);
73 property->child("y")->setValue(r.y(), valueOptions);
74 property->child("width")->setValue(r.width(), valueOptions);
75 property->child("height")->setValue(r.height(), valueOptions);
76}
77
78void KRectFComposedProperty::childValueChanged(KProperty *child, const QVariant &value,
79 KProperty::ValueOptions valueOptions)
80{
81 QRectF r(child->parent()->value().toRectF());
82
83 if (child->name() == "x")
84 r.moveLeft(value.toReal());
85 else if (child->name() == "y")
86 r.moveTop(value.toReal());
87 else if (child->name() == "width")
88 r.setWidth(value.toReal());
89 else if (child->name() == "height")
90 r.setHeight(value.toReal());
91
92 child->parent()->setValue(r, valueOptions);
93}
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)
qreal toReal(bool *ok) const const
QRectF toRectF() 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.