[escher] create class expression view

Change-Id: I16ddd22318ad120d736ad7f10bb2800a13c2b005
This commit is contained in:
Émilie Feral
2016-10-26 14:18:51 +02:00
parent 2eae7c43ff
commit 590c869bc8
4 changed files with 67 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
#include <escher/expression_view.h>
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);
}
}