2 Copyright 2007 Robert Knight <robertknight@gmail.com>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 #ifndef FLIPSCROLLVIEW_H
21 #define FLIPSCROLLVIEW_H
24 #include <QAbstractItemView>
30 * An "iPod-style" item view for single-column tree and list data models which
31 * displays items in pages (one per tree branch).
33 * Clicking on an item which has children (eg. a folder in a directory model)
34 * scrolls the whole contents of the view to show the items children. A large back
35 * arrow is displayed on the left of the display if the current item has a valid parent,
36 * when clicked on this scrolls the whole contents of the view to show the parent item's
39 * The view assumes that the item delegate will fill the background with the current palette's
40 * highlight color when the user hovers over items with the mouse. Item delegates should check
41 * for the QStyle::State_MouseOver or QStyle::State_Selected flags in the state
42 * field of the QStyleOptionViewItem passed to the QAbstractItemDelegate::paint() method.
44 class FlipScrollView
: public QAbstractItemView
49 /** Construct a new FlipScrollView with the specified parent. */
50 FlipScrollView(QWidget
*parent
= 0);
51 virtual ~FlipScrollView();
53 /** Go to the root item. */
56 // reimplemented from QAbstractItemView
57 virtual QModelIndex
indexAt(const QPoint
& point
) const;
58 virtual void scrollTo(const QModelIndex
& index
, ScrollHint hint
= EnsureVisible
);
59 virtual QRect
visualRect(const QModelIndex
& index
) const;
61 int itemHeight() const;
64 // reimplemented from QWidget
65 virtual void paintEvent(QPaintEvent
*event
);
66 virtual void mouseMoveEvent(QMouseEvent
*event
);
67 virtual void mousePressEvent(QMouseEvent
*event
);
68 virtual void mouseReleaseEvent(QMouseEvent
*event
);
69 virtual void resizeEvent(QResizeEvent
*event
);
70 virtual void keyPressEvent(QKeyEvent
*event
);
71 virtual void leaveEvent(QEvent
*event
);
73 // reimplemented from QAbstractItemView
74 virtual bool isIndexHidden(const QModelIndex
& index
) const;
75 virtual int horizontalOffset() const;
76 virtual int verticalOffset() const;
77 virtual QRegion
visualRegionForSelection(const QItemSelection
& selection
) const;
78 virtual QModelIndex
moveCursor(CursorAction cursorAction
, Qt::KeyboardModifiers modifiers
);
79 virtual void setSelection(const QRect
& rect
, QItemSelectionModel::SelectionFlags flags
);
80 virtual void startDrag(Qt::DropActions supportedActions
);
83 void openItem(const QModelIndex
& index
);
84 void updateFlipAnimation(qreal value
);
87 void paintItems(QPainter
&painter
, QPaintEvent
*event
, QModelIndex
&index
);
95 #endif // FLIPSCROLLVIEW_H