From 26eb96169454a41d0c3306b6329e8751882a2d1e Mon Sep 17 00:00:00 2001 From: Yoann Laissus Date: Sun, 14 Mar 2010 12:47:08 +0100 Subject: Implement the highlight all feature for the find bar (enabled by default) --- src/findbar.cpp | 26 ++++++++++++++++++++------ src/findbar.h | 4 +++- src/mainwindow.cpp | 20 ++++++++++++++++++++ src/mainwindow.h | 1 + 4 files changed, 44 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/findbar.cpp b/src/findbar.cpp index 4c780aca..94def263 100644 --- a/src/findbar.cpp +++ b/src/findbar.cpp @@ -52,9 +52,13 @@ FindBar::FindBar(QWidget *parent) : QWidget(parent) , m_lineEdit(new KLineEdit(this)) - , m_matchCase(new QCheckBox(i18n("&Match case"), this)) , m_hideTimer(new QTimer(this)) -{ + , m_matchCase(new QCheckBox(i18n("&Match case"), this)) + , m_highlightAll(new QCheckBox(i18n("&Highlight All"), this)) +{ + // mainwindow pointer + MainWindow *window = qobject_cast(parent); + QHBoxLayout *layout = new QHBoxLayout; // cosmetic @@ -65,6 +69,7 @@ FindBar::FindBar(QWidget *parent) hideButton->setAutoRaise(true); hideButton->setIcon(KIcon("dialog-close")); connect(hideButton, SIGNAL(clicked()), this, SLOT(hide())); + connect(hideButton, SIGNAL(clicked()), window, SLOT(highlightAll())); layout->addWidget(hideButton); layout->setAlignment(hideButton, Qt::AlignLeft | Qt::AlignTop); @@ -75,9 +80,6 @@ FindBar::FindBar(QWidget *parent) QLabel *label = new QLabel(i18n("Find:")); layout->addWidget(label); - // mainwindow pointer - MainWindow *window = qobject_cast(parent); - // lineEdit, focusProxy setFocusProxy(m_lineEdit); m_lineEdit->setMaximumWidth(250); @@ -92,13 +94,19 @@ FindBar::FindBar(QWidget *parent) connect(findPrev, SIGNAL(clicked()), window, SLOT(findPrevious())); layout->addWidget(findNext); layout->addWidget(findPrev); - + // Case sensitivity. Deliberately set so this is off by default. m_matchCase->setCheckState(Qt::Unchecked); m_matchCase->setTristate(false); connect(m_matchCase, SIGNAL(toggled(bool)), window, SLOT(matchCaseUpdate())); layout->addWidget(m_matchCase); + // Hightlight All. On by default + m_highlightAll->setCheckState(Qt::Checked); + m_highlightAll->setTristate(false); + connect(m_highlightAll, SIGNAL(toggled(bool)), window, SLOT(highlightAll())); + layout->addWidget(m_highlightAll); + // stretching widget on the left layout->addStretch(); @@ -126,6 +134,12 @@ bool FindBar::matchCase() const } +bool FindBar::highlightAllState() const +{ + return m_highlightAll->isChecked(); +} + + void FindBar::show() { // show findbar if not visible diff --git a/src/findbar.h b/src/findbar.h index 7a4efc59..78615f9a 100644 --- a/src/findbar.h +++ b/src/findbar.h @@ -53,6 +53,7 @@ public: KLineEdit *lineEdit() const; bool matchCase() const; void notifyMatch(bool match); + bool highlightAllState() const; public slots: void show(); @@ -63,8 +64,9 @@ signals: private: KLineEdit *m_lineEdit; - QCheckBox *m_matchCase; QTimer *m_hideTimer; + QCheckBox *m_matchCase; + QCheckBox *m_highlightAll; }; #endif diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 60784af0..e90a5903 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -794,6 +794,8 @@ void MainWindow::findNext() return; } + highlightAll(); + QWebPage::FindFlags options = QWebPage::FindWrapsAroundDocument; if (m_findBar->matchCase()) options |= QWebPage::FindCaseSensitively; @@ -823,6 +825,24 @@ void MainWindow::findPrevious() m_findBar->notifyMatch(found); } +void MainWindow::highlightAll() +{ + if (!currentTab()) + return; + + QWebPage::FindFlags options = QWebPage::HighlightAllOccurrences; + + currentTab()->view()->findText("", options); //Clear an existing highlight + + if(m_findBar->highlightAllState() && !m_findBar->isHidden()) + { + if (m_findBar->matchCase()) + options |= QWebPage::FindCaseSensitively; + + currentTab()->view()->findText(m_lastSearch, options); + } +} + void MainWindow::zoomIn() { diff --git a/src/mainwindow.h b/src/mainwindow.h index 57b88dfd..e9da090d 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -130,6 +130,7 @@ private slots: void matchCaseUpdate(); void findNext(); void findPrevious(); + void highlightAll(); // Zoom slots void zoomIn(); -- cgit v1.2.1 From e1877d4f49ef414182f37448e1338822e5c77517 Mon Sep 17 00:00:00 2001 From: Yoann Laissus Date: Sun, 14 Mar 2010 15:46:55 +0100 Subject: Fix capitalisation of "Highlight All" --- src/findbar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/findbar.cpp b/src/findbar.cpp index 94def263..7cbe9d17 100644 --- a/src/findbar.cpp +++ b/src/findbar.cpp @@ -54,7 +54,7 @@ FindBar::FindBar(QWidget *parent) , m_lineEdit(new KLineEdit(this)) , m_hideTimer(new QTimer(this)) , m_matchCase(new QCheckBox(i18n("&Match case"), this)) - , m_highlightAll(new QCheckBox(i18n("&Highlight All"), this)) + , m_highlightAll(new QCheckBox(i18n("&Highlight all"), this)) { // mainwindow pointer MainWindow *window = qobject_cast(parent); -- cgit v1.2.1 From 65f0f138d29e1f34626d8a25683bfe0a059fb8dc Mon Sep 17 00:00:00 2001 From: Yoann Laissus Date: Sun, 14 Mar 2010 23:34:45 +0100 Subject: Clear all the highlight when the find bar is closed with the esc key --- src/findbar.cpp | 1 - src/mainwindow.cpp | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/findbar.cpp b/src/findbar.cpp index 7cbe9d17..c97fd1f9 100644 --- a/src/findbar.cpp +++ b/src/findbar.cpp @@ -69,7 +69,6 @@ FindBar::FindBar(QWidget *parent) hideButton->setAutoRaise(true); hideButton->setIcon(KIcon("dialog-close")); connect(hideButton, SIGNAL(clicked()), this, SLOT(hide())); - connect(hideButton, SIGNAL(clicked()), window, SLOT(highlightAll())); layout->addWidget(hideButton); layout->setAlignment(hideButton, Qt::AlignLeft | Qt::AlignTop); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index e90a5903..b5df7acb 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -786,6 +786,8 @@ void MainWindow::findNext() if (!currentTab()) return; + highlightAll(); + if(m_findBar->isHidden()) { QPoint previous_position = currentTab()->view()->page()->currentFrame()->scrollPosition(); @@ -794,8 +796,6 @@ void MainWindow::findNext() return; } - highlightAll(); - QWebPage::FindFlags options = QWebPage::FindWrapsAroundDocument; if (m_findBar->matchCase()) options |= QWebPage::FindCaseSensitively; -- cgit v1.2.1