vcl/CustomTarget_qt5_moc.mk | 1 + vcl/CustomTarget_qt6_moc.mk | 1 + vcl/inc/qt5/QtInstanceLinkButton.hxx | 9 ++++++++- vcl/qt5/QtHyperlinkLabel.cxx | 1 + vcl/qt5/QtInstanceLinkButton.cxx | 13 +++++++++++++ 5 files changed, 24 insertions(+), 1 deletion(-)
New commits: commit ec59d5aec570887758236d8955e620d7bbb34d33 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Fri Oct 25 23:36:49 2024 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Sat Oct 26 13:20:29 2024 +0200 tdf#130857 qt weld: Make link buttons focusable + handle activation Set the text interaction flags [1] for the QLabel used for hyperlinks so that the links can be highlighted and activated using mouse and keyboard. Connect to the QLabel::linkActivated signal that gets emitted when a link gets activated, and call signal_activate_link in response. If that returns false, open the URL using QDesktopServices::openUrl instead. Another way to only support opening the URL using QDesktopServices::openUrl automatically would be to set the `openExternalLinks` property [2], but IIUC, the custom activation handler should have priority. With this in place, when opening the "Help" -> "About LibreOfficeDev" dialog in a WIP branch adding "cui/ui/aboutdialog.ui" to the list of .ui files in QtInstanceBuilder::IsUIFileSupported, the tab order now includes the hyperlinks in the dialog, and pressing Enter while one is focused, or clicking on one of them opens them in the browser when using the qt6 VCL plugin. [1] https://doc.qt.io/qt-6/qlabel.html#textInteractionFlags-prop [2] https://doc.qt.io/qt-6/qlabel.html#openExternalLinks-prop Change-Id: I4e3cbca6d01a652a1038b9750ee9049e1c7491be Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175670 Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> Tested-by: Jenkins diff --git a/vcl/CustomTarget_qt5_moc.mk b/vcl/CustomTarget_qt5_moc.mk index eece23bda8bf..26533420c67f 100644 --- a/vcl/CustomTarget_qt5_moc.mk +++ b/vcl/CustomTarget_qt5_moc.mk @@ -17,6 +17,7 @@ $(call gb_CustomTarget_get_target,vcl/qt5) : \ $(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/QtInstanceLinkButton.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 0e05b21b4fb0..f31184182a82 100644 --- a/vcl/CustomTarget_qt6_moc.mk +++ b/vcl/CustomTarget_qt6_moc.mk @@ -17,6 +17,7 @@ $(call gb_CustomTarget_get_target,vcl/qt6) : \ $(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/QtInstanceLinkButton.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/QtInstanceLinkButton.hxx b/vcl/inc/qt5/QtInstanceLinkButton.hxx index d87ffde4c706..2484aec008cd 100644 --- a/vcl/inc/qt5/QtInstanceLinkButton.hxx +++ b/vcl/inc/qt5/QtInstanceLinkButton.hxx @@ -14,8 +14,12 @@ #include <QtWidgets/QLabel> -class QtInstanceLinkButton : public QtInstanceWidget, public virtual weld::LinkButton +class QtInstanceLinkButton : public QObject, + public QtInstanceWidget, + public virtual weld::LinkButton { + Q_OBJECT + QtHyperlinkLabel* m_pLabel; public: @@ -26,6 +30,9 @@ public: virtual void set_label_wrap(bool bWrap) override; virtual void set_uri(const OUString& rUri) override; virtual OUString get_uri() const override; + +private Q_SLOTS: + void linkActivated(const QString& rUrl); }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/qt5/QtHyperlinkLabel.cxx b/vcl/qt5/QtHyperlinkLabel.cxx index b887347826a7..91851c285ac1 100644 --- a/vcl/qt5/QtHyperlinkLabel.cxx +++ b/vcl/qt5/QtHyperlinkLabel.cxx @@ -12,6 +12,7 @@ QtHyperlinkLabel::QtHyperlinkLabel(QWidget* pParent) : QLabel(pParent) { + setTextInteractionFlags(Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard); } void QtHyperlinkLabel::setDisplayText(const QString& rDisplayText) diff --git a/vcl/qt5/QtInstanceLinkButton.cxx b/vcl/qt5/QtInstanceLinkButton.cxx index e814215ac591..c54b6d1801e5 100644 --- a/vcl/qt5/QtInstanceLinkButton.cxx +++ b/vcl/qt5/QtInstanceLinkButton.cxx @@ -8,14 +8,19 @@ */ #include <QtInstanceLinkButton.hxx> +#include <QtInstanceLinkButton.moc> #include <vcl/qt/QtUtils.hxx> +#include <QtGui/QDesktopServices> + QtInstanceLinkButton::QtInstanceLinkButton(QtHyperlinkLabel* pLabel) : QtInstanceWidget(pLabel) , m_pLabel(pLabel) { assert(m_pLabel); + + connect(m_pLabel, &QtHyperlinkLabel::linkActivated, this, &QtInstanceLinkButton::linkActivated); } void QtInstanceLinkButton::set_label(const OUString& rText) @@ -48,4 +53,12 @@ OUString QtInstanceLinkButton::get_uri() const return sUri; } +void QtInstanceLinkButton::linkActivated(const QString& rUrl) +{ + if (signal_activate_link()) + return; + + QDesktopServices::openUrl(rUrl); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */