vcl/CustomTarget_qt5_moc.mk                  |    1 
 vcl/CustomTarget_qt6_moc.mk                  |    1 
 vcl/Library_vclplug_qt5.mk                   |    1 
 vcl/Library_vclplug_qt6.mk                   |    1 
 vcl/inc/qt5/QtInstance.hxx                   |    2 +
 vcl/inc/qt5/QtInstanceColorChooserDialog.hxx |   31 ++++++++++++++++++++
 vcl/inc/qt6/QtInstanceColorChooserDialog.hxx |   12 ++++++++
 vcl/qt5/QtInstance.cxx                       |   15 ++++++++++
 vcl/qt5/QtInstanceColorChooserDialog.cxx     |   40 +++++++++++++++++++++++++++
 vcl/qt6/QtInstanceColorChooserDialog.cxx     |   12 ++++++++
 10 files changed, 116 insertions(+)

New commits:
commit 072010169bb4668f3c624a9f379e8a79e4e3e57a
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Fri Jul 25 15:09:25 2025 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Fri Jul 25 19:58:15 2025 +0200

    tdf#167669 tdf#130857 qt: Use native QColorDialog
    
    Similar to how previous commit
    
        Change-Id: If5bfb453b55c905ffe332707e2fb261a48664c31
        Author: Michael Weghorn <m.wegh...@posteo.de>
        Date:   Fri Jul 25 14:55:34 2025 +0200
    
            tdf#167669 gtk: Use native GtkColorChooserDialog
    
    introduced the use of the native GtkColorChooserDialog
    for gtk3 and gtk4, use the native QColorDialog [1]
    for the Qt-based VCL plugins.
    
    Like GtkColorChooserDialog, it also has the advantage
    of providing a color picker to select a color from a pixel
    on screen, which the custom LO implementation doesn't have.
    
    [1] https://doc.qt.io/qt-6/qcolordialog.html
    
    Change-Id: If371d75c8a2687430a89de798d50aa10b8db1c29
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188345
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/CustomTarget_qt5_moc.mk b/vcl/CustomTarget_qt5_moc.mk
index 886799a07af3..2f3e22ac76c3 100644
--- a/vcl/CustomTarget_qt5_moc.mk
+++ b/vcl/CustomTarget_qt5_moc.mk
@@ -23,6 +23,7 @@ $(call gb_CustomTarget_get_target,vcl/qt5) : \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceBox.moc \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceCalendar.moc \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceCheckButton.moc \
+       $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceColorChooserDialog.moc \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceComboBox.moc \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceContainer.moc \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceDialog.moc \
diff --git a/vcl/CustomTarget_qt6_moc.mk b/vcl/CustomTarget_qt6_moc.mk
index d5e1964f0bff..73dd8e279db6 100644
--- a/vcl/CustomTarget_qt6_moc.mk
+++ b/vcl/CustomTarget_qt6_moc.mk
@@ -23,6 +23,7 @@ $(call gb_CustomTarget_get_target,vcl/qt6) : \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceBox.moc \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceCalendar.moc \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceCheckButton.moc \
+       $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceColorChooserDialog.moc \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceComboBox.moc \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceContainer.moc \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceDialog.moc \
diff --git a/vcl/Library_vclplug_qt5.mk b/vcl/Library_vclplug_qt5.mk
index e21175a70423..858d400b49ec 100644
--- a/vcl/Library_vclplug_qt5.mk
+++ b/vcl/Library_vclplug_qt5.mk
@@ -105,6 +105,7 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_qt5,\
     vcl/qt5/QtInstanceButton \
     vcl/qt5/QtInstanceCalendar \
     vcl/qt5/QtInstanceCheckButton \
+    vcl/qt5/QtInstanceColorChooserDialog \
     vcl/qt5/QtInstanceContainer \
     vcl/qt5/QtInstanceComboBox \
     vcl/qt5/QtInstanceDialog \
diff --git a/vcl/Library_vclplug_qt6.mk b/vcl/Library_vclplug_qt6.mk
index efab1cb133df..74bcf1289186 100644
--- a/vcl/Library_vclplug_qt6.mk
+++ b/vcl/Library_vclplug_qt6.mk
@@ -104,6 +104,7 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_qt6,\
     vcl/qt6/QtInstanceButton \
     vcl/qt6/QtInstanceCalendar \
     vcl/qt6/QtInstanceCheckButton \
+    vcl/qt6/QtInstanceColorChooserDialog \
     vcl/qt6/QtInstanceComboBox \
     vcl/qt6/QtInstanceContainer \
     vcl/qt6/QtInstanceDialog \
diff --git a/vcl/inc/qt5/QtInstance.hxx b/vcl/inc/qt5/QtInstance.hxx
index 699c04139f06..21cf0498e277 100644
--- a/vcl/inc/qt5/QtInstance.hxx
+++ b/vcl/inc/qt5/QtInstance.hxx
@@ -192,6 +192,8 @@ public:
                                                      VclMessageType 
eMessageType,
                                                      VclButtonsType 
eButtonType,
                                                      const OUString& 
rPrimaryMessage) override;
+    virtual std::unique_ptr<weld::ColorChooserDialog>
+    CreateColorChooserDialog(weld::Window* pParent, vcl::ColorPickerMode 
eMode) override;
 
 // so we fall back to the default abort, instead of duplicating it...
 #ifndef EMSCRIPTEN
diff --git a/vcl/inc/qt5/QtInstanceColorChooserDialog.hxx 
b/vcl/inc/qt5/QtInstanceColorChooserDialog.hxx
new file mode 100644
index 000000000000..53fdec7b08d6
--- /dev/null
+++ b/vcl/inc/qt5/QtInstanceColorChooserDialog.hxx
@@ -0,0 +1,31 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+
+#include "QtInstanceDialog.hxx"
+
+#include <QtWidgets/QColorDialog>
+
+class QtInstanceColorChooserDialog : public QtInstanceDialog,
+                                     public virtual weld::ColorChooserDialog
+{
+    Q_OBJECT
+
+    QColorDialog* m_pColorDialog;
+
+public:
+    QtInstanceColorChooserDialog(QColorDialog* pColorDialog);
+    ~QtInstanceColorChooserDialog();
+
+    virtual void set_color(const Color& rColor) override;
+    virtual Color get_color() const override;
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/vcl/inc/qt6/QtInstanceColorChooserDialog.hxx 
b/vcl/inc/qt6/QtInstanceColorChooserDialog.hxx
new file mode 100644
index 000000000000..06770d4c4871
--- /dev/null
+++ b/vcl/inc/qt6/QtInstanceColorChooserDialog.hxx
@@ -0,0 +1,12 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "../qt5/QtInstanceColorChooserDialog.hxx"
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/vcl/qt5/QtInstance.cxx b/vcl/qt5/QtInstance.cxx
index 55a8d3310b76..c3700e51cb7e 100644
--- a/vcl/qt5/QtInstance.cxx
+++ b/vcl/qt5/QtInstance.cxx
@@ -29,6 +29,7 @@
 #include <QtFilePicker.hxx>
 #include <QtFrame.hxx>
 #include <QtInstanceBuilder.hxx>
+#include <QtInstanceColorChooserDialog.hxx>
 #include <QtMenu.hxx>
 #include <QtObject.hxx>
 #include <QtOpenGLContext.hxx>
@@ -956,6 +957,20 @@ weld::MessageDialog* 
QtInstance::CreateMessageDialog(weld::Widget* pParent,
     }
 }
 
+std::unique_ptr<weld::ColorChooserDialog>
+QtInstance::CreateColorChooserDialog(weld::Window* pParent, 
vcl::ColorPickerMode)
+{
+    SolarMutexGuard g;
+
+    std::unique_ptr<weld::ColorChooserDialog> pColorChooserDialog;
+    RunInMainThread([&] {
+        QColorDialog* pDialog = new 
QColorDialog(GetNativeParentFromWeldParent(pParent));
+        pColorChooserDialog = 
std::make_unique<QtInstanceColorChooserDialog>(pDialog);
+    });
+
+    return pColorChooserDialog;
+};
+
 static void initResources()
 {
 #if defined EMSCRIPTEN && defined DISABLE_DYNLOADING && ENABLE_QT6
diff --git a/vcl/qt5/QtInstanceColorChooserDialog.cxx 
b/vcl/qt5/QtInstanceColorChooserDialog.cxx
new file mode 100644
index 000000000000..e15ccece93c4
--- /dev/null
+++ b/vcl/qt5/QtInstanceColorChooserDialog.cxx
@@ -0,0 +1,40 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <QtInstanceColorChooserDialog.hxx>
+#include <QtInstanceColorChooserDialog.moc>
+
+QtInstanceColorChooserDialog::QtInstanceColorChooserDialog(QColorDialog* 
pColorDialog)
+    : QtInstanceDialog(pColorDialog)
+    , m_pColorDialog(pColorDialog)
+{
+    assert(m_pColorDialog);
+}
+
+QtInstanceColorChooserDialog::~QtInstanceColorChooserDialog() {}
+
+void QtInstanceColorChooserDialog::set_color(const Color& rColor)
+{
+    SolarMutexGuard g;
+
+    GetQtInstance().RunInMainThread(
+        [this, &rColor] { m_pColorDialog->setCurrentColor(toQColor(rColor)); 
});
+}
+
+Color QtInstanceColorChooserDialog::get_color() const
+{
+    SolarMutexGuard g;
+
+    Color aColor;
+    GetQtInstance().RunInMainThread([&] { aColor = 
toColor(m_pColorDialog->currentColor()); });
+
+    return aColor;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/vcl/qt6/QtInstanceColorChooserDialog.cxx 
b/vcl/qt6/QtInstanceColorChooserDialog.cxx
new file mode 100644
index 000000000000..cae1ea6413f2
--- /dev/null
+++ b/vcl/qt6/QtInstanceColorChooserDialog.cxx
@@ -0,0 +1,12 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "../qt5/QtInstanceColorChooserDialog.cxx"
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */

Reply via email to