[rkward/work/preview_with_menu] rkward/plugin: First attempt at bringing more functionality (menus) into the previews. Implementation is still a bit hacky.
Thomas Friedrichsmeier
thomas.friedrichsmeier at ruhr-uni-bochum.de
Mon Feb 1 20:32:31 UTC 2016
Git commit f70de7951fdc181f5bf875249b2e18b403756da9 by Thomas Friedrichsmeier.
Committed on 01/02/2016 at 20:31.
Pushed by tfry into branch 'work/preview_with_menu'.
First attempt at bringing more functionality (menus) into the previews. Implementation is still a bit hacky.
M +69 -1 rkward/plugin/rkpreviewbox.cpp
M +2 -0 rkward/plugin/rkstandardcomponentgui.cpp
http://commits.kde.org/rkward/f70de7951fdc181f5bf875249b2e18b403756da9
diff --git a/rkward/plugin/rkpreviewbox.cpp b/rkward/plugin/rkpreviewbox.cpp
index 2fad847..b178c34 100644
--- a/rkward/plugin/rkpreviewbox.cpp
+++ b/rkward/plugin/rkpreviewbox.cpp
@@ -35,6 +35,74 @@
#define DO_PREVIEW 102
+#include <kxmlguifactory.h>
+#include <QMenu>
+#include <QToolButton>
+#include <QEvent>
+#include <QMenuBar>
+#include <kxmlguiwindow.h>
+#include <ktoolbar.h>
+#include <kmenubar.h>
+#include <QPointer>
+
+class RKXMLGUIPreviewArea : public KXmlGuiWindow {
+public:
+ explicit RKXMLGUIPreviewArea (QWidget* parent) : KXmlGuiWindow (parent) {
+ RK_TRACE (PLUGIN);
+ menu_button = new QToolButton (this);
+ menu_button->setPopupMode (QToolButton::InstantPopup);
+ menu_button->setIcon (QIcon::fromTheme ("menu_new"));
+ menu_button->setObjectName ("menubutton");
+ menu_button->setMenu (menu = new QMenu ());
+ current = 0;
+ setWindowFlags (Qt::Widget);
+ setMenuBar (new QMenuBar (this));
+ setHelpMenuEnabled (false);
+ }
+ ~RKXMLGUIPreviewArea () {
+ RK_TRACE (PLUGIN);
+
+ if (current) {
+ removeChildClient (current);
+ current->setFactory (0);
+ }
+ }
+protected:
+ /** build / destroy menu, when child is added removed. Note that we are in the fortunate situation that RKMDIWindow-children only ever get to the
+ * preview area via reparenting, i.e. contrary to usual QEvent::ChildAdded semnatics, they are always fully constructed, when added. */
+ void childEvent (QChildEvent *event) { // KF5 TODO: override keyword
+ RK_TRACE (PLUGIN);
+
+ if (event->type () == QEvent::ChildAdded) {
+ RKMDIWindow *child = qobject_cast<RKMDIWindow*> (event->child ());
+ if (child) {
+ if (current) {
+ removeChildClient (current);
+ factory ()->removeClient (current); // _always_ remove before adding, or the previous child will be leaked in the factory
+ }
+ current = child->getPart ();
+ insertChildClient (current);
+ setCentralWidget (child);
+ createGUI ("rkdummypart.rc");
+ menuBar ()->hide ();
+ QList<KToolBar*> tbars = toolBars ();
+ for (int i = 0; i < tbars.size (); ++i) tbars[i]->hide ();
+ menu->clear ();
+ QList<QAction*> entries = menuBar ()->actions ();
+ for (int i = 0; i < entries.size (); ++i) {
+ menu->addAction (entries[i]);
+ }
+ }
+ }
+ QObject::childEvent (event);
+ }
+private:
+ QToolButton *menu_button;
+ QMenu *menu;
+ QPointer<KParts::Part> current;
+};
+
+
RKPreviewBox::RKPreviewBox (const QDomElement &element, RKComponent *parent_component, QWidget *parent_widget) : RKComponent (parent_component, parent_widget) {
RK_TRACE (PLUGIN);
@@ -77,7 +145,7 @@ RKPreviewBox::RKPreviewBox (const QDomElement &element, RKComponent *parent_comp
if (placement == DockedPreview) {
RKStandardComponent *uicomp = topmostStandardComponent ();
if (uicomp) {
- QWidget *container = new KVBox ();
+ QWidget *container = new RKXMLGUIPreviewArea (0);
RKWorkplace::mainWorkplace ()->registerNamedWindow (idprop, this, container);
uicomp->addDockedPreview (container, state, toggle_preview_box->text ());
diff --git a/rkward/plugin/rkstandardcomponentgui.cpp b/rkward/plugin/rkstandardcomponentgui.cpp
index 4bb328b..a9c05bd 100644
--- a/rkward/plugin/rkstandardcomponentgui.cpp
+++ b/rkward/plugin/rkstandardcomponentgui.cpp
@@ -188,6 +188,8 @@ void RKStandardComponentGUI::finalize () {
tb->setIcon (RKStandardIcons::getIcon (RKStandardIcons::ActionDelete));
tb->setProperty ("preview_area", QVariant::fromValue (dummy));
connect (tb, SIGNAL (clicked()), this, SLOT (previewCloseButtonClicked()));
+ QWidget *button = previews[i].area->findChild<QWidget *> ("menubutton");
+ if (button) hl->addWidget (button);
hl->addStretch ();
hl->addWidget (lab);
hl->addWidget (tb);
More information about the rkward-tracker
mailing list