Commit 13ee1dd2 authored by Alessandro Portale's avatar Alessandro Portale
Browse files

Dummy template for Html5 app wizards

The template code is similar to the Qt Quick App wizard
template code. It has a Viewer class +.pri which wrap the "dirty
stuff", a main .pro file and main.cpp file. In this case, there
is also a "Hello World" index.html file.

The "dirty stuff" code exposes a quit() function to the JavaScript
in the webview, which can be triggerd via the index.html.

As the 1-line-summary of this commit states, it is a dummy. Some-
one with proper knowlede about QtWebkit please provide better
template code.

Task-Number: QTCREATORBUG-3284
parent 0b2451c4
# Add more folders to ship with the application, here
# DEPLOYMENTFOLDERS #
folder_01.source = html
DEPLOYMENTFOLDERS = folder_01
# DEPLOYMENTFOLDERS_END #
# Avoid auto screen rotation
# ORIENTATIONLOCK #
DEFINES += ORIENTATIONLOCK
# TARGETUID3 #
symbian:TARGET.UID3 = 0xE1111234
symbian:TARGET.CAPABILITY += NetworkServices
# Smart Installer package's UID
# This UID is from the protected range and therefore the package will
# fail to install if self-signed. By default qmake uses the unprotected
# range value if unprotected UID is defined for the application and
# 0x2002CCCF value if protected UID is given to the application
#symbian:DEPLOYMENT.installer_header = 0x2002CCCF
# If your application uses the Qt Mobility libraries, uncomment the following
# lines and add the respective components to the MOBILITY variable.
# CONFIG += mobility
# MOBILITY +=
# The .cpp file which was generated for your project. Feel free to hack it.
SOURCES += main.cpp
# Please do not modify the following two lines. Required for deployment.
include(html5applicationviewer/html5applicationviewer.pri)
# INCLUDE_DEPLOYMENT_PRI (wizard will remove the include and append deployment.pri to qmlapplicationviewer.pri, instead) #
include(../shared/deployment.pri)
qtcAddDeployment()
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<style type="text/css">
body { margin: 0; font-size: 2em; }
h1 { text-align: center; }
h1:first-child { color: red; }
h1:nth-child(2) { color: green; }
h1:last-child { color: blue; }
#quit { background-color: gray; color: white; font-weight: bold; display: block; text-align: right; }
</style>
<script type="text/javascript">
var counter = 0;
function toggleElement()
{
var elements = document.getElementsByTagName('h1');
for (var i = 0; i < elements.length; ++i)
elements[i].style.display = (counter % elements.length) == i ? '' : 'none';
counter++;
setTimeout('toggleElement()', 1000);
}
window.onload = function()
{
document.getElementById("quit").onmousedown = function()
{
Qt.quit();
};
toggleElement();
}
</script>
</head>
<body>
<a id="quit">X</a>
<h1>Hello</h1>
<h1>Html5</h1>
<h1>World</h1>
</body>
</html>
/*
This file was generated by the Html5 Application wizard of Qt Creator.
Html5ApplicationViewer is a convenience class containing mobile device specific
code such as screen orientation handling.
It is recommended not to modify this file, since newer versions of Qt Creator
may offer an updated version of it.
*/
#include "html5applicationviewer.h"
#include <QtCore/QCoreApplication>
#include <QtCore/QDir>
#include <QtCore/QFileInfo>
#include <QtGui/QVBoxLayout>
#include <QtGui/QGraphicsView>
#include <QtGui/QGraphicsScene>
#include <QtGui/QGraphicsLinearLayout>
#include <QtWebKit/QGraphicsWebView>
#include <QtWebKit/QWebFrame>
#if defined(Q_OS_SYMBIAN) && defined(ORIENTATIONLOCK)
#include <eikenv.h>
#include <eikappui.h>
#include <aknenv.h>
#include <aknappui.h>
#endif // Q_OS_SYMBIAN && ORIENTATIONLOCK
class Html5ApplicationViewerPrivate : public QGraphicsView
{
Q_OBJECT
public:
Html5ApplicationViewerPrivate(QWidget *parent = 0);
void resizeEvent(QResizeEvent *event);
static QString adjustPath(const QString &path);
public slots:
void quit();
private slots:
void addToJavaScript();
signals:
void quitRequested();
public:
QGraphicsWebView *m_webView;
};
Html5ApplicationViewerPrivate::Html5ApplicationViewerPrivate(QWidget *parent)
: QGraphicsView(parent)
{
QGraphicsScene *scene = new QGraphicsScene;
setScene(scene);
setFrameShape(QFrame::NoFrame);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_webView = new QGraphicsWebView;
scene->addItem(m_webView);
connect(m_webView->page()->mainFrame(),
SIGNAL(javaScriptWindowObjectCleared()), SLOT(addToJavaScript()));
}
void Html5ApplicationViewerPrivate::resizeEvent(QResizeEvent *event)
{
m_webView->resize(event->size());
}
QString Html5ApplicationViewerPrivate::adjustPath(const QString &path)
{
#ifdef Q_OS_UNIX
#ifdef Q_OS_MAC
if (!QDir::isAbsolutePath(path))
return QCoreApplication::applicationDirPath()
+ QLatin1String("/../Resources/") + path;
#else
const QString pathInShareDir = QCoreApplication::applicationDirPath()
+ QLatin1String("/../share/")
+ QFileInfo(QCoreApplication::applicationFilePath()).fileName()
+ QLatin1Char('/') + path;
if (QFileInfo(pathInShareDir).exists())
return pathInShareDir;
#endif
#endif
return path;
}
void Html5ApplicationViewerPrivate::quit()
{
emit quitRequested();
}
void Html5ApplicationViewerPrivate::addToJavaScript()
{
m_webView->page()->mainFrame()->addToJavaScriptWindowObject("Qt", this);
}
Html5ApplicationViewer::Html5ApplicationViewer(QWidget *parent)
: QWidget(parent)
, m_d(new Html5ApplicationViewerPrivate(this))
{
connect(m_d, SIGNAL(quitRequested()), SLOT(close()));
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(m_d);
layout->setMargin(0);
setLayout(layout);
}
Html5ApplicationViewer::~Html5ApplicationViewer()
{
delete m_d;
}
void Html5ApplicationViewer::loadFile(const QString &fileName)
{
m_d->m_webView->setUrl(QUrl(Html5ApplicationViewerPrivate::adjustPath(fileName)));
}
void Html5ApplicationViewer::loadUrl(const QUrl &url)
{
m_d->m_webView->setUrl(url);
}
void Html5ApplicationViewer::setOrientation(ScreenOrientation orientation)
{
#ifdef Q_OS_SYMBIAN
if (orientation != ScreenOrientationAuto) {
#if defined(ORIENTATIONLOCK)
const CAknAppUiBase::TAppUiOrientation uiOrientation =
(orientation == ScreenOrientationLockPortrait) ? CAknAppUi::EAppUiOrientationPortrait
: CAknAppUi::EAppUiOrientationLandscape;
CAknAppUi* appUi = dynamic_cast<CAknAppUi*> (CEikonEnv::Static()->AppUi());
TRAPD(error,
if (appUi)
appUi->SetOrientationL(uiOrientation);
);
Q_UNUSED(error)
#else // ORIENTATIONLOCK
qWarning("'ORIENTATIONLOCK' needs to be defined on Symbian when locking the orientation.");
#endif // ORIENTATIONLOCK
}
#elif defined(Q_WS_MAEMO_5)
Qt::WidgetAttribute attribute;
switch (orientation) {
case ScreenOrientationLockPortrait:
attribute = Qt::WA_Maemo5PortraitOrientation;
break;
case ScreenOrientationLockLandscape:
attribute = Qt::WA_Maemo5LandscapeOrientation;
break;
case ScreenOrientationAuto:
default:
attribute = Qt::WA_Maemo5AutoOrientation;
break;
}
setAttribute(attribute, true);
#else // Q_OS_SYMBIAN
Q_UNUSED(orientation);
#endif // Q_OS_SYMBIAN
}
void Html5ApplicationViewer::showExpanded()
{
#ifdef Q_OS_SYMBIAN
showFullScreen();
#elif defined(Q_WS_MAEMO_5)
showMaximized();
#else
show();
#endif
}
QGraphicsWebView *Html5ApplicationViewer::webView() const
{
return m_d->m_webView;
}
#include "html5applicationviewer.moc"
/*
This file was generated by the Html5 Application wizard of Qt Creator.
Html5ApplicationViewer is a convenience class containing mobile device specific
code such as screen orientation handling.
It is recommended not to modify this file, since newer versions of Qt Creator
may offer an updated version of it.
*/
#ifndef HTML5APPLICATIONVIEWER_H
#define HTML5APPLICATIONVIEWER_H
#include <QtGui/QWidget>
#include <QtCore/QUrl>
class QGraphicsWebView;
class Html5ApplicationViewer : public QWidget
{
Q_OBJECT
public:
enum ScreenOrientation {
ScreenOrientationLockPortrait,
ScreenOrientationLockLandscape,
ScreenOrientationAuto
};
explicit Html5ApplicationViewer(QWidget *parent = 0);
virtual ~Html5ApplicationViewer();
void loadFile(const QString &fileName);
void loadUrl(const QUrl &url);
void setOrientation(ScreenOrientation orientation);
void showExpanded();
QGraphicsWebView *webView() const;
private:
class Html5ApplicationViewerPrivate *m_d;
};
#endif // HTML5APPLICATIONVIEWER_H
# This file was generated by the Html5 Application wizard of Qt Creator.
# The code below adds the Html5ApplicationViewer to the project.
# It is recommended not to modify this file, since newer versions of Qt Creator
# may offer an updated version of it.
QT += webkit
SOURCES += $$PWD/html5applicationviewer.cpp
HEADERS += $$PWD/html5applicationviewer.h
INCLUDEPATH += $$PWD
#include <QtGui/QApplication>
#include "html5applicationviewer.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Html5ApplicationViewer viewer;
viewer.setOrientation(Html5ApplicationViewer::ScreenOrientationAuto); // ORIENTATION
viewer.showExpanded();
viewer.loadFile(QLatin1String("html/index.html")); // HTMLFILE
// viewer.loadUrl(QUrl(QLatin1String("http://dev.sencha.com/deploy/touch/examples/kitchensink/")));
return app.exec();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment