[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdebase/workspace/plasma/applets/kickoff
From:       Christian Loose <christian.loose () hamburg ! de>
Date:       2009-03-21 22:34:49
Message-ID: 1237674889.038634.26480.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 942528 by cloose:

Add context menu to the classic style kickoff menu (simplelauncher)

BUG: 158302
REVIEWED: http://reviewboard.kde.org/r/377/



 M  +5 -1      CMakeLists.txt  
 M  +24 -1     simpleapplet/simpleapplet.cpp  
 M  +5 -0      simpleapplet/simpleapplet.h  
 M  +15 -7     ui/contextmenufactory.cpp  
 M  +3 -1      ui/contextmenufactory.h  
 M  +2 -1      ui/launcher.cpp  


--- trunk/KDE/kdebase/workspace/plasma/applets/kickoff/CMakeLists.txt #942527:942528
@@ -71,7 +71,11 @@
 #######################################################################################
  # Kickoff Simple KMenu Plasma Applet
 
-set(SimpleApplet_SRCS simpleapplet/menuview.cpp simpleapplet/simpleapplet.cpp)
+set(SimpleApplet_SRCS
+    ui/contextmenufactory.cpp
+    simpleapplet/menuview.cpp
+    simpleapplet/simpleapplet.cpp
+)
 kde4_add_plugin(plasma_applet_simplelauncher ${SimpleApplet_SRCS})
 target_link_libraries(plasma_applet_simplelauncher ${KDE4_KUTILS_LIBS} \
${KDE4_PLASMA_LIBS} solidcontrol ${Kickoff_LIBS} kickoff)  install(TARGETS \
                plasma_applet_simplelauncher DESTINATION ${PLUGIN_INSTALL_DIR})
--- trunk/KDE/kdebase/workspace/plasma/applets/kickoff/simpleapplet/simpleapplet.cpp \
#942527:942528 @@ -67,7 +67,10 @@
 #include "core/recentapplications.h"
 #include "core/leavemodel.h"
 #include "core/urlitemlauncher.h"
+#include "ui/contextmenufactory.h"
 
+Q_DECLARE_METATYPE(QPersistentModelIndex)
+
 /// @internal KBookmarkOwner specialization
 class BookmarkOwner : public KBookmarkOwner
 {
@@ -109,13 +112,14 @@
 
     QList<QAction*> actions;
     QAction* switcher;
+    Kickoff::ContextMenuFactory *contextMenuFactory;
 
     explicit Private(MenuLauncherApplet *q)
             : q(q),
             menuview(0), icon(0), launcher(0),
             bookmarkcollection(0), bookmarkowner(0), bookmarkmenu(0),
             view(0), iconButton(0), formatComboBox(0),
-            switcher(0) {}
+            switcher(0), contextMenuFactory(0) {}
     ~Private() {
         delete bookmarkmenu;
         delete bookmarkowner;
@@ -263,6 +267,9 @@
     layout->setContentsMargins(0, 0, 0, 0);
     layout->setSpacing(0);
     layout->addItem(d->icon);
+
+    d->contextMenuFactory = new Kickoff::ContextMenuFactory(this);
+    d->contextMenuFactory->setApplet(this);
 }
 
 MenuLauncherApplet::~MenuLauncherApplet()
@@ -344,6 +351,19 @@
     KProcess::execute("kmenuedit");
 }
 
+void MenuLauncherApplet::customContextMenuRequested(const QPoint& pos)
+{
+    if (!d->menuview) {
+        return;
+    }
+
+    QAction* menuAction = d->menuview->actionAt(pos);
+    if (menuAction) {
+        const QPersistentModelIndex index = \
menuAction->data().value<QPersistentModelIndex>(); +        \
d->contextMenuFactory->showContextMenu(0, index, pos); +    }
+}
+
 void MenuLauncherApplet::createConfigurationInterface(KConfigDialog *parent)
 {
     QWidget *viewpage = new QWidget(parent);
@@ -485,8 +505,11 @@
         d->menuview = new Kickoff::MenuView();
         d->menuview->setAttribute(Qt::WA_DeleteOnClose);
         d->menuview->setFormatType( (Kickoff::MenuView::FormatType) d->formattype );
+        d->menuview->setContextMenuPolicy(Qt::CustomContextMenu);
         connect(d->menuview, SIGNAL(triggered(QAction*)), this, \
                SLOT(actionTriggered(QAction*)));
         connect(d->menuview, SIGNAL(aboutToHide()), d->icon, SLOT(setUnpressed()));
+        connect(d->menuview, SIGNAL(customContextMenuRequested(const QPoint&)),
+                this, SLOT(customContextMenuRequested(const QPoint&)));
         //connect(d->menuview, SIGNAL(afterBeingHidden()), d->menuview, \
SLOT(deleteLater()));  
         //Kickoff::MenuView::ModelOptions options = d->viewtypes.count() < 2 ? \
                Kickoff::MenuView::MergeFirstLevel : Kickoff::MenuView::None;
--- trunk/KDE/kdebase/workspace/plasma/applets/kickoff/simpleapplet/simpleapplet.h \
#942527:942528 @@ -115,6 +115,11 @@
      */
     void startMenuEditor();
 
+    /**
+     * Show a custom context menu for the selected action.
+     */
+    void customContextMenuRequested(const QPoint& pos);
+
 protected:
     /**
      * Create a configuration dialog.
--- trunk/KDE/kdebase/workspace/plasma/applets/kickoff/ui/contextmenufactory.cpp \
#942527:942528 @@ -47,6 +47,8 @@
 #include "core/favoritesmodel.h"
 #include "core/models.h"
 
+Q_DECLARE_METATYPE(QPersistentModelIndex)
+
 using namespace Kickoff;
 
 class ContextMenuFactory::Private
@@ -101,11 +103,15 @@
     delete d;
 }
 
-void ContextMenuFactory::showContextMenu(QAbstractItemView *view, const QPoint &pos)
+void ContextMenuFactory::showContextMenu(QAbstractItemView *view,
+                                         const QPersistentModelIndex& index, const \
QPoint& pos)  {
-    Q_ASSERT(view);
+    Q_UNUSED(pos);
 
-    const QModelIndex index = view->indexAt(pos);
+    if (!index.isValid()) {
+        return;
+    }
+
     const QString url = index.data(UrlRole).value<QString>();
 
     if (url.isEmpty()) {
@@ -129,7 +135,6 @@
         actions << favoriteAction;
     }
 
-
     // add to desktop
     QAction *addToDesktopAction = new QAction(this);
 
@@ -192,9 +197,11 @@
 
     // add view specific actions
     QAction *viewSeparator = new QAction(this);
-    viewSeparator->setSeparator(true);
-    actions << viewSeparator;
-    actions << viewActions(view);
+    if (view) {
+        viewSeparator->setSeparator(true);
+        actions << viewSeparator;
+        actions << viewActions(view);
+    }
 
     // display menu
     KMenu menu;
@@ -254,6 +261,7 @@
     delete viewSeparator;
     delete ejectAction;
 }
+
 void ContextMenuFactory::setViewActions(QAbstractItemView *view, const \
QList<QAction*>& actions)  {
     if (actions.isEmpty()) {
--- trunk/KDE/kdebase/workspace/plasma/applets/kickoff/ui/contextmenufactory.h \
#942527:942528 @@ -21,6 +21,7 @@
 
 // Qt
 #include <QAction>
+#include <QPersistentModelIndex>
 
 // Plasma
 #include <Plasma/Applet>
@@ -44,7 +45,8 @@
     void setApplet(Plasma::Applet *applet);
 
 public Q_SLOTS:
-    void showContextMenu(QAbstractItemView *view, const QPoint& pos);
+    void showContextMenu(QAbstractItemView *view,
+                         const QPersistentModelIndex& index, const QPoint& pos);
 
 private:
     class Private;
--- trunk/KDE/kdebase/workspace/plasma/applets/kickoff/ui/launcher.cpp #942527:942528
@@ -721,7 +721,8 @@
 {
     QAbstractItemView *view = qobject_cast<QAbstractItemView*>(sender());
     if (view) {
-        d->contextMenuFactory->showContextMenu(view, pos);
+        const QModelIndex index = view->indexAt(pos);
+        d->contextMenuFactory->showContextMenu(view, index, pos);
     }
 }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic