summaryrefslogtreecommitdiff
path: root/vcl/qt5/QtInstanceMenuButton.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'vcl/qt5/QtInstanceMenuButton.cxx')
-rw-r--r--vcl/qt5/QtInstanceMenuButton.cxx58
1 files changed, 46 insertions, 12 deletions
diff --git a/vcl/qt5/QtInstanceMenuButton.cxx b/vcl/qt5/QtInstanceMenuButton.cxx
index f6432abdc77d..6bbcd9cdcc9b 100644
--- a/vcl/qt5/QtInstanceMenuButton.cxx
+++ b/vcl/qt5/QtInstanceMenuButton.cxx
@@ -19,13 +19,15 @@
QtInstanceMenuButton::QtInstanceMenuButton(QToolButton* pButton)
: QtInstanceToggleButton(pButton)
, m_pToolButton(pButton)
+ , m_pPopover(nullptr)
{
assert(m_pToolButton);
- m_pToolButton->setPopupMode(QToolButton::InstantPopup);
- assert(m_pToolButton->menu());
- connect(m_pToolButton->menu(), &QMenu::triggered, this,
- &QtInstanceMenuButton::handleMenuItemTriggered);
+ if (m_pToolButton->menu())
+ connect(m_pToolButton->menu(), &QMenu::triggered, this,
+ &QtInstanceMenuButton::handleMenuItemTriggered);
+
+ connect(m_pToolButton, &QToolButton::clicked, this, &QtInstanceMenuButton::handleButtonClicked);
}
void QtInstanceMenuButton::insert_item(int nPos, const OUString& rId, const OUString& rStr,
@@ -38,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)
@@ -126,7 +135,11 @@ void QtInstanceMenuButton::set_item_visible(const OUString& rIdent, bool bVisibl
});
}
-void QtInstanceMenuButton::set_popover(weld::Widget*) { assert(false && "Not implemented yet"); }
+void QtInstanceMenuButton::set_popover(weld::Widget* pPopover)
+{
+ QtInstanceWidget* pPopoverWidget = dynamic_cast<QtInstanceWidget*>(pPopover);
+ m_pPopover = pPopoverWidget ? pPopoverWidget->getQWidget() : nullptr;
+}
QMenu& QtInstanceMenuButton::getMenu() const
{
@@ -137,7 +150,7 @@ QMenu& QtInstanceMenuButton::getMenu() const
QAction* QtInstanceMenuButton::getAction(const OUString& rIdent) const
{
- QList<QAction*> aActions = getMenu().actions();
+ const QList<QAction*> aActions = getMenu().actions();
for (QAction* pAction : aActions)
{
if (pAction && pAction->objectName() == toQString(rIdent))
@@ -147,6 +160,27 @@ 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)
+ m_pPopover->show();
+ else
+ m_pToolButton->showMenu();
+}
+
void QtInstanceMenuButton::handleMenuItemTriggered(QAction* pAction)
{
SolarMutexGuard g;