Issue #119: Improve search bar 2 (the revenge)

This commit is contained in:
Jakub Melka 2023-12-09 15:41:08 +01:00
parent 5a6f448467
commit d50ecdbb28
8 changed files with 140 additions and 83 deletions

View File

@ -533,7 +533,7 @@ void PDFAsynchronousTextLayoutCompiler::makeTextLayout()
m_isRunning = true;
ProgressStartupInfo info;
info.showDialog = true;
info.showDialog = false;
info.text = tr("Indexing document contents...");
m_proxy->getFontCache()->setCacheShrinkEnabled(this, false);

View File

@ -35,6 +35,7 @@
#include <QApplication>
#include <QStylePainter>
#include <QStyleOptionTitleBar>
namespace pdf
{
@ -222,27 +223,6 @@ void PDFWidgetTool::removeTool()
m_toolStack.pop_back();
}
class PDFFindTextToolDialog : public QDialog
{
public:
PDFFindTextToolDialog(PDFDrawWidgetProxy* proxy, QWidget* parent, Qt::WindowFlags f) :
QDialog(parent, f),
m_proxy(proxy)
{
}
virtual ~PDFFindTextToolDialog() override = default;
virtual bool event(QEvent* event) override;
protected:
virtual void paintEvent(QPaintEvent* event) override;
private:
PDFDrawWidgetProxy* m_proxy;
};
void PDFFindTextToolDialog::paintEvent(QPaintEvent* event)
{
QDialog::paintEvent(event);
@ -269,6 +249,13 @@ void PDFFindTextToolDialog::paintEvent(QPaintEvent* event)
painter.drawPrimitive(QStyle::PE_Frame, frameOption);
}
PDFFindTextToolDialog::PDFFindTextToolDialog(PDFDrawWidgetProxy* proxy, QWidget* parent, Qt::WindowFlags f) :
QDialog(parent, f),
m_proxy(proxy)
{
}
bool PDFFindTextToolDialog::event(QEvent* event)
{
switch (event->type())
@ -294,6 +281,37 @@ bool PDFFindTextToolDialog::event(QEvent* event)
break;
}
case QEvent::KeyPress:
{
QKeyEvent* keyEvent = dynamic_cast<QKeyEvent*>(event);
if (!keyEvent->modifiers() || ((keyEvent->modifiers() & Qt::KeypadModifier) && keyEvent->key() == Qt::Key_Enter))
{
switch (keyEvent->key())
{
case Qt::Key_Return:
case Qt::Key_Enter:
case Qt::Key_Home:
{
keyEvent->accept();
Q_EMIT goToFirstResult();
return true;
}
case Qt::Key_End:
{
keyEvent->accept();
Q_EMIT goToLastResult();
return true;
}
default:
break;
}
}
break;
}
default:
break;
}
@ -399,7 +417,7 @@ void PDFFindTextTool::setActiveImpl(bool active)
m_wholeWordsCheckBox->setChecked(m_savedIsWholeWords);
m_previousButton->setDefault(false);
m_nextButton->setDefault(false);
m_nextButton->setDefault(true);
m_previousButton->setShortcut(m_prevAction->shortcut());
m_nextButton->setShortcut(m_nextAction->shortcut());
@ -409,6 +427,8 @@ void PDFFindTextTool::setActiveImpl(bool active)
connect(m_findTextEdit, &QLineEdit::editingFinished, this, &PDFFindTextTool::onSearchText);
connect(m_caseSensitiveCheckBox, &QCheckBox::clicked, this, &PDFFindTextTool::onSearchText);
connect(m_wholeWordsCheckBox, &QCheckBox::clicked, this, &PDFFindTextTool::onSearchText);
connect(m_dialog, &PDFFindTextToolDialog::goToFirstResult, this, &PDFFindTextTool::onActionFirst);
connect(m_dialog, &PDFFindTextToolDialog::goToLastResult, this, &PDFFindTextTool::onActionLast);
QMargins margins = layout->contentsMargins();
margins.setTop(margins.top() + m_dialog->style()->pixelMetric(QStyle::PM_TitleBarHeight));
@ -487,22 +507,27 @@ void PDFFindTextTool::onSearchText()
}
}
void PDFFindTextTool::onActionFirst()
{
if (!m_findResults.empty())
{
setCurrentResultIndex(0);
}
}
void PDFFindTextTool::onActionLast()
{
if (!m_findResults.empty())
{
setCurrentResultIndex(m_findResults.size() - 1);
}
}
void PDFFindTextTool::onActionPrevious()
{
if (!m_findResults.empty())
{
if (m_selectedResultIndex == 0)
{
m_selectedResultIndex = m_findResults.size() - 1;
}
else
{
--m_selectedResultIndex;
}
m_textSelection.dirty();
getProxy()->repaintNeeded();
goToCurrentResult();
updateTitle();
setCurrentResultIndex(m_selectedResultIndex == 0 ? m_findResults.size() - 1 : m_selectedResultIndex - 1);
}
}
@ -510,7 +535,15 @@ void PDFFindTextTool::onActionNext()
{
if (!m_findResults.empty())
{
m_selectedResultIndex = (m_selectedResultIndex + 1) % m_findResults.size();
setCurrentResultIndex((m_selectedResultIndex + 1) % m_findResults.size());
}
}
void PDFFindTextTool::setCurrentResultIndex(size_t index)
{
if (!m_findResults.empty())
{
m_selectedResultIndex = index;
m_textSelection.dirty();
getProxy()->repaintNeeded();
goToCurrentResult();

View File

@ -145,6 +145,26 @@ private:
std::optional<QCursor> m_cursor;
};
class PDFFindTextToolDialog : public QDialog
{
Q_OBJECT
public:
PDFFindTextToolDialog(PDFDrawWidgetProxy* proxy, QWidget* parent, Qt::WindowFlags f);
virtual ~PDFFindTextToolDialog() override = default;
virtual bool event(QEvent* event) override;
signals:
void goToFirstResult();
void goToLastResult();
protected:
virtual void paintEvent(QPaintEvent* event) override;
private:
PDFDrawWidgetProxy* m_proxy;
};
/// Simple tool for find text in PDF document. It is much simpler than advanced
/// search and can't search using regular expressions.
class PDFFindTextTool : public PDFWidgetTool
@ -176,10 +196,13 @@ protected:
private:
void onSearchText();
void onActionFirst();
void onActionLast();
void onActionPrevious();
void onActionNext();
void onDialogRejected();
void setCurrentResultIndex(size_t index);
void performSearch();
void updateResultsUI();
void updateTitle();
@ -190,7 +213,7 @@ private:
QAction* m_nextAction;
QWidget* m_parentDialog;
QDialog* m_dialog;
PDFFindTextToolDialog* m_dialog;
QCheckBox* m_caseSensitiveCheckBox;
QCheckBox* m_wholeWordsCheckBox;
QLineEdit* m_findTextEdit;

View File

@ -89,7 +89,8 @@ PDFViewerMainWindow::PDFViewerMainWindow(QWidget* parent) :
m_isLoadingUI(false),
m_progress(new pdf::PDFProgress(this)),
m_progressTaskbarIndicator(new PDFWinTaskBarProgress(this)),
m_progressDialog(nullptr),
m_progressBarOnStatusBar(nullptr),
m_progressBarLeftLabelOnStatusBar(nullptr),
m_isChangingProgressStep(false)
{
ui->setupUi(this);
@ -100,6 +101,14 @@ PDFViewerMainWindow::PDFViewerMainWindow(QWidget* parent) :
adjustToolbar(ui->mainToolBar);
ui->mainToolBar->setWindowTitle(tr("Standard"));
// Initialize status bar
m_progressBarOnStatusBar = new QProgressBar(this);
m_progressBarOnStatusBar->setHidden(true);
m_progressBarLeftLabelOnStatusBar = new QLabel(this);
m_progressBarLeftLabelOnStatusBar->setHidden(true);
statusBar()->addPermanentWidget(m_progressBarLeftLabelOnStatusBar);
statusBar()->addPermanentWidget(m_progressBarOnStatusBar);
// Initialize actions
m_actionManager->setAction(PDFActionManager::Open, ui->actionOpen);
m_actionManager->setAction(PDFActionManager::Close, ui->actionClose);
@ -353,13 +362,12 @@ void PDFViewerMainWindow::onPageZoomSpinboxEditingFinished()
void PDFViewerMainWindow::onProgressStarted(pdf::ProgressStartupInfo info)
{
Q_ASSERT(!m_progressDialog);
if (info.showDialog)
{
m_progressDialog = new QProgressDialog(info.text, QString(), 0, 100, this);
m_progressDialog->setWindowModality(Qt::WindowModal);
m_progressDialog->setCancelButton(nullptr);
}
m_progressBarLeftLabelOnStatusBar->setText(info.text);
m_progressBarLeftLabelOnStatusBar->setVisible(!info.text.isEmpty());
m_progressBarOnStatusBar->setRange(0, 100);
m_progressBarOnStatusBar->reset();
m_progressBarOnStatusBar->show();
m_progressTaskbarIndicator->setRange(0, 100);
m_progressTaskbarIndicator->reset();
@ -377,24 +385,14 @@ void PDFViewerMainWindow::onProgressStep(int percentage)
}
pdf::PDFTemporaryValueChange guard(&m_isChangingProgressStep, true);
if (m_progressDialog)
{
m_progressDialog->setValue(percentage);
}
m_progressBarOnStatusBar->setValue(percentage);
m_progressTaskbarIndicator->setValue(percentage);
}
void PDFViewerMainWindow::onProgressFinished()
{
if (m_progressDialog)
{
m_progressDialog->hide();
m_progressDialog->deleteLater();
m_progressDialog = nullptr;
}
m_progressBarLeftLabelOnStatusBar->hide();
m_progressBarOnStatusBar->hide();
m_progressTaskbarIndicator->hide();
m_programController->setIsBusy(false);

View File

@ -41,7 +41,8 @@
#include <QTreeView>
#include <QMainWindow>
#include <QFutureWatcher>
#include <QProgressDialog>
#include <QLabel>
#include <QProgressBar>
class QLabel;
class QSpinBox;
@ -120,7 +121,8 @@ private:
pdf::PDFProgress* m_progress;
PDFWinTaskBarProgress* m_progressTaskbarIndicator;
QProgressDialog* m_progressDialog;
QProgressBar* m_progressBarOnStatusBar;
QLabel* m_progressBarLeftLabelOnStatusBar;
bool m_isChangingProgressStep;
};

View File

@ -88,7 +88,8 @@ PDFViewerMainWindowLite::PDFViewerMainWindowLite(QWidget* parent) :
m_isLoadingUI(false),
m_progress(new pdf::PDFProgress(this)),
m_progressTaskbarIndicator(new PDFWinTaskBarProgress(this)),
m_progressDialog(nullptr),
m_progressBarOnStatusBar(nullptr),
m_progressBarLeftLabelOnStatusBar(nullptr),
m_isChangingProgressStep(false)
{
ui->setupUi(this);
@ -99,6 +100,14 @@ PDFViewerMainWindowLite::PDFViewerMainWindowLite(QWidget* parent) :
adjustToolbar(ui->mainToolBar);
ui->mainToolBar->setWindowTitle(tr("Standard"));
// Initialize status bar
m_progressBarOnStatusBar = new QProgressBar(this);
m_progressBarOnStatusBar->setHidden(true);
m_progressBarLeftLabelOnStatusBar = new QLabel(this);
m_progressBarLeftLabelOnStatusBar->setHidden(true);
statusBar()->addPermanentWidget(m_progressBarLeftLabelOnStatusBar);
statusBar()->addPermanentWidget(m_progressBarOnStatusBar);
// Initialize actions
m_actionManager->setAction(PDFActionManager::Open, ui->actionOpen);
m_actionManager->setAction(PDFActionManager::Close, ui->actionClose);
@ -270,13 +279,12 @@ void PDFViewerMainWindowLite::onPageZoomSpinboxEditingFinished()
void PDFViewerMainWindowLite::onProgressStarted(pdf::ProgressStartupInfo info)
{
Q_ASSERT(!m_progressDialog);
if (info.showDialog)
{
m_progressDialog = new QProgressDialog(info.text, QString(), 0, 100, this);
m_progressDialog->setWindowModality(Qt::WindowModal);
m_progressDialog->setCancelButton(nullptr);
}
m_progressBarLeftLabelOnStatusBar->setText(info.text);
m_progressBarLeftLabelOnStatusBar->setVisible(!info.text.isEmpty());
m_progressBarOnStatusBar->setRange(0, 100);
m_progressBarOnStatusBar->reset();
m_progressBarOnStatusBar->show();
m_progressTaskbarIndicator->setRange(0, 100);
m_progressTaskbarIndicator->reset();
@ -294,24 +302,14 @@ void PDFViewerMainWindowLite::onProgressStep(int percentage)
}
pdf::PDFTemporaryValueChange guard(&m_isChangingProgressStep, true);
if (m_progressDialog)
{
m_progressDialog->setValue(percentage);
}
m_progressBarOnStatusBar->setValue(percentage);
m_progressTaskbarIndicator->setValue(percentage);
}
void PDFViewerMainWindowLite::onProgressFinished()
{
if (m_progressDialog)
{
m_progressDialog->hide();
m_progressDialog->deleteLater();
m_progressDialog = nullptr;
}
m_progressBarLeftLabelOnStatusBar->hide();
m_progressBarOnStatusBar->hide();
m_progressTaskbarIndicator->hide();
m_programController->setIsBusy(false);

View File

@ -40,7 +40,8 @@
#include <QTreeView>
#include <QMainWindow>
#include <QFutureWatcher>
#include <QProgressDialog>
#include <QProgressBar>
#include <QLabel>
class QLabel;
class QSpinBox;
@ -115,7 +116,8 @@ private:
pdf::PDFProgress* m_progress;
PDFWinTaskBarProgress* m_progressTaskbarIndicator;
QProgressDialog* m_progressDialog;
QProgressBar* m_progressBarOnStatusBar;
QLabel* m_progressBarLeftLabelOnStatusBar;
bool m_isChangingProgressStep;
};

View File

@ -1,4 +1,5 @@
CURRENT:
- Issue #119: Improve search bar 2 (the revenge)
- Issue #118: Adding CMAKE options for minimal builds
- Issue #116: Improve search bar (rembember searched text, allow scroll and zoom)
- Issue #115: Redesign of sidebar widget, new icons