add more spacing
[personal-kdebase.git] / workspace / plasma / applets / tasks / taskgroupitem.h
blob07ebbb0edea271228bc3d6fe457c51d91d21c749
1 /***************************************************************************
2 * Copyright (C) 2007 by Robert Knight <robertknight@gmail.com> *
3 * Copyright (C) 2008 by Alexis Ménard <darktears31@gmail.com> *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
19 ***************************************************************************/
22 #ifndef TASKGROUPITEM_H
23 #define TASKGROUPITEM_H
25 #include "abstracttaskitem.h"
26 #include "windowtaskitem.h"
27 // Own
28 #include <taskmanager/taskmanager.h>
29 #include "tasks.h"
30 #include <QMap>
31 #include <QHash>
33 using TaskManager::TaskGroup;
34 using TaskManager::GroupPtr;
35 using TaskManager::TaskItem;
36 using TaskManager::AbstractGroupableItem;
39 class LayoutWidget;
40 class SplitGroupItem;
41 class QGraphicsLinearLayout;
42 typedef QMap<int, AbstractTaskItem*> Order;
44 /**
45 * A task item for a TaskGroup. It can be displayed collapsed as single item or expanded as group.
47 class TaskGroupItem : public AbstractTaskItem
49 Q_OBJECT
51 public:
52 /** Constructs a new representation for a taskgroup. */
53 TaskGroupItem(QGraphicsWidget *parent, Tasks *applet, const bool showTooltip);
55 /** Sets the group represented by this task. */
56 void setGroup(TaskManager::GroupPtr);
58 /** Returns the group represented by this task. */
59 TaskManager::GroupPtr group() const;
61 virtual void close();
63 QList <AbstractTaskItem*> memberList() const;
64 AbstractTaskItem * activeSubTask();
66 virtual bool isWindowItem() const;
67 virtual bool isActive() const;
69 bool collapsed() const;
71 /** Returns Direct Member group if the passed item is in a subgroup */
72 AbstractTaskItem *directMember(AbstractTaskItem *);
74 /** Maximum number of Rows the group will have */
75 int maxRows();
76 //TODO remove and calculate reasonable value in the layout itself
77 void setMaxRows(int);
79 void setForceRows(bool);
80 bool forceRows();
83 *Why the split group works.
84 *drag split group: in the drop event the getDirectMember function is used which retrieves the parent item of the split group
85 *drop on split group: //on unsplitGroup the group adds all items from splitgroup / the grouping is done via the taskgroup in lib
86 *collapse on split group: because windowTaskItems retrive its parentgroup via tasks
88 /** Returns the second, new part(splitgroup) of the group when called on the normal group*/
89 TaskGroupItem * splitGroup();
90 /** Splits the group on position and returns the splitgroup*/
91 TaskGroupItem * splitGroup(int position);
92 /** To remove the childSplitgroupItem and be one item again*/
93 void unsplitGroup();
94 /** To be called on SplitGroups instead of setGroup()*/
95 void setSplitGroup(TaskGroup *group);
96 bool isSplit();
98 LayoutWidget *layoutWidget();
100 int indexOf (AbstractTaskItem *task);
102 int optimumCapacity();
104 AbstractTaskItem* abstractItem(AbstractItemPtr);
106 void setAdditionalMimeData(QMimeData* mimeData);
107 void publishIconGeometry() const;
108 void publishIconGeometry(const QRect &rect) const;
110 signals:
111 /** Emitted when a window is selected for activation, minimization, iconification */
112 void groupSelected(TaskGroupItem *);
113 void sizeHintChanged(Qt::SizeHint);
114 /** informs the LayoutWidget about changes */
115 void changed();
117 public slots:
118 virtual void activate();
119 /** TaskGroupItem* groupItem(GroupPtr);
121 * Reload all tasks
123 void reload();
125 void expand();
126 void collapse();
127 void updatePreferredSize();
129 protected:
130 AbstractTaskItem *taskItemForWId(WId id);
131 virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
132 virtual void paint(QPainter *painter,const QStyleOptionGraphicsItem *option,QWidget *widget);
134 virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
135 virtual void dropEvent(QGraphicsSceneDragDropEvent *event);
136 void handleDroppedId(WId id, AbstractTaskItem *targetTask, QGraphicsSceneDragDropEvent *event);
138 void mousePressEvent(QGraphicsSceneMouseEvent *event);
139 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
140 void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
142 public slots:
143 void updateActive(AbstractTaskItem *);
145 protected:
146 void updateToolTip();
148 protected slots:
149 virtual void wheelEvent(QGraphicsSceneWheelEvent *event);
151 private slots:
152 void updateTask(::TaskManager::TaskChanges changes);
154 /** Stay informed about changes in group */
155 void itemAdded(AbstractItemPtr);
156 void itemRemoved(AbstractItemPtr);
158 /** show a menu for editing group */
159 void editGroup();
160 /** Update to new position*/
161 void itemPositionChanged(AbstractItemPtr);
163 void popupMenu();
165 private:
166 AbstractTaskItem* createAbstractItem(AbstractItemPtr groupableItem);
167 TaskGroupItem* createNewGroup(QList <AbstractTaskItem *> members);
168 WindowTaskItem * createWindowTask(TaskManager::TaskItem* task);
169 TaskGroupItem * createTaskGroup(GroupPtr);
170 WindowTaskItem *createStartingTask(TaskManager::TaskItem* task);
172 void removeItem(AbstractTaskItem *item);
174 void layoutTaskItem(AbstractTaskItem* item, const QPointF &pos);
175 void setSplitIndex(int position);
177 int totalSubTasks();
178 AbstractTaskItem * selectSubTask(int index);
180 GroupPtr m_group;
182 QHash<AbstractItemPtr, AbstractTaskItem*> m_groupMembers;
184 LayoutWidget *m_expandedLayout;
185 QTimer *m_popupMenuTimer;
186 QHash <int, Order> m_taskOrder;
187 int m_lastActivated;
188 int m_activeTaskIndex;
189 int m_maximumRows;
190 bool m_forceRows;
191 int m_splitPosition;
192 TaskGroupItem *m_parentSplitGroup;
193 TaskGroupItem *m_childSplitGroup;
196 #endif