From d2eb11390946abc8200781c5d37112383217eb76 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Spitzm=C3=BCller?= Date: Sat, 29 Nov 2003 17:25:31 +0000 Subject: [PATCH] QVSpace dialog/QBranches: some minor (uncontroversial) bugfixes git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8156 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt2/ChangeLog | 10 +- src/frontends/qt2/QDocumentDialog.C | 2 +- src/frontends/qt2/QParagraphDialog.C | 2 +- src/frontends/qt2/QVSpace.C | 111 +++++++--------------- src/frontends/qt2/QVSpace.h | 2 - src/frontends/qt2/QVSpaceDialog.C | 1 + src/frontends/qt2/qt_helpers.C | 9 ++ src/frontends/qt2/ui/QVSpaceDialogBase.ui | 90 ++++++++++++------ 8 files changed, 120 insertions(+), 107 deletions(-) diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 393489c9d4..13c1ef7d73 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,6 +1,14 @@ 2003-11-29 Juergen Spitzmueller - * QParagraph.C: whitespace + * qt_helpers.C (widgetsToLength): handle glue lengths + * QDocumentDialog.C: use clicked() instead of pressed() + for branches color button. + * QVSpace.[Ch]: fix a few bugs, simplify the code (by using + qt_helpers functions) + * QDocumentDialog.C: + * ui/QDocumentDialogBase.ui: use lengthcombo instead of + QComboBox (which simplifies the code). + * QParagraphDialog.C: whitespace * ui/QParagraphDialogBase.ui: restore lost connections. 2003-11-29 Juergen Spitzmueller diff --git a/src/frontends/qt2/QDocumentDialog.C b/src/frontends/qt2/QDocumentDialog.C index 12876572ce..efee6907a5 100644 --- a/src/frontends/qt2/QDocumentDialog.C +++ b/src/frontends/qt2/QDocumentDialog.C @@ -167,7 +167,7 @@ QDocumentDialog::QDocumentDialog(QDocument * form) connect(branchesModule->addBranchPB, SIGNAL(pressed()), this, SLOT(addBranchPressed())); connect(branchesModule->removePB, SIGNAL(pressed()), this, SLOT(deleteBranchPressed())); connect(branchesModule->activatePB, SIGNAL(pressed()), this, SLOT(toggleBranchPressed())); - connect(branchesModule->colorPB, SIGNAL(pressed()), this, SLOT(toggleBranchColor())); + connect(branchesModule->colorPB, SIGNAL(clicked()), this, SLOT(toggleBranchColor())); branchesModule->branchesLV->setSorting(0); } diff --git a/src/frontends/qt2/QParagraphDialog.C b/src/frontends/qt2/QParagraphDialog.C index 78b6dcfbe2..542138521f 100644 --- a/src/frontends/qt2/QParagraphDialog.C +++ b/src/frontends/qt2/QParagraphDialog.C @@ -66,6 +66,6 @@ void QParagraphDialog::change_adaptor() void QParagraphDialog::enableLinespacingValue(int) { - bool const enable = linespacing->currentItem()==4; + bool const enable = linespacing->currentItem() == 4; linespacingValue->setEnabled(enable); } diff --git a/src/frontends/qt2/QVSpace.C b/src/frontends/qt2/QVSpace.C index 32aa3a4ebc..a3b896403f 100644 --- a/src/frontends/qt2/QVSpace.C +++ b/src/frontends/qt2/QVSpace.C @@ -20,7 +20,7 @@ #include "QVSpace.h" #include "QVSpaceDialog.h" #include "Qt2BC.h" -#include "lyxrc.h" // to set the deafult length values +#include "lyxrc.h" // to set the default length values #include "qt_helpers.h" #include "helper_funcs.h" @@ -34,16 +34,9 @@ #include #include #include +#include "lengthcombo.h" -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; @@ -52,13 +45,9 @@ namespace { void setWidgetsFromVSpace(VSpace const & space, QComboBox * spacing, QLineEdit * value, - QComboBox * unit, - QCheckBox * keep, vector units_) + LengthCombo * unit, + QCheckBox * keep) { - value->setText(""); - value->setEnabled(false); - unit->setEnabled(false); - int item = 0; switch (space.kind()) { case VSpace::NONE: @@ -81,48 +70,33 @@ void setWidgetsFromVSpace(VSpace const & space, 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()); + + LyXLength::UNIT default_unit = + (lyxrc.default_papersize > 3) ? LyXLength::CM : LyXLength::IN; + bool const custom_vspace = space.kind() == VSpace::LENGTH; + if (custom_vspace) { + value->setEnabled(true); + unit->setEnabled(true); + string length = space.length().asString(); + lengthToWidgets(value, unit, length, default_unit); + } else { + lengthToWidgets(value, unit, "", default_unit); + value->setEnabled(false); + unit->setEnabled(false); + } } VSpace setVSpaceFromWidgets(int spacing, - string value, - string unit, + QLineEdit * value, + LengthCombo * unit, bool keep) { - VSpace space; + VSpace space = VSpace(VSpace::NONE); switch (spacing) { case 0: @@ -144,21 +118,12 @@ VSpace setVSpaceFromWidgets(int spacing, 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)); + space = VSpace(LyXGlueLength( + widgetsToLength(value, unit))); break; } space.setKeep(keep); - return space; } @@ -168,7 +133,7 @@ VSpace setVSpaceFromWidgets(int spacing, typedef QController > base_class; QVSpace::QVSpace(Dialog & parent) - : base_class(parent, _("LyX: VSpace Settings")) + : base_class(parent, _("LyX: Vertical Space Settings")) {} @@ -177,19 +142,6 @@ 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); @@ -201,6 +153,15 @@ void QVSpace::build_dialog() bcview().addReadOnly(dialog_->valueLE); bcview().addReadOnly(dialog_->unitCO); bcview().addReadOnly(dialog_->keepCB); + + // remove the %-items from the unit choice + int num = dialog_->unitCO->count(); + for (int i=0; i < num; i++) { + if (dialog_->unitCO->text(i).contains("%") > 0) { + dialog_->unitCO->removeItem(i); + i -= 1; + } + } } @@ -215,8 +176,8 @@ void QVSpace::apply() VSpace const space = setVSpaceFromWidgets(dialog_->spacingCO->currentItem(), - fromqstr(dialog_->valueLE->text()), - fromqstr(dialog_->unitCO->currentText()), + dialog_->valueLE, + dialog_->unitCO, dialog_->keepCB->isChecked()); controller().params() = space; @@ -229,5 +190,5 @@ void QVSpace::update_contents() dialog_->spacingCO, dialog_->valueLE, dialog_->unitCO, - dialog_->keepCB, units_); + dialog_->keepCB); } diff --git a/src/frontends/qt2/QVSpace.h b/src/frontends/qt2/QVSpace.h index 5f5a377fdf..f35ad6e668 100644 --- a/src/frontends/qt2/QVSpace.h +++ b/src/frontends/qt2/QVSpace.h @@ -38,8 +38,6 @@ private: 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 index 69ecfe65d6..33305a9f09 100644 --- a/src/frontends/qt2/QVSpaceDialog.C +++ b/src/frontends/qt2/QVSpaceDialog.C @@ -19,6 +19,7 @@ #include #include #include +#include "lengthcombo.h" #include "qt_helpers.h" diff --git a/src/frontends/qt2/qt_helpers.C b/src/frontends/qt2/qt_helpers.C index 8aa22cbc09..109f083739 100644 --- a/src/frontends/qt2/qt_helpers.C +++ b/src/frontends/qt2/qt_helpers.C @@ -4,6 +4,7 @@ * Licence details can be found in the file COPYING. * * \author Dekel Tsur + * \author Jürgen Spitzmüller * * Full author contact details are available in file CREDITS. */ @@ -11,6 +12,7 @@ #include #include "support/tostr.h" +#include "support/lstrings.h" #include "gettext.h" #include "qt_helpers.h" @@ -21,6 +23,9 @@ #include + +using lyx::support::isStrDbl; + using std::make_pair; using std::string; using std::pair; @@ -79,6 +84,10 @@ void lengthToWidgets(QLineEdit * input, LengthCombo * combo, // no length (UNIT_NONE) combo->setCurrentItem(defaultUnit); input->setText(""); + } else if (!isValidLength(len) && !isStrDbl(len)) { + // use input field only for gluelengths + combo->setCurrentItem(defaultUnit); + input->setText(toqstr(len)); } else { combo->setCurrentItem(LyXLength(len).unit()); input->setText(toqstr(tostr(LyXLength(len).value()))); diff --git a/src/frontends/qt2/ui/QVSpaceDialogBase.ui b/src/frontends/qt2/ui/QVSpaceDialogBase.ui index c32640475d..4fc0bca360 100644 --- a/src/frontends/qt2/ui/QVSpaceDialogBase.ui +++ b/src/frontends/qt2/ui/QVSpaceDialogBase.ui @@ -13,7 +13,7 @@ 0 0 - 345 + 335 140 @@ -98,21 +98,6 @@ Do not reset the spacing on page break - - QComboBox - - name - unitCO - - - enabled - false - - - toolTip - Custom value. Needs spacing type "Custom". - - QLineEdit @@ -181,7 +166,7 @@ Supported spacing types - + name Spacer8 @@ -202,7 +187,7 @@ - + name Spacer9 @@ -223,7 +208,7 @@ - + QLayoutWidget name @@ -346,8 +331,59 @@ + + LengthCombo + + name + unitCO + + + + + name + Spacer5 + + + orientation + Horizontal + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + + LengthCombo +
lengthcombo.h
+ + -1 + -1 + + 0 + + 5 + 5 + + image0 + selectionChanged(LyXLength::UNIT) +
+
+ + + image0 + 789c6dd2c10ac2300c00d07bbf2234b7229d1be245fc04c5a3201e4615f430059d0711ff5ddb2e6bb236ec90eed134cb5a19d8ef36602af5ecdbfeeac05dda0798d3abebde87e3faa374d3807fa0d633a52d38d8de6f679fe33fc776e196f53cd010188256a3600a292882096246517815ca99884606e18044a3a40d91824820924265a7923a2e8bcd05f33db1173e002913175f2a6be6d3294871a2d95fa00e8a94ee017b69d339d90df1e77c57ea072ede6758 + + spacingCO @@ -362,22 +398,22 @@ change_adaptor() - unitCO - highlighted(const QString&) + spacingCO + activated(int) QVSpaceDialogBase - change_adaptor() + enableCustom(int) keepCB - checked() + clicked() QVSpaceDialogBase change_adaptor() - - spacingCO - activated(int) + + unitCO + selectionChanged(LyXLength::UNIT) QVSpaceDialogBase - enableCustom(int) + change_adaptor() change_adaptor() enableCustom(int) -- 2.39.2