]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt/GuiSearch.cpp
#12423 fix a focus change problem
[lyx.git] / src / frontends / qt / GuiSearch.cpp
index 88edf5365abe4a86fb5211c01f5c76f7f30f26a0..f12d42c11d42f155ee08a3d55f9ee4b24b27893e 100644 (file)
@@ -39,6 +39,7 @@
 #include <QPainter>
 #include <QLineEdit>
 #include <QSettings>
+#include <QHideEvent>
 #include <QShowEvent>
 #include "QSizePolicy"
 #if QT_VERSION >= 0x050000
@@ -63,8 +64,8 @@ static void uniqueInsert(QComboBox * box, QString const & text)
 }
 
 
-GuiSearchWidget::GuiSearchWidget(QWidget * parent)
-       :       QWidget(parent)
+GuiSearchWidget::GuiSearchWidget(QWidget * parent, GuiView & view)
+       :       QWidget(parent), view_(view)
 {
        setupUi(this);
 
@@ -149,6 +150,8 @@ void GuiSearchWidget::keyPressEvent(QKeyEvent * ev)
        }
        if (ev->key() == Qt::Key_Escape) {
                dispatch(FuncRequest(LFUN_DIALOG_HIDE, "findreplace"));
+               view_.setFocus();
+               bv_->buffer().updateBuffer();
                return;
        }
 
@@ -414,6 +417,16 @@ void GuiSearchWidget::showEvent(QShowEvent * e)
 }
 
 
+void GuiSearchWidget::hideEvent(QHideEvent *)
+{
+       dispatch(FuncRequest(LFUN_DIALOG_HIDE, "findreplace"));
+       view_.setFocus();
+       // update toolbar status
+       if (bv_)
+               bv_->buffer().updateBuffer();
+}
+
+
 void GuiSearchWidget::findBufferChanged()
 {
        docstring search = theClipboard().getFindBuffer();
@@ -542,8 +555,8 @@ void GuiSearchWidget::restoreSession(QString const & session_key)
        act_wholewords_->setChecked(settings.value(session_key + "/words", false).toBool());
        instantSearchCB->setChecked(settings.value(session_key + "/instant", false).toBool());
        act_immediate_->setChecked(settings.value(session_key + "/instant", false).toBool());
-       wrapCB->setChecked(settings.value(session_key + "/wrap", false).toBool());
-       act_wrap_->setChecked(settings.value(session_key + "/wrap", false).toBool());
+       wrapCB->setChecked(settings.value(session_key + "/wrap", true).toBool());
+       act_wrap_->setChecked(settings.value(session_key + "/wrap", true).toBool());
        selectionCB->setChecked(settings.value(session_key + "/selection", false).toBool());
        act_selection_->setChecked(settings.value(session_key + "/selection", false).toBool());
        minimized_ = settings.value(session_key + "/minimized", false).toBool();
@@ -554,7 +567,7 @@ void GuiSearchWidget::restoreSession(QString const & session_key)
 
 GuiSearch::GuiSearch(GuiView & parent, Qt::DockWidgetArea area, Qt::WindowFlags flags)
        : DockView(parent, "findreplace", qt_("Search and Replace"), area, flags),
-         widget_(new GuiSearchWidget(this))
+         widget_(new GuiSearchWidget(this, parent))
 {
        setWidget(widget_);
        widget_->setBufferView(bufferview());
@@ -565,29 +578,40 @@ GuiSearch::GuiSearch(GuiView & parent, Qt::DockWidgetArea area, Qt::WindowFlags
 }
 
 
-void GuiSearch::mousePressEvent(QMouseEvent *event)
+void GuiSearch::mousePressEvent(QMouseEvent * event)
 {
-    if (isFloating() && event->button() == Qt::LeftButton) {
-        dragPosition = event->globalPos() - frameGeometry().topLeft();
-        event->accept();
-    }
+       if (isFloating() && event->button() == Qt::LeftButton) {
+#if QT_VERSION >= 0x060000
+               dragPosition = event->globalPosition().toPoint() - frameGeometry().topLeft();
+#else
+               dragPosition = event->globalPos() - frameGeometry().topLeft();
+#endif
+               event->accept();
+       } else
+               DockView::mousePressEvent(event);
 }
 
 
-void GuiSearch::mouseMoveEvent(QMouseEvent *event)
+void GuiSearch::mouseMoveEvent(QMouseEvent * event)
 {
-    if (isFloating() && event->buttons() & Qt::LeftButton) {
-        move(event->globalPos() - dragPosition);
-        event->accept();
-    }
+       if (isFloating() && event->buttons() & Qt::LeftButton) {
+#if QT_VERSION >= 0x060000
+               move(event->globalPosition().toPoint() - dragPosition);
+#else
+               move(event->globalPos() - dragPosition);
+#endif
+               event->accept();
+       } else
+               DockView::mouseMoveEvent(event);
 }
 
 
-void GuiSearch::mouseDoubleClickEvent(QMouseEvent *event)
+void GuiSearch::mouseDoubleClickEvent(QMouseEvent * event)
 {
-    if (event->button() == Qt::LeftButton) {
-        setFloating(!isFloating());
-    }
+       if (event->button() == Qt::LeftButton)
+               setFloating(!isFloating());
+       else
+               DockView::mouseDoubleClickEvent(event);
 }
 
 
@@ -625,9 +649,10 @@ void GuiSearch::updateTitle()
                // remove title bar
                setTitleBarWidget(new QWidget());
                titleBarWidget()->hide();
-       } else
+       } else if (titleBarWidget()) {
                // restore title bar
                setTitleBarWidget(nullptr);
+       }
 }