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