diff --git a/apps/opencs/view/widget/coloreditor.cpp b/apps/opencs/view/widget/coloreditor.cpp index f06187992c..b31225962b 100644 --- a/apps/opencs/view/widget/coloreditor.cpp +++ b/apps/opencs/view/widget/coloreditor.cpp @@ -60,14 +60,7 @@ void CSVWidget::ColorEditor::showPicker() void CSVWidget::ColorEditor::pickerHid() { - // If the popup is hidden and mouse isn't above the editor, - // reset the editor checked state manually - QPoint globalEditorPosition = mapToGlobal(QPoint(0, 0)); - QRect globalEditorRect(globalEditorPosition, geometry().size()); - if (!globalEditorRect.contains(QCursor::pos())) - { - setChecked(false); - } + setChecked(false); emit pickingFinished(); } diff --git a/apps/opencs/view/widget/colorpickerpopup.cpp b/apps/opencs/view/widget/colorpickerpopup.cpp index dd53f1becc..8e71ce39e4 100644 --- a/apps/opencs/view/widget/colorpickerpopup.cpp +++ b/apps/opencs/view/widget/colorpickerpopup.cpp @@ -1,9 +1,12 @@ #include "colorpickerpopup.hpp" #include +#include #include #include +#include #include +#include CSVWidget::ColorPickerPopup::ColorPickerPopup(QWidget *parent) : QFrame(parent) @@ -40,6 +43,26 @@ void CSVWidget::ColorPickerPopup::showPicker(const QPoint &position, const QColo show(); } +void CSVWidget::ColorPickerPopup::mousePressEvent(QMouseEvent *event) +{ + QPushButton *button = qobject_cast(parentWidget()); + if (button != NULL) + { + QStyleOptionButton option; + option.init(button); + QRect buttonRect = option.rect; + buttonRect.moveTo(button->mapToGlobal(buttonRect.topLeft())); + + // If the mouse is pressed above the pop-up parent, + // the pop-up will be hidden and the pressed signal won't be repeated for the parent + if (buttonRect.contains(event->globalPos()) || buttonRect.contains(event->pos())) + { + setAttribute(Qt::WA_NoMouseReplay); + } + } + QFrame::mousePressEvent(event); +} + void CSVWidget::ColorPickerPopup::hideEvent(QHideEvent *event) { QFrame::hideEvent(event); diff --git a/apps/opencs/view/widget/colorpickerpopup.hpp b/apps/opencs/view/widget/colorpickerpopup.hpp index a7aec3bad6..602bbdb6da 100644 --- a/apps/opencs/view/widget/colorpickerpopup.hpp +++ b/apps/opencs/view/widget/colorpickerpopup.hpp @@ -19,6 +19,7 @@ namespace CSVWidget void showPicker(const QPoint &position, const QColor &initialColor); protected: + virtual void mousePressEvent(QMouseEvent *event); virtual void hideEvent(QHideEvent *event); virtual bool eventFilter(QObject *object, QEvent *event);