Commit 17ff7144 authored by Matthias Möller's avatar Matthias Möller
Browse files

- removed error message at startup

- add "remove" button

refs #1148

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@15677 383ad7c9-94d9-4d36-a494-682f7c89f535
parent db588772
...@@ -70,12 +70,11 @@ MaterialPicker::~MaterialPicker() { ...@@ -70,12 +70,11 @@ MaterialPicker::~MaterialPicker() {
void MaterialPicker::initializePlugin() { void MaterialPicker::initializePlugin() {
QWidget* toolBox = new QWidget(); QWidget* toolBox = new QWidget();
QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom, toolBox);
QGridLayout* grid = new QGridLayout();
pickMaterialButton_ = new QPushButton("&pick Material", toolBox); pickMaterialButton_ = new QPushButton("&pick Material", toolBox);
fillMaterialButton_ = new QPushButton("&fill Material", toolBox); fillMaterialButton_ = new QPushButton("&fill Material", toolBox);
QPushButton* clearListButton = new QPushButton("clear list", toolBox); QPushButton* clearListButton = new QPushButton("Clear List", toolBox);
QPushButton* removeItemButton = new QPushButton("Remove", toolBox);
pickMaterialButton_->setCheckable(true); pickMaterialButton_->setCheckable(true);
fillMaterialButton_->setCheckable(true); fillMaterialButton_->setCheckable(true);
...@@ -84,11 +83,12 @@ void MaterialPicker::initializePlugin() { ...@@ -84,11 +83,12 @@ void MaterialPicker::initializePlugin() {
materialListWidget_ = new QListWidget(toolBox); materialListWidget_ = new QListWidget(toolBox);
materials_ = OpenFlipperSettings().value( propName_, QStringList() ).toStringList(); //load saved materials
materialString_ = OpenFlipperSettings().value("MaterialPickerPlugin/Materials", QStringList()).toStringList();
for (int i = 0; i < materials_.size(); ++i) for (int i = 0; i < materialString_.size(); ++i)
{ {
QStringList savedString = materials_[i].split(";"); QStringList savedString = materialString_[i].split(";");
std::stringstream stream; std::stringstream stream;
MaterialInfo materialInfo; MaterialInfo materialInfo;
stream << savedString[1].toStdString(); stream << savedString[1].toStdString();
...@@ -122,38 +122,69 @@ void MaterialPicker::initializePlugin() { ...@@ -122,38 +122,69 @@ void MaterialPicker::initializePlugin() {
materialListWidget_->addItem( savedString[0] ); materialListWidget_->addItem( savedString[0] );
materialList_.push_back(materialInfo); materialList_.push_back(materialInfo);
} }
if (materials_.size())
//if material was saved, set first as current
if (materialString_.size())
materialListWidget_->setCurrentItem(materialListWidget_->item(0)); materialListWidget_->setCurrentItem(materialListWidget_->item(0));
else
fillMaterialButton_->setEnabled(false);
QGridLayout* removeGrid = new QGridLayout();
removeGrid->addWidget(removeItemButton,0,0);
removeGrid->addWidget(clearListButton,0,1);
QGridLayout* pickGrid = new QGridLayout();
pickGrid->addWidget(pickMaterialButton_, 0, 0);
pickGrid->addWidget(fillMaterialButton_, 0, 1);
QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom, toolBox);
layout->addWidget(materials); layout->addWidget(materials);
layout->addWidget(materialListWidget_); layout->addWidget(materialListWidget_);
layout->addWidget(clearListButton);
grid->addWidget(pickMaterialButton_, 0, 0);
grid->addWidget(fillMaterialButton_, 0, 1);
layout->addLayout(grid); layout->addLayout(removeGrid);
layout->addLayout(pickGrid);
connect(pickMaterialButton_, SIGNAL(clicked()), this, SLOT(slotPickMaterialMode())); connect(pickMaterialButton_, SIGNAL(clicked()), this, SLOT(slotPickMaterialMode()));
connect(fillMaterialButton_, SIGNAL(clicked()), this, SLOT(slotFillMaterialMode())); connect(fillMaterialButton_, SIGNAL(clicked()), this, SLOT(slotFillMaterialMode()));
connect(clearListButton, SIGNAL(clicked()), this, SLOT(clearList())); connect(clearListButton, SIGNAL(clicked()), this, SLOT(clearList()));
connect(materialListWidget_, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(editMode(QListWidgetItem*))); 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(assignNewName(QListWidgetItem*)));
connect(removeItemButton, SIGNAL(clicked()), this, SLOT(slotRemoveCurrentItem()));
QIcon* toolIcon = new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"material_picker.png"); QIcon* toolIcon = new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"material_picker.png");
emit addToolbox( tr("Material Picker"), toolBox, toolIcon); emit addToolbox( tr("Material Picker"), toolBox, toolIcon);
} }
//------------------------------------------------------------------------------
void MaterialPicker::removeItem(QListWidgetItem* _item)
{
unsigned index = materialListWidget_->row(_item);
materialListWidget_->takeItem(index);
materialList_.erase(materialList_.begin()+index);
materialString_.erase(materialString_.begin()+index);
OpenFlipperSettings().setValue(propName_, materialString_);
fillMaterialButton_->setEnabled(materialListWidget_->count());
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void MaterialPicker::clearList() { void MaterialPicker::clearList() {
materialListWidget_->clear(); materialListWidget_->clear();
materialList_.clear(); materialList_.clear();
materials_.clear(); materialString_.clear();
OpenFlipperSettings().setValue(propName_, materials_); OpenFlipperSettings().setValue(propName_, materialString_);
fillMaterialButton_->setEnabled(false);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void MaterialPicker::slotRemoveCurrentItem()
{
if (materialListWidget_->count())
removeItem(materialListWidget_->currentItem());
}
//------------------------------------------------------------------------------
void MaterialPicker::slotPickMaterialMode() { void MaterialPicker::slotPickMaterialMode() {
pickMaterialButton_->setChecked(true); pickMaterialButton_->setChecked(true);
fillMaterialButton_->setChecked(false); fillMaterialButton_->setChecked(false);
...@@ -220,6 +251,7 @@ void MaterialPicker::slotMouseEvent(QMouseEvent* _event) { ...@@ -220,6 +251,7 @@ void MaterialPicker::slotMouseEvent(QMouseEvent* _event) {
materialList_.push_back(materialInfo); materialList_.push_back(materialInfo);
//save new material
std::stringstream stream; std::stringstream stream;
stream << name.toStdString(); stream << name.toStdString();
stream << ";" << materialInfo.color_material; stream << ";" << materialInfo.color_material;
...@@ -231,8 +263,9 @@ void MaterialPicker::slotMouseEvent(QMouseEvent* _event) { ...@@ -231,8 +263,9 @@ void MaterialPicker::slotMouseEvent(QMouseEvent* _event) {
stream << ";" << materialInfo.reflectance; stream << ";" << materialInfo.reflectance;
QString materialString = stream.str().c_str(); QString materialString = stream.str().c_str();
materials_.push_back(materialString); materialString_.push_back(materialString);
OpenFlipperSettings().setValue(propName_, materials_); fillMaterialButton_->setEnabled(true);
OpenFlipperSettings().setValue(propName_, materialString_);
} }
// apply material from current item in list widget to picked object // apply material from current item in list widget to picked object
...@@ -271,15 +304,15 @@ void MaterialPicker::editMode(QListWidgetItem* _item) { ...@@ -271,15 +304,15 @@ void MaterialPicker::editMode(QListWidgetItem* _item) {
void MaterialPicker::assignNewName(QListWidgetItem* _item) void MaterialPicker::assignNewName(QListWidgetItem* _item)
{ {
unsigned index = materialListWidget_->row(_item); unsigned index = materialListWidget_->row(_item);
QString str = materials_[index]; QString str = materialString_[index];
QStringList strList = str.split(";"); QStringList strList = str.split(";");
strList[0] = _item->text(); strList[0] = _item->text();
str = ""; str = "";
for (int i = 0; i < strList.size()-1; ++i) for (int i = 0; i < strList.size()-1; ++i)
str += strList[i] + ";"; str += strList[i] + ";";
str += strList[strList.size()-1]; str += strList[strList.size()-1];
materials_[index] = str; materialString_[index] = str;
OpenFlipperSettings().setValue(propName_, materials_); OpenFlipperSettings().setValue(propName_, materialString_);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
......
...@@ -101,7 +101,7 @@ private: ...@@ -101,7 +101,7 @@ private:
QPushButton* pickMaterialButton_; QPushButton* pickMaterialButton_;
QPushButton* fillMaterialButton_; QPushButton* fillMaterialButton_;
QListWidget* materialListWidget_; QListWidget* materialListWidget_;
QStringList materials_; QStringList materialString_;//hold materials as a String (saves/load the material at the beginning)
QVector<MaterialInfo> materialList_; QVector<MaterialInfo> materialList_;
...@@ -120,6 +120,8 @@ private slots: ...@@ -120,6 +120,8 @@ private slots:
void slotFillMaterialMode(); void slotFillMaterialMode();
void slotRemoveCurrentItem();
/// items can be renamed by double clicking them /// items can be renamed by double clicking them
void editMode(QListWidgetItem* _item); void editMode(QListWidgetItem* _item);
...@@ -128,6 +130,8 @@ private slots: ...@@ -128,6 +130,8 @@ private slots:
void clearList(); void clearList();
void removeItem(QListWidgetItem* _item);
public slots: public slots:
QString version(){ return QString("1.0"); } QString version(){ return QString("1.0"); }
}; };
......
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