KProperty

pointedit.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-2015 Jarosław Staniek <staniek@kde.org>
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
26KPropertyPointDelegate::KPropertyPointDelegate()
27{
28}
29
30QString 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
43KPointComposedProperty::KPointComposedProperty(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}
53
54void 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
62void 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}
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
QLocale::Language language() const const
QString toString(qlonglong i) const const
QString tr(const char *sourceText, const char *disambiguation, int n)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString fromLatin1(const char *str, int size)
int toInt(bool *ok) const const
QPoint toPoint() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sun Feb 25 2024 18:41:55 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.