author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 06 Jul 2010 15:10:48 +0300 | |
changeset 30 | 5dc02b23752f |
parent 18 | 2f34d5167611 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the Qt3Support module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
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 |
||
48 |
QT_BEGIN_NAMESPACE |
|
49 |
||
50 |
/*! \class Q3WhatsThis |
|
51 |
\compat |
|
52 |
*/ |
|
53 |
||
54 |
/*! |
|
55 |
Constructs a new "What's This?" object for \a widget. |
|
56 |
*/ |
|
57 |
Q3WhatsThis::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 |
*/ |
|
67 |
Q3WhatsThis::~Q3WhatsThis() |
|
68 |
{ |
|
69 |
} |
|
70 |
||
71 |
/*! |
|
72 |
\internal |
|
73 |
||
74 |
Handles "What's This?" events. |
|
75 |
*/ |
|
76 |
bool 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 |
*/ |
|
106 |
QString 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 |
*/ |
|
123 |
bool 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 |
*/ |
|
213 |
QToolButton *Q3WhatsThis::whatsThisButton(QWidget * parent) |
|
214 |
{ |
|
215 |
return QWhatsThis::whatsThisButton(parent); |
|
216 |
} |
|
217 |
||
218 |
QT_END_NAMESPACE |
|
219 |
||
220 |
#endif // QT_NO_WHATSTHIS |