diff options
| author | 2022-04-29 10:48:09 +0200 | |
|---|---|---|
| committer | 2022-04-29 10:48:09 +0200 | |
| commit | 07c5f6ec23fcf9237a24e71adcfacabce677f818 (patch) | |
| tree | 588e8c5f82b9163181fad3581f610e6f1d88cba4 /src/bin/mobile | |
| parent | a9153f1615a842cfb9e9bcda4d9071e202618569 (diff) | |
| download | OneRoll-07c5f6ec23fcf9237a24e71adcfacabce677f818.tar.gz OneRoll-07c5f6ec23fcf9237a24e71adcfacabce677f818.zip | |
Change file organization.
Diffstat (limited to 'src/bin/mobile')
| -rw-r--r-- | src/bin/mobile/CMakeLists.txt | 109 | ||||
| -rw-r--r-- | src/bin/mobile/commandmodel.cpp | 54 | ||||
| -rw-r--r-- | src/bin/mobile/commandmodel.h | 50 | ||||
| -rw-r--r-- | src/bin/mobile/deployment.pri | 13 | ||||
| -rw-r--r-- | src/bin/mobile/main.cpp | 38 | ||||
| -rw-r--r-- | src/bin/mobile/main.qml | 172 | ||||
| -rw-r--r-- | src/bin/mobile/maincontroller.cpp | 44 | ||||
| -rw-r--r-- | src/bin/mobile/maincontroller.h | 29 | ||||
| -rw-r--r-- | src/bin/mobile/mobile.pro | 20 | ||||
| -rw-r--r-- | src/bin/mobile/mobile.qrc | 5 | ||||
| -rw-r--r-- | src/bin/mobile/qml.qrc | 6 | ||||
| -rw-r--r-- | src/bin/mobile/qml/main.qml | 17 | ||||
| -rw-r--r-- | src/bin/mobile/resources/images/add.png | bin | 0 -> 4696 bytes |
13 files changed, 557 insertions, 0 deletions
diff --git a/src/bin/mobile/CMakeLists.txt b/src/bin/mobile/CMakeLists.txt new file mode 100644 index 0000000..ddc0543 --- /dev/null +++ b/src/bin/mobile/CMakeLists.txt @@ -0,0 +1,109 @@ +cmake_minimum_required(VERSION 3.16) + +option(UPDATE_TRANSLATIONS "update Translation" OFF) +MESSAGE(STATUS "UPDATE TRANSLATIONS: ${UPDATE_TRANSLATIONS}") + + +project(diceGui) + + +# Find includes in corresponding build directories +set(CMAKE_INCLUDE_CURRENT_DIR ON) +# Instruct CMake to run moc automatically when needed. +set(CMAKE_AUTOMOC ON) + +# Find the QtWidgets library +find_package(Qt6 COMPONENTS Quick Qml Core Widgets Gui) +#find_package(Qt6QuickCompiler) + +set(EXECUTABLE_OUTPUT_PATH bin/) + +include_directories(${Qt5Core_INCLUDES} ${Qt5Widgets_INCLUDES} ${Qt5Gui_INCLUDES} ${Qt5Qml_INCLUDES} ${Qt5Quick_INCLUDES}../) +add_definitions(${Qt5Core_DEFINITIONS} ${Qt5Qml_DEFINITIONS} ${Qt5Quick_DEFINITIONS} ${Qt5Widgets_DEFINITIONS} ${Qt5Gui_DEFINITIONS} ) + +ADD_DEFINITIONS( + -std=c++11 +) + +set(diceGui_RESOURCES diceparser.qrc) +FIND_PACKAGE(Qt6LinguistTools) + + +IF(UPDATE_TRANSLATIONS) + MESSAGE( update Translation ) + FILE(GLOB_RECURSE translate_diceGui_SRCS ../*.cpp ../*.h) + SET(translate_SRCS ${translate_dice_SRCS}) + SET(diceGui_TS "${CMAKE_CURRENT_SOURCE_DIR}/i18n/diceGui_en.ts" "${CMAKE_CURRENT_SOURCE_DIR}/i18n/diceGui_fr.ts") +ELSE() + MESSAGE( NO updates for translations) + FILE(GLOB diceGui_TS "${CMAKE_CURRENT_SOURCE_DIR}/i18n/*.ts") +ENDIF(UPDATE_TRANSLATIONS) + +if(Qt5Core_FOUND) + + IF(UPDATE_TRANSLATIONS) + MESSAGE(status "find" ${diceGui_TS} ${translate_SRCS} ) + QT5_CREATE_TRANSLATION(diceGui_QM ${translate_SRCS} ${diceGui_TS}) + ELSE() + QT5_ADD_TRANSLATION(diceGui_QM ${diceGui_TS}) + ENDIF() + + QT5_ADD_RESOURCES(diceGui_RESOURCES_RCC ${diceGui_RESOURCES}) + + # guess plugins and libraries directory + set(QT_PLUGINS_DIR "${Qt5Core_DIR}/../../../plugins") + get_target_property(QT_LIBRARY_DIR Qt6::Core LOCATION) + get_filename_component(QT_LIBRARY_DIR ${QT_LIBRARY_DIR} PATH) +endif() + +SET( diceGui_sources + ../diceparser.cpp + ../range.cpp + ../booleancondition.cpp + ../validator.cpp + ../compositevalidator.cpp + ../operationcondition.cpp + ../die.cpp + ../parsingtoolbox.cpp + ../dicealias.cpp + ../result/result.cpp + ../result/scalarresult.cpp + ../result/stringresult.cpp + ../result/diceresult.cpp + ../node/countexecutenode.cpp + ../node/dicerollernode.cpp + ../node/executionnode.cpp + ../node/explodedicenode.cpp + ../node/helpnode.cpp + ../node/mergenode.cpp + ../node/jumpbackwardnode.cpp + ../node/keepdiceexecnode.cpp + ../node/listaliasnode.cpp + ../node/listsetrollnode.cpp + ../node/numbernode.cpp + ../node/parenthesesnode.cpp + ../node/paintnode.cpp + ../node/rerolldicenode.cpp + ../node/scalaroperatornode.cpp + ../node/sortresult.cpp + ../node/startingnode.cpp + ../node/ifnode.cpp + ../node/filternode.cpp + ../node/stringnode.cpp + ../node/splitnode.cpp + ../node/groupnode.cpp + ../node/variablenode.cpp + ../node/bind.cpp + main.cpp + maincontroller.cpp + commandmodel.cpp + ../highlightdice.cpp +) +qt5_add_resources(RESOURCE_ADDED mobile.qrc) + +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) + +#qt5_use_modules() diff --git a/src/bin/mobile/commandmodel.cpp b/src/bin/mobile/commandmodel.cpp new file mode 100644 index 0000000..7b50397 --- /dev/null +++ b/src/bin/mobile/commandmodel.cpp @@ -0,0 +1,54 @@ +/*************************************************************************** + * 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 "commandmodel.h" + +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/src/bin/mobile/commandmodel.h b/src/bin/mobile/commandmodel.h new file mode 100644 index 0000000..4037032 --- /dev/null +++ b/src/bin/mobile/commandmodel.h @@ -0,0 +1,50 @@ +/*************************************************************************** + * 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. * + ***************************************************************************/ +#ifndef COMMANDMODEL_H +#define COMMANDMODEL_H + +#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 diff --git a/src/bin/mobile/deployment.pri b/src/bin/mobile/deployment.pri new file mode 100644 index 0000000..265ce71 --- /dev/null +++ b/src/bin/mobile/deployment.pri @@ -0,0 +1,13 @@ +unix:!android { + isEmpty(target.path) { + qnx { + target.path = /tmp/$${TARGET}/bin + } else { + target.path = /opt/$${TARGET}/bin + } + export(target.path) + } + INSTALLS += target +} + +export(INSTALLS) diff --git a/src/bin/mobile/main.cpp b/src/bin/mobile/main.cpp new file mode 100644 index 0000000..9b81329 --- /dev/null +++ b/src/bin/mobile/main.cpp @@ -0,0 +1,38 @@ +/*************************************************************************** + * 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" + +int main(int argc, char* argv[]) +{ + QGuiApplication app(argc, argv); + + MainControler* main= new MainControler(); + + QQmlApplicationEngine engine; + main->initEngine(&engine); + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + + // main->setConnections(&engine); + + return app.exec(); +} diff --git a/src/bin/mobile/main.qml b/src/bin/mobile/main.qml new file mode 100644 index 0000000..700f3a7 --- /dev/null +++ b/src/bin/mobile/main.qml @@ -0,0 +1,172 @@ +import QtQuick 2.7 +import QtQuick.Window 2.2 + +Window { + id:root + visible: true + signal addRoll(string name, string cmd ) + signal roll(string cmd) + color: "black" + height: 1280 + width: 720 + + Column{ + + anchors.fill: parent + leftPadding: width*0.025 + rightPadding: width*0.025 + topPadding: width*0.025 + Rectangle { + height: parent.height*0.12 + width: parent.width*0.95 + Image { + anchors.fill: parent + horizontalAlignment: Image.AlignHCenter + verticalAlignment:Image.AlignVCenter + fillMode: Image.PreserveAspectFit + source: "qrc:/resources/images/add.png" + } + gradient: Gradient { + GradientStop { position: 0.0; color: "darkblue" } + GradientStop { position: 1.0; color: "blue" } + } + MouseArea { + anchors.fill: parent + onClicked:popupAdd.visible = true + } + } + + ListView { + model: _model + focus: true + height: parent.height*0.88 + width: parent.width*0.95 + delegate: Item{ + height: parent.height + width: parent.width + Column{ + width: parent.width + height: parent.height + Text{ + text: name + font.pointSize: 40 + color: "white" + + + } + Text{ + text: cmd + font.pointSize:30 + color: "white" + + } + } + MouseArea{ + anchors.fill:parent + onClicked: roll(cmd) + } + } + } + + } + Rectangle { + id: popupAdd + color: "black" + x: parent.width*0.1 + y: parent.height*0.1 + height: parent.height*0.80 + width: parent.width*0.80 + visible: false + border.color: "white" + border.width: 1 + + Column{ + id:form + anchors.top: parent.top + anchors.left: parent.left + anchors.right: parent.right + height: parent.height*0.80 + leftPadding: width*0.025 + rightPadding: width*0.025 + topPadding: width*0.025 + property alias name : nameInp + property alias cmd : cmdInp + Text { + text: qsTr("Name") + color: "white" + height: parent.height*0.1 + font.pointSize: 40 + } + Rectangle{ + height: parent.height*0.1 + width: parent.width*0.90 + border.color: "#BBBBBB" + border.width: 1 + color: "black" + TextInput{ + id: nameInp + color: "white" + anchors.fill: parent + font.pointSize: 40 + } + } + + Text { + text: qsTr("Command") + color: "white" + height: parent.height*0.1 + font.pointSize: 40 + } + Rectangle{ + height: parent.height*0.1 + width: parent.width*0.90 + border.color: "#BBBBBB" + border.width: 1 + color: "black" + TextInput{ + id: cmdInp + color: "white" + anchors.fill: parent + font.pointSize: 40 + } + } + } + + Rectangle { + color:"red" + id: cancel + anchors.top: form.bottom + anchors.left: form.left + anchors.right: form.horizontalCenter + anchors.bottom: parent.bottom + radius: height/2 + MouseArea { + anchors.fill: parent + onClicked:{ + nameInp.text="" + cmdInp.text="" + popupAdd.visible = false + } + } + } + Rectangle { + color:"green" + anchors.top: form.bottom + anchors.left: cancel.right + anchors.right: form.right + anchors.bottom: parent.bottom + radius: height/2 + MouseArea { + anchors.fill: parent + onClicked: + { + root.addRoll(nameInp,cmdInp.text); + nameInp.text="" + cmdInp.text="" + popupAdd.visible = false + } + } + + } + } +} diff --git a/src/bin/mobile/maincontroller.cpp b/src/bin/mobile/maincontroller.cpp new file mode 100644 index 0000000..6f301ff --- /dev/null +++ b/src/bin/mobile/maincontroller.cpp @@ -0,0 +1,44 @@ +#include "maincontroler.h" + +#include <QJSValue> +#include <QQmlEngine> + +MainControler::MainControler(QObject* parent) : QObject(parent) +{ + + m_diceParser= new DiceParser(); + qmlRegisterSingletonType("DiceParser", 1, 0, "Model", [](QQmlEngine* engine, QJSEngine* scriptEngine) -> QObject* { + Q_UNUSED(engine) + static CommandModel model; + static bool initialized= false; + if(!initialized) + { + model.insertCmd("L5R", "8D10e10k4"); + initialized= true; + } + return &model; + }); +} +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(); + for(int i= 0; i < m_diceParser->getStartNodeCount(); ++i) + { + // qDebug() << m_diceParser->getSumOfDiceResult(i); + } + } +} +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/src/bin/mobile/maincontroller.h b/src/bin/mobile/maincontroller.h new file mode 100644 index 0000000..43fc1ae --- /dev/null +++ b/src/bin/mobile/maincontroller.h @@ -0,0 +1,29 @@ +#ifndef MAINCONTROLER_H +#define MAINCONTROLER_H + +#include <QObject> +#include <QQmlApplicationEngine> + +#include "commandmodel.h" +#include "diceparser.h" + +class MainControler : public QObject +{ + Q_OBJECT +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/src/bin/mobile/mobile.pro b/src/bin/mobile/mobile.pro new file mode 100644 index 0000000..2e33522 --- /dev/null +++ b/src/bin/mobile/mobile.pro @@ -0,0 +1,20 @@ +TEMPLATE = app + +QT += qml quick +CONFIG += c++11 + +SOURCES += main.cpp maincontroler.cpp \ + commandmodel.cpp + +HEADERS += maincontroler.h \ + commandmodel.h + +RESOURCES += qml.qrc + +include(../diceparser.pri) + +# Additional import path used to resolve QML modules in Qt Creator's code model +QML_IMPORT_PATH = + +# Default rules for deployment. +include(deployment.pri) diff --git a/src/bin/mobile/mobile.qrc b/src/bin/mobile/mobile.qrc new file mode 100644 index 0000000..69145a8 --- /dev/null +++ b/src/bin/mobile/mobile.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/"> + <file>qml/main.qml</file> + </qresource> +</RCC> diff --git a/src/bin/mobile/qml.qrc b/src/bin/mobile/qml.qrc new file mode 100644 index 0000000..2cbbe08 --- /dev/null +++ b/src/bin/mobile/qml.qrc @@ -0,0 +1,6 @@ +<RCC> + <qresource prefix="/"> + <file>main.qml</file> + <file>resources/images/add.png</file> + </qresource> +</RCC> diff --git a/src/bin/mobile/qml/main.qml b/src/bin/mobile/qml/main.qml new file mode 100644 index 0000000..ed9d480 --- /dev/null +++ b/src/bin/mobile/qml/main.qml @@ -0,0 +1,17 @@ +import QtQuick 2.4 + +Item { + id:root + + ListView { + id: diceList + } + + Item{ + id: popupInput + + } + Item { + id: popupResult + } +} diff --git a/src/bin/mobile/resources/images/add.png b/src/bin/mobile/resources/images/add.png Binary files differnew file mode 100644 index 0000000..c8e1bd2 --- /dev/null +++ b/src/bin/mobile/resources/images/add.png |