Source

Target

Showing with 96 additions and 100 deletions
......@@ -125,7 +125,7 @@
\li \l {Qt Quick Controls Styles}
\endlist
\section2 Styles
\section2 Layouts
\list
\li \l {Qt Quick Layouts}
\endlist
......
......@@ -112,8 +112,16 @@ public:
void setGeometry(const QRectF &rect)
{
const QRect r(rect.toRect());
const QSize newSize(r.size());
m_item->setPosition(r.topLeft());
m_item->setSize(r.size());
QSizeF oldSize(m_item->width(), m_item->height());
if (newSize == oldSize) {
if (QQuickLayout *lay = qobject_cast<QQuickLayout *>(m_item))
if (lay->arrangementIsDirty())
lay->rearrange(newSize);
} else {
m_item->setSize(newSize);
}
}
QQuickItem *layoutItem() const { return m_item; }
......
......@@ -77,9 +77,10 @@ public:
void componentComplete();
virtual QSizeF sizeHint(Qt::SizeHint whichSizeHint) const = 0;
virtual void invalidate(QQuickItem * childItem = 0);
virtual void rearrange(const QSizeF &);
bool arrangementIsDirty() const { return m_dirty; }
protected:
bool event(QEvent *e);
virtual void rearrange(const QSizeF &);
enum Orientation {
Vertical = 0,
......
......@@ -69,10 +69,16 @@ Control {
/*!
\qmlproperty bool AbstractCheckable::pressed
This property is \c true if the control is pressed.
This property is \c true if the control is being pressed.
Set this property to manually invoke a mouse click.
*/
readonly property alias pressed: mouseArea.effectivePressed
property alias pressed: mouseArea.effectivePressed
/*! \qmlproperty bool AbstractCheckcable::hovered
This property indicates whether the control is being hovered.
*/
readonly property alias hovered: mouseArea.containsMouse
/*!
This property is \c true if the control is checked.
......@@ -99,13 +105,6 @@ Control {
/*! \internal */
property var __cycleStatesHandler: cycleRadioButtonStates
/*! \internal
This property is \c true if the control currently contains the
mouse cursor.
*/
readonly property alias __containsMouse: mouseArea.containsMouse
activeFocusOnTab: true
MouseArea {
......
......@@ -59,8 +59,14 @@ Control {
/*! \qmlproperty bool BasicButton::pressed
This property holds whether the button is pressed. */
readonly property bool pressed: behavior.effectivePressed
This property holds whether the button is being pressed. */
readonly property alias pressed: behavior.effectivePressed
/*! \qmlproperty bool BasicButton::hovered
This property indicates whether the control is being hovered.
*/
readonly property alias hovered: behavior.containsMouse
/*! This property holds whether the button is checkable.
......@@ -123,8 +129,6 @@ Control {
/*! \internal */
property string __position: "only"
/*! \internal */
property alias __containsMouse: behavior.containsMouse
/*! \internal */
readonly property bool __iconOverriden: button.action && (button.action.iconSource !== button.iconSource || button.action.iconName !== button.iconName)
/*! \internal */
property Action __action: action || ownAction
......
......@@ -93,13 +93,7 @@ Style {
bottom: 4
}
/*! This defines the background of the button. In addition to the public
properties of \c control, the following state properties are available:
\table
\row \li readonly property bool \b styleData.hovered \li The control is being hovered.
\endtable
*/
/*! This defines the background of the button. */
property Component background: Item {
implicitWidth: 100
implicitHeight: 25
......@@ -136,13 +130,7 @@ Style {
}
}
/*! This defines the label of the button. In addition to the public
properties of \c control, the following state properties are available:
\table
\row \li readonly property bool \b styleData.hovered \li The control is being hovered.
\endtable
*/
/*! This defines the label of the button. */
property Component label: Text {
renderType: Text.NativeRendering
verticalAlignment: Text.AlignVCenter
......@@ -162,9 +150,6 @@ Style {
id: backgroundLoader
anchors.fill: parent
sourceComponent: background
property QtObject styleData: QtObject {
readonly property bool hovered: control.__containsMouse
}
}
Loader {
......@@ -175,9 +160,6 @@ Style {
anchors.topMargin: padding.top
anchors.rightMargin: padding.right
anchors.bottomMargin: padding.bottom
property QtObject styleData: QtObject {
readonly property bool hovered: control.__containsMouse
}
}
}
}
......@@ -83,13 +83,7 @@ Style {
SystemPalette.Active : SystemPalette.Disabled
}
/*! This defines the text label. In addition to the public
properties of \c control, the following state properties are available:
\table
\row \li readonly property bool \b styleData.hovered \li The control is being hovered.
\endtable
*/
/*! This defines the text label. */
property Component label: Text {
text: control.text
color: __syspal.text
......@@ -108,13 +102,7 @@ Style {
/*! The spacing between indicator and label. */
property int spacing: 4
/*! This defines the indicator button. In addition to the public
properties of \c control, the following state properties are available:
\table
\row \li readonly property bool \b styleData.hovered \li The control is being hovered.
\endtable
*/
/*! This defines the indicator button. */
property Component indicator: Item {
implicitWidth: 18
implicitHeight: 18
......@@ -175,14 +163,12 @@ Style {
id: indicatorLoader
sourceComponent: indicator
anchors.verticalCenter: parent.verticalCenter
property QtObject styleData: QtObject { readonly property bool hovered: control.__containsMouse }
}
Loader {
id: labelLoader
sourceComponent: label
anchors.top: parent.top
anchors.bottom: parent.bottom
property QtObject styleData: QtObject { readonly property bool hovered: control.__containsMouse }
}
}
}
......
......@@ -63,13 +63,7 @@ Style {
/*! The padding between the background and the label components. */
padding { top: 4 ; left: 6 ; right: 6 ; bottom:4 }
/*! This defines the background of the button. In addition to the public
properties of \c control, the following state properties are available:
\table
\row \li readonly property bool \b styleData.hovered \li The control is being hovered.
\endtable
*/
/*! This defines the background of the button. */
property Component background: Item {
implicitWidth: 100
implicitHeight: 25
......@@ -105,13 +99,7 @@ Style {
}
}
/*! This defines the label of the button. In addition to the public
properties of \c control, the following state properties are available:
\table
\row \li readonly property bool \b styleData.hovered \li The control is being hovered.
\endtable
*/
/*! This defines the label of the button. */
property Component label: Item {
implicitWidth: textitem.implicitWidth + 20
Text {
......@@ -137,9 +125,6 @@ Style {
id: backgroundLoader
anchors.fill: parent
sourceComponent: background
property QtObject styleData: QtObject {
readonly property bool hovered: control.__containsMouse
}
}
Loader {
......@@ -150,9 +135,6 @@ Style {
anchors.topMargin: padding.top
anchors.rightMargin: padding.right
anchors.bottomMargin: padding.bottom
property QtObject styleData: QtObject {
readonly property bool hovered: control.__containsMouse
}
}
}
......
......@@ -83,13 +83,7 @@ Style {
/*! The \l RadioButton attached to this style. */
readonly property RadioButton control: __control
/*! This defines the text label. In addition to the public
properties of \c control, the following state properties are available:
\table
\row \li readonly property bool \b styleData.hovered \li The control is being hovered.
\endtable
*/
/*! This defines the text label. */
property Component label: Text {
text: control.text
renderType: Text.NativeRendering
......@@ -103,13 +97,7 @@ Style {
/*! The spacing between indicator and label. */
property int spacing: 4
/*! This defines the indicator button. In addition to the public
properties of \c control, the following state properties are available:
\table
\row \li readonly property bool \b styleData.hovered \li The control is being hovered.
\endtable
*/
/*! This defines the indicator button. */
property Component indicator: Rectangle {
width: 17
height: 17
......@@ -145,14 +133,12 @@ Style {
id: indicatorLoader
sourceComponent: indicator
anchors.verticalCenter: parent.verticalCenter
property QtObject styleData: QtObject { readonly property bool hovered: control.__containsMouse }
}
Loader {
id: labelLoader
sourceComponent: label
anchors.top: parent.top
anchors.bottom: parent.bottom
property QtObject styleData: QtObject { readonly property bool hovered: control.__containsMouse }
}
}
}
......
......@@ -122,7 +122,8 @@ Style {
}
/*! This property holds the background groove of the slider.
You can access the handle position through the \c handlePosition property.
You can access the handle position through the \c styleData.handlePosition property.
*/
property Component groove: Item {
anchors.verticalCenter: parent.verticalCenter
......@@ -164,7 +165,9 @@ Style {
Loader {
id: grooveLoader
property int handlePosition: handleLoader.x + handleLoader.width/2
property QtObject styleData: QtObject {
readonly property int handlePosition: handleLoader.x + handleLoader.width/2
}
x: padding.left
sourceComponent: groove
width: (horizontal ? parent.width : parent.height) - padding.left - padding.right
......
......@@ -46,7 +46,7 @@ Style {
elementType: "button"
sunken: control.pressed || (control.checkable && control.checked)
raised: !(control.pressed || (control.checkable && control.checked))
hover: control.__containsMouse
hover: control.hovered
text: control.iconSource === "" ? "" : control.text
hasFocus: control.activeFocus
hints: control.styleHints
......
......@@ -52,7 +52,7 @@ Style {
elementType: "checkbox"
sunken: control.pressed
on: control.checked || control.pressed
hover: control.__containsMouse
hover: control.hovered
enabled: control.enabled
hasFocus: control.activeFocus && styleitem.style == "mac"
hints: control.styleHints
......
......@@ -58,7 +58,7 @@ Style {
elementType: "combobox"
sunken: control.pressed
raised: !sunken
hover: control.__containsMouse
hover: control.hovered
enabled: control.enabled
// The style makes sure the text rendering won't overlap the decoration.
// In that case, 35 pixels margin in this case looks good enough. Worst
......
......@@ -56,7 +56,7 @@ Style {
anchors.verticalCenterOffset: macStyle ? -1 : 0
sunken: control.pressed
on: control.checked || control.pressed
hover: control.__containsMouse
hover: control.hovered
enabled: control.enabled
hasFocus: control.activeFocus && styleitem.style == "mac"
hints: control.styleHints
......
......@@ -116,7 +116,7 @@ Style {
elementType: "spinbox"
anchors.fill: parent
sunken: (styleData.downEnabled && styleData.downPressed) || (styleData.upEnabled && styleData.upPressed)
hover: styleData.hovered
hover: control.hovered
hints: control.styleHints
hasFocus: control.activeFocus
enabled: control.enabled
......
......@@ -48,7 +48,7 @@ Style {
sunken: true
hasFocus: control.activeFocus
hover: __containsMouse
hover: hovered
hints: control.styleHints
SystemPalette {
......
......@@ -48,8 +48,8 @@ Style {
elementType: "toolbutton"
on: control.checkable && control.checked
sunken: control.pressed
raised: !(control.checkable && control.checked) && control.__containsMouse
hover: control.__containsMouse
raised: !(control.checkable && control.checked) && control.hovered
hover: control.hovered
hasFocus: control.activeFocus
hints: control.styleHints
text: control.text
......
......@@ -658,5 +658,50 @@ Item {
layout.visible = false
layout.destroy() // Do not crash
}
Component {
id: rearrangeNestedLayouts_Component
RowLayout {
id: layout
anchors.fill: parent
width: 200
height: 20
RowLayout {
id: row
spacing: 0
Rectangle {
id: fixed
color: 'red'
implicitWidth: 20
implicitHeight: 20
}
Rectangle {
id: filler
color: 'grey'
Layout.fillWidth: true
implicitHeight: 20
}
}
}
}
function test_rearrangeNestedLayouts()
{
var layout = rearrangeNestedLayouts_Component.createObject(container)
var fixed = layout.children[0].children[0]
var filler = layout.children[0].children[1]
compare(itemRect(fixed), [0,0,20,20])
compare(itemRect(filler), [20,0,180,20])
fixed.implicitWidth = 100
wait(20); // wait for at least 20 ms (this matches the time between two frame
// repaints for 50hz displays)
compare(itemRect(fixed), [0,0,100,20])
compare(itemRect(filler), [100,0,100,20])
}
}
}
......@@ -178,7 +178,7 @@ Item {
setCoordinates(spinbox)
mouseMove(spinbox, mainCoord.x, mainCoord.y)
compare(spinbox.__styleData.hovered, true)
compare(spinbox.hovered, true)
compare(spinbox.__styleData.upHovered, false)
compare(spinbox.__styleData.downHovered, false)
......@@ -191,7 +191,7 @@ Item {
compare(spinbox.__styleData.downHovered, true)
mouseMove(spinbox, mainCoord.x - 2, mainCoord.y - 2)
compare(spinbox.__styleData.hovered, false)
compare(spinbox.hovered, false)
compare(spinbox.__styleData.upHovered, false)
compare(spinbox.__styleData.downHovered, false)
spinbox.destroy()
......