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>
24 #include <QGridLayout>
31 /// Window Dialog container for LyX dialogs.
32 /// This template class that encapsulates a given Widget inside a
33 /// QDialog and presents a Dialog interface
34 template<class MyController, class MyWidget>
35 class DialogView : public QDialog, public Dialog
39 GuiViewBase & parent, ///< the main window where to dock.
40 std::string const & name, ///< dialog identifier.
41 bool modal = false, ///< Window modality.
42 Qt::WindowFlags flags = 0
44 : QDialog(&parent, flags), name_(name)
47 MyController * c = new MyController(*this);
49 controller_->setLyXView(parent);
50 QGridLayout * gridLayout = new QGridLayout(this);
51 gridLayout->setMargin(0);
52 widget_ = new MyWidget(*c, this);
53 gridLayout->addWidget(widget_);
54 setWindowTitle("LyX: " + widget_->windowTitle());
57 /// Dialog inherited methods
62 controller().clearParams();
65 void showData(std::string const & data)
67 controller_->initialiseParams(data);
72 widget_->updateView(); // make sure its up-to-date
77 bool isVisibleView() const { return QDialog::isVisible(); }
78 void checkStatus() { updateView(); }
79 void redraw() { redrawView(); }
81 void updateData(std::string const & data)
83 controller_->initialiseParams(data);
88 widget_->updateView();
90 void partialUpdateView(int /*id*/) {}
91 Controller & controller() { return *controller_; }
92 std::string name() const { return name_; }
95 /// The encapsulated widget.
97 Controller * controller_;
100 void showEvent(QShowEvent * e)
102 #if (QT_VERSION >= 0x040200)
104 std::string key = name_ + "/geometry";
105 QDialog::restoreGeometry(settings.value(key.c_str()).toByteArray());
107 QDialog::showEvent(e);
110 void closeEvent(QCloseEvent * e)
112 #if (QT_VERSION >= 0x040200)
114 std::string key = name_ + "/geometry";
115 settings.setValue(key.c_str(), QDialog::saveGeometry());
117 QDialog::closeEvent(e);
124 #endif // DIALOG_VIEW_H