summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/findbar.cpp54
-rw-r--r--src/findbar.h4
-rw-r--r--src/mainwindow.cpp11
-rw-r--r--src/mainwindow.h8
4 files changed, 51 insertions, 26 deletions
diff --git a/src/findbar.cpp b/src/findbar.cpp
index 0e3f7385..e8dda5b2 100644
--- a/src/findbar.cpp
+++ b/src/findbar.cpp
@@ -45,6 +45,7 @@
#include <QtGui/QToolButton>
#include <QtGui/QLabel>
#include <QtGui/QColor>
+#include <QtGui/QKeyEvent>
#include <QtCore/QString>
#include <QtCore/QTimer>
@@ -67,7 +68,6 @@ FindBar::FindBar(MainWindow *window)
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);
@@ -83,7 +83,6 @@ FindBar::FindBar(MainWindow *window)
setFocusProxy(m_lineEdit);
m_lineEdit->setMaximumWidth(250);
connect(m_lineEdit, SIGNAL(textChanged(const QString &)), window, SLOT(find(const QString &)));
- connect(m_lineEdit, SIGNAL(returnPressed()), window, SLOT(findNext()));
layout->addWidget(m_lineEdit);
// buttons
@@ -103,7 +102,7 @@ FindBar::FindBar(MainWindow *window)
// Hightlight All. On by default
m_highlightAll->setCheckState(Qt::Checked);
m_highlightAll->setTristate(false);
- connect(m_highlightAll, SIGNAL(toggled(bool)), window, SLOT(highlightAll()));
+ connect(m_highlightAll, SIGNAL(toggled(bool)), window, SLOT(updateHighlight()));
layout->addWidget(m_highlightAll);
// stretching widget on the left
@@ -125,6 +124,23 @@ FindBar::~FindBar()
}
+void FindBar::keyPressEvent(QKeyEvent *event)
+{
+ if (event->key() == Qt::Key_Return)
+ {
+ if (event->modifiers() == Qt::ShiftModifier)
+ {
+ m_mainWindow->findPrevious();
+ }
+ else
+ {
+ m_mainWindow->findNext();
+ }
+ }
+ QWidget::keyPressEvent(event);
+}
+
+
bool FindBar::matchCase() const
{
return m_matchCase->isChecked();
@@ -136,29 +152,37 @@ bool FindBar::highlightAllState() const
return m_highlightAll->isChecked();
}
+
void FindBar::setVisible(bool visible)
{
QWidget::setVisible(visible);
- if (visible != isVisible())
- emit visibilityChanged(visible);
+ if (visible)
+ {
+ const QString selectedText = m_mainWindow->selectedText();
+ if (!hasFocus() && !selectedText.isEmpty())
+ {
+ const QString previousText = m_lineEdit->text();
+ m_lineEdit->setText(selectedText);
- if (visible) {
- if (!hasFocus()) {
- const QString selectedText = m_mainWindow->selectedText();
- if (!selectedText.isEmpty())
- m_lineEdit->setText(selectedText);
+ if (m_lineEdit->text() != previousText)
+ m_mainWindow->findPrevious();
+ else
+ m_mainWindow->updateHighlight();;
+ }
+ else if (selectedText.isEmpty())
+ {
+ emit searchString(m_lineEdit->text());
}
-
- // show findbar if not visible
- emit searchString(m_lineEdit->text());
m_hideTimer->start(60000);
- // set focus to findbar if user select showFindBar shortcut
m_lineEdit->setFocus();
m_lineEdit->selectAll();
- } else {
+ }
+ else
+ {
+ m_mainWindow->updateHighlight();;
m_hideTimer->stop();
}
}
diff --git a/src/findbar.h b/src/findbar.h
index 6451aac8..9aa5f039 100644
--- a/src/findbar.h
+++ b/src/findbar.h
@@ -57,9 +57,11 @@ public:
void setVisible(bool visible);
+protected:
+ void keyPressEvent(QKeyEvent *event);
+
signals:
void searchString(const QString &);
- void visibilityChanged(bool);
private:
MainWindow *m_mainWindow;
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 11580f69..92735f6f 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -370,8 +370,6 @@ void MainWindow::setupActions()
KShortcut findShortcut = KStandardShortcut::find();
findShortcut.setAlternate(Qt::Key_Slash);
a->setShortcut(findShortcut);
- a->setChecked(m_findBar->isVisible());
- connect(m_findBar, SIGNAL(visibilityChanged(bool)), a, SLOT(setChecked(bool)));
KStandardAction::findNext(this, SLOT(findNext()) , actionCollection());
KStandardAction::findPrev(this, SLOT(findPrevious()) , actionCollection());
@@ -781,6 +779,7 @@ void MainWindow::find(const QString & search)
return;
m_lastSearch = search;
+ updateHighlight();
findNext();
}
@@ -792,6 +791,7 @@ void MainWindow::matchCaseUpdate()
currentTab()->view()->findText(m_lastSearch, QWebPage::FindBackward);
findNext();
+ updateHighlight();
}
@@ -800,8 +800,6 @@ void MainWindow::findNext()
if (!currentTab())
return;
- highlightAll();
-
if (m_findBar->isHidden())
{
QPoint previous_position = currentTab()->view()->page()->currentFrame()->scrollPosition();
@@ -810,8 +808,6 @@ void MainWindow::findNext()
return;
}
- highlightAll();
-
QWebPage::FindFlags options = QWebPage::FindWrapsAroundDocument;
if (m_findBar->matchCase())
options |= QWebPage::FindCaseSensitively;
@@ -841,7 +837,8 @@ void MainWindow::findPrevious()
m_findBar->notifyMatch(found);
}
-void MainWindow::highlightAll()
+
+void MainWindow::updateHighlight()
{
if (!currentTab())
return;
diff --git a/src/mainwindow.h b/src/mainwindow.h
index cd55faa5..4180af5c 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -108,6 +108,11 @@ public slots:
virtual void configureToolbars();
+ // Find Bar slots
+ void findNext();
+ void findPrevious();
+ void updateHighlight();
+
signals:
// switching tabs
void ctrlTabPressed();
@@ -138,9 +143,6 @@ private slots:
// Find Action slots
void find(const QString &);
void matchCaseUpdate();
- void findNext();
- void findPrevious();
- void highlightAll();
// File Menu slots
void openLocation();