diff --git a/apps/sequence/Makefile b/apps/sequence/Makefile index 21ffd3e11..11a7a5d4a 100644 --- a/apps/sequence/Makefile +++ b/apps/sequence/Makefile @@ -2,6 +2,7 @@ app_objs += $(addprefix apps/sequence/,\ app.o\ list/list_controller.o\ list/type_parameter_controller.o\ + list/sequence_cell.o\ list/sequence_expression_cell.o\ list/sequence_title_cell.o\ values/values_controller.o\ diff --git a/apps/sequence/list/sequence_cell.cpp b/apps/sequence/list/sequence_cell.cpp new file mode 100644 index 000000000..c9eebbcf0 --- /dev/null +++ b/apps/sequence/list/sequence_cell.cpp @@ -0,0 +1,73 @@ +#include "sequence_cell.h" + +namespace Sequence { + +SequenceCell::SequenceCell() : + EvenOddCell(), + m_numberOfSubCells(1), + m_selectedSubCell(0), + m_sequence(nullptr) +{ +} + +int SequenceCell::numberOfSubCells() { + return m_numberOfSubCells; +} + +int SequenceCell::selectedSubCell() { + return m_selectedSubCell; +} + +void SequenceCell::selectSubCell(int selectedSubCell) { + m_selectedSubCell = selectedSubCell; + viewAtIndex(0)->setHighlighted(selectedSubCell == 0); + viewAtIndex(1)->setHighlighted(selectedSubCell == 1); + viewAtIndex(2)->setHighlighted(selectedSubCell == 2); + reloadCell(); +} + +void SequenceCell::setSequence(Sequence * sequence) { + m_sequence = sequence; + m_numberOfSubCells = (int)m_sequence->type()+1; + layoutSubviews(); +} + +void SequenceCell::setHighlighted(bool highlight) { + TableViewCell::setHighlighted(highlight); + viewAtIndex(0)->setHighlighted(false); + viewAtIndex(1)->setHighlighted(false); + viewAtIndex(2)->setHighlighted(false); + TableViewCell::setHighlighted(highlight); + if (isHighlighted()) { + viewAtIndex(m_selectedSubCell)->setHighlighted(true); + } + reloadCell(); +} + +void SequenceCell::setEven(bool even) { + EvenOddCell::setEven(even); + viewAtIndex(0)->setEven(even); + viewAtIndex(1)->setEven(even); + viewAtIndex(2)->setEven(even); + reloadCell(); +} + +int SequenceCell::numberOfSubviews() const { + return m_numberOfSubCells; +} + +View * SequenceCell::subviewAtIndex(int index) { + return viewAtIndex(index); +} + +void SequenceCell::layoutSubviews() { + KDCoordinate cellHeight = (bounds().height()-(m_numberOfSubCells-1)*k_separatorThickness)/m_numberOfSubCells; + KDRect expressionFrame(k_separatorThickness, 0, bounds().width() - k_separatorThickness, cellHeight); + viewAtIndex(0)->setFrame(expressionFrame); + expressionFrame = KDRect(k_separatorThickness, cellHeight+k_separatorThickness, bounds().width() - k_separatorThickness, cellHeight); + viewAtIndex(1)->setFrame(expressionFrame); + expressionFrame = KDRect(k_separatorThickness, 2*cellHeight+2*k_separatorThickness, bounds().width() - k_separatorThickness, cellHeight); + viewAtIndex(2)->setFrame(expressionFrame); +} + +} diff --git a/apps/sequence/list/sequence_cell.h b/apps/sequence/list/sequence_cell.h new file mode 100644 index 000000000..5b13f8d97 --- /dev/null +++ b/apps/sequence/list/sequence_cell.h @@ -0,0 +1,32 @@ +#ifndef SEQUENCE_SEQUENCE_CELL_H +#define SEQUENCE_SEQUENCE_CELL_H + +#include "../sequence.h" +#include + +namespace Sequence { + +class SequenceCell : public EvenOddCell { +public: + SequenceCell(); + virtual void setSequence(Sequence * sequence); + int numberOfSubCells(); + int selectedSubCell(); + void selectSubCell(int index); + void setHighlighted(bool highlight) override; + void setEven(bool even) override; + int numberOfSubviews() const override; + View * subviewAtIndex(int index) override; + void layoutSubviews() override; +protected: + constexpr static KDCoordinate k_separatorThickness = 1; + int m_numberOfSubCells; + int m_selectedSubCell; + Sequence * m_sequence; +private: + virtual EvenOddCell * viewAtIndex(int index) = 0; +}; + +} + +#endif