File indexing completed on 2024-05-12 16:02:02

0001 /*
0002  * SPDX-FileCopyrightText: 2016 Wolthera van Hovell tot Westerflier <griffinvalley@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef KISDLGINTERNALCOLORSELECTOR_H
0008 #define KISDLGINTERNALCOLORSELECTOR_H
0009 
0010 #include "kritawidgets_export.h"
0011 #include "KoColor.h"
0012 #include "KoColorSpace.h"
0013 #include "KoColorDisplayRendererInterface.h"
0014 #include "KoColorSet.h"
0015 
0016 #include <QScopedPointer>
0017 #include <QDialog>
0018 
0019 #include "KisScreenColorSamplerBase.h"
0020 
0021 class Ui_WdgDlgInternalColorSelector;
0022 class KoColorPatch;
0023 
0024 /**
0025  * @brief The KisInternalColorSelector class
0026  *
0027  * A non-modal color selector dialog that is not a plugin and can thus be used for filters.
0028  */
0029 class KRITAWIDGETS_EXPORT KisDlgInternalColorSelector : public QDialog
0030 {
0031     Q_OBJECT
0032 
0033     static std::function<KisScreenColorSamplerBase *(QWidget *)> s_screenColorSamplerFactory;
0034 
0035 public:
0036 
0037     static void setScreenColorSamplerFactory(std::function<KisScreenColorSamplerBase *(QWidget *)> f) {
0038         s_screenColorSamplerFactory = f;
0039     }
0040 
0041     struct Config
0042     {
0043         Config() :
0044             modal(true),
0045             visualColorSelector(true),
0046             paletteBox(true),
0047             screenColorSampler(true),
0048             prevNextButtons(true),
0049             hexInput(true),
0050             useAlpha(false){}
0051         bool modal;
0052         bool visualColorSelector;
0053         bool paletteBox;
0054         bool screenColorSampler;
0055         bool prevNextButtons;
0056         bool hexInput;
0057         bool useAlpha;
0058     };
0059 
0060     KisDlgInternalColorSelector(QWidget* parent, KoColor color, Config config, const QString &caption, const KoColorDisplayRendererInterface *displayRenderer = KoDumbColorDisplayRenderer::instance());
0061     ~KisDlgInternalColorSelector() override;
0062 
0063     /**
0064      * @brief slotColorSpaceChanged
0065      * Color space has changed, use this dialog to change the colorspace.
0066      */
0067     void colorSpaceChanged(const KoColorSpace *cs);
0068 
0069     /**
0070      * @brief lockUsedColorSpace
0071      * Lock the used colorspace of this selector.
0072      * @param cs
0073      */
0074     void lockUsedColorSpace(const KoColorSpace *cs);
0075 
0076     /**
0077      * @brief setDisplayRenderer
0078      * Set the display renderer. This is necessary for HDR color manage support.
0079      * @param displayRenderer
0080      */
0081     void setDisplayRenderer(const KoColorDisplayRendererInterface *displayRenderer);
0082 
0083     /**
0084      * @brief getModalColorDialog
0085      * Execute this dialog modally. The function returns
0086      * the KoColor you want.
0087      * @param color - The current color. Make sure this is in the color space you want your
0088      * end color to be in.
0089      * @param parent parent widget.
0090      * @param caption the dialog caption.
0091      */
0092     static KoColor getModalColorDialog(const KoColor color, QWidget* parent = 0, QString caption = QString());
0093 
0094     /**
0095      * @brief getCurrentColor
0096      * @return gives currently active color;
0097      */
0098     KoColor getCurrentColor();
0099 
0100     void chooseAlpha(bool chooseAlpha);
0101 
0102 Q_SIGNALS:
0103     /**
0104      * @brief signalForegroundColorChosen
0105      * The most important signal. This will sent out when a color has been chosen from the selector.
0106      * There will be a small delay to make sure that the selector causes too many updates.
0107      *
0108      * Do not connect this to slotColorUpdated.
0109      * @param color The new color chosen
0110      */
0111 
0112     void signalForegroundColorChosen(KoColor color);
0113 
0114 public Q_SLOTS:
0115     /**
0116      * @brief slotColorUpdated
0117      * Very important slot. Is connected to krita's resources to make sure it has
0118      * the currently active color. It's very important that this function is able to understand
0119      * when the signal came from itself.
0120      * @param newColor This is the new color.
0121      */
0122     void slotColorUpdated(KoColor newColor);
0123 
0124     /**
0125     * @brief slotSetColorFromPatch
0126     * update current color from kocolorpatch.
0127     * @param patch
0128     */
0129     void slotSetColorFromPatch(KoColorPatch* patch);
0130 
0131     /**
0132      * @brief setPreviousColor
0133      * set the previous color.
0134      */
0135     void setPreviousColor(KoColor c);
0136 
0137     void reject() override;
0138 
0139 private Q_SLOTS:
0140 
0141     void slotSelectorModelChanged();
0142     void endUpdateWithNewColor();
0143 
0144     /**
0145      * @brief slotFinishUp
0146      * This is called when the selector is closed, for saving the current palette.
0147      */
0148     void slotFinishUp();
0149 
0150     /**
0151      * @brief slotSetColorFromHex
0152      * Update from the hex color input.
0153      */
0154     void slotSetColorFromHex();
0155 
0156     void slotChangePalette(KoColorSetSP set);
0157 
0158 protected:
0159     void showEvent(QShowEvent *event) override;
0160 
0161 private:
0162     void focusInEvent(QFocusEvent *) override;
0163     /**
0164      * @brief updateAllElements
0165      * Updates each widget with the new element, and if it's responsible for the update sents
0166      * a signal out that there's a new color.
0167      */
0168     void updateAllElements(QObject *source);
0169 
0170 private:
0171     Ui_WdgDlgInternalColorSelector *m_ui;
0172     struct Private; //The private struct
0173     const QScopedPointer<Private> m_d; //the private pointer
0174 };
0175 
0176 #endif // KISDLGINTERNALCOLORSELECTOR_H