Qt 4.8
qgraphicswidget_p.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 <QtCore/qdebug.h>
47 #include <QtCore/qnumeric.h>
48 #include "qgraphicswidget_p.h"
49 #include "qgraphicslayoutitem_p.h"
50 #include "qgraphicslayout.h"
51 #include "qgraphicsscene_p.h"
52 #include <QtGui/qapplication.h>
53 #include <QtGui/qgraphicsscene.h>
54 #include <QtGui/qstyleoption.h>
55 #include <QtGui/QStyleOptionTitleBar>
56 #include <QtGui/QGraphicsSceneMouseEvent>
57 #if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC)
58 # include <QMacStyle>
59 #endif
60 
62 
63 void QGraphicsWidgetPrivate::init(QGraphicsItem *parentItem, Qt::WindowFlags wFlags)
64 {
66 
67  attributes = 0;
68  isWidget = 1; // QGraphicsItem::isWidget() returns true.
69  focusNext = focusPrev = q;
71 
72  adjustWindowFlags(&wFlags);
73  windowFlags = wFlags;
74 
75  if (parentItem)
76  setParentItemHelper(parentItem, 0, 0);
77 
79  q->setGraphicsItem(q);
80 
82  q->unsetWindowFrameMargins();
85  if (windowFlags & Qt::Window)
87 }
88 
90 {
91  Q_Q(const QGraphicsWidget);
92  int height = q->style()->pixelMetric(QStyle::PM_TitleBarHeight, &options);
93 #if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC)
94  if (qobject_cast<QMacStyle*>(q->style())) {
95  height -=4;
96  }
97 #endif
98  return (qreal)height;
99 }
100 
105 {
106  // Remove any lazily allocated data
107  delete[] margins;
108  delete[] windowFrameMargins;
109  delete windowData;
110 }
111 
122 {
123  if (!margins) {
124  margins = new qreal[4];
125  for (int i = 0; i < 4; ++i)
126  margins[i] = 0;
127  }
128 }
129 
140 {
141  if (!windowFrameMargins) {
142  windowFrameMargins = new qreal[4];
143  for (int i = 0; i < 4; ++i)
144  windowFrameMargins[i] = 0;
145  }
146 }
147 
158 {
159  if (!windowData)
160  windowData = new WindowData;
161 }
162 
164 {
165  if (this->palette == palette && this->palette.resolve() == palette.resolve())
166  return;
167  updatePalette(palette);
168 }
169 
171 {
172  inheritedPaletteResolveMask = inheritedMask;
173  QPalette naturalPalette = naturalWidgetPalette();
174  QPalette resolvedPalette = palette.resolve(naturalPalette);
175  updatePalette(resolvedPalette);
176 }
177 
179 {
181  // Update local palette setting.
182  this->palette = palette;
183 
184  // Calculate new mask.
185  if (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation))
187  int mask = palette.resolve() | inheritedPaletteResolveMask;
188 
189  // Propagate to children.
190  for (int i = 0; i < children.size(); ++i) {
191  QGraphicsItem *item = children.at(i);
192  if (item->isWidget()) {
193  QGraphicsWidget *w = static_cast<QGraphicsWidget *>(item);
195  w->d_func()->resolvePalette(mask);
196  } else {
197  item->d_ptr->resolvePalette(mask);
198  }
199  }
200 
201  // Notify change.
203  QApplication::sendEvent(q, &event);
204 }
205 
207 {
209  if ((direction == Qt::RightToLeft) == (testAttribute(Qt::WA_RightToLeft)))
210  return;
211  q->setAttribute(Qt::WA_RightToLeft, (direction == Qt::RightToLeft));
212 
213  // Propagate this change to all children.
214  for (int i = 0; i < children.size(); ++i) {
215  QGraphicsItem *item = children.at(i);
216  if (item->isWidget()) {
217  QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(item);
218  if (widget->parentWidget() && !widget->testAttribute(Qt::WA_SetLayoutDirection))
219  widget->d_func()->setLayoutDirection_helper(direction);
220  }
221  }
222 
223  // Send the notification event to this widget item.
226 }
227 
229 {
231  if (q->testAttribute(Qt::WA_SetLayoutDirection)) {
232  return;
233  }
236  } else if (scene) {
237  // ### shouldn't the scene have a layoutdirection really? how does
238  // ### QGraphicsWidget get changes from QApplication::layoutDirection?
240  } else {
242  }
243 }
244 
245 /* private slot */
247 {
249  if (refCountInvokeRelayout == 0) {
251  bool wasResized = q->testAttribute(Qt::WA_Resized);
252  q->resize(q->size()); // this will restrict the size
253  q->setAttribute(Qt::WA_Resized, wasResized);
254  }
255 }
256 
258 {
259  Q_Q(const QGraphicsWidget);
261  if (QGraphicsWidget *parent = q->parentWidget()) {
262  palette = parent->palette();
263  } else if (scene) {
264  palette = scene->palette();
265  }
266  palette.resolve(0);
267  return palette;
268 }
269 
271 {
272  if (this->font == font && this->font.resolve() == font.resolve())
273  return;
274  updateFont(font);
275 }
276 
278 {
280  inheritedFontResolveMask = inheritedMask;
281  if (QGraphicsWidget *p = q->parentWidget())
282  inheritedFontResolveMask |= p->d_func()->inheritedFontResolveMask;
283  QFont naturalFont = naturalWidgetFont();
284  QFont resolvedFont = font.resolve(naturalFont);
285  updateFont(resolvedFont);
286 }
287 
289 {
291  // Update the local font setting.
292  this->font = font;
293 
294  // Calculate new mask.
295  if (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation))
297  int mask = font.resolve() | inheritedFontResolveMask;
298 
299  // Propagate to children.
300  for (int i = 0; i < children.size(); ++i) {
301  QGraphicsItem *item = children.at(i);
302  if (item->isWidget()) {
303  QGraphicsWidget *w = static_cast<QGraphicsWidget *>(item);
305  w->d_func()->resolveFont(mask);
306  } else {
307  item->d_ptr->resolveFont(mask);
308  }
309  }
310 
311  if (!polished)
312  return;
313  // Notify change.
315  QApplication::sendEvent(q, &event);
316 }
317 
319 {
320  Q_Q(const QGraphicsWidget);
321  QFont naturalFont; // ### no application font support
322  if (QGraphicsWidget *parent = q->parentWidget()) {
323  naturalFont = parent->font();
324  } else if (scene) {
325  naturalFont = scene->font();
326  }
327  naturalFont.resolve(0);
328  return naturalFont;
329 }
330 
332 {
335  q->initStyleOption(option);
336  option->rect.setHeight(titleBarHeight(*option));
337  option->titleBarFlags = windowFlags;
340  bool isActive = q->isActiveWindow();
341  if (isActive) {
342  option->state |= QStyle::State_Active;
345  } else {
346  option->state &= ~QStyle::State_Active;
348  }
349  QFont windowTitleFont = QApplication::font("QWorkspaceTitleBar");
350  QRect textRect = q->style()->subControlRect(QStyle::CC_TitleBar, option, QStyle::SC_TitleBarLabel, 0);
351  option->text = QFontMetrics(windowTitleFont).elidedText(
353 }
354 
356 {
357  bool customize = (*flags & (Qt::CustomizeWindowHint
364 
365  uint type = (*flags & Qt::WindowType_Mask);
366  if (customize)
367  ;
368  else if (type == Qt::Dialog || type == Qt::Sheet)
370  else if (type == Qt::Tool)
372  else if (type == Qt::Window || type == Qt::SubWindow)
375 }
376 
378 {
383  windowData->buttonSunken = false;
386  // make sure that the coordinates (rect and pos) we send to the style are positive.
387  bar.rect = q->windowFrameRect().toRect();
388  bar.rect.moveTo(0,0);
389  bar.rect.setHeight(q->style()->pixelMetric(QStyle::PM_TitleBarHeight, &bar));
390  QPointF pos = event->pos();
391  if (windowFrameMargins) {
392  pos.rx() += windowFrameMargins[Left];
393  pos.ry() += windowFrameMargins[Top];
394  }
396  if (q->style()->subControlRect(QStyle::CC_TitleBar, &bar,
398  event->widget()).contains(pos.toPoint())) {
399  q->close();
400  }
401  }
402  if (!(static_cast<QGraphicsSceneMouseEvent *>(event)->buttons()))
404  event->accept();
405  }
406 }
407 
409 {
411  if (event->button() != Qt::LeftButton)
412  return;
413 
415  windowData->startGeometry = q->geometry();
416  windowData->grabbedSection = q->windowFrameSectionAt(event->pos());
420  windowData->buttonSunken = true;
421  q->update();
422  }
423  event->setAccepted(windowData->grabbedSection != Qt::NoSection);
424 }
425 
436  const QGraphicsWidget *widget,
437  bool heightForWidth = true)
438 {
440  const bool hasHFW = QGraphicsLayoutItemPrivate::get(widget)->hasHeightForWidth();
441  if (hasHFW == heightForWidth) {
442  minimumHeightForWidth = hasHFW
443  ? widget->effectiveSizeHint(Qt::MinimumSize, QSizeF(width, -1)).height()
444  : widget->effectiveSizeHint(Qt::MinimumSize, QSizeF(-1, width)).width(); //"width" is here height!
445  } else {
446  // widthForHeight
447  const qreal constraint = width;
448  while (maxh - minh > 0.1) {
449  qreal middle = minh + (maxh - minh)/2;
450  // ### really bad, if we are a widget with a layout it will call
451  // layout->effectiveSizeHint(Qt::MiniumumSize), which again will call
452  // sizeHint three times because of how the cache works
453  qreal hfw = hasHFW
454  ? widget->effectiveSizeHint(Qt::MinimumSize, QSizeF(middle, -1)).height()
455  : widget->effectiveSizeHint(Qt::MinimumSize, QSizeF(-1, middle)).width();
456  if (hfw > constraint) {
457  minh = middle;
458  } else if (hfw <= constraint) {
459  maxh = middle;
460  }
461  }
462  minimumHeightForWidth = maxh;
463  }
464  return minimumHeightForWidth;
465 }
466 
468  const QGraphicsWidget *widget)
469 {
470  return minimumHeightForWidth(height, minw, maxw, widget, false);
471 }
472 
473 static QSizeF closestAcceptableSize(const QSizeF &proposed,
474  const QGraphicsWidget *widget)
475 {
476  const QSizeF current = widget->size();
477 
478  qreal minw = proposed.width();
479  qreal maxw = current.width();
480  qreal minh = proposed.height();
481  qreal maxh = current.height();
482 
483  qreal middlew = maxw;
484  qreal middleh = maxh;
485  qreal min_hfw;
486  min_hfw = minimumHeightForWidth(maxw, minh, maxh, widget);
487 
488  do {
489  if (maxw - minw < 0.1) {
490  // we still havent found anything, cut off binary search
491  minw = maxw;
492  minh = maxh;
493  }
494  middlew = minw + (maxw - minw)/qreal(2.0);
495  middleh = minh + (maxh - minh)/qreal(2.0);
496 
497  min_hfw = minimumHeightForWidth(middlew, minh, maxh, widget);
498 
499  if (min_hfw > middleh) {
500  minw = middlew;
501  minh = middleh;
502  } else if (min_hfw <= middleh) {
503  maxw = middlew;
504  maxh = middleh;
505  }
506  } while (maxw != minw);
507 
508  min_hfw = minimumHeightForWidth(middlew, minh, maxh, widget);
509 
510  QSizeF result;
511  if (min_hfw < maxh) {
512  result = QSizeF(middlew, min_hfw);
513  } else {
514  // Needed because of the cut-off we do above.
515  result = QSizeF(minimumWidthForHeight(maxh, proposed.width(), current.width(), widget), maxh);
516  }
517  return result;
518 }
519 
520 static void _q_boundGeometryToSizeConstraints(const QRectF &startGeometry,
521  QRectF *rect, Qt::WindowFrameSection section,
522  const QSizeF &min, const QSizeF &max,
523  const QGraphicsWidget *widget)
524 {
525  const QRectF proposedRect = *rect;
526  qreal width = qBound(min.width(), proposedRect.width(), max.width());
527  qreal height = qBound(min.height(), proposedRect.height(), max.height());
528 
529  const bool hasHFW = QGraphicsLayoutItemPrivate::get(widget)->hasHeightForWidth();
530  const bool hasWFH = QGraphicsLayoutItemPrivate::get(widget)->hasWidthForHeight();
531 
532  const bool widthChanged = proposedRect.width() != widget->size().width();
533  const bool heightChanged = proposedRect.height() != widget->size().height();
534 
535  if (hasHFW || hasWFH) {
536  if (widthChanged || heightChanged) {
537  qreal minExtent;
538  qreal maxExtent;
539  qreal constraint;
540  qreal proposed;
541  if (hasHFW) {
542  minExtent = min.height();
543  maxExtent = max.height();
544  constraint = width;
545  proposed = proposedRect.height();
546  } else {
547  // width for height
548  minExtent = min.width();
549  maxExtent = max.width();
550  constraint = height;
551  proposed = proposedRect.width();
552  }
553  if (minimumHeightForWidth(constraint, minExtent, maxExtent, widget, hasHFW) > proposed) {
554  QSizeF effectiveSize = closestAcceptableSize(QSizeF(width, height), widget);
555  width = effectiveSize.width();
556  height = effectiveSize.height();
557  }
558  }
559  }
560 
561  switch (section) {
562  case Qt::LeftSection:
563  rect->setRect(startGeometry.right() - qRound(width), startGeometry.top(),
564  qRound(width), startGeometry.height());
565  break;
566  case Qt::TopLeftSection:
567  rect->setRect(startGeometry.right() - qRound(width), startGeometry.bottom() - qRound(height),
568  qRound(width), qRound(height));
569  break;
570  case Qt::TopSection:
571  rect->setRect(startGeometry.left(), startGeometry.bottom() - qRound(height),
572  startGeometry.width(), qRound(height));
573  break;
574  case Qt::TopRightSection:
575  rect->setTop(rect->bottom() - qRound(height));
576  rect->setWidth(qRound(width));
577  break;
578  case Qt::RightSection:
579  rect->setWidth(qRound(width));
580  break;
582  rect->setWidth(qRound(width));
583  rect->setHeight(qRound(height));
584  break;
585  case Qt::BottomSection:
586  rect->setHeight(qRound(height));
587  break;
589  rect->setRect(startGeometry.right() - qRound(width), startGeometry.top(),
590  qRound(width), qRound(height));
591  break;
592  default:
593  break;
594  }
595 }
596 
598 {
602  return;
603 
604  QLineF delta(q->mapFromScene(event->buttonDownScenePos(Qt::LeftButton)), event->pos());
605  QLineF parentDelta(q->mapToParent(delta.p1()), q->mapToParent(delta.p2()));
606  QLineF parentXDelta(q->mapToParent(QPointF(delta.p1().x(), 0)), q->mapToParent(QPointF(delta.p2().x(), 0)));
607  QLineF parentYDelta(q->mapToParent(QPointF(0, delta.p1().y())), q->mapToParent(QPointF(0, delta.p2().y())));
608 
609  QRectF newGeometry;
610  switch (windowData->grabbedSection) {
611  case Qt::LeftSection:
612  newGeometry = QRectF(windowData->startGeometry.topLeft()
613  + QPointF(parentXDelta.dx(), parentXDelta.dy()),
614  windowData->startGeometry.size() - QSizeF(delta.dx(), delta.dy()));
615  break;
616  case Qt::TopLeftSection:
617  newGeometry = QRectF(windowData->startGeometry.topLeft()
618  + QPointF(parentDelta.dx(), parentDelta.dy()),
619  windowData->startGeometry.size() - QSizeF(delta.dx(), delta.dy()));
620  break;
621  case Qt::TopSection:
622  newGeometry = QRectF(windowData->startGeometry.topLeft()
623  + QPointF(parentYDelta.dx(), parentYDelta.dy()),
624  windowData->startGeometry.size() - QSizeF(0, delta.dy()));
625  break;
626  case Qt::TopRightSection:
627  newGeometry = QRectF(windowData->startGeometry.topLeft()
628  + QPointF(parentYDelta.dx(), parentYDelta.dy()),
629  windowData->startGeometry.size() - QSizeF(-delta.dx(), delta.dy()));
630  break;
631  case Qt::RightSection:
632  newGeometry = QRectF(windowData->startGeometry.topLeft(),
633  windowData->startGeometry.size() + QSizeF(delta.dx(), 0));
634  break;
636  newGeometry = QRectF(windowData->startGeometry.topLeft(),
637  windowData->startGeometry.size() + QSizeF(delta.dx(), delta.dy()));
638  break;
639  case Qt::BottomSection:
640  newGeometry = QRectF(windowData->startGeometry.topLeft(),
641  windowData->startGeometry.size() + QSizeF(0, delta.dy()));
642  break;
644  newGeometry = QRectF(windowData->startGeometry.topLeft()
645  + QPointF(parentXDelta.dx(), parentXDelta.dy()),
646  windowData->startGeometry.size() - QSizeF(delta.dx(), -delta.dy()));
647  break;
648  case Qt::TitleBarArea:
649  newGeometry = QRectF(windowData->startGeometry.topLeft()
650  + QPointF(parentDelta.dx(), parentDelta.dy()),
652  break;
653  case Qt::NoSection:
654  break;
655  }
656 
660  q->effectiveSizeHint(Qt::MinimumSize),
661  q->effectiveSizeHint(Qt::MaximumSize),
662  q);
663  q->setGeometry(newGeometry);
664  }
665 }
666 
668 {
670  if (!hasDecoration())
671  return;
672 
674 
675  if (q->rect().contains(event->pos())) {
678  return;
679  }
680 
681  bool wasMouseOver = windowData->buttonMouseOver;
682  QRect oldButtonRect = windowData->buttonRect;
684  windowData->buttonMouseOver = false;
685  QPointF pos = event->pos();
687  // make sure that the coordinates (rect and pos) we send to the style are positive.
688  if (windowFrameMargins) {
689  pos.rx() += windowFrameMargins[Left];
690  pos.ry() += windowFrameMargins[Top];
691  }
693  bar.rect = q->windowFrameRect().toRect();
694  bar.rect.moveTo(0,0);
695  bar.rect.setHeight(int(titleBarHeight(bar)));
696 
697  Qt::CursorShape cursorShape = Qt::ArrowCursor;
698  bool needsSetCursorCall = true;
699  switch (q->windowFrameSectionAt(event->pos())) {
700  case Qt::TopLeftSection:
702  cursorShape = Qt::SizeFDiagCursor;
703  break;
704  case Qt::TopRightSection:
706  cursorShape = Qt::SizeBDiagCursor;
707  break;
708  case Qt::LeftSection:
709  case Qt::RightSection:
710  cursorShape = Qt::SizeHorCursor;
711  break;
712  case Qt::TopSection:
713  case Qt::BottomSection:
714  cursorShape = Qt::SizeVerCursor;
715  break;
716  case Qt::TitleBarArea:
717  windowData->buttonRect = q->style()->subControlRect(
719 #ifdef Q_WS_MAC
720  // On mac we should hover if we are in the 'area' of the buttons
721  windowData->buttonRect |= q->style()->subControlRect(
723  windowData->buttonRect |= q->style()->subControlRect(
725 #endif
727  windowData->buttonMouseOver = true;
728  event->ignore();
729  break;
730  default:
731  needsSetCursorCall = false;
732  event->ignore();
733  }
734 #ifndef QT_NO_CURSOR
735  if (needsSetCursorCall)
736  q->setCursor(cursorShape);
737 #endif
738  // update buttons if we hover over them
739  windowData->hoveredSubControl = q->style()->hitTestComplexControl(QStyle::CC_TitleBar, &bar, pos.toPoint(), 0);
742 
743  if (windowData->buttonMouseOver != wasMouseOver) {
744  if (!oldButtonRect.isNull())
745  q->update(QRectF(oldButtonRect).translated(q->windowFrameRect().topLeft()));
746  if (!windowData->buttonRect.isNull())
747  q->update(QRectF(windowData->buttonRect).translated(q->windowFrameRect().topLeft()));
748  }
749 }
750 
752 {
753  Q_UNUSED(event);
755  if (hasDecoration()) {
756  // ### restore the cursor, don't override it
757 #ifndef QT_NO_CURSOR
758  q->unsetCursor();
759 #endif
760 
762 
763  bool needsUpdate = false;
766  needsUpdate = true;
767 
768  // update the hover state (of buttons etc...)
770  windowData->buttonMouseOver = false;
772  if (needsUpdate)
773  q->update(windowData->buttonRect);
774  }
775 }
776 
778 {
780 }
781 
786 {
788 
790 
791  QGraphicsWidget *n = q; //last one in 'new' list
792  QGraphicsWidget *o = 0; //last one in 'old' list
793 
795 
796  QGraphicsWidget *firstOld = 0;
797  bool wasPreviousNew = true;
798 
799  while (w != q) {
800  bool isCurrentNew = q->isAncestorOf(w);
801  if (isCurrentNew) {
802  if (!wasPreviousNew) {
803  n->d_func()->focusNext = w;
804  w->d_func()->focusPrev = n;
805  }
806  n = w;
807  } else /*if (!isCurrentNew)*/ {
808  if (wasPreviousNew) {
809  if (o) {
810  o->d_func()->focusNext = w;
811  w->d_func()->focusPrev = o;
812  } else {
813  firstOld = w;
814  }
815  }
816  o = w;
817  }
818  w = w->d_func()->focusNext;
819  wasPreviousNew = isCurrentNew;
820  }
821 
822  // repair the 'old' chain
823  if (firstOld) {
824  o->d_func()->focusNext = firstOld;
825  firstOld->d_func()->focusPrev = o;
826  }
827 
828  // update tabFocusFirst for oldScene if the item is going to be removed from oldScene
829  if (newParent)
830  newScene = newParent->scene();
831 
832  if (oldScene && newScene != oldScene)
833  oldScene->d_func()->tabFocusFirst = (firstOld && firstOld->scene() == oldScene) ? firstOld : 0;
834 
835  QGraphicsItem *topLevelItem = newParent ? newParent->topLevelItem() : 0;
836  QGraphicsWidget *topLevel = 0;
837  if (topLevelItem && topLevelItem->isWidget())
838  topLevel = static_cast<QGraphicsWidget *>(topLevelItem);
839 
840  if (topLevel && newParent) {
841  QGraphicsWidget *last = topLevel->d_func()->focusPrev;
842  // link last with new chain
843  last->d_func()->focusNext = q;
844  focusPrev = last;
845 
846  // link last in chain with
847  topLevel->d_func()->focusPrev = n;
848  n->d_func()->focusNext = topLevel;
849  } else {
850  // q is the start of the focus chain
851  n->d_func()->focusNext = q;
852  focusPrev = n;
853  }
854 
855 }
856 
858 {
859  delete (this->layout);
860  layout = l;
861  if (!l) {
863  q->updateGeometry();
864  }
865 }
866 
868 {
869  Q_Q(const QGraphicsWidget);
870  return q->geometry().width();
871 }
872 
874 {
875  if (qIsNaN(w))
876  return;
878  if (q->geometry().width() == w)
879  return;
880 
881  q->setGeometry(QRectF(q->x(), q->y(), w, height()));
882 }
883 
885 {
887  q->setGeometry(QRectF(q->x(), q->y(), 0, height()));
888 }
889 
891 {
892  Q_Q(const QGraphicsWidget);
893  return q->geometry().height();
894 }
895 
897 {
898  if (qIsNaN(h))
899  return;
901  if (q->geometry().height() == h)
902  return;
903 
904  q->setGeometry(QRectF(q->x(), q->y(), width(), h));
905 }
906 
908 {
910  q->setGeometry(QRectF(q->x(), q->y(), width(), 0));
911 }
912 
914 {
915  if (inSetGeometry)
916  return;
918  inSetPos = 1;
919  // Ensure setGeometry is called (avoid recursion when setPos is
920  // called from within setGeometry).
921  q->setGeometry(QRectF(pos, q->size()));
922  inSetPos = 0 ;
923 }
924 
926 
927 #include "moc_qgraphicswidget.cpp"
928 
929 #endif //QT_NO_GRAPHICSVIEW
QSizeF effectiveSizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const
Returns the effective size hint for this QGraphicsLayoutItem.
static Qt::LayoutDirection layoutDirection()
QPalette naturalWidgetPalette() const
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
void setFont_helper(const QFont &font)
void windowFrameHoverMoveEvent(QGraphicsSceneHoverEvent *event)
void setParentItemHelper(QGraphicsItem *parent, const QVariant *newParentVariant, const QVariant *thisPointerVariant)
Make sure not to trigger any pure virtual function calls (e.
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
static void _q_boundGeometryToSizeConstraints(const QRectF &startGeometry, QRectF *rect, Qt::WindowFrameSection section, const QSizeF &min, const QSizeF &max, const QGraphicsWidget *widget)
QGraphicsItem * parent
qreal right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:527
static QGraphicsLayoutItemPrivate * get(QGraphicsLayoutItem *q)
static qreal minimumHeightForWidth(qreal width, qreal minh, qreal maxh, const QGraphicsWidget *widget, bool heightForWidth=true)
Used to calculate the Precondition: widget should support either hfw or wfh.
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:231
void setHeight(int h)
Sets the height of the rectangle to the given height.
Definition: qrect.h:445
int type
Definition: qmetatype.cpp:239
double qreal
Definition: qglobal.h:1193
QGraphicsWidget * focusPrev
void setHeight(qreal h)
Sets the height of the rectangle to the given height.
Definition: qrect.h:787
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
QGraphicsWidget * parentWidget() const
Returns a pointer to the item&#39;s parent widget.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
EventRef event
bool isWindow() const
Returns true if the item is a QGraphicsWidget window, otherwise returns false.
QPointer< QWidget > widget
Qt::WindowFrameSection grabbedSection
Qt::WindowFlags windowFlags
QScopedPointer< QGraphicsItemPrivate > d_ptr
struct QGraphicsWidgetPrivate::WindowData * windowData
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
qreal width() const
Returns the width.
Definition: qsize.h:284
Qt::FocusPolicy focusPolicy
qreal titleBarHeight(const QStyleOptionTitleBar &options) const
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
qreal height() const
Returns the height.
Definition: qsize.h:287
The QGraphicsSceneMouseEvent class provides mouse events in the graphics view framework.
qreal left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:525
void resolveFont(uint inheritedMask)
void adjustWindowFlags(Qt::WindowFlags *wFlags)
The QStyleOptionTitleBar class is used to describe the parameters for drawing a title bar...
Definition: qstyleoption.h:816
static Qt::MouseButtons buttons
QPalette palette
the scene&#39;s default palette
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
QGraphicsWidget * focusNext
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
void ensureWindowFrameMargins() const
Ensures that windowFrameMargins is allocated.
void setTop(qreal pos)
Sets the top edge of the rectangle to the given y coordinate.
Definition: qrect.h:674
QString text
the text of the title bar
Definition: qstyleoption.h:822
QWidget * widget() const
Returns the widget where the event originated, or 0 if the event originates from another application...
void windowFrameMousePressEvent(QGraphicsSceneMouseEvent *event)
void moveTo(int x, int t)
Moves the rectangle, leaving the top-left corner at the given position (x, y).
Definition: qrect.h:334
QStyle::SubControls activeSubControls
This variable holds a bitwise OR of the sub-controls that are active for the complex control...
Definition: qstyleoption.h:694
QGraphicsLayout * layout
void updateFont(const QFont &font)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
QString elidedText(const QString &text, Qt::TextElideMode mode, int width, int flags=0) const
If the string text is wider than width, returns an elided version of the string (i.
#define Q_Q(Class)
Definition: qglobal.h:2483
static QFont font()
Returns the default application font.
void resolvePalette(uint inheritedMask)
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
void updatePalette(const QPalette &palette)
QPointF buttonDownScenePos(Qt::MouseButton button) const
Returns the mouse cursor position in scene coordinates where the specified button was clicked...
QFont resolve(const QFont &) const
Returns a new QFont that has attributes copied from other that have not been previously set on this f...
Definition: qfont.cpp:1983
void windowFrameHoverLeaveEvent(QGraphicsSceneHoverEvent *event)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
qreal & rx()
Returns a reference to the x coordinate of this point.
Definition: qpoint.h:302
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
void setLayout_helper(QGraphicsLayout *l)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void fixFocusChainBeforeReparenting(QGraphicsWidget *newParent, QGraphicsScene *oldScene, QGraphicsScene *newScene=0)
LayoutDirection
Definition: qnamespace.h:1580
unsigned int uint
Definition: qglobal.h:996
void initStyleOptionTitleBar(QStyleOptionTitleBar *option)
void ensureMargins() const
Ensures that margins is allocated.
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
void setLayoutDirection_helper(Qt::LayoutDirection direction)
void setRect(qreal x, qreal y, qreal w, qreal h)
Sets the coordinates of the rectangle&#39;s top-left corner to (x, y), and its size to the given width an...
Definition: qrect.h:754
QGraphicsItem * topLevelItem() const
Returns this item&#39;s top-level item.
virtual void resolvePalette(uint inheritedMask)
Q_CORE_EXPORT bool qIsNaN(double d)
Returns true if the double {d} is not a number (NaN).
Definition: qnumeric.cpp:55
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
static QWidget * parentWidget(const QWidget *w)
bool isAncestorOf(const QGraphicsItem *child) const
Returns true if this item is an ancestor of child (i.e., if this item is child&#39;s parent, or one of child&#39;s parent&#39;s ancestors).
bool testAttribute(Qt::WidgetAttribute attribute) const
Returns true if attribute is enabled for this widget; otherwise, returns false.
Qt::LayoutDirection layoutDirection
the layout direction for this widget
Definition: qwidget.h:216
static qreal minimumWidthForHeight(qreal height, qreal minw, qreal maxw, const QGraphicsWidget *widget)
static QSizeF closestAcceptableSize(const QSizeF &proposed, const QGraphicsWidget *widget)
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
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
CursorShape
Definition: qnamespace.h:1262
void windowFrameMouseReleaseEvent(QGraphicsSceneMouseEvent *event)
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219
void windowFrameMouseMoveEvent(QGraphicsSceneMouseEvent *event)
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
The QGraphicsLayout class provides the base class for all layouts in Graphics View.
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
bool isWidget() const
Returns true if this item is a widget (i.
QFactoryLoader * l
virtual void resolveFont(uint inheritedMask)
QSizeF size() const
Returns the size of the rectangle.
Definition: qrect.h:713
qreal & ry()
Returns a reference to the y coordinate of this point.
Definition: qpoint.h:307
QPointF pos() const
Returns the mouse cursor position in item coordinates.
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
bool testAttribute(Qt::WidgetAttribute att) const
void setWidth(qreal w)
Sets the width of the rectangle to the given width.
Definition: qrect.h:784
void ensureWindowData()
Ensures that windowData is allocated.
QGraphicsScene * scene() const
Returns the current scene for the item, or 0 if the item is not stored in a scene.
Qt::WindowFlags titleBarFlags
the widget flags for the title bar
Definition: qstyleoption.h:825
qreal bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:528
void setPalette_helper(const QPalette &palette)
QFont font
the scene&#39;s default font
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
WindowFrameSection
Definition: qnamespace.h:1716
int titleBarState
the state of the title bar
Definition: qstyleoption.h:824
QSizeF size
the size of the widget
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
#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 rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
QStyle::SubControls subControls
This variable holds a bitwise OR of the sub-controls to be drawn for the complex control.
Definition: qstyleoption.h:693
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
Qt::MouseButtons buttons() const
Returns the combination of mouse buttons that were pressed at the time the event was sent...
void init(QGraphicsItem *parentItem, Qt::WindowFlags wFlags)
The QGraphicsSceneHoverEvent class provides hover events in the graphics view framework.
QPalette resolve(const QPalette &) const
Returns a new QPalette that has attributes copied from other.
Definition: qpalette.cpp:1101
Qt::LayoutDirection direction
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:61