#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"
#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;
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:
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:
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;
}
typedef QController<ControlVSpace, QView<QVSpaceDialog> > base_class;
QVSpace::QVSpace(Dialog & parent)
- : base_class(parent, _("LyX: VSpace Settings"))
+ : base_class(parent, _("LyX: Vertical Space Settings"))
{}
// 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);
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;
+ }
+ }
}
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;
dialog_->spacingCO,
dialog_->valueLE,
dialog_->unitCO,
- dialog_->keepCB, units_);
+ dialog_->keepCB);
}
<rect>
<x>0</x>
<y>0</y>
- <width>345</width>
+ <width>335</width>
<height>140</height>
</rect>
</property>
<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">
<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>
</size>
</property>
</spacer>
- <spacer row="2" column="2" >
+ <spacer row="2" column="2" rowspan="1" colspan="2" >
<property>
<name>name</name>
<cstring>Spacer9</cstring>
</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>
</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>
<slot>change_adaptor()</slot>
</connection>
<connection>
- <sender>unitCO</sender>
- <signal>highlighted(const QString&)</signal>
+ <sender>spacingCO</sender>
+ <signal>activated(int)</signal>
<receiver>QVSpaceDialogBase</receiver>
- <slot>change_adaptor()</slot>
+ <slot>enableCustom(int)</slot>
</connection>
<connection>
<sender>keepCB</sender>
- <signal>checked()</signal>
+ <signal>clicked()</signal>
<receiver>QVSpaceDialogBase</receiver>
<slot>change_adaptor()</slot>
</connection>
- <connection>
- <sender>spacingCO</sender>
- <signal>activated(int)</signal>
+ <connection>
+ <sender>unitCO</sender>
+ <signal>selectionChanged(LyXLength::UNIT)</signal>
<receiver>QVSpaceDialogBase</receiver>
- <slot>enableCustom(int)</slot>
+ <slot>change_adaptor()</slot>
</connection>
<slot access="protected">change_adaptor()</slot>
<slot access="protected">enableCustom(int)</slot>