Debian Codegraph @

hiro/qt/widget/line-edit.cpp

raw
1 #if defined(Hiro_LineEdit)
2
3 namespace hiro {
4
5 auto pLineEdit::construct() -> void {
6 qtWidget = qtLineEdit = new QtLineEdit(*this);
7 qtLineEdit->connect(qtLineEdit, SIGNAL(returnPressed()), SLOT(onActivate()));
8 qtLineEdit->connect(qtLineEdit, SIGNAL(textEdited(const QString&)), SLOT(onChange()));
9
10 pWidget::construct();
11 setBackgroundColor(state().backgroundColor);
12 setEditable(state().editable);
13 setForegroundColor(state().foregroundColor);
14 setText(state().text);
15 }
16
17 auto pLineEdit::destruct() -> void {
18 delete qtLineEdit;
19 qtWidget = qtLineEdit = nullptr;
20 }
21
22 auto pLineEdit::minimumSize() const -> Size {
23 auto size = pFont::size(qtWidget->font(), state().text);
24 return {size.width() + 12, size.height() + 12};
25 }
26
27 auto pLineEdit::setBackgroundColor(Color color) -> void {
28 static auto defaultColor = qtLineEdit->palette().color(QPalette::Base);
29
30 auto palette = qtLineEdit->palette();
31 palette.setColor(QPalette::Base, CreateColor(color, defaultColor));
32 qtLineEdit->setPalette(palette);
33 qtLineEdit->setAutoFillBackground((bool)color);
34 }
35
36 auto pLineEdit::setEditable(bool editable) -> void {
37 qtLineEdit->setReadOnly(!state().editable);
38 }
39
40 auto pLineEdit::setForegroundColor(Color color) -> void {
41 static auto defaultColor = qtLineEdit->palette().color(QPalette::Text);
42
43 auto palette = qtLineEdit->palette();
44 palette.setColor(QPalette::Text, CreateColor(color, defaultColor));
45 qtLineEdit->setPalette(palette);
46 }
47
48 auto pLineEdit::setText(const string& text) -> void {
49 qtLineEdit->setText(QString::fromUtf8(state().text));
50 }
51
52 auto QtLineEdit::onActivate() -> void {
53 p.self().doActivate();
54 }
55
56 auto QtLineEdit::onChange() -> void {
57 p.state().text = text().toUtf8().constData();
58 p.self().doChange();
59 }
60
61 }
62
63 #endif