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())-
175 return theme->themeHint(QPlatformTheme::DropShadow).toBool();-
176 return false;-
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)-
188 setPalette(parent->palette());-
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)) {-
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 }-
212 else-
213 {-
214 int sw = QApplication::desktop()->width() / 3;-
215 if (sw < 200)-
216 sw = 200;-
217 else if (sw > 300)-
218 sw = 300;-
219-
220 r = fontMetrics().boundingRect(0, 0, sw, 1000,-
221 Qt::AlignLeft + Qt::AlignTop-
222 + Qt::TextWordWrap + Qt::TextExpandTabs,-
223 text);-
224 }-
225 shadowWidth = dropShadow() ? 0 : 6;-
226 resize(r.width() + 2*hMargin + shadowWidth, r.height() + 2*vMargin + shadowWidth);-
227}-
228-
229QWhatsThat::~QWhatsThat()-
230{-
231 instance = 0;-
232 if (doc)-
233 delete doc;-
234}-
235-
236void QWhatsThat::showEvent(QShowEvent *)-
237{-
238 background = QGuiApplication::primaryScreen()->grabWindow(QApplication::desktop()->internalWinId(),-
239 x(), y(), width(), height());-
240}-
241-
242void QWhatsThat::mousePressEvent(QMouseEvent* e)-
243{-
244 pressed = true;-
245 if (e->button() == Qt::LeftButton && rect().contains(e->pos())) {-
246 if (doc)-
247 anchor = doc->documentLayout()->anchorAt(e->pos() - QPoint(hMargin, vMargin));-
248 return;-
249 }-
250 close();-
251}-
252-
253void QWhatsThat::mouseReleaseEvent(QMouseEvent* e)-
254{-
255 if (!pressed)-
256 return;-
257 if (widget && e->button() == Qt::LeftButton && doc && rect().contains(e->pos())) {-
258 QString a = doc->documentLayout()->anchorAt(e->pos() - QPoint(hMargin, vMargin));-
259 QString href;-
260 if (anchor == a)-
261 href = a;-
262 anchor.clear();-
263 if (!href.isEmpty()) {-
264 QWhatsThisClickedEvent e(href);-
265 if (QApplication::sendEvent(widget, &e))-
266 return;-
267 }-
268 }-
269 close();-
270}-
271-
272void QWhatsThat::mouseMoveEvent(QMouseEvent* e)-
273{-
274#ifdef QT_NO_CURSOR-
275 Q_UNUSED(e);-
276#else-
277 if (!doc)-
278 return;-
279 QString a = doc->documentLayout()->anchorAt(e->pos() - QPoint(hMargin, vMargin));-
280 if (!a.isEmpty())-
281 setCursor(Qt::PointingHandCursor);-
282 else-
283 setCursor(Qt::ArrowCursor);-
284#endif-
285}-
286-
287void QWhatsThat::keyPressEvent(QKeyEvent*)-
288{-
289 close();-
290}-
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)-
299 r.adjust(0, 0, -shadowWidth, -shadowWidth);-
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) {-
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)-
316 p.drawLine(w, i, w + 5, i + 5);-
317 for(i = w - i + h; i > 6; i -= 2)-
318 p.drawLine(i, h, i + 5, h + 5);-
319 for(; i > 0 ; i -= 2)-
320 p.drawLine(6, h + 6 - i, i + 5, h + 5);-
321 }-
322 r.adjust(0, 0, 1, 1);-
323 p.setPen(palette().toolTipText().color());-
324 r.adjust(hMargin, vMargin, -hMargin, -vMargin);-
325-
326 if (doc) {-
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 }-
335 else-
336 {-
337 p.drawText(r, Qt::AlignLeft + Qt::AlignTop + Qt::TextWordWrap + Qt::TextExpandTabs, text);-
338 }-
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 (int i = 0; i < toplevels.count(); ++i) {-
QWidgetauto *w =: toplevels.at(i);)
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)) {-
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 {-
401 QApplication::setOverrideCursor(Qt::WhatsThisCursor);-
402#endif-
403 }-
404#ifndef QT_NO_ACCESSIBILITY-
405 QAccessibleEvent event(this, QAccessible::ContextHelpStart);-
406 QAccessible::updateAccessibility(&event);-
407#endif-
408}-
409-
410QWhatsThisPrivate::~QWhatsThisPrivate()-
411{-
412 if (action)-
413 action->setChecked(false);-
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}-
423-
424bool QWhatsThisPrivate::eventFilter(QObject *o, QEvent *e)-
425{-
426 if (!o->isWidgetType())-
427 return false;-
428 QWidget * w = static_cast<QWidget *>(o);-
429 bool customWhatsThis = w->testAttribute(Qt::WA_CustomWhatsThis);-
430 switch (e->type()) {-
431 case QEvent::MouseButtonPress:-
432 {-
433 QMouseEvent *me = static_cast<QMouseEvent*>(e);-
434 if (me->button() == Qt::RightButton || customWhatsThis)-
435 return false;-
436 QHelpEvent e(QEvent::WhatsThis, me->pos(), me->globalPos());-
437 if (!QApplication::sendEvent(w, &e) || !e.isAccepted())-
438 leaveOnMouseRelease = true;-
439-
440 } break;-
441-
442 case QEvent::MouseMove:-
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:-
456 case QEvent::MouseButtonDblClick:-
457 if (leaveOnMouseRelease && e->type() == QEvent::MouseButtonRelease)-
458 QWhatsThis::leaveWhatsThisMode();-
459 if (static_cast<QMouseEvent*>(e)->button() == Qt::RightButton || customWhatsThis)-
460 return false; // ignore RMB release-
461 break;-
462 case QEvent::KeyPress:-
463 {-
464 QKeyEvent* kev = (QKeyEvent*)e;-
465-
466 if (kev->matches(QKeySequence::Cancel)) {-
467 QWhatsThis::leaveWhatsThisMode();-
468 return true;-
469 } else if (customWhatsThis) {-
470 return false;-
471 } else if (kev->key() == Qt::Key_Menu ||-
472 (kev->key() == Qt::Key_F10 &&-
473 kev->modifiers() == Qt::ShiftModifier)) {-
474 // we don't react to these keys, they are used for context menus-
475 return false;-
476 } else if (kev->key() != Qt::Key_Shift && kev->key() != Qt::Key_Alt // not a modifier key-
477 && kev->key() != Qt::Key_Control && kev->key() != Qt::Key_Meta) {-
478 QWhatsThis::leaveWhatsThisMode();-
479 }-
480 } break;-
481 default:-
482 return false;-
483 }-
484 return true;-
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}-
510-
511void QWhatsThisAction::actionTriggered()-
512{-
513 if (isChecked()) {-
514 QWhatsThis::enterWhatsThisMode();-
515 QWhatsThisPrivate::instance->action = this;-
516 }-
517}-
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)-
533 return;-
534 (void) new QWhatsThisPrivate;-
535 QEvent e(QEvent::EnterWhatsThisMode);-
536 QWhatsThisPrivate::notifyToplevels(&e);-
537 }-
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);-
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}-
565-
566void QWhatsThisPrivate::say(QWidget * widget, const QString &text, int x, int y)-
567{-
568 if (text.size() == 0)-
569 return;-
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 ?-
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)-
603 pos = widget->mapToGlobal(QPoint(0,0));-
604-
605 if (widget && w > widget->width() + 16)-
606 x = pos.x() + widget->width()/2 - w/2;-
607 else-
608 x = x - w/2;-
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())-
613 x = (widget? (qMin(screen.width(),-
614 pos.x() + widget->width())-
615 ) : screen.width())-
616 - w;-
617-
618 if (x < sx)-
619 x = sx;-
620-
621 if (widget && h > widget->height() + 16) {-
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())-
625 y = pos.y() + 2 - shadowWidth - h; // above, overlap-
626 }-
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())-
632 y = (widget ? (qMin(screen.height(),-
633 pos.y() + widget->height())-
634 ) : screen.height())-
635 - h;-
636 if (y < sy)-
637 y = sy;-
638-
639 whatsThat->move(x, y);-
640 whatsThat->show();-
641 whatsThat->grabKeyboard();-
642}-
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}-
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}-
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);-
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