ColorPlugin.hh 8.38 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2 3
*                                                                            *
*                              OpenFlipper                                   *
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

50 51 52 53 54 55 56 57 58
#ifndef COLORPLUGIN_HH
#define COLORPLUGIN_HH

#include <OpenFlipper/common/Types.hh>
#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/MenuInterface.hh>
#include <OpenFlipper/BasePlugin/ScriptInterface.hh>
#include <OpenFlipper/BasePlugin/ToolbarInterface.hh>
#include "OpenFlipper/BasePlugin/StatusbarInterface.hh"
59 60
#include "OpenFlipper/BasePlugin/OptionsInterface.hh"
#include "OpenFlipper/BasePlugin/INIInterface.hh"
61

62 63 64 65 66 67 68 69
#include <QObject>
#include <QMenuBar>
#include "ColorPlugin.hh"

#include "ColorOptions.hh"

#include "OpenFlipper/INIFile/INIFile.hh"

70
class ColorPlugin : public QObject, BaseInterface, MenuInterface, ScriptInterface, ToolbarInterface, StatusbarInterface, OptionsInterface, INIInterface
71
{
Jan Möbius's avatar
Jan Möbius committed
72 73 74 75 76 77 78 79 80 81
  
  Q_OBJECT

  Q_INTERFACES(BaseInterface)
  Q_INTERFACES(MenuInterface)
  Q_INTERFACES(ScriptInterface)
  Q_INTERFACES(ToolbarInterface)
  Q_INTERFACES(StatusbarInterface)
  Q_INTERFACES(OptionsInterface)
  Q_INTERFACES(INIInterface)
Jan Möbius's avatar
Jan Möbius committed
82

83 84 85 86
#if QT_VERSION >= 0x050000
  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-Color")
#endif

Jan Möbius's avatar
Jan Möbius committed
87
  signals:
88
    // BaseInterface
89
    void updateView();
90

91
    // ScriptInterface
Jan Möbius's avatar
Jan Möbius committed
92
    void scriptInfo( QString _functionName );
93

94
    // MenuInterface
95
    void addMenubarAction(QAction* _action, QString _type );
96

97
    // ToolbarInterface
Jan Möbius's avatar
Jan Möbius committed
98 99
    void addToolbar(QToolBar* _toolbar);
    void removeToolbar(QToolBar* _toolbar);
100

101
    // StatusbarInterface
Jan Möbius's avatar
Jan Möbius committed
102 103
    void showStatusMessage(QString _message, int _timeout = 0);

104
  private slots:
Jan Möbius's avatar
Jan Möbius committed
105

106
    // BaseInterface
Jan Möbius's avatar
Jan Möbius committed
107 108
    void pluginsInitialized();

109 110 111 112 113 114 115
    // OptionsInterface
    void applyOptions();

    // INIInterface
    void loadIniFileOptions(INIFile& _ini);
    void saveIniFileOptions(INIFile& _ini);

Jan Möbius's avatar
Jan Möbius committed
116
  public :
117

118 119
    // OptionsInterface
    bool initializeOptionsWidget(QWidget*& _widget);
Jan Möbius's avatar
Jan Möbius committed
120

121
    // BaseInterface
Jan Möbius's avatar
Jan Möbius committed
122
    QString name() { return (QString("Color Plugin")); };
Jan Möbius's avatar
Jan Möbius committed
123
    QString description( ) { return (tr("Sets the Default colors e.g. for slides, paper,... snapshots")); };
Jan Möbius's avatar
Jan Möbius committed
124

Matthias Möller's avatar
Matthias Möller committed
125
    /// ConstructorOptionsInterface
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
    ColorPlugin();


  //===========================================================================
  /** @name Show Colors in Options and Store them in INI files
    * @{ */
  //===========================================================================

  private:
    /// the options widget to set colors
    ColorOptions* optionsWidget_;

    /// generate an icon from a given color
    QIcon generateIcon(QRgb _color);

    /// generate an icon from a given color
    QIcon generateIcon(OpenMesh::Vec4f _color);

    /// get the color from a given icon
    QRgb getIconColor(QIcon _icon);

    /// set the color of a color vector to the one in the given icon
    void setNewColor(QIcon _icon, OpenMesh::Vec4f& _color);

    /// convert betweeen uint and Vec4f
    void convertColor(uint _color, OpenMesh::Vec4f& _vector);

    /// convert betweeen uint and Vec4f
    uint convertColor(OpenMesh::Vec4f& _vector);

    //internal storage of colors
    OpenMesh::Vec4f backgroundColorDefault_, backgroundColorPaper_, backgroundColorPresentation_;
    OpenMesh::Vec4f baseColorDefault_, baseColorPaper_, baseColorPresentation_;
    OpenMesh::Vec4f materialColorDefault_, materialColorPaper_, materialColorPresentation_;

    double lineWidthDefault_, lineWidthPaper_, lineWidthPresentation_;

  private slots:
    /// display a color dialog
    void getColorDialog();

  /** @} */

Jan Möbius's avatar
Jan Möbius committed
169 170 171
  //===========================================================================
  /** @name Scriptable functions to set colors
    * @{ */
172 173
  //===========================================================================

Jan Möbius's avatar
Jan Möbius committed
174 175 176 177 178
  public slots:
    /**
     * Applies Default colors to the whole scene
     */
    void setDefaultColor();
179

Jan Möbius's avatar
Jan Möbius committed
180 181 182
    /**
     * Applies colors for presentations to the scene
     */
183
    void setPresentationColor();
184

Jan Möbius's avatar
Jan Möbius committed
185 186 187 188 189 190 191 192 193 194
    /**
     * Applies colors for papers
     */
    void setPaperColor();

    /**
     * Sets the background color of the scene
    */
    void setBackgroundColor( Vector _color );

195 196
    /**
     * Sets the emissive color of an object
197 198 199
     */
    void setObjectEmissiveColor(int _objectId , Vector4 _color);

200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
    /**
     * Sets the ambient color of an object
     */
    void setObjectAmbientColor(int _objectId , Vector4 _color);

    /**
     * Sets the diffuse color of an object
     */
    void setObjectDiffuseColor(int _objectId , Vector4 _color);

    /**
     * Sets the specular color of an object
     */
    void setObjectSpecularColor(int _objectId , Vector4 _color);

215 216
  /** @} */

Jan Möbius's avatar
Jan Möbius committed
217 218 219
  //===========================================================================
  /** @name Other scriptable functions
   * @{ */
220 221
  //===========================================================================

Jan Möbius's avatar
Jan Möbius committed
222
  public slots:
223

Jan Möbius's avatar
Jan Möbius committed
224 225 226 227
    /**
     * Version info of the color plugin
     */
    QString version() { return QString("1.0"); };
228

Jan Möbius's avatar
Jan Möbius committed
229
  /** @} */
230 231 232
};

#endif //COLORPLUGIN_HH