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 <q3buttongroup.h>
39 using lyx::support::getStringFromVector;
40 using lyx::support::isStrDbl;
41 using lyx::support::subst;
47 typedef QController<ControlBox, QView<QBoxDialog> > base_class;
49 QBox::QBox(Dialog & parent)
50 : base_class(parent, _("Box Settings"))
54 void QBox::build_dialog()
56 dialog_.reset(new QBoxDialog(this));
58 // fill the box type choice
59 box_gui_tokens(ids_, gui_names_);
60 for (unsigned int i = 0; i < gui_names_.size(); ++i)
61 dialog_->typeCO->insertItem(toqstr(gui_names_[i]));
63 // add the special units to the height choice
64 // width needs different handling
65 box_gui_tokens_special_length(ids_spec_, gui_names_spec_);
66 for (unsigned int i = 1; i < gui_names_spec_.size(); ++i) {
67 dialog_->heightUnitsLC->insertItem(toqstr(gui_names_spec_[i]));
70 bcview().addReadOnly(dialog_->typeCO);
71 bcview().addReadOnly(dialog_->innerBoxCO);
72 bcview().addReadOnly(dialog_->valignCO);
73 bcview().addReadOnly(dialog_->ialignCO);
74 bcview().addReadOnly(dialog_->halignCO);
75 bcview().addReadOnly(dialog_->widthED);
76 bcview().addReadOnly(dialog_->heightED);
77 bcview().addReadOnly(dialog_->widthUnitsLC);
78 bcview().addReadOnly(dialog_->heightUnitsLC);
80 bcview().setRestore(dialog_->restorePB);
81 bcview().setOK(dialog_->okPB);
82 bcview().setApply(dialog_->applyPB);
83 bcview().setCancel(dialog_->closePB);
85 // initialize the length validator
86 addCheckedLineEdit(bcview(), dialog_->widthED, dialog_->widthLA);
87 addCheckedLineEdit(bcview(), dialog_->heightED, dialog_->heightLA);
91 void QBox::update_contents()
93 string type(controller().params().type);
94 for (unsigned int i = 0; i < gui_names_.size(); ++i) {
96 dialog_->typeCO->setCurrentItem(i);
100 unsigned int inner_type = 2;
101 if (!controller().params().inner_box)
104 if (controller().params().use_parbox)
107 bool frameless = (controller().params().type == "Frameless");
108 setInnerType(frameless, inner_type);
110 char c = controller().params().pos;
111 dialog_->valignCO->setCurrentItem(string("tcb").find(c, 0));
112 c = controller().params().inner_pos;
113 dialog_->ialignCO->setCurrentItem(string("tcbs").find(c, 0));
114 c = controller().params().hor_pos;
115 dialog_->halignCO->setCurrentItem(string("lcrs").find(c, 0));
117 bool ibox = controller().params().inner_box;
118 dialog_->valignCO->setEnabled(ibox);
119 dialog_->ialignCO->setEnabled(ibox);
120 dialog_->halignCO->setEnabled(!ibox);
123 LyXLength::UNIT default_unit =
124 (lyxrc.default_papersize > 3) ? LyXLength::CM : LyXLength::IN;
126 lengthToWidgets(dialog_->widthED, dialog_->widthUnitsLC,
127 (controller().params().width).asString(), default_unit);
129 string const special(controller().params().special);
130 if (!special.empty() && special != "none") {
132 for (unsigned int i = 0; i < gui_names_spec_.size(); i++) {
133 if (special == ids_spec_[i])
134 spc = toqstr(gui_names_spec_[i].c_str());
136 for (int j = 0; j < dialog_->widthUnitsLC->count(); j++) {
137 if (dialog_->widthUnitsLC->text(j) == spc)
138 dialog_->widthUnitsLC->setCurrentItem(j);
142 lengthToWidgets(dialog_->heightED, dialog_->heightUnitsLC,
143 (controller().params().height).asString(), default_unit);
145 string const height_special(controller().params().height_special);
146 if (!height_special.empty() && height_special != "none") {
148 for (unsigned int i = 0; i < gui_names_spec_.size(); i++) {
149 if (height_special == ids_spec_[i]) {
150 hspc = toqstr(gui_names_spec_[i].c_str());
153 for (int j = 0; j < dialog_->heightUnitsLC->count(); j++) {
154 if (dialog_->heightUnitsLC->text(j) == hspc) {
155 dialog_->heightUnitsLC->setCurrentItem(j);
160 dialog_->heightED->setEnabled(ibox);
161 dialog_->heightUnitsLC->setEnabled(ibox);
167 controller().params().type =
168 ids_[dialog_->typeCO->currentItem()];
170 controller().params().inner_box =
171 dialog_->innerBoxCO->currentText() != qt_("None");
172 controller().params().use_parbox =
173 dialog_->innerBoxCO->currentText() == qt_("Parbox");
175 controller().params().pos =
176 "tcb"[dialog_->valignCO->currentItem()];
177 controller().params().inner_pos =
178 "tcbs"[dialog_->ialignCO->currentItem()];
179 controller().params().hor_pos =
180 "lcrs"[dialog_->halignCO->currentItem()];
184 QString special = dialog_->widthUnitsLC->currentText();
185 QString value = dialog_->widthED->text();
186 if (special == qt_("Height")) {
189 } else if (special == qt_("Depth")) {
192 } else if (special == qt_("Total Height")) {
195 } else if (special == qt_("Width")) {
199 // the user might insert a non-special value in the line edit
200 if (isValidLength(fromqstr(value))) {
204 controller().params().special = ids_spec_[i];
208 width = fromqstr(value);
209 // beware: bogosity! the unit is simply ignored in this case
212 width = widgetsToLength(dialog_->widthED, dialog_->widthUnitsLC);
214 controller().params().width = LyXLength(width);
218 special = dialog_->heightUnitsLC->currentText();
219 value = dialog_->heightED->text();
220 if (special == qt_("Height")) {
223 } else if (special == qt_("Depth")) {
226 } else if (special == qt_("Total Height")) {
229 } else if (special == qt_("Width")) {
233 // the user might insert a non-special value in the line edit
234 if (isValidLength(fromqstr(value))) {
238 controller().params().height_special = ids_spec_[i];
241 if (spec && !isValidLength(fromqstr(dialog_->heightED->text()))) {
242 height = fromqstr(value);
243 // beware: bogosity! the unit is simply ignored in this case
246 height = widgetsToLength(dialog_->heightED, dialog_->heightUnitsLC);
248 controller().params().height = LyXLength(height);
252 void QBox::setSpecial(bool ibox)
254 box_gui_tokens_special_length(ids_spec_, gui_names_spec_);
255 // check if the widget contains the special units
256 int count = dialog_->widthUnitsLC->count();
257 bool has_special = false;
258 for (int i = 0; i < count; i++)
259 if (dialog_->widthUnitsLC->text(i).contains(qt_("Total Height")) > 0)
261 // insert 'em if needed...
262 if (!ibox && !has_special) {
263 for (unsigned int i = 1; i < gui_names_spec_.size(); i++)
264 dialog_->widthUnitsLC->insertItem(toqstr(gui_names_spec_[i]));
265 // ... or remove 'em if needed
266 } else if (ibox && has_special) {
267 dialog_->widthUnitsLC->clear();
268 for (int i = 0; i < num_units; i++)
269 dialog_->widthUnitsLC->insertItem(unit_name_gui[i]);
274 void QBox::setInnerType(bool frameless, int i)
276 // with "frameless" boxes, inner box is mandatory (i.e. is the actual box)
277 // we have to remove "none" then and adjust the combo
279 dialog_->innerBoxCO->clear();
280 dialog_->innerBoxCO->insertItem(qt_("Parbox"));
281 dialog_->innerBoxCO->insertItem(qt_("Minipage"));
282 dialog_->innerBoxCO->setCurrentItem(i - 1);
284 if (dialog_->innerBoxCO->count() == 2)
286 dialog_->innerBoxCO->clear();
287 dialog_->innerBoxCO->insertItem(qt_("None"));
288 dialog_->innerBoxCO->insertItem(qt_("Parbox"));
289 dialog_->innerBoxCO->insertItem(qt_("Minipage"));
290 dialog_->innerBoxCO->setCurrentItem(i);
294 } // namespace frontend