Blame view

build3/escher/src/button.cpp 1.29 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
  #include <escher/button.h>
  #include <escher/palette.h>
  #include <assert.h>
  
  Button::Button(Responder * parentResponder, I18n::Message textBody, Invocation invocation, KDText::FontSize size, KDColor textColor) :
    HighlightCell(),
    Responder(parentResponder),
    m_messageTextView(size, textBody, 0.5f, 0.5f, textColor),
    m_invocation(invocation),
    m_size(size)
  {
  }
  
  int Button::numberOfSubviews() const {
    return 1;
  }
  
  View * Button::subviewAtIndex(int index) {
    assert(index == 0);
    return &m_messageTextView;
  }
  
  void Button::layoutSubviews() {
    m_messageTextView.setFrame(bounds());
  }
  
  bool Button::handleEvent(Ion::Events::Event event) {
    if (event == Ion::Events::OK || event == Ion::Events::EXE) {
      m_invocation.perform(this);
      return true;
    }
    return false;
  }
  
  void Button::setHighlighted(bool highlight) {
    HighlightCell::setHighlighted(highlight);
    KDColor backgroundColor = highlight? Palette::Select : KDColorWhite;
    m_messageTextView.setBackgroundColor(backgroundColor);
    markRectAsDirty(bounds());
  }
  
  KDSize Button::minimalSizeForOptimalDisplay() const {
    KDSize textSize = m_messageTextView.minimalSizeForOptimalDisplay();
    return KDSize(textSize.width() + (m_size == KDText::FontSize::Small ? k_horizontalMarginSmall : k_horizontalMarginLarge), textSize.height() + k_verticalMargin);
  }