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

List:       kde-devel
Subject:    Re: in-place-editing patch for konqueror bookmarks
From:       "Aaron J. Seigo" <aseigo () olympusproject ! org>
Date:       2002-12-29 0:02:10
[Download RAW message or body]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Saturday 28 December 2002 04:50, Aaron J. Seigo wrote:
> i'm using it in my task oriented menu thingy... i've merged it with
> KPopupMenu and produced a patch, which is attached... thoughts?

here's a thought: how about me actually attaching the patch. ;-)

note that i haven't actually tested this yet (still compiling stuff), but it 
is a straightforward porting from the rmbMenu subclass to KPopupMenu ... i 
will, of course, test thoroughly before committing it if that is the end 
result...

- -- 
Aaron J. Seigo
GPG Fingerprint: 8B8B 2209 0C6F 7C47 B1EA  EE75 D6B7 2EB1 A7F1 DB43

"Everything should be made as simple as possible, but not simpler"
    - Albert Einstein
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE+DjuD1rcusafx20MRAlkWAJ9FBHYc3JZoBTKaXNqtJ+CywrTdoACeLKfP
7yiiJ85Bv3GVoxTYWz2VIqo=
=DjTs
-----END PGP SIGNATURE-----

["kpopupmenu_with_rmb.diff" (text/x-diff)]

Index: kpopupmenu.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdeui/kpopupmenu.cpp,v
retrieving revision 1.22
diff -u -3 -d -p -r1.22 kpopupmenu.cpp
--- kpopupmenu.cpp	29 Sep 2002 23:59:07 -0000	1.22
+++ kpopupmenu.cpp	28 Dec 2002 23:56:56 -0000
@@ -16,6 +16,7 @@
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
 */
+#include <qcursor.h>
 #include <qpainter.h>
 #include <qdrawutil.h>
 #include <qtimer.h>
@@ -202,7 +203,14 @@ public:
         , shortcuts(false)
         , autoExec(false)
         , lastHitIndex(-1)
+        , m_ctxMenu(0)
+        , continueCtxMenuShow(true)
     {}
+
+    ~KPopupMenuPrivate ()
+    {
+        delete m_ctxMenu;
+    }
 
     QString m_lastTitle;
 
@@ -217,8 +225,17 @@ public:
     QString originalText;
     
     int lastHitIndex;
+
+    // support for RMB menus on menus
+    KPopupMenu* m_ctxMenu;
+    bool continueCtxMenuShow;
+    static int s_highlightedItem;
+    static KPopupMenu* s_contextedMenu;
 };
 
+int KPopupMenu::KPopupMenuPrivate::s_highlightedItem = -1;
+KPopupMenu* KPopupMenu::KPopupMenuPrivate::s_contextedMenu = 0;
+
 
 KPopupMenu::KPopupMenu(QWidget *parent, const char *name)
     : QPopupMenu(parent, name)
@@ -230,6 +247,12 @@ KPopupMenu::KPopupMenu(QWidget *parent, 
 
 KPopupMenu::~KPopupMenu()
 {
+    if (KPopupMenuPrivate::s_contextedMenu == this)
+    {
+        KPopupMenuPrivate::s_contextedMenu = 0;
+        KPopupMenuPrivate::s_highlightedItem = -1;
+    }
+
     delete d;
 }
 
@@ -509,6 +532,106 @@ void KPopupMenu::setKeyboardShortcutsExe
 }
 /**
  * End keyboard navigation.
+ */
+
+/**
+ * RMB menus on menus
+ */
+KPopupMenu* KPopupMenu::contextMenu()
+{
+    if (!d->m_ctxMenu)
+    {
+        d->m_ctxMenu = new KPopupMenu(this);
+        connect(d->m_ctxMenu, SIGNAL(aboutToHide()), this, SLOT(ctxMenuHiding()));
+    }
+
+    return d->m_ctxMenu;
+}
+
+void KPopupMenu::cancelContextMenuShow()
+{
+    d->continueCtxMenuShow = false;
+}
+
+int KPopupMenu::contextMenuFocusItem()
+{
+    return KPopupMenuPrivate::s_highlightedItem;
+}
+
+QPopupMenu* KPopupMenu::contextMenuFocus()
+{
+    return KPopupMenuPrivate::s_contextedMenu;
+}
+
+void KPopupMenu::itemHighlighted(int /* whichItem */)
+{
+    if (!d->m_ctxMenu ||  !d->m_ctxMenu->isVisible())
+    {
+        return;
+    }
+
+    d->m_ctxMenu->hide();
+    showCtxMenu(mapFromGlobal(QCursor::pos()));
+}
+
+void KPopupMenu::showCtxMenu(QPoint pos)
+{
+    KPopupMenuPrivate::s_highlightedItem = idAt(pos);
+
+    if (KPopupMenuPrivate::s_highlightedItem == -1)
+    {
+            KPopupMenuPrivate::s_contextedMenu = 0;
+            return;
+    }
+
+    emit aboutToShowContextMenu(this, KPopupMenuPrivate::s_highlightedItem, d->m_ctxMenu);
+
+    if (!d->continueCtxMenuShow)
+    {
+        d->continueCtxMenuShow = true;
+        return;
+    }
+
+    KPopupMenuPrivate::s_contextedMenu = this;
+    d->m_ctxMenu->popup(this->mapToGlobal(pos));
+    connect(this, SIGNAL(highlighted(int)), this, SLOT(itemHighlighted(int)));
+}
+
+void KPopupMenu::ctxMenuHiding()
+{
+    disconnect(this, SIGNAL(highlighted(int)), this, SLOT(itemHighlighted(int)));
+}
+
+bool KPopupMenu::eventFilter(QObject* obj, QEvent* event)
+{
+    if (d->m_ctxMenu && obj == this)
+    {
+        if (event->type() == QEvent::MouseButtonRelease)
+        {
+            if (d->m_ctxMenu->isVisible())
+            {
+                return true;
+            }
+        }
+        else if (event->type() ==  QEvent::ContextMenu)
+        {
+            showCtxMenu(mapFromGlobal(QCursor::pos()));
+            return true;
+        }
+    }
+
+    return QWidget::eventFilter(obj, event);
+}
+
+void KPopupMenu::hideEvent(QHideEvent*)
+{
+    if (d->m_ctxMenu)
+    {
+        d->m_ctxMenu->hide();
+    }
+}
+/**
+ * end of RMB menus on menus support
  */
 
 // Obsolete
Index: kpopupmenu.h
===================================================================
RCS file: /home/kde/kdelibs/kdeui/kpopupmenu.h,v
retrieving revision 1.18
diff -u -3 -d -p -r1.18 kpopupmenu.h
--- kpopupmenu.h	28 Sep 2002 15:16:22 -0000	1.18
+++ kpopupmenu.h	28 Dec 2002 23:56:56 -0000
@@ -188,10 +188,31 @@ public:
      * insertTitle and changeTitle instead.
      */
     void setTitle(const QString &title);
+
+    /**
+     * Returns the context menu associated with this menu, or 0 if none
+     */
+    KPopupMenu* contextMenu();
+
+    /**
+     * Hides the context menu if shown
+     */
+    void cancelContextMenuShow();
+
+    /**
+     * returns the item and the menu associated with the RMB on menu event
+     */
+    static int contextMenuFocusItem();
+    static QPopupMenu* contextMenuFocus();
+
+signals:
+    void aboutToShowContextMenu(KPopupMenu* menu, int menuItem, KPopupMenu* ctxMenu);
 
 protected:
     virtual void closeEvent(QCloseEvent *);
     virtual void keyPressEvent(QKeyEvent* e);
+    virtual bool eventFilter(QObject* obj, QEvent* event);
+    virtual void hideEvent(QHideEvent*);
 
     virtual void virtual_hook( int id, void* data );
 
@@ -200,6 +221,9 @@ protected slots:
     QString underlineText(const QString& text, uint length);
     /// @since 3.1 
     void resetKeyboardVars(bool noMatches = false);
+    void itemHighlighted(int whichItem);
+    void showCtxMenu(QPoint pos);
+    void ctxMenuHiding();
 
 private:
     class KPopupMenuPrivate;

>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<

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

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