From: Stephan Witt Date: Sat, 5 Aug 2023 13:23:44 +0000 (+0200) Subject: #10740 fix focus problems with color picker on Mac X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=49fe82ec8ddf829aabeddb74cd51f1bef5b4df52;p=features.git #10740 fix focus problems with color picker on Mac - closing the color picker focuses the wrong (main) window - to return focus to correct (parent) window it has to be activated explicitly --- diff --git a/src/frontends/qt/GuiBranches.cpp b/src/frontends/qt/GuiBranches.cpp index 79d16403bd..795a6f6d6f 100644 --- a/src/frontends/qt/GuiBranches.cpp +++ b/src/frontends/qt/GuiBranches.cpp @@ -15,6 +15,7 @@ #include "ColorCache.h" #include "GuiApplication.h" +#include "GuiDialog.h" #include "Validator.h" #include "qt_helpers.h" @@ -35,7 +36,6 @@ #include #include #include -#include #ifdef KeyPress #undef KeyPress @@ -341,7 +341,7 @@ void GuiBranches::toggleColor(QTreeWidgetItem * item) else guiApp->getRgbColor(lcolor.getFromLyXName(bcolor), rgbcol); QColor const initial = rgb2qcolor(rgbcol); - QColor ncol = QColorDialog::getColor(initial, qApp->focusWidget()); + QColor ncol = GuiDialog::getColor(initial, this); if (!ncol.isValid()) return; diff --git a/src/frontends/qt/GuiDialog.cpp b/src/frontends/qt/GuiDialog.cpp index 67793df023..186d9ea3a0 100644 --- a/src/frontends/qt/GuiDialog.cpp +++ b/src/frontends/qt/GuiDialog.cpp @@ -21,6 +21,7 @@ #include #include +#include using namespace std; @@ -282,6 +283,24 @@ QString GuiDialog::browseRelToSub( } +QColor GuiDialog::getColor(const QColor &initial, QWidget *parent) +{ + const QColor color = QColorDialog::getColor(initial, parent); + if (guiApp->platformName() == "cocoa") { + QWidget * dialog = parent->window(); + // On Mac explicitly activate the parents top-level widget + // See #10740 + dialog->raise(); + dialog->activateWindow(); + } + return color; +} + +QColor GuiDialog::getColor(const QColor &initial) +{ + return getColor(initial, asQWidget()); +} + } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt/GuiDialog.h b/src/frontends/qt/GuiDialog.h index 50910f434c..bd50df067b 100644 --- a/src/frontends/qt/GuiDialog.h +++ b/src/frontends/qt/GuiDialog.h @@ -178,6 +178,9 @@ public: QString const & label2 = QString(), QString const & dir2 = QString()); + static QColor getColor(const QColor &initial, QWidget *parent); + QColor getColor(const QColor &initial); + private: ButtonController bc_; /// are we updating ? diff --git a/src/frontends/qt/GuiDocument.cpp b/src/frontends/qt/GuiDocument.cpp index e8c8c19e8a..820fb24901 100644 --- a/src/frontends/qt/GuiDocument.cpp +++ b/src/frontends/qt/GuiDocument.cpp @@ -73,7 +73,6 @@ #include #include #include -#include #include #include #include @@ -2293,8 +2292,7 @@ void GuiDocument::setCustomMargins(bool custom) void GuiDocument::changeBackgroundColor() { - QColor const & newColor = QColorDialog::getColor( - rgb2qcolor(set_backgroundcolor), asQWidget()); + QColor const & newColor = getColor(rgb2qcolor(set_backgroundcolor)); if (!newColor.isValid()) return; // set the color @@ -2322,8 +2320,7 @@ void GuiDocument::deleteBackgroundColor() void GuiDocument::changeFontColor() { - QColor const & newColor = QColorDialog::getColor( - rgb2qcolor(set_fontcolor), asQWidget()); + QColor const & newColor = getColor(rgb2qcolor(set_fontcolor)); if (!newColor.isValid()) return; // set the color @@ -2351,8 +2348,7 @@ void GuiDocument::deleteFontColor() void GuiDocument::changeNoteFontColor() { - QColor const & newColor = QColorDialog::getColor( - rgb2qcolor(set_notefontcolor), asQWidget()); + QColor const & newColor = getColor(rgb2qcolor(set_notefontcolor)); if (!newColor.isValid()) return; // set the color @@ -2378,8 +2374,7 @@ void GuiDocument::deleteNoteFontColor() void GuiDocument::changeBoxBackgroundColor() { - QColor const & newColor = QColorDialog::getColor( - rgb2qcolor(set_boxbgcolor), asQWidget()); + QColor const & newColor = getColor(rgb2qcolor(set_boxbgcolor)); if (!newColor.isValid()) return; // set the color diff --git a/src/frontends/qt/GuiIndices.cpp b/src/frontends/qt/GuiIndices.cpp index 5e145f56eb..6fa9cbc34e 100644 --- a/src/frontends/qt/GuiIndices.cpp +++ b/src/frontends/qt/GuiIndices.cpp @@ -16,6 +16,7 @@ #include "ColorCache.h" #include "GuiApplication.h" +#include "GuiDialog.h" #include "Validator.h" #include "qt_helpers.h" @@ -32,7 +33,6 @@ #include #include #include -#include using namespace std; @@ -290,7 +290,7 @@ void GuiIndices::toggleColor(QTreeWidgetItem * item) return; QColor const initial = rgb2qcolor(index->color()); - QColor ncol = QColorDialog::getColor(initial, qApp->focusWidget()); + QColor ncol = GuiDialog::getColor(initial, this); if (!ncol.isValid()) return; diff --git a/src/frontends/qt/GuiPrefs.cpp b/src/frontends/qt/GuiPrefs.cpp index a74d97fcc3..62ee81404d 100644 --- a/src/frontends/qt/GuiPrefs.cpp +++ b/src/frontends/qt/GuiPrefs.cpp @@ -56,7 +56,6 @@ #include #include -#include #include #include #include @@ -1056,7 +1055,7 @@ void PrefColors::changeColor() return; QString const color = newcolors_[size_t(row)]; - QColor const c = QColorDialog::getColor(QColor(color), qApp->focusWidget()); + QColor const c = form_->getColor(QColor(color)); if (setColor(row, c, color)) { setDisabledResets();