diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) +cmake_minimum_required(VERSION 2.8.11 FATAL_ERROR) project(KProperty) # ECM setup @@ -25,22 +25,33 @@ include(MacroLogFeature) include(KPropertyMacros) +simple_option(KPROPERTY_WIDGET "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(Qt5Core REQUIRED) +#find_package(Qt5Widgets REQUIRED) + +find_package(Qt5 ${REQUIRED_QT_VERSION} NO_MODULE REQUIRED Core) + +if(KPROPERTY_WIDGET) + 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_subdirectory(src) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,82 +1,107 @@ # 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 +if(KPROPERTY_WIDGET) + 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 ) +endif() -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}) +if(KPROPERTY_WIDGET) + set(kpropertywidget_LIB_SRCS $(kproperty_LIB_SRCS) + ${libkpropertyeditors_SRCS} + KDefaultPropertyFactory.cpp + KPropertyEditorView.cpp + KPropertyEditorDataModel.cpp + KPropertyUtils.cpp + KPropertyLineStyleSelector_p.cpp + KPropertyLineStyleModel_p.cpp + KPropertyLineStyleItemDelegate_p.cpp + ) +endif() + +ecm_create_qm_loader(kpropertycore_LIB_SRCS kproperty_qt) + +add_library(KPropertyCore SHARED ${kpropertycore_LIB_SRCS}) +target_link_libraries(KPropertyCore + Qt5::Core +) +if(KPROPERTY_WIDGET) + add_library(KPropertyWidget SHARED ${kpropertywidget_LIB_SRCS}) + target_link_libraries(KPropertyCore + KF5::WidgetsAddons + KF5::GuiAddons + ) +endif() -generate_export_header(KProperty) +generate_export_header(KPropertyCore) 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 +target_include_directories(KPropertyCore PUBLIC "$" INTERFACE "$" PRIVATE editors ) -target_link_libraries(KProperty - KF5::WidgetsAddons - KF5::GuiAddons - #TODO KF5::KIOWidgets +set_target_properties(KPropertyCore + PROPERTIES VERSION 1.0 + SOVERSION 1.0.0 + EXPORT_NAME KPropertyCore ) -set_target_properties(KProperty +if(KPROPERTY_WIDGET) +generate_export_header(KPropertyWidget) +target_include_directories(KPropertyWidget + PUBLIC "$" + INTERFACE "$" + PRIVATE editors +) + +set_target_properties(KPropertyWidget PROPERTIES VERSION 1.0 SOVERSION 1.0.0 - EXPORT_NAME KProperty + EXPORT_NAME KPropertyWidget ) +endif() # Create a Config.cmake and a ConfigVersion.cmake file and install them set(CMAKECONFIG_INSTALL_DIR "${CMAKECONFIG_INSTALL_PREFIX}/KProperty") @@ -96,27 +121,30 @@ INSTALL_DESTINATION "${CMAKECONFIG_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) - -ecm_generate_pri_file( - BASE_NAME KProperty - LIB_NAME KProperty - DEPS "widgets" - FILENAME_VAR PRI_FILENAME - INCLUDE_INSTALL_DIR ${INCLUDE_INSTALL_DIR}/KProperty -) +if(NOT KPROPERTY_MOBILE) + 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) + + + ecm_generate_pri_file( + BASE_NAME KProperty + LIB_NAME KProperty + DEPS "widgets" + FILENAME_VAR PRI_FILENAME + INCLUDE_INSTALL_DIR ${INCLUDE_INSTALL_DIR}/KProperty + ) +endif() install(FILES ${PRI_FILENAME} DESTINATION ${ECM_MKSPECS_INSTALL_DIR}) diff --git a/src/KProperty.cpp b/src/KProperty.cpp --- a/src/KProperty.cpp +++ b/src/KProperty.cpp @@ -26,7 +26,10 @@ #include "kproperty_debug.h" #include + +#ifdef KPROPERTY_WIDGET #include +#endif //! @internal class KProperty::Private @@ -359,8 +362,10 @@ 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); diff --git a/src/KPropertyFactory.h b/src/KPropertyFactory.h --- a/src/KPropertyFactory.h +++ b/src/KPropertyFactory.h @@ -25,9 +25,12 @@ #include #include #include + +#ifdef KPROPERTY_WIDGET #include #include #include +#endif //! An interface for for composed property handlers /*! You have to subclass KComposedPropertyInterface to override the behaviour of a property type.\n @@ -76,6 +79,7 @@ virtual KComposedPropertyInterface* createComposedProperty(KProperty *parent) const = 0; }; +#ifdef KPROPERTY_WIDGET //! 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. @@ -125,6 +129,7 @@ { 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 @@ -180,6 +185,7 @@ }; typedef KPropertyEditorCreator KPropertyLabelCreator; +#endif //! Creator returning composed property object template @@ -201,38 +207,40 @@ KPropertyFactory(); virtual ~KPropertyFactory(); QHash composedPropertyCreators() const; + void addComposedPropertyCreator( int type, KComposedPropertyCreatorInterface* creator ); + +#ifdef KPROPERTY_WIDGET 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()); - +#endif protected: - void addEditorInternal(int type, KPropertyEditorCreatorInterface *editor, bool own = true); - void addComposedPropertyCreatorInternal(int type, KComposedPropertyCreatorInterface* creator, bool own = true); +#ifdef KPROPERTY_WIDGET + void addEditorInternal(int type, KPropertyEditorCreatorInterface *editor, bool own = true); //! Adds value painter @a painter for type @a type. //! The painter becomes owned by the factory. void addPainterInternal(int type, KPropertyValuePainterInterface *painter, bool own = true); //! Adds value-to-text converted @a painter for type @a type. //! The converter becomes owned by the factory. void addDisplayInternal(int type, KPropertyValueDisplayInterface *display, bool own = true); - +#endif + class Private; Private * const d; }; @@ -246,6 +254,7 @@ public: bool isEditorForTypeAvailable( int type ) const; +#ifdef KPROPERTY_WIDGET QWidget * createEditor( int type, QWidget *parent, @@ -256,7 +265,8 @@ QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const; - +#endif + KComposedPropertyInterface* createComposedProperty(KProperty *parent); bool canConvertValueToText( int type ) const; diff --git a/src/KPropertyFactory.cpp b/src/KPropertyFactory.cpp --- a/src/KPropertyFactory.cpp +++ b/src/KPropertyFactory.cpp @@ -19,6 +19,8 @@ #include "KPropertyFactory.h" + +#ifdef KPROPERTY_WIDGET #include "KDefaultPropertyFactory.h" #include "KPropertyEditorView.h" #include "KPropertyEditorDataModel.h" @@ -49,6 +51,8 @@ KPropertyFactory::paintTopGridLine(this); } +#endif + //--------------- //! @internal @@ -65,9 +69,11 @@ QSet factories; QHash composedPropertyCreators; +#ifdef KPROPERTY_WIDGET QHash editorCreators; QHash valuePainters; QHash valueDisplays; +#endif }; Q_GLOBAL_STATIC(KPropertyFactoryManager, _self) @@ -81,19 +87,25 @@ } ~Private() { +#ifdef KPROPERTY_WIDGET qDeleteAll(editorCreatorsSet); qDeleteAll(valuePaintersSet); qDeleteAll(valueDisplaysSet); +#endif } QHash composedPropertyCreators; +#ifdef KPROPERTY_WIDGET QHash editorCreators; QHash valuePainters; QHash valueDisplays; +#endif QSet composedPropertyCreatorsSet; +#ifdef KPROPERTY_WIDGET QSet editorCreatorsSet; QSet valuePaintersSet; QSet valueDisplaysSet; +#endif }; KPropertyFactory::KPropertyFactory() @@ -111,6 +123,7 @@ return d->composedPropertyCreators; } +#ifdef KPROPERTY_WIDGET QHash KPropertyFactory::editorCreators() const { return d->editorCreators; @@ -140,10 +153,12 @@ addDisplayInternal( type, dynamic_cast(creator), false/* !own*/ ); } } +#endif void KPropertyFactory::addComposedPropertyCreator( int type, KComposedPropertyCreatorInterface* creator ) { addComposedPropertyCreatorInternal( type, creator, true ); +#ifdef KPROPERTY_WIDGET if (dynamic_cast(creator)) { addEditorInternal( type, dynamic_cast(creator), false/* !own*/ ); } @@ -153,8 +168,10 @@ if (dynamic_cast(creator)) { addDisplayInternal( type, dynamic_cast(creator), false/* !own*/ ); } +#endif } +#ifdef KPROPERTY_WIDGET void KPropertyFactory::addPainter(int type, KPropertyValuePainterInterface *painter) { addPainterInternal(type, painter, true); @@ -192,13 +209,16 @@ d->editorCreators.insert(type, editor); } +#endif + void KPropertyFactory::addComposedPropertyCreatorInternal(int type, KComposedPropertyCreatorInterface* creator, bool own) { if (own) d->composedPropertyCreatorsSet.insert(creator); d->composedPropertyCreators.insert(type, creator); } +#ifdef KPROPERTY_WIDGET void KPropertyFactory::addPainterInternal(int type, KPropertyValuePainterInterface *painter, bool own) { if (own) @@ -236,15 +256,18 @@ .arg(QLatin1String(widget->metaObject()->className())) .arg(gridLineColor.name()).arg(extraStyleSheet)); } +#endif //------------ KPropertyFactoryManager::KPropertyFactoryManager() : QObject(0) , d(new Private) { setObjectName(QLatin1String("KPropertyFactoryManager")); +#ifdef KPROPERTY_WIDGET registerFactory(new KDefaultPropertyFactory); +#endif } KPropertyFactoryManager::~KPropertyFactoryManager() @@ -267,6 +290,7 @@ { d->composedPropertyCreators.insert(it.key(), it.value()); } +#ifdef KPROPERTY_WIDGET QHash::ConstIterator editorCreatorsItEnd = factory->editorCreators().constEnd(); for (QHash::ConstIterator it( factory->editorCreators().constBegin() ); @@ -288,8 +312,10 @@ { d->valueDisplays.insert(it.key(), it.value()); } +#endif } +#ifdef KPROPERTY_WIDGET bool KPropertyFactoryManager::isEditorForTypeAvailable( int type ) const { return d->editorCreators.value(type); @@ -358,6 +384,8 @@ return display ? display->displayTextForProperty( property ) : property->value().toString(); } +#endif + KComposedPropertyInterface* KPropertyFactoryManager::createComposedProperty(KProperty *parent) { const KComposedPropertyCreatorInterface *creator = d->composedPropertyCreators.value( parent->type() ); @@ -416,6 +444,7 @@ { } +#ifdef KPROPERTY_WIDGET KPropertyEditorCreatorInterface::KPropertyEditorCreatorInterface() { } @@ -444,3 +473,4 @@ KPropertyValueDisplayInterface::~KPropertyValueDisplayInterface() { } +#endif diff --git a/src/KPropertyUnit_p.h b/src/KPropertyUnit_p.h --- a/src/KPropertyUnit_p.h +++ b/src/KPropertyUnit_p.h @@ -240,6 +240,8 @@ return symbol(); } +#ifdef KPROPERTY_WIDGET + /** * Get an approximate scale of a unit vector that was converted by * the transfomation. @@ -257,7 +259,8 @@ * average scale of the matrix. */ void adjustByPixelTransform(const QTransform &t); - +#endif + private: Type m_type; qreal m_pixelConversion; diff --git a/src/KPropertyUnit_p.cpp b/src/KPropertyUnit_p.cpp --- a/src/KPropertyUnit_p.cpp +++ b/src/KPropertyUnit_p.cpp @@ -22,7 +22,10 @@ #include "KPropertyUnit_p.h" #include "kproperty_debug.h" +#ifdef KPROPERTY_WIDGET #include +#endif + #include #include @@ -370,6 +373,7 @@ return defaultVal; } +#ifdef KPROPERTY_WIDGET qreal KPropertyUnit::approxTransformScale(const QTransform &t) { return std::sqrt(t.determinant()); @@ -379,6 +383,7 @@ { m_pixelConversion *= approxTransformScale(t); } +#endif #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug debug, const KPropertyUnit &unit) diff --git a/src/config-kproperty.h.cmake b/src/config-kproperty.h.cmake --- a/src/config-kproperty.h.cmake +++ b/src/config-kproperty.h.cmake @@ -31,4 +31,8 @@ //! @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