add more spacing
[personal-kdebase.git] / workspace / plasma / applets / tasks / layoutwidget.h
blob782b81de2dcc37c9d5f231aa52f20cc64f473ee4
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 LAYOUTWIDGET_H
23 #define LAYOUTWIDGET_H
25 //Own
26 #include "tasks.h"
28 // Qt
29 #include <QObject>
30 #include <QGraphicsGridLayout>
31 #include <QList>
32 #include <QMultiMap>
35 class TaskGroupItem;
36 class AbstractTaskItem;
38 using TaskManager::StartupPtr;
39 using TaskManager::TaskPtr;
40 using TaskManager::GroupManager;
43 /**
44 * A Layout for the expanded group
46 class LayoutWidget : public QObject
48 Q_OBJECT
50 public:
51 LayoutWidget(TaskGroupItem * parent, Tasks *applet);
52 ~LayoutWidget();
53 /** insert the item on the index in TaskGroupItem::getMemberList */
54 void addTaskItem(AbstractTaskItem*);
55 void removeTaskItem(AbstractTaskItem*);
56 /** insert the item on a specific index*/
57 bool insert(int index, AbstractTaskItem* item);
59 /** returns the insert index for a task drop on pos */
60 int insertionIndexAt(const QPointF &pos);
61 /** set the maximum number of rows */
62 void setMaximumRows(int);
63 /** force the layout to use maximumRows setting and fill rows before columns */
64 void setForceRows(bool);
66 /** the size including expanded groups*/
67 int size();
69 /** returns columnCount or rowCount depending on m_applet->formFactor() */
70 int numberOfRows();
71 /** returns columnCount or rowCount depending on m_applet->formFactor()*/
72 int numberOfColumns();
74 /** Returns the preferred number of rows based on the user settings but limited by calculation to honor AbstractGroupableItem::basicPreferredSize()*/
75 int maximumRows();
76 /** Returns the preferred number of columns calculated on base of AbstractGroupableItem::basicPreferredSize()*/
77 int preferredColumns();
79 public Q_SLOTS:
80 void update();
82 private Q_SLOTS:
83 void constraintsChanged(Plasma::Constraints);
85 Q_SIGNALS:
86 void sizeHintChanged(Qt::SizeHint);
88 private:
89 void init();
91 //void calculatePreferredRowSize();
92 bool remove(AbstractTaskItem* item);
94 void adjustStretch();
95 void updatePreferredSize();
97 /** Populates the actual QGraphicsGridLayout with items*/
98 void layoutItems();
100 bool m_hasSpacer;
101 QGraphicsWidget *m_spacer;
103 TaskGroupItem *m_groupItem;
104 QList <AbstractTaskItem*> m_itemPositions;
105 /** Calculates the number of columns and rows for the layoutItems function and returns <columns/rows>*/
106 QPair<int, int> gridLayoutSize();
108 /** Limit before row is full, more columns are added if maxRows is exeeded*/
109 int m_rowSize;
110 /** How many rows should be used*/
111 int m_maxRows;
113 bool m_forceRows;
115 Tasks *m_applet;
116 /** Creates and initialises a new QGraphicsGridLayout*/
117 void createLayout();
118 QGraphicsGridLayout *m_layout;
121 #endif