summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenjamin Poulain <benjamin.poulain@nokia.com>2010-08-22 01:17:43 +0200
committerBenjamin Poulain <benjamin.poulain@nokia.com>2010-08-22 04:10:58 +0200
commitfe02d0962810b1ebca33c219274a5e3390de5286 (patch)
treec922c970b2cc3039b41775abe1089e452f9ad515 /src
parentRestore bk icon on the right (diff)
downloadrekonq-fe02d0962810b1ebca33c219274a5e3390de5286.tar.xz
Make the FindBar a bit more robust
The FindBar was slots show() and hide() instead of the virtual method QWidget::setVisible(). This can lead to subtle bugs, because the behavior is different depending on the type of call (signal-slot connection VS direct call on a pointer to QWidget) and the function called (hide() is != than setVisible(false)).
Diffstat (limited to 'src')
-rw-r--r--src/findbar.cpp38
-rw-r--r--src/findbar.h4
-rw-r--r--src/mainwindow.cpp1
3 files changed, 18 insertions, 25 deletions
diff --git a/src/findbar.cpp b/src/findbar.cpp
index b3b80fac..18a4f168 100644
--- a/src/findbar.cpp
+++ b/src/findbar.cpp
@@ -138,25 +138,27 @@ 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) {
+ // 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();
@@ -180,16 +182,6 @@ void FindBar::notifyMatch(bool match)
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..974d6137 100644
--- a/src/findbar.h
+++ b/src/findbar.h
@@ -55,9 +55,9 @@ public:
void notifyMatch(bool match);
bool highlightAllState() const;
+ void setVisible(bool visible);
+
public slots:
- void show();
- void hide();
void toggleVisibility();
signals:
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 4f9d6dab..28a3bebf 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -370,6 +370,7 @@ void MainWindow::setupActions()
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());