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