summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Weghorn <m.weghorn@posteo.de>2025-01-27 21:46:17 +0100
committerMichael Weghorn <m.weghorn@posteo.de>2025-01-28 08:19:46 +0100
commit12c6bf058cf88b6d4cfe6e0aff09cf183ea9e033 (patch)
tree1e9dbd0d71efe414b65d5829a42aaf9839582ec9
parent3500c44bccafd442e50da604287342708506bb5c (diff)
tdf#130857 qt weld: Support MenuButton separators + respect pos
Implement QtInstanceMenuButton::insert_separator. Add a helper method QtInstanceMenuButton::insertAction that inserts the given action at the given position and use it from QtInstanceMenuButton::insert_item as well, which was so far only assigning the `nPos` local var, but not actually taking it into account to specify where to insert the new action. Use QWidget::insertAction [1] that allows to specify before which existing action the action should be inserted instead of always appending to the end. [1] https://doc.qt.io/qt-6/qwidget.html#insertAction Change-Id: I0acefb29f01b680b4efdf0ad6cea3bbf7f84c4b7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180807 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
-rw-r--r--vcl/inc/qt5/QtInstanceMenuButton.hxx3
-rw-r--r--vcl/qt5/QtInstanceMenuButton.cxx32
2 files changed, 28 insertions, 7 deletions
diff --git a/vcl/inc/qt5/QtInstanceMenuButton.hxx b/vcl/inc/qt5/QtInstanceMenuButton.hxx
index 84959df71852..52b8af9c1839 100644
--- a/vcl/inc/qt5/QtInstanceMenuButton.hxx
+++ b/vcl/inc/qt5/QtInstanceMenuButton.hxx
@@ -27,7 +27,7 @@ public:
const OUString* pIconName, VirtualDevice* pImageSurface,
TriState eCheckRadioFalse) override;
- virtual void insert_separator(int pos, const OUString& rId) override;
+ virtual void insert_separator(int nPos, const OUString& rId) override;
virtual void remove_item(const OUString& rId) override;
virtual void clear() override;
virtual void set_item_sensitive(const OUString& rIdent, bool bSensitive) override;
@@ -41,6 +41,7 @@ public:
private:
QMenu& getMenu() const;
QAction* getAction(const OUString& rIdent) const;
+ void insertAction(QAction* pAction, int nPos);
private Q_SLOTS:
void handleButtonClicked();
diff --git a/vcl/qt5/QtInstanceMenuButton.cxx b/vcl/qt5/QtInstanceMenuButton.cxx
index e68a7f656c90..617c02d3d980 100644
--- a/vcl/qt5/QtInstanceMenuButton.cxx
+++ b/vcl/qt5/QtInstanceMenuButton.cxx
@@ -40,22 +40,29 @@ void QtInstanceMenuButton::insert_item(int nPos, const OUString& rId, const OUSt
(void)eCheckRadioFalse;
GetQtInstance().RunInMainThread([&] {
- if (nPos == -1)
- nPos = getMenu().actions().count();
-
- QAction* pAction = getMenu().addAction(vclToQtStringWithAccelerator(rStr));
+ QAction* pAction = new QAction(vclToQtStringWithAccelerator(rStr), &getMenu());
pAction->setObjectName(toQString(rId));
if (pIconName)
pAction->setIcon(loadQPixmapIcon(*pIconName));
else if (pImageSurface)
pAction->setIcon(toQPixmap(*pImageSurface));
+
+ insertAction(pAction, nPos);
});
}
-void QtInstanceMenuButton::insert_separator(int, const OUString&)
+void QtInstanceMenuButton::insert_separator(int nPos, const OUString& rId)
{
- assert(false && "Not implemented yet");
+ SolarMutexGuard g;
+
+ GetQtInstance().RunInMainThread([&] {
+ QAction* pAction = new QAction(&getMenu());
+ pAction->setSeparator(true);
+ pAction->setObjectName(toQString(rId));
+
+ insertAction(pAction, nPos);
+ });
}
void QtInstanceMenuButton::remove_item(const OUString& rId)
@@ -153,6 +160,19 @@ QAction* QtInstanceMenuButton::getAction(const OUString& rIdent) const
return nullptr;
}
+void QtInstanceMenuButton::insertAction(QAction* pAction, int nPos)
+{
+ SolarMutexGuard g;
+
+ GetQtInstance().RunInMainThread([&] {
+ QAction* pNextAction = nullptr;
+ QList<QAction*> pActions = getMenu().actions();
+ if (nPos >= 0 && nPos < pActions.count())
+ pNextAction = pActions.at(nPos);
+ getMenu().insertAction(pNextAction, pAction);
+ });
+}
+
void QtInstanceMenuButton::handleButtonClicked()
{
if (m_pPopover)