Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve search in novel text #212

Merged
merged 1 commit into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/core/management_layer/plugins/novel_text/novel_text_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "text/novel_text_edit_shortcuts_manager.h"
#include "text/novel_text_edit_toolbar.h"
#include "text/novel_text_search_manager.h"
#include "text/novel_text_search_toolbar.h"

#include <business_layer/document/text/text_block_data.h>
#include <business_layer/document/text/text_cursor.h>
Expand Down Expand Up @@ -134,6 +135,11 @@ class NovelTextView::Implementation
void addReviewMark(const QColor& _textColor, const QColor& _backgroundColor,
const QString& _comment);

/**
* @brief Сменить панель инструментов на панель поиска
*/
void switchToSearchTollbar();


NovelTextView* q = nullptr;

Expand Down Expand Up @@ -588,6 +594,19 @@ void NovelTextView::Implementation::addReviewMark(const QColor& _textColor,
scalableWrapper->setFocus();
}

void NovelTextView::Implementation::switchToSearchTollbar()
{
toolbarAnimation->switchToolbars(toolbar->searchIcon(), toolbar->searchIconPosition(), toolbar,
searchManager->toolbar());
auto searchToolbar = qobject_cast<NovelTextSearchToolbar*>(searchManager->toolbar());
if (const auto selectedText = textEdit->textCursor().selectedText(); !selectedText.isEmpty()) {
searchToolbar->setSearchText(selectedText);
searchToolbar->selectSearchText();
} else {
searchToolbar->selectSearchText();
}
}


// ****

Expand Down Expand Up @@ -666,11 +685,8 @@ NovelTextView::NovelTextView(QWidget* _parent)
const bool animate = false;
d->textEdit->ensureCursorVisible(d->textEdit->textCursor(), animate);
});
connect(d->toolbar, &NovelTextEditToolbar::searchPressed, this, [this] {
d->toolbarAnimation->switchToolbars(d->toolbar->searchIcon(),
d->toolbar->searchIconPosition(), d->toolbar,
d->searchManager->toolbar());
});
connect(d->toolbar, &NovelTextEditToolbar::searchPressed, this,
[this] { d->switchToSearchTollbar(); });
//
connect(d->searchManager, &BusinessLayer::NovelTextSearchManager::hideToolbarRequested, this,
[this] { d->toolbarAnimation->switchToolbarsBack(); });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,16 @@ QString NovelTextSearchToolbar::replaceText() const
return d->replaceText->text();
}

void NovelTextSearchToolbar::setSearchText(const QString& _text)
{
d->searchText->setText(_text);
}

void NovelTextSearchToolbar::selectSearchText()
{
d->searchText->selectAll();
}

bool NovelTextSearchToolbar::eventFilter(QObject* _watched, QEvent* _event)
{
switch (_event->type()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ class NovelTextSearchToolbar : public FloatingToolBar
*/
QString replaceText() const;

/**
* @brief Установить текст в поле поиска
*/
void setSearchText(const QString& _text);

/**
* @brief Выделить текст в поле поиска
*/
void selectSearchText();

signals:
/**
* @brief Пользователь хочет закрыть панель поиска
Expand Down
Loading