mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Length validators for the graphics and box dialogs
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9320 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
59248bccd2
commit
fb9f8d569a
@ -1,3 +1,13 @@
|
||||
2004-11-27 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
|
||||
|
||||
* qt_helpers.[Ch]: new member function widgetsToLength
|
||||
for ordinary QComboBoxes
|
||||
* QGraphics.C:
|
||||
* QGraphicsDialog.C: use new member function. Add length
|
||||
validator
|
||||
* QBox.C:
|
||||
* QBoxDialog.C: Add length validator
|
||||
|
||||
2004-11-27 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
|
||||
|
||||
* ui/QTabularDialogBase.ui: Rename button ("Default" to "Set"),
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
#include "QBox.h"
|
||||
|
||||
#include "checkedwidgets.h"
|
||||
#include "lengthcombo.h"
|
||||
#include "QBoxDialog.h"
|
||||
#include "qt_helpers.h"
|
||||
@ -82,6 +83,10 @@ void QBox::build_dialog()
|
||||
bcview().setOK(dialog_->okPB);
|
||||
bcview().setApply(dialog_->applyPB);
|
||||
bcview().setCancel(dialog_->closePB);
|
||||
|
||||
// initialize the length validator
|
||||
addCheckedLineEdit(bcview(), dialog_->widthED, dialog_->widthLA);
|
||||
addCheckedLineEdit(bcview(), dialog_->heightED, dialog_->heightLA);
|
||||
}
|
||||
|
||||
|
||||
@ -179,6 +184,7 @@ void QBox::apply()
|
||||
int i = 0;
|
||||
bool spec = false;
|
||||
QString special = dialog_->widthUnitsLC->currentText();
|
||||
QString value = dialog_->widthED->text();
|
||||
if (special == qt_("Height")) {
|
||||
i = 1;
|
||||
spec = true;
|
||||
@ -191,12 +197,17 @@ void QBox::apply()
|
||||
} else if (special == qt_("Width")) {
|
||||
i = 4;
|
||||
spec = true;
|
||||
}
|
||||
// the user might insert a non-special value in the line edit
|
||||
if (isValidLength(fromqstr(value))) {
|
||||
i = 0;
|
||||
spec = false;
|
||||
}
|
||||
controller().params().special = ids_spec_[i];
|
||||
|
||||
string width;
|
||||
if (spec) {
|
||||
width = fromqstr(dialog_->widthED->text());
|
||||
width = fromqstr(value);
|
||||
// beware: bogosity! the unit is simply ignored in this case
|
||||
width += "in";
|
||||
} else
|
||||
@ -207,6 +218,7 @@ void QBox::apply()
|
||||
i = 0;
|
||||
spec = false;
|
||||
special = dialog_->heightUnitsLC->currentText();
|
||||
value = dialog_->heightED->text();
|
||||
if (special == qt_("Height")) {
|
||||
i = 1;
|
||||
spec = true;
|
||||
@ -220,11 +232,16 @@ void QBox::apply()
|
||||
i = 4;
|
||||
spec = true;
|
||||
}
|
||||
// the user might insert a non-special value in the line edit
|
||||
if (isValidLength(fromqstr(value))) {
|
||||
i = 0;
|
||||
spec = false;
|
||||
}
|
||||
controller().params().height_special = ids_spec_[i];
|
||||
|
||||
string height;
|
||||
if (spec) {
|
||||
height = fromqstr(dialog_->heightED->text());
|
||||
if (spec && !isValidLength(fromqstr(dialog_->heightED->text()))) {
|
||||
height = fromqstr(value);
|
||||
// beware: bogosity! the unit is simply ignored in this case
|
||||
height += "in";
|
||||
} else
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "QBoxDialog.h"
|
||||
|
||||
#include "lengthcombo.h"
|
||||
#include "lengthvalidator.h"
|
||||
#include "QBox.h"
|
||||
#include "qt_helpers.h"
|
||||
|
||||
@ -23,6 +24,18 @@
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
namespace {
|
||||
|
||||
LengthValidator * unsignedLengthValidator(QLineEdit * ed)
|
||||
{
|
||||
LengthValidator * v = new LengthValidator(ed);
|
||||
v->setBottom(LyXLength());
|
||||
return v;
|
||||
}
|
||||
|
||||
} // namespace anon
|
||||
|
||||
|
||||
QBoxDialog::QBoxDialog(QBox * form)
|
||||
: QBoxDialogBase(0, 0, false, 0),
|
||||
form_(form)
|
||||
@ -35,6 +48,9 @@ QBoxDialog::QBoxDialog(QBox * form)
|
||||
form, SLOT(slotApply()));
|
||||
connect(closePB, SIGNAL(clicked()),
|
||||
form, SLOT(slotClose()));
|
||||
|
||||
heightED->setValidator(unsignedLengthValidator(heightED));
|
||||
widthED->setValidator(unsignedLengthValidator(widthED));
|
||||
}
|
||||
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
#include "QGraphics.h"
|
||||
|
||||
#include "checkedwidgets.h"
|
||||
#include "lengthcombo.h"
|
||||
#include "QGraphicsDialog.h"
|
||||
#include "Qt2BC.h"
|
||||
@ -105,6 +106,16 @@ void QGraphics::build_dialog()
|
||||
bcview().addReadOnly(dialog_->origin);
|
||||
bcview().addReadOnly(dialog_->latexoptions);
|
||||
bcview().addReadOnly(dialog_->getPB);
|
||||
|
||||
// initialize the length validator
|
||||
addCheckedLineEdit(bcview(), dialog_->width, dialog_->sizewidthL_2);
|
||||
addCheckedLineEdit(bcview(), dialog_->height, dialog_->sizeheightL_2);
|
||||
addCheckedLineEdit(bcview(), dialog_->displayscale, dialog_->scaleLA);
|
||||
addCheckedLineEdit(bcview(), dialog_->angle, dialog_->angleL_2);
|
||||
addCheckedLineEdit(bcview(), dialog_->lbX, dialog_->xL);
|
||||
addCheckedLineEdit(bcview(), dialog_->lbY, dialog_->yL);
|
||||
addCheckedLineEdit(bcview(), dialog_->rtX, dialog_->xL_2);
|
||||
addCheckedLineEdit(bcview(), dialog_->rtY, dialog_->yL_2);
|
||||
}
|
||||
|
||||
|
||||
@ -117,15 +128,6 @@ int getItemNo(vector<string> v, string const & s) {
|
||||
return (cit != v.end()) ? int(cit - v.begin()) : 0;
|
||||
}
|
||||
|
||||
// returns the number of the unit in the array unit_name,
|
||||
// which is defined in lengthcommon.C
|
||||
int getUnitNo(char const * const c[], string const & s) {
|
||||
int i = 0;
|
||||
while (i < num_units && s != c[i])
|
||||
++i;
|
||||
return (i < num_units) ? i : 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -268,10 +270,8 @@ void QGraphics::update_contents()
|
||||
dialog_->widthUnit->setCurrentItem(unit_ + 1);
|
||||
}
|
||||
// 2. the height (a lengthgcombo type)
|
||||
dialog_->height->setText(toqstr(tostr(igp.height.value())));
|
||||
LyXLength::UNIT unit_ = (igp.height.value() > 0.0) ?
|
||||
igp.height.unit() : unitDefault;
|
||||
dialog_->heightUnit->setCurrentItem(unit_);
|
||||
lengthToWidgets(dialog_->height, dialog_->heightUnit,
|
||||
igp.height.asString(), unitDefault);
|
||||
|
||||
// enable height input in case of non "Scale%" as width-unit
|
||||
bool use_height = (dialog_->widthUnit->currentItem() > 0);
|
||||
@ -360,11 +360,10 @@ void QGraphics::apply()
|
||||
igp.display = lyx::graphics::NoDisplay;
|
||||
|
||||
string value = fromqstr(dialog_->width->text());
|
||||
if (dialog_->widthUnit->currentItem() > 0) {
|
||||
if (dialog_->widthUnit->currentItem() > 0 || isValidLength(value)) {
|
||||
// width/height combination
|
||||
QString const text = dialog_->widthUnit->currentText();
|
||||
int const unitNo = getUnitNo(unit_name_gui, fromqstr(text));
|
||||
igp.width = LyXLength(value + unit_name_ltx[unitNo]);
|
||||
igp.width =
|
||||
widgetsToLength(dialog_->width, dialog_->widthUnit);
|
||||
igp.scale = 0.0;
|
||||
} else {
|
||||
// scaling instead of a width
|
||||
@ -372,9 +371,8 @@ void QGraphics::apply()
|
||||
igp.width = LyXLength();
|
||||
}
|
||||
value = fromqstr(dialog_->height->text());
|
||||
QString text = dialog_->heightUnit->currentText();
|
||||
int const unitNo = getUnitNo(unit_name_gui, fromqstr(text));
|
||||
igp.height = LyXLength(value + unit_name_ltx[unitNo]);
|
||||
igp.height =
|
||||
LyXLength(widgetsToLength(dialog_->height, dialog_->heightUnit));
|
||||
|
||||
igp.keepAspectRatio = dialog_->aspectratio->isChecked();
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "QGraphics.h"
|
||||
|
||||
#include "lengthcombo.h"
|
||||
#include "lengthvalidator.h"
|
||||
#include "qt_helpers.h"
|
||||
|
||||
#include "debug.h"
|
||||
@ -23,6 +24,7 @@
|
||||
|
||||
#include <qpushbutton.h>
|
||||
#include <qlineedit.h>
|
||||
#include <qvalidator.h>
|
||||
|
||||
|
||||
using std::string;
|
||||
@ -30,6 +32,19 @@ using std::string;
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
LengthValidator * unsignedLengthValidator(QLineEdit * ed)
|
||||
{
|
||||
LengthValidator * v = new LengthValidator(ed);
|
||||
v->setBottom(LyXLength());
|
||||
return v;
|
||||
}
|
||||
|
||||
} // namespace anon
|
||||
|
||||
|
||||
QGraphicsDialog::QGraphicsDialog(QGraphics * form)
|
||||
: QGraphicsDialogBase(0, 0, false, 0),
|
||||
form_(form)
|
||||
@ -44,6 +59,18 @@ QGraphicsDialog::QGraphicsDialog(QGraphics * form)
|
||||
form, SLOT(slotRestore()));
|
||||
connect(editPB, SIGNAL(clicked()),
|
||||
this, SLOT(edit_clicked()));
|
||||
|
||||
angle->setValidator(new QDoubleValidator(-360, 360, 2, angle));
|
||||
|
||||
lbX->setValidator(new QIntValidator(lbX));
|
||||
lbY->setValidator(new QIntValidator(lbY));
|
||||
rtX->setValidator(new QIntValidator(rtX));
|
||||
rtY->setValidator(new QIntValidator(rtY));
|
||||
|
||||
displayscale->setValidator(new QDoubleValidator(0, 1000, 2,
|
||||
displayscale));
|
||||
height->setValidator(unsignedLengthValidator(height));
|
||||
width->setValidator(unsignedLengthValidator(width));
|
||||
}
|
||||
|
||||
|
||||
|
@ -14,11 +14,13 @@
|
||||
#include "lengthcombo.h"
|
||||
#include "qt_helpers.h"
|
||||
|
||||
#include "lengthcommon.h"
|
||||
#include "gettext.h"
|
||||
|
||||
#include "support/lstrings.h"
|
||||
#include "support/tostr.h"
|
||||
|
||||
#include <qcombobox.h>
|
||||
#include <qlineedit.h>
|
||||
#include <qtextcodec.h>
|
||||
|
||||
@ -78,6 +80,22 @@ string widgetsToLength(QLineEdit const * input, LengthCombo const * combo)
|
||||
}
|
||||
|
||||
|
||||
LyXLength widgetsToLength(QLineEdit const * input, QComboBox const * combo)
|
||||
{
|
||||
QString length = input->text();
|
||||
if (length.isEmpty())
|
||||
return LyXLength();
|
||||
|
||||
// don't return unit-from-choice if the input(field) contains a unit
|
||||
if (isValidGlueLength(fromqstr(length)))
|
||||
return LyXLength(fromqstr(length));
|
||||
|
||||
LyXLength::UNIT unit = unitFromString(fromqstr(combo->currentText()));
|
||||
|
||||
return LyXLength(length.toDouble(), unit);
|
||||
}
|
||||
|
||||
|
||||
void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
|
||||
string const & len, LyXLength::UNIT defaultUnit)
|
||||
{
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "lyxlength.h"
|
||||
|
||||
class LengthCombo;
|
||||
class QComboBox;
|
||||
class QLineEdit;
|
||||
class QString;
|
||||
|
||||
@ -24,8 +25,10 @@ std::string makeFontName(std::string const & family, std::string const & foundry
|
||||
|
||||
std::pair<std::string,std::string> parseFontName(std::string const & name);
|
||||
|
||||
/// method to get a LyXLength from widgets
|
||||
/// method to get a LyXLength from widgets (LengthCombo)
|
||||
std::string widgetsToLength(QLineEdit const * input, LengthCombo const * combo);
|
||||
/// method to get a LyXLength from widgets (QComboBox)
|
||||
LyXLength widgetsToLength(QLineEdit const * input, QComboBox const * combo);
|
||||
|
||||
/// method to set widgets from a LyXLength
|
||||
void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
|
||||
|
Loading…
Reference in New Issue
Block a user