File: text-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 (85 lines) | stat: -rw-r--r-- 2,573 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#if defined(Hiro_TextEdit)

namespace hiro {

auto pTextEdit::construct() -> void {
  qtWidget = qtTextEdit = new QtTextEdit(*this);
  qtTextEdit->connect(qtTextEdit, SIGNAL(textChanged()), SLOT(onChange()));

  pWidget::construct();
  setBackgroundColor(state().backgroundColor);
  setForegroundColor(state().foregroundColor);
  _setState();
}

auto pTextEdit::destruct() -> void {
if(Application::state().quit) return;  //TODO: hack
  delete qtTextEdit;
  qtWidget = qtTextEdit = nullptr;
}

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

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

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

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

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

auto pTextEdit::setText(const string& text) -> void {
  qtTextEdit->setPlainText(QString::fromUtf8(text));
}

auto pTextEdit::setTextCursor(TextCursor cursor) -> void {
  _setState();
}

auto pTextEdit::setWordWrap(bool wordWrap) -> void {
  _setState();
}

auto pTextEdit::text() const -> string {
  return qtTextEdit->toPlainText().toUtf8().constData();
}

auto pTextEdit::textCursor() const -> TextCursor {
  //TODO
  return state().textCursor;
}

auto pTextEdit::_setState() -> void {
  QTextCursor cursor = qtTextEdit->textCursor();
  s32 lastCharacter = strlen(qtTextEdit->toPlainText().toUtf8().constData());
  cursor.setPosition(max(0, min(lastCharacter, state().textCursor.offset())));
  cursor.setPosition(max(0, min(lastCharacter, state().textCursor.offset() + state().textCursor.length())), QTextCursor::KeepAnchor);
  qtTextEdit->setTextCursor(cursor);
  qtTextEdit->setTextInteractionFlags(state().editable
    ? Qt::TextEditorInteraction
    : Qt::TextSelectableByKeyboard | Qt::TextSelectableByMouse
  );
  qtTextEdit->setWordWrapMode(state().wordWrap ? QTextOption::WordWrap : QTextOption::NoWrap);
  qtTextEdit->setHorizontalScrollBarPolicy(state().wordWrap ? Qt::ScrollBarAlwaysOff : Qt::ScrollBarAlwaysOn);
  qtTextEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
}

auto QtTextEdit::onChange() -> void {
//p.state().text = text();
  p.self().doChange();
}

}

#endif