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

List:       kde-usability
Subject:    Re: kmenu concept
From:       Eric Ellsworth <whalesuit () softhome ! net>
Date:       2002-06-07 2:06:18
[Download RAW message or body]

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



On Thursday 06 June 2002 6:00 pm, Aaron J. Seigo wrote:
> hi all...
>
> here is something i was playing w/this afternoon ... build "instructoins"
> are at the bottom of the file...

Oooh, I like...., I like....

> note the RMB menus on the Internet sub menu ... the items don't do anything
> yet, but the RMB menus are there =)

The RMB's are excellent - I like how they show the title of the menu you're 
working on.  I still like the idea of having a menu item (not just RMB) for 
changing programs, because as many have pointed out, new users just won't see 
that RMB.

I've made a few modifications to pass on - mostly just filled out some menus.  
I thought we could evaluate just putting documents on the Recent Items menu - 
this is more "document-centric" for what that's worth (Cdn$.00001 :)  ).  I 
also notice when I tried to fill out the Music and Movies - Multimedia seems 
like a vague term to me that there's lots of disparate actions here:
Play MP3s
Play movies
Download music
Rip CDs
Burn CDs
Edit Music
Edit Movies
Play RealMedia
Play Ogg

Seeing as we're not likely to get all those applications to be condensed any 
time soon, perhaps we better think about a slightly modified way of 
addressing this menu....

> this is very preliminary and by no means complete, but i thought i'd toss
> some code out there for discussion...
Excellent way to get the party started.  Great work!

Cheers,

Eric
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE9ABUaPdSoslpx+lkRAmi1AJ9pV7/pkSyK7YHYGoWyadY4kJmzbgCdFmYZ
9iSQcQtI/kbLubtpk9SOnok=
=tSF+
-----END PGP SIGNATURE-----

["kmenu_playing.cc" (text/x-c++src)]

#include <qcursor.h>
#include <kaboutdata.h>
#include <kpopupmenu.h>
#include <kcmdlineargs.h>
#include <kmainwindow.h>
#include <kmenubar.h>
#include <qmenubar.h>
#include <kapplication.h>
#include <kstdaction.h>
#include <iostream>

class rmbPopup : public KPopupMenu
{
    Q_OBJECT

    public:
        rmbPopup(QWidget* parent = 0, const char* name = 0)
            : KPopupMenu(parent, name),
              m_ctxMenu(0),
              continueCtxMenuShow(true)
        {
            installEventFilter(this);
        }

        ~rmbPopup() 
        {
            delete m_ctxMenu;

            if (s_contextedMenu == this)
            {
                s_contextedMenu = 0;
                s_highlightedItem = -1;
            }
        }

        KPopupMenu* contextMenu()
        {
            if (!m_ctxMenu)
            {
                m_ctxMenu = new KPopupMenu(this);
                connect(m_ctxMenu, SIGNAL(aboutToHide()), this, \
SLOT(ctxMenuHiding()));  }

            return m_ctxMenu;
        }

        void cancelContextMenuShow()
        {
            continueCtxMenuShow = false;
        }

        static int contextMenuFocusItem()
        {
            return s_highlightedItem;
        }

        static QPopupMenu* contextMenuFocus()
        {
            return s_contextedMenu;
        }

    signals:
        void aboutToShowContextMenu(rmbPopup* menu, int menuItem, \
KPopupMenu* ctxMenu);

    protected slots:
        void itemHighlighted(int whichItem)
        {
            if (!m_ctxMenu ||  !m_ctxMenu->isVisible())
            {
                return;
            }

            m_ctxMenu->hide();
            showCtxMenu(mapFromGlobal(QCursor::pos()));
        }

        void showCtxMenu(QPoint pos)
        {
            s_highlightedItem = idAt(pos);

            if (s_highlightedItem == -1)
            {
                    s_contextedMenu = 0;
                    return;
            }

            emit aboutToShowContextMenu(this, s_highlightedItem, \
m_ctxMenu);

            if (!continueCtxMenuShow)
            {
                continueCtxMenuShow = true;
                return;
            }

            s_contextedMenu = this;
            m_ctxMenu->popup(this->mapToGlobal(pos));
            connect(this, SIGNAL(highlighted(int)), this, \
SLOT(itemHighlighted(int)));  }

        void ctxMenuHiding()
        {
            disconnect(this, SIGNAL(highlighted(int)), this, \
SLOT(itemHighlighted(int)));  }

    protected:
        bool eventFilter(QObject* obj, QEvent* event)
        {
            if (m_ctxMenu && obj == this)
            {
                if (event->type() == QEvent::MouseButtonRelease)
                {
                    if (m_ctxMenu->isVisible())
                    {
                        return true;
                    }
                }
                else if (event->type() ==  QEvent::ContextMenu )
                {
                    showCtxMenu(mapFromGlobal(QCursor::pos()));
                    return true;
                }
            }

            return QWidget::eventFilter(obj, event);
        }

        void hideEvent(QHideEvent*)
        {
            if (m_ctxMenu)
            {
                m_ctxMenu->hide();
            }
        }

    private:
        KPopupMenu* m_ctxMenu;
        bool continueCtxMenuShow;
        static int s_highlightedItem;
        static KPopupMenu* s_contextedMenu;
};

int rmbPopup::s_highlightedItem = -1;
KPopupMenu* rmbPopup::s_contextedMenu = 0;

class ctxMenuDriver : public QObject
{
    Q_OBJECT

    public:
        ctxMenuDriver()
        {
        }

        ~ctxMenuDriver()
        {
        }

    public slots:
        void contextualize(rmbPopup* menu, int menuItem, KPopupMenu* \
ctxMenu)  {
            QString shortcutText("Create a button on the panel for this \
item");  QString editText("Edit this item");
            QString deleteText("Delete this item");
            QString insertText("Insert a new item");
            
            ctxMenu->clear();
            ctxMenu->insertTitle(QString(menu->name()).append(": " + \
menu->text(menuItem)));  ctxMenu->insertItem(shortcutText);
            ctxMenu->insertItem(editText);
            ctxMenu->insertItem(deleteText);
            ctxMenu->insertItem(insertText);
        }

        void killItem()
        {
            rmbPopup::contextMenuFocus()->removeItem(rmbPopup::contextMenuFocusItem());
  }
};

#include "kmenu_playing.moc.cc"
#include <iostream>
int main(int argc, char* argv[])
{
    KAboutData about("menuExtTest", "menuExtTest", "0.1", "Testing \
KPopupMenu Extensions");  KCmdLineArgs::init(argc, argv, &about);
    KApplication foo;
    KMainWindow* testWindow = new KMainWindow(0);
    foo.setMainWidget(testWindow);
    ctxMenuDriver* driver = new ctxMenuDriver();
    
    rmbPopup* kMenu = new rmbPopup(testWindow, "File Menu");
    kMenu->setKeyboardShortcutsEnabled(true);
    kMenu->insertTitle("Recent Documents");
    rmbPopup* recentApps = new rmbPopup(testWindow, "recentApps");
    rmbPopup* recentDocs = new rmbPopup(testWindow, "recentDocs");
    /*    kMenu->insertItem("Applications", recentApps); */
    kMenu->insertItem("kmenu_playing.cc");
    kMenu->insertTitle("Activities");
    
    rmbPopup* apps = new rmbPopup(testWindow, "Internet");
    apps->insertItem("Web Browser (Konqueror)");
    apps->insertItem("Email (Kmail)");
    apps->insertItem("Instant Messenger (Kopete)");
    apps->insertItem("VNC (Keystone)");
    apps->insertItem("FTP (KBear)");
    apps->insertItem("   -- Change programs --");

    KPopupMenu* rmbMenu = apps->contextMenu();
    rmbMenu->insertTitle("Internet Menu Editor");
    rmbMenu->insertItem("Create shortcut on panel");
    rmbMenu->insertItem("Edit item");
    kMenu->insertItem("Internet", apps);
    QObject::connect(apps, SIGNAL(aboutToShowContextMenu(rmbPopup*, int, \
                KPopupMenu*)),
                     driver, SLOT(contextualize(rmbPopup*, int, \
KPopupMenu*)));  
    apps = new rmbPopup(testWindow, "Office Work");
    apps->insertItem("Word Processing (OpenOffice.org)");
    apps->insertItem("Spreadsheet (Gnumeric)");
    apps->insertItem("Presentations (KPresenter)");
    apps->insertItem("Drawing (The GIMP)");
    apps->insertItem("   -- Change programs --");
    rmbMenu = apps->contextMenu();
    rmbMenu->insertTitle("Office Work Menu Editor");
    rmbMenu->insertItem("Create shortcut on panel");
    rmbMenu->insertItem("Edit item");
    kMenu->insertItem("Office Work", apps);
    
    apps = new rmbPopup(testWindow, "Multimedia");
    rmbMenu = apps->contextMenu();
    rmbMenu->insertTitle("Multimedia Menu Editor");
    rmbMenu->insertItem("Create shortcut on panel");
    rmbMenu->insertItem("Edit item");
    kMenu->insertItem("Music, Movies and More", apps);
    apps->insertItem("Play music (XMMS)");
    apps->insertItem("Watch movies (aKtion)");
    apps->insertItem("Download Music (KNapster)");
    apps->insertItem("Record CD onto my computer");
    apps->insertItem("   -- Change Programs --");

    apps = new rmbPopup(testWindow, "More Applications");
    kMenu->insertItem("More Applications", apps);
     
    kMenu->insertTitle("Special Menus");
    rmbPopup* specialMenu = new rmbPopup(testWindow, "KPrint");
    kMenu->insertItem("Printing", specialMenu);

    kMenu->insertTitle("Destinations");
    kMenu->insertItem("Help");
    kMenu->insertItem("Control Center");
    kMenu->insertItem("Find Files");
    kMenu->insertItem("Home (Personal Files)");
    kMenu->insertItem("Run Command...");
    kMenu->insertSeparator();
    kMenu->insertItem("Lock Screen");
    kMenu->insertItem("Logout (username)");
    kMenu->insertTearOffHandle();

    KStdAction::quit(kapp, SLOT(quit()), testWindow->actionCollection());
    testWindow->menuBar()->insertItem("KMenu", kMenu);
    testWindow->show();
    int rc = kapp->exec();
 
    
    delete driver;
    return rc;
}

/*
 /usr/lib/qt3/bin/moc kmenu_playing.cc -o kmenu_playing.moc.cc
 g++ -o kmenu_playing kmenu_playing.cc -L/usr/lib/qt3/lib -L/opt/kde3/lib \
                -lqt-mt -lkdeui -lkdecore -I/usr/lib/qt3/include \
                -I/opt/kde3/include
 ./kmenu_playing
 */


_______________________________________________
kde-usability mailing list
kde-usability@mail.kde.org
http://mail.kde.org/mailman/listinfo/kde-usability

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

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