[rkward/work/preview_with_menu] rkward/plugin: Flatten menu in preview

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Tue Feb 2 08:06:47 UTC 2016


Git commit 7e96badca73fa6389201ca95f09ec704eb47c399 by Thomas Friedrichsmeier.
Committed on 02/02/2016 at 08:06.
Pushed by tfry into branch 'work/preview_with_menu'.

Flatten menu in preview

M  +15   -1    rkward/plugin/rkpreviewbox.cpp

http://commits.kde.org/rkward/7e96badca73fa6389201ca95f09ec704eb47c399

diff --git a/rkward/plugin/rkpreviewbox.cpp b/rkward/plugin/rkpreviewbox.cpp
index b178c34..78ec888 100644
--- a/rkward/plugin/rkpreviewbox.cpp
+++ b/rkward/plugin/rkpreviewbox.cpp
@@ -44,6 +44,7 @@
 #include <ktoolbar.h>
 #include <kmenubar.h>
 #include <QPointer>
+#include <QWidgetAction>
 
 class RKXMLGUIPreviewArea : public KXmlGuiWindow {
 public:
@@ -90,7 +91,20 @@ protected:
 				menu->clear ();
 				QList<QAction*> entries = menuBar ()->actions ();
 				for (int i = 0; i < entries.size (); ++i) {
-					menu->addAction (entries[i]);
+					QMenu *smenu = entries[i]->menu ();
+					if (!smenu) continue;
+					QList<QAction*> subentries = smenu->actions ();
+					if (subentries.isEmpty ()) continue;
+
+					QWidgetAction *act = new QWidgetAction (this);
+					QLabel *lab = new QLabel ("<b>" + entries[i]->text ().replace ('&', "") + "</b>");
+					lab->setAlignment (Qt::AlignCenter);
+					act->setDefaultWidget (lab);
+					menu->addAction (act);
+
+					for (int j = 0; j < subentries.size (); ++j) {
+						menu->addAction (subentries[j]);
+					}
 				}
 			}
 		}



More information about the rkward-tracker mailing list