#include "FuncStatus.h"
#include "LyXFunc.h"
+#include "support/Debug.h"
+
#include <string>
+using namespace std;
+
namespace lyx {
namespace frontend {
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
#include <string>
+class QWidget;
+
namespace lyx {
class Buffer;
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.
//@{
/// \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
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.
//@}
protected:
- virtual void apply() {}
+ virtual void apply();
private:
/** The Dialog's name is the means by which a dialog identifies
--- /dev/null
+/**
+ * \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"
* 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
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; }
//@}
};
#include <string>
#include <QCloseEvent>
+#include <QShowEvent>
#undef KeyPress
}
-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);
}
{
applyView();
clearSelection();
- hideView();
+ hide();
}
void GuiCitation::on_cancelPB_clicked()
{
clearSelection();
- hideView();
+ hide();
}
///
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
#include "GuiDialog.h"
#include "GuiView.h"
-#include "support/debug.h"
#include "qt_helpers.h"
+#include "support/debug.h"
+
#include <QCloseEvent>
#include <QMainWindow>
#include <QSettings>
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);
void GuiDialog::slotApply()
{
- apply();
+ applyView();
bc().apply();
}
void GuiDialog::slotOK()
{
is_closing_ = true;
- apply();
+ applyView();
is_closing_ = false;
QDialog::hide();
bc().ok();
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()
+void GuiDialog::changed()
{
- QSize const hint = sizeHint();
- if (hint.height() >= 0 && hint.width() >= 0)
- setMinimumSize(hint);
-
- updateView(); // make sure its up-to-date
- if (exitEarly())
+ if (updating_)
return;
-
- if (QWidget::isVisible()) {
- raise();
- activateWindow();
- } else {
- QWidget::show();
- }
- setFocus();
-}
-
-
-void GuiDialog::hideView()
-{
- QDialog::hide();
+ bc().setValid(isValid());
}
-void GuiDialog::changed()
+void GuiDialog::enableView(bool enable)
{
- if (updating_)
- return;
- bc().setValid(isValid());
+ bc().setReadOnly(!enable);
+ bc().setValid(enable);
+ DialogView::enableView(enable);
}
{
setUpdatesEnabled(false);
+ bc().setReadOnly(isBufferReadonly());
// protect the BC from unwarranted state transitions
updating_ = true;
updateContents();
updating_ = false;
-
- 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);
+ setUpdatesEnabled(true);
}
} // namespace frontend
#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
/// \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
*
* The buttons are disabled if not and (re-)enabled if yes.
*/
- void checkStatus();
void setButtonsValid(bool valid);
/** \name Dialog Components
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();
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()));
}
+void GuiParagraph::enableView(bool enable)
+{
+}
+
+
void GuiParagraph::updateView()
{
on_synchronizedViewCB_toggled();
#include "Layout.h"
#include "ui_ParagraphUi.h"
-#include "Dialog.h"
+#include "DialogView.h"
#include "ParagraphParameters.h"
#include "GuiView.h"
#include "qt_helpers.h"
namespace frontend {
class GuiParagraph
- : public QDialog, public Ui::ParagraphUi, public Dialog
+ : public DialogView, public Ui::ParagraphUi
{
Q_OBJECT
public:
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();
#include <QLineEdit>
#include <QCloseEvent>
+#include <QShowEvent>
using std::string;
}
-void GuiSearch::showView()
+void GuiSearch::showEvent(QShowEvent * e)
{
findCO->lineEdit()->selectAll();
- GuiDialog::showView();
+ GuiDialog::showEvent(e);
}
void replaceallClicked();
private:
- void showView();
+ void showEvent(QShowEvent * e);
void closeEvent(QCloseEvent * e);
///
bool initialiseParams(std::string const &) { return true; }
Dialog * const dialog = it->second.get();
if (dialog->isVisibleView())
- dialog->hide();
+ dialog->hideView();
d.open_insets_[name] = 0;
}
std::map<string, DialogPtr>::const_iterator end = d.dialogs_.end();
for(; it != end; ++it)
- it->second->hide();
+ it->second->hideView();
}
for(; it != end; ++it) {
Dialog * dialog = it->second.get();
if (dialog->isBufferDependent())
- dialog->hide();
+ dialog->hideView();
}
}
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
ButtonPolicy.h \
Dialog.cpp \
Dialog.h \
+ DialogView.cpp \
Resources.cpp \
Action.cpp \
BulletsModule.cpp \
NOMOCHEADER = \
ButtonController.h \
- DialogView.h \
GuiFontLoader.h \
GuiFontMetrics.h \
GuiImage.h \
BulletsModule.h \
ColorCache.h \
CustomizedWidgets.h \
+ DialogView.h \
DockView.h \
EmptyTable.h \
FloatPlacement.h \
<ui version="4.0" >
<class>ParagraphUi</class>
- <widget class="QWidget" name="ParagraphUi" >
+ <widget class="QDialog" name="ParagraphUi" >
<property name="geometry" >
<rect>
<x>0</x>