diff --git a/include/buttonmanageritems.h b/include/buttonmanageritems.h index a766692..e141ada 100644 --- a/include/buttonmanageritems.h +++ b/include/buttonmanageritems.h @@ -26,6 +26,9 @@ public: template T* getChild(int index) const; + template + T* getLastChild() const; + template T* getSibling(int index) const; diff --git a/src/buttonmanageritems.cpp b/src/buttonmanageritems.cpp index 76388e4..401ed8b 100644 --- a/src/buttonmanageritems.cpp +++ b/src/buttonmanageritems.cpp @@ -46,6 +46,11 @@ T* ButtonManagerItem::getChild(int index) const { return dynamic_cast(child(index)); } +template +T* ButtonManagerItem::getLastChild() const { + return getChild(childCount()-1); +} + template T* ButtonManagerItem::getSibling(int index) const { if(mparent->childCount() <= index || index < 0) @@ -428,7 +433,35 @@ void SampleItem::updatePosition() { } void SampleItem::moveToButtonAbove() { + ButtonItem* buttonabove = getParent()->getItemAbove(); + if(!buttonabove) { + buttonabove = getParent()->getParent()->getItemAbove()->getLastChild(); + } + // apply change in config + auto& buttonconf = getParent()->getConfig().samples; + auto& newbuttonconf = buttonabove->getConfig().samples; + + newbuttonconf.push_back(buttonconf.front()); + buttonconf.erase(buttonconf.begin()); + + // update buttons in old row + // updateAllPosBellow(-1, rowconf.size()+1); + + // remove button from this row and attach to other + bool wasExpanded = isExpanded(); + getParent()->removeChild(this); + + reenumerateAllSiblings(); // depends on mparent beeing set to the old row + + buttonabove->addChild(this); + //update local parent + mparent = buttonabove; + + //update local pos + pos = newbuttonconf.size()-1; + + setExpanded(wasExpanded); } void SampleItem::moveToButtonBelow() {