[graphics/krita] libs/ui/widgets: Add a setting for using the platform dialog

Halla Rempt null at kde.org
Wed Dec 15 10:23:52 GMT 2021


Git commit b366c26b499cea50da012b8f3b8c6afe5b716f9f by Halla Rempt.
Committed on 15/12/2021 at 10:22.
Pushed by rempt into branch 'master'.

Add a setting for using the platform dialog

Note: it's off by default on all platforms now, based on the
discussion here:

https://krita-artists.org/t/option-for-kritas-color-selector-dialog-on-mac/33339/5

Note: not for 5.0 -- because it changes the default behaviour
of Krita on macOS.

CCMAIL:kimageshop at kde.org

M  +31   -25   libs/ui/widgets/KoDualColorButton.cpp

https://invent.kde.org/graphics/krita/commit/b366c26b499cea50da012b8f3b8c6afe5b716f9f

diff --git a/libs/ui/widgets/KoDualColorButton.cpp b/libs/ui/widgets/KoDualColorButton.cpp
index 3c9a37d9cc..e3f938a688 100644
--- a/libs/ui/widgets/KoDualColorButton.cpp
+++ b/libs/ui/widgets/KoDualColorButton.cpp
@@ -8,6 +8,8 @@
 #include "KoColor.h"
 #include "KoColorDisplayRendererInterface.h"
 #include <kcolormimedata.h>
+#include <kconfiggroup.h>
+#include <ksharedconfig.h>
 
 #include "dcolorarrow.xbm"
 #include "dcolorreset.xpm"
@@ -347,21 +349,24 @@ void KoDualColorButton::mouseReleaseEvent( QMouseEvent *event )
     QRect backgroundRect;
     metrics( foregroundRect, backgroundRect );
 
+    KConfigGroup cfg =  KSharedConfig::openConfig()->group("colorselector");
+    bool usePlatformDialog = cfg.readEntry("UsePlatformColorDialog", false);
+
     if (foregroundRect.contains( event->pos())) {
         if (d->tmpSelection == Foreground) {
             if (d->popDialog) {
-#ifndef Q_OS_MACOS
-                d->colorSelectorDialog->setPreviousColor(d->foregroundColor);
-                // this should toggle, but I don't know how to implement that...
-                d->colorSelectorDialog->show();
-#else
-                QColor c = d->foregroundColor.toQColor();
-                c = QColorDialog::getColor(c, this);
-                if (c.isValid()) {
-                    d->foregroundColor = d->displayRenderer->approximateFromRenderedQColor(c);
-                    emit foregroundColorChanged(d->foregroundColor);
+                if (usePlatformDialog) {
+                    QColor c = d->foregroundColor.toQColor();
+                    c = QColorDialog::getColor(c, this);
+                    if (c.isValid()) {
+                        d->foregroundColor = d->displayRenderer->approximateFromRenderedQColor(c);
+                        emit foregroundColorChanged(d->foregroundColor);
+                    }
+                }
+                else {
+                    d->colorSelectorDialog->setPreviousColor(d->foregroundColor);
+                    d->colorSelectorDialog->show();
                 }
-#endif
             }
         }
         else {
@@ -369,22 +374,23 @@ void KoDualColorButton::mouseReleaseEvent( QMouseEvent *event )
             emit foregroundColorChanged( d->foregroundColor );
         }
     }
-    else if ( backgroundRect.contains( event->pos() )) {
+    else if (backgroundRect.contains( event->pos())) {
         if(d->tmpSelection == Background ) {
             if( d->popDialog) {
-#ifndef Q_OS_MACOS
-                KoColor c = d->backgroundColor;
-                c = KisDlgInternalColorSelector::getModalColorDialog(c, this, d->colorSelectorDialog->windowTitle());
-                d->backgroundColor = c;
-                emit backgroundColorChanged(d->backgroundColor);
-#else
-                QColor c = d->backgroundColor.toQColor();
-                c = QColorDialog::getColor(c, this);
-                if (c.isValid()) {
-                    d->backgroundColor = d->displayRenderer->approximateFromRenderedQColor(c);
+                if (usePlatformDialog) {
+                    KoColor c = d->backgroundColor;
+                    c = KisDlgInternalColorSelector::getModalColorDialog(c, this, d->colorSelectorDialog->windowTitle());
+                    d->backgroundColor = c;
                     emit backgroundColorChanged(d->backgroundColor);
                 }
-#endif
+                else {
+                    QColor c = d->backgroundColor.toQColor();
+                    c = QColorDialog::getColor(c, this);
+                    if (c.isValid()) {
+                        d->backgroundColor = d->displayRenderer->approximateFromRenderedQColor(c);
+                        emit backgroundColorChanged(d->backgroundColor);
+                    }
+                }
             }
         } else {
             d->backgroundColor = d->foregroundColor;
@@ -419,7 +425,7 @@ bool KoDualColorButton::event(QEvent *event)
             if (this->mapFromGlobal(QCursor::pos()).y() < backgroundRect.y()){
                 this->setToolTip(i18n("Foreground color selector"));
             }
-            else{ 
+            else{
                 this->setToolTip(i18n("Set foreground and background colors to black and white"));
             }
         }
@@ -427,7 +433,7 @@ bool KoDualColorButton::event(QEvent *event)
             if (this->mapFromGlobal(QCursor::pos()).y() < backgroundRect.y() ) {
                 this->setToolTip(i18n("Swap foreground and background colors"));
             }
-            else{ 
+            else{
                 this->setToolTip(i18n("Background color selector"));
             }
         }


More information about the kimageshop mailing list