From 590c869bc82da8d7673a0159d7ead574518fd042 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Wed, 26 Oct 2016 14:18:51 +0200 Subject: [PATCH] [escher] create class expression view Change-Id: I16ddd22318ad120d736ad7f10bb2800a13c2b005 --- escher/Makefile | 1 + escher/include/escher.h | 1 + escher/include/escher/expression_view.h | 28 +++++++++++++++++++ escher/src/expression_view.cpp | 37 +++++++++++++++++++++++++ 4 files changed, 67 insertions(+) create mode 100644 escher/include/escher/expression_view.h create mode 100644 escher/src/expression_view.cpp diff --git a/escher/Makefile b/escher/Makefile index dece7b5fe..4c3f8c8aa 100644 --- a/escher/Makefile +++ b/escher/Makefile @@ -6,6 +6,7 @@ objs += $(addprefix escher/src/,\ button.o\ container.o\ header_view_controller.o\ + expression_view.o\ image_view.o\ invocation.o\ input_view_controller.o\ diff --git a/escher/include/escher.h b/escher/include/escher.h index d49ce437d..b6ff9080c 100644 --- a/escher/include/escher.h +++ b/escher/include/escher.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include diff --git a/escher/include/escher/expression_view.h b/escher/include/escher/expression_view.h new file mode 100644 index 000000000..4be6819df --- /dev/null +++ b/escher/include/escher/expression_view.h @@ -0,0 +1,28 @@ +#ifndef ESCHER_EXPRESSION_VIEW_H +#define ESCHER_EXPRESSION_VIEW_H + +#include +#include +#include + +/* This class does not handle the expression layout as the size of the layout is + * needed to compute the size of table cells hosting the expression. As the size + * of this cell is determined before we set the expression in the expression + * view, we cannot use minimalSizeForOptimalDisplay to assess the required + * size. */ + +class ExpressionView : public View { +public: + ExpressionView(); + void setExpression(ExpressionLayout * expressionLayout); + void drawRect(KDContext * ctx, KDRect rect) const override; + void setBackgroundColor(KDColor backgroundColor); + void setTextColor(KDColor textColor); + KDSize minimalSizeForOptimalDisplay() override; +private: + ExpressionLayout * m_expressionLayout; + KDColor m_textColor; + KDColor m_backgroundColor; +}; + +#endif diff --git a/escher/src/expression_view.cpp b/escher/src/expression_view.cpp new file mode 100644 index 000000000..c8d0c342c --- /dev/null +++ b/escher/src/expression_view.cpp @@ -0,0 +1,37 @@ +#include + +ExpressionView::ExpressionView() : + m_expressionLayout(nullptr), + m_textColor(KDColorBlack), + m_backgroundColor(KDColorWhite) +{ +} + +void ExpressionView::setExpression(ExpressionLayout * expressionLayout) { + m_expressionLayout = expressionLayout; +} + +void ExpressionView::setBackgroundColor(KDColor backgroundColor) { + m_backgroundColor = backgroundColor; +} + +void ExpressionView::setTextColor(KDColor textColor) { + m_textColor = textColor; +} + +KDSize ExpressionView::minimalSizeForOptimalDisplay() { + if (m_expressionLayout == nullptr) { + return KDSizeZero; + } + return m_expressionLayout->size(); +} + +void ExpressionView::drawRect(KDContext * ctx, KDRect rect) const { + ctx->fillRect(rect, m_backgroundColor); + if (m_expressionLayout != nullptr) { + //Position the origin of expression + KDSize expressionSize = m_expressionLayout->size(); + KDPoint origin(0, 0.5f*(m_frame.height() - expressionSize.height())); + m_expressionLayout->draw(ctx, origin, m_textColor, m_backgroundColor); + } +}