~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kwin/tabbox/desktopitemdelegate.h

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/********************************************************************
 
2
 KWin - the KDE window manager
 
3
 This file is part of the KDE project.
 
4
 
 
5
Copyright (C) 2009 Martin Gräßlin <kde@martin-graesslin.com>
 
6
 
 
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.
 
11
 
 
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.
 
16
 
 
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
*********************************************************************/
 
20
 
 
21
#ifndef DESKTOPITEMDELEGATE_H
 
22
#define DESKTOPITEMDELEGATE_H
 
23
#include "itemlayoutconfig.h"
 
24
 
 
25
#include <QAbstractItemDelegate>
 
26
/**
 
27
* @file
 
28
* This file defines the class DesktopItemDelegate, the ItemDelegate for desktops.
 
29
*
 
30
* @author Martin Gräßlin <kde@martin-graesslin.com>
 
31
* @since 4.4
 
32
*/
 
33
 
 
34
namespace Plasma
 
35
{
 
36
class FrameSvg;
 
37
}
 
38
 
 
39
namespace KWin
 
40
{
 
41
namespace TabBox
 
42
{
 
43
class ClientItemDelegate;
 
44
 
 
45
/**
 
46
* The ItemDelegate for desktops used in TabBox.
 
47
*
 
48
* @author Martin Gräßlin <kde@martin-graesslin.com>
 
49
* @since 4.4
 
50
*/
 
51
class DesktopItemDelegate
 
52
    : public QAbstractItemDelegate
 
53
{
 
54
public:
 
55
    DesktopItemDelegate(QObject* parent = 0);
 
56
    ~DesktopItemDelegate();
 
57
 
 
58
    virtual QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
 
59
    virtual void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
 
60
 
 
61
    void setConfig(const ItemLayoutConfig& config);
 
62
    void setLayouts(QMap< QString, ItemLayoutConfig >& layouts);
 
63
 
 
64
private:
 
65
    /**
 
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
 
74
    */
 
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;
 
78
    /**
 
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
 
83
    */
 
84
    QSizeF rowSize(const QModelIndex& index, int row) const;
 
85
    /**
 
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
 
92
    */
 
93
    QSizeF textElementSizeHint(const QModelIndex& index, const ItemLayoutConfigRowElement& element, QString text) const;
 
94
    /**
 
95
    * The FrameSvg to render selected items
 
96
    */
 
97
    Plasma::FrameSvg* m_frame;
 
98
    ItemLayoutConfig m_config;
 
99
    QMap< QString, ItemLayoutConfig > m_layouts;
 
100
    ClientItemDelegate* m_clientDelegate;
 
101
};
 
102
 
 
103
} // namespace Tabbox
 
104
} // namespace KWin
 
105
 
 
106
#endif // DESKTOPITEMDELEGATE_H