ganeswidgets/inc/hgscrollbuffermanager.h
changeset 6 1cdcc61142d2
parent 5 4fa04caf0f43
equal deleted inserted replaced
5:4fa04caf0f43 6:1cdcc61142d2
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef HGSCROLLBUFFERMANAGER_H_
       
    20 #define HGSCROLLBUFFERMANAGER_H_
       
    21 
       
    22 #include <QObject>
       
    23 #include <QTimer>
       
    24 
       
    25 class UpdatePair
       
    26 {
       
    27 public:
       
    28     UpdatePair(int start, int count);
       
    29 
       
    30     int start() const;
       
    31     int end() const;
       
    32 
       
    33     bool adjacent(int start, int count) const;
       
    34     bool contains(const UpdatePair &other) const;
       
    35     void extend(int start, int count);
       
    36     void subtract(int start, int count);
       
    37 
       
    38     void shiftRight(int count);
       
    39     void shiftLeft(int count);
       
    40 
       
    41     bool operator== (const UpdatePair &other) const;
       
    42     bool operator< (const UpdatePair &other) const;
       
    43 
       
    44 private:
       
    45     int mStart;
       
    46     int mCount;
       
    47 };
       
    48 
       
    49 class UpdateBuffer : public QList<UpdatePair>
       
    50 {
       
    51 public:
       
    52     UpdateBuffer();
       
    53 
       
    54     void add(int start, int count);
       
    55     void remove(int start, int count);
       
    56     void shiftRight(int startingFrom, int amount);
       
    57     void shiftLeft(int startingFrom, int amount);
       
    58 };
       
    59 
       
    60 class HgScrollBufferManager: public QObject
       
    61     {
       
    62     Q_OBJECT
       
    63 public:
       
    64 
       
    65     HgScrollBufferManager(
       
    66             int bufferSize,
       
    67             int bufferTreshold,
       
    68             int initialPosition,
       
    69             int totalCount);
       
    70 
       
    71     virtual ~HgScrollBufferManager();
       
    72 
       
    73     void resetBuffer(int aPosition, int aTotalCount);
       
    74 
       
    75     void scrollPositionChanged(int newPosition);
       
    76 
       
    77     bool positionInsideBuffer(int position);
       
    78 
       
    79     void addItems(int start, int count);
       
    80     void removeItems(int start, int end);
       
    81     void moveItems(int start, int end, int target);
       
    82 
       
    83     void flushRequestBuffers();
       
    84 
       
    85     void currentBuffer(int& bufferStart, int& bufferEnd);
       
    86 
       
    87 signals:
       
    88 
       
    89     void releaseItems(int releaseStart, int releaseEnd);
       
    90     void requestItems(int requestStart, int requestEnd);
       
    91 
       
    92 protected slots:
       
    93 
       
    94     void timeout();
       
    95 
       
    96 protected:
       
    97 
       
    98     void init();
       
    99     void asyncUpdate();
       
   100 
       
   101     int changeBufferPosition(int newPos);
       
   102 
       
   103     void simpleAddItems(int start, int end);
       
   104     void simpleRemoveItems(int start, int end);
       
   105 
       
   106     void appendRequestBuffer(int start, int end);
       
   107     void appendReleaseBuffer(int start, int end);
       
   108 
       
   109 private:
       
   110 
       
   111     int mBufferSize;
       
   112     int mBufferTreshold;
       
   113     int mBufferPosition;
       
   114     int mDiff;
       
   115     int mTotalCount;
       
   116 
       
   117     bool mResetOrdered;
       
   118 
       
   119     int mRequestStart;
       
   120     int mRequestCount;
       
   121     int mReleaseStart;
       
   122     int mReleaseCount;
       
   123     QTimer mTimer;
       
   124     bool mFirstTime;
       
   125     
       
   126     UpdateBuffer mRequestBuffer;
       
   127     UpdateBuffer mReleaseBuffer;
       
   128     
       
   129 private:
       
   130     Q_DISABLE_COPY(HgScrollBufferManager)
       
   131     };
       
   132 
       
   133 #endif /*HGSCROLLBUFFERMANAGER_H_*/