]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincolumnwidget.h
Move the Ctrl-wheel zoom handling to dolphinview.
[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 wheelEvent(QWheelEvent* event);
113 virtual void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
114
115 private slots:
116 /**
117 * If the item specified by \a index is a directory, then this
118 * directory will be loaded in a new column. If the item is a
119 * file, the corresponding application will get started.
120 */
121 void triggerItem(const QModelIndex& index);
122
123 void slotEntered(const QModelIndex& index);
124
125 void requestActivation();
126
127 private:
128 /** Used by DolphinColumnWidget::setActive(). */
129 void activate();
130
131 /** Used by DolphinColumnWidget::setActive(). */
132 void deactivate();
133
134 KFileItem itemForIndex(const QModelIndex& index) const;
135
136 private:
137 bool m_active;
138 DolphinColumnView* m_view;
139 KUrl m_url; // URL of the directory that is shown
140 KUrl m_childUrl; // URL of the next column that is shown
141
142 QFont m_font;
143 QSize m_decorationSize;
144
145 KDirLister* m_dirLister;
146 DolphinModel* m_dolphinModel;
147 DolphinSortFilterProxyModel* m_proxyModel;
148
149 IconManager* m_iconManager;
150
151 bool m_dragging; // TODO: remove this property when the issue #160611 is solved in Qt 4.4
152 QRect m_dropRect; // TODO: remove this property when the issue #160611 is solved in Qt 4.4
153 };
154
155 inline bool DolphinColumnWidget::isActive() const
156 {
157 return m_active;
158 }
159
160 inline void DolphinColumnWidget::setChildUrl(const KUrl& url)
161 {
162 m_childUrl = url;
163 }
164
165 inline const KUrl& DolphinColumnWidget::childUrl() const
166 {
167 return m_childUrl;
168 }
169
170 inline void DolphinColumnWidget::setUrl(const KUrl& url)
171 {
172 if (url != m_url) {
173 m_url = url;
174 reload();
175 }
176 }
177
178 inline const KUrl& DolphinColumnWidget::url() const
179 {
180 return m_url;
181 }
182
183 #endif