Qt 4.8
|
#include <qgraphicslayoutitem_p.h>
Public Types | |
enum | SizeComponent { Width, Height } |
Public Functions | |
QSizeF * | effectiveSizeHints (const QSizeF &constraint) const |
void | ensureUserSizeHints () |
Ensures that userSizeHints is allocated. More... | |
bool | hasHeightForWidth () const |
bool | hasWidthForHeight () const |
void | init () |
QGraphicsItem * | parentItem () const |
Returns the parent item of this layout, or 0 if this layout is not installed on any widget. More... | |
QGraphicsLayoutItemPrivate (QGraphicsLayoutItem *parent, bool isLayout) | |
void | setSize (Qt::SizeHint which, const QSizeF &size) |
Sets the user size hint which to size. More... | |
void | setSizeComponent (Qt::SizeHint which, SizeComponent component, qreal value) |
Sets the width of the user size hint which to width. More... | |
virtual | ~QGraphicsLayoutItemPrivate () |
Static Public Functions | |
static QGraphicsLayoutItemPrivate * | get (QGraphicsLayoutItem *q) |
static const QGraphicsLayoutItemPrivate * | get (const QGraphicsLayoutItem *q) |
Definition at line 62 of file qgraphicslayoutitem_p.h.
|
virtual |
Definition at line 119 of file qgraphicslayoutitem.cpp.
QGraphicsLayoutItemPrivate::QGraphicsLayoutItemPrivate | ( | QGraphicsLayoutItem * | par, |
bool | layout | ||
) |
Definition at line 111 of file qgraphicslayoutitem.cpp.
effectiveSizeHint has a quirky behavior, one of the quirkinesses is when the hfw function is combined with user-specified min/max sizes. The input to hfw function (e.g width) must be within the min/max width constraint, and the output must be within the min/max height. This sets up a loose dependency between minimum width and maximum height (or minimum height, depending on the type of hfw function). Note that its only the concrete subclass that implements that hfw function that knows if this dependency means that the height will increase or decrease when the width is increased.
The application should try to ensure that the user-defined sizes are within the range so that they don't conflict with the hfw function.
Suppose, for instance that the hfw function is:
height = 2000/width
and the item has these user-defined sizes:
min ( 5, 5) pref(100, 10) max (500,100)
what is the return value if one calls item->effectiveSizeHint(Qt::MinimumSize, QSizeF(10, -1)); ? The sizeHint() function would return QSizeF(10, 200), but it would be bounded down to 100 due to the max value, so it would return (10, 100). This is not what the item expects, since it really wants that its hfw is respected. If this is a label with wrapped text, this would most likely lead to that some text is clipped. This is certainly not what the app developer wants. Now, it would be better if the user changed those constraints to match the hfw function:
min ( 20, 5) pref(100, 10) max (500,100)
here, it says that the width cannot be smaller than 20. This is because if it becomes smaller than 20 the result of the hfw function would violate the max height (100).
However, there is a similar problem if the width passed to the hfw function reaches max width:
the sizeHint() function would now return QSizeF(500, 4), but 4 is smaller than the minimum height (5), so effectiveSizeHint() would return (500, 5), which would leave too much space. In this case, setting the max width to 400 fixes the problem:
min ( 20, 5) pref(100, 10) max (400,100)
The implementor of a hfw widget must be aware of this when sizeHint() is reimplemented, so that the default min and max sizes works sensible. (unfortunately the implementor does not have the control over user-set values).
Definition at line 188 of file qgraphicslayoutitem.cpp.
Referenced by QGraphicsLayoutItem::effectiveSizeHint().
void QGraphicsLayoutItemPrivate::ensureUserSizeHints | ( | ) |
Ensures that userSizeHints is allocated.
This function must be called before any dereferencing.
Definition at line 302 of file qgraphicslayoutitem.cpp.
Referenced by setSize(), and setSizeComponent().
|
inlinestatic |
Definition at line 68 of file qgraphicslayoutitem_p.h.
Referenced by _q_boundGeometryToSizeConstraints(), QGridLayoutItem::dynamicConstraintOrientation(), QGridLayoutItem::hasDynamicConstraint(), hasHeightForWidth(), hasWidthForHeight(), and minimumHeightForWidth().
|
inlinestatic |
Definition at line 69 of file qgraphicslayoutitem_p.h.
bool QGraphicsLayoutItemPrivate::hasHeightForWidth | ( | ) | const |
Definition at line 355 of file qgraphicslayoutitem.cpp.
Referenced by _q_boundGeometryToSizeConstraints(), QGridLayoutItem::hasDynamicConstraint(), and minimumHeightForWidth().
bool QGraphicsLayoutItemPrivate::hasWidthForHeight | ( | ) | const |
Definition at line 375 of file qgraphicslayoutitem.cpp.
Referenced by _q_boundGeometryToSizeConstraints(), and QGridLayoutItem::hasDynamicConstraint().
void QGraphicsLayoutItemPrivate::init | ( | ) |
Definition at line 128 of file qgraphicslayoutitem.cpp.
QGraphicsItem * QGraphicsLayoutItemPrivate::parentItem | ( | ) | const |
Returns the parent item of this layout, or 0 if this layout is not installed on any widget.
If this is the item that the layout is installed on, it will return "itself".
If the layout is a sub-layout, this function returns the parent widget of the parent layout.
Note that it will traverse up the layout item hierarchy instead of just calling QGraphicsItem::parentItem(). This is on purpose.
Definition at line 282 of file qgraphicslayoutitem.cpp.
Referenced by QGraphicsLayoutPrivate::addChildLayoutItem(), QGraphicsLayoutPrivate::getMargin(), QGraphicsGridLayoutPrivate::styleInfo(), QGraphicsLinearLayoutPrivate::styleInfo(), QGraphicsAnchorLayoutPrivate::styleInfo(), and QGraphicsLayoutPrivate::visualDirection().
void QGraphicsLayoutItemPrivate::setSize | ( | Qt::SizeHint | which, |
const QSizeF & | size | ||
) |
Sets the user size hint which to size.
Use an invalid size to unset the size hint.
Definition at line 316 of file qgraphicslayoutitem.cpp.
Referenced by QGraphicsLayoutItem::setMaximumSize(), QGraphicsLayoutItem::setMinimumSize(), and QGraphicsLayoutItem::setPreferredSize().
void QGraphicsLayoutItemPrivate::setSizeComponent | ( | Qt::SizeHint | which, |
SizeComponent | component, | ||
qreal | value | ||
) |
Sets the width of the user size hint which to width.
Definition at line 340 of file qgraphicslayoutitem.cpp.
Referenced by QGraphicsLayoutItem::setMaximumHeight(), QGraphicsLayoutItem::setMaximumWidth(), QGraphicsLayoutItem::setMinimumHeight(), QGraphicsLayoutItem::setMinimumWidth(), QGraphicsLayoutItem::setPreferredHeight(), and QGraphicsLayoutItem::setPreferredWidth().
|
mutable |
Definition at line 87 of file qgraphicslayoutitem_p.h.
Referenced by effectiveSizeHints().
|
mutable |
Definition at line 86 of file qgraphicslayoutitem_p.h.
Referenced by effectiveSizeHints().
|
mutable |
Definition at line 88 of file qgraphicslayoutitem_p.h.
Referenced by effectiveSizeHints().
QRectF QGraphicsLayoutItemPrivate::geom |
Definition at line 96 of file qgraphicslayoutitem_p.h.
Referenced by QGraphicsWidget::setGeometry().
QGraphicsItem* QGraphicsLayoutItemPrivate::graphicsItem |
Definition at line 97 of file qgraphicslayoutitem_p.h.
quint32 QGraphicsLayoutItemPrivate::isLayout |
Definition at line 92 of file qgraphicslayoutitem_p.h.
Referenced by hasHeightForWidth(), and hasWidthForHeight().
quint32 QGraphicsLayoutItemPrivate::ownedByLayout |
Definition at line 93 of file qgraphicslayoutitem_p.h.
QGraphicsLayoutItem* QGraphicsLayoutItemPrivate::parent |
Definition at line 83 of file qgraphicslayoutitem_p.h.
Referenced by QGraphicsLayoutPrivate::getMargin(), parentItem(), and QGraphicsAnchorLayoutPrivate::styleInfo().
QGraphicsLayoutItem* QGraphicsLayoutItemPrivate::q_ptr |
Definition at line 95 of file qgraphicslayoutitem_p.h.
|
mutable |
Definition at line 90 of file qgraphicslayoutitem_p.h.
Referenced by effectiveSizeHints(), and init().
|
mutable |
Definition at line 91 of file qgraphicslayoutitem_p.h.
Referenced by effectiveSizeHints(), and init().
QSizePolicy QGraphicsLayoutItemPrivate::sizePolicy |
Definition at line 82 of file qgraphicslayoutitem_p.h.
QSizeF* QGraphicsLayoutItemPrivate::userSizeHints |
Definition at line 85 of file qgraphicslayoutitem_p.h.
Referenced by effectiveSizeHints(), ensureUserSizeHints(), setSize(), setSizeComponent(), and ~QGraphicsLayoutItemPrivate().