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
This commit is contained in:
Richard Heck 2007-04-05 14:58:15 +00:00
parent 21cc83ef2b
commit 11697004e8
10 changed files with 347 additions and 144 deletions

View File

@ -6,6 +6,7 @@
* \author John Levon * \author John Levon
* \author Edwin Leuven * \author Edwin Leuven
* \author Herbert Voß * \author Herbert Voß
* \author Richard Heck
* *
* Full author contact details are available in file CREDITS. * Full author contact details are available in file CREDITS.
*/ */
@ -90,8 +91,9 @@ void QGraphics::build_dialog()
bcview().addReadOnly(dialog_->getPB); bcview().addReadOnly(dialog_->getPB);
// initialize the length validator // initialize the length validator
addCheckedLineEdit(bcview(), dialog_->Width, dialog_->widthL); addCheckedLineEdit(bcview(), dialog_->Scale, dialog_->scaleCB);
addCheckedLineEdit(bcview(), dialog_->Height, dialog_->heightL); addCheckedLineEdit(bcview(), dialog_->Width, dialog_->WidthCB);
addCheckedLineEdit(bcview(), dialog_->Height, dialog_->HeightCB);
addCheckedLineEdit(bcview(), dialog_->displayscale, dialog_->scaleLA); addCheckedLineEdit(bcview(), dialog_->displayscale, dialog_->scaleLA);
addCheckedLineEdit(bcview(), dialog_->angle, dialog_->angleL); addCheckedLineEdit(bcview(), dialog_->angle, dialog_->angleL);
addCheckedLineEdit(bcview(), dialog_->lbX, dialog_->xL); addCheckedLineEdit(bcview(), dialog_->lbX, dialog_->xL);
@ -225,19 +227,41 @@ void QGraphics::update_contents()
dialog_->displayGB->setChecked(igp.display != graphics::NoDisplay); dialog_->displayGB->setChecked(igp.display != graphics::NoDisplay);
// the output section (width/height) // the output section (width/height)
dialog_->Scale->setText(toqstr(igp.scale)); dialog_->Scale->setText(toqstr(igp.scale));
//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);
lengthToWidgets(dialog_->Width, dialog_->widthUnit, lengthAutoToWidgets(dialog_->Width, dialog_->widthUnit, igp.width,
igp.width.asString(), unitDefault); 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);
lengthToWidgets(dialog_->Height, dialog_->heightUnit, lengthAutoToWidgets(dialog_->Height, dialog_->heightUnit, igp.height,
igp.height.asString(), unitDefault); 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_->aspectratio->setChecked(igp.keepAspectRatio); dialog_->scaleCB->setEnabled(!widthChecked && !heightChecked);
dialog_->WidthCB->setEnabled(!scaleChecked);
dialog_->HeightCB->setEnabled(!scaleChecked);
dialog_->aspectratio->setEnabled(widthChecked && heightChecked);
dialog_->scaleCB->setChecked(!igp.scale.empty() || igp.width.empty()); dialog_->setAutoText();
dialog_->Scale->setEnabled(!igp.scale.empty() || igp.width.empty());
dialog_->angle->setText(toqstr(igp.rotateAngle)); dialog_->angle->setText(toqstr(igp.rotateAngle));
@ -320,19 +344,27 @@ void QGraphics::apply()
if (!dialog_->displayGB->isChecked()) if (!dialog_->displayGB->isChecked())
igp.display = graphics::NoDisplay; igp.display = graphics::NoDisplay;
if (dialog_->scaleCB->isChecked() //the graphics section
&& !dialog_->Scale->text().isEmpty()) { if (dialog_->scaleCB->isChecked() && !dialog_->Scale->text().isEmpty()) {
igp.scale = fromqstr(dialog_->Scale->text()); igp.scale = fromqstr(dialog_->Scale->text());
igp.width = LyXLength("0pt");
igp.height = LyXLength("0pt");
igp.keepAspectRatio = false;
} else { } else {
igp.scale = string(); 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.noUnzip = dialog_->unzipCB->isChecked();
igp.lyxscale = convert<int>(fromqstr(dialog_->displayscale->text())); igp.lyxscale = convert<int>(fromqstr(dialog_->displayscale->text()));

View File

@ -6,6 +6,7 @@
* \author John Levon * \author John Levon
* \author Herbert Voß * \author Herbert Voß
* \author Abdelrazak Younes * \author Abdelrazak Younes
* \author Richard Heck
* *
* Full author contact details are available in file CREDITS. * Full author contact details are available in file CREDITS.
*/ */
@ -41,6 +42,7 @@ QGraphicsDialog::QGraphicsDialog(QGraphics * form)
: form_(form) : form_(form)
{ {
setupUi(this); setupUi(this);
//main buttons
connect(okPB, SIGNAL( clicked() ), connect(okPB, SIGNAL( clicked() ),
form, SLOT( slotOK() ) ); form, SLOT( slotOK() ) );
connect(applyPB, SIGNAL( clicked() ), connect(applyPB, SIGNAL( clicked() ),
@ -49,51 +51,47 @@ QGraphicsDialog::QGraphicsDialog(QGraphics * form)
form, SLOT( slotClose() ) ); form, SLOT( slotClose() ) );
connect(restorePB, SIGNAL( clicked() ), connect(restorePB, SIGNAL( clicked() ),
form, SLOT( slotRestore() ) ); form, SLOT( slotRestore() ) );
//graphics pane
connect(filename, SIGNAL( textChanged(const QString&) ), connect(filename, SIGNAL( textChanged(const QString&) ),
this, SLOT( change_adaptor() ) ); this, SLOT( change_adaptor() ) );
connect(subcaption, SIGNAL( textChanged(const QString&) ), connect(WidthCB, SIGNAL( clicked() ),
this, SLOT( change_adaptor() ) ); this, SLOT( change_adaptor() ) );
connect(HeightCB, SIGNAL( clicked() ),
// 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&) ),
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&) ),
this, SLOT( change_adaptor() ) ); this, SLOT( change_adaptor() ) );
connect(Width, SIGNAL( textChanged(const QString&) ), connect(Width, SIGNAL( textChanged(const QString&) ),
this, SLOT( change_adaptor() ) ); 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&) ), connect(Height, SIGNAL( textChanged(const QString&) ),
this, SLOT( change_adaptor() ) ); this, SLOT( change_adaptor() ) );
connect(heightUnit, SIGNAL( selectionChanged(lyx::LyXLength::UNIT) ), connect(heightUnit, SIGNAL( selectionChanged(lyx::LyXLength::UNIT) ),
this, SLOT( change_adaptor() ) ); this, SLOT( change_adaptor() ) );
connect(widthUnit, SIGNAL( selectionChanged(lyx::LyXLength::UNIT) ), connect(widthUnit, SIGNAL( selectionChanged(lyx::LyXLength::UNIT) ),
this, SLOT( change_adaptor() ) ); this, SLOT( change_adaptor() ) );
connect(aspectratio, SIGNAL( stateChanged(int) ),
this, SLOT( change_adaptor() ) );
connect(angle, SIGNAL( textChanged(const QString&) ), connect(angle, SIGNAL( textChanged(const QString&) ),
this, SLOT( change_adaptor() ) ); this, SLOT( change_adaptor() ) );
connect(origin, SIGNAL( activated(int) ), connect(origin, SIGNAL( activated(int) ),
this, SLOT( change_adaptor() ) ); this, SLOT( change_adaptor() ) );
connect(getPB, SIGNAL( clicked() ),
this, SLOT( change_adaptor() ) );
connect(scaleCB, SIGNAL( clicked() ), connect(scaleCB, SIGNAL( clicked() ),
this, SLOT(change_adaptor()) ); this, SLOT(change_adaptor()) );
connect(Scale, SIGNAL( textChanged(const QString&) ), connect(Scale, SIGNAL( textChanged(const QString&) ),
this, SLOT( change_adaptor() ) ); 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&) ), connect(lbY, SIGNAL( textChanged(const QString&) ),
this, SLOT( change_bb() ) ); this, SLOT( change_bb() ) );
connect(lbYunit, SIGNAL( activated(int) ), connect(lbYunit, SIGNAL( activated(int) ),
@ -102,7 +100,6 @@ QGraphicsDialog::QGraphicsDialog(QGraphics * form)
this, SLOT( change_bb() ) ); this, SLOT( change_bb() ) );
connect(rtYunit, SIGNAL( activated(int) ), connect(rtYunit, SIGNAL( activated(int) ),
this, SLOT( change_bb() ) ); this, SLOT( change_bb() ) );
connect(lbX, SIGNAL( textChanged(const QString&) ), connect(lbX, SIGNAL( textChanged(const QString&) ),
this, SLOT( change_bb() ) ); this, SLOT( change_bb() ) );
connect(lbXunit, SIGNAL( activated(int) ), connect(lbXunit, SIGNAL( activated(int) ),
@ -111,20 +108,39 @@ QGraphicsDialog::QGraphicsDialog(QGraphics * form)
this, SLOT( change_bb() ) ); this, SLOT( change_bb() ) );
connect(rtXunit, SIGNAL( activated(int) ), connect(rtXunit, SIGNAL( activated(int) ),
this, SLOT( change_bb() ) ); this, SLOT( change_bb() ) );
connect(getPB, SIGNAL( clicked() ),
angle->setValidator(new QDoubleValidator(-360, 360, 2, angle)); this, SLOT( change_adaptor() ) );
lbX->setValidator(new QDoubleValidator(lbX)); lbX->setValidator(new QDoubleValidator(lbX));
lbY->setValidator(new QDoubleValidator(lbY)); lbY->setValidator(new QDoubleValidator(lbY));
rtX->setValidator(new QDoubleValidator(rtX)); rtX->setValidator(new QDoubleValidator(rtX));
rtY->setValidator(new QDoubleValidator(rtY)); 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)); 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;
//FIXME: There is no scale text when the scale was "100" before keepaspectratio if (!Scale->isEnabled() && Scale->text() != "100")
//was checked and then scaleCB is checked again Scale->setText(QString("auto"));
//When somebody implements a void on toggling keepaspectration, this
//case should be handled there. setAutoTextCB(WidthCB, Width, widthUnit);
if (scaleCB->isChecked() && Scale->text() == "") setAutoTextCB(HeightCB, Height, heightUnit);
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);
} }
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)
{
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 frontend
} // namespace lyx } // namespace lyx

View File

@ -6,6 +6,7 @@
* *
* \author John Levon * \author John Levon
* \author Herbert Voß * \author Herbert Voß
* \author Richard Heck
* *
* Full author contact details are available in file CREDITS. * Full author contact details are available in file CREDITS.
*/ */
@ -28,7 +29,7 @@ class QGraphicsDialog : public QDialog, public Ui::QGraphicsUi {
Q_OBJECT Q_OBJECT
public: public:
QGraphicsDialog(QGraphics * form); QGraphicsDialog(QGraphics * form);
virtual void setAutoText();
virtual void show(); virtual void show();
protected Q_SLOTS: protected Q_SLOTS:
virtual void change_adaptor(); virtual void change_adaptor();
@ -38,6 +39,8 @@ protected Q_SLOTS:
virtual void on_editPB_clicked(); virtual void on_editPB_clicked();
virtual void on_filename_textChanged(const QString &); virtual void on_filename_textChanged(const QString &);
virtual void on_scaleCB_toggled(bool); virtual void on_scaleCB_toggled(bool);
virtual void on_WidthCB_toggled(bool);
virtual void on_HeightCB_toggled(bool);
protected: protected:
virtual void closeEvent(QCloseEvent * e); virtual void closeEvent(QCloseEvent * e);
private: private:

View File

@ -20,7 +20,7 @@ namespace lyx {
namespace frontend { namespace frontend {
void addCheckedLineEdit(BCView & bcview, void addCheckedLineEdit(BCView & bcview,
QLineEdit * input, QLabel * label) QLineEdit * input, QWidget * label)
{ {
bcview.addCheckedWidget(new CheckedLineEdit(input, 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) if (valid)
input->setPalette(QPalette()); input->setPalette(QPalette());
@ -60,7 +60,7 @@ void setWidget(bool valid, QLineEdit * input, QLabel * label)
} // namespace anon } // namespace anon
CheckedLineEdit::CheckedLineEdit(QLineEdit * input, QLabel * label) CheckedLineEdit::CheckedLineEdit(QLineEdit * input, QWidget * label)
: input_(input), label_(label) : input_(input), label_(label)
{} {}

View File

@ -14,18 +14,18 @@
#include "BCView.h" #include "BCView.h"
class QLabel; class QWidget;
class QLineEdit; class QLineEdit;
namespace lyx { namespace lyx {
namespace frontend { namespace frontend {
void addCheckedLineEdit(BCView & bcview, void addCheckedLineEdit(BCView & bcview,
QLineEdit * input, QLabel * label = 0); QLineEdit * input, QWidget * label = 0);
class CheckedLineEdit : public CheckedWidget { class CheckedLineEdit : public CheckedWidget {
public: public:
CheckedLineEdit(QLineEdit * input, QLabel * label = 0); CheckedLineEdit(QLineEdit * input, QWidget * label = 0);
private: private:
/// ///
@ -33,7 +33,7 @@ private:
/// ///
QLineEdit * input_; QLineEdit * input_;
QLabel * label_; QWidget * label_;
}; };
} // namespace frontend } // namespace frontend

View File

@ -5,6 +5,7 @@
* *
* \author Dekel Tsur * \author Dekel Tsur
* \author Jürgen Spitzmüller * \author Jürgen Spitzmüller
* \author Richard Heck
* *
* Full author contact details are available in file CREDITS. * Full author contact details are available in file CREDITS.
*/ */
@ -24,6 +25,7 @@
#include "debug.h" #include "debug.h"
#include <QComboBox> #include <QComboBox>
#include <QCheckBox>
#include <qlineedit.h> #include <qlineedit.h>
#include <qtextcodec.h> #include <qtextcodec.h>
@ -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<string>(LyXLength(len).value())));
}
void lengthToWidgets(QLineEdit * input, LengthCombo * combo, void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
string const & len, LyXLength::UNIT defaultUnit) string const & len, LyXLength::UNIT defaultUnit)
{ {
@ -103,12 +113,33 @@ void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
combo->setCurrentItem(defaultUnit); combo->setCurrentItem(defaultUnit);
input->setText(toqstr(len)); input->setText(toqstr(len));
} else { } else {
combo->setCurrentItem(LyXLength(len).unit()); lengthToWidgets(input, combo, LyXLength(len), defaultUnit);
input->setText(toqstr(convert<string>(LyXLength(len).value())));
} }
} }
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 *) QString const qt_(char const * str, const char *)
{ {
return toqstr(_(str)); return toqstr(_(str));

View File

@ -5,6 +5,7 @@
* Licence details can be found in the file COPYING. * Licence details can be found in the file COPYING.
* *
* \author Dekel Tsur * \author Dekel Tsur
* \author Richard Heck
* *
* Full author contact details are available in file CREDITS. * Full author contact details are available in file CREDITS.
*/ */
@ -17,11 +18,11 @@
#include "support/qstring_helpers.h" #include "support/qstring_helpers.h"
#include <QString> #include <QString>
#include <utility> #include <utility>
class QComboBox; class QComboBox;
class QLineEdit; class QLineEdit;
class QCheckBox;
class LengthCombo; class LengthCombo;
@ -36,9 +37,35 @@ std::string widgetsToLength(QLineEdit const * input, LengthCombo const * combo);
/// method to get a LyXLength from widgets (QComboBox) /// method to get a LyXLength from widgets (QComboBox)
LyXLength widgetsToLength(QLineEdit const * input, QComboBox const * combo); 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 /// 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, void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
std::string const & len, LyXLength::UNIT default_unit); 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 /// format a string to the given width
docstring const formatted(docstring const & text, int w = 80); docstring const formatted(docstring const & text, int w = 80);

View File

@ -232,15 +232,15 @@
</widget> </widget>
</item> </item>
<item row="2" column="0" > <item row="2" column="0" >
<widget class="QLabel" name="heightL" > <widget class="QCheckBox" name="HeightCB" >
<property name="enabled" > <property name="enabled" >
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="text" > <property name="toolTip" >
<string>&amp;Height:</string> <string>Sets height of graphic. Leave unchecked to set automatically.</string>
</property> </property>
<property name="buddy" > <property name="text" >
<cstring>Height</cstring> <string>Set &amp;height:</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -252,15 +252,15 @@
</widget> </widget>
</item> </item>
<item row="1" column="0" > <item row="1" column="0" >
<widget class="QLabel" name="widthL" > <widget class="QCheckBox" name="WidthCB" >
<property name="enabled" > <property name="enabled" >
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="text" > <property name="toolTip" >
<string>&amp;Width:</string> <string>Sets width of graphic. Leave unchecked to set automatically.</string>
</property> </property>
<property name="buddy" > <property name="text" >
<cstring>Width</cstring> <string>Set &amp;width:</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -270,7 +270,7 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="toolTip" > <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>
<property name="text" > <property name="text" >
<string>&amp;Maintain aspect ratio</string> <string>&amp;Maintain aspect ratio</string>
@ -448,7 +448,7 @@
</widget> </widget>
<widget class="QWidget" name="ExtraOptions" > <widget class="QWidget" name="ExtraOptions" >
<attribute name="title" > <attribute name="title" >
<string>E&amp;xtra options</string> <string>LaTe&amp;X and LyX options</string>
</attribute> </attribute>
<layout class="QGridLayout" > <layout class="QGridLayout" >
<property name="margin" > <property name="margin" >
@ -766,8 +766,10 @@
<tabstop>editPB</tabstop> <tabstop>editPB</tabstop>
<tabstop>scaleCB</tabstop> <tabstop>scaleCB</tabstop>
<tabstop>Scale</tabstop> <tabstop>Scale</tabstop>
<tabstop>WidthCB</tabstop>
<tabstop>Width</tabstop> <tabstop>Width</tabstop>
<tabstop>widthUnit</tabstop> <tabstop>widthUnit</tabstop>
<tabstop>HeightCB</tabstop>
<tabstop>Height</tabstop> <tabstop>Height</tabstop>
<tabstop>heightUnit</tabstop> <tabstop>heightUnit</tabstop>
<tabstop>aspectratio</tabstop> <tabstop>aspectratio</tabstop>
@ -801,53 +803,5 @@
</includes> </includes>
<resources/> <resources/>
<connections> <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> </connections>
</ui> </ui>

View File

@ -4,6 +4,7 @@
* Licence details can be found in the file COPYING. * Licence details can be found in the file COPYING.
* *
* \author Angus Leeming * \author Angus Leeming
* \author Richard Heck
* *
* Full author contact details are available in file CREDITS. * 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, PathValidator::PathValidator(bool acceptable_if_empty,
QWidget * parent) QWidget * parent)
: QValidator(parent), : QValidator(parent),

View File

@ -5,6 +5,7 @@
* Licence details can be found in the file COPYING. * Licence details can be found in the file COPYING.
* *
* \author Angus Leeming * \author Angus Leeming
* \author Richard Heck
* *
* Full author contact details are available in file CREDITS. * 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. /// @returns a new @c LengthValidator that does not accept negative lengths.
LengthValidator * unsignedLengthValidator(QLineEdit *); 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 // Forward declarations
class LyXRC; class LyXRC;