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