Numworks Epsilon  1.4.1
Graphing Calculator Operating System
main_controller.cpp
Go to the documentation of this file.
1 #include "main_controller.h"
2 #include "../global_preferences.h"
3 #include "../i18n.h"
4 #include "../../poincare/src/layout/baseline_relative_layout.h"
5 #include "../../poincare/src/layout/string_layout.h"
6 #include <assert.h>
7 #include <poincare.h>
8 
9 using namespace Poincare;
10 
11 namespace Settings {
12 
14 const SettingsMessageTree FloatDisplayModeChildren[3] = {SettingsMessageTree(I18n::Message::Auto), SettingsMessageTree(I18n::Message::Scientific), SettingsMessageTree(I18n::Message::SignificantFigures)};
15 const SettingsMessageTree complexFormatChildren[2] = {SettingsMessageTree(I18n::Message::Default), SettingsMessageTree(I18n::Message::Default)};
16 const SettingsMessageTree examChildren[1] = {SettingsMessageTree(I18n::Message::ActivateExamMode)};
17 const SettingsMessageTree aboutChildren[3] = {SettingsMessageTree(I18n::Message::SoftwareVersion), SettingsMessageTree(I18n::Message::SerialNumber), SettingsMessageTree(I18n::Message::FccId)};
18 
19 #if EPSILON_SOFTWARE_UPDATE_PROMPT
20 const SettingsMessageTree menu[8] =
21 #else
23 #endif
24  {SettingsMessageTree(I18n::Message::AngleUnit, angleChildren, 2), SettingsMessageTree(I18n::Message::DisplayMode, FloatDisplayModeChildren, 3), SettingsMessageTree(I18n::Message::ComplexFormat, complexFormatChildren, 2),
25  SettingsMessageTree(I18n::Message::Brightness), SettingsMessageTree(I18n::Message::Language), SettingsMessageTree(I18n::Message::ExamMode, examChildren, 1),
26 #if EPSILON_SOFTWARE_UPDATE_PROMPT
27  SettingsMessageTree(I18n::Message::UpdatePopUp),
28 #endif
29  SettingsMessageTree(I18n::Message::About, aboutChildren, 3)};
30 #if EPSILON_SOFTWARE_UPDATE_PROMPT
31 const SettingsMessageTree model = SettingsMessageTree(I18n::Message::SettingsApp, menu, 8);
32 #else
33 const SettingsMessageTree model = SettingsMessageTree(I18n::Message::SettingsApp, menu, 7);
34 #endif
35 
36 MainController::MainController(Responder * parentResponder) :
37  ViewController(parentResponder),
38 #if EPSILON_SOFTWARE_UPDATE_PROMPT
39  m_updateCell(I18n::Message::Default, KDText::FontSize::Large),
40 #endif
41  m_complexFormatCell(I18n::Message::Default, KDText::FontSize::Large),
42  m_brightnessCell(I18n::Message::Default, KDText::FontSize::Large),
43  m_complexFormatLayout(nullptr),
44  m_selectableTableView(this),
45  m_messageTreeModel((MessageTree *)&model),
46  m_subController(this),
47  m_languageController(this, 13)
48 {
49  for (int i = 0; i < k_numberOfSimpleChevronCells; i++) {
51  }
52 }
53 
55  if (m_complexFormatLayout) {
56  delete m_complexFormatLayout;
57  m_complexFormatLayout = nullptr;
58  }
59 }
60 
62  return &m_selectableTableView;
63 }
64 
66  if (selectedRow() < 0) {
68  }
69  app()->setFirstResponder(&m_selectableTableView);
70 }
71 
73  if (m_messageTreeModel->children(selectedRow())->numberOfChildren() == 0) {
74 #if EPSILON_SOFTWARE_UPDATE_PROMPT
75  if (m_messageTreeModel->children(selectedRow())->label() == I18n::Message::UpdatePopUp) {
76  if (event == Ion::Events::OK || event == Ion::Events::EXE) {
78  m_selectableTableView.reloadCellAtLocation(m_selectableTableView.selectedColumn(), m_selectableTableView.selectedRow());
79  return true;
80  }
81  return false;
82  }
83 #endif
84  if (m_messageTreeModel->children(selectedRow())->label() == I18n::Message::Brightness) {
85  if (event == Ion::Events::Right || event == Ion::Events::Left || event == Ion::Events::Plus || event == Ion::Events::Minus) {
87  int direction = (event == Ion::Events::Right || event == Ion::Events::Plus) ? delta : -delta;
89  m_selectableTableView.reloadCellAtLocation(m_selectableTableView.selectedColumn(), m_selectableTableView.selectedRow());
90  return true;
91  }
92  return false;
93  }
94  if (m_messageTreeModel->children(selectedRow())->label() == I18n::Message::Language) {
95  if (event == Ion::Events::OK || event == Ion::Events::EXE || event == Ion::Events::Right) {
96  stackController()->push(&m_languageController);
97  return true;
98  }
99  return false;
100  }
101  }
102  if (event == Ion::Events::OK || event == Ion::Events::EXE || event == Ion::Events::Right) {
103  m_subController.setMessageTreeModel(m_messageTreeModel->children(selectedRow()));
104  StackViewController * stack = stackController();
105  stack->push(&m_subController);
106  return true;
107  }
108  return false;
109 }
110 
112  return m_messageTreeModel->numberOfChildren();
113 };
114 
117 }
118 
120  return j*rowHeight(0);
121 }
122 
124  return offsetY/rowHeight(0);
125 }
126 
128  assert(index >= 0);
129  if (type == 0) {
130  assert(index < k_numberOfSimpleChevronCells);
131  return &m_cells[index];
132  }
133  assert(index == 0);
134  if (type == 2) {
135  return &m_brightnessCell;
136  }
137 #if EPSILON_SOFTWARE_UPDATE_PROMPT
138  if (type == 3) {
139  return &m_updateCell;
140  }
141 #endif
142  return &m_complexFormatCell;
143 }
144 
146  if (type == 0) {
147  return k_numberOfSimpleChevronCells;
148  }
149  return 1;
150 }
151 
153  if (j == 2) {
154  return 1;
155  }
156  if (j == 3) {
157  return 2;
158  }
159 #if EPSILON_SOFTWARE_UPDATE_PROMPT
160  if (j == 6) {
161  return 3;
162  }
163 #endif
164  return 0;
165 }
166 
168  MessageTableCell * myCell = (MessageTableCell *)cell;
169  myCell->setMessage(m_messageTreeModel->children(index)->label());
170 
171  if (index == 2) {
172  if (m_complexFormatLayout) {
173  delete m_complexFormatLayout;
174  m_complexFormatLayout = nullptr;
175  }
176  if (Preferences::sharedPreferences()->complexFormat() == Expression::ComplexFormat::Cartesian) {
177  const char text[] = {'a','+', Ion::Charset::IComplex, 'b', ' '};
178  m_complexFormatLayout = new StringLayout(text, sizeof(text), KDText::FontSize::Small);
179  } else {
180  const char base[] = {'r', Ion::Charset::Exponential};
181  const char superscript[] = {Ion::Charset::IComplex, Ion::Charset::SmallTheta, ' '};
182  m_complexFormatLayout = new BaselineRelativeLayout(new StringLayout(base, sizeof(base), KDText::FontSize::Small), new StringLayout(superscript, sizeof(superscript), KDText::FontSize::Small), BaselineRelativeLayout::Type::Superscript);
183  }
185  myExpCell->setExpression(m_complexFormatLayout);
186  return;
187  }
188  if (index == 3) {
190  GaugeView * myGauge = (GaugeView *)myGaugeCell->accessoryView();
191  myGauge->setLevel((float)GlobalPreferences::sharedGlobalPreferences()->brightnessLevel()/(float)Ion::Backlight::MaxBrightness);
192  return;
193  }
194  if (index == 4) {
196  static_cast<MessageTableCellWithChevronAndMessage *>(cell)->setSubtitle(I18n::LanguageNames[index]);
197  return;
198  }
199 #if EPSILON_SOFTWARE_UPDATE_PROMPT
200  if (index == 6) {
202  SwitchView * mySwitch = (SwitchView *)mySwitchCell->accessoryView();
203  mySwitch->setState(GlobalPreferences::sharedGlobalPreferences()->showUpdatePopUp());
204  return;
205  }
206 #endif
208  switch (index) {
209  case 0:
210  myTextCell->setSubtitle(m_messageTreeModel->children(index)->children((int)Preferences::sharedPreferences()->angleUnit())->label());
211  break;
212  case 1:
213  myTextCell->setSubtitle(m_messageTreeModel->children(index)->children((int)Preferences::sharedPreferences()->displayMode())->label());
214  break;
215  default:
216  myTextCell->setSubtitle(I18n::Message::Default);
217  break;
218  }
219 }
220 
222  m_selectableTableView.reloadData();
223 }
224 
225 StackViewController * MainController::stackController() const {
227 }
228 
229 }
constexpr Event Plus
Definition: events.h:107
Definition: i18n.h:6
#define assert(e)
Definition: assert.h:9
KDCoordinate rowHeight(int j) override
constexpr Event Minus
Definition: events.h:108
const SettingsMessageTree model
int reusableCellCount(int type) override
constexpr Event EXE
Definition: events.h:114
int16_t KDCoordinate
Definition: coordinate.h:6
void setMessageTreeModel(const MessageTree *messageTreeModel)
void push(ViewController *vc, KDColor textColor=Palette::SubTab, KDColor backgroundColor=KDColorWhite, KDColor separatorColor=Palette::GreyBright)
Responder * parentResponder() const
Definition: responder.cpp:12
const SettingsMessageTree angleChildren[2]
const ToolboxMessageTree menu[11]
void viewWillAppear() override
void willDisplayCellForIndex(HighlightCell *cell, int index) override
constexpr Expression::ComplexFormat Cartesian
int typeAtLocation(int i, int j) override
int numberOfChildren() const
Definition: message_tree.cpp:3
Definition: text.h:8
const SettingsMessageTree complexFormatChildren[2]
void reloadData(bool setFirstResponder=true)
const SettingsMessageTree aboutChildren[3]
void setShowUpdatePopUp(bool showUpdatePopUp)
I18n::Message label() const
Definition: message_tree.cpp:7
void reloadCellAtLocation(int i, int j)
Definition: table_view.cpp:49
int indexFromCumulatedHeight(KDCoordinate offsetY) override
constexpr Poincare::Expression::AngleUnit Radian
Definition: helper.h:4
void setBrightnessLevel(int brightnessLevel)
const SettingsMessageTree examChildren[1]
const SettingsMessageTree FloatDisplayModeChildren[3]
HighlightCell * reusableCell(int index, int type) override
void setMessageFontSize(KDText::FontSize fontSize)
constexpr Event Left
Definition: events.h:61
void didBecomeFirstResponder() override
constexpr uint8_t MaxBrightness
Definition: backlight.h:9
I18n::Language language() const
void setMessage(I18n::Message message)
static constexpr KDCoordinate ParameterCellHeight
Definition: metric.h:15
KDCoordinate cumulatedHeightFromIndex(int j) override
void setFirstResponder(Responder *responder)
Definition: app.cpp:62
Definition: view.h:23
constexpr Event Right
Definition: events.h:64
virtual const MessageTree * children(int index) const =0
void setExpression(Poincare::ExpressionLayout *expressionLayout)
void setLevel(float level)
Definition: gauge_view.cpp:28
App * app()
Definition: responder.cpp:77
constexpr Event OK
Definition: events.h:65
bool handleEvent(Ion::Events::Event event) override
static constexpr int NumberOfBrightnessStates
void setState(bool state)
Definition: switch_view.cpp:45
Definition: app.cpp:5
static GlobalPreferences * sharedGlobalPreferences()