#include "GuiBox.h"
+#include "FuncRequest.h"
#include "LengthCombo.h"
-#include "qt_helpers.h"
-#include "lengthcommon.h"
+#include "Length.h"
#include "LyXRC.h" // to set the default length values
+#include "qt_helpers.h"
#include "Validator.h"
-#include "controllers/ControlBox.h"
-#include "controllers/frontend_helpers.h"
-
#include "insets/InsetBox.h"
+#include "support/gettext.h"
+#include "support/foreach.h"
#include "support/lstrings.h"
#include <QPushButton>
#include <QLineEdit>
-#include <QCloseEvent>
-
-using lyx::support::getStringFromVector;
-using lyx::support::isStrDbl;
-using lyx::support::subst;
-using std::string;
+using namespace std;
namespace lyx {
namespace frontend {
-//////////////////////////////////////////////////////////////////
-//
-// GuiBoxDialog
-//
-//////////////////////////////////////////////////////////////////
+static QStringList boxGuiIds()
+{
+ return QStringList()
+ << "Frameless" << "Boxed"
+ << "ovalbox" << "Ovalbox"
+ << "Shadowbox" << "Shaded"
+ << "Doublebox";
+}
+
+
+static QStringList boxGuiNames()
+{
+ return QStringList()
+ << qt_("No frame") << qt_("Simple rectangular frame")
+ << qt_("Oval frame, thin") << qt_("Oval frame, thick")
+ << qt_("Drop shadow") << qt_("Shaded background")
+ << qt_("Double rectangular frame");
+}
+
+
+static QStringList boxGuiSpecialLengthIds()
+{
+ return QStringList() << "none" << "height" << "depth"
+ << "totalheight" << "width";
+}
+
-GuiBoxDialog::GuiBoxDialog(GuiBox * form)
- : form_(form)
+static QStringList boxGuiSpecialLengthNames()
+{
+ return QStringList() << qt_("None") << qt_("Height") << qt_("Depth")
+ << qt_("Total Height") << qt_("Width");
+}
+
+
+GuiBox::GuiBox(GuiView & lv)
+ : GuiDialog(lv, "box", qt_("Box Settings")), params_("")
{
setupUi(this);
- connect(restorePB, SIGNAL(clicked()), form, SLOT(slotRestore()));
- connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
- connect(applyPB, SIGNAL(clicked()), form, SLOT(slotApply()));
- connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
- connect(widthED, SIGNAL(textChanged(const QString &)),
+ // fill the box type choice
+ ids_ = boxGuiIds();
+ gui_names_ = boxGuiNames();
+ foreach (QString const & str, gui_names_)
+ typeCO->addItem(str);
+
+ // add the special units to the height choice
+ // width needs different handling
+ ids_spec_ = boxGuiSpecialLengthIds();
+ gui_names_spec_ = boxGuiSpecialLengthNames();
+ foreach (QString const & str, gui_names_spec_)
+ heightUnitsLC->addItem(str);
+
+ connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
+ connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
+ connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
+ connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
+
+ connect(widthED, SIGNAL(textChanged(QString)),
this, SLOT(change_adaptor()));
connect(widthUnitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
this, SLOT(change_adaptor()));
- connect(valignCO, SIGNAL(highlighted(const QString &)),
+ connect(valignCO, SIGNAL(highlighted(QString)),
this, SLOT(change_adaptor()));
- connect(heightED, SIGNAL(textChanged(const QString &)),
+ connect(heightCB, SIGNAL(stateChanged(int)),
this, SLOT(change_adaptor()));
- connect(heightUnitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT) ),
+ connect(heightED, SIGNAL(textChanged(QString)),
+ this, SLOT(change_adaptor()));
+ connect(heightUnitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
this, SLOT(change_adaptor()));
connect(restorePB, SIGNAL(clicked()), this, SLOT(restoreClicked()));
connect(typeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
connect(typeCO, SIGNAL(activated(int)), this, SLOT(typeChanged(int)));
connect(halignCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
connect(ialignCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
- connect(innerBoxCO, SIGNAL(activated(const QString&)),
- this, SLOT(innerBoxChanged(const QString &)));
+ connect(innerBoxCO, SIGNAL(activated(QString)),
+ this, SLOT(innerBoxChanged(QString)));
connect(innerBoxCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
+ connect(pagebreakCB, SIGNAL(stateChanged(int)),
+ this, SLOT(pagebreakClicked()));
heightED->setValidator(unsignedLengthValidator(heightED));
widthED->setValidator(unsignedLengthValidator(widthED));
-}
+ bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
+
+ bc().addReadOnly(typeCO);
+ bc().addReadOnly(innerBoxCO);
+ bc().addReadOnly(valignCO);
+ bc().addReadOnly(ialignCO);
+ bc().addReadOnly(halignCO);
+ bc().addReadOnly(widthED);
+ bc().addReadOnly(widthUnitsLC);
+ bc().addReadOnly(heightCB);
+ bc().addReadOnly(heightED);
+ bc().addReadOnly(heightUnitsLC);
+ bc().addReadOnly(pagebreakCB);
+
+ bc().setRestore(restorePB);
+ bc().setOK(okPB);
+ bc().setApply(applyPB);
+ bc().setCancel(closePB);
-void GuiBoxDialog::closeEvent(QCloseEvent * e)
-{
- form_->slotWMHide();
- e->accept();
+ // initialize the length validator
+ bc().addCheckedLineEdit(widthED, widthLA);
+ bc().addCheckedLineEdit(heightED, heightCB);
}
-void GuiBoxDialog::change_adaptor()
+void GuiBox::change_adaptor()
{
- form_->changed();
+ changed();
}
-void GuiBoxDialog::innerBoxChanged(const QString & str)
+void GuiBox::innerBoxChanged(QString const & str)
{
bool const ibox = (str != qt_("None"));
valignCO->setEnabled(ibox);
ialignCO->setEnabled(ibox);
halignCO->setEnabled(!ibox);
- heightED->setEnabled(ibox);
- heightUnitsLC->setEnabled(ibox);
- form_->setSpecial(ibox);
+ heightCB->setEnabled(ibox);
+ pagebreakCB->setEnabled(!ibox && typeCO->currentIndex() == 1);
+ if (heightCB->checkState() == Qt::Checked && ibox) {
+ heightED->setEnabled(true);
+ heightUnitsLC->setEnabled(true);
+ }
+ setSpecial(ibox);
}
-void GuiBoxDialog::typeChanged(int index)
+void GuiBox::typeChanged(int index)
{
bool const frameless = (index == 0);
if (frameless) {
valignCO->setEnabled(true);
ialignCO->setEnabled(true);
halignCO->setEnabled(false);
+ heightCB->setEnabled(true);
heightED->setEnabled(true);
heightUnitsLC->setEnabled(true);
- form_->setSpecial(true);
+ setSpecial(true);
}
+ if (index != 1)
+ pagebreakCB->setChecked(false);
int itype = innerBoxCO->currentIndex();
- form_->setInnerType(frameless, itype);
+ pagebreakCB->setEnabled(index == 1 && itype == 0);
+ setInnerType(frameless, itype);
}
-void GuiBoxDialog::restoreClicked()
+void GuiBox::restoreClicked()
{
- form_->setInnerType(true, 2);
+ setInnerType(true, 2);
widthED->setText("100");
widthUnitsLC->setCurrentItem(Length::PCW);
+ heightCB->setCheckState(Qt::Checked);
heightED->setText("1");
- for (int j = 0; j < heightUnitsLC->count(); j++) {
- if (heightUnitsLC->itemText(j) == qt_("Total Height"))
- heightUnitsLC->setCurrentItem(j);
+ for (int i = 0; i != heightUnitsLC->count(); ++i) {
+ if (heightUnitsLC->itemText(i) == qt_("Total Height"))
+ heightUnitsLC->setCurrentItem(i);
}
}
-//////////////////////////////////////////////////////////////////
-//
-// GuiBox
-//
-//////////////////////////////////////////////////////////////////
-
-
-GuiBox::GuiBox(GuiDialog & parent)
- : GuiView<GuiBoxDialog>(parent, _("Box Settings"))
-{}
-
-
-void GuiBox::build_dialog()
+void GuiBox::pagebreakClicked()
{
- dialog_.reset(new GuiBoxDialog(this));
-
- // fill the box type choice
- box_gui_tokens(ids_, gui_names_);
- for (unsigned int i = 0; i < gui_names_.size(); ++i)
- dialog_->typeCO->addItem(toqstr(gui_names_[i]));
-
- // add the special units to the height choice
- // width needs different handling
- box_gui_tokens_special_length(ids_spec_, gui_names_spec_);
- for (unsigned int i = 1; i < gui_names_spec_.size(); ++i)
- dialog_->heightUnitsLC->addItem(toqstr(gui_names_spec_[i]));
-
- bc().addReadOnly(dialog_->typeCO);
- bc().addReadOnly(dialog_->innerBoxCO);
- bc().addReadOnly(dialog_->valignCO);
- bc().addReadOnly(dialog_->ialignCO);
- bc().addReadOnly(dialog_->halignCO);
- bc().addReadOnly(dialog_->widthED);
- bc().addReadOnly(dialog_->heightED);
- bc().addReadOnly(dialog_->widthUnitsLC);
- bc().addReadOnly(dialog_->heightUnitsLC);
-
- bc().setRestore(dialog_->restorePB);
- bc().setOK(dialog_->okPB);
- bc().setApply(dialog_->applyPB);
- bc().setCancel(dialog_->closePB);
-
- // initialize the length validator
- bc().addCheckedLineEdit(dialog_->widthED, dialog_->widthLA);
- bc().addCheckedLineEdit(dialog_->heightED, dialog_->heightLA);
+ bool pbreak = (pagebreakCB->checkState() == Qt::Checked);
+ innerBoxCO->setEnabled(!pbreak);
+ if (pbreak) {
+ valignCO->setEnabled(false);
+ ialignCO->setEnabled(false);
+ halignCO->setEnabled(false);
+ heightCB->setEnabled(false);
+ heightED->setEnabled(false);
+ heightUnitsLC->setEnabled(false);
+ setSpecial(false);
+ } else {
+ typeChanged(typeCO->currentIndex());
+ }
+ change_adaptor();
}
-void GuiBox::update_contents()
+void GuiBox::updateContents()
{
- string type(controller().params().type);
- for (unsigned int i = 0; i < gui_names_.size(); ++i) {
+ QString type = toqstr(params_.type);
+ if (type == "Framed") {
+ pagebreakCB->setChecked(true);
+ type = "Boxed";
+ } else {
+ pagebreakCB->setChecked(false);
+ }
+
+ pagebreakCB->setEnabled(type == "Boxed" && !params_.inner_box);
+
+ for (int i = 0; i != gui_names_.size(); ++i) {
if (type == ids_[i])
- dialog_->typeCO->setCurrentIndex(i);
+ typeCO->setCurrentIndex(i);
}
// default: minipage
- unsigned int inner_type = 2;
- if (!controller().params().inner_box)
+ int inner_type = 2;
+ if (!params_.inner_box)
// none
inner_type = 0;
- if (controller().params().use_parbox)
+ if (params_.use_parbox)
// parbox
inner_type = 1;
- bool frameless = (controller().params().type == "Frameless");
+ bool frameless = (params_.type == "Frameless");
setInnerType(frameless, inner_type);
- char c = controller().params().pos;
- dialog_->valignCO->setCurrentIndex(string("tcb").find(c, 0));
- c = controller().params().inner_pos;
- dialog_->ialignCO->setCurrentIndex(string("tcbs").find(c, 0));
- c = controller().params().hor_pos;
- dialog_->halignCO->setCurrentIndex(string("lcrs").find(c, 0));
-
- bool ibox = controller().params().inner_box;
- dialog_->valignCO->setEnabled(ibox);
- dialog_->ialignCO->setEnabled(ibox);
- dialog_->halignCO->setEnabled(!ibox);
+ char c = params_.pos;
+ valignCO->setCurrentIndex(string("tcb").find(c, 0));
+ c = params_.inner_pos;
+ ialignCO->setCurrentIndex(string("tcbs").find(c, 0));
+ c = params_.hor_pos;
+ halignCO->setCurrentIndex(string("lcrs").find(c, 0));
+
+ bool ibox = params_.inner_box;
+ valignCO->setEnabled(ibox);
+ ialignCO->setEnabled(ibox);
+ halignCO->setEnabled(!ibox);
setSpecial(ibox);
Length::UNIT default_unit =
(lyxrc.default_papersize > 3) ? Length::CM : Length::IN;
- lengthToWidgets(dialog_->widthED, dialog_->widthUnitsLC,
- (controller().params().width).asString(), default_unit);
+ lengthToWidgets(widthED, widthUnitsLC,
+ (params_.width).asString(), default_unit);
- string const special(controller().params().special);
- if (!special.empty() && special != "none") {
+ QString const special = toqstr(params_.special);
+ if (!special.isEmpty() && special != "none") {
QString spc;
- for (unsigned int i = 0; i < gui_names_spec_.size(); i++) {
+ for (int i = 0; i != gui_names_spec_.size(); ++i) {
if (special == ids_spec_[i])
- spc = toqstr(gui_names_spec_[i].c_str());
+ spc = gui_names_spec_[i];
}
- for (int j = 0; j < dialog_->widthUnitsLC->count(); j++) {
- if (dialog_->widthUnitsLC->itemText(j) == spc)
- dialog_->widthUnitsLC->setCurrentIndex(j);
+ for (int i = 0; i != widthUnitsLC->count(); ++i) {
+ if (widthUnitsLC->itemText(i) == spc)
+ widthUnitsLC->setCurrentIndex(i);
}
}
- lengthToWidgets(dialog_->heightED, dialog_->heightUnitsLC,
- (controller().params().height).asString(), default_unit);
-
- string const height_special(controller().params().height_special);
- if (!height_special.empty() && height_special != "none") {
+ lengthToWidgets(heightED, heightUnitsLC,
+ (params_.height).asString(), default_unit);
+
+ QString const height_special = toqstr(params_.height_special);
+ if (!height_special.isEmpty() && height_special != "none") {
QString hspc;
- for (unsigned int i = 0; i < gui_names_spec_.size(); i++) {
- if (height_special == ids_spec_[i]) {
- hspc = toqstr(gui_names_spec_[i].c_str());
- }
+ for (int i = 0; i != gui_names_spec_.size(); ++i) {
+ if (height_special == ids_spec_[i])
+ hspc = gui_names_spec_[i];
}
- for (int j = 0; j < dialog_->heightUnitsLC->count(); j++) {
- if (dialog_->heightUnitsLC->itemText(j) == hspc) {
- dialog_->heightUnitsLC->setCurrentIndex(j);
- }
+ for (int i = 0; i != heightUnitsLC->count(); ++i) {
+ if (heightUnitsLC->itemText(i) == hspc)
+ heightUnitsLC->setCurrentIndex(i);
}
}
-
- dialog_->heightED->setEnabled(ibox);
- dialog_->heightUnitsLC->setEnabled(ibox);
+ // set no optional height when the value is the default "1\height"
+ // (special units like \height are handled as "in",
+ if (height_special == "totalheight" && params_.height == Length("1in"))
+ heightCB->setCheckState(Qt::Unchecked);
+ else
+ heightCB->setCheckState(Qt::Checked);
+
+ heightCB->setEnabled(ibox);
}
-void GuiBox::apply()
+void GuiBox::applyView()
{
- controller().params().type =
- ids_[dialog_->typeCO->currentIndex()];
+ bool pagebreak = pagebreakCB->isEnabled() && pagebreakCB->isChecked();
+ if (pagebreak)
+ params_.type = "Framed";
+ else
+ params_.type = fromqstr(ids_[typeCO->currentIndex()]);
- controller().params().inner_box =
- dialog_->innerBoxCO->currentText() != qt_("None");
- controller().params().use_parbox =
- dialog_->innerBoxCO->currentText() == qt_("Parbox");
+ params_.inner_box = (!pagebreak && innerBoxCO->currentText() != qt_("None"));
+ params_.use_parbox = (!pagebreak && innerBoxCO->currentText() == qt_("Parbox"));
- controller().params().pos =
- "tcb"[dialog_->valignCO->currentIndex()];
- controller().params().inner_pos =
- "tcbs"[dialog_->ialignCO->currentIndex()];
- controller().params().hor_pos =
- "lcrs"[dialog_->halignCO->currentIndex()];
+ params_.pos = "tcb"[valignCO->currentIndex()];
+ params_.inner_pos = "tcbs"[ialignCO->currentIndex()];
+ params_.hor_pos = "lcrs"[halignCO->currentIndex()];
int i = 0;
bool spec = false;
- QString special = dialog_->widthUnitsLC->currentText();
- QString value = dialog_->widthED->text();
+ QString special = widthUnitsLC->currentText();
+ QString value = widthED->text();
if (special == qt_("Height")) {
i = 1;
spec = true;
i = 0;
spec = false;
}
- controller().params().special = ids_spec_[i];
+ params_.special = fromqstr(ids_spec_[i]);
string width;
if (spec) {
width = fromqstr(value);
// beware: bogosity! the unit is simply ignored in this case
width += "in";
- } else
- width = widgetsToLength(dialog_->widthED, dialog_->widthUnitsLC);
+ } else {
+ width = widgetsToLength(widthED, widthUnitsLC);
+ }
- controller().params().width = Length(width);
+ params_.width = Length(width);
i = 0;
spec = false;
- special = dialog_->heightUnitsLC->currentText();
- value = dialog_->heightED->text();
+ special = heightUnitsLC->currentText();
+ value = heightED->text();
if (special == qt_("Height")) {
i = 1;
spec = true;
i = 0;
spec = false;
}
- controller().params().height_special = ids_spec_[i];
+ params_.height_special = fromqstr(ids_spec_[i]);
string height;
- if (spec && !isValidLength(fromqstr(dialog_->heightED->text()))) {
+ if (spec && !isValidLength(fromqstr(heightED->text()))) {
height = fromqstr(value);
// beware: bogosity! the unit is simply ignored in this case
height += "in";
} else
- height = widgetsToLength(dialog_->heightED, dialog_->heightUnitsLC);
-
- controller().params().height = Length(height);
+ height = widgetsToLength(heightED, heightUnitsLC);
+
+ // the height parameter is omitted in InsetBox.cpp when the value
+ // is "1in" and "Total Height" is used as unit.
+ // 1in + "Total Height" means "1\height" which is the LaTeX default when
+ // no height is given
+ if (heightCB->checkState() == Qt::Checked)
+ params_.height = Length(height);
+ else {
+ params_.height = Length("1in");
+ params_.height_special = fromqstr(ids_spec_[3]);
+ }
}
void GuiBox::setSpecial(bool ibox)
{
- box_gui_tokens_special_length(ids_spec_, gui_names_spec_);
+ // FIXME: Needed? Already done in the constructor
+ ids_spec_ = boxGuiSpecialLengthIds();
+ gui_names_spec_ = boxGuiSpecialLengthNames();
+
// check if the widget contains the special units
- int count = dialog_->widthUnitsLC->count();
+ int count = widthUnitsLC->count();
bool has_special = false;
- for (int i = 0; i < count; i++)
- if (dialog_->widthUnitsLC->itemText(i).contains(qt_("Total Height")) > 0)
+ for (int i = 0; i != count; ++i)
+ if (widthUnitsLC->itemText(i).contains(qt_("Total Height")) > 0)
has_special = true;
// insert 'em if needed...
if (!ibox && !has_special) {
- for (unsigned int i = 1; i < gui_names_spec_.size(); i++)
- dialog_->widthUnitsLC->addItem(toqstr(gui_names_spec_[i]));
+ for (int i = 1; i < gui_names_spec_.size(); ++i)
+ widthUnitsLC->addItem(gui_names_spec_[i]);
// ... or remove 'em if needed
} else if (ibox && has_special) {
- dialog_->widthUnitsLC->clear();
- for (int i = 0; i < num_units; i++)
- dialog_->widthUnitsLC->addItem(qt_(unit_name_gui[i]));
+ widthUnitsLC->clear();
+ for (int i = 0; i != num_units; ++i)
+ widthUnitsLC->addItem(qt_(unit_name_gui[i]));
}
}
// with "frameless" boxes, inner box is mandatory (i.e. is the actual box)
// we have to remove "none" then and adjust the combo
if (frameless) {
- dialog_->innerBoxCO->clear();
- dialog_->innerBoxCO->addItem(qt_("Parbox"));
- dialog_->innerBoxCO->addItem(qt_("Minipage"));
- dialog_->innerBoxCO->setCurrentIndex(i - 1);
+ innerBoxCO->clear();
+ innerBoxCO->addItem(qt_("Parbox"));
+ innerBoxCO->addItem(qt_("Minipage"));
+ if (i != 0)
+ innerBoxCO->setCurrentIndex(i - 1);
+ else
+ innerBoxCO->setCurrentIndex(i);
} else {
- if (dialog_->innerBoxCO->count() == 2)
- i += 1;
- dialog_->innerBoxCO->clear();
- dialog_->innerBoxCO->addItem(qt_("None"));
- dialog_->innerBoxCO->addItem(qt_("Parbox"));
- dialog_->innerBoxCO->addItem(qt_("Minipage"));
- dialog_->innerBoxCO->setCurrentIndex(i);
+ if (innerBoxCO->count() == 2)
+ ++i;
+ innerBoxCO->clear();
+ innerBoxCO->addItem(qt_("None"));
+ innerBoxCO->addItem(qt_("Parbox"));
+ innerBoxCO->addItem(qt_("Minipage"));
+ innerBoxCO->setCurrentIndex(i);
}
}
+bool GuiBox::initialiseParams(string const & data)
+{
+ InsetBox::string2params(data, params_);
+ return true;
+
+}
+
+
+void GuiBox::clearParams()
+{
+ params_ = InsetBoxParams("");
+}
+
+
+void GuiBox::dispatchParams()
+{
+ dispatch(FuncRequest(getLfun(), InsetBox::params2string(params_)));
+}
+
+
+Dialog * createGuiBox(GuiView & lv) { return new GuiBox(lv); }
+
+
} // namespace frontend
} // namespace lyx