2008-03-18 12:09:39 +01:00
|
|
|
/*
|
|
|
|
Copyright 2007 Robert Knight <robertknight@gmail.com>
|
|
|
|
Copyright 2008 Marco Martin <notmart@gmail.com>
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public License
|
|
|
|
along with this library; see the file COPYING.LIB. If not, write to
|
|
|
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DELEGATE_H
|
|
|
|
#define DELEGATE_H
|
|
|
|
|
|
|
|
// Qt
|
|
|
|
#include <QtGui/QAbstractItemDelegate>
|
|
|
|
|
|
|
|
// Plasma
|
|
|
|
#include <plasma/plasma_export.h>
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
class DelegatePrivate;
|
|
|
|
|
2008-03-18 12:09:39 +01:00
|
|
|
/**
|
|
|
|
* Item delegate for rendering items in Plasma menus implemented with item views.
|
|
|
|
*
|
|
|
|
* The delegate makes use of its own data roles that are:
|
|
|
|
* SubTitleRole: the text of the subtitle
|
|
|
|
* SubTitleMandatoryRole: if the subtitle is to always be displayed (as default the subtitle is displayed only on mouse over)
|
|
|
|
* ColumnTypeRole: if the column is a main column (with title and subtitle)
|
|
|
|
* or a secondary action column (only a little icon that appears on mouse over is displayed)
|
|
|
|
*/
|
|
|
|
class PLASMA_EXPORT Delegate : public QAbstractItemDelegate
|
|
|
|
{
|
2008-03-29 00:48:31 +01:00
|
|
|
Q_OBJECT
|
2008-03-29 09:37:44 +01:00
|
|
|
public:
|
2008-03-29 00:48:31 +01:00
|
|
|
|
2008-03-18 12:09:39 +01:00
|
|
|
enum SpecificRoles {
|
|
|
|
SubTitleRole = Qt::UserRole + 1,
|
|
|
|
SubTitleMandatoryRole = Qt::UserRole + 2,
|
|
|
|
ColumnTypeRole = Qt::UserRole + 3
|
|
|
|
};
|
|
|
|
|
|
|
|
enum ColumnType {
|
|
|
|
MainColumn = 1,
|
|
|
|
SecondaryActionColumn = 2
|
|
|
|
};
|
|
|
|
|
2008-04-25 12:16:49 +02:00
|
|
|
Delegate(QObject *parent = 0);
|
2008-03-18 12:09:39 +01:00
|
|
|
~Delegate();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps an arbitrary role to a role belonging to SpecificRoles.
|
|
|
|
* Using this function you can use any model with this delegate.
|
|
|
|
*
|
|
|
|
* @param role a role belonging to SpecificRoles
|
|
|
|
* @param actual an arbitrary role of the model we are using
|
|
|
|
*/
|
2008-04-25 13:35:20 +02:00
|
|
|
void setRoleMapping(SpecificRoles role, int actual);
|
|
|
|
|
|
|
|
int roleMapping(SpecificRoles role) const;
|
2008-03-18 12:09:39 +01:00
|
|
|
|
2008-06-16 11:51:33 +02:00
|
|
|
//Reimplemented
|
|
|
|
virtual void paint(QPainter *painter,const QStyleOptionViewItem& option,const QModelIndex& index) const;
|
|
|
|
|
2008-03-18 12:09:39 +01:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Returns the empty area after the title.
|
|
|
|
* The height is the height of the subtitle.
|
|
|
|
* It can be used by subclasses that wants to paint additional data after calling the paint function of the superclass.
|
|
|
|
*
|
|
|
|
* @param option options for the title text
|
|
|
|
* @param index model index that we want to compute the free area
|
|
|
|
*/
|
|
|
|
QRect rectAfterTitle(const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the empty area after the subtitle.
|
|
|
|
* The height is the height of the subtitle.
|
|
|
|
* It can be used by subclasses, that wants to paint additional data.
|
|
|
|
*
|
|
|
|
* @param option options for the subtitle text
|
|
|
|
* @param index model index that we want to compute the free area
|
|
|
|
*/
|
|
|
|
QRect rectAfterSubTitle(const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the empty area after both the title and the subtitle.
|
|
|
|
* The height is the height of the item.
|
|
|
|
* It can be used by subclasses that wants to paint additional data
|
|
|
|
*
|
|
|
|
* @param option options for the title and subtitle text
|
|
|
|
* @param index model index that we want to compute the free area
|
|
|
|
*/
|
|
|
|
QRect emptyRect(const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
|
|
|
|
|
|
|
virtual QSize sizeHint(const QStyleOptionViewItem& option , const QModelIndex& index) const;
|
|
|
|
|
|
|
|
private:
|
2008-07-01 20:56:43 +02:00
|
|
|
DelegatePrivate * const d;
|
2008-03-18 12:09:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // ITEMDELEGATE_H
|