3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Jürgen Vigna (Minipage stuff)
7 * \author Martin Vermeer
8 * \author Jürgen Spitzmüller
10 * Full author contact details are available in file CREDITS.
17 #include "checkedwidgets.h"
18 #include "lengthcombo.h"
19 #include "QBoxDialog.h"
20 #include "qt_helpers.h"
23 #include "lengthcommon.h"
24 #include "lyxrc.h" // to set the default length values
26 #include "controllers/ControlBox.h"
27 #include "controllers/helper_funcs.h"
29 #include "insets/insetbox.h"
31 #include "support/lstrings.h"
33 #include <qpushbutton.h>
34 #include <qlineedit.h>
35 #include <qcombobox.h>
36 #include <qbuttongroup.h>
40 using lyx::support::getStringFromVector;
41 using lyx::support::isStrDbl;
42 using lyx::support::subst;
48 typedef QController<ControlBox, QView<QBoxDialog> > base_class;
50 QBox::QBox(Dialog & parent)
51 : base_class(parent, _("Box Settings"))
55 void QBox::build_dialog()
57 dialog_.reset(new QBoxDialog(this));
59 // fill the box type choice
60 box_gui_tokens(ids_, gui_names_);
61 for (unsigned int i = 0; i < gui_names_.size(); ++i)
62 dialog_->typeCO->insertItem(toqstr(gui_names_[i]));
64 // add the special units to the height choice
65 // width needs different handling
66 box_gui_tokens_special_length(ids_spec_, gui_names_spec_);
67 for (unsigned int i = 1; i < gui_names_spec_.size(); ++i) {
68 dialog_->heightUnitsLC->insertItem(toqstr(gui_names_spec_[i]));
71 bcview().addReadOnly(dialog_->typeCO);
72 bcview().addReadOnly(dialog_->innerBoxCO);
73 bcview().addReadOnly(dialog_->valignCO);
74 bcview().addReadOnly(dialog_->ialignCO);
75 bcview().addReadOnly(dialog_->halignCO);
76 bcview().addReadOnly(dialog_->widthED);
77 bcview().addReadOnly(dialog_->heightED);
78 bcview().addReadOnly(dialog_->widthUnitsLC);
79 bcview().addReadOnly(dialog_->heightUnitsLC);
81 bcview().setRestore(dialog_->restorePB);
82 bcview().setOK(dialog_->okPB);
83 bcview().setApply(dialog_->applyPB);
84 bcview().setCancel(dialog_->closePB);
86 // initialize the length validator
87 addCheckedLineEdit(bcview(), dialog_->widthED, dialog_->widthLA);
88 addCheckedLineEdit(bcview(), dialog_->heightED, dialog_->heightLA);
92 void QBox::update_contents()
94 string type(controller().params().type);
95 for (unsigned int i = 0; i < gui_names_.size(); ++i) {
97 dialog_->typeCO->setCurrentItem(i);
101 unsigned int inner_type = 2;
102 if (!controller().params().inner_box)
105 if (controller().params().use_parbox)
108 bool frameless = (controller().params().type == "Frameless");
109 setInnerType(frameless, inner_type);
111 char c = controller().params().pos;
112 dialog_->valignCO->setCurrentItem(string("tcb").find(c, 0));
113 c = controller().params().inner_pos;
114 dialog_->ialignCO->setCurrentItem(string("tcbs").find(c, 0));
115 c = controller().params().hor_pos;
116 dialog_->halignCO->setCurrentItem(string("lcrs").find(c, 0));
118 bool ibox = controller().params().inner_box;
119 dialog_->valignCO->setEnabled(ibox);
120 dialog_->ialignCO->setEnabled(ibox);
121 dialog_->halignCO->setEnabled(!ibox);
124 LyXLength::UNIT default_unit =
125 (lyxrc.default_papersize > 3) ? LyXLength::CM : LyXLength::IN;
127 lengthToWidgets(dialog_->widthED, dialog_->widthUnitsLC,
128 (controller().params().width).asString(), default_unit);
130 string const special(controller().params().special);
131 if (!special.empty() && special != "none") {
133 for (unsigned int i = 0; i < gui_names_spec_.size(); i++) {
134 if (special == ids_spec_[i])
135 spc = toqstr(gui_names_spec_[i].c_str());
137 for (int j = 0; j < dialog_->widthUnitsLC->count(); j++) {
138 if (dialog_->widthUnitsLC->text(j) == spc)
139 dialog_->widthUnitsLC->setCurrentItem(j);
143 lengthToWidgets(dialog_->heightED, dialog_->heightUnitsLC,
144 (controller().params().height).asString(), default_unit);
146 string const height_special(controller().params().height_special);
147 if (!height_special.empty() && height_special != "none") {
149 for (unsigned int i = 0; i < gui_names_spec_.size(); i++) {
150 if (height_special == ids_spec_[i]) {
151 hspc = toqstr(gui_names_spec_[i].c_str());
154 for (int j = 0; j < dialog_->heightUnitsLC->count(); j++) {
155 if (dialog_->heightUnitsLC->text(j) == hspc) {
156 dialog_->heightUnitsLC->setCurrentItem(j);
161 dialog_->heightED->setEnabled(ibox);
162 dialog_->heightUnitsLC->setEnabled(ibox);
168 controller().params().type =
169 ids_[dialog_->typeCO->currentItem()];
171 controller().params().inner_box =
172 dialog_->innerBoxCO->currentText() != qt_("None");
173 controller().params().use_parbox =
174 dialog_->innerBoxCO->currentText() == qt_("Parbox");
176 controller().params().pos =
177 "tcb"[dialog_->valignCO->currentItem()];
178 controller().params().inner_pos =
179 "tcbs"[dialog_->ialignCO->currentItem()];
180 controller().params().hor_pos =
181 "lcrs"[dialog_->halignCO->currentItem()];
185 QString special = dialog_->widthUnitsLC->currentText();
186 QString value = dialog_->widthED->text();
187 if (special == qt_("Height")) {
190 } else if (special == qt_("Depth")) {
193 } else if (special == qt_("Total Height")) {
196 } else if (special == qt_("Width")) {
200 // the user might insert a non-special value in the line edit
201 if (isValidLength(fromqstr(value))) {
205 controller().params().special = ids_spec_[i];
209 width = fromqstr(value);
210 // beware: bogosity! the unit is simply ignored in this case
213 width = widgetsToLength(dialog_->widthED, dialog_->widthUnitsLC);
215 controller().params().width = LyXLength(width);
219 special = dialog_->heightUnitsLC->currentText();
220 value = dialog_->heightED->text();
221 if (special == qt_("Height")) {
224 } else if (special == qt_("Depth")) {
227 } else if (special == qt_("Total Height")) {
230 } else if (special == qt_("Width")) {
234 // the user might insert a non-special value in the line edit
235 if (isValidLength(fromqstr(value))) {
239 controller().params().height_special = ids_spec_[i];
242 if (spec && !isValidLength(fromqstr(dialog_->heightED->text()))) {
243 height = fromqstr(value);
244 // beware: bogosity! the unit is simply ignored in this case
247 height = widgetsToLength(dialog_->heightED, dialog_->heightUnitsLC);
249 controller().params().height = LyXLength(height);
253 void QBox::setSpecial(bool ibox)
255 box_gui_tokens_special_length(ids_spec_, gui_names_spec_);
256 // check if the widget contains the special units
257 int count = dialog_->widthUnitsLC->count();
258 bool has_special = false;
259 for (int i = 0; i < count; i++)
260 if (dialog_->widthUnitsLC->text(i).contains(qt_("Total Height")) > 0)
262 // insert 'em if needed...
263 if (!ibox && !has_special) {
264 for (unsigned int i = 1; i < gui_names_spec_.size(); i++)
265 dialog_->widthUnitsLC->insertItem(toqstr(gui_names_spec_[i]));
266 // ... or remove 'em if needed
267 } else if (ibox && has_special) {
268 dialog_->widthUnitsLC->clear();
269 for (int i = 0; i < num_units; i++)
270 dialog_->widthUnitsLC->insertItem(unit_name_gui[i]);
275 void QBox::setInnerType(bool frameless, int i)
277 // with "frameless" boxes, inner box is mandatory (i.e. is the actual box)
278 // we have to remove "none" then and adjust the combo
280 dialog_->innerBoxCO->clear();
281 dialog_->innerBoxCO->insertItem(qt_("Parbox"));
282 dialog_->innerBoxCO->insertItem(qt_("Minipage"));
283 dialog_->innerBoxCO->setCurrentItem(i - 1);
285 if (dialog_->innerBoxCO->count() == 2)
287 dialog_->innerBoxCO->clear();
288 dialog_->innerBoxCO->insertItem(qt_("None"));
289 dialog_->innerBoxCO->insertItem(qt_("Parbox"));
290 dialog_->innerBoxCO->insertItem(qt_("Minipage"));
291 dialog_->innerBoxCO->setCurrentItem(i);
295 } // namespace frontend