File indexing completed on 2024-03-24 04:43:39
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-2017 Jarosław Staniek <staniek@kde.org> 0005 Copyright (C) 2010 Adam Pigg <adam@piggz.co.uk> 0006 0007 This library is free software; you can redistribute it and/or 0008 modify it under the terms of the GNU Library General Public 0009 License as published by the Free Software Foundation; either 0010 version 2 of the License, or (at your option) any later version. 0011 0012 This library is distributed in the hope that it will be useful, 0013 but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 Library General Public License for more details. 0016 0017 You should have received a copy of the GNU Library General Public License 0018 along with this library; see the file COPYING.LIB. If not, write to 0019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0020 * Boston, MA 02110-1301, USA. 0021 */ 0022 0023 #include "pointfedit.h" 0024 #include "KPropertyUtils_p.h" 0025 0026 #include <QPointF> 0027 0028 KPropertyPointFDelegate::KPropertyPointFDelegate() 0029 { 0030 } 0031 0032 QString KPropertyPointFDelegate::propertyValueToString(const KProperty *property, 0033 const QLocale &locale) const 0034 { 0035 const KPropertyUtilsPrivate::ValueOptionsHandler options(*property); 0036 return options.valueWithPrefixAndSuffix(valueToString(property->value(), locale), locale); 0037 } 0038 0039 QString KPropertyPointFDelegate::valueToString(const QVariant& value, const QLocale &locale) const 0040 { 0041 const QPointF p(value.toPointF()); 0042 if (locale.language() == QLocale::C) { 0043 return QString::fromLatin1("%1, %2").arg(p.x()).arg(p.y()); 0044 } 0045 return QObject::tr("%1, %2", "Point") 0046 .arg(locale.toString(p.x())) 0047 .arg(locale.toString(p.y())); 0048 } 0049 0050 //------------ 0051 0052 KPointFComposedProperty::KPointFComposedProperty(KProperty *property) 0053 : KComposedPropertyInterface(property) 0054 { 0055 (void)new KProperty("x", 0056 QVariant(), QObject::tr("X", "Property: X coordinate"), 0057 QObject::tr("X Coordinate", "Property: X coordinate"), KProperty::Double, property); 0058 (void)new KProperty("y", 0059 QVariant(), QObject::tr("Y", "Property: Y coordinate"), 0060 QObject::tr("Y Coordinate", "Property: Y coordinate"), KProperty::Double, property); 0061 } 0062 0063 void KPointFComposedProperty::setValue(KProperty *property, 0064 const QVariant &value, KProperty::ValueOptions valueOptions) 0065 { 0066 const QPointF p( value.toPointF() ); 0067 property->child("x")->setValue(p.x(), valueOptions); 0068 property->child("y")->setValue(p.y(), valueOptions); 0069 } 0070 0071 void KPointFComposedProperty::childValueChanged(KProperty *child, 0072 const QVariant &value, KProperty::ValueOptions valueOptions) 0073 { 0074 QPointF p( child->parent()->value().toPointF() ); 0075 0076 if (child->name() == "x") 0077 p.setX(value.toDouble()); 0078 else if (child->name() == "y") 0079 p.setY(value.toDouble()); 0080 0081 child->parent()->setValue(p, valueOptions); 0082 }