Code formatting/indentation unified in trunk
[qtrapids] / src / plugins / PluginInterface.h
1 /***************************************************************************
2  *   Copyright (C) 2009 by Lassi Väätämöinen   *
3  *   lassi.vaatamoinen@ixonos.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  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20 #ifndef PLUGININTERFACE_H
21 #define PLUGININTERFACE_H
22
23 #include <QObject>
24 #include <QPluginLoader>
25
26 namespace qtrapids
27 {
28
29 /** @class PluginHostInterface
30         * @brief Defines interface for plugins to access the host application.
31         * A Host is an application that is extended by implementing Plugins,
32         * that implement the additional functionality
33 */
34 class PluginHostInterface : public QObject
35 {
36 public:
37
38     /// @brief Sets the plugin GUI element to host application
39     /// @note It is up to the host application to decide how to manage
40     /// and show the actual widget.
41     virtual bool setGui(QWidget* widget) = 0;
42
43     /// @brief Adds additional plugin wigdets to the host application.
44     /// This functio can be called by the plugin recursively, i.e. when GUI events occur
45     /// The host application must handle placing the additional widgets.
46     /// @todo Could we implement this using in a more manageable way, e.g. signal-slot?
47     virtual void addPluginWidget(QWidget* widget) = 0;
48     virtual void addToolbar() = 0;
49     virtual void addToolItem() = 0;
50     virtual void addMenu() = 0;
51     virtual void addMenuItem() = 0;
52 };
53
54
55 /** @class PluginInterface
56         * @brief Defines interface for a plugin instance.
57         * The host application uses PluginInterface interface for calling the plugins
58         * that extend the Host functionality
59 */
60 class PluginInterface : public QObject
61 {
62 public:
63     /// @brief Initializes the plugin instance.
64     virtual void initialize(PluginHostInterface* host) = 0;
65     virtual QWidget* getGui() = 0;
66 };
67
68 } //namespace qtrapids
69
70
71 // Declare the interfaces for the Qt framework.
72 Q_DECLARE_INTERFACE(qtrapids::PluginInterface,
73                     "com.ixonos.qtrapids.PluginInterface/1.0")
74 Q_DECLARE_INTERFACE(qtrapids::PluginHostInterface,
75                     "com.ixonos.qtrapids.PluginHostInterface/1.0")
76
77
78 //////////////// EXAMPLE PLUGIN DECLARATION /////////////////////////
79 // A simple plugin example using the PluginInterface
80 // For more info, see Qt documentation: "How to Create Qt Plugins"
81 //
82 // namespace qtrapids
83 // {
84 //
85 //      class MyPlugin : public PluginInterface {
86 //              Q_OBJECT
87 //              // NOTE: This macro tells Qt which interfaces the plugin implements (i.e. inherits):
88 //              Q_INTERFACES(qtrapids::PluginInterface)
89 //
90 //              public:
91 //                      MyPlugin();
92 //                      virtual void initialize(PluginHostInterface* host);
93 //                      virtual QWidget* getGui();
94 //
95 // // Additional plugin-specific signals and slots.
96 //              signals:
97 //                      void searchResult(QWidget* resultwidget);
98 //
99 //              private slots:
100 //                      void on_button_clicked();
101 //                      void on_result(QWidget* resultWidget);
102 //
103 //              private:
104 //      };
105 //
106 //
107 //      MyPlugin::MyPlugin(): host_(NULL) {}
108 //
109 //              void SearchPlugin::initialize(AbstractPluginHost* host)
110 //              {
111 //                      host_ = host;
112 //
113 //                      if (host_ != NULL) {
114 //                              QWidget *pluginWidget = new QWidget;
115 //                              QVBoxLayout *vbox = new QVBoxLayout;
116 //                              QPushButton *searchButton = new QPushButton("Search");
117 //                              vbox->addWidget(searchButton);
118 //                              pluginWidget->setLayout(vbox);
119 //
120 //                              connect(searchButton, SIGNAL(clicked()), this, SLOT(on_searchButton_clicked()));
121 //                              //connect(this, SIGNAL(searchResult(QWidget*)), this, SLOT(on_searchResult(QWidget*)));
122 //
123 //                              // Call host interface function to set the plugin GUI. Host handles the setup
124 //                              // to it's own policy
125 //                              host_->setGui(pluginWidget);
126 //                      }
127 //              }
128 // } // namespace qtrapids
129 //
130 //// NOTE: Remember to export the actual plugin to be visible for Qt:
131 //// Q_EXPORT_PLUGIN2(myplugin, qtrapids::MyPlugin)
132 //
133 ///////////////// END OF EXAMPLE PLUGIN ///////////////////////////////
134
135 #endif