2 * Copyright © 2008 Fredrik Höglund <fredrik@kde.org>
3 * Copyright © 2008 Rafael Fernández López <ereslibre@kde.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
24 #include "abstractitemview.h"
26 #include <QAbstractItemDelegate>
31 #include <QBasicTimer>
36 class KFileItemDelegate
;
38 class KFilePreviewGenerator
;
40 class QItemSelectionModel
;
42 class QStyleOptionViewItemV4
;
52 ViewItem() : rect(QRect()), layouted(false), needSizeAdjust(true) {}
55 bool needSizeAdjust
:1;
58 class IconView
: public AbstractItemView
62 Q_PROPERTY(QSize gridSize READ gridSize WRITE setGridSize
)
63 Q_PROPERTY(bool wordWrap READ wordWrap WRITE setWordWrap
)
64 Q_PROPERTY(bool alignToGrid READ alignToGrid WRITE setAlignToGrid
)
65 Q_PROPERTY(bool iconsMoveable READ iconsMoveable WRITE setIconsMoveable
)
66 Q_PROPERTY(bool drawShadows READ drawShadows WRITE setDrawShadows
)
67 Q_PROPERTY(QListView::Flow flow READ flow WRITE setFlow
)
70 IconView(QGraphicsWidget
*parent
);
73 void setModel(QAbstractItemModel
*model
);
75 void setGridSize(const QSize
&gridSize
);
76 QSize
gridSize() const;
78 void setIconSize(const QSize
&gridSize
);
80 void setWordWrap(bool on
);
81 bool wordWrap() const;
83 void setFlow(QListView::Flow flow
);
84 QListView::Flow
flow() const;
86 void setAlignToGrid(bool on
);
87 bool alignToGrid() const;
89 void setIconsMoveable(bool on
);
90 bool iconsMoveable() const;
92 void setDrawShadows(bool on
);
93 bool drawShadows() const;
95 void setIconPositionsData(const QStringList
&data
);
96 QStringList
iconPositionsData() const;
98 void renameSelectedIcon();
99 bool renameInProgress() const;
101 QRect
visualRect(const QModelIndex
&index
) const;
102 QRegion
visualRegion(const QModelIndex
&index
) const;
103 QModelIndex
indexAt(const QPointF
&point
) const;
105 void paint(QPainter
*painter
, const QStyleOptionGraphicsItem
*option
, QWidget
*widget
= 0);
108 void indexesMoved(const QModelIndexList
&indexes
);
112 bool indexIntersectsRect(const QModelIndex
&index
, const QRect
&rect
) const;
113 void startDrag(const QPointF
&pos
, QWidget
*widget
);
114 void focusInEvent(QFocusEvent
*event
);
115 void focusOutEvent(QFocusEvent
*event
);
116 void hoverEnterEvent(QGraphicsSceneHoverEvent
*event
);
117 void hoverLeaveEvent(QGraphicsSceneHoverEvent
*event
);
118 void hoverMoveEvent(QGraphicsSceneHoverEvent
*event
);
119 void mousePressEvent(QGraphicsSceneMouseEvent
*event
);
120 void mouseReleaseEvent(QGraphicsSceneMouseEvent
*event
);
121 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent
*event
);
122 void mouseMoveEvent(QGraphicsSceneMouseEvent
*event
);
123 void wheelEvent(QGraphicsSceneWheelEvent
*event
);
124 void contextMenuEvent(QGraphicsSceneContextMenuEvent
*event
);
125 void dragEnterEvent(QGraphicsSceneDragDropEvent
*event
);
126 void dragMoveEvent(QGraphicsSceneDragDropEvent
*event
);
127 void dropEvent(QGraphicsSceneDragDropEvent
*event
);
128 void timerEvent(QTimerEvent
*event
);
129 void changeEvent(QEvent
*event
);
130 void resizeEvent(QGraphicsSceneResizeEvent
*event
);
132 void rowsInserted(const QModelIndex
&parent
, int first
, int last
);
133 void rowsRemoved(const QModelIndex
&parent
, int first
, int last
);
135 void layoutChanged();
136 void dataChanged(const QModelIndex
&topLeft
, const QModelIndex
&bottomRight
);
137 void commitData(QWidget
*editor
);
138 void closeEditor(QWidget
*editor
, QAbstractItemDelegate::EndEditHint hint
);
140 void finishedScrolling();
143 void listingStarted(const KUrl
&url
);
145 void listingCompleted();
146 void listingCanceled();
147 void listingError(const QString
&message
);
148 void itemsDeleted(const KFileItemList
&items
);
151 void paintErrorMessage(QPainter
*painter
, const QRect
&rect
, const QString
&message
) const;
152 int columnsForWidth(qreal width
) const;
153 int rowsForHeight(qreal height
) const;
154 QPoint
nextGridPosition(const QPoint
&prevPos
, const QSize
&gridSize
, const QRect
&contentRect
) const;
155 QPoint
findNextEmptyPosition(const QPoint
&prevPos
, const QSize
&gridSize
, const QRect
&contentRect
) const;
157 void alignIconsToGrid();
158 QRect
itemsBoundingRect() const;
159 bool doLayoutSanityCheck();
160 void saveIconPositions() const;
161 void loadIconPositions();
162 void updateScrollBar();
163 void updateScrollBarGeometry();
164 void updateTextShadows(const QColor
&textColor
);
165 QStyleOptionViewItemV4
viewOptions() const;
168 QVector
<ViewItem
> m_items
;
169 QHash
<QString
, QPoint
> m_savedPositions
;
170 mutable QCache
<quint64
, QRegion
> m_regionCache
;
176 bool m_needPostLayoutPass
;
177 bool m_initialListing
;
178 bool m_positionsLoaded
;
180 bool m_dragInProgress
;
185 QPersistentModelIndex m_hoveredIndex
;
186 QPersistentModelIndex m_pressedIndex
;
187 QPersistentModelIndex m_editorIndex
;
189 QPointF m_buttonDownPos
;
191 QListView::Flow m_flow
;
192 QString m_errorMessage
;
193 QPoint m_lastDeletedPos
;
194 QPoint m_currentLayoutPos
;
196 QBasicTimer m_delayedLayoutTimer
;
197 QBasicTimer m_delayedRelayoutTimer
;
198 QBasicTimer m_delayedCacheClearTimer
;