]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincolumnwidget.h
Added Soprano include dir
[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 KDirLister;
34 class KFileItem;
35 class KFileItemList;
36 class QPixmap;
37
38 /**
39 * Represents one column inside the DolphinColumnView and has been
40 * extended to respect view options and hovering information.
41 */
42 class DolphinColumnWidget : public QListView
43 {
44 Q_OBJECT
45
46 public:
47 DolphinColumnWidget(QWidget* parent,
48 DolphinColumnView* columnView,
49 const KUrl& url);
50 virtual ~DolphinColumnWidget();
51
52 /** Sets the size of the icons. */
53 void setDecorationSize(const QSize& size);
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 /** Reloads the directory DolphinColumnWidget::url(). */
78 void reload();
79
80 void setShowHiddenFiles(bool show);
81 void setShowPreview(bool show);
82
83 /**
84 * Updates the background color dependent from the activation state
85 * \a isViewActive of the column view.
86 */
87 void updateBackground();
88
89 /**
90 * Filters the currently shown items by \a nameFilter. All items
91 * which contain the given filter string will be shown.
92 */
93 void setNameFilter(const QString& nameFilter);
94
95 protected:
96 virtual QStyleOptionViewItem viewOptions() const;
97 virtual void startDrag(Qt::DropActions supportedActions);
98 virtual void dragEnterEvent(QDragEnterEvent* event);
99 virtual void dragLeaveEvent(QDragLeaveEvent* event);
100 virtual void dragMoveEvent(QDragMoveEvent* event);
101 virtual void dropEvent(QDropEvent* event);
102 virtual void paintEvent(QPaintEvent* event);
103 virtual void mousePressEvent(QMouseEvent* event);
104 virtual void keyPressEvent(QKeyEvent* event);
105 virtual void contextMenuEvent(QContextMenuEvent* event);
106 virtual void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
107
108 private slots:
109 /**
110 * If the item specified by \a index is a directory, then this
111 * directory will be loaded in a new column. If the item is a
112 * file, the corresponding application will get started.
113 */
114 void triggerItem(const QModelIndex& index);
115
116 /**
117 * Generates a preview image for each file item in \a items.
118 * The current preview settings (maximum size, 'Show Preview' menu)
119 * are respected.
120 */
121 void generatePreviews(const KFileItemList& items);
122
123 /**
124 * Replaces the icon of the item \a item by the preview pixmap
125 * \a pixmap.
126 */
127 void showPreview(const KFileItem& item, const QPixmap& pixmap);
128
129 void slotEntered(const QModelIndex& index);
130
131 private:
132 /** Used by DolphinColumnWidget::setActive(). */
133 void activate();
134
135 /** Used by DolphinColumnWidget::setActive(). */
136 void deactivate();
137
138 /**
139 * Returns true, if the item \a item has been cut into
140 * the clipboard.
141 */
142 bool isCutItem(const KFileItem& item) const;
143
144 KFileItem itemForIndex(const QModelIndex& index) const;
145
146 private:
147 bool m_active;
148 bool m_showPreview;
149 DolphinColumnView* m_view;
150 KUrl m_url; // URL of the directory that is shown
151 KUrl m_childUrl; // URL of the next column that is shown
152
153 QFont m_font;
154 QSize m_decorationSize;
155
156 KDirLister* m_dirLister;
157 DolphinModel* m_dolphinModel;
158 DolphinSortFilterProxyModel* m_proxyModel;
159
160 bool m_dragging; // TODO: remove this property when the issue #160611 is solved in Qt 4.4
161 QRect m_dropRect; // TODO: remove this property when the issue #160611 is solved in Qt 4.4
162 };
163
164 inline bool DolphinColumnWidget::isActive() const
165 {
166 return m_active;
167 }
168
169 inline void DolphinColumnWidget::setChildUrl(const KUrl& url)
170 {
171 m_childUrl = url;
172 }
173
174 inline const KUrl& DolphinColumnWidget::childUrl() const
175 {
176 return m_childUrl;
177 }
178
179 inline void DolphinColumnWidget::setUrl(const KUrl& url)
180 {
181 if (url != m_url) {
182 m_url = url;
183 reload();
184 }
185 }
186
187 inline const KUrl& DolphinColumnWidget::url() const
188 {
189 return m_url;
190 }
191
192 #endif