Started to merge @ZobyTwo cmake branch
This commit is contained in:
189
projects/mtg/include/qt/corewrapper.h
Normal file
189
projects/mtg/include/qt/corewrapper.h
Normal file
@@ -0,0 +1,189 @@
|
||||
#ifndef COREWRAPPER_H
|
||||
#define COREWRAPPER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QElapsedTimer>
|
||||
#ifndef QT_WIDGET
|
||||
#include <QtDeclarative>
|
||||
#include <QGraphicsItem>
|
||||
#endif //QT_WIDGET
|
||||
#include "../include/JGE.h"
|
||||
#include "../include/JTypes.h"
|
||||
#include "../include/JApp.h"
|
||||
#include "../include/JFileSystem.h"
|
||||
#include "../include/JRenderer.h"
|
||||
#include "../include/JGameLauncher.h"
|
||||
|
||||
#if (defined Q_WS_MAEMO_5)
|
||||
// For screen on/off events support
|
||||
#include <mce/dbus-names.h>
|
||||
#include <mce/mode-names.h>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusMessage>
|
||||
#include <QDBusInterface>
|
||||
#endif //Q_WS_MAEMO_5
|
||||
|
||||
class WagicWrapper
|
||||
{
|
||||
public:
|
||||
WagicWrapper();
|
||||
virtual ~WagicWrapper();
|
||||
|
||||
private:
|
||||
JGE* m_engine;
|
||||
JApp* m_app;
|
||||
JGameLauncher* m_launcher;
|
||||
};
|
||||
|
||||
|
||||
#ifdef QT_WIDGET
|
||||
class WagicCore : public QGLWidget
|
||||
#else
|
||||
class WagicCore : public QDeclarativeItem
|
||||
#endif
|
||||
{
|
||||
private:
|
||||
#ifdef QT_WIDGET
|
||||
typedef QGLWidget super;
|
||||
#else
|
||||
typedef QDeclarativeItem super;
|
||||
#endif //QT_WIDGET
|
||||
void initApp();
|
||||
|
||||
public:
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int nominalWidth READ getNominalWidth CONSTANT)
|
||||
Q_PROPERTY(int nominalHeight READ getNominalHeight CONSTANT)
|
||||
Q_PROPERTY(float nominalRatio READ getNominalRatio CONSTANT)
|
||||
Q_PROPERTY(bool active READ getActive WRITE setActive NOTIFY activeChanged)
|
||||
|
||||
|
||||
public:
|
||||
explicit WagicCore(super *parent = 0);
|
||||
virtual ~WagicCore();
|
||||
static int runTestSuite();
|
||||
|
||||
Q_INVOKABLE void doOK() {
|
||||
doAndEnqueue(JGE_BTN_OK);
|
||||
};
|
||||
Q_INVOKABLE void doNext() {
|
||||
doAndEnqueue(JGE_BTN_PREV);
|
||||
};
|
||||
Q_INVOKABLE void doCancel() {
|
||||
doAndEnqueue(JGE_BTN_SEC);
|
||||
};
|
||||
Q_INVOKABLE void doMenu() {
|
||||
doAndEnqueue(JGE_BTN_MENU);
|
||||
};
|
||||
Q_INVOKABLE void done() {
|
||||
while(m_buttonQueue.size())
|
||||
{
|
||||
m_engine->ReleaseKey(m_buttonQueue.front());
|
||||
m_buttonQueue.pop();
|
||||
}
|
||||
m_engine->ResetInput();
|
||||
};
|
||||
Q_INVOKABLE void pixelInput(int x, int y);
|
||||
Q_INVOKABLE qint64 getTick() {
|
||||
return g_startTimer.elapsed();
|
||||
};
|
||||
Q_INVOKABLE void doScroll(int x, int y, int) {
|
||||
m_engine->Scroll(x, y);
|
||||
};
|
||||
int getNominalHeight(){ return SCREEN_HEIGHT;};
|
||||
int getNominalWidth(){ return SCREEN_WIDTH;};
|
||||
float getNominalRatio() { return ((float)SCREEN_WIDTH / (float)SCREEN_HEIGHT);};
|
||||
bool getActive() { return m_active; };
|
||||
void setActive(bool active);
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
void keyReleaseEvent(QKeyEvent *event);
|
||||
void initializeGL();
|
||||
void resizeGL(int width, int height);
|
||||
void paintGL();
|
||||
static char* getApplicationName() {
|
||||
return JGameLauncher::GetName();
|
||||
};
|
||||
|
||||
#ifdef QT_WIDGET
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
void mouseReleaseEvent(QMouseEvent *event);
|
||||
void mouseMoveEvent(QMouseEvent *event);
|
||||
void tapAndHoldTriggered(QTapAndHoldGesture* gesture);
|
||||
void showEvent(QShowEvent *event);
|
||||
void hideEvent(QHideEvent *event);
|
||||
bool gestureEvent(QGestureEvent* event);
|
||||
bool event(QEvent *event);
|
||||
void wheelEvent(QWheelEvent *event);
|
||||
#else
|
||||
void wheelEvent ( QGraphicsSceneWheelEvent * event);
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||
#endif
|
||||
|
||||
#ifdef QT_WIDGET
|
||||
public slots:
|
||||
void start(int);
|
||||
#endif
|
||||
|
||||
#ifdef Q_WS_MAEMO_5
|
||||
public slots:
|
||||
void displayStateChanged(const QDBusMessage &message);
|
||||
#endif //Q_WS_MAEMO_5
|
||||
|
||||
|
||||
signals:
|
||||
void activeChanged();
|
||||
|
||||
private slots:
|
||||
|
||||
private:
|
||||
int lastPosx(){
|
||||
#if QT_VERSION >= 0x050100
|
||||
return m_lastPos.x()*devicePixelRatio();
|
||||
#else
|
||||
return m_lastPos.x();
|
||||
#endif
|
||||
}
|
||||
int lastPosy(){
|
||||
#if QT_VERSION >= 0x050100
|
||||
return m_lastPos.y()*devicePixelRatio();
|
||||
#else
|
||||
return m_lastPos.y();
|
||||
#endif
|
||||
}
|
||||
void timerEvent( QTimerEvent* );
|
||||
void doAndEnqueue(JButton action) {
|
||||
m_engine->HoldKey_NoRepeat(action);
|
||||
m_buttonQueue.push(action);
|
||||
}
|
||||
|
||||
public:
|
||||
// used mainly to mesure the delta between 2 updates
|
||||
static QElapsedTimer g_startTimer;
|
||||
private:
|
||||
JGE* m_engine;
|
||||
JApp* m_app;
|
||||
JGameLauncher* m_launcher;
|
||||
qint64 m_lastTickCount;
|
||||
std::queue<JButton> m_buttonQueue;
|
||||
int m_timerId;
|
||||
bool m_active;
|
||||
QRect m_viewPort;
|
||||
QPoint m_lastPos;
|
||||
#ifdef QT_WIDGET
|
||||
#if (defined Q_WS_MAEMO_5) || (defined MEEGO_EDITION_HARMATTAN) || (defined Q_WS_ANDROID)
|
||||
int mMouseDownX;
|
||||
int mMouseDownY;
|
||||
qint64 mLastFingerDownTime;
|
||||
#endif //Q_WS_MAEMO_5
|
||||
#endif //QT_WIDGET
|
||||
|
||||
#ifdef Q_WS_MAEMO_5
|
||||
QDBusConnection dBusConnection;
|
||||
QDBusInterface* dBusInterface;
|
||||
#endif //Q_WS_MAEMO_5
|
||||
};
|
||||
#ifndef QT_WIDGET
|
||||
QML_DECLARE_TYPE(WagicCore)
|
||||
#endif //QT_WIDGET
|
||||
|
||||
#endif // COREWRAPPER_H
|
||||
147
projects/mtg/include/qt/filedownloader.h
Normal file
147
projects/mtg/include/qt/filedownloader.h
Normal file
@@ -0,0 +1,147 @@
|
||||
#ifndef FILEDOWNLOADER_H
|
||||
#define FILEDOWNLOADER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QByteArray>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QTemporaryFile>
|
||||
#ifdef QT_WIDGET
|
||||
#include <QProgressDialog>
|
||||
#include <QPushButton>
|
||||
#include <QCoreApplication>
|
||||
#else
|
||||
#include <qdeclarative.h>
|
||||
#endif //QT_WIDGET
|
||||
|
||||
|
||||
class FileDownloader :
|
||||
#ifdef QT_WIDGET
|
||||
public QProgressDialog
|
||||
#else
|
||||
public QObject
|
||||
#endif //QT_WIDGET
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(qint64 received READ received NOTIFY receivedChanged)
|
||||
Q_PROPERTY(QString status READ getStatus NOTIFY statusChanged)
|
||||
Q_PROPERTY(DownloadState state READ getState NOTIFY stateChanged )
|
||||
Q_PROPERTY(QString state_string READ getStateString NOTIFY stateStringChanged )
|
||||
Q_ENUMS(DownloadState)
|
||||
public:
|
||||
enum DownloadState {
|
||||
NETWORK_ERROR,
|
||||
DOWNLOADING_HASH,
|
||||
DOWNLOADING_FILE,
|
||||
DOWNLOADED
|
||||
} ;
|
||||
|
||||
explicit FileDownloader(QString localPath, QString targetFile, QObject *parent = 0);
|
||||
virtual ~FileDownloader();
|
||||
qint64 received() const {return m_received;};
|
||||
QString getStatus() {return m_status;};
|
||||
DownloadState getState() {
|
||||
return m_state;
|
||||
};
|
||||
QString getStateString() {
|
||||
if(m_state == DOWNLOADING_HASH )
|
||||
return "DOWNLOADING_HASH";
|
||||
else if(m_state == DOWNLOADING_FILE )
|
||||
return "DOWNLOADING_FILE";
|
||||
else
|
||||
return "DOWNLOADED";
|
||||
}
|
||||
|
||||
signals:
|
||||
void receivedChanged(int value);
|
||||
void statusChanged();
|
||||
void stateChanged(DownloadState state);
|
||||
void stateStringChanged();
|
||||
|
||||
private slots:
|
||||
void fileDownloaded(){
|
||||
// let's check some error
|
||||
if(m_downloadReply->error() != QNetworkReply::NoError) {
|
||||
m_state = NETWORK_ERROR;
|
||||
} else {
|
||||
if(m_tmp.write(m_downloadReply->readAll()) == -1) return;
|
||||
if(QFile(m_localPath).exists())
|
||||
QFile::remove(m_localPath);
|
||||
|
||||
m_tmp.close();
|
||||
computeLocalHash(m_tmp);
|
||||
if(m_localHash == m_remoteHash) {
|
||||
if(!m_tmp.rename(m_localPath)) return;
|
||||
m_tmp.setAutoRemove(false);
|
||||
m_state = DOWNLOADED;
|
||||
}
|
||||
else {
|
||||
m_state = NETWORK_ERROR;
|
||||
}
|
||||
}
|
||||
emit stateChanged(m_state);
|
||||
};
|
||||
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal){
|
||||
if(m_tmp.write(m_downloadReply->readAll()) == -1) return;
|
||||
if(!bytesTotal) return;
|
||||
m_received = bytesReceived*100/bytesTotal;
|
||||
emit receivedChanged(m_received);
|
||||
};
|
||||
void setDownloadUrl(QUrl url);
|
||||
void computeLocalHash(QFile& file);
|
||||
void requestHash(QUrl url);
|
||||
void computeRemoteHash();
|
||||
void handleStateChange(DownloadState state){
|
||||
#ifdef QT_WIDGET
|
||||
switch(state) {
|
||||
case NETWORK_ERROR:
|
||||
if(m_localHash == "") {
|
||||
setLabelText("Network Error");
|
||||
setCancelButton(new QPushButton("OK"));
|
||||
show();
|
||||
} else {
|
||||
emit finished(0);
|
||||
}
|
||||
break;
|
||||
case DOWNLOADED:
|
||||
emit finished(0);
|
||||
break;
|
||||
case DOWNLOADING_HASH:
|
||||
break;
|
||||
case DOWNLOADING_FILE:
|
||||
show();
|
||||
break;
|
||||
}
|
||||
|
||||
#else
|
||||
emit stateStringChanged();
|
||||
#endif //QT_WIDGET
|
||||
};
|
||||
#ifdef QT_WIDGET
|
||||
void handleCancel(){
|
||||
QCoreApplication::instance()->exit(1);
|
||||
}
|
||||
#endif //QT_WIDGET
|
||||
|
||||
|
||||
private:
|
||||
DownloadState m_state;
|
||||
QNetworkAccessManager m_WebCtrl;
|
||||
qint64 m_received;
|
||||
QTemporaryFile m_tmp;
|
||||
QString m_targetFile;
|
||||
QString m_localPath;
|
||||
QString m_localHash;
|
||||
QString m_remoteHash;
|
||||
bool m_OK;
|
||||
QString m_status;
|
||||
QNetworkReply* m_downloadReply;
|
||||
QNetworkReply* m_hashReply;
|
||||
};
|
||||
#ifndef QT_WIDGET
|
||||
QML_DECLARE_TYPEINFO(FileDownloader, QML_HAS_ATTACHED_PROPERTIES)
|
||||
#endif //QT_WIDGET
|
||||
|
||||
#endif // FILEDOWNLOADER_H
|
||||
Reference in New Issue
Block a user