Blame view

build6/epsilon-master/escher/src/expression_view.cpp 2.18 KB
6663b6c9   adorian   projet complet av...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
  #include <escher/expression_view.h>
  using namespace Poincare;
  
  ExpressionView::ExpressionView(float horizontalAlignment, float verticalAlignment,
      KDColor textColor, KDColor backgroundColor) :
    m_expressionLayout(nullptr),
    m_horizontalAlignment(horizontalAlignment),
    m_verticalAlignment(verticalAlignment),
    m_textColor(textColor),
    m_backgroundColor(backgroundColor),
    m_horizontalMargin(0)
  {
  }
  
  ExpressionLayout * ExpressionView::expressionLayout() const {
    return m_expressionLayout;
  }
  
  void ExpressionView::setExpressionLayout(ExpressionLayout * expressionLayout) {
    m_expressionLayout = expressionLayout;
    markRectAsDirty(bounds());
  }
  
  void ExpressionView::setBackgroundColor(KDColor backgroundColor) {
    if (m_backgroundColor != backgroundColor) {
      m_backgroundColor = backgroundColor;
      markRectAsDirty(bounds());
    }
  }
  
  void ExpressionView::setTextColor(KDColor textColor) {
    if (textColor != m_textColor) {
      m_textColor = textColor;
      markRectAsDirty(bounds());
    }
  }
  
  void ExpressionView::setAlignment(float horizontalAlignment, float verticalAlignment) {
    m_horizontalAlignment = horizontalAlignment;
    m_verticalAlignment = verticalAlignment;
    markRectAsDirty(bounds());
  }
  
  int ExpressionView::numberOfLayouts() const {
    return m_expressionLayout->numberOfDescendants(true);
  }
  
  KDSize ExpressionView::minimalSizeForOptimalDisplay() const {
    if (m_expressionLayout == nullptr) {
      return KDSizeZero;
    }
    KDSize expressionSize = m_expressionLayout->size();
    return KDSize(expressionSize.width() + 2*m_horizontalMargin, expressionSize.height());
  }
  
  KDPoint ExpressionView::drawingOrigin() const {
    KDSize expressionSize = m_expressionLayout->size();
    return KDPoint(m_horizontalMargin + m_horizontalAlignment*(m_frame.width() - 2*m_horizontalMargin - expressionSize.width()), max(0, (m_frame.height() - expressionSize.height())/2));
  }
  
  KDPoint ExpressionView::absoluteDrawingOrigin() const {
    return drawingOrigin().translatedBy(m_frame.topLeft());
  }
  
  void ExpressionView::drawRect(KDContext * ctx, KDRect rect) const {
    ctx->fillRect(rect, m_backgroundColor);
    if (m_expressionLayout != nullptr) {
      m_expressionLayout->draw(ctx, drawingOrigin(), m_textColor, m_backgroundColor);
    }
  }