//================================================================================================= ClipComponent* ClipsContainer::getFirstSelected () const { for (int i = 0; i < clipsNums(); ++i) { if (getUnchecked(i)->hasSelected()) return getUnchecked(i); } return nullptr; }
//================================================================================================= void ClipsContainer::resizeAllClips () const { for (int i = clipsNums(); --i >= 0; ) { getUnchecked(i)->setBounds(roundToIntAccurate(getUnchecked(i)->getStartXAtTimeScale()), 0, roundToIntAccurate(getUnchecked(i)->getEndXAtTimeScale() - getUnchecked(i)->getStartXAtTimeScale()), getHeight()); } }
//================================================================================================= ClipComponent* ClipsContainer::getLastSelected () const { for (int i = clipsNums(); --i >= 0;) { if (getUnchecked(i)->hasSelected()) return getUnchecked(i); } return nullptr; }
//================================================================================================= void ClipsContainer::moveClips(const int distance) const { for (int i = clipsNums(); --i >= 0; ) { if (getUnchecked(i)->hasSelected()) { // 将所有已选Clip的isDragging设置为true,防止多个Clips移动时,鼠标当前未拖拽的Clips的缩略图不随之一起移动 getUnchecked(i)->setDragging(true); getUnchecked(i)->setTopLeftPosition(roundToIntAccurate(getUnchecked(i)->getStartXAtTimeScale()) + distance, 0); } } }
//================================================================================================= void ClipsContainer::moveDone () { if (atLeastOneHasSelected()) undoManager->perform(new MoveAction(this)); // 将所有已选Clip的isDragging设置为false for (int i = clipsNums(); --i >= 0; ) { if (getUnchecked(i)->hasSelected()) getUnchecked(i)->setDragging(false); } }
//================================================================================================= void ClipsContainer::resized() { for (int i = clipsNums(); --i >= 0; ) { ClipComponent* clip = getUnchecked(i); clip->setBounds(clip->getX(), 0, clip->getWidth(), getHeight()); } }
//================================================================================================= const bool ClipsContainer::atLeastOneHasSelected () const { for (int i = clipsNums(); --i >= 0; ) { if (getUnchecked(i)->hasSelected()) return true; } return false; }
//================================================================================================= void ClipsContainer::selectByShift (ClipComponent* currentClip) const { const int currentIndex = indexOf(currentClip); // 获取当前最后一个处于已选状态的Clip int selectedIndex = clipsNums(); while (--selectedIndex >= 0) { if (getUnchecked(selectedIndex)->hasSelected()) break; } if (selectedIndex < 0) selectedIndex = 0; deselectAll(); for (int j = jmin(currentIndex, selectedIndex); j <= jmax(currentIndex, selectedIndex); ++j) getUnchecked(j)->setSelectState(true); }
//================================================================================================= const int ClipsContainer::selectedNums () const { int nums = 0; for (int i = clipsNums(); --i >= 0; ) { if (getUnchecked(i)->hasSelected()) ++nums; } return nums; }
//================================================================================================= void ClipsContainer::moveToOtherContainer (ClipsContainer* otherContainer) { for (int i = clipsNums(); --i >= 0; ) { if (getUnchecked(i)->hasSelected()) { getUnchecked(i)->setDragging(true); otherContainer->addAndMakeVisible(getUnchecked(i)); getUnchecked(i)->setSize(getUnchecked(i)->getWidth(), otherContainer->getHeight()); getUnchecked(i)->setTopLeftPosition(getUnchecked(i)->getX(), 0); otherContainer->clips.addIfNotAlreadyThere(getUnchecked(i)); clips.removeFirstMatchingValue(getUnchecked(i)); } } }
//================================================================================================= void ClipsContainer::clipsDragToResized (const int distance, const bool leftResized) { for (int i = clipsNums(); --i >= 0; ) { ClipComponent* clip = getUnchecked(i); if (clip->hasSelected() && leftResized) clip->setBounds(clip->getBounds().withLeft(roundToIntAccurate(clip->getStartXAtTimeScale()) + distance)); else if(clip->hasSelected() && !leftResized) clip->setBounds(clip->getBounds().withRight(roundToIntAccurate(clip->getEndXAtTimeScale()) + distance)); } }
void callListeners (Function fn) const { auto numListeners = valueTreesWithListeners.size(); if (numListeners == 1) { fn (valueTreesWithListeners.getUnchecked(0)->listeners); } else if (numListeners > 0) { auto listenersCopy = valueTreesWithListeners; for (int i = 0; i < numListeners; ++i) { auto* v = listenersCopy.getUnchecked(i); if (i == 0 || valueTreesWithListeners.contains (v)) fn (v->listeners); } } }
void callListeners (ValueTree::Listener* listenerToExclude, Function fn) const { auto numListeners = valueTreesWithListeners.size(); if (numListeners == 1) { valueTreesWithListeners.getUnchecked (0)->listeners.callExcluding (listenerToExclude, fn); } else if (numListeners > 0) { auto listenersCopy = valueTreesWithListeners; for (int i = 0; i < numListeners; ++i) { auto* v = listenersCopy.getUnchecked (i); if (i == 0 || valueTreesWithListeners.contains (v)) v->listeners.callExcluding (listenerToExclude, fn); } } }
//================================================================================================= void ClipsContainer::deselectAll () const { for (int i = clipsNums(); --i >= 0; ) getUnchecked(i)->setSelectState(false); }