Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
MaterialPicker.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43 * *
44 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 #ifndef MATERIALPICKER_HH
51 #define MATERIALPICKER_HH
52 
53 #include <QObject>
54 #include <QString>
55 
61 
63 #include <ACG/Utils/SmartPointer.hh>
64 
65 
67 {
68  Q_OBJECT
69  Q_INTERFACES(BaseInterface)
70  Q_INTERFACES(MouseInterface)
71  Q_INTERFACES(PickingInterface)
72  Q_INTERFACES(ToolboxInterface)
73  Q_INTERFACES(KeyInterface)
74 
75 #if QT_VERSION >= 0x050000
76  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-MaterialPicker")
77 #endif
78 
79 signals:
80  void addPickMode(const std::string &_mode);
81 
82  void updateView();
83 
84  void addToolbox( QString _name , QWidget* _widget, QIcon* _icon);
85 
86  void registerKey(int _key, Qt::KeyboardModifiers _modifiers, QString _description, bool _multiUse = false);
87 
88 public slots:
89 
90  void slotMouseEvent(QMouseEvent* _event);
91 
92  void slotPickModeChanged(const std::string& _mode);
93 
94  void slotKeyEvent (QKeyEvent* _event);
95 
96 public:
97 
99  ~MaterialPicker();
100 
101  QString name(){return QString("MaterialPicker");}
102  QString description(){return QString("Pick to store and set materials.");}
103 
104 private:
105 
107  {
108  bool color_material;
109  ACG::Vec4f base_color;
110  ACG::Vec4f ambient_color;
111  ACG::Vec4f diffuse_color;
112  ACG::Vec4f specular_color;
113  float shininess;
114  double reflectance;
115  int key;
116  };
117 
118  const std::string pickModeName_;
119  const QString propName_;
120  static const unsigned supportedKeys_ = 3;
121 
122  QPushButton* pickMaterialButton_;
123  QPushButton* fillMaterialButton_;
124 
125  //all these lists are synchronized:
126  QListWidget* materialListWidget_;
127  QVector<MaterialInfo> materialList_;
128  QStringList materialStrings_;//hold materials as a String (saves/load the material at the beginning)
129 
130  //key = hotKey, value = index for lists
131  std::map<int,size_t> shortKeyRow_;
132 
133  ptr::shared_ptr<MaterialNode> materialNode_;
134 
139 
140 private:
142  QString itemName(const QString &_name, int _key);
143 
145  QString plainName(const QString &string, int index);
146 
147 private slots:
148 
149  void initializePlugin();
150 
151  void pluginsInitialized();
152 
153  void slotPickMaterialMode();
154 
155  void slotFillMaterialMode();
156 
157  void slotRemoveCurrentItem();
158 
160  void editMode(QListWidgetItem* _item);
161 
162  void editModeCurrent();
163 
165  void saveNewName ( QWidget * _editor, QAbstractItemDelegate::EndEditHint _hint );
166  void saveNewName (QListWidgetItem* _item);
167 
169  QString materialString(const MaterialInfo& _mat, const QString &_name);
170 
171  void clearList();
172 
173  void removeItem(QListWidgetItem* _item);
174 
176  void createContextMenu(const QPoint& _point);
177 
179  void changeHotKey(const int _key);
180 
181  void slotMaterialProperties();
182 
183  void slotEnableListWidget(int _save);
184 
185  void slotMaterialChanged();
186 
187 public slots:
188  QString version(){ return QString("1.0"); }
189 };
190 
191 
192 #endif //MATERIALPICKER_HH
Interface class from which all plugins have to be created.
void editMode(QListWidgetItem *_item)
items can be renamed by double clicking them
QString materialString(const MaterialInfo &_mat, const QString &_name)
returns a formatted string for saving
Keyboard Event Interface.
Definition: KeyInterface.hh:76
QString description()
Return a description of what the plugin is doing.
QString plainName(const QString &string, int index)
returns the plain name of the material without hotkey hint
bool fillMaterial_
stores the state of the fill material button
bool pickMaterial_
stores the state of the pick material button
QString itemName(const QString &_name, int _key)
returns the item name with hotkey hint
void changeHotKey(const int _key)
change specified HotKey to current item
Allow access to picking functions.
Interface class for receiving mouse events.
Plugins can add its own toolbox to the main widget's toolbox area by using this interface.
void saveNewName(QWidget *_editor, QAbstractItemDelegate::EndEditHint _hint)
saves the new material name with hotkey hint
QString name()
Return a name for the plugin.
void createContextMenu(const QPoint &_point)
creates context menu on current item (current is the item at mouse position)