~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to plasma/desktop/applets/tasks/applauncheritem.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2010 by Anton Kreuzkamp <akreuzkamp@web.de>             *
 
3
 *                                                                         *
 
4
 *   This program is free software; you can redistribute it and/or modify  *
 
5
 *   it under the terms of the GNU General Public License as published by  *
 
6
 *   the Free Software Foundation; either version 2 of the License, or     *
 
7
 *   (at your option) any later version.                                   *
 
8
 *                                                                         *
 
9
 *   This program is distributed in the hope that it will be useful,       *
 
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
12
 *   GNU General Public License for more details.                          *
 
13
 *                                                                         *
 
14
 *   You should have received a copy of the GNU General Public License     *
 
15
 *   along with this program; if not, write to the                         *
 
16
 *   Free Software Foundation, Inc.,                                       *
 
17
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
 
18
 ***************************************************************************/
 
19
 
 
20
// Own
 
21
#include "applauncheritem.h"
 
22
#include "taskgroupitem.h"
 
23
 
 
24
#include <taskmanager/taskactions.h>
 
25
 
 
26
// Qt
 
27
#include <QGraphicsSceneContextMenuEvent>
 
28
#include <QGraphicsView>
 
29
 
 
30
// KDE
 
31
#include <KAuthorized>
 
32
#include <KIconEffect>
 
33
 
 
34
#include <Plasma/ToolTipManager>
 
35
#include <Plasma/Corona>
 
36
#include <Plasma/Containment>
 
37
#include <Plasma/PaintUtils>
 
38
 
 
39
AppLauncherItem::AppLauncherItem( QGraphicsWidget* parent, Tasks* applet, TaskManager::LauncherItem* launcher)
 
40
    : AbstractTaskItem(parent, applet)
 
41
{
 
42
    m_launcher = launcher;
 
43
    m_abstractItem = launcher;
 
44
}
 
45
 
 
46
void AppLauncherItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
 
47
{
 
48
    if (event->button() == Qt::LeftButton && boundingRect().contains(event->pos())) {
 
49
        m_launcher->launch();
 
50
    }
 
51
}
 
52
 
 
53
void AppLauncherItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *e)
 
54
{
 
55
    if (!KAuthorized::authorizeKAction("kwin_rmb") || !m_launcher) {
 
56
        QGraphicsWidget::contextMenuEvent(e);
 
57
        return;
 
58
    }
 
59
 
 
60
    QList <QAction*> actionList;
 
61
 
 
62
    QAction *configAction = m_applet->action("configure");
 
63
    if (configAction && configAction->isEnabled()) {
 
64
        actionList.append(configAction);
 
65
    }
 
66
 
 
67
    TaskManager::BasicMenu menu(0, m_launcher, &m_applet->groupManager(), actionList);
 
68
    menu.adjustSize();
 
69
 
 
70
    if (m_applet->formFactor() != Plasma::Vertical) {
 
71
        menu.setMinimumWidth(size().width());
 
72
    }
 
73
 
 
74
    Q_ASSERT(m_applet->containment());
 
75
    Q_ASSERT(m_applet->containment()->corona());
 
76
    stopWindowHoverEffect();
 
77
    menu.exec(m_applet->containment()->corona()->popupPosition(this, menu.size()));
 
78
}
 
79
 
 
80
 
 
81
void AppLauncherItem::updateToolTip()
 
82
{
 
83
    Plasma::ToolTipContent data(m_launcher->name(),m_launcher->genericName(),m_launcher->icon());
 
84
    data.setInstantPopup(true);
 
85
    Plasma::ToolTipManager::self()->setContent(this, data);
 
86
}
 
87
 
 
88
void AppLauncherItem::keyPressEvent(QKeyEvent *event)
 
89
{
 
90
    if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter)
 
91
    {
 
92
        m_launcher->launch();
 
93
    }
 
94
    else
 
95
    {
 
96
        QGraphicsWidget::keyPressEvent(event);
 
97
    }
 
98
}
 
99
 
 
100
void AppLauncherItem::setAdditionalMimeData(QMimeData* mimeData)
 
101
{
 
102
    if (m_launcher) {
 
103
        m_launcher->addMimeData(mimeData);
 
104
    }
 
105
}
 
106
 
 
107
#include "applauncheritem.moc"
 
108