1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qquickscreen_p.h"
44 #include "qquickitem.h"
45 #include "qquickitem_p.h"
46 #include "qquickcanvas.h"
53 \qmlclass Screen QQuickScreenAttached
54 \inqmlmodule QtQuick.Window 2
55 \brief The Screen attached object provides information about the Screen an Item is displayed on.
57 The Screen attached object is only valid inside Item or Item derived elements. Inside these elements
58 it refers to the screen that the element is currently being displayed on.
62 \qmlattachedproperty int QtQuickWindow2::Screen::width
65 This contains the width of the screen in pixels.
68 \qmlattachedproperty int QtQuickWindow2::Screen::height
71 This contains the height of the screen in pixels.
74 \qmlattachedproperty Qt::ScreenOrientation QtQuickWindow2::Screen::primaryOrientation
77 This contains the primary orientation of the screen.
80 \qmlattachedproperty Qt::ScreenOrientation QtQuickWindow2::Screen::orientation
83 This contains the current orientation of the screen.
86 \qmlattachedmethod int QtQuickWindow2::Screen::angleBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b)
88 Returns the rotation angle, in degrees, between the two specified angles.
91 QQuickScreenAttached::QQuickScreenAttached(QObject* attachee)
95 m_attachee = qobject_cast<QQuickItem*>(attachee);
98 QQuickItemPrivate::get(m_attachee)->extra.value().screenAttached = this;
100 if (m_attachee->canvas()) //It might not be assigned to a canvas yet
101 canvasChanged(m_attachee->canvas());
105 int QQuickScreenAttached::width() const
109 return m_screen->size().width();
112 int QQuickScreenAttached::height() const
116 return m_screen->size().height();
119 Qt::ScreenOrientation QQuickScreenAttached::primaryOrientation() const
122 return Qt::PrimaryOrientation;
123 return m_screen->primaryOrientation();
126 Qt::ScreenOrientation QQuickScreenAttached::orientation() const
129 return Qt::PrimaryOrientation;
130 return m_screen->orientation();
133 int QQuickScreenAttached::angleBetween(int a, int b)
136 return Qt::PrimaryOrientation;
137 return m_screen->angleBetween((Qt::ScreenOrientation)a,(Qt::ScreenOrientation)b);
140 void QQuickScreenAttached::canvasChanged(QQuickCanvas* c)//Called by QQuickItemPrivate::initCanvas
142 QScreen* screen = c ? c->screen() : 0;
143 if (screen != m_screen) {
144 QScreen* oldScreen = m_screen;
148 disconnect(oldScreen, SIGNAL(sizeChanged(QSize)),
149 this, SIGNAL(widthChanged()));
150 disconnect(oldScreen, SIGNAL(sizeChanged(QSize)),
151 this, SIGNAL(heightChanged()));
152 disconnect(oldScreen, SIGNAL(orientationChanged(Qt::ScreenOrientation)),
153 this, SIGNAL(orientationChanged()));
154 disconnect(oldScreen, SIGNAL(primaryOrientationChanged(Qt::ScreenOrientation)),
155 this, SIGNAL(primaryOrientationChanged()));
159 return; //Don't bother emitting signals, because the new values are garbage anyways
161 if (!oldScreen || screen->size() != oldScreen->size()) {
163 emit heightChanged();
166 if (!oldScreen || screen->orientation() != oldScreen->orientation())
167 emit orientationChanged();
168 if (!oldScreen || screen->primaryOrientation() != oldScreen->primaryOrientation())
169 emit primaryOrientationChanged();
172 connect(screen, SIGNAL(sizeChanged(QSize)),
173 this, SIGNAL(widthChanged()));
174 connect(screen, SIGNAL(sizeChanged(QSize)),
175 this, SIGNAL(heightChanged()));
176 connect(screen, SIGNAL(orientationChanged(Qt::ScreenOrientation)),
177 this, SIGNAL(orientationChanged()));
178 connect(screen, SIGNAL(primaryOrientationChanged(Qt::ScreenOrientation)),
179 this, SIGNAL(primaryOrientationChanged()));