Qt 4.8
qmlapplicationviewer.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 // checksum 0x5e4a version 0x5000d
43 /*
44  This file was generated by the Qt Quick Application wizard of Qt Creator.
45  QmlApplicationViewer is a convenience class containing mobile device specific
46  code such as screen orientation handling. Also QML paths and debugging are
47  handled here.
48  It is recommended not to modify this file, since newer versions of Qt Creator
49  may offer an updated version of it.
50 */
51 
52 #include "qmlapplicationviewer.h"
53 
54 #include <QtCore/QCoreApplication>
55 #include <QtCore/QDir>
56 #include <QtCore/QFileInfo>
57 #include <QtDeclarative/QDeclarativeComponent>
58 #include <QtDeclarative/QDeclarativeEngine>
59 #include <QtDeclarative/QDeclarativeContext>
60 
61 #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
62 
63 #include <qt_private/qdeclarativedebughelper_p.h>
64 
65 #if !defined(NO_JSDEBUGGER)
66 #include <jsdebuggeragent.h>
67 #endif
68 #if !defined(NO_QMLOBSERVER)
69 #include <qdeclarativeviewobserver.h>
70 #endif
71 
72 // Enable debugging before any QDeclarativeEngine is created
73 struct QmlJsDebuggingEnabler
74 {
75  QmlJsDebuggingEnabler()
76  {
78  }
79 };
80 
81 // Execute code in constructor before first QDeclarativeEngine is instantiated
82 static QmlJsDebuggingEnabler enableDebuggingHelper;
83 
84 #endif // QMLJSDEBUGGER
85 
87 {
89  friend class QmlApplicationViewer;
90  static QString adjustPath(const QString &path);
91 };
92 
94 {
95 #ifdef Q_OS_UNIX
96 #ifdef Q_OS_MAC
97  if (!QDir::isAbsolutePath(path))
99  + QLatin1String("/../Resources/") + path;
100 #else
101  const QString pathInInstallDir = QCoreApplication::applicationDirPath()
102  + QLatin1String("/../") + path;
103  if (pathInInstallDir.contains(QLatin1String("opt"))
104  && pathInInstallDir.contains(QLatin1String("bin"))
105  && QFileInfo(pathInInstallDir).exists()) {
106  return pathInInstallDir;
107  }
108 #endif
109 #endif
110  return path;
111 }
112 
114  QDeclarativeView(parent),
116 {
117  connect(engine(), SIGNAL(quit()), SLOT(close()));
119  // Qt versions prior to 4.8.0 don't have QML/JS debugging services built in
120 #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
121 #if !defined(NO_JSDEBUGGER)
122  new QmlJSDebugger::JSDebuggerAgent(engine());
123 #endif
124 #if !defined(NO_QMLOBSERVER)
125  new QmlJSDebugger::QDeclarativeViewObserver(this, this);
126 #endif
127 #endif
128 }
129 
131 {
132  delete m_d;
133 }
134 
136 {
139 }
140 
142 {
144 }
145 
147 {
148 //#if defined(Q_OS_SYMBIAN)
149 // // If the version of Qt on the device is < 4.7.2, that attribute won't work
150 // if (orientation != ScreenOrientationAuto) {
151 // const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
152 // if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
153 // qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
154 // return;
155 // }
156 // }
157 //#endif // Q_OS_SYMBIAN
158 
159 // Qt::WidgetAttribute attribute;
160 // switch (orientation) {
161 //#if QT_VERSION < 0x040702
162 // // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
163 // case ScreenOrientationLockPortrait:
164 // attribute = static_cast<Qt::WidgetAttribute>(128);
165 // break;
166 // case ScreenOrientationLockLandscape:
167 // attribute = static_cast<Qt::WidgetAttribute>(129);
168 // break;
169 // default:
170 // case ScreenOrientationAuto:
171 // attribute = static_cast<Qt::WidgetAttribute>(130);
172 // break;
173 //#else // QT_VERSION < 0x040702
174 // case ScreenOrientationLockPortrait:
175 // attribute = Qt::WA_LockPortraitOrientation;
176 // break;
177 // case ScreenOrientationLockLandscape:
178 // attribute = Qt::WA_LockLandscapeOrientation;
179 // break;
180 // default:
181 // case ScreenOrientationAuto:
182 // attribute = Qt::WA_AutoOrientation;
183 // break;
184 //#endif // QT_VERSION < 0x040702
185 // };
186 // setAttribute(attribute, true);
187 }
188 
190 {
191 #if defined(Q_OS_SYMBIAN) || defined(MEEGO_EDITION_HARMATTAN)
192  showFullScreen();
193 #elif defined(Q_WS_MAEMO_5)
194  showMaximized();
195 #else
196  show();
197 #endif
198 }
void showMaximized()
Shows the widget maximized.
Definition: qwidget.cpp:3218
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
static bool isAbsolutePath(const QString &path)
Returns true if path is absolute; returns false if it is relative.
Definition: qdir.h:192
The QDeclarativeView class provides a widget for displaying a Qt Declarative user interface...
void addImportPath(const QString &dir)
Adds path as a directory where the engine searches for installed modules in a URL-based directory str...
#define SLOT(a)
Definition: qobjectdefs.h:226
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
class QmlApplicationViewerPrivate * m_d
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool exists() const
Returns true if the file exists; otherwise returns false.
Definition: qfileinfo.cpp:675
The QString class provides a Unicode character string.
Definition: qstring.h:83
void addImportPath(const QString &path)
#define SIGNAL(a)
Definition: qobjectdefs.h:227
static QString applicationDirPath()
Returns the directory that contains the application executable.
void setOrientation(ScreenOrientation orientation)
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
void setMainQmlFile(const QString &file)
void setResizeMode(ResizeMode)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
void show()
Shows the widget and its child widgets.
void setSource(const QUrl &)
Sets the source to the url, loads the QML component and instantiates it.
QDeclarativeEngine * engine() const
Returns a pointer to the QDeclarativeEngine used for instantiating QML Components.
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
Definition: qurl.cpp:6374
bool close()
Closes this widget.
Definition: qwidget.cpp:8305
void showFullScreen()
Shows the widget in full-screen mode.
Definition: qwidget.cpp:3185
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
QmlApplicationViewer(QWidget *parent=0)
static QString adjustPath(const QString &path)