File indexing completed on 2024-04-21 04:41:02
0001 /* This file is part of the KDE project 0002 Copyright (C) 2008-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 "sizefedit.h" 0021 #include "KPropertyUtils_p.h" 0022 0023 #include <QSize> 0024 0025 KPropertySizeFDelegate::KPropertySizeFDelegate() 0026 { 0027 } 0028 0029 QString KPropertySizeFDelegate::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 KPropertySizeFDelegate::valueToString(const QVariant& value, const QLocale &locale) const 0037 { 0038 const QSizeF s(value.toSizeF()); 0039 if (locale.language() == QLocale::C) { 0040 return QString::fromLatin1("%1x%2").arg(s.width()).arg(s.height()); 0041 } 0042 return QObject::tr("%1x%2", "Size") 0043 .arg(locale.toString(s.width())) 0044 .arg(locale.toString(s.height())); 0045 } 0046 0047 //------------ 0048 0049 KSizeFComposedProperty::KSizeFComposedProperty(KProperty *property) 0050 : KComposedPropertyInterface(property) 0051 { 0052 (void)new KProperty("width", 0053 QVariant(), QObject::tr("Width"), QObject::tr("Width"), KProperty::Double, property); 0054 (void)new KProperty("height", 0055 QVariant(), QObject::tr("Height"), QObject::tr("Height"), KProperty::Double, property); 0056 } 0057 0058 void KSizeFComposedProperty::setValue(KProperty *property, 0059 const QVariant &value, KProperty::ValueOptions valueOptions) 0060 { 0061 const QSizeF s( value.toSizeF() ); 0062 property->child("width")->setValue(s.width(), valueOptions); 0063 property->child("height")->setValue(s.height(), valueOptions); 0064 } 0065 0066 void KSizeFComposedProperty::childValueChanged(KProperty *child, 0067 const QVariant &value, KProperty::ValueOptions valueOptions) 0068 { 0069 QSizeF s( child->parent()->value().toSizeF() ); 0070 if (child->name() == "width") 0071 s.setWidth(value.toDouble()); 0072 else if (child->name() == "height") 0073 s.setHeight(value.toDouble()); 0074 0075 child->parent()->setValue(s, valueOptions); 0076 }