Applets
quicklaunchApplet.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef QUICKLAUNCHAPPLET_H
00021 #define QUICKLAUNCHAPPLET_H
00022
00023 #include <plasma/applet.h>
00024 #include <plasma/widgets/iconwidget.h>
00025 #include <QGraphicsLinearLayout>
00026 #include <QGraphicsGridLayout>
00027 #include <QGraphicsLayoutItem>
00028 #include <QList>
00029 #include <KIcon>
00030 #include <KDialog>
00031
00032 #include "ui_quicklaunchConfig.h"
00033 #include "ui_quicklaunchAdd.h"
00034
00035 #include "quicklaunchIcon.h"
00036
00037 namespace Plasma
00038 {
00039 class Dialog;
00040 }
00041
00042 class QuicklaunchLayout : public QGraphicsGridLayout
00043 {
00044 public:
00045 QuicklaunchLayout(QGraphicsLayoutItem *parent, int rowCount)
00046 : QGraphicsGridLayout(parent), m_rowCount(rowCount)
00047 {}
00048 void setRowCount(int rowCount) { m_rowCount = rowCount; }
00049 void addItem(Plasma::IconWidget *icon) {
00050
00051
00052
00053
00054 int row = 0;
00055 int column = 0;
00056 while (itemAt(row, column))
00057 {
00058 kDebug() << "Row is" << row << "column is" << column;
00059 if (row < m_rowCount - 1) {
00060 row++;
00061 }
00062 else {
00063 kDebug() << "column++";
00064 row = 0;
00065 column++;
00066 }
00067 }
00068 QGraphicsGridLayout::addItem(icon, row, column);
00069 }
00070 QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint = QSizeF()) const
00071 {
00072 if (which == Qt::PreferredSize) {
00073 return QSizeF(columnCount() * geometry().height() / m_rowCount, QGraphicsGridLayout::sizeHint(which, constraint).height());
00074 }
00075 return QGraphicsGridLayout::sizeHint(which, constraint);
00076 }
00077 private:
00078 int m_rowCount;
00079 };
00080
00081 class QuicklaunchApplet : public Plasma::Applet
00082 {
00083 Q_OBJECT
00084 public:
00085 QuicklaunchApplet(QObject *parent, const QVariantList &args);
00086 ~QuicklaunchApplet();
00087
00092 QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint = QSizeF()) const;
00093
00098 Qt::Orientations expandingDirections() const { return 0; }
00099
00104 virtual QList<QAction*> contextActions(QuicklaunchIcon *icon = 0);
00105
00106 public slots:
00107 void createConfigurationInterface(KConfigDialog *parent);
00111 void showAddInterface();
00112
00113 protected:
00117 void saveState(KConfigGroup &config) const;
00118
00119 virtual bool eventFilter(QObject * object, QEvent * event);
00120
00125 void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
00126
00131 void dragMoveEvent(QGraphicsSceneDragDropEvent *event);
00132
00138 void dropEvent(QGraphicsSceneDragDropEvent *event);
00139
00143 void constraintsEvent(Plasma::Constraints constraints);
00144
00145 protected slots:
00149 void addAccepted();
00150
00154 void configAccepted();
00155
00156 private slots:
00157 void refactorUi();
00158 void showDialog();
00159 void removeCurrentIcon();
00160
00161 private:
00162 void init();
00163
00169 void addProgram(int index, const QString &desktopFile);
00170
00175 void loadPrograms(const QStringList &desktopFiles);
00176
00181 void clearLayout(QGraphicsLayout *layout);
00182
00186 void saveConfig() {}
00187
00188 bool dropHandler(const int pos, const QMimeData *mimedata);
00189
00190 QGraphicsLinearLayout *m_layout;
00191 QuicklaunchLayout *m_innerLayout;
00192 QList<QuicklaunchIcon*> m_icons;
00193 Plasma::IconWidget *m_arrow;
00194 int m_visibleIcons;
00195 int m_rowCount;
00196 int m_dialogRowCount;
00197 Plasma::Dialog *m_dialog;
00198 QGraphicsWidget * m_dialogWidget;
00199 QuicklaunchLayout *m_dialogLayout;
00200 KDialog *m_addDialog;
00201 Ui::quicklaunchConfig uiConfig;
00202 Ui::quicklaunchAdd addUi;
00203 QuicklaunchIcon *m_rightClickedIcon;
00204 QPointF m_mousePressPos;
00205
00206 QAction* m_addAction;
00207 QAction* m_removeAction;
00208 };
00209
00210 #endif