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>
38 using lyx::support::getStringFromVector;
39 using lyx::support::isStrDbl;
40 using lyx::support::subst;
46 typedef QController<ControlBox, QView<QBoxDialog> > box_base_class;
48 QBox::QBox(Dialog & parent)
49 : box_base_class(parent, _("Box Settings"))
53 void QBox::build_dialog()
55 dialog_.reset(new QBoxDialog(this));
57 // fill the box type choice
58 box_gui_tokens(ids_, gui_names_);
59 for (unsigned int i = 0; i < gui_names_.size(); ++i)
60 dialog_->typeCO->addItem(toqstr(gui_names_[i]));
62 // add the special units to the height choice
63 // width needs different handling
64 box_gui_tokens_special_length(ids_spec_, gui_names_spec_);
65 for (unsigned int i = 1; i < gui_names_spec_.size(); ++i) {
66 dialog_->heightUnitsLC->addItem(toqstr(gui_names_spec_[i]));
69 bcview().addReadOnly(dialog_->typeCO);
70 bcview().addReadOnly(dialog_->innerBoxCO);
71 bcview().addReadOnly(dialog_->valignCO);
72 bcview().addReadOnly(dialog_->ialignCO);
73 bcview().addReadOnly(dialog_->halignCO);
74 bcview().addReadOnly(dialog_->widthED);
75 bcview().addReadOnly(dialog_->heightED);
76 bcview().addReadOnly(dialog_->widthUnitsLC);
77 bcview().addReadOnly(dialog_->heightUnitsLC);
79 bcview().setRestore(dialog_->restorePB);
80 bcview().setOK(dialog_->okPB);
81 bcview().setApply(dialog_->applyPB);
82 bcview().setCancel(dialog_->closePB);
84 // initialize the length validator
85 addCheckedLineEdit(bcview(), dialog_->widthED, dialog_->widthLA);
86 addCheckedLineEdit(bcview(), dialog_->heightED, dialog_->heightLA);
90 void QBox::update_contents()
92 string type(controller().params().type);
93 for (unsigned int i = 0; i < gui_names_.size(); ++i) {
95 dialog_->typeCO->setCurrentIndex(i);
99 unsigned int inner_type = 2;
100 if (!controller().params().inner_box)
103 if (controller().params().use_parbox)
106 bool frameless = (controller().params().type == "Frameless");
107 setInnerType(frameless, inner_type);
109 char c = controller().params().pos;
110 dialog_->valignCO->setCurrentIndex(string("tcb").find(c, 0));
111 c = controller().params().inner_pos;
112 dialog_->ialignCO->setCurrentIndex(string("tcbs").find(c, 0));
113 c = controller().params().hor_pos;
114 dialog_->halignCO->setCurrentIndex(string("lcrs").find(c, 0));
116 bool ibox = controller().params().inner_box;
117 dialog_->valignCO->setEnabled(ibox);
118 dialog_->ialignCO->setEnabled(ibox);
119 dialog_->halignCO->setEnabled(!ibox);
122 LyXLength::UNIT default_unit =
123 (lyxrc.default_papersize > 3) ? LyXLength::CM : LyXLength::IN;
125 lengthToWidgets(dialog_->widthED, dialog_->widthUnitsLC,
126 (controller().params().width).asString(), default_unit);
128 string const special(controller().params().special);
129 if (!special.empty() && special != "none") {
131 for (unsigned int i = 0; i < gui_names_spec_.size(); i++) {
132 if (special == ids_spec_[i])
133 spc = toqstr(gui_names_spec_[i].c_str());
135 for (int j = 0; j < dialog_->widthUnitsLC->count(); j++) {
136 if (dialog_->widthUnitsLC->itemText(j) == spc)
137 dialog_->widthUnitsLC->setCurrentIndex(j);
141 lengthToWidgets(dialog_->heightED, dialog_->heightUnitsLC,
142 (controller().params().height).asString(), default_unit);
144 string const height_special(controller().params().height_special);
145 if (!height_special.empty() && height_special != "none") {
147 for (unsigned int i = 0; i < gui_names_spec_.size(); i++) {
148 if (height_special == ids_spec_[i]) {
149 hspc = toqstr(gui_names_spec_[i].c_str());
152 for (int j = 0; j < dialog_->heightUnitsLC->count(); j++) {
153 if (dialog_->heightUnitsLC->itemText(j) == hspc) {
154 dialog_->heightUnitsLC->setCurrentIndex(j);
159 dialog_->heightED->setEnabled(ibox);
160 dialog_->heightUnitsLC->setEnabled(ibox);
166 controller().params().type =
167 ids_[dialog_->typeCO->currentIndex()];
169 controller().params().inner_box =
170 dialog_->innerBoxCO->currentText() != qt_("None");
171 controller().params().use_parbox =
172 dialog_->innerBoxCO->currentText() == qt_("Parbox");
174 controller().params().pos =
175 "tcb"[dialog_->valignCO->currentIndex()];
176 controller().params().inner_pos =
177 "tcbs"[dialog_->ialignCO->currentIndex()];
178 controller().params().hor_pos =
179 "lcrs"[dialog_->halignCO->currentIndex()];
183 QString special = dialog_->widthUnitsLC->currentText();
184 QString value = dialog_->widthED->text();
185 if (special == qt_("Height")) {
188 } else if (special == qt_("Depth")) {
191 } else if (special == qt_("Total Height")) {
194 } else if (special == qt_("Width")) {
198 // the user might insert a non-special value in the line edit
199 if (isValidLength(fromqstr(value))) {
203 controller().params().special = ids_spec_[i];
207 width = fromqstr(value);
208 // beware: bogosity! the unit is simply ignored in this case
211 width = widgetsToLength(dialog_->widthED, dialog_->widthUnitsLC);
213 controller().params().width = LyXLength(width);
217 special = dialog_->heightUnitsLC->currentText();
218 value = dialog_->heightED->text();
219 if (special == qt_("Height")) {
222 } else if (special == qt_("Depth")) {
225 } else if (special == qt_("Total Height")) {
228 } else if (special == qt_("Width")) {
232 // the user might insert a non-special value in the line edit
233 if (isValidLength(fromqstr(value))) {
237 controller().params().height_special = ids_spec_[i];
240 if (spec && !isValidLength(fromqstr(dialog_->heightED->text()))) {
241 height = fromqstr(value);
242 // beware: bogosity! the unit is simply ignored in this case
245 height = widgetsToLength(dialog_->heightED, dialog_->heightUnitsLC);
247 controller().params().height = LyXLength(height);
251 void QBox::setSpecial(bool ibox)
253 box_gui_tokens_special_length(ids_spec_, gui_names_spec_);
254 // check if the widget contains the special units
255 int count = dialog_->widthUnitsLC->count();
256 bool has_special = false;
257 for (int i = 0; i < count; i++)
258 if (dialog_->widthUnitsLC->itemText(i).contains(qt_("Total Height")) > 0)
260 // insert 'em if needed...
261 if (!ibox && !has_special) {
262 for (unsigned int i = 1; i < gui_names_spec_.size(); i++)
263 dialog_->widthUnitsLC->addItem(toqstr(gui_names_spec_[i]));
264 // ... or remove 'em if needed
265 } else if (ibox && has_special) {
266 dialog_->widthUnitsLC->clear();
267 for (int i = 0; i < num_units; i++)
268 dialog_->widthUnitsLC->addItem(qt_(unit_name_gui[i]));
273 void QBox::setInnerType(bool frameless, int i)
275 // with "frameless" boxes, inner box is mandatory (i.e. is the actual box)
276 // we have to remove "none" then and adjust the combo
278 dialog_->innerBoxCO->clear();
279 dialog_->innerBoxCO->addItem(qt_("Parbox"));
280 dialog_->innerBoxCO->addItem(qt_("Minipage"));
281 dialog_->innerBoxCO->setCurrentIndex(i - 1);
283 if (dialog_->innerBoxCO->count() == 2)
285 dialog_->innerBoxCO->clear();
286 dialog_->innerBoxCO->addItem(qt_("None"));
287 dialog_->innerBoxCO->addItem(qt_("Parbox"));
288 dialog_->innerBoxCO->addItem(qt_("Minipage"));
289 dialog_->innerBoxCO->setCurrentIndex(i);
293 } // namespace frontend