aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mobile
diff options
context:
space:
mode:
authorRenaud G <renaud@rolisteam.org>2016-09-25 04:19:05 +0200
committerRenaud G <renaud@rolisteam.org>2016-09-25 04:19:05 +0200
commit664ac48622701dedaa816f5c27fff5f99389690e (patch)
tree9112c9051e3904a892207b73f2e64eda9b5306b5 /mobile
parente103f23c9d2e9096bde3b0d9fa798eed5dc8b64a (diff)
downloadOneRoll-664ac48622701dedaa816f5c27fff5f99389690e.tar.gz
OneRoll-664ac48622701dedaa816f5c27fff5f99389690e.zip
-first draft of mobile application.
Diffstat (limited to 'mobile')
-rw-r--r--mobile/CMakeLists.txt3
-rw-r--r--mobile/commandmodel.cpp32
-rw-r--r--mobile/commandmodel.h17
-rw-r--r--mobile/main.cpp75
-rw-r--r--mobile/maincontroler.cpp30
-rw-r--r--mobile/maincontroler.h11
-rw-r--r--mobile/resources/images/add.pngbin4612 -> 4696 bytes
7 files changed, 121 insertions, 47 deletions
diff --git a/mobile/CMakeLists.txt b/mobile/CMakeLists.txt
index 12e629a..0ccff18 100644
--- a/mobile/CMakeLists.txt
+++ b/mobile/CMakeLists.txt
@@ -92,8 +92,9 @@ SET( diceGui_sources
maincontroler.cpp
../highlightdice.cpp
)
+qt5_add_resources(RESOURCE_ADDED mobile.qrc)
-add_executable( diceGui ${diceGui_sources} ${diceGui_QM} )
+add_executable( diceGui ${diceGui_sources} ${diceGui_QM} ${RESOURCE_ADDED} )
target_link_libraries(diceGui ${Qt5Core_LIBRARIES} ${Qt5Widgets_LIBRARIES} ${Qt5Gui_LIBRARIES} ${Qt5Qml_LIBRARIES} ${Qt5Quick_LIBRARIES})
INSTALL_TARGETS(/bin diceGui)
diff --git a/mobile/commandmodel.cpp b/mobile/commandmodel.cpp
index 1f6f6e1..6a3ab1d 100644
--- a/mobile/commandmodel.cpp
+++ b/mobile/commandmodel.cpp
@@ -23,3 +23,35 @@ CommandModel::CommandModel()
{
}
+
+QVariant CommandModel::data(const QModelIndex &index, int role) const
+{
+ QPair<QString,QString> indexP = m_data.at(index.row());
+ if(role == NameRole)
+ {
+ return indexP.first;
+ }
+ else if(role == CmdRole)
+ {
+ return indexP.second;
+ }
+}
+
+int CommandModel::rowCount(const QModelIndex &parent) const
+{
+ return m_data.count();
+}
+QHash<int, QByteArray> CommandModel::roleNames() const
+{
+ QHash<int, QByteArray> roles;
+ roles[NameRole] = "name";
+ roles[CmdRole] = "cmd";
+ return roles;
+}
+void CommandModel::insertCmd(QString name, QString cmd)
+{
+ QModelIndex index;
+ beginInsertRows(index,0,0);
+ m_data.prepend(QPair<QString,QString>(name,cmd));
+ endInsertRows();
+}
diff --git a/mobile/commandmodel.h b/mobile/commandmodel.h
index e68c91e..2c20072 100644
--- a/mobile/commandmodel.h
+++ b/mobile/commandmodel.h
@@ -22,10 +22,25 @@
#include <QObject>
+#include <QAbstractListModel>
+
class CommandModel : public QAbstractListModel
{
+ Q_OBJECT
public:
+ enum CustomRole {NameRole = Qt::UserRole+1,CmdRole};
CommandModel();
+
+ virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole ) const;
+ virtual int rowCount(const QModelIndex &parent) const;
+
+ QHash<int, QByteArray> roleNames() const;
+
+
+public slots:
+ void insertCmd(QString name, QString cmd);
+private:
+ QList<QPair<QString,QString> > m_data;
};
-#endif // COMMANDMODEL_H \ No newline at end of file
+#endif // COMMANDMODEL_H
diff --git a/mobile/main.cpp b/mobile/main.cpp
index b450d5a..c4c8b0a 100644
--- a/mobile/main.cpp
+++ b/mobile/main.cpp
@@ -1,54 +1,39 @@
/***************************************************************************
-* Copyright (C) 2016 by Renaud Guezennec *
-* http://www.rolisteam.org/contact *
-* *
-* This file is part of DiceParser *
-* *
-* DiceParser is free software; you can redistribute it and/or modify *
-* it under the terms of the GNU General Public License as published by *
-* the Free Software Foundation; either version 2 of the License, or *
-* (at your option) any later version. *
-* *
-* This program is distributed in the hope that it will be useful, *
-* but WITHOUT ANY WARRANTY; without even the implied warranty of *
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
-* GNU General Public License for more details. *
-* *
-* You should have received a copy of the GNU General Public License *
-* along with this program; if not, write to the *
-* Free Software Foundation, Inc., *
-* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
-***************************************************************************/
+ * Copyright (C) 2016 by Renaud Guezennec *
+ * http://www.rolisteam.org/contact *
+ * *
+ * rolisteam is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+#include <QGuiApplication>
+#include <QQmlApplicationEngine>
+
+#include "maincontroler.h"
-
-
-
-
-#include <QApplication>
-#include <QQuickWindow>
-
-/**
- * @page DiceGui
- * The QML client for DiceParser the new dice system from rolisteam.
- * It is dedicated to be used on smartphone.
- * @section Build and install
- * To build this program, type these command:
- * - mkdir build
- * - cd build
- * - cmake ../
- * - make
- * - make install
- * @return
- */
int main(int argc, char *argv[])
{
- QApplication app(argc,argv);
- QApplication::setApplicationName("dice");
- QApplication::setApplicationVersion("1.0");
+ QGuiApplication app(argc, argv);
+
+ MainControler* main = new MainControler();
- QQuickWindow* m_window;
+ QQmlApplicationEngine engine;
+ main->initEngine(&engine);
+ engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
+ //main->setConnections(&engine);
- return 0;
+ return app.exec();
}
diff --git a/mobile/maincontroler.cpp b/mobile/maincontroler.cpp
index d6197e1..4b40fa2 100644
--- a/mobile/maincontroler.cpp
+++ b/mobile/maincontroler.cpp
@@ -1,7 +1,37 @@
#include "maincontroler.h"
+#include <QQmlContext>
+#include <QDebug>
+
MainControler::MainControler(QObject *parent)
: QObject(parent)
{
+ m_model = new CommandModel();
+ m_model->insertCmd("L5R","8D10e10k4");
+
+ m_diceParser = new DiceParser();
+}
+void MainControler::initEngine(QQmlApplicationEngine* engine)
+{
+ m_engine = engine;
+ engine->rootContext()->setContextProperty("_model",m_model);
+ connect(m_engine,SIGNAL(objectCreated(QObject*,QUrl)),this,SLOT(setConnections(QObject*,QUrl)));
+
+
+}
+void MainControler::rollDice(QString cmd)
+{
+ if(m_diceParser->parseLine(cmd))
+ {
+ m_diceParser->Start();
+ qDebug() << m_diceParser->getSumOfDiceResult();
+ }
+}
+void MainControler::setConnections(QObject* root,QUrl url)
+{
+ //QObject* root = engine->rootContext()->contextObject();
+
+ connect(root,SIGNAL(roll(QString)),this,SLOT(rollDice(QString)));
+ connect(root,SIGNAL(addRoll(QString,QString)),m_model,SLOT(insertCmd(QString,QString)));
}
diff --git a/mobile/maincontroler.h b/mobile/maincontroler.h
index 98d68ff..b94312d 100644
--- a/mobile/maincontroler.h
+++ b/mobile/maincontroler.h
@@ -2,6 +2,10 @@
#define MAINCONTROLER_H
#include <QObject>
+#include <QQmlApplicationEngine>
+
+#include "commandmodel.h"
+#include "diceparser.h"
class MainControler : public QObject
{
@@ -9,9 +13,16 @@ class MainControler : public QObject
public:
explicit MainControler(QObject *parent = 0);
+ void initEngine(QQmlApplicationEngine* );
signals:
public slots:
+ void setConnections(QObject* root,QUrl url);
+ void rollDice(QString cmd);
+private:
+ CommandModel* m_model;
+ DiceParser* m_diceParser;
+ QQmlApplicationEngine* m_engine;
};
#endif // MAINCONTROLER_H
diff --git a/mobile/resources/images/add.png b/mobile/resources/images/add.png
index 9d63dc4..c8e1bd2 100644
--- a/mobile/resources/images/add.png
+++ b/mobile/resources/images/add.png
Binary files differ