]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/dolphinfileitemdelegate.h
Use capitalized KDE includes
[dolphin.git] / src / views / dolphinfileitemdelegate.h
1 /***************************************************************************
2 * Copyright (C) 2008 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 DOLPHINFILEITEMDELEGATE_H
21 #define DOLPHINFILEITEMDELEGATE_H
22
23 #include <KFileItemDelegate>
24 #include <views/dolphinmodel.h>
25
26 class QAbstractProxyModel;
27
28 /**
29 * Extends KFileItemDelegate by the ability to show the hover effect
30 * and the selection in a minimized way for the name column of
31 * the details view.
32 *
33 * Note that this is a workaround, as Qt does not support having custom
34 * shapes within the visual rect of an item view. The visual part of
35 * workaround is handled inside DolphinFileItemDelegate, the behavior
36 * changes are handled in DolphinTreeView.
37 */
38 class DolphinFileItemDelegate : public KFileItemDelegate
39 {
40 public:
41 explicit DolphinFileItemDelegate(QObject* parent = 0);
42 virtual ~DolphinFileItemDelegate();
43
44 /**
45 * If \a minimized is true, the hover effect and the selection are
46 * only drawn above the icon and text of an item. Per default
47 * \a minimized is false, which means that the whole visual rect is
48 * used like in KFileItemDelegate.
49 */
50 void setMinimizedNameColumn(bool minimized);
51 bool hasMinimizedNameColumn() const;
52
53 virtual void paint(QPainter* painter,
54 const QStyleOptionViewItem& option,
55 const QModelIndex& index) const;
56
57 /**
58 * Returns the minimized width of the name column for the name \a name. This method
59 * is also used in DolphinDetailsView to handle the selection of items correctly.
60 */
61 static int nameColumnWidth(const QString& name, const QStyleOptionViewItem& option);
62
63 private:
64 static void adjustOptionWidth(QStyleOptionViewItemV4& option,
65 const QAbstractProxyModel* proxyModel,
66 const DolphinModel* dolphinModel,
67 const QModelIndex& index);
68
69 static void adjustOptionTextColor(QStyleOptionViewItemV4& option,
70 KVersionControlPlugin::VersionState state);
71
72 QPixmap emblemForState(KVersionControlPlugin::VersionState state, const QSize& size) const;
73
74 private:
75 bool m_hasMinimizedNameColumn;
76 mutable QSize m_cachedSize;
77 mutable QPixmap m_cachedEmblems[KVersionControlPlugin::LocallyModifiedUnstagedVersion + 1];
78 };
79
80 inline void DolphinFileItemDelegate::setMinimizedNameColumn(bool minimized)
81 {
82 m_hasMinimizedNameColumn = minimized;
83 }
84
85 inline bool DolphinFileItemDelegate::hasMinimizedNameColumn() const
86 {
87 return m_hasMinimizedNameColumn;
88 }
89
90 #endif