some more win32'fication to fix non-ascii filename handling
[kdelibs.git] / plasma / delegate.h
blobcff74b9d4083d262c72782f381e40940fec85b93
1 /*
2 Copyright 2007 Robert Knight <robertknight@gmail.com>
3 Copyright 2008 Marco Martin <notmart@gmail.com>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 #ifndef PLASMA_DELEGATE_H
22 #define PLASMA_DELEGATE_H
24 // Qt
25 #include <QtGui/QAbstractItemDelegate>
27 // Plasma
28 #include <plasma/plasma_export.h>
30 namespace Plasma
33 class DelegatePrivate;
35 /**
36 * @class Delegate plasma/delegate.h <Plasma/Delegate>
38 * Item delegate for rendering items in Plasma menus implemented with item views.
40 * The delegate makes use of its own data roles that are:
41 * SubTitleRole: the text of the subtitle
42 * SubTitleMandatoryRole: if the subtitle is to always be displayed
43 * (as default the subtitle is displayed only on mouse over)
44 * ColumnTypeRole: if the column is a main column (with title and subtitle)
45 * or a secondary action column (only a little icon that appears on mouse
46 * over is displayed)
48 class PLASMA_EXPORT Delegate : public QAbstractItemDelegate
50 Q_OBJECT
51 public:
53 enum SpecificRoles {
54 SubTitleRole = Qt::UserRole + 1,
55 SubTitleMandatoryRole = Qt::UserRole + 2,
56 ColumnTypeRole = Qt::UserRole + 3
59 enum ColumnType {
60 MainColumn = 1,
61 SecondaryActionColumn = 2
64 Delegate(QObject *parent = 0);
65 ~Delegate();
67 /**
68 * Maps an arbitrary role to a role belonging to SpecificRoles.
69 * Using this function you can use any model with this delegate.
71 * @param role a role belonging to SpecificRoles
72 * @param actual an arbitrary role of the model we are using
74 void setRoleMapping(SpecificRoles role, int actual);
76 int roleMapping(SpecificRoles role) const;
78 //Reimplemented
79 virtual void paint(QPainter *painter, const QStyleOptionViewItem &option,
80 const QModelIndex &index) const;
82 /**
83 * @return true if a tooltip should be shown
85 bool showToolTip() const;
87 protected:
88 /**
89 * Returns the empty area after the title.
90 * The height is the height of the subtitle.
91 * It can be used by subclasses that wants to paint additional data after
92 * calling the paint function of the superclass.
94 * @param option options for the title text
95 * @param index model index that we want to compute the free area
97 QRect rectAfterTitle(const QStyleOptionViewItem &option, const QModelIndex &index) const;
99 /**
100 * Returns the empty area after the subtitle.
101 * The height is the height of the subtitle.
102 * It can be used by subclasses, that wants to paint additional data.
104 * @param option options for the subtitle text
105 * @param index model index that we want to compute the free area
107 QRect rectAfterSubTitle(const QStyleOptionViewItem &option, const QModelIndex &index) const;
110 * Returns the empty area after both the title and the subtitle.
111 * The height is the height of the item.
112 * It can be used by subclasses that wants to paint additional data
114 * @param option options for the title and subtitle text
115 * @param index model index that we want to compute the free area
117 QRect emptyRect(const QStyleOptionViewItem &option, const QModelIndex &index) const;
119 virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
121 private:
122 DelegatePrivate *const d;
127 #endif // PLASMA_DELEGATE_H