MaterialPicker.hh 7.14 KB
Newer Older
Isaak Lim's avatar
Isaak Lim committed
1 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.              *
Isaak Lim's avatar
Isaak Lim committed
39 40 41 42 43
*                                                                            *
\*===========================================================================*/

/*===========================================================================*\
*                                                                            *
Jan Möbius's avatar
Jan Möbius committed
44 45 46
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
Isaak Lim's avatar
Isaak Lim committed
47 48 49 50 51 52 53 54
*                                                                            *
\*===========================================================================*/

#ifndef MATERIALPICKER_HH
#define MATERIALPICKER_HH

#include <QObject>
#include <QString>
55 56
#include <QPushButton>
#include <QListWidget>
Isaak Lim's avatar
Isaak Lim committed
57 58 59 60 61

#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/MouseInterface.hh>
#include <OpenFlipper/BasePlugin/PickingInterface.hh>
#include <OpenFlipper/BasePlugin/ToolboxInterface.hh>
62
#include <OpenFlipper/BasePlugin/KeyInterface.hh>
Isaak Lim's avatar
Isaak Lim committed
63 64

#include <OpenFlipper/common/Types.hh>
Matthias Möller's avatar
Matthias Möller committed
65
#include <ACG/Utils/SmartPointer.hh>
Isaak Lim's avatar
Isaak Lim committed
66 67


68
class MaterialPicker : public QObject, BaseInterface, MouseInterface, PickingInterface, ToolboxInterface, KeyInterface
Isaak Lim's avatar
Isaak Lim committed
69 70 71 72 73 74
{
  Q_OBJECT
  Q_INTERFACES(BaseInterface)
  Q_INTERFACES(MouseInterface)
  Q_INTERFACES(PickingInterface)
  Q_INTERFACES(ToolboxInterface)
75
  Q_INTERFACES(KeyInterface)
Isaak Lim's avatar
Isaak Lim committed
76

Matthias Möller's avatar
Matthias Möller committed
77 78
  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-MaterialPicker")

Isaak Lim's avatar
Isaak Lim committed
79 80 81 82 83
signals:
  void addPickMode(const std::string &_mode);

  void updateView();

Jan Möbius's avatar
Jan Möbius committed
84
  void addToolbox( QString  _name  , QWidget* _widget, QIcon* _icon);
Isaak Lim's avatar
Isaak Lim committed
85

86 87
  void registerKey(int _key, Qt::KeyboardModifiers _modifiers, QString _description, bool _multiUse = false);

Isaak Lim's avatar
Isaak Lim committed
88 89 90 91 92 93
public slots:

  void slotMouseEvent(QMouseEvent* _event);

  void slotPickModeChanged(const std::string& _mode);

94 95
  void slotKeyEvent (QKeyEvent* _event);

Isaak Lim's avatar
Isaak Lim committed
96 97 98 99 100 101 102 103 104 105
public:

  MaterialPicker();
  ~MaterialPicker();

  QString name(){return QString("MaterialPicker");}
  QString description(){return QString("Pick to store and set materials.");}

private:

106 107 108 109 110 111 112 113 114
  struct MaterialInfo
  {
     bool color_material;
     ACG::Vec4f base_color;
     ACG::Vec4f ambient_color;
     ACG::Vec4f diffuse_color;
     ACG::Vec4f specular_color;
     float shininess;
     double reflectance;
Matthias Möller's avatar
Matthias Möller committed
115
     int key;
116 117
  };

Isaak Lim's avatar
Isaak Lim committed
118
  const std::string pickModeName_;
119
  const QString propName_;
Matthias Möller's avatar
Matthias Möller committed
120
  static const unsigned supportedKeys_ = 3;
Isaak Lim's avatar
Isaak Lim committed
121 122 123 124

  QPushButton* pickMaterialButton_;
  QPushButton* fillMaterialButton_;

Matthias Möller's avatar
Matthias Möller committed
125 126
  //all these lists are synchronized:
  QListWidget* materialListWidget_;
Isaak Lim's avatar
Isaak Lim committed
127
  QVector<MaterialInfo> materialList_;
Matthias Möller's avatar
Matthias Möller committed
128 129 130
  QStringList materialStrings_;//hold materials as a String (saves/load the material at the beginning)

  //key = hotKey, value = index for lists
131
  std::map<int,size_t> shortKeyRow_;
Isaak Lim's avatar
Isaak Lim committed
132

Matthias Möller's avatar
Matthias Möller committed
133 134
  ptr::shared_ptr<MaterialNode> materialNode_;

Isaak Lim's avatar
Isaak Lim committed
135 136 137 138 139
  /// stores the state of the pick material button
  bool pickMaterial_;
  /// stores the state of the fill material button
  bool fillMaterial_;

Matthias Möller's avatar
Matthias Möller committed
140
private:
Matthias Möller's avatar
doc  
Matthias Möller committed
141
  /// returns the item name with hotkey hint
Matthias Möller's avatar
Matthias Möller committed
142 143
  QString itemName(const QString &_name, int _key);

Matthias Möller's avatar
doc  
Matthias Möller committed
144 145 146
  /// returns the plain name of the material without hotkey hint
  QString plainName(const QString &string, int index);

Isaak Lim's avatar
Isaak Lim committed
147 148 149 150 151 152 153 154 155 156
private slots:

  void initializePlugin();

  void pluginsInitialized();

  void slotPickMaterialMode();

  void slotFillMaterialMode();

157 158
  void slotRemoveCurrentItem();

Isaak Lim's avatar
Isaak Lim committed
159 160 161
  /// items can be renamed by double clicking them
  void editMode(QListWidgetItem* _item);

Matthias Möller's avatar
Matthias Möller committed
162 163 164 165 166 167 168 169
  void editModeCurrent();

  /// saves the new material name with hotkey hint
  void saveNewName ( QWidget * _editor, QAbstractItemDelegate::EndEditHint _hint );
  void saveNewName (QListWidgetItem* _item);

  /// returns a formatted string for saving
  QString materialString(const MaterialInfo& _mat, const QString &_name);
170

Isaak Lim's avatar
Isaak Lim committed
171 172
  void clearList();

173 174
  void removeItem(QListWidgetItem* _item);

Matthias Möller's avatar
Matthias Möller committed
175 176 177 178
  /// creates context menu on current item (current is the item at mouse position)
  void createContextMenu(const QPoint& _point);

  /// change specified HotKey to current item
179
  void changeHotKey(const int _key);
Matthias Möller's avatar
Matthias Möller committed
180 181 182 183 184

  void slotMaterialProperties();

  void slotEnableListWidget(int _save);

185
  void slotMaterialChanged();
Matthias Möller's avatar
Matthias Möller committed
186

Isaak Lim's avatar
Isaak Lim committed
187 188 189 190 191 192
public slots:
  QString version(){ return QString("1.0"); }
};


#endif //MATERIALPICKER_HH