summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@digia.com>2013-11-07 16:38:31 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-11-08 11:16:51 +0100
commit7a3c82077f909e314cbc685e7ecfc70d08cc42d6 (patch)
treefb0bfed88adb3c0618f3dce685e595e84c984095 /src/widgets
parent7a6bb4d9c9eee46e5f2e0aee9a93d38fd6b91c46 (diff)
Fix potential BC break in QColorDialog.
Replace newly reimplemented virtuals in d928dbbc919f5f39af9ce5c69eb8e9ffa9da71d3 . Task-number: QTBUG-34663 Task-number: QTBUG-14332 Change-Id: Idb2cc2ec237c96f7157470728bb79ff3efc504d0 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/dialogs/qcolordialog.cpp100
-rw-r--r--src/widgets/dialogs/qcolordialog.h3
-rw-r--r--src/widgets/dialogs/qcolordialog_p.h5
3 files changed, 61 insertions, 47 deletions
diff --git a/src/widgets/dialogs/qcolordialog.cpp b/src/widgets/dialogs/qcolordialog.cpp
index d20725fc89..2e6518dd17 100644
--- a/src/widgets/dialogs/qcolordialog.cpp
+++ b/src/widgets/dialogs/qcolordialog.cpp
@@ -427,6 +427,30 @@ void QWellArray::keyPressEvent(QKeyEvent* e)
//////////// QWellArray END
+// Event filter to be installed on the dialog while in color-picking mode.
+class QColorPickingEventFilter : public QObject {
+public:
+ explicit QColorPickingEventFilter(QColorDialogPrivate *dp, QObject *parent = 0) : QObject(parent), m_dp(dp) {}
+
+ bool eventFilter(QObject *, QEvent *event) Q_DECL_OVERRIDE
+ {
+ switch (event->type()) {
+ case QEvent::MouseMove:
+ return m_dp->handleColorPickingMouseMove(static_cast<QMouseEvent *>(event));
+ case QEvent::MouseButtonRelease:
+ return m_dp->handleColorPickingMouseButtonRelease(static_cast<QMouseEvent *>(event));
+ case QEvent::KeyPress:
+ return m_dp->handleColorPickingKeyPress(static_cast<QKeyEvent *>(event));
+ default:
+ break;
+ }
+ return false;
+ }
+
+private:
+ QColorDialogPrivate *m_dp;
+};
+
/*!
Returns the number of custom colors supported by QColorDialog. All
color dialogs share the same custom colors.
@@ -1520,7 +1544,9 @@ void QColorDialogPrivate::_q_newStandard(int r, int c)
void QColorDialogPrivate::_q_pickScreenColor()
{
Q_Q(QColorDialog);
- screenColorPicking = true;
+ if (!colorPickingEventFilter)
+ colorPickingEventFilter = new QColorPickingEventFilter(this);
+ q->installEventFilter(colorPickingEventFilter);
// If user pushes Escape, the last color before picking will be restored.
beforeScreenColorPicking = cs->currentColor();
/*For some reason, q->grabMouse(Qt::CrossCursor) doesn't change
@@ -1550,7 +1576,7 @@ void QColorDialogPrivate::_q_pickScreenColor()
void QColorDialogPrivate::releaseColorPicking()
{
Q_Q(QColorDialog);
- screenColorPicking = false;
+ q->removeEventFilter(colorPickingEventFilter);
q->releaseMouse();
q->releaseKeyboard();
#ifndef QT_NO_CURSOR
@@ -1572,7 +1598,7 @@ void QColorDialogPrivate::init(const QColor &initial)
// default: use the native dialog if possible. Can be overridden in setOptions()
nativeDialogInUse = (platformColorDialogHelper() != 0);
- screenColorPicking = false;
+ colorPickingEventFilter = 0;
nextCust = 0;
if (!nativeDialogInUse)
@@ -2123,55 +2149,41 @@ void QColorDialog::changeEvent(QEvent *e)
QDialog::changeEvent(e);
}
-/*!
- \reimp
-*/
-void QColorDialog::mouseMoveEvent(QMouseEvent *e)
+bool QColorDialogPrivate::handleColorPickingMouseMove(QMouseEvent *e)
{
- Q_D(QColorDialog);
- if (d->screenColorPicking) {
- setCurrentColor(d->grabScreenColor(e->globalPos()));
- d->lblScreenColorInfo->setText(QColorDialog::tr("Cursor at %1, %2, color: %3\nPress ESC to cancel")
- .arg(e->globalPos().x())
- .arg(e->globalPos().y())
- .arg(currentColor().name()));
- return;
- }
- QDialog::mouseMoveEvent(e);
+ Q_Q(QColorDialog);
+ const QPoint globalPos = e->globalPos();
+ const QColor color = grabScreenColor(globalPos);
+ q->setCurrentColor(color);
+ lblScreenColorInfo->setText(QColorDialog::tr("Cursor at %1, %2, color: %3\nPress ESC to cancel")
+ .arg(globalPos.x()).arg(globalPos.y()).arg(color.name()));
+ return true;
}
-/*!
- \reimp
-*/
-void QColorDialog::mouseReleaseEvent(QMouseEvent *e)
+bool QColorDialogPrivate::handleColorPickingMouseButtonRelease(QMouseEvent *e)
{
- Q_D(QColorDialog);
- if (d->screenColorPicking) {
- setCurrentColor(d->grabScreenColor(e->globalPos()));
- d->releaseColorPicking();
- return;
- }
- QDialog::mouseReleaseEvent(e);
+ Q_Q(QColorDialog);
+ q->setCurrentColor(grabScreenColor(e->globalPos()));
+ releaseColorPicking();
+ return true;
}
-/*!
- \reimp
-*/
-void QColorDialog::keyPressEvent(QKeyEvent *e)
+bool QColorDialogPrivate::handleColorPickingKeyPress(QKeyEvent *e)
{
- Q_D(QColorDialog);
- if (d->screenColorPicking) {
- if (e->key() == Qt::Key_Escape) {
- d->releaseColorPicking();
- d->setCurrentColor(d->beforeScreenColorPicking);
- } else if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
- setCurrentColor(d->grabScreenColor(QCursor::pos()));
- d->releaseColorPicking();
- }
- e->accept();
- return;
+ Q_Q(QColorDialog);
+ switch (e->key()) {
+ case Qt::Key_Escape:
+ releaseColorPicking();
+ q->setCurrentColor(beforeScreenColorPicking);
+ break;
+ case Qt::Key_Return:
+ case Qt::Key_Enter:
+ q->setCurrentColor(grabScreenColor(QCursor::pos()));
+ releaseColorPicking();
+ break;
}
- QDialog::keyPressEvent(e);
+ e->accept();
+ return true;
}
/*!
diff --git a/src/widgets/dialogs/qcolordialog.h b/src/widgets/dialogs/qcolordialog.h
index c7a1d6f400..c74ee6720a 100644
--- a/src/widgets/dialogs/qcolordialog.h
+++ b/src/widgets/dialogs/qcolordialog.h
@@ -112,9 +112,6 @@ Q_SIGNALS:
protected:
void changeEvent(QEvent *event);
- virtual void mouseMoveEvent(QMouseEvent *);
- virtual void mouseReleaseEvent(QMouseEvent *);
- virtual void keyPressEvent(QKeyEvent *);
void done(int result);
private:
diff --git a/src/widgets/dialogs/qcolordialog_p.h b/src/widgets/dialogs/qcolordialog_p.h
index 08199cc7c1..f58a9200db 100644
--- a/src/widgets/dialogs/qcolordialog_p.h
+++ b/src/widgets/dialogs/qcolordialog_p.h
@@ -70,6 +70,7 @@ class QLabel;
class QVBoxLayout;
class QPushButton;
class QWellArray;
+class QColorPickingEventFilter;
class QColorDialogPrivate : public QDialogPrivate
{
@@ -105,6 +106,9 @@ public:
void _q_newStandard(int, int);
void _q_pickScreenColor();
void releaseColorPicking();
+ bool handleColorPickingMouseMove(QMouseEvent *e);
+ bool handleColorPickingMouseButtonRelease(QMouseEvent *e);
+ bool handleColorPickingKeyPress(QKeyEvent *e);
QWellArray *custom;
QWellArray *standard;
@@ -125,6 +129,7 @@ public:
int nextCust;
bool smallDisplay;
bool screenColorPicking;
+ QColorPickingEventFilter *colorPickingEventFilter;
QRgb beforeScreenColorPicking;
QSharedPointer<QColorDialogOptions> options;