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
73signals:
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
82public slots:
83
84 void slotMouseEvent(QMouseEvent* _event);
85
86 void slotPickModeChanged(const std::string& _mode);
87
88 void slotKeyEvent (QKeyEvent* _event);
89
90public:
91
94
95 QString name(){return QString("MaterialPicker");}
96 QString description(){return QString("Pick to store and set materials.");}
97
98private:
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
122 QIcon* toolIcon_;
123
124 QVector<MaterialInfo> materialList_;
125 QStringList materialStrings_;//hold materials as a String (saves/load the material at the beginning)
126
127 //key = hotKey, value = index for lists
128 std::map<int,size_t> shortKeyRow_;
129
130 ptr::shared_ptr<MaterialNode> materialNode_;
131
136
137private:
139 QString itemName(const QString &_name, int _key);
140
142 QString plainName(const QString &string, int index);
143
144private slots:
145
146 void initializePlugin();
147
148 void pluginsInitialized();
149
150 void slotPickMaterialMode();
151
152 void slotFillMaterialMode();
153
154 void slotRemoveCurrentItem();
155
157 void editMode(QListWidgetItem* _item);
158
159 void editModeCurrent();
160
162 void saveNewName ( QWidget * _editor, QAbstractItemDelegate::EndEditHint _hint );
163 void saveNewName (QListWidgetItem* _item);
164
166 QString materialString(const MaterialInfo& _mat, const QString &_name);
167
168 void clearList();
169
170 void removeItem(QListWidgetItem* _item);
171
173 void createContextMenu(const QPoint& _point);
174
176 void changeHotKey(const int _key);
177
178 void slotMaterialProperties();
179
180 void slotEnableListWidget(int _save);
181
182 void slotMaterialChanged();
183
184public slots:
185 QString version(){ return QString("1.0"); }
186};
187
188
189#endif //MATERIALPICKER_HH
Interface class from which all plugins have to be created.
Keyboard Event Interface.
Definition: KeyInterface.hh:59
bool fillMaterial_
stores the state of the fill material button
bool pickMaterial_
stores the state of the pick material button
QString materialString(const MaterialInfo &_mat, const QString &_name)
returns a formatted string for saving
QString description()
Return a description of what the plugin is doing.
void saveNewName(QWidget *_editor, QAbstractItemDelegate::EndEditHint _hint)
saves the new material name with hotkey hint
void changeHotKey(const int _key)
change specified HotKey to current item
QString name()
Return a name for the plugin.
void editMode(QListWidgetItem *_item)
items can be renamed by double clicking them
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
void createContextMenu(const QPoint &_point)
creates context menu on current item (current is the item at mouse position)
Interface class for receiving mouse events.
Allow access to picking functions.
Plugins can add its own toolbox to the main widget's toolbox area by using this interface.