diff options
author | Oskar Linde <oskar.linde@gmail.com> | 2014-02-01 10:46:05 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2014-02-06 05:46:06 (GMT) |
commit | 4f5882566c43e9ba09c99e23431ad12890f1e3a6 (patch) | |
tree | bd1644337854ece8fe9f8bc7fe50fd73212684e9 | |
parent | 55192e46a4c0a977b7a9a35650b027c7a410ab14 (diff) |
Editor: Implemented simple Find functionality
Conflicts:
src/MainWindow.h
-rw-r--r-- | src/MainWindow.h | 9 | ||||
-rw-r--r-- | src/MainWindow.ui | 146 | ||||
-rw-r--r-- | src/mainwin.cc | 67 |
3 files changed, 213 insertions, 9 deletions
diff --git a/src/MainWindow.h b/src/MainWindow.h index 4948d46..a908be0 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -117,6 +117,15 @@ private slots: private slots: void actionRenderCSG(); + 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 csgRender(); void csgReloadRender(); #ifdef ENABLE_CGAL diff --git a/src/MainWindow.ui b/src/MainWindow.ui index 4cb043f..0b03e56 100644 --- a/src/MainWindow.ui +++ b/src/MainWindow.ui @@ -15,7 +15,16 @@ </property> <widget class="QWidget" name="centralwidget"> <layout class="QVBoxLayout" name="verticalLayout_2"> - <property name="margin"> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="topMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> <number>0</number> </property> <item> @@ -23,13 +32,86 @@ <property name="orientation"> <enum>Qt::Horizontal</enum> </property> - <widget class="Editor" name="editor" native="true"> - <property name="font"> - <font> - <family>Monaco</family> - <pointsize>8</pointsize> - </font> - </property> + <widget class="QWidget" name="editorlayoutwidget"> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <widget class="QFrame" name="find_panel"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Minimum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="frameShape"> + <enum>QFrame::NoFrame</enum> + </property> + <property name="frameShadow"> + <enum>QFrame::Raised</enum> + </property> + <property name="lineWidth"> + <number>0</number> + </property> + <layout class="QHBoxLayout" name="horizontalLayout"> + <property name="leftMargin"> + <number>5</number> + </property> + <property name="topMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>5</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Find</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="findInputField"/> + </item> + <item> + <widget class="QPushButton" name="prevButton"> + <property name="text"> + <string><</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="nextButton"> + <property name="text"> + <string>></string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="hideFindButton"> + <property name="text"> + <string>Done</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="Editor" name="editor" native="true"> + <property name="font"> + <font> + <family>Monaco</family> + <pointsize>8</pointsize> + </font> + </property> + </widget> + </item> + </layout> </widget> <widget class="QWidget" name="layoutWidget"> <layout class="QVBoxLayout" name="verticalLayout"> @@ -61,7 +143,16 @@ <number>0</number> </property> <layout class="QHBoxLayout" name="horizontalLayout"> - <property name="margin"> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="topMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> <number>0</number> </property> <item> @@ -165,6 +256,11 @@ <addaction name="editActionPasteVPT"/> <addaction name="editActionPasteVPR"/> <addaction name="separator"/> + <addaction name="editActionFind"/> + <addaction name="editActionFindNext"/> + <addaction name="editActionFindPrevious"/> + <addaction name="editActionUseSelectionForFind"/> + <addaction name="separator"/> <addaction name="editActionZoomIn"/> <addaction name="editActionZoomOut"/> <addaction name="editActionPreferences"/> @@ -653,6 +749,38 @@ <string>Preferences</string> </property> </action> + <action name="editActionFind"> + <property name="text"> + <string>Find...</string> + </property> + <property name="shortcut"> + <string>Ctrl+F</string> + </property> + </action> + <action name="editActionFindNext"> + <property name="text"> + <string>Find Next</string> + </property> + <property name="shortcut"> + <string>Ctrl+G</string> + </property> + </action> + <action name="editActionFindPrevious"> + <property name="text"> + <string>Find Previous</string> + </property> + <property name="shortcut"> + <string>Ctrl+Shift+G</string> + </property> + </action> + <action name="editActionUseSelectionForFind"> + <property name="text"> + <string>Use Selection for Find</string> + </property> + <property name="shortcut"> + <string>Ctrl+E</string> + </property> + </action> <action name="designActionFlushCaches"> <property name="text"> <string>Flush Caches</string> diff --git a/src/mainwin.cc b/src/mainwin.cc index c2a7b7e..07dff73 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -212,6 +212,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 @@ -284,6 +285,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))); @@ -373,6 +379,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()); @@ -1091,6 +1104,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<QKeyEvent*>(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())); |