]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincolumnwidget.h
Factorize all the view-related action handling to DolphinViewActionHandler, to remove...
[dolphin.git] / src / dolphincolumnwidget.h
1 /***************************************************************************
2 * Copyright (C) 2007 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 DOLPHINCOLUMNWIDGET_H
21 #define DOLPHINCOLUMNWIDGET_H
22
23 #include <QFont>
24 #include <QListView>
25 #include <QSize>
26 #include <QStyleOption>
27
28 #include <kurl.h>
29
30 class DolphinColumnView;
31 class DolphinModel;
32 class DolphinSortFilterProxyModel;
33 class KDirLister;
34 class KJob;
35 class KFileItem;
36 class KFileItemList;
37 class QPixmap;
38 namespace KIO
39 {
40 class PreviewJob;
41 }
42
43 /**
44 * Represents one column inside the DolphinColumnView and has been
45 * extended to respect view options and hovering information.
46 */
47 class DolphinColumnWidget : public QListView
48 {
49 Q_OBJECT
50
51 public:
52 DolphinColumnWidget(QWidget* parent,
53 DolphinColumnView* columnView,
54 const KUrl& url);
55 virtual ~DolphinColumnWidget();
56
57 /** Sets the size of the icons. */
58 void setDecorationSize(const QSize& size);
59
60 /**
61 * An active column is defined as column, which shows the same URL
62 * as indicated by the URL navigator. The active column is usually
63 * drawn in a lighter color. All operations are applied to this column.
64 */
65 void setActive(bool active);
66 bool isActive() const;
67
68 /**
69 * Sets the directory URL of the child column that is shown next to
70 * this column. This property is only used for a visual indication
71 * of the shown directory, it does not trigger a loading of the model.
72 */
73 void setChildUrl(const KUrl& url);
74 const KUrl& childUrl() const;
75
76 /** Sets the directory URL that is shown inside the column widget. */
77 void setUrl(const KUrl& url);
78
79 /** Returns the directory URL that is shown inside the column widget. */
80 const KUrl& url() const;
81
82 /** Reloads the directory DolphinColumnWidget::url(). */
83 void reload();
84
85 void setShowHiddenFiles(bool show);
86 void setShowPreview(bool show);
87
88 /**
89 * Updates the background color dependent from the activation state
90 * \a isViewActive of the column view.
91 */
92 void updateBackground();
93
94 /**
95 * Filters the currently shown items by \a nameFilter. All items
96 * which contain the given filter string will be shown.
97 */
98 void setNameFilter(const QString& nameFilter);
99
100 protected:
101 virtual QStyleOptionViewItem viewOptions() const;
102 virtual void startDrag(Qt::DropActions supportedActions);
103 virtual void dragEnterEvent(QDragEnterEvent* event);
104 virtual void dragLeaveEvent(QDragLeaveEvent* event);
105 virtual void dragMoveEvent(QDragMoveEvent* event);
106 virtual void dropEvent(QDropEvent* event);
107 virtual void paintEvent(QPaintEvent* event);
108 virtual void mousePressEvent(QMouseEvent* event);
109 virtual void keyPressEvent(QKeyEvent* event);
110 virtual void contextMenuEvent(QContextMenuEvent* event);
111 virtual void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
112
113 private slots:
114 /**
115 * If the item specified by \a index is a directory, then this
116 * directory will be loaded in a new column. If the item is a
117 * file, the corresponding application will get started.
118 */
119 void triggerItem(const QModelIndex& index);
120
121 /**
122 * Generates a preview image for each file item in \a items.
123 * The current preview settings (maximum size, 'Show Preview' menu)
124 * are respected.
125 */
126 void generatePreviews(const KFileItemList& items);
127
128 /**
129 * Replaces the icon of the item \a item by the preview pixmap
130 * \a pixmap.
131 */
132 void replaceIcon(const KFileItem& item, const QPixmap& pixmap);
133
134 void slotEntered(const QModelIndex& index);
135
136 /**
137 * Is invoked when the preview job has been finished and
138 * set m_previewJob to 0.
139 */
140 void slotPreviewJobFinished(KJob* job);
141
142 private:
143 /** Used by DolphinColumnWidget::setActive(). */
144 void activate();
145
146 /** Used by DolphinColumnWidget::setActive(). */
147 void deactivate();
148
149 /**
150 * Returns true, if the item \a item has been cut into
151 * the clipboard.
152 */
153 bool isCutItem(const KFileItem& item) const;
154
155 KFileItem itemForIndex(const QModelIndex& index) const;
156
157 private:
158 bool m_active;
159 bool m_showPreview;
160 DolphinColumnView* m_view;
161 KUrl m_url; // URL of the directory that is shown
162 KUrl m_childUrl; // URL of the next column that is shown
163
164 QFont m_font;
165 QSize m_decorationSize;
166
167 KDirLister* m_dirLister;
168 DolphinModel* m_dolphinModel;
169 DolphinSortFilterProxyModel* m_proxyModel;
170
171 KIO::PreviewJob* m_previewJob;
172
173 bool m_dragging; // TODO: remove this property when the issue #160611 is solved in Qt 4.4
174 QRect m_dropRect; // TODO: remove this property when the issue #160611 is solved in Qt 4.4
175 };
176
177 inline bool DolphinColumnWidget::isActive() const
178 {
179 return m_active;
180 }
181
182 inline void DolphinColumnWidget::setChildUrl(const KUrl& url)
183 {
184 m_childUrl = url;
185 }
186
187 inline const KUrl& DolphinColumnWidget::childUrl() const
188 {
189 return m_childUrl;
190 }
191
192 inline void DolphinColumnWidget::setUrl(const KUrl& url)
193 {
194 if (url != m_url) {
195 m_url = url;
196 reload();
197 }
198 }
199
200 inline const KUrl& DolphinColumnWidget::url() const
201 {
202 return m_url;
203 }
204
205 #endif