| 339 | } |
| 340 | |
| 341 | class NoReturnTextEdit : public QTextEdit { |
| 342 | Q_OBJECT |
| 343 | public: |
| 344 | explicit NoReturnTextEdit(QWidget* parent) : QTextEdit(parent) |
| 345 | { |
| 346 | setTextInteractionFlags(Qt::TextEditorInteraction); |
| 347 | setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOff); |
| 348 | setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOff); |
| 349 | } |
| 350 | bool event(QEvent* event) override |
| 351 | { |
| 352 | auto eventType = event->type(); |
| 353 | if (eventType == QEvent::KeyPress || eventType == QEvent::KeyRelease) { |
| 354 | QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event); |
| 355 | auto key = keyEvent->key(); |
| 356 | if ((key == Qt::Key_Return || key == Qt::Key_Enter) && eventType == QEvent::KeyPress) { |
| 357 | emit editingDone(); |
| 358 | return true; |
| 359 | } |
| 360 | if (key == Qt::Key_Tab) { |
| 361 | return true; |
| 362 | } |
| 363 | } |
| 364 | return QTextEdit::event(event); |
| 365 | } |
| 366 | signals: |
| 367 | void editingDone(); |
| 368 | }; |