Line | Source Code | Coverage |
---|
1 | /**************************************************************************** | - |
2 | ** | - |
3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
4 | ** Contact: http://www.qt-project.org/legal | - |
5 | ** | - |
6 | ** This file is part of the QtGui module of the Qt Toolkit. | - |
7 | ** | - |
8 | ** $QT_BEGIN_LICENSE:LGPL$ | - |
9 | ** Commercial License Usage | - |
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - |
11 | ** accordance with the commercial license agreement provided with the | - |
12 | ** Software or, alternatively, in accordance with the terms contained in | - |
13 | ** a written agreement between you and Digia. For licensing terms and | - |
14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
15 | ** use the contact form at http://qt.digia.com/contact-us. | - |
16 | ** | - |
17 | ** GNU Lesser General Public License Usage | - |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - |
19 | ** General Public License version 2.1 as published by the Free Software | - |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
21 | ** packaging of this file. Please review the following information to | - |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
24 | ** | - |
25 | ** In addition, as a special exception, Digia gives you certain additional | - |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
28 | ** | - |
29 | ** GNU General Public License Usage | - |
30 | ** Alternatively, this file may be used under the terms of the GNU | - |
31 | ** General Public License version 3.0 as published by the Free Software | - |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
33 | ** packaging of this file. Please review the following information to | - |
34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
36 | ** | - |
37 | ** | - |
38 | ** $QT_END_LICENSE$ | - |
39 | ** | - |
40 | ****************************************************************************/ | - |
41 | | - |
42 | #include "qwhatsthis.h" | - |
43 | #ifndef QT_NO_WHATSTHIS | - |
44 | #include "qpointer.h" | - |
45 | #include "qapplication.h" | - |
46 | #include <private/qguiapplication_p.h> | - |
47 | #include "qdesktopwidget.h" | - |
48 | #include "qevent.h" | - |
49 | #include "qpixmap.h" | - |
50 | #include "qscreen.h" | - |
51 | #include "qpainter.h" | - |
52 | #include "qtimer.h" | - |
53 | #include "qhash.h" | - |
54 | #include "qaction.h" | - |
55 | #include "qcursor.h" | - |
56 | #include "qbitmap.h" | - |
57 | #include "qtextdocument.h" | - |
58 | #include <qpa/qplatformtheme.h> | - |
59 | #include "private/qtextdocumentlayout_p.h" | - |
60 | #include "qtoolbutton.h" | - |
61 | #include "qdebug.h" | - |
62 | #ifndef QT_NO_ACCESSIBILITY | - |
63 | #include "qaccessible.h" | - |
64 | #endif | - |
65 | | - |
66 | QT_BEGIN_NAMESPACE | - |
67 | | - |
68 | /*! | - |
69 | \class QWhatsThis | - |
70 | \brief The QWhatsThis class provides a simple description of any | - |
71 | widget, i.e. answering the question "What's This?". | - |
72 | | - |
73 | \ingroup helpsystem | - |
74 | \inmodule QtWidgets | - |
75 | | - |
76 | "What's This?" help is part of an application's online help | - |
77 | system, and provides users with information about the | - |
78 | functionality and usage of a particular widget. "What's This?" | - |
79 | help texts are typically longer and more detailed than | - |
80 | \l{QToolTip}{tooltips}, but generally provide less information | - |
81 | than that supplied by separate help windows. | - |
82 | | - |
83 | QWhatsThis provides a single window with an explanatory text that | - |
84 | pops up when the user asks "What's This?". The default way for | - |
85 | users to ask the question is to move the focus to the relevant | - |
86 | widget and press Shift+F1. The help text appears immediately; it | - |
87 | goes away as soon as the user does something else. | - |
88 | (Note that if there is a shortcut for Shift+F1, this mechanism | - |
89 | will not work.) Some dialogs provide a "?" button that users can | - |
90 | click to enter "What's This?" mode; they then click the relevant | - |
91 | widget to pop up the "What's This?" window. It is also possible to | - |
92 | provide a a menu option or toolbar button to switch into "What's | - |
93 | This?" mode. | - |
94 | | - |
95 | To add "What's This?" text to a widget or an action, you simply | - |
96 | call QWidget::setWhatsThis() or QAction::setWhatsThis(). | - |
97 | | - |
98 | The text can be either rich text or plain text. If you specify a | - |
99 | rich text formatted string, it will be rendered using the default | - |
100 | stylesheet, making it possible to embed images in the displayed | - |
101 | text. To be as fast as possible, the default stylesheet uses a | - |
102 | simple method to determine whether the text can be rendered as | - |
103 | plain text. See Qt::mightBeRichText() for details. | - |
104 | | - |
105 | \snippet whatsthis/whatsthis.cpp 0 | - |
106 | | - |
107 | An alternative way to enter "What's This?" mode is to call | - |
108 | createAction(), and add the returned QAction to either a menu or | - |
109 | a tool bar. By invoking this context help action (in the picture | - |
110 | below, the button with the arrow and question mark icon) the user | - |
111 | switches into "What's This?" mode. If they now click on a widget | - |
112 | the appropriate help text is shown. The mode is left when help is | - |
113 | given or when the user presses Esc. | - |
114 | | - |
115 | \image whatsthis.png | - |
116 | | - |
117 | You can enter "What's This?" mode programmatically with | - |
118 | enterWhatsThisMode(), check the mode with inWhatsThisMode(), and | - |
119 | return to normal mode with leaveWhatsThisMode(). | - |
120 | | - |
121 | If you want to control the "What's This?" behavior of a widget | - |
122 | manually see Qt::WA_CustomWhatsThis. | - |
123 | | - |
124 | It is also possible to show different help texts for different | - |
125 | regions of a widget, by using a QHelpEvent of type | - |
126 | QEvent::WhatsThis. Intercept the help event in your widget's | - |
127 | QWidget::event() function and call QWhatsThis::showText() with the | - |
128 | text you want to display for the position specified in | - |
129 | QHelpEvent::pos(). If the text is rich text and the user clicks | - |
130 | on a link, the widget also receives a QWhatsThisClickedEvent with | - |
131 | the link's reference as QWhatsThisClickedEvent::href(). If a | - |
132 | QWhatsThisClickedEvent is handled (i.e. QWidget::event() returns | - |
133 | true), the help window remains visible. Call | - |
134 | QWhatsThis::hideText() to hide it explicitly. | - |
135 | | - |
136 | \sa QToolTip | - |
137 | */ | - |
138 | | - |
139 | Q_CORE_EXPORT void qDeleteInEventHandler(QObject *o); | - |
140 | | - |
141 | class QWhatsThat : public QWidget | - |
142 | { | - |
143 | Q_OBJECT | - |
144 | | - |
145 | public: | - |
146 | QWhatsThat(const QString& txt, QWidget* parent, QWidget *showTextFor); | - |
147 | ~QWhatsThat() ; | - |
148 | | - |
149 | static QWhatsThat *instance; | - |
150 | | - |
151 | protected: | - |
152 | void showEvent(QShowEvent *e); | - |
153 | void mousePressEvent(QMouseEvent*); | - |
154 | void mouseReleaseEvent(QMouseEvent*); | - |
155 | void mouseMoveEvent(QMouseEvent*); | - |
156 | void keyPressEvent(QKeyEvent*); | - |
157 | void paintEvent(QPaintEvent*); | - |
158 | | - |
159 | private: | - |
160 | QPointer<QWidget>widget; | - |
161 | bool pressed; | - |
162 | QString text; | - |
163 | QTextDocument* doc; | - |
164 | QString anchor; | - |
165 | QPixmap background; | - |
166 | }; | - |
167 | | - |
168 | QWhatsThat *QWhatsThat::instance = 0; | - |
169 | | - |
170 | // shadowWidth not const, for XP drop-shadow-fu turns it to 0 | - |
171 | static int shadowWidth = 6; // also used as '5' and '6' and even '8' below | - |
172 | static const int vMargin = 8; | - |
173 | static const int hMargin = 12; | - |
174 | | - |
175 | static inline bool dropShadow() | - |
176 | { | - |
177 | if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) partially evaluated: const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme() yes Evaluation Count:2 | no Evaluation Count:0 |
| 0-2 |
178 | return theme->themeHint(QPlatformTheme::DropShadow).toBool(); executed: return theme->themeHint(QPlatformTheme::DropShadow).toBool(); Execution Count:2 | 2 |
179 | return false; never executed: return false; | 0 |
180 | } | - |
181 | | - |
182 | QWhatsThat::QWhatsThat(const QString& txt, QWidget* parent, QWidget *showTextFor) | - |
183 | : QWidget(parent, Qt::Popup), | - |
184 | widget(showTextFor), pressed(false), text(txt) | - |
185 | { | - |
186 | delete instance; executed (the execution status of this line is deduced): delete instance; | - |
187 | instance = this; executed (the execution status of this line is deduced): instance = this; | - |
188 | setAttribute(Qt::WA_DeleteOnClose, true); executed (the execution status of this line is deduced): setAttribute(Qt::WA_DeleteOnClose, true); | - |
189 | setAttribute(Qt::WA_NoSystemBackground, true); executed (the execution status of this line is deduced): setAttribute(Qt::WA_NoSystemBackground, true); | - |
190 | if (parent) partially evaluated: parent no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
191 | setPalette(parent->palette()); never executed: setPalette(parent->palette()); | 0 |
192 | setMouseTracking(true); executed (the execution status of this line is deduced): setMouseTracking(true); | - |
193 | setFocusPolicy(Qt::StrongFocus); executed (the execution status of this line is deduced): setFocusPolicy(Qt::StrongFocus); | - |
194 | #ifndef QT_NO_CURSOR | - |
195 | setCursor(Qt::ArrowCursor); executed (the execution status of this line is deduced): setCursor(Qt::ArrowCursor); | - |
196 | #endif | - |
197 | QRect r; executed (the execution status of this line is deduced): QRect r; | - |
198 | doc = 0; executed (the execution status of this line is deduced): doc = 0; | - |
199 | ensurePolished(); // Ensures style sheet font before size calc executed (the execution status of this line is deduced): ensurePolished(); | - |
200 | if (Qt::mightBeRichText(text)) { partially evaluated: Qt::mightBeRichText(text) no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
201 | doc = new QTextDocument(); never executed (the execution status of this line is deduced): doc = new QTextDocument(); | - |
202 | doc->setUndoRedoEnabled(false); never executed (the execution status of this line is deduced): doc->setUndoRedoEnabled(false); | - |
203 | doc->setDefaultFont(QApplication::font(this)); never executed (the execution status of this line is deduced): doc->setDefaultFont(QApplication::font(this)); | - |
204 | #ifdef QT_NO_TEXTHTMLPARSER | - |
205 | doc->setPlainText(text); | - |
206 | #else | - |
207 | doc->setHtml(text); never executed (the execution status of this line is deduced): doc->setHtml(text); | - |
208 | #endif | - |
209 | doc->setUndoRedoEnabled(false); never executed (the execution status of this line is deduced): doc->setUndoRedoEnabled(false); | - |
210 | doc->adjustSize(); never executed (the execution status of this line is deduced): doc->adjustSize(); | - |
211 | r.setTop(0); never executed (the execution status of this line is deduced): r.setTop(0); | - |
212 | r.setLeft(0); never executed (the execution status of this line is deduced): r.setLeft(0); | - |
213 | r.setSize(doc->size().toSize()); never executed (the execution status of this line is deduced): r.setSize(doc->size().toSize()); | - |
214 | } | 0 |
215 | else | - |
216 | { | - |
217 | int sw = QApplication::desktop()->width() / 3; executed (the execution status of this line is deduced): int sw = QApplication::desktop()->width() / 3; | - |
218 | if (sw < 200) partially evaluated: sw < 200 no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
219 | sw = 200; never executed: sw = 200; | 0 |
220 | else if (sw > 300) partially evaluated: sw > 300 yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
221 | sw = 300; executed: sw = 300; Execution Count:1 | 1 |
222 | | - |
223 | r = fontMetrics().boundingRect(0, 0, sw, 1000, executed (the execution status of this line is deduced): r = fontMetrics().boundingRect(0, 0, sw, 1000, | - |
224 | Qt::AlignLeft + Qt::AlignTop executed (the execution status of this line is deduced): Qt::AlignLeft + Qt::AlignTop | - |
225 | + Qt::TextWordWrap + Qt::TextExpandTabs, executed (the execution status of this line is deduced): + Qt::TextWordWrap + Qt::TextExpandTabs, | - |
226 | text); executed (the execution status of this line is deduced): text); | - |
227 | } executed: } Execution Count:1 | 1 |
228 | shadowWidth = dropShadow() ? 0 : 6; partially evaluated: dropShadow() no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
229 | resize(r.width() + 2*hMargin + shadowWidth, r.height() + 2*vMargin + shadowWidth); executed (the execution status of this line is deduced): resize(r.width() + 2*hMargin + shadowWidth, r.height() + 2*vMargin + shadowWidth); | - |
230 | } executed: } Execution Count:1 | 1 |
231 | | - |
232 | QWhatsThat::~QWhatsThat() | - |
233 | { | - |
234 | instance = 0; never executed (the execution status of this line is deduced): instance = 0; | - |
235 | if (doc) | 0 |
236 | delete doc; never executed: delete doc; | 0 |
237 | } | 0 |
238 | | - |
239 | void QWhatsThat::showEvent(QShowEvent *) | - |
240 | { | - |
241 | background = QGuiApplication::primaryScreen()->grabWindow(QApplication::desktop()->internalWinId(), executed (the execution status of this line is deduced): background = QGuiApplication::primaryScreen()->grabWindow(QApplication::desktop()->internalWinId(), | - |
242 | x(), y(), width(), height()); executed (the execution status of this line is deduced): x(), y(), width(), height()); | - |
243 | } executed: } Execution Count:1 | 1 |
244 | | - |
245 | void QWhatsThat::mousePressEvent(QMouseEvent* e) | - |
246 | { | - |
247 | pressed = true; never executed (the execution status of this line is deduced): pressed = true; | - |
248 | if (e->button() == Qt::LeftButton && rect().contains(e->pos())) { never evaluated: e->button() == Qt::LeftButton never evaluated: rect().contains(e->pos()) | 0 |
249 | if (doc) | 0 |
250 | anchor = doc->documentLayout()->anchorAt(e->pos() - QPoint(hMargin, vMargin)); never executed: anchor = doc->documentLayout()->anchorAt(e->pos() - QPoint(hMargin, vMargin)); | 0 |
251 | return; | 0 |
252 | } | - |
253 | close(); never executed (the execution status of this line is deduced): close(); | - |
254 | } | 0 |
255 | | - |
256 | void QWhatsThat::mouseReleaseEvent(QMouseEvent* e) | - |
257 | { | - |
258 | if (!pressed) never evaluated: !pressed | 0 |
259 | return; | 0 |
260 | if (widget && e->button() == Qt::LeftButton && doc && rect().contains(e->pos())) { never evaluated: widget never evaluated: e->button() == Qt::LeftButton never evaluated: doc never evaluated: rect().contains(e->pos()) | 0 |
261 | QString a = doc->documentLayout()->anchorAt(e->pos() - QPoint(hMargin, vMargin)); never executed (the execution status of this line is deduced): QString a = doc->documentLayout()->anchorAt(e->pos() - QPoint(hMargin, vMargin)); | - |
262 | QString href; never executed (the execution status of this line is deduced): QString href; | - |
263 | if (anchor == a) never evaluated: anchor == a | 0 |
264 | href = a; never executed: href = a; | 0 |
265 | anchor.clear(); never executed (the execution status of this line is deduced): anchor.clear(); | - |
266 | if (!href.isEmpty()) { never evaluated: !href.isEmpty() | 0 |
267 | QWhatsThisClickedEvent e(href); never executed (the execution status of this line is deduced): QWhatsThisClickedEvent e(href); | - |
268 | if (QApplication::sendEvent(widget, &e)) never evaluated: QApplication::sendEvent(widget, &e) | 0 |
269 | return; | 0 |
270 | } | 0 |
271 | } | 0 |
272 | close(); never executed (the execution status of this line is deduced): close(); | - |
273 | } | 0 |
274 | | - |
275 | void QWhatsThat::mouseMoveEvent(QMouseEvent* e) | - |
276 | { | - |
277 | #ifdef QT_NO_CURSOR | - |
278 | Q_UNUSED(e); | - |
279 | #else | - |
280 | if (!doc) | 0 |
281 | return; | 0 |
282 | QString a = doc->documentLayout()->anchorAt(e->pos() - QPoint(hMargin, vMargin)); never executed (the execution status of this line is deduced): QString a = doc->documentLayout()->anchorAt(e->pos() - QPoint(hMargin, vMargin)); | - |
283 | if (!a.isEmpty()) never evaluated: !a.isEmpty() | 0 |
284 | setCursor(Qt::PointingHandCursor); never executed: setCursor(Qt::PointingHandCursor); | 0 |
285 | else | - |
286 | setCursor(Qt::ArrowCursor); never executed: setCursor(Qt::ArrowCursor); | 0 |
287 | #endif | - |
288 | } | - |
289 | | - |
290 | void QWhatsThat::keyPressEvent(QKeyEvent*) | - |
291 | { | - |
292 | close(); never executed (the execution status of this line is deduced): close(); | - |
293 | } | 0 |
294 | | - |
295 | void QWhatsThat::paintEvent(QPaintEvent*) | - |
296 | { | - |
297 | const bool drawShadow = dropShadow(); executed (the execution status of this line is deduced): const bool drawShadow = dropShadow(); | - |
298 | | - |
299 | QRect r = rect(); executed (the execution status of this line is deduced): QRect r = rect(); | - |
300 | r.adjust(0, 0, -1, -1); executed (the execution status of this line is deduced): r.adjust(0, 0, -1, -1); | - |
301 | if (drawShadow) partially evaluated: drawShadow no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
302 | r.adjust(0, 0, -shadowWidth, -shadowWidth); never executed: r.adjust(0, 0, -shadowWidth, -shadowWidth); | 0 |
303 | QPainter p(this); executed (the execution status of this line is deduced): QPainter p(this); | - |
304 | p.drawPixmap(0, 0, background); executed (the execution status of this line is deduced): p.drawPixmap(0, 0, background); | - |
305 | p.setPen(QPen(palette().toolTipText(), 0)); executed (the execution status of this line is deduced): p.setPen(QPen(palette().toolTipText(), 0)); | - |
306 | p.setBrush(palette().toolTipBase()); executed (the execution status of this line is deduced): p.setBrush(palette().toolTipBase()); | - |
307 | p.drawRect(r); executed (the execution status of this line is deduced): p.drawRect(r); | - |
308 | int w = r.width(); executed (the execution status of this line is deduced): int w = r.width(); | - |
309 | int h = r.height(); executed (the execution status of this line is deduced): int h = r.height(); | - |
310 | p.setPen(palette().brush(QPalette::Dark).color()); executed (the execution status of this line is deduced): p.setPen(palette().brush(QPalette::Dark).color()); | - |
311 | p.drawRect(1, 1, w-2, h-2); executed (the execution status of this line is deduced): p.drawRect(1, 1, w-2, h-2); | - |
312 | if (drawShadow) { partially evaluated: drawShadow no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
313 | p.setPen(palette().shadow().color()); never executed (the execution status of this line is deduced): p.setPen(palette().shadow().color()); | - |
314 | p.drawPoint(w + 5, 6); never executed (the execution status of this line is deduced): p.drawPoint(w + 5, 6); | - |
315 | p.drawLine(w + 3, 6, w + 5, 8); never executed (the execution status of this line is deduced): p.drawLine(w + 3, 6, w + 5, 8); | - |
316 | p.drawLine(w + 1, 6, w + 5, 10); never executed (the execution status of this line is deduced): p.drawLine(w + 1, 6, w + 5, 10); | - |
317 | int i; never executed (the execution status of this line is deduced): int i; | - |
318 | for(i=7; i < h; i += 2) | 0 |
319 | p.drawLine(w, i, w + 5, i + 5); never executed: p.drawLine(w, i, w + 5, i + 5); | 0 |
320 | for(i = w - i + h; i > 6; i -= 2) | 0 |
321 | p.drawLine(i, h, i + 5, h + 5); never executed: p.drawLine(i, h, i + 5, h + 5); | 0 |
322 | for(; i > 0 ; i -= 2) | 0 |
323 | p.drawLine(6, h + 6 - i, i + 5, h + 5); never executed: p.drawLine(6, h + 6 - i, i + 5, h + 5); | 0 |
324 | } | 0 |
325 | r.adjust(0, 0, 1, 1); executed (the execution status of this line is deduced): r.adjust(0, 0, 1, 1); | - |
326 | p.setPen(palette().toolTipText().color()); executed (the execution status of this line is deduced): p.setPen(palette().toolTipText().color()); | - |
327 | r.adjust(hMargin, vMargin, -hMargin, -vMargin); executed (the execution status of this line is deduced): r.adjust(hMargin, vMargin, -hMargin, -vMargin); | - |
328 | | - |
329 | if (doc) { partially evaluated: doc no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
330 | p.translate(r.x(), r.y()); never executed (the execution status of this line is deduced): p.translate(r.x(), r.y()); | - |
331 | QRect rect = r; never executed (the execution status of this line is deduced): QRect rect = r; | - |
332 | rect.translate(-r.x(), -r.y()); never executed (the execution status of this line is deduced): rect.translate(-r.x(), -r.y()); | - |
333 | p.setClipRect(rect); never executed (the execution status of this line is deduced): p.setClipRect(rect); | - |
334 | QAbstractTextDocumentLayout::PaintContext context; never executed (the execution status of this line is deduced): QAbstractTextDocumentLayout::PaintContext context; | - |
335 | context.palette.setBrush(QPalette::Text, context.palette.toolTipText()); never executed (the execution status of this line is deduced): context.palette.setBrush(QPalette::Text, context.palette.toolTipText()); | - |
336 | doc->documentLayout()->draw(&p, context); never executed (the execution status of this line is deduced): doc->documentLayout()->draw(&p, context); | - |
337 | } | 0 |
338 | else | - |
339 | { | - |
340 | p.drawText(r, Qt::AlignLeft + Qt::AlignTop + Qt::TextWordWrap + Qt::TextExpandTabs, text); executed (the execution status of this line is deduced): p.drawText(r, Qt::AlignLeft + Qt::AlignTop + Qt::TextWordWrap + Qt::TextExpandTabs, text); | - |
341 | } executed: } Execution Count:1 | 1 |
342 | } | - |
343 | | - |
344 | static const char * const button_image[] = { | - |
345 | "16 16 3 1", | - |
346 | " c None", | - |
347 | "o c #000000", | - |
348 | "a c #000080", | - |
349 | "o aaaaa ", | - |
350 | "oo aaa aaa ", | - |
351 | "ooo aaa aaa", | - |
352 | "oooo aa aa", | - |
353 | "ooooo aa aa", | - |
354 | "oooooo a aaa", | - |
355 | "ooooooo aaa ", | - |
356 | "oooooooo aaa ", | - |
357 | "ooooooooo aaa ", | - |
358 | "ooooo aaa ", | - |
359 | "oo ooo ", | - |
360 | "o ooo aaa ", | - |
361 | " ooo aaa ", | - |
362 | " ooo ", | - |
363 | " ooo ", | - |
364 | " ooo "}; | - |
365 | | - |
366 | class QWhatsThisPrivate : public QObject | - |
367 | { | - |
368 | public: | - |
369 | QWhatsThisPrivate(); | - |
370 | ~QWhatsThisPrivate(); | - |
371 | static QWhatsThisPrivate *instance; | - |
372 | bool eventFilter(QObject *, QEvent *); | - |
373 | QPointer<QAction> action; | - |
374 | static void say(QWidget *, const QString &, int x = 0, int y = 0); | - |
375 | static void notifyToplevels(QEvent *e); | - |
376 | bool leaveOnMouseRelease; | - |
377 | }; | - |
378 | | - |
379 | void QWhatsThisPrivate::notifyToplevels(QEvent *e) | - |
380 | { | - |
381 | QWidgetList toplevels = QApplication::topLevelWidgets(); executed (the execution status of this line is deduced): QWidgetList toplevels = QApplication::topLevelWidgets(); | - |
382 | for (int i = 0; i < toplevels.count(); ++i) { partially evaluated: i < toplevels.count() no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
383 | register QWidget *w = toplevels.at(i); never executed (the execution status of this line is deduced): register QWidget *w = toplevels.at(i); | - |
384 | QApplication::sendEvent(w, e); never executed (the execution status of this line is deduced): QApplication::sendEvent(w, e); | - |
385 | } | 0 |
386 | } executed: } Execution Count:1 | 1 |
387 | | - |
388 | QWhatsThisPrivate *QWhatsThisPrivate::instance = 0; | - |
389 | | - |
390 | QWhatsThisPrivate::QWhatsThisPrivate() | - |
391 | : leaveOnMouseRelease(false) | - |
392 | { | - |
393 | instance = this; never executed (the execution status of this line is deduced): instance = this; | - |
394 | qApp->installEventFilter(this); never executed (the execution status of this line is deduced): (static_cast<QApplication *>(QCoreApplication::instance()))->installEventFilter(this); | - |
395 | | - |
396 | QPoint pos = QCursor::pos(); never executed (the execution status of this line is deduced): QPoint pos = QCursor::pos(); | - |
397 | if (QWidget *w = QApplication::widgetAt(pos)) { never evaluated: QWidget *w = QApplication::widgetAt(pos) | 0 |
398 | QHelpEvent e(QEvent::QueryWhatsThis, w->mapFromGlobal(pos), pos); never executed (the execution status of this line is deduced): QHelpEvent e(QEvent::QueryWhatsThis, w->mapFromGlobal(pos), pos); | - |
399 | bool sentEvent = QApplication::sendEvent(w, &e); never executed (the execution status of this line is deduced): bool sentEvent = QApplication::sendEvent(w, &e); | - |
400 | #ifdef QT_NO_CURSOR | - |
401 | Q_UNUSED(sentEvent); | - |
402 | #else | - |
403 | QApplication::setOverrideCursor((!sentEvent || !e.isAccepted())? never executed (the execution status of this line is deduced): QApplication::setOverrideCursor((!sentEvent || !e.isAccepted())? | - |
404 | Qt::ForbiddenCursor:Qt::WhatsThisCursor); never executed (the execution status of this line is deduced): Qt::ForbiddenCursor:Qt::WhatsThisCursor); | - |
405 | } else { | 0 |
406 | QApplication::setOverrideCursor(Qt::WhatsThisCursor); never executed (the execution status of this line is deduced): QApplication::setOverrideCursor(Qt::WhatsThisCursor); | - |
407 | #endif | - |
408 | } | 0 |
409 | #ifndef QT_NO_ACCESSIBILITY | - |
410 | QAccessibleEvent event(this, QAccessible::ContextHelpStart); never executed (the execution status of this line is deduced): QAccessibleEvent event(this, QAccessible::ContextHelpStart); | - |
411 | QAccessible::updateAccessibility(&event); never executed (the execution status of this line is deduced): QAccessible::updateAccessibility(&event); | - |
412 | #endif | - |
413 | } | 0 |
414 | | - |
415 | QWhatsThisPrivate::~QWhatsThisPrivate() | - |
416 | { | - |
417 | if (action) | 0 |
418 | action->setChecked(false); never executed: action->setChecked(false); | 0 |
419 | #ifndef QT_NO_CURSOR | - |
420 | QApplication::restoreOverrideCursor(); never executed (the execution status of this line is deduced): QApplication::restoreOverrideCursor(); | - |
421 | #endif | - |
422 | #ifndef QT_NO_ACCESSIBILITY | - |
423 | QAccessibleEvent event(this, QAccessible::ContextHelpEnd); never executed (the execution status of this line is deduced): QAccessibleEvent event(this, QAccessible::ContextHelpEnd); | - |
424 | QAccessible::updateAccessibility(&event); never executed (the execution status of this line is deduced): QAccessible::updateAccessibility(&event); | - |
425 | #endif | - |
426 | instance = 0; never executed (the execution status of this line is deduced): instance = 0; | - |
427 | } | 0 |
428 | | - |
429 | bool QWhatsThisPrivate::eventFilter(QObject *o, QEvent *e) | - |
430 | { | - |
431 | if (!o->isWidgetType()) never evaluated: !o->isWidgetType() | 0 |
432 | return false; never executed: return false; | 0 |
433 | QWidget * w = static_cast<QWidget *>(o); never executed (the execution status of this line is deduced): QWidget * w = static_cast<QWidget *>(o); | - |
434 | bool customWhatsThis = w->testAttribute(Qt::WA_CustomWhatsThis); never executed (the execution status of this line is deduced): bool customWhatsThis = w->testAttribute(Qt::WA_CustomWhatsThis); | - |
435 | switch (e->type()) { | - |
436 | case QEvent::MouseButtonPress: | - |
437 | { | - |
438 | QMouseEvent *me = static_cast<QMouseEvent*>(e); never executed (the execution status of this line is deduced): QMouseEvent *me = static_cast<QMouseEvent*>(e); | - |
439 | if (me->button() == Qt::RightButton || customWhatsThis) never evaluated: me->button() == Qt::RightButton never evaluated: customWhatsThis | 0 |
440 | return false; never executed: return false; | 0 |
441 | QHelpEvent e(QEvent::WhatsThis, me->pos(), me->globalPos()); never executed (the execution status of this line is deduced): QHelpEvent e(QEvent::WhatsThis, me->pos(), me->globalPos()); | - |
442 | if (!QApplication::sendEvent(w, &e) || !e.isAccepted()) never evaluated: !QApplication::sendEvent(w, &e) never evaluated: !e.isAccepted() | 0 |
443 | leaveOnMouseRelease = true; never executed: leaveOnMouseRelease = true; | 0 |
444 | | - |
445 | } break; | 0 |
446 | | - |
447 | case QEvent::MouseMove: | - |
448 | { | - |
449 | QMouseEvent *me = static_cast<QMouseEvent*>(e); never executed (the execution status of this line is deduced): QMouseEvent *me = static_cast<QMouseEvent*>(e); | - |
450 | QHelpEvent e(QEvent::QueryWhatsThis, me->pos(), me->globalPos()); never executed (the execution status of this line is deduced): QHelpEvent e(QEvent::QueryWhatsThis, me->pos(), me->globalPos()); | - |
451 | bool sentEvent = QApplication::sendEvent(w, &e); never executed (the execution status of this line is deduced): bool sentEvent = QApplication::sendEvent(w, &e); | - |
452 | #ifdef QT_NO_CURSOR | - |
453 | Q_UNUSED(sentEvent); | - |
454 | #else | - |
455 | QApplication::changeOverrideCursor((!sentEvent || !e.isAccepted())? never executed (the execution status of this line is deduced): QApplication::changeOverrideCursor((!sentEvent || !e.isAccepted())? | - |
456 | Qt::ForbiddenCursor:Qt::WhatsThisCursor); never executed (the execution status of this line is deduced): Qt::ForbiddenCursor:Qt::WhatsThisCursor); | - |
457 | #endif | - |
458 | } | - |
459 | // fall through | - |
460 | case QEvent::MouseButtonRelease: code before this statement never executed: case QEvent::MouseButtonRelease: | 0 |
461 | case QEvent::MouseButtonDblClick: | - |
462 | if (leaveOnMouseRelease && e->type() == QEvent::MouseButtonRelease) never evaluated: leaveOnMouseRelease never evaluated: e->type() == QEvent::MouseButtonRelease | 0 |
463 | QWhatsThis::leaveWhatsThisMode(); never executed: QWhatsThis::leaveWhatsThisMode(); | 0 |
464 | if (static_cast<QMouseEvent*>(e)->button() == Qt::RightButton || customWhatsThis) never evaluated: static_cast<QMouseEvent*>(e)->button() == Qt::RightButton never evaluated: customWhatsThis | 0 |
465 | return false; // ignore RMB release never executed: return false; | 0 |
466 | break; | 0 |
467 | case QEvent::KeyPress: | - |
468 | { | - |
469 | QKeyEvent* kev = (QKeyEvent*)e; never executed (the execution status of this line is deduced): QKeyEvent* kev = (QKeyEvent*)e; | - |
470 | | - |
471 | if (kev->key() == Qt::Key_Escape) { never evaluated: kev->key() == Qt::Key_Escape | 0 |
472 | QWhatsThis::leaveWhatsThisMode(); never executed (the execution status of this line is deduced): QWhatsThis::leaveWhatsThisMode(); | - |
473 | return true; never executed: return true; | 0 |
474 | } else if (customWhatsThis) { never evaluated: customWhatsThis | 0 |
475 | return false; never executed: return false; | 0 |
476 | } else if (kev->key() == Qt::Key_Menu || never evaluated: kev->key() == Qt::Key_Menu | 0 |
477 | (kev->key() == Qt::Key_F10 && never evaluated: kev->key() == Qt::Key_F10 | 0 |
478 | kev->modifiers() == Qt::ShiftModifier)) { never evaluated: kev->modifiers() == Qt::ShiftModifier | 0 |
479 | // we don't react to these keys, they are used for context menus | - |
480 | return false; never executed: return false; | 0 |
481 | } else if (kev->key() != Qt::Key_Shift && kev->key() != Qt::Key_Alt // not a modifier key never evaluated: kev->key() != Qt::Key_Shift never evaluated: kev->key() != Qt::Key_Alt | 0 |
482 | && kev->key() != Qt::Key_Control && kev->key() != Qt::Key_Meta) { never evaluated: kev->key() != Qt::Key_Control never evaluated: kev->key() != Qt::Key_Meta | 0 |
483 | QWhatsThis::leaveWhatsThisMode(); never executed (the execution status of this line is deduced): QWhatsThis::leaveWhatsThisMode(); | - |
484 | } | 0 |
485 | } break; | 0 |
486 | default: | - |
487 | return false; never executed: return false; | 0 |
488 | } | - |
489 | return true; never executed: return true; | 0 |
490 | } | - |
491 | | - |
492 | class QWhatsThisAction: public QAction | - |
493 | { | - |
494 | Q_OBJECT | - |
495 | | - |
496 | public: | - |
497 | explicit QWhatsThisAction(QObject* parent = 0); | - |
498 | | - |
499 | private slots: | - |
500 | void actionTriggered(); | - |
501 | }; | - |
502 | | - |
503 | QWhatsThisAction::QWhatsThisAction(QObject *parent) : QAction(tr("What's This?"), parent) | - |
504 | { | - |
505 | #ifndef QT_NO_IMAGEFORMAT_XPM | - |
506 | QPixmap p((const char**)button_image); never executed (the execution status of this line is deduced): QPixmap p((const char**)button_image); | - |
507 | setIcon(p); never executed (the execution status of this line is deduced): setIcon(p); | - |
508 | #endif | - |
509 | setCheckable(true); never executed (the execution status of this line is deduced): setCheckable(true); | - |
510 | connect(this, SIGNAL(triggered()), this, SLOT(actionTriggered())); never executed (the execution status of this line is deduced): connect(this, "2""triggered()", this, "1""actionTriggered()"); | - |
511 | #ifndef QT_NO_SHORTCUT | - |
512 | setShortcut(Qt::ShiftModifier + Qt::Key_F1); never executed (the execution status of this line is deduced): setShortcut(Qt::ShiftModifier + Qt::Key_F1); | - |
513 | #endif | - |
514 | } | 0 |
515 | | - |
516 | void QWhatsThisAction::actionTriggered() | - |
517 | { | - |
518 | if (isChecked()) { never evaluated: isChecked() | 0 |
519 | QWhatsThis::enterWhatsThisMode(); never executed (the execution status of this line is deduced): QWhatsThis::enterWhatsThisMode(); | - |
520 | QWhatsThisPrivate::instance->action = this; never executed (the execution status of this line is deduced): QWhatsThisPrivate::instance->action = this; | - |
521 | } | 0 |
522 | } | 0 |
523 | | - |
524 | /*! | - |
525 | This function switches the user interface into "What's This?" | - |
526 | mode. The user interface can be switched back into normal mode by | - |
527 | the user (e.g. by them clicking or pressing Esc), or | - |
528 | programmatically by calling leaveWhatsThisMode(). | - |
529 | | - |
530 | When entering "What's This?" mode, a QEvent of type | - |
531 | Qt::EnterWhatsThisMode is sent to all toplevel widgets. | - |
532 | | - |
533 | \sa inWhatsThisMode(), leaveWhatsThisMode() | - |
534 | */ | - |
535 | void QWhatsThis::enterWhatsThisMode() | - |
536 | { | - |
537 | if (QWhatsThisPrivate::instance) never evaluated: QWhatsThisPrivate::instance | 0 |
538 | return; | 0 |
539 | (void) new QWhatsThisPrivate; never executed (the execution status of this line is deduced): (void) new QWhatsThisPrivate; | - |
540 | QEvent e(QEvent::EnterWhatsThisMode); never executed (the execution status of this line is deduced): QEvent e(QEvent::EnterWhatsThisMode); | - |
541 | QWhatsThisPrivate::notifyToplevels(&e); never executed (the execution status of this line is deduced): QWhatsThisPrivate::notifyToplevels(&e); | - |
542 | } | 0 |
543 | | - |
544 | /*! | - |
545 | Returns true if the user interface is in "What's This?" mode; | - |
546 | otherwise returns false. | - |
547 | | - |
548 | \sa enterWhatsThisMode() | - |
549 | */ | - |
550 | bool QWhatsThis::inWhatsThisMode() | - |
551 | { | - |
552 | return (QWhatsThisPrivate::instance != 0); executed: return (QWhatsThisPrivate::instance != 0); Execution Count:161 | 161 |
553 | } | - |
554 | | - |
555 | /*! | - |
556 | If the user interface is in "What's This?" mode, this function | - |
557 | switches back to normal mode; otherwise it does nothing. | - |
558 | | - |
559 | When leaving "What's This?" mode, a QEvent of type | - |
560 | Qt::LeaveWhatsThisMode is sent to all toplevel widgets. | - |
561 | | - |
562 | \sa enterWhatsThisMode(), inWhatsThisMode() | - |
563 | */ | - |
564 | void QWhatsThis::leaveWhatsThisMode() | - |
565 | { | - |
566 | delete QWhatsThisPrivate::instance; executed (the execution status of this line is deduced): delete QWhatsThisPrivate::instance; | - |
567 | QEvent e(QEvent::LeaveWhatsThisMode); executed (the execution status of this line is deduced): QEvent e(QEvent::LeaveWhatsThisMode); | - |
568 | QWhatsThisPrivate::notifyToplevels(&e); executed (the execution status of this line is deduced): QWhatsThisPrivate::notifyToplevels(&e); | - |
569 | } executed: } Execution Count:1 | 1 |
570 | | - |
571 | void QWhatsThisPrivate::say(QWidget * widget, const QString &text, int x, int y) | - |
572 | { | - |
573 | if (text.size() == 0) partially evaluated: text.size() == 0 no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
574 | return; | 0 |
575 | // make a fresh widget, and set it up | - |
576 | QWhatsThat *whatsThat = new QWhatsThat( executed (the execution status of this line is deduced): QWhatsThat *whatsThat = new QWhatsThat( | - |
577 | text, executed (the execution status of this line is deduced): text, | - |
578 | #if defined(Q_WS_X11) && !defined(QT_NO_CURSOR) executed (the execution status of this line is deduced):
| - |
579 | QApplication::desktop()->screen(widget ? widget->x11Info().screen() : QCursor::x11Screen()), executed (the execution status of this line is deduced):
| - |
580 | #else executed (the execution status of this line is deduced):
| - |
581 | 0, executed (the execution status of this line is deduced): 0, | - |
582 | #endif executed (the execution status of this line is deduced):
| - |
583 | widget executed (the execution status of this line is deduced): widget | - |
584 | ); executed (the execution status of this line is deduced): ); | - |
585 | | - |
586 | | - |
587 | // okay, now to find a suitable location | - |
588 | | - |
589 | int scr = (widget ? partially evaluated: widget no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
590 | QApplication::desktop()->screenNumber(widget) : executed (the execution status of this line is deduced): QApplication::desktop()->screenNumber(widget) : | - |
591 | #if defined(Q_WS_X11) && !defined(QT_NO_CURSOR) executed (the execution status of this line is deduced):
| - |
592 | QCursor::x11Screen() executed (the execution status of this line is deduced):
| - |
593 | #else executed (the execution status of this line is deduced):
| - |
594 | QApplication::desktop()->screenNumber(QPoint(x,y)) executed (the execution status of this line is deduced): QApplication::desktop()->screenNumber(QPoint(x,y)) | - |
595 | #endif // Q_WS_X11 executed (the execution status of this line is deduced):
| - |
596 | ); executed (the execution status of this line is deduced): ); | - |
597 | QRect screen = QApplication::desktop()->screenGeometry(scr); executed (the execution status of this line is deduced): QRect screen = QApplication::desktop()->screenGeometry(scr); | - |
598 | | - |
599 | int w = whatsThat->width(); executed (the execution status of this line is deduced): int w = whatsThat->width(); | - |
600 | int h = whatsThat->height(); executed (the execution status of this line is deduced): int h = whatsThat->height(); | - |
601 | int sx = screen.x(); executed (the execution status of this line is deduced): int sx = screen.x(); | - |
602 | int sy = screen.y(); executed (the execution status of this line is deduced): int sy = screen.y(); | - |
603 | | - |
604 | // first try locating the widget immediately above/below, | - |
605 | // with nice alignment if possible. | - |
606 | QPoint pos; executed (the execution status of this line is deduced): QPoint pos; | - |
607 | if (widget) partially evaluated: widget no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
608 | pos = widget->mapToGlobal(QPoint(0,0)); never executed: pos = widget->mapToGlobal(QPoint(0,0)); | 0 |
609 | | - |
610 | if (widget && w > widget->width() + 16) partially evaluated: widget no Evaluation Count:0 | yes Evaluation Count:1 |
never evaluated: w > widget->width() + 16 | 0-1 |
611 | x = pos.x() + widget->width()/2 - w/2; never executed: x = pos.x() + widget->width()/2 - w/2; | 0 |
612 | else | - |
613 | x = x - w/2; executed: x = x - w/2; Execution Count:1 | 1 |
614 | | - |
615 | // squeeze it in if that would result in part of what's this | - |
616 | // being only partially visible | - |
617 | if (x + w + shadowWidth > sx+screen.width()) partially evaluated: x + w + shadowWidth > sx+screen.width() no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
618 | x = (widget? (qMin(screen.width(), never executed: x = (widget? (qMin(screen.width(), pos.x() + widget->width()) ) : screen.width()) - w; never evaluated: widget | 0 |
619 | pos.x() + widget->width()) never executed: x = (widget? (qMin(screen.width(), pos.x() + widget->width()) ) : screen.width()) - w; | 0 |
620 | ) : screen.width()) never executed: x = (widget? (qMin(screen.width(), pos.x() + widget->width()) ) : screen.width()) - w; | 0 |
621 | - w; never executed: x = (widget? (qMin(screen.width(), pos.x() + widget->width()) ) : screen.width()) - w; | 0 |
622 | | - |
623 | if (x < sx) partially evaluated: x < sx yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
624 | x = sx; executed: x = sx; Execution Count:1 | 1 |
625 | | - |
626 | if (widget && h > widget->height() + 16) { partially evaluated: widget no Evaluation Count:0 | yes Evaluation Count:1 |
never evaluated: h > widget->height() + 16 | 0-1 |
627 | y = pos.y() + widget->height() + 2; // below, two pixels spacing never executed (the execution status of this line is deduced): y = pos.y() + widget->height() + 2; | - |
628 | // what's this is above or below, wherever there's most space | - |
629 | if (y + h + 10 > sy+screen.height()) never evaluated: y + h + 10 > sy+screen.height() | 0 |
630 | y = pos.y() + 2 - shadowWidth - h; // above, overlap never executed: y = pos.y() + 2 - shadowWidth - h; | 0 |
631 | } | 0 |
632 | y = y + 2; executed (the execution status of this line is deduced): y = y + 2; | - |
633 | | - |
634 | // squeeze it in if that would result in part of what's this | - |
635 | // being only partially visible | - |
636 | if (y + h + shadowWidth > sy+screen.height()) partially evaluated: y + h + shadowWidth > sy+screen.height() no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
637 | y = (widget ? (qMin(screen.height(), never executed: y = (widget ? (qMin(screen.height(), pos.y() + widget->height()) ) : screen.height()) - h; never evaluated: widget | 0 |
638 | pos.y() + widget->height()) never executed: y = (widget ? (qMin(screen.height(), pos.y() + widget->height()) ) : screen.height()) - h; | 0 |
639 | ) : screen.height()) never executed: y = (widget ? (qMin(screen.height(), pos.y() + widget->height()) ) : screen.height()) - h; | 0 |
640 | - h; never executed: y = (widget ? (qMin(screen.height(), pos.y() + widget->height()) ) : screen.height()) - h; | 0 |
641 | if (y < sy) partially evaluated: y < sy no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
642 | y = sy; | 0 |
643 | | - |
644 | whatsThat->move(x, y); executed (the execution status of this line is deduced): whatsThat->move(x, y); | - |
645 | whatsThat->show(); executed (the execution status of this line is deduced): whatsThat->show(); | - |
646 | whatsThat->grabKeyboard(); executed (the execution status of this line is deduced): whatsThat->grabKeyboard(); | - |
647 | } executed: } Execution Count:1 | 1 |
648 | | - |
649 | /*! | - |
650 | Shows \a text as a "What's This?" window, at global position \a | - |
651 | pos. The optional widget argument, \a w, is used to determine the | - |
652 | appropriate screen on multi-head systems. | - |
653 | | - |
654 | \sa hideText() | - |
655 | */ | - |
656 | void QWhatsThis::showText(const QPoint &pos, const QString &text, QWidget *w) | - |
657 | { | - |
658 | leaveWhatsThisMode(); executed (the execution status of this line is deduced): leaveWhatsThisMode(); | - |
659 | QWhatsThisPrivate::say(w, text, pos.x(), pos.y()); executed (the execution status of this line is deduced): QWhatsThisPrivate::say(w, text, pos.x(), pos.y()); | - |
660 | } executed: } Execution Count:1 | 1 |
661 | | - |
662 | /*! | - |
663 | If a "What's This?" window is showing, this destroys it. | - |
664 | | - |
665 | \sa showText() | - |
666 | */ | - |
667 | void QWhatsThis::hideText() | - |
668 | { | - |
669 | qDeleteInEventHandler(QWhatsThat::instance); never executed (the execution status of this line is deduced): qDeleteInEventHandler(QWhatsThat::instance); | - |
670 | } | 0 |
671 | | - |
672 | /*! | - |
673 | Returns a ready-made QAction, used to invoke "What's This?" context | - |
674 | help, with the given \a parent. | - |
675 | | - |
676 | The returned QAction provides a convenient way to let users enter | - |
677 | "What's This?" mode. | - |
678 | */ | - |
679 | QAction *QWhatsThis::createAction(QObject *parent) | - |
680 | { | - |
681 | return new QWhatsThisAction(parent); never executed: return new QWhatsThisAction(parent); | 0 |
682 | } | - |
683 | | - |
684 | QT_END_NAMESPACE | - |
685 | | - |
686 | #include "qwhatsthis.moc" | - |
687 | | - |
688 | #endif // QT_NO_WHATSTHIS | - |
689 | | - |
| | |