KProperty

pointedit.cpp
1 /* This file is part of the KDE project
2  Copyright (C) 2004 Cedric Pasteur <[email protected]>
3  Copyright (C) 2004 Alexander Dymo <[email protected]>
4  Copyright (C) 2008-2015 Jarosław Staniek <[email protected]>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20 */
21 
22 #include "pointedit.h"
23 
24 #include <QPoint>
25 
26 KPropertyPointDelegate::KPropertyPointDelegate()
27 {
28 }
29 
30 QString KPropertyPointDelegate::valueToString(const QVariant& value, const QLocale &locale) const
31 {
32  const QPoint p(value.toPoint());
33  if (locale.language() == QLocale::C) {
34  return QString::fromLatin1("%1, %2").arg(p.x()).arg(p.y());
35  }
36  return QObject::tr("%1, %2", "Point")
37  .arg(locale.toString(p.x()))
38  .arg(locale.toString(p.y()));
39 }
40 
41 //------------
42 
43 KPointComposedProperty::KPointComposedProperty(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 }
53 
54 void KPointComposedProperty::setValue(KProperty *property,
55  const QVariant &value, KProperty::ValueOptions valueOptions)
56 {
57  const QPoint p( value.toPoint() );
58  property->child("x")->setValue(p.x(), valueOptions);
59  property->child("y")->setValue(p.y(), valueOptions);
60 }
61 
62 void KPointComposedProperty::childValueChanged(KProperty *child,
63  const QVariant &value, KProperty::ValueOptions valueOptions)
64 {
65  QPoint p( child->parent()->value().toPoint() );
66 
67  if (child->name() == "x")
68  p.setX(value.toInt());
69  else if (child->name() == "y")
70  p.setY(value.toInt());
71 
72  child->parent()->setValue(p, valueOptions);
73 }
QString toString(qlonglong i) const const
KProperty * parent() const
Definition: KProperty.cpp:673
QString tr(const char *sourceText, const char *disambiguation, int n)
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
void setX(int x)
QString fromLatin1(const char *str, int size)
QPoint toPoint() 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 Tue Aug 4 2020 23:02:03 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.