qwhatsthis.cpp

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

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9