From 2e1abd05a7912b7ce198f7efb896da72a883040e Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Spitzm=C3=BCller?= Date: Sat, 29 Nov 2003 09:39:35 +0000 Subject: [PATCH] QVSpace dialog git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8154 a592a061-630c-0410-9148-cb99ea01b6c8 --- po/POTFILES.in | 3 + src/frontends/qt2/ChangeLog | 9 + src/frontends/qt2/Dialogs.C | 8 +- src/frontends/qt2/Makefile.am | 1 + src/frontends/qt2/Makefile.dialogs | 2 + src/frontends/qt2/QVSpace.C | 233 +++++++++++++ src/frontends/qt2/QVSpace.h | 45 +++ src/frontends/qt2/QVSpaceDialog.C | 58 ++++ src/frontends/qt2/QVSpaceDialog.h | 38 +++ src/frontends/qt2/ui/QVSpaceDialogBase.ui | 391 ++++++++++++++++++++++ 10 files changed, 787 insertions(+), 1 deletion(-) create mode 100644 src/frontends/qt2/QVSpace.C create mode 100644 src/frontends/qt2/QVSpace.h create mode 100644 src/frontends/qt2/QVSpaceDialog.C create mode 100644 src/frontends/qt2/QVSpaceDialog.h create mode 100644 src/frontends/qt2/ui/QVSpaceDialogBase.ui diff --git a/po/POTFILES.in b/po/POTFILES.in index 80f0c11025..7565d6aee5 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -86,6 +86,7 @@ src/frontends/qt2/QThesaurus.C src/frontends/qt2/QToc.C src/frontends/qt2/QURL.C src/frontends/qt2/QVCLog.C +src/frontends/qt2/QVSpace.C src/frontends/qt2/QWrap.C src/frontends/qt2/Qt2BC.h src/frontends/qt2/QtView.C @@ -106,6 +107,7 @@ src/frontends/xforms/FormCitation.C src/frontends/xforms/FormColorpicker.C src/frontends/xforms/FormDialogView.C src/frontends/xforms/FormDocument.C +src/frontends/xforms/FormDocumentNew.C src/frontends/xforms/FormERT.C src/frontends/xforms/FormErrorList.C src/frontends/xforms/FormExternal.C @@ -201,6 +203,7 @@ src/output_plaintext.C src/paragraph.C src/paragraph_funcs.C src/rowpainter.C +src/support/path_defines.C src/text.C src/text2.C src/text3.C diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index a06944abbd..06fbfc59c9 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,12 @@ +2003-11-29 Juergen Spitzmueller + + * QVSpace.[Ch]: (new) + * QVSpaceDialog.[Ch]: (new) + * ui/QVSpaceDialogBase.ui: (new) + * Makefile.am: + * Makefile.dialogs: + * Dialogs.C: new VSpace dialog. + 2003-11-24 Alfredo Braunstein * QContentpane.[Ch] (trackScrollbar): add diff --git a/src/frontends/qt2/Dialogs.C b/src/frontends/qt2/Dialogs.C index d44e9ee538..72d8d9dce5 100644 --- a/src/frontends/qt2/Dialogs.C +++ b/src/frontends/qt2/Dialogs.C @@ -35,6 +35,7 @@ #include "ControlTabularCreate.h" #include "ControlToc.h" #include "ControlVCLog.h" +#include "ControlVSpace.h" #include "ControlWrap.h" #include "Qt2BC.h" @@ -70,6 +71,7 @@ #include "QToc.h" #include "QURL.h" #include "QVCLog.h" +#include "QVSpace.h" #include "QWrap.h" #ifdef HAVE_LIBAIKSAURUS @@ -94,7 +96,7 @@ char const * const dialognames[] = { "aboutlyx", "bibitem", "bibtex", "branch", "thesaurus", #endif -"toc", "url", "vclog", "wrap" }; +"toc", "url", "vclog", "vspace", "wrap" }; char const * const * const end_dialognames = dialognames + (sizeof(dialognames) / sizeof(char *)); @@ -257,6 +259,10 @@ Dialog * Dialogs::build(string const & name) dialog->setController(new ControlVCLog(*dialog)); dialog->setView(new QVCLog(*dialog)); dialog->bc().bp(new OkCancelPolicy); + } else if (name == "vspace") { + dialog->setController(new ControlVSpace(*dialog)); + dialog->setView(new QVSpace(*dialog)); + dialog->bc().bp(new OkApplyCancelReadOnlyPolicy); } else if (name == "wrap") { dialog->setController(new ControlWrap(*dialog)); dialog->setView(new QWrap(*dialog)); diff --git a/src/frontends/qt2/Makefile.am b/src/frontends/qt2/Makefile.am index 09c8d11eab..2284d7e5e4 100644 --- a/src/frontends/qt2/Makefile.am +++ b/src/frontends/qt2/Makefile.am @@ -64,6 +64,7 @@ libqt2_la_SOURCES = \ QToc.C QToc.h \ QURL.C QURL.h \ QVCLog.C QVCLog.h \ + QVSpace.C QVSpace.h \ QWorkArea.h QWorkArea.C \ QWrap.C QWrap.h \ Qt2BC.C Qt2BC.h \ diff --git a/src/frontends/qt2/Makefile.dialogs b/src/frontends/qt2/Makefile.dialogs index f50b486b71..06bc5415cd 100644 --- a/src/frontends/qt2/Makefile.dialogs +++ b/src/frontends/qt2/Makefile.dialogs @@ -66,6 +66,7 @@ UIFILES = \ QTocDialogBase.ui \ QURLDialogBase.ui \ QVCLogDialogBase.ui \ + QVSpaceDialogBase.ui \ QWrapDialogBase.ui MOCFILES = \ @@ -124,6 +125,7 @@ MOCFILES = \ QtView.C QtView.h \ QURLDialog.C QURLDialog.h \ QVCLogDialog.C QVCLogDialog.h \ + QVSpaceDialog.C QVSpaceDialog.h \ QWrapDialog.C QWrapDialog.h \ QLToolbar.C QLToolbar.h \ socket_callback.C socket_callback.h diff --git a/src/frontends/qt2/QVSpace.C b/src/frontends/qt2/QVSpace.C new file mode 100644 index 0000000000..32aa3a4ebc --- /dev/null +++ b/src/frontends/qt2/QVSpace.C @@ -0,0 +1,233 @@ +/** + * \file QVSpace.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author André Pönitz + * \author Jürgen Vigna + * \author Rob Lahaye + * \author Angus Leeming + * \author Edwin Leuven + * \author Jürgen Spitzmüller + * + * Full author contact details are available in file CREDITS. + */ + +#include + +#include "debug.h" +#include "ControlVSpace.h" +#include "QVSpace.h" +#include "QVSpaceDialog.h" +#include "Qt2BC.h" +#include "lyxrc.h" // to set the deafult length values +#include "qt_helpers.h" +#include "helper_funcs.h" + +#include "Spacing.h" +#include "vspace.h" + +#include "support/lstrings.h" +#include "support/tostr.h" + +#include +#include +#include +#include + +using lyx::support::contains_functor; +using lyx::support::isStrDbl; +using lyx::support::subst; +using lyx::support::trim; + +using std::bind2nd; +using std::remove_if; + +using std::vector; +using std::string; + + +namespace { + +void setWidgetsFromVSpace(VSpace const & space, + QComboBox * spacing, + QLineEdit * value, + QComboBox * unit, + QCheckBox * keep, vector units_) +{ + value->setText(""); + value->setEnabled(false); + unit->setEnabled(false); + + int item = 0; + switch (space.kind()) { + case VSpace::NONE: + item = 0; + break; + case VSpace::DEFSKIP: + item = 1; + break; + case VSpace::SMALLSKIP: + item = 2; + break; + case VSpace::MEDSKIP: + item = 3; + break; + case VSpace::BIGSKIP: + item = 4; + break; + case VSpace::VFILL: + item = 5; + break; + case VSpace::LENGTH: + item = 6; + value->setEnabled(true); + unit->setEnabled(true); + string length = space.length().asString(); + string const default_unit = + (lyxrc.default_papersize > 3) ? "cm" : "in"; + string supplied_unit = default_unit; + LyXLength len(length); + if ((isValidLength(length) + || isStrDbl(length)) && !len.zero()) { + length = tostr(len.value()); + supplied_unit = subst(stringFromUnit(len.unit()), + "%", "%%"); + } + + int unit_item = 0; + int i = 0; + for (vector::const_iterator it = units_.begin(); + it != units_.end(); ++it) { + if (*it == default_unit) { + unit_item = i; + } + if (*it == supplied_unit) { + unit_item = i; + break; + } + i += 1; + } + value->setText(toqstr(length)); + unit->setCurrentItem(unit_item); + break; + } + spacing->setCurrentItem(item); + keep->setChecked(space.keep()); +} + + +VSpace setVSpaceFromWidgets(int spacing, + string value, + string unit, + bool keep) +{ + VSpace space; + + switch (spacing) { + case 0: + space = VSpace(VSpace::NONE); + break; + case 1: + space = VSpace(VSpace::DEFSKIP); + break; + case 2: + space = VSpace(VSpace::SMALLSKIP); + break; + case 3: + space = VSpace(VSpace::MEDSKIP); + break; + case 4: + space = VSpace(VSpace::BIGSKIP); + break; + case 5: + space = VSpace(VSpace::VFILL); + break; + case 6: + string s; + string const length = trim(value); + if (isValidGlueLength(length)) { + s = length; + } else if (!length.empty()){ + string u = trim(unit); + u = subst(u, "%%", "%"); + s = length + u; + } + space = VSpace(LyXGlueLength(s)); + break; + } + + space.setKeep(keep); + + return space; +} + +} // namespace anon + + +typedef QController > base_class; + +QVSpace::QVSpace(Dialog & parent) + : base_class(parent, _("LyX: VSpace Settings")) +{} + + +void QVSpace::build_dialog() +{ + // the tabbed folder + dialog_.reset(new QVSpaceDialog(this)); + + // Create the contents of the unit choices + // Don't include the "%" terms... + units_ = getLatexUnits(); + vector::iterator del = + remove_if(units_.begin(), units_.end(), + bind2nd(contains_functor(), "%")); + units_.erase(del, units_.end()); + + for (vector::const_iterator it = units_.begin(); + it != units_.end(); ++it) { + dialog_->unitCO->insertItem(toqstr(*it)); + } + + // Manage the ok, apply, restore and cancel/close buttons + bcview().setOK(dialog_->okPB); + bcview().setApply(dialog_->applyPB); + bcview().setCancel(dialog_->closePB); + bcview().setRestore(dialog_->restorePB); + + // disable for read-only documents + bcview().addReadOnly(dialog_->spacingCO); + bcview().addReadOnly(dialog_->valueLE); + bcview().addReadOnly(dialog_->unitCO); + bcview().addReadOnly(dialog_->keepCB); +} + + +void QVSpace::apply() +{ + // spacing + // If a vspace choice is "Length" but there's no text in + // the input field, reset the choice to "None". + if (dialog_->spacingCO->currentItem() == 6 + && dialog_->valueLE->text().isEmpty()) + dialog_->spacingCO->setCurrentItem(0); + + VSpace const space = + setVSpaceFromWidgets(dialog_->spacingCO->currentItem(), + fromqstr(dialog_->valueLE->text()), + fromqstr(dialog_->unitCO->currentText()), + dialog_->keepCB->isChecked()); + + controller().params() = space; +} + + +void QVSpace::update_contents() +{ + setWidgetsFromVSpace(controller().params(), + dialog_->spacingCO, + dialog_->valueLE, + dialog_->unitCO, + dialog_->keepCB, units_); +} diff --git a/src/frontends/qt2/QVSpace.h b/src/frontends/qt2/QVSpace.h new file mode 100644 index 0000000000..5f5a377fdf --- /dev/null +++ b/src/frontends/qt2/QVSpace.h @@ -0,0 +1,45 @@ +// -*- C++ -*- +/** + * \file QVSpace.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author André Pönitz + * \author Angus Leeming + * \author Jürgen Spitzmüller + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef QVSPACE_H +#define QVSPACE_H + +#include "QDialogView.h" + +#include + +class ControlVSpace; +class QVSpaceDialog; + +/** This class provides an Qt implementation of the VSpace dialog. + */ +class QVSpace + : public QController > +{ +public: + /// + friend class QVSpaceDialog; + /// + QVSpace(Dialog &); +private: + /// Build the dialog + virtual void build_dialog(); + /// Apply from dialog + virtual void apply(); + /// Update the dialog + virtual void update_contents(); + + std::vector units_; +}; + +#endif //QVSPACE_H diff --git a/src/frontends/qt2/QVSpaceDialog.C b/src/frontends/qt2/QVSpaceDialog.C new file mode 100644 index 0000000000..69ecfe65d6 --- /dev/null +++ b/src/frontends/qt2/QVSpaceDialog.C @@ -0,0 +1,58 @@ +/** + * \file QVSpaceDialog.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author John Levon + * \author Edwin Leuven + * \author Jürgen Spitzmüller + * + * Full author contact details are available in file CREDITS. + */ + +#include + +#include "QVSpaceDialog.h" +#include "QVSpace.h" + +#include +#include +#include +#include + +#include "qt_helpers.h" + + +QVSpaceDialog::QVSpaceDialog(QVSpace * form) + : QVSpaceDialogBase(0, 0, false, 0), + form_(form) +{ + connect(okPB, SIGNAL(clicked()), + form_, SLOT(slotOK())); + connect(applyPB, SIGNAL(clicked()), + form_, SLOT(slotApply())); + connect(closePB, SIGNAL(clicked()), + form_, SLOT(slotClose())); +} + + +void QVSpaceDialog::closeEvent(QCloseEvent * e) +{ + form_->slotWMHide(); + e->accept(); +} + + +void QVSpaceDialog::change_adaptor() +{ + form_->changed(); +} + + +void QVSpaceDialog::enableCustom(int) +{ + bool const enable = spacingCO->currentItem()==6; + valueLE->setEnabled(enable); + unitCO->setEnabled(enable); +} + diff --git a/src/frontends/qt2/QVSpaceDialog.h b/src/frontends/qt2/QVSpaceDialog.h new file mode 100644 index 0000000000..a69498daec --- /dev/null +++ b/src/frontends/qt2/QVSpaceDialog.h @@ -0,0 +1,38 @@ +// -*- C++ -*- +/** + * \file QVSpaceDialog.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author John Levon + * \author Jürgen Spitzmüller + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef QVSPACEDIALOG_H +#define QVSPACEDIALOG_H + + +#include "ui/QVSpaceDialogBase.h" + +class QVSpace; + +class QVSpaceDialog : public QVSpaceDialogBase { + Q_OBJECT + +public: + QVSpaceDialog(QVSpace * form); + +public slots: + void change_adaptor(); + +protected: + void closeEvent(QCloseEvent *); + void enableCustom(int); + +private: + QVSpace * form_; +}; + +#endif // QVSPACEDIALOG_H diff --git a/src/frontends/qt2/ui/QVSpaceDialogBase.ui b/src/frontends/qt2/ui/QVSpaceDialogBase.ui new file mode 100644 index 0000000000..c32640475d --- /dev/null +++ b/src/frontends/qt2/ui/QVSpaceDialogBase.ui @@ -0,0 +1,391 @@ + +QVSpaceDialogBase +config.h +qt_helpers.h + + QDialog + + name + QVSpaceDialogBase + + + geometry + + 0 + 0 + 345 + 140 + + + + caption + Form1 + + + sizeGripEnabled + true + + + + margin + 11 + + + spacing + 6 + + + QLabel + + name + spacingL + + + text + &Spacing: + + + buddy + spacingCO + + + + QLabel + + name + valueL + + + text + &Value: + + + buddy + valueLE + + + + QLabel + + name + keepL + + + text + &Protect: + + + buddy + keepCB + + + toolTip + + + + + QCheckBox + + name + keepCB + + + text + + + + toolTip + Do not reset the spacing on page break + + + + QComboBox + + name + unitCO + + + enabled + false + + + toolTip + Custom value. Needs spacing type "Custom". + + + + QLineEdit + + name + valueLE + + + enabled + false + + + toolTip + Custom value. Needs spacing type "Custom". + + + + QComboBox + + + text + None + + + + + text + DefSkip + + + + + text + SmallSkip + + + + + text + MedSkip + + + + + text + BigSkip + + + + + text + VFill + + + + + text + Custom + + + + name + spacingCO + + + toolTip + Supported spacing types + + + + + name + Spacer8 + + + orientation + Horizontal + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + + name + Spacer9 + + + orientation + Horizontal + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + QLayoutWidget + + name + Layout5 + + + + margin + 0 + + + spacing + 6 + + + QPushButton + + name + restorePB + + + text + &Restore + + + autoDefault + false + + + + + name + Spacer1 + + + orientation + Horizontal + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + QPushButton + + name + okPB + + + text + &OK + + + autoDefault + false + + + default + true + + + + QPushButton + + name + applyPB + + + text + &Apply + + + autoDefault + false + + + + QPushButton + + name + closePB + + + text + &Close + + + autoDefault + false + + + + + + + name + Spacer28 + + + orientation + Vertical + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + + + + spacingCO + highlighted(const QString&) + QVSpaceDialogBase + change_adaptor() + + + valueLE + textChanged(const QString&) + QVSpaceDialogBase + change_adaptor() + + + unitCO + highlighted(const QString&) + QVSpaceDialogBase + change_adaptor() + + + keepCB + checked() + QVSpaceDialogBase + change_adaptor() + + + spacingCO + activated(int) + QVSpaceDialogBase + enableCustom(int) + + change_adaptor() + enableCustom(int) + + + restorePB + okPB + applyPB + closePB + + -- 2.39.2