File: line-edit.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 (63 lines) | stat: -rw-r--r-- 1,753 bytes parent folder | download | duplicates (2)
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
#if defined(Hiro_LineEdit)

namespace hiro {

auto pLineEdit::construct() -> void {
  qtWidget = qtLineEdit = new QtLineEdit(*this);
  qtLineEdit->connect(qtLineEdit, SIGNAL(returnPressed()), SLOT(onActivate()));
  qtLineEdit->connect(qtLineEdit, SIGNAL(textEdited(const QString&)), SLOT(onChange()));

  pWidget::construct();
  setBackgroundColor(state().backgroundColor);
  setEditable(state().editable);
  setForegroundColor(state().foregroundColor);
  setText(state().text);
}

auto pLineEdit::destruct() -> void {
  delete qtLineEdit;
  qtWidget = qtLineEdit = nullptr;
}

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

auto pLineEdit::setBackgroundColor(Color color) -> void {
  static auto defaultColor = qtLineEdit->palette().color(QPalette::Base);

  auto palette = qtLineEdit->palette();
  palette.setColor(QPalette::Base, CreateColor(color, defaultColor));
  qtLineEdit->setPalette(palette);
  qtLineEdit->setAutoFillBackground((bool)color);
}

auto pLineEdit::setEditable(bool editable) -> void {
  qtLineEdit->setReadOnly(!state().editable);
}

auto pLineEdit::setForegroundColor(Color color) -> void {
  static auto defaultColor = qtLineEdit->palette().color(QPalette::Text);

  auto palette = qtLineEdit->palette();
  palette.setColor(QPalette::Text, CreateColor(color, defaultColor));
  qtLineEdit->setPalette(palette);
}

auto pLineEdit::setText(const string& text) -> void {
  qtLineEdit->setText(QString::fromUtf8(state().text));
}

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

auto QtLineEdit::onChange() -> void {
  p.state().text = text().toUtf8().constData();
  p.self().doChange();
}

}

#endif