Commit 6daf6404 authored by Bruno Coudoin's avatar Bruno Coudoin
Browse files

Added applicationInfo from Digia WeatherApp example.

Improved clickgame activity to start/stop properly
and handle screen size for the fishes.
parent 8b53fb18
......@@ -8,11 +8,22 @@ ActivityBase {
id: activity
focus: true
onStart: {}
onStop: {}
pageComponent: Image {
id: backgound
id: background
signal start
signal stop
focus: true
fillMode: Image.PreserveAspectCrop
Component.onCompleted: Activity.start(backgound, bar, bonus);
Component.onCompleted: {
activity.start.connect(start)
activity.stop.connect(stop)
}
onStart: { Activity.start(main, background, bar, bonus) }
onStop: { Activity.stop() }
// FIXME It's not working
Keys.onLeftPressed: Activity.leftClick()
......@@ -39,4 +50,5 @@ ActivityBase {
id: bonus
}
}
}
import QtQuick 2.1
import QtQuick.Particles 2.0
import "activity.js" as Activity
import GCompris 1.0
AnimatedSprite {
id: fish
Component.onCompleted: x=900
property Item main
Component.onCompleted: x = main.width
property int duration: 5000
frameRate: 2
interpolate: true
transform: Rotation {
id: rotate; origin.x: width / 2; origin.y: 0; axis { x: 0; y: 1; z: 0 } angle: 0
}
SequentialAnimation {
id: rotateLeftAnimation
loops: 1
PropertyAnimation {
target: rotate
properties: "angle"
from: 0
to: 180
duration: 500
}
id: rotateLeftAnimation
loops: 1
PropertyAnimation {
target: rotate
properties: "angle"
from: 0
to: 180
duration: 500
}
}
SequentialAnimation {
id: rotateRightAnimation
loops: 1
PropertyAnimation {
target: rotate
properties: "angle"
from: 180
to: 0
duration: 500
}
id: rotateRightAnimation
loops: 1
PropertyAnimation {
target: rotate
properties: "angle"
from: 180
to: 0
duration: 500
}
}
onXChanged: {
if(x > 600) {
if(x >= main.width - fish.width && rotate.angle == 180) {
// The window has been shrunk
} else if(x >= main.width - fish.width) {
rotateLeftAnimation.start()
x = 0
y = Activity.getY(y)
y = Math.random() * (main.height - fish.height)
bubbleEffect.restart()
} else if(x < 100) {
} else if(x <= 0) {
rotateRightAnimation.start()
x = 800
x = ApplicationInfo.applicationWidth
bubbleEffect.restart()
}
}
......
......@@ -188,20 +188,22 @@ var levelProperty = [
"minDuration": 6000
},
]
var currentImageId = 0;
var currentLevel = 0;
var currentImageId = 0
var currentLevel = 0
var main
var background
var bar;
var bonus;
var bar
var bonus
// The array of created fishes object
var createdFishes;
var killedFishes;
var createdFishes
var killedFishes
function start(_background, _bar, _bonus) {
function start(_main, _background, _bar, _bonus) {
main = _main
background = _background
bar = _bar;
bonus = _bonus;
bar = _bar
bonus = _bonus
currentLevel = 0
initLevel()
}
......@@ -257,8 +259,9 @@ function createFish(minDuration) {
var fish = component.createObject(
background,
{
"x": Math.floor(Math.random() * 400) + 100,
"y": Math.floor(Math.random() * 500),
"main": main,
"x": Math.random() * (main.width - fishSource.width),
"y": Math.random() * (main.height - fishSource.height),
"width": fishSource.width,
"height": fishSource.height,
"source": "qrc:/gcompris/src/activities/clickgame/resource/" +
......@@ -292,9 +295,3 @@ function fishKilled() {
}
}
function getY(y) {
if(currentLevel > 3) {
return Math.floor(Math.random() * 500)
}
return y
}
import QtQuick 2.1
import "qrc:/gcompris/src/core"
import QtQuick.Controls 1.0
import GCompris 1.0
Item {
......@@ -7,9 +7,20 @@ Item {
property Item main: parent;
property Component pageComponent
property QtObject activityInfo
property bool isLocked: true
signal home
signal start
signal stop
signal displayDialog(Item dialog)
Stack.onStatusChanged: {
if (Stack.status == Stack.Active) {
start()
} else if (Stack.status == Stack.Inactive) {
stop()
}
}
Keys.onEscapePressed: home()
Keys.onPressed: {
if (event.modifiers === Qt.ControlModifier &&
......@@ -22,6 +33,7 @@ Item {
}
Loader {
id: activity
sourceComponent: pageComponent
anchors.fill: parent
}
......
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
** of its contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QtCore/QFile>
#include <QtCore/qmath.h>
#include <QtCore/QUrl>
#include <QtCore/QUrlQuery>
#include <QtGui/QGuiApplication>
#include <QtGui/QScreen>
#include "ApplicationInfo.h"
#include <QDebug>
#include <QQmlEngine>
#include <qqml.h>
ApplicationInfo::ApplicationInfo()
{
m_isMobile = false;
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) || defined(Q_OS_BLACKBERRY)
m_isMobile = true;
#endif
m_constants = new QQmlPropertyMap(this);
m_constants->insert(QLatin1String("isMobile"), QVariant(m_isMobile));
QRect rect = qApp->primaryScreen()->geometry();
m_ratio = m_isMobile ? qMin(qMax(rect.width(), rect.height())/1136. , qMin(rect.width(), rect.height())/640.) : 1;
m_sliderHandleWidth = getSizeWithRatio(70);
m_sliderHandleHeight = getSizeWithRatio(87);
m_sliderGapWidth = getSizeWithRatio(100);
m_isPortraitMode = m_isMobile ? rect.height() > rect.width() : false;
m_hMargin = m_isPortraitMode ? 20 * ratio() : 50 * ratio();
m_applicationWidth = m_isMobile ? rect.width() : 1120;
if (m_isMobile)
connect(qApp->primaryScreen(), SIGNAL(physicalSizeChanged(QSizeF)), this, SLOT(notifyPortraitMode()));
}
void ApplicationInfo::setApplicationWidth(const int newWidth)
{
if (newWidth != m_applicationWidth) {
m_applicationWidth = newWidth;
emit applicationWidthChanged();
}
}
void ApplicationInfo::notifyPortraitMode()
{
int width = qApp->primaryScreen()->geometry().width();
int height = qApp->primaryScreen()->geometry().height();
setIsPortraitMode(height > width);
}
void ApplicationInfo::setIsPortraitMode(const bool newMode)
{
if (m_isPortraitMode != newMode) {
m_isPortraitMode = newMode;
m_hMargin = m_isPortraitMode ? 20 * ratio() : 50 * ratio();
emit portraitModeChanged();
emit hMarginChanged();
}
}
static QObject *systeminfo_provider(QQmlEngine *engine,
QJSEngine *scriptEngine)
{
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)
return new ApplicationInfo();
}
void ApplicationInfo::init()
{
qmlRegisterSingletonType<ApplicationInfo>(
"GCompris", 1, 0, "ApplicationInfo", systeminfo_provider);
}
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
** of its contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef APPLICATIONINFO_H
#define APPLICATIONINFO_H
#include <QtCore/QObject>
#include <QtQml/QQmlPropertyMap>
class ApplicationInfo : public QObject
{
Q_OBJECT
Q_PROPERTY(int applicationWidth READ applicationWidth WRITE setApplicationWidth NOTIFY applicationWidthChanged)
Q_PROPERTY(QObject *constants READ constants CONSTANT)
Q_PROPERTY(bool isPortraitMode READ isPortraitMode WRITE setIsPortraitMode NOTIFY portraitModeChanged)
Q_PROPERTY(qreal ratio READ ratio NOTIFY ratioChanged)
Q_PROPERTY(qreal hMargin READ hMargin NOTIFY hMarginChanged)
Q_PROPERTY(qreal sliderHandleWidth READ sliderHandleWidth NOTIFY ratioChanged)
Q_PROPERTY(qreal sliderHandleHeight READ sliderHandleHeight NOTIFY ratioChanged)
Q_PROPERTY(qreal sliderGapWidth READ sliderGapWidth NOTIFY ratioChanged)
public:
ApplicationInfo();
static void init();
QQmlPropertyMap *constants() const { return m_constants; }
int applicationWidth() const { return m_applicationWidth; }
void setApplicationWidth(const int newWidth);
bool isPortraitMode() const { return m_isPortraitMode; }
void setIsPortraitMode(const bool newMode);
qreal hMargin() const { return m_hMargin; }
qreal ratio() const { return m_ratio; }
qreal sliderHandleHeight() { return m_sliderHandleHeight; }
qreal sliderGapWidth() { return m_sliderGapWidth; }
qreal sliderHandleWidth() { return m_sliderHandleWidth; }
protected slots:
void notifyPortraitMode();
protected:
qreal getSizeWithRatio(const qreal height) { return ratio() * height; }
signals:
void applicationWidthChanged();
void portraitModeChanged();
void hMarginChanged();
void ratioChanged();
private:
int m_applicationWidth;
QQmlPropertyMap *m_constants;
bool m_isPortraitMode;
bool m_isMobile;
qreal m_ratio;
qreal m_hMargin;
qreal m_sliderHandleHeight, m_sliderHandleWidth, m_sliderGapWidth;
};
#endif // APPLICATIONINFO_H
import QtQuick 2.1
import GCompris 1.0
Rectangle {
id: bar
......@@ -10,7 +11,7 @@ Rectangle {
height: barRow.height - 30
border.color: "black"
border.width: 2
scale: 1.4
scale: 1 * ApplicationInfo.ratio
z: 1000
property BarEnumContent content
property int level: 0
......
SOURCES += \
$$PWD/ActivityInfo.cpp \
$$PWD/ActivityInfoTree.cpp \
$$PWD/main.cpp
$$PWD/main.cpp \
$$PWD/ApplicationInfo.cpp
HEADERS += \
$$PWD/ActivityInfo.h \
$$PWD/ActivityInfoTree.h
$$PWD/ActivityInfoTree.h \
$$PWD/ApplicationInfo.h
APP_FILES = \
$$PWD/ActivityBase.qml \
......
......@@ -4,12 +4,16 @@
#include <QtQml>
#include <QObject>
#include "ApplicationInfo.h"
#include "ActivityInfoTree.h"
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
app.setOrganizationName("GCompris");
app.setApplicationName("GCompris");
ApplicationInfo::init();
ActivityInfoTree::init();
QQmlApplicationEngine engine(QUrl("qrc:/gcompris/src/core/main.qml"));
......
......@@ -2,13 +2,14 @@ import QtQuick 2.1
import QtQuick.Controls 1.0
import QtQuick.Window 2.1
import "qrc:/gcompris/src/core"
import GCompris 1.0
Window {
id: main
width: 800
height: 520
minimumWidth: 600
minimumHeight: 400
title: "GCompris"
StackView {
......
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