move buttons down
This commit is contained in:
parent
9fc7a939d1
commit
d7ba980cfc
|
@ -79,6 +79,7 @@ private:
|
|||
RowItem* row = nullptr;
|
||||
|
||||
void moveToRowAbove();
|
||||
void moveToRowBelow();
|
||||
};
|
||||
|
||||
class SampleItem : public ButtonManagerItem {
|
||||
|
|
|
@ -35,7 +35,7 @@ void ButtonManagerItem::moveUp() {}
|
|||
void ButtonManagerItem::moveDown() {}
|
||||
|
||||
void ButtonManagerItem::updateAllPosBellow(int8_t diff, uint8_t size) {
|
||||
for(uint8_t i = pos+1; i <= size; ++i) {
|
||||
for(uint8_t i = pos+1; i < size; ++i) {
|
||||
ButtonManagerItem* item = dynamic_cast<ButtonManagerItem*>(mparent->child(i));
|
||||
if(item) {
|
||||
item->pos += diff;
|
||||
|
@ -74,7 +74,7 @@ bool RowItem::hasMoveDown() const {
|
|||
void RowItem::remove() {
|
||||
conf.buttons.erase(conf.buttons.begin() + pos);
|
||||
|
||||
updateAllPosBellow(-1, conf.buttons.size());
|
||||
updateAllPosBellow(-1, conf.buttons.size()+1);
|
||||
}
|
||||
|
||||
void RowItem::moveUp() {
|
||||
|
@ -166,7 +166,7 @@ void ButtonItem::remove() {
|
|||
auto& rowconf = row->getConfig();
|
||||
rowconf.erase(rowconf.begin() + pos);
|
||||
|
||||
updateAllPosBellow(-1, rowconf.size());
|
||||
updateAllPosBellow(-1, rowconf.size()+1);
|
||||
}
|
||||
|
||||
void ButtonItem::moveUp() {
|
||||
|
@ -198,6 +198,11 @@ void ButtonItem::moveUp() {
|
|||
}
|
||||
|
||||
void ButtonItem::moveDown() {
|
||||
if(pos == row->getConfig().size()-1) {
|
||||
moveToRowBelow();
|
||||
return;
|
||||
}
|
||||
|
||||
// moving down is the same as moving the item below up
|
||||
ButtonItem* rowbelow = dynamic_cast<ButtonItem*>(mparent->child(pos+1));
|
||||
if(rowbelow) {
|
||||
|
@ -207,7 +212,6 @@ void ButtonItem::moveDown() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void ButtonItem::nameWasChanged() {
|
||||
std::string newName = data(1, Qt::ItemDataRole::DisplayRole).toString().toStdString();
|
||||
getConfig().name = newName;
|
||||
|
@ -233,7 +237,7 @@ void ButtonItem::moveToRowAbove() {
|
|||
rowconf.erase(rowconf.begin());
|
||||
|
||||
// update buttons in old row
|
||||
updateAllPosBellow(-1, rowconf.size());
|
||||
updateAllPosBellow(-1, rowconf.size()+1);
|
||||
|
||||
// remove button from this row and attach to other
|
||||
bool wasExpanded = isExpanded();
|
||||
|
@ -250,6 +254,39 @@ void ButtonItem::moveToRowAbove() {
|
|||
setExpanded(wasExpanded);
|
||||
}
|
||||
|
||||
void ButtonItem::moveToRowBelow() {
|
||||
// get row below
|
||||
RowItem* rowbelow = row->getRowBelow();
|
||||
if(!rowbelow) {
|
||||
Log::error << "no row below!";
|
||||
return;
|
||||
}
|
||||
|
||||
// apply change in config
|
||||
auto& rowconf = row->getConfig();
|
||||
auto& newrowconf = rowbelow->getConfig();
|
||||
|
||||
newrowconf.insert(newrowconf.begin(), rowconf.back());
|
||||
rowconf.erase(rowconf.end());
|
||||
|
||||
// remove button from this row and attach to other
|
||||
bool wasExpanded = isExpanded();
|
||||
row->removeChild(this);
|
||||
|
||||
rowbelow->insertChild(0, this);
|
||||
//update local parents
|
||||
row = rowbelow;
|
||||
mparent = rowbelow;
|
||||
|
||||
//update local pos
|
||||
pos = 0;
|
||||
|
||||
//update new buttons below
|
||||
updateAllPosBellow(1, newrowconf.size());
|
||||
|
||||
setExpanded(wasExpanded);
|
||||
}
|
||||
|
||||
|
||||
SampleItem::SampleItem(ButtonItem* parent, uint8_t samplenr, Config::RootConfig& conf) : ButtonManagerItem(parent, TYPE, samplenr), conf(conf), button(parent) {
|
||||
const Config::SampleConfig& sample = getConfig();
|
||||
|
|
Loading…
Reference in New Issue