]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/DialogView.h
Remove unused code.
[lyx.git] / src / frontends / qt4 / DialogView.h
1 // -*- C++ -*-
2 /**
3  * \file DialogView.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Abdelrazak Younes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef DIALOG_VIEW_H
13 #define DIALOG_VIEW_H
14
15 #include "Dialog.h"
16 #include "GuiView.h"
17 #include "qt_helpers.h"
18 #include "debug.h"
19
20 #include <QCloseEvent>
21 #include <QDialog>
22 #include <QSettings>
23 #include <QShowEvent>
24 #include <QGridLayout>
25
26 #include <string>
27
28 namespace lyx {
29 namespace frontend {
30
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 MyWidget>
35 class DialogView : public QDialog, public Dialog
36 {
37 public:
38         DialogView(
39                 GuiView & 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
43                 )
44                 : QDialog(&parent, flags), name_(name)
45         {
46                 setModal(modal);
47                 QGridLayout * gridLayout = new QGridLayout(this);
48                 gridLayout->setMargin(0);
49                 widget_ = new MyWidget(*this, this);
50                 gridLayout->addWidget(widget_);
51                 setWindowTitle("LyX: " + widget_->windowTitle());
52         }
53
54         /// Dialog inherited methods
55         //@{
56         void applyView() {}
57         void hideView()
58         {
59                 clearParams();
60                 QDialog::hide();
61         }
62         void showData(std::string const & data)
63         {
64                 initialiseParams(data);
65                 showView();
66         }
67         void showView()
68         {
69                 widget_->updateView();  // make sure its up-to-date
70                 QDialog::show();
71                 raise();
72                 activateWindow();
73         }
74         bool isVisibleView() const { return QDialog::isVisible(); }
75         void checkStatus() { updateView(); }
76         void updateData(std::string const & data)
77         {
78                 initialiseParams(data);
79                 updateView();
80         }
81         void updateView()
82         {
83                 widget_->updateView();
84         }
85         std::string name() const { return name_; }
86         //@}
87 private:
88         /// The encapsulated widget.
89         MyWidget * widget_;
90         std::string name_;
91
92         void showEvent(QShowEvent * e)
93         {
94                 QSettings settings;
95                 std::string key = name_ + "/geometry";
96                 QDialog::restoreGeometry(settings.value(key.c_str()).toByteArray());
97             QDialog::showEvent(e);
98         }
99
100         void closeEvent(QCloseEvent * e)
101         {
102                 QSettings settings;
103                 std::string key = name_ + "/geometry";
104                 settings.setValue(key.c_str(), QDialog::saveGeometry());
105                 QDialog::closeEvent(e);
106         }
107 };
108
109 } // frontend
110 } // lyx
111
112 #endif // DIALOG_VIEW_H