Blame view

build3/apps/probability/cell.cpp 1.97 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
  #include "cell.h"
  #include <assert.h>
  
  namespace Probability {
  
  Cell::Cell() :
    HighlightCell(),
    m_labelView(KDText::FontSize::Large, (I18n::Message)0, 0, 0.5, KDColorBlack, KDColorWhite),
    m_icon(nullptr),
    m_focusedIcon(nullptr)
  {
  }
  
  int Cell::numberOfSubviews() const {
    return 3;
  }
  
  View * Cell::subviewAtIndex(int index) {
    assert(index >= 0 && index < 3);
    if (index == 0) {
      return &m_labelView;
    }
    if (index == 1) {
      return &m_iconView;
    }
    return &m_chevronView;
  }
  
  void Cell::layoutSubviews() {
    KDCoordinate width = bounds().width();
    KDCoordinate height = bounds().height();
    m_labelView.setFrame(KDRect(1+k_iconWidth+2*k_iconMargin, 1, width-2-k_iconWidth-2*k_iconMargin - k_chevronWidth, height-2));
    m_iconView.setFrame(KDRect(1+k_iconMargin, (height - k_iconHeight)/2, k_iconWidth, k_iconHeight));
    m_chevronView.setFrame(KDRect(width-1-k_chevronWidth-k_chevronMargin, 1, k_chevronWidth, height - 2));
  }
  
  void Cell::reloadCell() {
    HighlightCell::reloadCell();
    KDColor backgroundColor = isHighlighted()? Palette::Select : KDColorWhite;
    m_labelView.setBackgroundColor(backgroundColor);
    if (isHighlighted()) {
      m_iconView.setImage(m_focusedIcon);
    } else {
      m_iconView.setImage(m_icon);
    }
  }
  
  void Cell::setLabel(I18n::Message message) {
    m_labelView.setMessage(message);
  }
  
  void Cell::setImage(const Image * image, const Image * focusedImage) {
    m_icon = image;
    m_focusedIcon = focusedImage;
  }
  
  void Cell::drawRect(KDContext * ctx, KDRect rect) const {
    KDCoordinate width = bounds().width();
    KDCoordinate height = bounds().height();
    KDColor backgroundColor = isHighlighted() ? Palette::Select : KDColorWhite;
    ctx->fillRect(KDRect(1, 1, width-2, height-1), backgroundColor);
    ctx->fillRect(KDRect(0, 0, width, 1), Palette::GreyBright);
    ctx->fillRect(KDRect(0, 1, 1, height-1), Palette::GreyBright);
    ctx->fillRect(KDRect(width-1, 1, 1, height-1), Palette::GreyBright);
    ctx->fillRect(KDRect(0, height-1, width, 1), Palette::GreyBright);
   }
  
  }