delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / apps / dolphin / src / tooltips / ktooltip.h
blobd59f1bf170c3d16bad9bfcec1e1eb7e13867d52e
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 ***************************************************************************/
20 #ifndef KTOOLTIP_H
21 #define KTOOLTIP_H
23 #include <QObject>
24 #include <QPalette>
25 #include <QFont>
26 #include <QRect>
27 #include <QStyle>
28 #include <QFontMetrics>
30 class QString;
31 class QIcon;
32 class QSize;
33 class QPainter;
34 class QRegion;
36 class KToolTipItemPrivate;
38 /**
39 * KToolTipItem contains the data to be displayed in a tooltip.
41 * Custom data can be stored as QVariants in the object by calling
42 * setData() with a custom item role, and retrieved and displayed
43 * by a tooltip delegate by calling data().
45 * The default tooltip delegate uses Qt::DecorationRole and
46 * Qt::DisplayRole.
48 * To display the tooltip, call KToolTip::showTip() with a pointer
49 * to the KToolTipItem.
51 * You can reimplement the setData() and/or data() methods in this
52 * class to implement on-demand loading of data.
54 class KToolTipItem
56 public:
57 enum ItemType { DefaultType, UserType = 1000 };
59 /**
60 * Creates a KToolTipItem with @p text and no icon.
62 explicit KToolTipItem(const QString &text, int type = DefaultType);
64 /**
65 * Creates a KToolTipItem with an @p icon and @p text.
67 KToolTipItem(const QIcon &icon, const QString &text, int type = DefaultType);
69 /**
70 * Destroys the KToolTipItem.
72 virtual ~KToolTipItem();
74 /**
75 * Returns the item type.
77 int type() const;
79 QString text() const;
80 QIcon icon() const;
82 virtual QVariant data(int role) const;
83 virtual void setData(int role, const QVariant &data);
85 private:
86 KToolTipItemPrivate * const d;
90 class KStyleOptionToolTip
92 public:
93 KStyleOptionToolTip();
94 enum Corner { TopLeftCorner, TopRightCorner, BottomLeftCorner, BottomRightCorner, NoCorner };
96 Qt::LayoutDirection direction;
97 QFontMetrics fontMetrics;
98 QPalette palette;
99 QRect rect;
100 QStyle::State state;
101 QFont font;
102 QSize decorationSize;
103 Corner activeCorner;
107 * KToolTipDelegate is responsible for providing the size hint and
108 * painting the tooltips.
110 class KToolTipDelegate : public QObject
112 Q_OBJECT
113 public:
114 KToolTipDelegate();
115 virtual ~KToolTipDelegate();
117 virtual QSize sizeHint(const KStyleOptionToolTip *option, const KToolTipItem *item) const;
120 * If haveAlphaChannel() returns true, the paint device will be filled with
121 * Qt::transparent when this function is called, otherwise the content is
122 * undefined.
124 virtual void paint(QPainter *painter, const KStyleOptionToolTip *option,
125 const KToolTipItem *item) const;
128 * Reimplement this function to specify the region of the tooltip
129 * that accepts input. Any mouse events that occur outside this
130 * region will be sent to the widget below the tooltip.
132 * The default implementation returns a region containing the
133 * bounding rect of the tooltip.
135 * This function will only be called if haveAlphaChannel()
136 * returns true.
138 virtual QRegion inputShape(const KStyleOptionToolTip *option) const;
141 * Reimplement this function to specify a shape mask for the tooltip.
143 * The default implementation returns a region containing the
144 * bounding rect of the tooltip.
146 * This function will only be called if haveAlphaChannel()
147 * returns false.
149 virtual QRegion shapeMask(const KStyleOptionToolTip *option) const;
151 protected:
153 * Returns true if the tooltip has an alpha channel, and false
154 * otherwise.
156 * Implementors should assume that this condition may change at
157 * any time during the runtime of the application, as compositing
158 * can be enabled or disabled in the window manager.
160 bool haveAlphaChannel() const;
162 #if 0
163 private Q_SLOTS:
165 * Schedules a repaint of the tooltip item.
166 * This slot can be connected to a timer to animate the tooltip.
168 void update(const KToolTipItem *item);
169 #endif
174 * KToolTip provides customizable tooltips that can have animations as well as an alpha
175 * channel, allowing for dynamic transparency effects.
177 * ARGB tooltips work on X11 even when the application isn't using the ARGB visual.
179 namespace KToolTip
181 void showText(const QPoint &pos, const QString &text, QWidget *widget, const QRect &rect);
182 void showText(const QPoint &pos, const QString &text, QWidget *widget = 0);
185 * Shows the tip @p item at the global position indicated by @p pos.
187 * Ownership of the item is transferred to KToolTip. The item will be deleted
188 * automatically when it is hidden.
190 * The tip is shown immediately when this function is called.
192 void showTip(const QPoint &pos, KToolTipItem *item);
193 void hideTip();
195 void setToolTipDelegate(KToolTipDelegate *delegate);
198 #endif