Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (16 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/itemviews/qlistview_p.h

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information ([email protected])
     4** All rights reserved.
     5** Contact: Nokia Corporation ([email protected])
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you
     37** @nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    6868{
    6969    friend class QListViewPrivate;
    70     friend class QStaticListViewBase;
    71     friend class QDynamicListViewBase;
     70    friend class QViewBase;
     71    friend class QViewBase;
    7272public:
    7373    inline QListViewItem()
     
    8585        { return !(*this == other); }
    8686    inline bool isValid() const
    87         { return (x > -1) && (y > -1) && (w > 0) && (h > 0) && (indexHint > -1); }
     87        { return ) && (indexHint > -1); }
    8888    inline void invalidate()
    8989        { x = -1; y = -1; w = 0; h = 0; }
     
    121121{
    122122public:
    123     inline QCommonListViewBase(QListView *q, QListViewPrivate *d) : dd(d), qq(q) {}
    124 
     123    inline QCommonListViewBase(QListView *q, QListViewPrivate *d) : dd(d), qq(q), batchStartRow(0), batchSavedDeltaSeg(0) {}
     124    virtual ~QCommonListViewBase() {}
     125
     126    //common interface
     127    virtual int itemIndex(const QListViewItem &item) const = 0;
     128    virtual QListViewItem indexToListViewItem(const QModelIndex &index) const = 0;
     129    virtual bool doBatchedItemLayout(const QListViewLayoutInfo &info, int max) = 0;
     130    virtual void clear() = 0;
     131    virtual void setRowCount(int) = 0;
     132    virtual QVector<QModelIndex> intersectingSet(const QRect &area) const = 0;
     133    virtual void dataChanged(const QModelIndex &, const QModelIndex &) = 0;
     134
     135    virtual int horizontalScrollToValue(int index, QListView::ScrollHint hint,
     136        bool leftOf, bool rightOf, const QRect &area, const QRect &rect) const;
     137    virtual int verticalScrollToValue(int index, QListView::ScrollHint hint,
     138        bool above, bool below, const QRect &area, const QRect &rect) const;
     139    virtual void scrollContentsBy(int dx, int dy, bool scrollElasticBand);
     140    virtual QRect mapToViewport(const QRect &rect) const {return rect;}
     141    virtual int horizontalOffset() const;
     142    virtual int verticalOffset() const { return verticalScrollBar()->value(); }
     143    virtual void updateHorizontalScrollBar(const QSize &step);
     144    virtual void updateVerticalScrollBar(const QSize &step);
     145    virtual void appendHiddenRow(int row);
     146    virtual void removeHiddenRow(int row);
     147    virtual void setPositionForIndex(const QPoint &, const QModelIndex &) { }
     148
     149#ifndef QT_NO_DRAGANDDROP
     150    virtual void paintDragDrop(QPainter *painter) = 0;
     151    virtual bool filterDragMoveEvent(QDragMoveEvent *) { return false; }
     152    virtual bool filterDragLeaveEvent(QDragLeaveEvent *) { return false; }
     153    virtual bool filterDropEvent(QDropEvent *) { return false; }
     154    virtual bool filterStartDrag(Qt::DropActions) { return false; }
     155#endif
     156
     157
     158    //other inline members
    125159    inline int spacing() const;
    126160    inline bool isWrapping() const;
     
    134168    inline int column() const;
    135169
    136     inline int verticalScrollBarValue() const;
    137     inline int horizontalScrollBarValue() const;
     170    inline () const;
     171    inline () const;
    138172    inline QListView::ScrollMode verticalScrollMode() const;
    139173    inline QListView::ScrollMode horizontalScrollMode() const;
     
    154188    inline int hiddenCount() const;
    155189
    156     inline void clearIntersections() const;
    157     inline void appendToIntersections(const QModelIndex &idx) const;
    158 
    159190    inline bool isRightToLeft() const;
    160191
    161192    QListViewPrivate *dd;
    162193    QListView *qq;
    163 };
    164 
    165 // ### rename to QListModeViewBase
    166 class QStaticListViewBase : public QCommonListViewBase
    167 {
    168     friend class QListViewPrivate;
     194    QSize contentsSize;
     195    int batchStartRow;
     196    int batchSavedDeltaSeg;
     197};
     198
     199class QListModeViewBase : public QCommonListViewBase
     200{
    169201public:
    170     QStaticListViewBase(QListView *q, QListViewPrivate *d) : QCommonListViewBase(q, d),
    171         batchStartRow(0), batchSavedDeltaSeg(0), batchSavedPosition(0) {}
     202    QListModeViewBase(QListView *q, QListViewPrivate *d) : QCommonListViewBase(q, d) {}
    172203
    173204    QVector<int> flowPositions;
     
    175206    QVector<int> segmentStartRows;
    176207    QVector<int> segmentExtents;
    177 
    178     QSize contentsSize;
     208    QVector<int> scrollValueMap;
    179209
    180210    // used when laying out in batches
    181     int batchStartRow;
    182     int batchSavedDeltaSeg;
    183211    int batchSavedPosition;
    184212
     213
     214
     215
    185216    bool doBatchedItemLayout(const QListViewLayoutInfo &info, int max);
    186 
     217    void clear();
     218    void setRowCount(int rowCount) { flowPositions.resize(rowCount); }
     219    QVector<QModelIndex> intersectingSet(const QRect &area) const;
     220    void dataChanged(const QModelIndex &, const QModelIndex &);
     221
     222    int horizontalScrollToValue(int index, QListView::ScrollHint hint,
     223        bool leftOf, bool rightOf,const QRect &area, const QRect &rect) const;
     224    int verticalScrollToValue(int index, QListView::ScrollHint hint,
     225        bool above, bool below, const QRect &area, const QRect &rect) const;
     226    void scrollContentsBy(int dx, int dy, bool scrollElasticBand);
     227    QRect mapToViewport(const QRect &rect) const;
     228    int horizontalOffset() const;
     229    int verticalOffset() const;
     230    void updateHorizontalScrollBar(const QSize &step);
     231    void updateVerticalScrollBar(const QSize &step);
     232
     233#ifndef QT_NO_DRAGANDDROP
     234    void paintDragDrop(QPainter *painter);
     235
     236    // The next two methods are to be used on LefToRight flow only.
     237    // WARNING: Plenty of duplicated code from QAbstractItemView{,Private}.
     238    QAbstractItemView::DropIndicatorPosition position(const QPoint &pos, const QRect &rect, const QModelIndex &idx) const;
     239    void dragMoveEvent(QDragMoveEvent *e);
     240#endif
     241
     242private:
    187243    QPoint initStaticLayout(const QListViewLayoutInfo &info);
    188244    void doStaticLayout(const QListViewLayoutInfo &info);
    189     void intersectingStaticSet(const QRect &area) const;
    190 
    191     int itemIndex(const QListViewItem &item) const;
    192 
    193     int perItemScrollingPageSteps(int length, int bounds, bool wrap) const;
    194 
    195245    int perItemScrollToValue(int index, int value, int height,
    196246                             QAbstractItemView::ScrollHint hint,
    197247                             Qt::Orientation orientation, bool wrap, int extent) const;
    198 
    199     QRect mapToViewport(const QRect &rect) const;
    200 
    201     QListViewItem indexToListViewItem(const QModelIndex &index) const;
    202 
    203     void scrollContentsBy(int &dx, int &dy);
    204 
    205     int verticalPerItemValue(int itemIndex, int verticalValue, int areaHeight,
    206                        bool above, bool below, bool wrap, QListView::ScrollHint hint, int itemHeight) const;
    207     int horizontalPerItemValue(int itemIndex, int horizontalValue, int areaWidth,
    208                        bool leftOf, bool rightOf, bool wrap, QListView::ScrollHint hint, int itemWidth) const;
    209 
    210     void clear();
    211 };
    212 
    213 // ### rename to QIconModeViewBase
    214 class QDynamicListViewBase : public QCommonListViewBase
    215 {
    216     friend class QListViewPrivate;
     248    int perItemScrollingPageSteps(int length, int bounds, bool wrap) const;
     249};
     250
     251class QIconModeViewBase : public QCommonListViewBase
     252{
    217253public:
    218     QDynamicListViewBase(QListView *q, QListViewPrivate *d) : QCommonListViewBase(q, d),
    219         batchStartRow(0), batchSavedDeltaSeg(0) {}
     254    QIconModeViewBase(QListView *q, QListViewPrivate *d) : QCommonListViewBase(q, d), interSectingVector(0) {}
    220255
    221256    QBspTree tree;
     
    223258    QBitArray moved;
    224259
    225     QSize contentsSize;
    226 
    227260    QVector<QModelIndex> draggedItems; // indices to the tree.itemVector
    228261    mutable QPoint draggedItemsPos;
    229262
    230263    // used when laying out in batches
    231     int batchStartRow;
    232     int batchSavedDeltaSeg;
    233 
     264    QVector<QModelIndex> *interSectingVector; //used from within intersectingSet
     265
     266    //reimplementations
     267    int itemIndex(const QListViewItem &item) const;
     268    QListViewItem indexToListViewItem(const QModelIndex &index) const;
     269    bool doBatchedItemLayout(const QListViewLayoutInfo &info, int max);
     270    void clear();
     271    void setRowCount(int rowCount);
     272    QVector<QModelIndex> intersectingSet(const QRect &area) const;
     273
     274    void scrollContentsBy(int dx, int dy, bool scrollElasticBand);
    234275    void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
    235     bool doBatchedItemLayout(const QListViewLayoutInfo &info, int max);
    236 
     276    void appendHiddenRow(int row);
     277    void removeHiddenRow(int row);
     278    void setPositionForIndex(const QPoint &position, const QModelIndex &index);
     279
     280#ifndef QT_NO_DRAGANDDROP
     281    void paintDragDrop(QPainter *painter);
     282    bool filterDragMoveEvent(QDragMoveEvent *);
     283    bool filterDragLeaveEvent(QDragLeaveEvent *);
     284    bool filterDropEvent(QDropEvent *e);
     285    bool filterStartDrag(Qt::DropActions);
     286#endif
     287
     288private:
    237289    void initBspTree(const QSize &contents);
    238290    QPoint initDynamicLayout(const QListViewLayoutInfo &info);
    239291    void doDynamicLayout(const QListViewLayoutInfo &info);
    240     void intersectingDynamicSet(const QRect &area) const;
    241 
    242292    static void addLeaf(QVector<int> &leaf, const QRect &area,
    243293                        uint visited, QBspTree::Data data);
    244 
    245     void insertItem(int index);
    246     void removeItem(int index);
     294    QRect itemsRect(const QVector<QModelIndex> &indexes) const;
     295    QRect draggedItemsRect() const;
     296    QPoint snapToGrid(const QPoint &pos) const;
     297    void updateContentsSize();
     298    QPoint draggedItemsDelta() const;
     299    void drawItems(QPainter *painter, const QVector<QModelIndex> &indexes) const;
    247300    void moveItem(int index, const QPoint &dest);
    248301
    249     int itemIndex(const QListViewItem &item) const;
    250 
    251     void createItems(int to);
    252     void drawItems(QPainter *painter, const QVector<QModelIndex> &indexes) const;
    253     QRect itemsRect(const QVector<QModelIndex> &indexes) const;
    254 
    255     QPoint draggedItemsDelta() const;
    256     QRect draggedItemsRect() const;
    257 
    258     QPoint snapToGrid(const QPoint &pos) const;
    259 
    260     void scrollElasticBandBy(int dx, int dy);
    261 
    262     QListViewItem indexToListViewItem(const QModelIndex &index) const;
    263 
    264     void clear();
    265     void updateContentsSize();
    266302};
    267303
     
    278314    bool doItemsLayout(int num);
    279315
    280     inline void intersectingSet(const QRect &area, bool doLayout = true) const {
     316    inline intersectingSet(const QRect &area, bool doLayout = true) const {
    281317        if (doLayout) executePostedLayout();
    282318        QRect a = (q_func()->isRightToLeft() ? flipX(area.normalized()) : area.normalized());
    283         if (viewMode == QListView::ListMode) staticListView->intersectingStaticSet(a);
    284         else dynamicListView->intersectingDynamicSet(a);
     319        return commonListView->intersectingSet(a);
    285320    }
    286321
    287     // ### FIXME:
    288     inline void resetBatchStartRow()
    289         { if (viewMode == QListView::ListMode) staticListView->batchStartRow = 0;
    290               else dynamicListView->batchStartRow = 0; }
    291     inline int batchStartRow() const
    292         { return (viewMode == QListView::ListMode
    293           ? staticListView->batchStartRow : dynamicListView->batchStartRow); }
    294     inline QSize contentsSize() const
    295         { return (viewMode == QListView::ListMode
    296           ? staticListView->contentsSize : dynamicListView->contentsSize); }
    297     inline void setContentsSize(int w, int h)
    298         { if (viewMode == QListView::ListMode) staticListView->contentsSize = QSize(w, h);
    299           else dynamicListView->contentsSize = QSize(w, h); }
     322    inline void resetBatchStartRow() { commonListView->batchStartRow = 0; }
     323    inline int batchStartRow() const { return commonListView->batchStartRow; }
     324    inline QSize contentsSize() const { return commonListView->contentsSize; }
     325    inline void setContentsSize(int w, int h) { commonListView->contentsSize = QSize(w, h); }
    300326
    301327    inline int flipX(int x) const
     
    308334        { if (q_func()->isRightToLeft()) return flipX(item.rect()); return item.rect(); }
    309335
    310     int itemIndex(const QListViewItem &item) const;
    311336    QListViewItem indexToListViewItem(const QModelIndex &index) const;
    312337    inline QModelIndex listViewItemToIndex(const QListViewItem &item) const
    313         { return model->index(itemIndex(item), column, root); }
    314 
    315     QRect mapToViewport(const QRect &rect, bool greedy = false) const;
     338        { return model->index(commonListView->itemIndex(item), column, root); }
     339
     340    QRect rectForIndex(const QModelIndex &index) const
     341    {
     342        if (!isIndexValid(index) || index.parent() != root || index.column() != column || isHidden(index.row()))
     343            return QRect();
     344        executePostedLayout();
     345        return viewItemRect(indexToListViewItem(index));
     346    }
     347
     348    void viewUpdateGeometries() { q_func()->updateGeometries(); }
     349
     350
     351    QRect mapToViewport(const QRect &rect, bool extend = true) const;
    316352
    317353    QModelIndex closestIndex(const QRect &target, const QVector<QModelIndex> &candidates) const;
     
    326362    QItemSelection selection(const QRect &rect) const;
    327363    void selectAll(QItemSelectionModel::SelectionFlags command);
     364
     365
     366
     367
    328368
    329369    inline void setGridSize(const QSize &size) { grid = size; }
     
    352392    void scrollElasticBandBy(int dx, int dy);
    353393
    354     // ### FIXME: we only need one at a time
    355     QDynamicListViewBase *dynamicListView;
    356     QStaticListViewBase *staticListView;
     394    QItemViewPaintPairs draggablePaintPairs(const QModelIndexList &indexes, QRect *r) const;
     395
     396    void emitIndexesMoved(const QModelIndexList &indexes) { emit q_func()->indexesMoved(indexes); }
     397
     398
     399    QCommonListViewBase *commonListView;
    357400
    358401    // ### FIXME: see if we can move the members into the dynamic/static classes
     
    384427    QRect layoutBounds;
    385428
    386     // used for intersecting set
    387     mutable QVector<QModelIndex> intersectVector;
    388 
    389429    // timers
    390430    QBasicTimer batchLayoutTimer;
     
    415455inline int QCommonListViewBase::column() const { return dd->column; }
    416456
    417 inline int QCommonListViewBase::verticalScrollBarValue() const { return qq->verticalScrollBar()->value(); }
    418 inline int QCommonListViewBase::horizontalScrollBarValue() const { return qq->horizontalScrollBar()->value(); }
     457inline (); }
     458inline (); }
    419459inline QListView::ScrollMode QCommonListViewBase::verticalScrollMode() const { return qq->verticalScrollMode(); }
    420460inline QListView::ScrollMode QCommonListViewBase::horizontalScrollMode() const { return qq->horizontalScrollMode(); }
     
    439479inline int QCommonListViewBase::hiddenCount() const { return dd->hiddenRows.count(); }
    440480
    441 inline void QCommonListViewBase::clearIntersections() const { dd->intersectVector.clear(); }
    442 inline void QCommonListViewBase::appendToIntersections(const QModelIndex &idx) const { dd->intersectVector.append(idx); }
    443 
    444481inline bool QCommonListViewBase::isRightToLeft() const { return qq->isRightToLeft(); }
    445482
Note: See TracChangeset for help on using the changeset viewer.