Qt 4.8
qgraphicsproxywidget.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 "qglobal.h"
43 
44 #ifndef QT_NO_GRAPHICSVIEW
45 
46 #include "qgraphicslayout.h"
47 #include "qgraphicsproxywidget.h"
48 #include "private/qgraphicsproxywidget_p.h"
49 #include "private/qwidget_p.h"
50 #include "private/qapplication_p.h"
51 
52 #include <QtCore/qdebug.h>
53 #include <QtGui/qevent.h>
54 #include <QtGui/qgraphicsscene.h>
55 #include <QtGui/qgraphicssceneevent.h>
56 #include <QtGui/qlayout.h>
57 #include <QtGui/qpainter.h>
58 #include <QtGui/qstyleoption.h>
59 #include <QtGui/qgraphicsview.h>
60 #include <QtGui/qlistview.h>
61 #include <QtGui/qlineedit.h>
62 #include <QtGui/qtextedit.h>
63 
65 
66 //#define GRAPHICSPROXYWIDGET_DEBUG
67 
189 extern bool qt_sendSpontaneousEvent(QObject *, QEvent *);
190 Q_GUI_EXPORT extern bool qt_tab_all_widgets;
191 
196 {
198  q->setFocusPolicy(Qt::WheelFocus);
199  q->setAcceptDrops(true);
200 }
201 
206 {
208  mouseEvent.setPos(event->pos());
209  mouseEvent.setScreenPos(event->screenPos());
210  mouseEvent.setButton(Qt::NoButton);
211  mouseEvent.setButtons(0);
212  mouseEvent.setModifiers(event->modifiers());
213  sendWidgetMouseEvent(&mouseEvent);
214  event->setAccepted(mouseEvent.isAccepted());
215 }
216 
221 {
222  if (!event || !widget || !widget->isVisible())
223  return;
225 
226  // Find widget position and receiver.
227  QPointF pos = event->pos();
228  QPointer<QWidget> alienWidget = widget->childAt(pos.toPoint());
229  QPointer<QWidget> receiver = alienWidget ? alienWidget : widget;
230 
232  return; //another proxywidget will handle the events
233 
234  // Translate QGraphicsSceneMouse events to QMouseEvents.
236  switch (event->type()) {
240  embeddedMouseGrabber = receiver;
241  else
242  receiver = embeddedMouseGrabber;
243  break;
247  receiver = embeddedMouseGrabber;
248  break;
252  embeddedMouseGrabber = receiver;
253  else
254  receiver = embeddedMouseGrabber;
255  break;
257  type = QEvent::MouseMove;
259  receiver = embeddedMouseGrabber;
260  break;
261  default:
262  Q_ASSERT_X(false, "QGraphicsProxyWidget", "internal error");
263  break;
264  }
265 
266  if (!lastWidgetUnderMouse) {
268  lastWidgetUnderMouse = receiver;
269  }
270 
271  // Map event position from us to the receiver
272  pos = mapToReceiver(pos, receiver);
273 
274  // Send mouse event.
276  receiver->mapToGlobal(pos.toPoint()), event->button(),
277  event->buttons(), event->modifiers());
278 
279  QWidget *embeddedMouseGrabberPtr = (QWidget *)embeddedMouseGrabber;
280  QApplicationPrivate::sendMouseEvent(receiver, mouseEvent, alienWidget, widget,
281  &embeddedMouseGrabberPtr, lastWidgetUnderMouse, event->spontaneous());
282  embeddedMouseGrabber = embeddedMouseGrabberPtr;
283 
284  // Handle enter/leave events when last button is released from mouse
285  // grabber child widget.
286  if (embeddedMouseGrabber && type == QEvent::MouseButtonRelease && !event->buttons()) {
288  if (q->rect().contains(event->pos()) && q->acceptsHoverEvents())
289  lastWidgetUnderMouse = alienWidget ? alienWidget : widget;
290  else // released on the frame our outside the item, or doesn't accept hover events.
292 
294  embeddedMouseGrabber = 0;
295 
296 #ifndef QT_NO_CURSOR
297  // ### Restore the cursor, don't override it.
299  q->unsetCursor();
300 #endif
301  }
302 
303  event->setAccepted(mouseEvent->isAccepted());
304  delete mouseEvent;
305 }
306 
308 {
310  if (!event || !widget || !widget->isVisible())
311  return;
312 
313  QPointer<QWidget> receiver = widget->focusWidget();
314  if (!receiver)
315  receiver = widget;
316  Q_ASSERT(receiver);
317 
318  do {
319  bool res = QApplication::sendEvent(receiver, event);
320  if ((res && event->isAccepted()) || (q->isWindow() && receiver == widget))
321  break;
322  receiver = receiver->parentWidget();
323  } while (receiver);
324 }
325 
330 {
332  QPointer<QWidget> widgetGuard = widget;
333  QApplication::sendEvent(widget, &event);
334  if (widgetGuard && event.isAccepted())
335  QApplication::sendEvent(widget->style(), &event);
336 }
337 
348 {
349  Q_Q(const QGraphicsProxyWidget);
350  if (!widget || !q->hasFocus())
351  return QVariant();
352 
353  QWidget *focusWidget = widget->focusWidget();
354  if (!focusWidget)
355  focusWidget = widget;
356  QVariant v = focusWidget->inputMethodQuery(query);
357  QPointF focusWidgetPos = q->subWidgetRect(focusWidget).topLeft();
358  switch (v.type()) {
359  case QVariant::RectF:
360  v = v.toRectF().translated(focusWidgetPos);
361  break;
362  case QVariant::PointF:
363  v = v.toPointF() + focusWidgetPos;
364  break;
365  case QVariant::Rect:
366  v = v.toRect().translated(focusWidgetPos.toPoint());
367  break;
368  case QVariant::Point:
369  v = v.toPoint() + focusWidgetPos.toPoint();
370  break;
371  default:
372  break;
373  }
374  return v;
375 }
376 
382 {
383  if (!widget)
384  return 0;
385 
386  // Run around the focus chain until we find a widget that can take tab focus.
387  if (!child) {
388  child = next ? (QWidget *)widget : widget->d_func()->focus_prev;
389  } else {
390  child = next ? child->d_func()->focus_next : child->d_func()->focus_prev;
391  if ((next && child == widget) || (!next && child == widget->d_func()->focus_prev)) {
392  return 0;
393  }
394  }
395 
396  QWidget *oldChild = child;
398  do {
399  if (child->isEnabled()
400  && child->isVisibleTo(widget)
401  && ((child->focusPolicy() & focus_flag) == focus_flag)
402  && !(child->d_func()->extra && child->d_func()->extra->focus_proxy)) {
403  return child;
404  }
405  child = next ? child->d_func()->focus_next : child->d_func()->focus_prev;
406  } while (child != oldChild && !(next && child == widget) && !(!next && child == widget->d_func()->focus_prev));
407  return 0;
408 }
409 
414 {
416  widget = 0;
417  delete q;
418 }
419 
424 {
425 }
426 
431 {
433  if (!widget)
434  return;
435 
436  QRectF widgetGeometry = widget->geometry();
438  if (widget->isWindow()) {
439  QGraphicsProxyWidget *proxyParent = 0;
440  if (parentWidget && (proxyParent = qobject_cast<QGraphicsProxyWidget *>(q->parentWidget()))) {
441  // Nested window proxy (e.g., combobox popup), map widget to the
442  // parent widget's global coordinates, and map that to the parent
443  // proxy's child coordinates.
444  widgetGeometry.moveTo(proxyParent->subWidgetRect(parentWidget).topLeft()
445  + parentWidget->mapFromGlobal(widget->pos()));
446  }
447  }
448 
449  // Adjust to size hint if the widget has never been resized.
450  if (!widget->size().isValid())
451  widgetGeometry.setSize(widget->sizeHint());
452 
453  // Assign new geometry.
456  q->setGeometry(widgetGeometry);
459 }
460 
465 {
467  if (!widget)
468  return;
469 
470  QWidget *focusWidget = widget->focusWidget();
471  if (!focusWidget)
472  focusWidget = widget;
475 }
476 
488 {
489  QWExtra *extra;
490  if (!((extra = subWin->d_func()->extra) && extra->proxyWidget)) {
491  QGraphicsProxyWidget *subProxy = new QGraphicsProxyWidget(q_func(), subWin->windowFlags());
492  subProxy->d_func()->setWidget_helper(subWin, false);
493  }
494 }
495 
507 {
508  foreach (QGraphicsItem *child, children) {
509  if (child->isWidget()) {
510  if (QGraphicsProxyWidget *proxy = qobject_cast<QGraphicsProxyWidget *>(static_cast<QGraphicsWidget *>(child))) {
511  if (proxy->widget() == subWin) {
512  proxy->setWidget(0);
513  scene->removeItem(proxy);
514  delete proxy;
515  return;
516  }
517  }
518  }
519  }
520 }
521 
523 {
524  return true;
525 }
526 
531 {
532  QPointF p = pos;
533  // Map event position from us to the receiver, preserving its
534  // precision (don't use QWidget::mapFrom here).
535  while (receiver && receiver != widget) {
536  p -= QPointF(receiver->pos());
537  receiver = receiver->parentWidget();
538  }
539  return p;
540 }
541 
547  : QGraphicsWidget(*new QGraphicsProxyWidgetPrivate, parent, 0, wFlags)
548 {
550  d->init();
551 }
552 
557 {
559  if (d->widget) {
560  QObject::disconnect(d->widget, SIGNAL(destroyed()), this, SLOT(_q_removeWidgetSlot()));
561  delete d->widget;
562  }
563 }
564 
598 {
600  d->setWidget_helper(widget, true);
601 }
602 
604 {
606  if (newWidget == widget)
607  return;
608  if (widget) {
609  QObject::disconnect(widget, SIGNAL(destroyed()), q, SLOT(_q_removeWidgetSlot()));
612  widget->d_func()->extra->proxyWidget = 0;
613  resolveFont(inheritedFontResolveMask);
614  resolvePalette(inheritedPaletteResolveMask);
615  widget->update();
616 
617  foreach (QGraphicsItem *child, q->childItems()) {
618  if (child->d_ptr->isProxyWidget()) {
619  QGraphicsProxyWidget *childProxy = static_cast<QGraphicsProxyWidget *>(child);
620  QWidget * parent = childProxy->widget();
621  while (parent->parentWidget() != 0) {
622  if (parent == widget)
623  break;
624  parent = parent->parentWidget();
625  }
626  if (!childProxy->widget() || parent != widget)
627  continue;
628  childProxy->setWidget(0);
629  delete childProxy;
630  }
631  }
632 
633  widget = 0;
634 #ifndef QT_NO_CURSOR
635  q->unsetCursor();
636 #endif
637  q->setAcceptHoverEvents(false);
638  if (!newWidget)
639  q->update();
640  }
641  if (!newWidget)
642  return;
643  if (!newWidget->isWindow()) {
644  QWExtra *extra = newWidget->parentWidget()->d_func()->extra;
645  if (!extra || !extra->proxyWidget) {
646  qWarning("QGraphicsProxyWidget::setWidget: cannot embed widget %p "
647  "which is not a toplevel widget, and is not a child of an embedded widget", newWidget);
648  return;
649  }
650  }
651 
652  // Register this proxy within the widget's private.
653  // ### This is a bit backdoorish
654  QWExtra *extra = newWidget->d_func()->extra;
655  if (!extra) {
656  newWidget->d_func()->createExtra();
657  extra = newWidget->d_func()->extra;
658  }
659  QGraphicsProxyWidget **proxyWidget = &extra->proxyWidget;
660  if (*proxyWidget) {
661  if (*proxyWidget != q) {
662  qWarning("QGraphicsProxyWidget::setWidget: cannot embed widget %p"
663  "; already embedded", newWidget);
664  }
665  return;
666  }
667  *proxyWidget = q;
668 
670  newWidget->ensurePolished();
671  // Do not wait for this widget to close before the app closes ###
672  // shouldn't this widget inherit the attribute?
673  newWidget->setAttribute(Qt::WA_QuitOnClose, false);
674  q->setAcceptHoverEvents(true);
675 
677  q->setAttribute(Qt::WA_NoSystemBackground);
678  if (newWidget->testAttribute(Qt::WA_OpaquePaintEvent))
679  q->setAttribute(Qt::WA_OpaquePaintEvent);
680 
681  widget = newWidget;
682 
683  // Changes only go from the widget to the proxy.
688 
689  if ((autoShow && !newWidget->testAttribute(Qt::WA_WState_ExplicitShowHide)) || !newWidget->testAttribute(Qt::WA_WState_Hidden)) {
690  newWidget->show();
691  }
692 
693  // Copy the state from the widget onto the proxy.
694 #ifndef QT_NO_CURSOR
695  if (newWidget->testAttribute(Qt::WA_SetCursor))
696  q->setCursor(widget->cursor());
697 #endif
698  q->setEnabled(newWidget->isEnabled());
699  q->setVisible(newWidget->isVisible());
700  q->setLayoutDirection(newWidget->layoutDirection());
701  if (newWidget->testAttribute(Qt::WA_SetStyle))
702  q->setStyle(widget->style());
703 
704  resolveFont(inheritedFontResolveMask);
705  resolvePalette(inheritedPaletteResolveMask);
706 
707  if (!newWidget->testAttribute(Qt::WA_Resized))
708  newWidget->adjustSize();
709 
710  int left, top, right, bottom;
711  newWidget->getContentsMargins(&left, &top, &right, &bottom);
712  q->setContentsMargins(left, top, right, bottom);
713  q->setWindowTitle(newWidget->windowTitle());
714 
715  // size policies and constraints..
716  q->setSizePolicy(newWidget->sizePolicy());
717  QSize sz = newWidget->minimumSize();
718  q->setMinimumSize(sz.isNull() ? QSizeF() : QSizeF(sz));
719  sz = newWidget->maximumSize();
720  q->setMaximumSize(sz.isNull() ? QSizeF() : QSizeF(sz));
721 
722  updateProxyGeometryFromWidget();
723 
724  updateProxyInputMethodAcceptanceFromWidget();
725 
726  // Hook up the event filter to keep the state up to date.
727  newWidget->installEventFilter(q);
728  QObject::connect(newWidget, SIGNAL(destroyed()), q, SLOT(_q_removeWidgetSlot()));
729 
730  // Changes no longer go only from the widget to the proxy.
731  enabledChangeMode = QGraphicsProxyWidgetPrivate::NoMode;
732  visibleChangeMode = QGraphicsProxyWidgetPrivate::NoMode;
733  posChangeMode = QGraphicsProxyWidgetPrivate::NoMode;
734  sizeChangeMode = QGraphicsProxyWidgetPrivate::NoMode;
735 }
736 
743 {
744  Q_D(const QGraphicsProxyWidget);
745  return d->widget;
746 }
747 
758 {
759  Q_D(const QGraphicsProxyWidget);
760  if (!widget || !d->widget)
761  return QRectF();
762  if (d->widget == widget || d->widget->isAncestorOf(widget))
763  return QRectF(widget->mapTo(d->widget, QPoint(0, 0)), widget->size());
764  return QRectF();
765 }
766 
771 {
773  bool proxyResizesWidget = !d->posChangeMode && !d->sizeChangeMode;
774  if (proxyResizesWidget) {
777  }
779  if (proxyResizesWidget) {
780  d->posChangeMode = QGraphicsProxyWidgetPrivate::NoMode;
781  d->sizeChangeMode = QGraphicsProxyWidgetPrivate::NoMode;
782  }
783 }
784 
789  const QVariant &value)
790 {
792 
793  switch (change) {
794  case ItemPositionChange:
795  // The item's position is either changed directly on the proxy, in
796  // which case the position change should propagate to the widget,
797  // otherwise it happens as a side effect when filtering QEvent::Move.
798  if (!d->posChangeMode)
800  break;
802  // Move the internal widget if we're in widget-to-proxy
803  // mode. Otherwise the widget has already moved.
804  if (d->widget && d->posChangeMode != QGraphicsProxyWidgetPrivate::WidgetToProxyMode)
805  d->widget->move(value.toPoint());
807  d->posChangeMode = QGraphicsProxyWidgetPrivate::NoMode;
808  break;
809  case ItemVisibleChange:
810  if (!d->visibleChangeMode)
812  break;
814  if (d->widget && d->visibleChangeMode != QGraphicsProxyWidgetPrivate::WidgetToProxyMode)
815  d->widget->setVisible(isVisible());
816  if (d->visibleChangeMode == QGraphicsProxyWidgetPrivate::ProxyToWidgetMode)
817  d->visibleChangeMode = QGraphicsProxyWidgetPrivate::NoMode;
818  break;
819  case ItemEnabledChange:
820  if (!d->enabledChangeMode)
822  break;
824  if (d->widget && d->enabledChangeMode != QGraphicsProxyWidgetPrivate::WidgetToProxyMode)
825  d->widget->setEnabled(isEnabled());
826  if (d->enabledChangeMode == QGraphicsProxyWidgetPrivate::ProxyToWidgetMode)
827  d->enabledChangeMode = QGraphicsProxyWidgetPrivate::NoMode;
828  break;
829  default:
830  break;
831  }
832  return QGraphicsWidget::itemChange(change, value);
833 }
834 
839 {
841  if (!d->widget)
842  return QGraphicsWidget::event(event);
843 
844  switch (event->type()) {
845  case QEvent::StyleChange:
846  // Propagate style changes to the embedded widget.
847  if (!d->styleChangeMode) {
849  d->widget->setStyle(style());
850  d->styleChangeMode = QGraphicsProxyWidgetPrivate::NoMode;
851  }
852  break;
853  case QEvent::FontChange: {
854  // Propagate to widget.
855  QWidgetPrivate *wd = d->widget->d_func();
856  int mask = d->font.resolve() | d->inheritedFontResolveMask;
857  wd->inheritedFontResolveMask = mask;
858  wd->resolveFont();
859  break;
860  }
861  case QEvent::PaletteChange: {
862  // Propagate to widget.
863  QWidgetPrivate *wd = d->widget->d_func();
864  int mask = d->palette.resolve() | d->inheritedPaletteResolveMask;
865  wd->inheritedPaletteResolveMask = mask;
866  wd->resolvePalette();
867  break;
868  }
869  case QEvent::InputMethod: {
870  // Forward input method events if the focus widget enables
871  // input methods.
872  // ### Qt 4.5: this code must also go into a reimplementation
873  // of inputMethodEvent().
874  QWidget *focusWidget = d->widget->focusWidget();
875  if (focusWidget && focusWidget->testAttribute(Qt::WA_InputMethodEnabled))
876  QApplication::sendEvent(focusWidget, event);
877  break;
878  }
880  QWidget *focusWidget = d->widget->focusWidget();
881  while (focusWidget) {
882  QApplication::sendEvent(focusWidget, event);
883  if (event->isAccepted())
884  return true;
885  focusWidget = focusWidget->parentWidget();
886  }
887  return false;
888  }
889  case QEvent::KeyPress: {
890  QKeyEvent *k = static_cast<QKeyEvent *>(event);
891  if (k->key() == Qt::Key_Tab || k->key() == Qt::Key_Backtab) {
892  if (!(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) { //### Add MetaModifier?
893  QWidget *focusWidget = d->widget->focusWidget();
894  while (focusWidget) {
895  bool res = QApplication::sendEvent(focusWidget, event);
896  if ((res && event->isAccepted()) || (isWindow() && focusWidget == d->widget)) {
897  event->accept();
898  break;
899  }
900  focusWidget = focusWidget->parentWidget();
901  }
902  return true;
903  }
904  }
905  break;
906  }
907 #ifndef QT_NO_TOOLTIP
909  // Propagate the help event (for tooltip) to the widget under mouse
910  if (d->lastWidgetUnderMouse) {
912  QPoint pos = d->mapToReceiver(mapFromScene(he->scenePos()), d->lastWidgetUnderMouse).toPoint();
913  QHelpEvent e(QEvent::ToolTip, pos, he->screenPos());
914  QApplication::sendEvent(d->lastWidgetUnderMouse, &e);
915  event->setAccepted(e.isAccepted());
916  return e.isAccepted();
917  }
918  break;
919  }
920  case QEvent::ToolTipChange: {
921  // Propagate tooltip change to the widget
922  if (!d->tooltipChangeMode) {
924  d->widget->setToolTip(toolTip());
925  d->tooltipChangeMode = QGraphicsProxyWidgetPrivate::NoMode;
926  }
927  break;
928  }
929 #endif
930  default:
931  break;
932  }
933  return QGraphicsWidget::event(event);
934 }
935 
940 {
942 
943  if (object == d->widget) {
944  switch (event->type()) {
946  updateGeometry();
947  break;
948  case QEvent::Resize:
949  // If the widget resizes itself, we resize the proxy too.
950  // Prevent feed-back by checking the geometry change mode.
951  if (!d->sizeChangeMode)
952  d->updateProxyGeometryFromWidget();
953  break;
954  case QEvent::Move:
955  // If the widget moves itself, we move the proxy too. Prevent
956  // feed-back by checking the geometry change mode.
957  if (!d->posChangeMode)
958  d->updateProxyGeometryFromWidget();
959  break;
960  case QEvent::Hide:
961  case QEvent::Show:
962  // If the widget toggles its visible state, the proxy will follow.
963  if (!d->visibleChangeMode) {
965  setVisible(event->type() == QEvent::Show);
966  d->visibleChangeMode = QGraphicsProxyWidgetPrivate::NoMode;
967  }
968  break;
970  // If the widget toggles its enabled state, the proxy will follow.
971  if (!d->enabledChangeMode) {
973  setEnabled(d->widget->isEnabled());
974  d->enabledChangeMode = QGraphicsProxyWidgetPrivate::NoMode;
975  }
976  break;
977  case QEvent::StyleChange:
978  // Propagate style changes to the proxy.
979  if (!d->styleChangeMode) {
981  setStyle(d->widget->style());
982  d->styleChangeMode = QGraphicsProxyWidgetPrivate::NoMode;
983  }
984  break;
985 #ifndef QT_NO_TOOLTIP
987  // Propagate tooltip change to the proxy.
988  if (!d->tooltipChangeMode) {
990  setToolTip(d->widget->toolTip());
991  d->tooltipChangeMode = QGraphicsProxyWidgetPrivate::NoMode;
992  }
993  break;
994 #endif
995  default:
996  break;
997  }
998  }
999  return QGraphicsWidget::eventFilter(object, event);
1000 }
1001 
1006 {
1007  Q_UNUSED(event);
1008 }
1009 
1014 {
1015  Q_UNUSED(event);
1016 }
1017 
1018 #ifndef QT_NO_CONTEXTMENU
1019 
1023 {
1025  if (!event || !d->widget || !d->widget->isVisible() || !hasFocus())
1026  return;
1027 
1028  // Find widget position and receiver.
1029  QPointF pos = event->pos();
1030  QPointer<QWidget> alienWidget = d->widget->childAt(pos.toPoint());
1031  QPointer<QWidget> receiver = alienWidget ? alienWidget : d->widget;
1032 
1033  // Map event position from us to the receiver
1034  pos = d->mapToReceiver(pos, receiver);
1035 
1036  QPoint globalPos = receiver->mapToGlobal(pos.toPoint());
1037  //If the receiver by-pass the proxy its popups
1038  //will be top level QWidgets therefore they need
1039  //the screen position. mapToGlobal expect the widget to
1040  //have proper coordinates in regards of the windowing system
1041  //but it's not true because the widget is embedded.
1042  if (bypassGraphicsProxyWidget(receiver))
1043  globalPos = event->screenPos();
1044 
1045  // Send mouse event. ### Doesn't propagate the event.
1047  pos.toPoint(), globalPos, event->modifiers());
1049 
1050  event->setAccepted(contextMenuEvent.isAccepted());
1051 }
1052 #endif // QT_NO_CONTEXTMENU
1053 
1054 #ifndef QT_NO_DRAGANDDROP
1055 
1059 {
1060 #ifdef QT_NO_DRAGANDDROP
1061  Q_UNUSED(event);
1062 #else
1064  if (!d->widget)
1065  return;
1066 
1067  QDragEnterEvent proxyDragEnter(event->pos().toPoint(), event->dropAction(), event->mimeData(), event->buttons(), event->modifiers());
1068  proxyDragEnter.setAccepted(event->isAccepted());
1069  QApplication::sendEvent(d->widget, &proxyDragEnter);
1070  event->setAccepted(proxyDragEnter.isAccepted());
1071  if (proxyDragEnter.isAccepted()) // we discard answerRect
1072  event->setDropAction(proxyDragEnter.dropAction());
1073 #endif
1074 }
1079 {
1080  Q_UNUSED(event);
1081 #ifndef QT_NO_DRAGANDDROP
1083  if (!d->widget || !d->dragDropWidget)
1084  return;
1085  QDragLeaveEvent proxyDragLeave;
1086  QApplication::sendEvent(d->dragDropWidget, &proxyDragLeave);
1087  d->dragDropWidget = 0;
1088 #endif
1089 }
1090 
1095 {
1096 #ifdef QT_NO_DRAGANDDROP
1097  Q_UNUSED(event);
1098 #else
1100  if (!d->widget)
1101  return;
1102  QPointF p = event->pos();
1103  event->ignore();
1104  QPointer<QWidget> subWidget = d->widget->childAt(p.toPoint());
1105  QPointer<QWidget> receiver = subWidget ? subWidget : d->widget;
1106  bool eventDelivered = false;
1107  for (; receiver; receiver = receiver->parentWidget()) {
1108  if (!receiver->isEnabled() || !receiver->acceptDrops())
1109  continue;
1110  // Map event position from us to the receiver
1111  QPoint receiverPos = d->mapToReceiver(p, receiver).toPoint();
1112  if (receiver != d->dragDropWidget) {
1113  // Try to enter before we leave
1114  QDragEnterEvent dragEnter(receiverPos, event->possibleActions(), event->mimeData(), event->buttons(), event->modifiers());
1115  dragEnter.setDropAction(event->proposedAction());
1116  QApplication::sendEvent(receiver, &dragEnter);
1117  event->setAccepted(dragEnter.isAccepted());
1118  event->setDropAction(dragEnter.dropAction());
1119  if (!event->isAccepted()) {
1120  // propagate to the parent widget
1121  continue;
1122  }
1123 
1124  d->lastDropAction = event->dropAction();
1125 
1126  if (d->dragDropWidget) {
1127  QDragLeaveEvent dragLeave;
1128  QApplication::sendEvent(d->dragDropWidget, &dragLeave);
1129  }
1130  d->dragDropWidget = receiver;
1131  }
1132 
1133  QDragMoveEvent dragMove(receiverPos, event->possibleActions(), event->mimeData(), event->buttons(), event->modifiers());
1134  event->setDropAction(d->lastDropAction);
1135  QApplication::sendEvent(receiver, &dragMove);
1136  event->setAccepted(dragMove.isAccepted());
1137  event->setDropAction(dragMove.dropAction());
1138  if (event->isAccepted())
1139  d->lastDropAction = event->dropAction();
1140  eventDelivered = true;
1141  break;
1142  }
1143 
1144  if (!eventDelivered) {
1145  if (d->dragDropWidget) {
1146  // Leave the last drag drop item
1147  QDragLeaveEvent dragLeave;
1148  QApplication::sendEvent(d->dragDropWidget, &dragLeave);
1149  d->dragDropWidget = 0;
1150  }
1151  // Propagate
1152  event->setDropAction(Qt::IgnoreAction);
1153  }
1154 #endif
1155 }
1156 
1161 {
1162 #ifdef QT_NO_DRAGANDDROP
1163  Q_UNUSED(event);
1164 #else
1166  if (d->widget && d->dragDropWidget) {
1167  QPoint widgetPos = d->mapToReceiver(event->pos(), d->dragDropWidget).toPoint();
1168  QDropEvent dropEvent(widgetPos, event->possibleActions(), event->mimeData(), event->buttons(), event->modifiers());
1169  QApplication::sendEvent(d->dragDropWidget, &dropEvent);
1170  event->setAccepted(dropEvent.isAccepted());
1171  d->dragDropWidget = 0;
1172  }
1173 #endif
1174 }
1175 #endif
1176 
1181 {
1182  Q_UNUSED(event);
1183 }
1184 
1189 {
1190  Q_UNUSED(event);
1192  // If hoverMove was compressed away, make sure we update properly here.
1193  if (d->lastWidgetUnderMouse) {
1194  QApplicationPrivate::dispatchEnterLeave(0, d->lastWidgetUnderMouse);
1195  d->lastWidgetUnderMouse = 0;
1196  }
1197 }
1198 
1203 {
1205 #ifdef GRAPHICSPROXYWIDGET_DEBUG
1206  qDebug() << "QGraphicsProxyWidget::hoverMoveEvent";
1207 #endif
1208  // Ignore events on the window frame.
1209  if (!d->widget || !rect().contains(event->pos())) {
1210  if (d->lastWidgetUnderMouse) {
1211  QApplicationPrivate::dispatchEnterLeave(0, d->lastWidgetUnderMouse);
1212  d->lastWidgetUnderMouse = 0;
1213  }
1214  return;
1215  }
1216 
1217  d->embeddedMouseGrabber = 0;
1218  d->sendWidgetMouseEvent(event);
1219 }
1220 
1225 {
1226  Q_UNUSED(event);
1227 }
1228 
1233 {
1235  Q_UNUSED(event);
1236  d->embeddedMouseGrabber = 0;
1237 }
1238 
1243 {
1245 #ifdef GRAPHICSPROXYWIDGET_DEBUG
1246  qDebug() << "QGraphicsProxyWidget::mouseMoveEvent";
1247 #endif
1248  d->sendWidgetMouseEvent(event);
1249 }
1250 
1255 {
1257 #ifdef GRAPHICSPROXYWIDGET_DEBUG
1258  qDebug() << "QGraphicsProxyWidget::mousePressEvent";
1259 #endif
1260  d->sendWidgetMouseEvent(event);
1261 }
1262 
1267 {
1269 #ifdef GRAPHICSPROXYWIDGET_DEBUG
1270  qDebug() << "QGraphicsProxyWidget::mouseDoubleClickEvent";
1271 #endif
1272  d->sendWidgetMouseEvent(event);
1273 }
1274 
1278 #ifndef QT_NO_WHEELEVENT
1280 {
1282 #ifdef GRAPHICSPROXYWIDGET_DEBUG
1283  qDebug() << "QGraphicsProxyWidget::wheelEvent";
1284 #endif
1285  if (!d->widget)
1286  return;
1287 
1288  QPointF pos = event->pos();
1289  QPointer<QWidget> receiver = d->widget->childAt(pos.toPoint());
1290  if (!receiver)
1291  receiver = d->widget;
1292 
1293  // Map event position from us to the receiver
1294  pos = d->mapToReceiver(pos, receiver);
1295 
1296  // Send mouse event.
1297  QWheelEvent wheelEvent(pos.toPoint(), event->screenPos(), event->delta(),
1298  event->buttons(), event->modifiers(), event->orientation());
1299  QPointer<QWidget> focusWidget = d->widget->focusWidget();
1300  extern bool qt_sendSpontaneousEvent(QObject *, QEvent *);
1301  qt_sendSpontaneousEvent(receiver, &wheelEvent);
1302  event->setAccepted(wheelEvent.isAccepted());
1303 
1304  // ### Remove, this should be done by proper focusIn/focusOut events.
1305  if (focusWidget && !focusWidget->hasFocus()) {
1306  focusWidget->update();
1307  focusWidget = d->widget->focusWidget();
1308  if (focusWidget && focusWidget->hasFocus())
1309  focusWidget->update();
1310  }
1311 }
1312 #endif
1313 
1318 {
1320 #ifdef GRAPHICSPROXYWIDGET_DEBUG
1321  qDebug() << "QGraphicsProxyWidget::mouseReleaseEvent";
1322 #endif
1323  d->sendWidgetMouseEvent(event);
1324 }
1325 
1330 {
1332 #ifdef GRAPHICSPROXYWIDGET_DEBUG
1333  qDebug() << "QGraphicsProxyWidget::keyPressEvent";
1334 #endif
1335  d->sendWidgetKeyEvent(event);
1336 }
1337 
1342 {
1344 #ifdef GRAPHICSPROXYWIDGET_DEBUG
1345  qDebug() << "QGraphicsProxyWidget::keyReleaseEvent";
1346 #endif
1347  d->sendWidgetKeyEvent(event);
1348 }
1349 
1354 {
1355 #ifdef GRAPHICSPROXYWIDGET_DEBUG
1356  qDebug() << "QGraphicsProxyWidget::focusInEvent";
1357 #endif
1359 
1360  if (d->focusFromWidgetToProxy) {
1361  // Prevent recursion when the proxy autogains focus through the
1362  // embedded widget calling setFocus(). ### Could be done with event
1363  // filter on FocusIn instead?
1364  return;
1365  }
1366 
1367  d->proxyIsGivingFocus = true;
1368 
1369  switch (event->reason()) {
1370  case Qt::TabFocusReason: {
1371  if (QWidget *focusChild = d->findFocusChild(0, true))
1372  focusChild->setFocus(event->reason());
1373  break;
1374  }
1376  if (QWidget *focusChild = d->findFocusChild(0, false))
1377  focusChild->setFocus(event->reason());
1378  break;
1379  default:
1380  if (d->widget && d->widget->focusWidget()) {
1381  d->widget->focusWidget()->setFocus(event->reason());
1382  }
1383  break;
1384  }
1385 
1386  d->proxyIsGivingFocus = false;
1387 }
1388 
1393 {
1394 #ifdef GRAPHICSPROXYWIDGET_DEBUG
1395  qDebug() << "QGraphicsProxyWidget::focusOutEvent";
1396 #endif
1398  if (d->widget) {
1399  // We need to explicitly remove subfocus from the embedded widget's
1400  // focus widget.
1401  if (QWidget *focusWidget = d->widget->focusWidget())
1402  d->removeSubFocusHelper(focusWidget, event->reason());
1403  }
1404 }
1405 
1410 {
1412  if (!d->widget || !d->scene)
1414 
1416  QWidget *lastFocusChild = d->widget->focusWidget();
1417  if (QWidget *newFocusChild = d->findFocusChild(lastFocusChild, next)) {
1418  newFocusChild->setFocus(reason);
1419  return true;
1420  }
1421 
1423 }
1424 
1429 {
1430  Q_D(const QGraphicsProxyWidget);
1431  if (!d->widget)
1432  return QGraphicsWidget::sizeHint(which, constraint);
1433 
1434  QSizeF sh;
1435  switch (which) {
1436  case Qt::PreferredSize:
1437  if (QLayout *l = d->widget->layout())
1438  sh = l->sizeHint();
1439  else
1440  sh = d->widget->sizeHint();
1441  break;
1442  case Qt::MinimumSize:
1443  if (QLayout *l = d->widget->layout())
1444  sh = l->minimumSize();
1445  else
1446  sh = d->widget->minimumSizeHint();
1447  break;
1448  case Qt::MaximumSize:
1449  if (QLayout *l = d->widget->layout())
1450  sh = l->maximumSize();
1451  else
1453  break;
1454  case Qt::MinimumDescent:
1455  sh = constraint;
1456  break;
1457  default:
1458  break;
1459  }
1460  return sh;
1461 }
1462 
1467 {
1469  if (d->widget) {
1470  if (d->sizeChangeMode != QGraphicsProxyWidgetPrivate::WidgetToProxyMode)
1471  d->widget->resize(event->newSize().toSize());
1472  }
1474 }
1475 
1480 {
1482  Q_UNUSED(widget);
1483  if (!d->widget || !d->widget->isVisible())
1484  return;
1485 
1486  // Filter out repaints on the window frame.
1487  const QRect exposedWidgetRect = (option->exposedRect & rect()).toAlignedRect();
1488  if (exposedWidgetRect.isEmpty())
1489  return;
1490 
1491  // Disable QPainter's default pen being cosmetic. This allows widgets and
1492  // styles to follow Qt's existing defaults without getting ugly cosmetic
1493  // lines when scaled.
1494  bool restore = !(painter->renderHints() & QPainter::NonCosmeticDefaultPen);
1496 
1497  d->widget->render(painter, exposedWidgetRect.topLeft(), exposedWidgetRect);
1498 
1499  // Restore the render hints if necessary.
1500  if (restore)
1502 }
1503 
1508 {
1509  return Type;
1510 }
1511 
1530 {
1531  QGraphicsProxyWidget *proxy = child->graphicsProxyWidget();
1532  if (proxy)
1533  return proxy;
1534  if (!child->parentWidget()) {
1535  qWarning("QGraphicsProxyWidget::createProxyForChildWidget: top-level widget not in a QGraphicsScene");
1536  return 0;
1537  }
1538 
1540  if (!parentProxy)
1541  return 0;
1542 
1543  if (!QMetaObject::invokeMethod(parentProxy, "newProxyWidget", Qt::DirectConnection,
1544  Q_RETURN_ARG(QGraphicsProxyWidget*, proxy), Q_ARG(const QWidget*, child)))
1545  return 0;
1546  proxy->setParent(parentProxy);
1547  proxy->setWidget(child);
1548  return proxy;
1549 }
1550 
1570 {
1571  return new QGraphicsProxyWidget(this);
1572 }
1573 
1574 
1575 
1577 
1578 #include "moc_qgraphicsproxywidget.cpp"
1579 
1580 #endif //QT_NO_GRAPHICSVIEW
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QVariant inputMethodQueryHelper(Qt::InputMethodQuery query) const
Reimplemented from QGraphicsItemPrivate.
Qt::DropAction dropAction() const
Returns the action that was performed in this drag and drop.
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
QGraphicsWidget * focusWidget() const
If this widget, a child or descendant of this widget currently has input focus, this function will re...
QSize maximumSize
the widget&#39;s maximum size in pixels
Definition: qwidget.h:173
void setGeometry(const QRectF &rect)
Reimplemented Function
QSize minimumSize
the widget&#39;s minimum size
Definition: qwidget.h:172
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
bool qt_sendSpontaneousEvent(QObject *, QEvent *)
QPointF scenePos() const
Returns the position of the mouse cursor in scene coordinates at the moment the help event was sent...
bool hasFocus() const
Returns true if this item is active, and it or its focus proxy has keyboard input focus; otherwise...
QGraphicsItem * parent
QGraphicsProxyWidget(QGraphicsItem *parent=0, Qt::WindowFlags wFlags=0)
Constructs a new QGraphicsProxy widget.
The QKeyEvent class describes a key event.
Definition: qevent.h:224
QWidget * focusWidget() const
Returns the last child of this widget that setFocus had been called on.
Definition: qwidget.cpp:6863
int type
Definition: qmetatype.cpp:239
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
Reimplemented Function
QPointF toPointF() const
Returns the variant as a QPointF if the variant has type() Point or PointF ; otherwise returns a null...
Definition: qvariant.cpp:2509
void setModifiers(Qt::KeyboardModifiers modifiers)
EventRef event
bool isWindow() const
Returns true if the item is a QGraphicsWidget window, otherwise returns false.
QList< QGraphicsItem * > childItems() const
Returns a list of this item&#39;s children.
QScopedPointer< QGraphicsItemPrivate > d_ptr
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
Reimplemented Function
void setStyle(QStyle *style)
Sets the widget&#39;s style to style.
void unsetCursor()
Definition: qwidget.cpp:5311
QPoint mapTo(QWidget *, const QPoint &) const
Translates the widget coordinate pos to the coordinate system of parent.
Definition: qwidget.cpp:4409
static QMouseEvent * createExtendedMouseEvent(Type type, const QPointF &pos, const QPoint &globalPos, Qt::MouseButton button, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
Definition: qevent.cpp:251
void ensurePolished() const
Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette).
Definition: qwidget.cpp:10024
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition: qwidget.h:945
QSize toSize() const
Returns an integer based copy of this size.
Definition: qsize.h:355
The QWheelEvent class contains parameters that describe a wheel event.
Definition: qevent.h:139
The QContextMenuEvent class contains parameters that describe a context menu event.
Definition: qevent.h:396
void mousePressEvent(QGraphicsSceneMouseEvent *event)
Reimplemented Function
void setScreenPos(const QPoint &pos)
bool isVisible() const
Definition: qwidget.h:1005
bool isVisibleTo(QWidget *) const
Returns true if this widget would become visible if ancestor is shown; otherwise returns false...
Definition: qwidget.cpp:8371
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
int type() const
Reimplemented Function
Reason
This enum describes the reason why the event was sent.
Definition: qevent.h:399
QPoint screenPos() const
Returns the position of the mouse cursor in screen coordinates at the moment the hover event was sent...
void setAccepted(bool accepted)
Definition: qcoreevent.h:306
void setToolTip(const QString &toolTip)
Sets the item&#39;s tool tip to toolTip.
#define SLOT(a)
Definition: qobjectdefs.h:226
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const
Reimplemented Function
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
The QGraphicsSceneMouseEvent class provides mouse events in the graphics view framework.
void removeEventFilter(QObject *)
Removes an event filter object obj from this object.
Definition: qobject.cpp:2099
bool isVisible() const
Returns true if the item is visible; otherwise, false is returned.
#define QWIDGETSIZE_MAX
Defines the maximum size for a QWidget object.
Definition: qwidget.h:1087
Qt::FocusPolicy focusPolicy
the way the widget accepts keyboard focus
Definition: qwidget.h:187
void setWidget(QWidget *widget)
Embeds widget into this proxy widget.
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
void setDropAction(Qt::DropAction action)
Sets the action to be performed on the data by the target.
Definition: qevent.cpp:2746
QGraphicsScene * scene
Qt::MouseButton button() const
Returns the mouse button (if any) that caused the event.
QPointF topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:539
QRect translated(int dx, int dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:328
void sendWidgetKeyEvent(QKeyEvent *event)
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
Reimplemented Function
void resolvePalette()
Determine which palette is inherited from this widget&#39;s ancestors and QApplication::palette, resolve this against this widget&#39;s palette (attributes from the inherited palette are copied over this widget&#39;s palette).
Definition: qwidget.cpp:4927
#define Q_ARG(type, data)
Definition: qobjectdefs.h:246
The QGraphicsSceneResizeEvent class provides events for widget resizing in the graphics view framewor...
QPointF pos() const
Returns the position of the item in parent coordinates.
QGraphicsProxyWidget * graphicsProxyWidget() const
Returns the proxy widget for the corresponding embedded widget in a graphics view; otherwise returns ...
Definition: qwidget.cpp:12939
GraphicsItemChange
This enum describes the state changes that are notified by QGraphicsItem::itemChange().
static bool bypassGraphicsProxyWidget(const QWidget *p)
Returns true if p or any of its parents enable the Qt::BypassGraphicsProxyWidget window flag...
Definition: qwidget_p.h:353
void setButtons(Qt::MouseButtons buttons)
QWidget * findFocusChild(QWidget *child, bool next) const
virtual QVariant inputMethodQuery(Qt::InputMethodQuery) const
This method is only relevant for input widgets.
Definition: qwidget.cpp:9683
void focusInEvent(QFocusEvent *event)
Reimplemented Function
bool hasFocus() const
Definition: qwidget.cpp:6583
QRectF toRectF() const
Returns the variant as a QRectF if the variant has type() Rect or RectF ; otherwise returns an invali...
Definition: qvariant.cpp:2463
QGraphicsProxyWidget * newProxyWidget(const QWidget *)
The QDragMoveEvent class provides an event which is sent while a drag and drop action is in progress...
Definition: qevent.h:530
bool isEnabled() const
Returns true if the item is enabled; otherwise, false is returned.
QRectF rect() const
Returns the item&#39;s local rect as a QRectF.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_D(Class)
Definition: qglobal.h:2482
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
void setVisible(bool visible)
If visible is true, the item is made visible.
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
Reimplemented Function
void grabMouseEvent(QEvent *event)
Reimplemented Function
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
void setParent(QObject *)
Makes the object a child of parent.
Definition: qobject.cpp:1950
QStyle * style() const
Definition: qwidget.cpp:2742
void sendWidgetMouseEvent(QGraphicsSceneMouseEvent *event)
#define Q_Q(Class)
Definition: qglobal.h:2483
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
QGraphicsProxyWidget * proxyWidget
Definition: qwidget_p.h:251
Q_CORE_EXPORT void qDebug(const char *,...)
virtual bool focusNextPrevChild(bool next)
Finds a new widget to give the keyboard focus to, as appropriate for Tab and Shift+Tab, and returns true if it can find a new widget; returns false otherwise.
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
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void wheelEvent(QGraphicsSceneWheelEvent *event)
Reimplemented Function
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QPointF mapToReceiver(const QPointF &pos, const QWidget *receiver) const
void embedSubWindow(QWidget *)
Embeds subWin as a subwindow of this proxy widget.
bool isAccepted() const
Definition: qcoreevent.h:307
void destroyed(QObject *=0)
This signal is emitted immediately before the object obj is destroyed, and can not be blocked...
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifiers at the moment the hover event was sent.
void focusOutEvent(QFocusEvent *event)
Reimplemented Function
virtual bool isProxyWidget() const
void getContentsMargins(int *left, int *top, int *right, int *bottom) const
Returns the widget&#39;s contents margins for left, top, right, and bottom.
Definition: qwidget.cpp:7509
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
void setDropAction(Qt::DropAction action)
This function lets the receiver of the drop set the drop action that was performed to action...
void removeItem(QGraphicsItem *item)
Removes the item item and all its children from the scene.
void adjustSize()
Adjusts the size of the widget to fit its contents.
Definition: qwidget.cpp:8488
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90
QWidget * childAt(int x, int y) const
Returns the visible child widget at the position ({x}, {y}) in the widget&#39;s coordinate system...
Definition: qwidget.h:934
void setGeometry(const QRectF &rect)
This virtual function sets the geometry of the QGraphicsLayoutItem to rect, which is in parent coordi...
void unembedSubWindow(QWidget *)
Removes ("unembeds") subWin and deletes the proxy holder item.
void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
Reimplemented Function
The QHideEvent class provides an event which is sent after a widget is hidden.
Definition: qevent.h:388
bool spontaneous() const
Returns true if the event originated outside the application (a system event); otherwise returns fals...
Definition: qcoreevent.h:304
void setPos(const QPointF &pos)
virtual void resizeEvent(QGraphicsSceneResizeEvent *event)
This event handler, for GraphicsSceneResize events, is delivered after the widget has been resized (i...
QVariant itemChange(GraphicsItemChange change, const QVariant &value)
QGraphicsWidget uses the base implementation of this function to catch and deliver events related to ...
Q_CORE_EXPORT void qWarning(const char *,...)
QPoint screenPos() const
Returns the position of the mouse cursor in screen coordinates at the moment the the context menu was...
unsigned int uint
Definition: qglobal.h:996
#define Q_RETURN_ARG(type, data)
Definition: qobjectdefs.h:247
QString windowTitle
the window title (caption)
Definition: qwidget.h:198
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
The QDragLeaveEvent class provides an event that is sent to a widget when a drag and drop action leav...
Definition: qevent.h:577
QCursor cursor
the cursor shape for this widget
Definition: qwidget.h:183
QSize size
the size of the widget excluding any window frame
Definition: qwidget.h:165
~QGraphicsProxyWidget()
Destroys the proxy widget and any embedded widget.
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
QVariant extra(Extra type) const
bool acceptDrops
whether drop events are enabled for this widget
Definition: qwidget.h:197
QPoint screenPos() const
Returns the position of the mouse cursor in screen coordinates at the moment the help event was sent...
void setSize(const QSizeF &s)
Sets the size of the rectangle to the given size.
Definition: qrect.h:790
bool isEnabled() const
Definition: qwidget.h:948
void hoverMoveEvent(QGraphicsSceneHoverEvent *event)
Reimplemented Function
static QWidget * parentWidget(const QWidget *w)
QVariant itemChange(GraphicsItemChange change, const QVariant &value)
Reimplemented Function
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
The QGraphicsProxyWidget class provides a proxy layer for embedding a QWidget in a QGraphicsScene...
QPointF mapFromScene(const QPointF &point) const
Maps the point point, which is in this item&#39;s scene&#39;s coordinate system, to this item&#39;s coordinate sy...
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
Qt::DropAction proposedAction() const
Returns the drop action that is proposed, i.e., preferred.
Qt::LayoutDirection layoutDirection
the layout direction for this widget
Definition: qwidget.h:216
void ungrabMouseEvent(QEvent *event)
Reimplemented Function
uint inheritedPaletteResolveMask
Definition: qwidget_p.h:743
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:234
InputMethodQuery
Definition: qnamespace.h:1541
void setRenderHints(RenderHints hints, bool on=true)
Sets the given render hints on the painter if on is true; otherwise clears the render hints...
Definition: qpainter.cpp:7649
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.
Definition: qobject.cpp:2895
Qt::DropActions possibleActions() const
Returns the possible drop actions that the drag and drop can result in.
SizeHint
Definition: qnamespace.h:1708
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
The QGraphicsSceneHelpEvent class provides events when a tooltip is requested.
The QDropEvent class provides an event which is sent when a drag and drop action is completed...
Definition: qevent.h:476
QSizeF newSize() const
Returns the new size (i.e., the current size).
bool event(QEvent *event)
Handles the event.
The QGraphicsSceneDragDropEvent class provides events for drag and drop in the graphics view framewor...
FocusReason
Definition: qnamespace.h:1521
Type
This enum type defines the valid event types in Qt.
Definition: qcoreevent.h:62
QPoint pos
the position of the widget within its parent widget
Definition: qwidget.h:163
void keyReleaseEvent(QKeyEvent *event)
Reimplemented Function
void keyPressEvent(QKeyEvent *event)
Reimplemented Function
void dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
Reimplemented Function
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const
Reimplemented Function
QRect toRect() const
Returns the variant as a QRect if the variant has type() Rect ; otherwise returns an invalid QRect...
Definition: qvariant.cpp:2416
QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
Definition: qpoint.h:376
QString toolTip() const
Returns the item&#39;s tool tip, or an empty QString if no tool tip has been set.
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
void dragEnterEvent(QGraphicsSceneDragDropEvent *event)
Reimplemented Function
QSizePolicy sizePolicy
the default layout behavior of the widget
Definition: qwidget.h:171
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
The QDragEnterEvent class provides an event which is sent to a widget when a drag and drop action ent...
Definition: qevent.h:555
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
Reimplemented Function
void installEventFilter(QObject *)
Installs an event filter filterObj on this object.
Definition: qobject.cpp:2070
QPointF pos() const
Returns the position of the mouse cursor in item coordinates at the moment the hover event was sent...
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
Reimplemented Function
bool isValid() const
Returns true if both the width and height is equal to or greater than 0; otherwise returns false...
Definition: qsize.h:123
bool isWidget() const
Returns true if this item is a widget (i.
uint inheritedFontResolveMask
Definition: qwidget_p.h:742
QFactoryLoader * l
virtual bool contains(const QPointF &point) const
Returns true if this item contains point, which is in local coordinates; otherwise, false is returned.
Qt::FocusReason reason()
Definition: qevent.cpp:1197
static void mouseEvent(MouseAction action, QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey, QPoint pos, int delay=-1)
Definition: qtestmouse.h:71
static void dispatchEnterLeave(QWidget *enter, QWidget *leave)
void resolveFont()
Determine which font is implicitly imposed on this widget by its ancestors and QApplication::font, resolve this against its own font (attributes from the implicit font are copied over).
Definition: qwidget.cpp:5074
void moveTo(qreal x, qreal t)
Moves the rectangle, leaving the top-left corner at the given position (x, y).
Definition: qrect.h:728
void removeSubFocusHelper(QWidget *widget, Qt::FocusReason reason)
void dragMoveEvent(QGraphicsSceneDragDropEvent *event)
Reimplemented Function
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
QPoint mapFromGlobal(const QPoint &) const
Translates the global screen coordinate pos to widget coordinates.
QPointF pos() const
Returns the mouse cursor position in item coordinates.
bool isNull() const
Returns true if both the width and height is 0; otherwise returns false.
Definition: qsize.h:117
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.
void dropEvent(QGraphicsSceneDragDropEvent *event)
Reimplemented Function
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QSize sizeHint
the recommended size for the widget
Definition: qwidget.h:195
void hideEvent(QHideEvent *event)
Reimplemented Function
QGraphicsProxyWidget * createProxyForChildWidget(QWidget *child)
Creates a proxy widget for the given child of the widget contained in this proxy. ...
bool event(QEvent *event)
Reimplemented Function
QStyle * style() const
Returns a pointer to the widget&#39;s style.
void setEnabled(bool enabled)
If enabled is true, the item is enabled; otherwise, it is disabled.
RenderHints renderHints() const
Returns a flag that specifies the rendering hints that are set for this painter.
Definition: qpainter.cpp:7675
static QGraphicsProxyWidget * nearestGraphicsProxyWidget(const QWidget *origin)
Finds the nearest widget embedded in a graphics proxy widget along the chain formed by this widget an...
Definition: qwidget.cpp:6098
Qt::WindowFlags windowFlags() const
Window flags are a combination of a type (e.
Definition: qwidget.h:939
Q_GUI_EXPORT bool qt_tab_all_widgets
The QGraphicsSceneWheelEvent class provides wheel events in the graphics view framework.
QList< QGraphicsItem * > children
QRectF translated(qreal dx, qreal dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:740
QRectF exposedRect
the exposed rectangle, in item coordinates
Definition: qstyleoption.h:873
QPointer< QWidget > embeddedMouseGrabber
QRectF subWidgetRect(const QWidget *widget) const
Returns the rectangle for widget, which must be a descendant of widget(), or widget() itself...
void setButton(Qt::MouseButton button)
static bool sendMouseEvent(QWidget *receiver, QMouseEvent *event, QWidget *alienWidget, QWidget *native, QWidget **buttonDown, QPointer< QWidget > &lastMouseReceiver, bool spontaneous=true)
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
void updateGeometry()
If this widget is currently managed by a layout, this function notifies the layout that the widget&#39;s ...
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
void showEvent(QShowEvent *event)
Reimplemented Function
The QStyleOptionGraphicsItem class is used to describe the parameters needed to draw a QGraphicsItem...
Definition: qstyleoption.h:867
#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
QRect geometry
the geometry of the widget relative to its parent and excluding the window frame
Definition: qwidget.h:158
bool focusNextPrevChild(bool next)
Reimplemented Function
QPointer< QWidget > lastWidgetUnderMouse
QPoint mapToGlobal(const QPoint &) const
Translates the widget coordinate pos to global screen coordinates.
The QFocusEvent class contains event parameters for widget focus events.
Definition: qevent.h:275
QPoint toPoint() const
Returns the variant as a QPoint if the variant has type() Point or PointF ; otherwise returns a null ...
Definition: qvariant.cpp:2400
QWidget * widget() const
Returns a pointer to the embedded widget.
Qt::MouseButtons buttons() const
Returns the combination of mouse buttons that were pressed at the time the event was sent...
QPointF pos() const
Returns the mouse position of the event relative to the view that sent the event. ...
The QGraphicsSceneHoverEvent class provides hover events in the graphics view framework.
void resizeEvent(QGraphicsSceneResizeEvent *event)
Reimplemented Function
Reason reason() const
Returns the reason for the context menu event.
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288
The QHelpEvent class provides an event that is used to request helpful information about a particular...
Definition: qevent.h:586
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.
void setWidget_helper(QWidget *widget, bool autoShow)
bool eventFilter(QObject *object, QEvent *event)
Reimplemented Function
The QGraphicsSceneContextMenuEvent class provides context menu events in the graphics view framework...