summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenjamin Poulain <benjamin.poulain@nokia.com>2010-08-22 04:06:54 +0200
committerBenjamin Poulain <benjamin.poulain@nokia.com>2010-08-22 04:18:37 +0200
commit67138dcf8e3a1788928fd31256b29a257dae5eee (patch)
tree5acfb521de78d5a09ec475b4e7baa288c1967041 /src
parentChange the Find action to show() instead of toggle() (diff)
downloadrekonq-67138dcf8e3a1788928fd31256b29a257dae5eee.tar.xz
Use the selected text as the default search string of the FindBar
The common behavior of the Find action is to start a search with the current selected text if any. This patch implement this behavior for Rekonq.
Diffstat (limited to 'src')
-rw-r--r--src/findbar.cpp14
-rw-r--r--src/findbar.h5
-rw-r--r--src/mainwindow.cpp9
-rw-r--r--src/mainwindow.h2
4 files changed, 23 insertions, 7 deletions
diff --git a/src/findbar.cpp b/src/findbar.cpp
index bad3bf50..0e3f7385 100644
--- a/src/findbar.cpp
+++ b/src/findbar.cpp
@@ -49,16 +49,14 @@
#include <QtCore/QTimer>
-FindBar::FindBar(QWidget *parent)
- : QWidget(parent)
+FindBar::FindBar(MainWindow *window)
+ : QWidget(window)
+ , m_mainWindow(window)
, 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))
{
- // mainwindow pointer
- MainWindow *window = qobject_cast<MainWindow *>(parent);
-
QHBoxLayout *layout = new QHBoxLayout;
// cosmetic
@@ -146,6 +144,12 @@ void FindBar::setVisible(bool visible)
emit visibilityChanged(visible);
if (visible) {
+ if (!hasFocus()) {
+ const QString selectedText = m_mainWindow->selectedText();
+ if (!selectedText.isEmpty())
+ m_lineEdit->setText(selectedText);
+ }
+
// show findbar if not visible
emit searchString(m_lineEdit->text());
diff --git a/src/findbar.h b/src/findbar.h
index d82e9722..6451aac8 100644
--- a/src/findbar.h
+++ b/src/findbar.h
@@ -41,14 +41,14 @@
// Forward Declarations
class QString;
-
+class MainWindow;
class REKONQ_TESTS_EXPORT FindBar : public QWidget
{
Q_OBJECT
public:
- FindBar(QWidget *parent);
+ FindBar(MainWindow *parent);
~FindBar();
bool matchCase() const;
@@ -62,6 +62,7 @@ signals:
void visibilityChanged(bool);
private:
+ MainWindow *m_mainWindow;
KLineEdit *m_lineEdit;
QTimer *m_hideTimer;
QCheckBox *m_matchCase;
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 5eb43aa0..44cc6d59 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -907,6 +907,15 @@ void MainWindow::setWidgetsVisible(bool makeVisible)
}
+QString MainWindow::selectedText() const
+{
+ if (!currentTab())
+ return QString();
+
+ return currentTab()->view()->selectedText();
+}
+
+
void MainWindow::viewPageSource()
{
if (!currentTab())
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 3aa57f5c..cd55faa5 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -80,6 +80,8 @@ public:
virtual QSize sizeHint() const;
void setWidgetsVisible(bool makeFullScreen);
+ QString selectedText() const;
+
private:
void setupBookmarksAndToolsShortcuts();
void setupActions();