ToolboxInterface.hh 7.88 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2 3
*                                                                            *
*                              OpenFlipper                                   *
Martin Schultz's avatar
Martin Schultz committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
Jan Möbius's avatar
Jan Möbius committed
39
*                                                                            *
40 41 42
\*===========================================================================*/

/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
43 44 45 46 47
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
48
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
49

Jan Möbius's avatar
Jan Möbius committed
50 51
#ifndef TOOLBOXINTERFACE_HH
#define TOOLBOXINTERFACE_HH
Jan Möbius's avatar
 
Jan Möbius committed
52

Matthias Möller's avatar
Matthias Möller committed
53
#include <OpenFlipper/common/Types.hh>
Matthias Möller's avatar
Matthias Möller committed
54 55 56 57 58 59
#if QT_VERSION >= 0x050000 
  #include <QtWidgets>
#else
  #include <QtGui>
#endif

Jan Möbius's avatar
Jan Möbius committed
60 61
#include <QMenuBar>
#include <QStringList>
Matthias Möller's avatar
Matthias Möller committed
62

Jan Möbius's avatar
 
Jan Möbius committed
63

Jan Möbius's avatar
Jan Möbius committed
64 65 66 67
/** \file ToolboxInterface.hh
*
* Interface for adding per plugin toolboxes to OpenFlippers UI.\ref toolboxInterfacePage
*/
Jan Möbius's avatar
 
Jan Möbius committed
68

Jan Möbius's avatar
Jan Möbius committed
69

Jan Möbius's avatar
 
Jan Möbius committed
70
 /**
Mike Kremer's avatar
Mike Kremer committed
71
  * \brief Plugins can add its own toolbox to the main widget's toolbox area by using this interface.
72
  *
Jan Möbius's avatar
Jan Möbius committed
73 74 75 76
  * \ref toolboxInterfacePage "Detailed description" 
  * \n
  *
  * This Interface can be used by plugins which will provide a toolbox widget.
Jan Möbius's avatar
Jan Möbius committed
77
  * Each Plugin can create own Widgets in the toolbox area. Just create your widget and then add it with \n
Jan Möbius's avatar
Jan Möbius committed
78
  * emit addToolbox( QString  _name  , QWidget* _widget ) \n
Jan Möbius's avatar
Jan Möbius committed
79 80
  * to the user interface. You can create extra signals and slots in your Plugin.
  * These can be connected between your toolbox and your plugin.\n
81 82 83
  *
  * See our tutorials \ref ex2 and \ref ex3 for an example of to add custom toolboxes to
  * OpenFlipper.
Mike Kremer's avatar
Mike Kremer committed
84
  */
Jan Möbius's avatar
 
Jan Möbius committed
85 86 87 88 89 90 91 92 93 94
class ToolboxInterface {

   private slots :

   public :

      /// Destructor
      virtual ~ToolboxInterface() {};

    signals :
Dirk Wilden's avatar
Dirk Wilden committed
95

96 97
      /** \brief Add a toolbox widget to the gui with the given name
       *
Jan Möbius's avatar
Jan Möbius committed
98
       * This signal adds a toolbox widget to the toolbox area on the right.
Jan Möbius's avatar
Jan Möbius committed
99 100 101
       *
       * @param _name   Visible name of the toolbox
       * @param _widget Pointer to the toolbox widget
102
       */
Jan Möbius's avatar
Jan Möbius committed
103
      virtual void addToolbox( QString  _name  , QWidget* _widget ) {};
104

Jan Möbius's avatar
Jan Möbius committed
105
      /** \brief Add a toolbox widget to the gui with the given name and an icon
Dirk Wilden's avatar
Dirk Wilden committed
106
       *
Jan Möbius's avatar
Jan Möbius committed
107
       * This signal adds a toolbox widget to the toolbox area on the right. And sets an icon for it
Jan Möbius's avatar
Jan Möbius committed
108 109 110 111
       *
       * @param _name   Visible name of the toolbox
       * @param _widget Pointer to the toolbox widget
       * @param _icon   Icon for the toolbox
Dirk Wilden's avatar
Dirk Wilden committed
112
       */
Jan Möbius's avatar
Jan Möbius committed
113
      virtual void addToolbox( QString  _name  , QWidget* _widget, QIcon* _icon) {};
114 115 116 117 118 119 120 121 122 123 124 125

      /** \brief Add a toolbox widget to the gui with the given name, icon and header area widget.
       *
       * This signal adds a toolbox widget to the toolbox area on the right. And sets an icon for it
       *
       * @param _name   Visible name of the toolbox
       * @param _widget Pointer to the toolbox widget
       * @param _icon   Icon for the toolbox
       * @param _headerAreaWidget Widget displayed in the toolbox header between
       *   the title and the detach button.
       */
      virtual void addToolbox( QString  _name  , QWidget* _widget, QIcon* _icon, QWidget* _headerAreaWidget) {};
Jan Möbius's avatar
 
Jan Möbius committed
126 127
};

128 129 130 131 132 133


/** \page toolboxInterfacePage Toolbox Interface
\image html ToolboxInterface.png

The ToolboxInterface can be used by plugins to add widgets to the list of toolboxes in OpenFlippers
Jan Möbius's avatar
Jan Möbius committed
134
UI. The toolboxes are located left or right of the GL viewer (See image).
135 136 137 138 139 140 141 142 143 144 145

The list can be hidden by pressing Ctrl + t.

To use the ToolboxInterface:
<ul>
<li> include ToolboxInterface.hh in your plugins header file
<li> derive your plugin from the class ToolboxInterface
<li> add Q_INTERFACES(ToolboxInterface) to your plugin class 
<li> And add the signals or slots you want to use to your plugin class (You don't need to implement all of them)
</ul>

146
Usually you should implement the BaseInterface::pluginsInitialized() function from BaseInterface. In this function you can setup
Jan Möbius's avatar
Jan Möbius committed
147
your toolbox ( some kind of QWidget, can also be any widget created with QT-designer). Optionally you can also
148 149 150 151
add an icon to the toolbox. 

The following code shows a simple example to create an empty toolbox.
\code 
Jan Möbius's avatar
Jan Möbius committed
152
void ExamplePlugin::pluginsInitialized()
153 154 155 156 157
{
  // Create the Toolbox Widget
  QWidget* toolBox = new QWidget();
  
  // Create an icon which is shown along with the toolbox
Jan Möbius's avatar
Jan Möbius committed
158
  QIcon* toolIcon = new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"exampleIcon.png");
159 160
  
  // Tell the core to include the new toolbox widget with the name Simple Smoother, a pointer to the widget and a pointer to the icon
Jan Möbius's avatar
Jan Möbius committed
161
  emit addToolbox( tr("Example Plugin Toolbox") , toolBox, toolIcon );
162 163 164 165 166 167 168 169
}
\endcode

Signals and slots of your toolbox (e.g. from a QPushButton inside it) can be directly connected to signals and slots in
your plugin. Therefore the embedding of the widget into the toolbox list is fully transparent.

*/

170
Q_DECLARE_INTERFACE(ToolboxInterface,"OpenFlipper.ToolboxInterface/1.1")
Jan Möbius's avatar
 
Jan Möbius committed
171 172

#endif // TOOLBOXINTERFACE_HH