]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QParagraph.C
This new citation dialog follows a new design similar to lyx-1.3:
[lyx.git] / src / frontends / qt4 / 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 <q3buttongroup.h>
25 #include <qcheckbox.h>
26 #include <qlineedit.h>
27 #include <qpushbutton.h>
28
29
30 using std::string;
31
32 namespace lyx {
33 namespace frontend {
34
35 typedef QController<ControlParagraph, QView<QParagraphDialog> > base_class;
36
37
38 QParagraph::QParagraph(Dialog & parent)
39         : base_class(parent, _("Paragraph Settings"))
40 {}
41
42
43 void QParagraph::build_dialog()
44 {
45         // the dialog
46         dialog_.reset(new QParagraphDialog(this));
47
48         // Manage the ok, apply, restore and cancel/close buttons
49         bcview().setOK(dialog_->okPB);
50         bcview().setApply(dialog_->applyPB);
51         bcview().setCancel(dialog_->closePB);
52         bcview().setRestore(dialog_->restorePB);
53 }
54
55
56 void QParagraph::apply()
57 {
58         ParagraphParameters & params = controller().params();
59
60         // alignment
61         LyXAlignment align;
62         switch (dialog_->align->currentItem()) {
63         case 0:
64                 align = LYX_ALIGN_BLOCK;
65                 break;
66         case 1:
67                 align = LYX_ALIGN_LEFT;
68                 break;
69         case 2:
70                 align = LYX_ALIGN_RIGHT;
71                 break;
72         case 3:
73                 align = LYX_ALIGN_CENTER;
74                 break;
75         default:
76                 align = LYX_ALIGN_BLOCK;
77         }
78         params.align(align);
79
80         // get spacing
81         Spacing::Space linespacing = Spacing::Default;
82         string other;
83         switch (dialog_->linespacing->currentItem()) {
84         case 0:
85                 linespacing = Spacing::Default;
86                 break;
87         case 1:
88                 linespacing = Spacing::Single;
89                 break;
90         case 2:
91                 linespacing = Spacing::Onehalf;
92                 break;
93         case 3:
94                 linespacing = Spacing::Double;
95                 break;
96         case 4:
97                 linespacing = Spacing::Other;
98                 other = fromqstr(dialog_->linespacingValue->text());
99                 break;
100         }
101
102         Spacing const spacing(linespacing, other);
103         params.spacing(spacing);
104
105         // label width
106         params.labelWidthString(fromqstr(dialog_->labelWidth->text()));
107         // indendation
108         params.noindent(!dialog_->indentCB->isChecked());
109 }
110
111
112 void QParagraph::update_contents()
113 {
114         ParagraphParameters const & params = controller().params();
115
116         // label width
117         string const & labelwidth = params.labelWidthString();
118         // _() is correct here (this is stupid though !)
119         if (labelwidth != _("Senseless with this layout!")) {
120                 dialog_->labelwidthGB->setEnabled(true);
121                 dialog_->labelWidth->setText(toqstr(labelwidth));
122         } else {
123                 dialog_->labelwidthGB->setEnabled(false);
124                 dialog_->labelWidth->setText("");
125         }
126
127         // alignment
128         int i;
129         switch (params.align()) {
130         case LYX_ALIGN_LEFT:
131                 i = 1;
132                 break;
133         case LYX_ALIGN_RIGHT:
134                 i = 2;
135                 break;
136         case LYX_ALIGN_CENTER:
137                 i = 3;
138                 break;
139         default:
140                 i = 0;
141                 break;
142         }
143         dialog_->align->setCurrentItem(i);
144
145
146         //LyXAlignment alignpos = controller().alignPossible();
147
148         dialog_->indentCB->setChecked(!params.noindent());
149
150         // linespacing
151         int linespacing;
152         Spacing const & space = params.spacing();
153         switch (space.getSpace()) {
154         case Spacing::Single:
155                 linespacing = 1;
156                 break;
157         case Spacing::Onehalf:
158                 linespacing = 2;
159                 break;
160         case Spacing::Double:
161                 linespacing = 3;
162                 break;
163         case Spacing::Other:
164                 linespacing = 4;
165                 break;
166         default:
167                 linespacing = 0;
168                 break;
169         }
170         dialog_->linespacing->setCurrentItem(linespacing);
171         if (space.getSpace() == Spacing::Other) {
172                 dialog_->linespacingValue->setText(toqstr(space.getValueAsString()));
173                 dialog_->linespacingValue->setEnabled(true);
174         } else {
175                 dialog_->linespacingValue->setText("");
176                 dialog_->linespacingValue->setEnabled(false);
177         }
178 }
179
180 } // namespace frontend
181 } // namespace lyx