2
* Copyright (C) 2010 Ivan Cukic <ivan.cukic(at)kde.org>
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
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
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.
20
#include "activitycontrols.h"
21
#include <QGraphicsScene>
22
#include <KPushButton>
23
#include <KIconDialog>
24
#include <KWindowSystem>
25
#include "kactivityinfo.h"
26
#include <QApplication>
28
ActivityControls::ActivityControls(ActivityIcon * parent)
29
: QGraphicsWidget(parent)
33
bool ActivityControls::hidesContents() const
38
// ActivityRemovalConfirmation
40
ActivityRemovalConfirmation::ActivityRemovalConfirmation(ActivityIcon * parent)
41
: ActivityControls(parent)
43
m_layout = new QGraphicsLinearLayout(this);
44
m_layout->setOrientation(Qt::Vertical);
45
m_layout->setContentsMargins(16, 0, 0, 0);
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);
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()));
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()));
65
// ActivityConfiguration
67
ActivityConfiguration::ActivityConfiguration(ActivityIcon * parent, Activity * activity)
68
: ActivityControls(parent), m_activity(activity)
70
m_layoutButtons = new QGraphicsLinearLayout(this);
71
m_layoutButtons->setOrientation(Qt::Vertical);
72
m_layoutButtons->setContentsMargins(16, 0, 0, 0);
73
setLayout(m_layoutButtons);
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);
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()));
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()));
92
m_main = new QGraphicsWidget(parent);
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);
99
m_activityName = new Plasma::LineEdit(this);
100
m_layoutMain->addItem(m_activityName);
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()));
107
m_main->setGeometry(parent->contentsRect());
109
m_activityName->setText(m_activity->name());
111
m_activityIcon->setIcon(
112
QIcon(parent->pixmap(QSize(32, 32))));
114
if (m_activity && m_activity->info() && m_activity->info()->availability() == KActivityInfo::Everything) {
115
m_activityIcon->setEnabled(true);
117
m_activityIcon->setEnabled(false);
121
void ActivityConfiguration::hideEvent(QHideEvent * event)
123
ActivityControls::hideEvent(event);
128
void ActivityConfiguration::showEvent(QShowEvent * event)
130
ActivityControls::showEvent(event);
132
m_main->setZValue(zValue());
136
ActivityConfiguration::~ActivityConfiguration()
138
// delete m_layoutMain;
139
m_main->deleteLater();
142
void ActivityConfiguration::applyChanges()
144
m_activity->setName(m_activityName->text());
146
if (!m_iconName.isEmpty()) {
147
m_activity->setIcon(m_iconName);
151
void ActivityConfiguration::chooseIcon()
153
QString iconName = KIconDialog::getIcon();
155
if (!iconName.isEmpty()) {
156
m_activityIcon->setIcon(KIcon(iconName));
157
m_iconName = iconName;
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);
171
bool ActivityConfiguration::hidesContents() const