summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorsten Behrens <Thorsten.Behrens@CIB.de>2018-09-05 01:37:28 +0200
committerThorsten Behrens <Thorsten.Behrens@CIB.de>2018-09-05 08:08:37 +0200
commit6f3fcf10630a161dd10e80ad47b8ba90398bafaf (patch)
treefe2c88dbc44dde6f24d3a2d8564094b61f5a174b
parent1ddbf5c37a472c72b3b2be23381e18a9f1ad5823 (diff)
kde5: make disabled and hidden menu items work
Change-Id: I145a496bbc5b375bc309815b18f2c31fa4d50d6c Reviewed-on: https://gerrit.libreoffice.org/60012 Tested-by: Jenkins Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
-rw-r--r--vcl/inc/qt5/Qt5Menu.hxx6
-rw-r--r--vcl/qt5/Qt5Menu.cxx77
2 files changed, 72 insertions, 11 deletions
diff --git a/vcl/inc/qt5/Qt5Menu.hxx b/vcl/inc/qt5/Qt5Menu.hxx
index 412a9d9798f0..bbd18709ce51 100644
--- a/vcl/inc/qt5/Qt5Menu.hxx
+++ b/vcl/inc/qt5/Qt5Menu.hxx
@@ -68,11 +68,13 @@ class Qt5MenuItem : public SalMenuItem
public:
Qt5MenuItem(const SalItemParams*);
+ Qt5Menu* mpParentMenu; // The menu into which this menu item is inserted
+ Qt5Menu* mpSubMenu; // Submenu of this item (if defined)
+ QAction* mpAction; // action corresponding to this item
sal_uInt16 mnId; // Item ID
MenuItemType mnType; // Item type
bool mbVisible; // Item visibility.
- Qt5Menu* mpParentMenu; // The menu into which this menu item is inserted
- Qt5Menu* mpSubMenu; // Submenu of this item (if defined)
+ bool mbEnabled; // Item active.
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qt5/Qt5Menu.cxx b/vcl/qt5/Qt5Menu.cxx
index 7e7b5a5195a9..c7abd17c30d2 100644
--- a/vcl/qt5/Qt5Menu.cxx
+++ b/vcl/qt5/Qt5Menu.cxx
@@ -9,6 +9,7 @@
#include <Qt5Frame.hxx>
#include <Qt5MainWindow.hxx>
+#include <Qt5Bitmap.hxx>
#include <Qt5Menu.hxx>
#include <Qt5Menu.moc>
@@ -114,6 +115,7 @@ void Qt5Menu::DoFullMenuUpdate(Menu* pMenuBar, QMenu* pParentMenu)
{
// leaf menu
QAction* pAction = pQMenu->addAction(toQString(aText));
+ pSalMenuItem->mpAction = pAction;
pAction->setShortcut(toQString(nAccelKey.GetName(GetFrame()->GetWindow())));
if (itemBits & MenuItemBits::CHECKABLE)
@@ -132,6 +134,9 @@ void Qt5Menu::DoFullMenuUpdate(Menu* pMenuBar, QMenu* pParentMenu)
pQAG->addAction(pAction);
}
+ pAction->setEnabled(pSalMenuItem->mbEnabled);
+ pAction->setVisible(pSalMenuItem->mbVisible);
+
connect(pAction, &QAction::triggered, this,
[this, pSalMenuItem] { DispatchCommand(pSalMenuItem); });
}
@@ -147,17 +152,68 @@ void Qt5Menu::DoFullMenuUpdate(Menu* pMenuBar, QMenu* pParentMenu)
}
}
-void Qt5Menu::ShowItem(unsigned, bool) {}
+void Qt5Menu::ShowItem(unsigned nPos, bool bShow)
+{
+ if (nPos < maItems.size())
+ {
+ Qt5MenuItem* pSalMenuItem = GetItemAtPos(nPos);
+ if (pSalMenuItem->mpAction)
+ pSalMenuItem->mpAction->setVisible(bShow);
+ pSalMenuItem->mbVisible = bShow;
+ }
+}
+
+void Qt5Menu::CheckItem(unsigned nPos, bool bChecked)
+{
+ if (nPos < maItems.size())
+ {
+ Qt5MenuItem* pSalMenuItem = GetItemAtPos(nPos);
+ if (pSalMenuItem->mpAction)
+ pSalMenuItem->mpAction->setChecked(bChecked);
+ }
+}
+
+void Qt5Menu::EnableItem(unsigned nPos, bool bEnable)
+{
+ if (nPos < maItems.size())
+ {
+ Qt5MenuItem* pSalMenuItem = GetItemAtPos(nPos);
+ if (pSalMenuItem->mpAction)
+ pSalMenuItem->mpAction->setEnabled(bEnable);
+ pSalMenuItem->mbEnabled = bEnable;
+ }
+}
-void Qt5Menu::CheckItem(unsigned, bool) {}
+void Qt5Menu::SetItemText(unsigned, SalMenuItem* pItem, const rtl::OUString& rText)
+{
+ Qt5MenuItem* pSalMenuItem = static_cast<Qt5MenuItem*>(pItem);
+ if (pSalMenuItem->mpAction)
+ pSalMenuItem->mpAction->setText(toQString(rText));
+}
-void Qt5Menu::EnableItem(unsigned, bool) {}
+void Qt5Menu::SetItemImage(unsigned, SalMenuItem* pItem, const Image& rImage)
+{
+ BitmapEx aBmpEx(rImage.GetBitmapEx());
+ Bitmap aBmp(aBmpEx.GetBitmap());
-void Qt5Menu::SetItemText(unsigned, SalMenuItem*, const rtl::OUString&) {}
+ if (!aBmp || !aBmp.ImplGetSalBitmap())
+ return;
-void Qt5Menu::SetItemImage(unsigned, SalMenuItem*, const Image&) {}
+ // simple case, no transparency
+ Qt5MenuItem* pSalMenuItem = static_cast<Qt5MenuItem*>(pItem);
+ if (pSalMenuItem->mpAction)
+ pSalMenuItem->mpAction->setIcon(QPixmap::fromImage(
+ *static_cast<Qt5Bitmap*>(aBmp.ImplGetSalBitmap().get())->GetQImage()));
+}
-void Qt5Menu::SetAccelerator(unsigned, SalMenuItem*, const vcl::KeyCode&, const OUString&) {}
+void Qt5Menu::SetAccelerator(unsigned, SalMenuItem* pItem, const vcl::KeyCode&,
+ const OUString& rText)
+{
+ Qt5MenuItem* pSalMenuItem = static_cast<Qt5MenuItem*>(pItem);
+ if (pSalMenuItem->mpAction)
+ pSalMenuItem->mpAction->setShortcut(
+ QKeySequence(toQString(rText), QKeySequence::PortableText));
+}
void Qt5Menu::GetSystemMenuData(SystemMenuData*) {}
@@ -192,10 +248,13 @@ void Qt5Menu::DispatchCommand(Qt5MenuItem* pQItem)
void Qt5Menu::NativeItemText(OUString& rItemText) { rItemText = rItemText.replace('~', '&'); }
Qt5MenuItem::Qt5MenuItem(const SalItemParams* pItemData)
- : mnId(pItemData->nId)
- , mnType(pItemData->eType)
- , mpParentMenu(nullptr)
+ : mpParentMenu(nullptr)
, mpSubMenu(nullptr)
+ , mpAction(nullptr)
+ , mnId(pItemData->nId)
+ , mnType(pItemData->eType)
+ , mbVisible(true)
+ , mbEnabled(true)
{
}