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