From 2f168bd342436e55f17a20e52970b6a30e5cf319 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Sun, 7 Feb 2010 20:28:41 +0000 Subject: [PATCH] Box dialog: migrate to the new InsetDialog architecture. This simplifies the code and allows for immediate application of any change in the dialog. This is quite a complicated and non intuitive dialog still... git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33351 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiBox.cpp | 196 ++++++++++------------- src/frontends/qt4/GuiBox.h | 43 +++-- src/frontends/qt4/ui/BoxUi.ui | 290 +++++++++++++++------------------- src/insets/InsetBox.h | 4 +- 4 files changed, 233 insertions(+), 300 deletions(-) diff --git a/src/frontends/qt4/GuiBox.cpp b/src/frontends/qt4/GuiBox.cpp index 087f8663a6..aaffcb3388 100644 --- a/src/frontends/qt4/GuiBox.cpp +++ b/src/frontends/qt4/GuiBox.cpp @@ -74,7 +74,7 @@ static QStringList boxGuiSpecialLengthNames() GuiBox::GuiBox(GuiView & lv) - : GuiDialog(lv, "box", qt_("Box Settings")), params_("") + : InsetDialog(lv, BOX_CODE, LFUN_BOX_INSERT, "box", "Box Settings") { setupUi(this); @@ -91,69 +91,47 @@ GuiBox::GuiBox(GuiView & lv) for (int i = 0; i != ids_spec_.size(); ++i) heightUnitsLC->addItem(gui_names_spec_[i], ids_spec_[i]); - 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(widthED, SIGNAL(textChanged(QString)), this, SLOT(applyView())); connect(widthUnitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)), - this, SLOT(change_adaptor())); - connect(valignCO, SIGNAL(highlighted(QString)), - this, SLOT(change_adaptor())); - connect(heightCB, SIGNAL(stateChanged(int)), - this, SLOT(change_adaptor())); - connect(heightED, SIGNAL(textChanged(QString)), - this, SLOT(change_adaptor())); + this, SLOT(applyView())); + connect(valignCO, SIGNAL(highlighted(QString)), this, SLOT(applyView())); + connect(heightCB, SIGNAL(stateChanged(int)), this, SLOT(applyView())); + connect(heightED, SIGNAL(textChanged(QString)), this, SLOT(applyView())); 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(QString)), - this, SLOT(innerBoxChanged(QString))); - connect(innerBoxCO, SIGNAL(activated(int)), this, SLOT(change_adaptor())); - connect(pagebreakCB, SIGNAL(stateChanged(int)), - this, SLOT(pagebreakClicked())); + this, SLOT(applyView())); + connect(innerBoxCO, SIGNAL(activated(int)), this, SLOT(applyView())); + connect(typeCO, SIGNAL(activated(int)), this, SLOT(applyView())); + connect(halignCO, SIGNAL(activated(int)), this, SLOT(applyView())); + connect(ialignCO, SIGNAL(activated(int)), this, SLOT(applyView())); 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); - // initialize the length validator - bc().addCheckedLineEdit(widthED, widthLA); - bc().addCheckedLineEdit(heightED, heightCB); + addCheckedWidget(widthED, widthLA); + addCheckedWidget(heightED, heightCB); + + initDialog(); } -void GuiBox::change_adaptor() +void GuiBox::enableView(bool enable) { - changed(); + typeCO->setEnabled(enable); + innerBoxCO->setEnabled(enable); + valignCO->setEnabled(enable); + ialignCO->setEnabled(enable); + halignCO->setEnabled(enable); + widthED->setEnabled(enable); + widthUnitsLC->setEnabled(enable); + heightCB->setEnabled(enable); + heightED->setEnabled(enable); + heightUnitsLC->setEnabled(enable); + pagebreakCB->setEnabled(enable); } -void GuiBox::innerBoxChanged(QString const & str) +void GuiBox::on_innerBoxCO_activated(QString const & str) { bool const ibox = (str != qt_("None")); valignCO->setEnabled(ibox); @@ -161,13 +139,12 @@ void GuiBox::innerBoxChanged(QString const & str) halignCO->setEnabled(!ibox); heightCB->setEnabled(ibox); pagebreakCB->setEnabled(!ibox && typeCO->currentIndex() == 1); - heightED->setEnabled(heightCB->checkState() == Qt::Checked && ibox); - heightUnitsLC->setEnabled(heightCB->checkState() == Qt::Checked && ibox); setSpecial(ibox); + applyView(); } -void GuiBox::typeChanged(int index) +void GuiBox::on_typeCO_activated(int index) { bool const frameless = (index == 0); if (frameless) { @@ -175,8 +152,6 @@ void GuiBox::typeChanged(int index) ialignCO->setEnabled(true); halignCO->setEnabled(false); heightCB->setEnabled(true); - heightED->setEnabled(heightCB->checkState() == Qt::Checked); - heightUnitsLC->setEnabled(heightCB->checkState() == Qt::Checked); setSpecial(true); } if (index != 1) @@ -188,10 +163,11 @@ void GuiBox::typeChanged(int index) widthED->setEnabled(index != 5); widthUnitsLC->setEnabled(index != 5); setInnerType(frameless, itype); + applyView(); } -void GuiBox::restoreClicked() +void GuiBox::initDialog() { setInnerType(true, 2); widthED->setText("100"); @@ -202,7 +178,16 @@ void GuiBox::restoreClicked() } -void GuiBox::pagebreakClicked() +void GuiBox::on_heightCB_stateChanged(int state) +{ + bool const enable = (innerBoxCO->currentText() != qt_("None")) + && (state == Qt::Checked); + heightED->setEnabled(enable); + heightUnitsLC->setEnabled(enable); +} + + +void GuiBox::on_pagebreakCB_stateChanged() { bool pbreak = (pagebreakCB->checkState() == Qt::Checked); innerBoxCO->setEnabled(!pbreak); @@ -217,15 +202,17 @@ void GuiBox::pagebreakClicked() heightUnitsLC->setEnabled(false); setSpecial(false); } else { - typeChanged(typeCO->currentIndex()); + on_typeCO_activated(typeCO->currentIndex()); } - change_adaptor(); + applyView(); } -void GuiBox::updateContents() +void GuiBox::paramsToDialog(Inset const * inset) { - QString type = toqstr(params_.type); + InsetBox const * box = static_cast(inset); + InsetBoxParams const & params = box->params(); + QString type = toqstr(params.type); if (type == "Framed") { pagebreakCB->setChecked(true); type = "Boxed"; @@ -233,7 +220,7 @@ void GuiBox::updateContents() pagebreakCB->setChecked(false); } - pagebreakCB->setEnabled(type == "Boxed" && !params_.inner_box); + pagebreakCB->setEnabled(type == "Boxed" && !params.inner_box); for (int i = 0; i != gui_names_.size(); ++i) { if (type == ids_[i]) @@ -242,23 +229,23 @@ void GuiBox::updateContents() // default: minipage int inner_type = 2; - if (!params_.inner_box) + if (!params.inner_box) // none inner_type = 0; - if (params_.use_parbox) + if (params.use_parbox) // parbox inner_type = 1; - bool frameless = (params_.type == "Frameless"); + bool frameless = (params.type == "Frameless"); setInnerType(frameless, inner_type); - char c = params_.pos; + char c = params.pos; valignCO->setCurrentIndex(string("tcb").find(c, 0)); - c = params_.inner_pos; + c = params.inner_pos; ialignCO->setCurrentIndex(string("tcbs").find(c, 0)); - c = params_.hor_pos; + c = params.hor_pos; halignCO->setCurrentIndex(string("lcrs").find(c, 0)); - bool ibox = params_.inner_box; + bool ibox = params.inner_box; valignCO->setEnabled(ibox); ialignCO->setEnabled(ibox); halignCO->setEnabled(!ibox); @@ -267,21 +254,23 @@ void GuiBox::updateContents() Length::UNIT const default_unit = Length::defaultUnit(); lengthToWidgets(widthED, widthUnitsLC, - (params_.width).asString(), default_unit); + (params.width).asString(), default_unit); - QString const special = toqstr(params_.special); + QString const special = toqstr(params.special); if (!special.isEmpty() && special != "none") widthUnitsLC->setCurrentItem(special); lengthToWidgets(heightED, heightUnitsLC, - (params_.height).asString(), default_unit); + (params.height).asString(), default_unit); - QString const height_special = toqstr(params_.height_special); + QString const height_special = toqstr(params.height_special); if (!height_special.isEmpty() && height_special != "none") heightUnitsLC->setCurrentItem(height_special); // set no optional height if the value is the default "1\height" // (special units like \height are handled as "in", - if (height_special == "totalheight" && params_.height == Length("1in")) + // FIXME: this is a very bad UI, this check box should be disabled in + // this case, not forced to 'unchecked' state. + if (height_special == "totalheight" && params.height == Length("1in")) heightCB->setCheckState(Qt::Unchecked); else heightCB->setCheckState(Qt::Checked); @@ -290,34 +279,36 @@ void GuiBox::updateContents() } -void GuiBox::applyView() +docstring GuiBox::dialogToParams() const { - bool pagebreak = + bool const pagebreak = pagebreakCB->isEnabled() && pagebreakCB->isChecked(); + string box_type; if (pagebreak) - params_.type = "Framed"; + box_type = "Framed"; else - params_.type = fromqstr(ids_[typeCO->currentIndex()]); + box_type = fromqstr(ids_[typeCO->currentIndex()]); - params_.inner_box = + InsetBoxParams params(box_type); + params.inner_box = (!pagebreak && innerBoxCO->currentText() != qt_("None")); - params_.use_parbox = + params.use_parbox = (!pagebreak && innerBoxCO->currentText() == qt_("Parbox")); - params_.pos = "tcb"[valignCO->currentIndex()]; - params_.inner_pos = "tcbs"[ialignCO->currentIndex()]; - params_.hor_pos = "lcrs"[halignCO->currentIndex()]; + params.pos = "tcb"[valignCO->currentIndex()]; + params.inner_pos = "tcbs"[ialignCO->currentIndex()]; + params.hor_pos = "lcrs"[halignCO->currentIndex()]; QString unit = widthUnitsLC->itemData(widthUnitsLC->currentIndex()).toString(); QString value = widthED->text(); if (ids_spec_.contains(unit) && !isValidLength(fromqstr(value))) { - params_.special = fromqstr(unit); + params.special = fromqstr(unit); // Note: the unit is simply ignored in this case - params_.width = Length(value.toDouble(), Length::IN); + params.width = Length(value.toDouble(), Length::IN); } else { - params_.special = "none"; - params_.width = Length(widgetsToLength(widthED, widthUnitsLC)); + params.special = "none"; + params.width = Length(widgetsToLength(widthED, widthUnitsLC)); } // the height parameter is omitted if the value @@ -325,21 +316,22 @@ void GuiBox::applyView() // 1in + "Total Height" means "1\height" which is the LaTeX default // if no height is given if (heightCB->checkState() == Qt::Unchecked) { - params_.height = Length("1in"); - params_.height_special = "totalheight"; + params.height = Length("1in"); + params.height_special = "totalheight"; } else { unit = heightUnitsLC->itemData(heightUnitsLC->currentIndex()).toString(); value = heightED->text(); if (ids_spec_.contains(unit) && !isValidLength(fromqstr(value))) { - params_.height_special = fromqstr(unit); + params.height_special = fromqstr(unit); // Note: the unit is simply ignored in this case - params_.height = Length(value.toDouble(), Length::IN); + params.height = Length(value.toDouble(), Length::IN); } else { - params_.height_special = "none"; - params_.height = + params.height_special = "none"; + params.height = Length(widgetsToLength(heightED, heightUnitsLC)); } } + return from_ascii(InsetBox::params2string(params)); } @@ -388,24 +380,6 @@ void GuiBox::setInnerType(bool frameless, int 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); } diff --git a/src/frontends/qt4/GuiBox.h b/src/frontends/qt4/GuiBox.h index 813454a4d4..07a69f030f 100644 --- a/src/frontends/qt4/GuiBox.h +++ b/src/frontends/qt4/GuiBox.h @@ -13,7 +13,7 @@ #ifndef GUIBOX_H #define GUIBOX_H -#include "GuiDialog.h" +#include "InsetDialog.h" #include "ui_BoxUi.h" #include "insets/InsetBox.h" @@ -21,7 +21,7 @@ namespace lyx { namespace frontend { -class GuiBox : public GuiDialog, public Ui::BoxUi +class GuiBox : public InsetDialog, public Ui::BoxUi { Q_OBJECT @@ -29,33 +29,29 @@ public: GuiBox(GuiView & lv); private Q_SLOTS: - void change_adaptor(); - void innerBoxChanged(QString const &); - void typeChanged(int); - void restoreClicked(); - void pagebreakClicked(); + void on_innerBoxCO_activated(QString const &); + void on_typeCO_activated(int); + void initDialog(); + void on_heightCB_stateChanged(int state); + void on_pagebreakCB_stateChanged(); private: + /// \name Dialog inerited methods + //@{ + void enableView(bool enable); + //@} + + /// \name InsetDialog inherited methods + //@{ + void paramsToDialog(Inset const *); + docstring dialogToParams() const; + //@} + /// add and remove special lengths void setSpecial(bool ibox); /// only show valid inner box items void setInnerType(bool frameless, int i); - /// Apply changes - void applyView(); - /// update - void updateContents(); - - /// - bool initialiseParams(std::string const & data); - /// - void clearParams(); - /// - void dispatchParams(); - /// - bool isBufferDependent() const { return true; } - - /// QStringList ids_; /// QStringList gui_names_; @@ -63,9 +59,6 @@ private: QStringList ids_spec_; /// QStringList gui_names_spec_; - - /// - InsetBoxParams params_; }; } // namespace frontend diff --git a/src/frontends/qt4/ui/BoxUi.ui b/src/frontends/qt4/ui/BoxUi.ui index ce6eec4b28..e6d71d5cf2 100644 --- a/src/frontends/qt4/ui/BoxUi.ui +++ b/src/frontends/qt4/ui/BoxUi.ui @@ -1,7 +1,8 @@ - + + BoxUi - - + + 0 0 @@ -9,175 +10,171 @@ 288 - + - + true - - + + 9 - + 6 - - - + + + Check this if the box should break across pages - + Allow &page breaks - - - + + + Alignment - + true - - + + 9 - + 6 - - - - - 7 - 0 + + + + 0 0 - + Horizontal alignment of the content inside the box - + Left - + Center - + Right - + Stretch - - - - - 7 - 0 + + + + 0 0 - + Vertical alignment of the content inside the box - + Top - + Middle - + Bottom - + Stretch - - - + + + Vertical alignment of the box (with regard to baseline) - + Top - + Middle - + Bottom - - - + + + Vertical alignment of the box (with regard to baseline) - + &Box: - + valignCO - - - + + + Co&ntent: - + ialignCO - - - + + + Vertical alignment of the content inside the box - + Vertical - - - + + + Horizontal alignment of the content inside the box - + Horizontal @@ -185,39 +182,23 @@ - - - - 0 - - + + + 6 - - - - - - - &Restore - - - false - - - false - - - + + 0 + - + Qt::Horizontal - + QSizePolicy::Expanding - + 20 20 @@ -226,156 +207,143 @@ - - - - - - &OK - - - true - - - - - - + + - - &Apply + + &New - + false - + false - - + + &Close - + false - + false - - - + + + false - - - + + + - + &Height: - + false - + false - - - + + + - + Inner Bo&x: - + innerBoxCO - - + + - - - + + + - + &Decoration: - + typeCO - - - + + + - + &Width: - + widthED - - - + + + false - + Height value - - - + + + Width value - - - + + + Inner box -- needed for fixed width & line breaks - + None - + Parbox - + Minipage - - - + + + Supported box types @@ -400,13 +368,11 @@ ialignCO halignCO valignCO - restorePB - okPB closePB - applyPB + newPB - qt_i18n.h + qt_i18n.h @@ -416,11 +382,11 @@ heightED setEnabled(bool) - + 75 83 - + 171 83 @@ -432,11 +398,11 @@ heightUnitsLC setEnabled(bool) - + 86 100 - + 283 100 diff --git a/src/insets/InsetBox.h b/src/insets/InsetBox.h index 83ba43403e..60ecfbda64 100644 --- a/src/insets/InsetBox.h +++ b/src/insets/InsetBox.h @@ -83,6 +83,8 @@ public: static std::string params2string(InsetBoxParams const &); /// static void string2params(std::string const &, InsetBoxParams &); + /// + InsetBoxParams const & params() const { return params_; } private: /// friend class InsetBoxParams; @@ -121,8 +123,6 @@ private: /// void validate(LaTeXFeatures &) const; /// - InsetBoxParams const & params() const { return params_; } - /// bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const; /// void doDispatch(Cursor & cur, FuncRequest & cmd); -- 2.39.2