]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QParagraph.C
fix math fonts with LyX/Mac
[lyx.git] / src / frontends / qt2 / QParagraph.C
1 /**
2  * \file QParagraph.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Edwin Leuven
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "QParagraph.h"
14 #include "QParagraphDialog.h"
15 #include "Qt2BC.h"
16 #include "qt_helpers.h"
17
18 #include "ParagraphParameters.h"
19 #include "Spacing.h"
20
21 #include "controllers/ControlParagraph.h"
22 #include "controllers/helper_funcs.h"
23
24 #include "support/tostr.h"
25
26 #include <qbuttongroup.h>
27 #include <qcheckbox.h>
28 #include <qcombobox.h>
29 #include <qlineedit.h>
30 #include <qpushbutton.h>
31
32
33 using std::string;
34
35 namespace lyx {
36 namespace frontend {
37
38 typedef QController<ControlParagraph, QView<QParagraphDialog> > base_class;
39
40
41 QParagraph::QParagraph(Dialog & parent)
42         : base_class(parent, _("LyX: Paragraph Settings"))
43 {}
44
45
46 void QParagraph::build_dialog()
47 {
48         // the dialog
49         dialog_.reset(new QParagraphDialog(this));
50
51         // Manage the ok, apply, restore and cancel/close buttons
52         bcview().setOK(dialog_->okPB);
53         bcview().setApply(dialog_->applyPB);
54         bcview().setCancel(dialog_->closePB);
55         bcview().setRestore(dialog_->restorePB);
56 }
57
58
59 void QParagraph::apply()
60 {
61         ParagraphParameters & params = controller().params();
62
63         // alignment
64         LyXAlignment align;
65         switch (dialog_->align->currentItem()) {
66         case 0:
67                 align = LYX_ALIGN_BLOCK;
68                 break;
69         case 1:
70                 align = LYX_ALIGN_LEFT;
71                 break;
72         case 2:
73                 align = LYX_ALIGN_RIGHT;
74                 break;
75         case 3:
76                 align = LYX_ALIGN_CENTER;
77                 break;
78         default:
79                 align = LYX_ALIGN_BLOCK;
80         }
81         params.align(align);
82
83         // get spacing
84         Spacing::Space linespacing = Spacing::Default;
85         string other;
86         switch (dialog_->linespacing->currentItem()) {
87         case 0:
88                 linespacing = Spacing::Default;
89                 break;
90         case 1:
91                 linespacing = Spacing::Single;
92                 break;
93         case 2:
94                 linespacing = Spacing::Onehalf;
95                 break;
96         case 3:
97                 linespacing = Spacing::Double;
98                 break;
99         case 4:
100                 linespacing = Spacing::Other;
101                 other = fromqstr(dialog_->linespacingValue->text());
102                 break;
103         }
104
105         Spacing const spacing(linespacing, other);
106         params.spacing(spacing);
107
108         // label width
109         params.labelWidthString(fromqstr(dialog_->labelWidth->text()));
110         // indendation
111         params.noindent(!dialog_->indentCB->isChecked());
112 }
113
114
115 void QParagraph::update_contents()
116 {
117         ParagraphParameters const & params = controller().params();
118
119         // label width
120         string const & labelwidth = params.labelWidthString();
121         // _() is correct here (this is stupid though !)
122         if (labelwidth != _("Senseless with this layout!")) {
123                 dialog_->labelwidthGB->setEnabled(true);
124                 dialog_->labelWidth->setText(toqstr(labelwidth));
125         } else {
126                 dialog_->labelwidthGB->setEnabled(false);
127                 dialog_->labelWidth->setText("");
128         }
129
130         // alignment
131         int i;
132         switch (params.align()) {
133         case LYX_ALIGN_LEFT:
134                 i = 1;
135                 break;
136         case LYX_ALIGN_RIGHT:
137                 i = 2;
138                 break;
139         case LYX_ALIGN_CENTER:
140                 i = 3;
141                 break;
142         default:
143                 i = 0;
144                 break;
145         }
146         dialog_->align->setCurrentItem(i);
147
148
149         //LyXAlignment alignpos = controller().alignPossible();
150
151         dialog_->indentCB->setChecked(!params.noindent());
152
153         // linespacing
154         int linespacing;
155         Spacing const & space = params.spacing();
156         switch (space.getSpace()) {
157         case Spacing::Single:
158                 linespacing = 1;
159                 break;
160         case Spacing::Onehalf:
161                 linespacing = 2;
162                 break;
163         case Spacing::Double:
164                 linespacing = 3;
165                 break;
166         case Spacing::Other:
167                 linespacing = 4;
168                 break;
169         default:
170                 linespacing = 0;
171                 break;
172         }
173         dialog_->linespacing->setCurrentItem(linespacing);
174         if (space.getSpace() == Spacing::Other) {
175                 string const sp = tostr(space.getValue());
176                 dialog_->linespacingValue->setText(toqstr(sp));
177                 dialog_->linespacingValue->setEnabled(true);
178         } else {
179                 dialog_->linespacingValue->setText("");
180                 dialog_->linespacingValue->setEnabled(false);
181         }
182 }
183
184 } // namespace frontend
185 } // namespace lyx