1
/********************************************************************
2
KWin - the KDE window manager
3
This file is part of the KDE project.
5
Copyright (C) 2009 Martin Gräßlin <kde@martin-graesslin.com>
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program. If not, see <http://www.gnu.org/licenses/>.
19
*********************************************************************/
21
#ifndef DESKTOPITEMDELEGATE_H
22
#define DESKTOPITEMDELEGATE_H
23
#include "itemlayoutconfig.h"
25
#include <QAbstractItemDelegate>
28
* This file defines the class DesktopItemDelegate, the ItemDelegate for desktops.
30
* @author Martin Gräßlin <kde@martin-graesslin.com>
43
class ClientItemDelegate;
46
* The ItemDelegate for desktops used in TabBox.
48
* @author Martin Gräßlin <kde@martin-graesslin.com>
51
class DesktopItemDelegate
52
: public QAbstractItemDelegate
55
DesktopItemDelegate(QObject* parent = 0);
56
~DesktopItemDelegate();
58
virtual QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
59
virtual void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
61
void setConfig(const ItemLayoutConfig& config);
62
void setLayouts(QMap< QString, ItemLayoutConfig >& layouts);
66
* Paints the given text at the given position based on the given ItemLayoutConfigRowElement.
67
* @param painter The painter to paint the text
68
* @param option The current QStyleOptionViewItem
69
* @param element The current ItemLayoutConfigRowElement
70
* @param x The left x position for drawing the text
71
* @param y The top y position for drawing the text
72
* @param rowHeight The height of the current rendered row
73
* @param text The text which should be drawn
75
qreal paintTextElement(QPainter* painter, const QStyleOptionViewItem& option,
76
const ItemLayoutConfigRowElement& element,
77
const qreal& x, const qreal& y, const qreal& rowHeight, QString text) const;
79
* Calculates the size hint of the given row.
80
* @param index The current QModelIndex
81
* @param row The row for which the size hint has to be calculated
82
* @return The size hint of the given row
84
QSizeF rowSize(const QModelIndex& index, int row) const;
86
* Calculates the size hint of given text.
87
* This method is used to calculate the maximum size of a row.
88
* @param index The current model index
89
* @param element The ItemLayoutConfigRowElement defining how the text has to be laid out.
90
* @param text The text whose size has to be calculated
91
* @return The size of the given text if it would be rendered
93
QSizeF textElementSizeHint(const QModelIndex& index, const ItemLayoutConfigRowElement& element, QString text) const;
95
* The FrameSvg to render selected items
97
Plasma::FrameSvg* m_frame;
98
ItemLayoutConfig m_config;
99
QMap< QString, ItemLayoutConfig > m_layouts;
100
ClientItemDelegate* m_clientDelegate;
103
} // namespace Tabbox
106
#endif // DESKTOPITEMDELEGATE_H