Fix deprecated color capture in color picker

CCBUG: 357516
parent 59e35b84
...@@ -24,12 +24,14 @@ ...@@ -24,12 +24,14 @@
#include <QMouseEvent> #include <QMouseEvent>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QToolButton> #include <QToolButton>
#include <QScreen>
#include <QDesktopWidget> #include <QDesktopWidget>
#include <QFrame> #include <QFrame>
#include <QApplication> #include <QApplication>
#include <QTimer> #include <QTimer>
#include <QIcon> #include <QIcon>
#include <QDebug> #include <QDebug>
#include <QWindow>
#include <klocalizedstring.h> #include <klocalizedstring.h>
#ifdef Q_WS_X11 #ifdef Q_WS_X11
...@@ -108,8 +110,10 @@ void ColorPickerWidget::slotGetAverageColor() ...@@ -108,8 +110,10 @@ void ColorPickerWidget::slotGetAverageColor()
Window root = RootWindow(QX11Info::display(), QX11Info::appScreen()); Window root = RootWindow(QX11Info::display(), QX11Info::appScreen());
m_image = XGetImage(QX11Info::display(), root, m_grabRect.x(), m_grabRect.y(), m_grabRect.width(), m_grabRect.height(), -1, ZPixmap); m_image = XGetImage(QX11Info::display(), root, m_grabRect.x(), m_grabRect.y(), m_grabRect.width(), m_grabRect.height(), -1, ZPixmap);
#else #else
QWidget *desktop = QApplication::desktop(); QScreen *currentScreen = QApplication::primaryScreen();
m_image = QPixmap::grabWindow(desktop->winId(), m_grabRect.x(), m_grabRect.y(), m_grabRect.width(), m_grabRect.height()).toImage(); if (currentScreen) {
m_image = currentScreen->grabWindow(0, m_grabRect.x(), m_grabRect.y(), m_grabRect.width(), m_grabRect.height()).toImage();
}
#endif #endif
for (int x = 0; x < m_grabRect.width(); ++x) { for (int x = 0; x < m_grabRect.width(); ++x) {
...@@ -147,7 +151,7 @@ void ColorPickerWidget::mousePressEvent(QMouseEvent* event) ...@@ -147,7 +151,7 @@ void ColorPickerWidget::mousePressEvent(QMouseEvent* event)
} }
if (m_filterActive) { if (m_filterActive) {
m_grabRect = QRect(event->globalPos(), QSize(0, 0)); m_grabRect = QRect(event->globalPos(), QSize(1, 1));
m_grabRectFrame->setGeometry(m_grabRect); m_grabRectFrame->setGeometry(m_grabRect);
m_grabRectFrame->show(); m_grabRectFrame->show();
} }
...@@ -162,6 +166,7 @@ void ColorPickerWidget::mouseReleaseEvent(QMouseEvent *event) ...@@ -162,6 +166,7 @@ void ColorPickerWidget::mouseReleaseEvent(QMouseEvent *event)
m_grabRect.setWidth(event->globalX() - m_grabRect.x()); m_grabRect.setWidth(event->globalX() - m_grabRect.x());
m_grabRect.setHeight(event->globalY() - m_grabRect.y()); m_grabRect.setHeight(event->globalY() - m_grabRect.y());
m_grabRect = m_grabRect.normalized();
if (m_grabRect.width() * m_grabRect.height() == 0) { if (m_grabRect.width() * m_grabRect.height() == 0) {
m_grabRectFrame->hide(); m_grabRectFrame->hide();
...@@ -251,10 +256,13 @@ QColor ColorPickerWidget::grabColor(const QPoint &p, bool destroyImage) ...@@ -251,10 +256,13 @@ QColor ColorPickerWidget::grabColor(const QPoint &p, bool destroyImage)
Q_UNUSED(destroyImage) Q_UNUSED(destroyImage)
if (m_image.isNull()) { if (m_image.isNull()) {
QWidget *desktop = QApplication::desktop(); QScreen *currentScreen = QApplication::primaryScreen();
QPixmap pm = QPixmap::grabWindow(desktop->winId(), p.x(), p.y(), 1, 1); if (currentScreen) {
QImage i = pm.toImage(); QPixmap pm = currentScreen->grabWindow(0, p.x(), p.y(), 1, 1);
return i.pixel(0, 0); QImage i = pm.toImage();
return i.pixel(0, 0);
}
else return qRgb(0, 0, 0);
} else { } else {
return m_image.pixel(p.x(), p.y()); return m_image.pixel(p.x(), p.y());
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment