glue length validator for qt

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9286 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Spitzmüller 2004-11-22 12:22:19 +00:00
parent 58ee70b453
commit 4c63bdbff0
6 changed files with 52 additions and 6 deletions

View File

@ -1,3 +1,11 @@
2004-11-22 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* lengthvalidator.[Ch]: add GlueLength validator
* QVSpace.C:
* QVSpaceDialog.C: use GlueLength validator
* lengthcombo.C: whitespace
2004-11-17 Lars Gullik Bjonnes <larsbj@gullik.net>
* QPrefsDialog.h: include LColor.h to satisfy concept checks.

View File

@ -19,6 +19,7 @@
#include "QVSpaceDialog.h"
#include "Qt2BC.h"
#include "checkedwidgets.h"
#include "lengthcombo.h"
#include "qt_helpers.h"
@ -150,6 +151,9 @@ void QVSpace::build_dialog()
bcview().addReadOnly(dialog_->unitCO);
bcview().addReadOnly(dialog_->keepCB);
// initialize the length validator
addCheckedLineEdit(bcview(), dialog_->valueLE, dialog_->valueL);
// remove the %-items from the unit choice
dialog_->unitCO->noPercents();
}

View File

@ -16,6 +16,7 @@
#include "QVSpace.h"
#include "lengthcombo.h"
#include "lengthvalidator.h"
#include "qt_helpers.h"
#include <qcombobox.h>
@ -27,6 +28,19 @@
namespace lyx {
namespace frontend {
namespace {
LengthValidator * unsignedLengthValidator(QLineEdit * ed)
{
LengthValidator * v = new LengthValidator(ed);
v->setBottom(LyXGlueLength());
return v;
}
} // namespace anon
QVSpaceDialog::QVSpaceDialog(QVSpace * form)
: QVSpaceDialogBase(0, 0, false, 0),
form_(form)
@ -37,6 +51,8 @@ QVSpaceDialog::QVSpaceDialog(QVSpace * form)
form_, SLOT(slotApply()));
connect(closePB, SIGNAL(clicked()),
form_, SLOT(slotClose()));
valueLE->setValidator(unsignedLengthValidator(valueLE));
}
@ -55,7 +71,7 @@ void QVSpaceDialog::change_adaptor()
void QVSpaceDialog::enableCustom(int)
{
bool const enable = spacingCO->currentItem()==5;
bool const enable = spacingCO->currentItem() == 5;
valueLE->setEnabled(enable);
unitCO->setEnabled(enable);
}

View File

@ -19,7 +19,7 @@
LengthCombo::LengthCombo(QWidget * parent, char * name)
: QComboBox(parent, name)
{
for (int i=0; i < num_units; i++)
for (int i = 0; i < num_units; i++)
insertItem(unit_name_gui[i]);
connect(this, SIGNAL(activated(int)),

View File

@ -25,16 +25,22 @@ using std::string;
LengthValidator::LengthValidator(QWidget * parent, const char * name)
: QValidator(parent, name),
no_bottom_(true)
no_bottom_(true), glue_length_(false)
{}
QValidator::State LengthValidator::validate(QString & qtext, int &) const
{
string const text = fromqstr(qtext);
if (text.empty() || isStrDbl(text))
if (!text.empty() && isStrDbl(text))
return QValidator::Acceptable;
if (glue_length_) {
LyXGlueLength gl;
return (isValidGlueLength(text, &gl)) ?
QValidator::Acceptable : QValidator::Intermediate;
}
LyXLength l;
bool const valid_length = isValidLength(text, &l);
if (!valid_length)
@ -48,8 +54,16 @@ QValidator::State LengthValidator::validate(QString & qtext, int &) const
}
void LengthValidator::setBottom(LyXLength b)
void LengthValidator::setBottom(LyXLength const & b)
{
b_ = b;
no_bottom_ = false;
}
void LengthValidator::setBottom(LyXGlueLength const & g)
{
g_ = g;
no_bottom_ = false;
glue_length_ = true;
}

View File

@ -13,6 +13,7 @@
#define LENGTHVALIDATOR_H
#include "lyxlength.h"
#include "lyxgluelength.h"
#include <qvalidator.h>
class QWidget;
@ -26,7 +27,8 @@ public:
QValidator::State validate(QString &, int &) const;
void setBottom(LyXLength);
void setBottom(LyXLength const &);
void setBottom(LyXGlueLength const &);
LyXLength bottom() const { return b_; }
private:
@ -36,7 +38,9 @@ private:
#endif
LyXLength b_;
LyXGlueLength g_;
bool no_bottom_;
bool glue_length_;
};
# endif // NOT LENGTHVALIDATOR_H