vcl/inc/qt5/QtBuilder.hxx     |    7 +++++++
 vcl/qt5/QtBuilder.cxx         |   37 +++++++++++++++++++++++++++++++++++++
 vcl/qt5/QtInstanceBuilder.cxx |    2 ++
 3 files changed, 46 insertions(+)

New commits:
commit 09e76631dd60f1e6ffab3faa17889fe7327b8a3c
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Sat Dec 14 20:46:48 2024 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sun Dec 15 01:18:57 2024 +0100

    tdf#130857 tdf#162704 qt weld: Support QR/bar code dialog
    
    Declare support for the "QR and Barcode" dialog
    that can be triggered in Writer using "Insert" -> "OLE Object"
    -> "QR/Barcode".
    
    This means that native Qt widgets are used for that dialog
    now when using the qt5 or qt6 VCL plugin and starting LO with
    environment variable SAL_VCL_QT_USE_WELDED_WIDGETS=1 set.
    
    The native QPlainTextEdit also doesn't have the
    problem of rendering artifacts as described in tdf#162704
    for the vcl widget when used with qt6/kf6 and the Breeze
    style.
    
    Change-Id: I6263b8961d97141719e2b23dcc4467cda960d3e3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178485
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/qt5/QtInstanceBuilder.cxx b/vcl/qt5/QtInstanceBuilder.cxx
index bdc1744f259e..c1e86ac7018a 100644
--- a/vcl/qt5/QtInstanceBuilder.cxx
+++ b/vcl/qt5/QtInstanceBuilder.cxx
@@ -55,6 +55,7 @@ bool QtInstanceBuilder::IsUIFileSupported(const OUString& 
rUIFile)
         u"cui/ui/optnewdictionarydialog.ui"_ustr,
         u"cui/ui/password.ui"_ustr,
         u"cui/ui/pastespecial.ui"_ustr,
+        u"cui/ui/qrcodegen.ui"_ustr,
         u"cui/ui/querysetinsmodedialog.ui"_ustr,
         u"cui/ui/securityoptionsdialog.ui"_ustr,
         u"cui/ui/splitcellsdialog.ui"_ustr,
commit 89b00d3e34c93b4ea0701a321a3cecf57aa0e378
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Sat Dec 14 19:45:51 2024 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sun Dec 15 01:18:51 2024 +0100

    tdf#130857 qt weld: Drop scroll area parent if redundant
    
    For Qt widgets that already provide scrolling capabilities
    by themselves because they implement QAbstractScrollArea,
    as QPlainTextEdit does, there is no need to have a separate
    QScrollArea parent, and having one can even result in
    unexpected behavior as described in previous commit
    
        Change-Id: Ia94fdc8075a76af6a18b656a4c6b9168a408aee0
        Author: Michael Weghorn <m.wegh...@posteo.de>
        Date:   Fri Oct 4 18:16:18 2024 +0200
    
            tdf#130857 qt weld: Support "Alt Text" dialog
    
            Declare support for the "Alt Text" dialog that
            can e.g. be triggered as follows in Writer:
    
            * "Insert" -> "OLE Object" -> "QR and Barcode"
            * type anything, confirm
            * select the QR code
            * right click, select "Alt Text" in the context
              menu
    
            This means that native Qt widgets are used for that dialog
            now when using the qt5 or qt6 VCL plugin and starting LO with
            environment variable SAL_VCL_QT_USE_WELDED_WIDGETS=1 set.
    
            Currently, tab/focus behavior is a little odd,
            as focus first moves to the scroll area that
            the QScrollArea (created for the "GtkScrolledWindow"
            object in the .ui file) before it moves inside the
            QPlainTextEdit (created for the "GtkTextView" object
            in the .ui file) contained therein.
            That will be improved in an upcoming commit.
    
    Therefore, add special handling for the QScrollArea child:
    
    * If it subclasses QAbstractScrollArea, then remove
      the QScrollArea parent from the widget hierarchy,
      and put the child widget in its place. Don't do it
      directly in QtBuilder::tweakInsertedChild, but only
      after WidgetBuilder::processUIFile has finished
      processing the .ui file. This is necessary for
      the packing properties for the scroll area to be
      applied properly: WidgetBuilder::handleChild calls
      `tweakInsertedChild` before `applyPackingProperties`,
      so the child wouldn't yet "inherit" the correct
      packing properties (like grid position) otherwise.
      (Seen in a WIP branch with Writer's "Insert" ->
      "OLE Object" -> "QR and Barcode" dialog with an
      earlier attempt to replace directly, where the
      text field would move to the wrong position.)
    * If it doesn't subclass QAbstractScrollArea, set the
      widget as the scroll area's widget using
      QScrollArea::setWidget.
    
    The first scenario is the one in the "Alt Text"
    dialog described in the commit message quoted above
    and makes that dialog work as expected.
    The second scenario might be relevant in other
    dialogs, because just setting the widget as a
    child might not be sufficient for it to be
    placed and handled properly for scrolling.
    
    Change-Id: If475f8a8108eae958d49e0624e870936456206c0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178484
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/vcl/inc/qt5/QtBuilder.hxx b/vcl/inc/qt5/QtBuilder.hxx
index 743dc9961ec6..aaed05ef434e 100644
--- a/vcl/inc/qt5/QtBuilder.hxx
+++ b/vcl/inc/qt5/QtBuilder.hxx
@@ -41,6 +41,11 @@ private:
 
     std::vector<WinAndId> m_aChildren;
 
+    // vector of pairs, each containing:
+    // * a widget to remove from the widget hierarchy and delete (first item)
+    // * the widget to put in its place instead (second item)
+    std::vector<std::pair<QWidget*, QWidget*>> m_aWidgetReplacements;
+
 public:
     QtBuilder(QObject* pParent, std::u16string_view sUIRoot, const OUString& 
rUIFile);
     virtual ~QtBuilder();
@@ -87,6 +92,8 @@ public:
 
 private:
     static void deleteObject(QObject* pObject);
+    // remove pOldWidget from the widget hierarchy and set (child widget) 
pNewWidget in its place
+    static void replaceWidget(QWidget* pOldWidget, QWidget* pNewWidget);
     void setProperties(QObject* obj, stringmap& rProps);
     static void setLabelProperties(QLabel& rLabel, stringmap& rProps);
     void setSpinButtonProperties(QDoubleSpinBox& rSpinBox, stringmap& rProps);
diff --git a/vcl/qt5/QtBuilder.cxx b/vcl/qt5/QtBuilder.cxx
index 7d78acb281f8..85ad02384437 100644
--- a/vcl/qt5/QtBuilder.cxx
+++ b/vcl/qt5/QtBuilder.cxx
@@ -51,6 +51,10 @@ QtBuilder::QtBuilder(QObject* pParent, std::u16string_view 
sUIRoot, const OUStri
     : WidgetBuilder(sUIRoot, rUIFile, false)
 {
     processUIFile(pParent);
+
+    // tweak widget hierarchy (remove unnecessary parent widgets)
+    for (const std::pair<QWidget*, QWidget*>& rPair : m_aWidgetReplacements)
+        replaceWidget(rPair.first, rPair.second);
 }
 
 QtBuilder::~QtBuilder() {}
@@ -434,6 +438,27 @@ void QtBuilder::tweakInsertedChild(QObject* pParent, 
QObject* pCurrentChild, std
         }
     }
 
+    if (QScrollArea* pScrollAreaParent = qobject_cast<QScrollArea*>(pParent))
+    {
+        if (QAbstractScrollArea* pScrollArea = 
qobject_cast<QAbstractScrollArea*>(pCurrentChild))
+        {
+            // if the child provides scrolling capabilities itself, it doesn't 
need
+            // another scroll area parent -> mark parent scroll area for 
removal
+            m_aWidgetReplacements.emplace_back(pScrollAreaParent, pScrollArea);
+        }
+        else
+        {
+            // set as the scroll area's widget
+            QWidget* pCurrentWidget = nullptr;
+            if (pCurrentChild->isWidgetType())
+                pCurrentWidget = static_cast<QWidget*>(pCurrentChild);
+            else
+                pCurrentWidget = 
static_cast<QLayout*>(pCurrentChild)->parentWidget();
+            assert(pCurrentWidget);
+            pScrollAreaParent->setWidget(pCurrentWidget);
+        }
+    }
+
     if (QDialog* pDialog = qobject_cast<QDialog*>(pCurrentChild))
     {
         // no action needed for QMessageBox, where the default button box is 
used
@@ -625,6 +650,18 @@ void QtBuilder::deleteObject(QObject* pObject)
     pObject->deleteLater();
 }
 
+void QtBuilder::replaceWidget(QWidget* pOldWidget, QWidget* pNewWidget)
+{
+    QWidget* pParent = pOldWidget->parentWidget();
+    assert(pParent);
+    QLayout* pParentLayout = pParent->layout();
+    assert(pParentLayout && "New parent widget has no layout - not supported 
(yet)");
+
+    // replace old with new widget and mark old widget for removal
+    std::unique_ptr<QLayoutItem> 
pOldItem(pParentLayout->replaceWidget(pOldWidget, pNewWidget));
+    deleteObject(pOldWidget);
+}
+
 void QtBuilder::setProperties(QObject* pObject, stringmap& rProps)
 {
     if (QMessageBox* pMessageBox = qobject_cast<QMessageBox*>(pObject))
commit d798242b8a1761e1bbd9f9e8aff205dabd95017e
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Sat Dec 14 19:45:42 2024 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sun Dec 15 01:18:42 2024 +0100

    tdf#130857 qt weld: Support "Alt Text" dialog
    
    Declare support for the "Alt Text" dialog that
    can e.g. be triggered as follows in Writer:
    
    * "Insert" -> "OLE Object" -> "QR and Barcode"
    * type anything, confirm
    * select the QR code
    * right click, select "Alt Text" in the context
      menu
    
    This means that native Qt widgets are used for that dialog
    now when using the qt5 or qt6 VCL plugin and starting LO with
    environment variable SAL_VCL_QT_USE_WELDED_WIDGETS=1 set.
    
    Currently, tab/focus behavior is a little odd,
    as focus first moves to the scroll area that
    the QScrollArea (created for the "GtkScrolledWindow"
    object in the .ui file) before it moves inside the
    QPlainTextEdit (created for the "GtkTextView" object
    in the .ui file) contained therein.
    That will be improved in an upcoming commit.
    
    Change-Id: Ia94fdc8075a76af6a18b656a4c6b9168a408aee0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178483
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/qt5/QtInstanceBuilder.cxx b/vcl/qt5/QtInstanceBuilder.cxx
index 43d939269c7d..bdc1744f259e 100644
--- a/vcl/qt5/QtInstanceBuilder.cxx
+++ b/vcl/qt5/QtInstanceBuilder.cxx
@@ -51,6 +51,7 @@ bool QtInstanceBuilder::IsUIFileSupported(const OUString& 
rUIFile)
     static std::unordered_set<OUString> aSupportedUIFiles = {
         u"cui/ui/aboutdialog.ui"_ustr,
         u"cui/ui/insertrowcolumn.ui"_ustr,
+        u"cui/ui/objecttitledescdialog.ui"_ustr,
         u"cui/ui/optnewdictionarydialog.ui"_ustr,
         u"cui/ui/password.ui"_ustr,
         u"cui/ui/pastespecial.ui"_ustr,

Reply via email to