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.
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 controller_ = new MyController(*this, parent);
48 QGridLayout * gridLayout = new QGridLayout(this);
49 gridLayout->setMargin(0);
50 widget_ = new MyWidget(*controller_, this);
51 gridLayout->addWidget(widget_);
52 setWindowTitle("LyX: " + widget_->windowTitle());
55 /// Dialog inherited methods
60 controller().clearParams();
63 void showData(std::string const & data)
65 controller_->initialiseParams(data);
70 widget_->updateView(); // make sure its up-to-date
75 bool isVisibleView() const { return QDialog::isVisible(); }
76 void checkStatus() { updateView(); }
77 void redraw() { redrawView(); }
79 void updateData(std::string const & data)
81 controller_->initialiseParams(data);
86 widget_->updateView();
88 void partialUpdateView(int /*id*/) {}
89 Controller & controller() { return *controller_; }
90 std::string name() const { return name_; }
93 /// The encapsulated widget.
95 Controller * controller_;
98 void showEvent(QShowEvent * e)
100 #if (QT_VERSION >= 0x040200)
102 std::string key = name_ + "/geometry";
103 QDialog::restoreGeometry(settings.value(key.c_str()).toByteArray());
105 QDialog::showEvent(e);
108 void closeEvent(QCloseEvent * e)
110 #if (QT_VERSION >= 0x040200)
112 std::string key = name_ + "/geometry";
113 settings.setValue(key.c_str(), QDialog::saveGeometry());
115 QDialog::closeEvent(e);
122 #endif // DIALOG_VIEW_H