KProperty

rectedit.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2008-2015 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 "rectedit.h"
21
22#include <QRect>
23
24KPropertyRectDelegate::KPropertyRectDelegate()
25{
26}
27
28QString KPropertyRectDelegate::valueToString(const QVariant& value, const QLocale &locale) const
29{
30 const QRect r(value.toRect());
31 if (locale.language() == QLocale::C) {
32 return QString::fromLatin1("%1, %2, %3x%4").arg(r.x()).arg(r.y()).arg(r.width()).arg(r.height());
33 }
34 return QObject::tr("%1, %2, %3x%4", "Rectangle")
35 .arg(locale.toString(r.x()))
36 .arg(locale.toString(r.y()))
37 .arg(locale.toString(r.width()))
38 .arg(locale.toString(r.height()));
39}
40
41//------------
42
43KRectComposedProperty::KRectComposedProperty(KProperty *property)
45{
46 (void)new KProperty("x",
47 QVariant(), QObject::tr("X", "Property: X coordinate"),
48 QObject::tr("X Coordinate", "Property: X coordinate"), KProperty::Int, property);
49 (void)new KProperty("y",
50 QVariant(), QObject::tr("Y", "Property: Y coordinate"),
51 QObject::tr("Y Coordinate", "Property: Y coordinate"), KProperty::Int, property);
52 (void)new KProperty("width",
53 QVariant(), QObject::tr("Width", "Property: width of rectangle"),
54 QObject::tr("Width", "Property: width of rectangle"), KProperty::UInt, property);
55 (void)new KProperty("height",
56 QVariant(), QObject::tr("Height", "Property: height of rectangle"),
57 QObject::tr("Height", "Property: height of rectangle"), KProperty::UInt, property);
58}
59
60void KRectComposedProperty::setValue(KProperty *property,
61 const QVariant &value, KProperty::ValueOptions valueOptions)
62{
63 const QRect r( value.toRect() );
64 property->child("x")->setValue(r.x(), valueOptions);
65 property->child("y")->setValue(r.y(), valueOptions);
66 property->child("width")->setValue(r.width(), valueOptions);
67 property->child("height")->setValue(r.height(), valueOptions);
68}
69
70void KRectComposedProperty::childValueChanged(KProperty *child,
71 const QVariant &value, KProperty::ValueOptions valueOptions)
72{
73 QRect r( child->parent()->value().toRect() );
74
75 if (child->name() == "x")
76 r.moveLeft(value.toInt());
77 else if (child->name() == "y")
78 r.moveTop(value.toInt());
79 else if (child->name() == "width")
80 r.setWidth(value.toInt());
81 else if (child->name() == "height")
82 r.setHeight(value.toInt());
83
84 child->parent()->setValue(r, valueOptions);
85}
An interface for for composed property handlers.
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
Language language() const const
QString toString(QDate date, FormatType format) const const
QString tr(const char *sourceText, const char *disambiguation, int n)
QString arg(Args &&... args) const const
QString fromLatin1(QByteArrayView str)
int toInt(bool *ok) const const
QRect toRect() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:19:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.