]> git.lyx.org Git - features.git/commitdiff
Transfer more things from FindAndReplace to EmbeddedWorkArea.
authorAbdelrazak Younes <younes@lyx.org>
Sat, 22 Nov 2008 15:21:45 +0000 (15:21 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Sat, 22 Nov 2008 15:21:45 +0000 (15:21 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@27664 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/FindAndReplace.cpp
src/frontends/qt4/FindAndReplace.h
src/frontends/qt4/GuiWorkArea.cpp
src/frontends/qt4/GuiWorkArea.h

index 64c61d7b497f11d6de0e3831cab47393e124f32e..a1314e120ff36399bd43a6007c4846d7ed1329f2 100644 (file)
 
 #include "FindAndReplace.h"
 
-
-#include "GuiWorkArea.h"
-#include "GuiView.h"
+#include "GuiApplication.h"
 #include "qt_helpers.h"
+#include "GuiView.h"
+#include "GuiWorkArea.h"
 
-#include "Application.h"
 #include "buffer_funcs.h"
 #include "BufferParams.h"
 #include "Cursor.h"
 #include "output_latex.h"
 #include "TexRow.h"
 
-#include "support/FileName.h"
 #include "support/convert.h"
 #include "support/debug.h"
+#include "support/FileName.h"
 #include "support/gettext.h"
 #include "support/lassert.h"
 
-#include <QLineEdit>
 #include <QCloseEvent>
+#include <QLineEdit>
 
 #include <iostream>
 
@@ -44,11 +43,9 @@ using namespace lyx::support;
 namespace lyx {
 namespace frontend {
 
-
 FindAndReplace::FindAndReplace(GuiView & parent)
        : DockView(parent, "Find LyX", "Find LyX Dialog", Qt::RightDockWidgetArea),
-       parent_view_(parent),
-       delayedFocusTimer_(this)
+       parent_view_(parent)
 {
        setupUi(this);
        find_work_area_->setGuiView(parent_view_);
@@ -74,22 +71,11 @@ bool FindAndReplace::eventFilter(QObject *obj, QEvent *event)
                        }
                }
        }
-
        // standard event processing
        return QObject::eventFilter(obj, event);
 }
 
 
-void FindAndReplace::closeEvent(QCloseEvent * close_event)
-{
-       LYXERR(Debug::DEBUG, "FindAndReplace::closeEvent()");
-       find_work_area_->removeEventFilter(this);
-       disableSearchWorkArea();
-
-       DockView::closeEvent(close_event);
-}
-
-
 void FindAndReplace::selectAll()
 {
        dispatch(FuncRequest(LFUN_BUFFER_BEGIN));
@@ -104,7 +90,7 @@ void FindAndReplace::findAdv(bool casesensitive,
 {
        Buffer & buffer = find_work_area_->bufferView().buffer();
        docstring searchString;
-       if (! ignoreformat) {
+       if (!ignoreformat) {
                OutputParams runparams(&buffer.params().encoding());
                odocstringstream os;
                runparams.nice = true;
@@ -114,14 +100,18 @@ void FindAndReplace::findAdv(bool casesensitive,
                runparams.dryrun = true;
                buffer.texrow().reset();
 //             latexParagraphs(buffer, buffer.paragraphs(), os, buffer.texrow(), runparams);
-               for (ParagraphList::const_iterator pit = buffer.paragraphs().begin(); pit != buffer.paragraphs().end(); ++pit) {
+               ParagraphList::const_iterator pit = buffer.paragraphs().begin();
+               ParagraphList::const_iterator const end = buffer.paragraphs().end();
+               for (; pit != end; ++pit) {
                        TeXOnePar(buffer, buffer.text(), pit, os, buffer.texrow(), runparams);
-                       lyxerr << "searchString up to here: " << to_utf8(os.str()) << std::endl;
+                       LYXERR0("searchString up to here: " << os.str());
                }
                searchString = os.str();
        } else {
-               for (ParIterator it = buffer.par_iterator_begin(); it != buffer.par_iterator_end(); ++it) {
-                       lyxerr << "Adding to search string: '" << to_utf8(it->asString(false)) << "'" << std::endl;
+               ParIterator it = buffer.par_iterator_begin();
+               ParIterator end = buffer.par_iterator_end();
+               for (; it != end; ++it) {
+                       LYXERR0("Adding to search string: '" << it->asString(false) << "'");
                        searchString += it->asString(AS_STR_INSETS);
                }
        }
@@ -130,8 +120,9 @@ void FindAndReplace::findAdv(bool casesensitive,
                buffer.message(_("Nothing to search"));
                return;
        }
-       bool regexp = (to_utf8(searchString).find("\\regexp") != std::string::npos);
-       FindAdvOptions opt(searchString, casesensitive, matchword, ! backwards, expandmacros, ignoreformat, regexp);
+       bool const regexp = to_utf8(searchString).find("\\regexp") != std::string::npos;
+       FindAdvOptions opt(searchString, casesensitive, matchword, ! backwards,
+               expandmacros, ignoreformat, regexp);
        std::cerr << "Dispatching LFUN_WORD_FINDADV" << std::endl;
        std::ostringstream oss;
        oss << opt;
@@ -143,40 +134,10 @@ void FindAndReplace::findAdv(bool casesensitive,
 }
 
 
-void FindAndReplace::onDelayedFocus()
-{
-       LYXERR(Debug::DEBUG, "Delayed Focus");
-       parent_view_.setCurrentWorkArea(find_work_area_);
-       find_work_area_->setFocus();
-}
-
-
 void FindAndReplace::showEvent(QShowEvent *ev)
 {
-       LYXERR(Debug::DEBUG, "FindAndReplace::showEvent");
-       parent_view_.setCurrentWorkArea(find_work_area_);
        selectAll();
-       find_work_area_->redraw();
-       find_work_area_->setFocus();
-       find_work_area_->installEventFilter(this);
-       connect(&delayedFocusTimer_, SIGNAL(timeout()), this, SLOT(onDelayedFocus()));
-       delayedFocusTimer_.setSingleShot(true);
-       delayedFocusTimer_.start(100);
-
-       this->QWidget::showEvent(ev);
-}
-
-
-void FindAndReplace::disableSearchWorkArea()
-{
-       LYXERR(Debug::DEBUG, "FindAndReplace::disableSearchWorkArea()");
-       // Ok, closing the window before 100ms may be impossible, however...
-       delayedFocusTimer_.stop();
-       if (parent_view_.currentWorkArea() == find_work_area_) {
-               LASSERT(parent_view_.currentMainWorkArea(), /* */);
-               parent_view_.setCurrentWorkArea(parent_view_.currentMainWorkArea());
-       }
-       find_work_area_->stopBlinkingCursor();
+       QWidget::showEvent(ev);
 }
 
 
@@ -184,7 +145,7 @@ void FindAndReplace::hideEvent(QHideEvent *ev)
 {
        LYXERR(Debug::DEBUG, "FindAndReplace::hideEvent");
        find_work_area_->removeEventFilter(this);
-       disableSearchWorkArea();
+       find_work_area_->disable();
        this->QWidget::hideEvent(ev);
 }
 
@@ -220,8 +181,9 @@ void FindAndReplace::on_regexpInsertCombo_currentIndexChanged(int index)
 }
 
 
-void FindAndReplace::on_closePB_clicked() {
-       disableSearchWorkArea();
+void FindAndReplace::on_closePB_clicked()
+{
+       find_work_area_->disable();
        LYXERR(Debug::DEBUG, "Dispatching dialog-hide findreplaceadv" << std::endl);
        parent_view_.dispatch(FuncRequest(LFUN_DIALOG_TOGGLE, "findreplaceadv"));
 }
index 572f82b6e4c87817df2766a5f83f1372880c5df5..10c1dc5c6719fb1a5f5d91ac0961102bd4200b12 100644 (file)
@@ -72,10 +72,6 @@ private:
 
        GuiWorkArea * searchWorkArea_;  // The work area defining what to search
 
-       /// @TODO: Investigate on focus issue and remove this ugly hack, please !
-       QTimer delayedFocusTimer_;
-       void disableSearchWorkArea();
-
 private:
        /// Apply changes
        virtual void apply() {}
@@ -87,12 +83,6 @@ private:
                     docstring const & replacestr,
                     bool casesens, bool words, bool backwards, bool expandmacros, bool all);
        bool eventFilter(QObject *obj, QEvent *event);
-
-public Q_SLOTS:
-       /// this happens when the dialog is simply closed/hidden
-       void closeEvent(QCloseEvent * e);
-       /// this happens 100ms after dialog showEvent()
-       void onDelayedFocus();
 };
 
 
index e05bd8aff7579ba85e1786353bbd4b1cc039583d..bd330aee3258e8ec623af0275ff22c394de048c7 100644 (file)
@@ -1223,7 +1223,8 @@ bool GuiWorkArea::isFullScreen()
 ////////////////////////////////////////////////////////////////////
 
 
-EmbeddedWorkArea::EmbeddedWorkArea(QWidget * w): GuiWorkArea(w)
+EmbeddedWorkArea::EmbeddedWorkArea(QWidget * w): GuiWorkArea(w),
+       delayed_focus_timer_(this)
 {
        buffer_ = theBufferList().newBuffer(
                support::FileName::tempName().absFilename() + "_embedded.internal");
@@ -1236,15 +1237,57 @@ EmbeddedWorkArea::EmbeddedWorkArea(QWidget * w): GuiWorkArea(w)
        setDialogMode(true);
 }
 
+
 EmbeddedWorkArea::~EmbeddedWorkArea()
 {
        // No need to destroy buffer and bufferview here, because it is done
        // in theBuffeerList() destruction loop at application exit
-       LYXERR(Debug::DEBUG, "FindAndReplace::~FindAndReplace()");
 }
 
 
+void EmbeddedWorkArea::onDelayedFocus()
+{
+       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(close_event);
+}
+
 
+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();
+}
 
 ////////////////////////////////////////////////////////////////////
 //
index 784ae76876cc9d61f1f739e3ca3a496652aa338f..84e71298eb01d6c7d94d6c21f30de92a49fd7b15 100644 (file)
@@ -273,7 +273,22 @@ public:
        void setWidgetResizable(bool) {}
        void setWidget(QWidget *) {}
 
+       ///
+       void disable();
+
+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();
+
 private:
+       /// @TODO: Investigate on focus issue and remove this ugly hack, please !
+       QTimer delayed_focus_timer_;
        /// Embedded Buffer.
        Buffer * buffer_;
 }; // EmbeddedWorkArea