]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincolumnview.h
Move code for initializing and handling view extensions to the new class ViewExtensio...
[dolphin.git] / src / dolphincolumnview.h
1 /***************************************************************************
2 * Copyright (C) 2007-2009 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 DOLPHINCOLUMNVIEW_H
21 #define DOLPHINCOLUMNVIEW_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 DolphinColumnViewContainer;
33 class DolphinModel;
34 class DolphinSortFilterProxyModel;
35 class DolphinDirLister;
36 class DolphinViewAutoScroller;
37 class KFileItem;
38 class KFileItemList;
39 class SelectionManager;
40 class ViewExtensionsFactory;
41
42 /**
43 * Represents one column inside the DolphinColumnViewContainer.
44 */
45 class DolphinColumnView : public QListView
46 {
47 Q_OBJECT
48
49 public:
50 DolphinColumnView(QWidget* parent,
51 DolphinColumnViewContainer* container,
52 const KUrl& url);
53 virtual ~DolphinColumnView();
54
55 /**
56 * An active column is defined as column, which shows the same URL
57 * as indicated by the URL navigator. The active column is usually
58 * drawn in a lighter color. All operations are applied to this column.
59 */
60 void setActive(bool active);
61 bool isActive() const;
62
63 /**
64 * Sets the directory URL of the child column that is shown next to
65 * this column. This property is only used for a visual indication
66 * of the shown directory, it does not trigger a loading of the model.
67 */
68 void setChildUrl(const KUrl& url);
69 const KUrl& childUrl() const;
70
71 /** Sets the directory URL that is shown inside the column widget. */
72 void setUrl(const KUrl& url);
73
74 /** Returns the directory URL that is shown inside the column widget. */
75 const KUrl& url() const;
76
77 /**
78 * Updates the background color dependent from the activation state
79 * \a isViewActive of the column view.
80 */
81 void updateBackground();
82
83 /**
84 * Returns the item on the position \a pos. The KFileItem instance
85 * is null if no item is below the position.
86 */
87 KFileItem itemAt(const QPoint& pos) const;
88
89 protected:
90 virtual QStyleOptionViewItem viewOptions() const;
91 virtual void startDrag(Qt::DropActions supportedActions);
92 virtual void dragEnterEvent(QDragEnterEvent* event);
93 virtual void dragLeaveEvent(QDragLeaveEvent* event);
94 virtual void dragMoveEvent(QDragMoveEvent* event);
95 virtual void dropEvent(QDropEvent* event);
96 virtual void paintEvent(QPaintEvent* event);
97 virtual void mousePressEvent(QMouseEvent* event);
98 virtual void keyPressEvent(QKeyEvent* event);
99 virtual void contextMenuEvent(QContextMenuEvent* event);
100 virtual void wheelEvent(QWheelEvent* event);
101 virtual void leaveEvent(QEvent* event);
102 virtual void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
103 virtual void currentChanged(const QModelIndex& current, const QModelIndex& previous);
104
105 private slots:
106 void setNameFilter(const QString& nameFilter);
107 void setZoomLevel(int level);
108
109 void slotEntered(const QModelIndex& index);
110 void requestActivation();
111 void updateFont();
112
113 void slotShowPreviewChanged();
114
115 private:
116 /** Used by DolphinColumnView::setActive(). */
117 void activate();
118
119 /** Used by DolphinColumnView::setActive(). */
120 void deactivate();
121
122 void updateDecorationSize(bool showPreview);
123
124 private:
125 bool m_active;
126 DolphinColumnViewContainer* m_container;
127 SelectionManager* m_selectionManager;
128 DolphinViewAutoScroller* m_autoScroller;
129 ViewExtensionsFactory* m_extensionsFactory;
130 KUrl m_url; // URL of the directory that is shown
131 KUrl m_childUrl; // URL of the next column that is shown
132
133 QFont m_font;
134 QSize m_decorationSize;
135
136 DolphinDirLister* m_dirLister;
137 DolphinModel* m_dolphinModel;
138 DolphinSortFilterProxyModel* m_proxyModel;
139
140 QRect m_dropRect;
141
142 friend class DolphinColumnViewContainer;
143 };
144
145 inline bool DolphinColumnView::isActive() const
146 {
147 return m_active;
148 }
149
150 inline void DolphinColumnView::setChildUrl(const KUrl& url)
151 {
152 m_childUrl = url;
153 }
154
155 inline const KUrl& DolphinColumnView::childUrl() const
156 {
157 return m_childUrl;
158 }
159
160 inline void DolphinColumnView::setUrl(const KUrl& url)
161 {
162 if (url != m_url) {
163 m_url = url;
164 //reload();
165 }
166 }
167
168 inline const KUrl& DolphinColumnView::url() const
169 {
170 return m_url;
171 }
172
173 #endif