]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiParagraph.h
00cb552ef1300438e95df1f521df720e0327609b
[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 #include "Layout.h"
18 #include "ui_ParagraphUi.h"
19 #include "Dialog.h"
20 #include "ParagraphParameters.h"
21 #include "GuiView.h"
22 #include "qt_helpers.h"
23 #include "debug.h"
24
25 #include <QCloseEvent>
26 #include <QDialog>
27 #include <QSettings>
28 #include <QShowEvent>
29 #include <QGridLayout>
30
31 #include <map>
32 #include <string>
33
34 namespace lyx {
35 namespace frontend {
36
37 class GuiParagraph
38         : public QDialog, public Ui::ParagraphUi, public Controller, public Dialog
39 {
40         Q_OBJECT
41 public:
42         GuiParagraph(LyXView & lv);
43
44         /// update
45         void updateView();
46
47 private:
48         ///
49         void checkAlignmentRadioButtons();
50         ///
51         void alignmentToRadioButtons(LyXAlignment align = LYX_ALIGN_LAYOUT);
52         ///
53         LyXAlignment getAlignmentFromDialog();
54         ///
55         Controller & controller() { return *this; }
56         ///
57         typedef std::map<LyXAlignment, QRadioButton *> RadioMap;
58         RadioMap radioMap;
59
60         QString const alignDefaultLabel;
61
62         void applyView() {}
63         void hideView()
64         {
65                 clearParams();
66                 QDialog::hide();
67         }
68         void showData(std::string const & data)
69         {
70                 initialiseParams(data);
71                 showView();
72         }
73         void showView()
74         {
75                 updateView();  // make sure its up-to-date
76                 QDialog::show();
77                 raise();
78                 activateWindow();
79         }
80         bool isVisibleView() const { return QDialog::isVisible(); }
81         void checkStatus() { updateView(); }
82         void redraw() { redrawView(); }
83         void redrawView() {}
84         void updateData(std::string const & data)
85         {
86                 initialiseParams(data);
87                 updateView();
88         }
89         void partialUpdateView(int /*id*/) {}
90         std::string name() const { return "paragraph"; }
91
92 private:
93         std::string name_;
94
95         void showEvent(QShowEvent * e)
96         {
97 #if (QT_VERSION >= 0x040200)
98                 QSettings settings;
99                 std::string key = name_ + "/geometry";
100                 QDialog::restoreGeometry(settings.value(key.c_str()).toByteArray());
101 #endif
102             QDialog::showEvent(e);
103         }
104
105         void closeEvent(QCloseEvent * e)
106         {
107 #if (QT_VERSION >= 0x040200)
108                 QSettings settings;
109                 std::string key = name_ + "/geometry";
110                 settings.setValue(key.c_str(), QDialog::saveGeometry());
111 #endif
112             QDialog::closeEvent(e);
113         }
114
115 private Q_SLOTS:
116         ///
117         void changed();
118         ///
119         void on_synchronizedViewCB_toggled();
120         ///
121         void on_restorePB_clicked();
122         ///
123         void on_linespacing_activated(int);
124         /// Apply changes
125         void on_applyPB_clicked();
126
127 private:
128         ///
129         bool initialiseParams(std::string const & /*data*/) { return true; }
130         /// clean-up on hide.
131         void clearParams() {}
132         ///
133         void dispatchParams();
134         ///
135         bool isBufferDependent() const { return true; }
136         ///
137         ParagraphParameters & params();
138         ///
139         ParagraphParameters const & params() const;
140         ///
141         bool haveMulitParSelection();
142         ///
143         bool canIndent() const;
144         ///
145         LyXAlignment alignPossible() const;
146         ///
147         LyXAlignment alignDefault() const;
148
149 private:
150         ParagraphParameters multiparsel_;
151 };
152
153 } // namespace frontend
154 } // namespace lyx
155
156 #endif // QPARAGRAPH_H