示例#1
0
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;
}
示例#2
0
文件: main.cpp 项目: alien43/misc
    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
    }
示例#3
0
文件: main.cpp 项目: alien43/misc
 // 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];
         }
     }
 }
示例#4
0
//______________________________________________
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();

      }
示例#5
0
//______________________________________________
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();

    }