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 "ControlBox.h"
18 #include "QBoxDialog.h"
19 #include "qt_helpers.h"
20 #include "controllers/helper_funcs.h"
21 #include "support/lstrings.h"
22 #include "support/tostr.h"
25 #include "lyxrc.h" // to set the default length values
26 #include "insets/insetbox.h"
28 #include "lengthcombo.h"
29 #include "lengthcommon.h"
30 #include <qpushbutton.h>
31 #include <qlineedit.h>
32 #include <qcombobox.h>
33 #include <qbuttongroup.h>
37 using lyx::support::getStringFromVector;
38 using lyx::support::isStrDbl;
39 using lyx::support::subst;
43 typedef QController<ControlBox, QView<QBoxDialog> > base_class;
45 QBox::QBox(Dialog & parent)
46 : base_class(parent, _("LyX: Box Settings"))
50 void QBox::build_dialog()
52 dialog_.reset(new QBoxDialog(this));
54 // fill the box type choice
55 box_gui_tokens(ids_, gui_names_);
56 for (unsigned int i = 0; i < gui_names_.size(); ++i)
57 dialog_->typeCO->insertItem(toqstr(gui_names_[i]));
59 // add the special units to the height choice
60 // width needs different handling
61 box_gui_tokens_special_length(ids_spec_, gui_names_spec_);
62 for (unsigned int i = 1; i < gui_names_spec_.size(); ++i) {
63 dialog_->heightUnitsLC->insertItem(toqstr(gui_names_spec_[i]));
66 bcview().addReadOnly(dialog_->typeCO);
67 bcview().addReadOnly(dialog_->innerBoxCO);
68 bcview().addReadOnly(dialog_->valignCO);
69 bcview().addReadOnly(dialog_->ialignCO);
70 bcview().addReadOnly(dialog_->halignCO);
71 bcview().addReadOnly(dialog_->widthED);
72 bcview().addReadOnly(dialog_->heightED);
73 bcview().addReadOnly(dialog_->widthUnitsLC);
74 bcview().addReadOnly(dialog_->heightUnitsLC);
76 bcview().setRestore(dialog_->restorePB);
77 bcview().setOK(dialog_->okPB);
78 bcview().setApply(dialog_->applyPB);
79 bcview().setCancel(dialog_->closePB);
83 void QBox::update_contents()
85 string type(controller().params().type);
86 for (unsigned int i = 0; i < gui_names_.size(); ++i) {
88 dialog_->typeCO->setCurrentItem(i);
92 unsigned int inner_type = 2;
93 if (!controller().params().inner_box)
96 if (controller().params().use_parbox)
99 bool frameless = (controller().params().type == "Frameless");
100 setInnerType(frameless, inner_type);
102 char c = controller().params().pos;
103 dialog_->valignCO->setCurrentItem(string("tcb").find(c, 0));
104 c = controller().params().inner_pos;
105 dialog_->ialignCO->setCurrentItem(string("tcbs").find(c, 0));
106 c = controller().params().hor_pos;
107 dialog_->halignCO->setCurrentItem(string("lcrs").find(c, 0));
109 bool ibox = controller().params().inner_box;
110 dialog_->valignCO->setEnabled(ibox);
111 dialog_->ialignCO->setEnabled(ibox);
112 dialog_->halignCO->setEnabled(!ibox);
115 LyXLength::UNIT default_unit =
116 (lyxrc.default_papersize > 3) ? LyXLength::CM : LyXLength::IN;
118 lengthToWidgets(dialog_->widthED, dialog_->widthUnitsLC,
119 (controller().params().width).asString(), default_unit);
121 string const special(controller().params().special);
122 if (!special.empty() && special != "none") {
124 for (unsigned int i = 0; i < gui_names_spec_.size(); i++) {
125 if (special == ids_spec_[i])
126 spc = toqstr(gui_names_spec_[i].c_str());
128 for (int j = 0; j < dialog_->widthUnitsLC->count(); j++) {
129 if (dialog_->widthUnitsLC->text(j) == spc)
130 dialog_->widthUnitsLC->setCurrentItem(j);
134 lengthToWidgets(dialog_->heightED, dialog_->heightUnitsLC,
135 (controller().params().height).asString(), default_unit);
137 string const height_special(controller().params().height_special);
138 if (!height_special.empty() && height_special != "none") {
140 for (unsigned int i = 0; i < gui_names_spec_.size(); i++) {
141 if (height_special == ids_spec_[i]) {
142 hspc = toqstr(gui_names_spec_[i].c_str());
145 for (int j = 0; j < dialog_->heightUnitsLC->count(); j++) {
146 if (dialog_->heightUnitsLC->text(j) == hspc) {
147 dialog_->heightUnitsLC->setCurrentItem(j);
152 dialog_->heightED->setEnabled(ibox);
153 dialog_->heightUnitsLC->setEnabled(ibox);
159 controller().params().type =
160 ids_[dialog_->typeCO->currentItem()];
162 controller().params().inner_box =
163 dialog_->innerBoxCO->currentText() != qt_("None");
164 controller().params().use_parbox =
165 dialog_->innerBoxCO->currentText() == qt_("Parbox");
167 controller().params().pos =
168 "tcb"[dialog_->valignCO->currentItem()];
169 controller().params().inner_pos =
170 "tcbs"[dialog_->ialignCO->currentItem()];
171 controller().params().hor_pos =
172 "lcrs"[dialog_->halignCO->currentItem()];
176 QString special = dialog_->widthUnitsLC->currentText();
177 if (special == qt_("Height")) {
180 } else if (special == qt_("Depth")) {
183 } else if (special == qt_("Total Height")) {
186 } else if (special == qt_("Width")) {
190 controller().params().special = ids_spec_[i];
194 width = fromqstr(dialog_->widthED->text());
195 // beware: bogosity! the unit is simply ignored in this case
198 width = widgetsToLength(dialog_->widthED, dialog_->widthUnitsLC);
200 controller().params().width = LyXLength(width);
204 special = dialog_->heightUnitsLC->currentText();
205 if (special == qt_("Height")) {
208 } else if (special == qt_("Depth")) {
211 } else if (special == qt_("Total Height")) {
214 } else if (special == qt_("Width")) {
218 controller().params().height_special = ids_spec_[i];
222 height = fromqstr(dialog_->heightED->text());
223 // beware: bogosity! the unit is simply ignored in this case
226 height = widgetsToLength(dialog_->heightED, dialog_->heightUnitsLC);
228 controller().params().height = LyXLength(height);
232 void QBox::setSpecial(bool ibox)
234 box_gui_tokens_special_length(ids_spec_, gui_names_spec_);
235 // check if the widget contains the special units
236 int count = dialog_->widthUnitsLC->count();
237 bool has_special = false;
238 for (int i = 0; i < count; i++)
239 if (dialog_->widthUnitsLC->text(i).contains(qt_("Total Height")) > 0)
241 // insert 'em if needed...
242 if (!ibox && !has_special) {
243 for (unsigned int i = 1; i < gui_names_spec_.size(); i++)
244 dialog_->widthUnitsLC->insertItem(toqstr(gui_names_spec_[i]));
245 // ... or remove 'em if needed
246 } else if (ibox && has_special) {
247 dialog_->widthUnitsLC->clear();
248 for (int i = 0; i < num_units; i++)
249 dialog_->widthUnitsLC->insertItem(unit_name_gui[i]);
254 void QBox::setInnerType(bool frameless, int i)
256 // with "frameless" boxes, inner box is mandatory (i.e. is the actual box)
257 // we have to remove "none" then and adjust the combo
259 dialog_->innerBoxCO->clear();
260 dialog_->innerBoxCO->insertItem(qt_("Parbox"));
261 dialog_->innerBoxCO->insertItem(qt_("Minipage"));
262 dialog_->innerBoxCO->setCurrentItem(i - 1);
264 if (dialog_->innerBoxCO->count() == 2)
266 dialog_->innerBoxCO->clear();
267 dialog_->innerBoxCO->insertItem(qt_("None"));
268 dialog_->innerBoxCO->insertItem(qt_("Parbox"));
269 dialog_->innerBoxCO->insertItem(qt_("Minipage"));
270 dialog_->innerBoxCO->setCurrentItem(i);