[Development] AplicationWindow, QQuickWindow, contentRotation and setting width and height of contentItem

Alan Alpert 416365416c at gmail.com
Fri Aug 2 01:48:19 CEST 2013


On Thu, Aug 1, 2013 at 2:53 PM, Tomasz Olszak <olszak.tomasz at gmail.com> wrote:
> Hi,
>
> I would like to make POC of automatic rotation of ApplicationWindow's
> contentItem.
> It can be simple solution for devices which have accelerometer only and
> don't have system screen rotation.
>
> Following mockup works:
>
> /*ApplicationWindow.qml*/
>
> Window {
>
>     id: root
>
>
>
>     /* In the end some kind of boolean property will turn on/off following
> bindings or use transform property - don't decided yet*/
>
>     property bool contentItemFollowsContentOrientation: false
>
>
>
>     property bool __isPortrait: contentOrientation ===
> Qt.PortraitOrientation || contentOrientation ===
> Qt.InvertedPortraitOrientation
>
>     contentItem.x: __isPortrait ? 0 : root.width/2 - root.height/2
>
>     contentItem.y: __isPortrait ? 0 : root.height/2 - root.width/2
>
>     contentItem.width: __isPortrait ? root.width : root.height
>
>     contentItem.height: __isPortrait ? root.height : root.width
>
>     contentItem.rotation: (contentOrientation == Qt.LandscapeOrientation) ?
> 90 :
>
>                           (contentOrientation ==
> Qt.InvertedPortraitOrientation) ? 180 :
>
>                           (contentOrientation ==
> Qt.InvertedLandscapeOrientation) ? -90 : 0
>
>     Rectangle {
>
>         id: thisItemIsProperlyRotated
>
>         anchors.fill:parent
>
>     }
>
> }
>
>
> but only for square windows :) because following code have significant
> impact on behavior of contentItem.with and contentItem.height bindings:
>
>
> void QQuickWindowPrivate::initContentItem()
>
> {
>
>     Q_Q(QQuickWindow);
>
>     q->connect(q, SIGNAL(widthChanged(int)),
>
>             contentItem, SLOT(setWidth(int)));
>
>     q->connect(q, SIGNAL(heightChanged(int)),
>
>             contentItem, SLOT(setHeight(int)));
>
>     contentItem->setWidth(q->width());
>
>     contentItem->setHeight(q->height());
>
> }
>
>
> Shouldn't bindings be created instead of connections or maybe it was done on
> purpose?

Like Flickable, you aren't supposed to control the contentItem of
Window. It's only exposed because it unfortunately cannot be fully
hidden as an implementation detail (at least not without breaking
certain edge cases). So it's deliberate that you aren't able to
override this like a binding.

> Do you see any risks of adding such feature?

That people might start trying to control the contentItem when they
shouldn't ;) .

What's the problem with creating your own item instead of trying to
reuse the contentItem? Something like:
/* ApplicationWindow.qml */
Window {
    default property alias myData: myContentItem.data
    Item {
        id: myContentItem
        //All rotation logic goes here
    }
}

--
Alan Alpert



More information about the Development mailing list