* \author John Levon
* \author Edwin Leuven
* \author Herbert Voß
+ * \author Richard Heck
*
* Full author contact details are available in file CREDITS.
*/
bcview().addReadOnly(dialog_->getPB);
// initialize the length validator
- addCheckedLineEdit(bcview(), dialog_->Width, dialog_->widthL);
- addCheckedLineEdit(bcview(), dialog_->Height, dialog_->heightL);
+ addCheckedLineEdit(bcview(), dialog_->Scale, dialog_->scaleCB);
+ addCheckedLineEdit(bcview(), dialog_->Width, dialog_->WidthCB);
+ addCheckedLineEdit(bcview(), dialog_->Height, dialog_->HeightCB);
addCheckedLineEdit(bcview(), dialog_->displayscale, dialog_->scaleLA);
addCheckedLineEdit(bcview(), dialog_->angle, dialog_->angleL);
addCheckedLineEdit(bcview(), dialog_->lbX, dialog_->xL);
dialog_->displayGB->setChecked(igp.display != graphics::NoDisplay);
// the output section (width/height)
+
dialog_->Scale->setText(toqstr(igp.scale));
-
- lengthToWidgets(dialog_->Width, dialog_->widthUnit,
- igp.width.asString(), unitDefault);
-
- lengthToWidgets(dialog_->Height, dialog_->heightUnit,
- igp.height.asString(), unitDefault);
-
- dialog_->aspectratio->setChecked(igp.keepAspectRatio);
-
- dialog_->scaleCB->setChecked(!igp.scale.empty() || igp.width.empty());
-
- dialog_->Scale->setEnabled(!igp.scale.empty() || igp.width.empty());
+ //igp.scale defaults to 100, so we treat it as empty
+ bool const scaleChecked = !igp.scale.empty() && igp.scale != "100";
+ dialog_->scaleCB->blockSignals(true);
+ dialog_->scaleCB->setChecked(scaleChecked);
+ dialog_->scaleCB->blockSignals(false);
+ dialog_->Scale->setEnabled(scaleChecked);
+
+ lengthAutoToWidgets(dialog_->Width, dialog_->widthUnit, igp.width,
+ unitDefault);
+ bool const widthChecked = !dialog_->Width->text().isEmpty() &&
+ dialog_->Width->text() != "auto";
+ dialog_->WidthCB->blockSignals(true);
+ dialog_->WidthCB->setChecked(widthChecked);
+ dialog_->WidthCB->blockSignals(false);
+ dialog_->Width->setEnabled(widthChecked);
+ dialog_->widthUnit->setEnabled(widthChecked);
+
+ lengthAutoToWidgets(dialog_->Height, dialog_->heightUnit, igp.height,
+ unitDefault);
+ bool const heightChecked = !dialog_->Height->text().isEmpty()
+ && dialog_->Height->text() != "auto";
+ dialog_->HeightCB->blockSignals(true);
+ dialog_->HeightCB->setChecked(heightChecked);
+ dialog_->HeightCB->blockSignals(false);
+ dialog_->Height->setEnabled(heightChecked);
+ dialog_->heightUnit->setEnabled(heightChecked);
+
+ dialog_->scaleCB->setEnabled(!widthChecked && !heightChecked);
+ dialog_->WidthCB->setEnabled(!scaleChecked);
+ dialog_->HeightCB->setEnabled(!scaleChecked);
+ dialog_->aspectratio->setEnabled(widthChecked && heightChecked);
+
+ dialog_->setAutoText();
dialog_->angle->setText(toqstr(igp.rotateAngle));
if (!dialog_->displayGB->isChecked())
igp.display = graphics::NoDisplay;
-
- if (dialog_->scaleCB->isChecked()
- && !dialog_->Scale->text().isEmpty()) {
+
+ //the graphics section
+ if (dialog_->scaleCB->isChecked() && !dialog_->Scale->text().isEmpty()) {
igp.scale = fromqstr(dialog_->Scale->text());
+ igp.width = LyXLength("0pt");
+ igp.height = LyXLength("0pt");
+ igp.keepAspectRatio = false;
} else {
igp.scale = string();
+ igp.width = dialog_->WidthCB->isChecked() ?
+ //Note that this works even if dialog_->Width is "auto", since in
+ //that case we get "0pt".
+ LyXLength(widgetsToLength(dialog_->Width, dialog_->widthUnit)):
+ LyXLength("0pt");
+ igp.height = dialog_->HeightCB->isChecked() ?
+ LyXLength(widgetsToLength(dialog_->Height, dialog_->heightUnit)) :
+ LyXLength("0pt");
+ igp.keepAspectRatio = dialog_->aspectratio->isEnabled() &&
+ dialog_->aspectratio->isChecked() &&
+ igp.width.value() > 0 && igp.height.value() > 0;
}
- igp.width = LyXLength(widgetsToLength(dialog_->Width, dialog_->widthUnit));
-
- igp.height = LyXLength(widgetsToLength(dialog_->Height, dialog_->heightUnit));
-
- igp.keepAspectRatio = dialog_->aspectratio->isChecked();
-
igp.noUnzip = dialog_->unzipCB->isChecked();
igp.lyxscale = convert<int>(fromqstr(dialog_->displayscale->text()));
* \author John Levon
* \author Herbert Voß
* \author Abdelrazak Younes
+ * \author Richard Heck
*
* Full author contact details are available in file CREDITS.
*/
: form_(form)
{
setupUi(this);
+ //main buttons
connect(okPB, SIGNAL( clicked() ),
form, SLOT( slotOK() ) );
connect(applyPB, SIGNAL( clicked() ),
form, SLOT( slotClose() ) );
connect(restorePB, SIGNAL( clicked() ),
form, SLOT( slotRestore() ) );
+
+ //graphics pane
connect(filename, SIGNAL( textChanged(const QString&) ),
this, SLOT( change_adaptor() ) );
- connect(subcaption, SIGNAL( textChanged(const QString&) ),
- this, SLOT( change_adaptor() ) );
-
- // FIXME: we should connect to clicked() when we move to Qt 4.2 because
- // the toggled(bool) signal is also trigged when we update the widgets
- connect(subfigure, SIGNAL( toggled(bool) ),
- this, SLOT( change_adaptor() ) );
- connect(displayGB, SIGNAL( toggled(bool) ),
- this, SLOT( change_adaptor() ) );
-
- connect(latexoptions, SIGNAL( textChanged(const QString&) ),
+ connect(WidthCB, SIGNAL( clicked() ),
this, SLOT( change_adaptor() ) );
- connect(clip, SIGNAL( stateChanged(int) ),
- this, SLOT( change_adaptor() ) );
- connect(showCB, SIGNAL( currentIndexChanged(int) ),
- this, SLOT( change_adaptor() ) );
- connect(displayscale, SIGNAL( textChanged(const QString&) ),
+ connect(HeightCB, SIGNAL( clicked() ),
this, SLOT( change_adaptor() ) );
connect(Width, SIGNAL( textChanged(const QString&) ),
this, SLOT( change_adaptor() ) );
- connect(aspectratio, SIGNAL( stateChanged(int) ),
- this, SLOT( change_adaptor() ) );
- connect(draftCB, SIGNAL( stateChanged(int) ),
- this, SLOT( change_adaptor() ) );
- connect(unzipCB, SIGNAL( stateChanged(int) ),
- this, SLOT( change_adaptor() ) );
connect(Height, SIGNAL( textChanged(const QString&) ),
this, SLOT( change_adaptor() ) );
connect(heightUnit, SIGNAL( selectionChanged(lyx::LyXLength::UNIT) ),
this, SLOT( change_adaptor() ) );
connect(widthUnit, SIGNAL( selectionChanged(lyx::LyXLength::UNIT) ),
this, SLOT( change_adaptor() ) );
+ connect(aspectratio, SIGNAL( stateChanged(int) ),
+ this, SLOT( change_adaptor() ) );
connect(angle, SIGNAL( textChanged(const QString&) ),
this, SLOT( change_adaptor() ) );
connect(origin, SIGNAL( activated(int) ),
this, SLOT( change_adaptor() ) );
- connect(getPB, SIGNAL( clicked() ),
- this, SLOT( change_adaptor() ) );
connect(scaleCB, SIGNAL( clicked() ),
this, SLOT(change_adaptor()) );
connect(Scale, SIGNAL( textChanged(const QString&) ),
this, SLOT( change_adaptor() ) );
+
+ filename->setValidator(new PathValidator(true, filename));
+ setFocusProxy(filename);
+
+ QDoubleValidator * scaleValidator = new DoubleAutoValidator(Scale);
+ scaleValidator->setBottom(0);
+ scaleValidator->setDecimals(256); //I guess that will do
+ Scale->setValidator(scaleValidator);
+ Height->setValidator(unsignedLengthAutoValidator(Height));
+ Width->setValidator(unsignedLengthAutoValidator(Width));
+ angle->setValidator(new QDoubleValidator(-360, 360, 2, angle));
+ //clipping pane
+ connect(clip, SIGNAL( stateChanged(int) ),
+ this, SLOT( change_adaptor() ) );
connect(lbY, SIGNAL( textChanged(const QString&) ),
this, SLOT( change_bb() ) );
connect(lbYunit, SIGNAL( activated(int) ),
this, SLOT( change_bb() ) );
connect(rtYunit, SIGNAL( activated(int) ),
this, SLOT( change_bb() ) );
-
connect(lbX, SIGNAL( textChanged(const QString&) ),
this, SLOT( change_bb() ) );
connect(lbXunit, SIGNAL( activated(int) ),
this, SLOT( change_bb() ) );
connect(rtXunit, SIGNAL( activated(int) ),
this, SLOT( change_bb() ) );
-
- angle->setValidator(new QDoubleValidator(-360, 360, 2, angle));
-
+ connect(getPB, SIGNAL( clicked() ),
+ this, SLOT( change_adaptor() ) );
+
lbX->setValidator(new QDoubleValidator(lbX));
lbY->setValidator(new QDoubleValidator(lbY));
rtX->setValidator(new QDoubleValidator(rtX));
rtY->setValidator(new QDoubleValidator(rtY));
+ //extra options pane
+ connect(latexoptions, SIGNAL( textChanged(const QString&) ),
+ this, SLOT( change_adaptor() ) );
+ connect(draftCB, SIGNAL( stateChanged(int) ),
+ this, SLOT( change_adaptor() ) );
+ connect(unzipCB, SIGNAL( stateChanged(int) ),
+ this, SLOT( change_adaptor() ) );
+ // FIXME: we should connect to clicked() when we move to Qt 4.2 because
+ // the toggled(bool) signal is also trigged when we update the widgets
+ // (rgh-4/07) this isn't as much or a problem as it was, because we're now
+ // using blockSignals() to keep from triggering that signal when we call
+ // setChecked(). Note, too, that clicked() would get called whenever it
+ // is clicked, even right clicked (I think), not just whenever it is
+ // toggled.
+ connect(subfigure, SIGNAL( toggled(bool) ),
+ this, SLOT( change_adaptor() ) );
+ connect(subcaption, SIGNAL( textChanged(const QString&) ),
+ this, SLOT( change_adaptor() ) );
+ connect(displayGB, SIGNAL( toggled(bool) ),
+ this, SLOT( change_adaptor() ) );
+ connect(showCB, SIGNAL( currentIndexChanged(int) ),
+ this, SLOT( change_adaptor() ) );
+ connect(displayscale, SIGNAL( textChanged(const QString&) ),
+ this, SLOT( change_adaptor() ) );
displayscale->setValidator(new QIntValidator(displayscale));
- Height->setValidator(unsignedLengthValidator(Height));
- Width->setValidator(unsignedLengthValidator(Width));
-
- filename->setValidator(new PathValidator(true, filename));
- setFocusProxy(filename);
}
}
-void QGraphicsDialog::on_scaleCB_toggled(bool setscale)
+void QGraphicsDialog::setAutoText() {
+ if (scaleCB->isChecked()) return;
+ if (!Scale->isEnabled() && Scale->text() != "100")
+ Scale->setText(QString("auto"));
+
+ setAutoTextCB(WidthCB, Width, widthUnit);
+ setAutoTextCB(HeightCB, Height, heightUnit);
+}
+
+
+void QGraphicsDialog::on_scaleCB_toggled(bool setScale)
+{
+ Scale->setEnabled(setScale);
+ if (setScale) {
+ Scale->setText("");
+ Scale->setFocus(Qt::OtherFocusReason);
+ }
+
+ WidthCB->setDisabled(setScale);
+ WidthCB->blockSignals(true);
+ WidthCB->setChecked(false);
+ WidthCB->blockSignals(false);
+ Width->setEnabled(false);
+ widthUnit->setEnabled(false);
+
+ HeightCB->setDisabled(setScale);
+ HeightCB->blockSignals(true);
+ HeightCB->setChecked(false);
+ HeightCB->blockSignals(false);
+ Height->setEnabled(false);
+ heightUnit->setEnabled(false);
+
+ aspectratio->setDisabled(true);
+ aspectratio->setChecked(true);
+
+ setAutoText();
+}
+
+void QGraphicsDialog::on_WidthCB_toggled(bool setWidth)
{
- //FIXME: There is no scale text when the scale was "100" before keepaspectratio
- //was checked and then scaleCB is checked again
- //When somebody implements a void on toggling keepaspectration, this
- //case should be handled there.
- if (scaleCB->isChecked() && Scale->text() == "")
- Scale->setText("100");
- Scale->setEnabled(setscale);
- widthL->setDisabled(setscale);
- Width->setDisabled(setscale);
- widthUnit->setDisabled(setscale);
- aspectratio->setDisabled(setscale);
- bool noheight = setscale || aspectratio->checkState()==Qt::Checked;
- heightL->setDisabled(noheight);
- Height->setDisabled(noheight);
- heightUnit->setDisabled(noheight);
+ Width->setEnabled(setWidth);
+ widthUnit->setEnabled(setWidth);
+ if (setWidth)
+ Width->setFocus(Qt::OtherFocusReason);
+
+ bool const setHeight = HeightCB->isChecked();
+ aspectratio->setEnabled(setWidth && setHeight);
+ aspectratio->blockSignals(true);
+ aspectratio->setChecked(!(setWidth && setHeight));
+ aspectratio->blockSignals(false);
+
+ scaleCB->setEnabled(!setWidth && !setHeight);
+ //already will be unchecked, so don't need to do that
+ Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
+ && scaleCB->isChecked()); //should be false, but let's check
+
+ setAutoText();
}
+void QGraphicsDialog::on_HeightCB_toggled(bool setHeight)
+{
+ Height->setEnabled(setHeight);
+ heightUnit->setEnabled(setHeight);
+ if (setHeight)
+ Height->setFocus(Qt::OtherFocusReason);
+
+ bool const setWidth = WidthCB->isChecked();
+ aspectratio->setEnabled(setWidth && setHeight);
+ aspectratio->blockSignals(true);
+ aspectratio->setChecked(!(setWidth && setHeight));
+ aspectratio->blockSignals(false);
+
+ scaleCB->setEnabled(!setWidth && !setHeight);
+ //already unchecked
+ Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
+ && scaleCB->isChecked()); //should be false
+
+ setAutoText();
+}
+
+
} // namespace frontend
} // namespace lyx
*
* \author John Levon
* \author Herbert Voß
+ * \author Richard Heck
*
* Full author contact details are available in file CREDITS.
*/
Q_OBJECT
public:
QGraphicsDialog(QGraphics * form);
-
+ virtual void setAutoText();
virtual void show();
protected Q_SLOTS:
virtual void change_adaptor();
virtual void on_editPB_clicked();
virtual void on_filename_textChanged(const QString &);
virtual void on_scaleCB_toggled(bool);
+ virtual void on_WidthCB_toggled(bool);
+ virtual void on_HeightCB_toggled(bool);
protected:
virtual void closeEvent(QCloseEvent * e);
private:
namespace frontend {
void addCheckedLineEdit(BCView & bcview,
- QLineEdit * input, QLabel * label)
+ QLineEdit * input, QWidget * label)
{
bcview.addCheckedWidget(new CheckedLineEdit(input, label));
}
}
-void setWidget(bool valid, QLineEdit * input, QLabel * label)
+void setWidget(bool valid, QLineEdit * input, QWidget * label)
{
if (valid)
input->setPalette(QPalette());
} // namespace anon
-CheckedLineEdit::CheckedLineEdit(QLineEdit * input, QLabel * label)
+CheckedLineEdit::CheckedLineEdit(QLineEdit * input, QWidget * label)
: input_(input), label_(label)
{}
#include "BCView.h"
-class QLabel;
+class QWidget;
class QLineEdit;
namespace lyx {
namespace frontend {
void addCheckedLineEdit(BCView & bcview,
- QLineEdit * input, QLabel * label = 0);
+ QLineEdit * input, QWidget * label = 0);
class CheckedLineEdit : public CheckedWidget {
public:
- CheckedLineEdit(QLineEdit * input, QLabel * label = 0);
+ CheckedLineEdit(QLineEdit * input, QWidget * label = 0);
private:
///
///
QLineEdit * input_;
- QLabel * label_;
+ QWidget * label_;
};
} // namespace frontend
*
* \author Dekel Tsur
* \author Jürgen Spitzmüller
+ * \author Richard Heck
*
* Full author contact details are available in file CREDITS.
*/
#include "debug.h"
#include <QComboBox>
+#include <QCheckBox>
#include <qlineedit.h>
#include <qtextcodec.h>
}
+void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
+ LyXLength const & len, LyXLength::UNIT defaultUnit)
+{
+ combo->setCurrentItem(LyXLength(len).unit());
+ input->setText(toqstr(convert<string>(LyXLength(len).value())));
+}
+
+
void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
string const & len, LyXLength::UNIT defaultUnit)
{
combo->setCurrentItem(defaultUnit);
input->setText(toqstr(len));
} else {
- combo->setCurrentItem(LyXLength(len).unit());
- input->setText(toqstr(convert<string>(LyXLength(len).value())));
+ lengthToWidgets(input, combo, LyXLength(len), defaultUnit);
}
}
+void lengthAutoToWidgets(QLineEdit * input, LengthCombo * combo,
+ LyXLength const & len, LyXLength::UNIT defaultUnit)
+{
+ if (len.value() == 0)
+ lengthToWidgets(input, combo, "auto", defaultUnit);
+ else
+ lengthToWidgets(input, combo, len, defaultUnit);
+}
+
+
+//NOTE "CB" here because we probably will want one of these
+//for labeled sets, as well.
+void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit,
+ LengthCombo * lengthCombo)
+{
+ if (!checkBox->isChecked())
+ lengthToWidgets(lineEdit, lengthCombo, "auto", lengthCombo->currentLengthItem());
+ else if (lineEdit->text() == "auto")
+ lengthToWidgets(lineEdit, lengthCombo, string(""), lengthCombo->currentLengthItem());
+}
+
+
QString const qt_(char const * str, const char *)
{
return toqstr(_(str));
* Licence details can be found in the file COPYING.
*
* \author Dekel Tsur
+ * \author Richard Heck
*
* Full author contact details are available in file CREDITS.
*/
#include "support/qstring_helpers.h"
#include <QString>
-
#include <utility>
class QComboBox;
class QLineEdit;
+class QCheckBox;
class LengthCombo;
/// method to get a LyXLength from widgets (QComboBox)
LyXLength widgetsToLength(QLineEdit const * input, QComboBox const * combo);
+//FIXME It would be nice if defaultUnit were a default argument
/// method to set widgets from a LyXLength
+void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
+ LyXLength const & len, LyXLength::UNIT default_unit);
+/// method to set widgets from a string
void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
std::string const & len, LyXLength::UNIT default_unit);
+/// method to set widgets from a LyXLength with optional "auto" if zero
+void lengthAutoToWidgets(QLineEdit * input, LengthCombo * combo,
+ LyXLength const & len, LyXLength::UNIT defaultUnit);
+
+//FIXME setAutoTextCB should really take an argument, as indicated, that
+//determines what text is to be written for "auto". But making
+//that work involves more extensive revisions than we now want
+//to make, since "auto" also appears in update_contents() (see
+//QGraphics.C).
+//The right way to do this, I think, would be to define a class
+//checkedLengthSet (and a partnering labeledLengthSete) that encapsulated
+//the checkbox, line edit, and length combo together, and then made e.g.
+//lengthToWidgets, widgetsToLength, etc, all public methods of that class.
+//Perhaps even the validator could be exposed through it.
+/**
+ * sets a checkbox-line edit-length combo group, using "text" if the
+ * checkbox is unchecked and clearing the line edit if it previously
+ * said "text".
+*/
+void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit,
+ LengthCombo * lengthCombo/*, string text = "auto"*/);
+
/// format a string to the given width
docstring const formatted(docstring const & text, int w = 80);
</widget>
</item>
<item row="2" column="0" >
- <widget class="QLabel" name="heightL" >
+ <widget class="QCheckBox" name="HeightCB" >
<property name="enabled" >
<bool>true</bool>
</property>
- <property name="text" >
- <string>&Height:</string>
+ <property name="toolTip" >
+ <string>Sets height of graphic. Leave unchecked to set automatically.</string>
</property>
- <property name="buddy" >
- <cstring>Height</cstring>
+ <property name="text" >
+ <string>Set &height:</string>
</property>
</widget>
</item>
</widget>
</item>
<item row="1" column="0" >
- <widget class="QLabel" name="widthL" >
+ <widget class="QCheckBox" name="WidthCB" >
<property name="enabled" >
<bool>true</bool>
</property>
- <property name="text" >
- <string>&Width:</string>
+ <property name="toolTip" >
+ <string>Sets width of graphic. Leave unchecked to set automatically.</string>
</property>
- <property name="buddy" >
- <cstring>Width</cstring>
+ <property name="text" >
+ <string>Set &width:</string>
</property>
</widget>
</item>
<bool>true</bool>
</property>
<property name="toolTip" >
- <string>Maintain aspect ratio with largest dimension</string>
+ <string>Scale image to maximum size not exceeding width and height</string>
</property>
<property name="text" >
<string>&Maintain aspect ratio</string>
</widget>
<widget class="QWidget" name="ExtraOptions" >
<attribute name="title" >
- <string>E&xtra options</string>
+ <string>LaTe&X and LyX options</string>
</attribute>
<layout class="QGridLayout" >
<property name="margin" >
<tabstop>editPB</tabstop>
<tabstop>scaleCB</tabstop>
<tabstop>Scale</tabstop>
+ <tabstop>WidthCB</tabstop>
<tabstop>Width</tabstop>
<tabstop>widthUnit</tabstop>
+ <tabstop>HeightCB</tabstop>
<tabstop>Height</tabstop>
<tabstop>heightUnit</tabstop>
<tabstop>aspectratio</tabstop>
</includes>
<resources/>
<connections>
- <connection>
- <sender>aspectratio</sender>
- <signal>toggled(bool)</signal>
- <receiver>heightL</receiver>
- <slot>setDisabled(bool)</slot>
- <hints>
- <hint type="sourcelabel" >
- <x>201</x>
- <y>193</y>
- </hint>
- <hint type="destinationlabel" >
- <x>81</x>
- <y>158</y>
- </hint>
- </hints>
- </connection>
- <connection>
- <sender>aspectratio</sender>
- <signal>toggled(bool)</signal>
- <receiver>Height</receiver>
- <slot>setDisabled(bool)</slot>
- <hints>
- <hint type="sourcelabel" >
- <x>315</x>
- <y>193</y>
- </hint>
- <hint type="destinationlabel" >
- <x>275</x>
- <y>169</y>
- </hint>
- </hints>
- </connection>
- <connection>
- <sender>aspectratio</sender>
- <signal>toggled(bool)</signal>
- <receiver>heightUnit</receiver>
- <slot>setDisabled(bool)</slot>
- <hints>
- <hint type="sourcelabel" >
- <x>337</x>
- <y>193</y>
- </hint>
- <hint type="destinationlabel" >
- <x>337</x>
- <y>167</y>
- </hint>
- </hints>
- </connection>
</connections>
</ui>
* Licence details can be found in the file COPYING.
*
* \author Angus Leeming
+ * \author Richard Heck
*
* Full author contact details are available in file CREDITS.
*/
}
+LengthAutoValidator::LengthAutoValidator(QWidget * parent)
+ : LengthValidator(parent)
+{}
+
+
+QValidator::State LengthAutoValidator::validate(QString & qtext, int & dummy) const
+{
+ string const text = fromqstr(qtext);
+ if (text == "auto")
+ return QValidator::Acceptable;
+ return LengthValidator::validate(qtext, dummy);
+}
+
+
+LengthAutoValidator * unsignedLengthAutoValidator(QLineEdit * ed)
+{
+ LengthAutoValidator * v = new LengthAutoValidator(ed);
+ v->setBottom(LyXLength());
+ return v;
+}
+
+
+DoubleAutoValidator::DoubleAutoValidator(QWidget * parent) :
+ QDoubleValidator(parent) {}
+
+
+DoubleAutoValidator::DoubleAutoValidator(double bottom,
+ double top, int decimals, QObject * parent) :
+ QDoubleValidator(bottom, top, decimals, parent) {}
+
+
+QValidator::State DoubleAutoValidator::validate(QString & input, int & pos) const {
+ string const text = fromqstr(input);
+ if (text == "auto")
+ return QValidator::Acceptable;
+ return QDoubleValidator::validate(input, pos);
+}
+
+
PathValidator::PathValidator(bool acceptable_if_empty,
QWidget * parent)
: QValidator(parent),
* Licence details can be found in the file COPYING.
*
* \author Angus Leeming
+ * \author Richard Heck
*
* Full author contact details are available in file CREDITS.
*
/// @returns a new @c LengthValidator that does not accept negative lengths.
LengthValidator * unsignedLengthValidator(QLineEdit *);
+//FIXME This should be generalized to take "text" as part of the
+//constructor and so to set what text we check for, rather than
+//hard-coding it as "auto". But see qt_helpers.h for reasons this
+//is not so trivial and an idea about how to do it. (RGH)
+/** A class to ascertain whether the data passed to the @c validate()
+ * member function can be interpretted as a LyXGlueLength or is "auto".
+ */
+class LengthAutoValidator : public LengthValidator
+{
+ Q_OBJECT
+ public:
+ /// Define a validator for widget @c parent.
+ LengthAutoValidator(QWidget * parent);
+
+ /** @returns QValidator::Acceptable if @c data is a LyXGlueLength
+ * or is "auto". If not, returns QValidator::Intermediate.
+ */
+ QValidator::State validate(QString & data, int &) const;
+};
+
+/// @returns a new @c LengthAutoValidator that does not accept negative lengths.
+LengthAutoValidator * unsignedLengthAutoValidator(QLineEdit *);
+
+//FIXME As above, this should really take a text argument.
+/**
+ * A class to determine whether the passed is a double
+ * or is "auto".
+ *
+ */
+class DoubleAutoValidator : public QDoubleValidator {
+ Q_OBJECT
+ public:
+ DoubleAutoValidator(QWidget * parent);
+ DoubleAutoValidator(double bottom, double top, int decimals,
+ QObject * parent);
+ QValidator::State validate(QString & input, int & pos) const;
+};
// Forward declarations
class LyXRC;