Commit 47ec0d1d authored by jhammen's avatar jhammen

basic text search function

parent d8ed1474
......@@ -33,6 +33,7 @@ SOURCES += \
outputwidget.cpp \
projectlist.cpp \
projectsdialog.cpp \
searchwidget.cpp \
synhighlighter.cpp
HEADERS += \
......@@ -40,6 +41,7 @@ HEADERS += \
editorwidget.h \
scriptrun.h \
outputwidget.h \
searchwidget.h \
style.h \
projectlist.h \
foldertreeitem.h \
......@@ -62,7 +64,8 @@ unix {
FORMS += \
mainwindow.ui \
outputwidget.ui \
projectsdialog.ui
projectsdialog.ui \
searchwidget.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
......
......@@ -81,6 +81,23 @@ bool EditorWidget::save() {
return true;
}
uint32_t EditorWidget::searchText(const QString &term) {
moveCursor(QTextCursor::Start);
QList<QTextEdit::ExtraSelection> selections;
uint32_t count = 0;
while (find(term)) {
QTextEdit::ExtraSelection extra;
extra.cursor = textCursor();
extra.format.fontUnderline();
QColor color(210, 210, 210);
extra.format.setBackground(color);
selections.append(extra);
count++;
}
setExtraSelections(selections);
return count;
}
void EditorWidget::focusLine(int line, int column) {
QTextCursor cursor = textCursor();
cursor.movePosition(QTextCursor::Start);
......
......@@ -55,6 +55,7 @@ class EditorWidget : public QPlainTextEdit {
bool hasSelection() { return textCursor().hasSelection(); }
bool load();
bool save();
uint32_t searchText(const QString &term);
void focusLine(int line, int column = 0);
void commentSelection();
void moveFile(NamedFile &file) { mfile = file; }
......
clang-format -style="{BasedOnStyle: llvm, IndentWidth: 4, ColumnLimit: 100}" -i ./*.h ./*.cpp
......@@ -54,6 +54,10 @@ MainWindow::MainWindow(QWidget *parent)
ui->outputDockWidget->setHidden(true);
ui->folderTree->setColumnCount(1);
//
searchWidget = new SearchWidget();
ui->leftTabWidget->addTab(searchWidget, "Search");
connect(searchWidget, SIGNAL(searchCurrent(QString)), this, SLOT(searchCurrent(QString)));
ProjectList &projectList = ProjectList::getProjectList();
projectList.load();
......@@ -201,6 +205,14 @@ void MainWindow::markDirty(bool value) {
setWindowModified(value);
}
void MainWindow::searchCurrent(const QString &term) {
EditorWidget *editor = currentEditor();
if (editor) {
uint32_t results = editor->searchText(term);
searchWidget->results(results);
}
}
void MainWindow::showTime(Position pos) {
QTime qtime(0, 0, 0);
qtime = qtime.addMSecs(pos.msec);
......@@ -482,6 +494,11 @@ void MainWindow::on_actionRewind_triggered() {
void MainWindow::on_actionSaveFile_triggered() { currentEditor()->save(); }
void MainWindow::on_actionFocusFind_triggered() {
searchWidget->newFileSearch();
ui->leftTabWidget->setCurrentWidget(searchWidget);
}
void MainWindow::on_actionStartStopTransport_toggled(bool start) {
if (start) {
audioEngine.transportStart();
......
......@@ -23,6 +23,7 @@
#include "outputwidget.h"
#include "position.h"
#include "projectlist.h"
#include "searchwidget.h"
#include <QFileInfo>
#include <QLabel>
......@@ -48,6 +49,7 @@ class MainWindow : public QMainWindow {
void folderTreeClicked(QTreeWidgetItem *item, int col);
void handleLink(const QUrl &);
void markDirty(bool unsaved);
void searchCurrent(const QString &);
void showTime(Position pos);
void tabChanged(int index);
void closeOtherEditors();
......@@ -78,6 +80,7 @@ class MainWindow : public QMainWindow {
void on_actionUndo_triggered();
void on_actionWebsite_triggered();
void on_tabWidget_customContextMenuRequested(const QPoint &pos);
void on_actionFocusFind_triggered();
private:
QString *selectedFolder;
......@@ -86,6 +89,7 @@ class MainWindow : public QMainWindow {
uint transportPosition;
AudioConfiguration audioConfig;
Ui::MainWindow *ui;
SearchWidget *searchWidget;
QLabel timeWidget;
QLabel bbtWidget;
QLabel engineWidget;
......
......@@ -23,18 +23,26 @@
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QTreeWidget" name="folderTree">
<property name="columnCount">
<number>1</number>
<widget class="QTabWidget" name="leftTabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QTreeWidget" name="folderTree">
<property name="columnCount">
<number>1</number>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
<attribute name="title">
<string>Filesystem</string>
</attribute>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</widget>
<widget class="QTabWidget" name="tabWidget">
<property name="sizePolicy">
......@@ -96,6 +104,8 @@
<addaction name="actionPaste"/>
<addaction name="separator"/>
<addaction name="actionComment"/>
<addaction name="separator"/>
<addaction name="actionFocusFind"/>
</widget>
<widget class="QMenu" name="menuTransport">
<property name="title">
......@@ -504,6 +514,21 @@
<string>F2</string>
</property>
</action>
<action name="actionFocusFind">
<property name="icon">
<iconset theme="edit-find">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>Find</string>
</property>
<property name="toolTip">
<string>Find text</string>
</property>
<property name="shortcut">
<string>Ctrl+F</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
......
#include "searchwidget.h"
#include "ui_searchwidget.h"
SearchWidget::SearchWidget(QWidget *parent) : QWidget(parent), ui(new Ui::SearchWidget) {
ui->setupUi(this);
}
void SearchWidget::newFileSearch() {
ui->searchLineEdit->setFocus();
ui->searchLineEdit->selectAll();
}
void SearchWidget::results(uint32_t results) {
QString mesg = QString("%1 results").arg(results);
ui->countLabel->setText(mesg);
}
SearchWidget::~SearchWidget() { delete ui; }
void SearchWidget::on_searchButton_clicked() {
QLineEdit *lineEdit = this->ui->searchLineEdit;
emit searchCurrent(lineEdit->text());
}
void SearchWidget::on_searchLineEdit_returnPressed() {
QLineEdit *lineEdit = this->ui->searchLineEdit;
emit searchCurrent(lineEdit->text());
}
#ifndef SEARCHWIDGET_H
#define SEARCHWIDGET_H
#include <QWidget>
namespace Ui {
class SearchWidget;
}
class SearchWidget : public QWidget {
Q_OBJECT
public:
explicit SearchWidget(QWidget *parent = nullptr);
void newFileSearch();
void results(uint32_t results);
~SearchWidget();
signals:
void searchCurrent(QString);
private slots:
void on_searchButton_clicked();
void on_searchLineEdit_returnPressed();
private:
Ui::SearchWidget *ui;
};
#endif // SEARCHWIDGET_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SearchWidget</class>
<widget class="QWidget" name="SearchWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>496</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="searchLineEdit"/>
</item>
<item>
<widget class="QPushButton" name="searchButton">
<property name="text">
<string>Find</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QRadioButton" name="radioButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Find in current file</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="countLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QTreeWidget" name="treeWidget">
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment