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

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