mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
Adding the possibility to search for whole words only in the source viewer.
This commit is contained in:
parent
6f7d8b13f6
commit
4ae804b954
|
@ -28,6 +28,7 @@ SourceViewerSearch::SourceViewerSearch(SourceViewer* parent)
|
|||
: AnimatedWidget(AnimatedWidget::Up)
|
||||
, m_sourceViewer(parent)
|
||||
, ui(new Ui::SourceViewerSearch)
|
||||
, m_findFlags(0)
|
||||
{
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
ui->setupUi(widget());
|
||||
|
@ -42,6 +43,8 @@ SourceViewerSearch::SourceViewerSearch(SourceViewer* parent)
|
|||
connect(ui->lineEdit, SIGNAL(returnPressed()), this, SLOT(next()));
|
||||
connect(ui->next, SIGNAL(clicked()), this, SLOT(next()));
|
||||
connect(ui->previous, SIGNAL(clicked()), this, SLOT(previous()));
|
||||
connect(ui->wholeWords, SIGNAL(toggled(bool)), SLOT(searchWholeWords()));
|
||||
connect(this, SIGNAL(performSearch()), SLOT(find()));
|
||||
|
||||
QShortcut* findNextAction = new QShortcut(QKeySequence("F3"), this);
|
||||
connect(findNextAction, SIGNAL(activated()), this, SLOT(next()));
|
||||
|
@ -60,20 +63,29 @@ void SourceViewerSearch::activateLineEdit()
|
|||
|
||||
void SourceViewerSearch::next()
|
||||
{
|
||||
bool found = find(0);
|
||||
if (!found) {
|
||||
m_sourceViewer->sourceEdit()->moveCursor(QTextCursor::Start);
|
||||
}
|
||||
|
||||
ui->lineEdit->setProperty("notfound", QVariant(!found));
|
||||
|
||||
ui->lineEdit->style()->unpolish(ui->lineEdit);
|
||||
ui->lineEdit->style()->polish(ui->lineEdit);
|
||||
m_findFlags &= (~QTextDocument::FindBackward);
|
||||
emit performSearch();
|
||||
}
|
||||
|
||||
void SourceViewerSearch::previous()
|
||||
{
|
||||
bool found = find(QTextDocument::FindBackward);
|
||||
m_findFlags |= QTextDocument::FindBackward;
|
||||
emit performSearch();
|
||||
}
|
||||
|
||||
void SourceViewerSearch::searchWholeWords()
|
||||
{
|
||||
if (ui->wholeWords->isChecked()) {
|
||||
m_findFlags |= QTextDocument::FindWholeWords;
|
||||
} else {
|
||||
m_findFlags &= (~QTextDocument::FindWholeWords);
|
||||
}
|
||||
}
|
||||
|
||||
void SourceViewerSearch::find()
|
||||
{
|
||||
bool found = find(m_findFlags);
|
||||
|
||||
if (!found) {
|
||||
m_sourceViewer->sourceEdit()->moveCursor(QTextCursor::Start);
|
||||
}
|
||||
|
|
|
@ -40,19 +40,23 @@ public:
|
|||
bool eventFilter(QObject* obj, QEvent* event);
|
||||
|
||||
signals:
|
||||
void performSearch();
|
||||
|
||||
public slots:
|
||||
|
||||
private slots:
|
||||
void next();
|
||||
void previous();
|
||||
bool find(QTextDocument::FindFlags flags);
|
||||
void searchWholeWords();
|
||||
void find();
|
||||
bool find(QTextDocument::FindFlags);
|
||||
|
||||
private:
|
||||
SourceViewer* m_sourceViewer;
|
||||
Ui::SourceViewerSearch* ui;
|
||||
|
||||
QString m_lastSearchedString;
|
||||
QTextDocument::FindFlags m_findFlags;
|
||||
};
|
||||
|
||||
#endif // SOURCEVIEWERSEARCH_H
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>679</width>
|
||||
<height>40</height>
|
||||
<width>677</width>
|
||||
<height>38</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
|
@ -82,6 +82,13 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="wholeWords">
|
||||
<property name="text">
|
||||
<string>Whole words</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
|
|
Loading…
Reference in New Issue
Block a user