diff --git a/src/MainWindow.h b/src/MainWindow.h index c493d51c..d0d4cb89 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -115,6 +115,15 @@ private slots: void hideEditor(); void preferences(); +private slots: + void find(); + void findNext(); + void findPrev(); + void useSelectionForFind(); +protected: + void findOperation(QTextDocument::FindFlags options = 0); + virtual bool eventFilter(QObject* obj, QEvent *event); + private slots: void actionRenderPreview(); void csgRender(); diff --git a/src/MainWindow.ui b/src/MainWindow.ui index 147a41f2..711c6aeb 100644 --- a/src/MainWindow.ui +++ b/src/MainWindow.ui @@ -15,7 +15,16 @@ - + + 0 + + + 0 + + + 0 + + 0 @@ -23,13 +32,86 @@ Qt::Horizontal - - - - Monaco - 8 - - + + + + + + true + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Raised + + + 0 + + + + 5 + + + 0 + + + 5 + + + 0 + + + + + Find + + + + + + + + + + < + + + + + + + > + + + + + + + Done + + + + + + + + + + + Monaco + 8 + + + + + @@ -61,7 +143,16 @@ 0 - + + 0 + + + 0 + + + 0 + + 0 @@ -165,6 +256,11 @@ + + + + + @@ -653,6 +749,38 @@ Preferences + + + Find... + + + Ctrl+F + + + + + Find Next + + + Ctrl+G + + + + + Find Previous + + + Ctrl+Shift+G + + + + + Use Selection for Find + + + Ctrl+E + + Flush Caches diff --git a/src/mainwin.cc b/src/mainwin.cc index cc46ced2..bdf93697 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -210,6 +210,7 @@ MainWindow::MainWindow(const QString &filename) connect(this->e_fps, SIGNAL(textChanged(QString)), this, SLOT(updatedFps())); animate_panel->hide(); + find_panel->hide(); // Application menu #ifdef DEBUG @@ -282,6 +283,11 @@ MainWindow::MainWindow(const QString &filename) connect(this->editActionZoomOut, SIGNAL(triggered()), editor, SLOT(zoomOut())); connect(this->editActionHide, SIGNAL(triggered()), this, SLOT(hideEditor())); connect(this->editActionPreferences, SIGNAL(triggered()), this, SLOT(preferences())); + // Edit->Find + connect(this->editActionFind, SIGNAL(triggered()), this, SLOT(find())); + connect(this->editActionFindNext, SIGNAL(triggered()), this, SLOT(findNext())); + connect(this->editActionFindPrevious, SIGNAL(triggered()), this, SLOT(findPrev())); + connect(this->editActionUseSelectionForFind, SIGNAL(triggered()), this, SLOT(useSelectionForFind())); // Design menu connect(this->designActionAutoReload, SIGNAL(toggled(bool)), this, SLOT(autoReloadSet(bool))); @@ -371,6 +377,13 @@ MainWindow::MainWindow(const QString &filename) this, SLOT(setSyntaxHighlight(const QString&))); Preferences::inst()->apply(); + connect(this->findInputField, SIGNAL(returnPressed()), this, SLOT(findNext())); + find_panel->installEventFilter(this); + + connect(this->prevButton, SIGNAL(clicked()), this, SLOT(findPrev())); + connect(this->nextButton, SIGNAL(clicked()), this, SLOT(findNext())); + connect(this->hideFindButton, SIGNAL(clicked()), find_panel, SLOT(hide())); + // make sure it looks nice.. QSettings settings; resize(settings.value("window/size", QSize(800, 600)).toSize()); @@ -1088,6 +1101,60 @@ void MainWindow::pasteViewportRotation() cursor.insertText(txt); } +void MainWindow::find() +{ + find_panel->show(); + findInputField->setFocus(); + findInputField->selectAll(); +} + +void MainWindow::findOperation(QTextDocument::FindFlags options) { + bool success = editor->find(findInputField->text(), options); + if (!success) { // Implement wrap-around search behavior + QTextCursor old_cursor = editor->textCursor(); + QTextCursor tmp_cursor = old_cursor; + tmp_cursor.movePosition((options & QTextDocument::FindBackward) ? QTextCursor::End : QTextCursor::Start); + editor->setTextCursor(tmp_cursor); + bool success = editor->find(findInputField->text(), options); + if (!success) { + editor->setTextCursor(old_cursor); + } + } +} + +void MainWindow::findNext() +{ + findOperation(); +} + +void MainWindow::findPrev() +{ + findOperation(QTextDocument::FindBackward); +} + +void MainWindow::useSelectionForFind() +{ + findInputField->setText(editor->textCursor().selectedText()); +} + +bool MainWindow::eventFilter(QObject* obj, QEvent *event) +{ + if (obj == find_panel) + { + if (event->type() == QEvent::KeyPress) + { + QKeyEvent* keyEvent = static_cast(event); + if (keyEvent->key() == Qt::Key_Escape) + { + find_panel->hide(); + return true; + } + } + return false; + } + return QMainWindow::eventFilter(obj, event); +} + void MainWindow::updateTemporalVariables() { this->top_ctx.set_variable("$t", Value(this->e_tval->text().toDouble()));