include/vcl/builderbase.hxx   |    2 ++
 vcl/qt5/QtBuilder.cxx         |   35 +++++++++++++++++++++++++++++------
 vcl/source/window/builder.cxx |   22 +++++++++++-----------
 3 files changed, 42 insertions(+), 17 deletions(-)

New commits:
commit bb7baf41229f2ef6bc7e43a5355a7a32e3ff9276
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Fri Dec 20 00:06:19 2024 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Fri Dec 20 07:15:56 2024 +0100

    tdf#130857 vcl: Move extract* helpers to BuilderBase
    
    This will allow reusing them in QtBuilder in upcoming
    commits.
    
    Change-Id: I74d1cbf936d832443efccaaba4eb6625d32d1437
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178851
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/include/vcl/builderbase.hxx b/include/vcl/builderbase.hxx
index eb3aa847199f..2632dd6417af 100644
--- a/include/vcl/builderbase.hxx
+++ b/include/vcl/builderbase.hxx
@@ -45,6 +45,7 @@ public:
     typedef stringmap Adjustment;
     typedef stringmap TextBuffer;
 
+    static OUString extractActionName(stringmap& rMap);
     static sal_Int32 extractActive(stringmap& rMap);
     static bool extractResizable(stringmap& rMap);
 
@@ -88,6 +89,7 @@ protected:
     static bool extractHeadersVisible(stringmap& rMap);
     static bool extractEntry(stringmap& rMap);
     static OUString extractIconName(stringmap& rMap);
+    static OUString extractLabel(stringmap& rMap);
     static bool extractShowExpanders(stringmap& rMap);
     static OUString extractTitle(stringmap& rMap);
     static OUString extractTooltipText(stringmap& rMap);
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index fd604cbe1c94..62469d222d82 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -953,16 +953,6 @@ namespace
         return nBits;
     }
 
-    OUString extractLabel(VclBuilder::stringmap &rMap)
-    {
-        return extractStringEntry(rMap, u"label"_ustr);
-    }
-
-    OUString extractActionName(VclBuilder::stringmap &rMap)
-    {
-        return extractStringEntry(rMap, u"action-name"_ustr);
-    }
-
     Size extractSizeRequest(VclBuilder::stringmap &rMap)
     {
         OUString sWidthRequest(u"0"_ustr);
@@ -1009,7 +999,7 @@ namespace
         if (!rFrame.is())
             return;
 
-        OUString aCommand(extractActionName(rMap));
+        OUString aCommand(BuilderBase::extractActionName(rMap));
         if (aCommand.isEmpty())
             return;
 
@@ -3355,6 +3345,11 @@ bool 
BuilderBase::hasOrientationVertical(VclBuilder::stringmap &rMap)
     return bVertical;
 }
 
+OUString BuilderBase::extractActionName(stringmap& rMap)
+{
+    return extractStringEntry(rMap, u"action-name"_ustr);
+}
+
 sal_Int32 BuilderBase::extractActive(VclBuilder::stringmap& rMap)
 {
     sal_Int32 nActiveId = 0;
@@ -3403,6 +3398,11 @@ OUString 
BuilderBase::extractIconName(VclBuilder::stringmap &rMap)
     return !sReplace.isEmpty() ? sReplace : sIconName;
 }
 
+OUString BuilderBase::extractLabel(VclBuilder::stringmap& rMap)
+{
+    return extractStringEntry(rMap, u"label"_ustr);
+}
+
 bool BuilderBase::extractResizable(stringmap& rMap)
 {
     return extractBoolEntry(rMap, u"resizable"_ustr, true);
commit 78a27033548ad931932dbc91f2be5637337135d8
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Thu Dec 19 23:35:40 2024 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Fri Dec 20 07:15:45 2024 +0100

    tdf#130857 qt weld: Create QSplitter for "GtkPaned"
    
    GtkPaned [1] allows having two panes, allowing the
    user to adjust the size using a handle.
    
    In Qt, there's QSplitter [2] which would even support
    having more than just two children and also handle it
    in QtBuilder::replaceWidget.
    This is e.g. used in the (not yet supported, but
    seen in an experimental WIP branch) "File" -> "Open Remote"
    dialog in Writer, where the GtkPaned has a GtkScrolledWindow
    child that has a GtkTreeView child, and QTreeView
    (created for the GtkTreeView) is a subclass of
    QAbstractScrollArea, i.e. doesn't need a QScrollArea
    parent in order to be scrollable.
    
    Create a QSplitter for "GtkPaned" objects in .ui
    files.
    
    [1] https://docs.gtk.org/gtk3/class.Paned.html
    [2] https://doc.qt.io/qt-6/qsplitter.html#replaceWidget
    
    Change-Id: I7abaa1a0ca8e00046d5c3b1f2d4e00077b0aa360
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178850
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/vcl/qt5/QtBuilder.cxx b/vcl/qt5/QtBuilder.cxx
index 9cbf6ddaf3a4..f1e5748c1fa3 100644
--- a/vcl/qt5/QtBuilder.cxx
+++ b/vcl/qt5/QtBuilder.cxx
@@ -35,6 +35,7 @@
 #include <QtWidgets/QPushButton>
 #include <QtWidgets/QRadioButton>
 #include <QtWidgets/QScrollArea>
+#include <QtWidgets/QSplitter>
 #include <QtWidgets/QTabWidget>
 #include <QtWidgets/QToolButton>
 #include <QtWidgets/QTreeView>
@@ -278,6 +279,10 @@ QObject* QtBuilder::makeObject(QObject* pParent, 
std::u16string_view sName, std:
     {
         pObject = new QTabWidget(pParentWidget);
     }
+    else if (sName == u"GtkPaned")
+    {
+        pObject = new QSplitter(pParentWidget);
+    }
     else if (sName == u"GtkRadioButton")
     {
         pObject = new QRadioButton(pParentWidget);
@@ -347,8 +352,14 @@ QObject* QtBuilder::makeObject(QObject* pParent, 
std::u16string_view sName, std:
     if (!pWidget)
         pWidget = pLayoutParentWidget;
 
-    QTabWidget* pParentTabWidget = qobject_cast<QTabWidget*>(pParentWidget);
-    if (pParentTabWidget)
+    if (QSplitter* pSplitterParent = qobject_cast<QSplitter*>(pParentWidget))
+    {
+        assert(pWidget);
+        pSplitterParent->addWidget(pWidget);
+        // unset to not create a layout below
+        pParentWidget = nullptr;
+    }
+    else if (QTabWidget* pParentTabWidget = 
qobject_cast<QTabWidget*>(pParentWidget))
     {
         // remove QTabWidget child widget, set via QTabWidget::addTab instead
         assert(pWidget);
@@ -660,11 +671,23 @@ 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));
+    // replace old with new widget and mark old widget for deletion
+    if (QLayout* pParentLayout = pParent->layout())
+    {
+        std::unique_ptr<QLayoutItem> 
pOldItem(pParentLayout->replaceWidget(pOldWidget, pNewWidget));
+    }
+    else if (QSplitter* pSplitter = qobject_cast<QSplitter*>(pParent))
+    {
+        const int nIndex = pSplitter->indexOf(pOldWidget);
+        assert(nIndex >= 0 && "old widget not a child of the splitter");
+        pSplitter->replaceWidget(nIndex, pNewWidget);
+    }
+    else
+    {
+        assert(false && "Unhandled case in replaceWidget - not implemented 
(yet)");
+    }
+
     deleteObject(pOldWidget);
 }
 

Reply via email to