]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincolumnwidget.h
a lot of more KUrl::path() -> KUrl::toLocalFile() changes (mostly after a check for...
[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 DolphinDirLister;
36 class DolphinViewAutoScroller;
37 class KFilePreviewGenerator;
38 class KJob;
39 class KFileItem;
40 class KFileItemList;
41 class SelectionManager;
42 class ToolTipManager;
43 class QPixmap;
44
45 /**
46 * Represents one column inside the DolphinColumnView and has been
47 * extended to respect view options and hovering information.
48 */
49 class DolphinColumnWidget : public QListView
50 {
51 Q_OBJECT
52
53 public:
54 DolphinColumnWidget(QWidget* parent,
55 DolphinColumnView* columnView,
56 const KUrl& url);
57 virtual ~DolphinColumnWidget();
58
59 /** Sets the size of the icons. */
60 void setDecorationSize(const QSize& size);
61
62 /**
63 * An active column is defined as column, which shows the same URL
64 * as indicated by the URL navigator. The active column is usually
65 * drawn in a lighter color. All operations are applied to this column.
66 */
67 void setActive(bool active);
68 bool isActive() const;
69
70 /**
71 * Sets the directory URL of the child column that is shown next to
72 * this column. This property is only used for a visual indication
73 * of the shown directory, it does not trigger a loading of the model.
74 */
75 void setChildUrl(const KUrl& url);
76 const KUrl& childUrl() const;
77
78 /** Sets the directory URL that is shown inside the column widget. */
79 void setUrl(const KUrl& url);
80
81 /** Returns the directory URL that is shown inside the column widget. */
82 const KUrl& url() const;
83
84 /** Reloads the directory DolphinColumnWidget::url(). */
85 void reload();
86
87 void setSorting(DolphinView::Sorting sorting);
88 void setSortOrder(Qt::SortOrder order);
89 void setShowHiddenFiles(bool show);
90 void setShowPreview(bool show);
91
92 /**
93 * Updates the background color dependent from the activation state
94 * \a isViewActive of the column view.
95 */
96 void updateBackground();
97
98 /**
99 * Filters the currently shown items by \a nameFilter. All items
100 * which contain the given filter string will be shown.
101 */
102 void setNameFilter(const QString& nameFilter);
103
104 /**
105 * Does an inline editing for the item \a item.
106 */
107 void editItem(const KFileItem& item);
108
109 /**
110 * Returns the item on the position \a pos. The KFileItem instance
111 * is null if no item is below the position.
112 */
113 KFileItem itemAt(const QPoint& pos) const;
114
115 KFileItemList selectedItems() const;
116
117 /**
118 * Returns the MIME data for the selected items.
119 */
120 QMimeData* selectionMimeData() const;
121
122 protected:
123 virtual QStyleOptionViewItem viewOptions() const;
124 virtual void startDrag(Qt::DropActions supportedActions);
125 virtual void dragEnterEvent(QDragEnterEvent* event);
126 virtual void dragLeaveEvent(QDragLeaveEvent* event);
127 virtual void dragMoveEvent(QDragMoveEvent* event);
128 virtual void dropEvent(QDropEvent* event);
129 virtual void paintEvent(QPaintEvent* event);
130 virtual void mousePressEvent(QMouseEvent* event);
131 virtual void keyPressEvent(QKeyEvent* event);
132 virtual void contextMenuEvent(QContextMenuEvent* event);
133 virtual void wheelEvent(QWheelEvent* event);
134 virtual void leaveEvent(QEvent* event);
135 virtual void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
136 virtual void currentChanged(const QModelIndex& current, const QModelIndex& previous);
137
138 private slots:
139 void slotEntered(const QModelIndex& index);
140 void slotClicked(const QModelIndex& index);
141 void slotDoubleClicked(const QModelIndex& index);
142 void requestActivation();
143 void updateFont();
144
145 private:
146 /** Used by DolphinColumnWidget::setActive(). */
147 void activate();
148
149 /** Used by DolphinColumnWidget::setActive(). */
150 void deactivate();
151
152 private:
153 bool m_active;
154 DolphinColumnView* m_view;
155 SelectionManager* m_selectionManager;
156 DolphinViewAutoScroller* m_autoScroller;
157 KUrl m_url; // URL of the directory that is shown
158 KUrl m_childUrl; // URL of the next column that is shown
159
160 QFont m_font;
161 QSize m_decorationSize;
162
163 DolphinDirLister* m_dirLister;
164 DolphinModel* m_dolphinModel;
165 DolphinSortFilterProxyModel* m_proxyModel;
166
167 KFilePreviewGenerator* m_previewGenerator;
168
169 ToolTipManager* m_toolTipManager;
170
171 QRect m_dropRect;
172
173 friend class DolphinColumnView;
174 };
175
176 inline bool DolphinColumnWidget::isActive() const
177 {
178 return m_active;
179 }
180
181 inline void DolphinColumnWidget::setChildUrl(const KUrl& url)
182 {
183 m_childUrl = url;
184 }
185
186 inline const KUrl& DolphinColumnWidget::childUrl() const
187 {
188 return m_childUrl;
189 }
190
191 inline void DolphinColumnWidget::setUrl(const KUrl& url)
192 {
193 if (url != m_url) {
194 m_url = url;
195 reload();
196 }
197 }
198
199 inline const KUrl& DolphinColumnWidget::url() const
200 {
201 return m_url;
202 }
203
204 #endif