moveToButtonAbove

This commit is contained in:
mrbesen 2021-12-25 14:01:15 +01:00
parent 3db543869c
commit 9944959d8f
Signed by untrusted user: MrBesen
GPG Key ID: 596B2350DCD67504
2 changed files with 36 additions and 0 deletions

View File

@ -26,6 +26,9 @@ public:
template<typename T>
T* getChild(int index) const;
template<typename T>
T* getLastChild() const;
template<typename T>
T* getSibling(int index) const;

View File

@ -46,6 +46,11 @@ T* ButtonManagerItem::getChild(int index) const {
return dynamic_cast<T*>(child(index));
}
template<typename T>
T* ButtonManagerItem::getLastChild() const {
return getChild<T>(childCount()-1);
}
template<typename T>
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<ButtonItem>()->getItemAbove<ButtonItem>();
if(!buttonabove) {
buttonabove = getParent<ButtonItem>()->getParent<RowItem>()->getItemAbove<RowItem>()->getLastChild<ButtonItem>();
}
// apply change in config
auto& buttonconf = getParent<ButtonItem>()->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<ButtonItem>()->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() {