diff --git a/apps/Makefile b/apps/Makefile index 912c84e42..9923f3e55 100644 --- a/apps/Makefile +++ b/apps/Makefile @@ -1,7 +1,7 @@ include apps/home/Makefile include apps/graph/Makefile include apps/probability/Makefile -include apps/calcul/Makefile +include apps/calculation/Makefile #include apps/picview/Makefile app_objs += $(addprefix apps/,\ diff --git a/apps/apps_container.cpp b/apps/apps_container.cpp index daf5a5814..ce14ba17b 100644 --- a/apps/apps_container.cpp +++ b/apps/apps_container.cpp @@ -7,7 +7,7 @@ AppsContainer::AppsContainer() : Container(), m_homeApp(this), m_graphApp(&m_context), - m_calculApp(&m_context), + m_calculationApp(&m_context), m_context(Context()) { } @@ -21,7 +21,7 @@ App * AppsContainer::appAtIndex(int index) { &m_homeApp, &m_graphApp, &m_probabilityApp, - &m_calculApp, + &m_calculationApp, }; assert(sizeof(apps)/sizeof(apps[0]) == k_numberOfApps); assert(index >= 0 && index < k_numberOfApps); diff --git a/apps/apps_container.h b/apps/apps_container.h index 12eeb2a6d..a88e540d6 100644 --- a/apps/apps_container.h +++ b/apps/apps_container.h @@ -4,7 +4,7 @@ #include "home/app.h" #include "graph/app.h" #include "probability/app.h" -#include "calcul/app.h" +#include "calculation/app.h" #define USE_PIC_VIEW_APP 0 #if USE_PIC_VIEW_APP @@ -24,7 +24,7 @@ private: Home::App m_homeApp; Graph::App m_graphApp; Probability::App m_probabilityApp; - Calcul::App m_calculApp; + Calculation::App m_calculationApp; #if USE_PIC_VIEW_APP PicViewApp m_picViewApp; #endif diff --git a/apps/calcul/Makefile b/apps/calcul/Makefile deleted file mode 100644 index f129f6370..000000000 --- a/apps/calcul/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -app_objs += $(addprefix apps/calcul/,\ - app.o\ - calcul.o\ - calcul_store.o\ - history_view_cell.o\ - history_controller.o\ - edit_expression_controller.o\ -) - -inline_images += apps/calcul/calcul_icon.png - diff --git a/apps/calcul/calcul_store.cpp b/apps/calcul/calcul_store.cpp deleted file mode 100644 index e66e63047..000000000 --- a/apps/calcul/calcul_store.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include "calcul_store.h" -#include - -namespace Calcul { - -CalculStore::CalculStore() : - m_numberOfCalculs(0) -{ -} - -Calcul * CalculStore::calculAtIndex(int i) { - assert(i>=0 && i=0 && i -namespace Calcul { +namespace Calculation { class App : public ::App { public: @@ -15,7 +15,7 @@ protected: ViewController * rootViewController() override; private: Context * m_globalContext; - CalculStore m_calculStore; + CalculationStore m_calculationStore; HistoryController m_historyController; EditExpressionController m_editExpressionController; }; diff --git a/apps/calcul/calcul.cpp b/apps/calculation/calculation.cpp similarity index 65% rename from apps/calcul/calcul.cpp rename to apps/calculation/calculation.cpp index 666429b00..c18ff004e 100644 --- a/apps/calcul/calcul.cpp +++ b/apps/calculation/calculation.cpp @@ -1,9 +1,9 @@ -#include "calcul.h" +#include "calculation.h" #include -namespace Calcul { +namespace Calculation { -Calcul::Calcul() : +Calculation::Calculation() : m_text(""), m_expression(nullptr), m_layout(nullptr), @@ -11,7 +11,7 @@ Calcul::Calcul() : { } -void Calcul::setContent(const char * c, Context * context) { +void Calculation::setContent(const char * c, Context * context) { strlcpy(m_text, c, sizeof(m_text)); if (m_expression != nullptr) { delete m_expression; @@ -24,7 +24,7 @@ void Calcul::setContent(const char * c, Context * context) { m_evaluation = m_expression->approximate(*context); } -Calcul::~Calcul() { +Calculation::~Calculation() { if (m_layout != nullptr) { delete m_layout; } @@ -33,19 +33,19 @@ Calcul::~Calcul() { } } -const char * Calcul::text() { +const char * Calculation::text() { return m_text; } -Expression * Calcul::expression() { +Expression * Calculation::expression() { return m_expression; } -ExpressionLayout * Calcul::layout() { +ExpressionLayout * Calculation::layout() { return m_layout; } -Float * Calcul::evaluation() { +Float * Calculation::evaluation() { return &m_evaluation; } diff --git a/apps/calcul/calcul.h b/apps/calculation/calculation.h similarity index 66% rename from apps/calcul/calcul.h rename to apps/calculation/calculation.h index d2defa005..f7baa3eca 100644 --- a/apps/calcul/calcul.h +++ b/apps/calculation/calculation.h @@ -1,14 +1,14 @@ -#ifndef CALCUL_CALCUL_H -#define CALCUL_CALCUL_H +#ifndef CALCULATION_CALCULATION_H +#define CALCULATION_CALCULATION_H #include -namespace Calcul { +namespace Calculation { -class Calcul { +class Calculation { public: - Calcul(); - ~Calcul(); // Delete expression and layout, if needed + Calculation(); + ~Calculation(); // Delete expression and layout, if needed const char * text(); Expression * expression(); ExpressionLayout * layout(); diff --git a/apps/calcul/calcul_icon.png b/apps/calculation/calculation_icon.png similarity index 100% rename from apps/calcul/calcul_icon.png rename to apps/calculation/calculation_icon.png diff --git a/apps/calculation/calculation_store.cpp b/apps/calculation/calculation_store.cpp new file mode 100644 index 000000000..143e7a047 --- /dev/null +++ b/apps/calculation/calculation_store.cpp @@ -0,0 +1,49 @@ +#include "calculation_store.h" +#include + +namespace Calculation { + +CalculationStore::CalculationStore() : + m_numberOfCalculations(0), + m_startIndex(0) +{ +} + +Calculation * CalculationStore::calculationAtIndex(int i) { + assert(i>=0 && i= k_maxNumberOfCalculations) { + for (int k = 0; k < k_maxNumberOfCalculations; k++) { + m_calculations[k] = m_calculations[k+1]; + } + m_numberOfCalculations--; + } + Calculation addedCalculation = Calculation(); + m_calculations[m_numberOfCalculations] = addedCalculation; + Calculation * result = &m_calculations[m_numberOfCalculations]; + m_numberOfCalculations++; + return result; +} + +void CalculationStore::removeCalculation(Calculation * c) { + int i = 0; + while (&m_calculations[i] != c && i < m_numberOfCalculations) { + i++; + } + assert(i>=0 && i -namespace Calcul { +namespace Calculation { EditExpressionController::ContentView::ContentView(View * subview) : View(), @@ -39,11 +39,11 @@ TextField * EditExpressionController::ContentView::textField() { return &m_textField; } -EditExpressionController::EditExpressionController(Responder * parentResponder, HistoryController * historyController, CalculStore * calculStore) : +EditExpressionController::EditExpressionController(Responder * parentResponder, HistoryController * historyController, CalculationStore * calculationStore) : ViewController(parentResponder), m_contentView(historyController->view()), m_historyController(historyController), - m_calculStore(calculStore) + m_calculationStore(calculationStore) { m_contentView.textField()->setParentResponder(this); } @@ -68,9 +68,9 @@ bool EditExpressionController::handleEvent(Ion::Events::Event event) { switch (event) { case Ion::Events::Event::ENTER: { - Calcul * calcul = m_calculStore->addEmptyCalcul(); - App * calculApp = (App *)app(); - calcul->setContent(textBody(), calculApp->globalContext()); + Calculation * calculation = m_calculationStore->addEmptyCalculation(); + App * calculationApp = (App *)app(); + calculation->setContent(textBody(), calculationApp->globalContext()); m_historyController->reload(); m_contentView.textField()->setTextBuffer(""); return true; diff --git a/apps/calcul/edit_expression_controller.h b/apps/calculation/edit_expression_controller.h similarity index 78% rename from apps/calcul/edit_expression_controller.h rename to apps/calculation/edit_expression_controller.h index c1bac4ab1..89446d5d4 100644 --- a/apps/calcul/edit_expression_controller.h +++ b/apps/calculation/edit_expression_controller.h @@ -1,16 +1,16 @@ -#ifndef CALCUL_EDIT_EXPRESSION_CONTROLLER_H -#define CALCUL_EDIT_EXPRESSION_CONTROLLER_H +#ifndef CALCULATION_EDIT_EXPRESSION_CONTROLLER_H +#define CALCULATION_EDIT_EXPRESSION_CONTROLLER_H #include #include "history_controller.h" -#include "calcul_store.h" +#include "calculation_store.h" -namespace Calcul { +namespace Calculation { class HistoryController; class EditExpressionController : public ViewController { public: - EditExpressionController(Responder * parentResponder, HistoryController * historyController, CalculStore * calculStore); + EditExpressionController(Responder * parentResponder, HistoryController * historyController, CalculationStore * calculationStore); View * view() override; const char * title() const override; void didBecomeFirstResponder() override; @@ -34,7 +34,7 @@ private: void setTextBody(const char * text); ContentView m_contentView; HistoryController * m_historyController; - CalculStore * m_calculStore; + CalculationStore * m_calculationStore; }; } diff --git a/apps/calcul/history_controller.cpp b/apps/calculation/history_controller.cpp similarity index 81% rename from apps/calcul/history_controller.cpp rename to apps/calculation/history_controller.cpp index 94e3f94bd..931392f1a 100644 --- a/apps/calcul/history_controller.cpp +++ b/apps/calculation/history_controller.cpp @@ -2,13 +2,15 @@ #include "app.h" #include -namespace Calcul { +// TODO transform list in non simple list + adjust size to content +// make the list cell responder +namespace Calculation { -HistoryController::HistoryController(Responder * parentResponder, CalculStore * calculStore) : +HistoryController::HistoryController(Responder * parentResponder, CalculationStore * calculationStore) : ViewController(parentResponder), m_listView(ListView(this, 0, 0, 0, 0)), m_activeCell(0), - m_calculStore(calculStore) + m_calculationStore(calculationStore) { } @@ -17,7 +19,7 @@ View * HistoryController::HistoryController::view() { } const char * HistoryController::title() const { - return "Calcul Table"; + return "Calculation Table"; } void HistoryController::reload() { @@ -66,7 +68,7 @@ bool HistoryController::handleEvent(Ion::Events::Event event) { } int HistoryController::numberOfRows() { - return m_calculStore->numberOfCalculs(); + return m_calculationStore->numberOfCalculations(); }; @@ -74,7 +76,7 @@ View * HistoryController::reusableCell(int index, int type) { assert(type == 0); assert(index >= 0); assert(index < k_maxNumberOfDisplayedRows); - return &m_calculHistory[index]; + return &m_calculationHistory[index]; } int HistoryController::reusableCellCount(int type) { @@ -84,13 +86,13 @@ int HistoryController::reusableCellCount(int type) { void HistoryController::willDisplayCellForIndex(View * cell, int index) { HistoryViewCell * myCell = (HistoryViewCell *)cell; - myCell->setCalcul(m_calculStore->calculAtIndex(index)); + myCell->setCalculation(m_calculationStore->calculationAtIndex(index)); } KDCoordinate HistoryController::rowHeight(int j) { - Calcul * calcul = m_calculStore->calculAtIndex(j); - KDCoordinate calculHeight = calcul->layout()->size().height(); - return calculHeight; + Calculation * calculation = m_calculationStore->calculationAtIndex(j); + KDCoordinate calculationHeight = calculation->layout()->size().height(); + return calculationHeight; } KDCoordinate HistoryController::cumulatedHeightFromIndex(int j) { diff --git a/apps/calcul/history_controller.h b/apps/calculation/history_controller.h similarity index 71% rename from apps/calcul/history_controller.h rename to apps/calculation/history_controller.h index 8bd46f46f..a7b869ec1 100644 --- a/apps/calcul/history_controller.h +++ b/apps/calculation/history_controller.h @@ -1,18 +1,18 @@ -#ifndef CALCUL_HISTORY_CONTROLLER_H -#define CALCUL_HISTORY_CONTROLLER_H +#ifndef CALCULATION_HISTORY_CONTROLLER_H +#define CALCULATION_HISTORY_CONTROLLER_H #include #include #include "history_view_cell.h" -#include "calcul_store.h" +#include "calculation_store.h" -namespace Calcul { +namespace Calculation { class App; class HistoryController : public ViewController, ListViewDataSource { public: - HistoryController(Responder * parentResponder, CalculStore * calculStore); + HistoryController(Responder * parentResponder, CalculationStore * calculationStore); View * view() override; const char * title() const override; @@ -32,12 +32,12 @@ public: private: constexpr static int k_maxNumberOfDisplayedRows = 10; - constexpr static int k_defaultCalculCellWidth = 320; + constexpr static int k_defaultCalculationCellWidth = 320; constexpr static int k_resultWidth = 7*14; - HistoryViewCell m_calculHistory[k_maxNumberOfDisplayedRows]; + HistoryViewCell m_calculationHistory[k_maxNumberOfDisplayedRows]; ListView m_listView; int m_activeCell; - CalculStore * m_calculStore; + CalculationStore * m_calculationStore; }; } diff --git a/apps/calcul/history_view_cell.cpp b/apps/calculation/history_view_cell.cpp similarity index 72% rename from apps/calcul/history_view_cell.cpp rename to apps/calculation/history_view_cell.cpp index 9b64f7c8e..93b6d41fc 100644 --- a/apps/calcul/history_view_cell.cpp +++ b/apps/calculation/history_view_cell.cpp @@ -2,10 +2,10 @@ #include #include -namespace Calcul { +namespace Calculation { HistoryViewCell::HistoryViewCell() : - m_calcul(nullptr), + m_calculation(nullptr), m_highlighted(false), m_result(BufferTextView(1.0f, 0.5f)) { @@ -25,17 +25,17 @@ void HistoryViewCell::layoutSubviews() { KDCoordinate height = bounds().height(); // Position the result KDSize prettyPrintSize = KDSize(0,0); - if (m_calcul && m_calcul->layout() != nullptr) { - prettyPrintSize = m_calcul->layout()->size(); + if (m_calculation && m_calculation->layout() != nullptr) { + prettyPrintSize = m_calculation->layout()->size(); } KDRect resultFrame(prettyPrintSize.width(), 0, width - prettyPrintSize.width(), height); m_result.setFrame(resultFrame); } -void HistoryViewCell::setCalcul(Calcul * calcul) { - m_calcul = calcul; +void HistoryViewCell::setCalculation(Calculation * calculation) { + m_calculation = calculation; char buffer[7]; - m_calcul->evaluation()->convertFloatToText(buffer, 14, 7); + m_calculation->evaluation()->convertFloatToText(buffer, 14, 7); m_result.setText(buffer); } @@ -51,8 +51,8 @@ void HistoryViewCell::drawRect(KDContext * ctx, KDRect rect) const { KDColor backgroundColor = m_highlighted ? Palette::FocusCellBackgroundColor : Palette::CellBackgroundColor; ctx->fillRect(rect, backgroundColor); // Draw the pretty print - if (m_calcul && m_calcul->layout() != nullptr) { - m_calcul->layout()->draw(ctx, KDPointZero, KDColorBlack, backgroundColor); + if (m_calculation && m_calculation->layout() != nullptr) { + m_calculation->layout()->draw(ctx, KDPointZero, KDColorBlack, backgroundColor); } } diff --git a/apps/calcul/history_view_cell.h b/apps/calculation/history_view_cell.h similarity index 66% rename from apps/calcul/history_view_cell.h rename to apps/calculation/history_view_cell.h index 7864d9c66..a12743801 100644 --- a/apps/calcul/history_view_cell.h +++ b/apps/calculation/history_view_cell.h @@ -1,24 +1,23 @@ -#ifndef CALCUL_HISTORY_VIEW_CELL_H -#define CALCUL_HISTORY_VIEW_CELL_H +#ifndef CALCULATION_HISTORY_VIEW_CELL_H +#define CALCULATION_HISTORY_VIEW_CELL_H #include -#include "calcul.h" +#include "calculation.h" -namespace Calcul { +namespace Calculation { class HistoryViewCell : public View { public: HistoryViewCell(); BufferTextView * result(); - void setCalcul(Calcul * calcul); + void setCalculation(Calculation * calculation); void setHighlighted(bool highlight); void drawRect(KDContext * ctx, KDRect rect) const override; - int numberOfSubviews() const override; View * subviewAtIndex(int index) override; void layoutSubviews() override; private: - Calcul * m_calcul; + Calculation * m_calculation; bool m_highlighted; BufferTextView m_result; };