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

« back to all changes in this revision

Viewing changes to plasma/desktop/shell/activitymanager/activitycontrols.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 Ivan Cukic <ivan.cukic(at)kde.org>
 
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 version 2,
 
6
 *   or (at your option) any later version, as published by the Free
 
7
 *   Software Foundation
 
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
 
15
 *   License 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
#include "activitycontrols.h"
 
21
#include <QGraphicsScene>
 
22
#include <KPushButton>
 
23
#include <KIconDialog>
 
24
#include <KWindowSystem>
 
25
#include "kactivityinfo.h"
 
26
#include <QApplication>
 
27
 
 
28
ActivityControls::ActivityControls(ActivityIcon * parent)
 
29
    : QGraphicsWidget(parent)
 
30
{
 
31
}
 
32
 
 
33
bool ActivityControls::hidesContents() const
 
34
{
 
35
    return false;
 
36
}
 
37
 
 
38
// ActivityRemovalConfirmation
 
39
 
 
40
ActivityRemovalConfirmation::ActivityRemovalConfirmation(ActivityIcon * parent)
 
41
    : ActivityControls(parent)
 
42
{
 
43
    m_layout = new QGraphicsLinearLayout(this);
 
44
    m_layout->setOrientation(Qt::Vertical);
 
45
    m_layout->setContentsMargins(16, 0, 0, 0);
 
46
    setLayout(m_layout);
 
47
 
 
48
    m_labelRemoveActivity = new Plasma::Label(this);
 
49
    m_labelRemoveActivity->setText(i18n("Remove activity?"));
 
50
    m_labelRemoveActivity->setAlignment(Qt::AlignCenter);
 
51
    m_labelRemoveActivity->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
 
52
    m_layout->addItem(m_labelRemoveActivity);
 
53
 
 
54
    m_buttonConfirmRemoval = new Plasma::PushButton(this);
 
55
    m_buttonConfirmRemoval->setText(i18n("Remove"));
 
56
    m_layout->addItem(m_buttonConfirmRemoval);
 
57
    connect(m_buttonConfirmRemoval, SIGNAL(clicked()), this, SIGNAL(removalConfirmed()));
 
58
 
 
59
    m_buttonCancel = new Plasma::PushButton(this);
 
60
    m_buttonCancel->setText(i18n("Cancel"));
 
61
    m_layout->addItem(m_buttonCancel);
 
62
    connect(m_buttonCancel, SIGNAL(clicked()), this, SIGNAL(closed()));
 
63
}
 
64
 
 
65
// ActivityConfiguration
 
66
 
 
67
ActivityConfiguration::ActivityConfiguration(ActivityIcon * parent, Activity * activity)
 
68
    : ActivityControls(parent), m_activity(activity)
 
69
{
 
70
    m_layoutButtons = new QGraphicsLinearLayout(this);
 
71
    m_layoutButtons->setOrientation(Qt::Vertical);
 
72
    m_layoutButtons->setContentsMargins(16, 0, 0, 0);
 
73
    setLayout(m_layoutButtons);
 
74
 
 
75
    m_labelConfiguration = new Plasma::Label(this);
 
76
    m_labelConfiguration->setText(i18n("Accept changes?"));
 
77
    m_labelConfiguration->setAlignment(Qt::AlignCenter);
 
78
    m_labelConfiguration->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
 
79
    m_layoutButtons->addItem(m_labelConfiguration);
 
80
 
 
81
    m_buttonConfirmChanges = new Plasma::PushButton(this);
 
82
    m_buttonConfirmChanges->setText(i18n("Apply"));
 
83
    m_layoutButtons->addItem(m_buttonConfirmChanges);
 
84
    connect(m_buttonConfirmChanges, SIGNAL(clicked()), this, SLOT(applyChanges()));
 
85
    connect(m_buttonConfirmChanges, SIGNAL(clicked()), this, SIGNAL(closed()));
 
86
 
 
87
    m_buttonCancel = new Plasma::PushButton(this);
 
88
    m_buttonCancel->setText(i18n("Cancel"));
 
89
    m_layoutButtons->addItem(m_buttonCancel);
 
90
    connect(m_buttonCancel, SIGNAL(clicked()), this, SIGNAL(closed()));
 
91
 
 
92
    m_main = new QGraphicsWidget(parent);
 
93
 
 
94
    m_layoutMain = new QGraphicsLinearLayout(m_main);
 
95
    m_layoutMain->setOrientation(Qt::Vertical);
 
96
    m_layoutMain->setContentsMargins(0, 0, 0, 0);
 
97
    m_layoutMain->setSpacing(0);
 
98
 
 
99
    m_activityName = new Plasma::LineEdit(this);
 
100
    m_layoutMain->addItem(m_activityName);
 
101
 
 
102
    m_activityIcon = new Plasma::PushButton(this);
 
103
    m_activityIcon->setIcon(KIcon("plasma"));
 
104
    m_layoutMain->addItem(m_activityIcon);
 
105
    connect(m_activityIcon, SIGNAL(clicked()), this, SLOT(chooseIcon()));
 
106
 
 
107
    m_main->setGeometry(parent->contentsRect());
 
108
 
 
109
    m_activityName->setText(m_activity->name());
 
110
 
 
111
    m_activityIcon->setIcon(
 
112
            QIcon(parent->pixmap(QSize(32, 32))));
 
113
 
 
114
    if (m_activity && m_activity->info() && m_activity->info()->availability() == KActivityInfo::Everything) {
 
115
        m_activityIcon->setEnabled(true);
 
116
    } else {
 
117
        m_activityIcon->setEnabled(false);
 
118
    }
 
119
}
 
120
 
 
121
void ActivityConfiguration::hideEvent(QHideEvent * event)
 
122
{
 
123
    ActivityControls::hideEvent(event);
 
124
 
 
125
    m_main->hide();
 
126
}
 
127
 
 
128
void ActivityConfiguration::showEvent(QShowEvent * event)
 
129
{
 
130
    ActivityControls::showEvent(event);
 
131
 
 
132
    m_main->setZValue(zValue());
 
133
    m_main->show();
 
134
}
 
135
 
 
136
ActivityConfiguration::~ActivityConfiguration()
 
137
{
 
138
    // delete m_layoutMain;
 
139
    m_main->deleteLater();
 
140
}
 
141
 
 
142
void ActivityConfiguration::applyChanges()
 
143
{
 
144
    m_activity->setName(m_activityName->text());
 
145
 
 
146
    if (!m_iconName.isEmpty()) {
 
147
        m_activity->setIcon(m_iconName);
 
148
    }
 
149
}
 
150
 
 
151
void ActivityConfiguration::chooseIcon()
 
152
{
 
153
    QString iconName = KIconDialog::getIcon();
 
154
 
 
155
    if (!iconName.isEmpty()) {
 
156
        m_activityIcon->setIcon(KIcon(iconName));
 
157
        m_iconName = iconName;
 
158
    }
 
159
 
 
160
    // somehow, after closing KIconDialog, plasma loses focus
 
161
    // and the panel controller is closed, soforcing focus to
 
162
    // any of the top level windows that are shown
 
163
    foreach (QWidget * widget, QApplication::topLevelWidgets()) {
 
164
        if (widget->isVisible()) {
 
165
            KWindowSystem::forceActiveWindow(widget->winId(), 0);
 
166
            break;
 
167
        }
 
168
    }
 
169
}
 
170
 
 
171
bool ActivityConfiguration::hidesContents() const
 
172
{
 
173
    return true;
 
174
}