[LyX/master] #10740 fix focus problems with color picker on Mac
Stephan Witt
switt at lyx.org
Sat Aug 5 12:09:58 UTC 2023
commit 49fe82ec8ddf829aabeddb74cd51f1bef5b4df52
Author: Stephan Witt <switt at lyx.org>
Date: Sat Aug 5 15:23:44 2023 +0200
#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
---
src/frontends/qt/GuiBranches.cpp | 4 ++--
src/frontends/qt/GuiDialog.cpp | 19 +++++++++++++++++++
src/frontends/qt/GuiDialog.h | 3 +++
src/frontends/qt/GuiDocument.cpp | 13 ++++---------
src/frontends/qt/GuiIndices.cpp | 4 ++--
src/frontends/qt/GuiPrefs.cpp | 3 +--
6 files changed, 31 insertions(+), 15 deletions(-)
diff --git a/src/frontends/qt/GuiBranches.cpp b/src/frontends/qt/GuiBranches.cpp
index 79d1640..795a6f6 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 <QPixmap>
#include <QIcon>
#include <QColor>
-#include <QColorDialog>
#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 67793df..186d9ea 100644
--- a/src/frontends/qt/GuiDialog.cpp
+++ b/src/frontends/qt/GuiDialog.cpp
@@ -21,6 +21,7 @@
#include <QCloseEvent>
#include <QDialogButtonBox>
+#include <QColorDialog>
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 50910f4..bd50df0 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 e8c8c19..820fb24 100644
--- a/src/frontends/qt/GuiDocument.cpp
+++ b/src/frontends/qt/GuiDocument.cpp
@@ -73,7 +73,6 @@
#include <QAbstractItemModel>
#include <QButtonGroup>
#include <QColor>
-#include <QColorDialog>
#include <QCloseEvent>
#include <QDirIterator>
#include <QFontDatabase>
@@ -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 5e145f5..6fa9cbc 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 <QPixmap>
#include <QIcon>
#include <QColor>
-#include <QColorDialog>
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 a74d97f..62ee814 100644
--- a/src/frontends/qt/GuiPrefs.cpp
+++ b/src/frontends/qt/GuiPrefs.cpp
@@ -56,7 +56,6 @@
#include <QAbstractItemModel>
#include <QCheckBox>
-#include <QColorDialog>
#include <QFontDatabase>
#include <QHeaderView>
#include <QLineEdit>
@@ -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();
More information about the lyx-cvs
mailing list