diff --git a/examples/window.cpp b/examples/window.cpp index 0ae083c..ffbfd82 100644 --- a/examples/window.cpp +++ b/examples/window.cpp @@ -1,206 +1,232 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "window.h" #include #include #include #include #include #include #include #include #include #include #include #include #include +#include +#include Window::Window() : QWidget() , m_set(this, "example") , m_flatOption("flat", QCoreApplication::translate("main", "Flat display: do not display groups\n(useful for testing)")) , m_fontSizeOption("font-size", QCoreApplication::translate("main", "Set font size to (in points)\n(useful for testing whether editors keep the font settings)"), QCoreApplication::translate("main", "size")) , m_propertyOption("property", QCoreApplication::translate("main", "Display only specified property\n(useful when we want to focus on testing a single\nproperty editor)"), QCoreApplication::translate("main", "name")) , m_roOption("ro", QCoreApplication::translate("main", "Set all properties as read-only:\n(useful for testing read-only mode)")) { setObjectName("kpropertyexamplewindow"); setWindowIcon(QIcon::fromTheme("document-properties")); m_parser.setApplicationDescription(QCoreApplication::translate("main", "An example application for the KProperty library.")); m_parser.addHelpOption(); m_parser.addVersionOption(); parseCommandLine(); const QString singleProperty = m_parser.value(m_propertyOption); bool ok; const int fontSize = m_parser.value(m_fontSizeOption).toInt(&ok); if (fontSize > 0 && ok) { QFont f(font()); f.setPointSize(fontSize); setFont(f); } /* First, create the Set which will hold the properties. */ KProperty *p = 0; m_set.setReadOnly(m_parser.isSet(m_roOption)); QByteArray group; if (!m_parser.isSet(m_flatOption)) { group = "SimpleGroup"; m_set.setGroupDescription(group, "Simple Group"); } if (singleProperty.isEmpty() || singleProperty=="Name") { m_set.addProperty(new KProperty("Name", "Name"), group); m_set["Name"].setAutoSync(1); } if (singleProperty.isEmpty() || singleProperty=="Int") { 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); } if (singleProperty.isEmpty() || singleProperty=="3-State") { m_set.addProperty(p = new KProperty("3-State", QVariant(), "3 States", QString(), KProperty::Bool), group); p->setOption("3State", true); } if (singleProperty.isEmpty() || singleProperty=="Date") { m_set.addProperty(p = new KProperty("Date", QDate::currentDate(), "Date"), group); p->setIcon("date"); } if (singleProperty.isEmpty() || singleProperty=="Time") { m_set.addProperty(new KProperty("Time", QTime::currentTime(), "Time"), group); } if (singleProperty.isEmpty() || singleProperty=="DateTime") { m_set.addProperty(new KProperty("DateTime", QDateTime::currentDateTime(), "Date/Time"), group); } QStringList name_list; //strings name_list << "My Item" << "Other Item" << "Third Item"; if (singleProperty.isEmpty() || singleProperty=="List") { QStringList list;//keys list << "myitem" << "otheritem" << "3rditem"; m_set.addProperty(new KProperty("List", list, name_list, "otheritem", "List"), group); } if (singleProperty.isEmpty() || singleProperty=="List2") { // A valueFromList property matching strings with ints (could be any type supported by QVariant) QList keys; keys.append(1); keys.append(2); keys.append(3); KPropertyListData *listData = new KPropertyListData(keys, name_list); m_set.addProperty(new KProperty("List2", listData, 3, "List 2"), group); } // Complex if (!m_parser.isSet(m_flatOption)) { group = "ComplexGroup"; m_set.setGroupDescription(group, "Complex Group"); } if (singleProperty.isEmpty() || singleProperty=="Rect") { m_set.addProperty(new KProperty("Rect", QRect(5,11,100,200), "Rect"), group); } if (singleProperty.isEmpty() || singleProperty=="Point") { m_set.addProperty(new KProperty("Point", QPoint(3, 4), "Point"), group); } if (singleProperty.isEmpty() || singleProperty=="Size") { m_set.addProperty(new KProperty("Size", QSize(10, 20), "Size"), group); } if (singleProperty.isEmpty() || singleProperty=="RectF") { m_set.addProperty(new KProperty("RectF", QRectF(0.1, 0.5, 10.72, 18.21), "RectF"), group); } if (singleProperty.isEmpty() || singleProperty=="PointF") { m_set.addProperty(new KProperty("PointF", QPointF(3.14, 4.15), "PointF"), group); } if (singleProperty.isEmpty() || singleProperty=="SizeF") { m_set.addProperty(new KProperty("SizeF", QSizeF(1.1, 2.45), "SizeF"), group); } // Appearance if (!m_parser.isSet(m_flatOption)) { group = "Appearance Group"; m_set.setGroupDescription(group, "Appearance Group"); m_set.setGroupIcon(group, "appearance"); } if (singleProperty.isEmpty() || singleProperty=="Color") { m_set.addProperty(new KProperty("Color", palette().color(QPalette::Active, QPalette::Background), "Color"), group); } if (singleProperty.isEmpty() || singleProperty=="Pixmap") { QPixmap pm(QIcon::fromTheme("network-wired").pixmap(QSize(16,16))); m_set.addProperty(p = new KProperty("Pixmap", pm, "Pixmap"), group); 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"); } if (singleProperty.isEmpty() || singleProperty=="Cursor") { m_set.addProperty(new KProperty("Cursor", QCursor(Qt::WaitCursor), "Cursor"), group); } if (singleProperty.isEmpty() || singleProperty=="LineStyle") { m_set.addProperty(new KProperty("LineStyle", 3, "Line Style", QString(), KProperty::LineStyle), group); } if (singleProperty.isEmpty() || singleProperty=="SizePolicy") { QSizePolicy sp(sizePolicy()); sp.setHorizontalStretch(1); sp.setVerticalStretch(2); m_set.addProperty(new KProperty("SizePolicy", sp, "Size Policy"), group); } if (singleProperty.isEmpty() || singleProperty=="Invisible") { m_set.addProperty(p = new KProperty("Invisible", "I am invisible", "Invisible"), group); p->setVisible(false); } // 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; } Window::~Window() { } void Window::parseCommandLine() { m_parser.addOption(m_flatOption); m_parser.addOption(m_fontSizeOption); m_parser.addOption(m_propertyOption); 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/examples/window.h b/examples/window.h index e0d87b4..c9db58d 100644 --- a/examples/window.h +++ b/examples/window.h @@ -1,48 +1,58 @@ /* This file is part of the KDE project Copyright (C) 2004-2005 Cedric Pasteur Copyright (C) 2008-2009 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef WINDOW_H #define WINDOW_H #include #include #include +class QCheckBox; +class KPropertyEditorView; + /*! @internal * @short KPropertyExample application's main window */ class Window : public QWidget { Q_OBJECT public: Window(); virtual ~Window(); +protected Q_SLOTS: + void showGrid(int state); + void showFrame(int state); + private: void parseCommandLine(); KPropertySet m_set; QCommandLineParser m_parser; QCommandLineOption m_flatOption; QCommandLineOption m_fontSizeOption; QCommandLineOption m_propertyOption; QCommandLineOption m_roOption; + KPropertyEditorView *m_editorView; + QCheckBox *m_showGrid; + QCheckBox *m_showFrame; }; #endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a34d95c..5479578 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,260 +1,257 @@ # Options configure_file(config-kproperty.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-kproperty.h) set(kpropertycore_LIB_SRCS KProperty.cpp KPropertySet.cpp KPropertyUnit_p.cpp KPropertyFactory.cpp + KPropertyCoreUtils.cpp kproperty_debug.cpp ) if(KPROPERTY_WIDGETS) add_subdirectory(editors) set(kpropertywidgets_LIB_SRCS editors/utils.cpp editors/booledit.cpp + editors/coloredit.cpp editors/combobox.cpp editors/cursoredit.cpp editors/dateedit.cpp editors/datetimeedit.cpp # editors/dummywidget.cpp editors/fontedit.cpp editors/pixmapedit.cpp editors/pointedit.cpp editors/pointfedit.cpp editors/rectedit.cpp + editors/KPropertyRectFEditor.cpp editors/sizeedit.cpp editors/sizefedit.cpp editors/sizepolicyedit.cpp editors/spinbox.cpp editors/KPropertyStringEditor.cpp editors/linestyleedit.cpp # editors/stringlistedit.cpp # editors/symbolcombo.cpp editors/timeedit.cpp #TODO editors/urledit.cpp kproperty_debug.cpp # needed here too KPropertyWidgetsFactory.cpp KDefaultPropertyFactory.cpp KPropertyEditorView.cpp KPropertyEditorDataModel.cpp KPropertyUtils.cpp KPropertyLineStyleSelector_p.cpp KPropertyLineStyleModel_p.cpp 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 ${CMAKE_CURRENT_BINARY_DIR}/editors ) endif() set(kpropertycore_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} ) ecm_create_qm_loader(kpropertycore_LIB_SRCS kpropertycore_qt) add_library(KPropertyCore SHARED ${kpropertycore_LIB_SRCS}) target_link_libraries(KPropertyCore Qt5::Core ) generate_export_header(KPropertyCore) target_include_directories(KPropertyCore PUBLIC "$" INTERFACE "$" ) set_target_properties(KPropertyCore PROPERTIES VERSION 1.0 SOVERSION 1.0.0 EXPORT_NAME KPropertyCore ) if(KPROPERTY_WIDGETS) add_library(KPropertyWidgets SHARED ${kpropertywidgets_LIB_SRCS}) target_link_libraries(KPropertyWidgets KPropertyCore ) if(KPROPERTY_KF) target_link_libraries(KPropertyWidgets KF5::WidgetsAddons KF5::GuiAddons ) else() target_link_libraries(KPropertyWidgets Qt5::Widgets ) endif() generate_export_header(KPropertyWidgets) target_include_directories(KPropertyWidgets PUBLIC "$" INTERFACE "$" PRIVATE editors ) set_target_properties(KPropertyWidgets PROPERTIES VERSION 1.0 SOVERSION 1.0.0 EXPORT_NAME KPropertyWidgets ) endif() # Create a Config.cmake and a ConfigVersion.cmake file and install them set(CMAKECONFIG_CORE_INSTALL_DIR "${CMAKECONFIG_INSTALL_PREFIX}/KPropertyCore") # A place for KProperty plugins set(KPROPERTY_PLUGIN_INSTALL_DIR ${PLUGIN_INSTALL_DIR}/kproperty) ecm_setup_version(${KPROPERTY_VERSION} VARIABLE_PREFIX KPROPERTYCORE VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/kproperty_version.h" PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KPropertyCoreConfigVersion.cmake" ) ecm_configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/KPropertyCoreConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/KPropertyCoreConfig.cmake" INSTALL_DESTINATION "${CMAKECONFIG_CORE_INSTALL_DIR}" ) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/KPropertyCoreConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/KPropertyCoreConfigVersion.cmake" DESTINATION "${CMAKECONFIG_CORE_INSTALL_DIR}" COMPONENT Devel) if(SAILFISH) set(KDE_INSTALL_TARGETS_DEFAULT_ARGS LIBRARY DESTINATION lib) endif() install(TARGETS KPropertyCore EXPORT KPropertyCoreTargets ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) install(EXPORT KPropertyCoreTargets DESTINATION "${CMAKECONFIG_CORE_INSTALL_DIR}" FILE KPropertyCoreTargets.cmake) if(KPROPERTY_WIDGETS) set(CMAKECONFIG_WIDGETS_INSTALL_DIR "${CMAKECONFIG_INSTALL_PREFIX}/KPropertyWidgets") ecm_setup_version(${KPROPERTY_VERSION} VARIABLE_PREFIX KPROPERTYWIDGETS VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/kproperty_version.h" PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KPropertyWidgetsConfigVersion.cmake" ) ecm_configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/KPropertyWidgetsConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/KPropertyWidgetsConfig.cmake" INSTALL_DESTINATION "${CMAKECONFIG_WIDGETS_INSTALL_DIR}" ) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/KPropertyWidgetsConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/KPropertyWidgetsConfigVersion.cmake" DESTINATION "${CMAKECONFIG_WIDGETS_INSTALL_DIR}" COMPONENT Devel) install(TARGETS KPropertyWidgets EXPORT KPropertyWidgetsTargets ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) install(EXPORT KPropertyWidgetsTargets DESTINATION "${CMAKECONFIG_WIDGETS_INSTALL_DIR}" FILE KPropertyWidgetsTargets.cmake) endif() install(FILES ${PRI_FILENAME} DESTINATION ${ECM_MKSPECS_INSTALL_DIR}) if (GENERATE_PRI) ecm_generate_pri_file( BASE_NAME KPropertyCore LIB_NAME KPropertyCore DEPS "core" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${INCLUDE_INSTALL_DIR}/KPropertyCore ) if(KPROPERTY_WIDGETS) ecm_generate_pri_file( BASE_NAME KPropertyWidgets LIB_NAME KPropertyWidgets DEPS "widgets KPropertyCore" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${INCLUDE_INSTALL_DIR}/KPropertyWidgets ) endif() endif() #ecm_install_icons(${DATA_INSTALL_DIR}/kproperty/icons) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/kproperty_version.h" DESTINATION "${INCLUDE_INSTALL_DIR}" COMPONENT Devel) ecm_generate_headers(kpropertycore_FORWARDING_HEADERS REQUIRED_HEADERS kpropertycore_HEADERS ORIGINAL CAMELCASE HEADER_NAMES KProperty KPropertySet KPropertyFactory ) install( FILES ${kpropertycore_HEADERS} DESTINATION ${INCLUDE_INSTALL_DIR}/KPropertyCore COMPONENT Devel ) install( FILES ${kpropertycore_FORWARDING_HEADERS} ${PROJECT_BINARY_DIR}/src/kpropertycore_export.h ${PROJECT_BINARY_DIR}/src/config-kproperty.h DESTINATION ${INCLUDE_INSTALL_DIR}/KPropertyCore COMPONENT Devel ) if(KPROPERTY_WIDGETS) ecm_generate_headers(kpropertywidgets_FORWARDING_HEADERS REQUIRED_HEADERS kpropertywidgets_HEADERS ORIGINAL CAMELCASE HEADER_NAMES KPropertyWidgetsFactory KPropertyUtils KPropertyEditorView KPropertyEditorDataModel ) install( FILES ${kpropertywidgets_HEADERS} DESTINATION ${INCLUDE_INSTALL_DIR}/KPropertyWidgets COMPONENT Devel ) install( FILES ${kpropertywidgets_FORWARDING_HEADERS} ${PROJECT_BINARY_DIR}/src/kpropertywidgets_export.h DESTINATION ${INCLUDE_INSTALL_DIR}/KPropertyWidgets COMPONENT Devel ) endif() enable_testing() diff --git a/src/KDefaultPropertyFactory.cpp b/src/KDefaultPropertyFactory.cpp index 7aa8ed7..ce8a6d5 100644 --- a/src/KDefaultPropertyFactory.cpp +++ b/src/KDefaultPropertyFactory.cpp @@ -1,81 +1,79 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "KDefaultPropertyFactory.h" #include "config-kproperty.h" /* #include "customproperty.h"*/ #include "editors/booledit.h" +#include "editors/coloredit.h" #include "editors/combobox.h" #include "editors/cursoredit.h" #include "editors/dateedit.h" #include "editors/datetimeedit.h" // #include "editors/dummywidget.h" #include "editors/pixmapedit.h" #include "editors/pointedit.h" #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" #include "editors/spinbox.h" /*#include "stringlistedit.h"*/ #include "editors/linestyleedit.h" #include "editors/KPropertyStringEditor.h" // #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 similarity index 55% copy from src/KPropertyUtils.h copy to src/KPropertyCoreUtils.cpp index 544b694..7f8f877 100644 --- a/src/KPropertyUtils.h +++ b/src/KPropertyCoreUtils.cpp @@ -1,44 +1,39 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * 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 similarity index 67% copy from src/KPropertyUtils_p.h copy to src/KPropertyCoreUtils_p.h index 822a5f1..c019dec 100644 --- a/src/KPropertyUtils_p.h +++ b/src/KPropertyCoreUtils_p.h @@ -1,32 +1,35 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * 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); } #endif diff --git a/src/KPropertyEditorDataModel.cpp b/src/KPropertyEditorDataModel.cpp index 69b3836..241760f 100644 --- a/src/KPropertyEditorDataModel.cpp +++ b/src/KPropertyEditorDataModel.cpp @@ -1,289 +1,289 @@ /* This file is part of the KDE project Copyright (C) 2008-2009 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "KPropertyEditorDataModel.h" #include "KPropertyWidgetsFactory.h" #include "KProperty.h" #include "kproperty_debug.h" #include class KPropertyEditorDataModel::Private { public: explicit Private(KPropertySet *_set, KPropertySetIterator::Order _order = KPropertySetIterator::InsertionOrder) : set(_set), order(_order) { } KPropertySet *set; KProperty rootItem; QHash indicesForNames; KPropertySetIterator::Order order; //!< order of properties }; // ------------------- //! A property selector offering functor selecting only visible properties. /*! Used e.g. in EditorDataModel::index(). */ class VisiblePropertySelector : public KPropertySelector { public: VisiblePropertySelector() {} virtual bool operator()(const KProperty& prop) const { return prop.isVisible(); } KPropertySelector* clone() const { return new VisiblePropertySelector(); } }; // ------------------- KPropertyEditorDataModel::KPropertyEditorDataModel(KPropertySet &propertySet, QObject *parent, KPropertySetIterator::Order order) : QAbstractItemModel(parent) , d(new Private(&propertySet, order)) { collectIndices(); } KPropertyEditorDataModel::~KPropertyEditorDataModel() { delete d; } typedef QPair NameAndCaption; #if 0 static inline bool nameAndCaptionLessThan(const NameAndCaption &n1, const NameAndCaption &n2) { return QString::compare(n1.second, n2.second, Qt::CaseInsensitive) < 0; } #endif void KPropertyEditorDataModel::collectIndices() const { KPropertySetIterator it(*d->set, VisiblePropertySelector()); if (d->order == KPropertySetIterator::AlphabeticalOrder) { it.setOrder(KPropertySetIterator::AlphabeticalOrder); } d->indicesForNames.clear(); for (int row = 0; it.current(); row++, ++it) { // kprDebug() << it.current()->name() << "->" << row; d->indicesForNames.insert( it.current()->name(), QPersistentModelIndex( createIndex(row, 0, it.current()) ) ); } } QModelIndex KPropertyEditorDataModel::indexForPropertyName(const QByteArray& propertyName) const { return (const QModelIndex &)d->indicesForNames.value(propertyName); } QModelIndex KPropertyEditorDataModel::indexForColumn(const QModelIndex& index, int column) const { if (column == 0) return index; return createIndex(index.row(), column, propertyForItem(index)); } int KPropertyEditorDataModel::columnCount(const QModelIndex &parent) const { Q_UNUSED(parent); return 2; } QVariant KPropertyEditorDataModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); const int col = index.column(); if (col == 0) { KProperty *prop = propertyForItem(index); if (role == Qt::DisplayRole) { if (!prop->caption().isEmpty()) return prop->caption(); return prop->name(); } else if (role == PropertyModifiedRole) { return prop->isModified(); } } else if (col == 1) { KProperty *prop = propertyForItem(index); if (role == Qt::EditRole) { return prop->value(); } else if (role == Qt::DisplayRole) { - return KPropertyWidgetsFactoryManager::self()->convertValueToText(prop); + return KPropertyFactoryManager::self()->propertyValueToLocalizedString(prop); } } return QVariant(); } Qt::ItemFlags KPropertyEditorDataModel::flags(const QModelIndex &index) const { if (!index.isValid()) return Qt::ItemIsEnabled; const int col = index.column(); Qt::ItemFlags f = Qt::ItemIsEnabled | Qt::ItemIsSelectable; KProperty *prop = propertyForItem(index); if (prop) { if (col == 1) { f |= Qt::ItemIsEditable; } } return f; } KProperty *KPropertyEditorDataModel::propertyForItem(const QModelIndex &index) const { if (index.isValid()) { KProperty *item = static_cast(index.internalPointer()); if (item) return item; } return &d->rootItem; } QVariant KPropertyEditorDataModel::headerData(int section, Qt::Orientation orientation, int role) const { if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { if (section == 0) { return tr("Name", "Property name"); } else { return tr("Value", "Property value"); } } return QVariant(); } QModelIndex KPropertyEditorDataModel::index(int row, int column, const QModelIndex &parent) const { if (parent.isValid() && parent.column() != 0) return QModelIndex(); KProperty *parentItem = propertyForItem(parent); KProperty *childItem; if (parentItem == &d->rootItem) { // special case: top level int visibleRows = 0; KPropertySetIterator it(*d->set, VisiblePropertySelector()); if (d->order == KPropertySetIterator::AlphabeticalOrder) { it.setOrder(KPropertySetIterator::AlphabeticalOrder); } //! @todo use qBinaryFind()? for (; visibleRows < row && it.current(); visibleRows++, ++it) ; childItem = it.current(); } else { const QList* children = parentItem->children(); if (!children) return QModelIndex(); childItem = children->value(row); } if (!childItem) return QModelIndex(); return createIndex(row, column, childItem); } QModelIndex KPropertyEditorDataModel::parent(const QModelIndex &index) const { if (!index.isValid()) return QModelIndex(); KProperty *childItem = propertyForItem(index); KProperty *parentItem = childItem->parent(); if (!parentItem) return QModelIndex(); const QList* children = parentItem->children(); Q_ASSERT(children); const int indexOfItem = children->indexOf(childItem); Q_ASSERT(indexOfItem != -1); return createIndex(indexOfItem, 0, parentItem); } int KPropertyEditorDataModel::rowCount(const QModelIndex &parent) const { KProperty *parentItem = propertyForItem(parent); if (!parentItem || parentItem == &d->rootItem) { // top level return d->set->count(VisiblePropertySelector()); } const QList* children = parentItem->children(); return children ? children->count() : 0; } bool KPropertyEditorDataModel::setData(const QModelIndex &index, const QVariant &value, int role) { if (role != Qt::EditRole) return false; KProperty *item = propertyForItem(index); if (item == &d->rootItem) return false; item->setValue(value); return true; } bool KPropertyEditorDataModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role) { Q_UNUSED(section); Q_UNUSED(orientation); Q_UNUSED(value); Q_UNUSED(role); return false; } QModelIndex KPropertyEditorDataModel::buddy(const QModelIndex & idx) const { if (idx.column() == 0) return index( idx.row(), 1, parent(idx)); return idx; } KPropertySet& KPropertyEditorDataModel::propertySet() const { return *d->set; } void KPropertyEditorDataModel::setOrder(KPropertySetIterator::Order order) { if (d->order != order) { d->order = order; collectIndices(); } } KPropertySetIterator::Order KPropertyEditorDataModel::order() const { return d->order; } bool KPropertyEditorDataModel::hasChildren(const QModelIndex & parent) const { KProperty *parentItem = propertyForItem(parent); if (!parentItem || parentItem == &d->rootItem) { // top level return d->set->hasVisibleProperties(); } const QList* children = parentItem->children(); return children && !children->isEmpty(); } diff --git a/src/KPropertyEditorView.cpp b/src/KPropertyEditorView.cpp index a43bfa7..20b066e 100644 --- a/src/KPropertyEditorView.cpp +++ b/src/KPropertyEditorView.cpp @@ -1,581 +1,593 @@ /* This file is part of the KDE project Copyright (C) 2008-2009 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "KPropertyEditorView.h" #include "KPropertyEditorDataModel.h" #include "KProperty.h" #include "KPropertySet.h" #include "KPropertyWidgetsFactory.h" #include "kproperty_debug.h" +#include "KPropertyUtils_p.h" #include #include #include #include #include #include #include #include #include #if 0 // not sure if we should use it, better to fix Oxygen? #include //! Used to alter the widget's style at design time class EditorViewStyle : public KexiUtils::StyleProxy { public: explicit EditorViewStyle(QStyle* parentStyle) : KexiUtils::StyleProxy(parentStyle) { } virtual void drawPrimitive(PrimitiveElement elem, const QStyleOption* option, QPainter* painter, const QWidget* widget) const { /* if (elem == PE_PanelLineEdit) { const QStyleOptionFrame *panel = qstyleoption_cast(option); if (panel) { QStyleOptionFrame alteredOption(*panel); alteredOption.lineWidth = 0; KexiUtils::StyleProxy::drawPrimitive(elem, &alteredOption, painter, widget); return; } }*/ KexiUtils::StyleProxy::drawPrimitive(elem, option, painter, widget); } }; #endif static bool computeAutoSync(KProperty *property, bool defaultAutoSync) { return (property->autoSync() != 0 && property->autoSync() != 1) ? defaultAutoSync : (property->autoSync() != 0); } //---------- 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; virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; virtual QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const; mutable QPointer m_currentEditor; }; -ItemDelegate::ItemDelegate(QWidget *parent) +ItemDelegate::ItemDelegate(KPropertyEditorView *parent) : QItemDelegate(parent) { } ItemDelegate::~ItemDelegate() { } static int getIconSize(int fontPixelSize) { return fontPixelSize * 0.85; } static int typeForProperty( KProperty* prop ) { if (prop->listData()) return KProperty::ValueFromList; else return prop->type(); } void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, 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()); bool modified = false; if (index.column()==0) { r.setWidth(r.width() - 1); r.setLeft(0); QVariant modifiedVariant( editorModel->data(index, KPropertyEditorDataModel::PropertyModifiedRole) ); if (modifiedVariant.isValid() && modifiedVariant.toBool()) { modified = true; QFont font(alteredOption.font); font.setBold(true); alteredOption.font = font; } } else { r.setLeft(r.left()-1); } const int x2 = alteredOption.rect.right(); const int y2 = alteredOption.rect.bottom(); const int iconSize = getIconSize( alteredOption.font.pixelSize() ); if (modified) { alteredOption.rect.setRight( alteredOption.rect.right() - iconSize * 1 ); } KProperty *property = editorModel->propertyForItem(index); const int t = typeForProperty( property ); bool useQItemDelegatePaint = true; // ValueDisplayInterface is used by default if (index.column() == 1 && KPropertyWidgetsFactoryManager::self()->paint(t, painter, alteredOption, index)) { useQItemDelegatePaint = false; } if (useQItemDelegatePaint) { QItemDelegate::paint(painter, alteredOption, index); } if (modified) { alteredOption.rect.setRight( alteredOption.rect.right() - iconSize * 3 / 2 ); int y1 = alteredOption.rect.top(); QLinearGradient grad(x2 - iconSize * 2, y1, x2 - iconSize / 2, y1); QColor color( alteredOption.palette.color( (alteredOption.state & QStyle::State_Selected) ? QPalette::Highlight : QPalette::Base )); color.setAlpha(0); grad.setColorAt(0.0, color); color.setAlpha(255); grad.setColorAt(0.5, color); QBrush gradBrush(grad); painter->fillRect(x2 - iconSize * 2, y1, iconSize * 2, y2 - y1 + 1, gradBrush); QPixmap revertIcon(QIcon::fromTheme(QLatin1String("edit-undo")).pixmap(iconSize, iconSize)); //!TODO //revertIcon = KIconEffect().apply(revertIcon, KIconEffect::Colorize, 1.0, // alteredOption.palette.color( // (alteredOption.state & QStyle::State_Selected) ? QPalette::HighlightedText : QPalette::Text ), false); //painter->drawPixmap( x2 - iconSize - 2, // 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(); } QSize ItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { return QItemDelegate::sizeHint(option, index) + QSize(0, 2); } QWidget * ItemDelegate::createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const { if (!index.isValid()) return 0; 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()) { } } else { w = QItemDelegate::createEditor(parent, alteredOption, index); } QObject::disconnect(w, SIGNAL(commitData(QWidget*)), this, SIGNAL(commitData(QWidget*))); if (computeAutoSync( property, static_cast(this->parent())->isAutoSync() )) { QObject::connect(w, SIGNAL(commitData(QWidget*)), this, SIGNAL(commitData(QWidget*))); } m_currentEditor = w; return w; } //---------- class KPropertyEditorView::Private { public: Private() : set(0) , model(0) , gridLineColor( KPropertyEditorView::defaultGridLineColor() ) , autoSync(true) , slotPropertyChangedEnabled(true) { } KPropertySet *set; KPropertyEditorDataModel *model; ItemDelegate *itemDelegate; QColor gridLineColor; bool autoSync; bool slotPropertyChangedEnabled; }; KPropertyEditorView::KPropertyEditorView(QWidget* parent) : QTreeView(parent) , d( new Private ) { setObjectName(QLatin1String("KPropertyEditorView")); setAlternatingRowColors(true); setSelectionBehavior(QAbstractItemView::SelectRows); setSelectionMode(QAbstractItemView::SingleSelection); setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); setAnimated(false); setAllColumnsShowFocus(true); header()->setSectionsMovable(false); setEditTriggers( QAbstractItemView::CurrentChanged | QAbstractItemView::DoubleClicked | QAbstractItemView::EditKeyPressed | QAbstractItemView::AnyKeyPressed | QAbstractItemView::AllEditTriggers); setItemDelegate(d->itemDelegate = new ItemDelegate(this)); } KPropertyEditorView::~KPropertyEditorView() { delete d; } void KPropertyEditorView::changeSet(KPropertySet *set, SetOptions options) { changeSetInternal(set, options, QByteArray()); } void KPropertyEditorView::changeSet(KPropertySet *set, const QByteArray& propertyToSelect, SetOptions options) { changeSetInternal(set, options, propertyToSelect); } void KPropertyEditorView::changeSetInternal(KPropertySet *set, SetOptions options, const QByteArray& propertyToSelect) { //! @todo port?? #if 0 if (d->insideSlotValueChanged) { //changeSet() called from inside of slotValueChanged() //this is dangerous, because there can be pending events, //especially for the GUI stuff, so let's do delayed work d->setListLater_list = set; d->preservePrevSelection_preservePrevSelection = preservePrevSelection; d->preservePrevSelection_propertyToSelect = propertyToSelect; qApp->processEvents(QEventLoop::AllEvents); if (d->set) { //store prev. selection for this prop set if (d->currentItem) d->set->setPrevSelection(d->currentItem->property()->name()); kprDebug() << d->set->prevSelection(); } if (!d->setListLater_set) { d->setListLater_set = true; d->changeSetLaterTimer.setSingleShot(true); d->changeSetLaterTimer.start(10); } return; } #endif const bool setChanged = d->set != set; if (d->set) { acceptInput(); //store prev. selection for this prop set QModelIndex index = currentIndex(); if (index.isValid()) { //! @todo This crashes when changing the interpreter type in the script plugin #if 0 Property *property = d->model->propertyForItem(index); //if (property->isNull()) // kprDebug() << "WTF? a NULL property?"; //else //d->set->setPreviousSelection(property->name()); #endif } else { d->set->setPreviousSelection(QByteArray()); } if (setChanged) { d->set->disconnect(this); } } QByteArray selectedPropertyName1 = propertyToSelect; QByteArray selectedPropertyName2 = propertyToSelect; if (options & PreservePreviousSelection) { //try to find prev. selection: //1. in new list's prev. selection if (set) selectedPropertyName1 = set->previousSelection(); //2. in prev. list's current selection if (d->set) selectedPropertyName2 = d->set->previousSelection(); } if (setChanged) { d->set = set; } if (d->set && setChanged) { //receive property changes connect(d->set, SIGNAL(propertyChangedInternal(KPropertySet&,KProperty&)), this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); connect(d->set, SIGNAL(propertyReset(KPropertySet&,KProperty&)), this, SLOT(slotPropertyReset(KPropertySet&,KProperty&))); connect(d->set, SIGNAL(aboutToBeCleared()), this, SLOT(slotSetWillBeCleared())); connect(d->set, SIGNAL(aboutToBeDeleted()), this, SLOT(slotSetWillBeDeleted())); } KPropertyEditorDataModel *oldModel = d->model; const KPropertySetIterator::Order setOrder = (options & AlphabeticalOrder) ? KPropertySetIterator::AlphabeticalOrder : KPropertySetIterator::InsertionOrder; d->model = d->set ? new KPropertyEditorDataModel(*d->set, this, setOrder) : 0; setModel( d->model ); delete oldModel; if (d->model && d->set && !d->set->isEmpty() && (options & ExpandChildItems)) { const int rowCount = d->model->rowCount(); for (int row = 0; row < rowCount; row++) { expand( d->model->index(row, 0) ); } } emit propertySetChanged(d->set); if (d->set) { //select prev. selected item QModelIndex index; if (!selectedPropertyName2.isEmpty()) //try other one for old prop set index = d->model->indexForPropertyName( selectedPropertyName2 ); if (!index.isValid() && !selectedPropertyName1.isEmpty()) //try old one for current prop set index = d->model->indexForPropertyName( selectedPropertyName1 ); if (index.isValid()) { setCurrentIndex(index); scrollTo(index); } } } void KPropertyEditorView::slotSetWillBeCleared() { changeSet(0, QByteArray()); } void KPropertyEditorView::slotSetWillBeDeleted() { changeSet(0, QByteArray()); } void KPropertyEditorView::setAutoSync(bool enable) { d->autoSync = enable; } bool KPropertyEditorView::isAutoSync() const { return d->autoSync; } void KPropertyEditorView::currentChanged( const QModelIndex & current, const QModelIndex & previous ) { QTreeView::currentChanged( current, previous ); } bool KPropertyEditorView::edit( const QModelIndex & index, EditTrigger trigger, QEvent * event ) { bool result = QTreeView::edit( index, trigger, event ); if (result) { QLineEdit *lineEditEditor = dynamic_cast( (QObject*)d->itemDelegate->m_currentEditor ); if (lineEditEditor) { lineEditEditor->deselect(); lineEditEditor->end(false); } } return result; } void KPropertyEditorView::drawBranches( QPainter * painter, const QRect & rect, const QModelIndex & index ) const { QTreeView::drawBranches( painter, rect, index ); } QRect KPropertyEditorView::revertButtonArea( const QModelIndex& index ) const { if (index.column() != 0) return QRect(); QVariant modifiedVariant( d->model->data(index, KPropertyEditorDataModel::PropertyModifiedRole) ); if (!modifiedVariant.isValid() || !modifiedVariant.toBool()) return QRect(); const int iconSize = getIconSize( fontInfo().pixelSize() ); int x2 = columnWidth(0); int x1 = x2 - iconSize - 2; QRect r(visualRect(index)); // kprDebug() << r; r.setLeft(x1); r.setRight(x2); // kprDebug() << r; return r; } bool KPropertyEditorView::withinRevertButtonArea( int x, const QModelIndex& index ) const { QRect r(revertButtonArea( index )); if (!r.isValid()) return false; return r.left() < x && x < r.right(); } void KPropertyEditorView::mousePressEvent ( QMouseEvent * event ) { QTreeView::mousePressEvent( event ); QModelIndex index = indexAt( event->pos() ); setCurrentIndex(index); if (withinRevertButtonArea( event->x(), index )) { undo(); } } void KPropertyEditorView::undo() { if (!d->set || d->set->isReadOnly()) return; KProperty *property = d->model->propertyForItem(currentIndex()); if (computeAutoSync( property, d->autoSync )) property->resetValue(); } void KPropertyEditorView::acceptInput() { //! @todo } void KPropertyEditorView::commitData( QWidget * editor ) { d->slotPropertyChangedEnabled = false; QAbstractItemView::commitData( editor ); d->slotPropertyChangedEnabled = true; } bool KPropertyEditorView::viewportEvent( QEvent * event ) { if (event->type() == QEvent::ToolTip) { QHelpEvent *hevent = static_cast(event); const QModelIndex index = indexAt(hevent->pos()); if (index.column() == 0 && withinRevertButtonArea( hevent->x(), index )) { QRect r(revertButtonArea( index )); QToolTip::showText(hevent->globalPos(), tr("Undo changes"), this, r); } else { QToolTip::hideText(); } } return QTreeView::viewportEvent(event); } QColor KPropertyEditorView::gridLineColor() const { return d->gridLineColor; } void KPropertyEditorView::setGridLineColor(const QColor& color) { d->gridLineColor = color; + viewport()->update(); } static QModelIndex findChildItem(const KProperty& property, const QModelIndex &parent) { const KPropertyEditorDataModel *editorModel = dynamic_cast(parent.model()); if (editorModel->propertyForItem(parent) == &property) { return parent; } int row = 0; while (true) { QModelIndex childItem = parent.child(row, 0); if (childItem.isValid()) { QModelIndex subchild = findChildItem(property, childItem); if (subchild.isValid()) { return subchild; } } else { return QModelIndex(); } row++; } } void KPropertyEditorView::slotPropertyChanged(KPropertySet& set, KProperty& property) { Q_UNUSED(set); if (!d->slotPropertyChangedEnabled) return; d->slotPropertyChangedEnabled = false; KProperty *realProperty = &property; while (realProperty->parent()) { // find top-level property realProperty = realProperty->parent(); } const QModelIndex parentIndex( d->model->indexForPropertyName(realProperty->name()) ); if (parentIndex.isValid()) { QModelIndex index = findChildItem(property, parentIndex); updateSubtree(index); } d->slotPropertyChangedEnabled = true; } void KPropertyEditorView::updateSubtree(const QModelIndex &index) { if (!index.isValid()) { return; } update(index); QModelIndex valueIndex = d->model->indexForColumn(index, 1); if (valueIndex.isValid()) { update(valueIndex); } KProperty *property = static_cast(index.internalPointer()); if (property->children()) { int row = 0; foreach (KProperty* p, *property->children()) { updateSubtree(d->model->createIndex(row, 0, p)); ++row; } } } void KPropertyEditorView::slotPropertyReset(KPropertySet& set, KProperty& property) { //! @todo OK? slotPropertyChanged(set, property); } diff --git a/src/KPropertyEditorView.h b/src/KPropertyEditorView.h index 7d7f17e..b0138a7 100644 --- a/src/KPropertyEditorView.h +++ b/src/KPropertyEditorView.h @@ -1,166 +1,166 @@ /* This file is part of the KDE project Copyright (C) 2008-2009 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KPROPERTY_EDITORVIEW_H #define KPROPERTY_EDITORVIEW_H #include "kpropertywidgets_export.h" #include class KProperty; class KPropertySet; //! @brief A widget for editing properties //! @todo review this ............. /*! Editor widgets use property options using Property::option(const char *) to override default behaviour of editor items. Currently supported options are:
  • min: integer setting for minimum value for integer and double types. The default is 0. Set it to -1, if you want this special value to be allowed.
  • minValueText: user-visible translated string used for integer type to set "specialValueText" widget's property
  • max: integer setting for minimum value the property of integer type. Default is 0xffff.
  • precision: The number of decimals after the decimal point (for double types).
  • step: the size of the step that is taken when the user hits the up or down buttons (for double types).
  • 3State: boolean value used for boolean types; if true, the editor becomes a combobox (instead of checkable button) and accepta the third "null" state.
  • yesName: user-visible translated string used for boolean types (both 2- and 3-state) to display the "true" value. If not present, tr("Yes") is used.
  • noName: user-visible translated string used for boolean types (both 2- and 3-state) to display the "false" value. If not present, tr("No") is used.
  • 3rdStateName: user-visible translated string used for boolean types (both 2- and 3-state) to display the 3rd state "null" value. If not present, tr("None") is used.
  • nullName: user-visible translated string used for boolean types to display the "null" value if and only if the property accepts two states (i.e. when "3State" option is not true). If this option is not present, null values are displayed as false.
  • extraValueAllowed: Allow the user to manually enter a value into a combobox that is not in the list. The entered text will be returned as opposed to a matching key.
*/ class KPROPERTYWIDGETS_EXPORT KPropertyEditorView : public QTreeView { Q_OBJECT public: /*! Creates an empty property editor with @a parent as parent widget. */ explicit KPropertyEditorView(QWidget *parent = 0); ~KPropertyEditorView(); //! Options for changeSet(). enum SetOption { NoOptions = 0, PreservePreviousSelection = 1, //!< If used, previously selected editor item //!< will be kept selected. AlphabeticalOrder = 2, //!< Alphabetical order of properties (the default is insert-order) ExpandChildItems = 4 //!< Child property items are expanded (the default is "collapsed") }; Q_DECLARE_FLAGS(SetOptions, SetOption) //! @return grid line color, defaultGridLineColor() by default QColor gridLineColor() const; //! @return default grid line color - Qt::gray static QColor defaultGridLineColor() { return Qt::gray; } public Q_SLOTS: /*! Populates the editor view with items for each property from the @ set set. Child items for composed properties are also created. See SetOption documentation for description of @a options options. If @a preservePreviousSelection is true, previously selected editor item will be kept selected, if present. */ void changeSet(KPropertySet *set, SetOptions options = NoOptions); /*! Populates the editor view with items for each property from the @ set set. Child items for composed properties are also created. If @a propertyToSelect is provided, item for this property name will be selected, if present. */ void changeSet(KPropertySet *set, const QByteArray& propertyToSelect, SetOptions options = NoOptions); /*! If @a enable is true (the default), property values are automatically synced as soon as editor contents change (e.g. every time the user types a character) and the values are written back to the assigned property set. If @a enable is false, property set is updated only when selection within the property editor or user presses Enter/Return key. Each property can overwrite this setting by changing its own autoSync flag. */ void setAutoSync(bool enable); /*! @return value of autoSync flag. */ bool isAutoSync() const; /*! Accepts the changes made to the current editor item (if any) (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: /*! Emitted when current property set has been changed. May be 0. */ void propertySetChanged(KPropertySet *set); protected: virtual bool viewportEvent( QEvent * event ); protected Q_SLOTS: virtual void currentChanged( const QModelIndex & current, const QModelIndex & previous ); virtual void commitData( QWidget * editor ); /*! Called when current propertis of this set are about to be cleared. */ void slotSetWillBeCleared(); /*! Called when current property set is about to be destroyed. */ void slotSetWillBeDeleted(); /*! Updates editor widget in the editor.*/ void slotPropertyChanged(KPropertySet& set, KProperty& property); void slotPropertyReset(KPropertySet& set, KProperty& property); private: /*! Used by changeSet(). */ void changeSetInternal(KPropertySet *set, SetOptions options, const QByteArray& propertyToSelect); virtual bool edit( const QModelIndex & index, EditTrigger trigger, QEvent * event ); virtual void drawBranches( QPainter * painter, const QRect & rect, const QModelIndex & index ) const; virtual void mousePressEvent( QMouseEvent * event ); //! @return true if @a x is within the area of the revert button for @a index index. bool withinRevertButtonArea( int x, const QModelIndex& index ) const; //! @return area of revert button, if it is displayed for @a index index. //! Otherwise invalid QRect is returned. QRect revertButtonArea( const QModelIndex& index ) const; //! Updates item for @a index and all its children. void updateSubtree(const QModelIndex &index); /*! Undoes the last change in the property editor.*/ void undo(); class Private; Private * const d; }; Q_DECLARE_OPERATORS_FOR_FLAGS(KPropertyEditorView::SetOptions) #endif diff --git a/src/KPropertyFactory.cpp b/src/KPropertyFactory.cpp index 7377b9d..492638a 100644 --- a/src/KPropertyFactory.cpp +++ b/src/KPropertyFactory.cpp @@ -1,190 +1,287 @@ /* This file is part of the KDE project 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "KPropertyFactory.h" //--------------- //! @internal class KPropertyFactoryManager::Private { public: Private() { } ~Private() { qDeleteAll(factories); } QSet factories; QHash composedPropertyCreators; + QHash valueDisplays; }; Q_GLOBAL_STATIC(KPropertyFactoryManager, _self) //! @internal class KPropertyFactory::Private { public: Private() { } ~Private() { + qDeleteAll(valueDisplaysSet); } QHash composedPropertyCreators; QSet composedPropertyCreatorsSet; + QHash valueDisplays; + QSet valueDisplaysSet; }; typedef QList InitFunctions; //! @internal Used by KPropertyFactoryManager::addInitFunction() Q_GLOBAL_STATIC(InitFunctions, _initFunctions) KPropertyFactory::KPropertyFactory() : d( new Private ) { } KPropertyFactory::~KPropertyFactory() { delete d; } QHash KPropertyFactory::composedPropertyCreators() const { return d->composedPropertyCreators; } +QHash KPropertyFactory::valueDisplays() const +{ + return d->valueDisplays; +} + void KPropertyFactory::addComposedPropertyCreator( int type, KComposedPropertyCreatorInterface* creator ) { addComposedPropertyCreatorInternal( type, creator, true ); } void KPropertyFactory::addComposedPropertyCreatorInternal(int type, KComposedPropertyCreatorInterface* creator, bool own) { if (own) d->composedPropertyCreatorsSet.insert(creator); 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() : QObject(0) , d(new Private) { setObjectName(QLatin1String("KPropertyFactoryManager")); } KPropertyFactoryManager::~KPropertyFactoryManager() { delete d; } KPropertyFactoryManager* KPropertyFactoryManager::self() { if (_self.exists()) { // avoid recursion: initFunctions below may call self() return _self; } _self(); // KPropertyFactoryManager should exist as initFunctions may need it foreach(void (*initFunction)(), *_initFunctions) { initFunction(); } _initFunctions->clear(); return _self; } void KPropertyFactoryManager::registerFactory(KPropertyFactory *factory) { d->factories.insert(factory); QHash::ConstIterator composedPropertyCreatorsItEnd = factory->composedPropertyCreators().constEnd(); for (QHash::ConstIterator it( factory->composedPropertyCreators().constBegin() ); it != composedPropertyCreatorsItEnd; ++it) { 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) { const KComposedPropertyCreatorInterface *creator = d->composedPropertyCreators.value( parent->type() ); return creator ? creator->createComposedProperty(parent) : 0; } //static void KPropertyFactoryManager::addInitFunction(void (*initFunction)()) { _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(); /* CustomPropertyFactory *factory = d->registeredWidgets[type]; if (factory) return factory->createCustomProperty(parent); */ switch (type) { case Size: case Size_Width: case Size_Height: return new SizeCustomProperty(parent); case Point: case Point_X: case Point_Y: return new PointCustomProperty(parent); case Rect: case Rect_X: case Rect_Y: case Rect_Width: case Rect_Height: return new RectCustomProperty(parent); case SizePolicy: /* case SizePolicy_HorizontalStretch: case SizePolicy_VerticalStretch: case SizePolicy_HorizontalPolicy: case SizePolicy_VerticalPolicy:*/ return new SizePolicyCustomProperty(parent); default:; } return 0; #endif KComposedPropertyInterface::KComposedPropertyInterface(KProperty *parent) : m_childValueChangedEnabled(true) { Q_UNUSED(parent) } KComposedPropertyInterface::~KComposedPropertyInterface() { } KComposedPropertyCreatorInterface::KComposedPropertyCreatorInterface() { } KComposedPropertyCreatorInterface::~KComposedPropertyCreatorInterface() { } diff --git a/src/KPropertyFactory.h b/src/KPropertyFactory.h index 6d37fbb..9a31d24 100644 --- a/src/KPropertyFactory.h +++ b/src/KPropertyFactory.h @@ -1,139 +1,182 @@ /* This file is part of the KDE project 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KPROPERTY_FACTORY_H #define KPROPERTY_FACTORY_H #include "KProperty.h" #include #include #include //! An interface for for composed property handlers /*! You have to subclass KComposedPropertyInterface to override the behaviour of a property type.\n In the constructor, you should create the child properties (if needed). Then, you need to implement the functions concerning values.\n Example implementation of composed properties can be found in editors/ directory. */ class KPROPERTYCORE_EXPORT KComposedPropertyInterface { public: explicit KComposedPropertyInterface(KProperty *parent); virtual ~KComposedPropertyInterface(); /*! This function modifies the child properties for parent value @a value. It is called by @ref Property::setValue() when the property is composed. You don't have to modify the property value, it is done by Property class. Note that when calling Property::setValue, you need to set useComposedProperty (the third parameter) to false, or there will be infinite recursion. */ virtual void setValue(KProperty *property, const QVariant &value, bool rememberOldValue) = 0; void childValueChangedInternal(KProperty *child, const QVariant &value, bool rememberOldValue) { if (m_childValueChangedEnabled) childValueChanged(child, value, rememberOldValue); } void setChildValueChangedEnabled(bool set) { m_childValueChangedEnabled = set; } /*! @return true if values @a first and @a second are equal. Used in KProperty::setValue() to check if value has been changed before setting value. Default implementation uses operator==. */ inline virtual bool valuesEqual(const QVariant &first, const QVariant &second) { return first == second; } protected: virtual void childValueChanged(KProperty *child, const QVariant &value, bool rememberOldValue) = 0; /*! This method emits the \a Set::propertyChanged() signal for all sets our parent-property is registered in. */ void emitPropertyChanged(); bool m_childValueChangedEnabled : 1; }; class KPROPERTYCORE_EXPORT KComposedPropertyCreatorInterface { public: KComposedPropertyCreatorInterface(); virtual ~KComposedPropertyCreatorInterface(); virtual KComposedPropertyInterface* createComposedProperty(KProperty *parent) const = 0; }; //! Creator returning composed property object template class KComposedPropertyCreator : public KComposedPropertyCreatorInterface { public: KComposedPropertyCreator() : KComposedPropertyCreatorInterface() {} virtual ~KComposedPropertyCreator() {} virtual ComposedProperty* createComposedProperty(KProperty *parent) const { return new ComposedProperty(parent); } }; +//! 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 public: KComposedPropertyInterface* createComposedProperty(KProperty *parent); //! Registers factory @a factory. It becomes owned by the manager. void registerFactory(KPropertyFactory *factory); /*! \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(); //! Adds function @a initFunction that will be called after the manager is created. //! Useful for creation custom factories. static void addInitFunction(void (*initFunction)()); private: class Private; Private * const d; }; #endif diff --git a/src/KPropertyLineStyleItemDelegate_p.cpp b/src/KPropertyLineStyleItemDelegate_p.cpp index d5c30db..7977d1d 100644 --- a/src/KPropertyLineStyleItemDelegate_p.cpp +++ b/src/KPropertyLineStyleItemDelegate_p.cpp @@ -1,58 +1,101 @@ /* 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 * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "KPropertyLineStyleItemDelegate_p.h" +#include "KPropertyCoreUtils_p.h" #include #include KPropertyLineStyleItemDelegate::KPropertyLineStyleItemDelegate(QObject * parent) : QAbstractItemDelegate(parent) { } KPropertyLineStyleItemDelegate::~KPropertyLineStyleItemDelegate() { } +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 { painter->save(); if (option.state & QStyle::State_Selected) 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(); } QSize KPropertyLineStyleItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { Q_UNUSED(option); Q_UNUSED(index); return QSize(100, 15); } diff --git a/src/KPropertyLineStyleItemDelegate_p.h b/src/KPropertyLineStyleItemDelegate_p.h index 842c2ba..c860331 100644 --- a/src/KPropertyLineStyleItemDelegate_p.h +++ b/src/KPropertyLineStyleItemDelegate_p.h @@ -1,34 +1,39 @@ /* 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 * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KPROPERTYLINESTYLEITEMDELEGATE_H #define KPROPERTYLINESTYLEITEMDELEGATE_H #include /// The line style item delegate for rendering the styles class KPropertyLineStyleItemDelegate : public QAbstractItemDelegate { public: explicit KPropertyLineStyleItemDelegate(QObject *parent = 0); 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/KPropertyLineStyleModel_p.cpp b/src/KPropertyLineStyleModel_p.cpp index 147522d..6101ae3 100644 --- a/src/KPropertyLineStyleModel_p.cpp +++ b/src/KPropertyLineStyleModel_p.cpp @@ -1,101 +1,101 @@ /* This file is part of the KDE project * Copyright (C) 2007 Jan Hambrecht * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "KPropertyLineStyleModel_p.h" #include KPropertyLineStyleModel::KPropertyLineStyleModel(QObject *parent) : QAbstractListModel(parent), m_hasTempStyle(false) { // add standard dash patterns for (int i = Qt::NoPen; i < Qt::CustomDashLine; i++) { QPen pen(static_cast(i)); m_styles << pen.dashPattern(); } } int KPropertyLineStyleModel::rowCount(const QModelIndex &/*parent*/) const { return m_styles.count() + (m_hasTempStyle ? 1 : 0); } QVariant KPropertyLineStyleModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); 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()) pen.setDashPattern(m_styles[index.row()]); else if (m_hasTempStyle) pen.setDashPattern(m_tempStyle); else pen.setStyle(Qt::NoPen); return QVariant(pen); } case Qt::SizeHintRole: return QSize(100, 15); default: return QVariant(); } } bool KPropertyLineStyleModel::addCustomStyle(const QVector &style) { if (m_styles.contains(style)) return false; m_styles.append(style); return true; } int KPropertyLineStyleModel::setLineStyle(Qt::PenStyle style, const QVector &dashes) { // check if we select a standard or custom style if (style < Qt::CustomDashLine) { // a standard style m_hasTempStyle = false; //reset(); return style; } else if (style == Qt::CustomDashLine) { // a custom style -> check if already added int index = m_styles.indexOf(dashes, Qt::CustomDashLine); if (index < 0) { // not already added -> add temporarly m_tempStyle = dashes; m_hasTempStyle = true; //reset(); return m_styles.count(); } else { // already added -> return index m_hasTempStyle = false; //reset(); return index; } } return -1; } diff --git a/src/KPropertyLineStyleSelector_p.cpp b/src/KPropertyLineStyleSelector_p.cpp index 67ace34..2b31881 100644 --- a/src/KPropertyLineStyleSelector_p.cpp +++ b/src/KPropertyLineStyleSelector_p.cpp @@ -1,91 +1,91 @@ /* 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 * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "KPropertyLineStyleSelector_p.h" #include "KPropertyLineStyleModel_p.h" #include "KPropertyLineStyleItemDelegate_p.h" +#include "KPropertyWidgetsFactory.h" #include #include class KPropertyLineStyleSelector::Private { public: Private(QWidget *parent) : model(new KPropertyLineStyleModel(parent)) { } KPropertyLineStyleModel *model; }; KPropertyLineStyleSelector::KPropertyLineStyleSelector(QWidget *parent) : QComboBox(parent), d(new Private(this)) { setModel(d->model); setItemDelegate(new KPropertyLineStyleItemDelegate(this)); + setEditable(false); + setInsertPolicy(QComboBox::NoInsert); + setContextMenuPolicy(Qt::NoContextMenu); } KPropertyLineStyleSelector::~KPropertyLineStyleSelector() { delete d; } void KPropertyLineStyleSelector::paintEvent(QPaintEvent *pe) { QComboBox::paintEvent(pe); QStyleOptionComboBox option; 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) { return d->model->addCustomStyle(style); } void KPropertyLineStyleSelector::setLineStyle(Qt::PenStyle style, const QVector &dashes) { int index = d->model->setLineStyle(style, dashes); if (index >= 0) setCurrentIndex(index); } Qt::PenStyle KPropertyLineStyleSelector::lineStyle() const { QPen pen = itemData(currentIndex(), Qt::DecorationRole).value(); return pen.style(); } QVector KPropertyLineStyleSelector::lineDashes() const { QPen pen = itemData(currentIndex(), Qt::DecorationRole).value(); return pen.dashPattern(); } diff --git a/src/KPropertyLineStyleSelector_p.h b/src/KPropertyLineStyleSelector_p.h index 1f8325f..12a555d 100644 --- a/src/KPropertyLineStyleSelector_p.h +++ b/src/KPropertyLineStyleSelector_p.h @@ -1,71 +1,72 @@ /* 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 * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KPROPERTYLINESTYLESELECTOR_H #define KPROPERTYLINESTYLESELECTOR_H #include "kpropertywidgets_export.h" #include /** * A custom combobox widget for selecting line styles. */ class KPROPERTYWIDGETS_EXPORT KPropertyLineStyleSelector : public QComboBox { Q_OBJECT public: explicit KPropertyLineStyleSelector(QWidget *parent = 0); virtual ~KPropertyLineStyleSelector(); /** * Adds a new line style to the combobox. * * If the style already exists, it is not added to the selector. * * @param style the line style to add * @return true if style is unique among the existing styles and was added, else false */ bool addCustomStyle(const QVector &style); /** * Selects the specified style. * * If the style was already added it gets selected. If the style was not added already * it gets temporary added and selected. * * @param style the style to display * @param dashes the dashes of the style if style == Qt::CustomDashLine */ void setLineStyle(Qt::PenStyle style, const QVector &dashes = QVector()); /// Returns the current line style Qt::PenStyle lineStyle() const; /// Returns the dashes of the current line style QVector lineDashes() const; protected: void paintEvent(QPaintEvent *pe); private: class Private; Private * const d; }; #endif diff --git a/src/KPropertyUtils.cpp b/src/KPropertyUtils.cpp index 018cf09..cea7f12 100644 --- a/src/KPropertyUtils.cpp +++ b/src/KPropertyUtils.cpp @@ -1,234 +1,245 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "KPropertyUtils.h" #include "KPropertyUtils_p.h" #include "KPropertyEditorView.h" #include #include #include #include #include #include #include #include +#include #define BRANCHBOX_SIZE 9 //! @internal static void paintListViewExpander(QPainter* p, QWidget* w, int height, const QPalette& palette, bool isOpen) { const int marg = (height - 2 - BRANCHBOX_SIZE) / 2; int xmarg = marg; #if 0 //! @todo disabled: kstyles do not paint background yet... reenable in the future... KStyle* kstyle = dynamic_cast(widget->style()); if (kstyle) { kstyle->drawKStylePrimitive( KStyle::KPE_ListViewExpander, p, w, QRect(xmarg, marg, BRANCHBOX_SIZE, BRANCHBOX_SIZE), cg, isOpen ? 0 : QStyle::Style_On, QStyleOption::Default); } #endif Q_UNUSED(w); //draw by hand p->setPen(KPropertyEditorView::defaultGridLineColor()); p->drawRect(xmarg, marg, BRANCHBOX_SIZE, BRANCHBOX_SIZE); p->fillRect(xmarg + 1, marg + 1, BRANCHBOX_SIZE - 2, BRANCHBOX_SIZE - 2, palette.brush(QPalette::Base)); p->setPen(palette.color(QPalette::Foreground)); p->drawLine(xmarg + 2, marg + BRANCHBOX_SIZE / 2, xmarg + BRANCHBOX_SIZE - 3, marg + BRANCHBOX_SIZE / 2); if (!isOpen) { p->drawLine(xmarg + BRANCHBOX_SIZE / 2, marg + 2, xmarg + BRANCHBOX_SIZE / 2, marg + BRANCHBOX_SIZE - 3); } } //! @internal //! Based on KPopupTitle, see kpopupmenu.cpp class GroupWidgetBase : public QWidget { public: explicit GroupWidgetBase(QWidget* parent) : QWidget(parent) , m_isOpen(true) , m_mouseDown(false) { QSizePolicy sp(QSizePolicy::Preferred, QSizePolicy::Fixed); sp.setHorizontalStretch(0); sp.setVerticalStretch(1); setSizePolicy(sp); } void setText(const QString &text) { m_titleStr = text; } void setIcon(const QPixmap &pix) { m_miniicon = pix; } virtual bool isOpen() const { return m_isOpen; } virtual void setOpen(bool set) { m_isOpen = set; } virtual QSize sizeHint() const { QSize s(QWidget::sizeHint()); s.setHeight(fontMetrics().height()*2); return s; } protected: virtual void paintEvent(QPaintEvent *) { QRect r(rect()); QPainter p(this); QStyleOptionHeader option; option.initFrom(this); option.state = m_mouseDown ? QStyle::State_Sunken : QStyle::State_Raised; style()->drawControl(QStyle::CE_Header, &option, &p, this); paintListViewExpander(&p, this, r.height() + 2, palette(), isOpen()); if (!m_miniicon.isNull()) { p.drawPixmap(24, (r.height() - m_miniicon.height()) / 2, m_miniicon); } if (!m_titleStr.isEmpty()) { int indent = 16 + (m_miniicon.isNull() ? 0 : (m_miniicon.width() + 4)); p.setPen(palette().color(QPalette::Text)); QFont f = p.font(); f.setBold(true); p.setFont(f); p.drawText(indent + 8, 0, width() - (indent + 8), height(), Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, m_titleStr); } } virtual bool event(QEvent * e) { if (e->type() == QEvent::MouseButtonPress || e->type() == QEvent::MouseButtonRelease) { QMouseEvent* me = static_cast(e); if (me->button() == Qt::LeftButton) { m_mouseDown = e->type() == QEvent::MouseButtonPress; update(); } } return QWidget::event(e); } protected: QString m_titleStr; QPixmap m_miniicon; bool m_isOpen; bool m_mouseDown; }; /* class GroupWidget : public GroupWidgetBase { public: explicit GroupWidget(EditorGroupItem *parentItem) : GroupWidgetBase(parentItem->listView()->viewport()) , m_parentItem(parentItem) { } virtual bool isOpen() const { return m_parentItem->isOpen(); } protected: EditorGroupItem *m_parentItem; };*/ class KPropertyGroupWidget::Private { public: Private() {} QVBoxLayout* lyr; GroupWidgetBase *groupWidget; QPointer contents; }; KPropertyGroupWidget::KPropertyGroupWidget(const QString& title, QWidget* parent) : QWidget(parent) , d(new Private()) { QSizePolicy sp(QSizePolicy::Preferred, QSizePolicy::Fixed); sp.setHorizontalStretch(0); sp.setVerticalStretch(1); setSizePolicy(sp); d->lyr = new QVBoxLayout(this); d->groupWidget = new GroupWidgetBase(this); d->groupWidget->setText(title); d->lyr->addWidget(d->groupWidget); d->lyr->addSpacing(4); } KPropertyGroupWidget::~KPropertyGroupWidget() { delete d; } void KPropertyGroupWidget::setContents(QWidget* contents) { if (d->contents) { d->contents->hide(); d->lyr->removeWidget(d->contents); delete d->contents; } d->contents = contents; if (d->contents) { d->lyr->addWidget(d->contents); d->contents->show(); } update(); } bool KPropertyGroupWidget::event(QEvent * e) { if (e->type() == QEvent::MouseButtonPress) { QMouseEvent* me = static_cast(e); if (me->button() == Qt::LeftButton && d->contents && d->groupWidget->rect().contains(me->pos())) { d->groupWidget->setOpen(!d->groupWidget->isOpen()); if (d->groupWidget->isOpen()) d->contents->show(); else d->contents->hide(); d->lyr->invalidate(); update(); } } return QWidget::event(e); } QColor KPropertyUtils::contrastColor(const QColor& c) { int g = qGray(c.rgb()); if (g > 110) return c.dark(300); else if (g > 80) return c.light(250); else if (g > 20) 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.h b/src/KPropertyUtils.h index 544b694..8d44e94 100644 --- a/src/KPropertyUtils.h +++ b/src/KPropertyUtils.h @@ -1,44 +1,44 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KPROPERTY_UTILS_H #define KPROPERTY_UTILS_H #include "kpropertywidgets_export.h" #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 { public: KPropertyGroupWidget(const QString& title, QWidget* parent); ~KPropertyGroupWidget(); void setContents(QWidget* contents); protected: virtual bool event(QEvent * e); class Private; Private * const d; }; #endif diff --git a/src/KPropertyUtils_p.h b/src/KPropertyUtils_p.h index 822a5f1..cb87efd 100644 --- a/src/KPropertyUtils_p.h +++ b/src/KPropertyUtils_p.h @@ -1,32 +1,38 @@ /* This file is part of the KDE project Copyright (C) 2010 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #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.cpp b/src/KPropertyWidgetsFactory.cpp index e52f309..f712d2e 100644 --- a/src/KPropertyWidgetsFactory.cpp +++ b/src/KPropertyWidgetsFactory.cpp @@ -1,400 +1,376 @@ /* This file is part of the KDE project 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "KPropertyFactory.h" #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); } QVariant KPropertyLabel::value() const { return m_value; } void KPropertyLabel::setValue(const QVariant& value) { - setText( m_iface->displayText(value) ); + setText( m_iface->valueToString(value, QLocale()) ); m_value = value; } void KPropertyLabel::paintEvent( QPaintEvent * event ) { QLabel::paintEvent(event); KPropertyWidgetsFactory::paintTopGridLine(this); } //--------------- +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 { public: Private() { } ~Private() { } QHash editorCreators; QHash valuePainters; - QHash valueDisplays; }; Q_GLOBAL_STATIC(KPropertyWidgetsFactoryManager, _self) //! @internal Make sure sure the KPropertyWidgetsFactoryManager is created after //! KPropertyFactoryManager (delayed). Unless KPropertyFactoryManager is created, //! KPropertyWidgetsFactoryManager isn't created. //! @todo is this worth putting in a reusable macro? struct KPropertyWidgetsFactoryManagerInitializer { KPropertyWidgetsFactoryManagerInitializer() { KPropertyFactoryManager::addInitFunction(&initMe); } static void initMe() { KPropertyWidgetsFactoryManager::self(); } }; KPropertyWidgetsFactoryManagerInitializer init; //! @internal class KPropertyWidgetsFactory::Private { public: Private() { } ~Private() { qDeleteAll(editorCreatorsSet); qDeleteAll(valuePaintersSet); - qDeleteAll(valueDisplaysSet); } QHash editorCreators; QHash valuePainters; - QHash valueDisplays; QSet editorCreatorsSet; QSet valuePaintersSet; - QSet valueDisplaysSet; }; KPropertyWidgetsFactory::KPropertyWidgetsFactory() : d( new Private ) { } KPropertyWidgetsFactory::~KPropertyWidgetsFactory() { delete d; } QHash KPropertyWidgetsFactory::editorCreators() const { return d->editorCreators; } QHash KPropertyWidgetsFactory::valuePainters() const { return d->valuePainters; } -QHash KPropertyWidgetsFactory::valueDisplays() const -{ - return d->valueDisplays; -} - void KPropertyWidgetsFactory::addEditor(int type, KPropertyEditorCreatorInterface *creator) { addEditorInternal( type, creator, true ); if (dynamic_cast(creator)) { addComposedPropertyCreatorInternal( type, dynamic_cast(creator), false/* !own*/ ); } if (dynamic_cast(creator)) { addPainterInternal( type, dynamic_cast(creator), false/* !own*/ ); } if (dynamic_cast(creator)) { addDisplayInternal( type, dynamic_cast(creator), false/* !own*/ ); } } void KPropertyWidgetsFactory::addPainter(int type, KPropertyValuePainterInterface *painter) { addPainterInternal(type, painter, true); if (dynamic_cast(painter)) { addComposedPropertyCreatorInternal( type, dynamic_cast(painter), false/* !own*/ ); } if (dynamic_cast(painter)) { addEditorInternal( type, dynamic_cast(painter), false/* !own*/ ); } if (dynamic_cast(painter)) { addDisplayInternal( type, dynamic_cast(painter), false/* !own*/ ); } } -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) d->editorCreatorsSet.insert(editor); d->editorCreators.insert(type, editor); } void KPropertyWidgetsFactory::addPainterInternal(int type, KPropertyValuePainterInterface *painter, bool own) { if (own) d->valuePaintersSet.insert(painter); 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())) .arg(gridLineColor.name()).arg(extraStyleSheet)); } //------------ KPropertyWidgetsFactoryManager::KPropertyWidgetsFactoryManager() : d(new Private) { registerFactory(new KDefaultPropertyFactory); } KPropertyWidgetsFactoryManager::~KPropertyWidgetsFactoryManager() { delete d; } KPropertyWidgetsFactoryManager* KPropertyWidgetsFactoryManager::self() { KPropertyFactoryManager::self(); // make sure KPropertyFactoryManager instance exists // before KPropertyWidgetsFactoryManager ctor is called return _self; } void KPropertyWidgetsFactoryManager::registerFactory(KPropertyWidgetsFactory *factory) { KPropertyFactoryManager::self()->registerFactory(factory); QHash::ConstIterator editorCreatorsItEnd = factory->editorCreators().constEnd(); for (QHash::ConstIterator it( factory->editorCreators().constBegin() ); it != editorCreatorsItEnd; ++it) { d->editorCreators.insert(it.key(), it.value()); } QHash::ConstIterator valuePaintersItEnd = factory->valuePainters().constEnd(); for (QHash::ConstIterator it( factory->valuePainters().constBegin() ); it != valuePaintersItEnd; ++it) { 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 { return d->editorCreators.value(type); } QWidget * KPropertyWidgetsFactoryManager::createEditor( int type, QWidget *parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const { const KPropertyEditorCreatorInterface *creator = d->editorCreators.value(type); if (!creator) return 0; QWidget *w = creator->createEditor(type, parent, option, index); if (w) { const KPropertyEditorDataModel *editorModel = dynamic_cast(index.model()); KProperty *property = editorModel->propertyForItem(index); 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 = QString::fromLatin1("%1 { border-top: 1px solid %2; } ") .arg(cssClassName).arg(gridLineColor.name()); // kprDebug() << css; w->setStyleSheet(css); } } return w; } bool KPropertyWidgetsFactoryManager::paint( int type, QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const { const KPropertyValuePainterInterface *_painter = d->valuePainters.value(type); if (!_painter) return false; QStyleOptionViewItem realOption(option); if (option.state & QStyle::State_Selected) { // paint background because there may be editor widget with no autoFillBackground set realOption.palette.setBrush(QPalette::Text, realOption.palette.highlightedText()); painter->fillRect(realOption.rect, realOption.palette.highlight()); } painter->setPen(realOption.palette.text().color()); _painter->paint(painter, realOption, index); 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(); /* CustomPropertyFactory *factory = d->registeredWidgets[type]; if (factory) return factory->createCustomProperty(parent); */ switch (type) { case Size: case Size_Width: case Size_Height: return new SizeCustomProperty(parent); case Point: case Point_X: case Point_Y: return new PointCustomProperty(parent); case Rect: case Rect_X: case Rect_Y: case Rect_Width: case Rect_Height: return new RectCustomProperty(parent); case SizePolicy: /* case SizePolicy_HorizontalStretch: case SizePolicy_VerticalStretch: case SizePolicy_HorizontalPolicy: case SizePolicy_VerticalPolicy:*/ return new SizePolicyCustomProperty(parent); default:; } return 0; #endif KPropertyEditorCreatorInterface::KPropertyEditorCreatorInterface() { } KPropertyEditorCreatorInterface::~KPropertyEditorCreatorInterface() { } +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) { } KPropertyValuePainterInterface::KPropertyValuePainterInterface() { } KPropertyValuePainterInterface::~KPropertyValuePainterInterface() { } - -KPropertyValueDisplayInterface::KPropertyValueDisplayInterface() -{ -} - -KPropertyValueDisplayInterface::~KPropertyValueDisplayInterface() -{ -} - diff --git a/src/KPropertyWidgetsFactory.h b/src/KPropertyWidgetsFactory.h index ef0d7b5..297bc3d 100644 --- a/src/KPropertyWidgetsFactory.h +++ b/src/KPropertyWidgetsFactory.h @@ -1,217 +1,190 @@ /* This file is part of the KDE project 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KPROPERTYWIDGETS_FACTORY_H #define KPROPERTYWIDGETS_FACTORY_H #include "kpropertywidgets_export.h" #include "KProperty.h" #include "KPropertyFactory.h" #include #include #include #include #include #include //! An interface for editor widget creators. /*! Options can be set in the options attribute in order to customize widget creation process. Do this in the EditorCreatorInterface constructor. */ class KPROPERTYWIDGETS_EXPORT KPropertyEditorCreatorInterface { public: KPropertyEditorCreatorInterface(); 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(). */ class Options { public: Options(); /*! In order to have better look of the widget within the property editor view, we usually remove borders from the widget (see FactoryManager::createEditor()). and adding 1 pixel 'gray border' on the top. Default value is true. */ bool removeBorders; }; //! Options for altering the editor widget creation process Options options; }; class KPROPERTYWIDGETS_EXPORT KPropertyValuePainterInterface { public: KPropertyValuePainterInterface(); virtual ~KPropertyValuePainterInterface(); virtual void paint( QPainter * painter, 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 Q_PROPERTY(QVariant value READ value WRITE setValue USER true) public: KPropertyLabel(QWidget *parent, const KPropertyValueDisplayInterface *iface); QVariant value() const; Q_SIGNALS: void commitData( QWidget * editor ); public Q_SLOTS: void setValue(const QVariant& value); protected: virtual void paintEvent( QPaintEvent * event ); private: const KPropertyValueDisplayInterface *m_iface; 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, public KPropertyValueDisplayInterface, public KPropertyValuePainterInterface { public: KPropertyEditorCreator() : KPropertyEditorCreatorInterface() {} virtual ~KPropertyEditorCreator() {} virtual QWidget * createEditor( int type, QWidget *parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const { Q_UNUSED(type); Q_UNUSED(option); Q_UNUSED(index); 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); } }; typedef KPropertyEditorCreator KPropertyLabelCreator; class KPROPERTYWIDGETS_EXPORT KPropertyWidgetsFactory : public KPropertyFactory { public: KPropertyWidgetsFactory(); virtual ~KPropertyWidgetsFactory(); 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; }; class KProperty; class KCustomProperty; class KPROPERTYWIDGETS_EXPORT KPropertyWidgetsFactoryManager { public: bool isEditorForTypeAvailable( int type ) const; QWidget * createEditor( int type, QWidget *parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const; bool paint( int type, QPainter * painter, 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); /*! \return a pointer to a factory manager instance.*/ static KPropertyWidgetsFactoryManager* self(); KPropertyWidgetsFactoryManager(); ~KPropertyWidgetsFactoryManager(); private: class Private; Private * const d; }; #endif diff --git a/src/editors/CMakeLists.txt b/src/editors/CMakeLists.txt index fbd0fa4..0bbd1d9 100644 --- a/src/editors/CMakeLists.txt +++ b/src/editors/CMakeLists.txt @@ -1,53 +1,51 @@ set(KPROPERTY_EDITORS_HEADERS Utils BoolEdit + ColorEdit ComboBox CursorEdit DateEdit DateTimeEdit #DummyWidget FontEdit LineStyleEdit 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 # TODO: rename to camelcase, then uncomment "ORIGINAL CAMELCASE" HEADER_NAMES ${KPROPERTY_EDITORS_HEADERS} ) ecm_generate_headers(kproperty_editors_FORWARDING_HEADERS REQUIRED_HEADERS kproperty_editors_HEADERS ORIGINAL CAMELCASE HEADER_NAMES KPropertyStringEditor ) install( FILES ${kproperty_editors_HEADERS} DESTINATION ${INCLUDE_INSTALL_DIR}/KPropertyWidgets COMPONENT Devel ) install( FILES ${kproperty_editors_FORWARDING_HEADERS} DESTINATION ${INCLUDE_INSTALL_DIR}/KPropertyWidgets COMPONENT Devel ) diff --git a/src/editors/rectedit.cpp b/src/editors/KPropertyRectFEditor.cpp similarity index 60% copy from src/editors/rectedit.cpp copy to src/editors/KPropertyRectFEditor.cpp index 867c06f..b79308a 100644 --- a/src/editors/rectedit.cpp +++ b/src/editors/KPropertyRectFEditor.cpp @@ -1,81 +1,92 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ -#include "rectedit.h" +#include "KPropertyRectFEditor.h" #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()); + 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/rectedit.h b/src/editors/KPropertyRectFEditor.h similarity index 65% copy from src/editors/rectedit.h copy to src/editors/KPropertyRectFEditor.h index 468d9c2..9b5aee6 100644 --- a/src/editors/rectedit.h +++ b/src/editors/KPropertyRectFEditor.h @@ -1,45 +1,46 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * 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/KPropertyStringEditor.cpp b/src/editors/KPropertyStringEditor.cpp index 9558609..fa92bf4 100644 --- a/src/editors/KPropertyStringEditor.cpp +++ b/src/editors/KPropertyStringEditor.cpp @@ -1,67 +1,79 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "KPropertyStringEditor.h" KPropertyStringEditor::KPropertyStringEditor(QWidget *parent) : QLineEdit(parent) , m_slotTextChangedEnabled(true) { setFrame(false); setContentsMargins(0,1,0,0); setClearButtonEnabled(true); connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(slotTextChanged(const QString&))); } KPropertyStringEditor::~KPropertyStringEditor() { } QString KPropertyStringEditor::value() const { return text(); } void KPropertyStringEditor::setValue(const QString& value) { m_slotTextChangedEnabled = false; setText(value); m_slotTextChangedEnabled = true; /* deselect(); end(false);*/ } void KPropertyStringEditor::slotTextChanged( const QString & text ) { Q_UNUSED(text) if (!m_slotTextChangedEnabled) return; 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/KPropertyStringEditor.h b/src/editors/KPropertyStringEditor.h index 5862180..3105821 100644 --- a/src/editors/KPropertyStringEditor.h +++ b/src/editors/KPropertyStringEditor.h @@ -1,62 +1,65 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KPROPERTY_STRINGEDIT_H #define KPROPERTY_STRINGEDIT_H #include "KPropertyWidgetsFactory.h" #include class KPROPERTYWIDGETS_EXPORT KPropertyStringEditor : public QLineEdit { Q_OBJECT Q_PROPERTY(QString value READ value WRITE setValue USER true) public: explicit KPropertyStringEditor(QWidget *parent = 0); ~KPropertyStringEditor(); QString value() const; Q_SIGNALS: void commitData( QWidget * editor ); public Q_SLOTS: void setValue(const QString& value); private Q_SLOTS: void slotTextChanged( const QString & text ); private: 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/booledit.cpp b/src/editors/booledit.cpp index 9e2b8cc..e9dbbb2 100644 --- a/src/editors/booledit.cpp +++ b/src/editors/booledit.cpp @@ -1,347 +1,349 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "booledit.h" #include "KPropertyEditorDataModel.h" #include "kproperty_debug.h" #include #include #include #include /*! @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) { if (value.isNull() || !value.isValid()) return 2; else return value.toBool() ? 0 : 1; } //------------------------- class BoolEditGlobal { public: BoolEditGlobal() : yesIcon(QIcon::fromTheme(QLatin1String("dialog-ok")).pixmap(QSize(22,22))) , noIcon(QIcon::fromTheme(QLatin1String("button_no")).pixmap(QSize(22,22))) { noneIcon.fill(Qt::transparent); } QPixmap yesIcon; QPixmap noIcon; QPixmap noneIcon; }; Q_GLOBAL_STATIC(BoolEditGlobal, g_boolEdit) 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); // setToolButtonStyle(Qt::ToolButtonTextBesideIcon); setAutoFillBackground(true); // setFlat(false); // setStyle(qApp->style()); // setPalette(qApp->palette()); // setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); //we're not using layout to because of problems with button size // m_toggle->move(0, 0); // m_toggle->resize(width(), height()); /* KColorScheme cs(QPalette::Active); QColor focus = cs.decoration(KColorScheme::FocusColor).color(); setStyleSheet( QString::fromLatin1("QToolButton { " "border: 1px solid %1; " "border-radius: 0px; " "padding: 0 0px; }").arg(focus.name())); */ // setFocusWidget(m_toggle); // setStyleSheet( // QLatin1String(" QPushButton { border: none; padding:0;background-color: red; }") ); connect(this, SIGNAL(toggled(bool)), this, SLOT(slotValueChanged(bool))); } KPropertyBoolEditor::~KPropertyBoolEditor() { } bool KPropertyBoolEditor::value() const { return isChecked(); } void KPropertyBoolEditor::setValue(bool value) { // m_toggle->blockSignals(true); setChecked(value); // setState(value); // m_toggle->blockSignals(false); // if (emitChange) // emit valueChanged(this); } void KPropertyBoolEditor::slotValueChanged(bool state) { Q_UNUSED(state); emit commitData(this); // setState(state); //// emit valueChanged(this); } void KPropertyBoolEditor::draw(QPainter *p, const QRect &r, const QVariant &value, const QString& text, bool threeState) { // p->eraseRect(r); QRect r2(r); r2.setLeft(r2.left() + 16 + 6); //16 = SmallSize // r2.setTop(r2.top() + 1); if (!threeState && value.isNull()) { // 2 states but null value p->drawText(r2, Qt::AlignVCenter | Qt::AlignLeft, text); } else { QPixmap icon; // QString text; if (threeState && valueToIndex(value) == 2) { // draw icon for the 3rd state for Three-State editor icon = g_boolEdit->noneIcon; } else { // draw true or false icon regardless of the 2 or 3 state version icon = value.toBool() ? g_boolEdit->yesIcon : g_boolEdit->noIcon; } /* if (threeState if (value.isNull() || !value.isValid()) //draw text state for Three-State editor if (value.isNull() || !value.isValid()) text = overrideText;*/ // kprDebug() << r2; p->drawPixmap( r.left() + 3, r2.top() + (r2.height() - 16) / 2,icon); //16 = SmallSize p->drawText( r2, Qt::AlignVCenter | Qt::AlignLeft, text); } } void KPropertyBoolEditor::paintEvent( QPaintEvent * event ) { QToolButton::paintEvent(event); QPainter p(this); const QVariant v( value() ); KPropertyBoolEditor::draw(&p, rect(), v, v.toBool() ? m_yesText : m_noText, false /*2state*/); } bool KPropertyBoolEditor::eventFilter(QObject* watched, QEvent* e) { if (e->type() == QEvent::KeyPress) { QKeyEvent* ev = static_cast(e); const int k = ev->key(); if (k == Qt::Key_Space || k == Qt::Key_Enter || k == Qt::Key_Return) { // if (m_toggle) toggle(); return true; } } return QToolButton::eventFilter(watched, e); } /*void BoolEdit::setReadOnlyInternal(bool readOnly) { setVisibleFlag(!readOnly); }*/ //-------------------------------------------------- class ThreeStateBoolIconProvider : public KPropertyComboBoxEditor::Options::IconProviderInterface { public: ThreeStateBoolIconProvider() {} virtual QIcon icon(int index) const { if (index == 0) return g_boolEdit->yesIcon; else if (index == 1) return g_boolEdit->noIcon; return g_boolEdit->noneIcon; } virtual IconProviderInterface* clone() const { return new ThreeStateBoolIconProvider(); } }; static KPropertyComboBoxEditor::Options initThreeStateBoolOptions() { KPropertyComboBoxEditor::Options options; options.iconProvider = new ThreeStateBoolIconProvider(); return options; } KPropertyThreeStateBoolEditor::KPropertyThreeStateBoolEditor( const KPropertyListData& listData, QWidget *parent) : KPropertyComboBoxEditor(listData, initThreeStateBoolOptions(), parent) { // QPixmap nullIcon(m_yesIcon.size()); //transparent pixmap of appropriate size // nullIcon.fill(Qt::transparent); // m_edit->addItem(nullIcon, thirdState.toString().isEmpty() ? tr("None") : thirdState.toString()); setCurrentIndex(2); } KPropertyThreeStateBoolEditor::~KPropertyThreeStateBoolEditor() { } QVariant KPropertyThreeStateBoolEditor::value() const { // list items: true, false, NULL const int idx = currentIndex(); if (idx == 0) return true; else return idx == 1 ? false : QVariant(); } /*void ThreeStateBoolEdit::setProperty(Property *prop) { m_setValueEnabled = false; //setValue() couldn't be called before fillBox() Widget::setProperty(prop); m_setValueEnabled = true; if (prop) setValue(prop->value(), false); //now the value can be set }*/ void KPropertyThreeStateBoolEditor::setValue(const QVariant &value) { // if (!m_setValueEnabled) // return; setCurrentIndex( valueToIndex(value) ); // if (emitChange) // emit valueChanged(this); } //--------------- KPropertyBoolDelegate::KPropertyBoolDelegate() { options.removeBorders = false; } QWidget * KPropertyBoolDelegate::createEditor( int type, QWidget *parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const { Q_UNUSED(type); Q_UNUSED(option); const KPropertyEditorDataModel *editorModel = dynamic_cast(index.model()); KProperty *prop = editorModel->propertyForItem(index); // boolean editors can optionally accept 3rd state: if (prop->option("3State", false).toBool()) { KPropertyListData threeStateListData; setupThreeStateListData(threeStateListData, prop); return new KPropertyThreeStateBoolEditor(threeStateListData, parent); } else { return new KPropertyBoolEditor(prop, parent); } } void KPropertyBoolDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const { painter->save(); const KPropertyEditorDataModel *editorModel = dynamic_cast(index.model()); 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/booledit.h b/src/editors/booledit.h index c2b8459..2fbfc7a 100644 --- a/src/editors/booledit.h +++ b/src/editors/booledit.h @@ -1,102 +1,104 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KPROPERTY_BOOLEDIT_H #define KPROPERTY_BOOLEDIT_H #include "combobox.h" #include "KPropertyFactory.h" #include #include #include //! A bool editor supporting two states: true and false. /*! For null values, false is displayed. */ class KPROPERTYWIDGETS_EXPORT KPropertyBoolEditor : public QToolButton { Q_OBJECT Q_PROPERTY(bool value READ value WRITE setValue USER true) public: explicit KPropertyBoolEditor(const KProperty *prop, QWidget *parent = 0); ~KPropertyBoolEditor(); bool value() const; static void draw(QPainter *p, const QRect &r, const QVariant &value, const QString& text, bool threeState); Q_SIGNALS: void commitData(QWidget* editor); public Q_SLOTS: void setValue(bool value); protected Q_SLOTS: void slotValueChanged(bool state); protected: virtual void paintEvent( QPaintEvent * event ); // virtual void setReadOnlyInternal(bool readOnly); // void setState(bool state); // virtual void resizeEvent(QResizeEvent *ev); virtual bool eventFilter(QObject* watched, QEvent* e); private: QString m_yesText; QString m_noText; }; //! A bool editor supporting three states: true, false and null. /*! The editor is implemented as a drop-down list. */ class KPROPERTYWIDGETS_EXPORT KPropertyThreeStateBoolEditor : public KPropertyComboBoxEditor { Q_OBJECT // Q_PROPERTY(QVariant value READ value WRITE setValue USER true) public: explicit KPropertyThreeStateBoolEditor(const KPropertyListData& listData, QWidget *parent = 0); ~KPropertyThreeStateBoolEditor(); 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(); 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 propertyValueToString(const KProperty* prop, const QLocale &locale) const; + + virtual QString valueToString(const QVariant& value, const QLocale &locale) const; }; #endif diff --git a/src/editors/coloredit.cpp b/src/editors/coloredit.cpp index b01cc04..810d055 100644 --- a/src/editors/coloredit.cpp +++ b/src/editors/coloredit.cpp @@ -1,87 +1,116 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #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) : KColorCombo(parent) { connect(this, SIGNAL(activated(QColor)), this, SLOT(slotValueChanged(QColor))); QList< QColor > colors; const int oxygenColorsCount = g_oxygenColors->count(); for (int i = 0; i < oxygenColorsCount; i++) { 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() { } QVariant KPropertyColorComboEditor::value() const { return color(); } void KPropertyColorComboEditor::setValue(const QVariant &value) { setColor(value.value()); } void KPropertyColorComboEditor::slotValueChanged(const QColor&) { 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, const QStyleOptionViewItem & option, const QModelIndex & index ) const { painter->save(); const QBrush b(index.data(Qt::EditRole).value()); painter->setBrush(b); painter->setPen(QPen(Qt::NoPen)); painter->drawRect(option.rect); painter->setBrush(KPropertyUtils::contrastColor(b.color())); painter->setPen(KPropertyUtils::contrastColor(b.color())); 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/coloredit.h b/src/editors/coloredit.h index 7894e75..54a0fe5 100644 --- a/src/editors/coloredit.h +++ b/src/editors/coloredit.h @@ -1,66 +1,72 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KPROPERTY_COLOREDIT_H #define KPROPERTY_COLOREDIT_H #include "KPropertyWidgetsFactory.h" +#include "config-kproperty.h" +#ifdef KPROPERTY_KF #include //! Color combo box //! @todo enable transparency selection //! @todo add transparency option //! @todo reimplement view using KColorCells class KPROPERTYWIDGETS_EXPORT KPropertyColorComboEditor : public KColorCombo { Q_OBJECT Q_PROPERTY(QVariant value READ value WRITE setValue USER true) public: explicit KPropertyColorComboEditor(QWidget *parent = 0); ~KPropertyColorComboEditor(); QVariant value() const; Q_SIGNALS: void commitData( QWidget * editor ); public Q_SLOTS: void setValue(const QVariant &value); protected Q_SLOTS: void slotValueChanged(const QColor&); }; +#endif // KPROPERTY_KF class KPROPERTYWIDGETS_EXPORT KPropertyColorComboDelegate : public KPropertyEditorCreatorInterface, - public KPropertyValuePainterInterface + public KPropertyValuePainterInterface, + public KPropertyValueDisplayInterface { public: KPropertyColorComboDelegate() {} 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/combobox.cpp b/src/editors/combobox.cpp index 6147676..3306102 100644 --- a/src/editors/combobox.cpp +++ b/src/editors/combobox.cpp @@ -1,294 +1,311 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "combobox.h" #include "KPropertyEditorDataModel.h" #include "KPropertyEditorView.h" #include "kproperty_debug.h" #include "KPropertyWidgetsFactory.h" +#include "KPropertyUtils_p.h" #include #include KPropertyComboBoxEditor::Options::Options() : iconProvider(0) , extraValueAllowed(false) { } KPropertyComboBoxEditor::Options::Options(const KPropertyComboBoxEditor::Options& other) { *this = other; if (other.iconProvider) iconProvider = other.iconProvider->clone(); } KPropertyComboBoxEditor::Options::~Options() { delete iconProvider; } KPropertyComboBoxEditor::KPropertyComboBoxEditor(const KPropertyListData& listData, const Options& options, QWidget *parent) : QComboBox(parent) , m_setValueEnabled(true) , m_options(options) { // QHBoxLayout *l = new QHBoxLayout(this); // l->setMargin(0); // l->setSpacing(0); // m_edit = new KComboBox(this); // m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); // m_edit->setMinimumHeight(5); //setPlainWidgetStyle(m_edit); // l->addWidget(m_edit); setEditable( m_options.extraValueAllowed ); setInsertPolicy(QComboBox::NoInsert); // m_edit->setMinimumSize(10, 0); // to allow the combo to be resized to a small size setAutoCompletion(true); setContextMenuPolicy(Qt::NoContextMenu); // if (listData) setListData(listData); // if (property->listData()) { // fillValues(property); //} //not needed for combo setLeavesTheSpaceForRevertButton(true); // 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()) { kprWarning() << "property listData not available!"; return false; } return true; } QVariant KPropertyComboBoxEditor::value() const { if (!listDataKeysAvailable()) return QVariant(); const int idx = currentIndex(); if (idx < 0 || idx >= (int)m_listData.keys.count() || m_listData.names[idx] != currentText().trimmed()) { if (!m_options.extraValueAllowed || currentText().isEmpty()) return QVariant(); return QVariant(currentText().trimmed());//trimmed 4 safety } return QVariant(m_listData.keys[idx]); } void KPropertyComboBoxEditor::setValue(const QVariant &value) { if (!listDataKeysAvailable()) return; if (!m_setValueEnabled) return; int idx = m_listData.keys.indexOf(value/*.toString()TODO*/); // kprDebug() << "**********" << idx << "" << value.toString(); if (idx >= 0 && idx < count()) { setCurrentIndex(idx); } else { if (idx < 0) { if (m_options.extraValueAllowed) { setCurrentIndex(-1); setEditText(value.toString()); } kprWarning() << "NO SUCH KEY:" << value.toString() << "property=" << objectName(); } else { QStringList list; for (int i = 0; i < count(); i++) list += itemText(i); kprWarning() << "NO SUCH INDEX WITHIN COMBOBOX:" << idx << "count=" << count() << "value=" << value.toString() << "property=" << objectName() << "\nActual combobox contents" << list; } setItemText(currentIndex(), QString()); } if (value.isNull()) return; //?? if (emitChange) //?? emit valueChanged(this); } void KPropertyComboBoxEditor::fillValues() { clear(); //m_edit->clearContents(); // if (!m_property) // return; if (!listDataKeysAvailable()) return; // m_keys = m_property->listData()->keys; int index = 0; foreach( const QString& itemName, m_listData.names ) { addItem(itemName); if (m_options.iconProvider) { QIcon icon = m_options.iconProvider->icon(index); setItemIcon(index, icon); } index++; } QCompleter *comp = new QCompleter(m_listData.names); comp->setWidget(this); } /* void ComboBox::setProperty( const Property *property ) { // const bool b = (property() == prop); // m_setValueEnabled = false; //setValue() couldn't be called before fillBox() // Widget::setProperty(prop); // m_setValueEnabled = true; // if (!b) // m_property = property; m_listData = *property->listData(); fillValues(); // if (prop) // setValue(prop->value(), false); //now the value can be set }*/ void KPropertyComboBoxEditor::setListData(const KPropertyListData & listData) { m_listData = listData; fillValues(); } void KPropertyComboBoxEditor::slotValueChanged(int) { // emit valueChanged(this); emit commitData( this ); } void KPropertyComboBoxEditor::paintEvent( QPaintEvent * event ) { QComboBox::paintEvent(event); KPropertyWidgetsFactory::paintTopGridLine(this); } /* void ComboBox::setReadOnlyInternal(bool readOnly) { setVisibleFlag(!readOnly); }*/ /*QString ComboBox::keyForValue(const QVariant &value) { const QMap *list = property()->valueList(); Property::ListData *list = property()->listData(); if (!list) return QString(); int idx = listData->keys.findIndex( value ); QMap::ConstIterator endIt = list->constEnd(); for(QMap::ConstIterator it = list->constBegin(); it != endIt; ++it) { if(it.data() == value) return it.key(); } return QString(); }*/ //----------------------- KPropertyComboBoxDelegate::KPropertyComboBoxDelegate() { 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(); if (property->value().isNull()) return QString(); //kprDebug() << "property->value()==" << property->value(); const int idx = listData->keys.indexOf( property->value() ); //kprDebug() << "idx==" << idx; if (idx == -1) { if (!property->option("extraValueAllowed").toBool()) return QString(); else return property->value().toString(); } 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 { Q_UNUSED(type); Q_UNUSED(option); const KPropertyEditorDataModel *editorModel = dynamic_cast(index.model()); KProperty *property = editorModel->propertyForItem(index); KPropertyComboBoxEditor::Options options; options.extraValueAllowed = property->option("extraValueAllowed", false).toBool(); KPropertyComboBoxEditor *cb = new KPropertyComboBoxEditor(*property->listData(), options, parent); return cb; } /*void ComboBoxDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const { }*/ diff --git a/src/editors/combobox.h b/src/editors/combobox.h index 034be37..c2409eb 100644 --- a/src/editors/combobox.h +++ b/src/editors/combobox.h @@ -1,105 +1,109 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KPROPERTY_COMBOBOX_H #define KPROPERTY_COMBOBOX_H #include "KPropertyWidgetsFactory.h" #include class KPROPERTYWIDGETS_EXPORT KPropertyComboBoxEditor : public QComboBox { Q_OBJECT Q_PROPERTY(QVariant value READ value WRITE setValue USER true) public: class Options { public: class IconProviderInterface { public: IconProviderInterface() {} virtual ~IconProviderInterface() {} virtual QIcon icon(int index) const = 0; virtual IconProviderInterface* clone() const = 0; }; Options(); Options(const Options& other); ~Options(); IconProviderInterface *iconProvider; bool extraValueAllowed; }; // explicit ComboBox(const Property* property, QWidget *parent = 0); KPropertyComboBoxEditor(const KPropertyListData& listData, const Options& options, QWidget *parent = 0); virtual ~KPropertyComboBoxEditor(); virtual QVariant value() const; // virtual void setProperty(const Property *property); void setListData(const KPropertyListData & listData); + static QString borderSheet(const QWidget *widget); + Q_SIGNALS: void commitData( QWidget * editor ); public Q_SLOTS: virtual void setValue(const QVariant &value); protected Q_SLOTS: void slotValueChanged(int value); protected: virtual void paintEvent( QPaintEvent * event ); // virtual void setReadOnlyInternal(bool readOnly); QString keyForValue(const QVariant &value); void fillValues(); bool listDataKeysAvailable() const; // KComboBox *m_edit; // const Property *m_property; KPropertyListData m_listData; // QList keys; bool m_setValueEnabled; Options m_options; }; class KPROPERTYWIDGETS_EXPORT KPropertyComboBoxDelegate : public KPropertyEditorCreatorInterface, public KPropertyValueDisplayInterface { 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; // virtual void paint( QPainter * painter, // const QStyleOptionViewItem & option, const QModelIndex & index ) const; }; #endif diff --git a/src/editors/cursoredit.cpp b/src/editors/cursoredit.cpp index 1e173fa..49b1fed 100644 --- a/src/editors/cursoredit.cpp +++ b/src/editors/cursoredit.cpp @@ -1,241 +1,266 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "cursoredit.h" #include "KProperty.h" +#include "KPropertyCoreUtils_p.h" +#include "KPropertyUtils_p.h" #include "xpm/blank_cursor.xpm" #include "xpm/arrow_cursor.xpm" #include "xpm/bdiag_cursor.xpm" #include "xpm/busy_cursor.xpm" #include "xpm/closedhand_cursor.xpm" #include "xpm/cross_cursor.xpm" #include "xpm/fdiag_cursor.xpm" #include "xpm/forbidden_cursor.xpm" #include "xpm/hand_cursor.xpm" #include "xpm/ibeam_cursor.xpm" #include "xpm/openhand_cursor.xpm" #include "xpm/sizeall_cursor.xpm" #include "xpm/sizehor_cursor.xpm" #include "xpm/sizever_cursor.xpm" #include "xpm/splith_cursor.xpm" #include "xpm/splitv_cursor.xpm" #include "xpm/uparrow_cursor.xpm" #include "xpm/wait_cursor.xpm" #include "xpm/whatsthis_cursor.xpm" #include #include class CursorListData : public KPropertyListData { public: CursorListData() : KPropertyListData(keysInternal(), stringsInternal()) { } Qt::CursorShape indexToShape(int index) const { if (index < 0 || index >= keys.count()) return Qt::ArrowCursor; return (Qt::CursorShape)(keys[index].toInt()); } int shapeToIndex(Qt::CursorShape _shape) const { int index = 0; foreach (const QVariant& shape, keys) { if (shape.toInt() == _shape) return index; index++; } return 0; } QPixmap pixmapForIndex(int index, const QPalette& pal, bool transparentBackground = false) const { if (index < 0 || index > 18) index = 0; QPixmap xpm(m_xpms[index]); if (transparentBackground) return xpm; QPixmap px(xpm.size()); QColor bg( pal.color(QPalette::Base) ); // paint bg with to avoid invisible black-on-black painting bg.setAlpha(127); px.fill(bg); QPainter p(&px); - p.drawPixmap(0, 0, xpm); + p.drawPixmap(0, 2, xpm); return px; } private: static QList keysInternal() { QList keys; keys << int(Qt::BlankCursor) << int(Qt::ArrowCursor) << int(Qt::UpArrowCursor) << int(Qt::CrossCursor) << int(Qt::WaitCursor) << int(Qt::IBeamCursor) << int(Qt::SizeVerCursor) << int(Qt::SizeHorCursor) << int(Qt::SizeBDiagCursor) << int(Qt::SizeFDiagCursor) << int(Qt::SizeAllCursor) << int(Qt::SplitVCursor) << int(Qt::SplitHCursor) << int(Qt::PointingHandCursor) << int(Qt::ForbiddenCursor) << int(Qt::WhatsThisCursor) << int(Qt::BusyCursor) << int(Qt::OpenHandCursor) << int(Qt::ClosedHandCursor); return keys; } static QStringList stringsInternal() { QStringList strings; strings << QObject::tr("No cursor", "Mouse Cursor Shape") //0 << QObject::tr("Arrow", "Mouse Cursor Shape") //1 << QObject::tr("Up arrow", "Mouse Cursor Shape") //2 << QObject::tr("Cross", "Mouse Cursor Shape") //3 << QObject::tr("Waiting", "Mouse Cursor Shape") //4 << QObject::tr("Text cursor", "Mouse Cursor Shape") //5 << QObject::tr("Size vertical", "Mouse Cursor Shape") //6 << QObject::tr("Size horizontal", "Mouse Cursor Shape") //7 << QObject::tr("Size slash", "Mouse Cursor Shape") //8 << QObject::tr("Size backslash", "Mouse Cursor Shape") //9 << QObject::tr("Size all", "Mouse Cursor Shape") //10 << QObject::tr("Split vertical", "Mouse Cursor Shape") //11 << QObject::tr("Split horizontal", "Mouse Cursor Shape") //12 << QObject::tr("Pointing hand", "Mouse Cursor Shape") //13 << QObject::tr("Forbidden", "Mouse Cursor Shape") //14 << QObject::tr("What's this?", "Mouse Cursor Shape") //15 << QObject::tr("Busy", "Mouse Cursor Shape") //16 << QObject::tr("Open hand", "Mouse Cursor Shape") //17 << QObject::tr("Closed hand", "Mouse Cursor Shape"); //18 return strings; } static const char * const * const m_xpms[]; }; const char * const * const CursorListData::m_xpms[] = { blank_cursor_xpm, arrow_cursor_xpm, uparrow_cursor_xpm, cross_cursor_xpm, wait_cursor_xpm, ibeam_cursor_xpm, sizever_cursor_xpm, sizehor_cursor_xpm, bdiag_cursor_xpm, fdiag_cursor_xpm, sizeall_cursor_xpm, splitv_cursor_xpm, splith_cursor_xpm, hand_cursor_xpm, forbidden_cursor_xpm, whatsthis_cursor_xpm, busy_cursor_xpm, openhand_cursor_xpm, closedhand_cursor_xpm }; Q_GLOBAL_STATIC(CursorListData, s_cursorListData) //---------------------- class CursorIconProvider : public KPropertyComboBoxEditor::Options::IconProviderInterface { public: explicit CursorIconProvider(QWidget* parent) : m_parent(parent) {} virtual QIcon icon(int index) const { return s_cursorListData->pixmapForIndex(index, m_parent->palette()); } virtual IconProviderInterface* clone() const { return new CursorIconProvider(m_parent); } QWidget* m_parent; }; //---------------------- static KPropertyComboBoxEditor::Options initComboBoxOptions(QWidget* parent) { KPropertyComboBoxEditor::Options options; options.iconProvider = new CursorIconProvider(parent); return options; } 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() { } QCursor KPropertyCursorEditor::cursorValue() const { return QCursor((Qt::CursorShape)KPropertyComboBoxEditor::value().toInt()); } void KPropertyCursorEditor::setCursorValue(const QCursor &value) { KPropertyComboBoxEditor::setValue( (int)(value.shape()) ); } //--------------- KPropertyCursorDelegate::KPropertyCursorDelegate() { options.removeBorders = false; } QWidget * KPropertyCursorDelegate::createEditor( int type, QWidget *parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const { Q_UNUSED(type); Q_UNUSED(option); Q_UNUSED(index); return new KPropertyCursorEditor(parent); } void KPropertyCursorDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const { painter->save(); int comboIndex = s_cursorListData->shapeToIndex( index.data(Qt::EditRole).value().shape() ); 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/cursoredit.h b/src/editors/cursoredit.h index 0aca816..aa5cffc 100644 --- a/src/editors/cursoredit.h +++ b/src/editors/cursoredit.h @@ -1,53 +1,56 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KPROPERTY_CURSOREDIT_H #define KPROPERTY_CURSOREDIT_H #include "combobox.h" class KPROPERTYWIDGETS_EXPORT KPropertyCursorEditor : public KPropertyComboBoxEditor { Q_OBJECT Q_PROPERTY(QCursor value READ cursorValue WRITE setCursorValue USER true) public: explicit KPropertyCursorEditor(QWidget *parent = 0); virtual ~KPropertyCursorEditor(); virtual QCursor cursorValue() const; virtual void setCursorValue(const QCursor &value); }; class KPROPERTYWIDGETS_EXPORT KPropertyCursorDelegate : public KPropertyEditorCreatorInterface, - public KPropertyValuePainterInterface + public KPropertyValuePainterInterface, + public KPropertyValueDisplayInterface { public: KPropertyCursorDelegate(); 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/dateedit.cpp b/src/editors/dateedit.cpp index e52b656..4f7b69d 100644 --- a/src/editors/dateedit.cpp +++ b/src/editors/dateedit.cpp @@ -1,98 +1,98 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "dateedit.h" #include "KPropertyEditorDataModel.h" #include KPropertyDateEditor::KPropertyDateEditor(const KProperty* prop, QWidget* parent) : QDateEdit(parent) { setFrame(false); setCalendarPopup(true); const QDate minDate = prop->option("min").toDate(); if (minDate.isValid()) { setMinimumDate(minDate); } const QDate maxDate = prop->option("max").toDate(); if (maxDate.isValid()) { setMaximumDate(maxDate); } connect(this, SIGNAL(dateChanged(QDate)), this, SLOT(onDateChanged())); } KPropertyDateEditor::~KPropertyDateEditor() { } QVariant KPropertyDateEditor::value() const { return QVariant(date()); } void KPropertyDateEditor::setValue(const QVariant& value) { blockSignals(true); setDate(value.toDate()); blockSignals(false); } void KPropertyDateEditor::paintEvent(QPaintEvent* event) { QDateEdit::paintEvent(event); KPropertyWidgetsFactory::paintTopGridLine(this); } void KPropertyDateEditor::onDateChanged() { emit commitData(this); } //! @todo Port to KLocale, be inspired by KexiDateTableEdit (with Kexi*Formatter) KPropertyDateDelegate::KPropertyDateDelegate() { } -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, const QStyleOptionViewItem& option, const QModelIndex& index) const { Q_UNUSED(type); Q_UNUSED(option); const KPropertyEditorDataModel *editorModel = dynamic_cast(index.model()); KProperty *prop = editorModel->propertyForItem(index); return new KPropertyDateEditor(prop, parent); } diff --git a/src/editors/dateedit.h b/src/editors/dateedit.h index 955131d..fce15ce 100644 --- a/src/editors/dateedit.h +++ b/src/editors/dateedit.h @@ -1,64 +1,65 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KPROPERTY_DATEEDIT_H #define KPROPERTY_DATEEDIT_H #include "KPropertyWidgetsFactory.h" #include class KPROPERTYWIDGETS_EXPORT KPropertyDateEditor : public QDateEdit { Q_OBJECT Q_PROPERTY(QVariant value READ value WRITE setValue USER true) public: KPropertyDateEditor(const KProperty* prop, QWidget* parent); virtual ~KPropertyDateEditor(); QVariant value() const; Q_SIGNALS: void commitData(QWidget* editor); public Q_SLOTS: void setValue(const QVariant& value); protected: virtual void paintEvent(QPaintEvent* event); protected Q_SLOTS: void onDateChanged(); }; 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; }; #endif diff --git a/src/editors/datetimeedit.cpp b/src/editors/datetimeedit.cpp index a0b50f4..01c4461 100644 --- a/src/editors/datetimeedit.cpp +++ b/src/editors/datetimeedit.cpp @@ -1,101 +1,99 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "datetimeedit.h" #include "KPropertyEditorDataModel.h" #include "KPropertyWidgetsFactory.h" #include KPropertyDateTimeEditor::KPropertyDateTimeEditor(const KProperty* prop, QWidget* parent) : QDateTimeEdit(parent) { - Q_UNUSED(prop); - setFrame(false); setCalendarPopup(true); const QDateTime minDateTime = prop->option("min").toDateTime(); if (minDateTime.isValid()) { setMinimumDateTime(minDateTime); } const QDateTime maxDateTime = prop->option("max").toDateTime(); if (maxDateTime.isValid()) { setMaximumDateTime(maxDateTime); } connect(this, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(onDateTimeChanged())); } KPropertyDateTimeEditor::~KPropertyDateTimeEditor() { } QVariant KPropertyDateTimeEditor::value() const { return QVariant(dateTime()); } void KPropertyDateTimeEditor::setValue(const QVariant& value) { blockSignals(true); setDateTime(value.toDateTime()); blockSignals(false); } void KPropertyDateTimeEditor::paintEvent(QPaintEvent* event) { QDateTimeEdit::paintEvent(event); KPropertyWidgetsFactory::paintTopGridLine(this); } void KPropertyDateTimeEditor::onDateTimeChanged() { emit commitData(this); } //! @todo Port to KLocale, be inspired by KexiDateTimeTableEdit (with Kexi*Formatter) KPropertyDateTimeDelegate::KPropertyDateTimeDelegate() { } -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, const QStyleOptionViewItem& option, const QModelIndex& index) const { Q_UNUSED(type); Q_UNUSED(option); const KPropertyEditorDataModel *editorModel = dynamic_cast(index.model()); KProperty *prop = editorModel->propertyForItem(index); return new KPropertyDateTimeEditor(prop, parent); } diff --git a/src/editors/datetimeedit.h b/src/editors/datetimeedit.h index 050f5b3..d68a81b 100644 --- a/src/editors/datetimeedit.h +++ b/src/editors/datetimeedit.h @@ -1,64 +1,65 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KPROPERTY_DATETIMEEDIT_H #define KPROPERTY_DATETIMEEDIT_H #include "KPropertyWidgetsFactory.h" #include class KPROPERTYWIDGETS_EXPORT KPropertyDateTimeEditor : public QDateTimeEdit { Q_OBJECT Q_PROPERTY(QVariant value READ value WRITE setValue USER true) public: KPropertyDateTimeEditor(const KProperty* prop, QWidget* parent); virtual ~KPropertyDateTimeEditor(); QVariant value() const; Q_SIGNALS: void commitData(QWidget* editor); public Q_SLOTS: void setValue(const QVariant& value); protected: virtual void paintEvent(QPaintEvent* event); protected Q_SLOTS: void onDateTimeChanged(); }; 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; }; #endif diff --git a/src/editors/fontedit.cpp b/src/editors/fontedit.cpp index 9aaa538..4f7d450 100644 --- a/src/editors/fontedit.cpp +++ b/src/editors/fontedit.cpp @@ -1,123 +1,154 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "fontedit.h" #include "fontedit_p.h" #include "utils.h" #include "kproperty_debug.h" #include #include #include #include #include #include #include #include #include #include #include KPropertyFontEditRequester::KPropertyFontEditRequester(QWidget *parent) : QWidget(parent) , m_paletteChangedEnabled(true) { setBackgroundRole(QPalette::Base); QHBoxLayout *lyr = new QHBoxLayout(this); lyr->setContentsMargins(0,0,0,0); lyr->setSpacing( 1 ); lyr->addStretch(1); m_button = new QPushButton(this); setFocusProxy(m_button); KPropertyUtils::setupDotDotDotButton(m_button, tr("Click to select a font"), tr("Selects font")); connect( m_button, SIGNAL( clicked() ), SLOT( slotSelectFontClicked() ) ); lyr->addWidget(m_button); setValue(qApp->font()); } QFont KPropertyFontEditRequester::value() const { return m_font; } void KPropertyFontEditRequester::setValue(const QFont &value) { //kprDebug() << QFontDatabase().families(); m_font = value; } void KPropertyFontEditRequester::slotSelectFontClicked() { bool ok; QFont font; - font = QFontDialog::getFont( &ok, parentWidget() ); + font = QFontDialog::getFont(&ok, m_font, parentWidget()); if (ok) { m_font = font; setValue(m_font); emit commitData(this); } } bool KPropertyFontEditRequester::event( QEvent * event ) { return QWidget::event(event); } // ----------- +KPropertyFontDelegate::KPropertyFontDelegate() +{ +} + QWidget * KPropertyFontDelegate::createEditor( int type, QWidget *parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const { Q_UNUSED(type); Q_UNUSED(option); Q_UNUSED(index); return new KPropertyFontEditRequester(parent); } void KPropertyFontDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const { 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) f.setPixelSize(option.font.pixelSize()); painter->setFont( f ); QRect rect( option.rect ); rect.setLeft( rect.left() + 1 ); const QString txt( QObject::tr("Abc", "Font sample for property editor item, typically \"Abc\"") ); painter->drawText( rect, Qt::AlignLeft | Qt::AlignVCenter, QObject::tr("Abc", "Font sample for property editor item, typically \"Abc\"") ); 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/fontedit.h b/src/editors/fontedit.h index 36ca59a..11fc634 100644 --- a/src/editors/fontedit.h +++ b/src/editors/fontedit.h @@ -1,39 +1,44 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KPROPERTY_FONTEDIT_H #define KPROPERTY_FONTEDIT_H #include "KPropertyWidgetsFactory.h" 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/linestyleedit.cpp b/src/editors/linestyleedit.cpp index ae988e0..1675ee7 100644 --- a/src/editors/linestyleedit.cpp +++ b/src/editors/linestyleedit.cpp @@ -1,100 +1,115 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #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); } KPropertyLineStyleComboEditor::~KPropertyLineStyleComboEditor() { } QVariant KPropertyLineStyleComboEditor::value() const { return int(lineStyle()); } 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) { if (!hasVisibleStyle(value)) { setLineStyle(Qt::NoPen); return; } setLineStyle(static_cast(value.toInt())); } void KPropertyLineStyleComboEditor::slotValueChanged(int) { emit commitData(this); } QWidget * KPropertyLineStyleComboDelegate::createEditor( int type, QWidget *parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const { Q_UNUSED(type) Q_UNUSED(option) Q_UNUSED(index) return new KPropertyLineStyleComboEditor(parent); } void KPropertyLineStyleComboDelegate::paint( QPainter * painter, 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/linestyleedit.h b/src/editors/linestyleedit.h index 82acfdc..577703f 100644 --- a/src/editors/linestyleedit.h +++ b/src/editors/linestyleedit.h @@ -1,65 +1,68 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KPROPERTY_LINESTYLEEDIT_H #define KPROPERTY_LINESTYLEEDIT_H #include "KPropertyWidgetsFactory.h" #include "KPropertyLineStyleSelector_p.h" //! Line style combo box (Property::LineStyle, equivalent of Qt::PenStyle) //! @todo enable transparency selection //! @todo add transparency option //! @todo reimplement view using KColorCells class KPROPERTYWIDGETS_EXPORT KPropertyLineStyleComboEditor : public KPropertyLineStyleSelector { Q_OBJECT Q_PROPERTY(QVariant value READ value WRITE setValue USER true) public: explicit KPropertyLineStyleComboEditor(QWidget *parent = 0); ~KPropertyLineStyleComboEditor(); QVariant value() const; Q_SIGNALS: void commitData(QWidget * editor); public Q_SLOTS: void setValue(const QVariant &value); protected Q_SLOTS: void slotValueChanged(int index); }; class KPROPERTYWIDGETS_EXPORT KPropertyLineStyleComboDelegate : public KPropertyEditorCreatorInterface, - public KPropertyValuePainterInterface + public KPropertyValuePainterInterface, + public KPropertyValueDisplayInterface { public: KPropertyLineStyleComboDelegate() {options.removeBorders = false;} 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/pixmapedit.cpp b/src/editors/pixmapedit.cpp index dae9d69..566c077 100644 --- a/src/editors/pixmapedit.cpp +++ b/src/editors/pixmapedit.cpp @@ -1,259 +1,277 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "pixmapedit.h" #include "utils.h" #include "KProperty.h" #include "KPropertyEditorDataModel.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include KPropertyPixmapEditor::KPropertyPixmapEditor(KProperty *prop, QWidget *parent) : QWidget(parent) , m_property(prop) { setBackgroundRole(QPalette::Base); QHBoxLayout *lyr = new QHBoxLayout(this); lyr->setContentsMargins(0,0,0,0); m_edit = new QLabel(this); lyr->addWidget(m_edit); m_edit->setContentsMargins(0, 1, 0, 0); m_edit->setToolTip(tr("Click to show image preview")); m_edit->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); // m_edit->setMinimumHeight(5); m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); m_edit->setBackgroundRole(QPalette::Base); m_edit->setMouseTracking(true); m_edit->installEventFilter(this); m_button = new QPushButton(this); lyr->addWidget(m_button); KPropertyUtils::setupDotDotDotButton(m_button, tr("Insert image from file"), tr("Inserts image from file")); m_popup = new QLabel(0, Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint | Qt::WindowStaysOnTopHint); m_popup->setBackgroundRole(QPalette::Base); m_popup->setFrameStyle(QFrame::Plain | QFrame::Box); m_popup->setMargin(2); m_popup->setLineWidth(1); m_popup->hide(); setFocusProxy(m_edit); connect(m_button, SIGNAL(clicked()), this, SLOT(selectPixmap())); } KPropertyPixmapEditor::~KPropertyPixmapEditor() { delete m_popup; } QVariant KPropertyPixmapEditor::value() const { return m_pixmap; } void KPropertyPixmapEditor::setValue(const QVariant &value) { m_pixmap = value.value(); if (m_pixmap.isNull() || (m_pixmap.height() <= height())) { // m_edit->setPixmap(m_pixmap); m_previewPixmap = m_pixmap; } else { QImage img(m_pixmap.toImage()); const QSize sz(size() - QSize(0,1)); if (!QRect(QPoint(0, 0), sz).contains(m_pixmap.rect())) { img = img.scaled(sz, Qt::KeepAspectRatio, Qt::SmoothTransformation); m_previewPixmap = QPixmap::fromImage(img);//preview pixmap is a bit larger } else { m_previewPixmap = m_pixmap; // img = img.scaled(sz, Qt::KeepAspectRatio, Qt::SmoothTransformation); } // const QPixmap pm( QPixmap::fromImage(img) ); // m_edit->setPixmap(pm); } // if (emitChange) // emit valueChanged(this); emit commitData(this); } QString KPropertyPixmapEditor::selectPixmapFileName() { /*#ifdef PURE_QT QString url = QFileDialog::getOpenFileName(); if (!url.isEmpty()) { m_edit->setPixmap(QPixmap(url)); emit valueChanged(this); } #endif*/ const QString caption(tr("Insert Image From File (for \"%1\" property)").arg(m_property->caption())); /*KDE4: #ifdef Q_OS_WIN QString recentDir; QString fileName = Q3FileDialog::getOpenFileName( KFileDialog::getStartURL(":lastVisitedImagePath", recentDir).path(), convertKFileDialogFilterToQFileDialogFilter(KImageIO::pattern(KImageIO::Reading)), this, 0, caption); #else*/ const QUrl url(QFileDialog::getOpenFileUrl(this, caption)); QString fileName = url.isLocalFile() ? url.toLocalFile() : url.toString(); //! @todo download the file if remote, then set fileName properly //#endif return fileName; } void KPropertyPixmapEditor::selectPixmap() { const QString fileName(selectPixmapFileName()); if (fileName.isEmpty()) return; QPixmap pm; if (!pm.load(fileName)) { //! @todo err msg return; } setValue(pm); /* KDE4: #ifdef Q_OS_WIN //save last visited path QUrl url(fileName); if (url.isLocalFile()) KRecentDirs::add(":lastVisitedImagePath", url.adjusted(QUrl::RemoveFilename|QUrl::StripTrailingSlash).path()); #endif */ } /* void PixmapEdit::resizeEvent(QResizeEvent *e) { Widget::resizeEvent(e); m_edit->move(0, 0); m_edit->resize(e->size() - QSize(m_button->width(), -1)); m_button->move(m_edit->width(), 0); m_button->setFixedSize(m_button->width(), height()); }*/ bool KPropertyPixmapEditor::eventFilter(QObject *o, QEvent *ev) { if (o == m_edit) { if (ev->type() == QEvent::MouseButtonPress && static_cast(ev)->button() == Qt::LeftButton) { if (m_previewPixmap.height() <= m_edit->height() && m_previewPixmap.width() <= m_edit->width()) return false; m_popup->setPixmap(m_previewPixmap.isNull() ? m_pixmap : m_previewPixmap); m_popup->resize(m_previewPixmap.size() + QSize(2*3, 2*3)); QPoint pos = QCursor::pos() + QPoint(3, 15); const QRect screenRect = QApplication::desktop()->availableGeometry(this); if ((pos.x() + m_popup->width()) > screenRect.width()) pos.setX(screenRect.width() - m_popup->width()); if ((pos.y() + m_popup->height()) > screenRect.height()) pos.setY(mapToGlobal(QPoint(0, 0)).y() - m_popup->height()); m_popup->move(pos); m_popup->show(); } else if (ev->type() == QEvent::MouseButtonRelease || ev->type() == QEvent::Hide) { if (m_popup->isVisible()) { m_popup->hide(); } } else if (ev->type() == QEvent::KeyPress) { QKeyEvent* e = static_cast(ev); if ((e->key() == Qt::Key_Enter) || (e->key() == Qt::Key_Space) || (e->key() == Qt::Key_Return)) { m_button->animateClick(); return true; } } } return QWidget::eventFilter(o, ev); } /* void PixmapEdit::setReadOnlyInternal(bool readOnly) { m_button->setEnabled(!readOnly); }*/ //----------------------- KPropertyPixmapDelegate::KPropertyPixmapDelegate() { // options.removeBorders = false; } QWidget* KPropertyPixmapDelegate::createEditor( int type, QWidget *parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const { Q_UNUSED(type); Q_UNUSED(option); const KPropertyEditorDataModel *editorModel = dynamic_cast(index.model()); KProperty *property = editorModel->propertyForItem(index); KPropertyPixmapEditor *pe = new KPropertyPixmapEditor(property, parent); return pe; } void KPropertyPixmapDelegate::paint( QPainter * painter, 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; m_scaledPixmap = value.value(); if (m_scaledPixmap.height() > r2.height() || m_scaledPixmap.width() > r2.width()) { //scale down QImage img(m_scaledPixmap.toImage()); img = img.scaled(r2.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); 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/pixmapedit.h b/src/editors/pixmapedit.h index 954152d..4080faa 100644 --- a/src/editors/pixmapedit.h +++ b/src/editors/pixmapedit.h @@ -1,87 +1,90 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KPROPERTY_PIXMAPEDIT_H #define KPROPERTY_PIXMAPEDIT_H #include "KPropertyWidgetsFactory.h" #include #include class QLabel; class QPushButton; class KPROPERTYWIDGETS_EXPORT KPropertyPixmapEditor : public QWidget { Q_OBJECT Q_PROPERTY(QVariant value READ value WRITE setValue USER true) public: explicit KPropertyPixmapEditor(KProperty *prop, QWidget *parent = 0); ~KPropertyPixmapEditor(); QVariant value() const; public Q_SLOTS: void setValue(const QVariant &value); Q_SIGNALS: void commitData( QWidget * editor ); protected: virtual bool eventFilter(QObject *o, QEvent *ev); protected Q_SLOTS: /*! Helper used by selectPixmap(). Can be also used by subclassess. Selected path will be stored in "lastVisitedImagePath" config entry within "Recent Dirs" config group of application's settings. This entry can be later reused when file dialogs are opened for selecting image files. */ QString selectPixmapFileName(); /*! Selects a new pixmap using "open" file dialog. Can be reimplemented. */ virtual void selectPixmap(); protected: QLabel *m_edit; QLabel *m_popup; QPushButton *m_button; KProperty *m_property; //! @todo QVariant m_recentlyPainted; QPixmap m_pixmap; //! @todo QPixmap m_scaledPixmap QPixmap m_previewPixmap; }; class KPROPERTYWIDGETS_EXPORT KPropertyPixmapDelegate : public KPropertyEditorCreatorInterface, - public KPropertyValuePainterInterface + public KPropertyValuePainterInterface, + public KPropertyValueDisplayInterface { public: KPropertyPixmapDelegate(); 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/pointedit.cpp b/src/editors/pointedit.cpp index 14d25f0..6037cf2 100644 --- a/src/editors/pointedit.cpp +++ b/src/editors/pointedit.cpp @@ -1,69 +1,80 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "pointedit.h" #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())); } //------------ KPointComposedProperty::KPointComposedProperty(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); (void)new KProperty("y", QVariant(), QObject::tr("Y", "Property: Y coordinate"), QObject::tr("Y Coordinate", "Property: Y coordinate"), KProperty::Int, property); } void KPointComposedProperty::setValue(KProperty *property, const QVariant &value, bool rememberOldValue) { const QPoint p( value.toPoint() ); property->child("x")->setValue(p.x(), rememberOldValue, false); property->child("y")->setValue(p.y(), rememberOldValue, false); } void KPointComposedProperty::childValueChanged(KProperty *child, const QVariant &value, bool rememberOldValue) { Q_UNUSED(rememberOldValue); QPoint p( child->parent()->value().toPoint() ); if (child->name() == "x") p.setX(value.toInt()); else if (child->name() == "y") p.setY(value.toInt()); child->parent()->setValue(p, true, false); } diff --git a/src/editors/pointedit.h b/src/editors/pointedit.h index a68ed83..6d528e4 100644 --- a/src/editors/pointedit.h +++ b/src/editors/pointedit.h @@ -1,47 +1,48 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KPROPERTY_POINTEDIT_H #define KPROPERTY_POINTEDIT_H #include "KPropertyWidgetsFactory.h" class KPROPERTYWIDGETS_EXPORT KPointComposedProperty : public KComposedPropertyInterface { public: explicit KPointComposedProperty(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 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/pointfedit.cpp b/src/editors/pointfedit.cpp index 0c581b4..d483209 100644 --- a/src/editors/pointfedit.cpp +++ b/src/editors/pointfedit.cpp @@ -1,70 +1,81 @@ /* 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 modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "pointfedit.h" #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())); } //------------ KPointFComposedProperty::KPointFComposedProperty(KProperty *property) : KComposedPropertyInterface(property) { (void)new KProperty("x", QVariant(), QObject::tr("X", "Property: X coordinate"), 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::Double, property); } void KPointFComposedProperty::setValue(KProperty *property, const QVariant &value, bool rememberOldValue) { const QPointF p( value.toPointF() ); property->child("x")->setValue(p.x(), rememberOldValue, false); property->child("y")->setValue(p.y(), rememberOldValue, false); } void KPointFComposedProperty::childValueChanged(KProperty *child, const QVariant &value, bool rememberOldValue) { Q_UNUSED(rememberOldValue); QPointF p( child->parent()->value().toPointF() ); if (child->name() == "x") p.setX(value.toDouble()); else if (child->name() == "y") p.setY(value.toDouble()); child->parent()->setValue(p, true, false); } diff --git a/src/editors/pointfedit.h b/src/editors/pointfedit.h index e1284b8..5d3d9fa 100644 --- a/src/editors/pointfedit.h +++ b/src/editors/pointfedit.h @@ -1,48 +1,49 @@ /* 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 modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KPROPERTY_POINTFEDIT_H #define KPROPERTY_POINTFEDIT_H #include "KPropertyWidgetsFactory.h" class KPROPERTYWIDGETS_EXPORT KPointFComposedProperty : public KComposedPropertyInterface { public: explicit KPointFComposedProperty(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 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/rectedit.cpp b/src/editors/rectedit.cpp index 867c06f..327735e 100644 --- a/src/editors/rectedit.cpp +++ b/src/editors/rectedit.cpp @@ -1,81 +1,92 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "rectedit.h" #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())); } //------------ KRectComposedProperty::KRectComposedProperty(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); (void)new KProperty("y", QVariant(), QObject::tr("Y", "Property: Y coordinate"), QObject::tr("Y Coordinate", "Property: Y coordinate"), KProperty::Int, property); (void)new KProperty("width", QVariant(), QObject::tr("Width", "Property: width of rectangle"), QObject::tr("Width", "Property: width of rectangle"), KProperty::UInt, property); (void)new KProperty("height", QVariant(), QObject::tr("Height", "Property: height of rectangle"), QObject::tr("Height", "Property: height of rectangle"), KProperty::UInt, property); } void KRectComposedProperty::setValue(KProperty *property, const QVariant &value, bool rememberOldValue) { const QRect r( value.toRect() ); 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) { Q_UNUSED(rememberOldValue); QRect r( child->parent()->value().toRect() ); if (child->name() == "x") r.moveLeft(value.toInt()); else if (child->name() == "y") r.moveTop(value.toInt()); else if (child->name() == "width") r.setWidth(value.toInt()); else if (child->name() == "height") r.setHeight(value.toInt()); child->parent()->setValue(r, true, false); } diff --git a/src/editors/rectedit.h b/src/editors/rectedit.h index 468d9c2..0638d73 100644 --- a/src/editors/rectedit.h +++ b/src/editors/rectedit.h @@ -1,45 +1,46 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KPROPERTY_RECTEDIT_H #define KPROPERTY_RECTEDIT_H #include "KPropertyWidgetsFactory.h" class KPROPERTYWIDGETS_EXPORT KRectComposedProperty : public KComposedPropertyInterface { public: explicit KRectComposedProperty(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 + 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/sizeedit.cpp b/src/editors/sizeedit.cpp index dd19b5d..3cd0d61 100644 --- a/src/editors/sizeedit.cpp +++ b/src/editors/sizeedit.cpp @@ -1,64 +1,75 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "sizeedit.h" #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())); } //------------ KSizeComposedProperty::KSizeComposedProperty(KProperty *property) : KComposedPropertyInterface(property) { (void)new KProperty("width", QVariant(), QObject::tr("Width"), QObject::tr("Width"), KProperty::UInt, property); (void)new KProperty("height", QVariant(), QObject::tr("Height"), QObject::tr("Height"), KProperty::UInt, property); } void KSizeComposedProperty::setValue(KProperty *property, const QVariant &value, bool rememberOldValue) { const QSize s( value.toSize() ); property->child("width")->setValue(s.width(), rememberOldValue, false); property->child("height")->setValue(s.height(), rememberOldValue, false); } void KSizeComposedProperty::childValueChanged(KProperty *child, const QVariant &value, bool rememberOldValue) { Q_UNUSED(rememberOldValue); QSize s( child->parent()->value().toSize() ); if (child->name() == "width") s.setWidth(value.toInt()); else if (child->name() == "height") s.setHeight(value.toInt()); child->parent()->setValue(s, true, false); } diff --git a/src/editors/sizeedit.h b/src/editors/sizeedit.h index 5d423f1..d4a1f3d 100644 --- a/src/editors/sizeedit.h +++ b/src/editors/sizeedit.h @@ -1,47 +1,48 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KPROPERTY_SIZEEDIT_H #define KPROPERTY_SIZEEDIT_H #include "KPropertyWidgetsFactory.h" class KPROPERTYWIDGETS_EXPORT KSizeComposedProperty : public KComposedPropertyInterface { public: explicit KSizeComposedProperty(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 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/sizefedit.cpp b/src/editors/sizefedit.cpp index c69ffe4..506560e 100644 --- a/src/editors/sizefedit.cpp +++ b/src/editors/sizefedit.cpp @@ -1,64 +1,75 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "sizefedit.h" #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())); } //------------ KSizeFComposedProperty::KSizeFComposedProperty(KProperty *property) : KComposedPropertyInterface(property) { (void)new KProperty("width", QVariant(), QObject::tr("Width"), QObject::tr("Width"), KProperty::Double, property); (void)new KProperty("height", QVariant(), QObject::tr("Height"), QObject::tr("Height"), KProperty::Double, property); } void KSizeFComposedProperty::setValue(KProperty *property, const QVariant &value, bool rememberOldValue) { const QSizeF s( value.toSizeF() ); property->child("width")->setValue(s.width(), rememberOldValue, false); property->child("height")->setValue(s.height(), rememberOldValue, false); } void KSizeFComposedProperty::childValueChanged(KProperty *child, const QVariant &value, bool rememberOldValue) { Q_UNUSED(rememberOldValue); QSizeF s( child->parent()->value().toSizeF() ); if (child->name() == "width") s.setWidth(value.toDouble()); else if (child->name() == "height") s.setHeight(value.toDouble()); child->parent()->setValue(s, true, false); } diff --git a/src/editors/sizefedit.h b/src/editors/sizefedit.h index 0a35465..3b5cb57 100644 --- a/src/editors/sizefedit.h +++ b/src/editors/sizefedit.h @@ -1,47 +1,48 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KPROPERTY_SIZEFEDIT_H #define KPROPERTY_SIZEFEDIT_H #include "KPropertyWidgetsFactory.h" class KPROPERTYWIDGETS_EXPORT KSizeFComposedProperty : public KComposedPropertyInterface { public: explicit KSizeFComposedProperty(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 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/sizepolicyedit.cpp b/src/editors/sizepolicyedit.cpp index 3fb4ec5..af9068e 100644 --- a/src/editors/sizepolicyedit.cpp +++ b/src/editors/sizepolicyedit.cpp @@ -1,137 +1,146 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "sizepolicyedit.h" +#include "KPropertyCoreUtils_p.h" #include class SizePolicyListData : public KPropertyListData { public: SizePolicyListData() : KPropertyListData(keysInternal(), stringsInternal()) { } QString nameForPolicy(QSizePolicy::Policy p) { const int index = keys.indexOf((int)p); if (index == -1) return names[0]; return names[index]; } private: static QList keysInternal() { QList keys; keys << QSizePolicy::Fixed << QSizePolicy::Minimum << QSizePolicy::Maximum << QSizePolicy::Preferred << QSizePolicy::Expanding << QSizePolicy::MinimumExpanding << QSizePolicy::Ignored; return keys; } static QStringList stringsInternal() { QStringList strings; strings << QObject::tr("Fixed", "Size Policy") << QObject::tr("Minimum", "Size Policy") << QObject::tr("Maximum", "Size Policy") << QObject::tr("Preferred", "Size Policy") << QObject::tr("Expanding", "Size Policy") << QObject::tr("Minimum Expanding", "Size Policy") << QObject::tr("Ignored", "Size Policy"); return strings; } }; Q_GLOBAL_STATIC(SizePolicyListData, s_sizePolicyListData) //--------- -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 const KPropertyListData& KPropertySizePolicyDelegate::listData() { return *s_sizePolicyListData; } //------------ KSizePolicyComposedProperty::KSizePolicyComposedProperty(KProperty *property) : KComposedPropertyInterface(property) { (void)new KProperty("hor_policy", new SizePolicyListData(), QVariant(), QObject::tr("Hor. Policy"), QObject::tr("Horizontal Policy"), KProperty::ValueFromList, property); (void)new KProperty("vert_policy", new SizePolicyListData(), QVariant(), QObject::tr("Vert. Policy"), QObject::tr("Vertical Policy"), KProperty::ValueFromList, property); (void)new KProperty("hor_stretch", QVariant(), QObject::tr("Hor. Stretch"), QObject::tr("Horizontal Stretch"), KProperty::UInt, property); (void)new KProperty("vert_stretch", QVariant(), QObject::tr("Vert. Stretch"), QObject::tr("Vertical Stretch"), KProperty::UInt, property); } void KSizePolicyComposedProperty::setValue(KProperty *property, const QVariant &value, bool rememberOldValue) { const QSizePolicy sp( value.value() ); property->child("hor_policy")->setValue(sp.horizontalPolicy(), rememberOldValue, false); property->child("vert_policy")->setValue(sp.verticalPolicy(), rememberOldValue, false); property->child("hor_stretch")->setValue(sp.horizontalStretch(), rememberOldValue, false); property->child("vert_stretch")->setValue(sp.verticalStretch(), rememberOldValue, false); } void KSizePolicyComposedProperty::childValueChanged(KProperty *child, const QVariant &value, bool rememberOldValue) { Q_UNUSED(rememberOldValue); QSizePolicy sp( child->parent()->value().value() ); if (child->name() == "hor_policy") sp.setHorizontalPolicy(static_cast(value.toInt())); else if (child->name() == "vert_policy") sp.setVerticalPolicy(static_cast(value.toInt())); else if (child->name() == "hor_stretch") sp.setHorizontalStretch(value.toInt()); else if (child->name() == "vert_stretch") sp.setVerticalStretch(value.toInt()); child->parent()->setValue(sp, true, false); } bool KSizePolicyComposedProperty::valuesEqual(const QVariant &first, const QVariant &second) { return first.value() == second.value(); } diff --git a/src/editors/sizepolicyedit.h b/src/editors/sizepolicyedit.h index abec70a..76018ed 100644 --- a/src/editors/sizepolicyedit.h +++ b/src/editors/sizepolicyedit.h @@ -1,50 +1,50 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KPROPERTY_SIZEPOLICYEDIT_H #define KPROPERTY_SIZEPOLICYEDIT_H #include "KPropertyWidgetsFactory.h" class KPROPERTYWIDGETS_EXPORT KSizePolicyComposedProperty : public KComposedPropertyInterface { public: explicit KSizePolicyComposedProperty(KProperty *parent); virtual void setValue(KProperty *property, const QVariant &value, bool rememberOldValue); virtual void childValueChanged(KProperty *child, const QVariant &value, bool rememberOldValue); virtual bool valuesEqual(const QVariant &first, const QVariant &second) Q_DECL_OVERRIDE; }; 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(); }; #endif diff --git a/src/editors/spinbox.cpp b/src/editors/spinbox.cpp index fce7f06..53c17ae 100644 --- a/src/editors/spinbox.cpp +++ b/src/editors/spinbox.cpp @@ -1,290 +1,312 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "spinbox.h" #include "KProperty.h" #include "KProperty_p.h" #include "KPropertyEditorDataModel.h" #include "KPropertyEditorView.h" #include "KPropertyUnit_p.h" #include "KPropertyWidgetsFactory.h" #include "kproperty_debug.h" #include #include #include #include //! @return font size expressed in points (pt) //! or if points are not available - in pixels (px) for @a font static QString fontSizeForCSS(const QFont& font) { return font.pointSize() > 0 ? QString::fromLatin1("%1pt").arg(font.pointSize()) : QString::fromLatin1("%1px").arg(font.pixelSize()); } static QString cssForSpinBox(const char *_class, const QFont& font, int itemHeight) { return QString::fromLatin1( "%5 { border-left: 0; border-right: 0; font-size: %3; } " "%5::down-button { height: %1px; %4 } " "%5::up-button { height: %2px; } " "QLineEdit { border-width:0px; } " ) .arg(itemHeight/2 - 1).arg(itemHeight - itemHeight/2 - 1) .arg(fontSizeForCSS(font)) .arg(QLatin1String((itemHeight/2 <= 9) ? "bottom: 2px;" : "bottom: 0px;")) .arg(QLatin1String(_class)); } KPropertyIntSpinBox::KPropertyIntSpinBox(const KProperty* prop, QWidget *parent, int itemHeight) : QSpinBox(parent) , m_unsigned(prop->type() == KProperty::UInt) { // kprDebug() << "itemHeight:" << itemHeight; QLineEdit* le = findChild(); setContentsMargins(0,0,0,0); if (le) { // le->setFixedHeight(itemHeight); le->setAlignment(Qt::AlignLeft); le->setContentsMargins(0,0,0,0); } // 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)); QVariant maxVal(prop->option("max", INT_MAX)); setMinimum(minVal.toInt()); setMaximum(maxVal.toInt()); QString minValueText(prop->option("minValueText").toString()); if (!minValueText.isEmpty()) setSpecialValueText(minValueText); connect(this, SIGNAL(valueChanged(int)), this, SLOT(slotValueChanged(int))); } KPropertyIntSpinBox::~KPropertyIntSpinBox() { } QVariant KPropertyIntSpinBox::value() const { if (m_unsigned) return uint(QSpinBox::value()); return QSpinBox::value(); } void KPropertyIntSpinBox::setValue(const QVariant& value) { int v( value.toInt() ); if (m_unsigned && v<0) { kprWarning() << "could not assign negative value" << v << "- assigning 0"; v = 0; } QSpinBox::setValue(v); } void KPropertyIntSpinBox::slotValueChanged(int value) { Q_UNUSED(value); emit commitData(this); } //----------------------- class KPropertyDoubleSpinBox::Private { public: KPropertyUnit unit; bool hasUnit; }; static void decodeUnit(const KProperty &property, KPropertyUnit *unit, bool *hasUnit) { const QString unitString = property.option("unit").toString(); if (unitString.isEmpty()) { *hasUnit = false; } else { *unit = KPropertyUnit::fromSymbol(unitString, hasUnit); } } KPropertyDoubleSpinBox::KPropertyDoubleSpinBox(const KProperty* prop, QWidget *parent, int itemHeight) : QDoubleSpinBox(parent) , d(new Private) { setFrame(false); QLineEdit* le = findChild(); if (le) { le->setAlignment(Qt::AlignLeft); 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")); if (minVal.canConvert(QMetaType::Double)) { setMinimum(minVal.toDouble()); } QVariant maxVal(prop->option("max", double(INT_MAX / 100))); if (maxVal.canConvert(QMetaType::Double)) { setMaximum(maxVal.toDouble()); } QVariant step(prop->option("step", KPROPERTY_DEFAULT_DOUBLE_VALUE_STEP)); if (step.canConvert(QMetaType::Double)) { setSingleStep(step.toDouble()); } //! @todo implement slider // bool slider = prop->option("slider", false).toBool(); QVariant precision(prop->option("precision")); if (precision.canConvert(QMetaType::Int)) { setDecimals(precision.toInt()); } QString minValueText(prop->option("minValueText").toString()); if (!minValueText.isEmpty()) setSpecialValueText(minValueText); decodeUnit(*prop, &d->unit, &d->hasUnit); connect(this, SIGNAL(valueChanged(double)), this, SLOT(slotValueChanged(double))); } KPropertyDoubleSpinBox::~KPropertyDoubleSpinBox() { delete d; } void KPropertyDoubleSpinBox::resizeEvent( QResizeEvent * event ) { setFixedHeight(height() + 1); QDoubleSpinBox::resizeEvent(event); } void KPropertyDoubleSpinBox::setValue(double v) { if (d->hasUnit) { QDoubleSpinBox::setValue(d->unit.toUserValue(v)); return; } QDoubleSpinBox::setValue(v); } double KPropertyDoubleSpinBox::value() const { if (d->hasUnit) { return d->unit.fromUserValue(QDoubleSpinBox::value()); } return QDoubleSpinBox::value(); } void KPropertyDoubleSpinBox::slotValueChanged(double value) { Q_UNUSED(value); emit commitData(this); } //----------------------- KPropertyIntSpinBoxDelegate::KPropertyIntSpinBoxDelegate() { } -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")); QString minValueText(prop->option("minValueText").toString()); if (!minValue.isNull() && !minValueText.isEmpty() && minValue.toInt() == prop->value().toInt()) { 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, const QStyleOptionViewItem & option, const QModelIndex & index ) const { Q_UNUSED(type); const KPropertyEditorDataModel *editorModel = dynamic_cast(index.model()); KProperty *prop = editorModel->propertyForItem(index); return new KPropertyIntSpinBox(prop, parent, option.rect.height() - 2); } //----------------------- KPropertyDoubleSpinBoxDelegate::KPropertyDoubleSpinBoxDelegate() { } -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, const QStyleOptionViewItem & option, const QModelIndex & index ) const { Q_UNUSED(type); const KPropertyEditorDataModel *editorModel = dynamic_cast(index.model()); KProperty *prop = editorModel->propertyForItem(index); return new KPropertyDoubleSpinBox(prop, parent, option.rect.height() - 2 - 1); } diff --git a/src/editors/spinbox.h b/src/editors/spinbox.h index 1dd8532..7b0688f 100644 --- a/src/editors/spinbox.h +++ b/src/editors/spinbox.h @@ -1,124 +1,128 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KPROPERTY_SPINBOX_H #define KPROPERTY_SPINBOX_H #include "KPropertyWidgetsFactory.h" #include #include //! A delegate supporting Int and UInt types /*! Note that due to KIntNumInput limitations, for UInt the maximum value is INT_MAX, not UINT_MAX. */ class KPROPERTYWIDGETS_EXPORT KPropertyIntSpinBox : public QSpinBox { Q_OBJECT Q_PROPERTY(QVariant value READ value WRITE setValue USER true) public: KPropertyIntSpinBox(const KProperty* prop, QWidget *parent, int itemHeight); virtual ~KPropertyIntSpinBox(); QVariant value() const; // virtual void setProperty(const Property *prop); Q_SIGNALS: void commitData(QWidget* editor); public Q_SLOTS: void setValue(const QVariant& value); //! @todo virtual bool eventFilter(QObject *o, QEvent *e); /* QLineEdit * lineEdit() const { return KIntSpinBox::lineEdit(); }*/ protected Q_SLOTS: void slotValueChanged(int value); private: bool m_unsigned; }; //! Double editor class KPROPERTYWIDGETS_EXPORT KPropertyDoubleSpinBox : public QDoubleSpinBox { Q_OBJECT Q_PROPERTY(double value READ value WRITE setValue USER true) public: //! @todo Support setting precision limits, step, etc. KPropertyDoubleSpinBox(const KProperty* prop, QWidget *parent, int itemHeight); virtual ~KPropertyDoubleSpinBox(); // virtual bool eventFilter(QObject *o, QEvent *e); /* QLineEdit * lineEdit() const { return QDoubleSpinBox::lineEdit(); }*/ double value() const; Q_SIGNALS: void commitData(QWidget* editor); public Q_SLOTS: void setValue(double value); protected Q_SLOTS: void slotValueChanged(double value); protected: //! Used to fix height of the internal spin box virtual void resizeEvent( QResizeEvent * event ); class Private; Private * const d; }; //! 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; }; #endif diff --git a/src/editors/timeedit.cpp b/src/editors/timeedit.cpp index ca49aca..19c6b5c 100644 --- a/src/editors/timeedit.cpp +++ b/src/editors/timeedit.cpp @@ -1,96 +1,103 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "timeedit.h" #include #include KPropertyTimeEditor::KPropertyTimeEditor(const KProperty* prop, QWidget* parent) : QTimeEdit(parent) { setFrame(false); + setContentsMargins(0,1,0,0); const QTime minTime = prop->option("min").toTime(); if (minTime.isValid()) { setMinimumTime(minTime); } const QTime maxTime = prop->option("max").toTime(); if (maxTime.isValid()) { setMaximumTime(maxTime); } connect(this, SIGNAL(timeChanged(QTime)), this, SLOT(onTimeChanged())); } KPropertyTimeEditor::~KPropertyTimeEditor() { } QVariant KPropertyTimeEditor::value() const { return QVariant(time()); } void KPropertyTimeEditor::setValue(const QVariant& value) { blockSignals(true); setTime(value.toTime()); blockSignals(false); } void KPropertyTimeEditor::paintEvent(QPaintEvent* event) { QTimeEdit::paintEvent(event); KPropertyWidgetsFactory::paintTopGridLine(this); } void KPropertyTimeEditor::onTimeChanged() { emit commitData(this); } //! @todo Port to KLocale, be inspired by KexiTimeTableEdit (with Kexi*Formatter) KPropertyTimeDelegate::KPropertyTimeDelegate() { } -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, const QStyleOptionViewItem& option, const QModelIndex& index) const { Q_UNUSED(type); Q_UNUSED(option); const KPropertyEditorDataModel* editorModel = dynamic_cast(index.model()); KProperty* prop = editorModel->propertyForItem(index); return new KPropertyTimeEditor(prop, parent); } diff --git a/src/editors/timeedit.h b/src/editors/timeedit.h index aa596ba..fb45905 100644 --- a/src/editors/timeedit.h +++ b/src/editors/timeedit.h @@ -1,64 +1,65 @@ /* 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KPROPERTY_TIMEEDIT_H #define KPROPERTY_TIMEEDIT_H #include "KPropertyWidgetsFactory.h" #include class KPROPERTYWIDGETS_EXPORT KPropertyTimeEditor : public QTimeEdit { Q_OBJECT Q_PROPERTY(QVariant value READ value WRITE setValue USER true) public: KPropertyTimeEditor(const KProperty* prop, QWidget* parent); virtual ~KPropertyTimeEditor(); QVariant value() const; Q_SIGNALS: void commitData(QWidget* editor); public Q_SLOTS: void setValue(const QVariant& value); protected: virtual void paintEvent(QPaintEvent* event); protected Q_SLOTS: void onTimeChanged(); }; 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; }; #endif