6663b6c9
adorian
projet complet av...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
#include "main_controller.h"
#include "helpers.h"
#include "../global_preferences.h"
#include "../i18n.h"
#include <assert.h>
using namespace Poincare;
namespace Settings {
const SettingsMessageTree angleChildren[2] = {SettingsMessageTree(I18n::Message::Degres), SettingsMessageTree(I18n::Message::Radian)};
const SettingsMessageTree editionModeChildren[2] = {SettingsMessageTree(I18n::Message::EditionLinear), SettingsMessageTree(I18n::Message::Edition2D)};
const SettingsMessageTree floatDisplayModeChildren[3] = {SettingsMessageTree(I18n::Message::Auto), SettingsMessageTree(I18n::Message::Scientific), SettingsMessageTree(I18n::Message::SignificantFigures)};
const SettingsMessageTree complexFormatChildren[2] = {SettingsMessageTree(I18n::Message::Default), SettingsMessageTree(I18n::Message::Default)};
const SettingsMessageTree examChildren[1] = {SettingsMessageTree(I18n::Message::ActivateExamMode)};
const SettingsMessageTree aboutChildren[3] = {SettingsMessageTree(I18n::Message::SoftwareVersion), SettingsMessageTree(I18n::Message::SerialNumber), SettingsMessageTree(I18n::Message::FccId)};
#if EPSILON_SOFTWARE_UPDATE_PROMPT
const SettingsMessageTree menu[9] =
#else
const SettingsMessageTree menu[8] =
#endif
{SettingsMessageTree(I18n::Message::AngleUnit, angleChildren, 2),
SettingsMessageTree(I18n::Message::DisplayMode, floatDisplayModeChildren, 3),
SettingsMessageTree(I18n::Message::EditionMode, editionModeChildren, 2),
SettingsMessageTree(I18n::Message::ComplexFormat, complexFormatChildren, 2),
SettingsMessageTree(I18n::Message::Brightness),
SettingsMessageTree(I18n::Message::Language),
SettingsMessageTree(I18n::Message::ExamMode, examChildren, 1),
#if EPSILON_SOFTWARE_UPDATE_PROMPT
SettingsMessageTree(I18n::Message::UpdatePopUp),
#endif
SettingsMessageTree(I18n::Message::About, aboutChildren, 3)};
#if EPSILON_SOFTWARE_UPDATE_PROMPT
const SettingsMessageTree model = SettingsMessageTree(I18n::Message::SettingsApp, menu, 9);
#else
const SettingsMessageTree model = SettingsMessageTree(I18n::Message::SettingsApp, menu, 8);
#endif
MainController::MainController(Responder * parentResponder) :
ViewController(parentResponder),
#if EPSILON_SOFTWARE_UPDATE_PROMPT
m_updateCell(I18n::Message::Default, KDText::FontSize::Large),
#endif
m_complexFormatCell(I18n::Message::Default, KDText::FontSize::Large),
m_brightnessCell(I18n::Message::Default, KDText::FontSize::Large),
m_complexFormatLayout(nullptr),
m_selectableTableView(this),
m_messageTreeModel((MessageTree *)&model),
m_subController(this),
m_languageController(this, 13)
{
for (int i = 0; i < k_numberOfSimpleChevronCells; i++) {
m_cells[i].setMessageFontSize(KDText::FontSize::Large);
}
}
MainController::~MainController() {
if (m_complexFormatLayout) {
delete m_complexFormatLayout;
m_complexFormatLayout = nullptr;
}
}
View * MainController::view() {
return &m_selectableTableView;
}
void MainController::didBecomeFirstResponder() {
if (selectedRow() < 0) {
selectCellAtLocation(0, 0);
}
app()->setFirstResponder(&m_selectableTableView);
}
bool MainController::handleEvent(Ion::Events::Event event) {
if (m_messageTreeModel->children(selectedRow())->numberOfChildren() == 0) {
#if EPSILON_SOFTWARE_UPDATE_PROMPT
if (m_messageTreeModel->children(selectedRow())->label() == I18n::Message::UpdatePopUp) {
if (event == Ion::Events::OK || event == Ion::Events::EXE) {
GlobalPreferences::sharedGlobalPreferences()->setShowUpdatePopUp(!GlobalPreferences::sharedGlobalPreferences()->showUpdatePopUp());
m_selectableTableView.reloadCellAtLocation(m_selectableTableView.selectedColumn(), m_selectableTableView.selectedRow());
return true;
}
return false;
}
#endif
if (m_messageTreeModel->children(selectedRow())->label() == I18n::Message::Brightness) {
if (event == Ion::Events::Right || event == Ion::Events::Left || event == Ion::Events::Plus || event == Ion::Events::Minus) {
int delta = Ion::Backlight::MaxBrightness/GlobalPreferences::NumberOfBrightnessStates;
int direction = (event == Ion::Events::Right || event == Ion::Events::Plus) ? delta : -delta;
GlobalPreferences::sharedGlobalPreferences()->setBrightnessLevel(GlobalPreferences::sharedGlobalPreferences()->brightnessLevel()+direction);
m_selectableTableView.reloadCellAtLocation(m_selectableTableView.selectedColumn(), m_selectableTableView.selectedRow());
return true;
}
return false;
}
if (m_messageTreeModel->children(selectedRow())->label() == I18n::Message::Language) {
if (event == Ion::Events::OK || event == Ion::Events::EXE || event == Ion::Events::Right) {
stackController()->push(&m_languageController);
return true;
}
return false;
}
}
if (event == Ion::Events::OK || event == Ion::Events::EXE || event == Ion::Events::Right) {
m_subController.setMessageTreeModel(m_messageTreeModel->children(selectedRow()));
StackViewController * stack = stackController();
stack->push(&m_subController);
return true;
}
return false;
}
int MainController::numberOfRows() {
return m_messageTreeModel->numberOfChildren();
};
KDCoordinate MainController::rowHeight(int j) {
return Metric::ParameterCellHeight;
}
KDCoordinate MainController::cumulatedHeightFromIndex(int j) {
return j*rowHeight(0);
}
int MainController::indexFromCumulatedHeight(KDCoordinate offsetY) {
return offsetY/rowHeight(0);
}
HighlightCell * MainController::reusableCell(int index, int type) {
assert(index >= 0);
if (type == 0) {
assert(index < k_numberOfSimpleChevronCells);
return &m_cells[index];
}
assert(index == 0);
if (type == 2) {
return &m_brightnessCell;
}
#if EPSILON_SOFTWARE_UPDATE_PROMPT
if (type == 3) {
return &m_updateCell;
}
#endif
return &m_complexFormatCell;
}
int MainController::reusableCellCount(int type) {
if (type == 0) {
return k_numberOfSimpleChevronCells;
}
return 1;
}
int MainController::typeAtLocation(int i, int j) {
if (j == 3) {
return 1;
}
if (j == 4) {
return 2;
}
#if EPSILON_SOFTWARE_UPDATE_PROMPT
if (j == 7) {
return 3;
}
#endif
return 0;
}
void MainController::willDisplayCellForIndex(HighlightCell * cell, int index) {
MessageTableCell * myCell = (MessageTableCell *)cell;
myCell->setMessage(m_messageTreeModel->children(index)->label());
if (index == 3) {
if (m_complexFormatLayout) {
delete m_complexFormatLayout;
m_complexFormatLayout = nullptr;
}
if (Preferences::sharedPreferences()->complexFormat() == Expression::ComplexFormat::Cartesian) {
m_complexFormatLayout = Helpers::CartesianComplexFormat(KDText::FontSize::Small);
} else {
m_complexFormatLayout = Helpers::PolarComplexFormat(KDText::FontSize::Small);
}
MessageTableCellWithChevronAndExpression * myExpCell = (MessageTableCellWithChevronAndExpression *)cell;
myExpCell->setExpressionLayout(m_complexFormatLayout);
return;
}
if (index == 4) {
MessageTableCellWithGauge * myGaugeCell = (MessageTableCellWithGauge *)cell;
GaugeView * myGauge = (GaugeView *)myGaugeCell->accessoryView();
myGauge->setLevel((float)GlobalPreferences::sharedGlobalPreferences()->brightnessLevel()/(float)Ion::Backlight::MaxBrightness);
return;
}
if (index == 5) {
int index = (int)GlobalPreferences::sharedGlobalPreferences()->language()-1;
static_cast<MessageTableCellWithChevronAndMessage *>(cell)->setSubtitle(I18n::LanguageNames[index]);
return;
}
#if EPSILON_SOFTWARE_UPDATE_PROMPT
if (index == 7) {
MessageTableCellWithSwitch * mySwitchCell = (MessageTableCellWithSwitch *)cell;
SwitchView * mySwitch = (SwitchView *)mySwitchCell->accessoryView();
mySwitch->setState(GlobalPreferences::sharedGlobalPreferences()->showUpdatePopUp());
return;
}
#endif
MessageTableCellWithChevronAndMessage * myTextCell = (MessageTableCellWithChevronAndMessage *)cell;
switch (index) {
case 0:
myTextCell->setSubtitle(m_messageTreeModel->children(index)->children((int)Preferences::sharedPreferences()->angleUnit())->label());
break;
case 1:
myTextCell->setSubtitle(m_messageTreeModel->children(index)->children((int)Preferences::sharedPreferences()->displayMode())->label());
break;
case 2:
myTextCell->setSubtitle(m_messageTreeModel->children(index)->children((int)Preferences::sharedPreferences()->editionMode())->label());
break;
default:
myTextCell->setSubtitle(I18n::Message::Default);
break;
}
}
void MainController::viewWillAppear() {
m_selectableTableView.reloadData();
}
StackViewController * MainController::stackController() const {
return (StackViewController *)parentResponder();
}
}
|