diff --git a/libs/widgets/CMakeLists.txt b/libs/widgets/CMakeLists.txt index 73b775a6b9..0f02994eeb 100644 --- a/libs/widgets/CMakeLists.txt +++ b/libs/widgets/CMakeLists.txt @@ -1,118 +1,119 @@ add_subdirectory( tests ) include_directories(${CMAKE_CURRENT_BINARY_DIR}) set(kritawidgets_LIB_SRCS KoVBox.cpp KoDialog.cpp KoZoomWidget.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 KoRuler.cpp KoResourceServerProvider.cpp KoLineStyleSelector.cpp KoLineStyleItemDelegate.cpp KoLineStyleModel.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 WidgetsDebug.cpp kis_file_name_requester.cpp KisColorSelectorInterface.cpp KoAnchorSelectionWidget.cpp KisGradientSlider.cpp KisGradientSliderWidget.cpp kis_color_input.cpp # classes used by internal color selector kis_spinbox_color_selector.cpp + KisSpinboxHSXSelector.cpp KisVisualColorSelector.cpp KisVisualColorSelectorShape.cpp KisVisualEllipticalSelectorShape.cpp KisVisualRectangleSelectorShape.cpp KisVisualTriangleSelectorShape.cpp KisScreenColorPickerBase.cpp KisDlgInternalColorSelector.cpp KisPaletteModel.cpp KisPaletteDelegate.cpp kis_palette_view.cpp KisPaletteChooser.cpp KisPaletteComboBox.cpp 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 kritaresources kritaresourcewidgets 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/KisSpinboxHSXSelector.cpp b/libs/widgets/KisSpinboxHSXSelector.cpp new file mode 100644 index 0000000000..fb7502ab62 --- /dev/null +++ b/libs/widgets/KisSpinboxHSXSelector.cpp @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2020 Mathias Wein + * + * 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 "KisSpinboxHSXSelector.h" + +#include +#include +#include +#include +#include "kis_double_parse_spin_box.h" +#include "KisVisualColorSelector.h" + +struct KisSpinboxHSXSelector::Private +{ + QList labels; + QList spinBoxes; + QFormLayout *layout {0}; +}; + +KisSpinboxHSXSelector::KisSpinboxHSXSelector(QWidget *parent) + : QWidget(parent) + , m_d(new Private) +{ + m_d->layout = new QFormLayout(this); + for (int i = 0; i < 3; i++){ + m_d->labels.push_back(new QLabel(this)); + m_d->spinBoxes.push_back(new KisDoubleParseSpinBox(this)); + m_d->layout->addRow(m_d->labels[i], m_d->spinBoxes[i]); + connect(m_d->spinBoxes.back(), SIGNAL(valueChanged(double)), this, SLOT(slotSpinBoxChanged())); + } + m_d->labels[0]->setText(i18n("Hue:")); + m_d->labels[1]->setText(i18n("Saturation:")); + m_d->labels[2]->setText(":"); + m_d->spinBoxes[0]->setMaximum(360.0); + m_d->spinBoxes[1]->setMaximum(100.0); + m_d->spinBoxes[2]->setMaximum(100.0); + m_d->spinBoxes[0]->setSuffix(" °"); + m_d->spinBoxes[1]->setSuffix(" %"); + m_d->spinBoxes[2]->setSuffix(" %"); +} + +KisSpinboxHSXSelector::~KisSpinboxHSXSelector() +{ +} + +void KisSpinboxHSXSelector::attachToSelector(KisVisualColorSelector *selector) +{ + connect(selector, SIGNAL(sigColorModelChanged()), this, SLOT(slotColorModelChanged())); + connect(selector, SIGNAL(sigHSXChanged(QVector3D)), this, SLOT(slotHSXChanged(QVector3D))); + connect(this, SIGNAL(sigHSXChanged(QVector3D)), selector, SLOT(slotSetHSX(QVector3D))); +} + +void KisSpinboxHSXSelector::slotColorModelChanged() +{ + const KisVisualColorSelector *selector = qobject_cast(sender()); + if (!selector) { + return; + } + + switch (selector->getColorModel()) { + case KisVisualColorSelector::HSV: + m_d->labels[2]->setText(i18n("Value:")); + break; + case KisVisualColorSelector::HSL: + m_d->labels[2]->setText(i18n("Lightness:")); + break; + case KisVisualColorSelector::HSI: + m_d->labels[2]->setText(i18n("Intensity:")); + break; + case KisVisualColorSelector::HSY: + m_d->labels[2]->setText(i18n("Luma:")); + break; + default: + break; + } +} + +void KisSpinboxHSXSelector::slotHSXChanged(const QVector3D &hsx) +{ + const QSignalBlocker s1(m_d->spinBoxes[0]), s2(m_d->spinBoxes[1]), s3(m_d->spinBoxes[2]); + m_d->spinBoxes[0]->setValue(hsx[0] * 360.0); + m_d->spinBoxes[1]->setValue(hsx[1] * 100.0); + m_d->spinBoxes[2]->setValue(hsx[2] * 100.0); +} + +void KisSpinboxHSXSelector::slotSpinBoxChanged() +{ + QVector3D hsx(m_d->spinBoxes[0]->value() / 360.0, + m_d->spinBoxes[1]->value() / 100.0, + m_d->spinBoxes[2]->value() / 100.0); + emit sigHSXChanged(hsx); +} diff --git a/libs/widgets/KisSpinboxHSXSelector.h b/libs/widgets/KisSpinboxHSXSelector.h new file mode 100644 index 0000000000..58d002354b --- /dev/null +++ b/libs/widgets/KisSpinboxHSXSelector.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2020 Mathias Wein + * + * 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 KISSPINBOXHSXSELECTOR_H +#define KISSPINBOXHSXSELECTOR_H + +#include +#include +#include "kritawidgets_export.h" +#include + +class KisVisualColorSelector; + +/** + * A set of spinboxes to adjust HSV, HSL, HSI or HSY' values. + * This class is meant to be used in conjunction with KisVisualColorSelector only. + */ + +class KRITAWIDGETS_EXPORT KisSpinboxHSXSelector : public QWidget +{ + Q_OBJECT +public: + explicit KisSpinboxHSXSelector(QWidget *parent = nullptr); + ~KisSpinboxHSXSelector() override; + + /** + * @brief connect signals and slots with given selector to + * synchronize value and color model changes. + * + * Note: in case the selector switches to a non-HSX color model, + * it needs to be deactivated or hidden manually since it will + * not synchronize values for other selector models. + */ + void attachToSelector(KisVisualColorSelector *selector); + +Q_SIGNALS: + void sigHSXChanged(const QVector3D &hsx); + +public Q_SLOTS: + void slotColorModelChanged(); + void slotHSXChanged(const QVector3D &hsx); +private Q_SLOTS: + void slotSpinBoxChanged(); +private: + struct Private; + const QScopedPointer m_d; +}; + +#endif // KISSPINBOXHSXSELECTOR_H