Event filter for text edit — handle Enter and per-key sending
| 544 | |
| 545 | // Event filter for text edit — handle Enter and per-key sending |
| 546 | bool AetherSDR::CwxPanel::eventFilter(QObject* obj, QEvent* event) |
| 547 | { |
| 548 | if (obj == m_textEdit && event->type() == QEvent::KeyPress) { |
| 549 | auto* ke = static_cast<QKeyEvent*>(event); |
| 550 | |
| 551 | if (ke->key() == Qt::Key_Escape) { |
| 552 | if (m_model) m_model->clearBuffer(); |
| 553 | m_textEdit->clear(); |
| 554 | return true; |
| 555 | } |
| 556 | |
| 557 | if (m_model && m_model->isLive()) { |
| 558 | // Live mode: send each character immediately |
| 559 | QString text = ke->text(); |
| 560 | if (!text.isEmpty() && ke->key() != Qt::Key_Return && ke->key() != Qt::Key_Enter) { |
| 561 | if (ke->key() == Qt::Key_Backspace) { |
| 562 | m_model->erase(1); |
| 563 | } else { |
| 564 | m_model->sendChar(text); |
| 565 | } |
| 566 | } |
| 567 | // Still let the text edit display the character |
| 568 | return false; |
| 569 | } |
| 570 | |
| 571 | // Send mode: Enter sends the buffer |
| 572 | if (ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Enter) { |
| 573 | sendBuffer(); |
| 574 | return true; |
| 575 | } |
| 576 | } |
| 577 | // Context menu on history bubbles |
| 578 | if (auto* bubble = dynamic_cast<CwxBubble*>(obj)) { |
| 579 | if (event->type() == QEvent::ContextMenu) { |
| 580 | auto* ce = static_cast<QContextMenuEvent*>(event); |
| 581 | QMenu menu(this); |
| 582 | AetherSDR::ThemeManager::instance().applyStyleSheet(&menu, "QMenu { background: {{color.background.1}}; color: {{color.text.primary}}; border: 1px solid {{color.background.2}}; }" |
| 583 | "QMenu::item:selected { background: {{color.accent}}; color: {{color.background.spectrum}}; }" |
| 584 | "QMenu::separator { height: 1px; background: {{color.background.2}}; margin: 4px 8px; }"); |
| 585 | QAction* resendAction = menu.addAction("Resend"); |
| 586 | menu.addSeparator(); |
| 587 | QAction* clearAction = menu.addAction("Clear History"); |
| 588 | QAction* chosen = menu.exec(ce->globalPos()); |
| 589 | if (chosen == resendAction) { |
| 590 | resendText(bubble->text()); |
| 591 | } else if (chosen == clearAction) { |
| 592 | clearHistory(); |
| 593 | } |
| 594 | return true; |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | return QWidget::eventFilter(obj, event); |
| 599 | } |
| 600 | |
| 601 | void AetherSDR::CwxPanel::resendText(const QString& text) |
| 602 | { |
nothing calls this directly
no test coverage detected