~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/qt3support/widgets/q3whatsthis.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the Qt 3 compatibility classes of the Qt Toolkit.
 
6
**
 
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.
 
10
**
 
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.
 
15
**
 
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.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
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.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#include "q3whatsthis.h"
 
30
#include "qapplication.h"
 
31
#include "qwidget.h"
 
32
#include "qevent.h"
 
33
 
 
34
/*! \class Q3WhatsThis
 
35
    \compat
 
36
*/
 
37
 
 
38
/*!
 
39
    Constructs a new "What's This?" object for \a widget.
 
40
*/
 
41
Q3WhatsThis::Q3WhatsThis(QWidget *widget)
 
42
    : QObject(widget)
 
43
{
 
44
    if (widget)
 
45
        widget->installEventFilter(this);
 
46
}
 
47
 
 
48
/*!
 
49
    Destroys the "What's This?" object.
 
50
*/
 
51
Q3WhatsThis::~Q3WhatsThis()
 
52
{
 
53
}
 
54
 
 
55
/*!
 
56
    \internal
 
57
 
 
58
    Handles "What's This?" events.
 
59
*/
 
60
bool Q3WhatsThis::eventFilter(QObject *o, QEvent *e)
 
61
{
 
62
    if (o != parent() || !o->isWidgetType())
 
63
        return false;
 
64
 
 
65
    if (e->type() == QEvent::WhatsThis) {
 
66
        QString s = text(static_cast<QHelpEvent*>(e)->pos());
 
67
        if (!s.isEmpty())
 
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();
 
71
        if (clicked(href))
 
72
            QWhatsThis::hideText();
 
73
    } else {
 
74
        return false;
 
75
    }
 
76
    return true;
 
77
}
 
78
 
 
79
/*!
 
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.
 
83
 
 
84
    The default implementation returns an empty string.
 
85
*/
 
86
QString Q3WhatsThis::text(const QPoint & /* pos */)
 
87
{
 
88
    if (parent() && parent()->isWidgetType())
 
89
        return static_cast<QWidget*>(parent())->whatsThis();
 
90
    return QString();
 
91
}
 
92
 
 
93
/*!
 
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.
 
97
 
 
98
    If the function returns true (the default), the "What's this?"
 
99
    window is closed, otherwise it remains visible.
 
100
 
 
101
    The default implementation ignores \a href and returns true.
 
102
*/
 
103
bool Q3WhatsThis::clicked(const QString & /* href */)
 
104
{
 
105
    return true;
 
106
}
 
107
 
 
108
/*!
 
109
    \fn void Q3WhatsThis::enterWhatsThisMode()
 
110
 
 
111
    Enters "What's This?" mode and returns immediately.
 
112
 
 
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.
 
118
 
 
119
    The user can also use the Esc key to leave "What's This?" mode.
 
120
 
 
121
    \sa inWhatsThisMode(), leaveWhatsThisMode()
 
122
*/
 
123
 
 
124
/*!
 
125
    \fn bool Q3WhatsThis::inWhatsThisMode()
 
126
 
 
127
    Returns true if the application is in "What's This?" mode;
 
128
    otherwise returns false.
 
129
 
 
130
    \sa enterWhatsThisMode(), leaveWhatsThisMode()
 
131
*/
 
132
 
 
133
/*!
 
134
    \fn void Q3WhatsThis::add(QWidget *widget, const QString &text)
 
135
 
 
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().
 
139
 
 
140
    The text is destroyed if the widget is later destroyed, so it need
 
141
    not be explicitly removed.
 
142
 
 
143
    \sa remove()
 
144
*/
 
145
 
 
146
/*!
 
147
    \fn void Q3WhatsThis::remove(QWidget *widget)
 
148
 
 
149
    Removes the "What's This?" help associated with the \a widget.
 
150
    This happens automatically if the widget is destroyed.
 
151
 
 
152
    \sa add()
 
153
*/
 
154
 
 
155
/*!
 
156
    \fn void Q3WhatsThis::leaveWhatsThisMode(const QString& text = QString(), const QPoint& pos = QCursor::pos(), QWidget* widget = 0)
 
157
 
 
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.
 
163
 
 
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.
 
169
 
 
170
    \sa inWhatsThisMode(), enterWhatsThisMode(), clicked()
 
171
*/
 
172
 
 
173
/*!
 
174
    \fn void Q3WhatsThis::display(const QString &text, const QPoint &pos, QWidget *widget)
 
175
 
 
176
    Display \a text in a help window at the global screen position \a
 
177
    pos.
 
178
 
 
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.
 
182
 
 
183
    \sa clicked()
 
184
*/
 
185
 
 
186
/*!
 
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
 
189
    parent:
 
190
 
 
191
    \code
 
192
        (void)QWhatsThis::whatsThisButton( my_help_tool_bar );
 
193
    \endcode
 
194
*/
 
195
QToolButton *Q3WhatsThis::whatsThisButton(QWidget * parent)
 
196
{
 
197
    return QWhatsThis::whatsThisButton(parent);
 
198
}