source: trunk/src/qt3support/widgets/q3whatsthis.cpp@ 345

Last change on this file since 345 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 6.9 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the Qt3Support module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "q3whatsthis.h"
43#ifndef QT_NO_WHATSTHIS
44#include "qapplication.h"
45#include "qwidget.h"
46#include "qevent.h"
47
48QT_BEGIN_NAMESPACE
49
50/*! \class Q3WhatsThis
51 \compat
52*/
53
54/*!
55 Constructs a new "What's This?" object for \a widget.
56*/
57Q3WhatsThis::Q3WhatsThis(QWidget *widget)
58 : QObject(widget)
59{
60 if (widget)
61 widget->installEventFilter(this);
62}
63
64/*!
65 Destroys the "What's This?" object.
66*/
67Q3WhatsThis::~Q3WhatsThis()
68{
69}
70
71/*!
72 \internal
73
74 Handles "What's This?" events.
75*/
76bool Q3WhatsThis::eventFilter(QObject *o, QEvent *e)
77{
78 if (o != parent() || !o->isWidgetType())
79 return false;
80
81 if (e->type() == QEvent::WhatsThis) {
82 QString s = text(static_cast<QHelpEvent*>(e)->pos());
83 if (!s.isEmpty())
84 QWhatsThis::showText(static_cast<QHelpEvent*>(e)->globalPos(), s, static_cast<QWidget*>(o));
85 } else if (e->type() == QEvent::QueryWhatsThis) {
86 QString s = text(static_cast<QHelpEvent*>(e)->pos());
87 if (s.isEmpty())
88 return false;
89 } else if (e->type() == QEvent::WhatsThisClicked) {
90 QString href = static_cast<QWhatsThisClickedEvent*>(e)->href();
91 if (clicked(href))
92 QWhatsThis::hideText();
93 } else {
94 return false;
95 }
96 return true;
97}
98
99/*!
100 This virtual function returns the text for position \a pos in the
101 widget that this "What's This?" object documents. If there is no
102 "What's This?" text for the position, an empty string is returned.
103
104 The default implementation returns an empty string.
105*/
106QString Q3WhatsThis::text(const QPoint & /* pos */)
107{
108 if (parent() && parent()->isWidgetType())
109 return static_cast<QWidget*>(parent())->whatsThis();
110 return QString();
111}
112
113/*!
114 This virtual function is called when the user clicks inside the
115 "What's this?" window. \a href is the link the user clicked on, or
116 an empty string if there was no link.
117
118 If the function returns true (the default), the "What's this?"
119 window is closed, otherwise it remains visible.
120
121 The default implementation ignores \a href and returns true.
122*/
123bool Q3WhatsThis::clicked(const QString & /* href */)
124{
125 return true;
126}
127
128/*!
129 \fn void Q3WhatsThis::enterWhatsThisMode()
130
131 Enters "What's This?" mode and returns immediately.
132
133 Qt will install a special cursor and take over mouse input until
134 the user clicks somewhere. It then shows any help available and
135 ends "What's This?" mode. Finally, Qt removes the special cursor
136 and help window and then restores ordinary event processing, at
137 which point the left mouse button is no longer pressed.
138
139 The user can also use the Esc key to leave "What's This?" mode.
140
141 \sa inWhatsThisMode(), leaveWhatsThisMode()
142*/
143
144/*!
145 \fn bool Q3WhatsThis::inWhatsThisMode()
146
147 Returns true if the application is in "What's This?" mode;
148 otherwise returns false.
149
150 \sa enterWhatsThisMode(), leaveWhatsThisMode()
151*/
152
153/*!
154 \fn void Q3WhatsThis::add(QWidget *widget, const QString &text)
155
156 Adds \a text as "What's This?" help for \a widget. If the text is
157 rich text formatted (i.e. it contains markup) it will be rendered
158 with the default stylesheet QStyleSheet::defaultSheet().
159
160 The text is destroyed if the widget is later destroyed, so it need
161 not be explicitly removed.
162
163 \sa remove()
164*/
165
166/*!
167 \fn void Q3WhatsThis::remove(QWidget *widget)
168
169 Removes the "What's This?" help associated with the \a widget.
170 This happens automatically if the widget is destroyed.
171
172 \sa add()
173*/
174
175/*!
176 \fn void Q3WhatsThis::leaveWhatsThisMode(const QString& text = QString(), const QPoint& pos = QCursor::pos(), QWidget* widget = 0)
177
178 This function is used internally by widgets that support
179 QWidget::customWhatsThis(); applications do not usually call it.
180 An example of such a widget is Q3PopupMenu: menus still work
181 normally in "What's This?" mode but also provide help texts for
182 individual menu items.
183
184 If \a text is not empty, a "What's This?" help window is
185 displayed at the global screen position \a pos. If widget \a widget is
186 not 0 and has its own dedicated QWhatsThis object, this object
187 will receive clicked() messages when the user clicks on hyperlinks
188 inside the help text.
189
190 \sa inWhatsThisMode(), enterWhatsThisMode(), clicked()
191*/
192
193/*!
194 \fn void Q3WhatsThis::display(const QString &text, const QPoint &pos, QWidget *widget)
195
196 Display \a text in a help window at the global screen position \a
197 pos.
198
199 If widget \a widget is not 0 and has its own dedicated QWhatsThis
200 object, this object will receive clicked() messages when the user
201 clicks on hyperlinks inside the help text.
202
203 \sa clicked()
204*/
205
206/*!
207 Creates a QToolButton preconfigured to enter "What's This?" mode
208 when clicked. You will often use this with a tool bar as \a
209 parent:
210
211 \snippet doc/src/snippets/code/src_qt3support_widgets_q3whatsthis.cpp 0
212*/
213QToolButton *Q3WhatsThis::whatsThisButton(QWidget * parent)
214{
215 return QWhatsThis::whatsThisButton(parent);
216}
217
218QT_END_NAMESPACE
219
220#endif // QT_NO_WHATSTHIS
Note: See TracBrowser for help on using the repository browser.