File indexing completed on 2024-04-21 04:41:01
0001 /* This file is part of the KDE project 0002 Copyright (C) 2015-2017 Jarosław Staniek <staniek@kde.org> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "KPropertyRectFEditor.h" 0021 #include "KPropertyUtils_p.h" 0022 0023 #include <QRectF> 0024 0025 KPropertyRectFDelegate::KPropertyRectFDelegate() 0026 { 0027 } 0028 0029 QString KPropertyRectFDelegate::propertyValueToString(const KProperty *property, 0030 const QLocale &locale) const 0031 { 0032 const KPropertyUtilsPrivate::ValueOptionsHandler options(*property); 0033 return options.valueWithPrefixAndSuffix(valueToString(property->value(), locale), locale); 0034 } 0035 0036 QString KPropertyRectFDelegate::valueToString(const QVariant& value, const QLocale &locale) const 0037 { 0038 const QRectF r(value.toRectF()); 0039 if (locale.language() == QLocale::C) { 0040 return QString::fromLatin1("%1, %2, %3x%4").arg(r.x()).arg(r.y()).arg(r.width()).arg(r.height()); 0041 } 0042 return QObject::tr("%1, %2, %3x%4", "Rectangle") 0043 .arg(locale.toString(r.x())) 0044 .arg(locale.toString(r.y())) 0045 .arg(locale.toString(r.width())) 0046 .arg(locale.toString(r.height())); 0047 } 0048 0049 //------------ 0050 0051 KRectFComposedProperty::KRectFComposedProperty(KProperty *property) 0052 : KComposedPropertyInterface(property) 0053 { 0054 (void)new KProperty("x", 0055 QVariant(), QObject::tr("X", "Property: X coordinate"), 0056 QObject::tr("X Coordinate", "Property: X coordinate"), KProperty::Double, property); 0057 (void)new KProperty("y", 0058 QVariant(), QObject::tr("Y", "Property: Y coordinate"), 0059 QObject::tr("Y Coordinate", "Property: Y coordinate"), KProperty::Double, property); 0060 (void)new KProperty("width", 0061 QVariant(), QObject::tr("Width", "Property: width of rectangle"), 0062 QObject::tr("Width", "Property: width of rectangle"), KProperty::Double, property); 0063 (void)new KProperty("height", 0064 QVariant(), QObject::tr("Height", "Property: height of rectangle"), 0065 QObject::tr("Height", "Property: height of rectangle"), KProperty::Double, property); 0066 } 0067 0068 void KRectFComposedProperty::setValue(KProperty *property, 0069 const QVariant &value, KProperty::ValueOptions valueOptions) 0070 { 0071 const QRectF r(value.toRectF()); 0072 property->child("x")->setValue(r.x(), valueOptions); 0073 property->child("y")->setValue(r.y(), valueOptions); 0074 property->child("width")->setValue(r.width(), valueOptions); 0075 property->child("height")->setValue(r.height(), valueOptions); 0076 } 0077 0078 void KRectFComposedProperty::childValueChanged(KProperty *child, const QVariant &value, 0079 KProperty::ValueOptions valueOptions) 0080 { 0081 QRectF r(child->parent()->value().toRectF()); 0082 0083 if (child->name() == "x") 0084 r.moveLeft(value.toReal()); 0085 else if (child->name() == "y") 0086 r.moveTop(value.toReal()); 0087 else if (child->name() == "width") 0088 r.setWidth(value.toReal()); 0089 else if (child->name() == "height") 0090 r.setHeight(value.toReal()); 0091 0092 child->parent()->setValue(r, valueOptions); 0093 }