summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/findbar.cpp57
-rw-r--r--src/findbar.h10
-rw-r--r--src/mainwindow.cpp13
-rw-r--r--src/mainwindow.h2
4 files changed, 41 insertions, 41 deletions
diff --git a/src/findbar.cpp b/src/findbar.cpp
index b3b80fac..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
@@ -138,25 +136,33 @@ bool FindBar::highlightAllState() const
return m_highlightAll->isChecked();
}
-
-void FindBar::show()
+void FindBar::setVisible(bool visible)
{
- // show findbar if not visible
- if (isHidden())
- {
- emit visibilityChanged(true);
- QWidget::show();
+ QWidget::setVisible(visible);
+
+ if (visible != isVisible())
+ 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());
- }
- m_hideTimer->start(60000);
+ m_hideTimer->start(60000);
- // set focus to findbar if user select showFindBar shortcut
- m_lineEdit->setFocus();
- m_lineEdit->selectAll();
+ // set focus to findbar if user select showFindBar shortcut
+ m_lineEdit->setFocus();
+ m_lineEdit->selectAll();
+ } else {
+ m_hideTimer->stop();
+ }
}
-
void FindBar::notifyMatch(bool match)
{
QPalette p = m_lineEdit->palette();
@@ -179,18 +185,3 @@ void FindBar::notifyMatch(bool match)
m_lineEdit->setPalette(p);
m_hideTimer->start(60000);
}
-
-
-void FindBar::hide()
-{
- m_hideTimer->stop();
- emit visibilityChanged(false);
- QWidget::hide();
- emit(searchString(m_lineEdit->text()));
-}
-
-
-void FindBar::toggleVisibility()
-{
- isVisible() ? hide() : show();
-}
diff --git a/src/findbar.h b/src/findbar.h
index 38bbcbc5..6451aac8 100644
--- a/src/findbar.h
+++ b/src/findbar.h
@@ -41,30 +41,28 @@
// 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;
void notifyMatch(bool match);
bool highlightAllState() const;
-public slots:
- void show();
- void hide();
- void toggleVisibility();
+ void setVisible(bool visible);
signals:
void searchString(const QString &);
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 4f9d6dab..44cc6d59 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -365,11 +365,11 @@ void MainWindow::setupActions()
KStandardAction::print(this, SLOT(printRequested()), actionCollection());
KStandardAction::quit(this , SLOT(close()), actionCollection());
- a = KStandardAction::find(m_findBar, SLOT(toggleVisibility()), actionCollection());
+ a = KStandardAction::find(m_findBar, SLOT(show()), actionCollection());
KShortcut findShortcut = KStandardShortcut::find();
findShortcut.setAlternate(Qt::Key_Slash);
a->setShortcut(findShortcut);
- a->setCheckable(true);
+ a->setChecked(m_findBar->isVisible());
connect(m_findBar, SIGNAL(visibilityChanged(bool)), a, SLOT(setChecked(bool)));
KStandardAction::findNext(this, SLOT(findNext()) , actionCollection());
@@ -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();