This commit is contained in:
Daniel Ramöller 2023-01-23 18:05:26 -05:00 committed by Richard Kimberly Heck
parent fca8e54289
commit 62413580de
3 changed files with 27 additions and 1 deletions

View File

@ -481,6 +481,8 @@ PreambleModule::PreambleModule(QWidget * parent)
preambleTE->setFont(guiApp->typewriterSystemFont());
preambleTE->setWordWrapMode(QTextOption::NoWrap);
setFocusProxy(preambleTE);
// Install event filter on find line edit to capture return/enter key
findLE->installEventFilter(this);
connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
connect(findLE, SIGNAL(textEdited(const QString &)), this, SLOT(checkFindButton()));
connect(findButtonPB, SIGNAL(clicked()), this, SLOT(findText()));
@ -499,6 +501,23 @@ PreambleModule::PreambleModule(QWidget * parent)
}
bool PreambleModule::eventFilter(QObject * sender, QEvent * event)
{
if (sender == findLE) {
if (event->type()==QEvent::KeyPress) {
QKeyEvent * key = static_cast<QKeyEvent *>(event);
if ( (key->key()==Qt::Key_Enter) || (key->key()==Qt::Key_Return) ) {
findText();
// Return true to filter out the event
return true;
}
}
}
return QWidget::eventFilter(sender, event);
}
void PreambleModule::checkFindButton()
{
findButtonPB->setEnabled(!findLE->text().isEmpty());

View File

@ -373,6 +373,9 @@ Q_SIGNALS:
/// signal that something's changed in the Widget.
void changed();
protected:
bool eventFilter(QObject * sender, QEvent * event);
private:
void closeEvent(QCloseEvent *) override;
void on_preambleTE_textChanged() { changed(); }

View File

@ -30,7 +30,11 @@
<number>6</number>
</property>
<item row="1" column="0">
<widget class="QLineEdit" name="findLE"/>
<widget class="QLineEdit" name="findLE">
<property name="placeholderText">
<string>Find in preamble</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="findButtonPB">