File indexing completed on 2024-12-22 04:13:17
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 #ifndef KISSCREENCOLORSAMPLER_H 0007 #define KISSCREENCOLORSAMPLER_H 0008 0009 #include <QScopedPointer> 0010 #include <QEvent> 0011 #include <QMouseEvent> 0012 0013 #include "KoColor.h" 0014 #include <KisScreenColorSamplerBase.h> 0015 0016 #include "kritaui_export.h" 0017 0018 /** 0019 * @brief The KisScreenColorSampler class 0020 * Based on the original QColorDialog's screen color picker, this class provides a button 0021 * that can be used to activate a color sampler that can sample from anywhere on the screen. 0022 */ 0023 class KRITAUI_EXPORT KisScreenColorSampler : public KisScreenColorSamplerBase 0024 { 0025 Q_OBJECT 0026 public: 0027 explicit KisScreenColorSampler(bool showInfoLabel = false, QWidget *parent = 0); 0028 ~KisScreenColorSampler() override; 0029 0030 KoColor currentColor(); 0031 0032 bool handleColorSamplingMouseMove(QMouseEvent *e); 0033 bool handleColorSamplingMouseButtonRelease(QMouseEvent *e); 0034 bool handleColorSamplingKeyPress(QKeyEvent *e); 0035 0036 /// reloads icon(s) when theme is updated 0037 void updateIcons() override; 0038 0039 bool performRealColorSamplingOfCanvas() const; 0040 0041 static KisScreenColorSampler *createScreenColorSampler(QWidget *parent = 0) {return new KisScreenColorSampler(parent);} 0042 0043 Q_SIGNALS: 0044 void sigNewColorSampled(KoColor c); 0045 void sigNewColorHovered(KoColor c); 0046 0047 public Q_SLOTS: 0048 void sampleScreenColor(); 0049 void setPerformRealColorSamplingOfCanvas(bool enable); 0050 void setCurrentColor(KoColor c); 0051 0052 private Q_SLOTS: 0053 void updateColorSampling(); 0054 protected: 0055 void changeEvent(QEvent *event) override; 0056 private: 0057 struct Private; //The private struct 0058 const QScopedPointer<Private> m_d; //the private pointer 0059 0060 KoColor grabScreenColor(const QPoint &p); 0061 void updateColorLabelText(const QPoint &globalPos); 0062 void releaseColorSampling(); 0063 void continueUpdateColorSampling(const QPoint &globalPos); 0064 }; 0065 0066 class KisScreenColorSamplingEventFilter : public QObject { 0067 public: 0068 explicit KisScreenColorSamplingEventFilter(KisScreenColorSampler *w, QObject *parent = 0); 0069 0070 bool eventFilter(QObject *, QEvent *event) override; 0071 private: 0072 KisScreenColorSampler *m_w; 0073 }; 0074 0075 #endif // KISSCREENCOLORSAMPLER_H