mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
Factorize general code out of GuiDialog and into the base Dialog class. This is now possible thanks to the moving of Dialog.{cpp,h} to qt4/. Any dialog must inherit QWidget within Qt so it is safe to use Dialog::asQWidget() method (which is similar to dynamic casting).
* GuiDialog now inherits DialogView. GuiDialog is only there to bring the ButtonController archaeological interface; any new dialog should inherit DialogView and any new dock widget should inherit DockView. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22049 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
0e2ec55add
commit
604c1148ea
@ -19,8 +19,12 @@
|
||||
#include "FuncStatus.h"
|
||||
#include "LyXFunc.h"
|
||||
|
||||
#include "support/Debug.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
@ -122,5 +126,120 @@ Buffer const & Dialog::buffer() const
|
||||
return *lyxview_->buffer();
|
||||
}
|
||||
|
||||
|
||||
void Dialog::showData(string const & data)
|
||||
{
|
||||
if (isBufferDependent() && !isBufferAvailable())
|
||||
return;
|
||||
|
||||
if (!initialiseParams(data)) {
|
||||
LYXERR0("Dialog \"" << name()
|
||||
<< "\" failed to translate the data string passed to show()");
|
||||
return;
|
||||
}
|
||||
|
||||
showView();
|
||||
}
|
||||
|
||||
|
||||
void Dialog::apply()
|
||||
{
|
||||
if (isBufferDependent()) {
|
||||
if (!isBufferAvailable() ||
|
||||
(isBufferReadonly() && !canApplyToReadOnly()))
|
||||
return;
|
||||
}
|
||||
|
||||
applyView();
|
||||
dispatchParams();
|
||||
|
||||
if (disconnectOnApply() && !isClosing()) {
|
||||
disconnect();
|
||||
initialiseParams(string());
|
||||
updateView();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Dialog::updateData(string const & data)
|
||||
{
|
||||
if (isBufferDependent() && !isBufferAvailable())
|
||||
return;
|
||||
|
||||
if (!initialiseParams(data)) {
|
||||
LYXERR0("Dialog \"" << name()
|
||||
<< "\" could not be initialized");
|
||||
return;
|
||||
}
|
||||
|
||||
updateView();
|
||||
}
|
||||
|
||||
|
||||
void Dialog::showView()
|
||||
{
|
||||
updateView(); // make sure its up-to-date
|
||||
if (exitEarly())
|
||||
return;
|
||||
|
||||
QWidget * w = asQWidget();
|
||||
QSize const hint = w->sizeHint();
|
||||
if (hint.height() >= 0 && hint.width() >= 0)
|
||||
w->setMinimumSize(hint);
|
||||
|
||||
if (w->isVisible()) {
|
||||
w->raise();
|
||||
w->activateWindow();
|
||||
} else
|
||||
w->show();
|
||||
|
||||
w->setFocus();
|
||||
}
|
||||
|
||||
|
||||
void Dialog::hideView()
|
||||
{
|
||||
QWidget * w = asQWidget();
|
||||
if (!w->isVisible())
|
||||
return;
|
||||
clearParams();
|
||||
disconnect();
|
||||
w->hide();
|
||||
}
|
||||
|
||||
|
||||
bool Dialog::isVisibleView() const
|
||||
{
|
||||
return asQWidget()->isVisible();
|
||||
}
|
||||
|
||||
|
||||
void Dialog::checkStatus()
|
||||
{
|
||||
// buffer independant dialogs are always active.
|
||||
// This check allows us leave canApply unimplemented for some dialogs.
|
||||
if (!isBufferDependent())
|
||||
return;
|
||||
|
||||
// deactivate the dialog if we have no buffer
|
||||
if (!isBufferAvailable()) {
|
||||
enableView(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// check whether this dialog may be active
|
||||
if (canApply()) {
|
||||
bool const readonly = isBufferReadonly();
|
||||
enableView(!readonly);
|
||||
// refreshReadOnly() is too generous in _enabling_ widgets
|
||||
// update dialog to disable disabled widgets again
|
||||
|
||||
if (!readonly || canApplyToReadOnly())
|
||||
updateView();
|
||||
|
||||
} else
|
||||
enableView(false);
|
||||
}
|
||||
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
||||
|
@ -16,6 +16,8 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
class QWidget;
|
||||
|
||||
namespace lyx {
|
||||
|
||||
class Buffer;
|
||||
@ -51,6 +53,9 @@ public:
|
||||
|
||||
virtual ~Dialog();
|
||||
|
||||
virtual QWidget * asQWidget() = 0;
|
||||
virtual QWidget const * asQWidget() const = 0;
|
||||
|
||||
/** \name Container Access
|
||||
* These methods are publicly accessible because they are invoked
|
||||
* by the parent container acting on commands from the LyX kernel.
|
||||
@ -58,30 +63,21 @@ public:
|
||||
//@{
|
||||
/// \param data is a string encoding of the data to be displayed.
|
||||
/// It is passed to the Controller to be translated into a useable form.
|
||||
virtual void showData(std::string const & /*data*/) {}
|
||||
virtual void updateData(std::string const & /*data*/) {}
|
||||
|
||||
virtual void hide() {}
|
||||
|
||||
virtual void showData(std::string const & data);
|
||||
virtual void updateData(std::string const & data);
|
||||
//@}
|
||||
|
||||
/** Check whether we may apply our data.
|
||||
*
|
||||
* The buttons are disabled if not and (re-)enabled if yes.
|
||||
*/
|
||||
virtual void checkStatus() {}
|
||||
virtual void checkStatus();
|
||||
|
||||
/** When applying, it's useful to know whether the dialog is about
|
||||
* to close or not (no point refreshing the display for example).
|
||||
*/
|
||||
virtual bool isClosing() const { return false; }
|
||||
|
||||
|
||||
/** \c Button controller part
|
||||
*/
|
||||
virtual void setButtonsValid(bool /*valid*/) {}
|
||||
|
||||
|
||||
/** \c View part
|
||||
* of a Model-Controller-View split of a generic dialog.
|
||||
* These few methods are all that a generic dialog needs of a
|
||||
@ -95,16 +91,20 @@ public:
|
||||
virtual void applyView() = 0;
|
||||
|
||||
/// Hide the dialog from sight
|
||||
virtual void hideView() = 0;
|
||||
void hideView();
|
||||
|
||||
/// Create the dialog if necessary, update it and display it.
|
||||
virtual void showView() = 0;
|
||||
void showView();
|
||||
|
||||
/// Update the display of the dialog whilst it is still visible.
|
||||
virtual void updateView() = 0;
|
||||
|
||||
// Default Implementation does nothing.
|
||||
// Each dialog has to choose what control to enable or disable.
|
||||
virtual void enableView(bool /*enable*/) {}
|
||||
|
||||
/// \return true if the dialog is visible.
|
||||
virtual bool isVisibleView() const = 0;
|
||||
virtual bool isVisibleView() const;
|
||||
//@}
|
||||
|
||||
/// Dialog identifier.
|
||||
@ -230,7 +230,7 @@ public:
|
||||
//@}
|
||||
|
||||
protected:
|
||||
virtual void apply() {}
|
||||
virtual void apply();
|
||||
|
||||
private:
|
||||
/** The Dialog's name is the means by which a dialog identifies
|
||||
|
57
src/frontends/qt4/DialogView.cpp
Normal file
57
src/frontends/qt4/DialogView.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
/**
|
||||
* \file Dialog.cpp
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author Angus Leeming
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "DialogView.h"
|
||||
|
||||
#include "GuiView.h"
|
||||
#include "qt_helpers.h"
|
||||
|
||||
#include <QCloseEvent>
|
||||
#include <QSettings>
|
||||
#include <QShowEvent>
|
||||
|
||||
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
DialogView::DialogView(GuiView & lv, std::string const & name)
|
||||
: QDialog(&lv), Dialog(lv, name)
|
||||
{}
|
||||
|
||||
|
||||
void DialogView::setViewTitle(docstring const & title)
|
||||
{
|
||||
setWindowTitle("LyX: " + toqstr(title));
|
||||
}
|
||||
|
||||
|
||||
void DialogView::showEvent(QShowEvent * e)
|
||||
{
|
||||
QSettings settings;
|
||||
QString key = toqstr(name()) + "/geometry";
|
||||
restoreGeometry(settings.value(key).toByteArray());
|
||||
QDialog::showEvent(e);
|
||||
}
|
||||
|
||||
|
||||
void DialogView::closeEvent(QCloseEvent * e)
|
||||
{
|
||||
QSettings settings;
|
||||
QString key = toqstr(name()) + "/geometry";
|
||||
settings.setValue(key, saveGeometry());
|
||||
QDialog::closeEvent(e);
|
||||
}
|
||||
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
||||
|
||||
#include "DialogView_moc.cpp"
|
@ -9,102 +9,47 @@
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
#ifndef DIALOG_VIEW_H
|
||||
#define DIALOG_VIEW_H
|
||||
#ifndef DIALOGVIEW_H
|
||||
#define DIALOGVIEW_H
|
||||
|
||||
#include "Dialog.h"
|
||||
#include "GuiView.h"
|
||||
#include "qt_helpers.h"
|
||||
#include "support/debug.h"
|
||||
|
||||
#include <QCloseEvent>
|
||||
#include <QDialog>
|
||||
#include <QSettings>
|
||||
#include <QShowEvent>
|
||||
#include <QGridLayout>
|
||||
|
||||
#include <string>
|
||||
class QCloseEvent;
|
||||
class QShowEvent;
|
||||
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
/// Window Dialog container for LyX dialogs.
|
||||
/// This template class that encapsulates a given Widget inside a
|
||||
/// QDialog and presents a Dialog interface
|
||||
template<class MyWidget>
|
||||
/** \c Dialog collects the different parts of a Model-Controller-View
|
||||
* split of a generic dialog together.
|
||||
*/
|
||||
class DialogView : public QDialog, public Dialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DialogView(
|
||||
GuiView & parent, ///< the main window where to dock.
|
||||
std::string const & name, ///< dialog identifier.
|
||||
bool modal = false, ///< Window modality.
|
||||
Qt::WindowFlags flags = 0
|
||||
)
|
||||
: QDialog(&parent, flags), Dialog(parent, name)
|
||||
{
|
||||
setModal(modal);
|
||||
QGridLayout * gridLayout = new QGridLayout(this);
|
||||
gridLayout->setMargin(0);
|
||||
widget_ = new MyWidget(*this, this);
|
||||
gridLayout->addWidget(widget_);
|
||||
setWindowTitle("LyX: " + widget_->windowTitle());
|
||||
}
|
||||
/// \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.
|
||||
explicit DialogView(GuiView & lv, std::string const & name);
|
||||
virtual ~DialogView() {}
|
||||
|
||||
/// Dialog inherited methods
|
||||
//@{
|
||||
void applyView() {}
|
||||
void hideView()
|
||||
{
|
||||
clearParams();
|
||||
QDialog::hide();
|
||||
}
|
||||
void showData(std::string const & data)
|
||||
{
|
||||
initialiseParams(data);
|
||||
showView();
|
||||
}
|
||||
void showView()
|
||||
{
|
||||
widget_->updateView(); // make sure its up-to-date
|
||||
QDialog::show();
|
||||
raise();
|
||||
activateWindow();
|
||||
}
|
||||
bool isVisibleView() const { return QDialog::isVisible(); }
|
||||
void checkStatus() { updateView(); }
|
||||
void updateData(std::string const & data)
|
||||
{
|
||||
initialiseParams(data);
|
||||
updateView();
|
||||
}
|
||||
void updateView()
|
||||
{
|
||||
widget_->updateView();
|
||||
}
|
||||
//@}
|
||||
private:
|
||||
/// The encapsulated widget.
|
||||
MyWidget * widget_;
|
||||
virtual QWidget * asQWidget() { return this; }
|
||||
virtual QWidget const * asQWidget() const { return this; }
|
||||
|
||||
void showEvent(QShowEvent * e)
|
||||
{
|
||||
QSettings settings;
|
||||
std::string key = name() + "/geometry";
|
||||
QDialog::restoreGeometry(settings.value(key.c_str()).toByteArray());
|
||||
QDialog::showEvent(e);
|
||||
}
|
||||
public:
|
||||
///
|
||||
void setViewTitle(docstring const & title);
|
||||
|
||||
void closeEvent(QCloseEvent * e)
|
||||
{
|
||||
QSettings settings;
|
||||
std::string key = name() + "/geometry";
|
||||
settings.setValue(key.c_str(), QDialog::saveGeometry());
|
||||
QDialog::closeEvent(e);
|
||||
}
|
||||
///
|
||||
void closeEvent(QCloseEvent *);
|
||||
///
|
||||
void showEvent(QShowEvent *);
|
||||
};
|
||||
|
||||
} // frontend
|
||||
} // lyx
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
||||
|
||||
#endif // DIALOG_VIEW_H
|
||||
#endif // DIALOGVIEW_H
|
||||
|
@ -43,27 +43,12 @@ public:
|
||||
|
||||
virtual ~DockView() {}
|
||||
|
||||
virtual QWidget * asQWidget() { return this; }
|
||||
virtual QWidget const * asQWidget() const { return this; }
|
||||
|
||||
/// Dialog inherited methods
|
||||
//@{
|
||||
void applyView() {}
|
||||
void hideView() { QDockWidget::hide(); }
|
||||
void showData(std::string const & data)
|
||||
{
|
||||
initialiseParams(data);
|
||||
showView();
|
||||
}
|
||||
void showView()
|
||||
{
|
||||
updateView(); // make sure its up-to-date
|
||||
QDockWidget::show();
|
||||
}
|
||||
bool isVisibleView() const { return QDockWidget::isVisible(); }
|
||||
void checkStatus() { updateView(); }
|
||||
void updateData(std::string const & data)
|
||||
{
|
||||
initialiseParams(data);
|
||||
updateView();
|
||||
}
|
||||
bool isClosing() const { return false; }
|
||||
//@}
|
||||
};
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include <string>
|
||||
|
||||
#include <QCloseEvent>
|
||||
#include <QShowEvent>
|
||||
|
||||
#undef KeyPress
|
||||
|
||||
@ -138,27 +139,12 @@ void GuiCitation::applyView()
|
||||
}
|
||||
|
||||
|
||||
void GuiCitation::hideView()
|
||||
{
|
||||
clearParams();
|
||||
accept();
|
||||
}
|
||||
|
||||
|
||||
void GuiCitation::showView()
|
||||
void GuiCitation::showEvent(QShowEvent * e)
|
||||
{
|
||||
init();
|
||||
findLE->clear();
|
||||
availableLV->setFocus();
|
||||
QDialog::show();
|
||||
raise();
|
||||
activateWindow();
|
||||
}
|
||||
|
||||
|
||||
bool GuiCitation::isVisibleView() const
|
||||
{
|
||||
return QDialog::isVisible();
|
||||
GuiDialog::showEvent(e);
|
||||
}
|
||||
|
||||
|
||||
@ -166,14 +152,14 @@ void GuiCitation::on_okPB_clicked()
|
||||
{
|
||||
applyView();
|
||||
clearSelection();
|
||||
hideView();
|
||||
hide();
|
||||
}
|
||||
|
||||
|
||||
void GuiCitation::on_cancelPB_clicked()
|
||||
{
|
||||
clearSelection();
|
||||
hideView();
|
||||
hide();
|
||||
}
|
||||
|
||||
|
||||
|
@ -38,18 +38,14 @@ public:
|
||||
|
||||
///
|
||||
void applyView();
|
||||
/// Hide the dialog from sight
|
||||
void hideView();
|
||||
/// Create the dialog if necessary, update it and display it.
|
||||
void showView();
|
||||
/// \return true if the dialog is visible.
|
||||
bool isVisibleView() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
/// Update the display of the dialog whilst it is still visible.
|
||||
void updateView();
|
||||
|
||||
private:
|
||||
///
|
||||
void showEvent(QShowEvent * e);
|
||||
///
|
||||
void closeEvent(QCloseEvent * e);
|
||||
/// prepares a call to GuiCitation::searchKeys when we
|
||||
|
@ -12,9 +12,10 @@
|
||||
|
||||
#include "GuiDialog.h"
|
||||
#include "GuiView.h"
|
||||
#include "support/debug.h"
|
||||
#include "qt_helpers.h"
|
||||
|
||||
#include "support/debug.h"
|
||||
|
||||
#include <QCloseEvent>
|
||||
#include <QMainWindow>
|
||||
#include <QSettings>
|
||||
@ -26,21 +27,10 @@ namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
GuiDialog::GuiDialog(GuiView & lv, std::string const & name)
|
||||
: QDialog(&lv), Dialog(lv, name), is_closing_(false)
|
||||
: DialogView(lv, name), is_closing_(false)
|
||||
{}
|
||||
|
||||
|
||||
GuiDialog::~GuiDialog()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void GuiDialog::setViewTitle(docstring const & title)
|
||||
{
|
||||
setWindowTitle("LyX: " + toqstr(title));
|
||||
}
|
||||
|
||||
|
||||
void GuiDialog::setButtonsValid(bool valid)
|
||||
{
|
||||
bc().setValid(valid);
|
||||
@ -49,7 +39,7 @@ void GuiDialog::setButtonsValid(bool valid)
|
||||
|
||||
void GuiDialog::slotApply()
|
||||
{
|
||||
apply();
|
||||
applyView();
|
||||
bc().apply();
|
||||
}
|
||||
|
||||
@ -57,7 +47,7 @@ void GuiDialog::slotApply()
|
||||
void GuiDialog::slotOK()
|
||||
{
|
||||
is_closing_ = true;
|
||||
apply();
|
||||
applyView();
|
||||
is_closing_ = false;
|
||||
QDialog::hide();
|
||||
bc().ok();
|
||||
@ -80,66 +70,6 @@ void GuiDialog::slotRestore()
|
||||
bc().restore();
|
||||
}
|
||||
|
||||
void GuiDialog::checkStatus()
|
||||
{
|
||||
// buffer independant dialogs are always active.
|
||||
// This check allows us leave canApply unimplemented for some dialogs.
|
||||
if (!isBufferDependent())
|
||||
return;
|
||||
|
||||
// deactivate the dialog if we have no buffer
|
||||
if (!isBufferAvailable()) {
|
||||
bc().setReadOnly(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// check whether this dialog may be active
|
||||
if (canApply()) {
|
||||
bool const readonly = isBufferReadonly();
|
||||
bc().setReadOnly(readonly);
|
||||
// refreshReadOnly() is too generous in _enabling_ widgets
|
||||
// update dialog to disable disabled widgets again
|
||||
|
||||
if (!readonly || canApplyToReadOnly())
|
||||
updateView();
|
||||
|
||||
} else {
|
||||
bc().setReadOnly(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool GuiDialog::isVisibleView() const
|
||||
{
|
||||
return QDialog::isVisible();
|
||||
}
|
||||
|
||||
|
||||
void GuiDialog::showView()
|
||||
{
|
||||
QSize const hint = sizeHint();
|
||||
if (hint.height() >= 0 && hint.width() >= 0)
|
||||
setMinimumSize(hint);
|
||||
|
||||
updateView(); // make sure its up-to-date
|
||||
if (exitEarly())
|
||||
return;
|
||||
|
||||
if (QWidget::isVisible()) {
|
||||
raise();
|
||||
activateWindow();
|
||||
} else {
|
||||
QWidget::show();
|
||||
}
|
||||
setFocus();
|
||||
}
|
||||
|
||||
|
||||
void GuiDialog::hideView()
|
||||
{
|
||||
QDialog::hide();
|
||||
}
|
||||
|
||||
|
||||
void GuiDialog::changed()
|
||||
{
|
||||
@ -149,101 +79,27 @@ void GuiDialog::changed()
|
||||
}
|
||||
|
||||
|
||||
void GuiDialog::enableView(bool enable)
|
||||
{
|
||||
bc().setReadOnly(!enable);
|
||||
bc().setValid(enable);
|
||||
DialogView::enableView(enable);
|
||||
}
|
||||
|
||||
|
||||
void GuiDialog::updateView()
|
||||
{
|
||||
setUpdatesEnabled(false);
|
||||
|
||||
bc().setReadOnly(isBufferReadonly());
|
||||
// protect the BC from unwarranted state transitions
|
||||
updating_ = true;
|
||||
updateContents();
|
||||
updating_ = false;
|
||||
// The widgets may not be valid, so refresh the button controller
|
||||
bc().refresh();
|
||||
|
||||
setUpdatesEnabled(true);
|
||||
QDialog::update();
|
||||
}
|
||||
|
||||
|
||||
void GuiDialog::showData(string const & data)
|
||||
{
|
||||
if (isBufferDependent() && !isBufferAvailable())
|
||||
return;
|
||||
|
||||
if (!initialiseParams(data)) {
|
||||
LYXERR0("Dialog \"" << name()
|
||||
<< "\" failed to translate the data string passed to show()");
|
||||
return;
|
||||
}
|
||||
|
||||
bc().setReadOnly(isBufferReadonly());
|
||||
showView();
|
||||
// The widgets may not be valid, so refresh the button controller
|
||||
bc().refresh();
|
||||
}
|
||||
|
||||
|
||||
void GuiDialog::updateData(string const & data)
|
||||
{
|
||||
if (isBufferDependent() && !isBufferAvailable())
|
||||
return;
|
||||
|
||||
if (!initialiseParams(data)) {
|
||||
LYXERR0("Dialog \"" << name()
|
||||
<< "\" could not be initialized");
|
||||
return;
|
||||
}
|
||||
|
||||
bc().setReadOnly(isBufferReadonly());
|
||||
updateView();
|
||||
// The widgets may not be valid, so refresh the button controller
|
||||
bc().refresh();
|
||||
}
|
||||
|
||||
|
||||
void GuiDialog::hide()
|
||||
{
|
||||
if (!isVisibleView())
|
||||
return;
|
||||
|
||||
clearParams();
|
||||
hideView();
|
||||
Dialog::disconnect();
|
||||
}
|
||||
|
||||
|
||||
void GuiDialog::apply()
|
||||
{
|
||||
if (isBufferDependent()) {
|
||||
if (!isBufferAvailable() ||
|
||||
(isBufferReadonly() && !canApplyToReadOnly()))
|
||||
return;
|
||||
}
|
||||
|
||||
applyView();
|
||||
dispatchParams();
|
||||
|
||||
if (disconnectOnApply() && !is_closing_) {
|
||||
Dialog::disconnect();
|
||||
initialiseParams(string());
|
||||
updateView();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GuiDialog::showEvent(QShowEvent * e)
|
||||
{
|
||||
QSettings settings;
|
||||
string key = name() + "/geometry";
|
||||
restoreGeometry(settings.value(key.c_str()).toByteArray());
|
||||
QDialog::showEvent(e);
|
||||
}
|
||||
|
||||
|
||||
void GuiDialog::closeEvent(QCloseEvent * e)
|
||||
{
|
||||
QSettings settings;
|
||||
string key = name() + "/geometry";
|
||||
settings.setValue(key.c_str(), saveGeometry());
|
||||
QDialog::closeEvent(e);
|
||||
}
|
||||
|
||||
} // namespace frontend
|
||||
|
@ -12,24 +12,18 @@
|
||||
#ifndef GUIDIALOG_H
|
||||
#define GUIDIALOG_H
|
||||
|
||||
#include "Dialog.h"
|
||||
#include "DialogView.h"
|
||||
#include "ButtonController.h"
|
||||
|
||||
#include "insets/InsetCommandParams.h"
|
||||
|
||||
#include <QDialog>
|
||||
#include <QObject>
|
||||
|
||||
class QCloseEvent;
|
||||
class QShowEvent;
|
||||
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
/** \c Dialog collects the different parts of a Model-Controller-View
|
||||
* split of a generic dialog together.
|
||||
*/
|
||||
class GuiDialog : public QDialog, public Dialog
|
||||
class GuiDialog : public DialogView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -38,7 +32,6 @@ public:
|
||||
/// \param name is the identifier given to the dialog by its parent
|
||||
/// container.
|
||||
explicit GuiDialog(GuiView & lv, std::string const & name);
|
||||
~GuiDialog();
|
||||
|
||||
public Q_SLOTS:
|
||||
/** \name Buttons
|
||||
@ -59,7 +52,6 @@ public:
|
||||
*
|
||||
* The buttons are disabled if not and (re-)enabled if yes.
|
||||
*/
|
||||
void checkStatus();
|
||||
void setButtonsValid(bool valid);
|
||||
|
||||
/** \name Dialog Components
|
||||
@ -70,53 +62,27 @@ public:
|
||||
ButtonController & bc() { return bc_; }
|
||||
//@}
|
||||
|
||||
void setViewTitle(docstring const & title);
|
||||
|
||||
|
||||
/// the dialog has changed contents
|
||||
virtual void changed();
|
||||
|
||||
virtual void enableView(bool enable);
|
||||
|
||||
/// default: do nothing
|
||||
virtual void applyView() {}
|
||||
/// default: do nothing
|
||||
virtual void updateContents() {}
|
||||
///
|
||||
void closeEvent(QCloseEvent *);
|
||||
///
|
||||
void showEvent(QShowEvent *);
|
||||
|
||||
protected:
|
||||
/// Hide the dialog.
|
||||
virtual void hideView();
|
||||
/// Create the dialog if necessary, update it and display it.
|
||||
virtual void showView();
|
||||
///
|
||||
virtual bool isVisibleView() const;
|
||||
public:
|
||||
/// is the dialog currently valid ?
|
||||
virtual bool isValid() { return true; }
|
||||
|
||||
public:
|
||||
/** \name Container Access
|
||||
* These methods are publicly accessible because they are invoked
|
||||
* by the parent container acting on commands from the LyX kernel.
|
||||
*/
|
||||
//@{
|
||||
/// \param data is a string encoding of the data to be displayed.
|
||||
/// It is passed to the Controller to be translated into a useable form.
|
||||
void showData(std::string const & data);
|
||||
void updateData(std::string const & data);
|
||||
|
||||
void hide();
|
||||
|
||||
//@}
|
||||
|
||||
/** When applying, it's useful to know whether the dialog is about
|
||||
* to close or not (no point refreshing the display for example).
|
||||
*/
|
||||
bool isClosing() const { return is_closing_; }
|
||||
|
||||
void apply();
|
||||
|
||||
/// Update the display of the dialog whilst it is still visible.
|
||||
virtual void updateView();
|
||||
|
||||
|
@ -48,16 +48,11 @@ namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
GuiParagraph::GuiParagraph(GuiView & lv)
|
||||
: Dialog(lv, "paragraph")
|
||||
: DialogView(lv, "paragraph")
|
||||
{
|
||||
setupUi(this);
|
||||
setWindowTitle(qt_("Paragraph Settings"));
|
||||
|
||||
//setModal(modal);
|
||||
QGridLayout * gridLayout = new QGridLayout(this);
|
||||
gridLayout->setMargin(0);
|
||||
gridLayout->addWidget(this);
|
||||
|
||||
connect(alignDefaultRB, SIGNAL(clicked()), this, SLOT(changed()));
|
||||
connect(alignJustRB, SIGNAL(clicked()), this, SLOT(changed()));
|
||||
connect(alignLeftRB, SIGNAL(clicked()), this, SLOT(changed()));
|
||||
@ -210,6 +205,11 @@ void GuiParagraph::on_restorePB_clicked()
|
||||
}
|
||||
|
||||
|
||||
void GuiParagraph::enableView(bool enable)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void GuiParagraph::updateView()
|
||||
{
|
||||
on_synchronizedViewCB_toggled();
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
#include "Layout.h"
|
||||
#include "ui_ParagraphUi.h"
|
||||
#include "Dialog.h"
|
||||
#include "DialogView.h"
|
||||
#include "ParagraphParameters.h"
|
||||
#include "GuiView.h"
|
||||
#include "qt_helpers.h"
|
||||
@ -38,7 +38,7 @@ namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
class GuiParagraph
|
||||
: public QDialog, public Ui::ParagraphUi, public Dialog
|
||||
: public DialogView, public Ui::ParagraphUi
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
@ -63,51 +63,13 @@ private:
|
||||
QString const alignDefaultLabel;
|
||||
|
||||
void applyView() {}
|
||||
void hideView()
|
||||
{
|
||||
clearParams();
|
||||
QDialog::hide();
|
||||
}
|
||||
void showData(std::string const & data)
|
||||
{
|
||||
initialiseParams(data);
|
||||
showView();
|
||||
}
|
||||
void showView()
|
||||
{
|
||||
updateView(); // make sure its up-to-date
|
||||
QDialog::show();
|
||||
raise();
|
||||
activateWindow();
|
||||
}
|
||||
bool isVisibleView() const { return QDialog::isVisible(); }
|
||||
void checkStatus() { updateView(); }
|
||||
void updateData(std::string const & data)
|
||||
{
|
||||
initialiseParams(data);
|
||||
updateView();
|
||||
}
|
||||
void enableView(bool enable);
|
||||
|
||||
std::string name() const { return "paragraph"; }
|
||||
|
||||
private:
|
||||
QString name_;
|
||||
|
||||
void showEvent(QShowEvent * e)
|
||||
{
|
||||
QSettings settings;
|
||||
QString key = name_ + "/geometry";
|
||||
QDialog::restoreGeometry(settings.value(key).toByteArray());
|
||||
QDialog::showEvent(e);
|
||||
}
|
||||
|
||||
void closeEvent(QCloseEvent * e)
|
||||
{
|
||||
QSettings settings;
|
||||
QString key = name_ + "/geometry";
|
||||
settings.setValue(key, QDialog::saveGeometry());
|
||||
QDialog::closeEvent(e);
|
||||
}
|
||||
|
||||
private Q_SLOTS:
|
||||
///
|
||||
void changed();
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include <QLineEdit>
|
||||
#include <QCloseEvent>
|
||||
#include <QShowEvent>
|
||||
|
||||
using std::string;
|
||||
|
||||
@ -64,10 +65,10 @@ GuiSearch::GuiSearch(GuiView & lv)
|
||||
}
|
||||
|
||||
|
||||
void GuiSearch::showView()
|
||||
void GuiSearch::showEvent(QShowEvent * e)
|
||||
{
|
||||
findCO->lineEdit()->selectAll();
|
||||
GuiDialog::showView();
|
||||
GuiDialog::showEvent(e);
|
||||
}
|
||||
|
||||
|
||||
|
@ -33,7 +33,7 @@ private Q_SLOTS:
|
||||
void replaceallClicked();
|
||||
|
||||
private:
|
||||
void showView();
|
||||
void showEvent(QShowEvent * e);
|
||||
void closeEvent(QCloseEvent * e);
|
||||
///
|
||||
bool initialiseParams(std::string const &) { return true; }
|
||||
|
@ -1668,7 +1668,7 @@ void GuiView::hideDialog(string const & name, Inset * inset)
|
||||
|
||||
Dialog * const dialog = it->second.get();
|
||||
if (dialog->isVisibleView())
|
||||
dialog->hide();
|
||||
dialog->hideView();
|
||||
d.open_insets_[name] = 0;
|
||||
}
|
||||
|
||||
@ -1699,7 +1699,7 @@ void GuiView::hideAll() const
|
||||
std::map<string, DialogPtr>::const_iterator end = d.dialogs_.end();
|
||||
|
||||
for(; it != end; ++it)
|
||||
it->second->hide();
|
||||
it->second->hideView();
|
||||
}
|
||||
|
||||
|
||||
@ -1711,7 +1711,7 @@ void GuiView::hideBufferDependent() const
|
||||
for(; it != end; ++it) {
|
||||
Dialog * dialog = it->second.get();
|
||||
if (dialog->isBufferDependent())
|
||||
dialog->hide();
|
||||
dialog->hideView();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1729,7 +1729,7 @@ void GuiView::updateBufferDependent(bool switched) const
|
||||
if (dialog->initialiseParams(""))
|
||||
dialog->updateView();
|
||||
else
|
||||
dialog->hide();
|
||||
dialog->hideView();
|
||||
} else {
|
||||
// A bit clunky, but the dialog will request
|
||||
// that the kernel provides it with the necessary
|
||||
|
@ -50,6 +50,7 @@ SOURCEFILES = \
|
||||
ButtonPolicy.h \
|
||||
Dialog.cpp \
|
||||
Dialog.h \
|
||||
DialogView.cpp \
|
||||
Resources.cpp \
|
||||
Action.cpp \
|
||||
BulletsModule.cpp \
|
||||
@ -135,7 +136,6 @@ SOURCEFILES = \
|
||||
|
||||
NOMOCHEADER = \
|
||||
ButtonController.h \
|
||||
DialogView.h \
|
||||
GuiFontLoader.h \
|
||||
GuiFontMetrics.h \
|
||||
GuiImage.h \
|
||||
@ -149,6 +149,7 @@ MOCHEADER = \
|
||||
BulletsModule.h \
|
||||
ColorCache.h \
|
||||
CustomizedWidgets.h \
|
||||
DialogView.h \
|
||||
DockView.h \
|
||||
EmptyTable.h \
|
||||
FloatPlacement.h \
|
||||
|
@ -1,6 +1,6 @@
|
||||
<ui version="4.0" >
|
||||
<class>ParagraphUi</class>
|
||||
<widget class="QWidget" name="ParagraphUi" >
|
||||
<widget class="QDialog" name="ParagraphUi" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>0</x>
|
||||
|
Loading…
Reference in New Issue
Block a user