vcl/inc/qt5/QtInstanceTreeView.hxx |    3 +++
 vcl/qt5/QtInstanceBuilder.cxx      |    2 ++
 vcl/qt5/QtInstanceTreeView.cxx     |   34 ++++++++++++++++++++++++++--------
 3 files changed, 31 insertions(+), 8 deletions(-)

New commits:
commit 66a674f915badf9e586b8e3854954d71dc908a4d
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Fri Feb 21 15:33:53 2025 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sat Feb 22 10:53:52 2025 +0100

    tdf#130857 qt weld: Support spelling options dialog
    
    Declare support for the .ui files used for Writer's
    "Tools" -> "Spelling" -> "Options" dialog.
    
    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.
    
    This dialog makes use of the weld::TreeView feature
    of having a special checkbutton column for which support
    was added in the QtInstanceTreeView implementation
    in previous commit
    
        Change-Id: I5889429bf77e69cec4004fd54b2f93454d911c36
        Author: Michael Weghorn <m.wegh...@posteo.de>
        Date:   Fri Feb 21 15:20:49 2025 +0100
    
            tdf#130857 qt weld: Add support for special toggle button column
    
    Change-Id: Ic0b81e9e9d429ad558783121f6981719ee8fe920
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182007
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/qt5/QtInstanceBuilder.cxx b/vcl/qt5/QtInstanceBuilder.cxx
index a9ddf3955f1b..07e5498c6d34 100644
--- a/vcl/qt5/QtInstanceBuilder.cxx
+++ b/vcl/qt5/QtInstanceBuilder.cxx
@@ -67,12 +67,14 @@ bool QtInstanceBuilder::IsUIFileSupported(const OUString& 
rUIFile)
         u"cui/ui/namedialog.ui"_ustr,
         u"cui/ui/numberdialog.ui"_ustr,
         u"cui/ui/objecttitledescdialog.ui"_ustr,
+        u"cui/ui/optlingupage.ui"_ustr,
         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/querydialog.ui"_ustr,
         u"cui/ui/securityoptionsdialog.ui"_ustr,
+        u"cui/ui/spelloptionsdialog.ui"_ustr,
         u"cui/ui/splitcellsdialog.ui"_ustr,
         u"cui/ui/tipofthedaydialog.ui"_ustr,
         u"cui/ui/toolbarmodedialog.ui"_ustr,
commit 24cbe829cfe1e341a67d5aeb4197384259d980ec
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Fri Feb 21 15:20:49 2025 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sat Feb 22 10:53:45 2025 +0100

    tdf#130857 qt weld: Add support for special toggle button column
    
    As the comment for weld::TreeView in weld.hxx says:
    
        /* Model column indexes are considered to begin at 0, but with special 
columns
           before index 0. A expander image column (and an additional optional 
toggle
           button column when enable_toggle_buttons is used). Column index -1 is
           reserved to access those columns.
        */
        class VCL_DLLPUBLIC TreeView : virtual public Widget
    
    Add initial support for the special toggle button
    column (only for checkbuttons/checkboxes initially,
    not radiobuttons).
    
    That special column gets enabled when
    weld::TreeView::enable_toggle_buttons gets called.
    For those methods that provide access, a column
    index of -1 is used to access that special column,
    and the first "normal" column uses an (external)
    column index of 0.
    
    In the QtInstanceTreeView's QStandardItemModel however,
    the special column has an index of 0 (because it
    is the first one) and the next column has a column
    index of 1.
    
    Adjust QtInstanceTreeView::modelIndex to calculate
    the model index accordingly when the special
    column has been enabled.
    
    This is similar to what the GTK and VCL implementations
    do, see GtkInstanceTreeView::to_internal_model
    or SalInstanceTreeView::to_internal_model.
    
    Introduce QtInstanceTreeView::m_bExtraToggleButtonColumnEnabled
    to keep track of whether this column has been enabled.
    
    Add QtInstanceTreeView::toggleButtonModelIndex
    for a helper to get the QModelIndex for the cell
    containing the checkbox for a given row.
    (For now, this assumes that the column index is 0,
    which may or may not change when adding support for
    the other "special column" for the expander image
    also mentioned in the weld::TreeView doc quoted above.
    
    In QtInstanceTreeView::enable_toggle_buttons, resize
    the column according to the contents, as otherwise
    it was taking way too much space when tested with
    an upcoming commit adding support for Writer's
    "Tools" -> "Spelling" -> "Options" dialog.
    
    Change-Id: I5889429bf77e69cec4004fd54b2f93454d911c36
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182006
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/inc/qt5/QtInstanceTreeView.hxx 
b/vcl/inc/qt5/QtInstanceTreeView.hxx
index 0edcf22d6095..59574cd75eee 100644
--- a/vcl/inc/qt5/QtInstanceTreeView.hxx
+++ b/vcl/inc/qt5/QtInstanceTreeView.hxx
@@ -22,6 +22,8 @@ class QtInstanceTreeView : public QtInstanceWidget, public 
virtual weld::TreeVie
     QStandardItemModel* m_pModel;
     QItemSelectionModel* m_pSelectionModel;
 
+    bool m_bExtraToggleButtonColumnEnabled = false;
+
 public:
     QtInstanceTreeView(QTreeView* pTreeView);
 
@@ -190,6 +192,7 @@ private:
     QModelIndex modelIndex(int nRow, int nCol = 0) const;
     QModelIndex modelIndex(const weld::TreeIter& rIter, int nCol = 0) const;
     static int rowIndex(const weld::TreeIter& rIter);
+    QModelIndex toggleButtonModelIndex(int nRow) const;
     QModelIndex firstTextColumnModelIndex(int nRow) const;
     static QAbstractItemView::SelectionMode mapSelectionMode(SelectionMode 
eMode);
 
diff --git a/vcl/qt5/QtInstanceTreeView.cxx b/vcl/qt5/QtInstanceTreeView.cxx
index f0a678e0a79a..b7bb97e0593e 100644
--- a/vcl/qt5/QtInstanceTreeView.cxx
+++ b/vcl/qt5/QtInstanceTreeView.cxx
@@ -14,6 +14,8 @@
 
 #include <vcl/qt/QtUtils.hxx>
 
+#include <QtWidgets/QHeaderView>
+
 // role used for the ID in the QStandardItem
 constexpr int ROLE_ID = Qt::UserRole + 1000;
 
@@ -66,6 +68,9 @@ void QtInstanceTreeView::insert(const weld::TreeIter* 
pParent, int nPos, const O
         else if (pImageSurface)
             pItem->setIcon(toQPixmap(*pImageSurface));
 
+        if (m_bExtraToggleButtonColumnEnabled)
+            
m_pModel->itemFromIndex(toggleButtonModelIndex(nPos))->setCheckable(true);
+
         if (pRet)
             static_cast<QtInstanceTreeIter*>(pRet)->setModelIndex(aIndex);
     });
@@ -110,9 +115,16 @@ OUString QtInstanceTreeView::get_selected_id() const
     return sId;
 }
 
-void QtInstanceTreeView::enable_toggle_buttons(weld::ColumnToggleType)
+void QtInstanceTreeView::enable_toggle_buttons(weld::ColumnToggleType eType)
 {
-    assert(false && "Not implemented yet");
+    (void)eType;
+    assert(eType == weld::ColumnToggleType::Check && "Only checkboxes 
supported so far");
+
+    assert(m_pModel->rowCount() == 0 && "Must be called before inserting any 
data");
+
+    m_bExtraToggleButtonColumnEnabled = true;
+
+    m_pTreeView->header()->setSectionResizeMode(0, 
QHeaderView::ResizeToContents);
 }
 
 void QtInstanceTreeView::set_clicks_to_toggle(int) { assert(false && "Not 
implemented yet"); }
@@ -231,25 +243,21 @@ void QtInstanceTreeView::set_id(int nRow, const OUString& 
rId)
 
 void QtInstanceTreeView::set_toggle(int nRow, TriState eState, int nCol)
 {
-    assert(nCol != -1 && "Special column index -1 not handled yet");
-
     SolarMutexGuard g;
 
     GetQtInstance().RunInMainThread([&] {
-        const QModelIndex aIndex = modelIndex(nRow, nCol);
+        QModelIndex aIndex = nCol == -1 ? toggleButtonModelIndex(nRow) : 
modelIndex(nRow, nCol);
         m_pModel->itemFromIndex(aIndex)->setCheckState(toQtCheckState(eState));
     });
 }
 
 TriState QtInstanceTreeView::get_toggle(int nRow, int nCol) const
 {
-    assert(nCol != -1 && "Special column index -1 not handled yet");
-
     SolarMutexGuard g;
 
     TriState eState = TRISTATE_INDET;
     GetQtInstance().RunInMainThread([&] {
-        const QModelIndex aIndex = modelIndex(nRow, nCol);
+        QModelIndex aIndex = nCol == -1 ? toggleButtonModelIndex(nRow) : 
modelIndex(nRow, nCol);
         eState = toVclTriState(m_pModel->itemFromIndex(aIndex)->checkState());
     });
 
@@ -905,6 +913,8 @@ QAbstractItemView::SelectionMode 
QtInstanceTreeView::mapSelectionMode(SelectionM
 
 QModelIndex QtInstanceTreeView::modelIndex(int nRow, int nCol) const
 {
+    if (m_bExtraToggleButtonColumnEnabled)
+        nCol += 1;
     return m_pModel->index(nRow, nCol);
 }
 
@@ -919,6 +929,14 @@ int QtInstanceTreeView::rowIndex(const weld::TreeIter& 
rIter)
     return aModelIndex.row();
 }
 
+QModelIndex QtInstanceTreeView::toggleButtonModelIndex(int nRow) const
+{
+    assert(m_bExtraToggleButtonColumnEnabled && "Special toggle button column 
is not enabled");
+
+    // Special toggle button column is always the first one
+    return m_pModel->index(nRow, 0);
+}
+
 QModelIndex QtInstanceTreeView::firstTextColumnModelIndex(int nRow) const
 {
     for (int i = 0; i < m_pModel->columnCount(); i++)

Reply via email to