]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/dolphinfileitemdelegate.h
Details view optimization
[dolphin.git] / src / views / dolphinfileitemdelegate.h
1 /***************************************************************************
2 * Copyright (C) 2008 by Peter Penz <peter.penz19@gmail.com> *
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 Q_OBJECT
41 public:
42 explicit DolphinFileItemDelegate(QObject* parent = 0);
43 virtual ~DolphinFileItemDelegate();
44
45 /**
46 * If \a minimized is true, the hover effect and the selection are
47 * only drawn above the icon and text of an item. Per default
48 * \a minimized is false, which means that the whole visual rect is
49 * used like in KFileItemDelegate.
50 */
51 void setMinimizedNameColumn(bool minimized);
52 bool hasMinimizedNameColumn() const;
53
54 virtual void paint(QPainter* painter,
55 const QStyleOptionViewItem& option,
56 const QModelIndex& index) const;
57
58 /**
59 * Returns the minimized width of the name column for the name \a name. This method
60 * is also used in DolphinDetailsView to handle the selection of items correctly.
61 */
62 static int nameColumnWidth(const QString& name, const QStyleOptionViewItem& option);
63
64 private slots:
65 void handleDisplayPaletteChange();
66
67 private:
68 static void adjustOptionWidth(QStyleOptionViewItemV4& option,
69 const QAbstractProxyModel* proxyModel,
70 const DolphinModel* dolphinModel,
71 const QModelIndex& index);
72
73 static void adjustOptionTextColor(QStyleOptionViewItemV4& option,
74 KVersionControlPlugin::VersionState state);
75
76 QPixmap emblemForState(KVersionControlPlugin::VersionState state, const QSize& size) const;
77
78 private:
79 bool m_hasMinimizedNameColumn;
80 mutable QSize m_cachedSize;
81 mutable QPixmap m_cachedEmblems[KVersionControlPlugin::LocallyModifiedUnstagedVersion + 1];
82 mutable QColor m_cachedInactiveTextColor;
83 mutable bool m_cachedInactiveTextColorDirty;
84 };
85
86 inline void DolphinFileItemDelegate::setMinimizedNameColumn(bool minimized)
87 {
88 m_hasMinimizedNameColumn = minimized;
89 }
90
91 inline bool DolphinFileItemDelegate::hasMinimizedNameColumn() const
92 {
93 return m_hasMinimizedNameColumn;
94 }
95
96 #endif