]> cloud.milkyroute.net Git - dolphin.git/commitdiff
The file ktooltip.h contained the three public classes KToolTip, KToolTipDelegate...
authorPeter Penz <peter.penz19@gmail.com>
Sun, 21 Jun 2009 10:20:28 +0000 (10:20 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Sun, 21 Jun 2009 10:20:28 +0000 (10:20 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=984646

src/CMakeLists.txt
src/tooltips/kformattedballoontipdelegate.cpp
src/tooltips/kformattedballoontipdelegate.h
src/tooltips/ktooltip.cpp
src/tooltips/ktooltip.h
src/tooltips/ktooltip_p.h
src/tooltips/ktooltipdelegate.cpp [new file with mode: 0644]
src/tooltips/ktooltipdelegate.h [new file with mode: 0644]
src/tooltips/ktooltipitem.cpp [new file with mode: 0644]
src/tooltips/ktooltipitem.h [new file with mode: 0644]

index 083b31e21ffa43e05b1d63816a0e24f54487bb8a..c959899a248c2525ea7e537bae9fe5717f628cf0 100644 (file)
@@ -43,6 +43,8 @@ set(dolphinprivate_LIB_SRCS
     settings/viewpropsprogressinfo.cpp
     tooltips/dolphintooltip.cpp
     tooltips/ktooltip.cpp
+    tooltips/ktooltipdelegate.cpp
+    tooltips/ktooltipitem.cpp
     tooltips/kformattedballoontipdelegate.cpp
     tooltips/tooltipmanager.cpp
     viewproperties.cpp
index 2659ccd976f6a27c9b53d2702c1d85f2d728bc88..643068cbb86fb414e45dcfa91dffb9a623d0a2a0 100644 (file)
  *******************************************************************************/
 
 #include "kformattedballoontipdelegate.h"
+#include "ktooltipitem.h"
+#include "ktooltip.h"
 #include <QBitmap>
+#include <QIcon>
 #include <QLinearGradient>
 #include <QTextDocument>
 #include <kcolorscheme.h>
index 4dc9f8bbbecff55151bf933c76662dd62bb5ad52..bc8ab23f9817c7c006c254c78705ad199d24ce5c 100644 (file)
@@ -21,7 +21,7 @@
 #ifndef KFORMATTEDBALLOONTIPDELEGATE_H
 #define KFORMATTEDBALLOONTIPDELEGATE_H
 
-#include <tooltips/ktooltip.h>
+#include <tooltips/ktooltipdelegate.h>
 #include <QPainter>
 
 class KFormattedBalloonTipDelegate : public KToolTipDelegate
index e33cd197c9ee20a1723da255898d2968fb7f477b..114271661f28d299205f651edef3b1853ffcde75 100644 (file)
 
 #include "ktooltip.h"
 #include "ktooltip_p.h"
+#include "ktooltipdelegate.h"
 
 #include <QApplication>
-#include <QMap>
-#include <QPixmap>
 #include <QPainter>
-#include <QVariant>
-#include <QIcon>
 #include <QWidget>
 #include <QToolTip>
-#include <QDebug>
 
 #ifdef Q_WS_X11
 #  include <QX11Info>
@@ -42,173 +38,9 @@ const int ShapeInput = 2;
 #endif
 
 
-class KToolTipItemPrivate
-{
-public:
-    QMap<int, QVariant> map;
-    int type;
-};
-
-KToolTipItem::KToolTipItem(const QString &text, int type)
-    : d(new KToolTipItemPrivate)
-{
-    d->map[Qt::DisplayRole] = text;
-    d->type = type;
-}
-
-KToolTipItem::KToolTipItem(const QIcon &icon, const QString &text, int type)
-    : d(new KToolTipItemPrivate)
-{
-    d->map[Qt::DecorationRole] = icon;
-    d->map[Qt::DisplayRole]    = text;
-    d->type = type;
-}
-
-KToolTipItem::~KToolTipItem()
-{
-    delete d;
-}
-
-int KToolTipItem::type() const
-{
-    return d->type;
-}
-
-QString KToolTipItem::text() const
-{
-    return data(Qt::DisplayRole).toString();
-}
-
-QIcon KToolTipItem::icon() const
-{
-    return qvariant_cast<QIcon>(data(Qt::DecorationRole));
-}
-
-QVariant KToolTipItem::data(int role) const
-{
-    return d->map.value(role);
-}
-
-void KToolTipItem::setData(int role, const QVariant &data)
-{
-    d->map[role] = data;
-    KToolTipManager::instance()->update();
-}
-
-
-
-// ----------------------------------------------------------------------------
-
-
-KStyleOptionToolTip::KStyleOptionToolTip()
-    : fontMetrics(QApplication::font())
-{
-}
-
-
-// ----------------------------------------------------------------------------
-
-
-
-KToolTipDelegate::KToolTipDelegate() : QObject()
-{
-}
-
-KToolTipDelegate::~KToolTipDelegate()
-{
-}
-
-QSize KToolTipDelegate::sizeHint(const KStyleOptionToolTip &option, const KToolTipItem &item) const
-{
-    QSize size;
-    size.rwidth() = option.fontMetrics.width(item.text());
-    size.rheight() = option.fontMetrics.lineSpacing();
-
-    QIcon icon = item.icon();
-    if (!icon.isNull()) {
-        const QSize iconSize = icon.actualSize(option.decorationSize);
-        size.rwidth() += iconSize.width() + 4;
-        size.rheight() = qMax(size.height(), iconSize.height());
-    }
-
-    return size + QSize(20, 20);
-
-}
-
-void KToolTipDelegate::paint(QPainter *painter,
-                             const KStyleOptionToolTip &option,
-                             const KToolTipItem &item) const
-{
-    bool haveAlpha = haveAlphaChannel();
-    painter->setRenderHint(QPainter::Antialiasing);
-
-    QPainterPath path;
-    if (haveAlpha)
-        path.addRoundRect(option.rect.adjusted(0, 0, -1, -1), 25);
-    else
-        path.addRect(option.rect.adjusted(0, 0, -1, -1));
-
-    QColor color = option.palette.color(QPalette::ToolTipBase);
-    QColor from = color.lighter(105);
-    QColor to   = color.darker(120);
-
-    QLinearGradient gradient(0, 0, 0, 1);
-    gradient.setCoordinateMode(QGradient::ObjectBoundingMode);
-    gradient.setColorAt(0, from);
-    gradient.setColorAt(1, to);
-
-    painter->translate(.5, .5);
-    painter->setPen(QPen(Qt::black, 1));
-    painter->setBrush(gradient);
-    painter->drawPath(path);
-    painter->translate(-.5, -.5);
-
-    if (haveAlpha) {
-        QLinearGradient mask(0, 0, 0, 1);
-        gradient.setCoordinateMode(QGradient::ObjectBoundingMode);
-        gradient.setColorAt(0, QColor(0, 0, 0, 192));
-        gradient.setColorAt(1, QColor(0, 0, 0, 72));
-        painter->setCompositionMode(QPainter::CompositionMode_DestinationIn);
-        painter->fillRect(option.rect, gradient);
-        painter->setCompositionMode(QPainter::CompositionMode_SourceOver);
-    }
-
-    QRect textRect = option.rect.adjusted(10, 10, -10, -10);
-
-    QIcon icon = item.icon();
-    if (!icon.isNull()) {
-        const QSize iconSize = icon.actualSize(option.decorationSize);
-        painter->drawPixmap(textRect.topLeft(), icon.pixmap(iconSize));
-        textRect.adjust(iconSize.width() + 4, 0, 0, 0);
-    }
-    painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, item.text());
-}
-
-QRegion KToolTipDelegate::inputShape(const KStyleOptionToolTip &option) const
-{
-    return QRegion(option.rect);
-}
-
-QRegion KToolTipDelegate::shapeMask(const KStyleOptionToolTip &option) const
-{
-    return QRegion(option.rect);
-}
-
-bool KToolTipDelegate::haveAlphaChannel() const
-{
-#ifdef Q_WS_X11
-    return QX11Info::isCompositingManagerRunning();
-#else
-       return false;
-#endif
-}
-
-
-
 // ----------------------------------------------------------------------------
 
 
-
 class KTipLabel : public QWidget
 {
 public:
@@ -295,13 +127,9 @@ KToolTipDelegate *KTipLabel::delegate() const
 }
 
 
-
-
 // ----------------------------------------------------------------------------
 
 
-
-
 KToolTipManager *KToolTipManager::s_instance = 0;
 
 KToolTipManager::KToolTipManager()
@@ -360,11 +188,9 @@ KToolTipDelegate *KToolTipManager::delegate() const
 }
 
 
-
 // ----------------------------------------------------------------------------
 
 
-
 namespace KToolTip
 {
     void showText(const QPoint &pos, const QString &text, QWidget *widget, const QRect &rect)
index 31589c69044caf58a4796e1669fddd18b120d5ec..6de08315c0ceeccf857cf3f199c802411bd9cc06 100644 (file)
 #ifndef KTOOLTIP_H
 #define KTOOLTIP_H
 
-#include <QObject>
-#include <QPalette>
-#include <QFont>
-#include <QRect>
+#include <tooltips/ktooltipitem.h>
+
 #include <QStyle>
 #include <QFontMetrics>
-
-class QString;
-class QIcon;
-class QSize;
-class QPainter;
-class QRegion;
-
-class KToolTipItemPrivate;
-
-/**
- * KToolTipItem contains the data to be displayed in a tooltip.
- *
- * Custom data can be stored as QVariants in the object by calling
- * setData() with a custom item role, and retrieved and displayed
- * by a tooltip delegate by calling data().
- *
- * The default tooltip delegate uses Qt::DecorationRole and
- * Qt::DisplayRole.
- *
- * To display the tooltip, call KToolTip::showTip() with a pointer
- * to the KToolTipItem.
- *
- * You can reimplement the setData() and/or data() methods in this
- * class to implement on-demand loading of data.
- */
-class KToolTipItem
-{
-public:
-     enum ItemType { DefaultType, UserType = 1000 };
-
-     /**
-      * Creates a KToolTipItem with @p text and no icon.
-      */
-     explicit KToolTipItem(const QString &text, int type = DefaultType);
-
-     /**
-      * Creates a KToolTipItem with an @p icon and @p text.
-      */
-     KToolTipItem(const QIcon &icon, const QString &text, int type = DefaultType);
-
-     /**
-      * Destroys the KToolTipItem.
-      */
-     virtual ~KToolTipItem();
-
-     /**
-      * Returns the item type.
-      */
-     int type() const;
-
-     QString text() const;
-     QIcon icon() const;
-
-     virtual QVariant data(int role) const;
-     virtual void setData(int role, const QVariant &data);
-
-private:
-     KToolTipItemPrivate * const d;
-};
-
-
-class KStyleOptionToolTip
-{
-public:
-    KStyleOptionToolTip();
-    enum Corner { TopLeftCorner, TopRightCorner, BottomLeftCorner, BottomRightCorner, NoCorner };
-
-    Qt::LayoutDirection direction;
-    QFontMetrics fontMetrics;
-    QPalette palette;
-    QRect rect;
-    QStyle::State state;
-    QFont font;
-    QSize decorationSize;
-    Corner activeCorner;
-};
-
-/**
- * KToolTipDelegate is responsible for providing the size hint and
- * painting the tooltips.
- */
-class KToolTipDelegate : public QObject
-{
-    Q_OBJECT
-public:
-     KToolTipDelegate();
-     virtual ~KToolTipDelegate();
-
-     virtual QSize sizeHint(const KStyleOptionToolTip &option, const KToolTipItem &item) const;
-
-     /**
-      * If haveAlphaChannel() returns true, the paint device will be filled with
-      * Qt::transparent when this function is called, otherwise the content is
-      * undefined.
-      */
-     virtual void paint(QPainter *painter,
-                        const KStyleOptionToolTip &option,
-                        const KToolTipItem &item) const;
-
-     /**
-      * Reimplement this function to specify the region of the tooltip
-      * that accepts input. Any mouse events that occur outside this
-      * region will be sent to the widget below the tooltip.
-      *
-      * The default implementation returns a region containing the
-      * bounding rect of the tooltip.
-      *
-      * This function will only be called if haveAlphaChannel()
-      * returns true.
-      */
-     virtual QRegion inputShape(const KStyleOptionToolTip &option) const;
-
-     /**
-      * Reimplement this function to specify a shape mask for the tooltip.
-      *
-      * The default implementation returns a region containing the
-      * bounding rect of the tooltip.
-      *
-      * This function will only be called if haveAlphaChannel()
-      * returns false.
-      */
-     virtual QRegion shapeMask(const KStyleOptionToolTip &option) const;
-
-protected:
-     /**
-      * Returns true if the tooltip has an alpha channel, and false
-      * otherwise.
-      *
-      * Implementors should assume that this condition may change at
-      * any time during the runtime of the application, as compositing
-      * can be enabled or disabled in the window manager.
-      */
-     bool haveAlphaChannel() const;
-
-#if 0
-private Q_SLOTS:
-     /**
-      * Schedules a repaint of the tooltip item.
-      * This slot can be connected to a timer to animate the tooltip.
-      */
-     void update(const KToolTipItem *item);
-#endif
-};
-
+class KToolTipDelegate;
 
 /**
  * KToolTip provides customizable tooltips that can have animations as well as an alpha
index 5aa5326cfa352b60c91dffce0845758403e48fcb..5bc37236de695d4000b2328b3ce507aef6f9de1d 100644 (file)
@@ -20,6 +20,8 @@
 #ifndef KTOOLTIP_P_H
 #define KTOOLTIP_P_H
 
+#include <QPoint>
+
 class KTipLabel;
 class KStyleOptionToolTip;
 class KToolTipDelegate;
diff --git a/src/tooltips/ktooltipdelegate.cpp b/src/tooltips/ktooltipdelegate.cpp
new file mode 100644 (file)
index 0000000..0141db1
--- /dev/null
@@ -0,0 +1,138 @@
+/***************************************************************************
+ *   Copyright (C) 2008 by Fredrik Höglund <fredrik@kde.org>               *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program 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 General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
+ ***************************************************************************/
+
+#include "ktooltipdelegate.h"
+
+#include "ktooltip.h"
+
+#include <QApplication>
+#include <QPainter>
+#include <QIcon>
+
+#ifdef Q_WS_X11
+#  include <QX11Info>
+#  include <X11/Xlib.h>
+#  include <X11/extensions/shape.h>
+#endif
+
+
+// ----------------------------------------------------------------------------
+
+
+KStyleOptionToolTip::KStyleOptionToolTip()
+    : fontMetrics(QApplication::font())
+{
+}
+
+
+// ----------------------------------------------------------------------------
+
+
+KToolTipDelegate::KToolTipDelegate() : QObject()
+{
+}
+
+KToolTipDelegate::~KToolTipDelegate()
+{
+}
+
+QSize KToolTipDelegate::sizeHint(const KStyleOptionToolTip &option, const KToolTipItem &item) const
+{
+    QSize size;
+    size.rwidth() = option.fontMetrics.width(item.text());
+    size.rheight() = option.fontMetrics.lineSpacing();
+
+    QIcon icon = item.icon();
+    if (!icon.isNull()) {
+        const QSize iconSize = icon.actualSize(option.decorationSize);
+        size.rwidth() += iconSize.width() + 4;
+        size.rheight() = qMax(size.height(), iconSize.height());
+    }
+
+    return size + QSize(20, 20);
+
+}
+
+void KToolTipDelegate::paint(QPainter *painter,
+                             const KStyleOptionToolTip &option,
+                             const KToolTipItem &item) const
+{
+    bool haveAlpha = haveAlphaChannel();
+    painter->setRenderHint(QPainter::Antialiasing);
+
+    QPainterPath path;
+    if (haveAlpha)
+        path.addRoundRect(option.rect.adjusted(0, 0, -1, -1), 25);
+    else
+        path.addRect(option.rect.adjusted(0, 0, -1, -1));
+
+    QColor color = option.palette.color(QPalette::ToolTipBase);
+    QColor from = color.lighter(105);
+    QColor to   = color.darker(120);
+
+    QLinearGradient gradient(0, 0, 0, 1);
+    gradient.setCoordinateMode(QGradient::ObjectBoundingMode);
+    gradient.setColorAt(0, from);
+    gradient.setColorAt(1, to);
+
+    painter->translate(.5, .5);
+    painter->setPen(QPen(Qt::black, 1));
+    painter->setBrush(gradient);
+    painter->drawPath(path);
+    painter->translate(-.5, -.5);
+
+    if (haveAlpha) {
+        QLinearGradient mask(0, 0, 0, 1);
+        gradient.setCoordinateMode(QGradient::ObjectBoundingMode);
+        gradient.setColorAt(0, QColor(0, 0, 0, 192));
+        gradient.setColorAt(1, QColor(0, 0, 0, 72));
+        painter->setCompositionMode(QPainter::CompositionMode_DestinationIn);
+        painter->fillRect(option.rect, gradient);
+        painter->setCompositionMode(QPainter::CompositionMode_SourceOver);
+    }
+
+    QRect textRect = option.rect.adjusted(10, 10, -10, -10);
+
+    QIcon icon = item.icon();
+    if (!icon.isNull()) {
+        const QSize iconSize = icon.actualSize(option.decorationSize);
+        painter->drawPixmap(textRect.topLeft(), icon.pixmap(iconSize));
+        textRect.adjust(iconSize.width() + 4, 0, 0, 0);
+    }
+    painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, item.text());
+}
+
+QRegion KToolTipDelegate::inputShape(const KStyleOptionToolTip &option) const
+{
+    return QRegion(option.rect);
+}
+
+QRegion KToolTipDelegate::shapeMask(const KStyleOptionToolTip &option) const
+{
+    return QRegion(option.rect);
+}
+
+bool KToolTipDelegate::haveAlphaChannel() const
+{
+#ifdef Q_WS_X11
+    return QX11Info::isCompositingManagerRunning();
+#else
+       return false;
+#endif
+}
diff --git a/src/tooltips/ktooltipdelegate.h b/src/tooltips/ktooltipdelegate.h
new file mode 100644 (file)
index 0000000..a219ec5
--- /dev/null
@@ -0,0 +1,110 @@
+/***************************************************************************
+ *   Copyright (C) 2008 by Fredrik Höglund <fredrik@kde.org>               *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program 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 General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
+ ***************************************************************************/
+
+#ifndef KTOOLTIPDELEGATE_H
+#define KTOOLTIPDELEGATE_H
+
+#include <QFontMetrics>
+#include <QFont>
+#include <QObject>
+#include <QPalette>
+#include <QRect>
+#include <QStyle>
+#include <QSize>
+
+class KStyleOptionToolTip;
+class KToolTipItem;
+class QPainter;
+class QRegion;
+
+class KStyleOptionToolTip
+{
+public:
+    KStyleOptionToolTip();
+    enum Corner { TopLeftCorner, TopRightCorner, BottomLeftCorner, BottomRightCorner, NoCorner };
+
+    Qt::LayoutDirection direction;
+    QFontMetrics fontMetrics;
+    QPalette palette;
+    QRect rect;
+    QStyle::State state;
+    QFont font;
+    QSize decorationSize;
+    Corner activeCorner;
+};
+
+/**
+ * KToolTipDelegate is responsible for providing the size hint and
+ * painting the tooltips.
+ */
+class KToolTipDelegate : public QObject
+{
+    Q_OBJECT
+public:
+     KToolTipDelegate();
+     virtual ~KToolTipDelegate();
+
+     virtual QSize sizeHint(const KStyleOptionToolTip &option, const KToolTipItem &item) const;
+
+     /**
+      * If haveAlphaChannel() returns true, the paint device will be filled with
+      * Qt::transparent when this function is called, otherwise the content is
+      * undefined.
+      */
+     virtual void paint(QPainter *painter,
+                        const KStyleOptionToolTip &option,
+                        const KToolTipItem &item) const;
+
+     /**
+      * Reimplement this function to specify the region of the tooltip
+      * that accepts input. Any mouse events that occur outside this
+      * region will be sent to the widget below the tooltip.
+      *
+      * The default implementation returns a region containing the
+      * bounding rect of the tooltip.
+      *
+      * This function will only be called if haveAlphaChannel()
+      * returns true.
+      */
+     virtual QRegion inputShape(const KStyleOptionToolTip &option) const;
+
+     /**
+      * Reimplement this function to specify a shape mask for the tooltip.
+      *
+      * The default implementation returns a region containing the
+      * bounding rect of the tooltip.
+      *
+      * This function will only be called if haveAlphaChannel()
+      * returns false.
+      */
+     virtual QRegion shapeMask(const KStyleOptionToolTip &option) const;
+
+protected:
+     /**
+      * Returns true if the tooltip has an alpha channel, and false
+      * otherwise.
+      *
+      * Implementors should assume that this condition may change at
+      * any time during the runtime of the application, as compositing
+      * can be enabled or disabled in the window manager.
+      */
+     bool haveAlphaChannel() const;
+};
+
+#endif
diff --git a/src/tooltips/ktooltipitem.cpp b/src/tooltips/ktooltipitem.cpp
new file mode 100644 (file)
index 0000000..78f778a
--- /dev/null
@@ -0,0 +1,76 @@
+/***************************************************************************
+ *   Copyright (C) 2008 by Fredrik Höglund <fredrik@kde.org>               *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program 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 General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
+ ***************************************************************************/
+
+#include "ktooltipitem.h"
+#include "ktooltip_p.h"
+
+#include <QIcon>
+
+class KToolTipItemPrivate
+{
+public:
+    QMap<int, QVariant> map;
+    int type;
+};
+
+KToolTipItem::KToolTipItem(const QString &text, int type)
+    : d(new KToolTipItemPrivate)
+{
+    d->map[Qt::DisplayRole] = text;
+    d->type = type;
+}
+
+KToolTipItem::KToolTipItem(const QIcon &icon, const QString &text, int type)
+    : d(new KToolTipItemPrivate)
+{
+    d->map[Qt::DecorationRole] = icon;
+    d->map[Qt::DisplayRole]    = text;
+    d->type = type;
+}
+
+KToolTipItem::~KToolTipItem()
+{
+    delete d;
+}
+
+int KToolTipItem::type() const
+{
+    return d->type;
+}
+
+QString KToolTipItem::text() const
+{
+    return data(Qt::DisplayRole).toString();
+}
+
+QIcon KToolTipItem::icon() const
+{
+    return qvariant_cast<QIcon>(data(Qt::DecorationRole));
+}
+
+QVariant KToolTipItem::data(int role) const
+{
+    return d->map.value(role);
+}
+
+void KToolTipItem::setData(int role, const QVariant &data)
+{
+    d->map[role] = data;
+    KToolTipManager::instance()->update();
+}
diff --git a/src/tooltips/ktooltipitem.h b/src/tooltips/ktooltipitem.h
new file mode 100644 (file)
index 0000000..1d628d8
--- /dev/null
@@ -0,0 +1,84 @@
+/***************************************************************************
+ *   Copyright (C) 2008 by Fredrik Höglund <fredrik@kde.org>               *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program 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 General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
+ ***************************************************************************/
+
+#ifndef KTOOLTIPITEM_H
+#define KTOOLTIPITEM_H
+
+#include <QVariant>
+
+class QString;
+class QIcon;
+class QSize;
+class QPainter;
+class QRegion;
+
+class KToolTipItemPrivate;
+
+/**
+ * KToolTipItem contains the data to be displayed in a tooltip.
+ *
+ * Custom data can be stored as QVariants in the object by calling
+ * setData() with a custom item role, and retrieved and displayed
+ * by a tooltip delegate by calling data().
+ *
+ * The default tooltip delegate uses Qt::DecorationRole and
+ * Qt::DisplayRole.
+ *
+ * To display the tooltip, call KToolTip::showTip() with a pointer
+ * to the KToolTipItem.
+ *
+ * You can reimplement the setData() and/or data() methods in this
+ * class to implement on-demand loading of data.
+ */
+class KToolTipItem
+{
+public:
+     enum ItemType { DefaultType, UserType = 1000 };
+
+     /**
+      * Creates a KToolTipItem with @p text and no icon.
+      */
+     explicit KToolTipItem(const QString &text, int type = DefaultType);
+
+     /**
+      * Creates a KToolTipItem with an @p icon and @p text.
+      */
+     KToolTipItem(const QIcon &icon, const QString &text, int type = DefaultType);
+
+     /**
+      * Destroys the KToolTipItem.
+      */
+     virtual ~KToolTipItem();
+
+     /**
+      * Returns the item type.
+      */
+     int type() const;
+
+     QString text() const;
+     QIcon icon() const;
+
+     virtual QVariant data(int role) const;
+     virtual void setData(int role, const QVariant &data);
+
+private:
+     KToolTipItemPrivate * const d;
+};
+
+#endif