not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / plasma / applets / quicklaunch / quicklaunchApplet.h
blob2ea01095b762a1623fc3eb974eb5f2e21b4b9963
1 /***************************************************************************
2 * Copyright (C) 2008 by Lukas Appelhans *
3 * l.appelhans@gmx.de *
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 ***************************************************************************/
20 #ifndef QUICKLAUNCHAPPLET_H
21 #define QUICKLAUNCHAPPLET_H
23 #include <plasma/applet.h>
24 #include <plasma/widgets/iconwidget.h>
25 #include <QGraphicsLinearLayout>
26 #include <QGraphicsGridLayout>
27 #include <QGraphicsLayoutItem>
28 #include <QList>
29 #include <KIcon>
30 #include <KDialog>
32 #include "ui_quicklaunchConfig.h"
33 #include "ui_quicklaunchAdd.h"
35 #include "quicklaunchIcon.h"
37 namespace Plasma
39 class Dialog;
42 class QuicklaunchLayout : public QGraphicsGridLayout
44 public:
45 QuicklaunchLayout(QGraphicsLayoutItem *parent, int rowCount)
46 : QGraphicsGridLayout(parent), m_rowCount(rowCount)
48 void setRowCount(int rowCount) { m_rowCount = rowCount; }
49 void addItem(Plasma::IconWidget *icon) {
50 //kDebug() << "Row count is" << rowCount() << "Wanted row count is" << m_rowCount;
51 //int row = m_rowCount == rowCount() || rowCount() == -1 ? 0 : rowCount();
52 //int column = m_rowCount == rowCount() || columnCount() == 0 ? columnCount() : columnCount() - 1;
53 //kDebug() << "Adding icon to row = " << row << ", column = " << column;
54 int row = 0;
55 int column = 0;
56 while (itemAt(row, column))
58 kDebug() << "Row is" << row << "column is" << column;
59 if (row < m_rowCount - 1) {
60 row++;
62 else {
63 kDebug() << "column++";
64 row = 0;
65 column++;
68 QGraphicsGridLayout::addItem(icon, row, column);
70 QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint = QSizeF()) const
72 if (which == Qt::PreferredSize) {
73 return QSizeF(columnCount() * geometry().height() / m_rowCount, QGraphicsGridLayout::sizeHint(which, constraint).height());
75 return QGraphicsGridLayout::sizeHint(which, constraint);
77 private:
78 int m_rowCount;
81 class QuicklaunchApplet : public Plasma::Applet
83 Q_OBJECT
84 public:
85 QuicklaunchApplet(QObject *parent, const QVariantList &args);
86 ~QuicklaunchApplet();
88 /**
89 * Returns hints about the geometry of the figure
90 * @return Hints about proportionality of the applet
92 QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint = QSizeF()) const;
94 /**
95 * Returns info about if we want to expand or not
96 * For now, we never need to expand
98 Qt::Orientations expandingDirections() const { return 0; }
101 * List of actions to add in context menu
102 * @return List of QAction pointers
104 virtual QList<QAction*> contextActions(QuicklaunchIcon *icon = 0);
106 public slots:
107 void createConfigurationInterface(KConfigDialog *parent);
109 * Slot for showing the Add Icon interface
111 void showAddInterface();
113 protected:
115 * Overloaded method to save the state on exit
117 void saveState(KConfigGroup &config) const;
119 virtual bool eventFilter(QObject * object, QEvent * event);
122 * Overloaded drag enter event listener
123 * Check if the dragged item is valid
125 void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
128 * Overloaded drag move event listener
129 * Listens for drag moves
131 void dragMoveEvent(QGraphicsSceneDragDropEvent *event);
134 * Overloaded drop event listener
135 * Determines if a dropped item is valid Url, and if so
136 * add the icon to the applet
138 void dropEvent(QGraphicsSceneDragDropEvent *event);
141 * Called when something in the geometry has changed
143 void constraintsEvent(Plasma::Constraints constraints);
145 protected slots:
147 * Called when the user has clicked OK in the Add Icon interface
149 void addAccepted();
152 * Called when the user has clicked OK or apply in the Config interface
154 void configAccepted();
156 private slots:
157 void refactorUi();
158 void showDialog();
159 void removeCurrentIcon();
161 private:
162 void init();
165 * Read a Url, and insert at the given position
166 * @param index The position to insert the icon into
167 * @param desktopFile The Url to read
169 void addProgram(int index, const QString &desktopFile);
172 * Read all Urls from a list, and insert into icon list
173 * @param desktopFiles List with Urls
175 void loadPrograms(const QStringList &desktopFiles);
178 * Removes all items from a BoxLayout
179 * @param layout Layout to clear
181 void clearLayout(QGraphicsLayout *layout);
184 * Saves icons into plasma applet config file
186 void saveConfig() {}
188 bool dropHandler(const int pos, const QMimeData *mimedata);
190 QGraphicsLinearLayout *m_layout;
191 QuicklaunchLayout *m_innerLayout;
192 QList<QuicklaunchIcon*> m_icons;
193 Plasma::IconWidget *m_arrow;
194 int m_visibleIcons;
195 int m_rowCount;
196 int m_dialogRowCount;
197 Plasma::Dialog *m_dialog;
198 QGraphicsWidget * m_dialogWidget;
199 QuicklaunchLayout *m_dialogLayout;
200 KDialog *m_addDialog;
201 Ui::quicklaunchConfig uiConfig;
202 Ui::quicklaunchAdd addUi;
203 QuicklaunchIcon *m_rightClickedIcon;
204 QPointF m_mousePressPos;
206 QAction* m_addAction;
207 QAction* m_removeAction;
210 #endif