File indexing completed on 2024-04-28 08:32:23
0001 /* This file is part of the KDE project 0002 Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr> 0003 Copyright (C) 2004 Alexander Dymo <cloudtemple@mskat.net> 0004 Copyright (C) 2008-2015 Jarosław Staniek <staniek@kde.org> 0005 0006 This library is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU Library General Public 0008 License as published by the Free Software Foundation; either 0009 version 2 of the License, or (at your option) any later version. 0010 0011 This library is distributed in the hope that it will be useful, 0012 but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 Library General Public License for more details. 0015 0016 You should have received a copy of the GNU Library General Public License 0017 along with this library; see the file COPYING.LIB. If not, write to 0018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0019 * Boston, MA 02110-1301, USA. 0020 */ 0021 0022 #include "pointedit.h" 0023 0024 #include <QPoint> 0025 0026 KPropertyPointDelegate::KPropertyPointDelegate() 0027 { 0028 } 0029 0030 QString KPropertyPointDelegate::valueToString(const QVariant& value, const QLocale &locale) const 0031 { 0032 const QPoint p(value.toPoint()); 0033 if (locale.language() == QLocale::C) { 0034 return QString::fromLatin1("%1, %2").arg(p.x()).arg(p.y()); 0035 } 0036 return QObject::tr("%1, %2", "Point") 0037 .arg(locale.toString(p.x())) 0038 .arg(locale.toString(p.y())); 0039 } 0040 0041 //------------ 0042 0043 KPointComposedProperty::KPointComposedProperty(KProperty *property) 0044 : KComposedPropertyInterface(property) 0045 { 0046 (void)new KProperty("x", 0047 QVariant(), QObject::tr("X", "Property: X coordinate"), 0048 QObject::tr("X Coordinate", "Property: X coordinate"), KProperty::Int, property); 0049 (void)new KProperty("y", 0050 QVariant(), QObject::tr("Y", "Property: Y coordinate"), 0051 QObject::tr("Y Coordinate", "Property: Y coordinate"), KProperty::Int, property); 0052 } 0053 0054 void KPointComposedProperty::setValue(KProperty *property, 0055 const QVariant &value, KProperty::ValueOptions valueOptions) 0056 { 0057 const QPoint p( value.toPoint() ); 0058 property->child("x")->setValue(p.x(), valueOptions); 0059 property->child("y")->setValue(p.y(), valueOptions); 0060 } 0061 0062 void KPointComposedProperty::childValueChanged(KProperty *child, 0063 const QVariant &value, KProperty::ValueOptions valueOptions) 0064 { 0065 QPoint p( child->parent()->value().toPoint() ); 0066 0067 if (child->name() == "x") 0068 p.setX(value.toInt()); 0069 else if (child->name() == "y") 0070 p.setY(value.toInt()); 0071 0072 child->parent()->setValue(p, valueOptions); 0073 }