QModelIndex ThumbnailModel::previousThumbnail(QModelIndex s) const { QModelIndex i = s; while(true) { i = previousIndex(i); if(!i.isValid()) break; if(!i.data(IsDirRole).toBool()) return i; } return s; }
int sum(Index lastIndex) const { #ifdef USE_SIGNED_INDEX_TYPE return lastIndex >= 0 ? sums_.at(lastIndex) + sum(previousIndex(lastIndex) - 1) : 0; #else int result = 0; do { result += sums_.at(lastIndex); lastIndex = previousIndex(lastIndex); if (lastIndex != 0) { // here last index cannot be 1, so it cannot become 0 after // decreasing it by 1 --lastIndex; } } while (lastIndex != 0); return result; #endif }
// Takes O(vector size) time to perform void initialize(std::vector<int> numbers) { // Thanks to someone for this simple idea std::partial_sum(numbers.begin(), numbers.end(), numbers.begin()); sums_.resize(numbers.size()); for (Index i = 0; i < size(); ++i) { sums_[i] = numbers[i]; Index previousI = previousIndex(i); if (previousI > 0) { sums_[i] -= numbers[previousI - 1]; } } }
//______________________________________________ Animation::Pointer TabBarData::animation( const QPoint& position ) const { if ( !enabled() ) return Animation::Pointer(); const QTabBar* local( qobject_cast<const QTabBar*>( target().data() ) ); if ( !local ) return Animation::Pointer(); int index( local->tabAt( position ) ); if ( index < 0 ) return Animation::Pointer(); else if ( index == currentIndex() ) return currentIndexAnimation(); else if ( index == previousIndex() ) return previousIndexAnimation(); else return Animation::Pointer(); }
//______________________________________________ qreal TabBarData::opacity( const QPoint& position ) const { if ( !enabled() ) return OpacityInvalid; const QTabBar* local( qobject_cast<const QTabBar*>( target().data() ) ); if ( !local ) return OpacityInvalid; int index( local->tabAt( position ) ); if ( index < 0 ) return OpacityInvalid; else if ( index == currentIndex() ) return currentOpacity(); else if ( index == previousIndex() ) return previousOpacity(); else return OpacityInvalid; }
//______________________________________________ Animation::Pointer HeaderViewData::animation( const QPoint& position ) const { if( !enabled() ) return Animation::Pointer(); const QHeaderView* local( qobject_cast<const QHeaderView*>( target().data() ) ); if( !local ) return Animation::Pointer(); int index( local->logicalIndexAt( position ) ); if( index < 0 ) return Animation::Pointer(); else if( index == currentIndex() ) return currentIndexAnimation(); else if( index == previousIndex() ) return previousIndexAnimation(); else return Animation::Pointer(); }