Developer Documentation
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 #ifndef MATERIALPICKER_HH
45 #define MATERIALPICKER_HH
46 
47 #include <QObject>
48 #include <QString>
49 #include <QPushButton>
50 #include <QListWidget>
51 
57 
59 #include <ACG/Utils/SmartPointer.hh>
60 
61 
63 {
64  Q_OBJECT
65  Q_INTERFACES(BaseInterface)
66  Q_INTERFACES(MouseInterface)
67  Q_INTERFACES(PickingInterface)
68  Q_INTERFACES(ToolboxInterface)
69  Q_INTERFACES(KeyInterface)
70 
71  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-MaterialPicker")
72 
73 signals:
74  void addPickMode(const std::string &_mode);
75 
76  void updateView();
77 
78  void addToolbox( QString _name , QWidget* _widget, QIcon* _icon);
79 
80  void registerKey(int _key, Qt::KeyboardModifiers _modifiers, QString _description, bool _multiUse = false);
81 
82 public slots:
83 
84  void slotMouseEvent(QMouseEvent* _event);
85 
86  void slotPickModeChanged(const std::string& _mode);
87 
88  void slotKeyEvent (QKeyEvent* _event);
89 
90 public:
91 
93  ~MaterialPicker();
94 
95  QString name(){return QString("MaterialPicker");}
96  QString description(){return QString("Pick to store and set materials.");}
97 
98 private:
99 
101  {
102  bool color_material;
103  ACG::Vec4f base_color;
104  ACG::Vec4f ambient_color;
105  ACG::Vec4f diffuse_color;
106  ACG::Vec4f specular_color;
107  float shininess;
108  double reflectance;
109  int key;
110  };
111 
112  const std::string pickModeName_;
113  const QString propName_;
114  static const unsigned supportedKeys_ = 3;
115 
116  QPushButton* pickMaterialButton_;
117  QPushButton* fillMaterialButton_;
118 
119  //all these lists are synchronized:
120  QListWidget* materialListWidget_;
121  QVector<MaterialInfo> materialList_;
122  QStringList materialStrings_;//hold materials as a String (saves/load the material at the beginning)
123 
124  //key = hotKey, value = index for lists
125  std::map<int,size_t> shortKeyRow_;
126 
127  ptr::shared_ptr<MaterialNode> materialNode_;
128 
133 
134 private:
136  QString itemName(const QString &_name, int _key);
137 
139  QString plainName(const QString &string, int index);
140 
141 private slots:
142 
143  void initializePlugin();
144 
145  void pluginsInitialized();
146 
147  void slotPickMaterialMode();
148 
149  void slotFillMaterialMode();
150 
151  void slotRemoveCurrentItem();
152 
154  void editMode(QListWidgetItem* _item);
155 
156  void editModeCurrent();
157 
159  void saveNewName ( QWidget * _editor, QAbstractItemDelegate::EndEditHint _hint );
160  void saveNewName (QListWidgetItem* _item);
161 
163  QString materialString(const MaterialInfo& _mat, const QString &_name);
164 
165  void clearList();
166 
167  void removeItem(QListWidgetItem* _item);
168 
170  void createContextMenu(const QPoint& _point);
171 
173  void changeHotKey(const int _key);
174 
175  void slotMaterialProperties();
176 
177  void slotEnableListWidget(int _save);
178 
179  void slotMaterialChanged();
180 
181 public slots:
182  QString version(){ return QString("1.0"); }
183 };
184 
185 
186 #endif //MATERIALPICKER_HH
void editMode(QListWidgetItem *_item)
items can be renamed by double clicking them
Interface class for receiving mouse events.
Plugins can add its own toolbox to the main widget&#39;s toolbox area by using this interface.
QString name()
Return a name for the plugin.
bool fillMaterial_
stores the state of the fill material button
void saveNewName(QWidget *_editor, QAbstractItemDelegate::EndEditHint _hint)
saves the new material name with hotkey hint
QString materialString(const MaterialInfo &_mat, const QString &_name)
returns a formatted string for saving
void createContextMenu(const QPoint &_point)
creates context menu on current item (current is the item at mouse position)
bool pickMaterial_
stores the state of the pick material button
Keyboard Event Interface.
Definition: KeyInterface.hh:59
QString description()
Return a description of what the plugin is doing.
QString itemName(const QString &_name, int _key)
returns the item name with hotkey hint
QString plainName(const QString &string, int index)
returns the plain name of the material without hotkey hint
Interface class from which all plugins have to be created.
Allow access to picking functions.
void changeHotKey(const int _key)
change specified HotKey to current item