diff --git a/sdrgui/CMakeLists.txt b/sdrgui/CMakeLists.txt index 341129f64..bfb62aa82 100644 --- a/sdrgui/CMakeLists.txt +++ b/sdrgui/CMakeLists.txt @@ -22,6 +22,7 @@ set(sdrgui_SOURCES gui/commandoutputdialog.cpp gui/comboboxnoarrow.cpp gui/crightclickenabler.cpp + gui/customtextedit.cpp gui/cwkeyergui.cpp gui/devicestreamselectiondialog.cpp gui/deviceuserargsdialog.cpp @@ -93,6 +94,7 @@ set(sdrgui_HEADERS gui/commandoutputdialog.h gui/comboboxnoarrow.h gui/crightclickenabler.h + gui/customtextedit.h gui/cwkeyergui.h gui/devicestreamselectiondialog.h gui/deviceuserargsdialog.h diff --git a/sdrgui/gui/customtextedit.cpp b/sdrgui/gui/customtextedit.cpp new file mode 100644 index 000000000..67ceb13a8 --- /dev/null +++ b/sdrgui/gui/customtextedit.cpp @@ -0,0 +1,52 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2020 Edouard Griffiths, F4EXB // +// // +// Subclasses QTextEdit to implement and editingFinished() signal like // +// QLineEdit's one // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include "customtextedit.h" + +CustomTextEdit::CustomTextEdit(QWidget* parent) : QTextEdit(parent), textChanged(false), trackChange(false) +{ + connect(this,&QTextEdit::textChanged,this,&CustomTextEdit::handleTextChange); +} + +void CustomTextEdit::focusInEvent(QFocusEvent* e) +{ + trackChange = true; + textChanged = false; + QTextEdit::focusInEvent(e); +} + +void CustomTextEdit::focusOutEvent(QFocusEvent *e) +{ + QTextEdit::focusOutEvent(e); + trackChange = false; + + if (textChanged) + { + textChanged = false; + emit editingFinished(); + } +} + +void CustomTextEdit::handleTextChange() +{ + if (trackChange) { + textChanged = true; + } +} diff --git a/sdrgui/gui/customtextedit.h b/sdrgui/gui/customtextedit.h new file mode 100644 index 000000000..680a534dd --- /dev/null +++ b/sdrgui/gui/customtextedit.h @@ -0,0 +1,41 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2020 Edouard Griffiths, F4EXB // +// // +// Subclasses QTextEdit to implement and editingFinished() signal like // +// QLineEdit's one // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include + +class CustomTextEdit : public QTextEdit +{ + Q_OBJECT +public: + CustomTextEdit(QWidget* parent = nullptr); + +protected: + void focusInEvent(QFocusEvent* e); + void focusOutEvent(QFocusEvent *e); + +signals: + void editingFinished(); + +private slots: + void handleTextChange(); + +private: + bool textChanged, trackChange; +};