Qt 4.8
Functions
qgraphicswidget_p.cpp File Reference
#include "qglobal.h"
#include <QtCore/qdebug.h>
#include <QtCore/qnumeric.h>
#include "qgraphicswidget_p.h"
#include "qgraphicslayoutitem_p.h"
#include "qgraphicslayout.h"
#include "qgraphicsscene_p.h"
#include <QtGui/qapplication.h>
#include <QtGui/qgraphicsscene.h>
#include <QtGui/qstyleoption.h>
#include <QtGui/QStyleOptionTitleBar>
#include <QtGui/QGraphicsSceneMouseEvent>
#include <QMacStyle>
#include "moc_qgraphicswidget.cpp"

Go to the source code of this file.

Functions

static void _q_boundGeometryToSizeConstraints (const QRectF &startGeometry, QRectF *rect, Qt::WindowFrameSection section, const QSizeF &min, const QSizeF &max, const QGraphicsWidget *widget)
 
static QSizeF closestAcceptableSize (const QSizeF &proposed, const QGraphicsWidget *widget)
 
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. More...
 
static qreal minimumWidthForHeight (qreal height, qreal minw, qreal maxw, const QGraphicsWidget *widget)
 

Function Documentation

◆ _q_boundGeometryToSizeConstraints()

static void _q_boundGeometryToSizeConstraints ( const QRectF startGeometry,
QRectF rect,
Qt::WindowFrameSection  section,
const QSizeF min,
const QSizeF max,
const QGraphicsWidget widget 
)
static

Definition at line 520 of file qgraphicswidget_p.cpp.

Referenced by QGraphicsWidgetPrivate::windowFrameMouseMoveEvent().

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 }
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.
double qreal
Definition: qglobal.h:1193
void setHeight(qreal h)
Sets the height of the rectangle to the given height.
Definition: qrect.h:787
qreal width() const
Returns the width.
Definition: qsize.h:284
qreal height() const
Returns the height.
Definition: qsize.h:287
qreal left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:525
void setTop(qreal pos)
Sets the top edge of the rectangle to the given y coordinate.
Definition: qrect.h:674
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
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
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
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
static QSizeF closestAcceptableSize(const QSizeF &proposed, const QGraphicsWidget *widget)
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
void setWidth(qreal w)
Sets the width of the rectangle to the given width.
Definition: qrect.h:784
qreal bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:528
QSizeF size
the size of the widget
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ closestAcceptableSize()

static QSizeF closestAcceptableSize ( const QSizeF proposed,
const QGraphicsWidget widget 
)
static

Definition at line 473 of file qgraphicswidget_p.cpp.

Referenced by _q_boundGeometryToSizeConstraints().

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 }
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.
double qreal
Definition: qglobal.h:1193
QPointer< QWidget > widget
qreal width() const
Returns the width.
Definition: qsize.h:284
qreal height() const
Returns the height.
Definition: qsize.h:287
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
static qreal minimumWidthForHeight(qreal height, qreal minw, qreal maxw, const QGraphicsWidget *widget)
QSizeF size
the size of the widget

◆ minimumHeightForWidth()

static qreal minimumHeightForWidth ( qreal  width,
qreal  minh,
qreal  maxh,
const QGraphicsWidget widget,
bool  heightForWidth = true 
)
static

Used to calculate the Precondition: widget should support either hfw or wfh.

If heightForWidth is set to false, this function will query the width for height instead. width will then be interpreted as height, minh and maxh will be interpreted as minimum width and maximum width.

Definition at line 435 of file qgraphicswidget_p.cpp.

Referenced by _q_boundGeometryToSizeConstraints(), QLayout::activate(), closestAcceptableSize(), QGridLayoutPrivate::isDirty(), and minimumWidthForHeight().

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 }
QSizeF effectiveSizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const
Returns the effective size hint for this QGraphicsLayoutItem.
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.
double qreal
Definition: qglobal.h:1193
qreal width() const
Returns the width.
Definition: qsize.h:284
qreal height() const
Returns the height.
Definition: qsize.h:287
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202

◆ minimumWidthForHeight()

static qreal minimumWidthForHeight ( qreal  height,
qreal  minw,
qreal  maxw,
const QGraphicsWidget widget 
)
static

Definition at line 467 of file qgraphicswidget_p.cpp.

Referenced by closestAcceptableSize().

469 {
470  return minimumHeightForWidth(height, minw, maxw, widget, false);
471 }
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.