]> cloud.milkyroute.net Git - dolphin.git/blob - src/tooltips/ktooltipitem.cpp
The file ktooltip.h contained the three public classes KToolTip, KToolTipDelegate...
[dolphin.git] / src / tooltips / ktooltipitem.cpp
1 /***************************************************************************
2 * Copyright (C) 2008 by Fredrik Höglund <fredrik@kde.org> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #include "ktooltipitem.h"
21 #include "ktooltip_p.h"
22
23 #include <QIcon>
24
25 class KToolTipItemPrivate
26 {
27 public:
28 QMap<int, QVariant> map;
29 int type;
30 };
31
32 KToolTipItem::KToolTipItem(const QString &text, int type)
33 : d(new KToolTipItemPrivate)
34 {
35 d->map[Qt::DisplayRole] = text;
36 d->type = type;
37 }
38
39 KToolTipItem::KToolTipItem(const QIcon &icon, const QString &text, int type)
40 : d(new KToolTipItemPrivate)
41 {
42 d->map[Qt::DecorationRole] = icon;
43 d->map[Qt::DisplayRole] = text;
44 d->type = type;
45 }
46
47 KToolTipItem::~KToolTipItem()
48 {
49 delete d;
50 }
51
52 int KToolTipItem::type() const
53 {
54 return d->type;
55 }
56
57 QString KToolTipItem::text() const
58 {
59 return data(Qt::DisplayRole).toString();
60 }
61
62 QIcon KToolTipItem::icon() const
63 {
64 return qvariant_cast<QIcon>(data(Qt::DecorationRole));
65 }
66
67 QVariant KToolTipItem::data(int role) const
68 {
69 return d->map.value(role);
70 }
71
72 void KToolTipItem::setData(int role, const QVariant &data)
73 {
74 d->map[role] = data;
75 KToolTipManager::instance()->update();
76 }