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

List:       kde-panel-devel
Subject:    Re: [Panel-devel] KDE/kdebase/workspace/plasma/applets/kickoff
From:       "Robert Knight" <robertknight () gmail ! com>
Date:       2007-12-09 6:12:11
Message-ID: 13ed09c00712082212u20ae3042x6fbb5b03fca2ab47 () mail ! gmail ! com
[Download RAW message or body]

Hi,

> * added optional favorites submenu
> * added optional switch user, lock and logout actions
> * added configuration interface to enable/disable them

Is it necessary or useful to make these menu items optional?  I can
see that not everyone might want to have a list of shortcuts (the
favorites) in the menu, but I'm not sure the same can be said for the
Switch User, Lock and Logout options.

Regards,
Robert.

On 08/12/2007, Sebastian Sauer <mail@dipe.org> wrote:
> SVN commit 746417 by sebsauer:
> 
> * fix menu-pos on zoom!=1:1
> * added optional favorites submenu
> * added optional switch user, lock and logout actions
> * added configuration interface to enable/disable them
> 
> 
> 
> M  +5 -0      core/urlitemlauncher.cpp
> M  +2 -0      core/urlitemlauncher.h
> M  +9 -3      simpleapplet/menuview.cpp
> M  +153 -17   simpleapplet/simpleapplet.cpp
> M  +8 -15     simpleapplet/simpleapplet.h
> 
> 
> --- trunk/KDE/kdebase/workspace/plasma/applets/kickoff/core/urlitemlauncher.cpp \
> #746416:746417 @@ -121,6 +121,11 @@
> return Private::openUrl(urlString);
> }
> 
> +bool UrlItemLauncher::openUrl(const QString& url)
> +{
> +    return Private::openUrl(url);
> +}
> +
> void UrlItemLauncher::onSetupDone(Solid::ErrorType error, QVariant errorData, const \
> QString &udi) {
> if (error!=Solid::NoError) {
> --- trunk/KDE/kdebase/workspace/plasma/applets/kickoff/core/urlitemlauncher.h \
> #746416:746417 @@ -71,6 +71,8 @@
> public Q_SLOTS:
> /** Open the specified @p index from a Kickoff model. */
> bool openItem(const QModelIndex& index);
> +    /** Open the specified @p url */
> +    bool openUrl(const QString& url);
> 
> private Q_SLOTS:
> void onSetupDone(Solid::ErrorType error, QVariant errorData, const QString &udi);
> --- trunk/KDE/kdebase/workspace/plasma/applets/kickoff/simpleapplet/menuview.cpp \
> #746416:746417 @@ -23,6 +23,7 @@
> // Qt
> #include <QtCore/QAbstractItemModel>
> #include <QtCore/QStack>
> +#include <QtCore/QUrl>
> #include <QtDebug>
> 
> // Local
> @@ -75,6 +76,7 @@
> {
> connect(this,SIGNAL(triggered(QAction*)),this,SLOT(actionTriggered(QAction*)));
> UrlItemLauncher::addGlobalHandler(UrlItemLauncher::ExtensionHandler,"desktop",new \
> ServiceItemHandler); +    \
> UrlItemLauncher::addGlobalHandler(UrlItemLauncher::ProtocolHandler, "leave", new \
> LeaveItemHandler); }
> MenuView::~MenuView()
> {
> @@ -121,7 +123,8 @@
> QMenu *menu = qobject_cast<QMenu*>(parentWidget);
> while (menu) {
> int row = menu->actions().indexOf(action);
> -        Q_ASSERT( row != -1 );
> +        if( row < 0 )
> +            return QModelIndex();
> rows.push(row);
> 
> if (menu == this) {
> @@ -254,7 +257,10 @@
> void MenuView::actionTriggered(QAction *action)
> {
> QModelIndex index = indexForAction(action);
> -    Q_ASSERT(index.isValid());
> -    d->launcher->openItem(index);
> +    if (index.isValid())
> +        d->launcher->openItem(index);
> +    else if (action->data().type() == QVariant::Url)
> +        d->launcher->openUrl(action->data().toUrl().toString());
> }
> +
> #include "menuview.moc"
> --- trunk/KDE/kdebase/workspace/plasma/applets/kickoff/simpleapplet/simpleapplet.cpp \
> #746416:746417 @@ -22,12 +22,15 @@
> #include "simpleapplet/menuview.h"
> 
> // Qt
> +#include <QCheckBox>
> +#include <QVBoxLayout>
> #include <QGraphicsSceneMouseEvent>
> #include <QGraphicsView>
> #include <QtDebug>
> 
> // KDE
> #include <KIcon>
> +#include <KDialog>
> 
> // Plasma
> #include <plasma/layouts/boxlayout.h>
> @@ -35,24 +38,71 @@
> #include <plasma/containment.h>
> 
> // Local
> +#include "core/models.h"
> #include "core/applicationmodel.h"
> +#include "core/favoritesmodel.h"
> +#include "core/leavemodel.h"
> 
> +class MenuLauncherApplet::Private
> +{
> +public:
> +        QMenu *menuview;
> +        Plasma::Icon *icon;
> +        Kickoff::MenuView *appview;
> +        Kickoff::MenuView* favview;
> +
> +        bool showFavorites;
> +        bool showLeaveSwitchUser;
> +        bool showLeaveLock;
> +        bool showLeaveLogout;
> +
> +        KDialog *dialog;
> +        QCheckBox *showFavCheckBox;
> +        QCheckBox *showSwitchUserCheckBox;
> +        QCheckBox *showLockCheckBox;
> +        QCheckBox *showLogoutCheckBox;
> +
> +        Private() : menuview(0), appview(0), favview(0), dialog(0) {}
> +        ~Private() { delete dialog; delete menuview; delete appview; delete \
> favview; } +};
> +
> MenuLauncherApplet::MenuLauncherApplet(QObject *parent, const QVariantList &args)
> > Plasma::Applet(parent,args),
> -      m_menuview(0)
> +      d(new Private)
> {
> +    setHasConfigurationInterface(true);
> +
> Plasma::HBoxLayout *layout = new Plasma::HBoxLayout(this);
> layout->setMargin(0);
> -    m_icon = new Plasma::Icon(KIcon("start-here"), QString(), this);
> -    m_icon->setFlag(ItemIsMovable, false);
> -    connect(m_icon, SIGNAL(pressed(bool, QGraphicsSceneMouseEvent*)), this, \
> SLOT(toggleMenu(bool,QGraphicsSceneMouseEvent*))); +
> +    d->icon = new Plasma::Icon(QString(), this);
> +    d->icon->setFlag(ItemIsMovable, false);
> +    connect(d->icon, SIGNAL(pressed(bool, QGraphicsSceneMouseEvent*)), this, \
> SLOT(toggleMenu(bool,QGraphicsSceneMouseEvent*))); +
> +    d->showFavorites = true;
> +    d->showLeaveSwitchUser = true;
> +    d->showLeaveLock = true;
> +    d->showLeaveLogout = true;
> }
> 
> MenuLauncherApplet::~MenuLauncherApplet()
> {
> -    delete m_menuview;
> +    delete d;
> }
> 
> +void MenuLauncherApplet::init()
> +{
> +    KConfigGroup cg = config();
> +
> +    d->icon->setIcon(KIcon(cg.readEntry("icon","start-here")));
> +    //setMinimumContentSize(d->icon->iconSize()); //setSize(d->icon->iconSize())
> +
> +    d->showFavorites = cg.readEntry("showFavorites",d->showFavorites);
> +    d->showLeaveSwitchUser = \
> cg.readEntry("showLeaveSwitchUser",d->showLeaveSwitchUser); +    d->showLeaveLock = \
> cg.readEntry("showLeaveLock",d->showLeaveLock); +    d->showLeaveLogout = \
> cg.readEntry("showLeaveLogout",d->showLeaveLogout); +}
> +
> QSizeF MenuLauncherApplet::contentSizeHint() const
> {
> return QSizeF(48,48);
> @@ -63,34 +113,120 @@
> return 0;
> }
> 
> +void MenuLauncherApplet::showConfigurationInterface()
> +{
> +    if (! d->dialog) {
> +        d->dialog = new KDialog();
> +        d->dialog->setCaption( i18nc("@title:window","Configure Menu") );
> +        d->dialog->setButtons( KDialog::Ok | KDialog::Cancel | KDialog::Apply );
> +        connect(d->dialog, SIGNAL(applyClicked()), this, SLOT(configAccepted()));
> +        connect(d->dialog, SIGNAL(okClicked()), this, SLOT(configAccepted()));
> +
> +        QVBoxLayout *layout = new QVBoxLayout(d->dialog->mainWidget());
> +        d->dialog->mainWidget()->setLayout(layout);
> +
> +        d->showFavCheckBox = new QCheckBox(i18n("Favorites"), \
> d->dialog->mainWidget()); +        \
> d->showFavCheckBox->setCheckState(d->showFavorites ? Qt::Checked : Qt::Unchecked); \
> +        layout->addWidget(d->showFavCheckBox); +
> +        d->showSwitchUserCheckBox = new QCheckBox(i18n("Switch User"), \
> d->dialog->mainWidget()); +        \
> d->showSwitchUserCheckBox->setCheckState(d->showLeaveSwitchUser ? Qt::Checked : \
> Qt::Unchecked); +        layout->addWidget(d->showSwitchUserCheckBox);
> +
> +        d->showLockCheckBox = new QCheckBox(i18n("Lock"), \
> d->dialog->mainWidget()); +        \
> d->showLockCheckBox->setCheckState(d->showLeaveLock ? Qt::Checked : Qt::Unchecked); \
> +        layout->addWidget(d->showLockCheckBox); +
> +        d->showLogoutCheckBox = new QCheckBox(i18n("Logout"), \
> d->dialog->mainWidget()); +        \
> d->showLogoutCheckBox->setCheckState(d->showLeaveLogout ? Qt::Checked : \
> Qt::Unchecked); +        layout->addWidget(d->showLogoutCheckBox);
> +    }
> +    d->dialog->show();
> +}
> +
> +void MenuLauncherApplet::configAccepted()
> +{
> +    d->showFavorites = d->showFavCheckBox->checkState() == Qt::Checked;
> +    d->showLeaveSwitchUser = d->showSwitchUserCheckBox->checkState() == \
> Qt::Checked; +    d->showLeaveLock = d->showLockCheckBox->checkState() == \
> Qt::Checked; +    d->showLeaveLogout = d->showLogoutCheckBox->checkState() == \
> Qt::Checked; +
> +    KConfigGroup cg = config();
> +    cg.writeEntry("showFavorites", d->showFavorites);
> +    cg.writeEntry("showLeaveSwitchUser", d->showLeaveSwitchUser);
> +    cg.writeEntry("showLeaveLock", d->showLeaveLock);
> +    cg.writeEntry("showLeaveLogout", d->showLeaveLogout);
> +    cg.config()->sync();
> +
> +    delete d->menuview;
> +    d->menuview = 0;
> +}
> +
> void MenuLauncherApplet::toggleMenu(bool pressed, QGraphicsSceneMouseEvent *event)
> {
> if (!pressed) {
> return;
> }
> 
> -    if (!m_menuview) {
> -        m_menuview = new Kickoff::MenuView();
> -        ApplicationModel *appModel = new ApplicationModel(m_menuview);
> -        appModel->setDuplicatePolicy(ApplicationModel::ShowLatestOnlyPolicy);
> -        m_menuview->setModel(appModel);
> +    if (!d->menuview) {
> +        d->menuview = new QMenu();
> +
> +        if(!d->appview) {
> +            d->appview = new Kickoff::MenuView();
> +            ApplicationModel *appModel = new ApplicationModel(d->appview);
> +            appModel->setDuplicatePolicy(ApplicationModel::ShowLatestOnlyPolicy);
> +            d->appview->setModel(appModel);
> +        }
> +        foreach (QAction *action, d->appview->actions())
> +            d->menuview->addAction(action);
> +        connect(d->menuview,SIGNAL(triggered(QAction*)),d->appview,SLOT(actionTriggered(QAction*)));
>  +
> +        if (d->showFavorites) {
> +            if (!d->favview) {
> +                d->favview = new Kickoff::MenuView();
> +                Kickoff::FavoritesModel* favmodel = new \
> Kickoff::FavoritesModel(d->favview); +                \
> d->favview->setModel(favmodel); +            }
> +            d->menuview->addSeparator();
> +            foreach (QAction *action, d->favview->actions())
> +                d->menuview->addAction(action);
> +            connect(d->menuview,SIGNAL(triggered(QAction*)),d->favview,SLOT(actionTriggered(QAction*)));
>  +        }
> +
> +        if (d->showLeaveSwitchUser || d->showLeaveLock || d->showLeaveLogout) {
> +            d->menuview->addSeparator();
> +            if (d->showLeaveSwitchUser) {
> +                QAction *lockaction = \
> d->menuview->addAction(KIcon("system-switch-user"),i18n("Switch User")); +          \
> lockaction->setData(QUrl("leave:/switch")); +            }
> +            if (d->showLeaveLock) {
> +                QAction *lockaction = \
> d->menuview->addAction(KIcon("system-lock-screen"),i18n("Lock")); +                \
> lockaction->setData(QUrl("leave:/lock")); +            }
> +            if (d->showLeaveLogout) {
> +                QAction *logoutaction = \
> d->menuview->addAction(KIcon("system-log-out"),i18n("Logout")); +                \
> logoutaction->setData(QUrl("leave:/logout")); +            }
> +        }
> }
> 
> -    QPointF scenePos = mapToScene(boundingRect().topLeft());
> +    const QPointF scenePos = mapToScene(boundingRect().topLeft());
> QWidget *viewWidget = event->widget() ? event->widget()->parentWidget() : 0;
> QGraphicsView *view = qobject_cast<QGraphicsView*>(viewWidget);
> QPoint globalPos;
> if (view) {
> -        QPoint viewPos = view->mapFromScene(scenePos);
> +        const QPoint viewPos = view->mapFromScene(scenePos);
> globalPos = view->mapToGlobal(viewPos);
> -        int ypos = globalPos.ry() - m_menuview->sizeHint().height();
> -        if( ypos < 0 )
> -            ypos = globalPos.ry() + boundingRect().height();
> +        int ypos = globalPos.ry() - d->menuview->sizeHint().height();
> +        if( ypos < 0 ) {
> +            const QRect size = mapToView(view, boundingRect());
> +            ypos = globalPos.ry() + size.height();
> +        }
> globalPos.ry() = ypos;
> }
> 
> -    m_menuview->setAttribute(Qt::WA_DeleteOnClose);
> -    m_menuview->popup(globalPos);
> +    d->menuview->setAttribute(Qt::WA_DeleteOnClose);
> +    d->menuview->popup(globalPos);
> }
> 
> #include "simpleapplet.moc"
> --- trunk/KDE/kdebase/workspace/plasma/applets/kickoff/simpleapplet/simpleapplet.h \
> #746416:746417 @@ -20,24 +20,11 @@
> #ifndef SIMPLEAPPLET_H
> #define SIMPLEAPPLET_H
> 
> -// KDE
> -#include <KIcon>
> -
> // Plasma
> #include <plasma/applet.h>
> 
> class QGraphicsSceneMouseEvent;
> 
> -namespace Kickoff
> -{
> -    class MenuView;
> -}
> -namespace Plasma
> -{
> -    class Icon;
> -    class PushButton;
> -}
> -
> class MenuLauncherApplet : public Plasma::Applet
> {
> Q_OBJECT
> @@ -46,15 +33,21 @@
> MenuLauncherApplet(QObject *parent, const QVariantList &args);
> virtual ~MenuLauncherApplet();
> 
> +        void init();
> +
> QSizeF contentSizeHint() const;
> Qt::Orientations expandingDirections() const;
> 
> +public slots:
> +        void showConfigurationInterface();
> +
> protected slots:
> +        void configAccepted();
> void toggleMenu(bool pressed, QGraphicsSceneMouseEvent *event);
> 
> private:
> -        Kickoff::MenuView *m_menuview;
> -        Plasma::Icon *m_icon;
> +        class Private;
> +        Private * const d;
> };
> 
> K_EXPORT_PLASMA_APPLET(menulauncher, MenuLauncherApplet)
> 
_______________________________________________
Panel-devel mailing list
Panel-devel@kde.org
https://mail.kde.org/mailman/listinfo/panel-devel


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

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