1/*
2 * Copyright 2008 by Marco Martin <notmart@gmail.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as
6 * published by the Free Software Foundation; either version 2, or
7 * (at your option) any later version.
8
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20#ifndef PLASMA_ABSTRACTTOOLBOX_H
21#define PLASMA_ABSTRACTTOOLBOX_H
22
23#include <QGraphicsWidget>
24#include <QGraphicsItem>
25
26#include <kplugininfo.h>
27
28#include "plasma/plasma_export.h"
29
30class QAction;
31
32class KConfigGroup;
33
34namespace Plasma
35{
36
37class AbstractToolBoxPrivate;
38class Containment;
39
40class PLASMA_EXPORT AbstractToolBox : public QGraphicsWidget
41{
42 Q_OBJECT
43 Q_INTERFACES(QGraphicsItem)
44 Q_PROPERTY(bool showing READ isShowing WRITE setShowing)
45
46public:
47 enum ToolType {
48 AddTool = 0,
49 ConfigureTool = 100,
50 ControlTool = 200,
51 MiscTool = 300,
52 DestructiveTool = 400,
53 UserToolType = DestructiveTool + 1000
54 };
55 Q_ENUMS(ToolType)
56
57 explicit AbstractToolBox(Containment *parent);
58 explicit AbstractToolBox(QObject *parent = 0,
59 const QVariantList &args = QVariantList());
60 ~AbstractToolBox();
61
62 /**
63 * Create a new AbstractToolBox, loading the proper plugin
64 * @param name the plugin name
65 * @param args the plugin arguments
66 * @param containment the containment parent of the toolbox
67 * @since 4.6
68 */
69 static AbstractToolBox *load(const QString &name, const QVariantList &args=QVariantList(), Plasma::Containment *containment=0);
70
71 /**
72 * Returns a list of all installed ToolBox plugins
73 *
74 * @param parentApp the application to filter applets on. Uses the
75 * X-KDE-ParentApp entry (if any) in the plugin info.
76 * The default value of QString() will result in a
77 * list containing only applets not specifically
78 * registered to an application.
79 *
80 * @since 4.6
81 */
82 static KPluginInfo::List listToolBoxInfo(const QString
83 &parentApp = QString());
84
85 /**
86 * create a toolbox tool from the given action
87 * @p action the action to associate the tool with
88 */
89 virtual void addTool(QAction *action) = 0;
90
91 /**
92 * remove the tool associated with this action
93 */
94 virtual void removeTool(QAction *action) = 0;
95
96 /**
97 * @return true if the ToolBox is open and shown the actions list
98 */
99 virtual bool isShowing() const = 0;
100
101 /**
102 * Opens or closes the ToolBox
103 */
104 virtual void setShowing(const bool show) = 0;
105
106public Q_SLOTS:
107 //FIXME for KDE5: those should become virtuals
108 /**
109 * Restore the ToolBox settings
110 * It has to be reimplemented in toolboxes that need it
111 * @since 4.6
112 */
113 void restore(const KConfigGroup &group);
114
115 /**
116 * Save the ToolBox settings
117 * It has to be reimplemented in toolboxes that need it
118 * @since 4.6
119 */
120 void save(const KConfigGroup &group);
121
122 /**
123 * Inform the ToolBox it has to reposition itlself
124 * It has to be reimplemented in toolboxes that need it
125 * @since 4.6
126 */
127 void reposition();
128
129Q_SIGNALS:
130 /**
131 * Toolbox opened or closed
132 */
133 void toggled();
134
135 /**
136 * Toolbox opened or closed
137 * @param open tells if the toolbox opened or closed
138 */
139 void visibilityChanged(bool open);
140
141protected:
142 Containment *containment() const;
143
144private:
145 AbstractToolBoxPrivate * const d;
146
147};
148
149} // Plasma namespace
150
151/**
152 * Register an applet when it is contained in a loadable module
153 */
154#define K_EXPORT_PLASMA_TOOLBOX(libname, classname) \
155K_PLUGIN_FACTORY(factory, registerPlugin<classname>();) \
156K_EXPORT_PLUGIN(factory("plasma_toolbox_" #libname)) \
157K_EXPORT_PLUGIN_VERSION(PLASMA_VERSION)
158
159#endif // multiple inclusion guard
160
161