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

Last change on this file since 846 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 6.9 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the Qt3Support module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
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** 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 have questions regarding the use of this file, please contact
37** Nokia 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.