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