Skip to content

Commit

Permalink
feat: improve search in document (KDAB#25)
Browse files Browse the repository at this point in the history
Fixes tasks:
QtUiDocument
QtTsDocument
RCDocument text view
RCDocument central view
RCDocument left tree
  • Loading branch information
mgiroday committed Sep 10, 2024
1 parent 05fd9fd commit 15b61a5
Show file tree
Hide file tree
Showing 15 changed files with 968 additions and 138 deletions.
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ set(PROJECT_SOURCES
gui_constants.h
guisettings.h
guisettings.cpp
highlightsearchdelegate.h
highlightsearchdelegate.cpp
historypanel.h
historypanel.cpp
imageview.h
Expand Down
39 changes: 39 additions & 0 deletions src/gui/findwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
#include "findwidget.h"
#include "core/logger.h"
#include "core/project.h"
#include "core/qttsdocument.h"
#include "core/qtuidocument.h"
#include "core/textdocument.h"
#include "guisettings.h"
#include "qttsview.h"
#include "qtuiview.h"
#include "ui_findwidget.h"

#include <QAction>
Expand Down Expand Up @@ -86,11 +90,35 @@ QString FindWidget::findString()

void FindWidget::findNext()
{
auto qtUiDocument = qobject_cast<Core::QtUiDocument *>(Core::Project::instance()->currentDocument());
if (qtUiDocument) {
Q_EMIT search(ui->findEdit->text(), QtUiView::FindForward);
return;
}

auto qtTsDocument = qobject_cast<Core::QtTsDocument *>(Core::Project::instance()->currentDocument());
if (qtTsDocument) {
Q_EMIT search(ui->findEdit->text(), QtTsView::FindForward);
return;
}

find(findFlags());
}

void FindWidget::findPrevious()
{
auto qtUiDocument = qobject_cast<Core::QtUiDocument *>(Core::Project::instance()->currentDocument());
if (qtUiDocument) {
Q_EMIT search(ui->findEdit->text(), QtUiView::FindBackward);
return;
}

auto qtTsDocument = qobject_cast<Core::QtTsDocument *>(Core::Project::instance()->currentDocument());
if (qtTsDocument) {
Q_EMIT search(ui->findEdit->text(), QtTsView::FindBackward);
return;
}

find(findFlags() | Core::TextDocument::FindBackward);
}

Expand Down Expand Up @@ -153,4 +181,15 @@ void FindWidget::replace(bool onlyOne)
}
}

void FindWidget::hideEvent(QHideEvent *event)
{
Q_EMIT findWidgetHiding();
QWidget::hideEvent(event);
}

void FindWidget::showReplaceFeature(bool show)
{
ui->replaceFrame->setVisible(show);
}

} // namespace Gui
9 changes: 9 additions & 0 deletions src/gui/findwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ class FindWidget : public QWidget

void open();

void showReplaceFeature(bool show = true);

signals:
void search(const QString &text, int options);
void findWidgetHiding();

protected:
void hideEvent(QHideEvent *event) override;

private:
int findFlags() const;
QString findString();
Expand Down
Loading

0 comments on commit 15b61a5

Please sign in to comment.