From fe02d0962810b1ebca33c219274a5e3390de5286 Mon Sep 17 00:00:00 2001 From: Benjamin Poulain Date: Sun, 22 Aug 2010 01:17:43 +0200 Subject: 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)). --- src/findbar.cpp | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) (limited to 'src/findbar.cpp') 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(); -- cgit v1.2.1