KProperty

pointfedit.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
3 Copyright (C) 2004 Alexander Dymo <cloudtemple@mskat.net>
4 Copyright (C) 2008-2017 Jarosław Staniek <staniek@kde.org>
5 Copyright (C) 2010 Adam Pigg <adam@piggz.co.uk>
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
28KPropertyPointFDelegate::KPropertyPointFDelegate()
29{
30}
31
32QString 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
39QString 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
52KPointFComposedProperty::KPointFComposedProperty(KProperty *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
63void 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
71void 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}
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
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)
double toDouble(bool *ok) const const
QPointF toPointF() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:11:18 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.