4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Abdelrazak Younes
9 * Full author contact details are available in file CREDITS.
15 #include "controllers/Dialog.h"
17 #include "qt_helpers.h"
20 #include <QCloseEvent>
30 /// Window Dialog container for LyX dialogs.
31 /// This template class that encapsulates a given Widget inside a
32 /// QDialog and presents a Dialog interface
33 template<class MyController, class MyWidget>
34 class DialogView : public QDialog, public Dialog
38 GuiViewBase & parent, ///< the main window where to dock.
39 std::string const & name, ///< dialog identifier.
40 bool modal = false, ///< Window modality.
41 Qt::WindowFlags flags = 0
43 : QDialog(&parent, flags), name_(name)
46 MyController * c = new MyController(*this);
48 controller_->setLyXView(parent);
49 widget_ = new MyWidget(*c, this);
50 setWindowTitle("LyX: " + widget_->windowTitle());
53 /// Dialog inherited methods
58 controller().clearParams();
61 void showData(std::string const & data)
63 controller_->initialiseParams(data);
68 widget_->updateView(); // make sure its up-to-date
73 bool isVisibleView() const { return QDialog::isVisible(); }
74 void checkStatus() { updateView(); }
75 void redraw() { redrawView(); }
77 void updateData(std::string const & data)
79 controller_->initialiseParams(data);
84 widget_->updateView();
86 void partialUpdateView(int /*id*/) {}
87 Controller & controller() { return *controller_; }
88 std::string name() const { return name_; }
91 /// The encapsulated widget.
93 Controller * controller_;
96 void showEvent(QShowEvent * e)
98 #if (QT_VERSION >= 0x040200)
100 std::string key = name_ + "/geometry";
101 QDialog::restoreGeometry(settings.value(key.c_str()).toByteArray());
103 QDialog::showEvent(e);
106 void closeEvent(QCloseEvent * e)
108 #if (QT_VERSION >= 0x040200)
110 std::string key = name_ + "/geometry";
111 settings.setValue(key.c_str(), QDialog::saveGeometry());
113 QDialog::closeEvent(e);
120 #endif // DIALOG_VIEW_H