From 282447d14ef44ef2f7155d1aa18588dd7e6804ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 9 Feb 2017 10:39:02 +0100 Subject: [PATCH] [apps/sequence/list] display the page change type when clicking on the sequence type row in the list parameters Change-Id: I11a2931cb81eda8a14a9e163ded93148dba5bb4c --- .../list/list_parameter_controller.cpp | 43 ++++++++++++------- .../sequence/list/list_parameter_controller.h | 4 ++ apps/shared/list_parameter_controller.cpp | 7 ++- 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/apps/sequence/list/list_parameter_controller.cpp b/apps/sequence/list/list_parameter_controller.cpp index 7a78f68ea..205a079ea 100644 --- a/apps/sequence/list/list_parameter_controller.cpp +++ b/apps/sequence/list/list_parameter_controller.cpp @@ -9,7 +9,8 @@ namespace Sequence { ListParameterController::ListParameterController(Responder * parentResponder, SequenceStore * sequenceStore) : Shared::ListParameterController(parentResponder, sequenceStore), - m_typeCell(ChevronExpressionMenuListCell((char *)"Type de suite")) + m_typeCell(ChevronExpressionMenuListCell((char *)"Type de suite")), + m_changeTypeParameterController(this) { } @@ -26,25 +27,15 @@ const char * ListParameterController::title() const { void ListParameterController::setSequence(Sequence * sequence) { setFunction(sequence); - if (m_typeLayout != nullptr) { - delete m_typeLayout; - m_typeLayout = nullptr; - } - if (sequence->type() == Sequence::Type::Explicite) { - m_typeLayout = new BaselineRelativeLayout(new StringLayout(sequence->name(), 1), new StringLayout("n", 1, KDText::FontSize::Small), BaselineRelativeLayout::Type::Subscript); - } - if (sequence->type() == Sequence::Type::SingleRecurrence) { - m_typeLayout = new BaselineRelativeLayout(new StringLayout(sequence->name(), 1), new StringLayout("n+1", 3, KDText::FontSize::Small), BaselineRelativeLayout::Type::Subscript); - } - if (sequence->type() == Sequence::Type::DoubleRecurrence) { - m_typeLayout = new BaselineRelativeLayout(new StringLayout(sequence->name(), 1), new StringLayout("n+2", 3, KDText::FontSize::Small), BaselineRelativeLayout::Type::Subscript); - } - m_typeCell.setExpression(m_typeLayout); + m_sequence = sequence; } bool ListParameterController::handleEvent(Ion::Events::Event event) { if (event == Ion::Events::OK && m_selectableTableView.selectedRow() == 3) { - return false; + StackViewController * stack = (StackViewController *)(parentResponder()); + m_changeTypeParameterController.setSequence(m_sequence); + stack->push(&m_changeTypeParameterController); + return true; } if (event == Ion::Events::OK && m_selectableTableView.selectedRow() == 2) { if (m_functionStore->numberOfFunctions() > 0) { @@ -72,4 +63,24 @@ int ListParameterController::reusableCellCount() { return k_totalNumberOfCell; } +void ListParameterController::willDisplayCellForIndex(TableViewCell * cell, int index) { + Shared::ListParameterController::willDisplayCellForIndex(cell, index); + if (cell == &m_typeCell && m_sequence != nullptr) { + if (m_typeLayout != nullptr) { + delete m_typeLayout; + m_typeLayout = nullptr; + } + if (m_sequence->type() == Sequence::Type::Explicite) { + m_typeLayout = new BaselineRelativeLayout(new StringLayout(m_sequence->name(), 1), new StringLayout("n", 1, KDText::FontSize::Small), BaselineRelativeLayout::Type::Subscript); + } + if (m_sequence->type() == Sequence::Type::SingleRecurrence) { + m_typeLayout = new BaselineRelativeLayout(new StringLayout(m_sequence->name(), 1), new StringLayout("n+1", 3, KDText::FontSize::Small), BaselineRelativeLayout::Type::Subscript); + } + if (m_sequence->type() == Sequence::Type::DoubleRecurrence) { + m_typeLayout = new BaselineRelativeLayout(new StringLayout(m_sequence->name(), 1), new StringLayout("n+2", 3, KDText::FontSize::Small), BaselineRelativeLayout::Type::Subscript); + } + m_typeCell.setExpression(m_typeLayout); + } +} + } diff --git a/apps/sequence/list/list_parameter_controller.h b/apps/sequence/list/list_parameter_controller.h index b35dd50a5..b5d06cb7e 100644 --- a/apps/sequence/list/list_parameter_controller.h +++ b/apps/sequence/list/list_parameter_controller.h @@ -4,6 +4,7 @@ #include "../../shared/list_parameter_controller.h" #include "../sequence.h" #include "../sequence_store.h" +#include "change_type_parameter_controller.h" namespace Sequence { @@ -17,10 +18,13 @@ public: int numberOfRows() override; TableViewCell * reusableCell(int index) override; int reusableCellCount() override; + void willDisplayCellForIndex(TableViewCell * cell, int index) override; private: constexpr static int k_totalNumberOfCell = 4; ChevronExpressionMenuListCell m_typeCell; Poincare::ExpressionLayout * m_typeLayout; + ChangeTypeParameterController m_changeTypeParameterController; + Sequence * m_sequence; }; } diff --git a/apps/shared/list_parameter_controller.cpp b/apps/shared/list_parameter_controller.cpp index 33714460b..f08722361 100644 --- a/apps/shared/list_parameter_controller.cpp +++ b/apps/shared/list_parameter_controller.cpp @@ -24,7 +24,11 @@ View * ListParameterController::view() { void ListParameterController::didBecomeFirstResponder() { m_selectableTableView.dataHasChanged(true); - m_selectableTableView.selectCellAtLocation(0, 0); + if (m_selectableTableView.selectedRow() == -1) { + m_selectableTableView.selectCellAtLocation(0, 0); + } else { + m_selectableTableView.selectCellAtLocation(m_selectableTableView.selectedColumn(), m_selectableTableView.selectedRow()); + } app()->setFirstResponder(&m_selectableTableView); } @@ -37,6 +41,7 @@ void ListParameterController::willDisplayCellForIndex(TableViewCell * cell, int void ListParameterController::setFunction(Function * function) { m_function = function; + m_selectableTableView.selectCellAtLocation(0, 0); } bool ListParameterController::handleEvent(Ion::Events::Event event) {