KProperty

rectedit.cpp
1 /* This file is part of the KDE project
2  Copyright (C) 2008-2015 Jarosław Staniek <[email protected]>
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 
24 KPropertyRectDelegate::KPropertyRectDelegate()
25 {
26 }
27 
28 QString 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 
43 KRectComposedProperty::KRectComposedProperty(KProperty *property)
44  : KComposedPropertyInterface(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 
60 void 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 
70 void 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 }
QString toString(qlonglong i) const const
KProperty * parent() const
Definition: KProperty.cpp:673
QString tr(const char *sourceText, const char *disambiguation, int n)
void moveLeft(int x)
An interface for for composed property handlers.
int toInt(bool *ok) const const
QLocale::Language language() const const
QByteArray name() const
Definition: KProperty.cpp:324
The base class representing a single property.
Definition: KProperty.h:95
QVariant value() const
Definition: KProperty.cpp:394
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString fromLatin1(const char *str, int size)
QRect toRect() const const
bool setValue(const QVariant &value, ValueOptions options=ValueOptions())
Sets value of the property.
Definition: KProperty.cpp:405
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun Aug 9 2020 23:10:57 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.