diff --git a/examples/window.h b/examples/window.h --- a/examples/window.h +++ b/examples/window.h @@ -25,6 +25,9 @@ #include #include +class QCheckBox; +class KPropertyEditorView; + /*! @internal * @short KPropertyExample application's main window */ class Window : public QWidget @@ -34,6 +37,10 @@ Window(); virtual ~Window(); +protected Q_SLOTS: + void showGrid(int state); + void showFrame(int state); + private: void parseCommandLine(); @@ -43,6 +50,9 @@ QCommandLineOption m_fontSizeOption; QCommandLineOption m_propertyOption; QCommandLineOption m_roOption; + KPropertyEditorView *m_editorView; + QCheckBox *m_showGrid; + QCheckBox *m_showFrame; }; #endif diff --git a/examples/window.cpp b/examples/window.cpp --- a/examples/window.cpp +++ b/examples/window.cpp @@ -1,6 +1,6 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur - Copyright (C) 2008-2009 Jarosław Staniek + Copyright (C) 2008-2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -34,6 +34,8 @@ #include #include #include +#include +#include Window::Window() : QWidget() @@ -82,7 +84,8 @@ m_set.addProperty(new KProperty("Int", 2, "Int"), group); } if (singleProperty.isEmpty() || singleProperty=="Double") { - m_set.addProperty(new KProperty("Double", 3.1415, "Double"), group); + m_set.addProperty(p = new KProperty("Double", 3.14159, "Double"), group); + p->setOption("precision", 4); // will round to 3.1416 } if (singleProperty.isEmpty() || singleProperty=="Bool") { m_set.addProperty(new KProperty("Bool", QVariant(true), "Bool"), group); @@ -160,7 +163,8 @@ p->setIcon("kpaint"); } if (singleProperty.isEmpty() || singleProperty=="Font") { - QFont myFont("Times", 12); + QFont myFont("Times New Roman", 12); + myFont.setUnderline(true); m_set.addProperty(p = new KProperty("Font", myFont, "Font"), group); p->setIcon("fonts"); } @@ -184,11 +188,22 @@ // qDebug() << m_set.groupNames(); QVBoxLayout *lyr = new QVBoxLayout(this); - KPropertyEditorView *editorView = new KPropertyEditorView(this); - lyr->addWidget(editorView); - editorView->changeSet(&m_set, KPropertyEditorView::ExpandChildItems); + m_editorView = new KPropertyEditorView(this); + lyr->addWidget(m_editorView); + m_editorView->changeSet(&m_set, KPropertyEditorView::ExpandChildItems); + m_showGrid = new QCheckBox("Show grid"); + m_showGrid->setChecked(true); + connect(m_showGrid, &QCheckBox::stateChanged, this, &Window::showGrid); + QHBoxLayout *hlyr = new QHBoxLayout; + lyr->addLayout(hlyr); + hlyr->addWidget(m_showGrid); + m_showFrame = new QCheckBox("Show frame"); + m_showFrame->setChecked(true); + connect(m_showFrame, &QCheckBox::stateChanged, this, &Window::showFrame); + hlyr->addWidget(m_showFrame); + hlyr->addStretch(1); resize(400, qApp->desktop()->height() - 200); - editorView->setFocus(); + m_editorView->setFocus(); qDebug() << m_set; } @@ -204,3 +219,14 @@ m_parser.addOption(m_roOption); m_parser.process(*(QCoreApplication::instance())); } + +void Window::showGrid(int state) +{ + m_editorView->setGridLineColor( + state == Qt::Checked ? KPropertyEditorView::defaultGridLineColor() : QColor()); +} + +void Window::showFrame(int state) +{ + m_editorView->setFrameStyle(state == Qt::Checked ? QFrame::Box : QFrame::NoFrame); +} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,6 +6,7 @@ KPropertySet.cpp KPropertyUnit_p.cpp KPropertyFactory.cpp + KPropertyCoreUtils.cpp kproperty_debug.cpp ) @@ -15,6 +16,7 @@ set(kpropertywidgets_LIB_SRCS editors/utils.cpp editors/booledit.cpp + editors/coloredit.cpp editors/combobox.cpp editors/cursoredit.cpp editors/dateedit.cpp @@ -25,6 +27,7 @@ editors/pointedit.cpp editors/pointfedit.cpp editors/rectedit.cpp + editors/KPropertyRectFEditor.cpp editors/sizeedit.cpp editors/sizefedit.cpp editors/sizepolicyedit.cpp @@ -47,12 +50,6 @@ KPropertyLineStyleItemDelegate_p.cpp ) - if(KPROPERTY_KF) - list(APPEND kpropertywidgets_LIB_SRCS - editors/coloredit.cpp - ) - endif() - ecm_create_qm_loader(kpropertywidgets_LIB_SRCS kpropertywidgets_qt) set(kpropertywidgets_INCLUDE_DIRS diff --git a/src/KDefaultPropertyFactory.cpp b/src/KDefaultPropertyFactory.cpp --- a/src/KDefaultPropertyFactory.cpp +++ b/src/KDefaultPropertyFactory.cpp @@ -1,5 +1,5 @@ /* This file is part of the KDE project - Copyright (C) 2008 Jarosław Staniek + Copyright (C) 2008-2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -22,6 +22,7 @@ /* #include "customproperty.h"*/ #include "editors/booledit.h" +#include "editors/coloredit.h" #include "editors/combobox.h" #include "editors/cursoredit.h" #include "editors/dateedit.h" @@ -32,6 +33,7 @@ #include "editors/pointfedit.h" #include "editors/fontedit.h" #include "editors/rectedit.h" +#include "editors/KPropertyRectFEditor.h" #include "editors/sizeedit.h" #include "editors/sizefedit.h" #include "editors/sizepolicyedit.h" @@ -42,38 +44,34 @@ // #include "symbolcombo.h" #include "editors/timeedit.h" // #include "urledit.h" -#ifdef KPROPERTY_KF -# include "editors/coloredit.h" -#endif KDefaultPropertyFactory::KDefaultPropertyFactory() : KPropertyWidgetsFactory() { addEditor( KProperty::Bool, new KPropertyBoolDelegate ); +//! @todo addEditor( KProperty::ByteArray, new KPropertyByteArrayDelegate ); + addEditor( KProperty::Color, new KPropertyColorComboDelegate ); addEditor( KProperty::Cursor, new KPropertyCursorDelegate ); addEditor( KProperty::Date, new KPropertyDateDelegate ); addEditor( KProperty::DateTime, new KPropertyDateTimeDelegate ); addEditor( KProperty::Double, new KPropertyDoubleSpinBoxDelegate ); addEditor( KProperty::Font, new KPropertyFontDelegate ); addEditor( KProperty::Int, new KPropertyIntSpinBoxDelegate ); addEditor( KProperty::LineStyle, new KPropertyLineStyleComboDelegate ); -//! @todo addEditor( KProperty::LongLong, new LongLongSpinBoxDelegate ); + addEditor( KProperty::LongLong, new KPropertyIntSpinBoxDelegate ); //!< @todo add more specialized delegate addEditor( KProperty::Pixmap, new KPropertyPixmapDelegate ); addEditor( KProperty::Point, new KPropertyPointDelegate ); addEditor( KProperty::PointF, new KPropertyPointFDelegate ); addEditor( KProperty::Rect, new KPropertyRectDelegate ); -//! @todo addEditor( KProperty::RectF, new RectFDelegate ); + addEditor( KProperty::RectF, new KPropertyRectFDelegate ); addEditor( KProperty::Size, new KPropertySizeDelegate ); addEditor( KProperty::SizeF, new KPropertySizeFDelegate ); addEditor( KProperty::SizePolicy, new KPropertySizePolicyDelegate ); addEditor( KProperty::String, new KPropertyStringDelegate ); addEditor( KProperty::Time, new KPropertyTimeDelegate ); -//! @todo addEditor( KProperty::UInt, new IntSpinBoxDelegate ); -//! @todo addEditor( KProperty::ULongLong, new LongLongSpinBoxDelegate ); + addEditor( KProperty::UInt, new KPropertyIntSpinBoxDelegate ); //!< @todo add more specialized delegate + addEditor( KProperty::ULongLong, new KPropertyIntSpinBoxDelegate ); //!< @todo add more specialized delegate addEditor( KProperty::ValueFromList, new KPropertyComboBoxDelegate ); -#ifdef KPROPERTY_KF - addEditor( KProperty::Color, new KPropertyColorComboDelegate ); -#endif } KDefaultPropertyFactory::~KDefaultPropertyFactory() diff --git a/src/KPropertyUtils.h b/src/KPropertyCoreUtils.cpp copy from src/KPropertyUtils.h copy to src/KPropertyCoreUtils.cpp --- a/src/KPropertyUtils.h +++ b/src/KPropertyCoreUtils.cpp @@ -1,5 +1,5 @@ /* This file is part of the KDE project - Copyright (C) 2006-2008 Jarosław Staniek + Copyright (C) 2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -17,28 +17,23 @@ * Boston, MA 02110-1301, USA. */ -#ifndef KPROPERTY_UTILS_H -#define KPROPERTY_UTILS_H +#include "KPropertyCoreUtils_p.h" -#include "kpropertywidgets_export.h" +#include -#include - -//! @short A container widget that can be used to split information into hideable sections -//! for a property editor-like panes. -class KPROPERTYWIDGETS_EXPORT KPropertyGroupWidget : public QWidget +//! @internal Needed by keyForEnumValue() to get access to staticQtMetaObject +struct StaticQtMetaObject : public QObject { -public: - KPropertyGroupWidget(const QString& title, QWidget* parent); - ~KPropertyGroupWidget(); - - void setContents(QWidget* contents); - -protected: - virtual bool event(QEvent * e); - - class Private; - Private * const d; + static inline const QMetaObject& get() {return staticQtMetaObject;} }; -#endif +QString KPropertyUtils::keyForEnumValue(const char *enumName, int enumIndex) +{ + const QMetaObject& mo = StaticQtMetaObject::get(); + const int index = mo.indexOfEnumerator(enumName); + if (index < 0) { + return QString(); + } + QMetaEnum me = mo.enumerator(index); + return QString::fromLatin1(me.valueToKey(enumIndex)); +} diff --git a/src/KPropertyUtils_p.h b/src/KPropertyCoreUtils_p.h copy from src/KPropertyUtils_p.h copy to src/KPropertyCoreUtils_p.h --- a/src/KPropertyUtils_p.h +++ b/src/KPropertyCoreUtils_p.h @@ -1,5 +1,5 @@ /* This file is part of the KDE project - Copyright (C) 2010 Jarosław Staniek + Copyright (C) 2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -17,15 +17,18 @@ * Boston, MA 02110-1301, USA. */ -#ifndef KPROPERTY_UTILS_P_H -#define KPROPERTY_UTILS_P_H +#ifndef KPROPERTYCORE_UTILS_P_H +#define KPROPERTYCORE_UTILS_P_H -#include +#include "kpropertycore_export.h" +#include namespace KPropertyUtils { -QColor contrastColor(const QColor& c); +//! @return key for enum value with @a enumIndex of enum @a enumName +//! Example call: keyForEnumValue("CursorShape", Qt::WaitCursor) returns "WaitCursor". +KPROPERTYCORE_EXPORT QString keyForEnumValue(const char *enumName, int enumIndex); } diff --git a/src/KPropertyEditorDataModel.cpp b/src/KPropertyEditorDataModel.cpp --- a/src/KPropertyEditorDataModel.cpp +++ b/src/KPropertyEditorDataModel.cpp @@ -128,7 +128,7 @@ return prop->value(); } else if (role == Qt::DisplayRole) { - return KPropertyWidgetsFactoryManager::self()->convertValueToText(prop); + return KPropertyFactoryManager::self()->propertyValueToLocalizedString(prop); } } return QVariant(); diff --git a/src/KPropertyEditorView.h b/src/KPropertyEditorView.h --- a/src/KPropertyEditorView.h +++ b/src/KPropertyEditorView.h @@ -112,7 +112,7 @@ (as if the user had pressed Enter key). */ void acceptInput(); - //! Sets grid line color + //! Sets color of grid lines. Use invalid color QColor() to hide grid lines. void setGridLineColor(const QColor& color); Q_SIGNALS: diff --git a/src/KPropertyEditorView.cpp b/src/KPropertyEditorView.cpp --- a/src/KPropertyEditorView.cpp +++ b/src/KPropertyEditorView.cpp @@ -23,6 +23,7 @@ #include "KPropertySet.h" #include "KPropertyWidgetsFactory.h" #include "kproperty_debug.h" +#include "KPropertyUtils_p.h" #include #include @@ -75,7 +76,7 @@ class ItemDelegate : public QItemDelegate { public: - explicit ItemDelegate(QWidget *parent); + explicit ItemDelegate(KPropertyEditorView *parent); virtual ~ItemDelegate(); virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; @@ -86,7 +87,7 @@ mutable QPointer m_currentEditor; }; -ItemDelegate::ItemDelegate(QWidget *parent) +ItemDelegate::ItemDelegate(KPropertyEditorView *parent) : QItemDelegate(parent) { } @@ -113,7 +114,10 @@ const QModelIndex &index) const { QStyleOptionViewItem alteredOption(option); - alteredOption.rect.setTop(alteredOption.rect.top() + 1); + const QColor gridLineColor(qobject_cast(parent())->gridLineColor()); + if (gridLineColor.isValid()) { + alteredOption.rect.setTop(alteredOption.rect.top() + 1); + } painter->save(); QRect r(option.rect); const KPropertyEditorDataModel *editorModel = dynamic_cast(index.model()); @@ -174,13 +178,16 @@ // y1 + 1 + (alteredOption.rect.height() - revertIcon.height()) / 2, revertIcon); } - QColor gridLineColor( dynamic_cast(painter->device()) ? - dynamic_cast(painter->device())->gridLineColor() - : KPropertyEditorView::defaultGridLineColor() ); - QPen pen(gridLineColor); - pen.setWidth(1); - painter->setPen(pen); - painter->drawRect(r); + if (gridLineColor.isValid()) { + QPen pen(gridLineColor); + painter->setPen(pen); + painter->drawRect(r); + } + else { + QPen pen(alteredOption.palette.color(QPalette::AlternateBase)); + painter->setPen(pen); + painter->drawLine(r.topLeft(), r.topRight()); + } //kprDebug()<<"rect:" << r << "viewport:" << painter->viewport() << "window:"<window(); painter->restore(); } @@ -199,9 +206,13 @@ QStyleOptionViewItem alteredOption(option); const KPropertyEditorDataModel *editorModel = dynamic_cast(index.model()); KProperty *property = editorModel->propertyForItem(index); - int t = typeForProperty(property); + const int t = typeForProperty(property); alteredOption.rect.setHeight(alteredOption.rect.height()+3); QWidget *w = KPropertyWidgetsFactoryManager::self()->createEditor(t, parent, alteredOption, index); + if (!w) { + // fall back to String type + w = KPropertyWidgetsFactoryManager::self()->createEditor(KProperty::String, parent, alteredOption, index); + } if (w) { if (-1 != w->metaObject()->indexOfSignal(QMetaObject::normalizedSignature("commitData(QWidget*)").constData()) && property && !property->children()) @@ -512,6 +523,7 @@ void KPropertyEditorView::setGridLineColor(const QColor& color) { d->gridLineColor = color; + viewport()->update(); } static QModelIndex findChildItem(const KProperty& property, const QModelIndex &parent) diff --git a/src/KPropertyFactory.h b/src/KPropertyFactory.h --- a/src/KPropertyFactory.h +++ b/src/KPropertyFactory.h @@ -92,25 +92,56 @@ } }; +//! Provides a specialized conversion of value to string depending on type +class KPROPERTYCORE_EXPORT KPropertyValueDisplayInterface +{ +public: + KPropertyValueDisplayInterface(); + + virtual ~KPropertyValueDisplayInterface(); + + virtual QString propertyValueToString(const KProperty* property, const QLocale &locale) const + { return valueToString(property->value(), locale); } + + virtual QString valueToString(const QVariant& value, const QLocale &locale) const = 0; + + //! Maximum length of strings to display in valueToString(), propertyValueToString() + //! and KPropertyValuePainterInterface::paint(). + //! Used to avoid inefficiences. Equal to 250. + //! @todo Make configurable? + static int maxStringValueLength(); + + //! @return @a value converted to string usign QVariant::toString(), truncated if it's longer than @ref maxStringValueLength() + //! @see maxStringValueLength(); + static QString valueToLocalizedString(const QVariant& value); +}; + class KPROPERTYCORE_EXPORT KPropertyFactory { public: KPropertyFactory(); + virtual ~KPropertyFactory(); + QHash composedPropertyCreators() const; - void addComposedPropertyCreator( int type, KComposedPropertyCreatorInterface* creator ); + QHash valueDisplays() const; + + void addComposedPropertyCreator(int type, KComposedPropertyCreatorInterface* creator); + + void addDisplay(int type, KPropertyValueDisplayInterface *display); protected: void addComposedPropertyCreatorInternal(int type, KComposedPropertyCreatorInterface* creator, bool own = true); + //! Adds value-to-text converted @a painter for type @a type. + //! The converter becomes owned by the factory. + void addDisplayInternal(int type, KPropertyValueDisplayInterface *display, bool own = true); + class Private; Private * const d; }; -class KProperty; -class KCustomProperty; - class KPROPERTYCORE_EXPORT KPropertyFactoryManager : public QObject { Q_OBJECT @@ -123,6 +154,18 @@ /*! \return a pointer to a factory manager instance.*/ static KPropertyFactoryManager* self(); + bool canConvertValueToText(int type) const; + + bool canConvertValueToText(const KProperty* property) const; + + QString propertyValueToString(const KProperty* property) const; + + QString valueToString(int type, const QVariant &value) const; + + QString propertyValueToLocalizedString(const KProperty* property) const; + + QString valueToLocalizedString(int type, const QVariant &value) const; + KPropertyFactoryManager(); ~KPropertyFactoryManager(); diff --git a/src/KPropertyFactory.cpp b/src/KPropertyFactory.cpp --- a/src/KPropertyFactory.cpp +++ b/src/KPropertyFactory.cpp @@ -36,6 +36,7 @@ QSet factories; QHash composedPropertyCreators; + QHash valueDisplays; }; Q_GLOBAL_STATIC(KPropertyFactoryManager, _self) @@ -49,10 +50,13 @@ } ~Private() { + qDeleteAll(valueDisplaysSet); } QHash composedPropertyCreators; QSet composedPropertyCreatorsSet; + QHash valueDisplays; + QSet valueDisplaysSet; }; typedef QList InitFunctions; @@ -74,6 +78,11 @@ return d->composedPropertyCreators; } +QHash KPropertyFactory::valueDisplays() const +{ + return d->valueDisplays; +} + void KPropertyFactory::addComposedPropertyCreator( int type, KComposedPropertyCreatorInterface* creator ) { addComposedPropertyCreatorInternal( type, creator, true ); @@ -86,6 +95,53 @@ d->composedPropertyCreators.insert(type, creator); } +void KPropertyFactory::addDisplay(int type, KPropertyValueDisplayInterface *display) +{ + addDisplayInternal(type, display, true); + if (dynamic_cast(display)) { + addComposedPropertyCreatorInternal( type, + dynamic_cast(display), false/* !own*/ ); + } + if (dynamic_cast(display)) { + addDisplayInternal( type, dynamic_cast(display), false/* !own*/ ); + } +} + +void KPropertyFactory::addDisplayInternal(int type, KPropertyValueDisplayInterface *display, bool own) +{ + if (own) { + d->valueDisplaysSet.insert(display); + } + d->valueDisplays.insert(type, display); +} + +//------------ + +KPropertyValueDisplayInterface::KPropertyValueDisplayInterface() +{ +} + +KPropertyValueDisplayInterface::~KPropertyValueDisplayInterface() +{ +} + +//static +int KPropertyValueDisplayInterface::maxStringValueLength() +{ + return 250; +} + +//static +QString KPropertyValueDisplayInterface::valueToLocalizedString(const QVariant& value) +{ + QString s(value.toString()); + if (KPropertyValueDisplayInterface::maxStringValueLength() < s.length()) { + s.truncate(KPropertyValueDisplayInterface::maxStringValueLength()); + return QObject::tr("%1...", "Truncated string").arg(s); + } + return s; +} + //------------ KPropertyFactoryManager::KPropertyFactoryManager() @@ -123,6 +179,13 @@ { d->composedPropertyCreators.insert(it.key(), it.value()); } + QHash::ConstIterator valueDisplaysItEnd + = factory->valueDisplays().constEnd(); + for (QHash::ConstIterator it( factory->valueDisplays().constBegin() ); + it != valueDisplaysItEnd; ++it) + { + d->valueDisplays.insert(it.key(), it.value()); + } } KComposedPropertyInterface* KPropertyFactoryManager::createComposedProperty(KProperty *parent) @@ -137,6 +200,40 @@ _initFunctions->append(initFunction); } +bool KPropertyFactoryManager::canConvertValueToText(int type) const +{ + return d->valueDisplays.value(type) != 0; +} + +bool KPropertyFactoryManager::canConvertValueToText(const KProperty* property) const +{ + return canConvertValueToText(property->type()); +} + +QString KPropertyFactoryManager::propertyValueToString(const KProperty* property) const +{ + const KPropertyValueDisplayInterface *display = d->valueDisplays.value(property->type()); + return display ? display->propertyValueToString(property, QLocale::c()) : property->value().toString(); +} + +QString KPropertyFactoryManager::valueToString(int type, const QVariant &value) const +{ + const KPropertyValueDisplayInterface *display = d->valueDisplays.value(type); + return display ? display->valueToString(value, QLocale::c()) : value.toString(); +} + +QString KPropertyFactoryManager::propertyValueToLocalizedString(const KProperty* property) const +{ + const KPropertyValueDisplayInterface *display = d->valueDisplays.value(property->type()); + return display ? display->propertyValueToString(property, QLocale()) : KPropertyValueDisplayInterface::valueToLocalizedString(property->value()); +} + +QString KPropertyFactoryManager::valueToLocalizedString(int type, const QVariant &value) const +{ + const KPropertyValueDisplayInterface *display = d->valueDisplays.value(type); + return display ? display->valueToString(value, QLocale()) : KPropertyValueDisplayInterface::valueToLocalizedString(value.toString()); +} + //! @todo #if 0 const int type = parent->type(); diff --git a/src/KPropertyLineStyleItemDelegate_p.h b/src/KPropertyLineStyleItemDelegate_p.h --- a/src/KPropertyLineStyleItemDelegate_p.h +++ b/src/KPropertyLineStyleItemDelegate_p.h @@ -1,5 +1,6 @@ /* This file is part of the KDE project * Copyright (C) 2007 Jan Hambrecht + * Copyright (C) 2015 Jarosław Staniek * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -29,6 +30,10 @@ virtual ~KPropertyLineStyleItemDelegate(); void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; QSize sizeHint (const QStyleOptionViewItem &option, const QModelIndex &index) const; + + static void paintItem(QPainter *painter, const QPen &pen_, const QRect &rect, const QStyleOption &option); + + static QString styleName(Qt::PenStyle style, const QLocale &locale); }; #endif diff --git a/src/KPropertyLineStyleItemDelegate_p.cpp b/src/KPropertyLineStyleItemDelegate_p.cpp --- a/src/KPropertyLineStyleItemDelegate_p.cpp +++ b/src/KPropertyLineStyleItemDelegate_p.cpp @@ -1,5 +1,6 @@ /* This file is part of the KDE project * Copyright (C) 2007 Jan Hambrecht + * Copyright (C) 2015 Jarosław Staniek * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -18,6 +19,7 @@ */ #include "KPropertyLineStyleItemDelegate_p.h" +#include "KPropertyCoreUtils_p.h" #include #include @@ -31,6 +33,51 @@ { } +class PenStyleData : public QHash +{ +public: + PenStyleData() { + insert(Qt::NoPen, QObject::tr("None", "No Line")); + insert(Qt::SolidLine, QObject::tr("Solid Line")); + insert(Qt::DashLine, QObject::tr("Dash Line")); + insert(Qt::DotLine, QObject::tr("Dot Line")); + insert(Qt::DashDotLine, QObject::tr("Dash-Dot Line")); + insert(Qt::DashDotDotLine, QObject::tr("Dash-Dot-Dot Line")); + insert(Qt::CustomDashLine, QObject::tr("Custom Dash Line")); + } +}; + +Q_GLOBAL_STATIC(PenStyleData, g_penStyleData) + +//static +QString KPropertyLineStyleItemDelegate::styleName(Qt::PenStyle style, const QLocale &locale) +{ + if (locale.language() == QLocale::C) { + return KPropertyUtils::keyForEnumValue("PenStyle", style); + } + return g_penStyleData->value(style); +} + +//static +void KPropertyLineStyleItemDelegate::paintItem(QPainter *painter, const QPen &pen_, + const QRect &rect, const QStyleOption &option) +{ + painter->save(); + QPen pen(pen_); + pen.setBrush(option.state & QStyle::State_Selected ? option.palette.highlightedText() : option.palette.text()); + if (pen.style() == Qt::NoPen) { + pen.setWidth(0); + pen.setStyle(Qt::SolidLine); + painter->setPen(pen); + painter->drawText(rect, Qt::AlignLeft | Qt::AlignVCenter, g_penStyleData->value(Qt::NoPen)); + } else { + pen.setWidth(3); + painter->setPen(pen); + painter->drawLine(rect.left(), rect.center().y(), rect.right(), rect.center().y()); + } + painter->restore(); +} + void KPropertyLineStyleItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const @@ -41,11 +88,7 @@ painter->fillRect(option.rect, option.palette.highlight()); QPen pen = index.data(Qt::DecorationRole).value(); - pen.setBrush(option.palette.text()); // use the view-specific palette; the model hardcodes this to black - painter->setPen(pen); - painter->drawLine(option.rect.left(), option.rect.center().y(), - option.rect.right(), option.rect.center().y()); - + paintItem(painter, pen, option.rect, option); painter->restore(); } diff --git a/src/KPropertyLineStyleModel_p.cpp b/src/KPropertyLineStyleModel_p.cpp --- a/src/KPropertyLineStyleModel_p.cpp +++ b/src/KPropertyLineStyleModel_p.cpp @@ -45,7 +45,7 @@ switch(role) { case Qt::DecorationRole: { QPen pen(Qt::black); - pen.setWidth(2); + pen.setWidth(3); if (index.row() < Qt::CustomDashLine) pen.setStyle(static_cast(index.row())); else if (index.row() < m_styles.count()) diff --git a/src/KPropertyLineStyleSelector_p.h b/src/KPropertyLineStyleSelector_p.h --- a/src/KPropertyLineStyleSelector_p.h +++ b/src/KPropertyLineStyleSelector_p.h @@ -1,5 +1,6 @@ /* This file is part of the KDE project * Copyright (C) 2007 Jan Hambrecht + * Copyright (C) 2015 Jarosław Staniek * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public diff --git a/src/KPropertyLineStyleSelector_p.cpp b/src/KPropertyLineStyleSelector_p.cpp --- a/src/KPropertyLineStyleSelector_p.cpp +++ b/src/KPropertyLineStyleSelector_p.cpp @@ -1,5 +1,6 @@ /* This file is part of the KDE project * Copyright (C) 2007 Jan Hambrecht + * Copyright (C) 2015 Jarosław Staniek * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -20,6 +21,7 @@ #include "KPropertyLineStyleSelector_p.h" #include "KPropertyLineStyleModel_p.h" #include "KPropertyLineStyleItemDelegate_p.h" +#include "KPropertyWidgetsFactory.h" #include #include @@ -40,6 +42,9 @@ { setModel(d->model); setItemDelegate(new KPropertyLineStyleItemDelegate(this)); + setEditable(false); + setInsertPolicy(QComboBox::NoInsert); + setContextMenuPolicy(Qt::NoContextMenu); } KPropertyLineStyleSelector::~KPropertyLineStyleSelector() @@ -55,15 +60,10 @@ option.initFrom(this); option.frame = hasFrame(); QRect r = style()->subControlRect(QStyle::CC_ComboBox, &option, QStyle::SC_ComboBoxEditField, this); - if (!option.frame) // frameless combo boxes have smaller margins but styles do not take this into account - r.adjust(-14, 0, 14, 1); - QPen pen = itemData(currentIndex(), Qt::DecorationRole).value(); - pen.setBrush(option.palette.text()); // use the view-specific palette; the model hardcodes this to black - QPainter painter(this); - painter.setPen(pen); - painter.drawLine(r.left(), r.center().y(), r.right(), r.center().y()); + KPropertyLineStyleItemDelegate::paintItem(&painter, pen, r, option); + KPropertyWidgetsFactory::paintTopGridLine(this); } bool KPropertyLineStyleSelector::addCustomStyle(const QVector &style) diff --git a/src/KPropertyUtils.h b/src/KPropertyUtils.h --- a/src/KPropertyUtils.h +++ b/src/KPropertyUtils.h @@ -1,5 +1,5 @@ /* This file is part of the KDE project - Copyright (C) 2006-2008 Jarosław Staniek + Copyright (C) 2006-2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public diff --git a/src/KPropertyUtils.cpp b/src/KPropertyUtils.cpp --- a/src/KPropertyUtils.cpp +++ b/src/KPropertyUtils.cpp @@ -1,7 +1,7 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur Copyright (C) 2004 Alexander Dymo - Copyright (C) 2004-2008 Jarosław Staniek + Copyright (C) 2004-2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -31,6 +31,7 @@ #include #include #include +#include #define BRANCHBOX_SIZE 9 @@ -232,3 +233,13 @@ return c.light(400); return Qt::lightGray; } + +QColor KPropertyUtils::gridLineColor(const QWidget *widget) +{ + Q_ASSERT(widget); + KPropertyEditorView *view = 0; + if (widget->parentWidget()) { + view = qobject_cast(widget->parentWidget()->parentWidget()); + } + return view ? view->gridLineColor() : QColor(); +} diff --git a/src/KPropertyUtils_p.h b/src/KPropertyUtils_p.h --- a/src/KPropertyUtils_p.h +++ b/src/KPropertyUtils_p.h @@ -20,13 +20,19 @@ #ifndef KPROPERTY_UTILS_P_H #define KPROPERTY_UTILS_P_H -#include +class QColor; +class QWidget; namespace KPropertyUtils { +//! @return contrast color for @a c color. QColor contrastColor(const QColor& c); +//! @return grid line color defined by a KPropertyEditorView widget contains @a widget +//! Invalid color is returned if no grid is defined or KPropertyEditorView was not found. +QColor gridLineColor(const QWidget *widget); + } #endif diff --git a/src/KPropertyWidgetsFactory.h b/src/KPropertyWidgetsFactory.h --- a/src/KPropertyWidgetsFactory.h +++ b/src/KPropertyWidgetsFactory.h @@ -42,8 +42,8 @@ virtual ~KPropertyEditorCreatorInterface(); - virtual QWidget * createEditor( int type, QWidget *parent, - const QStyleOptionViewItem & option, const QModelIndex & index ) const = 0; + virtual QWidget * createEditor(int type, QWidget *parent, + const QStyleOptionViewItem &option, const QModelIndex &index) const; /*! Options for altering the editor widget creation process, used by KPropertyFactoryManager::createEditor(). */ @@ -69,20 +69,8 @@ const QStyleOptionViewItem & option, const QModelIndex & index ) const = 0; }; -class KPROPERTYWIDGETS_EXPORT KPropertyValueDisplayInterface -{ -public: - KPropertyValueDisplayInterface(); - virtual ~KPropertyValueDisplayInterface(); - virtual QString displayTextForProperty( const KProperty* property ) const - { return displayText(property->value()); } - virtual QString displayText( const QVariant& value ) const - { return value.toString(); } -}; - - //! Label widget that can be used for displaying text-based read-only items -//! Used in LabelCreator. +//! Used in KPropertyLabelCreator. class KPROPERTYWIDGETS_EXPORT KPropertyLabel : public QLabel { Q_OBJECT @@ -103,6 +91,9 @@ QVariant m_value; }; +KPROPERTYWIDGETS_EXPORT void paintInternal(const KPropertyValueDisplayInterface *iface, QPainter *painter, + const QStyleOptionViewItem & option, const QModelIndex & index); + //! Creator returning editor template class KPROPERTYWIDGETS_EXPORT KPropertyEditorCreator : public KPropertyEditorCreatorInterface, @@ -123,15 +114,10 @@ return new Widget(parent, this); } - virtual void paint( QPainter * painter, - const QStyleOptionViewItem & option, const QModelIndex & index ) const + virtual void paint(QPainter *painter, + const QStyleOptionViewItem & option, const QModelIndex & index) const { - painter->save(); - QRect r(option.rect); - r.setLeft(r.left()+1); - painter->drawText( r, Qt::AlignLeft | Qt::AlignVCenter, - displayText( index.data(Qt::EditRole) ) ); - painter->restore(); + paintInternal(this, painter, option, index); } }; @@ -146,31 +132,24 @@ QHash editorCreators() const; QHash valuePainters() const; - QHash valueDisplays() const; //! Adds editor creator @a creator for type @a type. //! The creator becomes owned by the factory. void addEditor(int type, KPropertyEditorCreatorInterface *creator); void addPainter(int type, KPropertyValuePainterInterface *painter); - void addDisplay(int type, KPropertyValueDisplayInterface *display); - static void paintTopGridLine(QWidget *widget); - static void setTopAndBottomBordersUsingStyleSheet(QWidget *widget, QWidget* parent, - const QString& extraStyleSheet = QString()); + static void setTopAndBottomBordersUsingStyleSheet(QWidget *widget, + const QString& extraStyleSheet = QString()); protected: void addEditorInternal(int type, KPropertyEditorCreatorInterface *editor, bool own = true); //! Adds value painter @a painter for type @a type. //! The painter becomes owned by the factory. void addPainterInternal(int type, KPropertyValuePainterInterface *painter, bool own = true); - //! Adds value-to-text converted @a painter for type @a type. - //! The converter becomes owned by the factory. - void addDisplayInternal(int type, KPropertyValueDisplayInterface *display, bool own = true); - class Private; Private * const d; }; @@ -194,12 +173,6 @@ const QStyleOptionViewItem & option, const QModelIndex & index ) const; - bool canConvertValueToText( int type ) const; - - bool canConvertValueToText( const KProperty* property ) const; - - QString convertValueToText( const KProperty* property ) const; - //! Registers factory @a factory. It becomes owned by the manager. void registerFactory(KPropertyWidgetsFactory *factory); diff --git a/src/KPropertyWidgetsFactory.cpp b/src/KPropertyWidgetsFactory.cpp --- a/src/KPropertyWidgetsFactory.cpp +++ b/src/KPropertyWidgetsFactory.cpp @@ -23,13 +23,22 @@ #include "KDefaultPropertyFactory.h" #include "KPropertyEditorView.h" #include "KPropertyEditorDataModel.h" +#include "KPropertyStringEditor.h" KPropertyLabel::KPropertyLabel(QWidget *parent, const KPropertyValueDisplayInterface *iface) : QLabel(parent) , m_iface(iface) { setAutoFillBackground(true); - setContentsMargins(0,1,0,0); + + KPropertyEditorView* view = 0; + if (parent) { + view = qobject_cast(parent->parentWidget()); + } + const QColor gridLineColor(view ? view->gridLineColor() : KPropertyEditorView::defaultGridLineColor()); + const int top = 1 + (gridLineColor.isValid() ? 1 : 0); + + setContentsMargins(0, top, 0, 0); setIndent(1); } @@ -40,7 +49,7 @@ void KPropertyLabel::setValue(const QVariant& value) { - setText( m_iface->displayText(value) ); + setText( m_iface->valueToString(value, QLocale()) ); m_value = value; } @@ -52,6 +61,19 @@ //--------------- +void paintInternal(const KPropertyValueDisplayInterface *iface, + QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) +{ + painter->save(); + QRect r(option.rect); + r.setLeft(r.left()+1); + painter->drawText( r, Qt::AlignLeft | Qt::AlignVCenter, + iface->valueToString(index.data(Qt::EditRole), QLocale())); + painter->restore(); +} + +//--------------- + //! @internal class KPropertyWidgetsFactoryManager::Private { @@ -65,7 +87,6 @@ QHash editorCreators; QHash valuePainters; - QHash valueDisplays; }; Q_GLOBAL_STATIC(KPropertyWidgetsFactoryManager, _self) @@ -93,16 +114,13 @@ { qDeleteAll(editorCreatorsSet); qDeleteAll(valuePaintersSet); - qDeleteAll(valueDisplaysSet); } QHash editorCreators; QHash valuePainters; - QHash valueDisplays; QSet editorCreatorsSet; QSet valuePaintersSet; - QSet valueDisplaysSet; }; KPropertyWidgetsFactory::KPropertyWidgetsFactory() @@ -125,11 +143,6 @@ return d->valuePainters; } -QHash KPropertyWidgetsFactory::valueDisplays() const -{ - return d->valueDisplays; -} - void KPropertyWidgetsFactory::addEditor(int type, KPropertyEditorCreatorInterface *creator) { addEditorInternal( type, creator, true ); @@ -160,21 +173,6 @@ } } -void KPropertyWidgetsFactory::addDisplay(int type, KPropertyValueDisplayInterface *display) -{ - addDisplayInternal(type, display, true); - if (dynamic_cast(display)) { - addComposedPropertyCreatorInternal( type, - dynamic_cast(display), false/* !own*/ ); - } - if (dynamic_cast(display)) { - addEditorInternal( type, dynamic_cast(display), false/* !own*/ ); - } - if (dynamic_cast(display)) { - addDisplayInternal( type, dynamic_cast(display), false/* !own*/ ); - } -} - void KPropertyWidgetsFactory::addEditorInternal(int type, KPropertyEditorCreatorInterface *editor, bool own) { if (own) @@ -189,31 +187,31 @@ d->valuePainters.insert(type, painter); } -void KPropertyWidgetsFactory::addDisplayInternal(int type, KPropertyValueDisplayInterface *display, bool own) -{ - if (own) - d->valueDisplaysSet.insert(display); - d->valueDisplays.insert(type, display); -} - //static void KPropertyWidgetsFactory::paintTopGridLine(QWidget *widget) { // paint top grid line - QPainter p(widget); - QColor gridLineColor( dynamic_cast(widget->parentWidget()) ? - dynamic_cast(widget->parentWidget())->gridLineColor() - : KPropertyEditorView::defaultGridLineColor() ); - p.setPen(QPen( QBrush(gridLineColor), 1)); - p.drawLine(0, 0, widget->width()-1, 0); + KPropertyEditorView* view = 0; + if (widget->parentWidget()) { + view = qobject_cast(widget->parentWidget()->parentWidget()); + } + const QColor gridLineColor(view ? view->gridLineColor() : KPropertyEditorView::defaultGridLineColor()); + if (gridLineColor.isValid()) { + QPainter p(widget); + p.setPen(QPen( QBrush(gridLineColor), 1)); + p.drawLine(0, 0, widget->width()-1, 0); + } } //static -void KPropertyWidgetsFactory::setTopAndBottomBordersUsingStyleSheet(QWidget *widget, QWidget* parent, const QString& extraStyleSheet) +void KPropertyWidgetsFactory::setTopAndBottomBordersUsingStyleSheet(QWidget *widget, + const QString& extraStyleSheet) { - QColor gridLineColor( dynamic_cast(parent) ? - dynamic_cast(parent)->gridLineColor() - : KPropertyEditorView::defaultGridLineColor() ); + KPropertyEditorView* view = 0; + if (widget->parentWidget()) { + view = qobject_cast(widget->parentWidget()->parentWidget()); + } + const QColor gridLineColor(view ? view->gridLineColor() : KPropertyEditorView::defaultGridLineColor()); widget->setStyleSheet( QString::fromLatin1("%1 { border-top: 1px solid %2;border-bottom: 1px solid %2; } %3") .arg(QLatin1String(widget->metaObject()->className())) @@ -258,13 +256,6 @@ { d->valuePainters.insert(it.key(), it.value()); } - QHash::ConstIterator valueDisplaysItEnd - = factory->valueDisplays().constEnd(); - for (QHash::ConstIterator it( factory->valueDisplays().constBegin() ); - it != valueDisplaysItEnd; ++it) - { - d->valueDisplays.insert(it.key(), it.value()); - } } bool KPropertyWidgetsFactoryManager::isEditorForTypeAvailable( int type ) const @@ -287,9 +278,9 @@ w->setObjectName(QLatin1String(property->name())); if (creator->options.removeBorders) { //! @todo get real border color from the palette - QColor gridLineColor( dynamic_cast(parent) ? - dynamic_cast(parent)->gridLineColor() - : KPropertyEditorView::defaultGridLineColor() ); + QColor gridLineColor(qobject_cast(parent->parentWidget()) ? + qobject_cast(parent->parentWidget())->gridLineColor() + : KPropertyEditorView::defaultGridLineColor()); QString cssClassName = QLatin1String(w->metaObject()->className()); cssClassName.replace(QLatin1String("KProperty"), QString()); //!< @todo QString css = @@ -319,22 +310,6 @@ return true; } -bool KPropertyWidgetsFactoryManager::canConvertValueToText( int type ) const -{ - return d->valueDisplays.value(type) != 0; -} - -bool KPropertyWidgetsFactoryManager::canConvertValueToText( const KProperty* property ) const -{ - return d->valueDisplays.value( property->type() ) != 0; -} - -QString KPropertyWidgetsFactoryManager::convertValueToText( const KProperty* property ) const -{ - const KPropertyValueDisplayInterface *display = d->valueDisplays.value( property->type() ); - return display ? display->displayTextForProperty( property ) : property->value().toString(); -} - //! @todo #if 0 const int type = parent->type(); @@ -377,6 +352,16 @@ { } +QWidget* KPropertyEditorCreatorInterface::createEditor(int type, QWidget *parent, + const QStyleOptionViewItem & option, + const QModelIndex & index) const +{ + Q_UNUSED(type); + Q_UNUSED(option); + Q_UNUSED(index); + return new KPropertyStringEditor(parent); +} + KPropertyEditorCreatorInterface::Options::Options() : removeBorders(true) { @@ -389,12 +374,3 @@ KPropertyValuePainterInterface::~KPropertyValuePainterInterface() { } - -KPropertyValueDisplayInterface::KPropertyValueDisplayInterface() -{ -} - -KPropertyValueDisplayInterface::~KPropertyValueDisplayInterface() -{ -} - diff --git a/src/editors/CMakeLists.txt b/src/editors/CMakeLists.txt --- a/src/editors/CMakeLists.txt +++ b/src/editors/CMakeLists.txt @@ -1,6 +1,7 @@ set(KPROPERTY_EDITORS_HEADERS Utils BoolEdit + ColorEdit ComboBox CursorEdit DateEdit @@ -11,19 +12,16 @@ PixmapEdit PointEdit RectEdit + #TODO KPropertyRectFEditor SizeEdit SizePolicyEdit SpinBox + #TODO KPropertyStringEditor #StringListEdit #SymbolCombo TimeEdit #TODO UrlEdit ) -if(KPROPERTY_KF) - list(APPEND KPROPERTY_EDITORS_HEADERS - ColorEdit - ) -endif() ecm_generate_headers(kproperty_editors_FORWARDING_HEADERS REQUIRED_HEADERS kproperty_editors_HEADERS diff --git a/src/editors/rectedit.h b/src/editors/KPropertyRectFEditor.h copy from src/editors/rectedit.h copy to src/editors/KPropertyRectFEditor.h --- a/src/editors/rectedit.h +++ b/src/editors/KPropertyRectFEditor.h @@ -1,5 +1,5 @@ /* This file is part of the KDE project - Copyright (C) 2008 Jarosław Staniek + Copyright (C) 2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -17,29 +17,30 @@ * Boston, MA 02110-1301, USA. */ -#ifndef KPROPERTY_RECTEDIT_H -#define KPROPERTY_RECTEDIT_H +#ifndef KPROPERTY_RECTFEDITOR_H +#define KPROPERTY_RECTFEDITOR_H #include "KPropertyWidgetsFactory.h" -class KPROPERTYWIDGETS_EXPORT KRectComposedProperty : public KComposedPropertyInterface +class KPROPERTYWIDGETS_EXPORT KRectFComposedProperty : public KComposedPropertyInterface { public: - explicit KRectComposedProperty(KProperty *parent); + explicit KRectFComposedProperty(KProperty *parent); virtual void setValue(KProperty *property, const QVariant &value, bool rememberOldValue); virtual void childValueChanged(KProperty *child, const QVariant &value, bool rememberOldValue); }; -class KPROPERTYWIDGETS_EXPORT KPropertyRectDelegate : public KPropertyLabelCreator, - public KComposedPropertyCreator +class KPROPERTYWIDGETS_EXPORT KPropertyRectFDelegate : public KPropertyLabelCreator, + public KComposedPropertyCreator { public: - KPropertyRectDelegate() {} - virtual QString displayText( const QVariant& value ) const; + KPropertyRectFDelegate(); + + virtual QString valueToString(const QVariant& value, const QLocale &locale) const; }; #endif diff --git a/src/editors/rectedit.cpp b/src/editors/KPropertyRectFEditor.cpp copy from src/editors/rectedit.cpp copy to src/editors/KPropertyRectFEditor.cpp --- a/src/editors/rectedit.cpp +++ b/src/editors/KPropertyRectFEditor.cpp @@ -1,5 +1,5 @@ /* This file is part of the KDE project - Copyright (C) 2008 Jarosław Staniek + Copyright (C) 2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -17,65 +17,76 @@ * Boston, MA 02110-1301, USA. */ -#include "rectedit.h" +#include "KPropertyRectFEditor.h" -#include +#include -static const char RECTEDIT_MASK[] = "%1, %2, %3x%4"; +KPropertyRectFDelegate::KPropertyRectFDelegate() +{ +} -QString KPropertyRectDelegate::displayText( const QVariant& value ) const +QString KPropertyRectFDelegate::valueToString(const QVariant& value, const QLocale &locale) const { - const QRect r(value.toRect()); - return QString::fromLatin1(RECTEDIT_MASK) - .arg(r.x()) - .arg(r.y()) - .arg(r.width()) - .arg(r.height()); + const QRectF r(value.toRectF()); + if (r.isNull()) { + if (locale.language() == QLocale::C) { + return QString(); + } + return QObject::tr("None", "Null value"); + } + if (locale.language() == QLocale::C) { + return QString::fromLatin1("%1, %2, %3x%4").arg(r.x()).arg(r.y()).arg(r.width()).arg(r.height()); + } + return QObject::tr("%1, %2, %3x%4", "Rectangle") + .arg(locale.toString(r.x())) + .arg(locale.toString(r.y())) + .arg(locale.toString(r.width())) + .arg(locale.toString(r.height())); } //------------ -KRectComposedProperty::KRectComposedProperty(KProperty *property) +KRectFComposedProperty::KRectFComposedProperty(KProperty *property) : KComposedPropertyInterface(property) { (void)new KProperty("x", QVariant(), QObject::tr("X", "Property: X coordinate"), - QObject::tr("X Coordinate", "Property: X coordinate"), KProperty::Int, property); + QObject::tr("X Coordinate", "Property: X coordinate"), KProperty::Double, property); (void)new KProperty("y", QVariant(), QObject::tr("Y", "Property: Y coordinate"), - QObject::tr("Y Coordinate", "Property: Y coordinate"), KProperty::Int, property); + QObject::tr("Y Coordinate", "Property: Y coordinate"), KProperty::Double, property); (void)new KProperty("width", QVariant(), QObject::tr("Width", "Property: width of rectangle"), - QObject::tr("Width", "Property: width of rectangle"), KProperty::UInt, property); + QObject::tr("Width", "Property: width of rectangle"), KProperty::Double, property); (void)new KProperty("height", QVariant(), QObject::tr("Height", "Property: height of rectangle"), - QObject::tr("Height", "Property: height of rectangle"), KProperty::UInt, property); + QObject::tr("Height", "Property: height of rectangle"), KProperty::Double, property); } -void KRectComposedProperty::setValue(KProperty *property, +void KRectFComposedProperty::setValue(KProperty *property, const QVariant &value, bool rememberOldValue) { - const QRect r( value.toRect() ); + const QRectF r(value.toRectF()); property->child("x")->setValue(r.x(), rememberOldValue, false); property->child("y")->setValue(r.y(), rememberOldValue, false); property->child("width")->setValue(r.width(), rememberOldValue, false); property->child("height")->setValue(r.height(), rememberOldValue, false); } -void KRectComposedProperty::childValueChanged(KProperty *child, - const QVariant &value, bool rememberOldValue) +void KRectFComposedProperty::childValueChanged(KProperty *child, const QVariant &value, + bool rememberOldValue) { Q_UNUSED(rememberOldValue); - QRect r( child->parent()->value().toRect() ); + QRectF r(child->parent()->value().toRectF()); if (child->name() == "x") - r.moveLeft(value.toInt()); + r.moveLeft(value.toReal()); else if (child->name() == "y") - r.moveTop(value.toInt()); + r.moveTop(value.toReal()); else if (child->name() == "width") - r.setWidth(value.toInt()); + r.setWidth(value.toReal()); else if (child->name() == "height") - r.setHeight(value.toInt()); + r.setHeight(value.toReal()); child->parent()->setValue(r, true, false); } diff --git a/src/editors/KPropertyStringEditor.h b/src/editors/KPropertyStringEditor.h --- a/src/editors/KPropertyStringEditor.h +++ b/src/editors/KPropertyStringEditor.h @@ -1,7 +1,7 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur Copyright (C) 2004 Alexander Dymo - Copyright (C) 2008 Jarosław Staniek + Copyright (C) 2008-2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -50,13 +50,16 @@ bool m_slotTextChangedEnabled; }; -class KPROPERTYWIDGETS_EXPORT KPropertyStringDelegate : public KPropertyEditorCreatorInterface +class KPROPERTYWIDGETS_EXPORT KPropertyStringDelegate : public KPropertyEditorCreatorInterface, + public KPropertyValueDisplayInterface { public: - KPropertyStringDelegate() {} + KPropertyStringDelegate(); virtual QWidget * createEditor( int type, QWidget *parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const; + + virtual QString valueToString(const QVariant& value, const QLocale &locale) const; }; #endif diff --git a/src/editors/KPropertyStringEditor.cpp b/src/editors/KPropertyStringEditor.cpp --- a/src/editors/KPropertyStringEditor.cpp +++ b/src/editors/KPropertyStringEditor.cpp @@ -1,7 +1,7 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur Copyright (C) 2004 Alexander Dymo - Copyright (C) 2008 Jarosław Staniek + Copyright (C) 2008-2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -57,11 +57,23 @@ emit commitData(this); } +KPropertyStringDelegate::KPropertyStringDelegate() +{ +} + QWidget* KPropertyStringDelegate::createEditor( int type, QWidget *parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const { Q_UNUSED(type); Q_UNUSED(option); Q_UNUSED(index); return new KPropertyStringEditor(parent); } + +QString KPropertyStringDelegate::valueToString(const QVariant& value, const QLocale &locale) const +{ + if (locale.language() == QLocale::C) { + return value.toString(); + } + return valueToLocalizedString(value); +} diff --git a/src/editors/booledit.h b/src/editors/booledit.h --- a/src/editors/booledit.h +++ b/src/editors/booledit.h @@ -1,7 +1,7 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur Copyright (C) 2004 Alexander Dymo - Copyright (C) 2006-2008 Jarosław Staniek + Copyright (C) 2006-2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -81,13 +81,11 @@ QVariant value() const; void setValue(const QVariant &value); - -Q_SIGNALS: - void commitData( QWidget * editor ); }; class KPROPERTYWIDGETS_EXPORT KPropertyBoolDelegate : public KPropertyEditorCreatorInterface, - public KPropertyValuePainterInterface + public KPropertyValuePainterInterface, + public KPropertyValueDisplayInterface { public: KPropertyBoolDelegate(); @@ -97,6 +95,10 @@ virtual void paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const; + + virtual QString propertyValueToString(const KProperty* prop, const QLocale &locale) const; + + virtual QString valueToString(const QVariant& value, const QLocale &locale) const; }; #endif diff --git a/src/editors/booledit.cpp b/src/editors/booledit.cpp --- a/src/editors/booledit.cpp +++ b/src/editors/booledit.cpp @@ -1,6 +1,6 @@ /* This file is part of the KDE project Copyright (C) 2004 Alexander Dymo - Copyright (C) 2006-2008 Jarosław Staniek + Copyright (C) 2006-2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -29,33 +29,38 @@ /*! @return name for state with index @a index, where 0 means true, 1 means false and 2 means none */ -static QString stateName(int index, const KProperty* prop) +static QString stateName(int index, const QLocale &locale, const KProperty* prop = 0) { QString stateNameString; if (index == 0) { - stateNameString = prop->option("yesName", QString()).toString(); - if (stateNameString.isEmpty()) - return QObject::tr("Yes", "Property value: Boolean state Yes"); + stateNameString = prop ? prop->option("yesName", QString()).toString() : QString(); + if (stateNameString.isEmpty()) { + return locale.language() == QLocale::C ? QString::fromLatin1("true") + : QObject::tr("Yes", "Property value: Boolean state Yes"); + } } else if (index == 1) { - stateNameString = prop->option("noName", QString()).toString(); - if (stateNameString.isEmpty()) - return QObject::tr("No", "Property value: Boolean state No"); + stateNameString = prop ? prop->option("noName", QString()).toString() : QString(); + if (stateNameString.isEmpty()) { + return locale.language() == QLocale::C ? QString::fromLatin1("false") + : QObject::tr("No", "Property value: Boolean state No"); + } } else { - stateNameString = prop->option("3rdStateName", QString()).toString(); - if (stateNameString.isEmpty()) - return QObject::tr("None", "Property value: Boolean (3rd) undefined state None"); + stateNameString = prop ? prop->option("3rdStateName", QString()).toString() : QString(); + if (stateNameString.isEmpty()) { + return locale.language() == QLocale::C ? QString::fromLatin1("null") + : QObject::tr("None", "Property value: Boolean (3rd) undefined state None"); + } } return stateNameString; } //! Sets up @a data list data with keys and names for true, false, none values, respectively -static void setupThreeStateListData(KPropertyListData &data, - const KProperty* prop) +static void setupThreeStateListData(KPropertyListData &data, const KProperty* prop) { data.keys << true << false << QVariant(); - data.names << stateName(0, prop) << stateName(1, prop) << stateName(2, prop); + data.names << stateName(0, QLocale(), prop) << stateName(1, QLocale(), prop) << stateName(2, QLocale(), prop); } static int valueToIndex(const QVariant& value) @@ -86,8 +91,8 @@ KPropertyBoolEditor::KPropertyBoolEditor(const KProperty *prop, QWidget *parent) : QToolButton(parent) - , m_yesText( stateName(0, prop) ) - , m_noText( stateName(1, prop) ) + , m_yesText( stateName(0, QLocale(), prop) ) + , m_noText( stateName(1, QLocale(), prop) ) { setFocusPolicy(Qt::WheelFocus); setCheckable(true); @@ -320,28 +325,25 @@ KProperty *prop = editorModel->propertyForItem(index); const QVariant value( index.data(Qt::EditRole) ); QRect rect(option.rect); + const bool threeState = prop->option("3State", false).toBool(); + KPropertyBoolEditor::draw(painter, rect, value, propertyValueToString(prop, QLocale()), threeState); + painter->restore(); +} + +QString KPropertyBoolDelegate::propertyValueToString(const KProperty* prop, const QLocale &locale) const +{ if (prop->option("3State", false).toBool()) { - int listIndex = valueToIndex(value); -// const QString stateNameString( stateName(listIndex, prop) ); -/* const int iconSize = IconSize(KIconLoader::Small); - if (listIndex < 0 || listIndex > 2) - listIndex = 2; - QRect r( option.rect ); - r.setLeft(1+r.left()+2+iconSize); - painter->drawText(r, Qt::AlignVCenter | Qt::AlignLeft, - threeStateListData.names[listIndex] ); */ - KPropertyBoolEditor::draw(painter, rect, value, stateName(listIndex, prop), true/*3state*/); + int listIndex = valueToIndex(prop->value()); + return stateName(listIndex, locale, prop); } - else - { - if (value.isNull() && !prop->option("nullName", QString()).toString().isEmpty()) { - KPropertyBoolEditor::draw(painter, rect, value, - prop->option("nullName", QString()).toString(), false/*2state*/); - } - else { - KPropertyBoolEditor::draw(painter, rect, value, stateName(value.toBool() ? 0 : 1, prop), - false/*2state*/); - } + if (prop->value().isNull() && !prop->option("nullName", QString()).toString().isEmpty()) { + return prop->option("nullName", QString()).toString(); } - painter->restore(); + return valueToString(prop->value(), locale); +} + +QString KPropertyBoolDelegate::valueToString(const QVariant& value, const QLocale &locale) const +{ + // assume 2-state + return stateName(value.toBool() ? 0 : 1, locale); } diff --git a/src/editors/coloredit.h b/src/editors/coloredit.h --- a/src/editors/coloredit.h +++ b/src/editors/coloredit.h @@ -1,5 +1,5 @@ /* This file is part of the KDE project - Copyright (C) 2010 Jarosław Staniek + Copyright (C) 2010-2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -21,7 +21,9 @@ #define KPROPERTY_COLOREDIT_H #include "KPropertyWidgetsFactory.h" +#include "config-kproperty.h" +#ifdef KPROPERTY_KF #include //! Color combo box @@ -49,9 +51,11 @@ protected Q_SLOTS: void slotValueChanged(const QColor&); }; +#endif // KPROPERTY_KF class KPROPERTYWIDGETS_EXPORT KPropertyColorComboDelegate : public KPropertyEditorCreatorInterface, - public KPropertyValuePainterInterface + public KPropertyValuePainterInterface, + public KPropertyValueDisplayInterface { public: KPropertyColorComboDelegate() {} @@ -61,6 +65,8 @@ virtual void paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const; + + virtual QString valueToString(const QVariant& value, const QLocale &locale) const; }; #endif diff --git a/src/editors/coloredit.cpp b/src/editors/coloredit.cpp --- a/src/editors/coloredit.cpp +++ b/src/editors/coloredit.cpp @@ -1,5 +1,5 @@ /* This file is part of the KDE project - Copyright (C) 2010 Jarosław Staniek + Copyright (C) 2010-2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -20,12 +20,12 @@ #include "coloredit.h" #include "KPropertyUtils_p.h" -#include - -#include #include #include +#ifdef KPROPERTY_KF +#include + Q_GLOBAL_STATIC_WITH_ARGS(KColorCollection, g_oxygenColors, (QLatin1String("Oxygen.colors"))) KPropertyColorComboEditor::KPropertyColorComboEditor(QWidget *parent) @@ -39,6 +39,16 @@ colors += g_oxygenColors->color(i); } setColors(colors); + + int paddingTop = 1; + if (!KPropertyUtils::gridLineColor(this).isValid()) { + setFrame(false); + paddingTop = 0; + } + QString styleSheet = QString::fromLatin1("QComboBox { \ + border: 1px; \ + padding-top: %1px; padding-left: 1px; }").arg(paddingTop); + setStyleSheet(styleSheet); } KPropertyColorComboEditor::~KPropertyColorComboEditor() @@ -59,14 +69,28 @@ { emit commitData(this); } +#endif // KPROPERTY_KF -QWidget * KPropertyColorComboDelegate::createEditor( int type, QWidget *parent, - const QStyleOptionViewItem & option, const QModelIndex & index ) const +QWidget * KPropertyColorComboDelegate::createEditor(int type, QWidget *parent, + const QStyleOptionViewItem &option, const QModelIndex &index) const { Q_UNUSED(type) Q_UNUSED(option) Q_UNUSED(index) +#ifdef KPROPERTY_KF return new KPropertyColorComboEditor(parent); +#else + return KPropertyEditorCreatorInterface::createEditor(type, parent, option, index); +#endif +} + +static QString colorToName(const QColor &color, const QLocale &locale) +{ + if (!color.isValid()) { + return locale.language() == QLocale::C ? QString::fromLatin1("#invalid") + : QObject::tr("#invalid", "Invalid color"); + } + return color.alpha() == 255 ? color.name(QColor::HexRgb) : color.name(QColor::HexArgb); } void KPropertyColorComboDelegate::paint( QPainter * painter, @@ -82,6 +106,11 @@ QFont f(option.font); f.setFamily(QLatin1String("courier")); painter->setFont(f); - painter->drawText(option.rect, Qt::AlignCenter, b.color().name()); + painter->drawText(option.rect, Qt::AlignCenter, colorToName(b.color(), QLocale())); painter->restore(); } + +QString KPropertyColorComboDelegate::valueToString(const QVariant& value, const QLocale &locale) const +{ + return colorToName(value.value(), locale); +} diff --git a/src/editors/combobox.h b/src/editors/combobox.h --- a/src/editors/combobox.h +++ b/src/editors/combobox.h @@ -1,7 +1,7 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur Copyright (C) 2004 Alexander Dymo - Copyright (C) 2008 Jarosław Staniek + Copyright (C) 2008-2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -60,6 +60,8 @@ // virtual void setProperty(const Property *property); void setListData(const KPropertyListData & listData); + static QString borderSheet(const QWidget *widget); + Q_SIGNALS: void commitData( QWidget * editor ); @@ -93,7 +95,9 @@ public: KPropertyComboBoxDelegate(); - virtual QString displayTextForProperty( const KProperty* property ) const; + virtual QString propertyValueToString(const KProperty* property, const QLocale &locale) const; + + QString valueToString(const QVariant& value, const QLocale &locale) const; virtual QWidget * createEditor( int type, QWidget *parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const; diff --git a/src/editors/combobox.cpp b/src/editors/combobox.cpp --- a/src/editors/combobox.cpp +++ b/src/editors/combobox.cpp @@ -1,7 +1,7 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur Copyright (C) 2004 Alexander Dymo - Copyright (C) 2008 Jarosław Staniek + Copyright (C) 2008-2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -24,6 +24,7 @@ #include "KPropertyEditorView.h" #include "kproperty_debug.h" #include "KPropertyWidgetsFactory.h" +#include "KPropertyUtils_p.h" #include #include @@ -77,32 +78,41 @@ // setFocusWidget(m_edit); connect(this, SIGNAL(activated(int)), this, SLOT(slotValueChanged(int))); - setFrame(false); -/* QList > children( findChildren() ); - foreach (QWidget* w, children) { - kprDebug() << w->objectName() << w->metaObject()->className(); - w->setStyleSheet(QString()); - }*/ - //QComboBoxPrivateContainer - + int paddingTop = 2; + int paddingLeft = 3; + const QString style(parent->style()->objectName()); + if (!KPropertyUtils::gridLineColor(this).isValid()) { + setFrame(false); + paddingTop = 0; + } + if (style == QLatin1String("windowsvista") || style == QLatin1String("fusion")) { + paddingLeft = 2; + } //Set the stylesheet to a plain style - QString styleSheet; - QPalette p = QGuiApplication::palette(); - QColor focus = p.highlight().color(); - - styleSheet = QString::fromLatin1("QComboBox { \ - border: 1px solid %1; \ - border-radius: 0px; \ - padding: 0px 18px; }").arg(focus.name()); - + QString styleSheet = QString::fromLatin1("QComboBox { \ + %1 \ + padding-top: %2px; padding-left: %3px; }").arg(borderSheet(this)).arg(paddingTop).arg(paddingLeft); setStyleSheet(styleSheet); } KPropertyComboBoxEditor::~KPropertyComboBoxEditor() { } +//static +QString KPropertyComboBoxEditor::borderSheet(const QWidget *widget) +{ + Q_ASSERT(widget); + const QString style(widget->parentWidget() ? widget->parentWidget()->style()->objectName() : QString()); + if (style == QLatin1String("windowsvista") // a hack + || style == QLatin1String("fusion")) + { + return QString(); + } + return QLatin1String("border: 0px; "); +} + bool KPropertyComboBoxEditor::listDataKeysAvailable() const { if (m_listData.keys.isEmpty()) { @@ -255,8 +265,9 @@ options.removeBorders = false; } -QString KPropertyComboBoxDelegate::displayTextForProperty( const KProperty* property ) const +QString KPropertyComboBoxDelegate::propertyValueToString(const KProperty* property, const QLocale &locale) const { + Q_UNUSED(locale) KPropertyListData *listData = property->listData(); if (!listData) return property->value().toString(); @@ -274,6 +285,12 @@ return property->listData()->names[ idx ]; } +QString KPropertyComboBoxDelegate::valueToString(const QVariant& value, const QLocale &locale) const +{ + Q_UNUSED(locale) + return value.toString(); +} + QWidget* KPropertyComboBoxDelegate::createEditor( int type, QWidget *parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const { diff --git a/src/editors/cursoredit.h b/src/editors/cursoredit.h --- a/src/editors/cursoredit.h +++ b/src/editors/cursoredit.h @@ -1,7 +1,7 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur Copyright (C) 2004 Alexander Dymo - Copyright (C) 2008 Jarosław Staniek + Copyright (C) 2008-2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -38,7 +38,8 @@ }; class KPROPERTYWIDGETS_EXPORT KPropertyCursorDelegate : public KPropertyEditorCreatorInterface, - public KPropertyValuePainterInterface + public KPropertyValuePainterInterface, + public KPropertyValueDisplayInterface { public: KPropertyCursorDelegate(); @@ -48,6 +49,8 @@ virtual void paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const; + + virtual QString valueToString(const QVariant& value, const QLocale &locale) const; }; #endif diff --git a/src/editors/cursoredit.cpp b/src/editors/cursoredit.cpp --- a/src/editors/cursoredit.cpp +++ b/src/editors/cursoredit.cpp @@ -1,7 +1,7 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur Copyright (C) 2004 Alexander Dymo - Copyright (C) 2008 Jarosław Staniek + Copyright (C) 2008-2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -21,6 +21,8 @@ #include "cursoredit.h" #include "KProperty.h" +#include "KPropertyCoreUtils_p.h" +#include "KPropertyUtils_p.h" #include "xpm/blank_cursor.xpm" #include "xpm/arrow_cursor.xpm" @@ -82,7 +84,7 @@ bg.setAlpha(127); px.fill(bg); QPainter p(&px); - p.drawPixmap(0, 0, xpm); + p.drawPixmap(0, 2, xpm); return px; } private: @@ -190,6 +192,21 @@ KPropertyCursorEditor::KPropertyCursorEditor(QWidget *parent) : KPropertyComboBoxEditor(*s_cursorListData, initComboBoxOptions( this ), parent) { + int paddingTop = 1; + int paddingLeft = 2; + const QString style(parent->style()->objectName()); + if (!KPropertyUtils::gridLineColor(this).isValid()) { + setFrame(false); + paddingTop = 0; + } + if (style == QLatin1String("windowsvista") || style == QLatin1String("fusion")) { + paddingLeft = 1; + } + QString styleSheet = QString::fromLatin1("QComboBox { \ + %1 \ + padding-top: %2px; padding-left: %3px; }").arg(KPropertyComboBoxEditor::borderSheet(this)) + .arg(paddingTop).arg(paddingLeft); + setStyleSheet(styleSheet); } KPropertyCursorEditor::~KPropertyCursorEditor() @@ -230,12 +247,20 @@ int pmSize = (option.rect.height() >= 32) ? 32 : 16; const QPixmap pm( s_cursorListData->pixmapForIndex(comboIndex, option.palette) .scaled(pmSize, pmSize, Qt::KeepAspectRatio, Qt::SmoothTransformation) ); - QPoint pmPoint(option.rect.topLeft()); - pmPoint.setX(pmPoint.x() + 2); + QPoint pmPoint(option.rect.topLeft() + QPoint(2, 1)); painter->drawPixmap(pmPoint, pm); QRect r(option.rect); - r.setLeft(2 + r.left() + 1 + pm.width()); - painter->drawText(r, Qt::AlignVCenter | Qt::AlignLeft, - s_cursorListData->names[ comboIndex ] ); + r.setLeft(7 + r.left() + 1 + pm.width()); + painter->drawText(r, Qt::AlignVCenter | Qt::AlignLeft, valueToString(index.data(Qt::EditRole), QLocale())); painter->restore(); } + +QString KPropertyCursorDelegate::valueToString(const QVariant& value, const QLocale &locale) const +{ + const Qt::CursorShape shape = value.value().shape(); + if (locale.language() == QLocale::C) { + return KPropertyUtils::keyForEnumValue("CursorShape", shape); + } + const int comboIndex = s_cursorListData->shapeToIndex(shape); + return s_cursorListData->names[comboIndex]; +} diff --git a/src/editors/dateedit.h b/src/editors/dateedit.h --- a/src/editors/dateedit.h +++ b/src/editors/dateedit.h @@ -1,7 +1,8 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur - Copyright (C) 2004 Alexander Dymo - Copyright (C) 2012 Friedrich W. H. Kossebau + Copyright (C) 2004 Alexander Dymo + Copyright (C) 2012 Friedrich W. H. Kossebau + Copyright (C) 2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -50,12 +51,12 @@ }; class KPROPERTYWIDGETS_EXPORT KPropertyDateDelegate : public KPropertyEditorCreatorInterface, - public KPropertyValueDisplayInterface + public KPropertyValueDisplayInterface { public: KPropertyDateDelegate(); - virtual QString displayTextForProperty(const KProperty* prop) const; + virtual QString valueToString(const QVariant& value, const QLocale &locale) const; virtual QWidget* createEditor(int type, QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const; diff --git a/src/editors/dateedit.cpp b/src/editors/dateedit.cpp --- a/src/editors/dateedit.cpp +++ b/src/editors/dateedit.cpp @@ -1,7 +1,8 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur - Copyright (C) 2004 Alexander Dymo - Copyright (C) 2012 Friedrich W. H. Kossebau + Copyright (C) 2004 Alexander Dymo + Copyright (C) 2012 Friedrich W. H. Kossebau + Copyright (C) 2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -77,11 +78,10 @@ { } -QString KPropertyDateDelegate::displayTextForProperty(const KProperty* prop) const +QString KPropertyDateDelegate::valueToString(const QVariant& value, const QLocale &locale) const { - const QLocale locale; const QString defaultDateFormat = locale.dateFormat(QLocale::ShortFormat); - return prop->value().toDate().toString(defaultDateFormat); + return value.toDate().toString(defaultDateFormat); } QWidget* KPropertyDateDelegate::createEditor(int type, QWidget* parent, diff --git a/src/editors/datetimeedit.h b/src/editors/datetimeedit.h --- a/src/editors/datetimeedit.h +++ b/src/editors/datetimeedit.h @@ -1,7 +1,8 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur - Copyright (C) 2004 Alexander Dymo - Copyright (C) 2012 Friedrich W. H. Kossebau + Copyright (C) 2004 Alexander Dymo + Copyright (C) 2012 Friedrich W. H. Kossebau + Copyright (C) 2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -50,12 +51,12 @@ }; class KPROPERTYWIDGETS_EXPORT KPropertyDateTimeDelegate : public KPropertyEditorCreatorInterface, - public KPropertyValueDisplayInterface + public KPropertyValueDisplayInterface { public: KPropertyDateTimeDelegate(); - virtual QString displayTextForProperty(const KProperty* prop) const; + virtual QString valueToString(const QVariant& value, const QLocale &locale) const; virtual QWidget* createEditor(int type, QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const; diff --git a/src/editors/datetimeedit.cpp b/src/editors/datetimeedit.cpp --- a/src/editors/datetimeedit.cpp +++ b/src/editors/datetimeedit.cpp @@ -1,7 +1,8 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur - Copyright (C) 2004 Alexander Dymo - Copyright (C) 2012 Friedrich W. H. Kossebau + Copyright (C) 2004 Alexander Dymo + Copyright (C) 2012 Friedrich W. H. Kossebau + Copyright (C) 2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -29,8 +30,6 @@ KPropertyDateTimeEditor::KPropertyDateTimeEditor(const KProperty* prop, QWidget* parent) : QDateTimeEdit(parent) { - Q_UNUSED(prop); - setFrame(false); setCalendarPopup(true); @@ -80,11 +79,10 @@ { } -QString KPropertyDateTimeDelegate::displayTextForProperty(const KProperty* prop) const +QString KPropertyDateTimeDelegate::valueToString(const QVariant& value, const QLocale &locale) const { - const QLocale locale; const QString defaultDateTimeFormat = locale.dateTimeFormat(QLocale::ShortFormat); - return prop->value().toDateTime().toString(defaultDateTimeFormat); + return value.toDateTime().toString(defaultDateTimeFormat); } QWidget* KPropertyDateTimeDelegate::createEditor(int type, QWidget* parent, diff --git a/src/editors/fontedit.h b/src/editors/fontedit.h --- a/src/editors/fontedit.h +++ b/src/editors/fontedit.h @@ -1,7 +1,7 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur - Copyright (C) 2004 Alexander Dymo - Copyright (C) 2005-2009 Jarosław Staniek + Copyright (C) 2004 Alexander Dymo + Copyright (C) 2005-2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -26,14 +26,19 @@ class KPROPERTYWIDGETS_EXPORT KPropertyFontDelegate : public KPropertyEditorCreatorInterface, - public KPropertyValuePainterInterface + public KPropertyValuePainterInterface, + public KPropertyValueDisplayInterface { public: - KPropertyFontDelegate() {} + KPropertyFontDelegate(); + virtual QWidget * createEditor( int type, QWidget *parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const; + virtual void paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const; + + virtual QString valueToString(const QVariant& value, const QLocale &locale) const; }; #endif diff --git a/src/editors/fontedit.cpp b/src/editors/fontedit.cpp --- a/src/editors/fontedit.cpp +++ b/src/editors/fontedit.cpp @@ -1,7 +1,7 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur - Copyright (C) 2004 Alexander Dymo - Copyright (C) 2005-2009 Jarosław Staniek + Copyright (C) 2004 Alexander Dymo + Copyright (C) 2005-2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -70,7 +70,7 @@ { bool ok; QFont font; - font = QFontDialog::getFont( &ok, parentWidget() ); + font = QFontDialog::getFont(&ok, m_font, parentWidget()); if (ok) { m_font = font; setValue(m_font); @@ -85,6 +85,10 @@ // ----------- +KPropertyFontDelegate::KPropertyFontDelegate() +{ +} + QWidget * KPropertyFontDelegate::createEditor( int type, QWidget *parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const { @@ -100,10 +104,6 @@ painter->save(); const QFont origFont( painter->font() ); QFont f( index.data(Qt::EditRole).value() ); - int size = f.pointSize(); // will be needed later - if (size == -1) { - size = f.pixelSize(); - } if (option.font.pointSize() > 0) f.setPointSize(option.font.pointSize()); else if (option.font.pixelSize() > 0) @@ -117,7 +117,38 @@ rect.setLeft(rect.left() + 5 + painter->fontMetrics().width( txt )); painter->setFont(origFont); - painter->drawText( rect, Qt::AlignLeft | Qt::AlignVCenter, - QObject::tr("%1, %2pt", "Font family and size, e.g. Arial, 2pt").arg(f.family()).arg(size)); + painter->drawText(rect, Qt::AlignLeft | Qt::AlignVCenter, valueToString(index.data(Qt::EditRole), QLocale())); painter->restore(); } + +QString KPropertyFontDelegate::valueToString(const QVariant& value, const QLocale &locale) const +{ + const QFont f(value.value()); + qreal size = f.pointSizeF(); + QString unit; + if (size == -1) { + size = f.pixelSize(); + unit = QLatin1String("px"); + } + else { + unit = QLatin1String("pt"); + } + QStringList list; + list << f.family(); + const bool translate = locale.language() == QLocale::C; + list << (translate ? QObject::tr("%1%2", ", e.g. 12pt").arg(size).arg(unit) + : QString::fromLatin1("%1%2").arg(size).arg(unit)); + if (f.bold()) { + list << (translate ? QObject::tr("bold", "bold font") : QLatin1String("bold")); + } + if (f.italic()) { + list << (translate ? QObject::tr("italic", "italic font") : QLatin1String("italic")); + } + if (f.strikeOut()) { + list << (translate ? QObject::tr("strikeout", "strikeout font") : QLatin1String("strikeout")); + } + if (f.underline()) { + list << (translate ? QObject::tr("underline", "underline font") : QLatin1String("underline")); + } + return QLocale::c().createSeparatedList(list); // yes, C locale, we just want ',' separator. +} diff --git a/src/editors/linestyleedit.h b/src/editors/linestyleedit.h --- a/src/editors/linestyleedit.h +++ b/src/editors/linestyleedit.h @@ -1,5 +1,5 @@ /* This file is part of the KDE project - Copyright (C) 2010 Jarosław Staniek + Copyright (C) 2010-2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -50,7 +50,8 @@ }; class KPROPERTYWIDGETS_EXPORT KPropertyLineStyleComboDelegate : public KPropertyEditorCreatorInterface, - public KPropertyValuePainterInterface + public KPropertyValuePainterInterface, + public KPropertyValueDisplayInterface { public: KPropertyLineStyleComboDelegate() {options.removeBorders = false;} @@ -60,6 +61,8 @@ virtual void paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const; + + virtual QString valueToString(const QVariant& value, const QLocale &locale) const; }; #endif diff --git a/src/editors/linestyleedit.cpp b/src/editors/linestyleedit.cpp --- a/src/editors/linestyleedit.cpp +++ b/src/editors/linestyleedit.cpp @@ -1,5 +1,5 @@ /* This file is part of the KDE project - Copyright (C) 2010 Jarosław Staniek + Copyright (C) 2010-2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -18,26 +18,36 @@ */ #include "linestyleedit.h" +#include "KPropertyWidgetsFactory.h" +#include "combobox.h" +#include "KPropertyLineStyleItemDelegate_p.h" +#include "KPropertyUtils_p.h" #include #include #include KPropertyLineStyleComboEditor::KPropertyLineStyleComboEditor(QWidget *parent) : KPropertyLineStyleSelector(parent) { - setFrame(false); connect(this, SIGNAL(activated(int)), this, SLOT(slotValueChanged(int))); - QString styleSheet; - QPalette p = QGuiApplication::palette(); - QColor focus = p.highlight().color(); - - styleSheet = QString::fromLatin1("KoLineStyleSelector { \ - border: 1px solid %1; \ - border-radius: 0px; \ - padding: 0px 18px; }").arg(focus.name()); - + int paddingTop = 1; + int paddingLeft = 0; + const QString style(parent->style()->objectName()); + if (!KPropertyUtils::gridLineColor(this).isValid()) { + setFrame(false); + paddingTop = 0; + } + if (style == QLatin1String("windows") || style == QLatin1String("fusion")) { + paddingLeft = 3; + } else if (style == QLatin1String("windowsvista")) { + paddingLeft = 2; + } + QString styleSheet = QString::fromLatin1("KPropertyLineStyleSelector { \ + %1 \ + padding-top: %2px; padding-left: %3px; }").arg(KPropertyComboBoxEditor::borderSheet(this)) + .arg(paddingTop).arg(paddingLeft); setStyleSheet(styleSheet); } @@ -52,7 +62,8 @@ static bool hasVisibleStyle(const QVariant &value) { - return !value.isNull() && value.canConvert(QVariant::Int) && value.toInt() < Qt::CustomDashLine; + return !value.isNull() && value.canConvert(QVariant::Int) && value.toInt() < Qt::CustomDashLine + && value.toInt() >= Qt::NoPen; } void KPropertyLineStyleComboEditor::setValue(const QVariant &value) @@ -82,19 +93,23 @@ const QStyleOptionViewItem & option, const QModelIndex & index ) const { painter->save(); - QPen pen(Qt::NoPen); + Qt::PenStyle penStyle = Qt::NoPen; if (hasVisibleStyle(index.data(Qt::EditRole))) { - pen.setBrush(option.palette.text()); - pen.setWidth(3); - pen.setStyle(static_cast(index.data(Qt::EditRole).toInt())); + penStyle = static_cast(index.data(Qt::EditRole).toInt()); } - painter->setPen(pen); const QWidget *paintedWidget = dynamic_cast(painter->device()); const QStyle *style = paintedWidget ? paintedWidget->style() : qApp->style(); QStyleOptionComboBox cbOption; cbOption.rect = option.rect; QRect r = style->subControlRect(QStyle::CC_ComboBox, &cbOption, QStyle::SC_ComboBoxEditField, 0); r.setRight(option.rect.right() - (r.left() - option.rect.left())); - painter->drawLine(r.left(), r.center().y(), r.right(), r.center().y()); + KPropertyLineStyleItemDelegate::paintItem(painter, QPen(penStyle), r, option); painter->restore(); } + +QString KPropertyLineStyleComboDelegate::valueToString(const QVariant& value, const QLocale &locale) const +{ + Qt::PenStyle style = (value.isNull() || !value.canConvert(QVariant::Int) || value.toInt() > Qt::CustomDashLine + || value.toInt() < Qt::NoPen) ? Qt::NoPen : static_cast(value.toInt()); + return KPropertyLineStyleItemDelegate::styleName(style, locale); +} diff --git a/src/editors/pixmapedit.h b/src/editors/pixmapedit.h --- a/src/editors/pixmapedit.h +++ b/src/editors/pixmapedit.h @@ -1,7 +1,7 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur - Copyright (C) 2004 Alexander Dymo - Copyright (C) 2005-2008 Jarosław Staniek + Copyright (C) 2004 Alexander Dymo + Copyright (C) 2005-2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -72,7 +72,8 @@ }; class KPROPERTYWIDGETS_EXPORT KPropertyPixmapDelegate : public KPropertyEditorCreatorInterface, - public KPropertyValuePainterInterface + public KPropertyValuePainterInterface, + public KPropertyValueDisplayInterface { public: KPropertyPixmapDelegate(); @@ -82,6 +83,8 @@ virtual void paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const; + + virtual QString valueToString(const QVariant& value, const QLocale &locale) const; }; #endif diff --git a/src/editors/pixmapedit.cpp b/src/editors/pixmapedit.cpp --- a/src/editors/pixmapedit.cpp +++ b/src/editors/pixmapedit.cpp @@ -1,7 +1,7 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur Copyright (C) 2004 Alexander Dymo - Copyright (C) 2005-2008 Jarosław Staniek + Copyright (C) 2005-2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -235,14 +235,13 @@ const QStyleOptionViewItem & option, const QModelIndex & index ) const { QPixmap pm( index.data(Qt::EditRole).value() ); - if (pm.isNull()) - return; painter->save(); - if (pm.height() > option.rect.height() || pm.width() > option.rect.width()) { //scale down - QImage img(pm.toImage()); - img = img.scaled(option.rect.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); - pm = QPixmap::fromImage(img); - } + if (!pm.isNull()) { + if (pm.height() > option.rect.height() || pm.width() > option.rect.width()) { //scale down + QImage img(pm.toImage()); + img = img.scaled(option.rect.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); + pm = QPixmap::fromImage(img); + } //! @todo /* if (m_recentlyPainted != value) { m_recentlyPainted = value; @@ -253,7 +252,26 @@ m_scaledPixmap = QPixmap::fromImage(img); } }*/ - painter->drawPixmap(option.rect.topLeft().x(), - option.rect.topLeft().y() + (option.rect.height() - pm.height()) / 2, pm); + painter->drawPixmap(option.rect.topLeft().x(), + option.rect.topLeft().y() + (option.rect.height() - pm.height()) / 2, pm); + } + QRect r(option.rect); + r.setLeft(r.left() + pm.width() + 2); + painter->drawText(r, valueToString(index.data(Qt::EditRole), QLocale())); painter->restore(); } + +QString KPropertyPixmapDelegate::valueToString(const QVariant& value, const QLocale &locale) const +{ + const QPixmap pm(value.value()); + if (pm.isNull()) { + if (locale.language() == QLocale::C) { + return QString(); + } + return QObject::tr("None", "No pixmap"); + } + if (locale.language() == QLocale::C) { + return QString::fromLatin1("%1x%2px").arg(pm.width()).arg(pm.height()); + } + return QObject::tr("%1x%2px").arg(locale.toString(pm.width())).arg(locale.toString(pm.height())); +} diff --git a/src/editors/pointedit.h b/src/editors/pointedit.h --- a/src/editors/pointedit.h +++ b/src/editors/pointedit.h @@ -1,7 +1,7 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur Copyright (C) 2004 Alexander Dymo - Copyright (C) 2008 Jarosław Staniek + Copyright (C) 2008-2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -37,11 +37,12 @@ }; class KPROPERTYWIDGETS_EXPORT KPropertyPointDelegate : public KPropertyLabelCreator, - public KComposedPropertyCreator + public KComposedPropertyCreator { public: - KPropertyPointDelegate() {} - virtual QString displayText( const QVariant& value ) const; + KPropertyPointDelegate(); + + virtual QString valueToString(const QVariant& value, const QLocale &locale) const; }; #endif diff --git a/src/editors/pointedit.cpp b/src/editors/pointedit.cpp --- a/src/editors/pointedit.cpp +++ b/src/editors/pointedit.cpp @@ -1,7 +1,7 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur Copyright (C) 2004 Alexander Dymo - Copyright (C) 2008 Jarosław Staniek + Copyright (C) 2008-2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -23,14 +23,25 @@ #include -static const char POINTEDIT_MASK[] = "%1, %2"; +KPropertyPointDelegate::KPropertyPointDelegate() +{ +} -QString KPropertyPointDelegate::displayText( const QVariant& value ) const +QString KPropertyPointDelegate::valueToString(const QVariant& value, const QLocale &locale) const { const QPoint p(value.toPoint()); - return QString::fromLatin1(POINTEDIT_MASK) - .arg(p.x()) - .arg(p.y()); + if (p.isNull()) { + if (locale.language() == QLocale::C) { + return QString(); + } + return QObject::tr("None", "Null value"); + } + if (locale.language() == QLocale::C) { + return QString::fromLatin1("%1, %2").arg(p.x()).arg(p.y()); + } + return QObject::tr("%1, %2", "Point") + .arg(locale.toString(p.x())) + .arg(locale.toString(p.y())); } //------------ diff --git a/src/editors/pointfedit.h b/src/editors/pointfedit.h --- a/src/editors/pointfedit.h +++ b/src/editors/pointfedit.h @@ -1,7 +1,7 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur Copyright (C) 2004 Alexander Dymo - Copyright (C) 2008 Jarosław Staniek + Copyright (C) 2008-2015 Jarosław Staniek Copyright (C) 2010 Adam Pigg This library is free software; you can redistribute it and/or @@ -38,11 +38,12 @@ }; class KPROPERTYWIDGETS_EXPORT KPropertyPointFDelegate : public KPropertyLabelCreator, - public KComposedPropertyCreator + public KComposedPropertyCreator { public: - KPropertyPointFDelegate() {} - virtual QString displayText( const QVariant& value ) const; + KPropertyPointFDelegate(); + + virtual QString valueToString(const QVariant& value, const QLocale &locale) const; }; #endif diff --git a/src/editors/pointfedit.cpp b/src/editors/pointfedit.cpp --- a/src/editors/pointfedit.cpp +++ b/src/editors/pointfedit.cpp @@ -1,7 +1,7 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur Copyright (C) 2004 Alexander Dymo - Copyright (C) 2008 Jarosław Staniek + Copyright (C) 2008-2015 Jarosław Staniek Copyright (C) 2010 Adam Pigg This library is free software; you can redistribute it and/or @@ -24,14 +24,25 @@ #include -static const char POINTFEDIT_MASK[] = "%1, %2"; +KPropertyPointFDelegate::KPropertyPointFDelegate() +{ +} -QString KPropertyPointFDelegate::displayText( const QVariant& value ) const +QString KPropertyPointFDelegate::valueToString(const QVariant& value, const QLocale &locale) const { const QPointF p(value.toPointF()); - return QString::fromLatin1(POINTFEDIT_MASK) - .arg(p.x()) - .arg(p.y()); + if (p.isNull()) { + if (locale.language() == QLocale::C) { + return QString(); + } + return QObject::tr("None", "Null value"); + } + if (locale.language() == QLocale::C) { + return QString::fromLatin1("%1, %2").arg(p.x()).arg(p.y()); + } + return QObject::tr("%1, %2", "Point") + .arg(locale.toString(p.x())) + .arg(locale.toString(p.y())); } //------------ diff --git a/src/editors/rectedit.h b/src/editors/rectedit.h --- a/src/editors/rectedit.h +++ b/src/editors/rectedit.h @@ -1,5 +1,5 @@ /* This file is part of the KDE project - Copyright (C) 2008 Jarosław Staniek + Copyright (C) 2008-2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -35,11 +35,12 @@ }; class KPROPERTYWIDGETS_EXPORT KPropertyRectDelegate : public KPropertyLabelCreator, - public KComposedPropertyCreator + public KComposedPropertyCreator { public: - KPropertyRectDelegate() {} - virtual QString displayText( const QVariant& value ) const; + KPropertyRectDelegate(); + + virtual QString valueToString(const QVariant& value, const QLocale &locale) const; }; #endif diff --git a/src/editors/rectedit.cpp b/src/editors/rectedit.cpp --- a/src/editors/rectedit.cpp +++ b/src/editors/rectedit.cpp @@ -1,5 +1,5 @@ /* This file is part of the KDE project - Copyright (C) 2008 Jarosław Staniek + Copyright (C) 2008-2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -21,16 +21,27 @@ #include -static const char RECTEDIT_MASK[] = "%1, %2, %3x%4"; +KPropertyRectDelegate::KPropertyRectDelegate() +{ +} -QString KPropertyRectDelegate::displayText( const QVariant& value ) const +QString KPropertyRectDelegate::valueToString(const QVariant& value, const QLocale &locale) const { const QRect r(value.toRect()); - return QString::fromLatin1(RECTEDIT_MASK) - .arg(r.x()) - .arg(r.y()) - .arg(r.width()) - .arg(r.height()); + if (r.isNull()) { + if (locale.language() == QLocale::C) { + return QString(); + } + return QObject::tr("None", "Null value"); + } + if (locale.language() == QLocale::C) { + return QString::fromLatin1("%1, %2, %3x%4").arg(r.x()).arg(r.y()).arg(r.width()).arg(r.height()); + } + return QObject::tr("%1, %2, %3x%4", "Rectangle") + .arg(locale.toString(r.x())) + .arg(locale.toString(r.y())) + .arg(locale.toString(r.width())) + .arg(locale.toString(r.height())); } //------------ diff --git a/src/editors/sizeedit.h b/src/editors/sizeedit.h --- a/src/editors/sizeedit.h +++ b/src/editors/sizeedit.h @@ -1,7 +1,7 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur Copyright (C) 2004 Alexander Dymo - Copyright (C) 2008 Jarosław Staniek + Copyright (C) 2008-2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -37,11 +37,12 @@ }; class KPROPERTYWIDGETS_EXPORT KPropertySizeDelegate : public KPropertyLabelCreator, - public KComposedPropertyCreator + public KComposedPropertyCreator { public: - KPropertySizeDelegate() {} - virtual QString displayText( const QVariant& value ) const; + KPropertySizeDelegate(); + + virtual QString valueToString(const QVariant& value, const QLocale &locale) const; }; #endif diff --git a/src/editors/sizeedit.cpp b/src/editors/sizeedit.cpp --- a/src/editors/sizeedit.cpp +++ b/src/editors/sizeedit.cpp @@ -1,5 +1,5 @@ /* This file is part of the KDE project - Copyright (C) 2008 Jarosław Staniek + Copyright (C) 2008-2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -21,14 +21,25 @@ #include -static const char SIZEEDIT_MASK[] = "%1x%2"; +KPropertySizeDelegate::KPropertySizeDelegate() +{ +} -QString KPropertySizeDelegate::displayText( const QVariant& value ) const +QString KPropertySizeDelegate::valueToString(const QVariant& value, const QLocale &locale) const { const QSize s(value.toSize()); - return QString::fromLatin1(SIZEEDIT_MASK) - .arg(s.width()) - .arg(s.height()); + if (s.isNull()) { + if (locale.language() == QLocale::C) { + return QString(); + } + return QObject::tr("None", "Null value"); + } + if (locale.language() == QLocale::C) { + return QString::fromLatin1("%1x%2").arg(s.width()).arg(s.height()); + } + return QObject::tr("%1x%2", "Size") + .arg(locale.toString(s.width())) + .arg(locale.toString(s.height())); } //------------ diff --git a/src/editors/sizefedit.h b/src/editors/sizefedit.h --- a/src/editors/sizefedit.h +++ b/src/editors/sizefedit.h @@ -1,7 +1,7 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur Copyright (C) 2004 Alexander Dymo - Copyright (C) 2008 Jarosław Staniek + Copyright (C) 2008-2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -37,11 +37,12 @@ }; class KPROPERTYWIDGETS_EXPORT KPropertySizeFDelegate : public KPropertyLabelCreator, - public KComposedPropertyCreator + public KComposedPropertyCreator { public: - KPropertySizeFDelegate() {} - virtual QString displayText( const QVariant& value ) const; + KPropertySizeFDelegate(); + + virtual QString valueToString(const QVariant& value, const QLocale &locale) const; }; #endif diff --git a/src/editors/sizefedit.cpp b/src/editors/sizefedit.cpp --- a/src/editors/sizefedit.cpp +++ b/src/editors/sizefedit.cpp @@ -1,5 +1,5 @@ /* This file is part of the KDE project - Copyright (C) 2008 Jarosław Staniek + Copyright (C) 2008-2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -21,14 +21,25 @@ #include -static const char SIZEFEDIT_MASK[] = "%1x%2"; +KPropertySizeFDelegate::KPropertySizeFDelegate() +{ +} -QString KPropertySizeFDelegate::displayText( const QVariant& value ) const +QString KPropertySizeFDelegate::valueToString(const QVariant& value, const QLocale &locale) const { const QSizeF s(value.toSizeF()); - return QString::fromLatin1(SIZEFEDIT_MASK) - .arg(s.width()) - .arg(s.height()); + if (s.isNull()) { + if (locale.language() == QLocale::C) { + return QString(); + } + return QObject::tr("None", "Null value"); + } + if (locale.language() == QLocale::C) { + return QString::fromLatin1("%1x%2").arg(s.width()).arg(s.height()); + } + return QObject::tr("%1x%2", "Size") + .arg(locale.toString(s.width())) + .arg(locale.toString(s.height())); } //------------ diff --git a/src/editors/sizepolicyedit.h b/src/editors/sizepolicyedit.h --- a/src/editors/sizepolicyedit.h +++ b/src/editors/sizepolicyedit.h @@ -1,5 +1,5 @@ /* This file is part of the KDE project - Copyright (C) 2008-2009 Jarosław Staniek + Copyright (C) 2008-2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -37,12 +37,12 @@ }; class KPROPERTYWIDGETS_EXPORT KPropertySizePolicyDelegate : public KPropertyLabelCreator, - public KComposedPropertyCreator + public KComposedPropertyCreator { public: - KPropertySizePolicyDelegate() {} + KPropertySizePolicyDelegate(); - virtual QString displayText( const QVariant& value ) const; + virtual QString valueToString(const QVariant& value, const QLocale &locale) const; static const KPropertyListData& listData(); }; diff --git a/src/editors/sizepolicyedit.cpp b/src/editors/sizepolicyedit.cpp --- a/src/editors/sizepolicyedit.cpp +++ b/src/editors/sizepolicyedit.cpp @@ -1,5 +1,5 @@ /* This file is part of the KDE project - Copyright (C) 2008-2009 Jarosław Staniek + Copyright (C) 2008-2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -18,6 +18,7 @@ */ #include "sizepolicyedit.h" +#include "KPropertyCoreUtils_p.h" #include @@ -66,17 +67,25 @@ //--------- -static const char SIZEPOLICY_MASK[] = "%1, %2, %3, %4"; +KPropertySizePolicyDelegate::KPropertySizePolicyDelegate() +{ +} -QString KPropertySizePolicyDelegate::displayText( const QVariant& value ) const +QString KPropertySizePolicyDelegate::valueToString(const QVariant& value, const QLocale &locale) const { const QSizePolicy sp(value.value()); - - return QString::fromLatin1(SIZEPOLICY_MASK) + if (locale.language() == QLocale::C) { + return QString::fromLatin1("%1, %2, %3, %4") + .arg(KPropertyUtils::keyForEnumValue("SizePolicy", sp.horizontalPolicy())) + .arg(KPropertyUtils::keyForEnumValue("SizePolicy", sp.verticalPolicy())) + .arg(sp.horizontalStretch()) + .arg(sp.verticalStretch()); + } + return QObject::tr("%1, %2, %3, %4", "Size Policy") .arg(s_sizePolicyListData->nameForPolicy(sp.horizontalPolicy())) .arg(s_sizePolicyListData->nameForPolicy(sp.verticalPolicy())) - .arg(sp.horizontalStretch()) - .arg(sp.verticalStretch()); + .arg(locale.toString(sp.horizontalStretch())) + .arg(locale.toString(sp.verticalStretch())); } //static diff --git a/src/editors/spinbox.h b/src/editors/spinbox.h --- a/src/editors/spinbox.h +++ b/src/editors/spinbox.h @@ -1,7 +1,7 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur Copyright (C) 2004 Alexander Dymo - Copyright (C) 2008 Jarosław Staniek + Copyright (C) 2008-2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -98,24 +98,28 @@ //! A delegate supporting Int, UInt, LongLong and ULongLong types class KPROPERTYWIDGETS_EXPORT KPropertyIntSpinBoxDelegate : public KPropertyEditorCreatorInterface, - public KPropertyValueDisplayInterface + public KPropertyValueDisplayInterface { public: KPropertyIntSpinBoxDelegate(); - virtual QString displayTextForProperty( const KProperty* prop ) const; + virtual QString propertyValueToString(const KProperty* prop, const QLocale &locale) const; + + virtual QString valueToString(const QVariant& value, const QLocale &locale) const; virtual QWidget * createEditor( int type, QWidget *parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const; }; class KPROPERTYWIDGETS_EXPORT KPropertyDoubleSpinBoxDelegate : public KPropertyEditorCreatorInterface, - public KPropertyValueDisplayInterface + public KPropertyValueDisplayInterface { public: KPropertyDoubleSpinBoxDelegate(); - virtual QString displayTextForProperty( const KProperty* prop ) const; + virtual QString propertyValueToString(const KProperty* prop, const QLocale &locale) const; + + virtual QString valueToString(const QVariant& value, const QLocale &locale) const; virtual QWidget * createEditor( int type, QWidget *parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const; diff --git a/src/editors/spinbox.cpp b/src/editors/spinbox.cpp --- a/src/editors/spinbox.cpp +++ b/src/editors/spinbox.cpp @@ -1,7 +1,7 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur Copyright (C) 2004 Alexander Dymo - Copyright (C) 2008-2009 Jarosław Staniek + Copyright (C) 2008-2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -72,7 +72,7 @@ // kprDebug() << parent->font().pointSize(); setFrame(true); QString css = cssForSpinBox("QSpinBox", font(), itemHeight); - KPropertyWidgetsFactory::setTopAndBottomBordersUsingStyleSheet(this, parent, css); + KPropertyWidgetsFactory::setTopAndBottomBordersUsingStyleSheet(this, css); setStyleSheet(css); QVariant minVal(prop->option("min", m_unsigned ? 0 : -INT_MAX)); @@ -143,15 +143,15 @@ le->setContentsMargins(0,0,0,0); le->setFrame(false); } -/* KPropertyFactory::setTopAndBottomBordersUsingStyleSheet(sb, parent, +/* KPropertyFactory::setTopAndBottomBordersUsingStyleSheet(sb, QString::fromLatin1( "QDoubleSpinBox { border-left: 0; border-right: 0; } " "QDoubleSpinBox::down-button { height: %1px; } " "QDoubleSpinBox::up-button { height: %2px; }" ).arg(itemHeight/2).arg(itemHeight - itemHeight/2) );*/ QString css = cssForSpinBox("QDoubleSpinBox", font(), itemHeight); - KPropertyWidgetsFactory::setTopAndBottomBordersUsingStyleSheet(this, parent, css); + KPropertyWidgetsFactory::setTopAndBottomBordersUsingStyleSheet(this, css); setStyleSheet(css); QVariant minVal(prop->option("min")); @@ -219,8 +219,12 @@ { } -QString KPropertyIntSpinBoxDelegate::displayTextForProperty( const KProperty* prop ) const +QString KPropertyIntSpinBoxDelegate::propertyValueToString(const KProperty* prop, + const QLocale &locale) const { + KPropertyUnit unit; + bool hasUnit; + decodeUnit(*prop, &unit, &hasUnit); if (prop->hasOptions()) { //replace min value with minValueText if defined QVariant minValue(prop->option("min")); @@ -231,7 +235,16 @@ return minValueText; } } - return QString::number(prop->value().toInt()); + if (hasUnit && locale.language() != QLocale::C) { + return QObject::tr("%1 %2", " ") + .arg(valueToString(prop->value(), locale)).arg(unit.toString()); + } + return valueToString(prop->value(), locale); +} + +QString KPropertyIntSpinBoxDelegate::valueToString(const QVariant& value, const QLocale &locale) const +{ + return locale.toString(value.toInt()); } QWidget* KPropertyIntSpinBoxDelegate::createEditor( int type, QWidget *parent, @@ -251,32 +264,41 @@ { } -QString KPropertyDoubleSpinBoxDelegate::displayTextForProperty( const KProperty* prop ) const +QString KPropertyDoubleSpinBoxDelegate::propertyValueToString(const KProperty* prop, + const QLocale &locale) const { KPropertyUnit unit; bool hasUnit; decodeUnit(*prop, &unit, &hasUnit); - QLocale locale; + int precision = -1; if (prop->hasOptions()) { //replace min value with minValueText if defined QVariant minValue(prop->option("min")); QString minValueText(prop->option("minValueText").toString()); if (!minValue.isNull() && !minValueText.isEmpty() && minValue.toDouble() == prop->value().toDouble()) { - if (hasUnit) - return QObject::tr("%1 %2", " ").arg(minValueText).arg(unit.toString()); - else - return minValueText; + return minValueText; + } + if (prop->option("precision").canConvert(QMetaType::Int)) { + precision = prop->option("precision").toInt(); } } //! @todo precision? //! @todo rounding using KLocale::formatNumber(const QString &numStr, bool round = true,int precision = 2)? - if (hasUnit) { + if (hasUnit && locale.language() != QLocale::C) { return QObject::tr("%1 %2", " ") - .arg(locale.toString(prop->value().toDouble())).arg(unit.toString()); + .arg(valueToString(prop->value(), locale)).arg(unit.toString()); + } + if (prop->value().canConvert(QMetaType::Double) && precision >= 0) { + return locale.toString(prop->value().toDouble(), 'f', precision); } - return locale.toString(prop->value().toDouble()); + return valueToString(prop->value(), locale); +} + +QString KPropertyDoubleSpinBoxDelegate::valueToString(const QVariant& value, const QLocale &locale) const +{ + return locale.toString(value.toDouble()); } QWidget* KPropertyDoubleSpinBoxDelegate::createEditor( int type, QWidget *parent, diff --git a/src/editors/timeedit.h b/src/editors/timeedit.h --- a/src/editors/timeedit.h +++ b/src/editors/timeedit.h @@ -1,7 +1,8 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur - Copyright (C) 2004 Alexander Dymo - Copyright (C) 2012 Friedrich W. H. Kossebau + Copyright (C) 2004 Alexander Dymo + Copyright (C) 2012 Friedrich W. H. Kossebau + Copyright (C) 2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -50,12 +51,12 @@ }; class KPROPERTYWIDGETS_EXPORT KPropertyTimeDelegate : public KPropertyEditorCreatorInterface, - public KPropertyValueDisplayInterface + public KPropertyValueDisplayInterface { public: KPropertyTimeDelegate(); - virtual QString displayTextForProperty(const KProperty* prop) const; + virtual QString valueToString(const QVariant& value, const QLocale &locale) const; virtual QWidget* createEditor(int type, QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const; diff --git a/src/editors/timeedit.cpp b/src/editors/timeedit.cpp --- a/src/editors/timeedit.cpp +++ b/src/editors/timeedit.cpp @@ -1,7 +1,8 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur - Copyright (C) 2004 Alexander Dymo - Copyright (C) 2012 Friedrich W. H. Kossebau + Copyright (C) 2004 Alexander Dymo + Copyright (C) 2012 Friedrich W. H. Kossebau + Copyright (C) 2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -28,6 +29,7 @@ : QTimeEdit(parent) { setFrame(false); + setContentsMargins(0,1,0,0); const QTime minTime = prop->option("min").toTime(); if (minTime.isValid()) { @@ -75,11 +77,16 @@ { } -QString KPropertyTimeDelegate::displayTextForProperty(const KProperty* prop) const +QString KPropertyTimeDelegate::valueToString(const QVariant& value, const QLocale &locale) const { - const QLocale locale; + if (locale.language() == QLocale::C) { + if (value.isNull()) { + return QString(); + } + return value.toTime().toString(Qt::ISODate); + } const QString defaultTimeFormat = locale.timeFormat(QLocale::ShortFormat); - return prop->value().toTime().toString(defaultTimeFormat); + return value.toTime().toString(defaultTimeFormat); } QWidget* KPropertyTimeDelegate::createEditor(int type, QWidget* parent,