1 /***************************************************************************
2 * Copyright (C) 2008 by Lukas Appelhans *
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 ***************************************************************************/
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>
32 #include "ui_quicklaunchConfig.h"
33 #include "ui_quicklaunchAdd.h"
35 #include "quicklaunchIcon.h"
42 class QuicklaunchLayout
: public QGraphicsGridLayout
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;
56 while (itemAt(row
, column
))
58 kDebug() << "Row is" << row
<< "column is" << column
;
59 if (row
< m_rowCount
- 1) {
63 kDebug() << "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
);
81 class QuicklaunchApplet
: public Plasma::Applet
85 QuicklaunchApplet(QObject
*parent
, const QVariantList
&args
);
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;
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);
107 void createConfigurationInterface(KConfigDialog
*parent
);
109 * Slot for showing the Add Icon interface
111 void showAddInterface();
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
);
147 * Called when the user has clicked OK in the Add Icon interface
152 * Called when the user has clicked OK or apply in the Config interface
154 void configAccepted();
159 void removeCurrentIcon();
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
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
;
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
;