mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
New virtual method frontend::Dialog::on_BufferViewChanged()
This is called anytime the buffer view attached to the GuiView changes.
This commit is contained in:
parent
9b4926c6e6
commit
f4c390712e
@ -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
|
||||
|
51
src/frontends/qt4/DialogView.cpp
Normal file
51
src/frontends/qt4/DialogView.cpp
Normal file
@ -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"
|
@ -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
|
||||
|
54
src/frontends/qt4/DockView.cpp
Normal file
54
src/frontends/qt4/DockView.cpp
Normal file
@ -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"
|
@ -29,20 +29,16 @@ namespace frontend {
|
||||
**/
|
||||
class DockView : public QDockWidget, public Dialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DockView(
|
||||
GuiView & parent, ///< the main window where to dock.
|
||||
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();
|
||||
}
|
||||
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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -15,7 +15,6 @@
|
||||
|
||||
#include "GuiView.h"
|
||||
|
||||
#include "Dialog.h"
|
||||
#include "DispatchResult.h"
|
||||
#include "FileDialog.h"
|
||||
#include "FontLoader.h"
|
||||
@ -1194,8 +1193,8 @@ 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());
|
||||
@ -1203,16 +1202,22 @@ void GuiView::on_currentWorkAreaChanged(GuiWorkArea * wa)
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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:
|
||||
///
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
@ -100,6 +100,8 @@ Q_SIGNALS:
|
||||
void titleChanged(GuiWorkArea *);
|
||||
///
|
||||
void busy(bool);
|
||||
///
|
||||
void bufferViewChanged();
|
||||
|
||||
private Q_SLOTS:
|
||||
/// Scroll the BufferView.
|
||||
|
@ -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 \
|
||||
|
Loading…
Reference in New Issue
Block a user