]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphiniconsview.h
Make sort/descending available in dolphinpart
[dolphin.git] / src / dolphiniconsview.h
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program 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 *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #ifndef DOLPHINICONSVIEW_H
21 #define DOLPHINICONSVIEW_H
22
23 #include <kcategorizedview.h>
24
25 #include <kfileitem.h>
26 #include <kfileitemdelegate.h>
27
28 #include <QFont>
29 #include <QSize>
30 #include <QStyleOption>
31
32 #include <libdolphin_export.h>
33
34 class DolphinController;
35 class DolphinCategoryDrawer;
36
37 /**
38 * @brief Represents the view, where each item is shown as an icon.
39 *
40 * It is also possible that instead of the icon a preview of the item
41 * content is shown.
42 */
43 class LIBDOLPHINPRIVATE_EXPORT DolphinIconsView : public KCategorizedView
44 {
45 Q_OBJECT
46
47 public:
48 explicit DolphinIconsView(QWidget* parent, DolphinController* controller);
49 virtual ~DolphinIconsView();
50
51 /** @see QAbstractItemView::visualRect() */
52 virtual QRect visualRect(const QModelIndex& index) const;
53
54 protected:
55 virtual QStyleOptionViewItem viewOptions() const;
56 virtual void contextMenuEvent(QContextMenuEvent* event);
57 virtual void mousePressEvent(QMouseEvent* event);
58 virtual void startDrag(Qt::DropActions supportedActions);
59 virtual void dragEnterEvent(QDragEnterEvent* event);
60 virtual void dragLeaveEvent(QDragLeaveEvent* event);
61 virtual void dragMoveEvent(QDragMoveEvent* event);
62 virtual void dropEvent(QDropEvent* event);
63 virtual void paintEvent(QPaintEvent* event);
64 virtual void keyPressEvent(QKeyEvent* event);
65 virtual void wheelEvent(QWheelEvent* event);
66
67 private slots:
68 void triggerItem(const QModelIndex& index);
69 void slotEntered(const QModelIndex& index);
70 void slotShowPreviewChanged();
71 void slotAdditionalInfoChanged(const KFileItemDelegate::InformationList& info);
72 void zoomIn();
73 void zoomOut();
74
75 private:
76 bool isZoomInPossible() const;
77 bool isZoomOutPossible() const;
78
79 /** Returns the increased icon size for the size \a size. */
80 int increasedIconSize(int size) const;
81
82 /** Returns the decreased icon size for the size \a size. */
83 int decreasedIconSize(int size) const;
84
85 /**
86 * Updates the size of the grid depending on the state
87 * of \a showPreview and \a additionalInfoCount.
88 */
89 void updateGridSize(bool showPreview, int additionalInfoCount);
90
91 KFileItem itemForIndex(const QModelIndex& index) const;
92
93 /**
94 * Returns the number of additional information lines that should
95 * be shown below the item name.
96 */
97 int additionalInfoCount() const;
98
99 private:
100 DolphinController* m_controller;
101 DolphinCategoryDrawer* m_categoryDrawer;
102
103 QFont m_font;
104 QSize m_decorationSize;
105 QStyleOptionViewItem::Position m_decorationPosition;
106 Qt::Alignment m_displayAlignment;
107
108 QSize m_itemSize;
109
110 bool m_dragging; // TODO: remove this property when the issue #160611 is solved in Qt 4.4
111 QRect m_dropRect; // TODO: remove this property when the issue #160611 is solved in Qt 4.4
112 };
113
114 #endif