KProperty

pointfedit.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-2017 Jarosław Staniek <[email protected]>
5  Copyright (C) 2010 Adam Pigg <[email protected]>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21 */
22 
23 #include "pointfedit.h"
24 #include "KPropertyUtils_p.h"
25 
26 #include <QPointF>
27 
28 KPropertyPointFDelegate::KPropertyPointFDelegate()
29 {
30 }
31 
32 QString KPropertyPointFDelegate::propertyValueToString(const KProperty *property,
33  const QLocale &locale) const
34 {
35  const KPropertyUtilsPrivate::ValueOptionsHandler options(*property);
36  return options.valueWithPrefixAndSuffix(valueToString(property->value(), locale), locale);
37 }
38 
39 QString KPropertyPointFDelegate::valueToString(const QVariant& value, const QLocale &locale) const
40 {
41  const QPointF p(value.toPointF());
42  if (locale.language() == QLocale::C) {
43  return QString::fromLatin1("%1, %2").arg(p.x()).arg(p.y());
44  }
45  return QObject::tr("%1, %2", "Point")
46  .arg(locale.toString(p.x()))
47  .arg(locale.toString(p.y()));
48 }
49 
50 //------------
51 
52 KPointFComposedProperty::KPointFComposedProperty(KProperty *property)
53  : KComposedPropertyInterface(property)
54 {
55  (void)new KProperty("x",
56  QVariant(), QObject::tr("X", "Property: X coordinate"),
57  QObject::tr("X Coordinate", "Property: X coordinate"), KProperty::Double, property);
58  (void)new KProperty("y",
59  QVariant(), QObject::tr("Y", "Property: Y coordinate"),
60  QObject::tr("Y Coordinate", "Property: Y coordinate"), KProperty::Double, property);
61 }
62 
63 void KPointFComposedProperty::setValue(KProperty *property,
64  const QVariant &value, KProperty::ValueOptions valueOptions)
65 {
66  const QPointF p( value.toPointF() );
67  property->child("x")->setValue(p.x(), valueOptions);
68  property->child("y")->setValue(p.y(), valueOptions);
69 }
70 
71 void KPointFComposedProperty::childValueChanged(KProperty *child,
72  const QVariant &value, KProperty::ValueOptions valueOptions)
73 {
74  QPointF p( child->parent()->value().toPointF() );
75 
76  if (child->name() == "x")
77  p.setX(value.toDouble());
78  else if (child->name() == "y")
79  p.setY(value.toDouble());
80 
81  child->parent()->setValue(p, valueOptions);
82 }
QPointF toPointF() const const
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.
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(qreal x)
QString fromLatin1(const char *str, int size)
double toDouble(bool *ok) 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.