ColorPlugin.hh 7.81 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
#pragma once
Jan Möbius's avatar
 
Jan Möbius committed
43 44 45 46 47 48 49

#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"
50 51
#include "OpenFlipper/BasePlugin/OptionsInterface.hh"
#include "OpenFlipper/BasePlugin/INIInterface.hh"
Jan Möbius's avatar
 
Jan Möbius committed
52

53 54 55 56 57 58 59 60
#include <QObject>
#include <QMenuBar>
#include "ColorPlugin.hh"

#include "ColorOptions.hh"

#include "OpenFlipper/INIFile/INIFile.hh"

61
class ColorPlugin : public QObject, BaseInterface, MenuInterface, ScriptInterface, ToolbarInterface, StatusbarInterface, OptionsInterface, INIInterface
Jan Möbius's avatar
 
Jan Möbius committed
62
{
Jan Möbius's avatar
Jan Möbius committed
63 64 65 66 67 68 69 70 71 72
  
  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
73

Matthias Möller's avatar
Matthias Möller committed
74 75
  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-Color")

Jan Möbius's avatar
Jan Möbius committed
76
  signals:
77
    // BaseInterface
Jan Möbius's avatar
 
Jan Möbius committed
78
    void updateView();
Jan Möbius's avatar
 
Jan Möbius committed
79

80
    // ScriptInterface
Jan Möbius's avatar
Jan Möbius committed
81
    void scriptInfo( QString _functionName );
Jan Möbius's avatar
 
Jan Möbius committed
82

83
    // MenuInterface
84
    void addMenubarAction(QAction* _action, QString _type );
Jan Möbius's avatar
 
Jan Möbius committed
85

86
    // ToolbarInterface
Jan Möbius's avatar
Jan Möbius committed
87 88
    void addToolbar(QToolBar* _toolbar);
    void removeToolbar(QToolBar* _toolbar);
Jan Möbius's avatar
 
Jan Möbius committed
89

90
    // StatusbarInterface
Jan Möbius's avatar
Jan Möbius committed
91 92
    void showStatusMessage(QString _message, int _timeout = 0);

Jan Möbius's avatar
 
Jan Möbius committed
93
  private slots:
Jan Möbius's avatar
Jan Möbius committed
94

95
    // BaseInterface
Jan Möbius's avatar
Jan Möbius committed
96 97
    void pluginsInitialized();

98 99 100 101 102 103 104
    // OptionsInterface
    void applyOptions();

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

Jan Möbius's avatar
Jan Möbius committed
105
  public :
Jan Möbius's avatar
 
Jan Möbius committed
106

107 108
    // OptionsInterface
    bool initializeOptionsWidget(QWidget*& _widget);
Jan Möbius's avatar
Jan Möbius committed
109

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

Matthias Möller's avatar
Matthias Möller committed
114
    /// ConstructorOptionsInterface
115 116 117 118 119 120 121 122 123 124 125 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
    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
158 159 160
  //===========================================================================
  /** @name Scriptable functions to set colors
    * @{ */
Jan Möbius's avatar
 
Jan Möbius committed
161 162
  //===========================================================================

Jan Möbius's avatar
Jan Möbius committed
163 164 165 166 167
  public slots:
    /**
     * Applies Default colors to the whole scene
     */
    void setDefaultColor();
Jan Möbius's avatar
 
Jan Möbius committed
168

Jan Möbius's avatar
Jan Möbius committed
169 170 171
    /**
     * Applies colors for presentations to the scene
     */
172
    void setPresentationColor();
Jan Möbius's avatar
 
Jan Möbius committed
173

Jan Möbius's avatar
Jan Möbius committed
174 175 176 177 178 179 180 181 182 183
    /**
     * Applies colors for papers
     */
    void setPaperColor();

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

184 185
    /**
     * Sets the emissive color of an object
186 187 188
     */
    void setObjectEmissiveColor(int _objectId , Vector4 _color);

189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
    /**
     * 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);

204 205
  /** @} */

Jan Möbius's avatar
Jan Möbius committed
206 207 208
  //===========================================================================
  /** @name Other scriptable functions
   * @{ */
Jan Möbius's avatar
 
Jan Möbius committed
209 210
  //===========================================================================

Jan Möbius's avatar
Jan Möbius committed
211
  public slots:
Jan Möbius's avatar
 
Jan Möbius committed
212

Jan Möbius's avatar
Jan Möbius committed
213 214 215 216
    /**
     * Version info of the color plugin
     */
    QString version() { return QString("1.0"); };
Jan Möbius's avatar
 
Jan Möbius committed
217

Jan Möbius's avatar
Jan Möbius committed
218
  /** @} */
Jan Möbius's avatar
 
Jan Möbius committed
219 220
};

221