Commit 38f4046d authored by Matthias Möller's avatar Matthias Möller

- add shortcuts for materials (ctrl+1/2/3)

NOTE: missing options for assigning materials to the buttons and missing visualization

refs #1148

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@15680 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 17ff7144
......@@ -51,7 +51,7 @@
MaterialPicker::MaterialPicker()
:
pickModeName_("MaterialPicker"),
propName_("MaterialPicker/Materials"),
propName_("MaterialPickerPlugin/Materials"),
pickMaterialButton_(0),
fillMaterialButton_(0),
materialListWidget_(0),
......@@ -84,7 +84,7 @@ void MaterialPicker::initializePlugin() {
materialListWidget_ = new QListWidget(toolBox);
//load saved materials
materialString_ = OpenFlipperSettings().value("MaterialPickerPlugin/Materials", QStringList()).toStringList();
materialString_ = OpenFlipperSettings().value(propName_, QStringList()).toStringList();
for (int i = 0; i < materialString_.size(); ++i)
{
......@@ -117,7 +117,16 @@ void MaterialPicker::initializePlugin() {
stream.clear();
stream << savedString[7].toStdString();
stream >> materialInfo.reflectance;
stream.str("");
stream.clear();
int key;
if (savedString.size() < 9)
savedString.push_back(QString::number(Qt::Key_unknown));
stream << savedString[8].toStdString();
stream >> key;
if (key != Qt::Key_unknown)
shortKeyRow_[key] = materialListWidget_->count();
materialListWidget_->addItem( savedString[0] );
materialList_.push_back(materialInfo);
......@@ -148,7 +157,7 @@ void MaterialPicker::initializePlugin() {
connect(fillMaterialButton_, SIGNAL(clicked()), this, SLOT(slotFillMaterialMode()));
connect(clearListButton, SIGNAL(clicked()), this, SLOT(clearList()));
connect(materialListWidget_, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(editMode(QListWidgetItem*)));
connect(materialListWidget_,SIGNAL(itemChanged ( QListWidgetItem*)), this, SLOT(assignNewName(QListWidgetItem*)));
connect(materialListWidget_,SIGNAL(itemChanged ( QListWidgetItem*)), this, SLOT(saveNewName(QListWidgetItem*)));
connect(removeItemButton, SIGNAL(clicked()), this, SLOT(slotRemoveCurrentItem()));
QIcon* toolIcon = new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"material_picker.png");
......@@ -211,6 +220,9 @@ void MaterialPicker::slotFillMaterialMode() {
void MaterialPicker::pluginsInitialized() {
emit addPickMode(pickModeName_);
emit registerKey (Qt::Key_1, Qt::ControlModifier, tr("Material 1"), false);
emit registerKey (Qt::Key_2, Qt::ControlModifier, tr("Material 2"), false);
emit registerKey (Qt::Key_3, Qt::ControlModifier, tr("Material 3"), false);
}
//------------------------------------------------------------------------------
......@@ -244,6 +256,13 @@ void MaterialPicker::slotMouseEvent(QMouseEvent* _event) {
materialInfo.shininess = material->shininess();
materialInfo.reflectance = material->reflectance();
int key = Qt::Key_unknown;
if (shortKeyRow_.size() < 3)
{
shortKeyRow_[Qt::Key_1+shortKeyRow_.size()] = materialListWidget_->count();
key = Qt::Key_1+shortKeyRow_.size();
}
// update list widget and material list
QString name = QString("material id: %1").arg(material->id());
materialListWidget_->addItem( name );
......@@ -261,6 +280,7 @@ void MaterialPicker::slotMouseEvent(QMouseEvent* _event) {
stream << ";" << materialInfo.specular_color;
stream << ";" << materialInfo.shininess;
stream << ";" << materialInfo.reflectance;
stream << ";" << key;
QString materialString = stream.str().c_str();
materialString_.push_back(materialString);
......@@ -301,12 +321,16 @@ void MaterialPicker::editMode(QListWidgetItem* _item) {
}
//------------------------------------------------------------------------------
void MaterialPicker::assignNewName(QListWidgetItem* _item)
void MaterialPicker::saveNewName(QListWidgetItem* _item)
{
unsigned index = materialListWidget_->row(_item);
QString str = materialString_[index];
QStringList strList = str.split(";");
//pass name
strList[0] = _item->text();
//create new String to save
str = "";
for (int i = 0; i < strList.size()-1; ++i)
str += strList[i] + ";";
......@@ -322,4 +346,28 @@ void MaterialPicker::slotPickModeChanged(const std::string& _mode) {
fillMaterialButton_->setChecked( _mode == pickModeName_ && fillMaterial_ );
}
void MaterialPicker::slotKeyEvent(QKeyEvent* _event)
{
if (_event->key() == Qt::Key_1 && _event->modifiers() == Qt::ControlModifier)
{
if (shortKeyRow_.find(Qt::Key_1) == shortKeyRow_.end())
return;
slotFillMaterialMode();
materialListWidget_->setCurrentRow(shortKeyRow_[Qt::Key_1]);
}
if (_event->key() == Qt::Key_2 && _event->modifiers() == Qt::ControlModifier)
{
if (shortKeyRow_.find(Qt::Key_2) == shortKeyRow_.end())
return;
slotFillMaterialMode();
materialListWidget_->setCurrentRow(shortKeyRow_[Qt::Key_2]);
}
if (_event->key() == Qt::Key_3 && _event->modifiers() == Qt::ControlModifier)
{
if (shortKeyRow_.find(Qt::Key_3) == shortKeyRow_.end())
return;
slotFillMaterialMode();
materialListWidget_->setCurrentRow(shortKeyRow_[Qt::Key_3]);
}
}
Q_EXPORT_PLUGIN2( materialPicker , MaterialPicker );
......@@ -50,27 +50,19 @@
#include <OpenFlipper/BasePlugin/MouseInterface.hh>
#include <OpenFlipper/BasePlugin/PickingInterface.hh>
#include <OpenFlipper/BasePlugin/ToolboxInterface.hh>
#include <OpenFlipper/BasePlugin/KeyInterface.hh>
#include <OpenFlipper/common/Types.hh>
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;
};
class MaterialPicker : public QObject, BaseInterface, MouseInterface, PickingInterface, ToolboxInterface
class MaterialPicker : public QObject, BaseInterface, MouseInterface, PickingInterface, ToolboxInterface, KeyInterface
{
Q_OBJECT
Q_INTERFACES(BaseInterface)
Q_INTERFACES(MouseInterface)
Q_INTERFACES(PickingInterface)
Q_INTERFACES(ToolboxInterface)
Q_INTERFACES(KeyInterface)
signals:
void addPickMode(const std::string &_mode);
......@@ -79,12 +71,16 @@ signals:
void addToolbox( QString _name , QWidget* _widget, QIcon* _icon);
void registerKey(int _key, Qt::KeyboardModifiers _modifiers, QString _description, bool _multiUse = false);
public slots:
void slotMouseEvent(QMouseEvent* _event);
void slotPickModeChanged(const std::string& _mode);
void slotKeyEvent (QKeyEvent* _event);
public:
MaterialPicker();
......@@ -95,6 +91,17 @@ public:
private:
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;
};
const std::string pickModeName_;
const QString propName_;
......@@ -104,6 +111,7 @@ private:
QStringList materialString_;//hold materials as a String (saves/load the material at the beginning)
QVector<MaterialInfo> materialList_;
std::map<int,size_t> shortKeyRow_;
/// stores the state of the pick material button
bool pickMaterial_;
......@@ -126,7 +134,7 @@ private slots:
void editMode(QListWidgetItem* _item);
/// saves the new material name
void assignNewName(QListWidgetItem* _item);
void saveNewName(QListWidgetItem* _item);
void clearList();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment