diff options
author | Michael Weghorn <m.weghorn@posteo.de> | 2024-10-04 16:36:16 +0200 |
---|---|---|
committer | Michael Weghorn <m.weghorn@posteo.de> | 2024-10-05 09:39:13 +0200 |
commit | 778fb6b8f7273f8c792c3c7c78e5ec2acb5e3463 (patch) | |
tree | 4c1a40b1ec714340df60a680fcd4e768801d4f65 /vcl | |
parent | 5c114216707d5bbc52ac361c802a696f64f8016c (diff) |
tdf#130857 qt weld: Add QtInstanceEntry
Add a native Qt implementation for weld::Entry,
QtInstanceEntry, that uses a QLineEdit,
and let QtInstanceBuilder use it when it
encounters a "GtkEntry" object in a .ui file.
Implement the most straightforward and probably most
relevant methods, and trigger an assert in case one of
the not yet implemented methods gets called for now.
These can be implemented when adding support
for .ui files whose dialogs make use of these
features.
None of the .ui files currently marked as
supported by QtInstanceBuilder uses this new class
yet, but it will be needed to support more in the future.
Change-Id: I56e26fe22b1cc0cb7d61cfd1503991273957e23f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174489
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/Library_vclplug_qt5.mk | 1 | ||||
-rw-r--r-- | vcl/Library_vclplug_qt6.mk | 1 | ||||
-rw-r--r-- | vcl/inc/qt5/QtInstanceBuilder.hxx | 2 | ||||
-rw-r--r-- | vcl/inc/qt5/QtInstanceEntry.hxx | 51 | ||||
-rw-r--r-- | vcl/inc/qt6/QtInstanceEntry.hxx | 12 | ||||
-rw-r--r-- | vcl/qt5/QtBuilder.cxx | 5 | ||||
-rw-r--r-- | vcl/qt5/QtInstanceBuilder.cxx | 9 | ||||
-rw-r--r-- | vcl/qt5/QtInstanceEntry.cxx | 141 | ||||
-rw-r--r-- | vcl/qt6/QtInstanceEntry.cxx | 12 |
9 files changed, 230 insertions, 4 deletions
diff --git a/vcl/Library_vclplug_qt5.mk b/vcl/Library_vclplug_qt5.mk index b17b5d336462..d3046eba60a4 100644 --- a/vcl/Library_vclplug_qt5.mk +++ b/vcl/Library_vclplug_qt5.mk @@ -100,6 +100,7 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_qt5,\ vcl/qt5/QtInstanceCheckButton \ vcl/qt5/QtInstanceContainer \ vcl/qt5/QtInstanceDialog \ + vcl/qt5/QtInstanceEntry \ vcl/qt5/QtInstanceMessageDialog \ vcl/qt5/QtInstanceLabel \ vcl/qt5/QtInstanceWidget \ diff --git a/vcl/Library_vclplug_qt6.mk b/vcl/Library_vclplug_qt6.mk index 684c7d409e1f..832adf500931 100644 --- a/vcl/Library_vclplug_qt6.mk +++ b/vcl/Library_vclplug_qt6.mk @@ -99,6 +99,7 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_qt6,\ vcl/qt6/QtInstanceCheckButton \ vcl/qt6/QtInstanceContainer \ vcl/qt6/QtInstanceDialog \ + vcl/qt6/QtInstanceEntry \ vcl/qt6/QtInstanceLabel \ vcl/qt6/QtInstanceMessageDialog \ vcl/qt6/QtInstanceWidget \ diff --git a/vcl/inc/qt5/QtInstanceBuilder.hxx b/vcl/inc/qt5/QtInstanceBuilder.hxx index ff5d9e83fc68..713f7c5fed6a 100644 --- a/vcl/inc/qt5/QtInstanceBuilder.hxx +++ b/vcl/inc/qt5/QtInstanceBuilder.hxx @@ -55,7 +55,7 @@ public: virtual std::unique_ptr<weld::Spinner> weld_spinner(const OUString&) override; virtual std::unique_ptr<weld::Image> weld_image(const OUString&) override; virtual std::unique_ptr<weld::Calendar> weld_calendar(const OUString&) override; - virtual std::unique_ptr<weld::Entry> weld_entry(const OUString&) override; + virtual std::unique_ptr<weld::Entry> weld_entry(const OUString& rId) override; virtual std::unique_ptr<weld::SpinButton> weld_spin_button(const OUString&) override; virtual std::unique_ptr<weld::MetricSpinButton> weld_metric_spin_button(const OUString&, FieldUnit) override; diff --git a/vcl/inc/qt5/QtInstanceEntry.hxx b/vcl/inc/qt5/QtInstanceEntry.hxx new file mode 100644 index 000000000000..001d6714bcc4 --- /dev/null +++ b/vcl/inc/qt5/QtInstanceEntry.hxx @@ -0,0 +1,51 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 "QtInstanceWidget.hxx" + +#include <QtWidgets/QLineEdit> + +class QtInstanceEntry : public QtInstanceWidget, public virtual weld::Entry +{ + QLineEdit* m_pLineEdit; + +public: + QtInstanceEntry(QLineEdit* pLineEdit); + + virtual void set_text(const OUString& rText) override; + virtual OUString get_text() const override; + virtual void set_width_chars(int nChars) override; + virtual int get_width_chars() const override; + virtual void set_max_length(int nChars) override; + virtual void select_region(int nStartPos, int nEndPos) override; + virtual bool get_selection_bounds(int& rStartPos, int& rEndPos) override; + virtual void replace_selection(const OUString& rText) override; + virtual void set_position(int nCursorPos) override; + virtual int get_position() const override; + virtual void set_editable(bool bEditable) override; + virtual bool get_editable() const override; + virtual void set_message_type(weld::EntryMessageType eType) override; + virtual void set_placeholder_text(const OUString& rText) override; + + virtual void set_overwrite_mode(bool bOn) override; + virtual bool get_overwrite_mode() const override; + + virtual void set_font(const vcl::Font& rFont) override; + virtual void set_font_color(const Color& rColor) override; + + virtual void cut_clipboard() override; + virtual void copy_clipboard() override; + virtual void paste_clipboard() override; + + virtual void set_alignment(TxtAlign eXAlign) override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/qt6/QtInstanceEntry.hxx b/vcl/inc/qt6/QtInstanceEntry.hxx new file mode 100644 index 000000000000..f8b85d462faa --- /dev/null +++ b/vcl/inc/qt6/QtInstanceEntry.hxx @@ -0,0 +1,12 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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/QtInstanceEntry.hxx" + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/qt5/QtBuilder.cxx b/vcl/qt5/QtBuilder.cxx index da4bb8ec5974..bc1dac89b15e 100644 --- a/vcl/qt5/QtBuilder.cxx +++ b/vcl/qt5/QtBuilder.cxx @@ -19,6 +19,7 @@ #include <QtWidgets/QDialogButtonBox> #include <QtWidgets/QGroupBox> #include <QtWidgets/QLabel> +#include <QtWidgets/QLineEdit> #include <QtWidgets/QLayout> #include <QtWidgets/QPushButton> @@ -144,6 +145,10 @@ QObject* QtBuilder::makeObject(QObject* pParent, std::u16string_view sName, cons { pObject = new QDialog(pParentWidget); } + else if (sName == u"GtkEntry") + { + pObject = new QLineEdit(pParentWidget); + } else if (sName == u"GtkFrame") { pObject = new QGroupBox(pParentWidget); diff --git a/vcl/qt5/QtInstanceBuilder.cxx b/vcl/qt5/QtInstanceBuilder.cxx index b4f608d49932..8bab727f6800 100644 --- a/vcl/qt5/QtInstanceBuilder.cxx +++ b/vcl/qt5/QtInstanceBuilder.cxx @@ -13,6 +13,7 @@ #include <QtBuilder.hxx> #include <QtInstanceCheckButton.hxx> +#include <QtInstanceEntry.hxx> #include <QtInstanceLabel.hxx> #include <QtInstanceMessageDialog.hxx> @@ -193,10 +194,12 @@ std::unique_ptr<weld::Calendar> QtInstanceBuilder::weld_calendar(const OUString& return nullptr; } -std::unique_ptr<weld::Entry> QtInstanceBuilder::weld_entry(const OUString&) +std::unique_ptr<weld::Entry> QtInstanceBuilder::weld_entry(const OUString& rId) { - assert(false && "Not implemented yet"); - return nullptr; + QLineEdit* pLineEdit = m_xBuilder->get<QLineEdit>(rId); + std::unique_ptr<weld::Entry> xRet(pLineEdit ? std::make_unique<QtInstanceEntry>(pLineEdit) + : nullptr); + return xRet; } std::unique_ptr<weld::SpinButton> QtInstanceBuilder::weld_spin_button(const OUString&) diff --git a/vcl/qt5/QtInstanceEntry.cxx b/vcl/qt5/QtInstanceEntry.cxx new file mode 100644 index 000000000000..f1ab7bf824fc --- /dev/null +++ b/vcl/qt5/QtInstanceEntry.cxx @@ -0,0 +1,141 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <QtInstanceEntry.hxx> + +QtInstanceEntry::QtInstanceEntry(QLineEdit* pLineEdit) + : QtInstanceWidget(pLineEdit) + , m_pLineEdit(pLineEdit) +{ + assert(m_pLineEdit); +} + +void QtInstanceEntry::set_text(const OUString& rText) +{ + SolarMutexGuard g; + GetQtInstance().RunInMainThread([&] { m_pLineEdit->setText(toQString(rText)); }); +} + +OUString QtInstanceEntry::get_text() const +{ + SolarMutexGuard g; + OUString sText; + GetQtInstance().RunInMainThread([&] { sText = toOUString(m_pLineEdit->text()); }); + return sText; +} + +void QtInstanceEntry::set_width_chars(int) { assert(false && "Not implemented yet"); } + +int QtInstanceEntry::get_width_chars() const +{ + assert(false && "Not implemented yet"); + return -1; +} + +void QtInstanceEntry::set_max_length(int nChars) +{ + SolarMutexGuard g; + GetQtInstance().RunInMainThread([&] { m_pLineEdit->setMaxLength(nChars); }); +} + +void QtInstanceEntry::select_region(int nStartPos, int nEndPos) +{ + SolarMutexGuard g; + + GetQtInstance().RunInMainThread([&] { + if (nEndPos == -1) + nEndPos = m_pLineEdit->text().length(); + + const int nLength = nEndPos - nStartPos; + m_pLineEdit->setSelection(nStartPos, nLength); + }); +} + +bool QtInstanceEntry::get_selection_bounds(int& rStartPos, int& rEndPos) +{ + SolarMutexGuard g; + + bool bHasSelection = false; + GetQtInstance().RunInMainThread([&] { + bHasSelection = m_pLineEdit->hasSelectedText(); + rStartPos = m_pLineEdit->selectionStart(); + rEndPos = m_pLineEdit->selectionEnd(); + }); + + return bHasSelection; +} + +void QtInstanceEntry::replace_selection(const OUString& rText) +{ + SolarMutexGuard g; + GetQtInstance().RunInMainThread([&] { m_pLineEdit->insert(toQString(rText)); }); +} + +void QtInstanceEntry::set_position(int nCursorPos) +{ + SolarMutexGuard g; + GetQtInstance().RunInMainThread([&] { m_pLineEdit->setCursorPosition(nCursorPos); }); +} + +int QtInstanceEntry::get_position() const +{ + SolarMutexGuard g; + int nCursorPos = 0; + GetQtInstance().RunInMainThread([&] { nCursorPos = m_pLineEdit->cursorPosition(); }); + + return nCursorPos; +} + +void QtInstanceEntry::set_editable(bool bEditable) +{ + SolarMutexGuard g; + GetQtInstance().RunInMainThread([&] { m_pLineEdit->setReadOnly(!bEditable); }); +} + +bool QtInstanceEntry::get_editable() const +{ + SolarMutexGuard g; + bool bEditable = false; + GetQtInstance().RunInMainThread([&] { bEditable = !m_pLineEdit->isReadOnly(); }); + + return bEditable; +} + +void QtInstanceEntry::set_message_type(weld::EntryMessageType) +{ + assert(false && "Not implemented yet"); +} + +void QtInstanceEntry::set_placeholder_text(const OUString& rText) +{ + SolarMutexGuard g; + GetQtInstance().RunInMainThread([&] { m_pLineEdit->setPlaceholderText(toQString(rText)); }); +} + +void QtInstanceEntry::set_overwrite_mode(bool) { assert(false && "Not implemented yet"); } + +bool QtInstanceEntry::get_overwrite_mode() const +{ + assert(false && "Not implemented yet"); + return false; +} + +void QtInstanceEntry::set_font(const vcl::Font&) { assert(false && "Not implemented yet"); } + +void QtInstanceEntry::set_font_color(const Color&) { assert(false && "Not implemented yet"); } + +void QtInstanceEntry::cut_clipboard() { assert(false && "Not implemented yet"); } + +void QtInstanceEntry::copy_clipboard() { assert(false && "Not implemented yet"); } + +void QtInstanceEntry::paste_clipboard() { assert(false && "Not implemented yet"); } + +void QtInstanceEntry::set_alignment(TxtAlign) { assert(false && "Not implemented yet"); } + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/qt6/QtInstanceEntry.cxx b/vcl/qt6/QtInstanceEntry.cxx new file mode 100644 index 000000000000..7cf1bf2c023f --- /dev/null +++ b/vcl/qt6/QtInstanceEntry.cxx @@ -0,0 +1,12 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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/QtInstanceEntry.cxx" + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |