File: line-edit.cpp

package info (click to toggle)
higan 098-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 11,904 kB
  • ctags: 13,286
  • sloc: cpp: 108,285; ansic: 778; makefile: 32; sh: 18
file content (71 lines) | stat: -rw-r--r-- 1,756 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
64
65
66
67
68
69
70
71
#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();
  _setState();
}

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 {
  _setState();
}

auto pLineEdit::setEditable(bool editable) -> void {
  _setState();
}

auto pLineEdit::setForegroundColor(Color color) -> void {
  _setState();
}

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

auto pLineEdit::_setState() -> void {
  if(auto color = state().backgroundColor) {
    QPalette palette = qtLineEdit->palette();
    palette.setColor(QPalette::Base, QColor(color.red(), color.green(), color.blue()));
    qtLineEdit->setPalette(palette);
    qtLineEdit->setAutoFillBackground(true);
  } else {
    //todo
  }
  qtLineEdit->setReadOnly(!state().editable);
  if(auto color = state().foregroundColor) {
    QPalette palette = qtLineEdit->palette();
    palette.setColor(QPalette::Text, QColor(color.red(), color.green(), color.blue()));
    qtLineEdit->setPalette(palette);
  } else {
    //todo
  }
  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