File: radio-label.cpp

package info (click to toggle)
ares 126-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 32,600 kB
  • sloc: cpp: 356,508; ansic: 20,394; makefile: 16; sh: 2
file content (80 lines) | stat: -rw-r--r-- 2,031 bytes parent folder | download | duplicates (4)
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
71
72
73
74
75
76
77
78
79
80
#if defined(Hiro_RadioLabel)

namespace hiro {

auto pRadioLabel::construct() -> void {
  qtWidget = qtRadioLabel = new QtRadioLabel(*this);
  qtRadioLabel->setAutoExclusive(false);
  qtRadioLabel->connect(qtRadioLabel, SIGNAL(toggled(bool)), SLOT(onActivate()));

  pWidget::construct();
  setGroup(state().group);
  _setState();
}

auto pRadioLabel::destruct() -> void {
  if(qtRadioLabel) delete qtRadioLabel;
  qtWidget = qtRadioLabel = nullptr;
}

auto pRadioLabel::minimumSize() const -> Size {
  auto size = pFont::size(qtWidget->font(), state().text);
  return {size.width() + 26, size.height() + 6};
}

auto pRadioLabel::setChecked() -> void {
  _setState();
}

auto pRadioLabel::setGroup(sGroup group) -> void {
  bool first = true;
  if(auto& group = state().group) {
    group->self()->lock();
    for(auto& weak : group->state.objects) {
      if(auto object = weak.acquire()) {
        if(auto radioLabel = dynamic_cast<mRadioLabel*>(object.data())) {
          if(auto self = radioLabel->self()) {
            self->qtRadioLabel->setChecked(radioLabel->state.checked = first);
            first = false;
          }
        }
      }
    }
    group->self()->unlock();
  }
}

auto pRadioLabel::setText(const string& text) -> void {
  _setState();
}

auto pRadioLabel::_setState() -> void {
  if(auto& group = state().group) {
    group->self()->lock();
    for(auto& weak : group->state.objects) {
      if(auto object = weak.acquire()) {
        if(auto radioLabel = dynamic_cast<mRadioLabel*>(object.data())) {
          if(auto self = radioLabel->self()) {
            self->qtRadioLabel->setChecked(radioLabel->state.checked);
          }
        }
      }
    }
    group->self()->unlock();
  }
  qtRadioLabel->setText(QString::fromUtf8(state().text));
}

auto QtRadioLabel::onActivate() -> void {
  if(auto& group = p.state().group) {
    if(!group->self()->locked()) {
      bool wasChecked = p.state().checked;
      p.self().setChecked();
      if(!wasChecked) p.self().doActivate();
    }
  }
}

}

#endif