QVSpace dialog/QBranches: some minor (uncontroversial) bugfixes

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8156 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Spitzmüller 2003-11-29 17:25:31 +00:00
parent 98584b07ac
commit d2eb113909
8 changed files with 124 additions and 111 deletions

View File

@ -1,6 +1,14 @@
2003-11-29 Juergen Spitzmueller <j.spitzmueller@gmx.de>
* 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 <j.spitzmueller@gmx.de>

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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 <qlineedit.h>
#include <qcheckbox.h>
#include <qpushbutton.h>
#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<string> 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<string>::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<ControlVSpace, QView<QVSpaceDialog> > 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<string>::iterator del =
remove_if(units_.begin(), units_.end(),
bind2nd(contains_functor(), "%"));
units_.erase(del, units_.end());
for (vector<string>::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);
}

View File

@ -38,8 +38,6 @@ private:
virtual void apply();
/// Update the dialog
virtual void update_contents();
std::vector<std::string> units_;
};
#endif //QVSPACE_H

View File

@ -19,6 +19,7 @@
#include <qcombobox.h>
#include <qpushbutton.h>
#include <qvalidator.h>
#include "lengthcombo.h"
#include "qt_helpers.h"

View File

@ -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 <config.h>
#include "support/tostr.h"
#include "support/lstrings.h"
#include "gettext.h"
#include "qt_helpers.h"
@ -21,6 +23,9 @@
#include <algorithm>
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())));

View File

@ -13,7 +13,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>345</width>
<width>335</width>
<height>140</height>
</rect>
</property>
@ -98,21 +98,6 @@
<string>Do not reset the spacing on page break</string>
</property>
</widget>
<widget row="1" column="2" >
<class>QComboBox</class>
<property stdset="1">
<name>name</name>
<cstring>unitCO</cstring>
</property>
<property stdset="1">
<name>enabled</name>
<bool>false</bool>
</property>
<property>
<name>toolTip</name>
<string>Custom value. Needs spacing type "Custom".</string>
</property>
</widget>
<widget row="1" column="1" >
<class>QLineEdit</class>
<property stdset="1">
@ -181,7 +166,7 @@
<string>Supported spacing types</string>
</property>
</widget>
<spacer row="0" column="2" >
<spacer row="0" column="2" rowspan="1" colspan="2" >
<property>
<name>name</name>
<cstring>Spacer8</cstring>
@ -202,7 +187,7 @@
</size>
</property>
</spacer>
<spacer row="2" column="2" >
<spacer row="2" column="2" rowspan="1" colspan="2" >
<property>
<name>name</name>
<cstring>Spacer9</cstring>
@ -223,7 +208,7 @@
</size>
</property>
</spacer>
<widget row="4" column="0" rowspan="1" colspan="3" >
<widget row="4" column="0" rowspan="1" colspan="4" >
<class>QLayoutWidget</class>
<property stdset="1">
<name>name</name>
@ -346,8 +331,59 @@
</size>
</property>
</spacer>
<widget row="1" column="2" >
<class>LengthCombo</class>
<property stdset="1">
<name>name</name>
<cstring>unitCO</cstring>
</property>
</widget>
<spacer row="1" column="3" >
<property>
<name>name</name>
<cstring>Spacer5</cstring>
</property>
<property stdset="1">
<name>orientation</name>
<enum>Horizontal</enum>
</property>
<property stdset="1">
<name>sizeType</name>
<enum>Expanding</enum>
</property>
<property>
<name>sizeHint</name>
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</grid>
</widget>
<customwidgets>
<customwidget>
<class>LengthCombo</class>
<header location="local">lengthcombo.h</header>
<sizehint>
<width>-1</width>
<height>-1</height>
</sizehint>
<container>0</container>
<sizepolicy>
<hordata>5</hordata>
<verdata>5</verdata>
</sizepolicy>
<pixmap>image0</pixmap>
<signal>selectionChanged(LyXLength::UNIT)</signal>
</customwidget>
</customwidgets>
<images>
<image>
<name>image0</name>
<data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1be245fc04c5a3201e4615f430059d0711ff5ddb2e6bb236ec90eed134cb5a19d8ef36602af5ecdbfeeac05dda0798d3abebde87e3faa374d3807fa0d633a52d38d8de6f679fe33fc776e196f53cd010188256a3600a292882096246517815ca99884606e18044a3a40d91824820924265a7923a2e8bcd05f33db1173e002913175f2a6be6d3294871a2d95fa00e8a94ee017b69d339d90df1e77c57ea072ede6758</data>
</image>
</images>
<connections>
<connection>
<sender>spacingCO</sender>
@ -360,18 +396,6 @@
<signal>textChanged(const QString&amp;)</signal>
<receiver>QVSpaceDialogBase</receiver>
<slot>change_adaptor()</slot>
</connection>
<connection>
<sender>unitCO</sender>
<signal>highlighted(const QString&amp;)</signal>
<receiver>QVSpaceDialogBase</receiver>
<slot>change_adaptor()</slot>
</connection>
<connection>
<sender>keepCB</sender>
<signal>checked()</signal>
<receiver>QVSpaceDialogBase</receiver>
<slot>change_adaptor()</slot>
</connection>
<connection>
<sender>spacingCO</sender>
@ -379,6 +403,18 @@
<receiver>QVSpaceDialogBase</receiver>
<slot>enableCustom(int)</slot>
</connection>
<connection>
<sender>keepCB</sender>
<signal>clicked()</signal>
<receiver>QVSpaceDialogBase</receiver>
<slot>change_adaptor()</slot>
</connection>
<connection>
<sender>unitCO</sender>
<signal>selectionChanged(LyXLength::UNIT)</signal>
<receiver>QVSpaceDialogBase</receiver>
<slot>change_adaptor()</slot>
</connection>
<slot access="protected">change_adaptor()</slot>
<slot access="protected">enableCustom(int)</slot>
</connections>