commit f4c390712ea835cc04a3da13b0fff59db66cf359
Author: Guillaume Munch <g...@lyx.org>
Date:   Wed Sep 28 21:33:44 2016 +0200

    New virtual method frontend::Dialog::on_BufferViewChanged()
    
    This is called anytime the buffer view attached to the GuiView changes.
---
 src/frontends/qt4/Dialog.h        |    2 +
 src/frontends/qt4/DialogView.cpp  |   51 ++++++++++++++++++++++++++++++++++
 src/frontends/qt4/DialogView.h    |   28 +++++-------------
 src/frontends/qt4/DockView.cpp    |   54 +++++++++++++++++++++++++++++++++++++
 src/frontends/qt4/DockView.h      |   42 +++++++++-------------------
 src/frontends/qt4/GuiDialog.cpp   |    3 ++
 src/frontends/qt4/GuiDialog.h     |    3 ++
 src/frontends/qt4/GuiView.cpp     |   35 +++++++++++------------
 src/frontends/qt4/GuiView.h       |    2 +
 src/frontends/qt4/GuiWorkArea.cpp |    1 +
 src/frontends/qt4/GuiWorkArea.h   |    2 +
 src/frontends/qt4/Makefile.am     |    6 +++-
 12 files changed, 161 insertions(+), 68 deletions(-)

diff --git a/src/frontends/qt4/Dialog.h b/src/frontends/qt4/Dialog.h
index f3f9c1d..bf4a313 100644
--- a/src/frontends/qt4/Dialog.h
+++ b/src/frontends/qt4/Dialog.h
@@ -264,6 +264,8 @@ protected:
        void setTitle(QString const & title) { title_ = title; }
        ///
        virtual void apply();
+       /// To be called when the buffer view has changed
+       virtual void on_bufferViewChanged() = 0;
 
 private:
        /** The Dialog's name is the means by which a dialog identifies
diff --git a/src/frontends/qt4/DialogView.cpp b/src/frontends/qt4/DialogView.cpp
new file mode 100644
index 0000000..7b9ee9c
--- /dev/null
+++ b/src/frontends/qt4/DialogView.cpp
@@ -0,0 +1,51 @@
+// -*- C++ -*-
+/**
+ * \file DialogView.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "DialogView.h"
+
+
+namespace lyx {
+namespace frontend {
+
+DialogView::DialogView(GuiView & lv, QString const & name, QString const & 
title)
+       : QDialog(&lv), Dialog(lv, name, "LyX: " + title)
+{
+       connect(&lv, SIGNAL(bufferViewChanged()),
+               this, SLOT(on_bufferViewChanged()));
+
+       // remove question marks from Windows dialogs
+       setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
+}
+
+
+void DialogView::closeEvent(QCloseEvent * ev)
+{
+       clearParams();
+       Dialog::disconnect();
+       ev->accept();
+}
+
+
+void DialogView::hideEvent(QHideEvent * ev)
+{
+       if (!ev->spontaneous()) {
+               clearParams();
+               Dialog::disconnect();
+               ev->accept();
+       }
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "moc_DialogView.cpp"
diff --git a/src/frontends/qt4/DialogView.h b/src/frontends/qt4/DialogView.h
index 520a1e8..180bcb1 100644
--- a/src/frontends/qt4/DialogView.h
+++ b/src/frontends/qt4/DialogView.h
@@ -23,17 +23,14 @@ namespace frontend {
 
 class DialogView : public QDialog, public Dialog
 {
+       Q_OBJECT
+
 public:
        /// \param lv is the access point for the dialog to the LyX kernel.
        /// \param name is the identifier given to the dialog by its parent
        /// container.
        /// \param title is the window title used for decoration.
-       DialogView(GuiView & lv, QString const & name, QString const & title)
-               : QDialog(&lv), Dialog(lv, name, "LyX: " + title)
-       {
-               // remove question marks from Windows dialogs
-               setWindowFlags(windowFlags() & 
~Qt::WindowContextHelpButtonHint);
-       }
+       DialogView(GuiView & lv, QString const & name, QString const & title);
 
        virtual QWidget * asQWidget() { return this; }
        virtual QWidget const * asQWidget() const { return this; }
@@ -47,21 +44,12 @@ protected:
        bool needBufferOpen() const { return isBufferDependent(); }
        //@}
        /// Any dialog that overrides this method should make sure to call it.
-       void closeEvent(QCloseEvent * ev)
-       {
-               clearParams();
-               Dialog::disconnect();
-               ev->accept();
-       }
+       void closeEvent(QCloseEvent * ev);
        /// Any dialog that overrides this method should make sure to call it.
-       void hideEvent(QHideEvent * ev)
-       {
-               if (!ev->spontaneous()) {
-                       clearParams();
-                       Dialog::disconnect();
-                       ev->accept();
-               }
-       }
+       void hideEvent(QHideEvent * ev);
+
+protected Q_SLOTS:
+       void on_bufferViewChanged() {};
 };
 
 } // namespace frontend
diff --git a/src/frontends/qt4/DockView.cpp b/src/frontends/qt4/DockView.cpp
new file mode 100644
index 0000000..ea385ee
--- /dev/null
+++ b/src/frontends/qt4/DockView.cpp
@@ -0,0 +1,54 @@
+// -*- C++ -*-
+/**
+ * \file DockView.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "DockView.h"
+
+
+namespace lyx {
+namespace frontend {
+
+
+DockView::DockView(GuiView & parent, QString const & name,
+                   QString const & title, Qt::DockWidgetArea area,
+                   Qt::WindowFlags flags)
+       : QDockWidget(&parent, flags), Dialog(parent, name, title)
+{
+       setObjectName(name);
+       parent.addDockWidget(area, this);
+       hide();
+       connect(&parent, SIGNAL(bufferViewChanged()),
+               this, SLOT(on_bufferViewChanged()));
+}
+
+
+void DockView::keyPressEvent(QKeyEvent * ev)
+{
+       if (ev->key() == Qt::Key_Escape) {
+               QMainWindow * mw = static_cast<QMainWindow *>(parent());
+               if (!mw) {
+                       ev->ignore();
+                       return;
+               }
+               mw->activateWindow();
+               mw->setFocus();
+               if (isFloating())
+                       hide();
+               ev->accept();
+       }
+}
+
+
+} // frontend
+} // lyx
+
+#include "moc_DockView.cpp"
diff --git a/src/frontends/qt4/DockView.h b/src/frontends/qt4/DockView.h
index d71b75b..3c5f764 100644
--- a/src/frontends/qt4/DockView.h
+++ b/src/frontends/qt4/DockView.h
@@ -29,20 +29,16 @@ namespace frontend {
  **/
 class DockView : public QDockWidget, public Dialog
 {
+       Q_OBJECT
+
 public:
-       DockView(
-               GuiView & parent, ///< the main window where to dock.
-               QString const & name, ///< dialog identifier.
-               QString const & title, ///< dialog title.
-               Qt::DockWidgetArea area = Qt::LeftDockWidgetArea, ///< Position 
of the dock (and also drawer)
-               Qt::WindowFlags flags = 0
-       )
-               : QDockWidget(&parent, flags), Dialog(parent, name, title)
-       {
-               setObjectName(name);
-               parent.addDockWidget(area, this);
-               hide();
-       }
+       DockView(GuiView & parent, ///< the main window where to dock.
+                QString const & name, ///< dialog identifier.
+                QString const & title, ///< dialog title.
+                Qt::DockWidgetArea area = Qt::LeftDockWidgetArea, ///< 
Position of
+                                                                               
                                           ///the dock (and
+                                                                               
                                           ///also drawer)
+                Qt::WindowFlags flags = 0);
 
        virtual ~DockView() {}
 
@@ -52,27 +48,17 @@ public:
        /// We don't want to restore geometry session for dock widgets.
        void restoreSession() {}
 
-       void keyPressEvent(QKeyEvent * ev)
-       {
-               if (ev->key() == Qt::Key_Escape) {
-                       QMainWindow * mw = static_cast<QMainWindow *>(parent());
-                       if (!mw) {
-                               ev->ignore();
-                               return;
-                       }
-                       mw->activateWindow();
-                       mw->setFocus();
-                       if (isFloating())
-                               hide();
-                       ev->accept();
-               }
-       }
+       void keyPressEvent(QKeyEvent * ev);
+
        /// Dialog inherited methods
        //@{
        void applyView() {}
        bool isClosing() const { return false; }
        bool needBufferOpen() const { return false; }
        //@}
+
+protected Q_SLOTS:
+       void on_bufferViewChanged() {} //override
 };
 
 } // frontend
diff --git a/src/frontends/qt4/GuiDialog.cpp b/src/frontends/qt4/GuiDialog.cpp
index 8f8a872..91ee667 100644
--- a/src/frontends/qt4/GuiDialog.cpp
+++ b/src/frontends/qt4/GuiDialog.cpp
@@ -28,6 +28,9 @@ GuiDialog::GuiDialog(GuiView & lv, QString const & name, 
QString const & title)
        : QDialog(&lv), Dialog(lv, name, "LyX: " + title), updating_(false), 
          is_closing_(false)
 {
+       connect(&lv, SIGNAL(bufferViewChanged()),
+               this, SLOT(on_bufferViewChanged()));
+
        // remove question marks from Windows dialogs
        setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
 }
diff --git a/src/frontends/qt4/GuiDialog.h b/src/frontends/qt4/GuiDialog.h
index 1e95fc5..20ffde0 100644
--- a/src/frontends/qt4/GuiDialog.h
+++ b/src/frontends/qt4/GuiDialog.h
@@ -59,6 +59,9 @@ public Q_SLOTS:
        ///
        void closeEvent(QCloseEvent * e);
 
+protected Q_SLOTS:
+       void on_bufferViewChanged() {};//override
+
 public:
        /** Check whether we may apply our data.
         *
diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp
index cb06f34..b6c2781 100644
--- a/src/frontends/qt4/GuiView.cpp
+++ b/src/frontends/qt4/GuiView.cpp
@@ -15,7 +15,6 @@
 
 #include "GuiView.h"
 
-#include "Dialog.h"
 #include "DispatchResult.h"
 #include "FileDialog.h"
 #include "FontLoader.h"
@@ -1194,25 +1193,31 @@ void GuiView::updateWindowTitle(GuiWorkArea * wa)
 void GuiView::on_currentWorkAreaChanged(GuiWorkArea * wa)
 {
        if (d.current_work_area_)
-               QObject::disconnect(d.current_work_area_, SIGNAL(busy(bool)),
-                       this, SLOT(setBusy(bool)));
+               // disconnect the current work area from all slots
+               QObject::disconnect(d.current_work_area_, 0, this, 0);
        disconnectBuffer();
        disconnectBufferView();
        connectBufferView(wa->bufferView());
        connectBuffer(wa->bufferView().buffer());
        d.current_work_area_ = wa;
        QObject::connect(wa, SIGNAL(titleChanged(GuiWorkArea *)),
-               this, SLOT(updateWindowTitle(GuiWorkArea *)));
-       QObject::connect(wa, SIGNAL(busy(bool)), this, SLOT(setBusy(bool)));
-       updateWindowTitle(wa);
+                        this, SLOT(updateWindowTitle(GuiWorkArea *)));
+       QObject::connect(wa, SIGNAL(busy(bool)),
+                        this, SLOT(setBusy(bool)));
+       QObject::connect(wa, SIGNAL(bufferViewChanged()),
+                        this, SIGNAL(bufferViewChanged()));
+       Q_EMIT updateWindowTitle(wa);
+       Q_EMIT bufferViewChanged();
 
        structureChanged();
 
        // The document settings needs to be reinitialised.
+       // TODO: no longer needed now there is bufferViewChanged?
        updateDialog("document", "");
 
        // Buffer-dependent dialogs must be updated. This is done here because
        // some dialogs require buffer()->text.
+       // TODO: no longer needed now there is bufferViewChanged?
        updateDialogs();
 }
 
@@ -1228,6 +1233,8 @@ void GuiView::on_lastWorkAreaRemoved()
                return;
 
        // Reset and updates the dialogs.
+       Q_EMIT bufferViewChanged();
+       // TODO: no longer needed now there is bufferViewChanged?
        d.toc_models_.reset(0);
        updateDialog("document", "");
        updateDialogs();
@@ -1310,19 +1317,10 @@ bool GuiView::event(QEvent * e)
                        
cap::saveSelection(old_view->currentBufferView()->cursor());
                }
                guiApp->setCurrentView(this);
-               if (d.current_work_area_) {
-                       BufferView & bv = d.current_work_area_->bufferView();
-                       connectBufferView(bv);
-                       connectBuffer(bv.buffer());
-                       // The document structure, name and dialogs might have
-                       // changed in another view.
-                       structureChanged();
-                       // The document settings needs to be reinitialised.
-                       updateDialog("document", "");
-                       updateDialogs();
-               } else {
+               if (d.current_work_area_)
+                       on_currentWorkAreaChanged(d.current_work_area_);
+               else
                        resetWindowTitle();
-               }
                setFocus();
                return QMainWindow::event(e);
        }
@@ -1477,6 +1475,7 @@ void GuiView::setCurrentWorkArea(GuiWorkArea * wa)
        if (!wa) {
                d.current_work_area_ = 0;
                d.setBackground();
+               Q_EMIT bufferViewChanged();
                return;
        }
 
diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h
index d396421..c71b1f6 100644
--- a/src/frontends/qt4/GuiView.h
+++ b/src/frontends/qt4/GuiView.h
@@ -214,6 +214,8 @@ public:
 Q_SIGNALS:
        void closing(int);
        void triggerShowDialog(QString const & qname, QString const & qdata, 
Inset * inset);
+       // emitted when the work area or its buffer view changed
+       void bufferViewChanged();
 
 public Q_SLOTS:
        ///
diff --git a/src/frontends/qt4/GuiWorkArea.cpp 
b/src/frontends/qt4/GuiWorkArea.cpp
index a0f57fe..31df06b 100644
--- a/src/frontends/qt4/GuiWorkArea.cpp
+++ b/src/frontends/qt4/GuiWorkArea.cpp
@@ -392,6 +392,7 @@ void GuiWorkArea::setBuffer(Buffer & buffer)
        if (buffer.text().paragraphs().size() > 4)
                setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
        QTimer::singleShot(50, this, SLOT(fixVerticalScrollBar()));
+       Q_EMIT bufferViewChanged();
 }
 
 
diff --git a/src/frontends/qt4/GuiWorkArea.h b/src/frontends/qt4/GuiWorkArea.h
index a039f0e..a8b7c5a 100644
--- a/src/frontends/qt4/GuiWorkArea.h
+++ b/src/frontends/qt4/GuiWorkArea.h
@@ -100,6 +100,8 @@ Q_SIGNALS:
        void titleChanged(GuiWorkArea *);
        ///
        void busy(bool);
+       ///
+       void bufferViewChanged();
 
 private Q_SLOTS:
        /// Scroll the BufferView.
diff --git a/src/frontends/qt4/Makefile.am b/src/frontends/qt4/Makefile.am
index 190e888..299e3c6 100644
--- a/src/frontends/qt4/Makefile.am
+++ b/src/frontends/qt4/Makefile.am
@@ -61,6 +61,8 @@ SOURCEFILES = \
        CategorizedCombo.cpp \
        ColorCache.cpp \
        CustomizedWidgets.cpp \
+       DialogView.cpp \
+       DockView.cpp \
        EmptyTable.cpp \
        FancyLineEdit.cpp \
        FileDialog.cpp \
@@ -159,8 +161,6 @@ SOURCEFILES = \
 NOMOCHEADER = \
        ButtonController.h \
        ColorCache.h \
-       DialogView.h \
-       DockView.h \
        FileDialog.h \
        GuiFontExample.h \
        GuiFontLoader.h \
@@ -180,6 +180,8 @@ MOCHEADER = \
        BulletsModule.h \
        CategorizedCombo.h \
        CustomizedWidgets.h \
+       DialogView.h \
+       DockView.h \
        EmptyTable.h \
        FancyLineEdit.h \
        FindAndReplace.h \

Reply via email to