add more spacing
[personal-kdebase.git] / apps / plasma / applets / folderview / iconview.h
blob207d7ac52bfb6fbdcd2a81f726d080df887bfd5f
1 /*
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.
21 #ifndef ICONVIEW_H
22 #define ICONVIEW_H
24 #include "abstractitemview.h"
26 #include <QAbstractItemDelegate>
27 #include <QListView>
28 #include <QPointer>
29 #include <QCache>
30 #include <QTime>
31 #include <QBasicTimer>
34 class KUrl;
35 class KDirModel;
36 class KFileItemDelegate;
37 class KFileItemList;
38 class KFilePreviewGenerator;
39 class KNewMenu;
40 class QItemSelectionModel;
41 class ProxyModel;
42 class QStyleOptionViewItemV4;
43 class QScrollBar;
45 namespace Plasma
47 class ScrollBar;
50 struct ViewItem
52 ViewItem() : rect(QRect()), layouted(false), needSizeAdjust(true) {}
53 QRect rect;
54 bool layouted:1;
55 bool needSizeAdjust:1;
58 class IconView : public AbstractItemView
60 Q_OBJECT
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)
69 public:
70 IconView(QGraphicsWidget *parent);
71 ~IconView();
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);
107 signals:
108 void indexesMoved(const QModelIndexList &indexes);
109 void busy(bool);
111 protected:
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);
134 void modelReset();
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();
142 private slots:
143 void listingStarted(const KUrl &url);
144 void listingClear();
145 void listingCompleted();
146 void listingCanceled();
147 void listingError(const QString &message);
148 void itemsDeleted(const KFileItemList &items);
150 private:
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;
156 void layoutItems();
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;
167 private:
168 QVector<ViewItem> m_items;
169 QHash<QString, QPoint> m_savedPositions;
170 mutable QCache<quint64, QRegion> m_regionCache;
171 qreal m_margins[4];
172 int m_columns;
173 int m_rows;
174 int m_validRows;
175 bool m_layoutBroken;
176 bool m_needPostLayoutPass;
177 bool m_initialListing;
178 bool m_positionsLoaded;
179 bool m_doubleClick;
180 bool m_dragInProgress;
181 bool m_iconsLocked;
182 bool m_alignToGrid;
183 bool m_wordWrap;
184 bool m_drawShadows;
185 QPersistentModelIndex m_hoveredIndex;
186 QPersistentModelIndex m_pressedIndex;
187 QPersistentModelIndex m_editorIndex;
188 QRect m_rubberBand;
189 QPointF m_buttonDownPos;
190 QTime m_pressTime;
191 QListView::Flow m_flow;
192 QString m_errorMessage;
193 QPoint m_lastDeletedPos;
194 QPoint m_currentLayoutPos;
195 QSize m_gridSize;
196 QBasicTimer m_delayedLayoutTimer;
197 QBasicTimer m_delayedRelayoutTimer;
198 QBasicTimer m_delayedCacheClearTimer;
201 #endif