Blame view

epsilon-master/apps/shared/list_parameter_controller.cpp 3.36 KB
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
  #include "list_parameter_controller.h"
  #include <assert.h>
  
  namespace Shared {
  
  ListParameterController::ListParameterController(Responder * parentResponder, FunctionStore * functionStore, I18n::Message functionColorMessage, I18n::Message deleteFunctionMessage, SelectableTableViewDelegate * tableDelegate) :
    ViewController(parentResponder),
    m_selectableTableView(this, this, this, tableDelegate),
    m_functionStore(functionStore),
    m_function(nullptr),
  #if FUNCTION_COLOR_CHOICE
    m_colorCell(functionColorMessage),
  #endif
    m_enableCell(I18n::Message::ActivateDesactivate),
    m_deleteCell(deleteFunctionMessage)
  {
  }
  
  const char * ListParameterController::title() {
    return I18n::translate(I18n::Message::FunctionOptions);
  }
  
  View * ListParameterController::view() {
    return &m_selectableTableView;
  }
  
  void ListParameterController::didBecomeFirstResponder() {
    app()->setFirstResponder(&m_selectableTableView);
  }
  
  void ListParameterController::viewWillAppear() {
    ViewController::viewWillAppear();
    if (selectedRow() == -1) {
      selectCellAtLocation(0, 0);
    } else {
      selectCellAtLocation(selectedColumn(), selectedRow());
    }
    m_selectableTableView.reloadData();
  }
  
  void ListParameterController::willDisplayCellForIndex(HighlightCell * cell, int index) {
    if (cell == &m_enableCell) {
      SwitchView * switchView = (SwitchView *)m_enableCell.accessoryView();
      switchView->setState(m_function->isActive());
    }
  }
  
  void ListParameterController::setFunction(Function * function) {
    m_function = function;
    selectCellAtLocation(0, 0);
  }
  
  bool ListParameterController::handleEvent(Ion::Events::Event event) {
    if (event == Ion::Events::OK || event == Ion::Events::EXE) {
      return handleEnterOnRow(selectedRow());
    }
    return false;
  }
  
  int ListParameterController::numberOfRows() {
    return k_totalNumberOfCell;
  };
  
  HighlightCell * ListParameterController::reusableCell(int index) {
    assert(index >= 0);
    assert(index < k_totalNumberOfCell);
  #if FUNCTION_COLOR_CHOICE
    HighlightCell * cells[] = {&m_colorCell, &m_enableCell, &m_deleteCell};
  #else
    HighlightCell * cells[] = {&m_enableCell, &m_deleteCell};
  #endif
    return cells[index];
  }
  
  int ListParameterController::reusableCellCount() {
    return k_totalNumberOfCell;
  }
  
  KDCoordinate ListParameterController::cellHeight() {
    return Metric::ParameterCellHeight;
  }
  
  bool ListParameterController::handleEnterOnRow(int rowIndex) {
    switch (rowIndex) {
  #if FUNCTION_COLOR_CHOICE
      case 0:
      /* TODO: implement function color choice */
        return true;
      case 1:
  #else
      case 0:
  #endif
        m_function->setActive(!m_function->isActive());
        m_selectableTableView.reloadData();
        return true;
  #if FUNCTION_COLOR_CHOICE
        case 2:
  #else
        case 1:
  #endif
      {
        if (m_functionStore->numberOfModels() > 1) {
          m_functionStore->removeModel(m_function);
          StackViewController * stack = (StackViewController *)(parentResponder());
          stack->pop();
          return true;
        } else {
          if (m_functionStore->numberOfDefinedModels() == 1) {
            Function * f = m_functionStore->definedFunctionAtIndex(0);
            f->setContent("");
            StackViewController * stack = (StackViewController *)(parentResponder());
            stack->pop();
            return true;
          }
          app()->displayWarning(I18n::Message::NoFunctionToDelete);
          return true;
        }
    }
    default:
      return false;
    }
  }
  
  }