vcl/Library_vclplug_qt5.mk | 2 + vcl/Library_vclplug_qt6.mk | 2 + vcl/inc/qt5/QtHyperlinkLabel.hxx | 37 +++++++++++++++++++++++++ vcl/inc/qt5/QtInstanceBuilder.hxx | 2 - vcl/inc/qt5/QtInstanceLinkButton.hxx | 31 +++++++++++++++++++++ vcl/inc/qt6/QtHyperlinkLabel.hxx | 12 ++++++++ vcl/inc/qt6/QtInstanceLinkButton.hxx | 12 ++++++++ vcl/qt5/QtBuilder.cxx | 13 ++++++++ vcl/qt5/QtHyperlinkLabel.cxx | 34 +++++++++++++++++++++++ vcl/qt5/QtInstanceBuilder.cxx | 9 ++++-- vcl/qt5/QtInstanceLinkButton.cxx | 51 +++++++++++++++++++++++++++++++++++ vcl/qt6/QtHyperlinkLabel.cxx | 12 ++++++++ vcl/qt6/QtInstanceLinkButton.cxx | 12 ++++++++ 13 files changed, 225 insertions(+), 4 deletions(-)
New commits: commit 4689363f7259a4364c38d40664bd9cf3d945ed30 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Fri Oct 25 20:45:39 2024 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Sat Oct 26 13:11:35 2024 +0200 tdf#130857 qt weld: Add child layouts to grid If a QLayout object is created as the child of a QGridLayout object (e.g. a "GtkBox" as the direct child of a "GtkGrid" in a .ui file), add that layout to the QGridLayout - initially in a new row, but rearranging that will be done as part of processing the "packing" properties of the children once that is implemented for layouts as well. (See QtBuilder::applyPackingProperties and QtBuilder::applyGridPackingProperties where this is currently only implemented for QWidget children). This will be needed e.g. for the "Help" -> "About LibreOfficeDev" dialog. Change-Id: I292134b26efa0dfe5c8fe0684dc02dece338d579 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175659 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/vcl/qt5/QtBuilder.cxx b/vcl/qt5/QtBuilder.cxx index 31e86f0b2543..d59f76a3ed35 100644 --- a/vcl/qt5/QtBuilder.cxx +++ b/vcl/qt5/QtBuilder.cxx @@ -243,6 +243,8 @@ QObject* QtBuilder::makeObject(QObject* pParent, std::u16string_view sName, cons // add layout to parent layout if (QBoxLayout* pParentBoxLayout = qobject_cast<QBoxLayout*>(pParentLayout)) pParentBoxLayout->addLayout(pLayout); + else if (QGridLayout* pParentGridLayout = qobject_cast<QGridLayout*>(pParentLayout)) + pParentGridLayout->addLayout(pLayout, pParentGridLayout->rowCount(), 0); } m_aChildren.emplace_back(sID, pObject); commit 0846977a2280824006fb1620706cc785802336e3 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Fri Oct 25 20:41:48 2024 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Sat Oct 26 13:11:19 2024 +0200 tdf#130857 qt weld: Add a QtInstanceLinkButton Add a new QtInstanceLinkButton class that is the weld::LinkButton implementing using a native Qt widget. QLabel can be used to display a hyperlink, as it supports the HTML syntax for the text, so using , QLabel myLabel; myLabel.setText(QLatin1String("<a href=\"https://www.libreoffice.org">LibreOffice Website</a>")); can be used to let the QLabel handle a hyperlink. To make it simple to set this as needed for a QLabel, implement a new QLabel subclass called QtHyperlinkLabel that provides convenient getters and setters to set the displayed text and the link target, and takes care of setting the QLabel text based on that as needed. Implement QtInstanceLinkButton using an instance of that class as the widget and create an instance of that class in QtBuilder when encountering a "GtkLinkButton" object while processing a .ui file and evaluate the "label" and "uri" properties. Change-Id: I71d28b6e5e3cbd110ec5b3d1232d55e9d2bb8a1b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175656 Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> Tested-by: Jenkins diff --git a/vcl/Library_vclplug_qt5.mk b/vcl/Library_vclplug_qt5.mk index 2a60b474b2d1..2a8441a566b0 100644 --- a/vcl/Library_vclplug_qt5.mk +++ b/vcl/Library_vclplug_qt5.mk @@ -93,6 +93,7 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_qt5,\ vcl/qt5/QtGraphics_Controls \ vcl/qt5/QtGraphics_GDI \ vcl/qt5/QtGraphics_Text \ + vcl/qt5/QtHyperlinkLabel \ vcl/qt5/QtInstance \ vcl/qt5/QtInstance_Print \ vcl/qt5/QtInstanceBuilder \ @@ -104,6 +105,7 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_qt5,\ vcl/qt5/QtInstanceEntry \ vcl/qt5/QtInstanceFrame \ vcl/qt5/QtInstanceImage \ + vcl/qt5/QtInstanceLinkButton \ vcl/qt5/QtInstanceMessageDialog \ vcl/qt5/QtInstanceLabel \ vcl/qt5/QtInstanceRadioButton \ diff --git a/vcl/Library_vclplug_qt6.mk b/vcl/Library_vclplug_qt6.mk index 485db0a19768..e5247de86c4e 100644 --- a/vcl/Library_vclplug_qt6.mk +++ b/vcl/Library_vclplug_qt6.mk @@ -92,6 +92,7 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_qt6,\ vcl/qt6/QtGraphics_Controls \ vcl/qt6/QtGraphics_GDI \ vcl/qt6/QtGraphics_Text \ + vcl/qt6/QtHyperlinkLabel \ vcl/qt6/QtInstance \ vcl/qt6/QtInstance_Print \ vcl/qt6/QtInstanceBuilder \ @@ -104,6 +105,7 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_qt6,\ vcl/qt6/QtInstanceFrame \ vcl/qt6/QtInstanceImage \ vcl/qt6/QtInstanceLabel \ + vcl/qt6/QtInstanceLinkButton \ vcl/qt6/QtInstanceMessageDialog \ vcl/qt6/QtInstanceRadioButton \ vcl/qt6/QtInstanceTextView \ diff --git a/vcl/inc/qt5/QtHyperlinkLabel.hxx b/vcl/inc/qt5/QtHyperlinkLabel.hxx new file mode 100644 index 000000000000..f188f2ba9e18 --- /dev/null +++ b/vcl/inc/qt5/QtHyperlinkLabel.hxx @@ -0,0 +1,37 @@ +/* -*- 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 <QtWidgets/QLabel> + +/** + * QLabel subclass for a label that holds a hyperlink, + * with convenient getters/setters for the displayed text + * and the hyperlink target. + */ +class QtHyperlinkLabel : public QLabel +{ + QString m_sDisplayText; + QString m_sUri; + +public: + QtHyperlinkLabel(QWidget* pParent); + + QString displayText() const { return m_sDisplayText; } + void setDisplayText(const QString& rDisplayText); + + QString uri() const { return m_sUri; } + void setUri(const QString& rUri); + +private: + void update(); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/qt5/QtInstanceBuilder.hxx b/vcl/inc/qt5/QtInstanceBuilder.hxx index cc02e6ce3b21..6df0b81dd335 100644 --- a/vcl/inc/qt5/QtInstanceBuilder.hxx +++ b/vcl/inc/qt5/QtInstanceBuilder.hxx @@ -45,7 +45,7 @@ public: virtual std::unique_ptr<weld::MenuButton> weld_menu_button(const OUString&) override; virtual std::unique_ptr<weld::MenuToggleButton> weld_menu_toggle_button(const OUString&) override; - virtual std::unique_ptr<weld::LinkButton> weld_link_button(const OUString&) override; + virtual std::unique_ptr<weld::LinkButton> weld_link_button(const OUString& rId) override; virtual std::unique_ptr<weld::ToggleButton> weld_toggle_button(const OUString&) override; virtual std::unique_ptr<weld::RadioButton> weld_radio_button(const OUString& rId) override; virtual std::unique_ptr<weld::CheckButton> weld_check_button(const OUString& rId) override; diff --git a/vcl/inc/qt5/QtInstanceLinkButton.hxx b/vcl/inc/qt5/QtInstanceLinkButton.hxx new file mode 100644 index 000000000000..d87ffde4c706 --- /dev/null +++ b/vcl/inc/qt5/QtInstanceLinkButton.hxx @@ -0,0 +1,31 @@ +/* -*- 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 "QtHyperlinkLabel.hxx" +#include "QtInstanceWidget.hxx" + +#include <QtWidgets/QLabel> + +class QtInstanceLinkButton : public QtInstanceWidget, public virtual weld::LinkButton +{ + QtHyperlinkLabel* m_pLabel; + +public: + QtInstanceLinkButton(QtHyperlinkLabel* pLabel); + + virtual void set_label(const OUString& rText) override; + virtual OUString get_label() const override; + virtual void set_label_wrap(bool bWrap) override; + virtual void set_uri(const OUString& rUri) override; + virtual OUString get_uri() const override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/qt6/QtHyperlinkLabel.hxx b/vcl/inc/qt6/QtHyperlinkLabel.hxx new file mode 100644 index 000000000000..8afedee790d9 --- /dev/null +++ b/vcl/inc/qt6/QtHyperlinkLabel.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/QtHyperlinkLabel.hxx" + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/qt6/QtInstanceLinkButton.hxx b/vcl/inc/qt6/QtInstanceLinkButton.hxx new file mode 100644 index 000000000000..2f9204a48432 --- /dev/null +++ b/vcl/inc/qt6/QtInstanceLinkButton.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/QtInstanceLinkButton.hxx" + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/qt5/QtBuilder.cxx b/vcl/qt5/QtBuilder.cxx index 2bf4f12dc662..31e86f0b2543 100644 --- a/vcl/qt5/QtBuilder.cxx +++ b/vcl/qt5/QtBuilder.cxx @@ -9,6 +9,7 @@ #include <QtBuilder.hxx> +#include <QtInstanceLinkButton.hxx> #include <QtInstanceMessageDialog.hxx> #include <QtTools.hxx> @@ -193,6 +194,16 @@ QObject* QtBuilder::makeObject(QObject* pParent, std::u16string_view sName, cons extractMnemonicWidget(sID, rMap); pObject = new QLabel(pParentWidget); } + else if (sName == u"GtkLinkButton") + { + QtHyperlinkLabel* pLabel = new QtHyperlinkLabel(pParentWidget); + if (rMap.contains(u"label"_ustr)) + pLabel->setDisplayText(toQString(rMap[u"label"_ustr])); + if (rMap.contains(u"uri"_ustr)) + pLabel->setUri(toQString(rMap[u"label"_ustr])); + + pObject = pLabel; + } else if (sName == u"GtkRadioButton") { pObject = new QRadioButton(pParentWidget); diff --git a/vcl/qt5/QtHyperlinkLabel.cxx b/vcl/qt5/QtHyperlinkLabel.cxx new file mode 100644 index 000000000000..b887347826a7 --- /dev/null +++ b/vcl/qt5/QtHyperlinkLabel.cxx @@ -0,0 +1,34 @@ +/* -*- 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 <QtHyperlinkLabel.hxx> + +QtHyperlinkLabel::QtHyperlinkLabel(QWidget* pParent) + : QLabel(pParent) +{ +} + +void QtHyperlinkLabel::setDisplayText(const QString& rDisplayText) +{ + m_sDisplayText = rDisplayText; + update(); +}; + +void QtHyperlinkLabel::setUri(const QString& rUri) +{ + m_sUri = rUri; + update(); +}; + +void QtHyperlinkLabel::update() +{ + setText(QLatin1String("<a href=\"%1\">%2</a>").arg(m_sUri).arg(m_sDisplayText)); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/qt5/QtInstanceBuilder.cxx b/vcl/qt5/QtInstanceBuilder.cxx index 6001128760d6..7558bb63a508 100644 --- a/vcl/qt5/QtInstanceBuilder.cxx +++ b/vcl/qt5/QtInstanceBuilder.cxx @@ -18,6 +18,7 @@ #include <QtInstanceFrame.hxx> #include <QtInstanceImage.hxx> #include <QtInstanceLabel.hxx> +#include <QtInstanceLinkButton.hxx> #include <QtInstanceMessageDialog.hxx> #include <QtInstanceRadioButton.hxx> #include <QtInstanceTextView.hxx> @@ -151,10 +152,12 @@ std::unique_ptr<weld::MenuToggleButton> QtInstanceBuilder::weld_menu_toggle_butt return nullptr; } -std::unique_ptr<weld::LinkButton> QtInstanceBuilder::weld_link_button(const OUString&) +std::unique_ptr<weld::LinkButton> QtInstanceBuilder::weld_link_button(const OUString& rId) { - assert(false && "Not implemented yet"); - return nullptr; + QtHyperlinkLabel* pLabel = m_xBuilder->get<QtHyperlinkLabel>(rId); + std::unique_ptr<weld::LinkButton> xRet(pLabel ? std::make_unique<QtInstanceLinkButton>(pLabel) + : nullptr); + return xRet; } std::unique_ptr<weld::ToggleButton> QtInstanceBuilder::weld_toggle_button(const OUString&) diff --git a/vcl/qt5/QtInstanceLinkButton.cxx b/vcl/qt5/QtInstanceLinkButton.cxx new file mode 100644 index 000000000000..e814215ac591 --- /dev/null +++ b/vcl/qt5/QtInstanceLinkButton.cxx @@ -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/. + */ + +#include <QtInstanceLinkButton.hxx> + +#include <vcl/qt/QtUtils.hxx> + +QtInstanceLinkButton::QtInstanceLinkButton(QtHyperlinkLabel* pLabel) + : QtInstanceWidget(pLabel) + , m_pLabel(pLabel) +{ + assert(m_pLabel); +} + +void QtInstanceLinkButton::set_label(const OUString& rText) +{ + SolarMutexGuard g; + GetQtInstance().RunInMainThread([&] { m_pLabel->setDisplayText(toQString(rText)); }); +} + +OUString QtInstanceLinkButton::get_label() const +{ + SolarMutexGuard g; + OUString sLabel; + GetQtInstance().RunInMainThread([&] { sLabel = toOUString(m_pLabel->displayText()); }); + return sLabel; +} + +void QtInstanceLinkButton::set_label_wrap(bool) { assert(false && "Not implemented yet"); } + +void QtInstanceLinkButton::set_uri(const OUString& rUri) +{ + SolarMutexGuard g; + GetQtInstance().RunInMainThread([&] { m_pLabel->setUri(toQString(rUri)); }); +} + +OUString QtInstanceLinkButton::get_uri() const +{ + SolarMutexGuard g; + OUString sUri; + GetQtInstance().RunInMainThread([&] { sUri = toOUString(m_pLabel->uri()); }); + return sUri; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/qt6/QtHyperlinkLabel.cxx b/vcl/qt6/QtHyperlinkLabel.cxx new file mode 100644 index 000000000000..4b518036813b --- /dev/null +++ b/vcl/qt6/QtHyperlinkLabel.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/QtHyperlinkLabel.cxx" + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/qt6/QtInstanceLinkButton.cxx b/vcl/qt6/QtInstanceLinkButton.cxx new file mode 100644 index 000000000000..5cf866815511 --- /dev/null +++ b/vcl/qt6/QtInstanceLinkButton.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/QtInstanceLinkButton.cxx" + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */