Qt 4.8
Public Functions | Static Public Functions | Public Variables | Static Public Variables | List of all members
QWhatsThisPrivate Class Reference
Inheritance diagram for QWhatsThisPrivate:
QObject

Public Functions

bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
 QWhatsThisPrivate ()
 
 ~QWhatsThisPrivate ()
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Static Public Functions

static void notifyToplevels (QEvent *e)
 
static void say (QWidget *, const QString &, int x=0, int y=0)
 
- Static Public Functions inherited from QObject
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 receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 

Public Variables

QPointer< QActionaction
 
bool leaveOnMouseRelease
 

Static Public Variables

static QWhatsThisPrivateinstance = 0
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 388 of file qwhatsthis.cpp.

Constructors and Destructors

◆ QWhatsThisPrivate()

QWhatsThisPrivate::QWhatsThisPrivate ( )

Definition at line 415 of file qwhatsthis.cpp.

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 }
static void updateAccessibility(QObject *, int who, Event reason)
Notifies accessibility clients about a change in object&#39;s accessibility information.
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
static QWidget * widgetAt(const QPoint &p)
Returns the widget at global screen position point, or 0 if there is no Qt widget there...
#define qApp
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
static QWhatsThisPrivate * instance
Definition: qwhatsthis.cpp:393
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
static void setOverrideCursor(const QCursor &)
Use changeOverrideCursor(cursor) (if replace is true) or setOverrideCursor(cursor) (if replace is fal...
#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
static QPoint pos()
Returns the position of the cursor (hot spot) in global screen coordinates.
Definition: qcursor_mac.mm:310
The QHelpEvent class provides an event that is used to request helpful information about a particular...
Definition: qevent.h:586

◆ ~QWhatsThisPrivate()

QWhatsThisPrivate::~QWhatsThisPrivate ( )

Definition at line 439 of file qwhatsthis.cpp.

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 }
static void updateAccessibility(QObject *, int who, Event reason)
Notifies accessibility clients about a change in object&#39;s accessibility information.
QPointer< QAction > action
Definition: qwhatsthis.cpp:395
static QWhatsThisPrivate * instance
Definition: qwhatsthis.cpp:393
void setChecked(bool)
Definition: qaction.cpp:1138
static void restoreOverrideCursor()
Undoes the last setOverrideCursor().

Functions

◆ eventFilter()

bool QWhatsThisPrivate::eventFilter ( QObject ,
QEvent  
)
virtual

Filters events if this object has been installed as an event filter for the watched object.

In your reimplementation of this function, if you want to filter the event out, i.e. stop it being handled further, return true; otherwise return false.

Example:

class MainWindow : public QMainWindow
{
public:
MainWindow();
protected:
bool eventFilter(QObject *obj, QEvent *ev);
private:
QTextEdit *textEdit;
};
MainWindow::MainWindow()
{
textEdit = new QTextEdit;
setCentralWidget(textEdit);
textEdit->installEventFilter(this);
}
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
if (obj == textEdit) {
if (event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
qDebug() << "Ate key press" << keyEvent->key();
return true;
} else {
return false;
}
} else {
// pass the event on to the parent class
return QMainWindow::eventFilter(obj, event);
}
}

Notice in the example above that unhandled events are passed to the base class's eventFilter() function, since the base class might have reimplemented eventFilter() for its own internal purposes.

Warning
If you delete the receiver object in this function, be sure to return true. Otherwise, Qt will forward the event to the deleted object and the program might crash.
See also
installEventFilter()

Reimplemented from QObject.

Definition at line 456 of file qwhatsthis.cpp.

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 }
The QKeyEvent class describes a key event.
Definition: qevent.h:224
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:95
static void changeOverrideCursor(const QCursor &)
Changes the currently active application override cursor to cursor.
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
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
Qt::MouseButton button() const
Returns the button that caused the event.
Definition: qevent.h:101
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
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
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
The QHelpEvent class provides an event that is used to request helpful information about a particular...
Definition: qevent.h:586

◆ notifyToplevels()

void QWhatsThisPrivate::notifyToplevels ( QEvent e)
static

Definition at line 404 of file qwhatsthis.cpp.

Referenced by QWhatsThis::leaveWhatsThisMode().

405 {
407  for (int i = 0; i < toplevels.count(); ++i) {
408  register QWidget *w = toplevels.at(i);
410  }
411 }
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
static QWidgetList topLevelWidgets()
Returns a list of the top-level widgets (windows) in the application.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ say()

void QWhatsThisPrivate::say ( QWidget widget,
const QString text,
int  x = 0,
int  y = 0 
)
static

Definition at line 669 of file qwhatsthis.cpp.

Referenced by QWhatsThis::showText().

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 }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
const QX11Info & x11Info() const
Returns information about the configuration of the X display used to display the widget.
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
int height() const
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
int height
the height of the widget excluding any window frame
Definition: qwidget.h:167
int width() const
#define QT_NO_CURSOR
void show()
Shows the widget and its child widgets.
static QDesktopWidget * desktop()
Returns the desktop widget (also called the root window).
void grabKeyboard()
Grabs the keyboard input.
static int shadowWidth
Definition: qwhatsthis.cpp:181
const QRect screenGeometry(int screen=-1) const
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
int screenNumber(const QWidget *widget=0) const
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
QPoint mapToGlobal(const QPoint &) const
Translates the widget coordinate pos to global screen coordinates.
void move(int x, int y)
This corresponds to move(QPoint(x, y)).
Definition: qwidget.h:1011
int screen() const
Returns the number of the screen currently in use.

Properties

◆ action

QPointer<QAction> QWhatsThisPrivate::action

Definition at line 395 of file qwhatsthis.cpp.

Referenced by QWhatsThisAction::actionTriggered(), and ~QWhatsThisPrivate().

◆ instance

QWhatsThisPrivate * QWhatsThisPrivate::instance = 0
static

◆ leaveOnMouseRelease

bool QWhatsThisPrivate::leaveOnMouseRelease

Definition at line 401 of file qwhatsthis.cpp.

Referenced by eventFilter().


The documentation for this class was generated from the following file: