summaryrefslogtreecommitdiffstats
path: root/src/widgets/dialogs/qcolordialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/dialogs/qcolordialog.cpp')
-rw-r--r--src/widgets/dialogs/qcolordialog.cpp56
1 files changed, 51 insertions, 5 deletions
diff --git a/src/widgets/dialogs/qcolordialog.cpp b/src/widgets/dialogs/qcolordialog.cpp
index aa1b4b1023..5fffe61877 100644
--- a/src/widgets/dialogs/qcolordialog.cpp
+++ b/src/widgets/dialogs/qcolordialog.cpp
@@ -57,6 +57,7 @@
#include "qdialogbuttonbox.h"
#include "qscreen.h"
#include "qcursor.h"
+#include "qtimer.h"
#include <algorithm>
@@ -1539,8 +1540,18 @@ void QColorDialogPrivate::_q_pickScreenColor()
#else
q->grabMouse();
#endif
+
+#ifdef Q_OS_WIN32 // excludes WinCE and WinRT
+ // On Windows mouse tracking doesn't work over other processes's windows
+ updateTimer->start(30);
+
+ // HACK: Because mouse grabbing doesn't work across processes, we have to have a dummy,
+ // invisible window to catch the mouse click, otherwise we will click whatever we clicked
+ // and loose focus.
+ dummyTransparentWindow.show();
+#endif
q->grabKeyboard();
- /* With setMouseTracking(true) the desired color can be more precisedly picked up,
+ /* With setMouseTracking(true) the desired color can be more precisely picked up,
* and continuously pushing the mouse button is not necessary.
*/
q->setMouseTracking(true);
@@ -1567,6 +1578,10 @@ void QColorDialogPrivate::releaseColorPicking()
cp->setCrossVisible(true);
q->removeEventFilter(colorPickingEventFilter);
q->releaseMouse();
+#ifdef Q_OS_WIN32
+ updateTimer->stop();
+ dummyTransparentWindow.setVisible(false);
+#endif
q->releaseKeyboard();
q->setMouseTracking(false);
lblScreenColorInfo->setText(QLatin1String("\n"));
@@ -1593,6 +1608,10 @@ void QColorDialogPrivate::init(const QColor &initial)
#ifdef Q_WS_MAC
delegate = 0;
#endif
+#ifdef Q_OS_WIN32
+ dummyTransparentWindow.resize(1, 1);
+ dummyTransparentWindow.setFlags(Qt::Tool | Qt::FramelessWindowHint);
+#endif
q->setCurrentColor(initial);
}
@@ -1733,6 +1752,10 @@ void QColorDialogPrivate::initWidgets()
cancel = buttons->addButton(QDialogButtonBox::Cancel);
QObject::connect(cancel, SIGNAL(clicked()), q, SLOT(reject()));
+#ifdef Q_OS_WIN32
+ updateTimer = new QTimer(q);
+ QObject::connect(updateTimer, SIGNAL(timeout()), q, SLOT(_q_updateColorPicking()));
+#endif
retranslateStrings();
}
@@ -2138,18 +2161,41 @@ void QColorDialog::changeEvent(QEvent *e)
QDialog::changeEvent(e);
}
-bool QColorDialogPrivate::handleColorPickingMouseMove(QMouseEvent *e)
+void QColorDialogPrivate::_q_updateColorPicking()
{
- // If the cross is visible the grabbed color will be black most of the times
- cp->setCrossVisible(!cp->geometry().contains(e->pos()));
+#ifndef QT_NO_CURSOR
+ Q_Q(QColorDialog);
+ static QPoint lastGlobalPos;
+ QPoint newGlobalPos = QCursor::pos();
+ if (lastGlobalPos == newGlobalPos)
+ return;
+ lastGlobalPos = newGlobalPos;
- const QPoint globalPos = e->globalPos();
+ if (!q->rect().contains(q->mapFromGlobal(newGlobalPos))) { // Inside the dialog mouse tracking works, handleColorPickingMouseMove will be called
+ updateColorPicking(newGlobalPos);
+#ifdef Q_OS_WIN32
+ dummyTransparentWindow.setPosition(newGlobalPos);
+#endif
+ }
+#endif // ! QT_NO_CURSOR
+}
+
+void QColorDialogPrivate::updateColorPicking(const QPoint &globalPos)
+{
const QColor color = grabScreenColor(globalPos);
// QTBUG-39792, do not change standard, custom color selectors while moving as
// otherwise it is not possible to pre-select a custom cell for assignment.
setCurrentColor(color, ShowColor);
updateColorLabelText(globalPos);
+}
+
+bool QColorDialogPrivate::handleColorPickingMouseMove(QMouseEvent *e)
+{
+ // If the cross is visible the grabbed color will be black most of the times
+ cp->setCrossVisible(!cp->geometry().contains(e->pos()));
+
+ updateColorPicking(e->globalPos());
return true;
}