From: Richard Heck Date: Thu, 5 Apr 2007 14:58:15 +0000 (+0000) Subject: Fix for bug 3215. All changes in src/frontends/qt4/. X-Git-Tag: 1.6.10~10330 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=11697004e8d271cd135b2e664115c13ad7c6261b;p=features.git Fix for bug 3215. All changes in src/frontends/qt4/. Changed dialog and added routines to deal with an "auto" label in cases where defaults are used. ui/MarginsUi.ui: Changed labels for width and height to checkboxes. Removed connections. checkwidgets.[Ch]: Extended checkedLineEdit routines to take a QWidget. qt_helpers.[Ch]: Added void lengthToWidgets(QLineEdit *, LengthCombo *, LyXLength const &, LyXLength::UNIT) Added void lengthAutoToWidgets(QLineEdit *, LengthCombo *, LyXLength const &, LyXLength::UNIT) Added void setAutoTextCB(QCheckBox *, QLineEdit *, LengthCombo *) validators.[Ch]: Added class LengthAutoValidator : public LengthValidator Added class DoubleAutoValidator : public QDoubleValidator QGraphicsDialog.[Ch] Added virtual void setAutoText() Added virtual void on_WidthCB_toggled(bool) Added virtual void on_HeightCB_toggled(bool) Used the new functions to set "auto" in default cases and toggle checkboxes as needed. Set validator for scale. Re-organized connect routines. QGraphics.C: Completely re-worked update_contents(). Significant changes to apply(). git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17735 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/qt4/QGraphics.C b/src/frontends/qt4/QGraphics.C index 29f156ee4d..d8bd29f24e 100644 --- a/src/frontends/qt4/QGraphics.C +++ b/src/frontends/qt4/QGraphics.C @@ -6,6 +6,7 @@ * \author John Levon * \author Edwin Leuven * \author Herbert Voß + * \author Richard Heck * * Full author contact details are available in file CREDITS. */ @@ -90,8 +91,9 @@ void QGraphics::build_dialog() 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); @@ -225,19 +227,41 @@ void QGraphics::update_contents() 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)); @@ -319,20 +343,28 @@ void QGraphics::apply() 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(fromqstr(dialog_->displayscale->text())); diff --git a/src/frontends/qt4/QGraphicsDialog.C b/src/frontends/qt4/QGraphicsDialog.C index f8e9ee475a..7357d40094 100644 --- a/src/frontends/qt4/QGraphicsDialog.C +++ b/src/frontends/qt4/QGraphicsDialog.C @@ -6,6 +6,7 @@ * \author John Levon * \author Herbert Voß * \author Abdelrazak Younes + * \author Richard Heck * * Full author contact details are available in file CREDITS. */ @@ -41,6 +42,7 @@ QGraphicsDialog::QGraphicsDialog(QGraphics * form) : form_(form) { setupUi(this); + //main buttons connect(okPB, SIGNAL( clicked() ), form, SLOT( slotOK() ) ); connect(applyPB, SIGNAL( clicked() ), @@ -49,51 +51,47 @@ QGraphicsDialog::QGraphicsDialog(QGraphics * form) 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) ), @@ -102,7 +100,6 @@ QGraphicsDialog::QGraphicsDialog(QGraphics * form) 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) ), @@ -111,20 +108,39 @@ QGraphicsDialog::QGraphicsDialog(QGraphics * form) 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); } @@ -183,25 +199,87 @@ void QGraphicsDialog::on_filename_textChanged(const QString & 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 diff --git a/src/frontends/qt4/QGraphicsDialog.h b/src/frontends/qt4/QGraphicsDialog.h index 396e99d0af..2e0a0da91e 100644 --- a/src/frontends/qt4/QGraphicsDialog.h +++ b/src/frontends/qt4/QGraphicsDialog.h @@ -6,6 +6,7 @@ * * \author John Levon * \author Herbert Voß + * \author Richard Heck * * Full author contact details are available in file CREDITS. */ @@ -28,7 +29,7 @@ class QGraphicsDialog : public QDialog, public Ui::QGraphicsUi { Q_OBJECT public: QGraphicsDialog(QGraphics * form); - + virtual void setAutoText(); virtual void show(); protected Q_SLOTS: virtual void change_adaptor(); @@ -38,6 +39,8 @@ protected Q_SLOTS: 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: diff --git a/src/frontends/qt4/checkedwidgets.C b/src/frontends/qt4/checkedwidgets.C index c694ac1069..35fd180cbe 100644 --- a/src/frontends/qt4/checkedwidgets.C +++ b/src/frontends/qt4/checkedwidgets.C @@ -20,7 +20,7 @@ namespace lyx { namespace frontend { void addCheckedLineEdit(BCView & bcview, - QLineEdit * input, QLabel * label) + QLineEdit * input, QWidget * label) { bcview.addCheckedWidget(new CheckedLineEdit(input, label)); } @@ -41,7 +41,7 @@ void setWarningColor(QWidget * widget) } -void setWidget(bool valid, QLineEdit * input, QLabel * label) +void setWidget(bool valid, QLineEdit * input, QWidget * label) { if (valid) input->setPalette(QPalette()); @@ -60,7 +60,7 @@ void setWidget(bool valid, QLineEdit * input, QLabel * label) } // namespace anon -CheckedLineEdit::CheckedLineEdit(QLineEdit * input, QLabel * label) +CheckedLineEdit::CheckedLineEdit(QLineEdit * input, QWidget * label) : input_(input), label_(label) {} diff --git a/src/frontends/qt4/checkedwidgets.h b/src/frontends/qt4/checkedwidgets.h index a915a1016c..84d50509ab 100644 --- a/src/frontends/qt4/checkedwidgets.h +++ b/src/frontends/qt4/checkedwidgets.h @@ -14,18 +14,18 @@ #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: /// @@ -33,7 +33,7 @@ private: /// QLineEdit * input_; - QLabel * label_; + QWidget * label_; }; } // namespace frontend diff --git a/src/frontends/qt4/qt_helpers.C b/src/frontends/qt4/qt_helpers.C index 8c9b7a3729..e1709a2c92 100644 --- a/src/frontends/qt4/qt_helpers.C +++ b/src/frontends/qt4/qt_helpers.C @@ -5,6 +5,7 @@ * * \author Dekel Tsur * \author Jürgen Spitzmüller + * \author Richard Heck * * Full author contact details are available in file CREDITS. */ @@ -24,6 +25,7 @@ #include "debug.h" #include +#include #include #include @@ -91,6 +93,14 @@ LyXLength widgetsToLength(QLineEdit const * input, QComboBox const * combo) } +void lengthToWidgets(QLineEdit * input, LengthCombo * combo, + LyXLength const & len, LyXLength::UNIT defaultUnit) +{ + combo->setCurrentItem(LyXLength(len).unit()); + input->setText(toqstr(convert(LyXLength(len).value()))); +} + + void lengthToWidgets(QLineEdit * input, LengthCombo * combo, string const & len, LyXLength::UNIT defaultUnit) { @@ -103,12 +113,33 @@ void lengthToWidgets(QLineEdit * input, LengthCombo * combo, combo->setCurrentItem(defaultUnit); input->setText(toqstr(len)); } else { - combo->setCurrentItem(LyXLength(len).unit()); - input->setText(toqstr(convert(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)); diff --git a/src/frontends/qt4/qt_helpers.h b/src/frontends/qt4/qt_helpers.h index 5c52b1fdfa..6dbad18772 100644 --- a/src/frontends/qt4/qt_helpers.h +++ b/src/frontends/qt4/qt_helpers.h @@ -5,6 +5,7 @@ * Licence details can be found in the file COPYING. * * \author Dekel Tsur + * \author Richard Heck * * Full author contact details are available in file CREDITS. */ @@ -17,11 +18,11 @@ #include "support/qstring_helpers.h" #include - #include class QComboBox; class QLineEdit; +class QCheckBox; class LengthCombo; @@ -36,9 +37,35 @@ 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); +//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); diff --git a/src/frontends/qt4/ui/QGraphicsUi.ui b/src/frontends/qt4/ui/QGraphicsUi.ui index bd776267ec..6fd3094c3c 100644 --- a/src/frontends/qt4/ui/QGraphicsUi.ui +++ b/src/frontends/qt4/ui/QGraphicsUi.ui @@ -232,15 +232,15 @@ - + true - - &Height: + + Sets height of graphic. Leave unchecked to set automatically. - - Height + + Set &height: @@ -252,15 +252,15 @@ - + true - - &Width: + + Sets width of graphic. Leave unchecked to set automatically. - - Width + + Set &width: @@ -270,7 +270,7 @@ true - Maintain aspect ratio with largest dimension + Scale image to maximum size not exceeding width and height &Maintain aspect ratio @@ -448,7 +448,7 @@ - E&xtra options + LaTe&X and LyX options @@ -766,8 +766,10 @@ editPB scaleCB Scale + WidthCB Width widthUnit + HeightCB Height heightUnit aspectratio @@ -801,53 +803,5 @@ - - aspectratio - toggled(bool) - heightL - setDisabled(bool) - - - 201 - 193 - - - 81 - 158 - - - - - aspectratio - toggled(bool) - Height - setDisabled(bool) - - - 315 - 193 - - - 275 - 169 - - - - - aspectratio - toggled(bool) - heightUnit - setDisabled(bool) - - - 337 - 193 - - - 337 - 167 - - - diff --git a/src/frontends/qt4/validators.C b/src/frontends/qt4/validators.C index bde62fe000..3020d2420c 100644 --- a/src/frontends/qt4/validators.C +++ b/src/frontends/qt4/validators.C @@ -4,6 +4,7 @@ * Licence details can be found in the file COPYING. * * \author Angus Leeming + * \author Richard Heck * * Full author contact details are available in file CREDITS. */ @@ -92,6 +93,45 @@ LengthValidator * unsignedLengthValidator(QLineEdit * ed) } +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), diff --git a/src/frontends/qt4/validators.h b/src/frontends/qt4/validators.h index ca90785821..e003f1500d 100644 --- a/src/frontends/qt4/validators.h +++ b/src/frontends/qt4/validators.h @@ -5,6 +5,7 @@ * Licence details can be found in the file COPYING. * * \author Angus Leeming + * \author Richard Heck * * Full author contact details are available in file CREDITS. * @@ -75,6 +76,43 @@ private: /// @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;