From fd29d6a93195d49379bb6d2673a1dbce20ae240f Mon Sep 17 00:00:00 2001 From: Jordan Sherer Date: Sat, 1 Jun 2019 22:41:10 -0400 Subject: [PATCH] Added log window population via double click of words in the rx window --- keyeater.cpp | 13 +++++++++++++ keyeater.h | 12 ++++++++++++ logqso.cpp | 20 ++++++++++++++++++++ logqso.h | 1 + mainwindow.cpp | 30 ++++++++++++++++++++++++++++++ mainwindow.h | 1 + 6 files changed, 77 insertions(+) diff --git a/keyeater.cpp b/keyeater.cpp index 3a37242..55bc57e 100644 --- a/keyeater.cpp +++ b/keyeater.cpp @@ -42,3 +42,16 @@ bool MousePressEater::eventFilter(QObject *obj, QEvent *event){ return QObject::eventFilter(obj, event); } +bool MouseDoubleClickEater::eventFilter(QObject *obj, QEvent *event){ + if (event->type() == QEvent::MouseButtonDblClick) { + QMouseEvent *mouseEvent = static_cast(event); + bool processed = false; + emit this->mouseDoubleClicked(obj, mouseEvent, &processed); + if(processed){ + return true; + } + } + + // standard event processing + return QObject::eventFilter(obj, event); +} diff --git a/keyeater.h b/keyeater.h index 88719ae..e51c53d 100644 --- a/keyeater.h +++ b/keyeater.h @@ -44,7 +44,19 @@ public: Q_SIGNAL void mousePressed(QObject *obj, QMouseEvent *evt, bool *pProcessed); }; +class MouseDoubleClickEater : public QObject +{ + Q_OBJECT +public: + MouseDoubleClickEater(){} + virtual ~MouseDoubleClickEater(){} +protected: + bool eventFilter(QObject *obj, QEvent *event); + +public: + Q_SIGNAL void mouseDoubleClicked(QObject *obj, QMouseEvent *evt, bool *pProcessed); +}; diff --git a/logqso.cpp b/logqso.cpp index 2ee27e3..097c9d7 100644 --- a/logqso.cpp +++ b/logqso.cpp @@ -34,6 +34,26 @@ LogQSO::~LogQSO () { } +bool LogQSO::acceptText(QString text){ + auto w = focusWidget(); + if(!w){ + return false; + } + + auto name = QString(w->metaObject()->className()); + if(name != "QLineEdit"){ + return false; + } + + auto l = static_cast(w); + if(!l->text().isEmpty()){ + return false; + } + + l->setText(text); + return true; +} + void LogQSO::on_start_now_button_pressed(){ ui->start_date_time->setDateTime(DriftingDateTime::currentDateTimeUtc()); } diff --git a/logqso.h b/logqso.h index 716e043..c3d0348 100644 --- a/logqso.h +++ b/logqso.h @@ -37,6 +37,7 @@ public: public slots: void accept(); + bool acceptText(QString text); signals: void acceptQSO (QDateTime const& QSO_date_off, QString const& call, QString const& grid diff --git a/mainwindow.cpp b/mainwindow.cpp index b75ebff..73215e8 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1176,6 +1176,12 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple, }); ui->extFreeTextMsgEdit->installEventFilter(enterFilter); + auto doubleClickFilter = new MouseDoubleClickEater(); + connect(doubleClickFilter, &MouseDoubleClickEater::mouseDoubleClicked, this, [this](QObject *, QMouseEvent *, bool *){ + QTimer::singleShot(150, this, &MainWindow::on_textEditRX_mouseDoubleClicked); + }); + ui->textEditRX->viewport()->installEventFilter(doubleClickFilter); + auto clearActionSep = new QAction(nullptr); clearActionSep->setSeparator(true); @@ -6217,6 +6223,30 @@ QPair MainWindow::popMessageFrame(){ return m_txFrameQueue.dequeue(); } +void MainWindow::on_textEditRX_mouseDoubleClicked(){ + auto c = ui->textEditRX->textCursor(); + auto text = c.selectedText(); + if(text.isEmpty()){ + return; + } + + int start = c.selectionStart(); + int end = c.selectionEnd(); + + c.clearSelection(); + c.setPosition(start); + c.movePosition(QTextCursor::PreviousCharacter, QTextCursor::MoveAnchor); + c.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, 1 + end-start); + + auto prev = c.selectedText(); + if(prev.startsWith("-") || prev.startsWith("+")){ + ui->textEditRX->setTextCursor(c); + text = prev; + } + + m_logDlg->acceptText(text); +} + void MainWindow::on_nextFreeTextMsg_currentTextChanged (QString const& text) { msgtype(text, ui->nextFreeTextMsg); diff --git a/mainwindow.h b/mainwindow.h index d1a5435..f06136c 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -326,6 +326,7 @@ private slots: void on_tableWidgetCalls_cellDoubleClicked(int row, int col); void on_tableWidgetCalls_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected); void on_freeTextMsg_currentTextChanged (QString const&); + void on_textEditRX_mouseDoubleClicked(); void on_nextFreeTextMsg_currentTextChanged (QString const&); void on_extFreeTextMsgEdit_currentTextChanged (QString const&); int currentFreqOffset();