KProperty

sizeedit.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2008-2015 Jarosław Staniek <staniek@kde.org>
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 "sizeedit.h"
21
22#include <QSize>
23
24KPropertySizeDelegate::KPropertySizeDelegate()
25{
26}
27
28QString KPropertySizeDelegate::valueToString(const QVariant& value, const QLocale &locale) const
29{
30 const QSize s(value.toSize());
31 if (locale.language() == QLocale::C) {
32 return QString::fromLatin1("%1x%2").arg(s.width()).arg(s.height());
33 }
34 return QObject::tr("%1x%2", "Size")
35 .arg(locale.toString(s.width()))
36 .arg(locale.toString(s.height()));
37}
38
39//------------
40
41KSizeComposedProperty::KSizeComposedProperty(KProperty *property)
43{
44 (void)new KProperty("width",
45 QVariant(), QObject::tr("Width"), QObject::tr("Width"), KProperty::UInt, property);
46 (void)new KProperty("height",
47 QVariant(), QObject::tr("Height"), QObject::tr("Height"), KProperty::UInt, property);
48}
49
50void KSizeComposedProperty::setValue(KProperty *property,
51 const QVariant &value, KProperty::ValueOptions valueOptions)
52{
53 const QSize s( value.toSize() );
54 property->child("width")->setValue(s.width(), valueOptions);
55 property->child("height")->setValue(s.height(), valueOptions);
56}
57
58void KSizeComposedProperty::childValueChanged(KProperty *child,
59 const QVariant &value, KProperty::ValueOptions valueOptions)
60{
61 QSize s( child->parent()->value().toSize() );
62 if (child->name() == "width")
63 s.setWidth(value.toInt());
64 else if (child->name() == "height")
65 s.setHeight(value.toInt());
66
67 child->parent()->setValue(s, valueOptions);
68}
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
QSize toSize() 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.