119 lines
2.8 KiB
C++
119 lines
2.8 KiB
C++
#include "buttonmanageritems.h"
|
|
|
|
#include <Log.h>
|
|
|
|
// itemtypes
|
|
const static int ROWTYPE = 1000;
|
|
const static int BUTTONTYPE = 1001;
|
|
const static int SAMPLETYPE = 1002;
|
|
|
|
ButtonManagerItem::ButtonManagerItem(QTreeWidgetItem* parent, int type) : QTreeWidgetItem(parent, type), mparent(parent) {
|
|
}
|
|
|
|
ButtonManagerItem::~ButtonManagerItem() {}
|
|
|
|
bool ButtonManagerItem::hasAdd() const {
|
|
return false;
|
|
}
|
|
|
|
bool ButtonManagerItem::hasEdit() const {
|
|
return false;
|
|
}
|
|
|
|
bool ButtonManagerItem::hasRemove() const {
|
|
return false;
|
|
}
|
|
|
|
bool ButtonManagerItem::hasMoveUp() const {
|
|
return false;
|
|
}
|
|
|
|
bool ButtonManagerItem::hasMoveDown() const {
|
|
return false;
|
|
}
|
|
|
|
|
|
void ButtonManagerItem::add() {}
|
|
|
|
void ButtonManagerItem::edit() {}
|
|
|
|
void ButtonManagerItem::remove() {}
|
|
|
|
void ButtonManagerItem::moveUp() {}
|
|
|
|
void ButtonManagerItem::moveDown() {}
|
|
|
|
|
|
RowItem::RowItem(QTreeWidgetItem* parent, uint8_t rownr, Config::RootConfig& conf) : ButtonManagerItem(parent, TYPE), conf(conf), pos(rownr) {
|
|
const std::vector<Config::ButtonConfig>& btnrow = conf.buttons.at(rownr);
|
|
|
|
updatePosition();
|
|
|
|
// iterate buttons in a row
|
|
for(const Config::ButtonConfig& btn : btnrow) {
|
|
QTreeWidgetItem* qbtn = new QTreeWidgetItem(BUTTONTYPE);
|
|
qbtn->setData(1, Qt::ItemDataRole::DisplayRole, QVariant(QString::fromStdString(btn.name)));
|
|
qbtn->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
|
|
addChild(qbtn);
|
|
|
|
// iterate samples in a button
|
|
for(uint8_t samplenr = 0; samplenr < btn.samples.size(); ++samplenr) {
|
|
const Config::SampleConfig& sample = btn.samples.at(samplenr);
|
|
QTreeWidgetItem* qsample = new QTreeWidgetItem(SAMPLETYPE);
|
|
qsample->setData(2, Qt::ItemDataRole::DisplayRole, QVariant((int) samplenr+1));
|
|
qsample->setData(3, Qt::ItemDataRole::DisplayRole, QVariant(QString::fromStdString(sample.file)));
|
|
qbtn->addChild(qsample);
|
|
}
|
|
}
|
|
}
|
|
|
|
bool RowItem::hasMoveUp() const {
|
|
return pos > 0;
|
|
}
|
|
|
|
bool RowItem::hasMoveDown() const {
|
|
return pos < conf.buttons.size()-1;
|
|
}
|
|
|
|
void RowItem::moveUp() {
|
|
//apply change to config
|
|
conf.buttons.at(pos-1).swap(conf.buttons.at(pos));
|
|
|
|
Log::trace << "rows swapped in config";
|
|
|
|
// apply change in GUI
|
|
|
|
//get Child above
|
|
RowItem* rowaboveItem = dynamic_cast<RowItem*>(mparent->child(pos-1));
|
|
if(rowaboveItem) {
|
|
rowaboveItem->pos++;
|
|
rowaboveItem->updatePosition();
|
|
} else {
|
|
Log::error << "row above could not be updated";
|
|
}
|
|
|
|
QTreeWidgetItem* myparent = mparent;
|
|
Log::debug << "parent: " << myparent;
|
|
|
|
int index = myparent->indexOfChild(this);
|
|
Log::debug << "index: " << index;
|
|
|
|
bool wasexpanded = isExpanded();
|
|
myparent->removeChild(this);
|
|
|
|
myparent->insertChild(index-1, this);
|
|
setExpanded(wasexpanded);
|
|
|
|
pos--;
|
|
updatePosition();
|
|
}
|
|
|
|
void RowItem::moveDown() {
|
|
|
|
}
|
|
|
|
void RowItem::updatePosition() {
|
|
setData(0, Qt::ItemDataRole::DisplayRole, QVariant((int) pos+1));
|
|
}
|
|
|