]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiParagraph.h
fix memory leaks
[lyx.git] / src / frontends / qt4 / GuiParagraph.h
1 // -*- C++ -*-
2 /**
3  * \file GuiParagraph.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Edwin Leuven
8  * \author John Levon
9  * \author Abdelrazak Younes
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #ifndef GUIPARAGRAPH_H
15 #define GUIPARAGRAPH_H
16
17 // Uncomment this if you prefer dock widget
18 //#define USE_DOCK_WIDGET
19
20 #include "Layout.h"
21 #include "ui_ParagraphUi.h"
22 #include "Dialog.h"
23 #include "ParagraphParameters.h"
24 #include "GuiView.h"
25 #include "qt_helpers.h"
26 #include "support/debug.h"
27
28 #include <QCloseEvent>
29 #include <QDialog>
30 #include <QSettings>
31 #include <QShowEvent>
32 #include <QGridLayout>
33
34 #include <map>
35 #include <string>
36
37 namespace lyx {
38 namespace frontend {
39
40 class GuiParagraph
41         : public QDialog, public Ui::ParagraphUi, public Dialog
42 {
43         Q_OBJECT
44 public:
45         GuiParagraph(GuiView & lv);
46
47         /// update
48         void updateView();
49
50 private:
51         ///
52         void checkAlignmentRadioButtons();
53         ///
54         void alignmentToRadioButtons(LyXAlignment align = LYX_ALIGN_LAYOUT);
55         ///
56         LyXAlignment getAlignmentFromDialog();
57         ///
58         typedef std::map<LyXAlignment, QRadioButton *> RadioMap;
59         RadioMap radioMap;
60         typedef std::map<LyXAlignment, docstring> AlignmentLabels;
61         AlignmentLabels labelMap;
62
63         QString const alignDefaultLabel;
64
65         void applyView() {}
66         void hideView()
67         {
68                 clearParams();
69                 QDialog::hide();
70         }
71         void showData(std::string const & data)
72         {
73                 initialiseParams(data);
74                 showView();
75         }
76         void showView()
77         {
78                 updateView();  // make sure its up-to-date
79                 QDialog::show();
80                 raise();
81                 activateWindow();
82         }
83         bool isVisibleView() const { return QDialog::isVisible(); }
84         void checkStatus() { updateView(); }
85         void updateData(std::string const & data)
86         {
87                 initialiseParams(data);
88                 updateView();
89         }
90         std::string name() const { return "paragraph"; }
91
92 private:
93         QString name_;
94
95         void showEvent(QShowEvent * e)
96         {
97                 QSettings settings;
98                 QString key = name_ + "/geometry";
99                 QDialog::restoreGeometry(settings.value(key).toByteArray());
100             QDialog::showEvent(e);
101         }
102
103         void closeEvent(QCloseEvent * e)
104         {
105                 QSettings settings;
106                 QString key = name_ + "/geometry";
107                 settings.setValue(key, QDialog::saveGeometry());
108                 QDialog::closeEvent(e);
109         }
110
111 private Q_SLOTS:
112         ///
113         void changed();
114         ///
115         void on_synchronizedViewCB_toggled();
116         ///
117         void on_restorePB_clicked();
118         ///
119         void on_linespacing_activated(int);
120         /// Apply changes
121         void on_applyPB_clicked();
122
123 private:
124         ///
125         bool initialiseParams(std::string const & /*data*/) { return true; }
126         /// clean-up on hide.
127         void clearParams() {}
128         ///
129         void dispatchParams();
130         ///
131         bool isBufferDependent() const { return true; }
132         ///
133         ParagraphParameters & params();
134         ///
135         ParagraphParameters const & params() const;
136         ///
137         bool haveMulitParSelection();
138         ///
139         bool canIndent() const;
140         ///
141         LyXAlignment alignPossible() const;
142         ///
143         LyXAlignment alignDefault() const;
144
145 private:
146         ParagraphParameters multiparsel_;
147 };
148
149 } // namespace frontend
150 } // namespace lyx
151
152 #endif // QPARAGRAPH_H