1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the Qt 3 compatibility classes of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#include "q3whatsthis.h"
30
#include "qapplication.h"
34
/*! \class Q3WhatsThis
39
Constructs a new "What's This?" object for \a widget.
41
Q3WhatsThis::Q3WhatsThis(QWidget *widget)
45
widget->installEventFilter(this);
49
Destroys the "What's This?" object.
51
Q3WhatsThis::~Q3WhatsThis()
58
Handles "What's This?" events.
60
bool Q3WhatsThis::eventFilter(QObject *o, QEvent *e)
62
if (o != parent() || !o->isWidgetType())
65
if (e->type() == QEvent::WhatsThis) {
66
QString s = text(static_cast<QHelpEvent*>(e)->pos());
68
QWhatsThis::showText(static_cast<QHelpEvent*>(e)->globalPos(), s, static_cast<QWidget*>(o));
69
} else if (e->type() == QEvent::WhatsThisClicked) {
70
QString href = static_cast<QWhatsThisClickedEvent*>(e)->href();
72
QWhatsThis::hideText();
80
This virtual function returns the text for position \a pos in the
81
widget that this "What's This?" object documents. If there is no
82
"What's This?" text for the position, an empty string is returned.
84
The default implementation returns an empty string.
86
QString Q3WhatsThis::text(const QPoint & /* pos */)
88
if (parent() && parent()->isWidgetType())
89
return static_cast<QWidget*>(parent())->whatsThis();
94
This virtual function is called when the user clicks inside the
95
"What's this?" window. \a href is the link the user clicked on, or
96
an empty string if there was no link.
98
If the function returns true (the default), the "What's this?"
99
window is closed, otherwise it remains visible.
101
The default implementation ignores \a href and returns true.
103
bool Q3WhatsThis::clicked(const QString & /* href */)
109
\fn void Q3WhatsThis::enterWhatsThisMode()
111
Enters "What's This?" mode and returns immediately.
113
Qt will install a special cursor and take over mouse input until
114
the user clicks somewhere. It then shows any help available and
115
ends "What's This?" mode. Finally, Qt removes the special cursor
116
and help window and then restores ordinary event processing, at
117
which point the left mouse button is no longer pressed.
119
The user can also use the Esc key to leave "What's This?" mode.
121
\sa inWhatsThisMode(), leaveWhatsThisMode()
125
\fn bool Q3WhatsThis::inWhatsThisMode()
127
Returns true if the application is in "What's This?" mode;
128
otherwise returns false.
130
\sa enterWhatsThisMode(), leaveWhatsThisMode()
134
\fn void Q3WhatsThis::add(QWidget *widget, const QString &text)
136
Adds \a text as "What's This?" help for \a widget. If the text is
137
rich text formatted (i.e. it contains markup) it will be rendered
138
with the default stylesheet QStyleSheet::defaultSheet().
140
The text is destroyed if the widget is later destroyed, so it need
141
not be explicitly removed.
147
\fn void Q3WhatsThis::remove(QWidget *widget)
149
Removes the "What's This?" help associated with the \a widget.
150
This happens automatically if the widget is destroyed.
156
\fn void Q3WhatsThis::leaveWhatsThisMode(const QString& text = QString(), const QPoint& pos = QCursor::pos(), QWidget* widget = 0)
158
This function is used internally by widgets that support
159
QWidget::customWhatsThis(); applications do not usually call it.
160
An example of such a widget is Q3PopupMenu: menus still work
161
normally in "What's This?" mode but also provide help texts for
162
individual menu items.
164
If \a text is not empty, a "What's This?" help window is
165
displayed at the global screen position \a pos. If widget \a widget is
166
not 0 and has its own dedicated QWhatsThis object, this object
167
will receive clicked() messages when the user clicks on hyperlinks
168
inside the help text.
170
\sa inWhatsThisMode(), enterWhatsThisMode(), clicked()
174
\fn void Q3WhatsThis::display(const QString &text, const QPoint &pos, QWidget *widget)
176
Display \a text in a help window at the global screen position \a
179
If widget \a widget is not 0 and has its own dedicated QWhatsThis
180
object, this object will receive clicked() messages when the user
181
clicks on hyperlinks inside the help text.
187
Creates a QToolButton preconfigured to enter "What's This?" mode
188
when clicked. You will often use this with a tool bar as \a
192
(void)QWhatsThis::whatsThisButton( my_help_tool_bar );
195
QToolButton *Q3WhatsThis::whatsThisButton(QWidget * parent)
197
return QWhatsThis::whatsThisButton(parent);