KProperty

sizeedit.cpp
1 /* This file is part of the KDE project
2  Copyright (C) 2008-2015 Jarosław Staniek <[email protected]>
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 
24 KPropertySizeDelegate::KPropertySizeDelegate()
25 {
26 }
27 
28 QString 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 
41 KSizeComposedProperty::KSizeComposedProperty(KProperty *property)
42  : KComposedPropertyInterface(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 
50 void 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 
58 void 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 }
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
void setWidth(int width)
QLocale::Language language() const const
QByteArray name() const
Definition: KProperty.cpp:324
QSize toSize() const const
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
QString fromLatin1(const char *str, int size)
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 Wed Aug 12 2020 23:03:00 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.