Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
/*
* SPDX-FileCopyrightText: 2016 Wolthera van Hovell tot Westerflier <[email protected]>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef KISSCREENCOLORSAMPLER_H
#define KISSCREENCOLORSAMPLER_H
#include <QScopedPointer>
#include <QEvent>
#include <QMouseEvent>
#include "KoColor.h"
#include <KisScreenColorSamplerBase.h>
#include "kritaui_export.h"
/**
* @brief The KisScreenColorSampler class
* Based on the original QColorDialog's screen color picker, this class provides a button
* that can be used to activate a color sampler that can sample from anywhere on the screen.
*/
class KRITAUI_EXPORT KisScreenColorSampler : public KisScreenColorSamplerBase
{
Q_OBJECT
public:
explicit KisScreenColorSampler(bool showInfoLabel = false, QWidget *parent = 0);
~KisScreenColorSampler() override;
KoColor currentColor();
bool handleColorSamplingMouseMove(QMouseEvent *e);
bool handleColorSamplingMouseButtonRelease(QMouseEvent *e);
bool handleColorSamplingKeyPress(QKeyEvent *e);
/// reloads icon(s) when theme is updated
void updateIcons() override;
bool performRealColorSamplingOfCanvas() const;
static KisScreenColorSampler *createScreenColorSampler(QWidget *parent = 0) {return new KisScreenColorSampler(parent);}
Q_SIGNALS:
void sigNewColorSampled(KoColor c);
void sigNewColorHovered(KoColor c);
public Q_SLOTS:
void sampleScreenColor();
void setPerformRealColorSamplingOfCanvas(bool enable);
void setCurrentColor(KoColor c);
void cancel();
private Q_SLOTS:
void updateColorSampling();
protected:
void changeEvent(QEvent *event) override;
private:
struct Private; //The private struct
const QScopedPointer<Private> m_d; //the private pointer
KoColor grabScreenColor(const QPoint &p);
void updateColorLabelText(const QPoint &globalPos);
void releaseColorSampling();
void continueUpdateColorSampling(const QPoint &globalPos);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
bool tryToUsePlatformIntegration();
private Q_SLOTS:
void colorPicked(const QColor &color);
#endif
};
class KisScreenColorSamplingEventFilter : public QObject {
public:
explicit KisScreenColorSamplingEventFilter(KisScreenColorSampler *w, QObject *parent = 0);
bool eventFilter(QObject *, QEvent *event) override;
private:
KisScreenColorSampler *m_w;
};
#endif // KISSCREENCOLORSAMPLER_H