From b718b83074405298a77f0e2aa6adf201255de7c2 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Sat, 22 Nov 2008 17:35:17 +0000 Subject: [PATCH] FindAndReplace: more simplification and correct focus handling. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@27668 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/FindAndReplace.cpp | 17 +++------- src/frontends/qt4/FindAndReplace.h | 5 +-- src/frontends/qt4/GuiWorkArea.cpp | 50 ++++++++-------------------- src/frontends/qt4/GuiWorkArea.h | 12 ++----- 4 files changed, 21 insertions(+), 63 deletions(-) diff --git a/src/frontends/qt4/FindAndReplace.cpp b/src/frontends/qt4/FindAndReplace.cpp index a1314e120f..2a0024a89a 100644 --- a/src/frontends/qt4/FindAndReplace.cpp +++ b/src/frontends/qt4/FindAndReplace.cpp @@ -50,6 +50,7 @@ FindAndReplace::FindAndReplace(GuiView & parent) setupUi(this); find_work_area_->setGuiView(parent_view_); find_work_area_->init(); + setFocusProxy(find_work_area_); } @@ -133,20 +134,11 @@ void FindAndReplace::findAdv(bool casesensitive, // searchString, len, casesensitive, matchword, ! backwards, expandmacros); } - -void FindAndReplace::showEvent(QShowEvent *ev) +bool FindAndReplace::initialiseParams(std::string const &) { + find_work_area_->setFocus(); selectAll(); - QWidget::showEvent(ev); -} - - -void FindAndReplace::hideEvent(QHideEvent *ev) -{ - LYXERR(Debug::DEBUG, "FindAndReplace::hideEvent"); - find_work_area_->removeEventFilter(this); - find_work_area_->disable(); - this->QWidget::hideEvent(ev); + return true; } @@ -159,7 +151,6 @@ void FindAndReplace::find(bool backwards) expandMacrosCB->isChecked(), ignoreFormatCB->isChecked()); parent_view_.currentMainWorkArea()->redraw(); - parent_view_.setCurrentWorkArea(find_work_area_); find_work_area_->setFocus(); } diff --git a/src/frontends/qt4/FindAndReplace.h b/src/frontends/qt4/FindAndReplace.h index 10c1dc5c67..f1f89b0b01 100644 --- a/src/frontends/qt4/FindAndReplace.h +++ b/src/frontends/qt4/FindAndReplace.h @@ -36,15 +36,12 @@ class FindAndReplace : public DockView, public Ui::FindAndReplaceUi public: FindAndReplace(GuiView & parent); - bool initialiseParams(std::string const &) { return true; } + bool initialiseParams(std::string const &); void clearParams() {} void dispatchParams() {} bool isBufferDependent() const { return true; } void selectAll(); - void showEvent(QShowEvent * ev); - void hideEvent(QHideEvent * ev); - /// update void updateView() {} //virtual void update_contents() {} diff --git a/src/frontends/qt4/GuiWorkArea.cpp b/src/frontends/qt4/GuiWorkArea.cpp index bd330aee32..8e3c6911c4 100644 --- a/src/frontends/qt4/GuiWorkArea.cpp +++ b/src/frontends/qt4/GuiWorkArea.cpp @@ -1223,13 +1223,10 @@ bool GuiWorkArea::isFullScreen() //////////////////////////////////////////////////////////////////// -EmbeddedWorkArea::EmbeddedWorkArea(QWidget * w): GuiWorkArea(w), - delayed_focus_timer_(this) +EmbeddedWorkArea::EmbeddedWorkArea(QWidget * w): GuiWorkArea(w) { buffer_ = theBufferList().newBuffer( support::FileName::tempName().absFilename() + "_embedded.internal"); - LASSERT(buffer_ != 0, /* */); - buffer_->setUnnamed(true); buffer_->setFullyLoaded(true); setBuffer(*buffer_); @@ -1245,48 +1242,27 @@ EmbeddedWorkArea::~EmbeddedWorkArea() } -void EmbeddedWorkArea::onDelayedFocus() +void EmbeddedWorkArea::closeEvent(QCloseEvent * ev) { - LYXERR(Debug::DEBUG, "Delayed Focus"); - view().setCurrentWorkArea(this); - setFocus(); -} - - -void EmbeddedWorkArea::showEvent(QShowEvent *ev) -{ - view().setCurrentWorkArea(this); - redraw(); - setFocus(); - installEventFilter(this); - connect(&delayed_focus_timer_, SIGNAL(timeout()), this, - SLOT(onDelayedFocus())); - delayed_focus_timer_.setSingleShot(true); - delayed_focus_timer_.start(100); - - GuiWorkArea::showEvent(ev); -} - - -void EmbeddedWorkArea::closeEvent(QCloseEvent * close_event) -{ - LYXERR(Debug::DEBUG, "FindAndReplace::closeEvent()"); - removeEventFilter(this); disable(); + GuiWorkArea::closeEvent(ev); +} - GuiWorkArea::closeEvent(close_event); + +void EmbeddedWorkArea::hideEvent(QHideEvent * ev) +{ + disable(); + GuiWorkArea::hideEvent(ev); } void EmbeddedWorkArea::disable() { - // Ok, closing the window before 100ms may be impossible, however... - delayed_focus_timer_.stop(); - if (view().currentWorkArea() == this) { - LASSERT(view().currentMainWorkArea(), /* */); - view().setCurrentWorkArea(view().currentMainWorkArea()); - } stopBlinkingCursor(); + if (view().currentWorkArea() != this) + return; + LASSERT(view().currentMainWorkArea(), /* */); + view().setCurrentWorkArea(view().currentMainWorkArea()); } //////////////////////////////////////////////////////////////////// diff --git a/src/frontends/qt4/GuiWorkArea.h b/src/frontends/qt4/GuiWorkArea.h index 84e71298eb..06f9e2d313 100644 --- a/src/frontends/qt4/GuiWorkArea.h +++ b/src/frontends/qt4/GuiWorkArea.h @@ -278,17 +278,11 @@ public: protected: /// - void showEvent(QShowEvent * ev); - /// this happens when the dialog is simply closed/hidden - void closeEvent(QCloseEvent * e); - -private Q_SLOTS: - /// this happens 100ms after dialog showEvent() - void onDelayedFocus(); + void closeEvent(QCloseEvent * ev); + /// + void hideEvent(QHideEvent *ev); private: - /// @TODO: Investigate on focus issue and remove this ugly hack, please ! - QTimer delayed_focus_timer_; /// Embedded Buffer. Buffer * buffer_; }; // EmbeddedWorkArea