diff --git a/libs/widgets/CMakeLists.txt b/libs/widgets/CMakeLists.txt index a2a2b1f45d..2bb25e6b5c 100644 --- a/libs/widgets/CMakeLists.txt +++ b/libs/widgets/CMakeLists.txt @@ -1,139 +1,135 @@ add_subdirectory( tests ) include_directories(${CMAKE_CURRENT_BINARY_DIR}) set(kritawidgets_LIB_SRCS KoGradientEditWidget.cpp KoVBox.cpp KoDialog.cpp KoZoomWidget.cpp KoTagToolButton.cpp KoTagChooserWidget.cpp KoTagFilterWidget.cpp KoResourceTaggingManager.cpp KoResourceItemChooserContextMenu.cpp KoAspectButton.cpp KoPagePreviewWidget.cpp KoSliderCombo.cpp KoColorPopupButton.cpp KoConfigAuthorPage.cpp KoUnitDoubleSpinBox.cpp KoZoomAction.cpp KoZoomController.cpp KoZoomInput.cpp KoZoomHandler.cpp KoZoomMode.cpp KoDpi.cpp KoColorPatch.cpp KoColorPopupAction.cpp KoColorSetWidget.cpp KoColorSlider.cpp KoTriangleColorSelector.cpp KoResourcePopupAction.cpp KoIconToolTip.cpp KoResourceItemChooser.cpp KoResourceItemChooserSync.cpp KoResourceModel.cpp KoResourceItemDelegate.cpp KoResourceItemView.cpp KoResourceTagStore.cpp KoRuler.cpp KoItemToolTip.cpp KoCheckerBoardPainter.cpp KoResourceServerAdapter.cpp KoResourceServerProvider.cpp KoLineStyleSelector.cpp KoLineStyleItemDelegate.cpp KoLineStyleModel.cpp KoResourceFiltering.cpp KoTitledTabWidget.cpp KoToolBoxButton.cpp KoToolBox.cpp KoToolBoxDocker.cpp KoToolBoxFactory.cpp KoToolDocker.cpp KoPageLayoutWidget.cpp KoPageLayoutDialog.cpp KoShadowConfigWidget.cpp KoMarkerSelector.cpp KoMarkerModel.cpp KoMarkerItemDelegate.cpp KoDocumentInfoDlg.cpp KoTableView.cpp WidgetsDebug.cpp kis_file_name_requester.cpp - kis_double_parse_spin_box.cpp - kis_double_parse_unit_spin_box.cpp - kis_int_parse_spin_box.cpp - KisColorSelectorInterface.cpp KoAnchorSelectionWidget.cpp KisGradientSlider.cpp KisGradientSliderWidget.cpp kis_color_input.cpp # classes used by internal color selector kis_spinbox_color_selector.cpp KisVisualColorSelector.cpp KisVisualColorSelectorShape.cpp KisVisualEllipticalSelectorShape.cpp KisVisualRectangleSelectorShape.cpp KisVisualTriangleSelectorShape.cpp KisScreenColorPickerBase.cpp KisDlgInternalColorSelector.cpp KisPaletteModel.cpp KisPaletteDelegate.cpp kis_palette_view.cpp KisPaletteListWidget.cpp KisPaletteComboBox.cpp kis_popup_button.cc kis_color_button.cpp ) ki18n_wrap_ui( kritawidgets_LIB_SRCS KoConfigAuthorPage.ui koDocumentInfoAboutWidget.ui koDocumentInfoAuthorWidget.ui wdg_file_name_requester.ui KoPageLayoutWidget.ui KoShadowConfigWidget.ui WdgDlgInternalColorSelector.ui WdgPaletteListWidget.ui ) add_library(kritawidgets SHARED ${kritawidgets_LIB_SRCS}) generate_export_header(kritawidgets BASE_NAME kritawidgets) target_link_libraries(kritawidgets kritaodf kritaglobal kritaflake kritapigment kritawidgetutils Qt5::PrintSupport KF5::CoreAddons KF5::ConfigGui KF5::GuiAddons KF5::WidgetsAddons KF5::ConfigCore KF5::Completion ) if(X11_FOUND) target_link_libraries(kritawidgets Qt5::X11Extras ${X11_LIBRARIES}) endif() set_target_properties(kritawidgets PROPERTIES VERSION ${GENERIC_KRITA_LIB_VERSION} SOVERSION ${GENERIC_KRITA_LIB_SOVERSION} ) install(TARGETS kritawidgets ${INSTALL_TARGETS_DEFAULT_ARGS}) diff --git a/libs/widgets/tests/CMakeLists.txt b/libs/widgets/tests/CMakeLists.txt index efa12a79c7..7cb62d2545 100644 --- a/libs/widgets/tests/CMakeLists.txt +++ b/libs/widgets/tests/CMakeLists.txt @@ -1,18 +1,17 @@ set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} ) add_definitions(-DFILES_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data/") add_definitions(-DFILES_OUTPUT_DIR="${CMAKE_CURRENT_BINARY_DIR}") #add_subdirectory(filedialogtester) include(ECMAddTests) include(KritaAddBrokenUnitTest) ecm_add_tests( zoomhandler_test.cpp zoomcontroller_test.cpp KoResourceTaggingTest.cpp - kis_parse_spin_boxes_test.cpp KoAnchorSelectionWidgetTest.cpp NAME_PREFIX "libs-widgets-" LINK_LIBRARIES kritawidgets Qt5::Test) diff --git a/libs/widgetutils/CMakeLists.txt b/libs/widgetutils/CMakeLists.txt index 6163a25966..23a80b3ee5 100644 --- a/libs/widgetutils/CMakeLists.txt +++ b/libs/widgetutils/CMakeLists.txt @@ -1,134 +1,137 @@ add_subdirectory(tests) configure_file(xmlgui/config-xmlgui.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-xmlgui.h ) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/config) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/xmlgui) set(kritawidgetutils_LIB_SRCS WidgetUtilsDebug.cpp kis_icon_utils.cpp kis_action_registry.cpp KisActionsSnapshot.cpp KoGroupButton.cpp KoProgressProxy.cpp KoFakeProgressProxy.cpp KoProgressBar.cpp KoProgressUpdater.cpp KoUpdater.cpp KoUpdaterPrivate_p.cpp KoProperties.cpp KoFileDialog.cpp KoResourcePaths.cpp KisKineticScroller.cpp KisSqueezedComboBox.cpp KisDialogStateSaver.cpp - + + kis_double_parse_spin_box.cpp + kis_double_parse_unit_spin_box.cpp + kis_int_parse_spin_box.cpp kis_num_parser.cpp kis_spin_box_unit_manager.cpp config/kcolorscheme.cpp config/kcolorschememanager.cpp config/khelpclient.cpp config/klanguagebutton.cpp config/krecentfilesaction.cpp config/kstandardaction.cpp xmlgui/KisShortcutsEditorItem.cpp xmlgui/KisShortcutEditWidget.cpp xmlgui/KisShortcutsEditorDelegate.cpp xmlgui/KisShortcutsDialog.cpp xmlgui/KisShortcutsDialog_p.cpp xmlgui/KisShortcutsEditor.cpp xmlgui/KisShortcutsEditor_p.cpp xmlgui/kshortcutschemeseditor.cpp xmlgui/kshortcutschemeshelper.cpp xmlgui/kaboutkdedialog_p.cpp xmlgui/kactioncategory.cpp xmlgui/kactioncollection.cpp xmlgui/kbugreport.cpp xmlgui/kcheckaccelerators.cpp xmlgui/kedittoolbar.cpp xmlgui/kgesture.cpp xmlgui/kgesturemap.cpp xmlgui/khelpmenu.cpp xmlgui/kkeysequencewidget.cpp xmlgui/kmainwindow.cpp xmlgui/kmenumenuhandler_p.cpp xmlgui/kshortcutwidget.cpp xmlgui/kswitchlanguagedialog_p.cpp xmlgui/ktoggletoolbaraction.cpp xmlgui/ktoolbar.cpp xmlgui/ktoolbarhandler.cpp xmlgui/kundoactions.cpp xmlgui/kxmlguibuilder.cpp xmlgui/kxmlguiclient.cpp xmlgui/kxmlguifactory.cpp xmlgui/kxmlguifactory_p.cpp xmlgui/kxmlguiversionhandler.cpp xmlgui/kxmlguiwindow.cpp ) if (HAVE_DBUS) set(kritawidgetutils_LIB_SRCS ${kritawidgetutils_LIB_SRCS} xmlgui/kmainwindowiface.cpp ) endif() ki18n_wrap_ui(kritawidgetutils_LIB_SRCS xmlgui/KisShortcutsDialog.ui xmlgui/kshortcutwidget.ui ) qt5_add_resources(kritawidgetutils_LIB_SRCS xmlgui/kxmlgui.qrc) add_library(kritawidgetutils SHARED ${kritawidgetutils_LIB_SRCS}) target_include_directories(kritawidgetutils PUBLIC $ $ ) generate_export_header(kritawidgetutils BASE_NAME kritawidgetutils) if (HAVE_DBUS) set (KRITA_WIDGET_UTILS_EXTRA_LIBS ${KRITA_WIDGET_UTILS_EXTRA_LIBS} Qt5::DBus) endif () if (APPLE) find_library(FOUNDATION_LIBRARY Foundation) set(KRITA_WIDGET_UTILS_EXTRA_LIBS ${KRITA_WIDGET_UTILS_EXTRA_LIBS} ${FOUNDATION_LIBRARY}) endif () target_link_libraries(kritawidgetutils PUBLIC Qt5::Widgets Qt5::Gui Qt5::Xml Qt5::Core KF5::ItemViews kritaglobal PRIVATE Qt5::PrintSupport KF5::I18n KF5::ConfigCore KF5::CoreAddons KF5::ConfigGui KF5::GuiAddons KF5::WidgetsAddons KF5::WindowSystem kritaplugin kritaodf ${KRITA_WIDGET_UTILS_EXTRA_LIBS} ) set_target_properties(kritawidgetutils PROPERTIES VERSION ${GENERIC_KRITA_LIB_VERSION} SOVERSION ${GENERIC_KRITA_LIB_SOVERSION} ) install(TARGETS kritawidgetutils ${INSTALL_TARGETS_DEFAULT_ARGS}) diff --git a/libs/widgetutils/KisDialogStateSaver.cpp b/libs/widgetutils/KisDialogStateSaver.cpp index 1dbf6c4328..1241f61345 100644 --- a/libs/widgetutils/KisDialogStateSaver.cpp +++ b/libs/widgetutils/KisDialogStateSaver.cpp @@ -1,138 +1,184 @@ /* * Copyright (c) 2019 Boudewijn Rempt * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "KisDialogStateSaver.h" #include #include #include #include #include #include #include #include #include +#include "kis_int_parse_spin_box.h" +#include "kis_double_parse_spin_box.h" +#include "kis_double_parse_unit_spin_box.h" + + void KisDialogStateSaver::saveState(QWidget *parent, const QString &dialogName) { Q_ASSERT(parent); Q_ASSERT(!dialogName.isEmpty()); KConfigGroup group(KSharedConfig::openConfig(), dialogName); Q_FOREACH(QWidget *widget, parent->findChildren(QString())) { - if (widget && !widget->objectName().isEmpty() ) { - if (qobject_cast(widget)) { + if (!widget->objectName().isEmpty() ) { + if (qobject_cast(widget)) { + group.writeEntry(widget->objectName(), qobject_cast(widget)->value()); + } + else if (qobject_cast(widget)) { + group.writeEntry(widget->objectName(), qobject_cast(widget)->value()); + } + else if (qobject_cast(widget)) { + // XXX: also save the unit + group.writeEntry(widget->objectName(), qobject_cast(widget)->value()); + } + else if (qobject_cast(widget)) { group.writeEntry(widget->objectName(), qobject_cast(widget)->isChecked()); } else if (qobject_cast(widget)) { group.writeEntry(widget->objectName(), qobject_cast(widget)->currentIndex()); } else if (qobject_cast(widget)) { group.writeEntry(widget->objectName(), qobject_cast(widget)->text()); } else if (qobject_cast(widget)) { group.writeEntry(widget->objectName(), qobject_cast(widget)->value()); } else if (qobject_cast(widget)) { group.writeEntry(widget->objectName(), qobject_cast(widget)->value()); } else if (qobject_cast(widget)) { group.writeEntry(widget->objectName(), qobject_cast(widget)->value()); } + else { - //qWarning() << "Cannot save state for object" << widget; + qWarning() << "Cannot save state for object" << widget; } - } + else { + qWarning() << "Dialog" << dialogName << "has a widget without an objectname:" << widget; + } + } } void KisDialogStateSaver::restoreState(QWidget *parent, const QString &dialogName, const QMap &defaults) { Q_ASSERT(parent); Q_ASSERT(!dialogName.isEmpty()); KConfigGroup group( KSharedConfig::openConfig(), dialogName); Q_FOREACH(QWidget *widget, parent->findChildren(QString())) { - if (widget && !widget->objectName().isEmpty()) { + if (!widget->objectName().isEmpty()) { QString widgetName = widget->objectName(); QVariant defaultValue; if (defaults.contains(widgetName)) { defaultValue = defaults[widgetName]; } - if (qobject_cast(widget)) { + if (qobject_cast(widget)) { + if (defaultValue.isValid()) { + qobject_cast(widget)->setValue(defaultValue.toInt()); + } + else { + qobject_cast(widget)->setValue(group.readEntry(widgetName, qobject_cast(widget)->value())); + } + } + else if (qobject_cast(widget)) { + if (defaultValue.isValid()) { + qobject_cast(widget)->setValue(defaultValue.toInt()); + } + else { + qobject_cast(widget)->setValue(group.readEntry(widgetName, qobject_cast(widget)->value())); + } + } + else if (qobject_cast(widget)) { + if (defaultValue.isValid()) { + qobject_cast(widget)->setValue(defaultValue.toInt()); + } + else { + qobject_cast(widget)->setValue(group.readEntry(widgetName, qobject_cast(widget)->value())); + } + } + else if (qobject_cast(widget)) { if (defaultValue.isValid()) { qobject_cast(widget)->setChecked(defaultValue.toBool()); } else { qobject_cast(widget)->setChecked(group.readEntry(widgetName, qobject_cast(widget)->isChecked())); } } else if (qobject_cast(widget)) { if (defaultValue.isValid()) { qobject_cast(widget)->setCurrentIndex(defaultValue.toInt()); } else { qobject_cast(widget)->setCurrentIndex(group.readEntry(widgetName, qobject_cast(widget)->currentIndex())); } } else if (qobject_cast(widget)) { if (defaultValue.isValid()) { qobject_cast(widget)->setText(defaultValue.toString()); } else { qobject_cast(widget)->setText(group.readEntry(widgetName, qobject_cast(widget)->text())); } } else if (qobject_cast(widget)) { if (defaultValue.isValid()) { qobject_cast(widget)->setValue(defaultValue.toInt()); } else { qobject_cast(widget)->setValue(group.readEntry(widgetName, qobject_cast(widget)->value())); } } else if (qobject_cast(widget)) { if (defaultValue.isValid()) { qobject_cast(widget)->setValue(defaultValue.toInt()); } else { qobject_cast(widget)->setValue(group.readEntry(widgetName, qobject_cast(widget)->value())); } } else if (qobject_cast(widget)) { if (defaultValue.isValid()) { qobject_cast(widget)->setValue(defaultValue.toDouble()); } else { qobject_cast(widget)->setValue(group.readEntry(widgetName, qobject_cast(widget)->value())); } } else { //qWarning() << "Cannot restore state for object" << widget; } } + else { + qWarning() << "Dialog" << dialogName << "has a widget without an object name:" << widget; + } } } diff --git a/libs/widgetutils/KisDialogStateSaver.h b/libs/widgetutils/KisDialogStateSaver.h index 78ee33260f..4b2a727ca7 100644 --- a/libs/widgetutils/KisDialogStateSaver.h +++ b/libs/widgetutils/KisDialogStateSaver.h @@ -1,55 +1,55 @@ /* * Copyright (c) 2019 Boudewijn Rempt * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KISDIALOGSTATESAVER_H #define KISDIALOGSTATESAVER_H #include "kritawidgetutils_export.h" #include #include #include #include /** * @brief The KisDialogStateSaver class saves state for the specified * widget in the kritarc file and restores it. Simply call saveState * in your dialog's destructor, and use restoreState in the constructor. */ namespace KisDialogStateSaver { /** * @brief saveState saves the state for the specified widgets * @param parent the parent at the top of the QObject hierarchy that contains the child widgets * @param dialogName the name for the section under which we will save the state * @return true if all the widgets could be saved, false if there was a problem */ KRITAWIDGETUTILS_EXPORT void saveState(QWidget *parent, const QString &dialogName); /** * @brief restoreState restores the state of the dialog * @param parent the parent at the top of the QObject hierarchy that contains the child widgets * @param dialogName the name for the section under which we will restore the state - * @param defaults: contains default values for widgets. If there are widgets for which no default - * has been specified, the default value created by QVariant will be used. - * in the variant part of the map. + * @param defaults: contains default values for widgets. This overrides what is stored in the config + * file. If there is no value in the config file, and no default specified, the value set for + * the widget (for instance in the ui file) will be used. * @return true if all the widgets could be restored, false if there was a problem */ KRITAWIDGETUTILS_EXPORT void restoreState(QWidget *parent, const QString &dialogName, const QMap &defaults = QMap()); }; #endif // KISDIALOGSTATESAVER_H diff --git a/libs/widgets/kis_double_parse_spin_box.cpp b/libs/widgetutils/kis_double_parse_spin_box.cpp similarity index 100% rename from libs/widgets/kis_double_parse_spin_box.cpp rename to libs/widgetutils/kis_double_parse_spin_box.cpp diff --git a/libs/widgets/kis_double_parse_spin_box.h b/libs/widgetutils/kis_double_parse_spin_box.h similarity index 96% rename from libs/widgets/kis_double_parse_spin_box.h rename to libs/widgetutils/kis_double_parse_spin_box.h index 42a5e9ca09..35ccea3e28 100644 --- a/libs/widgets/kis_double_parse_spin_box.h +++ b/libs/widgetutils/kis_double_parse_spin_box.h @@ -1,85 +1,85 @@ /* * Copyright (c) 2016 Laurent Valentin Jospin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KISDOUBLEPARSESPINBOX_H #define KISDOUBLEPARSESPINBOX_H #include -#include "kritawidgets_export.h" +#include "kritawidgetutils_export.h" class QLabel; /*! * \brief The KisDoubleParseSpinBox class is a cleverer doubleSpinBox, able to parse arithmetic expressions. * * Use this spinbox instead of the basic one from Qt if you want it to be able to parse arithmetic expressions. */ -class KRITAWIDGETS_EXPORT KisDoubleParseSpinBox : public QDoubleSpinBox +class KRITAWIDGETUTILS_EXPORT KisDoubleParseSpinBox : public QDoubleSpinBox { Q_OBJECT public: KisDoubleParseSpinBox(QWidget* parent = 0); ~KisDoubleParseSpinBox() override; //KisDoubleParseSpinBox may be used polymorphycally as a QDoubleSpinBox. double valueFromText(const QString & text) const override; QString textFromValue(double val) const override; QValidator::State validate ( QString & input, int & pos ) const override; void stepBy(int steps) override; void setValue(double value); //polymorphism won't work directly, we use a signal/slot hack to do so but if signals are disabled this function will still be useful. bool isLastValid() const{ return boolLastValid; } //! \brief this virtual function is similar to cleanText(); for KisDoubleParseSpinBox. But child class may remove additional artifacts. virtual QString veryCleanText() const; Q_SIGNALS: //! \brief signal emitted when the last parsed expression creates an error. void errorWhileParsing(QString expr) const; //! \brief signal emitted when the last parsed expression is valid. void noMoreParsingError() const; public Q_SLOTS: //! \brief useful to let the widget change its stylesheet when an error occurred in the last expression. void setErrorStyle(); //! \brief useful to let the widget reset its stylesheet when there's no more error. void clearErrorStyle(); //! \brief say the widget to return to an error free state. void clearError(); protected: mutable bool boolLastValid; mutable double oldValue; mutable QString lastExprParsed; QLabel* warningIcon; QPalette oldPalette; bool isOldPaletteSaved; QMargins oldMargins; bool areOldMarginsSaved; }; #endif // KISDOUBLEPARSESPINBOX_H diff --git a/libs/widgets/kis_double_parse_unit_spin_box.cpp b/libs/widgetutils/kis_double_parse_unit_spin_box.cpp similarity index 100% rename from libs/widgets/kis_double_parse_unit_spin_box.cpp rename to libs/widgetutils/kis_double_parse_unit_spin_box.cpp diff --git a/libs/widgets/kis_double_parse_unit_spin_box.h b/libs/widgetutils/kis_double_parse_unit_spin_box.h similarity index 97% rename from libs/widgets/kis_double_parse_unit_spin_box.h rename to libs/widgetutils/kis_double_parse_unit_spin_box.h index 35fad9e068..1652512647 100644 --- a/libs/widgets/kis_double_parse_unit_spin_box.h +++ b/libs/widgetutils/kis_double_parse_unit_spin_box.h @@ -1,139 +1,139 @@ /* * Copyright (c) 2016 Laurent Valentin Jospin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KIS_DOUBLEPARSEUNITSPINBOX_H #define KIS_DOUBLEPARSEUNITSPINBOX_H #include #include "kis_double_parse_spin_box.h" -#include "kritawidgets_export.h" +#include "kritawidgetutils_export.h" class KisSpinBoxUnitManager; /*! * \brief The KisDoubleParseUnitSpinBox class is an evolution of the \see KoUnitDoubleSpinBox, but inherit from \see KisDoubleParseSpinBox to be able to parse math expressions. * * This class store the */ -class KRITAWIDGETS_EXPORT KisDoubleParseUnitSpinBox : public KisDoubleParseSpinBox +class KRITAWIDGETUTILS_EXPORT KisDoubleParseUnitSpinBox : public KisDoubleParseSpinBox { Q_OBJECT public: KisDoubleParseUnitSpinBox(QWidget* parent = 0); ~KisDoubleParseUnitSpinBox() override; void setUnitManager(KisSpinBoxUnitManager* unitManager); /** * Set the new value in points (or other reference unit) which will then be converted to the current unit for display * @param newValue the new value * @see value() */ virtual void changeValue( double newValue ); /** * This spinbox shows the internal value after a conversion to the unit set here. */ virtual void setUnit(const KoUnit &unit); virtual void setUnit(const QString & symbol); /*! * \brief setReturnUnit set a unit, such that the spinbox now return values in this unit instead of the reference unit for the current dimension. * \param symbol the symbol of the new unit. */ void setReturnUnit(const QString & symbol); /** * @brief setDimensionType set the dimension (for example length or angle) of the units the spinbox manage * @param dim the dimension id. (if not an id in KisSpinBoxUnitManager::UnitDimension, then the function does nothing). */ virtual void setDimensionType(int dim); /// @return the current value, converted in points double value( ) const; /// Set minimum value in points. void setMinimum(double min); /// Set maximum value in points. void setMaximum(double max); /// Set step size in the current unit. void setLineStep(double step); /// Set step size in points. void setLineStepPt(double step); /// Set minimum, maximum value and the step size (all in points) void setMinMaxStep( double min, double max, double step ); /// reimplemented from superclass, will forward to KoUnitDoubleValidator QValidator::State validate(QString &input, int &pos) const override; /** * Transform the double in a nice text, using locale symbols * @param value the number as double * @return the resulting string */ QString textFromValue( double value ) const override; //! \brief get the text in the spinbox without prefix or suffix, and remove unit symbol if present. QString veryCleanText() const override; /** * Transform a string into a double, while taking care of locale specific symbols. * @param str the string to transform into a number * @return the value as double */ double valueFromText( const QString& str ) const override; void setUnitChangeFromOutsideBehavior(bool toggle); //if set to false, setting the unit using KoUnit won't have any effect. //! \brief display the unit symbol in the spinbox or not. For example if the unit is displayed in a combobox connected to the unit manager. void setDisplayUnit(bool toggle); void preventDecimalsChangeFromUnitManager(bool prevent); Q_SIGNALS: /// emitted like valueChanged in the parent, but this one emits the point value, or converted to another reference unit. void valueChangedPt( qreal ); private: class Private; Private * const d; QString detectUnit(); QString makeTextClean(QString const& txt) const; //those functions are useful to sync the spinbox with its unitmanager. //! \brief change the unit, reset the spin box every time. From the outside it's always set unit that should be called. void internalUnitChange(QString const& symbol); void prepareUnitChange(); private Q_SLOTS: // exists to do emits for valueChangedPt void privateValueChanged(); void detectUnitChanges(); void disconnectExternalUnitManager(); }; #endif // KIS_DOUBLEPARSEUNITSPINBOX_H diff --git a/libs/widgets/kis_int_parse_spin_box.cpp b/libs/widgetutils/kis_int_parse_spin_box.cpp similarity index 100% rename from libs/widgets/kis_int_parse_spin_box.cpp rename to libs/widgetutils/kis_int_parse_spin_box.cpp diff --git a/libs/widgets/kis_int_parse_spin_box.h b/libs/widgetutils/kis_int_parse_spin_box.h similarity index 96% rename from libs/widgets/kis_int_parse_spin_box.h rename to libs/widgetutils/kis_int_parse_spin_box.h index 887b099a2b..2e43f70431 100644 --- a/libs/widgets/kis_int_parse_spin_box.h +++ b/libs/widgetutils/kis_int_parse_spin_box.h @@ -1,82 +1,82 @@ /* * Copyright (c) 2016 Laurent Valentin Jospin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KISINTPARSESPINBOX_H #define KISINTPARSESPINBOX_H #include -#include "kritawidgets_export.h" +#include "kritawidgetutils_export.h" class QLabel; /*! * \brief The KisDoubleParseSpinBox class is a cleverer doubleSpinBox, able to parse arithmetic expressions. * * Use this spinbox instead of the basic one from Qt if you want it to be able to parse arithmetic expressions. */ -class KRITAWIDGETS_EXPORT KisIntParseSpinBox : public QSpinBox +class KRITAWIDGETUTILS_EXPORT KisIntParseSpinBox : public QSpinBox { Q_OBJECT public: KisIntParseSpinBox(QWidget *parent = 0); ~KisIntParseSpinBox() override; int valueFromText(const QString & text) const override; QString textFromValue(int val) const override; QValidator::State validate ( QString & input, int & pos ) const override; void stepBy(int steps) override; void setValue(int val); //polymorphism won't work directly, we use a signal/slot hack to do so but if signals are disabled this function will still be useful. bool isLastValid() const{ return boolLastValid; } Q_SIGNALS: //! \brief signal emitted when the last parsed expression create an error. void errorWhileParsing(QString expr) const; //! \brief signal emitted when the last parsed expression is valid. void noMoreParsingError() const; public Q_SLOTS: //! \brief useful to let the widget change it's stylesheet when an error occurred in the last expression. void setErrorStyle(); //! \brief useful to let the widget reset it's stylesheet when there's no more error. void clearErrorStyle(); //! \brief say the widget to return to an error free state. void clearError(); protected: mutable QString* lastExprParsed; mutable bool boolLastValid; mutable int oldVal; //store the last correctly evaluated value. QLabel* warningIcon; QPalette oldPalette; bool isOldPaletteSaved; QMargins oldMargins; bool areOldMarginsSaved; }; #endif // KISINTPARSESPINBOX_H diff --git a/libs/widgetutils/tests/CMakeLists.txt b/libs/widgetutils/tests/CMakeLists.txt index 5a05fe2d82..e33a08c245 100644 --- a/libs/widgetutils/tests/CMakeLists.txt +++ b/libs/widgetutils/tests/CMakeLists.txt @@ -1,29 +1,30 @@ set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} ) include_directories ( ${CMAKE_SOURCE_DIR}/libs/widgetutils ${CMAKE_SOURCE_DIR}/sdk/tests ) include(ECMAddTests) ecm_add_tests( KisActionsSnapshotTest.cpp KoPropertiesTest.cpp kis_simple_math_parser_test.cpp # FIXME this test should be in the ui directory TestKoProgressUpdater.cpp TestSqueezedComboBox.cpp + kis_parse_spin_boxes_test.cpp NAME_PREFIX "libs-widgetutils-" LINK_LIBRARIES kritawidgetutils kritaimage Qt5::Test ) ki18n_wrap_ui(DialogStateSaver_SRCS dialogsavertestwidget.ui ) ecm_add_test( KisDialogStateSaverTest.cpp ${DialogStateSaver_SRCS} TEST_NAME KisDialogStateSaverTest LINK_LIBRARIES kritawidgetutils Qt5::Test KF5::ConfigCore NAME_PREFIX "libs-widgetutils-") diff --git a/libs/widgets/tests/kis_parse_spin_boxes_test.cpp b/libs/widgetutils/tests/kis_parse_spin_boxes_test.cpp similarity index 100% rename from libs/widgets/tests/kis_parse_spin_boxes_test.cpp rename to libs/widgetutils/tests/kis_parse_spin_boxes_test.cpp diff --git a/libs/widgets/tests/kis_parse_spin_boxes_test.h b/libs/widgetutils/tests/kis_parse_spin_boxes_test.h similarity index 100% rename from libs/widgets/tests/kis_parse_spin_boxes_test.h rename to libs/widgetutils/tests/kis_parse_spin_boxes_test.h