1 /***************************************************************************
2 * Copyright (C) 2007 by Robert Knight <robertknight@gmail.com> *
3 * Copyright (C) 2008 by Alexis Ménard <darktears31@gmail.com> *
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. *
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. *
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"
28 #include <taskmanager/taskmanager.h>
33 using TaskManager::TaskGroup
;
34 using TaskManager::GroupPtr
;
35 using TaskManager::TaskItem
;
36 using TaskManager::AbstractGroupableItem
;
41 class QGraphicsLinearLayout
;
42 typedef QMap
<int, AbstractTaskItem
*> Order
;
45 * A task item for a TaskGroup. It can be displayed collapsed as single item or expanded as group.
47 class TaskGroupItem
: public AbstractTaskItem
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;
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 */
76 //TODO remove and calculate reasonable value in the layout itself
79 void setForceRows(bool);
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*/
94 /** To be called on SplitGroups instead of setGroup()*/
95 void setSplitGroup(TaskGroup
*group
);
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;
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 */
118 virtual void activate();
119 /** TaskGroupItem* groupItem(GroupPtr);
127 void updatePreferredSize();
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
);
143 void updateActive(AbstractTaskItem
*);
146 void updateToolTip();
149 virtual void wheelEvent(QGraphicsSceneWheelEvent
*event
);
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 */
160 /** Update to new position*/
161 void itemPositionChanged(AbstractItemPtr
);
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
);
178 AbstractTaskItem
* selectSubTask(int index
);
182 QHash
<AbstractItemPtr
, AbstractTaskItem
*> m_groupMembers
;
184 LayoutWidget
*m_expandedLayout
;
185 QTimer
*m_popupMenuTimer
;
186 QHash
<int, Order
> m_taskOrder
;
188 int m_activeTaskIndex
;
192 TaskGroupItem
*m_parentSplitGroup
;
193 TaskGroupItem
*m_childSplitGroup
;