File: button.cpp

package info (click to toggle)
ares 134%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 34,680 kB
  • sloc: cpp: 338,717; ansic: 89,036; sh: 52; makefile: 27
file content (66 lines) | stat: -rw-r--r-- 1,811 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
#if defined(Hiro_Button)

namespace hiro {

auto pButton::construct() -> void {
  qtWidget = qtButton = new QtButton(*this);
  qtButton->setToolButtonStyle(Qt::ToolButtonTextOnly);
  qtButton->connect(qtButton, SIGNAL(released()), SLOT(onActivate()));

  setBordered(state().bordered);
  setIcon(state().icon);
  setOrientation(state().orientation);
  setText(state().text);

  pWidget::construct();
}

auto pButton::destruct() -> void {
  delete qtButton;
  qtWidget = qtButton = nullptr;
}

auto pButton::minimumSize() const -> Size {
  auto size = pFont::size(qtWidget->font(), state().text ? state().text : " ");

  if(state().orientation == Orientation::Horizontal) {
    size.setWidth(size.width() + state().icon.width());
    size.setHeight(max(size.height(), state().icon.height()));
  }

  if(state().orientation == Orientation::Vertical) {
    size.setWidth(max(size.width(), state().icon.width()));
    size.setHeight(size.height() + state().icon.height());
  }

  return {size.width() + (state().text ? 20 : 12), size.height() + 12};
}

auto pButton::setBordered(bool bordered) -> void {
  qtButton->setAutoRaise(!bordered);
}

auto pButton::setIcon(const image& icon) -> void {
  qtButton->setIconSize(QSize(icon.width(), icon.height()));
  qtButton->setIcon(CreateIcon(icon));
  qtButton->setStyleSheet("text-align: top;");
}

auto pButton::setOrientation(Orientation orientation) -> void {
  switch(orientation) {
  case Orientation::Horizontal: qtButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); break;
  case Orientation::Vertical:   qtButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);  break;
  }
}

auto pButton::setText(const string& text) -> void {
  qtButton->setText(QString::fromUtf8(text));
}

auto QtButton::onActivate() -> void {
  p.self().doActivate();
}

}

#endif