void KNWidgetSwitcher::setCurrentWidget(int currentIndex) { //Ensure the current index is in the range. Q_ASSERT(currentIndex>-1 && currentIndex<m_widgets.size()); //Change the current index widget to be the target widget without animation. //Hide the widget. setWidgetVisible(m_currentIndex, false); //Reset the out widget index to invalid. m_outWidgetIndex=-1; //Save current index. m_currentIndex=currentIndex; //Show the widget. setWidgetVisible(m_currentIndex, true); //Move the current widget. m_widgets.at(m_currentIndex)->setGeometry(rect()); }
void KNWidgetSwitcher::setCurrentIndex(const int ¤tIndex) { //Ensure the current index is in the range. Q_ASSERT(currentIndex>-1 && currentIndex<m_widgets.size()); //Check the following things: // 1. The current index is right the index we want. // 2. There's a switching animation is running. //If any one of the condition is detected, ignore the requirement. if(currentIndex==m_currentIndex || m_movingAnimationGroup->state()==QAbstractAnimation::Running) { return; } //Stop the animation group. m_movingAnimationGroup->stop(); //Save the last widget index to out index, set the new current index. m_outWidgetIndex=m_currentIndex; m_currentIndex=currentIndex; //Get the current widget. QWidget *currentWidget=m_widgets.at(m_currentIndex); //Reset the animation target. m_inAnimation->setTargetObject(currentWidget); m_outAnimation->setTargetObject(m_widgets.at(m_outWidgetIndex)); //Update the start and end value. updateAnimationPosition(); //Prepare the widget. setWidgetVisible(m_currentIndex, true); //Raise the current widget. currentWidget->raise(); //Emit start to move signal. emit moveStart(); //Start animation. m_movingAnimationGroup->start(); }
void KNWidgetSwitcher::onActionMovingFinished() { //Emit move finished signal. emit moveEnd(); //Check out whether widget index is invalid. if(m_outWidgetIndex<0 || (m_outWidgetIndex>m_widgets.size())) { //Ignore the calling. return; } //Hide the widget. setWidgetVisible(m_outWidgetIndex, false); //Reset the out widget index to invalid. m_outWidgetIndex=-1; }
void KNWidgetSwitcher::setCurrentIndex(int currentIndex) { if(currentIndex==m_currentIndex) { return; } if(currentIndex>=0 && currentIndex<m_widgets.size()) { m_switchAnime->stop(); m_flyOutAnime->setTargetObject(m_widgets.at(m_currentIndex)); m_flyInAnime->setTargetObject(m_widgets.at(currentIndex)); QRect centerRect=rect(), leftRect=QRect(-centerRect.width(), 0, centerRect.width(), centerRect.height()), rightRect=QRect(centerRect.width(), 0, centerRect.width(), centerRect.height()); m_flyOutAnime->setStartValue(centerRect); m_flyInAnime->setEndValue(centerRect); if(currentIndex > m_currentIndex) { //This widget is after the current, move left. m_flyOutAnime->setEndValue(leftRect); m_flyInAnime->setStartValue(rightRect); } else { //Move right. m_flyOutAnime->setEndValue(rightRect); m_flyInAnime->setStartValue(leftRect); } m_movedOutPage = m_currentIndex; setWidgetVisible(currentIndex, true); setWidgetFocus(currentIndex); m_switchAnime->start(); m_currentIndex = currentIndex; } }
void KNWidgetSwitcher::hideMovedOut() { setWidgetVisible(m_movedOutPage, false); emit movedComplete(); }
void KNMusicMainPlayerContent::setColumnCount(int columnCount) { //Checkout the column count. if(columnCount>3) { //Greater than 3 columns, take it as 3 column. columnCount=3; } //If the column is less than 1, there will be at least 1 column. else if(columnCount<1) { //Save the column count. columnCount=1; } //Check out whether the column count is the same or not. if(columnCount!=m_columnCount) { //Save the valid column count. m_columnCount=columnCount; //Emit the changed signal. emit columnCountChanged(m_columnCount); //Check out the column count first. switch(m_columnCount) { case 1: //Reset the current index to 0. m_currentIndex=0; m_singleSwitcher->setCurrentIndex(0); //Hide the second and the third widget. setWidgetVisible(0, true); setWidgetVisible(1, false); setWidgetVisible(2, false); //Show up the switcher. m_singleSwitcher->show(); break; case 2: //Reset the index to -1. m_currentIndex=-1; //Hide the single switcher. m_singleSwitcher->hide(); //Show the first and second widget. setWidgetVisible(0, true); setWidgetVisible(1, true); setWidgetVisible(2, false); break; case 3: //Reset the index to -1. m_currentIndex=-1; //Show all the widgets. setWidgetVisible(0, true); setWidgetVisible(1, true); setWidgetVisible(2, true); //Hide the single switcher. m_singleSwitcher->hide(); break; } } //Update the geometry. regeometryWidgets(); }