diff --git a/src/frontends/qt4/Dialog.cpp b/src/frontends/qt4/Dialog.cpp index 47db6db5a7..abc6007deb 100644 --- a/src/frontends/qt4/Dialog.cpp +++ b/src/frontends/qt4/Dialog.cpp @@ -42,17 +42,6 @@ using namespace lyx::support; namespace lyx { namespace frontend { -bool CheckedLineEdit2::check() const -{ - bool const valid = input_->hasAcceptableInput(); - // Visual feedback. - setValid(input_, valid); - if (label_) - setValid(label_, valid); - return valid; -} - - Dialog::Dialog(GuiView & lv, QString const & name, QString const & title) : name_(name), title_(title), lyxview_(&lv) {} @@ -62,21 +51,6 @@ Dialog::~Dialog() {} -void Dialog::addCheckedWidget(QLineEdit * input, QWidget * label) -{ - checked_line_edits_.append(CheckedLineEdit2(input, label)); -} - - -bool Dialog::checkWidgets() const -{ - bool valid = true; - Q_FOREACH(CheckedLineEdit2 const & le, checked_line_edits_) - valid &= le.check(); - return valid; -} - - bool Dialog::canApply() const { FuncRequest const fr(getLfun(), fromqstr(name_)); diff --git a/src/frontends/qt4/Dialog.h b/src/frontends/qt4/Dialog.h index 1fd0500636..34232d29a2 100644 --- a/src/frontends/qt4/Dialog.h +++ b/src/frontends/qt4/Dialog.h @@ -22,7 +22,6 @@ #include class QWidget; -class QLineEdit; namespace lyx { @@ -46,28 +45,6 @@ enum KernelDocType DOCBOOK }; -/// CheckedLineEdit -// FIXME: Get rid of CheckedLineEdit in ButtonController and rename this one -// to it. -class CheckedLineEdit2 -{ -public: - CheckedLineEdit2(QLineEdit * input, QWidget * label = 0) - : input_(input), label_(label) - {} - /// - bool check() const; - -private: - // non-owned - QLineEdit * input_; - QWidget * label_; -}; - - -typedef QList CheckedLineEdits; - - /** \c Dialog collects the different parts of a Model-Controller-View * split of a generic dialog together. */ @@ -279,11 +256,6 @@ protected: void setTitle(QString const & title) { title_ = title; } /// virtual void apply(); - /// Add a widget to the list of all widgets whose validity should - /// be checked explicitly when the buttons are refreshed. - void addCheckedWidget(QLineEdit * input, QWidget * label = 0); - /// \return true if all CheckedWidgets are in a valid state. - bool checkWidgets() const; private: /** The Dialog's name is the means by which a dialog identifies @@ -298,9 +270,6 @@ private: /// intentionally unimplemented, therefore uncopiable Dialog(Dialog const &); void operator=(Dialog const &); - - /// - CheckedLineEdits checked_line_edits_; }; diff --git a/src/frontends/qt4/FloatPlacement.cpp b/src/frontends/qt4/FloatPlacement.cpp index 1e3bcbd8ad..c40b3b2ec7 100644 --- a/src/frontends/qt4/FloatPlacement.cpp +++ b/src/frontends/qt4/FloatPlacement.cpp @@ -27,8 +27,10 @@ using namespace lyx::support; namespace lyx { +namespace frontend { + FloatPlacement::FloatPlacement(bool show_options, QWidget * parent) - : QWidget(parent), float_list_(0) + : InsetParamsWidget(parent), float_list_(0) { setupUi(this); @@ -244,6 +246,7 @@ void FloatPlacement::checkAllowed() } } +} // namespace frontend } // namespace lyx #include "moc_FloatPlacement.cpp" diff --git a/src/frontends/qt4/FloatPlacement.h b/src/frontends/qt4/FloatPlacement.h index ba975ad09f..dca71b9dba 100644 --- a/src/frontends/qt4/FloatPlacement.h +++ b/src/frontends/qt4/FloatPlacement.h @@ -13,10 +13,9 @@ #ifndef FLOATPLACEMENT_H #define FLOATPLACEMENT_H +#include "InsetParamsWidget.h" #include "ui_FloatPlacementUi.h" -#include - #include "support/docstring.h" namespace lyx { @@ -25,15 +24,20 @@ class FloatList; class Inset; class InsetFloatParams; -class FloatPlacement : public QWidget, public Ui::FloatPlacementUi { +namespace frontend { + +class FloatPlacement : public InsetParamsWidget, public Ui::FloatPlacementUi { Q_OBJECT public: FloatPlacement(bool show_options = false, QWidget * parent = 0); - /// + /// \name DialogView inherited methods + //@{ + InsetCode insetCode() { return FLOAT_CODE; } + FuncCode creationCode() { return LFUN_FLOAT_INSERT; } void paramsToDialog(Inset const *); - /// docstring dialogToParams() const; + //@} /// void useWide(); /// @@ -47,9 +51,6 @@ private Q_SLOTS: void on_defaultsCB_stateChanged(int state); void changedSlot(); -Q_SIGNALS: - void changed(); - private: /// void checkAllowed(); @@ -64,6 +65,7 @@ private: FloatList const * float_list_; }; +} // namespace frontend } // namespace lyx #endif // FLOATPLACEMENT_H diff --git a/src/frontends/qt4/GuiBox.cpp b/src/frontends/qt4/GuiBox.cpp index bd3321e200..9c6196bbeb 100644 --- a/src/frontends/qt4/GuiBox.cpp +++ b/src/frontends/qt4/GuiBox.cpp @@ -73,8 +73,7 @@ static QStringList boxGuiSpecialLengthNames() } -GuiBox::GuiBox(GuiView & lv) - : InsetDialog(lv, BOX_CODE, LFUN_BOX_INSERT, "box", "Box Settings") +GuiBox::GuiBox(QWidget * parent) : InsetParamsWidget(parent) { setupUi(this); @@ -91,15 +90,15 @@ GuiBox::GuiBox(GuiView & lv) for (int i = 0; i != ids_spec_.size(); ++i) heightUnitsLC->addItem(gui_names_spec_[i], ids_spec_[i]); - connect(widthED, SIGNAL(textChanged(QString)), this, SLOT(applyView())); + connect(widthED, SIGNAL(textChanged(QString)), this, SIGNAL(changed())); connect(widthUnitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)), - this, SLOT(applyView())); - connect(valignCO, SIGNAL(highlighted(QString)), this, SLOT(applyView())); - connect(heightED, SIGNAL(textChanged(QString)), this, SLOT(applyView())); + this, SIGNAL(changed())); + connect(valignCO, SIGNAL(highlighted(QString)), this, SIGNAL(changed())); + connect(heightED, SIGNAL(textChanged(QString)), this, SIGNAL(changed())); connect(heightUnitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)), - this, SLOT(applyView())); - connect(halignCO, SIGNAL(activated(int)), this, SLOT(applyView())); - connect(ialignCO, SIGNAL(activated(int)), this, SLOT(applyView())); + this, SIGNAL(changed())); + connect(halignCO, SIGNAL(activated(int)), this, SIGNAL(changed())); + connect(ialignCO, SIGNAL(activated(int)), this, SIGNAL(changed())); heightED->setValidator(unsignedLengthValidator(heightED)); widthED->setValidator(unsignedLengthValidator(widthED)); @@ -112,22 +111,6 @@ GuiBox::GuiBox(GuiView & lv) } -void GuiBox::enableView(bool enable) -{ - 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::on_innerBoxCO_activated(QString const & str) { bool const ibox = (str != qt_("None")); @@ -137,7 +120,7 @@ void GuiBox::on_innerBoxCO_activated(QString const & str) heightCB->setEnabled(ibox); pagebreakCB->setEnabled(!ibox && typeCO->currentIndex() == 1); setSpecial(ibox); - applyView(); + changed(); } @@ -160,7 +143,7 @@ void GuiBox::on_typeCO_activated(int index) widthED->setEnabled(index != 5); widthUnitsLC->setEnabled(index != 5); setInnerType(frameless, itype); - applyView(); + changed(); } @@ -181,7 +164,7 @@ void GuiBox::on_heightCB_stateChanged(int state) && (state == Qt::Checked); heightED->setEnabled(enable); heightUnitsLC->setEnabled(enable); - applyView(); + changed(); } @@ -202,7 +185,7 @@ void GuiBox::on_pagebreakCB_stateChanged() heightED->setEnabled(false); heightUnitsLC->setEnabled(false); setSpecial(false); - applyView(); + changed(); } @@ -378,10 +361,6 @@ void GuiBox::setInnerType(bool frameless, int i) } } - -Dialog * createGuiBox(GuiView & lv) { return new GuiBox(lv); } - - } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/GuiBox.h b/src/frontends/qt4/GuiBox.h index 07a69f030f..25b6bfa9b3 100644 --- a/src/frontends/qt4/GuiBox.h +++ b/src/frontends/qt4/GuiBox.h @@ -13,20 +13,19 @@ #ifndef GUIBOX_H #define GUIBOX_H -#include "InsetDialog.h" +#include "InsetParamsWidget.h" #include "ui_BoxUi.h" -#include "insets/InsetBox.h" namespace lyx { namespace frontend { -class GuiBox : public InsetDialog, public Ui::BoxUi +class GuiBox : public InsetParamsWidget, public Ui::BoxUi { Q_OBJECT public: - GuiBox(GuiView & lv); + GuiBox(QWidget * parent = 0); private Q_SLOTS: void on_innerBoxCO_activated(QString const &); @@ -36,13 +35,10 @@ private Q_SLOTS: void on_pagebreakCB_stateChanged(); private: - /// \name Dialog inerited methods - //@{ - void enableView(bool enable); - //@} - - /// \name InsetDialog inherited methods + /// \name DialogView inherited methods //@{ + InsetCode insetCode() { return BOX_CODE; } + FuncCode creationCode() { return LFUN_BOX_INSERT; } void paramsToDialog(Inset const *); docstring dialogToParams() const; //@} diff --git a/src/frontends/qt4/GuiDocument.h b/src/frontends/qt4/GuiDocument.h index 920e95145d..537dce2749 100644 --- a/src/frontends/qt4/GuiDocument.h +++ b/src/frontends/qt4/GuiDocument.h @@ -43,12 +43,12 @@ namespace lyx { class BufferParams; -class FloatPlacement; class LayoutModuleList; class TextClass; namespace frontend { +class FloatPlacement; class GuiBranches; class GuiIndices; class ModuleSelectionManager; diff --git a/src/frontends/qt4/GuiERT.cpp b/src/frontends/qt4/GuiERT.cpp index bc65101b6a..004290b1c9 100644 --- a/src/frontends/qt4/GuiERT.cpp +++ b/src/frontends/qt4/GuiERT.cpp @@ -14,6 +14,9 @@ #include "GuiERT.h" +#include "GuiApplication.h" +#include "GuiView.h" + #include "insets/InsetERT.h" #include "FuncRequest.h" @@ -28,20 +31,12 @@ using namespace std; namespace lyx { namespace frontend { -GuiERT::GuiERT(GuiView & lv) - : InsetDialog(lv, ERT_CODE, LFUN_INSET_INSERT, "ert", "TeX Code Settings") +GuiERT::GuiERT(QWidget * parent) : InsetParamsWidget(parent) { setupUi(this); - connect(collapsedRB, SIGNAL(clicked()), this, SLOT(applyView())); - connect(openRB, SIGNAL(clicked()), this, SLOT(applyView())); -} - - -void GuiERT::enableView(bool enable) -{ - collapsedRB->setEnabled(enable); - openRB->setEnabled(enable); + connect(collapsedRB, SIGNAL(clicked()), this, SIGNAL(changed())); + connect(openRB, SIGNAL(clicked()), this, SIGNAL(changed())); } @@ -56,17 +51,15 @@ docstring GuiERT::dialogToParams() const void GuiERT::paramsToDialog(Inset const * inset) { InsetERT const * ert = static_cast(inset); - InsetCollapsable::CollapseStatus status = ert->status(*bufferview()); + // FIXME: This dialog has absolutely no value... + BufferView const * bv = guiApp->currentView()->currentBufferView(); + InsetCollapsable::CollapseStatus status = ert->status(*bv); switch (status) { case InsetCollapsable::Open: openRB->setChecked(true); break; case InsetCollapsable::Collapsed: collapsedRB->setChecked(true); break; } } - -Dialog * createGuiERT(GuiView & lv) { return new GuiERT(lv); } - - } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/GuiERT.h b/src/frontends/qt4/GuiERT.h index b9b7cccc03..8177b01b8d 100644 --- a/src/frontends/qt4/GuiERT.h +++ b/src/frontends/qt4/GuiERT.h @@ -12,27 +12,24 @@ #ifndef GUIERT_H #define GUIERT_H -#include "InsetDialog.h" +#include "InsetParamsWidget.h" #include "ui_ERTUi.h" namespace lyx { namespace frontend { -class GuiERT : public InsetDialog, public Ui::ERTUi +class GuiERT : public InsetParamsWidget, public Ui::ERTUi { Q_OBJECT public: - GuiERT(GuiView & lv); + GuiERT(QWidget * parent = 0); private: - /// \name Dialog inerited methods - //@{ - void enableView(bool enable); - //@} - - /// \name InsetDialog inherited methods + /// \name InsetParamsWidget inherited methods //@{ + InsetCode insetCode() { return ERT_CODE; } + FuncCode creationCode() { return LFUN_INSET_INSERT; } void paramsToDialog(Inset const *); docstring dialogToParams() const; //@} diff --git a/src/frontends/qt4/GuiFloat.cpp b/src/frontends/qt4/GuiFloat.cpp deleted file mode 100644 index 832ed8396f..0000000000 --- a/src/frontends/qt4/GuiFloat.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/** - * \file GuiFloat.cpp - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Edwin Leuven - * - * Full author contact details are available in file CREDITS. - */ - -#include - -#include "GuiFloat.h" - -#include "FloatPlacement.h" - -#include "FuncRequest.h" - -#include - -using namespace std; - -namespace lyx { -namespace frontend { - -GuiFloat::GuiFloat(GuiView & lv) - : InsetDialog(lv, FLOAT_CODE, LFUN_FLOAT_INSERT, "float", "Float Settings") -{ - setupUi(this); - - // enable span columns checkbox - floatFP->useWide(); - // enable sideways checkbox - floatFP->useSideways(); - - connect(floatFP, SIGNAL(changed()), this, SLOT(applyView())); -} - - -void GuiFloat::enableView(bool enable) -{ - floatFP->setEnabled(enable); -} - - -void GuiFloat::paramsToDialog(Inset const * inset) -{ - floatFP->paramsToDialog(inset); -} - - -docstring GuiFloat::dialogToParams() const -{ - return floatFP->dialogToParams(); -} - -Dialog * createGuiFloat(GuiView & lv) { return new GuiFloat(lv); } - -} // namespace frontend -} // namespace lyx - -#include "moc_GuiFloat.cpp" diff --git a/src/frontends/qt4/GuiFloat.h b/src/frontends/qt4/GuiFloat.h deleted file mode 100644 index b98ddb0ae6..0000000000 --- a/src/frontends/qt4/GuiFloat.h +++ /dev/null @@ -1,46 +0,0 @@ -// -*- C++ -*- -/** - * \file GuiFloat.h - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Edwin Leuven - * - * Full author contact details are available in file CREDITS. - */ - -#ifndef GUIFLOAT_H -#define GUIFLOAT_H - -#include "InsetDialog.h" - -#include "ui_FloatUi.h" - - -namespace lyx { -namespace frontend { - -class GuiFloat : public InsetDialog, public Ui::FloatUi -{ - Q_OBJECT - -public: - GuiFloat(GuiView & lv); - -private: - /// \name Dialog inerited methods - //@{ - void enableView(bool enable); - //@} - - /// \name InsetDialog inherited methods - //@{ - void paramsToDialog(Inset const *); - docstring dialogToParams() const; - //@} -}; - -} // namespace frontend -} // namespace lyx - -#endif // GUIFLOAT_H diff --git a/src/frontends/qt4/GuiInfo.cpp b/src/frontends/qt4/GuiInfo.cpp index fa756303c3..db7efb5d65 100644 --- a/src/frontends/qt4/GuiInfo.cpp +++ b/src/frontends/qt4/GuiInfo.cpp @@ -47,8 +47,7 @@ char const * info_types_gui[] = N_("menu"), N_("icon"), N_("buffer"), ""}; -GuiInfo::GuiInfo(GuiView & lv) - : InsetDialog(lv, INFO_CODE, LFUN_INFO_INSERT, "info", "Info") +GuiInfo::GuiInfo(QWidget * parent) : InsetParamsWidget(parent) { setupUi(this); @@ -57,8 +56,8 @@ GuiInfo::GuiInfo(GuiView & lv) typeCO->addItem(qt_(info_types_gui[n])); typeCO->blockSignals(false); - connect(typeCO, SIGNAL(currentIndexChanged(int)), this, SLOT(applyView())); - connect(nameLE, SIGNAL(textChanged(QString)), this, SLOT(applyView())); + connect(typeCO, SIGNAL(currentIndexChanged(int)), this, SIGNAL(changed())); + connect(nameLE, SIGNAL(textChanged(QString)), this, SIGNAL(changed())); } @@ -91,17 +90,6 @@ docstring GuiInfo::dialogToParams() const } -void GuiInfo::enableView(bool enable) -{ - typeCO->setEnabled(enable); - nameLE->setEnabled(enable); - newPB->setEnabled(!enable); -} - - -Dialog * createGuiInfo(GuiView & lv) { return new GuiInfo(lv); } - - } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/GuiInfo.h b/src/frontends/qt4/GuiInfo.h index a25d61944d..5b8259ba7c 100644 --- a/src/frontends/qt4/GuiInfo.h +++ b/src/frontends/qt4/GuiInfo.h @@ -12,7 +12,7 @@ #ifndef GUI_INFO_H #define GUI_INFO_H -#include "InsetDialog.h" +#include "InsetParamsWidget.h" #include "ui_InfoUi.h" namespace lyx { @@ -21,21 +21,18 @@ class Inset; namespace frontend { -class GuiInfo : public InsetDialog, public Ui::InfoUi +class GuiInfo : public InsetParamsWidget, public Ui::InfoUi { Q_OBJECT public: - GuiInfo(GuiView & lv); - - /// \name Dialog inherited methods - //@{ - void enableView(bool enable); - //@} + GuiInfo(QWidget * parent = 0); private: - /// \name InsetDialog inherited methods + /// \name InsetParamsWidget inherited methods //@{ + InsetCode insetCode() { return INFO_CODE; } + FuncCode creationCode() { return LFUN_INFO_INSERT; } void paramsToDialog(Inset const *); docstring dialogToParams() const; //@} diff --git a/src/frontends/qt4/GuiVSpace.cpp b/src/frontends/qt4/GuiVSpace.cpp index 70d2ba7e6e..984464a9b8 100644 --- a/src/frontends/qt4/GuiVSpace.cpp +++ b/src/frontends/qt4/GuiVSpace.cpp @@ -21,8 +21,9 @@ #include "qt_helpers.h" #include "Validator.h" -#include "Spacing.h" #include "FuncRequest.h" +#include "Spacing.h" +#include "VSpace.h" #include "insets/InsetVSpace.h" @@ -39,48 +40,24 @@ using namespace std; namespace lyx { namespace frontend { -GuiVSpace::GuiVSpace(GuiView & lv) - : GuiDialog(lv, "vspace", qt_("Vertical Space Settings")) +GuiVSpace::GuiVSpace(QWidget * parent) : InsetParamsWidget(parent) { setupUi(this); - connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); - connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply())); - connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); - - connect(spacingCO, SIGNAL(highlighted(QString)), - this, SLOT(change_adaptor())); connect(valueLE, SIGNAL(textChanged(QString)), - this, SLOT(change_adaptor())); + this, SIGNAL(changed())); + connect(keepCB, SIGNAL(clicked()), + this, SIGNAL(changed())); + connect(unitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)), + this, SIGNAL(changed())); + connect(spacingCO, SIGNAL(activated(int)), this, SLOT(enableCustom(int))); - connect(keepCB, SIGNAL(clicked()), - this, SLOT(change_adaptor())); - connect(unitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)), - this, SLOT(change_adaptor())); valueLE->setValidator(unsignedGlueLengthValidator(valueLE)); - // Manage the ok, apply, restore and cancel/close buttons - bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy); - bc().setOK(okPB); - bc().setApply(applyPB); - bc().setCancel(closePB); - - // disable for read-only documents - bc().addReadOnly(spacingCO); - bc().addReadOnly(valueLE); - bc().addReadOnly(unitCO); - bc().addReadOnly(keepCB); - // initialize the length validator - bc().addCheckedLineEdit(valueLE, valueL); -} - - -void GuiVSpace::change_adaptor() -{ - changed(); + addCheckedWidget(valueLE, valueL); } @@ -144,47 +121,26 @@ static VSpace setVSpaceFromWidgets(int spacing, } -void GuiVSpace::applyView() +docstring GuiVSpace::dialogToParams() const { // If a vspace choice is "Length" but there's no text in // the input field, do not insert a vspace at all. if (spacingCO->currentIndex() == 5 && valueLE->text().isEmpty()) - return; + return docstring(); - params_ = setVSpaceFromWidgets(spacingCO->currentIndex(), - valueLE, unitCO, keepCB->isChecked()); + VSpace const params = setVSpaceFromWidgets(spacingCO->currentIndex(), + valueLE, unitCO, keepCB->isChecked()); + return from_ascii(InsetVSpace::params2string(params)); } -void GuiVSpace::updateContents() +void GuiVSpace::paramsToDialog(Inset const * inset) { - setWidgetsFromVSpace(params_, spacingCO, valueLE, unitCO, keepCB); + InsetVSpace const * vs = static_cast(inset); + VSpace const & params = vs->space(); + setWidgetsFromVSpace(params, spacingCO, valueLE, unitCO, keepCB); } - -bool GuiVSpace::initialiseParams(string const & data) -{ - InsetVSpace::string2params(data, params_); - setButtonsValid(true); - return true; -} - - -void GuiVSpace::clearParams() -{ - params_ = VSpace(); -} - - -void GuiVSpace::dispatchParams() -{ - dispatch(FuncRequest(getLfun(), InsetVSpace::params2string(params_))); -} - - -Dialog * createGuiVSpace(GuiView & lv) { return new GuiVSpace(lv); } - - } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/GuiVSpace.h b/src/frontends/qt4/GuiVSpace.h index 93a6319fe9..1c28142ffa 100644 --- a/src/frontends/qt4/GuiVSpace.h +++ b/src/frontends/qt4/GuiVSpace.h @@ -15,42 +15,31 @@ #ifndef GUIVSPACE_H #define GUIVSPACE_H -#include "GuiDialog.h" +#include "InsetParamsWidget.h" #include "ui_VSpaceUi.h" -#include "VSpace.h" namespace lyx { namespace frontend { -class GuiVSpace : public GuiDialog, public Ui::VSpaceUi +class GuiVSpace : public InsetParamsWidget, public Ui::VSpaceUi { Q_OBJECT public: - GuiVSpace(GuiView & lv); + GuiVSpace(QWidget * parent = 0); private Q_SLOTS: - /// - void change_adaptor(); /// void enableCustom(int); private: - /// Apply from dialog - void applyView(); - /// Update the dialog - void updateContents(); - /// - bool initialiseParams(std::string const & data); - /// clean-up on hide. - void clearParams(); - /// clean-up on hide. - void dispatchParams(); - /// - bool isBufferDependent() const { return true; } - - /// - VSpace params_; + /// \name DialogView inherited methods + //@{ + InsetCode insetCode() { return VSPACE_CODE; } + FuncCode creationCode() { return LFUN_INSET_INSERT; } + void paramsToDialog(Inset const *); + docstring dialogToParams() const; + //@} }; } // namespace frontend diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index eeb8b47aa8..c5f51c5b23 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -3437,12 +3437,12 @@ void GuiView::updateDialogs() updateLayoutList(); } +Dialog * createDialog(GuiView & lv, string const & name); // will be replaced by a proper factory... Dialog * createGuiAbout(GuiView & lv); Dialog * createGuiBibitem(GuiView & lv); Dialog * createGuiBibtex(GuiView & lv); -Dialog * createGuiBox(GuiView & lv); Dialog * createGuiBranch(GuiView & lv); Dialog * createGuiChanges(GuiView & lv); Dialog * createGuiCharacter(GuiView & lv); @@ -3451,13 +3451,10 @@ Dialog * createGuiCompare(GuiView & lv); Dialog * createGuiDelimiter(GuiView & lv); Dialog * createGuiDocument(GuiView & lv); Dialog * createGuiErrorList(GuiView & lv); -Dialog * createGuiERT(GuiView & lv); Dialog * createGuiExternal(GuiView & lv); -Dialog * createGuiFloat(GuiView & lv); Dialog * createGuiGraphics(GuiView & lv); Dialog * createGuiInclude(GuiView & lv); Dialog * createGuiIndex(GuiView & lv); -Dialog * createGuiInfo(GuiView & lv); Dialog * createGuiLabel(GuiView & lv); Dialog * createGuiListings(GuiView & lv); Dialog * createGuiLog(GuiView & lv); @@ -3485,7 +3482,6 @@ Dialog * createGuiTextHSpace(GuiView & lv); Dialog * createGuiToc(GuiView & lv); Dialog * createGuiThesaurus(GuiView & lv); Dialog * createGuiHyperlink(GuiView & lv); -Dialog * createGuiVSpace(GuiView & lv); Dialog * createGuiViewSource(GuiView & lv); Dialog * createGuiWrap(GuiView & lv); Dialog * createGuiProgressView(GuiView & lv); @@ -3496,14 +3492,16 @@ Dialog * GuiView::build(string const & name) { LASSERT(isValidName(name), return 0); + Dialog * dialog = createDialog(*this, name); + if (dialog) + return dialog; + if (name == "aboutlyx") return createGuiAbout(*this); if (name == "bibitem") return createGuiBibitem(*this); if (name == "bibtex") return createGuiBibtex(*this); - if (name == "box") - return createGuiBox(*this); if (name == "branch") return createGuiBranch(*this); if (name == "changes") @@ -3518,8 +3516,6 @@ Dialog * GuiView::build(string const & name) return createGuiDocument(*this); if (name == "errorlist") return createGuiErrorList(*this); - if (name == "ert") - return createGuiERT(*this); if (name == "external") return createGuiExternal(*this); if (name == "file") @@ -3528,8 +3524,6 @@ Dialog * GuiView::build(string const & name) return createGuiSearch(*this); if (name == "findreplaceadv") return createGuiSearchAdv(*this); - if (name == "float") - return createGuiFloat(*this); if (name == "graphics") return createGuiGraphics(*this); if (name == "href") @@ -3540,8 +3534,6 @@ Dialog * GuiView::build(string const & name) return createGuiIndex(*this); if (name == "index_print") return createGuiPrintindex(*this); - if (name == "info") - return createGuiInfo(*this); if (name == "label") return createGuiLabel(*this); if (name == "listings") @@ -3590,8 +3582,6 @@ Dialog * GuiView::build(string const & name) return createGuiToc(*this); if (name == "view-source") return createGuiViewSource(*this); - if (name == "vspace") - return createGuiVSpace(*this); if (name == "wrap") return createGuiWrap(*this); if (name == "progress") diff --git a/src/frontends/qt4/InsetDialog.cpp b/src/frontends/qt4/InsetDialog.cpp deleted file mode 100644 index ce2056a373..0000000000 --- a/src/frontends/qt4/InsetDialog.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/** - * \file InsetDialog.cpp - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Abdelrazak Younes - * - * Full author contact details are available in file CREDITS. - */ - -#include - -#include "InsetDialog.h" - -#include "qt_helpers.h" - -#include "Buffer.h" -#include "buffer_funcs.h" -#include "BufferParams.h" -#include "BufferView.h" -#include "Cursor.h" -#include "FuncRequest.h" - -#include "support/debug.h" -#include "support/lstrings.h" - -using namespace std; -using namespace lyx::support; - -namespace lyx { -namespace frontend { - -///////////////////////////////////////////////////////////////// -// -// InsetDialog::Private -// -///////////////////////////////////////////////////////////////// - -struct InsetDialog::Private -{ - Private(InsetCode code, FuncCode creation_code) - : inset_code_(code), creation_code_(creation_code) - { - } - - /// - InsetCode inset_code_; - /// - FuncCode creation_code_; -}; - -///////////////////////////////////////////////////////////////// -// -// InsetDialog -// -///////////////////////////////////////////////////////////////// - -InsetDialog::InsetDialog(GuiView & lv, InsetCode code, FuncCode creation_code, - char const * name, char const * display_name) - : DialogView(lv, name, qt_(display_name)), d(new Private(code, creation_code)) -{ -} - - -void InsetDialog::on_closePB_clicked() -{ - hide(); -} - - -void InsetDialog::on_newPB_clicked() -{ - docstring const argument = dialogToParams(); - dispatch(FuncRequest(d->creation_code_, argument)); -} - - -void InsetDialog::applyView() -{ - if (!checkWidgets()) - return; - - Inset const * i = inset(d->inset_code_); - if (!i) - return; - - docstring const argument = dialogToParams(); - if (!i->validateModifyArgument(argument)) - return; - - dispatch(FuncRequest(LFUN_INSET_MODIFY, argument)); -} - - -void InsetDialog::updateView() -{ - Inset const * i = inset(d->inset_code_); - if (i) - paramsToDialog(i); - else - enableView(false); - - //FIXME: the newPB push button cannot be accessed here and so cannot be - // disabled... - /* - docstring const argument = dialogToParams(); - newPB->setEnabled( - getStatus(FuncRequest(LFUN_INSET_MODIFY, argument).enabled()); - */ -} - -} // namespace frontend -} // namespace lyx - -#include "moc_InsetDialog.cpp" diff --git a/src/frontends/qt4/InsetParamsDialog.cpp b/src/frontends/qt4/InsetParamsDialog.cpp new file mode 100644 index 0000000000..0448d26c26 --- /dev/null +++ b/src/frontends/qt4/InsetParamsDialog.cpp @@ -0,0 +1,200 @@ +/** + * \file InsetParamsDialog.cpp + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Abdelrazak Younes + * + * Full author contact details are available in file CREDITS. + */ + +#include + +#include "InsetParamsDialog.h" + +#include "GuiBox.h" +#include "GuiERT.h" +#include "GuiInfo.h" +#include "GuiVSpace.h" +#include "FloatPlacement.h" + +#include "InsetParamsWidget.h" +#include "qt_helpers.h" + +#include "Buffer.h" +#include "buffer_funcs.h" +#include "BufferParams.h" +#include "BufferView.h" +#include "Cursor.h" +#include "FuncRequest.h" +#include "FuncStatus.h" +#include "LyX.h" + +#include "support/debug.h" +#include "support/lstrings.h" + +using namespace std; +using namespace lyx::support; + +namespace lyx { +namespace frontend { + +///////////////////////////////////////////////////////////////// +// +// InsetParamsDialog::Private +// +///////////////////////////////////////////////////////////////// + +struct InsetParamsDialog::Private +{ + /// + InsetParamsWidget * widget_; +}; + +///////////////////////////////////////////////////////////////// +// +// InsetParamsDialog +// +///////////////////////////////////////////////////////////////// + +InsetParamsDialog::InsetParamsDialog(GuiView & lv, InsetParamsWidget * widget) + : DialogView(lv, toqstr(insetName(widget->insetCode())), + toqstr(insetName(widget->insetCode()))), d(new Private) +{ + setupUi(this); + setInsetParamsWidget(widget); + synchronizedViewCB->setChecked(false); + on_synchronizedViewCB_stateChanged(false); +} + +InsetParamsDialog::~InsetParamsDialog() +{ + delete d; +} + + +void InsetParamsDialog::setInsetParamsWidget(InsetParamsWidget * widget) +{ + d->widget_ = widget; + stackedWidget->addWidget(widget); + stackedWidget->setCurrentWidget(widget); +} + + +void InsetParamsDialog::on_restorePB_clicked() +{ + updateView(); +} + + +void InsetParamsDialog::on_okPB_clicked() +{ + applyView(); + hide(); +} + + +void InsetParamsDialog::on_applyPB_clicked() +{ + if (synchronizedViewCB->isChecked()) { + docstring const argument = d->widget_->dialogToParams(); + dispatch(FuncRequest(d->widget_->creationCode(), argument)); + } else { + applyView(); + } +} + + +void InsetParamsDialog::on_closePB_clicked() +{ + hide(); +} + + +void InsetParamsDialog::on_synchronizedViewCB_stateChanged(int state) +{ + bool const sync = (state == Qt::Checked); + QString const label = sync ? qt_("&New") : qt_("&Apply"); + applyPB->setText(label); + okPB->setEnabled(!sync); + restorePB->setEnabled(!sync); + if (sync) + connect(d->widget_, SIGNAL(changed()), this, SLOT(applyView())); + else + QObject::disconnect(d->widget_, SIGNAL(changed()), this, SLOT(applyView())); +} + + +void InsetParamsDialog::applyView() +{ + if (!d->widget_->checkWidgets()) + return; + + Inset const * i = inset(d->widget_->insetCode()); + if (!i) + return; + + docstring const argument = d->widget_->dialogToParams(); + + if (argument.empty() || !i->validateModifyArgument(argument)) { + //FIXME: newPB is not accessible + //newPB->setEnabled(false); + return; + } + //FIXME: newPB is not accessible + //newPB->setEnabled(true); + dispatch(FuncRequest(LFUN_INSET_MODIFY, argument)); +} + + +void InsetParamsDialog::updateView() +{ + Inset const * i = inset(d->widget_->insetCode()); + if (i) + d->widget_->paramsToDialog(i); + else + d->widget_->setEnabled(false); + + docstring const argument = d->widget_->dialogToParams(); + FuncCode const code = synchronizedViewCB->isChecked() + ? d->widget_->creationCode() : LFUN_INSET_MODIFY; + applyPB->setEnabled( + lyx::getStatus(FuncRequest(code, argument)).enabled()); +} + + +Dialog * createDialog(GuiView & lv, InsetCode code) +{ + InsetParamsWidget * widget; + switch (code) { + case ERT_CODE: + widget = new GuiERT; + break; + case FLOAT_CODE: + widget = new FloatPlacement(true); + break; + case BOX_CODE: + widget = new GuiBox; + break; + case INFO_CODE: + widget = new GuiInfo; + break; + case VSPACE_CODE: + widget = new GuiVSpace; + break; + default: return 0; + } + InsetParamsDialog * dialog = new InsetParamsDialog(lv, widget); + return dialog; +} + + +Dialog * createDialog(GuiView & lv, string const & name) +{ + return createDialog(lv, insetCode(name)); +} + +} // namespace frontend +} // namespace lyx + +#include "moc_InsetParamsDialog.cpp" diff --git a/src/frontends/qt4/InsetDialog.h b/src/frontends/qt4/InsetParamsDialog.h similarity index 54% rename from src/frontends/qt4/InsetDialog.h rename to src/frontends/qt4/InsetParamsDialog.h index 7a38f2521e..d0d5e55201 100644 --- a/src/frontends/qt4/InsetDialog.h +++ b/src/frontends/qt4/InsetParamsDialog.h @@ -1,6 +1,6 @@ // -*- C++ -*- /** - * \file InsetDialog.h + * \file InsetParamsDialog.h * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * @@ -9,10 +9,11 @@ * Full author contact details are available in file CREDITS. */ -#ifndef INSET_DIALOG_H -#define INSET_DIALOG_H +#ifndef INSET_PARAMS_DIALOG_H +#define INSET_PARAMS_DIALOG_H #include "DialogView.h" +#include "ui_InsetParamsUi.h" #include "qt_i18n.h" @@ -22,15 +23,27 @@ class Inset; namespace frontend { +class InsetParamsWidget; -class InsetDialog : public DialogView +class InsetParamsDialog : public DialogView, public Ui::InsetParamsUi { Q_OBJECT - public: - InsetDialog(GuiView & lv, InsetCode code, FuncCode creation_code, - char const * name, char const * display_name); + InsetParamsDialog(GuiView & lv, InsetParamsWidget * widget); + ~InsetParamsDialog(); + /// + void setInsetParamsWidget(InsetParamsWidget * widget); + +protected Q_SLOTS: + void applyView(); + void on_restorePB_clicked(); + void on_okPB_clicked(); + void on_applyPB_clicked(); + void on_closePB_clicked(); + void on_synchronizedViewCB_stateChanged(int state); + +private: /// \name DialogView inherited methods //@{ void updateView(); @@ -38,19 +51,6 @@ public: bool isBufferDependent() const { return true; } bool canApply() const { return true; } //@} - -protected Q_SLOTS: - void applyView(); - void on_newPB_clicked(); - void on_closePB_clicked(); - -protected: - /// - virtual void paramsToDialog(Inset const *) = 0; - /// - virtual docstring dialogToParams() const = 0; - -private: /// pimpl struct Private; Private * d; @@ -59,4 +59,4 @@ private: } // namespace frontend } // namespace lyx -#endif // INSET_DIALOG_H +#endif // INSET_PARAMS_DIALOG_H diff --git a/src/frontends/qt4/InsetParamsWidget.cpp b/src/frontends/qt4/InsetParamsWidget.cpp new file mode 100644 index 0000000000..5eae61c9ca --- /dev/null +++ b/src/frontends/qt4/InsetParamsWidget.cpp @@ -0,0 +1,64 @@ +// -*- C++ -*- +/** + * \file InsetParamsWidget.cpp + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Abdelrazak Younes + * + * Full author contact details are available in file CREDITS. + */ + +#include + +#include "InsetParamsWidget.h" + +#include "qt_helpers.h" + +#include + +namespace lyx { + +namespace frontend { + +CheckedWidget::CheckedWidget(QLineEdit * input, QWidget * label) + : input_(input), label_(label) +{ +} + + +bool CheckedWidget::check() const +{ + bool const valid = input_->hasAcceptableInput(); + // Visual feedback. + setValid(input_, valid); + if (label_) + setValid(label_, valid); + return valid; +} + + + +InsetParamsWidget::InsetParamsWidget(QWidget * parent) : QWidget(parent) +{ +} + + +void InsetParamsWidget::addCheckedWidget(QLineEdit * input, QWidget * label) +{ + checked_widgets_.append(CheckedWidget(input, label)); +} + + +bool InsetParamsWidget::checkWidgets() const +{ + bool valid = true; + Q_FOREACH(CheckedWidget const & le, checked_widgets_) + valid &= le.check(); + return valid; +} + +} // namespace frontend +} // namespace lyx + +#include "moc_InsetParamsWidget.cpp" diff --git a/src/frontends/qt4/InsetParamsWidget.h b/src/frontends/qt4/InsetParamsWidget.h new file mode 100644 index 0000000000..0e989c7e3f --- /dev/null +++ b/src/frontends/qt4/InsetParamsWidget.h @@ -0,0 +1,84 @@ +// -*- C++ -*- +/** + * \file InsetParamsWidget.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Abdelrazak Younes + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef INSET_PARAMS_WIDGET_H +#define INSET_PARAMS_WIDGET_H + +#include "insets/InsetCode.h" + +#include "FuncCode.h" + +#include "support/strfwd.h" + +#include + +class QLineEdit; + +namespace lyx { + +class Inset; + +namespace frontend { + +/// CheckedWidget +// FIXME: Get rid of CheckedLineEdit in ButtonController and rename this one +// to it. +class CheckedWidget +{ +public: + CheckedWidget(QLineEdit * input, QWidget * label = 0); + /// + bool check() const; + +private: + // non-owned + QLineEdit * input_; + QWidget * label_; +}; + + +typedef QList CheckedWidgets; + +class InsetParamsWidget : public QWidget +{ + Q_OBJECT + +Q_SIGNALS: + void changed(); +public: + InsetParamsWidget(QWidget * parent); + /// This is a base class; destructor must exist and be virtual. + virtual ~InsetParamsWidget() {} + /// + virtual InsetCode insetCode() = 0; + /// + virtual FuncCode creationCode() = 0; + /// + virtual void paramsToDialog(Inset const *) = 0; + /// + virtual docstring dialogToParams() const = 0; + + /// \return true if all CheckedWidgets are in a valid state. + bool checkWidgets() const; + +protected: + /// Add a widget to the list of all widgets whose validity should + /// be checked explicitly when the buttons are refreshed. + void addCheckedWidget(QLineEdit * input, QWidget * label = 0); +private: + /// + CheckedWidgets checked_widgets_; +}; + +} // namespace frontend +} // namespace lyx + +#endif // INSET_PARAMS_WIDGET_H diff --git a/src/frontends/qt4/Makefile.am b/src/frontends/qt4/Makefile.am index 936bc2d827..8b8a40b6d0 100644 --- a/src/frontends/qt4/Makefile.am +++ b/src/frontends/qt4/Makefile.am @@ -132,7 +132,8 @@ SOURCEFILES = \ GuiWrap.cpp \ IconPalette.cpp \ InsertTableWidget.cpp \ - InsetDialog.cpp \ + InsetParamsDialog.cpp \ + InsetParamsWidget.cpp \ LengthCombo.cpp \ LyXFileDialog.cpp \ LaTeXHighlighter.cpp \ @@ -235,7 +236,8 @@ MOCHEADER = \ GuiWrap.h \ IconPalette.h \ InsertTableWidget.h \ - InsetDialog.h \ + InsetParamsDialog.h \ + InsetParamsWidget.h \ LayoutBox.h \ LengthCombo.h \ LyXFileDialog.h \ @@ -267,7 +269,6 @@ UIFILES = \ ExternalUi.ui \ FindAndReplaceUi.ui \ FloatPlacementUi.ui \ - FloatUi.ui \ FontUi.ui \ GraphicsUi.ui \ HSpaceUi.ui \ @@ -276,6 +277,7 @@ UIFILES = \ IndexUi.ui \ IndicesUi.ui \ InfoUi.ui \ + InsetParamsUi.ui \ LabelUi.ui \ LanguageUi.ui \ LaTeXUi.ui \ diff --git a/src/frontends/qt4/ui/BoxUi.ui b/src/frontends/qt4/ui/BoxUi.ui index b36638c70e..2d786eee67 100644 --- a/src/frontends/qt4/ui/BoxUi.ui +++ b/src/frontends/qt4/ui/BoxUi.ui @@ -1,18 +1,19 @@ + BoxUi - + 0 0 - 356 - 288 + 261 + 245 - + true @@ -181,61 +182,6 @@ - - - - 6 - - - 0 - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 20 - 20 - - - - - - - - - - - &New - - - false - - - false - - - - - - - &Close - - - false - - - false - - - - - @@ -367,8 +313,6 @@ ialignCO halignCO valignCO - closePB - newPB qt_i18n.h diff --git a/src/frontends/qt4/ui/ERTUi.ui b/src/frontends/qt4/ui/ERTUi.ui index 671d40f0e0..648d155d04 100644 --- a/src/frontends/qt4/ui/ERTUi.ui +++ b/src/frontends/qt4/ui/ERTUi.ui @@ -1,18 +1,19 @@ + ERTUi - + 0 0 - 197 - 135 + 175 + 99 - + true @@ -57,58 +58,6 @@ - - - - 6 - - - 0 - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 20 - 20 - - - - - - - - - - - &New - - - false - - - false - - - - - - - Close - - - true - - - - - diff --git a/src/frontends/qt4/ui/FloatUi.ui b/src/frontends/qt4/ui/FloatUi.ui deleted file mode 100644 index bfddc8fcd5..0000000000 --- a/src/frontends/qt4/ui/FloatUi.ui +++ /dev/null @@ -1,95 +0,0 @@ - - FloatUi - - - - 0 - 0 - 410 - 336 - - - - - - - true - - - - 6 - - - 11 - - - - - - - - 6 - - - 0 - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 20 - 20 - - - - - - - - - - - &New - - - false - - - false - - - - - - - &Close - - - - - - - - - - lyx::FloatPlacement - -
FloatPlacement.h
- 1 -
-
- - closePB - - - qt_i18n.h - - - -
diff --git a/src/frontends/qt4/ui/InfoUi.ui b/src/frontends/qt4/ui/InfoUi.ui index 13aa181e13..7d30fb75e6 100644 --- a/src/frontends/qt4/ui/InfoUi.ui +++ b/src/frontends/qt4/ui/InfoUi.ui @@ -1,86 +1,50 @@ - + + InfoUi - - + + 0 0 320 - 131 + 75 - + - + true - + - - - - + + + + Information Type: - - + + - - - + + + Information Name: - - - - - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 84 - 20 - - - - - - - - &New - - - - - - - &Close - - - true - - + + - qt_i18n.h + qt_i18n.h diff --git a/src/frontends/qt4/ui/InsetParamsUi.ui b/src/frontends/qt4/ui/InsetParamsUi.ui new file mode 100644 index 0000000000..57e0fd77b5 --- /dev/null +++ b/src/frontends/qt4/ui/InsetParamsUi.ui @@ -0,0 +1,148 @@ + + + InsetParamsUi + + + + 0 + 0 + 438 + 292 + + + + Qt::NoFocus + + + Inset Parameter Configuration + + + + 9 + + + 6 + + + + + Qt::Horizontal + + + + 281 + 31 + + + + + + + + Qt::LeftToRight + + + I&mmediate Apply + + + + + + + 6 + + + 0 + + + + + &Restore + + + false + + + + + + + Qt::Horizontal + + + + 31 + 27 + + + + + + + + &OK + + + true + + + + + + + &Apply + + + false + + + + + + + &Close + + + false + + + + + + + + + Qt::Vertical + + + + 351 + 16 + + + + + + + + 1 + + + + + + + + + synchronizedViewCB + restorePB + okPB + applyPB + closePB + + + qt_i18n.h + + + + diff --git a/src/frontends/qt4/ui/VSpaceUi.ui b/src/frontends/qt4/ui/VSpaceUi.ui index 3cf902ed90..083dc170da 100644 --- a/src/frontends/qt4/ui/VSpaceUi.ui +++ b/src/frontends/qt4/ui/VSpaceUi.ui @@ -1,146 +1,110 @@ - + + VSpaceUi - - + + 0 0 - 259 - 120 + 215 + 96 - + - + true - - - - - - - &OK - - - false - - - true - - - - - - - &Apply - - - false - - - - - - - &Close - - - false - - - - - - - - + + + + &Spacing: - + spacingCO - - - + + + Insert the spacing even after a page break - + - - - + + + - + &Protect: - + keepCB - - + + - - - + + + false - - Custom value. Needs spacing type "Custom". + + Custom value. Needs spacing type "Custom". - - - + + + &Value: - + valueLE - - - + + + Supported spacing types - + DefSkip - + SmallSkip - + MedSkip - + BigSkip - + VFill - + Custom @@ -160,12 +124,9 @@ valueLE unitCO keepCB - okPB - applyPB - closePB - qt_i18n.h + qt_i18n.h