8#include <QGuiApplication>
49 QTimer *updateTimer = 0;
50 QWindow dummyTransparentWindow;
61 QVBoxLayout *layout =
new QVBoxLayout(
this);
62 m_d->screenColorSamplerButton =
new QPushButton();
64 m_d->screenColorSamplerButton->setMinimumHeight(25);
65 layout->addWidget(
m_d->screenColorSamplerButton);
68 m_d->lblScreenColorInfo =
new QLabel(QLatin1String(
"\n"));
69 layout->addWidget(
m_d->lblScreenColorInfo);
72 layout->setContentsMargins(0, 0, 0, 0);
79 m_d->updateTimer =
new QTimer(
this);
80 m_d->dummyTransparentWindow.resize(1, 1);
81 m_d->dummyTransparentWindow.setFlags(Qt::Tool | Qt::FramelessWindowHint);
92 m_d->screenColorSamplerButton->setIcon(
kisIcon(
"krita_tool_color_sampler"));
97 return m_d->currentColor;
102 return m_d->performRealColorSamplingOfCanvas;
107 m_d->performRealColorSamplingOfCanvas = enable;
112 m_d->updateInputGrabberWidget();
113 if (
m_d->inputGrabberWidget ==
nullptr) {
118 if (!
m_d->colorSamplingEventFilter) {
121 m_d->inputGrabberWidget->installEventFilter(
m_d->colorSamplingEventFilter);
124 m_d->inputGrabberWidget->grabMouse(Qt::CrossCursor);
128 m_d->updateTimer->start(30);
133 m_d->dummyTransparentWindow.show();
135 m_d->inputGrabberWidget->grabKeyboard();
139 m_d->inputGrabberWidget->setMouseTracking(
true);
141 m_d->screenColorSamplerButton->setDisabled(
true);
143 const QPoint globalPos = QCursor::pos();
150 m_d->currentColor = c;
163 if (
m_d->performRealColorSamplingOfCanvas) {
167 QPoint widgetPoint = canvasWidget->mapFromGlobal(
p);
169 if (canvasWidget->visibleRegion().contains(widgetPoint)) {
178 QColor color = referenceImageLayer->getPixel(imagePoint);
179 if (color.isValid()) {
187 image->
projection()->
pixel(imagePoint.x(), imagePoint.y(), &sampledColor);
195 QScreen *targetScreen = QGuiApplication::screenAt(
p);
198 const QPoint screenPos =
p - targetScreen->geometry().topLeft();
200 QImage grabImage = targetScreen->grabWindow(0, screenPos.x(), screenPos.y(), 1, 1).toImage();
201 col.
fromQColor(QColor::fromRgb(grabImage.pixel(0, 0)));
209 if (
m_d->lblScreenColorInfo) {
212 QString location = QString::number(globalPos.x())+QString(
", ")+QString::number(globalPos.y());
213 m_d->lblScreenColorInfo->setWordWrap(
true);
214 m_d->lblScreenColorInfo->setText(location+QString(
": ")+colname);
237 if (e->matches(QKeySequence::Cancel)) {
239 }
else if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
253 m_d->inputGrabberWidget->removeEventFilter(
m_d->colorSamplingEventFilter);
254 m_d->inputGrabberWidget->releaseMouse();
256 m_d->updateTimer->stop();
257 m_d->dummyTransparentWindow.setVisible(
false);
259 m_d->inputGrabberWidget->releaseKeyboard();
260 m_d->inputGrabberWidget->setMouseTracking(
false);
262 if (
m_d->lblScreenColorInfo) {
263 m_d->lblScreenColorInfo->setText(QLatin1String(
"\n"));
266 m_d->screenColorSamplerButton->setDisabled(
false);
271 QWidget::changeEvent(e);
276 static QPoint lastGlobalPos;
277 QPoint newGlobalPos = QCursor::pos();
278 if (lastGlobalPos == newGlobalPos)
280 lastGlobalPos = newGlobalPos;
282 if (!
rect().contains(mapFromGlobal(newGlobalPos))) {
285 m_d->dummyTransparentWindow.setPosition(newGlobalPos);
308 switch (event->type()) {
309 case QEvent::MouseMove:
311 case QEvent::MouseButtonRelease:
313 case QEvent::KeyPress:
KIS_DECLARE_STATIC_INITIALIZER
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
KisReferenceImagesDecorationSP referenceImagesDecoration() const
KisCoordinatesConverter * coordinatesConverter
KisAbstractCanvasWidget * canvasWidget
_Private::Traits< T >::Result widgetToImage(const T &obj) const
static void setScreenColorSamplerFactory(std::function< KisScreenColorSamplerBase *(QWidget *)> f)
static KisGrabKeyboardFocusRecoveryWorkaround * instance()
const KoColorSpace * colorSpace() const
WrapAroundAxis wrapAroundModeAxis() const
KisPaintDeviceSP projection() const
QRect bounds() const override
bool wrapAroundModePermitted() const
bool pixel(qint32 x, qint32 y, QColor *c) const
static KisPart * instance()
The KisScreenColorSampler class Based on the original QColorDialog's screen color picker,...
void sigNewColorHovered(KoColor c)
void changeEvent(QEvent *event) override
const QScopedPointer< Private > m_d
void sigNewColorSampled(KoColor c)
void updateColorSampling()
void setPerformRealColorSamplingOfCanvas(bool enable)
void updateColorLabelText(const QPoint &globalPos)
KisScreenColorSampler(bool showInfoLabel=false, QWidget *parent=0)
void continueUpdateColorSampling(const QPoint &globalPos)
bool handleColorSamplingMouseMove(QMouseEvent *e)
KoColor grabScreenColor(const QPoint &p)
void updateIcons() override
reloads icon(s) when theme is updated
void releaseColorSampling()
bool performRealColorSamplingOfCanvas() const
void setCurrentColor(KoColor c)
~KisScreenColorSampler() override
bool handleColorSamplingMouseButtonRelease(QMouseEvent *e)
bool handleColorSamplingKeyPress(QKeyEvent *e)
static KisScreenColorSampler * createScreenColorSampler(QWidget *parent=0)
bool eventFilter(QObject *, QEvent *event) override
KisScreenColorSamplingEventFilter(KisScreenColorSampler *w, QObject *parent=0)
KisScreenColorSampler * m_w
KisCanvas2 * canvasBase() const
KisImageWSP image() const
QPointer< KisDocument > document
static QString toQString(const KoColor &color)
toQString create a user-visible string of the channel names and the channel values
void fromQColor(const QColor &c)
Convenient function for converting from a QColor.
KoColor beforeScreenColorSampling
QWidget * inputGrabberWidget
KisScreenColorSamplingEventFilter * colorSamplingEventFilter
QLabel * lblScreenColorInfo
void updateInputGrabberWidget()
QPushButton * screenColorSamplerButton
bool performRealColorSamplingOfCanvas
static QPoint ptToWrappedPt(QPoint pt, const QRect &wrapRect, WrapAroundAxis wrapAxis)