2008-10-11 18:19:04 +02:00
|
|
|
/*
|
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.
|
|
|
|
*/
|
|
|
|
|
2008-08-06 11:19:29 +02:00
|
|
|
#ifndef PLASMA_DELEGATE_H
|
|
|
|
#define PLASMA_DELEGATE_H
|
2008-03-18 12:09:39 +01:00
|
|
|
|
|
|
|
// 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
|
|
|
/**
|
2008-08-25 19:47:48 +02:00
|
|
|
* @class Delegate plasma/delegate.h <Plasma/Delegate>
|
|
|
|
*
|
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
|
2008-10-11 18:19:04 +02:00
|
|
|
* SubTitleMandatoryRole: if the subtitle is to always be displayed
|
|
|
|
* (as default the subtitle is displayed only on mouse over)
|
2008-03-18 12:09:39 +01:00
|
|
|
* ColumnTypeRole: if the column is a main column (with title and subtitle)
|
2008-10-11 18:19:04 +02:00
|
|
|
* or a secondary action column (only a little icon that appears on mouse
|
|
|
|
* over is displayed)
|
2008-03-18 12:09:39 +01:00
|
|
|
*/
|
|
|
|
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 {
|
2008-10-11 18:19:04 +02:00
|
|
|
SubTitleRole = Qt::UserRole + 1,
|
|
|
|
SubTitleMandatoryRole = Qt::UserRole + 2,
|
|
|
|
ColumnTypeRole = Qt::UserRole + 3
|
2008-03-18 12:09:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
enum ColumnType {
|
2008-10-11 18:19:04 +02:00
|
|
|
MainColumn = 1,
|
|
|
|
SecondaryActionColumn = 2
|
2008-03-18 12:09:39 +01:00
|
|
|
};
|
|
|
|
|
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
|
2008-10-11 18:19:04 +02:00
|
|
|
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
|
|
|
const QModelIndex &index) const;
|
2008-06-16 11:51:33 +02:00
|
|
|
|
2008-03-18 12:09:39 +01:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Returns the empty area after the title.
|
|
|
|
* The height is the height of the subtitle.
|
2008-10-11 18:19:04 +02:00
|
|
|
* It can be used by subclasses that wants to paint additional data after
|
|
|
|
* calling the paint function of the superclass.
|
2008-03-18 12:09:39 +01:00
|
|
|
*
|
|
|
|
* @param option options for the title text
|
|
|
|
* @param index model index that we want to compute the free area
|
|
|
|
*/
|
2008-10-11 18:19:04 +02:00
|
|
|
QRect rectAfterTitle(const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
2008-03-18 12:09:39 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2008-10-11 18:19:04 +02:00
|
|
|
QRect rectAfterSubTitle(const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
2008-03-18 12:09:39 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2008-10-11 18:19:04 +02:00
|
|
|
QRect emptyRect(const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
2008-03-18 12:09:39 +01:00
|
|
|
|
2008-10-11 18:19:04 +02:00
|
|
|
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
2008-03-18 12:09:39 +01:00
|
|
|
|
|
|
|
private:
|
2008-10-11 18:19:04 +02:00
|
|
|
DelegatePrivate *const d;
|
2008-03-18 12:09:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-10-11 18:19:04 +02:00
|
|
|
#endif // PLASMA_DELEGATE_H
|