| 16 | #include <QTextEdit> |
| 17 | |
| 18 | NoteView::NoteView(Note* note) |
| 19 | : m_note(note) |
| 20 | , m_textEdit(new QTextEdit(this)) { |
| 21 | auto* layout = new QHBoxLayout(this); |
| 22 | layout->setContentsMargins(0, 0, 0, 0); |
| 23 | |
| 24 | QPalette palette = m_textEdit->palette(); |
| 25 | palette.setColor(QPalette::Base, m_note->backgroundColor()); |
| 26 | palette.setColor(QPalette::Text, m_note->textColor()); |
| 27 | |
| 28 | m_textEdit->setPalette(palette); |
| 29 | m_textEdit->setFont(m_note->textFont()); |
| 30 | m_textEdit->setText(m_note->text()); |
| 31 | |
| 32 | layout->addWidget(m_textEdit); |
| 33 | |
| 34 | connect(m_note, &Note::textChanged, this, &NoteView::noteTextChanged); |
| 35 | connect(m_note, &Note::backgroundColorChanged, this, &NoteView::noteBackgroundColorChanged); |
| 36 | connect(m_note, &Note::textColorChanged, this, &NoteView::noteTextColorChanged); |
| 37 | connect(m_note, &Note::textFontChanged, this, &NoteView::noteTextFontChanged); |
| 38 | |
| 39 | // don't put every single character change onto the undo stack, delay it similarly how it's done in TimedLineEdit |
| 40 | connect(m_textEdit, &QTextEdit::textChanged, [&]() { |
| 41 | if (m_textChangedTimerId != -1) |
| 42 | killTimer(m_textChangedTimerId); |
| 43 | m_textChangedTimerId = startTimer(1000); |
| 44 | }); |
| 45 | } |
| 46 | |
| 47 | void NoteView::print(QPrinter* printer) const { |
| 48 | m_textEdit->print(printer); |
nothing calls this directly
no test coverage detected