vcl/CustomTarget_qt5_moc.mk     |    1 
 vcl/CustomTarget_qt6_moc.mk     |    1 
 vcl/inc/qt5/QtInstanceEntry.hxx |    4 ++
 vcl/qt5/QtInstanceComboBox.cxx  |   59 +++++++++++++++++++++++++++++++++++-----
 vcl/qt5/QtInstanceEntry.cxx     |    5 +++
 5 files changed, 62 insertions(+), 8 deletions(-)

New commits:
commit 0d2188d376829115bfb096f946973f05fde31a51
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Thu Oct 24 12:37:15 2024 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Fri Oct 25 08:57:24 2024 +0200

    tdf#130857 qt weld: Implement QtInstanceComboBox::{g,s}et_active_id
    
    This is made use of e.g. in the "Tools" ->
    "Options" -> "Languages and Locales" -> "Writing Aids"
    -> "New" dialog" in a WIP branch where that dialog's
    .ui file ("cui/ui/optnewdictionarydialog.ui") was added to the
    list of supported files for QtInstanceBuilder.
    
    Change-Id: I5099672bac495bf47cc0d6aa806a69e8729066e1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175546
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/vcl/qt5/QtInstanceComboBox.cxx b/vcl/qt5/QtInstanceComboBox.cxx
index bf0dbb1a092e..3915f2728c4a 100644
--- a/vcl/qt5/QtInstanceComboBox.cxx
+++ b/vcl/qt5/QtInstanceComboBox.cxx
@@ -145,11 +145,27 @@ int QtInstanceComboBox::find_text(const OUString& rStr) 
const
 
 OUString QtInstanceComboBox::get_active_id() const
 {
-    assert(false && "Not implemented yet");
-    return OUString();
+    SolarMutexGuard g;
+
+    OUString sId;
+    GetQtInstance().RunInMainThread([&] {
+        QVariant aUserData = m_pComboBox->currentData();
+        if (aUserData.canConvert<QString>())
+            sId = toOUString(aUserData.toString());
+    });
+
+    return sId;
 }
 
-void QtInstanceComboBox::set_active_id(const OUString&) { assert(false && "Not 
implemented yet"); }
+void QtInstanceComboBox::set_active_id(const OUString& rId)
+{
+    SolarMutexGuard g;
+
+    GetQtInstance().RunInMainThread([&] {
+        int nIndex = find_id(rId);
+        set_active(nIndex);
+    });
+}
 
 OUString QtInstanceComboBox::get_id(int nPos) const
 {
commit 2db9f1c08e28d0ae06be7db5a20912f9198468f0
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Thu Oct 24 12:27:27 2024 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Fri Oct 25 08:57:17 2024 +0200

    tdf#130857 qt weld: Notify about weld::Entry text/cursor changes
    
    In QtInstanceEntry, notify about cursor and text
    changes by connecting to the corresponding
    QLineEdit signals and calling
    weld::Entry::signal_cursor_position and
    weld::Entrysignal_changed accordingly.
    
    This is made use of e.g. in the "Tools" ->
    "Options" -> "Languages and Locales" -> "Writing Aids"
    -> "New" dialog" in a WIP branch where that dialog's
    .ui file ("cui/ui/optnewdictionarydialog.ui") was added to the
    list of supported files for QtInstanceBuilder.
    Without this commit, the "OK" button would remain
    greyed out even after typing a new name in the
    edit.
    
    Change-Id: I006ed711652c65b0af1d8af5ae5c4dc80691a9b3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175545
    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 857b3eb41a65..eece23bda8bf 100644
--- a/vcl/CustomTarget_qt5_moc.mk
+++ b/vcl/CustomTarget_qt5_moc.mk
@@ -16,6 +16,7 @@ $(call gb_CustomTarget_get_target,vcl/qt5) : \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtInstance.moc \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceComboBox.moc \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceDialog.moc \
+       $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceEntry.moc \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceMessageDialog.moc \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtMainWindow.moc \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtMenu.moc \
diff --git a/vcl/CustomTarget_qt6_moc.mk b/vcl/CustomTarget_qt6_moc.mk
index a58f79a2bbf4..0e05b21b4fb0 100644
--- a/vcl/CustomTarget_qt6_moc.mk
+++ b/vcl/CustomTarget_qt6_moc.mk
@@ -16,6 +16,7 @@ $(call gb_CustomTarget_get_target,vcl/qt6) : \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtInstance.moc \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceComboBox.moc \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceDialog.moc \
+       $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceEntry.moc \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceMessageDialog.moc \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtMainWindow.moc \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtMenu.moc \
diff --git a/vcl/inc/qt5/QtInstanceEntry.hxx b/vcl/inc/qt5/QtInstanceEntry.hxx
index 001d6714bcc4..4007765a41f8 100644
--- a/vcl/inc/qt5/QtInstanceEntry.hxx
+++ b/vcl/inc/qt5/QtInstanceEntry.hxx
@@ -13,8 +13,10 @@
 
 #include <QtWidgets/QLineEdit>
 
-class QtInstanceEntry : public QtInstanceWidget, public virtual weld::Entry
+class QtInstanceEntry : public QObject, public QtInstanceWidget, public 
virtual weld::Entry
 {
+    Q_OBJECT;
+
     QLineEdit* m_pLineEdit;
 
 public:
diff --git a/vcl/qt5/QtInstanceEntry.cxx b/vcl/qt5/QtInstanceEntry.cxx
index 4b40eb48bb9a..f1001cc834db 100644
--- a/vcl/qt5/QtInstanceEntry.cxx
+++ b/vcl/qt5/QtInstanceEntry.cxx
@@ -8,6 +8,7 @@
  */
 
 #include <QtInstanceEntry.hxx>
+#include <QtInstanceEntry.moc>
 
 #include <vcl/qt/QtUtils.hxx>
 
@@ -16,6 +17,10 @@ QtInstanceEntry::QtInstanceEntry(QLineEdit* pLineEdit)
     , m_pLineEdit(pLineEdit)
 {
     assert(m_pLineEdit);
+
+    QObject::connect(m_pLineEdit, &QLineEdit::cursorPositionChanged, this,
+                     [&] { signal_cursor_position(); });
+    QObject::connect(m_pLineEdit, &QLineEdit::textEdited, this, [&] { 
signal_changed(); });
 }
 
 void QtInstanceEntry::set_text(const OUString& rText)
commit 4b1a85ec15de0c0aa3e6537e0b2fb10ccc0e38fe
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Thu Oct 24 10:49:38 2024 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Fri Oct 25 08:57:10 2024 +0200

    tdf#130857 qt weld: Implement combobox text selection
    
    QComboBox::LineEdit provides access to the combobox's
    line edit, which can then be used to retrieve/modify
    the text selection.
    
    Make use of that to implement
    QtInstanceComboBox::get_entry_selection_bounds
    and QtInstanceComboBox::select_entry_region.
    
    Change-Id: I5aa0abd9e24c58cafda9032d631bd8c028c037ae
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175544
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/qt5/QtInstanceComboBox.cxx b/vcl/qt5/QtInstanceComboBox.cxx
index c623104c8a38..bf0dbb1a092e 100644
--- a/vcl/qt5/QtInstanceComboBox.cxx
+++ b/vcl/qt5/QtInstanceComboBox.cxx
@@ -12,6 +12,8 @@
 
 #include <vcl/qt/QtUtils.hxx>
 
+#include <QtWidgets/QLineEdit>
+
 QtInstanceComboBox::QtInstanceComboBox(QComboBox* pComboBox)
     : QtInstanceWidget(pComboBox)
     , m_pComboBox(pComboBox)
@@ -215,12 +217,39 @@ void QtInstanceComboBox::set_entry_width_chars(int) { 
assert(false && "Not imple
 
 void QtInstanceComboBox::set_entry_max_length(int) { assert(false && "Not 
implemented yet"); }
 
-void QtInstanceComboBox::select_entry_region(int, int) { assert(false && "Not 
implemented yet"); }
+void QtInstanceComboBox::select_entry_region(int nStartPos, int nEndPos)
+{
+    SolarMutexGuard g;
+
+    GetQtInstance().RunInMainThread([&] {
+        QLineEdit* pEdit = m_pComboBox->lineEdit();
+        if (pEdit)
+        {
+            if (nEndPos == -1)
+                nEndPos = pEdit->text().length();
+
+            const int nLength = nEndPos - nStartPos;
+            pEdit->setSelection(nStartPos, nLength);
+        }
+    });
+}
 
-bool QtInstanceComboBox::get_entry_selection_bounds(int&, int&)
+bool QtInstanceComboBox::get_entry_selection_bounds(int& rStartPos, int& 
rEndPos)
 {
-    assert(false && "Not implemented yet");
-    return false;
+    SolarMutexGuard g;
+
+    bool bHasSelection = false;
+    GetQtInstance().RunInMainThread([&] {
+        QLineEdit* pEdit = m_pComboBox->lineEdit();
+        if (pEdit)
+        {
+            bHasSelection = pEdit->hasSelectedText();
+            rStartPos = pEdit->selectionStart();
+            rEndPos = pEdit->selectionEnd();
+        }
+    });
+
+    return bHasSelection;
 }
 
 void QtInstanceComboBox::set_entry_completion(bool, bool)

Reply via email to