]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QParagraph.C
renaming in frontends/qt4/ui: s/Q//g
[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  * \author Richard Heck
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "QParagraph.h"
15 #include "QParagraphDialog.h"
16 #include "Qt2BC.h"
17 #include "qt_helpers.h"
18
19 #include "debug.h"
20 #include "ParagraphParameters.h"
21 #include "Spacing.h"
22 #include "layout.h"
23
24 #include "controllers/ControlParagraph.h"
25 #include "controllers/helper_funcs.h"
26
27 #include <QCheckBox>
28 #include <QLineEdit>
29 #include <QPushButton>
30
31
32 using std::string;
33 using std::endl;
34
35 namespace lyx {
36 namespace frontend {
37
38 typedef QController<ControlParagraph, QView<QParagraphDialog> > paragraph_base_class;
39
40
41 QParagraph::QParagraph(Dialog & parent)
42         : paragraph_base_class(parent, _("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         params.align(dialog_->getAlignmentFromDialog());
64
65         // get spacing
66         Spacing::Space linespacing = Spacing::Default;
67         string other;
68         switch (dialog_->linespacing->currentIndex()) {
69         case 0:
70                 linespacing = Spacing::Default;
71                 break;
72         case 1:
73                 linespacing = Spacing::Single;
74                 break;
75         case 2:
76                 linespacing = Spacing::Onehalf;
77                 break;
78         case 3:
79                 linespacing = Spacing::Double;
80                 break;
81         case 4:
82                 linespacing = Spacing::Other;
83                 other = fromqstr(dialog_->linespacingValue->text());
84                 break;
85         }
86
87         Spacing const spacing(linespacing, other);
88         params.spacing(spacing);
89
90         // label width
91         params.labelWidthString(qstring_to_ucs4(dialog_->labelWidth->text()));
92         // indendation
93         params.noindent(!dialog_->indentCB->isChecked());
94 }
95
96
97 void QParagraph::update_contents()
98 {
99         ParagraphParameters const & params = controller().params();
100
101         // label width
102         docstring const & labelwidth = params.labelWidthString();
103         // FIXME We should not compare translated strings
104         if (labelwidth != _("Senseless with this layout!")) {
105                 dialog_->labelwidthGB->setEnabled(true);
106                 dialog_->labelWidth->setText(toqstr(labelwidth));
107         } else {
108                 dialog_->labelwidthGB->setEnabled(false);
109                 dialog_->labelWidth->setText("");
110         }
111
112         // alignment
113         LyXAlignment newAlignment = params.align();
114         LyXAlignment defaultAlignment = controller().alignDefault();
115         bool alignmentIsDefault = 
116                 newAlignment == LYX_ALIGN_LAYOUT || newAlignment == defaultAlignment;
117         dialog_->alignDefaultCB->blockSignals(true);
118         dialog_->alignDefaultCB->setChecked(alignmentIsDefault);
119         dialog_->alignDefaultCB->blockSignals(false);
120         dialog_->checkAlignmentRadioButtons();
121         dialog_->alignmentToRadioButtons(newAlignment);
122
123         //indentation
124         dialog_->indentCB->setChecked(!params.noindent());
125
126         // linespacing
127         int linespacing;
128         Spacing const & space = params.spacing();
129         switch (space.getSpace()) {
130         case Spacing::Single:
131                 linespacing = 1;
132                 break;
133         case Spacing::Onehalf:
134                 linespacing = 2;
135                 break;
136         case Spacing::Double:
137                 linespacing = 3;
138                 break;
139         case Spacing::Other:
140                 linespacing = 4;
141                 break;
142         default:
143                 linespacing = 0;
144                 break;
145         }
146         dialog_->linespacing->setCurrentIndex(linespacing);
147         if (space.getSpace() == Spacing::Other) {
148                 dialog_->linespacingValue->setText(toqstr(space.getValueAsString()));
149                 dialog_->linespacingValue->setEnabled(true);
150         } else {
151                 dialog_->linespacingValue->setText("");
152                 dialog_->linespacingValue->setEnabled(false);
153         }
154 }
155
156 } // namespace frontend
157 } // namespace lyx