Attached is my patch to fix bug 3215 and bug 3390. After testing out the different possible solutions my patch uses a simple solution: When keepaspectratio is checken, the width and height have the same value and unit because of LaTeX's method that the smallest value is the boarder wheile the acpect ratio of the image is left when scaling. I added some comments to the code and describe it with an example in the manual to make this clear.

My patch fixes also a small problem that there was no scale factor when turning off the aspectratio option in the graphics dialog.

I tested this roughly and hope I did it right. Please test.

---

Richard Heck wrote:

but you don't really want width = height.
> Height should be proportional to width, depending upon how big
the graphic is. So, say, if the graphic is 2 in x 4in and you set width
= 1in, then height = 2 in.

I asked some people what they expect when choosing an option named aspectratio and they indeed expect this but LaTeX's (graphicx-package's) aspectratio works a bit different so I think the solution I implemented is the best in this case. The patch to the EmbeddedObjects manual describes the method with an example to make this clear.

regards Uwe
Index: lib/doc/EmbeddedObjects.lyx
===================================================================
--- lib/doc/EmbeddedObjects.lyx	(revision 17667)
+++ lib/doc/EmbeddedObjects.lyx	(working copy)
@@ -405,6 +405,22 @@
  button.
  The program can be set for every image format in the file format settings
  in LyX's preferences.
+\newline
+When you use the option 
+\family sans
+Maintain aspect ratio
+\family default
+ the width and heigth will have the same unit and value.
+ For the image treatment the smaller value of width and height will be used
+ as maximum, that means if you have for example an image with the size 10\InsetSpace \thinspace{}
+cm×20\InsetSpace \thinspace{}
+cm
+ (width×height) and you specify 10\InsetSpace \thinspace{}
+cm×10\InsetSpace \thinspace{}
+cm as size in LyX, the image will
+ have the size 5\InsetSpace \thinspace{}
+cm×10\InsetSpace \thinspace{}
+cm in the output.
 \end_layout
 
 \begin_layout Description
Index: src/frontends/qt4/QGraphicsDialog.C
===================================================================
--- src/frontends/qt4/QGraphicsDialog.C	(revision 17667)
+++ src/frontends/qt4/QGraphicsDialog.C	(working copy)
@@ -120,6 +120,9 @@
 	rtY->setValidator(new QDoubleValidator(rtY));
 
 	displayscale->setValidator(new QIntValidator(displayscale));
+
+	//FIXME We should have a validator for Scale, too.
+	//It would have to inherit from QDoubleValidator
 	Height->setValidator(unsignedLengthValidator(Height));
 	Width->setValidator(unsignedLengthValidator(Width));
 
@@ -182,18 +185,60 @@
 	editPB->setDisabled(filename.isEmpty());
 }
 
+void QGraphicsDialog::on_Height_textChanged(const QString &)
+{
+	//when aspectratio is checked, the unit of the height is used also for the width
+	//and the height value is used also for the width value
+	if (aspectratio->isChecked()) {
+		if (widthUnit->currentIndex() != heightUnit->currentIndex())
+			widthUnit->setCurrentIndex(heightUnit->currentIndex());
+		Width->setText(Height->text());
+	}
+}
 
+void QGraphicsDialog::on_Width_textChanged(const QString &)
+{
+	//when aspectratio is checked, the unit of the width is used also for the height
+	//and the width value is used also for the height value
+	if (aspectratio->isChecked()) {
+		if (widthUnit->currentIndex() != heightUnit->currentIndex())
+			heightUnit->setCurrentIndex(widthUnit->currentIndex());
+		Height->setText(Width->text());
+	}
+}
+
+void QGraphicsDialog::on_aspectratio_toggled()
+{
+	//when aspectratio is checked, the unit of the width is used also for the height
+	//and the smaller value (but not zero) of width and height is used for width and height
+	if (aspectratio->isChecked()) {
+		int Hvalue = Height->text().toInt();
+		int Wvalue = Width->text().toInt();
+		if (widthUnit->currentIndex() != heightUnit->currentIndex())
+			heightUnit->setCurrentIndex(widthUnit->currentIndex());
+		if (Wvalue < Hvalue && Wvalue != 0)
+			Height->setText(Width->text());
+		if (Wvalue == 0)
+			Width->setText(Height->text());
+		if (Hvalue < Wvalue && Hvalue != 0)
+			Width->setText(Height->text());
+		if (Hvalue == 0)
+			Height->setText(Width->text());
+	}
+}
+
 void QGraphicsDialog::on_scaleCB_toggled(bool setscale)
 {
+	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);
+	heightL->setDisabled(setscale);
+	Height->setDisabled(setscale);
+	heightUnit->setDisabled(setscale);
 }
 
 } // namespace frontend
Index: src/frontends/qt4/QGraphicsDialog.h
===================================================================
--- src/frontends/qt4/QGraphicsDialog.h	(revision 17667)
+++ src/frontends/qt4/QGraphicsDialog.h	(working copy)
@@ -37,6 +37,9 @@
 	virtual void on_getPB_clicked();
 	virtual void on_editPB_clicked();
 	virtual void on_filename_textChanged(const QString &);
+	virtual void on_Height_textChanged(const QString &);
+	virtual void on_Width_textChanged(const QString &);
+	virtual void on_aspectratio_toggled();
 	virtual void on_scaleCB_toggled(bool);
 protected:
 	virtual void closeEvent(QCloseEvent * e);
Index: src/frontends/qt4/ui/QGraphicsUi.ui
===================================================================
--- src/frontends/qt4/ui/QGraphicsUi.ui	(revision 17667)
+++ src/frontends/qt4/ui/QGraphicsUi.ui	(working copy)
@@ -834,54 +834,5 @@
   <include location="local" >qt_helpers.h</include>
  </includes>
  <resources/>
- <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>

Reply via email to