1
/***************************************************************************
4
* Copyright (C) 2008 Jason Stubbs <jasonbstubbs@gmail.com> *
6
* This program is free software; you can redistribute it and/or modify *
7
* it under the terms of the GNU General Public License as published by *
8
* the Free Software Foundation; either version 2 of the License, or *
9
* (at your option) any later version. *
11
* This program is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU General Public License for more details. *
16
* You should have received a copy of the GNU General Public License *
17
* along with this program; if not, write to the *
18
* Free Software Foundation, Inc., *
19
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
20
***************************************************************************/
24
#include <QtGui/QGraphicsWidget>
35
: hiddenState(Task::NotHidden),
37
status(Task::UnknownStatus),
38
category(Task::UnknownCategory)
42
QHash<Plasma::Applet *, QGraphicsWidget *> widgetsByHost;
43
Task::HideStates hiddenState;
46
Task::Category category;
50
Task::Task(QObject *parent)
59
foreach (QGraphicsWidget * widget, d->widgetsByHost) {
60
disconnect(widget, 0, this, 0);
61
// sometimes it appears that the widget will get scheduled for a repaint
62
// then it gets deleted here and QGraphicsScene doesn't get that straight
63
// in its bookkeeping and crashes occur; work around this by giving it a
64
// chance to schedule after the next paintfun
65
widget->deleteLater();
70
QGraphicsWidget *Task::widget(Plasma::Applet *host, bool createIfNecessary)
74
QGraphicsWidget *widget = d->widgetsByHost.value(host);
76
if (!widget && createIfNecessary) {
77
widget = createWidget(host);
80
d->widgetsByHost.insert(host, widget);
81
connect(widget, SIGNAL(destroyed()), this, SLOT(widgetDeleted()));
88
bool Task::isEmbeddable(Plasma::Applet *host)
94
return d->widgetsByHost.value(host) || isEmbeddable();
97
QHash<Plasma::Applet *, QGraphicsWidget *> Task::widgetsByHost() const
99
return d->widgetsByHost;
102
void Task::abandon(Plasma::Applet *host)
104
QGraphicsWidget *widget = d->widgetsByHost.value(host);
106
widget->deleteLater();
110
QGraphicsWidget *Task::forget(Plasma::Applet *host)
112
return d->widgetsByHost.take(host);
115
void Task::widgetDeleted()
117
bool wasEmbeddable = isEmbeddable();
119
QGraphicsWidget * w = static_cast<QGraphicsWidget*>(sender());
120
QMutableHashIterator<Plasma::Applet *, QGraphicsWidget *> it(d->widgetsByHost);
121
while (it.hasNext()) {
123
if (it.value() == w) {
128
if (!wasEmbeddable && isEmbeddable()) {
133
void Task::setHidden(HideStates state)
135
d->hiddenState = state;
138
Task::HideStates Task::hidden() const
140
return d->hiddenState;
143
bool Task::isUsed() const
145
return !d->widgetsByHost.isEmpty();
148
Task::Order Task::order() const
153
void Task::setOrder(Order order)
158
void Task::setCategory(Category category)
160
if (d->category == category) {
164
d->category = category;
168
Task::Category Task::category() const
173
void Task::setStatus(Status status)
175
if (d->status == status) {
184
Task::Status Task::status() const
189
void Task::resetHiddenStatus()
191
if (d->status == NeedsAttention) {
192
//tasks don't get moved anymore
194
if (hidden() & AutoHidden) {
195
setHidden(hidden() ^ AutoHidden);
198
if (d->status == Active && (hidden() & AutoHidden)) {
199
setHidden(hidden() ^ AutoHidden);
200
} else if (d->status == Passive) {
201
setHidden(hidden() | AutoHidden);