+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"),
#include "QBox.h"
+#include "checkedwidgets.h"
#include "lengthcombo.h"
#include "QBoxDialog.h"
#include "qt_helpers.h"
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);
}
int i = 0;
bool spec = false;
QString special = dialog_->widthUnitsLC->currentText();
+ QString value = dialog_->widthED->text();
if (special == qt_("Height")) {
i = 1;
spec = true;
} 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
i = 0;
spec = false;
special = dialog_->heightUnitsLC->currentText();
+ value = dialog_->heightED->text();
if (special == qt_("Height")) {
i = 1;
spec = true;
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
#include "QBoxDialog.h"
#include "lengthcombo.h"
+#include "lengthvalidator.h"
#include "QBox.h"
#include "qt_helpers.h"
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)
form, SLOT(slotApply()));
connect(closePB, SIGNAL(clicked()),
form, SLOT(slotClose()));
+
+ heightED->setValidator(unsignedLengthValidator(heightED));
+ widthED->setValidator(unsignedLengthValidator(widthED));
}
#include "QGraphics.h"
+#include "checkedwidgets.h"
#include "lengthcombo.h"
#include "QGraphicsDialog.h"
#include "Qt2BC.h"
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);
}
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;
-}
-
}
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);
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
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();
#include "QGraphics.h"
#include "lengthcombo.h"
+#include "lengthvalidator.h"
#include "qt_helpers.h"
#include "debug.h"
#include <qpushbutton.h>
#include <qlineedit.h>
+#include <qvalidator.h>
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)
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));
}
#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>
}
+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)
{
#include "lyxlength.h"
class LengthCombo;
+class QComboBox;
class QLineEdit;
class QString;
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,