2 * Copyright © 2008 Fredrik Höglund <fredrik@kde.org>
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 ABSTRACTITEMVIEW_H
21 #define ABSTRACTITEMVIEW_H
23 #include <QGraphicsWidget>
24 #include <QAbstractItemDelegate>
28 #include <QBasicTimer>
30 #include <plasma/widgets/scrollbar.h>
35 class KFileItemDelegate
;
36 class KFilePreviewGenerator
;
38 class QItemSelectionModel
;
40 class QStyleOptionViewItemV4
;
44 // The abstract base class for IconView and ListView
45 class AbstractItemView
: public QGraphicsWidget
49 Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize
)
52 AbstractItemView(QGraphicsWidget
*parent
= 0);
55 virtual void setModel(QAbstractItemModel
*model
);
56 QAbstractItemModel
*model() const;
58 void setSelectionModel(QItemSelectionModel
*model
);
59 QItemSelectionModel
*selectionModel() const;
61 void setItemDelegate(KFileItemDelegate
*delegate
);
62 KFileItemDelegate
*itemDelegate() const;
64 virtual void setIconSize(const QSize
&iconSize
);
65 QSize
iconSize() const;
67 QScrollBar
*verticalScrollBar() const;
69 QRect
visibleArea() const;
70 virtual QModelIndex
indexAt(const QPointF
&point
) const = 0;
71 virtual QRect
visualRect(const QModelIndex
&index
) const = 0;
74 void activated(const QModelIndex
&index
);
75 void contextMenuRequest(QWidget
*widget
, const QPoint
&screenPos
);
78 void markAreaDirty(const QRect
&rect
);
79 void markAreaDirty(const QRectF
&rect
) { markAreaDirty(rect
.toAlignedRect()); }
80 QRect
scrollBackBuffer();
81 void prepareBackBuffer();
82 void syncBackBuffer(QPainter
*painter
, const QRect
&clipRect
);
84 QPointF
mapToViewport(const QPointF
&point
) const;
85 QRectF
mapToViewport(const QRectF
&rect
) const;
86 QPointF
mapFromViewport(const QPointF
&point
) const;
87 QRectF
mapFromViewport(const QRectF
&rect
) const;
89 void timerEvent(QTimerEvent
*event
);
91 void smoothScroll(int dx
, int dy
);
92 void startScrolling();
97 virtual void rowsInserted(const QModelIndex
&parent
, int first
, int last
);
98 virtual void rowsRemoved(const QModelIndex
&parent
, int first
, int last
);
99 virtual void modelReset();
100 virtual void layoutChanged();
101 virtual void dataChanged(const QModelIndex
&topLeft
, const QModelIndex
&bottomRight
);
102 virtual void commitData(QWidget
*editor
);
103 virtual void closeEditor(QWidget
*editor
, QAbstractItemDelegate::EndEditHint hint
);
105 virtual void finishedScrolling();
108 void scrollBarValueChanged(int value
);
109 void scrollBarActionTriggered(int action
);
110 void scrollBarSliderReleased();
113 KFileItemDelegate
*m_delegate
;
114 QPointer
<KDirModel
> m_dirModel
;
115 QPointer
<ProxyModel
> m_model
;
116 QPointer
<QItemSelectionModel
> m_selectionModel
;
118 QRegion m_dirtyRegion
;
120 QPixmap m_topFadeTile
;
121 QPixmap m_bottomFadeTile
;
122 Plasma::ScrollBar
*m_scrollBar
;
124 QWidget
*m_styleWidget
;
125 int m_lastScrollValue
;
128 // These variables are for the smooth scrolling code
137 bool m_smoothScrolling
;
138 QBasicTimer m_smoothScrollTimer
;
142 inline QPointF
AbstractItemView::mapToViewport(const QPointF
&point
) const
144 return point
+ QPointF(0, m_scrollBar
->value());
147 inline QRectF
AbstractItemView::mapToViewport(const QRectF
&rect
) const
149 return rect
.translated(0, m_scrollBar
->value());
152 inline QPointF
AbstractItemView::mapFromViewport(const QPointF
&point
) const
154 return point
- QPointF(0, m_scrollBar
->value());
157 inline QRectF
AbstractItemView::mapFromViewport(const QRectF
&rect
) const
159 return rect
.translated(0, -m_scrollBar
->value());
162 #endif // ABSTRACTITEMVIEW_H