diff --git a/apps/solver/Makefile b/apps/solver/Makefile new file mode 100644 index 000000000..7fa8dab15 --- /dev/null +++ b/apps/solver/Makefile @@ -0,0 +1,18 @@ +snapshots += Solver::App::Snapshot +snapshot_headers += apps/solver/app.h + +app_objs += $(addprefix apps/solver/,\ + app.o\ + equation_store.o\ + list_controller.o\ +) + +i18n_files += $(addprefix apps/solver/,\ + base.de.i18n\ + base.en.i18n\ + base.es.i18n\ + base.fr.i18n\ + base.pt.i18n\ +) + +app_images += apps/solver/solver_icon.png diff --git a/apps/solver/app.cpp b/apps/solver/app.cpp new file mode 100644 index 000000000..5a554a5c6 --- /dev/null +++ b/apps/solver/app.cpp @@ -0,0 +1,68 @@ +#include "app.h" +#include "../i18n.h" +#include "solver_icon.h" + +using namespace Shared; + +namespace Solver { + +I18n::Message App::Descriptor::name() { + return I18n::Message::SolverApp; +} + +I18n::Message App::Descriptor::upperName() { + return I18n::Message::SolverAppCapital; +} + +const Image * App::Descriptor::icon() { + return ImageStore::SolverIcon; +} + +App::Snapshot::Snapshot() : + m_equationStore() +{ +} + +App * App::Snapshot::unpack(Container * container) { + return new App(container, this); +} + +App::Descriptor * App::Snapshot::descriptor() { + static Descriptor descriptor; + return &descriptor; +} + +void App::Snapshot::reset() { + // Delete all equations + m_equationStore.removeAll(); +} + +void App::Snapshot::tidy() { + // Delete all expressions of equations + m_equationStore.tidy(); +} + +App::App(Container * container, Snapshot * snapshot) : + ExpressionFieldDelegateApp(container, snapshot, &m_inputViewController), + m_listController(&m_stackViewController, snapshot->equationStore(), &m_listFooter), + m_listFooter(&m_stackViewController, &m_listController, &m_listController, ButtonRowController::Position::Bottom, ButtonRowController::Style::EmbossedGrey), + m_stackViewController(&m_inputViewController, &m_listFooter), + m_inputViewController(&m_modalViewController, &m_stackViewController, this, this) +{ +} + +void App::willBecomeInactive() { + if (m_modalViewController.isDisplayingModal()) { + m_modalViewController.dismissModalViewController(); + } + if (inputViewController()->isDisplayingModal()) { + inputViewController()->abortEditionAndDismiss(); + } + ::App::willBecomeInactive(); +} + +const char * App::XNT() { + return "x"; +} + +} diff --git a/apps/solver/app.h b/apps/solver/app.h new file mode 100644 index 000000000..bb83f8b90 --- /dev/null +++ b/apps/solver/app.h @@ -0,0 +1,43 @@ +#ifndef SOLVER_SOLVER_APP_H +#define SOLVER_SOLVER_APP_H + +#include +#include "../shared/expression_field_delegate_app.h" +#include "list_controller.h" +#include "equation_store.h" + +namespace Solver { + +class App : public Shared::ExpressionFieldDelegateApp { +public: + class Descriptor : public ::App::Descriptor { + public: + I18n::Message name() override; + I18n::Message upperName() override; + const Image * icon() override; + }; + class Snapshot : public ::App::Snapshot { + public: + Snapshot(); + App * unpack(Container * container) override; + Descriptor * descriptor() override; + void reset() override; + EquationStore * equationStore() { return &m_equationStore; } + private: + void tidy() override; + EquationStore m_equationStore; + }; + InputViewController * inputViewController() { return &m_inputViewController; } + void willBecomeInactive() override; + const char * XNT() override; +private: + App(Container * container, Snapshot * snapshot); + ListController m_listController; + ButtonRowController m_listFooter; + StackViewController m_stackViewController; + InputViewController m_inputViewController; +}; + +} + +#endif diff --git a/apps/solver/base.de.i18n b/apps/solver/base.de.i18n new file mode 100644 index 000000000..56ed27fb0 --- /dev/null +++ b/apps/solver/base.de.i18n @@ -0,0 +1,4 @@ +SolverApp = "Equation" +SolverAppCapital = "EQUATION" +AddEquation = "Ajouter une équation" +Resolve = "Résoudre" diff --git a/apps/solver/base.en.i18n b/apps/solver/base.en.i18n new file mode 100644 index 000000000..f809f6f93 --- /dev/null +++ b/apps/solver/base.en.i18n @@ -0,0 +1,4 @@ +SolverApp = "Equation" +SolverAppCapital = "EQUATION" +AddEquation = "Ajouter une équation" +Resolve = "Résoudre l'équation" diff --git a/apps/solver/base.es.i18n b/apps/solver/base.es.i18n new file mode 100644 index 000000000..56ed27fb0 --- /dev/null +++ b/apps/solver/base.es.i18n @@ -0,0 +1,4 @@ +SolverApp = "Equation" +SolverAppCapital = "EQUATION" +AddEquation = "Ajouter une équation" +Resolve = "Résoudre" diff --git a/apps/solver/base.fr.i18n b/apps/solver/base.fr.i18n new file mode 100644 index 000000000..f809f6f93 --- /dev/null +++ b/apps/solver/base.fr.i18n @@ -0,0 +1,4 @@ +SolverApp = "Equation" +SolverAppCapital = "EQUATION" +AddEquation = "Ajouter une équation" +Resolve = "Résoudre l'équation" diff --git a/apps/solver/base.pt.i18n b/apps/solver/base.pt.i18n new file mode 100644 index 000000000..56ed27fb0 --- /dev/null +++ b/apps/solver/base.pt.i18n @@ -0,0 +1,4 @@ +SolverApp = "Equation" +SolverAppCapital = "EQUATION" +AddEquation = "Ajouter une équation" +Resolve = "Résoudre" diff --git a/apps/solver/equation.h b/apps/solver/equation.h new file mode 100644 index 000000000..d2c57f4c1 --- /dev/null +++ b/apps/solver/equation.h @@ -0,0 +1,13 @@ +#ifndef SOLVER_EQUATION_h +#define SOLVER_EQUATION_h + +#include "../shared/expression_model.h" + +namespace Solver { + +class Equation : public Shared::ExpressionModel { +}; + +} + +#endif diff --git a/apps/solver/equation_store.cpp b/apps/solver/equation_store.cpp new file mode 100644 index 000000000..f2a3e2a56 --- /dev/null +++ b/apps/solver/equation_store.cpp @@ -0,0 +1,14 @@ +#include "equation_store.h" + +namespace Solver { + +Equation * EquationStore::emptyModel() { + static Equation e; + return &e; +} + +void EquationStore::setModelAtIndex(Shared::ExpressionModel * e, int i) { + m_equations[i] = *(static_cast(e));; +} + +} diff --git a/apps/solver/equation_store.h b/apps/solver/equation_store.h new file mode 100644 index 000000000..ab190c131 --- /dev/null +++ b/apps/solver/equation_store.h @@ -0,0 +1,30 @@ +#ifndef SOLVER_EQUATION_STORE_H +#define SOLVER_EQUATION_STORE_H + +#include "equation.h" +#include "../shared/expression_model_store.h" +#include + +namespace Solver { + +class EquationStore : public Shared::ExpressionModelStore { +public: + EquationStore() {} + Equation * modelAtIndex(int i) override { + assert(i>=0 && i + +using namespace Shared; + +namespace Solver { + +ListController::ListController(Responder * parentResponder, EquationStore * equationStore, ButtonRowController * footer) : + ExpressionModelListController(parentResponder, I18n::Message::AddEquation), + ButtonRowDelegate(nullptr, footer), + m_equationStore(equationStore), + m_resolveButton(this, I18n::Message::Resolve, Invocation([](void * context, void * sender) { + ListController * list = (ListController *)context; + StackViewController * stackController = list->stackController(); + // TODO + //stackController->push(list->solutionPage ??) + }, this), KDText::FontSize::Small, Palette::PurpleBright) +{ +} + +int ListController::numberOfButtons(ButtonRowController::Position position) const { + if (position == ButtonRowController::Position::Bottom) { + return 1; + } + return 0; +} + +Button * ListController::buttonAtIndex(int index, ButtonRowController::Position position) const { + if (position == ButtonRowController::Position::Top) { + return nullptr; + } + return const_cast