[escher] ExpressionView drawingOrigin().

Change-Id: I737f17f857edb6e9971feeeb196f2698cc92ad9e
This commit is contained in:
Léa Saviot
2017-12-14 13:51:40 +01:00
parent 589926284c
commit 8828eaf79f
2 changed files with 8 additions and 5 deletions

View File

@@ -22,6 +22,7 @@ public:
void setTextColor(KDColor textColor);
void setAlignment(float horizontalAlignment, float verticalAlignment);
KDSize minimalSizeForOptimalDisplay() const override;
KDPoint drawingOrigin() const;
private:
/* Warning: we do not need to delete the previous expression layout when
* deleting object or setting a new expression layout. Indeed, the expression

View File

@@ -47,13 +47,15 @@ KDSize ExpressionView::minimalSizeForOptimalDisplay() const {
return m_expressionLayout->size();
}
KDPoint ExpressionView::drawingOrigin() const {
KDSize expressionSize = m_expressionLayout->size();
return KDPoint(m_horizontalAlignment*(m_frame.width() - expressionSize.width()),
0.5f*(m_frame.height() - expressionSize.height()));
}
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(m_horizontalAlignment*(m_frame.width() - expressionSize.width()),
0.5f*(m_frame.height() - expressionSize.height()));
m_expressionLayout->draw(ctx, origin, m_textColor, m_backgroundColor);
m_expressionLayout->draw(ctx, drawingOrigin(), m_textColor, m_backgroundColor);
}
}