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