1 /***************************************************************************
2 * Copyright (C) 2008 by Peter Penz <peter.penz@gmx.at> *
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
41 explicit DolphinFileItemDelegate(QObject
* parent
= 0);
42 virtual ~DolphinFileItemDelegate();
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.
50 void setMinimizedNameColumn(bool minimized
);
51 bool hasMinimizedNameColumn() const;
53 virtual void paint(QPainter
* painter
,
54 const QStyleOptionViewItem
& option
,
55 const QModelIndex
& index
) const;
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.
61 static int nameColumnWidth(const QString
& name
, const QStyleOptionViewItem
& option
);
64 static void adjustOptionWidth(QStyleOptionViewItemV4
& option
,
65 const QAbstractProxyModel
* proxyModel
,
66 const DolphinModel
* dolphinModel
,
67 const QModelIndex
& index
);
69 static void adjustOptionTextColor(QStyleOptionViewItemV4
& option
,
70 KVersionControlPlugin::VersionState state
);
72 QPixmap
emblemForState(KVersionControlPlugin::VersionState state
, const QSize
& size
) const;
75 bool m_hasMinimizedNameColumn
;
76 mutable QSize m_cachedSize
;
77 mutable QPixmap m_cachedEmblems
[KVersionControlPlugin::LocallyModifiedUnstagedVersion
+ 1];
80 inline void DolphinFileItemDelegate::setMinimizedNameColumn(bool minimized
)
82 m_hasMinimizedNameColumn
= minimized
;
85 inline bool DolphinFileItemDelegate::hasMinimizedNameColumn() const
87 return m_hasMinimizedNameColumn
;