diff --git a/CMakeLists.txt b/CMakeLists.txt index 35c9a0d..e93a7c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,47 +1,60 @@ -cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) +if(EXISTS "/usr/lib/qt5/qml/Sailfish/Silica/SilicaGridView.qml") #SailfishOS + cmake_minimum_required(VERSION 2.8.11 FATAL_ERROR) +else() + cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) +endif() + + project(KProperty) # ECM setup find_package(ECM 1.8.0 REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR}) if(POLICY CMP0063) # Honor visibility properties for all target types (since cmake 3.3) cmake_policy(SET CMP0063 OLD) endif() include(ECMGenerateHeaders) include(ECMGeneratePriFile) include(ECMPackageConfigHelpers) include(ECMPoQmTools) include(ECMSetupVersion) include(ECMOptionalAddSubdirectory) include(KDEInstallDirs) include(KDEFrameworkCompilerSettings) include(KDECMakeSettings) include(FeatureSummary) include(GenerateExportHeader) include(MacroLogFeature) include(KPropertyMacros) +simple_option(KPROPERTY_WIDGETS "Build the QtWidget components of KProperty" ON) + set(KPROPERTY_VERSION "2.96.0") # Update this # Dependencies set(REQUIRED_QT_VERSION "5.2.0") -# Required components to build this framework -find_package(Qt5 ${REQUIRED_QT_VERSION} NO_MODULE REQUIRED Core Widgets) -find_package(KF5 5.7.0 REQUIRED Config CoreAddons WidgetsAddons GuiAddons) -#TODO KIO +find_package(Qt5 ${REQUIRED_QT_VERSION} NO_MODULE REQUIRED Core) + +if(KPROPERTY_WIDGETS) + find_package(Qt5 ${REQUIRED_QT_VERSION} NO_MODULE REQUIRED Widgets) + find_package(KF5 5.7.0 REQUIRED Config CoreAddons WidgetsAddons GuiAddons) + + #TODO KIO + get_git_revision_and_branch() + add_tests() + add_examples() +endif() -get_git_revision_and_branch() -add_tests() -add_examples() add_unfinished_features_option() -add_pc_file() +add_pc_file(KPropertyCore) +add_pc_file(KPropertyWidgets) add_subdirectory(src) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) macro_display_feature_log() diff --git a/KProperty.pc.cmake b/KPropertyCore.pc.cmake similarity index 63% copy from KProperty.pc.cmake copy to KPropertyCore.pc.cmake index c2175e6..71020a3 100644 --- a/KProperty.pc.cmake +++ b/KPropertyCore.pc.cmake @@ -1,12 +1,12 @@ prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=${prefix} libdir=${exec_prefix}/lib includedir=${prefix}/include -Name: KProperty -Description: A property editing framework with editor +Name: KPropertyCore +Description: A property editing framework with editor (core) Version: @KPROPERTY_VERSION@ URL: https://community.kde.org/KProperty -Requires: Qt5Core Qt5Gui KF5WidgetsAddons KF5GuiAddons +Requires: Qt5Core Libs: -L${libdir} Cflags: -I${includedir} diff --git a/KProperty.pc.cmake b/KPropertyWidgets.pc.cmake similarity index 58% rename from KProperty.pc.cmake rename to KPropertyWidgets.pc.cmake index c2175e6..7ff30c1 100644 --- a/KProperty.pc.cmake +++ b/KPropertyWidgets.pc.cmake @@ -1,12 +1,12 @@ prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=${prefix} libdir=${exec_prefix}/lib includedir=${prefix}/include -Name: KProperty -Description: A property editing framework with editor +Name: KPropertyWidgets +Description: A property editing framework with edito (widgets) Version: @KPROPERTY_VERSION@ URL: https://community.kde.org/KProperty -Requires: Qt5Core Qt5Gui KF5WidgetsAddons KF5GuiAddons +Requires: KPropertyCore Qt5Core Qt5Gui KF5WidgetsAddons KF5GuiAddons Libs: -L${libdir} Cflags: -I${includedir} diff --git a/cmake/modules/KPropertyMacros.cmake b/cmake/modules/KPropertyMacros.cmake index 0ca41ea..225cfe2 100644 --- a/cmake/modules/KPropertyMacros.cmake +++ b/cmake/modules/KPropertyMacros.cmake @@ -1,101 +1,101 @@ # Additional CMake macros # # Copyright (C) 2015 Jarosław Staniek # # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. include(FeatureSummary) include(GetGitRevisionDescription) # Adds a feature info using add_feature_info() with _NAME and _DESCRIPTION. # If _NAME is equal to _DEFAULT, shows this fact. macro(add_simple_feature_info _NAME _DESCRIPTION _DEFAULT) if("${_DEFAULT}" STREQUAL "${${_NAME}}") set(_STATUS " (default value)") else() set(_STATUS "") endif() add_feature_info(${_NAME} ${_NAME} ${_DESCRIPTION}${_STATUS}) endmacro() # Adds a simple option using option() with _NAME and _DESCRIPTION and a feature # info for it using add_simple_feature_info(). If _NAME is equal to _DEFAULT, shows this fact. macro(simple_option _NAME _DESCRIPTION _DEFAULT) option(${_NAME} ${_DESCRIPTION} ${_DEFAULT}) add_simple_feature_info(${_NAME} ${_DESCRIPTION} ${_DEFAULT}) endmacro() # Fetches git revision and branch from the source dir of the current build if possible. # Sets ${PROJECT_NAME_UPPER}_GIT_SHA1_STRING and ${PROJECT_NAME_UPPER}_GIT_BRANCH_STRING variables. macro(get_git_revision_and_branch) get_git_head_revision(GIT_REFSPEC _GIT_SHA1) get_git_branch(_GIT_BRANCH) string(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPER) if(_GIT_SHA1 AND _GIT_BRANCH) string(SUBSTRING ${_GIT_SHA1} 0 7 _GIT_SHA1) set(${PROJECT_NAME_UPPER}_GIT_SHA1_STRING ${_GIT_SHA1}) set(${PROJECT_NAME_UPPER}_GIT_BRANCH_STRING ${_GIT_BRANCH}) else() set(${PROJECT_NAME_UPPER}_GIT_SHA1_STRING "") set(${PROJECT_NAME_UPPER}_GIT_BRANCH_STRING "") endif() endmacro() # Adds BUILD_TESTING option to enable all kinds of tests. If enabled, build in autotests/ # and tests/ subdirectory is enabled. IF optional argument ARG1 is ON, building tests will # be ON by default. Otherwise building tests will be OFF. ARG1 is OFF by default. # If tests are OFF, BUILD_COVERAGE is set to OFF. # If tests are on BUILD_TESTING macro is defined. macro(add_tests) if (NOT "${ARG1}" STREQUAL "ON") set(_SET OFF) endif() simple_option(BUILD_TESTING "Build tests" ${_SET}) # override default from CTest.cmake if(BUILD_TESTING) add_definitions(-DBUILD_TESTING) include(CTest) if (EXISTS ${CMAKE_SOURCE_DIR}/autotests) add_subdirectory(autotests) endif() if (EXISTS ${CMAKE_SOURCE_DIR}/tests) add_subdirectory(tests) endif() else() set(BUILD_COVERAGE OFF) simple_option(BUILD_COVERAGE "Build test coverage (disabled because BUILD_TESTING is OFF)" OFF) endif() endmacro() # Adds BUILD_EXAMPLES option to enable examples. If enabled, build in examples/ subdirectory # is enabled. If optional argument ARG1 is ON, building examples will be ON by default. # Otherwise building examples will be OFF. ARG1 is OFF by default. macro(add_examples) set(_SET ${ARGV0}) if (NOT "${_SET}" STREQUAL ON) set(_SET OFF) endif() simple_option(BUILD_EXAMPLES "Build example applications" ${_SET}) if (BUILD_EXAMPLES AND EXISTS ${CMAKE_SOURCE_DIR}/examples) add_subdirectory(examples) endif() endmacro() # Adds ${PROJECT_NAME_UPPER}_UNFINISHED option. If it is ON, unfinished features # (useful for testing but may confuse end-user) are compiled-in. # This option is OFF by default. macro(add_unfinished_features_option) string(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPER) simple_option(${PROJECT_NAME_UPPER}_UNFINISHED "Include unfinished features (useful for testing but may confuse end-user)" OFF) endmacro() -# Adds commands that generate ${PROJECT_NAME}.pc file out of ${PROJECT_NAME}.pc.cmake file +# Adds commands that generate ${PKGCONFIG_FILE_NAME}.pc file out of ${PKGCONFIG_FILE_NAME}.pc.cmake file # and install the .pc file to ${LIB_INSTALL_DIR}/pkgconfig. These commands are not executed for WIN32. -# ${CMAKE_SOURCE_DIR}/${PROJECT_NAME}.pc.cmake should exist. -macro(add_pc_file) +# ${CMAKE_SOURCE_DIR}/${PKGCONFIG_FILE_NAME}.pc.cmake should exist. +macro(add_pc_file PKGCONFIG_FILE_NAME) if (NOT WIN32) - configure_file(${CMAKE_SOURCE_DIR}/${PROJECT_NAME}.pc.cmake ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc @ONLY) - install(FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) + configure_file(${CMAKE_SOURCE_DIR}/${PKGCONFIG_FILE_NAME}.pc.cmake ${CMAKE_BINARY_DIR}/${PKGCONFIG_FILE_NAME}.pc @ONLY) + install(FILES ${CMAKE_BINARY_DIR}/${PKGCONFIG_FILE_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) endif() endmacro() diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 921ee4d..dad9f94 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,13 +1,13 @@ find_package(Qt5Widgets REQUIRED) find_package(KF5WidgetsAddons) find_package(KF5GuiAddons) remove_definitions( -DQT_NO_KEYWORDS -DQT_NO_SIGNALS_SLOTS_KEYWORDS -DQT_NO_CAST_FROM_ASCII ) set(kpropertyexample_SRCS main.cpp window.cpp) add_executable(kpropertyexample ${kpropertyexample_SRCS}) -target_link_libraries(kpropertyexample Qt5::Widgets KProperty) +target_link_libraries(kpropertyexample Qt5::Widgets KPropertyWidgets) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 58957c0..4101ac8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,159 +1,246 @@ # Options # simple_option(KPROPERTY_...... "....." OFF) - configure_file(config-kproperty.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-kproperty.h) -add_subdirectory(editors) - -set(libkpropertyeditors_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/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 -) - -set(kproperty_LIB_SRCS - kproperty_debug.cpp +set(kpropertycore_LIB_SRCS KProperty.cpp KPropertySet.cpp - KPropertyFactory.cpp - KDefaultPropertyFactory.cpp - KPropertyEditorView.cpp - KPropertyEditorDataModel.cpp - KPropertyUtils.cpp KPropertyUnit_p.cpp - KPropertyLineStyleSelector_p.cpp - KPropertyLineStyleModel_p.cpp - KPropertyLineStyleItemDelegate_p.cpp - ${libkpropertyeditors_SRCS} + KPropertyFactory.cpp + kproperty_debug.cpp ) -ecm_create_qm_loader(kproperty_LIB_SRCS kproperty_qt) - -add_library(KProperty SHARED ${kproperty_LIB_SRCS}) - -generate_export_header(KProperty) +if(KPROPERTY_WIDGETS) + add_subdirectory(editors) + + set(libkpropertyeditors_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/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 + ) + + set(kpropertywidgets_LIB_SRCS + ${libkpropertyeditors_SRCS} + kpropertywidgets_debug.cpp + KPropertyWidgetsFactory.cpp + KDefaultPropertyFactory.cpp + KPropertyEditorView.cpp + KPropertyEditorDataModel.cpp + KPropertyUtils.cpp + KPropertyLineStyleSelector_p.cpp + KPropertyLineStyleModel_p.cpp + KPropertyLineStyleItemDelegate_p.cpp + ) +endif() set(kproperty_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/kproperty ${CMAKE_CURRENT_BINARY_DIR}/editors ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/editors ) -target_include_directories(KProperty - PUBLIC "$" - INTERFACE "$" - PRIVATE editors +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_link_libraries(KProperty - KF5::WidgetsAddons - KF5::GuiAddons - #TODO KF5::KIOWidgets +target_include_directories(KPropertyCore + PUBLIC "$" + INTERFACE "$" + PRIVATE editors ) -set_target_properties(KProperty +set_target_properties(KPropertyCore PROPERTIES VERSION 1.0 SOVERSION 1.0.0 - EXPORT_NAME KProperty + EXPORT_NAME KPropertyCore ) +if(KPROPERTY_WIDGETS) + add_library(KPropertyWidgets SHARED ${kpropertywidgets_LIB_SRCS}) + target_link_libraries(KPropertyWidgets + KPropertyCore + KF5::WidgetsAddons + KF5::GuiAddons + ) + 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_INSTALL_DIR "${CMAKECONFIG_INSTALL_PREFIX}/KProperty") +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 KPROPERTY VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/kproperty_version.h" - PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KPropertyConfigVersion.cmake" + PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KPropertyCoreConfigVersion.cmake" ) ecm_configure_package_config_file( - "${CMAKE_CURRENT_SOURCE_DIR}/KPropertyConfig.cmake.in" - "${CMAKE_CURRENT_BINARY_DIR}/KPropertyConfig.cmake" - INSTALL_DESTINATION "${CMAKECONFIG_INSTALL_DIR}" + "${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}/KPropertyConfig.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/KPropertyConfigVersion.cmake" - DESTINATION "${CMAKECONFIG_INSTALL_DIR}" - COMPONENT Devel) - -install(TARGETS KProperty - EXPORT KPropertyTargets - ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) - -install(EXPORT KPropertyTargets - DESTINATION "${CMAKECONFIG_INSTALL_DIR}" - FILE KPropertyTargets.cmake) + "${CMAKE_CURRENT_BINARY_DIR}/KPropertyCoreConfig.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/KPropertyCoreConfigVersion.cmake" + DESTINATION "${CMAKECONFIG_CORE_INSTALL_DIR}" + COMPONENT Devel) + +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 KPROPERTY + 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}) ecm_generate_pri_file( - BASE_NAME KProperty - LIB_NAME KProperty - DEPS "widgets" + BASE_NAME KPropertyCore + LIB_NAME KPropertyCore + DEPS "core" FILENAME_VAR PRI_FILENAME - INCLUDE_INSTALL_DIR ${INCLUDE_INSTALL_DIR}/KProperty + INCLUDE_INSTALL_DIR ${INCLUDE_INSTALL_DIR}/KPropertyCore ) - -install(FILES ${PRI_FILENAME} - DESTINATION ${ECM_MKSPECS_INSTALL_DIR}) + +if(KPROPERTY_WIDGETS) + ecm_generate_pri_file( + BASE_NAME KPropertyWidgets + LIB_NAME KPropertyWidgets + DEPS "" + FILENAME_VAR PRI_FILENAME + INCLUDE_INSTALL_DIR ${INCLUDE_INSTALL_DIR}/KPropertyWidgets + ) +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(kproperty_FORWARDING_HEADERS - REQUIRED_HEADERS kproperty_HEADERS +ecm_generate_headers(kpropertycore_FORWARDING_HEADERS + REQUIRED_HEADERS kpropertycore_HEADERS ORIGINAL CAMELCASE HEADER_NAMES - KPropertyFactory KProperty KPropertySet - KPropertyUtils KPropertyFactory - KPropertyEditorView - KPropertyEditorDataModel ) install( FILES - ${kproperty_HEADERS} - DESTINATION ${INCLUDE_INSTALL_DIR}/KProperty + ${kpropertycore_HEADERS} + DESTINATION ${INCLUDE_INSTALL_DIR}/KPropertyCore COMPONENT Devel ) install( FILES - ${kproperty_FORWARDING_HEADERS} - ${PROJECT_BINARY_DIR}/src/kproperty_export.h + ${kpropertycore_FORWARDING_HEADERS} + ${PROJECT_BINARY_DIR}/src/kpropertycore_export.h ${PROJECT_BINARY_DIR}/src/config-kproperty.h - DESTINATION ${INCLUDE_INSTALL_DIR}/KProperty + 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 + ${PROJECT_BINARY_DIR}/src/config-kproperty.h + DESTINATION ${INCLUDE_INSTALL_DIR}/KPropertyWidgets + COMPONENT Devel + ) +endif() + enable_testing() diff --git a/src/KDefaultPropertyFactory.cpp b/src/KDefaultPropertyFactory.cpp index 4a16a3c..a137a95 100644 --- a/src/KDefaultPropertyFactory.cpp +++ b/src/KDefaultPropertyFactory.cpp @@ -1,77 +1,78 @@ /* This file is part of the KDE project Copyright (C) 2008 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 "KPropertyWidgetsFactory.h" #include "KProperty.h" /* #include "customproperty.h"*/ #include "editors/booledit.h" #include "editors/combobox.h" #include "editors/coloredit.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/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" KDefaultPropertyFactory::KDefaultPropertyFactory() - : KPropertyFactory() + : KPropertyWidgetsFactory() { addEditor( KProperty::Bool, new KPropertyBoolDelegate ); addEditor( KProperty::Cursor, new KPropertyCursorDelegate ); addEditor( KProperty::Color, new KPropertyColorComboDelegate ); 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::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::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::ValueFromList, new KPropertyComboBoxDelegate ); } KDefaultPropertyFactory::~KDefaultPropertyFactory() { } diff --git a/src/KDefaultPropertyFactory.h b/src/KDefaultPropertyFactory.h index a923685..6e8e78e 100644 --- a/src/KDefaultPropertyFactory.h +++ b/src/KDefaultPropertyFactory.h @@ -1,32 +1,32 @@ /* This file is part of the KDE project Copyright (C) 2008 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 KDEFAULTPROPERTYFACTORY_H #define KDEFAULTPROPERTYFACTORY_H -#include "KPropertyFactory.h" +#include "KPropertyWidgetsFactory.h" -class KDefaultPropertyFactory : public KPropertyFactory +class KDefaultPropertyFactory : public KPropertyWidgetsFactory { public: KDefaultPropertyFactory(); ~KDefaultPropertyFactory(); }; #endif diff --git a/src/KProperty.cpp b/src/KProperty.cpp index f8f1cc2..c9f3e92 100644 --- a/src/KProperty.cpp +++ b/src/KProperty.cpp @@ -1,815 +1,820 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur Copyright (C) 2004 Alexander Dymo Copyright (C) 2004-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 "KProperty.h" #include "KProperty_p.h" #include "KPropertySet.h" #include "KPropertyFactory.h" #include "kproperty_debug.h" #include + +#ifdef KPROPERTY_WIDGET #include +#endif //! @internal class KProperty::Private { public: Private() : type(0), caption(0), listData(0), changed(false), storable(true), readOnly(false), visible(true), autosync(-1), composed(0), useComposedProperty(true), sets(0), parent(0), children(0), relatedProperties(0) { } inline void setCaptionForDisplaying(const QString& captionForDisplaying) { delete caption; if (captionForDisplaying.simplified() != captionForDisplaying) { if (captionForDisplaying.isEmpty()) { caption = 0; } else { caption = new QString(captionForDisplaying.simplified()); } } else { caption = 0; } this->captionForDisplaying = captionForDisplaying; } ~Private() { delete caption; caption = 0; delete listData; if (children) { qDeleteAll(*children); delete children; } delete relatedProperties; delete composed; delete sets; } int type; QByteArray name; QString captionForDisplaying; QString* caption; QString description; QVariant value; QVariant oldValue; /*! The string-to-value correspondence list of the property.*/ KPropertyListData* listData; QString icon; bool changed; bool storable; bool readOnly; bool visible; int autosync; QMap options; KComposedPropertyInterface *composed; //! Flag used to allow composed property to use setValue() without causing recursion bool useComposedProperty; //! Used when a single set is assigned for the property QPointer set; //! Used when multiple sets are assigned for the property QList< QPointer > *sets; KProperty *parent; QList *children; //! list of properties with the same name (when intersecting buffers) QList *relatedProperties; }; ///////////////////////////////////////////////////////////////// KPropertyListData::KPropertyListData(const QStringList& keys_, const QStringList& names_) : names(names_) { setKeysAsStringList(keys_); } KPropertyListData::KPropertyListData(const QList keys_, const QStringList& names_) : keys(keys_), names(names_) { } KPropertyListData::KPropertyListData() { } KPropertyListData::~KPropertyListData() { } void KPropertyListData::setKeysAsStringList(const QStringList& list) { keys.clear(); for (QStringList::ConstIterator it = list.constBegin(); it != list.constEnd(); ++it) { keys.append(*it); } } QStringList KPropertyListData::keysAsStringList() const { QStringList result; for (QList::ConstIterator it = keys.constBegin(); it != keys.constEnd(); ++it) { result.append((*it).toString()); } return result; } ///////////////////////////////////////////////////////////////// KProperty::KProperty(const QByteArray &name, const QVariant &value, const QString &caption, const QString &description, int type, KProperty* parent) : d(new KProperty::Private()) { d->name = name; d->setCaptionForDisplaying(caption); d->description = description; if (type == (int)Auto) d->type = value.type(); else d->type = type; d->composed = KPropertyFactoryManager::self()->createComposedProperty(this); if (parent) parent->addChild(this); setValue(value, false); } KProperty::KProperty(const QByteArray &name, const QStringList &keys, const QStringList &strings, const QVariant &value, const QString &caption, const QString &description, int type, KProperty* parent) : d(new KProperty::Private()) { d->name = name; d->setCaptionForDisplaying(caption); d->description = description; d->type = type; setListData(keys, strings); d->composed = KPropertyFactoryManager::self()->createComposedProperty(this); if (parent) parent->addChild(this); setValue(value, false); } KProperty::KProperty(const QByteArray &name, KPropertyListData* listData, const QVariant &value, const QString &caption, const QString &description, int type, KProperty* parent) : d(new KProperty::Private()) { d->name = name; d->setCaptionForDisplaying(caption); d->description = description; d->type = type; d->listData = listData; d->composed = KPropertyFactoryManager::self()->createComposedProperty(this); if (parent) parent->addChild(this); setValue(value, false); } KProperty::KProperty() : d(new KProperty::Private()) { } KProperty::KProperty(const KProperty &prop) : d(new KProperty::Private()) { *this = prop; } KProperty::~KProperty() { delete d; } QByteArray KProperty::name() const { return d->name; } void KProperty::setName(const QByteArray &name) { d->name = name; } QString KProperty::caption() const { return d->caption ? *d->caption : d->captionForDisplaying; } QString KProperty::captionForDisplaying() const { return d->captionForDisplaying; } void KProperty::setCaption(const QString &caption) { d->setCaptionForDisplaying(caption); } QString KProperty::description() const { return d->description; } void KProperty::setDescription(const QString &desc) { d->description = desc; } int KProperty::type() const { return d->type; } void KProperty::setType(int type) { d->type = type; } QString KProperty::icon() const { return d->icon; } void KProperty::setIcon(const QString &icon) { d->icon = icon; } QVariant KProperty::value() const { return d->value; } QVariant KProperty::oldValue() const { return d->oldValue; } void KProperty::childValueChanged(KProperty *child, const QVariant &value, bool rememberOldValue) { if (!d->composed) return; d->composed->childValueChangedInternal(child, value, rememberOldValue); } //! @return true if @a currentValue and @a value are compatible static bool compatibleTypes(const QVariant& currentValue, const QVariant &value) { if (currentValue.isNull() || value.isNull()) return true; const QVariant::Type t = currentValue.type(); const QVariant::Type newt = value.type(); if (t == newt) return true; if ( (t == QVariant::Int && newt == QVariant::UInt) || (t == QVariant::UInt && newt == QVariant::Int) || (t == QVariant::ByteArray && newt == QVariant::String) || (t == QVariant::String && newt == QVariant::ByteArray) || (t == QVariant::ULongLong && newt == QVariant::LongLong) || (t == QVariant::LongLong && newt == QVariant::ULongLong)) { return true; } return false; } void KProperty::setValue(const QVariant &value, bool rememberOldValue, bool useComposedProperty) { if (d->name.isEmpty()) { kprWarning() << "COULD NOT SET value to a null property"; return; } QVariant currentValue = this->value(); if (!compatibleTypes(currentValue, value)) { kprWarning() << "INCOMPATIBLE TYPES! old=" << currentValue << "new=" << value; } //1. Check if the value should be changed bool ch; const QVariant::Type t = currentValue.type(); const QVariant::Type newt = value.type(); if ( t == QVariant::DateTime || t == QVariant::Time) { //for date and datetime types: compare with strings, because there //can be miliseconds difference ch = (currentValue.toString() != value.toString()); } else if (t == QVariant::String || t == QVariant::ByteArray) { //property is changed for string type, //if one of value is empty and other isn't.. ch = ((currentValue.toString().isEmpty() != value.toString().isEmpty()) //..or both are not empty and values differ || (!currentValue.toString().isEmpty() && !value.toString().isEmpty() && currentValue != value)); } else if (t == QVariant::Double) { const double factor = 1.0 / option("step", KPROPERTY_DEFAULT_DOUBLE_VALUE_STEP).toDouble(); //kprDebug() // << "double compared:" << currentValue.toDouble() << value.toDouble() // << ":" << static_cast(currentValue.toDouble() * factor) << static_cast(value.toDouble() * factor); ch = static_cast(currentValue.toDouble() * factor) != static_cast(value.toDouble() * factor); } else if (t == QVariant::Invalid && newt == QVariant::Invalid) { ch = false; +#ifdef KPROPERTY_WIDGET } else if (t == QVariant::SizePolicy) { ch = (currentValue.value() != value.value()); +#endif } else { ch = (currentValue != value); } if (!ch) return; //2. Then change it, and store old value if necessary if (rememberOldValue) { if (!d->changed) d->oldValue = currentValue; d->changed = true; } else { d->oldValue = QVariant(); // clear old value d->changed = false; } if (d->parent) { d->parent->childValueChanged(this, value, rememberOldValue); } QVariant prevValue; if (d->composed && useComposedProperty) { prevValue = currentValue; //??? d->composed->setChildValueChangedEnabled(false); d->composed->setValue(this, value, rememberOldValue); d->composed->setChildValueChangedEnabled(true); } else { prevValue = currentValue; } d->value = value; if (!d->parent) { // emit only if parent has not done it emitPropertyChanged(); // called as last step in this method! } } void KProperty::resetValue() { d->changed = false; bool cleared = false; if (d->set) d->set->informAboutClearing(cleared); //inform me about possibly clearing the property sets setValue(oldValue(), false); if (cleared) return; //property set has been cleared: no further actions make sense as 'this' is dead // maybe parent prop is also unchanged now if (d->parent && d->parent->value() == d->parent->oldValue()) d->parent->d->changed = false; if (d->sets) { foreach (QPointer set, *d->sets) { if (!set.isNull()) //may be destroyed in the meantime emit set->propertyReset(*set, *this); } } else if (d->set) { emit d->set->propertyReset(*d->set, *this); } } KPropertyListData* KProperty::listData() const { return d->listData; } void KProperty::setListData(KPropertyListData* list) { if (list == d->listData) return; delete d->listData; d->listData = list; } void KProperty::setListData(const QStringList &keys, const QStringList &names) { KPropertyListData* list = new KPropertyListData(keys, names); setListData(list); } //////////////////////////////////////////////////////////////// bool KProperty::isNull() const { return d->name.isEmpty(); } bool KProperty::isModified() const { return d->changed; } void KProperty::clearModifiedFlag() { d->changed = false; } bool KProperty::isReadOnly() const { return d->readOnly; } void KProperty::setReadOnly(bool readOnly) { d->readOnly = readOnly; } bool KProperty::isVisible() const { return d->visible; } void KProperty::setVisible(bool visible) { d->visible = visible; } int KProperty::autoSync() const { return d->autosync; } void KProperty::setAutoSync(int sync) { d->autosync = sync; } bool KProperty::isStorable() const { return d->storable; } void KProperty::setStorable(bool storable) { d->storable = storable; } void KProperty::setOption(const char* name, const QVariant& val) { d->options[name] = val; } QVariant KProperty::option(const char* name, const QVariant& defaultValue) const { if (d->options.contains(name)) return d->options[name]; return defaultValue; } bool KProperty::hasOptions() const { return !d->options.isEmpty(); } ///////////////////////////////////////////////////////////////// const KProperty& KProperty::operator= (const QVariant & val) { setValue(val); return *this; } const KProperty& KProperty::operator= (const KProperty & property) { if (&property == this) return *this; delete d->listData; d->listData = 0; delete d->children; d->children = 0; delete d->relatedProperties; d->relatedProperties = 0; delete d->composed; d->composed = 0; d->name = property.d->name; d->setCaptionForDisplaying(property.captionForDisplaying()); d->description = property.d->description; d->type = property.d->type; d->icon = property.d->icon; d->autosync = property.d->autosync; d->visible = property.d->visible; d->storable = property.d->storable; d->readOnly = property.d->readOnly; d->options = property.d->options; if (property.d->listData) { d->listData = new KPropertyListData(*property.d->listData); } if (property.d->composed) { delete d->composed; d->composed = KPropertyFactoryManager::self()->createComposedProperty(this); // updates all children value, using KComposedPropertyInterface setValue(property.value()); } else { d->value = property.d->value; if (property.d->children) { // no KComposedPropertyInterface (should never happen), simply copy all children d->children = new QList(); QList::ConstIterator endIt = property.d->children->constEnd(); for (QList::ConstIterator it = property.d->children->constBegin(); it != endIt; ++it) { KProperty *child = new KProperty(*(*it)); addChild(child); } } } if (property.d->relatedProperties) { d->relatedProperties = new QList(*(property.d->relatedProperties)); } // update these later because they may have been changed when creating children d->oldValue = property.d->oldValue; d->changed = property.d->changed; return *this; } bool KProperty::operator ==(const KProperty &prop) const { return ((d->name == prop.d->name) && (value() == prop.value())); } ///////////////////////////////////////////////////////////////// const QList* KProperty::children() const { return d->children; } KProperty* KProperty::child(const QByteArray &name) { QList::ConstIterator endIt = d->children->constEnd(); for (QList::ConstIterator it = d->children->constBegin(); it != endIt; ++it) { if ((*it)->name() == name) return *it; } return 0; } KProperty* KProperty::parent() const { return d->parent; } void KProperty::addChild(KProperty *prop) { if (!prop) return; if (!d->children || qFind(d->children->begin(), d->children->end(), prop) == d->children->end()) { // not in our list if (!d->children) d->children = new QList(); d->children->append(prop); prop->d->parent = this; } else { kprWarning() << "property" << name() << ": child property" << prop->name() << "already added"; return; } } void KProperty::addSet(KPropertySet *set) { if (!set) return; if (!d->set) {//simple case d->set = set; return; } if (d->set == set || d->sets->contains(set)) return; if (!d->sets) { d->sets = new QList< QPointer >; } d->sets->append(QPointer(set)); } const QList* KProperty::related() const { return d->relatedProperties; } void KProperty::addRelatedProperty(KProperty *property) { if (!d->relatedProperties) d->relatedProperties = new QList(); QList::iterator it = qFind(d->relatedProperties->begin(), d->relatedProperties->end(), property); if (it == d->relatedProperties->end()) // not in our list d->relatedProperties->append(property); } KComposedPropertyInterface* KProperty::composedProperty() const { return d->composed; } void KProperty::setComposedProperty(KComposedPropertyInterface *prop) { if (d->composed == prop) return; delete d->composed; d->composed = prop; } #if 0 int Property::sortingKey() const { return d->sortingKey; } void Property::setSortingKey(int key) { d->sortingKey = key; } #endif void KProperty::emitPropertyChanged() { QList< QPointer > *sets = 0; if (d->sets) { sets = d->sets; } else if (d->parent) { sets = d->parent->d->sets; } if (sets) { foreach (QPointer s, *sets) { if (!s.isNull()) { //may be destroyed in the meantime emit s->propertyChangedInternal(*s, *this); emit s->propertyChanged(*s, *this); } } } else { QPointer set; set = d->set; if (d->set) { set = d->set; } else if (d->parent) { set = d->parent->d->set; } if (!set.isNull()) { //if the slot connect with that signal may call set->clear() - that's //the case e.g. at kexi/plugins/{macros|scripting}/* - this Property //may got destroyed ( see Set::removeProperty(Property*) ) while we are //still on it. So, if we try to access ourself/this once the signal //got emitted we may end in a very hard to reproduce crash. So, the //emit should happen as last step in this method! emit set->propertyChangedInternal(*set, *this); emit set->propertyChanged(*set, *this); } } } QMap KProperty::options() const { return d->options; } ///////////////////////////////////////////////////////////////// void KProperty::debug() const { kprDebug() << *this; } -KPROPERTY_EXPORT QDebug operator<<(QDebug dbg, const KProperty &p) +KPROPERTYCORE_EXPORT QDebug operator<<(QDebug dbg, const KProperty &p) { dbg.nospace() << "KProperty(" << "NAME=" << p.name(); if (!p.caption().isEmpty()) { dbg.nospace() << " CAPTION=" << p.caption(); } if (!p.description().isEmpty()) { dbg.nospace() << " DESC=" << p.description(); } dbg.nospace() << " TYPE=" << p.type(); if (p.value().isValid()) { dbg.nospace() << " VALUE=" << p.value(); } else { dbg.nospace() << " VALUE="; } if (p.oldValue().isValid()) { dbg.nospace() << " OLDVALUE=" << p.oldValue(); } if (p.isModified()) { dbg.nospace() << " MODIFIED"; } if (!p.isVisible()) { dbg.nospace() << " HIDDEN"; } //! @todo children... if (p.hasOptions()) { dbg.nospace() << " OPTIONS(" << p.options().count() << "): ["; QList optionKeys( p.options().keys() ); qSort(optionKeys); bool first = true; foreach (const QByteArray& key, optionKeys) { if (first) { first = false; } else { dbg.space() << ","; } dbg.nospace() << key << ":" << p.option(key.constData()); } dbg.nospace() << "]"; } dbg.nospace() << ")"; return dbg.space(); } diff --git a/src/KProperty.h b/src/KProperty.h index 2ed73c3..74eda1d 100644 --- a/src/KProperty.h +++ b/src/KProperty.h @@ -1,450 +1,450 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur Copyright (C) 2004 Alexander Dymo Copyright (C) 2004-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_PROPERTY_H #define KPROPERTY_PROPERTY_H #include #include #include #include -#include "kproperty_export.h" +#include "kpropertycore_export.h" /*! \brief Namespace for a set of classes implementing generic properties framework. Main classes of this framework are: - Property, representing a single property with its own type and value - Set, a set of properties - Editor, a widget for displaying and editing properties provided by a Set object. Every property has its own row displayed using EditorItem object, within Editor widget. Widget class provides editing feature for EditorItem objects if a user selects a given item. KProperty framework also supports adding composed and property types and custom property editor types. Take a look at the test application, available in the test/ directory to see example uses of the framework. @author Cedric Pasteur @author Alexander Dymo @author Jarosław Staniek */ class KComposedPropertyInterface; class KPropertySet; /*! Data container for properties of list type. */ -class KPROPERTY_EXPORT KPropertyListData +class KPROPERTYCORE_EXPORT KPropertyListData { public: /*! Data container for list-value property. We will be able to choose an item from this list. */ KPropertyListData(const QStringList& keys_, const QStringList& names_); KPropertyListData(const QList keys_, const QStringList& names_); KPropertyListData(); ~KPropertyListData(); void setKeysAsStringList(const QStringList& list); QStringList keysAsStringList() const; /*! The string list containing all possible keys for this property or NULL if this is not a property of type 'list'. The values in this list are ordered, so the first key element is associated with first element from the 'names' list, and so on. */ QList keys; // QStringList keys; //! @todo what about using QValueList here too? /*! The list of translated names that will be visible on the screen. First value is referenced by first key, and so on. */ QStringList names; //unused for now /*! True (the default), if the list has fixed number of possible //unused for now items (keys). If this is false, user can add or enter own values. */ //unused for now bool fixed; }; /*! \brief The base class representing a single property It can hold a property of any type supported by QVariant. You can also create you own property types (see Using Custom Properties in Factory doc). As a consequence, do not subclass Property, use \ref KComposedPropertyInterface instead. \n Each property stores old value to allow undo. It has a name (a QByteArray), a caption (user-visible translated name shown in Editor) and a description (also translated). \n It also supports setting arbitrary number of options (of type option=value). See Editor for a list of options, and their meaning. \code // To create a property property = Property(name, value, caption, description); // name is a QByteArray, // value is whatever type QVariant supports // To create a valueFromList property (matching strings with strings) QStringList keys, strings; keys << "one" << "two" << "three"; // possible values of the property // Strings (possibly translated) shown in the editor instead of the values strings << tr("One") << tr("Two") << tr("Three"); property = Property(name, keys, strings, "two", caption); // To create a valueFromList property (matching strings with QVariant) QValueList keys2; keys2.append(1); keys2.append(2); keys2.append(3); Property::ListData listData(keys2, strings); m_set->addProperty(new Property("List2", listData, "otheritem", "List2"), group); \endcode Note that you need to use QVariant(bool, int) to create a boolean property value. See QVariant docs for more details. Sometimes, for longer property captions or these with more words, e.g. "Allow Zero Size", its usable to provide newline characters, e.g. "Allow Zero\nSize". If caption argument of the constructors contains newline characters, caption() will return this text with substituted these characters with spaces. In such cases, captionForDisplaying() is used to get the original caption text usable (with newline, if any) for displaying within a property editor. \author Cedric Pasteur \author Alexander Dymo \author Jarosław Staniek */ -class KPROPERTY_EXPORT KProperty +class KPROPERTYCORE_EXPORT KProperty { public: /*! Defines types of properties. Properties defined by plugins should have a type number >= UserDefined .*/ enum Type { //standard supported QVariant types Auto = 0x00ffffff, Invalid = QVariant::Invalid, BitArray = QVariant::BitArray, Bitmap = QVariant::Bitmap, Bool = QVariant::Bool, Brush = QVariant::Brush, ByteArray = QVariant::ByteArray, Char = QVariant::Char, Color = QVariant::Color, Cursor = QVariant::Cursor, Date = QVariant::Date, DateTime = QVariant::DateTime, Double = QVariant::Double, Font = QVariant::Font, Icon = QVariant::Icon, Image = QVariant::Image, Int = QVariant::Int, KeySequence = QVariant::KeySequence, Line = QVariant::Line, LineF = QVariant::LineF, List = QVariant::List, Locale = QVariant::Locale, LongLong = QVariant::LongLong, Map = QVariant::Map, Matrix = QVariant::Matrix, Transform = QVariant::Transform, Palette = QVariant::Palette, Pen = QVariant::Pen, Pixmap = QVariant::Pixmap, Point = QVariant::Point, PointF = QVariant::PointF, Polygon = QVariant::Polygon, Rect = QVariant::Rect, RectF = QVariant::RectF, RegExp = QVariant::RegExp, Region = QVariant::Region, Size = QVariant::Size, SizeF = QVariant::SizeF, SizePolicy = QVariant::SizePolicy, String = QVariant::String, StringList = QVariant::StringList, TextFormat = QVariant::TextFormat, TextLength = QVariant::TextLength, Time = QVariant::Time, UInt = QVariant::UInt, ULongLong = QVariant::ULongLong, Url = QVariant::Url, //predefined custom types ValueFromList = 1000 /*** children() const; /*! \return a child property for \a name, or NULL if there is no property with that name. */ KProperty* child(const QByteArray &name); /*! \return parent property for this property, or NULL if there is no parent property. */ KProperty* parent() const; /*! \return the composed property for this property, or NULL if there was no composed property defined. */ KComposedPropertyInterface* composedProperty() const; /*! Sets composed property \a prop for this property. */ void setComposedProperty(KComposedPropertyInterface *prop); /*! \return true if this property is null. Null properties have empty names. */ bool isNull() const; //! \return true if this property value is changed. bool isModified() const; //! Clears "modified" flag, so isModified() will return false. void clearModifiedFlag(); /*! \return true if the property is read-only. The property can be read-write but still not editable because the property set containing it may be set to read-only. By default the property is read-write. See Set::isReadOnly() for more details. */ bool isReadOnly() const; /*! Sets this property to be read-only. @see isReadOnly() */ void setReadOnly(bool readOnly); /*! \return true if the property is visible.*/ bool isVisible() const; /*! Set the visibility.*/ void setVisible(bool visible); /*! \return true if the property can be saved to a stream, xml, etc. There is a possibility to use "GUI" properties that aren't stored but used only in a GUI.*/ bool isStorable() const; /*! Sets "storable" flag for this property. @see isStorable() */ void setStorable(bool storable); /*! \return 1 if the property should be synced automatically in Property Editor as soon as editor contents change (e.g. when the user types text). If autoSync() == 0, property value will be updated when the user presses Enter or when another editor gets the focus. Property follows Property Editor's global rule if autoSync() !=0 and !=1 (the default). */ int autoSync() const; /*! if \a sync is 1, the property will be synced automatically in the Property Editor as soon as editor's contents change (e.g. when the user types text). If \a sync is 0, property value will be updated when the user presses Enter or when another editor gets the focus. Property follows Property Editor's global rule if sync !=0 and !=1 (the default). */ void setAutoSync(int sync); /*! Sets value \a val for option \a name. Options are used to describe additional details for property behaviour, e.g. within Editor. See Editor ctor documentation for the list of supported options. */ void setOption(const char* name, const QVariant& val); /*! \return a value for option \a name or null value if there is no such option set. If there is no such value, @a defaultValue is returned. */ QVariant option(const char* name, const QVariant& defaultValue = QVariant()) const; /*! \return true if at least one option is defined for this property. */ bool hasOptions() const; /*! Equivalent to setValue(const QVariant &) */ const KProperty& operator= (const QVariant& val); /*! Assigns a deep copy of all attributes of \a property to this property. */ const KProperty& operator= (const KProperty &property); /*! Compares two properties.*/ bool operator ==(const KProperty &prop) const; #if 0 /*! \return a key used for sorting. Usually its set by Set::addProperty() and Property::addChild() to a unique value, so that this property can be sorted in a property editor in original order. \see EditorItem::compare() */ int sortingKey() const; #endif protected: /*! Adds \a prop as a child of this property. The children will be owned by this property. */ void addChild(KProperty *prop); /*! Adds \a set to this property. */ void addSet(KPropertySet *set); #if 0 /*! Sets a key used for sorting. */ void setSortingKey(int key); #endif /*! \return a list of related properties for this property. */ const QList* related() const; /*! Adds related property for this property. */ void addRelatedProperty(KProperty *property); /*! This method emits the \a Set::propertyChanged() signal for all sets this property is registered in. The \a value() method above calls this method of the value changed. */ void emitPropertyChanged(); /*! Outputs debug string for this property. */ void debug() const; /*! For operator <<. */ QMap options() const; //! @internal class Private; friend class Private; Private * const d; friend class KPropertySet; friend class KPropertyBuffer; friend class KComposedPropertyInterface; - friend KPROPERTY_EXPORT QDebug operator<<(QDebug dbg, const KProperty &p); + friend KPROPERTYCORE_EXPORT QDebug operator<<(QDebug dbg, const KProperty &p); }; //! qDebug() stream operator. Writes property @a p to the debug output in a nicely formatted way. -KPROPERTY_EXPORT QDebug operator<<(QDebug dbg, const KProperty &p); +KPROPERTYCORE_EXPORT QDebug operator<<(QDebug dbg, const KProperty &p); #endif diff --git a/src/KPropertyConfig.cmake.in b/src/KPropertyCoreConfig.cmake.in similarity index 86% copy from src/KPropertyConfig.cmake.in copy to src/KPropertyCoreConfig.cmake.in index f979003..5f1f402 100644 --- a/src/KPropertyConfig.cmake.in +++ b/src/KPropertyCoreConfig.cmake.in @@ -1,22 +1,21 @@ # KPropertyConfig.cmake provides information about the installed KProperty library. # It can be used directly from CMake via find_package(KProperty NO_MODULE) # # The following CMake variables are provided: # KProperty_VERSION_MAJOR - the major version number of KProperty # KProperty_VERSION_MINOR - the minor version number of KProperty # KProperty_VERSION_PATCH - the patch version number of KProperty # KProperty_INCLUDE_DIRS - the include directories to use # # Additionally, the following imported library targets are created, which may be used directly # with target_link_libraries(): # KProperty - the KProperty library @PACKAGE_INIT@ find_dependency(Qt5Core @REQUIRED_QT_VERSION@) -find_dependency(Qt5Widgets @REQUIRED_QT_VERSION@) -include("${CMAKE_CURRENT_LIST_DIR}/KPropertyTargets.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/KPropertyCoreTargets.cmake") # "public" variables: # TODO diff --git a/src/KPropertyEditorDataModel.cpp b/src/KPropertyEditorDataModel.cpp index 7d128ca..69b3836 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 "KPropertyFactory.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 KPropertyFactoryManager::self()->convertValueToText(prop); + return KPropertyWidgetsFactoryManager::self()->convertValueToText(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/KPropertyEditorDataModel.h b/src/KPropertyEditorDataModel.h index c87f30a..a958f70 100644 --- a/src/KPropertyEditorDataModel.h +++ b/src/KPropertyEditorDataModel.h @@ -1,96 +1,97 @@ /* This file is part of the KDE project Copyright (C) 2008 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_EDITORDATAMODEL_H #define KPROPERTY_EDITORDATAMODEL_H +#include "kpropertywidgets_export.h" +#include "KPropertySet.h" + #include #include -#include "KPropertySet.h" - class KProperty; /*! @short A data model for using Set objects within the Qt's model/view API. @see KPropertyEditorView */ -class KPROPERTY_EXPORT KPropertyEditorDataModel : public QAbstractItemModel +class KPROPERTYWIDGETS_EXPORT KPropertyEditorDataModel : public QAbstractItemModel { Q_OBJECT public: explicit KPropertyEditorDataModel(KPropertySet &propertySet, QObject *parent = 0, KPropertySetIterator::Order order = KPropertySetIterator::InsertionOrder); ~KPropertyEditorDataModel(); enum Role { PropertyModifiedRole = Qt::UserRole + 0 }; QVariant data(const QModelIndex &index, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; QModelIndex parent(const QModelIndex &index) const; int rowCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const; Qt::ItemFlags flags(const QModelIndex &index) const; bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole); QModelIndex buddy(const QModelIndex & index) const; //! @return property set object for this model. KPropertySet& propertySet() const; //! @return property object for model index @a index //! or 0 for invalid index or index without property assigned. KProperty *propertyForItem(const QModelIndex& index) const; //! @return model index for property named @a propertyName //! or invalid index if such property could not be found. QModelIndex indexForPropertyName(const QByteArray& propertyName) const; //! @return a sibling for model index @a index and columnd @a column QModelIndex indexForColumn(const QModelIndex& index, int column) const; //! Sets order for properties. Restarts the iterator. void setOrder(KPropertySetIterator::Order order); //! @return order for properties. KPropertySetIterator::Order order() const; //! Reimplemented for optimization. bool hasChildren(const QModelIndex & parent = QModelIndex()) const; private: void collectIndices() const; class Private; Private * const d; friend class KPropertyEditorView; }; #endif diff --git a/src/KPropertyEditorView.cpp b/src/KPropertyEditorView.cpp index 2b3067c..a43bfa7 100644 --- a/src/KPropertyEditorView.cpp +++ b/src/KPropertyEditorView.cpp @@ -1,581 +1,581 @@ /* 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 "KPropertyFactory.h" +#include "KPropertyWidgetsFactory.h" #include "kproperty_debug.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); 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) : 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); 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 && KPropertyFactoryManager::self()->paint(t, painter, alteredOption, index)) { + 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); //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); alteredOption.rect.setHeight(alteredOption.rect.height()+3); - QWidget *w = KPropertyFactoryManager::self()->createEditor(t, parent, alteredOption, index); + QWidget *w = KPropertyWidgetsFactoryManager::self()->createEditor(t, 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; } 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 6a9bf89..7d7f17e 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 "kproperty_export.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 KPROPERTY_EXPORT KPropertyEditorView : public QTreeView +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 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 e1c12ea..ec1f4c9 100644 --- a/src/KPropertyFactory.cpp +++ b/src/KPropertyFactory.cpp @@ -1,446 +1,206 @@ /* This file is part of the KDE project Copyright (C) 2008 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" - -KPropertyLabel::KPropertyLabel(QWidget *parent, const KPropertyValueDisplayInterface *iface) - : QLabel(parent) - , m_iface(iface) -{ - setAutoFillBackground(true); - setContentsMargins(0,1,0,0); - setIndent(1); -} - -QVariant KPropertyLabel::value() const -{ - return m_value; -} - -void KPropertyLabel::setValue(const QVariant& value) -{ - setText( m_iface->displayText(value) ); - m_value = value; -} - -void KPropertyLabel::paintEvent( QPaintEvent * event ) -{ - QLabel::paintEvent(event); - KPropertyFactory::paintTopGridLine(this); -} //--------------- //! @internal class KPropertyFactoryManager::Private { public: Private() { } ~Private() { qDeleteAll(factories); } QSet factories; QHash composedPropertyCreators; - QHash editorCreators; - QHash valuePainters; - QHash valueDisplays; }; Q_GLOBAL_STATIC(KPropertyFactoryManager, _self) //! @internal class KPropertyFactory::Private { public: Private() { } ~Private() { - qDeleteAll(editorCreatorsSet); - qDeleteAll(valuePaintersSet); - qDeleteAll(valueDisplaysSet); } QHash composedPropertyCreators; - QHash editorCreators; - QHash valuePainters; - QHash valueDisplays; QSet composedPropertyCreatorsSet; - QSet editorCreatorsSet; - QSet valuePaintersSet; - QSet valueDisplaysSet; }; KPropertyFactory::KPropertyFactory() : d( new Private ) { } KPropertyFactory::~KPropertyFactory() { delete d; } QHash KPropertyFactory::composedPropertyCreators() const { return d->composedPropertyCreators; } +#ifdef KPROPERTY_WIDGET QHash KPropertyFactory::editorCreators() const { return d->editorCreators; } QHash KPropertyFactory::valuePainters() const { return d->valuePainters; } QHash KPropertyFactory::valueDisplays() const { return d->valueDisplays; } void KPropertyFactory::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*/ ); } } +#endif void KPropertyFactory::addComposedPropertyCreator( int type, KComposedPropertyCreatorInterface* creator ) { addComposedPropertyCreatorInternal( type, creator, true ); - if (dynamic_cast(creator)) { - addEditorInternal( 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 KPropertyFactory::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 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)) { - addEditorInternal( type, dynamic_cast(display), false/* !own*/ ); - } - if (dynamic_cast(display)) { - addDisplayInternal( type, dynamic_cast(display), false/* !own*/ ); - } -} - -void KPropertyFactory::addEditorInternal(int type, KPropertyEditorCreatorInterface *editor, bool own) -{ - if (own) - d->editorCreatorsSet.insert(editor); - d->editorCreators.insert(type, editor); } void KPropertyFactory::addComposedPropertyCreatorInternal(int type, KComposedPropertyCreatorInterface* creator, bool own) { if (own) d->composedPropertyCreatorsSet.insert(creator); d->composedPropertyCreators.insert(type, creator); } -void KPropertyFactory::addPainterInternal(int type, KPropertyValuePainterInterface *painter, bool own) -{ - if (own) - d->valuePaintersSet.insert(painter); - d->valuePainters.insert(type, painter); -} - -void KPropertyFactory::addDisplayInternal(int type, KPropertyValueDisplayInterface *display, bool own) -{ - if (own) - d->valueDisplaysSet.insert(display); - d->valueDisplays.insert(type, display); -} - -//static -void KPropertyFactory::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); -} - -//static -void KPropertyFactory::setTopAndBottomBordersUsingStyleSheet(QWidget *widget, QWidget* parent, const QString& extraStyleSheet) -{ - QColor gridLineColor( dynamic_cast(parent) ? - dynamic_cast(parent)->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)); -} - //------------ KPropertyFactoryManager::KPropertyFactoryManager() : QObject(0) , d(new Private) { setObjectName(QLatin1String("KPropertyFactoryManager")); - registerFactory(new KDefaultPropertyFactory); + //TODO ??? registerFactory(new KDefaultPropertyFactory); + } KPropertyFactoryManager::~KPropertyFactoryManager() { delete d; } KPropertyFactoryManager* KPropertyFactoryManager::self() { 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 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 KPropertyFactoryManager::isEditorForTypeAvailable( int type ) const -{ - return d->editorCreators.value(type); -} - -QWidget * KPropertyFactoryManager::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() ); - 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 KPropertyFactoryManager::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 KPropertyFactoryManager::canConvertValueToText( int type ) const -{ - return d->valueDisplays.value(type) != 0; -} - -bool KPropertyFactoryManager::canConvertValueToText( const KProperty* property ) const -{ - return d->valueDisplays.value( property->type() ) != 0; -} - -QString KPropertyFactoryManager::convertValueToText( const KProperty* property ) const -{ - const KPropertyValueDisplayInterface *display = d->valueDisplays.value( property->type() ); - return display ? display->displayTextForProperty( property ) : property->value().toString(); } KComposedPropertyInterface* KPropertyFactoryManager::createComposedProperty(KProperty *parent) { const KComposedPropertyCreatorInterface *creator = d->composedPropertyCreators.value( parent->type() ); return creator ? creator->createComposedProperty(parent) : 0; } //! @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() { } - -KPropertyEditorCreatorInterface::KPropertyEditorCreatorInterface() -{ -} - -KPropertyEditorCreatorInterface::~KPropertyEditorCreatorInterface() -{ -} - -KPropertyEditorCreatorInterface::Options::Options() - : removeBorders(true) -{ -} - -KPropertyValuePainterInterface::KPropertyValuePainterInterface() -{ -} - -KPropertyValuePainterInterface::~KPropertyValuePainterInterface() -{ -} - -KPropertyValueDisplayInterface::KPropertyValueDisplayInterface() -{ -} - -KPropertyValueDisplayInterface::~KPropertyValueDisplayInterface() -{ -} diff --git a/src/KPropertyFactory.h b/src/KPropertyFactory.h index 2c9fbc7..8907d89 100644 --- a/src/KPropertyFactory.h +++ b/src/KPropertyFactory.h @@ -1,284 +1,133 @@ /* This file is part of the KDE project Copyright (C) 2008 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 -#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 KPROPERTY_EXPORT KComposedPropertyInterface +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; } 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 KPROPERTY_EXPORT KComposedPropertyCreatorInterface +class KPROPERTYCORE_EXPORT KComposedPropertyCreatorInterface { public: KComposedPropertyCreatorInterface(); virtual ~KComposedPropertyCreatorInterface(); virtual KComposedPropertyInterface* createComposedProperty(KProperty *parent) const = 0; }; -//! 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 KPROPERTY_EXPORT KPropertyEditorCreatorInterface -{ -public: - KPropertyEditorCreatorInterface(); - - virtual ~KPropertyEditorCreatorInterface(); - - virtual QWidget * createEditor( int type, QWidget *parent, - const QStyleOptionViewItem & option, const QModelIndex & index ) const = 0; - - /*! 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 KPROPERTY_EXPORT KPropertyValuePainterInterface -{ -public: - KPropertyValuePainterInterface(); - virtual ~KPropertyValuePainterInterface(); - virtual void paint( QPainter * painter, - const QStyleOptionViewItem & option, const QModelIndex & index ) const = 0; -}; - -class KPROPERTY_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. -class KPROPERTY_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; -}; - -//! Creator returning editor -template -class KPROPERTY_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 - { - 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(); - } -}; - -typedef KPropertyEditorCreator KPropertyLabelCreator; - //! Creator returning composed property object template -class KPROPERTY_EXPORT KComposedPropertyCreator : public KComposedPropertyCreatorInterface +class KPROPERTYCORE_EXPORT KComposedPropertyCreator : public KComposedPropertyCreatorInterface { public: KComposedPropertyCreator() : KComposedPropertyCreatorInterface() {} virtual ~KComposedPropertyCreator() {} virtual ComposedProperty* createComposedProperty(KProperty *parent) const { return new ComposedProperty(parent); } }; -class KPROPERTY_EXPORT KPropertyFactory +class KPROPERTYCORE_EXPORT KPropertyFactory { public: KPropertyFactory(); virtual ~KPropertyFactory(); QHash composedPropertyCreators() const; - 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 addComposedPropertyCreator( int type, KComposedPropertyCreatorInterface* 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()); - protected: - void addEditorInternal(int type, KPropertyEditorCreatorInterface *editor, bool own = true); - void addComposedPropertyCreatorInternal(int type, KComposedPropertyCreatorInterface* creator, 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 KPROPERTY_EXPORT KPropertyFactoryManager : public QObject +class KPROPERTYCORE_EXPORT KPropertyFactoryManager : public QObject { Q_OBJECT 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; - + KComposedPropertyInterface* createComposedProperty(KProperty *parent); - 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(KPropertyFactory *factory); KCustomProperty* createCustomProperty( KProperty *parent ); /*! \return a pointer to a factory manager instance.*/ static KPropertyFactoryManager* self(); KPropertyFactoryManager(); ~KPropertyFactoryManager(); private: class Private; Private * const d; }; #endif diff --git a/src/KPropertyLineStyleSelector_p.h b/src/KPropertyLineStyleSelector_p.h index e6bbedb..1f8325f 100644 --- a/src/KPropertyLineStyleSelector_p.h +++ b/src/KPropertyLineStyleSelector_p.h @@ -1,71 +1,71 @@ /* 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. */ #ifndef KPROPERTYLINESTYLESELECTOR_H #define KPROPERTYLINESTYLESELECTOR_H -#include "kproperty_export.h" +#include "kpropertywidgets_export.h" #include /** * A custom combobox widget for selecting line styles. */ -class KPROPERTY_EXPORT KPropertyLineStyleSelector : public QComboBox +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/KPropertySet.cpp b/src/KPropertySet.cpp index 8a5b373..3bbcfc0 100644 --- a/src/KPropertySet.cpp +++ b/src/KPropertySet.cpp @@ -1,734 +1,734 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur Copyright (C) 2004 Alexander Dymo Copyright (C) 2004-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 "KPropertySet.h" #include "kproperty_debug.h" #include //! @internal class KPropertySet::Private { public: explicit Private(KPropertySet *set) : q(set), readOnly(false), informAboutClearing(0), m_visiblePropertiesCount(0) {} ~Private() {} inline uint visiblePropertiesCount() const { return m_visiblePropertiesCount; } inline KProperty* property(const QByteArray &name) const { return hash.value(name.toLower()); } inline KProperty& propertyOrNull(const QByteArray &name) const { KProperty *p = property(name); if (p) return *p; nonConstNull.setName(0); //to ensure returned property is null kprWarning() << "PROPERTY" << name << "NOT FOUND"; return nonConstNull; } void addProperty(KProperty *property, QByteArray group/*, bool updateSortingKey*/) { if (!property) { kprWarning() << "property == 0"; return; } if (property->isNull()) { kprWarning() << "COULD NOT ADD NULL PROPERTY"; return; } if (group.isEmpty()) group = "common"; KProperty *p = this->property(property->name()); if (p) { q->addRelatedProperty(p, property); } else { list.append(property); hash.insert(property->name().toLower(), property); if (property->isVisible()) { m_visiblePropertiesCount++; } q->addToGroup(group, property); } property->addSet(q); #if 0 if (updateSortingKey) property->setSortingKey(count()); #endif } void removeProperty(KProperty *property) { if (!property) return; if (!list.removeOne(property)) { kprDebug() << "Set does not contain property" << property; return; } KProperty *p = hash.take(property->name()); q->removeFromGroup(p); if (p->isVisible()) { m_visiblePropertiesCount--; } if (ownProperty) { emit q->aboutToDeleteProperty(*q, *p); delete p; } } void clear() { if (informAboutClearing) *informAboutClearing = true; informAboutClearing = 0; emit q->aboutToBeCleared(); m_visiblePropertiesCount = 0; qDeleteAll(propertiesOfGroup); propertiesOfGroup.clear(); groupNames.clear(); groupForProperties.clear(); groupDescriptions.clear(); groupIcons.clear(); qDeleteAll(list); list.clear(); hash.clear(); } inline int count() const { return list.count(); } inline bool isEmpty() const { return list.isEmpty(); } inline QByteArray groupForProperty(KProperty *property) const { return groupForProperties.value(property); } inline void addPropertyToGroup(KProperty *property, const QByteArray &groupLower) { groupForProperties.insert(property, groupLower); } inline void removePropertyFromGroup(KProperty *property) { groupForProperties.remove(property); } // Copy all attributes except complex ones void copyAttributesFrom(const Private &other) { KPropertySet *origSet = q; *this = other; q = origSet; // do not copy too deeply list.clear(); hash.clear(); groupForProperties.clear(); m_visiblePropertiesCount = 0; } // Copy all properties from the other set void copyPropertiesFrom( const QList::ConstIterator& constBegin, const QList::ConstIterator& constEnd, const KPropertySet & set) { for (QList::ConstIterator it(constBegin); it!=constEnd; ++it) { KProperty *prop = new KProperty(*(*it)); addProperty(prop, set.groupForProperty( *it ) #if 0 , false /* don't updateSortingKey, because the key is already set in Property copy ctor.*/ #endif ); } } inline QList::ConstIterator listConstIterator() const { return list.constBegin(); } inline QList::ConstIterator listConstEnd() const { return list.constEnd(); } KPropertySet *q; //groups of properties: // list of group name: (list of property names) QMap* > propertiesOfGroup; QList groupNames; QHash groupDescriptions; QHash groupIcons; // map of property: group bool ownProperty; bool readOnly; QByteArray prevSelection; QString typeName; //! Used in Set::informAboutClearing(Property*) to declare that the property wants //! to be informed that the set has been cleared (all properties are deleted) bool* informAboutClearing; mutable KProperty nonConstNull; private: //! a list of properties, preserving their order, owner of Property objects QList list; //! a hash of properties in form name -> property QHash hash; QHash groupForProperties; uint m_visiblePropertiesCount; //! cache for optimization, //! used by @ref bool Set::hasVisibleProperties() }; ////////////////////////////////////////////// KPropertySelector::KPropertySelector() { } KPropertySelector::~KPropertySelector() { } ////////////////////////////////////////////// typedef QPair Iterator_PropertyAndString; static inline bool Iterator_propertyAndStringLessThan( const Iterator_PropertyAndString &n1, const Iterator_PropertyAndString &n2) { return QString::compare(n1.second, n2.second, Qt::CaseInsensitive) < 0; } ////////////////////////////////////////////// KPropertySetIterator::KPropertySetIterator(const KPropertySet &set) : m_set(&set) , m_iterator( set.d->listConstIterator() ) , m_end( set.d->listConstEnd() ) , m_selector( 0 ) , m_order(KPropertySetIterator::InsertionOrder) { } KPropertySetIterator::KPropertySetIterator(const KPropertySet &set, const KPropertySelector& selector) : m_set(&set) , m_iterator( set.d->listConstIterator() ) , m_end( set.d->listConstEnd() ) , m_selector( selector.clone() ) , m_order(KPropertySetIterator::InsertionOrder) { skipNotAcceptable(); } KPropertySetIterator::~KPropertySetIterator() { delete m_selector; } void KPropertySetIterator::skipNotAcceptable() { if (!m_selector) return; //kprDebug() << "FROM:" << *current(); if (current() && !(*m_selector)( *current() )) { // skip first items that not are acceptable by the selector ++(*this); } //kprDebug() << "TO:" << *current(); } void KPropertySetIterator::setOrder(KPropertySetIterator::Order order) { if (m_order == order) return; m_order = order; switch (m_order) { case KPropertySetIterator::AlphabeticalOrder: case KPropertySetIterator::AlphabeticalByName: { QList propertiesAndStrings; m_iterator = m_set->d->listConstIterator(); m_end = m_set->d->listConstEnd(); for (; m_iterator!=m_end; ++m_iterator) { KProperty *prop = *m_iterator; QString captionOrName; if (m_order == KPropertySetIterator::AlphabeticalOrder) { captionOrName = prop->caption(); } if (captionOrName.isEmpty()) { captionOrName = QLatin1String(prop->name()); } propertiesAndStrings.append( qMakePair(prop, captionOrName) ); } qSort(propertiesAndStrings.begin(), propertiesAndStrings.end(), Iterator_propertyAndStringLessThan); m_sorted.clear(); foreach (const Iterator_PropertyAndString& propertyAndString, propertiesAndStrings) { m_sorted.append(propertyAndString.first); } // restart the iterator m_iterator = m_sorted.constBegin(); m_end = m_sorted.constEnd(); break; } default: m_sorted.clear(); // restart the iterator m_iterator = m_set->d->listConstIterator(); m_end = m_set->d->listConstEnd(); } skipNotAcceptable(); } void KPropertySetIterator::operator ++() { while (true) { ++m_iterator; if (!m_selector) return; // selector exists if (!current()) // end encountered return; if ((*m_selector)( *current() )) return; } } ////////////////////////////////////////////// KPropertySet::KPropertySet(QObject *parent, const QString &typeName) : QObject(parent) , d(new KPropertySet::Private(this)) { setObjectName(typeName.toLower()); d->ownProperty = true; d->groupDescriptions.insert("common", tr("General", "General properties")); d->typeName = typeName.toLower(); } KPropertySet::KPropertySet(const KPropertySet &set) : QObject(0 /* implicit sharing the parent is dangerous */) , d(new KPropertySet::Private(this)) { setObjectName(set.objectName()); *this = set; } KPropertySet::KPropertySet(bool propertyOwner) : QObject(0) , d(new KPropertySet::Private(this)) { d->ownProperty = propertyOwner; d->groupDescriptions.insert("common", tr("General", "General properties")); } KPropertySet::~KPropertySet() { emit aboutToBeCleared(); emit aboutToBeDeleted(); clear(); delete d; } ///////////////////////////////////////////////////// void KPropertySet::addProperty(KProperty *property, QByteArray group) { d->addProperty(property, group); } void KPropertySet::removeProperty(KProperty *property) { d->removeProperty(property); } void KPropertySet::removeProperty(const QByteArray &name) { KProperty *p = d->property(name); removeProperty(p); } void KPropertySet::clear() { d->clear(); } void KPropertySet::informAboutClearing(bool& cleared) { cleared = false; d->informAboutClearing = &cleared; } ///////////////////////////////////////////////////// QByteArray KPropertySet::groupForProperty(KProperty *property) const { return d->groupForProperty(property); } void KPropertySet::addToGroup(const QByteArray &group, KProperty *property) { if (!property || group.isEmpty()) return; //do not add the same property to the group twice const QByteArray groupLower(group.toLower()); if (d->groupForProperty(property) == groupLower) { kprWarning() << "Group" << group << "already contains property" << property->name(); return; } QList* propertiesOfGroup = d->propertiesOfGroup.value(groupLower); if (!propertiesOfGroup) { propertiesOfGroup = new QList(); d->propertiesOfGroup.insert(groupLower, propertiesOfGroup); d->groupNames.append(groupLower); } propertiesOfGroup->append(property->name()); d->addPropertyToGroup(property, groupLower); } void KPropertySet::removeFromGroup(KProperty *property) { if (!property) return; const QByteArray group( d->groupForProperty(property) ); if (group.isEmpty()) return; QList* propertiesOfGroup = d->propertiesOfGroup[ group ]; if (propertiesOfGroup) { propertiesOfGroup->removeAt(propertiesOfGroup->indexOf(property->name())); } if (propertiesOfGroup->isEmpty()) { //remove group as well d->propertiesOfGroup.take(group); delete propertiesOfGroup; const int i = d->groupNames.indexOf(group); if (i != -1) d->groupNames.removeAt(i); } d->removePropertyFromGroup(property); } QList KPropertySet::groupNames() const { return d->groupNames; } QList KPropertySet::propertyNamesForGroup(const QByteArray &group) const { QList* propertiesOfGroup = d->propertiesOfGroup.value(group); return propertiesOfGroup ? *propertiesOfGroup : QList(); } void KPropertySet::setGroupDescription(const QByteArray &group, const QString desc) { d->groupDescriptions.insert(group.toLower(), desc); } QString KPropertySet::groupDescription(const QByteArray &group) const { const QString result( d->groupDescriptions.value(group.toLower()) ); if (!result.isEmpty()) return result; return QLatin1String(group); } void KPropertySet::setGroupIcon(const QByteArray &group, const QString& icon) { d->groupIcons.insert(group.toLower(), icon); } QString KPropertySet::groupIcon(const QByteArray &group) const { return d->groupIcons.value(group); } ///////////////////////////////////////////////////// uint KPropertySet::count() const { return d->count(); } uint KPropertySet::count(const KPropertySelector& selector) const { uint result = 0; for (KPropertySetIterator it(*this, selector); it.current(); ++it, result++) ; return result; } bool KPropertySet::isEmpty() const { return d->isEmpty(); } bool KPropertySet::hasVisibleProperties() const { return d->visiblePropertiesCount() > 0; } bool KPropertySet::hasProperties(const KPropertySelector& selector) const { KPropertySetIterator it(*this, selector); return it.current(); } bool KPropertySet::isReadOnly() const { return d->readOnly; } void KPropertySet::setReadOnly(bool readOnly) { d->readOnly = readOnly; } bool KPropertySet::contains(const QByteArray &name) const { return d->property(name); } KProperty& KPropertySet::property(const QByteArray &name) const { return d->propertyOrNull(name); } KProperty& KPropertySet::operator[](const QByteArray &name) const { return d->propertyOrNull(name); } const KPropertySet& KPropertySet::operator= (const KPropertySet & set) { if (&set == this) return *this; clear(); d->copyAttributesFrom(*set.d); d->copyPropertiesFrom(set.d->listConstIterator(), set.d->listConstEnd(), set); return *this; } QVariant KPropertySet::propertyValue(const QByteArray &name, const QVariant& defaultValue) const { const KProperty *p = d->property(name); return p ? p->value() : defaultValue; } void KPropertySet::changeProperty(const QByteArray &property, const QVariant &value) { KProperty *p = d->property(property); if (p) p->setValue(value); } void KPropertySet::debug() const { kprDebug() << *this; } -KPROPERTY_EXPORT QDebug operator<<(QDebug dbg, const KPropertySet &set) +KPROPERTYCORE_EXPORT QDebug operator<<(QDebug dbg, const KPropertySet &set) { dbg.nospace() << "KPropertySet("; if (!set.typeName().isEmpty()) { dbg.nospace() << "TYPENAME=" << set.typeName(); if (set.isEmpty()) { dbg.space() << ")"; return dbg.space(); } } if (set.isEmpty()) { dbg.space() << ")"; return dbg.space(); } dbg.nospace() << " PROPERTIES(" << set.count() << "):\n"; KPropertySetIterator it(set); it.setOrder(KPropertySetIterator::AlphabeticalByName); bool first = true; for ( ; it.current(); ++it) { if (first) { first = false; } else { dbg.nospace() << "\n"; } dbg.nospace() << *it.current(); } dbg.nospace() << "\n)"; return dbg.space(); } QByteArray KPropertySet::previousSelection() const { return d->prevSelection; } void KPropertySet::setPreviousSelection(const QByteArray &prevSelection) { d->prevSelection = prevSelection; } QString KPropertySet::typeName() const { return d->typeName; } void KPropertySet::addRelatedProperty(KProperty *p1, KProperty *p2) const { p1->addRelatedProperty(p2); } QMap KPropertySet::propertyValues() const { QMap result; for (KPropertySetIterator it(*this); it.current(); ++it) { result.insert(it.current()->name(), it.current()->value()); } return result; } ///////////////////////////////////////////////////// KPropertyBuffer::KPropertyBuffer() : KPropertySet(false) { connect(this, SIGNAL(propertyChanged(KPropertySet&,KProperty&)), this, SLOT(intersectedChanged(KPropertySet&,KProperty&))); connect(this, SIGNAL(propertyReset(KPropertySet&,KProperty&)), this, SLOT(intersectedReset(KPropertySet&,KProperty&))); } KPropertyBuffer::KPropertyBuffer(const KPropertySet& set) : KPropertySet(false) { connect(this, SIGNAL(propertyChanged(KPropertySet&,KProperty&)), this, SLOT(intersectedChanged(KPropertySet&,KProperty&))); connect(this, SIGNAL(propertyReset(KPropertySet&,KProperty&)), this, SLOT(intersectedReset(KPropertySet&,KProperty&))); init(set); } void KPropertyBuffer::init(const KPropertySet& set) { //deep copy of set const QList::ConstIterator itEnd(set.d->listConstEnd()); for (QList::ConstIterator it(set.d->listConstIterator()); it!=itEnd; ++it) { KProperty *prop = new KProperty(*(*it)); QByteArray group = set.groupForProperty(*it); QString groupDesc = set.groupDescription( group ); setGroupDescription(group, groupDesc); addProperty(prop, group); prop->addRelatedProperty(*it); } } void KPropertyBuffer::intersect(const KPropertySet& set) { if (isEmpty()) { init(set); return; } const QList::ConstIterator itEnd(set.d->listConstEnd()); for (QList::ConstIterator it(set.d->listConstIterator()); it!=itEnd; ++it) { const QByteArray key( (*it)->name() ); KProperty *property = set.d->property( key ); if (property) { blockSignals(true); (*it)->resetValue(); (*it)->addRelatedProperty(property); blockSignals(false); } else { removeProperty(key); } } } void KPropertyBuffer::intersectedChanged(KPropertySet& set, KProperty& prop) { Q_UNUSED(set); if (!contains(prop.name())) return; const QList *props = prop.related(); for (QList::ConstIterator it = props->constBegin(); it != props->constEnd(); ++it) { (*it)->setValue(prop.value(), false); } } void KPropertyBuffer::intersectedReset(KPropertySet& set, KProperty& prop) { Q_UNUSED(set); if (!contains(prop.name())) return; const QList *props = prop.related(); for (QList::ConstIterator it = props->constBegin(); it != props->constEnd(); ++it) { (*it)->setValue(prop.value(), false); } } diff --git a/src/KPropertySet.h b/src/KPropertySet.h index d70e85d..e2724d5 100644 --- a/src/KPropertySet.h +++ b/src/KPropertySet.h @@ -1,340 +1,340 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur Copyright (C) 2004 Alexander Dymo Copyright (C) 2004-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_SET_H #define KPROPERTY_SET_H #include #include #include #include "KProperty.h" //! An interface for functor selecting properties. /*! Used in Iterator. */ -class KPROPERTY_EXPORT KPropertySelector +class KPROPERTYCORE_EXPORT KPropertySelector { public: KPropertySelector(); virtual ~KPropertySelector(); //! An operator implementing the functor. virtual bool operator()(const KProperty& prop) const = 0; //! Creates a deep copy of the selector. //! Required for proper usage of the selector. virtual KPropertySelector* clone() const = 0; }; //! A class to iterate over a Set. /*! It behaves like a QList::ConstIterator. Usage: @code for (Set::Iterator it(set); it.current(); ++it) { .... } @endcode Usage with selector: @code for (Set::Iterator it(set, MySelector()); it.current(); ++it) { .... } @endcode */ -class KPROPERTY_EXPORT KPropertySetIterator +class KPROPERTYCORE_EXPORT KPropertySetIterator { public: //! Creates iterator for @a set set of properties. /*! The properties are sorted by insertion order by default. Use setOrder(Iterator::Alphabetical) to have alphabetical order. */ explicit KPropertySetIterator(const KPropertySet &set); //! Creates iterator for @a set set of properties. /*! @a selector functor is used to iterate only over specified properties. The properties are sorted by insertion order by default. Use setOrder(Iterator::Alphabetical) to have alphabetical order. */ KPropertySetIterator(const KPropertySet &set, const KPropertySelector& selector); ~KPropertySetIterator(); //! Ordering options for properties /*! @see setOrder() */ enum Order { InsertionOrder, //!< insertion order AlphabeticalOrder, //!< alphabetical order (case-insensitively by captions) AlphabeticalByName //!< alphabetical order (case-insensitively by name) }; //! Sets order for properties. Restarts the iterator. void setOrder(Order order); //! @return order for properties. Order order() const { return m_order; } void operator ++(); KProperty* operator *() const { return current(); } KProperty* current() const { return m_iterator==m_end ? 0 : *m_iterator; } friend class KPropertySet; private: void skipNotAcceptable(); const KPropertySet *m_set; QList::ConstIterator m_iterator; QList::ConstIterator m_end; KPropertySelector *m_selector; Order m_order; QList m_sorted; //!< for sorted order }; /*! \brief Set of properties \author Cedric Pasteur \author Alexander Dymo \author Jarosław Staniek */ -class KPROPERTY_EXPORT KPropertySet : public QObject +class KPROPERTYCORE_EXPORT KPropertySet : public QObject { Q_OBJECT public: //! Constructs a new Set object. //! @see typeName() explicit KPropertySet(QObject *parent = 0, const QString &typeName = QString()); /*! Constructs a deep copy of \a set. The new object will not have a QObject parent even if \a set has such parent. */ explicit KPropertySet(const KPropertySet& set); virtual ~KPropertySet(); /*! Adds the property to the set, in the group. You can use any group name, except "common" (which is already used for basic group). */ void addProperty(KProperty *property, QByteArray group = "common"); /*! Removes property from the set. Emits aboutToDeleteProperty before removing.*/ void removeProperty(KProperty *property); /*! Removes property with the given name from the set. Emits aboutToDeleteProperty() before removing.*/ void removeProperty(const QByteArray &name); /*! Removes all properties from the property set and destroys them. */ void clear(); /*! @return the number of top-level properties in the set. */ uint count() const; /*! @return the number of top-level properties in the set matching criteria defined by @a selector. */ uint count(const KPropertySelector& selector) const; /*! @return true if the set is empty, i.e. count() is 0; otherwise returns false. */ bool isEmpty() const; /*! @return true if the set is contains visible properties. */ bool hasVisibleProperties() const; /*! @return true if the set is contains properties matching criteria defined by @a selector. */ bool hasProperties(const KPropertySelector& selector) const; /*! \return true if the set is read-only. In read-only property set, no property can be modified regardless of read-only flag of any property (see Property::isReadOnly()). On the other hand, if Property::isReadOnly() is true of a property and Set::isReadOnly() is false, the property is still read-only. Read-only property set prevents editing in the property editor. By default the set is read-write. */ bool isReadOnly() const; /*! Sets this set to be read-only. @see isReadOnly */ void setReadOnly(bool readOnly); /*! \return true if the set contains property names \a name. */ bool contains(const QByteArray &name) const; /*! \return property named with \a name. If no such property is found, null property (Property::null) is returned. */ KProperty& property(const QByteArray &name) const; /*! Accesses a property by it's name. Property reference is returned, so all property modifications are allowed. If there is no such property, null property is returned, so it's good practice to use contains() is you're unsure if the property exists. For example, to set a value of a property, use: /code Set set; ... if (!set.contains("myProperty")) { dosomething; } set["myProperty"].setValue("My Value"); /endcode @return \ref Property with given name. @see changeProperty(const QByteArray &, const QVariant &) @see changePropertyIfExists(const QByteArray &, const QVariant &) */ KProperty& operator[](const QByteArray &name) const; /*! @return value for property named with @a name. If no such property is found, default value @a defaultValue is returned. */ QVariant propertyValue(const QByteArray &name, const QVariant& defaultValue = QVariant()) const; /*! Creates a deep copy of \a set and assigns it to this property set. */ const KPropertySet& operator= (const KPropertySet &set); /*! Change the value of property whose key is \a property to \a value. @see void changePropertyIfExists(const QByteArray &, const QVariant &) */ void changeProperty(const QByteArray &property, const QVariant &value); /*! Change the value of property whose key is \a property to \a value only if it exists in the set. @see void changeProperty(const QByteArray &, const QVariant &) */ void changePropertyIfExists(const QByteArray &property, const QVariant &value) { if (contains(property)) changeProperty(property, value); } /*! Sets the user-visible translated string that will be shown in Editor to represent \a group. */ void setGroupDescription(const QByteArray &group, const QString desc); /*! \return the user-visible translated description string for \a group that will be shown in Editor to represent \a group. If there is no special description set for the group, \a group is just returned. */ QString groupDescription(const QByteArray &group) const; /*! Sets the icon name \a icon to be displayed for \a group. */ void setGroupIcon(const QByteArray &group, const QString& icon); /*! \return the icons name for \a group. */ QString groupIcon(const QByteArray &group) const; /*! \return a list of all group names. The order of items is undefined. */ QList groupNames() const; /*! \return a list of all property names for group @ group. The order of items is undefined. */ QList propertyNamesForGroup(const QByteArray &group) const; /*! Used by property editor to preserve previous selection when this set is assigned again. */ QByteArray previousSelection() const; void setPreviousSelection(const QByteArray& prevSelection); /*! An optional name of this property set's type, that is usable when we want to know if two property set objects have the same type. This avoids e.g. reloading of all Editor's contents. Also, informs whether two property set objects are compatible. For comparing purposes, type names are lowercase for case insensitive comparisons.*/ QString typeName() const; /*! Prints debug output for this set. */ void debug() const; //! @return property values for this set QMap propertyValues() const; protected: /*! Constructs a set which owns or does not own it's properties.*/ KPropertySet(bool propertyOwner); /*! @return group name for property @a property */ QByteArray groupForProperty(KProperty *property) const; /*! Adds property to a group.*/ void addToGroup(const QByteArray &group, KProperty *property); /*! Removes property from a group.*/ void removeFromGroup(KProperty *property); /*! Adds the property to the set, in the group. You can use any group name, except "common" (which is already used for basic group). @internal */ void addPropertyInternal(KProperty *property, QByteArray group); /*! @internal used to declare that \a property wants to be informed that the set has been cleared (all properties are deleted) */ void informAboutClearing(bool& cleared); /*! Helper for Private class. */ void addRelatedProperty(KProperty *p1, KProperty *p2) const; Q_SIGNALS: /*! Emitted when the value of the property is changed.*/ void propertyChanged(KPropertySet& set, KProperty& property); /*! @internal Exists to be sure that we emitted it before propertyChanged(), so Editor object can handle this. */ void propertyChangedInternal(KPropertySet& set, KProperty& property); /*! Emitted when the value of the property is reset.*/ void propertyReset(KPropertySet& set, KProperty& property); /*! Emitted when property is about to be deleted.*/ void aboutToDeleteProperty(KPropertySet& set, KProperty& property); /*! Emitted when property set object is about to be cleared (using clear()). This signal is also emitted from destructor before emitting aboutToBeDeleted(). */ void aboutToBeCleared(); /*! Emitted when property set object is about to be deleted.*/ void aboutToBeDeleted(); protected: class Private; friend class Private; Private * const d; friend class KPropertySetIterator; friend class KProperty; friend class KPropertyBuffer; }; //! qDebug() stream operator. Writes this set to the debug output in a nicely formatted way. -KPROPERTY_EXPORT QDebug operator<<(QDebug dbg, const KPropertySet &set); +KPROPERTYCORE_EXPORT QDebug operator<<(QDebug dbg, const KPropertySet &set); /*! A property buffer \author Cedric Pasteur \author Alexander Dymo \author Adam Treat @todo Find a better name to show it's a set that doesn't own property */ -class KPROPERTY_EXPORT KPropertyBuffer : public KPropertySet +class KPROPERTYCORE_EXPORT KPropertyBuffer : public KPropertySet { Q_OBJECT public: KPropertyBuffer(); explicit KPropertyBuffer(const KPropertySet &set); /*! Intersects with other Set.*/ virtual void intersect(const KPropertySet& set); protected Q_SLOTS: void intersectedChanged(KPropertySet& set, KProperty& prop); void intersectedReset(KPropertySet& set, KProperty& prop); private: void init(const KPropertySet& set); }; #endif diff --git a/src/KPropertyUnit_p.cpp b/src/KPropertyUnit_p.cpp index 0571092..86217fe 100644 --- a/src/KPropertyUnit_p.cpp +++ b/src/KPropertyUnit_p.cpp @@ -1,394 +1,399 @@ /* This file is part of the KDE project Copyright (C) 2001 David Faure Copyright (C) 2004, Nicolas GOUTTE Copyright 2012 Friedrich W. H. Kossebau 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 "KPropertyUnit_p.h" #include "kproperty_debug.h" +#ifdef KPROPERTY_WIDGET #include +#endif + #include #include // ensure the same order as in KPropertyUnit::Unit static const char* const unitNameList[KPropertyUnit::TypeCount] = { "mm", "pt", "in", "cm", "dm", "pi", "cc", "px" }; QString KPropertyUnit::unitDescription(KPropertyUnit::Type type) { switch (type) { case KPropertyUnit::Millimeter: return QObject::tr("Millimeters (mm)"); case KPropertyUnit::Centimeter: return QObject::tr("Centimeters (cm)"); case KPropertyUnit::Decimeter: return QObject::tr("Decimeters (dm)"); case KPropertyUnit::Inch: return QObject::tr("Inches (in)"); case KPropertyUnit::Pica: return QObject::tr("Pica (pi)"); case KPropertyUnit::Cicero: return QObject::tr("Cicero (cc)"); case KPropertyUnit::Point: return QObject::tr("Points (pt)"); case KPropertyUnit::Pixel: return QObject::tr("Pixels (px)"); default: return QObject::tr("Unsupported unit"); } } // grouped by units which are similar static const KPropertyUnit::Type typesInUi[KPropertyUnit::TypeCount] = { KPropertyUnit::Millimeter, KPropertyUnit::Centimeter, KPropertyUnit::Decimeter, KPropertyUnit::Inch, KPropertyUnit::Pica, KPropertyUnit::Cicero, KPropertyUnit::Point, KPropertyUnit::Pixel, }; QStringList KPropertyUnit::listOfUnitNameForUi(ListOptions listOptions) { QStringList lst; for (int i = 0; i < KPropertyUnit::TypeCount; ++i) { const Type type = typesInUi[i]; if ((type != Pixel) || ((listOptions & HideMask) == ListAll)) lst.append(unitDescription(type)); } return lst; } KPropertyUnit KPropertyUnit::fromListForUi(int index, ListOptions listOptions, qreal factor) { KPropertyUnit::Type type = KPropertyUnit::Point; if ((0 <= index) && (index < KPropertyUnit::TypeCount)) { // iterate through all enums and skip the Pixel enum if needed for (int i = 0; i < KPropertyUnit::TypeCount; ++i) { if ((listOptions&HidePixel) && (typesInUi[i] == Pixel)) { ++index; continue; } if (i == index) { type = typesInUi[i]; break; } } } return KPropertyUnit(type, factor); } int KPropertyUnit::indexInListForUi(ListOptions listOptions) const { if ((listOptions&HidePixel) && (m_type == Pixel)) { return -1; } int result = -1; int skipped = 0; for (int i = 0; i < KPropertyUnit::TypeCount; ++i) { if ((listOptions&HidePixel) && (typesInUi[i] == Pixel)) { ++skipped; continue; } if (typesInUi[i] == m_type) { result = i - skipped; break; } } return result; } qreal KPropertyUnit::toUserValue(qreal ptValue) const { switch (m_type) { case Millimeter: return toMillimeter(ptValue); case Centimeter: return toCentimeter(ptValue); case Decimeter: return toDecimeter(ptValue); case Inch: return toInch(ptValue); case Pica: return toPica(ptValue); case Cicero: return toCicero(ptValue); case Pixel: return ptValue * m_pixelConversion; case Point: default: return toPoint(ptValue); } } qreal KPropertyUnit::ptToUnit(qreal ptValue, const KPropertyUnit &unit) { switch (unit.m_type) { case Millimeter: return POINT_TO_MM(ptValue); case Centimeter: return POINT_TO_CM(ptValue); case Decimeter: return POINT_TO_DM(ptValue); case Inch: return POINT_TO_INCH(ptValue); case Pica: return POINT_TO_PI(ptValue); case Cicero: return POINT_TO_CC(ptValue); case Pixel: return ptValue * unit.m_pixelConversion; case Point: default: return ptValue; } } QString KPropertyUnit::toUserStringValue(qreal ptValue) const { return QLocale::system().toString(toUserValue(ptValue)); } qreal KPropertyUnit::fromUserValue(qreal value) const { switch (m_type) { case Millimeter: return MM_TO_POINT(value); case Centimeter: return CM_TO_POINT(value); case Decimeter: return DM_TO_POINT(value); case Inch: return INCH_TO_POINT(value); case Pica: return PI_TO_POINT(value); case Cicero: return CC_TO_POINT(value); case Pixel: return value / m_pixelConversion; case Point: default: return value; } } qreal KPropertyUnit::fromUserValue(const QString &value, bool *ok) const { return fromUserValue(QLocale::system().toDouble(value, ok)); } qreal KPropertyUnit::parseValue(const QString& _value, qreal defaultVal) { if (_value.isEmpty()) return defaultVal; QString value(_value.simplified()); value.remove(QLatin1Char(' ')); int firstLetter = -1; for (int i = 0; i < value.length(); ++i) { if (value.at(i).isLetter()) { if (value.at(i) == QLatin1Char('e')) continue; firstLetter = i; break; } } if (firstLetter == -1) return value.toDouble(); const QString symbol = value.mid(firstLetter); value.truncate(firstLetter); const qreal val = value.toDouble(); if (symbol == QLatin1String("pt")) return val; bool ok; KPropertyUnit u = KPropertyUnit::fromSymbol(symbol, &ok); if (ok) return u.fromUserValue(val); if (symbol == QLatin1String("m")) return DM_TO_POINT(val * 10.0); else if (symbol == QLatin1String("km")) return DM_TO_POINT(val * 10000.0); kprWarning() << "KPropertyUnit::parseValue: Unit " << symbol << " is not supported, please report."; //! @todo add support for mi/ft ? return defaultVal; } KPropertyUnit KPropertyUnit::fromSymbol(const QString &symbol, bool *ok) { Type result = Point; if (symbol == QLatin1String("inch") /*compat*/) { result = Inch; if (ok) *ok = true; } else { if (ok) *ok = false; for (int i = 0; i < TypeCount; ++i) { if (symbol == QLatin1String(unitNameList[i])) { result = static_cast(i); if (ok) *ok = true; } } } return KPropertyUnit(result); } qreal KPropertyUnit::convertFromUnitToUnit(qreal value, const KPropertyUnit &fromUnit, const KPropertyUnit &toUnit, qreal factor) { qreal pt; switch (fromUnit.type()) { case Millimeter: pt = MM_TO_POINT(value); break; case Centimeter: pt = CM_TO_POINT(value); break; case Decimeter: pt = DM_TO_POINT(value); break; case Inch: pt = INCH_TO_POINT(value); break; case Pica: pt = PI_TO_POINT(value); break; case Cicero: pt = CC_TO_POINT(value); break; case Pixel: pt = value / factor; break; case Point: default: pt = value; } switch (toUnit.type()) { case Millimeter: return POINT_TO_MM(pt); case Centimeter: return POINT_TO_CM(pt); case Decimeter: return POINT_TO_DM(pt); case Inch: return POINT_TO_INCH(pt); case Pica: return POINT_TO_PI(pt); case Cicero: return POINT_TO_CC(pt); case Pixel: return pt * factor; case Point: default: return pt; } } QString KPropertyUnit::symbol() const { return QLatin1String(unitNameList[m_type]); } qreal KPropertyUnit::parseAngle(const QString& _value, qreal defaultVal) { if (_value.isEmpty()) return defaultVal; QString value(_value.simplified()); value.remove(QLatin1Char(' ')); int firstLetter = -1; for (int i = 0; i < value.length(); ++i) { if (value.at(i).isLetter()) { if (value.at(i) == QLatin1Char('e')) continue; firstLetter = i; break; } } if (firstLetter == -1) return value.toDouble(); const QString type = value.mid(firstLetter); value.truncate(firstLetter); const qreal val = value.toDouble(); if (type == QLatin1String("deg")) return val; else if (type == QLatin1String("rad")) return val * 180 / M_PI; else if (type == QLatin1String("grad")) return val * 0.9; return defaultVal; } +#ifdef KPROPERTY_WIDGET qreal KPropertyUnit::approxTransformScale(const QTransform &t) { return std::sqrt(t.determinant()); } void KPropertyUnit::adjustByPixelTransform(const QTransform &t) { m_pixelConversion *= approxTransformScale(t); } +#endif #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug debug, const KPropertyUnit &unit) { #ifndef NDEBUG debug.nospace() << unit.symbol(); #else Q_UNUSED(unit); #endif return debug.space(); } #endif diff --git a/src/KPropertyUnit_p.h b/src/KPropertyUnit_p.h index e779f08..e83291f 100644 --- a/src/KPropertyUnit_p.h +++ b/src/KPropertyUnit_p.h @@ -1,273 +1,276 @@ /* This file is part of the KDE project Copyright (C) 1998, 1999 Reginald Stadlbauer Copyright (C) 1998, 1999 Torben Weis Copyright (C) 2004, Nicolas GOUTTE Copyright (C) 2010 Thomas Zander Copyright 2012 Friedrich W. H. Kossebau 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 KPROPERTYUNIT_H #define KPROPERTYUNIT_H -#include "kproperty_export.h" +#include "kpropertycore_export.h" #include #include #include #include #include // for floor // 1 inch ^= 72 pt // 1 inch ^= 25.399956 mm (-pedantic ;p) // 1 pt = 1/12 pi // 1 pt ^= 0.0077880997 cc // 1 cc = 12 dd // Note: I don't use division but multiplication with the inverse value // because it's faster ;p (Werner) #define POINT_TO_MM(px) qreal((px)*0.352777167) #define MM_TO_POINT(mm) qreal((mm)*2.83465058) #define POINT_TO_CM(px) qreal((px)*0.0352777167) #define CM_TO_POINT(cm) qreal((cm)*28.3465058) #define POINT_TO_DM(px) qreal((px)*0.00352777167) #define DM_TO_POINT(dm) qreal((dm)*283.465058) #define POINT_TO_INCH(px) qreal((px)*0.01388888888889) #define INCH_TO_POINT(inch) qreal((inch)*72.0) #define MM_TO_INCH(mm) qreal((mm)*0.039370147) #define INCH_TO_MM(inch) qreal((inch)*25.399956) #define POINT_TO_PI(px) qreal((px)*0.083333333) #define POINT_TO_CC(px) qreal((px)*0.077880997) #define PI_TO_POINT(pi) qreal((pi)*12) #define CC_TO_POINT(cc) qreal((cc)*12.840103) /** * %Calligra stores everything in pt (using "qreal") internally. * When displaying a value to the user, the value is converted to the user's unit * of choice, and rounded to a reasonable precision to avoid 0.999999 * * For implementing the selection of a unit type in the UI use the *ForUi() methods. * They ensure the same order of the unit types in all places, with the order not * bound to the order in the enum (so ABI-compatible extension is possible) and * with the order and scope of listed types controlled by the @c ListOptions parameter. */ -class KPROPERTY_EXPORT KPropertyUnit +class KPROPERTYCORE_EXPORT KPropertyUnit { public: /** Length units supported by Calligra. */ enum Type { Millimeter = 0, Point, ///< Postscript point, 1/72th of an Inco Inch, Centimeter, Decimeter, Pica, Cicero, Pixel, TypeCount ///< @internal }; /// Used to control the scope of the unit types listed in the UI enum ListOption { ListAll = 0, HidePixel = 1, HideMask = HidePixel }; Q_DECLARE_FLAGS(ListOptions, ListOption) /** Returns a KPropertyUnit instance with the type at the @p index of the UI list with the given @p listOptions. */ static KPropertyUnit fromListForUi(int index, ListOptions listOptions = ListAll, qreal factor = 1.0); /// Convert a unit symbol string into a KPropertyUnit /// @param symbol symbol to convert /// @param ok if set, it will be true if the unit was known, false if unknown static KPropertyUnit fromSymbol(const QString &symbol, bool *ok = 0); /** Construction requires initialization. The factor is for variable factor units like pixel */ explicit KPropertyUnit(Type unit = Point, qreal factor = 1.0) { m_type = unit; m_pixelConversion = factor; } KPropertyUnit& operator=(Type unit) { m_type = unit; m_pixelConversion = 1.0; return *this; } bool operator!=(const KPropertyUnit &other) const { return !operator==(other); } bool operator==(const KPropertyUnit &other) const { return m_type == other.m_type && (m_type != Pixel || qFuzzyCompare(m_pixelConversion, other.m_pixelConversion)); } KPropertyUnit::Type type() const { return m_type; } void setFactor(qreal factor) { m_pixelConversion = factor; } /** * Prepare ptValue to be displayed in pt * This method will round to 0.001 precision */ static qreal toPoint(qreal ptValue) { // No conversion, only rounding (to 0.001 precision) return floor(ptValue * 1000.0) / 1000.0; } /** * Prepare ptValue to be displayed in mm * This method will round to 0.0001 precision, use POINT_TO_MM() for lossless conversion. */ static qreal toMillimeter(qreal ptValue) { // "mm" values are rounded to 0.0001 millimeters return floor(POINT_TO_MM(ptValue) * 10000.0) / 10000.0; } /** * Prepare ptValue to be displayed in cm * This method will round to 0.0001 precision, use POINT_TO_CM() for lossless conversion. */ static qreal toCentimeter(qreal ptValue) { return floor(POINT_TO_CM(ptValue) * 10000.0) / 10000.0; } /** * Prepare ptValue to be displayed in dm * This method will round to 0.0001 precision, use POINT_TO_DM() for lossless conversion. */ static qreal toDecimeter(qreal ptValue) { return floor(POINT_TO_DM(ptValue) * 10000.0) / 10000.0; } /** * Prepare ptValue to be displayed in inch * This method will round to 0.00001 precision, use POINT_TO_INCH() for lossless conversion. */ static qreal toInch(qreal ptValue) { // "in" values are rounded to 0.00001 inches return floor(POINT_TO_INCH(ptValue) * 100000.0) / 100000.0; } /** * Prepare ptValue to be displayed in pica * This method will round to 0.00001 precision, use POINT_TO_PI() for lossless conversion. */ static qreal toPica(qreal ptValue) { // "pi" values are rounded to 0.00001 inches return floor(POINT_TO_PI(ptValue) * 100000.0) / 100000.0; } /** * Prepare ptValue to be displayed in cicero * This method will round to 0.00001 precision, use POINT_TO_CC() for lossless conversion. */ static qreal toCicero(qreal ptValue) { // "cc" values are rounded to 0.00001 inches return floor(POINT_TO_CC(ptValue) * 100000.0) / 100000.0; } /** * convert the given value directly from one unit to another */ static qreal convertFromUnitToUnit(qreal value, const KPropertyUnit &fromUnit, const KPropertyUnit &toUnit, qreal factor = 1.0); /** * This method is the one to use to display a value in a dialog * \return the value @p ptValue converted to unit and rounded, ready to be displayed */ qreal toUserValue(qreal ptValue) const; /** * Convert the value @p ptValue to a given unit @p unit * Unlike KPropertyUnit::ptToUnit the return value remains unrounded, so that it can be used in complex calculation * \return the converted value */ static qreal ptToUnit(qreal ptValue, const KPropertyUnit &unit); /// This method is the one to use to display a value in a dialog /// @return the value @p ptValue converted the unit and rounded, ready to be displayed QString toUserStringValue(qreal ptValue) const; /// This method is the one to use to read a value from a dialog /// @return the value converted to points for internal use qreal fromUserValue(qreal value) const; /// This method is the one to use to read a value from a dialog /// @param value value entered by the user /// @param ok if set, the pointed bool is set to true if the value could be /// converted to a qreal, and to false otherwise. /// @return the value converted to points for internal use qreal fromUserValue(const QString &value, bool *ok = 0) const; /// Get the description string of the given unit static QString unitDescription(KPropertyUnit::Type type); /// Get the symbol string of the unit QString symbol() const; /// Returns the list of unit types for the UI, controlled with the given @p listOptions. static QStringList listOfUnitNameForUi(ListOptions listOptions = ListAll); /// Get the index of this unit in the list of unit types for the UI, /// if it is controlled with the given @p listOptions. int indexInListForUi(ListOptions listOptions = ListAll) const; /// parse common %Calligra and Odf values, like "10cm", "5mm" to pt static qreal parseValue(const QString &value, qreal defaultVal = 0.0); /// parse an angle to its value in degrees static qreal parseAngle(const QString &value, qreal defaultVal = 0.0); QString toString() { return symbol(); } +#ifdef KPROPERTY_WIDGET + /** * Get an approximate scale of a unit vector that was converted by * the transfomation. * * Please note that exact values are guaranteed only for * combinations of Translate, Rotation and Unifor Scale * matrices. For combinations having shears and perspective the * value will be average for the point near CS origin. */ static qreal approxTransformScale(const QTransform &t); /** * Adjust the unit by pixel transformation applied to the * describing object. It multiplies the pixel coefficient by the * average scale of the matrix. */ void adjustByPixelTransform(const QTransform &t); - +#endif + private: Type m_type; qreal m_pixelConversion; }; #ifndef QT_NO_DEBUG_STREAM -KPROPERTY_EXPORT QDebug operator<<(QDebug, const KPropertyUnit &); +KPROPERTYCORE_EXPORT QDebug operator<<(QDebug, const KPropertyUnit &); #endif Q_DECLARE_METATYPE(KPropertyUnit) Q_DECLARE_OPERATORS_FOR_FLAGS(KPropertyUnit::ListOptions) #endif diff --git a/src/KPropertyUtils.h b/src/KPropertyUtils.h index 37ac5f7..544b694 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 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 "kproperty_export.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 KPROPERTY_EXPORT KPropertyGroupWidget : public QWidget +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/KPropertyConfig.cmake.in b/src/KPropertyWidgetsConfig.cmake.in similarity index 92% rename from src/KPropertyConfig.cmake.in rename to src/KPropertyWidgetsConfig.cmake.in index f979003..4e28e53 100644 --- a/src/KPropertyConfig.cmake.in +++ b/src/KPropertyWidgetsConfig.cmake.in @@ -1,22 +1,22 @@ # KPropertyConfig.cmake provides information about the installed KProperty library. # It can be used directly from CMake via find_package(KProperty NO_MODULE) # # The following CMake variables are provided: # KProperty_VERSION_MAJOR - the major version number of KProperty # KProperty_VERSION_MINOR - the minor version number of KProperty # KProperty_VERSION_PATCH - the patch version number of KProperty # KProperty_INCLUDE_DIRS - the include directories to use # # Additionally, the following imported library targets are created, which may be used directly # with target_link_libraries(): # KProperty - the KProperty library @PACKAGE_INIT@ find_dependency(Qt5Core @REQUIRED_QT_VERSION@) find_dependency(Qt5Widgets @REQUIRED_QT_VERSION@) -include("${CMAKE_CURRENT_LIST_DIR}/KPropertyTargets.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/KPropertyWidgetsTargets.cmake") # "public" variables: # TODO diff --git a/src/KPropertyFactory.cpp b/src/KPropertyWidgetsFactory.cpp similarity index 70% copy from src/KPropertyFactory.cpp copy to src/KPropertyWidgetsFactory.cpp index e1c12ea..6299234 100644 --- a/src/KPropertyFactory.cpp +++ b/src/KPropertyWidgetsFactory.cpp @@ -1,446 +1,392 @@ /* This file is part of the KDE project Copyright (C) 2008 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" KPropertyLabel::KPropertyLabel(QWidget *parent, const KPropertyValueDisplayInterface *iface) : QLabel(parent) , m_iface(iface) { setAutoFillBackground(true); setContentsMargins(0,1,0,0); setIndent(1); } QVariant KPropertyLabel::value() const { return m_value; } void KPropertyLabel::setValue(const QVariant& value) { setText( m_iface->displayText(value) ); m_value = value; } void KPropertyLabel::paintEvent( QPaintEvent * event ) { QLabel::paintEvent(event); - KPropertyFactory::paintTopGridLine(this); + KPropertyWidgetsFactory::paintTopGridLine(this); } //--------------- //! @internal -class KPropertyFactoryManager::Private +class KPropertyWidgetsFactoryManager::Private { public: Private() { } ~Private() { qDeleteAll(factories); } QSet factories; - QHash composedPropertyCreators; QHash editorCreators; QHash valuePainters; QHash valueDisplays; + }; - Q_GLOBAL_STATIC(KPropertyFactoryManager, _self) + Q_GLOBAL_STATIC(KPropertyWidgetsFactoryManager, _self) //! @internal -class KPropertyFactory::Private +class KPropertyWidgetsFactory::Private { public: Private() { } ~Private() { qDeleteAll(editorCreatorsSet); qDeleteAll(valuePaintersSet); qDeleteAll(valueDisplaysSet); } - QHash composedPropertyCreators; QHash editorCreators; QHash valuePainters; QHash valueDisplays; - QSet composedPropertyCreatorsSet; + QSet editorCreatorsSet; QSet valuePaintersSet; QSet valueDisplaysSet; + }; -KPropertyFactory::KPropertyFactory() +KPropertyWidgetsFactory::KPropertyWidgetsFactory() : d( new Private ) { } -KPropertyFactory::~KPropertyFactory() +KPropertyWidgetsFactory::~KPropertyWidgetsFactory() { delete d; } -QHash KPropertyFactory::composedPropertyCreators() const -{ - return d->composedPropertyCreators; -} - -QHash KPropertyFactory::editorCreators() const +QHash KPropertyWidgetsFactory::editorCreators() const { return d->editorCreators; } -QHash KPropertyFactory::valuePainters() const +QHash KPropertyWidgetsFactory::valuePainters() const { return d->valuePainters; } -QHash KPropertyFactory::valueDisplays() const +QHash KPropertyWidgetsFactory::valueDisplays() const { return d->valueDisplays; } -void KPropertyFactory::addEditor(int type, KPropertyEditorCreatorInterface *creator) +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 KPropertyFactory::addComposedPropertyCreator( int type, KComposedPropertyCreatorInterface* creator ) -{ - addComposedPropertyCreatorInternal( type, creator, true ); - if (dynamic_cast(creator)) { - addEditorInternal( 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 KPropertyFactory::addPainter(int type, KPropertyValuePainterInterface *painter) +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 KPropertyFactory::addDisplay(int type, KPropertyValueDisplayInterface *display) +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 KPropertyFactory::addEditorInternal(int type, KPropertyEditorCreatorInterface *editor, bool own) +void KPropertyWidgetsFactory::addEditorInternal(int type, KPropertyEditorCreatorInterface *editor, bool own) { if (own) d->editorCreatorsSet.insert(editor); d->editorCreators.insert(type, editor); } -void KPropertyFactory::addComposedPropertyCreatorInternal(int type, KComposedPropertyCreatorInterface* creator, bool own) -{ - if (own) - d->composedPropertyCreatorsSet.insert(creator); - d->composedPropertyCreators.insert(type, creator); -} - -void KPropertyFactory::addPainterInternal(int type, KPropertyValuePainterInterface *painter, bool own) +void KPropertyWidgetsFactory::addPainterInternal(int type, KPropertyValuePainterInterface *painter, bool own) { if (own) d->valuePaintersSet.insert(painter); d->valuePainters.insert(type, painter); } -void KPropertyFactory::addDisplayInternal(int type, KPropertyValueDisplayInterface *display, bool own) +void KPropertyWidgetsFactory::addDisplayInternal(int type, KPropertyValueDisplayInterface *display, bool own) { if (own) d->valueDisplaysSet.insert(display); d->valueDisplays.insert(type, display); } //static -void KPropertyFactory::paintTopGridLine(QWidget *widget) +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); } //static -void KPropertyFactory::setTopAndBottomBordersUsingStyleSheet(QWidget *widget, QWidget* parent, const QString& extraStyleSheet) +void KPropertyWidgetsFactory::setTopAndBottomBordersUsingStyleSheet(QWidget *widget, QWidget* parent, const QString& extraStyleSheet) { QColor gridLineColor( dynamic_cast(parent) ? dynamic_cast(parent)->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)); } //------------ -KPropertyFactoryManager::KPropertyFactoryManager() - : QObject(0) +KPropertyWidgetsFactoryManager::KPropertyWidgetsFactoryManager() + : KPropertyFactoryManager() , d(new Private) { - setObjectName(QLatin1String("KPropertyFactoryManager")); + setObjectName(QLatin1String("KPropertyWidgetsFactoryManager")); registerFactory(new KDefaultPropertyFactory); } -KPropertyFactoryManager::~KPropertyFactoryManager() +KPropertyWidgetsFactoryManager::~KPropertyWidgetsFactoryManager() { delete d; } -KPropertyFactoryManager* KPropertyFactoryManager::self() +KPropertyWidgetsFactoryManager* KPropertyWidgetsFactoryManager::self() { return _self; } -void KPropertyFactoryManager::registerFactory(KPropertyFactory *factory) +void KPropertyWidgetsFactoryManager::registerFactory(KPropertyWidgetsFactory *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 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 KPropertyFactoryManager::isEditorForTypeAvailable( int type ) const +bool KPropertyWidgetsFactoryManager::isEditorForTypeAvailable( int type ) const { return d->editorCreators.value(type); } -QWidget * KPropertyFactoryManager::createEditor( +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() ); 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 KPropertyFactoryManager::paint( int type, QPainter * painter, +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 KPropertyFactoryManager::canConvertValueToText( int type ) const +bool KPropertyWidgetsFactoryManager::canConvertValueToText( int type ) const { return d->valueDisplays.value(type) != 0; } -bool KPropertyFactoryManager::canConvertValueToText( const KProperty* property ) const +bool KPropertyWidgetsFactoryManager::canConvertValueToText( const KProperty* property ) const { return d->valueDisplays.value( property->type() ) != 0; } -QString KPropertyFactoryManager::convertValueToText( const KProperty* property ) const +QString KPropertyWidgetsFactoryManager::convertValueToText( const KProperty* property ) const { const KPropertyValueDisplayInterface *display = d->valueDisplays.value( property->type() ); return display ? display->displayTextForProperty( property ) : property->value().toString(); } -KComposedPropertyInterface* KPropertyFactoryManager::createComposedProperty(KProperty *parent) -{ - const KComposedPropertyCreatorInterface *creator = d->composedPropertyCreators.value( parent->type() ); - return creator ? creator->createComposedProperty(parent) : 0; -} - //! @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() -{ -} - KPropertyEditorCreatorInterface::KPropertyEditorCreatorInterface() { } KPropertyEditorCreatorInterface::~KPropertyEditorCreatorInterface() { } KPropertyEditorCreatorInterface::Options::Options() : removeBorders(true) { } KPropertyValuePainterInterface::KPropertyValuePainterInterface() { } KPropertyValuePainterInterface::~KPropertyValuePainterInterface() { } KPropertyValueDisplayInterface::KPropertyValueDisplayInterface() { } KPropertyValueDisplayInterface::~KPropertyValueDisplayInterface() { } + diff --git a/src/KPropertyFactory.h b/src/KPropertyWidgetsFactory.h similarity index 65% copy from src/KPropertyFactory.h copy to src/KPropertyWidgetsFactory.h index 2c9fbc7..a2a6dfa 100644 --- a/src/KPropertyFactory.h +++ b/src/KPropertyWidgetsFactory.h @@ -1,284 +1,223 @@ /* This file is part of the KDE project Copyright (C) 2008 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 +#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 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 KPROPERTY_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; } - -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 KPROPERTY_EXPORT KComposedPropertyCreatorInterface -{ -public: - KComposedPropertyCreatorInterface(); - - virtual ~KComposedPropertyCreatorInterface(); - - virtual KComposedPropertyInterface* createComposedProperty(KProperty *parent) const = 0; -}; - //! 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 KPROPERTY_EXPORT KPropertyEditorCreatorInterface +class KPROPERTYWIDGETS_EXPORT KPropertyEditorCreatorInterface { public: KPropertyEditorCreatorInterface(); virtual ~KPropertyEditorCreatorInterface(); virtual QWidget * createEditor( int type, QWidget *parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const = 0; /*! 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 KPROPERTY_EXPORT KPropertyValuePainterInterface +class KPROPERTYWIDGETS_EXPORT KPropertyValuePainterInterface { public: KPropertyValuePainterInterface(); virtual ~KPropertyValuePainterInterface(); virtual void paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const = 0; }; -class KPROPERTY_EXPORT KPropertyValueDisplayInterface +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. -class KPROPERTY_EXPORT KPropertyLabel : public QLabel +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; }; //! Creator returning editor template -class KPROPERTY_EXPORT KPropertyEditorCreator : public KPropertyEditorCreatorInterface, +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 { 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(); } }; typedef KPropertyEditorCreator KPropertyLabelCreator; -//! Creator returning composed property object -template -class KPROPERTY_EXPORT KComposedPropertyCreator : public KComposedPropertyCreatorInterface -{ -public: - KComposedPropertyCreator() : KComposedPropertyCreatorInterface() {} - virtual ~KComposedPropertyCreator() {} - - virtual ComposedProperty* createComposedProperty(KProperty *parent) const { - return new ComposedProperty(parent); - } -}; - -class KPROPERTY_EXPORT KPropertyFactory +class KPROPERTYWIDGETS_EXPORT KPropertyWidgetsFactory : public KPropertyFactory { public: - KPropertyFactory(); - virtual ~KPropertyFactory(); - QHash composedPropertyCreators() const; + 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 addComposedPropertyCreator( int type, KComposedPropertyCreatorInterface* 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()); protected: void addEditorInternal(int type, KPropertyEditorCreatorInterface *editor, bool own = true); - void addComposedPropertyCreatorInternal(int type, - KComposedPropertyCreatorInterface* creator, 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 KPROPERTY_EXPORT KPropertyFactoryManager : public QObject +class KPROPERTYWIDGETS_EXPORT KPropertyWidgetsFactoryManager : public KPropertyFactoryManager { Q_OBJECT 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; - + KComposedPropertyInterface* createComposedProperty(KProperty *parent); 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(KPropertyFactory *factory); + void registerFactory(KPropertyWidgetsFactory *factory); KCustomProperty* createCustomProperty( KProperty *parent ); /*! \return a pointer to a factory manager instance.*/ - static KPropertyFactoryManager* self(); + static KPropertyWidgetsFactoryManager* self(); - KPropertyFactoryManager(); - ~KPropertyFactoryManager(); + KPropertyWidgetsFactoryManager(); + ~KPropertyWidgetsFactoryManager(); private: class Private; Private * const d; }; #endif diff --git a/src/config-kproperty.h.cmake b/src/config-kproperty.h.cmake index 5ee9707..e5c9d32 100644 --- a/src/config-kproperty.h.cmake +++ b/src/config-kproperty.h.cmake @@ -1,34 +1,38 @@ #ifndef KPROPERTY_CONFIG_H #define KPROPERTY_CONFIG_H /* config-kproperty.h. Generated by cmake from config-kproperty.h.cmake */ /*! @file config-kproperty.h Global KProperty configuration (build time) */ //! @def KPROPERTY_GIT_SHA1_STRING //! @brief Indicates the git sha1 commit which was used for compilation of KProperty #cmakedefine KPROPERTY_GIT_SHA1_STRING "@KPROPERTY_GIT_SHA1_STRING@" //! @def KPROPERTY_GIT_BRANCH_STRING //! @brief Indicates the git branch which was used for compilation of KProperty #cmakedefine KPROPERTY_GIT_BRANCH_STRING "@KPROPERTY_GIT_BRANCH_STRING@" //! @def BIN_INSTALL_DIR //! @brief The subdirectory relative to the install prefix for executables. #define BIN_INSTALL_DIR "${BIN_INSTALL_DIR}" //! @def KPROPERTY_TESTING_EXPORT //! @brief Export symbols for testing #ifdef BUILD_TESTING # define KPROPERTY_TESTING_EXPORT KPROPERTY_EXPORT #else # define KPROPERTY_TESTING_EXPORT #endif //! @def KPROPERTY_UNFINISHED //! @brief Defined if unfinished features of KProperty are enabled #cmakedefine KPROPERTY_UNFINISHED +//! @def KPROPERTY_WIDGET +//! @brief Defined if QtWidgets components of KProperty are enabled +#cmakedefine KPROPERTY_WIDGET + #endif diff --git a/src/editors/CMakeLists.txt b/src/editors/CMakeLists.txt index 147ffc4..8c1af75 100644 --- a/src/editors/CMakeLists.txt +++ b/src/editors/CMakeLists.txt @@ -1,46 +1,46 @@ ecm_generate_headers(kproperty_editors_FORWARDING_HEADERS REQUIRED_HEADERS kproperty_editors_HEADERS # TODO: rename to camelcase, then uncomment "ORIGINAL CAMELCASE" HEADER_NAMES Utils BoolEdit ColorEdit ComboBox CursorEdit DateEdit DateTimeEdit #DummyWidget FontEdit LineStyleEdit PixmapEdit PointEdit RectEdit SizeEdit SizePolicyEdit SpinBox #StringListEdit #SymbolCombo TimeEdit #TODO UrlEdit ) 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}/KProperty + DESTINATION ${INCLUDE_INSTALL_DIR}/KPropertyWidgets COMPONENT Devel ) install( FILES ${kproperty_editors_FORWARDING_HEADERS} - DESTINATION ${INCLUDE_INSTALL_DIR}/KProperty + DESTINATION ${INCLUDE_INSTALL_DIR}/KPropertyWidgets COMPONENT Devel ) diff --git a/src/editors/KPropertyStringEditor.h b/src/editors/KPropertyStringEditor.h index 908c89c..5862180 100644 --- a/src/editors/KPropertyStringEditor.h +++ b/src/editors/KPropertyStringEditor.h @@ -1,62 +1,62 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur Copyright (C) 2004 Alexander Dymo Copyright (C) 2008 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 "KPropertyFactory.h" +#include "KPropertyWidgetsFactory.h" #include -class KPROPERTY_EXPORT KPropertyStringEditor : public QLineEdit +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 KPROPERTY_EXPORT KPropertyStringDelegate : public KPropertyEditorCreatorInterface +class KPROPERTYWIDGETS_EXPORT KPropertyStringDelegate : public KPropertyEditorCreatorInterface { public: KPropertyStringDelegate() {} virtual QWidget * createEditor( int type, QWidget *parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const; }; #endif diff --git a/src/editors/booledit.h b/src/editors/booledit.h index 8ca5f5f..c2b8459 100644 --- a/src/editors/booledit.h +++ b/src/editors/booledit.h @@ -1,102 +1,102 @@ /* 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 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 KPROPERTY_EXPORT KPropertyBoolEditor : public QToolButton +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 KPROPERTY_EXPORT KPropertyThreeStateBoolEditor : public KPropertyComboBoxEditor +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 KPROPERTY_EXPORT KPropertyBoolDelegate : public KPropertyEditorCreatorInterface, +class KPROPERTYWIDGETS_EXPORT KPropertyBoolDelegate : public KPropertyEditorCreatorInterface, public KPropertyValuePainterInterface { 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; }; #endif diff --git a/src/editors/coloredit.h b/src/editors/coloredit.h index 47a58bb..da2f931 100644 --- a/src/editors/coloredit.h +++ b/src/editors/coloredit.h @@ -1,65 +1,66 @@ /* 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_COLOREDIT_H #define KPROPERTY_COLOREDIT_H -#include "KPropertyFactory.h" +#include "kpropertywidgets_export.h" +#include "KPropertyWidgetsFactory.h" #include //! Color combo box //! @todo enable transparency selection //! @todo add transparency option //! @todo reimplement view using KColorCells -class KPROPERTY_EXPORT KPropertyColorComboEditor : public KColorCombo +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&); }; -class KPROPERTY_EXPORT KPropertyColorComboDelegate : public KPropertyEditorCreatorInterface, +class KPROPERTYWIDGETS_EXPORT KPropertyColorComboDelegate : public KPropertyEditorCreatorInterface, public KPropertyValuePainterInterface { 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; }; #endif diff --git a/src/editors/combobox.cpp b/src/editors/combobox.cpp index 3fcc7f9..855aa77 100644 --- a/src/editors/combobox.cpp +++ b/src/editors/combobox.cpp @@ -1,293 +1,294 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur Copyright (C) 2004 Alexander Dymo Copyright (C) 2008 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 "kpropertywidgets_debug.h" +#include "KPropertyWidgetsFactory.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 //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()); setStyleSheet(styleSheet); } KPropertyComboBoxEditor::~KPropertyComboBoxEditor() { } bool KPropertyComboBoxEditor::listDataKeysAvailable() const { if (m_listData.keys.isEmpty()) { - kprWarning() << "property listData not available!"; + kprwWarning() << "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() + kprwWarning() << "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 + kprwWarning() << "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); - KPropertyFactory::paintTopGridLine(this); + 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 { 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 ]; } 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 73c0207..d5ba5e3 100644 --- a/src/editors/combobox.h +++ b/src/editors/combobox.h @@ -1,105 +1,106 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur Copyright (C) 2004 Alexander Dymo Copyright (C) 2008 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 "KPropertyFactory.h" +#include "KPropertyWidgetsFactory.h" +#include "kpropertywidgets_export.h" #include -class KPROPERTY_EXPORT KPropertyComboBoxEditor : public QComboBox +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); 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 KPROPERTY_EXPORT KPropertyComboBoxDelegate : public KPropertyEditorCreatorInterface, +class KPROPERTYWIDGETS_EXPORT KPropertyComboBoxDelegate : public KPropertyEditorCreatorInterface, public KPropertyValueDisplayInterface { public: KPropertyComboBoxDelegate(); virtual QString displayTextForProperty( const KProperty* property ) 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.h b/src/editors/cursoredit.h index bb1e3a6..0aca816 100644 --- a/src/editors/cursoredit.h +++ b/src/editors/cursoredit.h @@ -1,53 +1,53 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur Copyright (C) 2004 Alexander Dymo Copyright (C) 2008 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 KPROPERTY_EXPORT KPropertyCursorEditor : public KPropertyComboBoxEditor +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 KPROPERTY_EXPORT KPropertyCursorDelegate : public KPropertyEditorCreatorInterface, +class KPROPERTYWIDGETS_EXPORT KPropertyCursorDelegate : public KPropertyEditorCreatorInterface, public KPropertyValuePainterInterface { 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; }; #endif diff --git a/src/editors/dateedit.cpp b/src/editors/dateedit.cpp index 251de80..e52b656 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 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); - KPropertyFactory::paintTopGridLine(this); + 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 { const QLocale locale; const QString defaultDateFormat = locale.dateFormat(QLocale::ShortFormat); return prop->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 4699e48..955131d 100644 --- a/src/editors/dateedit.h +++ b/src/editors/dateedit.h @@ -1,64 +1,64 @@ /* 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 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 "KPropertyFactory.h" +#include "KPropertyWidgetsFactory.h" #include -class KPROPERTY_EXPORT KPropertyDateEditor : public QDateEdit +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 KPROPERTY_EXPORT KPropertyDateDelegate : public KPropertyEditorCreatorInterface, +class KPROPERTYWIDGETS_EXPORT KPropertyDateDelegate : public KPropertyEditorCreatorInterface, public KPropertyValueDisplayInterface { public: KPropertyDateDelegate(); virtual QString displayTextForProperty(const KProperty* prop) 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 037f48b..a0b50f4 100644 --- a/src/editors/datetimeedit.cpp +++ b/src/editors/datetimeedit.cpp @@ -1,100 +1,101 @@ /* 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 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); - KPropertyFactory::paintTopGridLine(this); + 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 { const QLocale locale; const QString defaultDateTimeFormat = locale.dateTimeFormat(QLocale::ShortFormat); return prop->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 5e24e1f..050f5b3 100644 --- a/src/editors/datetimeedit.h +++ b/src/editors/datetimeedit.h @@ -1,64 +1,64 @@ /* 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 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 "KPropertyFactory.h" +#include "KPropertyWidgetsFactory.h" #include -class KPROPERTY_EXPORT KPropertyDateTimeEditor : public QDateTimeEdit +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 KPROPERTY_EXPORT KPropertyDateTimeDelegate : public KPropertyEditorCreatorInterface, +class KPROPERTYWIDGETS_EXPORT KPropertyDateTimeDelegate : public KPropertyEditorCreatorInterface, public KPropertyValueDisplayInterface { public: KPropertyDateTimeDelegate(); virtual QString displayTextForProperty(const KProperty* prop) const; virtual QWidget* createEditor(int type, QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const; }; #endif diff --git a/src/editors/dummywidget.h b/src/editors/dummywidget.h index 43a1ea4..42cceb3 100644 --- a/src/editors/dummywidget.h +++ b/src/editors/dummywidget.h @@ -1,49 +1,49 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur Copyright (C) 2004 Alexander Dymo 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_DUMMYWIDGET_H #define KPROPERTY_DUMMYWIDGET_H #include "KPropertyFactory.h" #include -class KPROPERTY_EXPORT KPropertyDummyWidget: public Widget +class KPROPERTYWIDGETS_EXPORT KPropertyDummyWidget: public Widget { Q_OBJECT public: explicit KPropertyDummyWidget(KProperty *property, QWidget *parent = 0); virtual ~KPropertyDummyWidget(); virtual QVariant value() const; virtual void setValue(const QVariant &value, bool emitChange = true); virtual void drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value); protected: virtual void setReadOnlyInternal(bool readOnly); private: QVariant m_value; }; #endif diff --git a/src/editors/fontedit.h b/src/editors/fontedit.h index e406b36..36ca59a 100644 --- a/src/editors/fontedit.h +++ b/src/editors/fontedit.h @@ -1,39 +1,39 @@ /* 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 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 "KPropertyFactory.h" +#include "KPropertyWidgetsFactory.h" -class KPROPERTY_EXPORT KPropertyFontDelegate : public KPropertyEditorCreatorInterface, +class KPROPERTYWIDGETS_EXPORT KPropertyFontDelegate : public KPropertyEditorCreatorInterface, public KPropertyValuePainterInterface { public: 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; }; #endif diff --git a/src/editors/linestyleedit.h b/src/editors/linestyleedit.h index 407d798..82acfdc 100644 --- a/src/editors/linestyleedit.h +++ b/src/editors/linestyleedit.h @@ -1,65 +1,65 @@ /* 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_LINESTYLEEDIT_H #define KPROPERTY_LINESTYLEEDIT_H -#include "KPropertyFactory.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 KPROPERTY_EXPORT KPropertyLineStyleComboEditor : public KPropertyLineStyleSelector +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 KPROPERTY_EXPORT KPropertyLineStyleComboDelegate : public KPropertyEditorCreatorInterface, +class KPROPERTYWIDGETS_EXPORT KPropertyLineStyleComboDelegate : public KPropertyEditorCreatorInterface, public KPropertyValuePainterInterface { 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; }; #endif diff --git a/src/editors/pixmapedit.h b/src/editors/pixmapedit.h index fd1e6e2..954152d 100644 --- a/src/editors/pixmapedit.h +++ b/src/editors/pixmapedit.h @@ -1,87 +1,87 @@ /* 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 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 "KPropertyFactory.h" +#include "KPropertyWidgetsFactory.h" #include #include class QLabel; class QPushButton; -class KPROPERTY_EXPORT KPropertyPixmapEditor : public QWidget +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 KPROPERTY_EXPORT KPropertyPixmapDelegate : public KPropertyEditorCreatorInterface, +class KPROPERTYWIDGETS_EXPORT KPropertyPixmapDelegate : public KPropertyEditorCreatorInterface, public KPropertyValuePainterInterface { 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; }; #endif diff --git a/src/editors/pointedit.h b/src/editors/pointedit.h index 4f9e195..a68ed83 100644 --- a/src/editors/pointedit.h +++ b/src/editors/pointedit.h @@ -1,47 +1,47 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur Copyright (C) 2004 Alexander Dymo Copyright (C) 2008 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 "KPropertyFactory.h" +#include "KPropertyWidgetsFactory.h" -class KPROPERTY_EXPORT KPointComposedProperty : public KComposedPropertyInterface +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 KPROPERTY_EXPORT KPropertyPointDelegate : public KPropertyLabelCreator, +class KPROPERTYWIDGETS_EXPORT KPropertyPointDelegate : public KPropertyLabelCreator, public KComposedPropertyCreator { public: KPropertyPointDelegate() {} virtual QString displayText( const QVariant& value ) const; }; #endif diff --git a/src/editors/pointfedit.h b/src/editors/pointfedit.h index c0583e0..e1284b8 100644 --- a/src/editors/pointfedit.h +++ b/src/editors/pointfedit.h @@ -1,48 +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) 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 "KPropertyFactory.h" +#include "KPropertyWidgetsFactory.h" -class KPROPERTY_EXPORT KPointFComposedProperty : public KComposedPropertyInterface +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 KPROPERTY_EXPORT KPropertyPointFDelegate : public KPropertyLabelCreator, +class KPROPERTYWIDGETS_EXPORT KPropertyPointFDelegate : public KPropertyLabelCreator, public KComposedPropertyCreator { public: KPropertyPointFDelegate() {} virtual QString displayText( const QVariant& value ) const; }; #endif diff --git a/src/editors/rectedit.h b/src/editors/rectedit.h index 8a38df6..468d9c2 100644 --- a/src/editors/rectedit.h +++ b/src/editors/rectedit.h @@ -1,45 +1,45 @@ /* This file is part of the KDE project Copyright (C) 2008 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 "KPropertyFactory.h" +#include "KPropertyWidgetsFactory.h" -class KPROPERTY_EXPORT KRectComposedProperty : public KComposedPropertyInterface +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 KPROPERTY_EXPORT KPropertyRectDelegate : public KPropertyLabelCreator, +class KPROPERTYWIDGETS_EXPORT KPropertyRectDelegate : public KPropertyLabelCreator, public KComposedPropertyCreator { public: KPropertyRectDelegate() {} virtual QString displayText( const QVariant& value ) const; }; #endif diff --git a/src/editors/sizeedit.h b/src/editors/sizeedit.h index 7a17bae..5d423f1 100644 --- a/src/editors/sizeedit.h +++ b/src/editors/sizeedit.h @@ -1,47 +1,47 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur Copyright (C) 2004 Alexander Dymo Copyright (C) 2008 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 "KPropertyFactory.h" +#include "KPropertyWidgetsFactory.h" -class KPROPERTY_EXPORT KSizeComposedProperty : public KComposedPropertyInterface +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 KPROPERTY_EXPORT KPropertySizeDelegate : public KPropertyLabelCreator, +class KPROPERTYWIDGETS_EXPORT KPropertySizeDelegate : public KPropertyLabelCreator, public KComposedPropertyCreator { public: KPropertySizeDelegate() {} virtual QString displayText( const QVariant& value ) const; }; #endif diff --git a/src/editors/sizefedit.h b/src/editors/sizefedit.h index 993a735..0a35465 100644 --- a/src/editors/sizefedit.h +++ b/src/editors/sizefedit.h @@ -1,47 +1,47 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur Copyright (C) 2004 Alexander Dymo Copyright (C) 2008 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 "KPropertyFactory.h" +#include "KPropertyWidgetsFactory.h" -class KPROPERTY_EXPORT KSizeFComposedProperty : public KComposedPropertyInterface +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 KPROPERTY_EXPORT KPropertySizeFDelegate : public KPropertyLabelCreator, +class KPROPERTYWIDGETS_EXPORT KPropertySizeFDelegate : public KPropertyLabelCreator, public KComposedPropertyCreator { public: KPropertySizeFDelegate() {} virtual QString displayText( const QVariant& value ) const; }; #endif diff --git a/src/editors/sizepolicyedit.h b/src/editors/sizepolicyedit.h index 6f83018..4276f5e 100644 --- a/src/editors/sizepolicyedit.h +++ b/src/editors/sizepolicyedit.h @@ -1,48 +1,48 @@ /* 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_SIZEPOLICYEDIT_H #define KPROPERTY_SIZEPOLICYEDIT_H -#include "KPropertyFactory.h" +#include "KPropertyWidgetsFactory.h" -class KPROPERTY_EXPORT KSizePolicyComposedProperty : public KComposedPropertyInterface +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); }; -class KPROPERTY_EXPORT KPropertySizePolicyDelegate : public KPropertyLabelCreator, +class KPROPERTYWIDGETS_EXPORT KPropertySizePolicyDelegate : public KPropertyLabelCreator, public KComposedPropertyCreator { public: KPropertySizePolicyDelegate() {} virtual QString displayText( const QVariant& value ) const; static const KPropertyListData& listData(); }; #endif diff --git a/src/editors/spinbox.cpp b/src/editors/spinbox.cpp index ff3cd53..0d46f9e 100644 --- a/src/editors/spinbox.cpp +++ b/src/editors/spinbox.cpp @@ -1,289 +1,290 @@ /* 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 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 "kproperty_debug.h" +#include "KPropertyWidgetsFactory.h" +#include "kpropertywidgets_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); - KPropertyFactory::setTopAndBottomBordersUsingStyleSheet(this, parent, css); + KPropertyWidgetsFactory::setTopAndBottomBordersUsingStyleSheet(this, parent, 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"; + kprwWarning() << "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, 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); - KPropertyFactory::setTopAndBottomBordersUsingStyleSheet(this, parent, css); + KPropertyWidgetsFactory::setTopAndBottomBordersUsingStyleSheet(this, parent, 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 { 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()); } 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 { KPropertyUnit unit; bool hasUnit; decodeUnit(*prop, &unit, &hasUnit); QLocale locale; 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; } } //! @todo precision? //! @todo rounding using KLocale::formatNumber(const QString &numStr, bool round = true,int precision = 2)? if (hasUnit) { return QObject::tr("%1 %2", " ") .arg(locale.toString(prop->value().toDouble())).arg(unit.toString()); } return locale.toString(prop->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 9e8ad8c..1dd8532 100644 --- a/src/editors/spinbox.h +++ b/src/editors/spinbox.h @@ -1,124 +1,124 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur Copyright (C) 2004 Alexander Dymo Copyright (C) 2008 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 "KPropertyFactory.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 KPROPERTY_EXPORT KPropertyIntSpinBox : public QSpinBox +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 KPROPERTY_EXPORT KPropertyDoubleSpinBox : public QDoubleSpinBox +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 KPROPERTY_EXPORT KPropertyIntSpinBoxDelegate : public KPropertyEditorCreatorInterface, +class KPROPERTYWIDGETS_EXPORT KPropertyIntSpinBoxDelegate : public KPropertyEditorCreatorInterface, public KPropertyValueDisplayInterface { public: KPropertyIntSpinBoxDelegate(); virtual QString displayTextForProperty( const KProperty* prop ) const; virtual QWidget * createEditor( int type, QWidget *parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const; }; -class KPROPERTY_EXPORT KPropertyDoubleSpinBoxDelegate : public KPropertyEditorCreatorInterface, +class KPROPERTYWIDGETS_EXPORT KPropertyDoubleSpinBoxDelegate : public KPropertyEditorCreatorInterface, public KPropertyValueDisplayInterface { public: KPropertyDoubleSpinBoxDelegate(); virtual QString displayTextForProperty( const KProperty* prop ) const; virtual QWidget * createEditor( int type, QWidget *parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const; }; #endif diff --git a/src/editors/stringlistedit.h b/src/editors/stringlistedit.h index 65a39d3..0a74adb 100644 --- a/src/editors/stringlistedit.h +++ b/src/editors/stringlistedit.h @@ -1,56 +1,56 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur Copyright (C) 2004 Alexander Dymo 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_STRINGLISTEDIT_H #define KPROPERTY_STRINGLISTEDIT_H #include "KPropertyFactory.h" #include class QLineEdit; class QPushButton; -class KPROPERTY_EXPORT KPropertyStringListEditor : public Widget +class KPROPERTYWIDGETS_EXPORT KPropertyStringListEditor : public Widget { Q_OBJECT public: explicit KPropertyStringListEditor(KProperty *property, QWidget *parent = 0); virtual ~KPropertyStringListEditor(); virtual QVariant value() const; virtual void setValue(const QVariant &value, bool emitChange = true); virtual void drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value); protected: virtual void setReadOnlyInternal(bool readOnly); protected Q_SLOTS: void showEditor(); private: QLineEdit *m_edit; QStringList m_list; QPushButton *m_selectButton; }; #endif diff --git a/src/editors/symbolcombo.h b/src/editors/symbolcombo.h index 6a184f5..dc09a31 100644 --- a/src/editors/symbolcombo.h +++ b/src/editors/symbolcombo.h @@ -1,54 +1,54 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur Copyright (C) 2004 Alexander Dymo 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_SYMBOLCOMBO_H #define KPROPERTY_SYMBOLCOMBO_H #include "KPropertyFactory.h" class QLineEdit; class QPushButton; -class KPROPERTY_EXPORT KPropertySymbolComboEditor : public Widget +class KPROPERTYWIDGETS_EXPORT KPropertySymbolComboEditor : public Widget { Q_OBJECT public: explicit KPropertySymbolComboEditor(KProperty *property, QWidget *parent = 0); virtual ~KPropertySymbolComboEditor(); virtual QVariant value() const; virtual void setValue(const QVariant &value, bool emitChange = true); virtual void drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value); protected: virtual void setReadOnlyInternal(bool readOnly); protected Q_SLOTS: void selectChar(); void slotValueChanged(const QString &text); private: QLineEdit *m_edit; QPushButton *m_select; }; #endif diff --git a/src/editors/timeedit.cpp b/src/editors/timeedit.cpp index a88c4d8..ca49aca 100644 --- a/src/editors/timeedit.cpp +++ b/src/editors/timeedit.cpp @@ -1,96 +1,96 @@ /* 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 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); 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); - KPropertyFactory::paintTopGridLine(this); + 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 { const QLocale locale; const QString defaultTimeFormat = locale.timeFormat(QLocale::ShortFormat); return prop->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 fd63f64..aa596ba 100644 --- a/src/editors/timeedit.h +++ b/src/editors/timeedit.h @@ -1,64 +1,64 @@ /* 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 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 "KPropertyFactory.h" +#include "KPropertyWidgetsFactory.h" #include -class KPROPERTY_EXPORT KPropertyTimeEditor : public QTimeEdit +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 KPROPERTY_EXPORT KPropertyTimeDelegate : public KPropertyEditorCreatorInterface, +class KPROPERTYWIDGETS_EXPORT KPropertyTimeDelegate : public KPropertyEditorCreatorInterface, public KPropertyValueDisplayInterface { public: KPropertyTimeDelegate(); virtual QString displayTextForProperty(const KProperty* prop) const; virtual QWidget* createEditor(int type, QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const; }; #endif diff --git a/src/editors/urledit.h b/src/editors/urledit.h index dab2b64..fc3a1aa 100644 --- a/src/editors/urledit.h +++ b/src/editors/urledit.h @@ -1,57 +1,57 @@ /* This file is part of the KDE project Copyright (C) 2004 Cedric Pasteur Copyright (C) 2004 Alexander Dymo 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_URLEDIT_H #define KPROPERTY_URLEDIT_H #include "KPropertyFactory.h" class KUrlRequester; -class KPROPERTY_EXPORT KPropertyUrlEditor : public Widget +class KPROPERTYWIDGETS_EXPORT KPropertyUrlEditor : public Widget { Q_PROPERTY(QVariant value READ value WRITE setValue USER true) Q_OBJECT public: explicit KPropertyUrlEditor(KProperty *property, QWidget *parent = 0); virtual ~KPropertyUrlEditor(); virtual QVariant value() const; virtual void setProperty(KProperty *property); Q_SIGNALS: void commitData( QWidget * editor ); public Q_SLOTS: virtual void setValue(const QVariant &value); protected Q_SLOTS: void slotValueChanged(const QString &url); protected: virtual void setReadOnlyInternal(bool readOnly); private: KUrlRequester *m_edit; }; #endif diff --git a/src/editors/utils.cpp b/src/editors/utils.cpp index 744cb36..d85655b 100644 --- a/src/editors/utils.cpp +++ b/src/editors/utils.cpp @@ -1,36 +1,36 @@ /* This file is part of the KDE project Copyright (C) 2008 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 "utils.h" #include #include -KPROPERTY_EXPORT void KPropertyUtils::setupDotDotDotButton(QPushButton *button, const QString& toolTip, const QString& whatsThis) +KPROPERTYCORE_EXPORT void KPropertyUtils::setupDotDotDotButton(QPushButton *button, const QString& toolTip, const QString& whatsThis) { button->setText(QObject::tr("...", "Three dots for 'Insert image from file' button")); if (!toolTip.isEmpty()) button->setToolTip(toolTip); if (!whatsThis.isEmpty()) button->setWhatsThis(whatsThis); button->setFocusPolicy(Qt::NoFocus); button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); const QFontMetrics fm(button->font()); button->setFixedWidth(fm.width(button->text() + QLatin1String(" "))); } diff --git a/src/editors/utils.h b/src/editors/utils.h index f037c8b..9238c25 100644 --- a/src/editors/utils.h +++ b/src/editors/utils.h @@ -1,38 +1,38 @@ /* This file is part of the KDE project Copyright (C) 2008 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_EDITORS_UTILS_H #define KPROPERTY_EDITORS_UTILS_H -#include "kproperty_export.h" +#include "kpropertycore_export.h" #include class QPushButton; namespace KPropertyUtils { //! Sets up a "..." button with fine-tuned settings. -KPROPERTY_EXPORT void setupDotDotDotButton(QPushButton *button, +KPROPERTYCORE_EXPORT void setupDotDotDotButton(QPushButton *button, const QString& toolTip = QString(), const QString& whatsThis = QString()); } #endif diff --git a/src/KDefaultPropertyFactory.h b/src/kpropertywidgets_debug.cpp similarity index 73% copy from src/KDefaultPropertyFactory.h copy to src/kpropertywidgets_debug.cpp index a923685..07bcb30 100644 --- a/src/KDefaultPropertyFactory.h +++ b/src/kpropertywidgets_debug.cpp @@ -1,32 +1,22 @@ /* This file is part of the KDE project - Copyright (C) 2008 Jarosław Staniek + Copyright (C) 2015 Laurent Montel 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 KDEFAULTPROPERTYFACTORY_H -#define KDEFAULTPROPERTYFACTORY_H +#include "kpropertywidgets_debug.h" +Q_LOGGING_CATEGORY(KPROPERTYW_LOG, "org.kde.kproperty.widgets") -#include "KPropertyFactory.h" - -class KDefaultPropertyFactory : public KPropertyFactory -{ -public: - KDefaultPropertyFactory(); - ~KDefaultPropertyFactory(); -}; - -#endif diff --git a/src/KDefaultPropertyFactory.h b/src/kpropertywidgets_debug.h similarity index 68% copy from src/KDefaultPropertyFactory.h copy to src/kpropertywidgets_debug.h index a923685..7b67090 100644 --- a/src/KDefaultPropertyFactory.h +++ b/src/kpropertywidgets_debug.h @@ -1,32 +1,30 @@ /* This file is part of the KDE project - Copyright (C) 2008 Jarosław Staniek + Copyright (C) 2015 Laurent Montel 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 KDEFAULTPROPERTYFACTORY_H -#define KDEFAULTPROPERTYFACTORY_H +#ifndef KPROPERTYWIDGETS_DEBUG_H +#define KPROPERTYWIDGETS_DEBUG_H -#include "KPropertyFactory.h" +#include +Q_DECLARE_LOGGING_CATEGORY(KPROPERTYW_LOG) -class KDefaultPropertyFactory : public KPropertyFactory -{ -public: - KDefaultPropertyFactory(); - ~KDefaultPropertyFactory(); -}; +#define kprwDebug(...) qCDebug(KPROPERTYW_LOG, __VA_ARGS__) +#define kprwWarning(...) qCWarning(KPROPERTYW_LOG, __VA_ARGS__) +#define kprwCritical(...) qCCritical(KPROPERTYW_LOG, __VA_ARGS__) #endif