Qt 4.8
qwhatsthis.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 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 "qdesktopwidget.h"
47 #include "qevent.h"
48 #include "qpixmap.h"
49 #include "qpainter.h"
50 #include "qtimer.h"
51 #include "qhash.h"
52 #include "qaction.h"
53 #include "qcursor.h"
54 #include "qbitmap.h"
55 #include "qtextdocument.h"
56 #include "../text/qtextdocumentlayout_p.h"
57 #include "qtoolbutton.h"
58 #include "qdebug.h"
59 #ifndef QT_NO_ACCESSIBILITY
60 #include "qaccessible.h"
61 #endif
62 #if defined(Q_WS_WIN)
63 #include "qt_windows.h"
64 #ifndef SPI_GETDROPSHADOW
65 #define SPI_GETDROPSHADOW 0x1024
66 #endif
67 #endif
68 #if defined(Q_WS_X11)
69 #include "qx11info_x11.h"
70 #include <qwidget.h>
71 #endif
72 
74 
150 
151 class QWhatsThat : public QWidget
152 {
153  Q_OBJECT
154 
155 public:
156  QWhatsThat(const QString& txt, QWidget* parent, QWidget *showTextFor);
157  ~QWhatsThat() ;
158 
160 
161 protected:
162  void showEvent(QShowEvent *e);
166  void keyPressEvent(QKeyEvent*);
167  void paintEvent(QPaintEvent*);
168 
169 private:
171  bool pressed;
176 };
177 
179 
180 // shadowWidth not const, for XP drop-shadow-fu turns it to 0
181 static int shadowWidth = 6; // also used as '5' and '6' and even '8' below
182 static const int vMargin = 8;
183 static const int hMargin = 12;
184 
186  : QWidget(parent, Qt::Popup),
187  widget(showTextFor), pressed(false), text(txt)
188 {
189  delete instance;
190  instance = this;
193  if (parent)
194  setPalette(parent->palette());
195  setMouseTracking(true);
197 #ifndef QT_NO_CURSOR
199 #endif
200  QRect r;
201  doc = 0;
202  ensurePolished(); // Ensures style sheet font before size calc
203  if (Qt::mightBeRichText(text)) {
204  doc = new QTextDocument();
205  doc->setUndoRedoEnabled(false);
207 #ifdef QT_NO_TEXTHTMLPARSER
209 #else
210  doc->setHtml(text);
211 #endif
212  doc->setUndoRedoEnabled(false);
213  doc->adjustSize();
214  r.setTop(0);
215  r.setLeft(0);
216  r.setSize(doc->size().toSize());
217  }
218  else
219  {
220  int sw = QApplication::desktop()->width() / 3;
221  if (sw < 200)
222  sw = 200;
223  else if (sw > 300)
224  sw = 300;
225 
226  r = fontMetrics().boundingRect(0, 0, sw, 1000,
229  text);
230  }
231 #if defined(Q_WS_WIN)
234  {
235  BOOL shadow;
236  SystemParametersInfo(SPI_GETDROPSHADOW, 0, &shadow, 0);
237  shadowWidth = shadow ? 0 : 6;
238  }
239 #endif
240  resize(r.width() + 2*hMargin + shadowWidth, r.height() + 2*vMargin + shadowWidth);
241 }
242 
244 {
245  instance = 0;
246  if (doc)
247  delete doc;
248 }
249 
251 {
253  x(), y(), width(), height());
254 }
255 
257 {
258  pressed = true;
259  if (e->button() == Qt::LeftButton && rect().contains(e->pos())) {
260  if (doc)
262  return;
263  }
264  close();
265 }
266 
268 {
269  if (!pressed)
270  return;
271  if (widget && e->button() == Qt::LeftButton && doc && rect().contains(e->pos())) {
273  QString href;
274  if (anchor == a)
275  href = a;
276  anchor.clear();
277  if (!href.isEmpty()) {
278  QWhatsThisClickedEvent e(href);
280  return;
281  }
282  }
283  close();
284 }
285 
287 {
288 #ifdef QT_NO_CURSOR
289  Q_UNUSED(e);
290 #else
291  if (!doc)
292  return;
294  if (!a.isEmpty())
296  else
298 #endif
299 }
300 
302 {
303  close();
304 }
305 
307 {
308  bool drawShadow = true;
309 #if defined(Q_WS_WIN)
312  {
313  BOOL shadow;
314  SystemParametersInfo(SPI_GETDROPSHADOW, 0, &shadow, 0);
315  drawShadow = !shadow;
316  }
317 #elif defined(Q_WS_MAC) || defined(Q_WS_QWS)
318  drawShadow = false; // never draw it on OS X or QWS, as we get it for free
319 #endif
320 
321  QRect r = rect();
322  r.adjust(0, 0, -1, -1);
323  if (drawShadow)
324  r.adjust(0, 0, -shadowWidth, -shadowWidth);
325  QPainter p(this);
326  p.drawPixmap(0, 0, background);
327  p.setPen(QPen(palette().toolTipText(), 0));
328  p.setBrush(palette().toolTipBase());
329  p.drawRect(r);
330  int w = r.width();
331  int h = r.height();
332  p.setPen(palette().brush(QPalette::Dark).color());
333  p.drawRect(1, 1, w-2, h-2);
334  if (drawShadow) {
335  p.setPen(palette().shadow().color());
336  p.drawPoint(w + 5, 6);
337  p.drawLine(w + 3, 6, w + 5, 8);
338  p.drawLine(w + 1, 6, w + 5, 10);
339  int i;
340  for(i=7; i < h; i += 2)
341  p.drawLine(w, i, w + 5, i + 5);
342  for(i = w - i + h; i > 6; i -= 2)
343  p.drawLine(i, h, i + 5, h + 5);
344  for(; i > 0 ; i -= 2)
345  p.drawLine(6, h + 6 - i, i + 5, h + 5);
346  }
347  r.adjust(0, 0, 1, 1);
348  p.setPen(palette().toolTipText().color());
350 
351  if (doc) {
352  p.translate(r.x(), r.y());
353  QRect rect = r;
354  rect.translate(-r.x(), -r.y());
355  p.setClipRect(rect);
357  context.palette.setBrush(QPalette::Text, context.palette.toolTipText());
358  doc->documentLayout()->draw(&p, context);
359  }
360  else
361  {
363  }
364 }
365 
366 static const char * const button_image[] = {
367 "16 16 3 1",
368 " c None",
369 "o c #000000",
370 "a c #000080",
371 "o aaaaa ",
372 "oo aaa aaa ",
373 "ooo aaa aaa",
374 "oooo aa aa",
375 "ooooo aa aa",
376 "oooooo a aaa",
377 "ooooooo aaa ",
378 "oooooooo aaa ",
379 "ooooooooo aaa ",
380 "ooooo aaa ",
381 "oo ooo ",
382 "o ooo aaa ",
383 " ooo aaa ",
384 " ooo ",
385 " ooo ",
386 " ooo "};
387 
389 {
390  public:
394  bool eventFilter(QObject *, QEvent *);
396 #ifdef QT3_SUPPORT
397  QPointer<QToolButton> button;
398 #endif
399  static void say(QWidget *, const QString &, int x = 0, int y = 0);
400  static void notifyToplevels(QEvent *e);
402 };
403 
405 {
407  for (int i = 0; i < toplevels.count(); ++i) {
408  register QWidget *w = toplevels.at(i);
410  }
411 }
412 
414 
416  : leaveOnMouseRelease(false)
417 {
418  instance = this;
419  qApp->installEventFilter(this);
420 
421  QPoint pos = QCursor::pos();
422  if (QWidget *w = QApplication::widgetAt(pos)) {
423  QHelpEvent e(QEvent::QueryWhatsThis, w->mapFromGlobal(pos), pos);
424  bool sentEvent = QApplication::sendEvent(w, &e);
425 #ifdef QT_NO_CURSOR
426  Q_UNUSED(sentEvent);
427 #else
428  QApplication::setOverrideCursor((!sentEvent || !e.isAccepted())?
430  } else {
432 #endif
433  }
434 #ifndef QT_NO_ACCESSIBILITY
436 #endif
437 }
438 
440 {
441  if (action)
442  action->setChecked(false);
443 #ifdef QT3_SUPPORT
444  if (button)
445  button->setChecked(false);
446 #endif
447 #ifndef QT_NO_CURSOR
449 #endif
450 #ifndef QT_NO_ACCESSIBILITY
452 #endif
453  instance = 0;
454 }
455 
457 {
458  if (!o->isWidgetType())
459  return false;
460  QWidget * w = static_cast<QWidget *>(o);
461  bool customWhatsThis = w->testAttribute(Qt::WA_CustomWhatsThis);
462  switch (e->type()) {
464  {
465  QMouseEvent *me = static_cast<QMouseEvent*>(e);
466  if (me->button() == Qt::RightButton || customWhatsThis)
467  return false;
468  QHelpEvent e(QEvent::WhatsThis, me->pos(), me->globalPos());
469  if (!QApplication::sendEvent(w, &e) || !e.isAccepted())
470  leaveOnMouseRelease = true;
471 
472  } break;
473 
474  case QEvent::MouseMove:
475  {
476  QMouseEvent *me = static_cast<QMouseEvent*>(e);
478  bool sentEvent = QApplication::sendEvent(w, &e);
479 #ifdef QT_NO_CURSOR
480  Q_UNUSED(sentEvent);
481 #else
482  QApplication::changeOverrideCursor((!sentEvent || !e.isAccepted())?
484 #endif
485  }
486  // fall through
491  if (static_cast<QMouseEvent*>(e)->button() == Qt::RightButton || customWhatsThis)
492  return false; // ignore RMB release
493  break;
494  case QEvent::KeyPress:
495  {
496  QKeyEvent* kev = (QKeyEvent*)e;
497 
498  if (kev->key() == Qt::Key_Escape) {
500  return true;
501  } else if (customWhatsThis) {
502  return false;
503  } else if (kev->key() == Qt::Key_Menu ||
504  (kev->key() == Qt::Key_F10 &&
505  kev->modifiers() == Qt::ShiftModifier)) {
506  // we don't react to these keys, they are used for context menus
507  return false;
508  } else if (kev->key() != Qt::Key_Shift && kev->key() != Qt::Key_Alt // not a modifier key
509  && kev->key() != Qt::Key_Control && kev->key() != Qt::Key_Meta) {
511  }
512  } break;
513  default:
514  return false;
515  }
516  return true;
517 }
518 
520 {
521  Q_OBJECT
522 
523 public:
524  explicit QWhatsThisAction(QObject* parent = 0);
525 
526 private slots:
527  void actionTriggered();
528 };
529 
531 {
532 #ifndef QT_NO_IMAGEFORMAT_XPM
533  QPixmap p((const char**)button_image);
534  setIcon(p);
535 #endif
536  setCheckable(true);
537  connect(this, SIGNAL(triggered()), this, SLOT(actionTriggered()));
538 #ifndef QT_NO_SHORTCUT
540 #endif
541 }
542 
544 {
545  if (isChecked()) {
547  QWhatsThisPrivate::instance->action = this;
548  }
549 }
550 
552 {
553 }
554 
555 #ifdef QT3_SUPPORT
556 
566 void QWhatsThis::add(QWidget *w, const QString &s)
567 {
568  w->setWhatsThis(s);
569 }
570 
581 void QWhatsThis::remove(QWidget *w)
582 {
583  w->setWhatsThis(QString());
584 }
585 
586 class QWhatsThisButton : public QToolButton
587 {
588  Q_OBJECT
589 public:
590  QWhatsThisButton(QWidget *p) : QToolButton(p) {
591  setCheckable(true);
592  QPixmap pix( const_cast<const char**>(button_image) );
593  setIcon( pix );
594  QObject::connect(this, SIGNAL(toggled(bool)), this, SLOT(whatToggled(bool)));
595  setAutoRaise(true);
596  setFocusPolicy(Qt::NoFocus);
597  }
598 
599 public slots:
600  void whatToggled(bool b) {
601  if (b) {
603  QWhatsThisPrivate::instance->button = this;
604  }
605  }
606 };
607 
616 QToolButton * QWhatsThis::whatsThisButton(QWidget * parent)
617 {
618  return new QWhatsThisButton(parent);
619 }
620 #endif
621 
634 {
635  if (QWhatsThisPrivate::instance)
636  return;
637  (void) new QWhatsThisPrivate;
640  }
641 
649 {
650  return (QWhatsThisPrivate::instance != 0);
651 }
652 
663 {
667 }
668 
669 void QWhatsThisPrivate::say(QWidget * widget, const QString &text, int x, int y)
670 {
671  if (text.size() == 0)
672  return;
673  // make a fresh widget, and set it up
674  QWhatsThat *whatsThat = new QWhatsThat(
675  text,
676 #if defined(Q_WS_X11) && !defined(QT_NO_CURSOR)
677  QApplication::desktop()->screen(widget ? widget->x11Info().screen() : QCursor::x11Screen()),
678 #else
679  0,
680 #endif
681  widget
682  );
683 
684 
685  // okay, now to find a suitable location
686 
687  int scr = (widget ?
689 #if defined(Q_WS_X11) && !defined(QT_NO_CURSOR)
690  QCursor::x11Screen()
691 #else
693 #endif // Q_WS_X11
694  );
695  QRect screen = QApplication::desktop()->screenGeometry(scr);
696 
697  int w = whatsThat->width();
698  int h = whatsThat->height();
699  int sx = screen.x();
700  int sy = screen.y();
701 
702  // first try locating the widget immediately above/below,
703  // with nice alignment if possible.
704  QPoint pos;
705  if (widget)
706  pos = widget->mapToGlobal(QPoint(0,0));
707 
708  if (widget && w > widget->width() + 16)
709  x = pos.x() + widget->width()/2 - w/2;
710  else
711  x = x - w/2;
712 
713  // squeeze it in if that would result in part of what's this
714  // being only partially visible
715  if (x + w + shadowWidth > sx+screen.width())
716  x = (widget? (qMin(screen.width(),
717  pos.x() + widget->width())
718  ) : screen.width())
719  - w;
720 
721  if (x < sx)
722  x = sx;
723 
724  if (widget && h > widget->height() + 16) {
725  y = pos.y() + widget->height() + 2; // below, two pixels spacing
726  // what's this is above or below, wherever there's most space
727  if (y + h + 10 > sy+screen.height())
728  y = pos.y() + 2 - shadowWidth - h; // above, overlap
729  }
730  y = y + 2;
731 
732  // squeeze it in if that would result in part of what's this
733  // being only partially visible
734  if (y + h + shadowWidth > sy+screen.height())
735  y = (widget ? (qMin(screen.height(),
736  pos.y() + widget->height())
737  ) : screen.height())
738  - h;
739  if (y < sy)
740  y = sy;
741 
742  whatsThat->move(x, y);
743  whatsThat->show();
744  whatsThat->grabKeyboard();
745 }
746 
754 void QWhatsThis::showText(const QPoint &pos, const QString &text, QWidget *w)
755 {
756  leaveWhatsThisMode();
757  QWhatsThisPrivate::say(w, text, pos.x(), pos.y());
758 }
759 
766 {
767  qDeleteInEventHandler(QWhatsThat::instance);
768 }
769 
778 {
779  return new QWhatsThisAction(parent);
780 }
781 
783 
784 #include "qwhatsthis.moc"
785 
786 #endif // QT_NO_WHATSTHIS
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
static const int vMargin
Definition: qwhatsthis.cpp:182
QString anchor
Definition: qwhatsthis.cpp:174
QPalette palette
the widget&#39;s palette
Definition: qwidget.h:180
static void updateAccessibility(QObject *, int who, Event reason)
Notifies accessibility clients about a change in object&#39;s accessibility information.
bool eventFilter(QObject *, QEvent *)
Filters events if this object has been installed as an event filter for the watched object...
Definition: qwhatsthis.cpp:456
The QKeyEvent class describes a key event.
Definition: qevent.h:224
void setShortcut(const QKeySequence &shortcut)
Definition: qaction.cpp:450
int y() const
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QPointer< QWidget > widget
#define add(aName)
void ensurePolished() const
Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette).
Definition: qwidget.cpp:10024
QSize toSize() const
Returns an integer based copy of this size.
Definition: qsize.h:355
void adjustSize()
Adjusts the document to a reasonable size.
void setCheckable(bool)
Definition: qaction.cpp:1094
void setClipRect(const QRectF &, Qt::ClipOperation op=Qt::ReplaceClip)
Enables clipping, and sets the clip region to the given rectangle using the given clip operation...
Definition: qpainter.cpp:2801
QPixmap background
Definition: qwhatsthis.cpp:175
#define SLOT(a)
Definition: qobjectdefs.h:226
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
const QX11Info & x11Info() const
Returns information about the configuration of the X display used to display the widget.
Q_GUI_EXPORT bool mightBeRichText(const QString &)
Returns true if the string text is likely to be rich text; otherwise returns false.
void keyPressEvent(QKeyEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive key press events f...
Definition: qwhatsthis.cpp:301
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
QString text
Definition: qwhatsthis.cpp:172
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
#define SPI_GETDROPSHADOW
Definition: qwhatsthis.cpp:65
Q_CORE_EXPORT void qDeleteInEventHandler(QObject *o)
Definition: qobject.cpp:4348
long ASN1_INTEGER_get ASN1_INTEGER * a
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
void drawLine(const QLineF &line)
Draws a line defined by line.
Definition: qpainter.h:573
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
static const WinVersion WindowsVersion
the version of the Windows operating system on which the application is run (Windows only) ...
Definition: qglobal.h:1613
The QString class provides a Unicode character string.
Definition: qstring.h:83
static const char *const button_image[]
Definition: qwhatsthis.cpp:366
QString anchorAt(const QPointF &pos) const
Returns the reference of the anchor the given position, or an empty string if no anchor exists at tha...
QPalette palette
the default color that is used for the text, when no color is specified.
void showEvent(QShowEvent *e)
This event handler can be reimplemented in a subclass to receive widget show events which are passed ...
Definition: qwhatsthis.cpp:250
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
int height() const
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
void mouseReleaseEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse release even...
Definition: qwhatsthis.cpp:267
void drawPoint(const QPointF &pt)
Draws a single point at the given position using the current pen&#39;s color.
Definition: qpainter.h:676
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:95
static QFont font()
Returns the default application font.
static void changeOverrideCursor(const QCursor &)
Changes the currently active application override cursor to cursor.
void setWhatsThis(const QString &)
Definition: qwidget.cpp:11655
QRect boundingRect(QChar) const
Returns the rectangle that is covered by ink if character ch were to be drawn at the origin of the co...
static QWidget * widgetAt(const QPoint &p)
Returns the widget at global screen position point, or 0 if there is no Qt widget there...
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
Definition: qevent.cpp:999
int key() const
Returns the code of the key that was pressed or released.
Definition: qevent.h:231
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void setPlainText(const QString &text)
Replaces the entire contents of the document with the given plain text.
void drawText(const QPointF &p, const QString &s)
Draws the given text with the currently defined text direction, beginning at the given position...
Definition: qpainter.cpp:6231
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void setBrush(ColorRole cr, const QBrush &brush)
Sets the brush for the given color role to the specified brush for all groups in the palette...
Definition: qpalette.h:206
bool isAccepted() const
Definition: qcoreevent.h:307
void toggled(bool)
This signal is emitted whenever a checkable action changes its isChecked() status.
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
#define qApp
int width() const
void setTop(int pos)
Sets the top edge of the rectangle to the given y coordinate.
Definition: qrect.h:261
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void actionTriggered()
Definition: qwhatsthis.cpp:543
void adjust(int x1, int y1, int x2, int y2)
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Definition: qrect.h:434
const QPalette & palette() const
QFontMetrics fontMetrics() const
Returns the font metrics for the widget&#39;s current font.
Definition: qwidget.h:984
void setSize(const QSize &s)
Sets the size of the rectangle to the given size.
Definition: qrect.h:448
QWhatsThisAction(QObject *parent=0)
Definition: qwhatsthis.cpp:530
static QWhatsThat * instance
Definition: qwhatsthis.cpp:159
static bool inWhatsThisMode()
Returns true if the user interface is in "What&#39;s This?" mode; otherwise returns false.
Definition: qwhatsthis.cpp:648
QSizeF size
Returns the actual size of the document.
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
static void notifyToplevels(QEvent *e)
Definition: qwhatsthis.cpp:404
void setCursor(const QCursor &)
Definition: qwidget.cpp:5290
void setHtml(const QString &html)
Replaces the entire contents of the document with the given HTML-formatted text in the html string...
#define QT_NO_CURSOR
void show()
Shows the widget and its child widgets.
The QShowEvent class provides an event that is sent when a widget is shown.
Definition: qevent.h:380
void mousePressEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
Definition: qwhatsthis.cpp:256
static void say(QWidget *, const QString &, int x=0, int y=0)
Definition: qwhatsthis.cpp:669
Qt::MouseButton button() const
Returns the button that caused the event.
Definition: qevent.h:101
static QWidgetList topLevelWidgets()
Returns a list of the top-level widgets (windows) in the application.
QRect rect() const
#define Q_OBJECT
Definition: qobjectdefs.h:157
bool contains(const QPoint &p, bool proper=false) const
Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false...
Definition: qrect.cpp:1101
QPointer< QAction > action
Definition: qwhatsthis.cpp:395
virtual bool eventFilter(QObject *, QEvent *)
Filters events if this object has been installed as an event filter for the watched object...
Definition: qobject.cpp:1375
void setMouseTracking(bool enable)
Definition: qwidget.h:990
static const int hMargin
Definition: qwhatsthis.cpp:183
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
static QDesktopWidget * desktop()
Returns the desktop widget (also called the root window).
static QWhatsThisPrivate * instance
Definition: qwhatsthis.cpp:393
void setDefaultFont(const QFont &font)
Sets the default font to use in the document layout.
void grabKeyboard()
Grabs the keyboard input.
bool isWidgetType() const
Returns true if the object is a widget; otherwise returns false.
Definition: qobject.h:146
static int shadowWidth
Definition: qwhatsthis.cpp:181
const QRect screenGeometry(int screen=-1) const
void mouseMoveEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse move events ...
Definition: qwhatsthis.cpp:286
int x() const
void resize(int w, int h)
This corresponds to resize(QSize(w, h)).
Definition: qwidget.h:1014
void setChecked(bool)
Definition: qaction.cpp:1138
friend class QToolButton
Definition: qaction.h:248
#define Q_CORE_EXPORT
Definition: qglobal.h:1449
void setLeft(int pos)
Sets the left edge of the rectangle to the given x coordinate.
Definition: qrect.h:258
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
QString text() const
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
The QWhatsThisClickedEvent class provides an event that can be used to handle hyperlinks in a "What&#39;s...
Definition: qevent.h:619
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QAbstractTextDocumentLayout * documentLayout() const
Returns the document layout for this document.
void setBrush(const QBrush &brush)
Sets the painter&#39;s brush to the given brush.
Definition: qpainter.cpp:4171
QTextDocument * doc
Definition: qwhatsthis.cpp:173
The QAbstractTextDocumentLayout::PaintContext class is a convenience class defining the parameters us...
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
void setUndoRedoEnabled(bool enable)
QPointer< QWidget > widget
Definition: qwhatsthis.cpp:170
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
Definition: qnamespace.h:54
void setIcon(const QIcon &icon)
Definition: qaction.cpp:772
void paintEvent(QPaintEvent *)
This event handler can be reimplemented in a subclass to receive paint events passed in event...
Definition: qwhatsthis.cpp:306
WId internalWinId() const
Returns the window system identifier of the widget, or 0 if the widget is not created yet...
Definition: qwidget.h:244
bool isChecked() const
Definition: qaction.cpp:1151
void drawRect(const QRectF &rect)
Draws the current rectangle with the current pen and brush.
Definition: qpainter.h:650
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
const QBrush & toolTipText() const
Returns the tool tip text brush of the current color group.
Definition: qpalette.h:133
static void setOverrideCursor(const QCursor &)
Use changeOverrideCursor(cursor) (if replace is true) or setOverrideCursor(cursor) (if replace is fal...
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device...
Definition: qpainter.cpp:5619
int screenNumber(const QWidget *widget=0) const
static QPixmap grabWindow(WId, int x=0, int y=0, int w=-1, int h=-1)
Creates and returns a pixmap constructed by grabbing the contents of the given window restricted by Q...
bool close()
Closes this widget.
Definition: qwidget.cpp:8305
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
static void restoreOverrideCursor()
Undoes the last setOverrideCursor().
The QToolButton class provides a quick-access button to commands or options, usually used inside a QT...
Definition: qtoolbutton.h:59
#define slots
Definition: qobjectdefs.h:68
static void showText(const QPoint &pos, const QString &text, QWidget *w=0)
Shows text as a "What&#39;s This?" window, at global position pos.
Definition: qwhatsthis.cpp:754
static void hideText()
If a "What&#39;s This?" window is showing, this destroys it.
Definition: qwhatsthis.cpp:765
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
static QAction * createAction(QObject *parent=0)
Returns a ready-made QAction, used to invoke "What&#39;s This?" context help, with the given parent...
Definition: qwhatsthis.cpp:777
void translate(int dx, int dy)
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position...
Definition: qrect.h:312
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
const QPoint & globalPos() const
Returns the global position of the mouse cursor at the time of the event.
Definition: qevent.h:96
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
QWhatsThat(const QString &txt, QWidget *parent, QWidget *showTextFor)
Definition: qwhatsthis.cpp:185
void triggered(bool checked=false)
This signal is emitted when an action is activated by the user; for example, when the user clicks a m...
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64
void setPalette(const QPalette &)
Use the single-argument overload instead.
Definition: qwidget.cpp:4858
static void enterWhatsThisMode()
This function switches the user interface into "What&#39;s This?" mode.
Definition: qwhatsthis.cpp:633
static void leaveWhatsThisMode()
If the user interface is in "What&#39;s This?" mode, this function switches back to normal mode; otherwis...
Definition: qwhatsthis.cpp:662
void move(int x, int y)
This corresponds to move(QPoint(x, y)).
Definition: qwidget.h:1011
static QPoint pos()
Returns the position of the cursor (hot spot) in global screen coordinates.
Definition: qcursor_mac.mm:310
int screen() const
Returns the number of the screen currently in use.
virtual void draw(QPainter *painter, const PaintContext &context)=0
Draws the layout with the given painter using the given context.
void setFocusPolicy(Qt::FocusPolicy policy)
Definition: qwidget.cpp:7631
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
The QHelpEvent class provides an event that is used to request helpful information about a particular...
Definition: qevent.h:586
void translate(const QPointF &offset)
Translates the coordinate system by the given offset; i.e.
Definition: qpainter.cpp:3311