forked from MrBesen/soundboard
moveToButtonAbove
This commit is contained in:
parent
3db543869c
commit
9944959d8f
|
@ -26,6 +26,9 @@ public:
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T* getChild(int index) const;
|
T* getChild(int index) const;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
T* getLastChild() const;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T* getSibling(int index) const;
|
T* getSibling(int index) const;
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,11 @@ T* ButtonManagerItem::getChild(int index) const {
|
||||||
return dynamic_cast<T*>(child(index));
|
return dynamic_cast<T*>(child(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
T* ButtonManagerItem::getLastChild() const {
|
||||||
|
return getChild<T>(childCount()-1);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T* ButtonManagerItem::getSibling(int index) const {
|
T* ButtonManagerItem::getSibling(int index) const {
|
||||||
if(mparent->childCount() <= index || index < 0)
|
if(mparent->childCount() <= index || index < 0)
|
||||||
|
@ -428,7 +433,35 @@ void SampleItem::updatePosition() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SampleItem::moveToButtonAbove() {
|
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() {
|
void SampleItem::moveToButtonBelow() {
|
||||||
|
|
Loading…
Reference in New Issue