1 /***************************************************************************
2 * Copyright (C) 2008 by Peter Penz <peter.penz19@gmail.com> *
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. *
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. *
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 ***************************************************************************/
20 #ifndef DOLPHINFILEITEMDELEGATE_H
21 #define DOLPHINFILEITEMDELEGATE_H
23 #include <KFileItemDelegate>
24 #include <views/dolphinmodel.h>
26 class QAbstractProxyModel
;
29 * Extends KFileItemDelegate by the ability to show the hover effect
30 * and the selection in a minimized way for the name column of
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.
38 class DolphinFileItemDelegate
: public KFileItemDelegate
42 explicit DolphinFileItemDelegate(QObject
* parent
= 0);
43 virtual ~DolphinFileItemDelegate();
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.
51 void setMinimizedNameColumn(bool minimized
);
52 bool hasMinimizedNameColumn() const;
54 virtual void paint(QPainter
* painter
,
55 const QStyleOptionViewItem
& option
,
56 const QModelIndex
& index
) const;
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.
62 static int nameColumnWidth(const QString
& name
, const QStyleOptionViewItem
& option
);
65 void handleDisplayPaletteChange();
68 static void adjustOptionWidth(QStyleOptionViewItemV4
& option
,
69 const QAbstractProxyModel
* proxyModel
,
70 const DolphinModel
* dolphinModel
,
71 const QModelIndex
& index
);
73 static void adjustOptionTextColor(QStyleOptionViewItemV4
& option
,
74 KVersionControlPlugin::VersionState state
);
76 QPixmap
emblemForState(KVersionControlPlugin::VersionState state
, const QSize
& size
) const;
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
;
86 inline void DolphinFileItemDelegate::setMinimizedNameColumn(bool minimized
)
88 m_hasMinimizedNameColumn
= minimized
;
91 inline bool DolphinFileItemDelegate::hasMinimizedNameColumn() const
93 return m_hasMinimizedNameColumn
;