From ddd4c4560cf307b89fd94360e5b33bf9eb99b7b8 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 2 Oct 2016 19:57:01 +0200 Subject: [PATCH] support to auto change color when color dialog is modal --- src/Gui/Widgets.cpp | 32 +++++++++++++++++++++++++++++--- src/Gui/Widgets.h | 3 +++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/Gui/Widgets.cpp b/src/Gui/Widgets.cpp index 8478288cb..f6406b15b 100644 --- a/src/Gui/Widgets.cpp +++ b/src/Gui/Widgets.cpp @@ -517,6 +517,7 @@ struct ColorButtonP QColor old, col; QPointer cd; bool allowChange; + bool autoChange; bool drawFrame; bool modal; bool dirty; @@ -524,6 +525,7 @@ struct ColorButtonP ColorButtonP() : cd(0) , allowChange(true) + , autoChange(false) , drawFrame(true) , modal(true) , dirty(true) @@ -604,6 +606,16 @@ bool ColorButton::isModal() const return d->modal; } +void ColorButton::setAutoChangeColor(bool on) +{ + d->autoChange = on; +} + +bool ColorButton::autoChangeColor() const +{ + return d->autoChange; +} + /** * Draws the button label. */ @@ -675,9 +687,23 @@ void ColorButton::onChooseColor() #if QT_VERSION >= 0x040500 if (d->modal) { #endif - QColor c = QColorDialog::getColor(d->col, this); - if (c.isValid()) { - setColor(c); + QColor currentColor = d->col; + QColorDialog cd(d->col, this); + + if (d->autoChange) { + connect(&cd, SIGNAL(currentColorChanged(const QColor &)), + this, SLOT(onColorChosen(const QColor&))); + } + + if (cd.exec() == QDialog::Accepted) { + QColor c = cd.selectedColor(); + if (c.isValid()) { + setColor(c); + changed(); + } + } + else if (d->autoChange) { + setColor(currentColor); changed(); } #if QT_VERSION >= 0x040500 diff --git a/src/Gui/Widgets.h b/src/Gui/Widgets.h index 7de00fbec..901279c45 100644 --- a/src/Gui/Widgets.h +++ b/src/Gui/Widgets.h @@ -191,6 +191,9 @@ public: void setModal(bool); bool isModal() const; + void setAutoChangeColor(bool); + bool autoChangeColor() const; + public Q_SLOTS: void onChooseColor();