Files
Upsilon/apps/probability/law/law_controller.cpp
Émilie Feral 7283a0c13a [escher] implement list view to inherit from table view
Change-Id: I4bee7292fa7d21ad4d24a86a287857309933d78f
2016-09-28 15:09:14 +02:00

94 lines
2.4 KiB
C++

#include "law_controller.h"
#include <assert.h>
#include "../app.h"
static const char * sMessages[] = {
"Loi Normale",
"Exponentielle",
"Student",
"Khi 2",
"Binomiale",
"Poisson",
"Geometrique"
};
Probability::LawController::LawController(Responder * parentResponder) :
ViewController(parentResponder),
m_listView(ListView(this, Metric::TopMargin, Metric::RightMargin,
Metric::BottomMargin, Metric::LeftMargin)),
m_activeCell(0)
{
m_messages = sMessages;
}
View * Probability::LawController::view() {
return &m_listView;
}
const char * Probability::LawController::title() const {
return "Type de Loi";
}
void Probability::LawController::didBecomeFirstResponder() {
setActiveCell(0);
}
void Probability::LawController::setActiveCell(int index) {
if (index < 0 || index >= k_totalNumberOfModels) {
return;
}
TableViewCell * previousCell = (TableViewCell *)(m_listView.cellAtIndex(m_activeCell));
previousCell->setHighlighted(false);
m_activeCell = index;
m_listView.scrollToRow(index);
TableViewCell * cell = (TableViewCell *)(m_listView.cellAtIndex(index));
cell->setHighlighted(true);
}
bool Probability::LawController::handleEvent(Ion::Events::Event event) {
switch (event) {
case Ion::Events::Event::DOWN_ARROW:
setActiveCell(m_activeCell+1);
return true;
case Ion::Events::Event::UP_ARROW:
setActiveCell(m_activeCell-1);
return true;
case Ion::Events::Event::ENTER:
((Probability::App *)app())->setLaw(App::Law::Normal);
return true;
default:
return false;
}
}
int Probability::LawController::numberOfRows() {
return k_totalNumberOfModels;
};
View * Probability::LawController::reusableCell(int index) {
assert(index >= 0);
assert(index < k_maxNumberOfCells);
return &m_cells[index];
}
int Probability::LawController::reusableCellCount() {
return k_maxNumberOfCells;
}
void Probability::LawController::willDisplayCellForIndex(View * cell, int index) {
TableViewCell * myCell = (TableViewCell *)cell;
myCell->textView()->setText(m_messages[index]);
if (m_activeCell == index) {
myCell->textView()->setBackgroundColor(Palette::FocusCellBackgroundColor);
} else {
myCell->textView()->setBackgroundColor(Palette::CellBackgroundColor);
}
myCell->textView()->setTextColor(KDColorBlack);
myCell->textView()->setAlignment(0., 0.5);
}
KDCoordinate Probability::LawController::cellHeight() {
return 35;
}