Bug 121159 - "Maintain aspect ratio" option for images
Summary: "Maintain aspect ratio" option for images
Status: RESOLVED FIXED
Alias: None
Product: kst
Classification: Applications
Component: general (show other bugs)
Version: 1.x
Platform: unspecified Solaris
: HI wishlist
Target Milestone: ---
Assignee: kst
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-02-01 16:45 UTC by Nicolas Brisset
Modified: 2006-05-24 20:48 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Proposed patch. (1.50 KB, patch)
2006-05-19 00:56 UTC, Duncan Hanson
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nicolas Brisset 2006-02-01 16:45:25 UTC
Version:           1.2.0_devel (using KDE 3.4.0, compiled sources)
Compiler:          gcc version 3.4.3
OS:                SunOS (sun4u) release 5.8

When inserting an image, in some cases it is crucial to be able to maintain its aspect ratio. This is currently impossible to do. I think a "Maintain aspect ratio" option should be added, and even used as default.
Comment 1 Netterfield 2006-02-15 01:35:54 UTC
Should implement for 1.3.
Comment 2 George Staikos 2006-03-20 03:35:21 UTC
I think this should be "blocked" by a more important issue: WYSIWYG, and maintaining aspect ratio of all objects.
Comment 3 Nicolas Brisset 2006-03-23 12:00:47 UTC
George, I don't understand your comment... From my experiments, there is a modifier key that allows to resize objects while maintaining their aspect ratio, which is good. The problem (specific to image objects) is that you need to define their bounding box blindly, before you can insert the image since the dialog wher you sprecify the input file comes only after you've drawn a rectangle. The problem (and difference with other objects) is due to the fact that for images there is a "right" size (or at least aspect ratio) *before* you start drawing (that of the original image file). This is not the case when you draw other objects, which do not have a "right" size a priori.
Comment 4 Andrew Walker 2006-03-28 01:51:00 UTC
Proposal: Add a Maintain aspect ratio checkbox to the picture dialog. If this is checked then when creating a new picture object the aspect ratio will be maintained. This would be relatively simple.

More difficult would be enforcing the aspect ratio when a picture object is saved to a graphics file, printed, or dropped onto another object (changing its parent). For these cases we could assume that the top-left corner remains fixed in aspect relative to the parent.

Are there any other such cases?

Should we prefer to modify the width or the height to maintain the aspect ratio?
Or possibly whichever necessitates the smaller change in pixel space.
Comment 5 Netterfield 2006-03-28 02:08:19 UTC
The fixed aspect ration images should work conceptually in the same way as a 
label.  They should render on any output medium with a fixed aspect ratio, as 
do labels.  The anchor position (I think it is the bottom left) should be the 
same for fixed aspect images as it is for labels.
Comment 6 Duncan Hanson 2006-05-17 01:00:34 UTC
SVN commit 541675 by dhanson:

BUG:121159 Added a _maintainAspect boolean for KstViewObjects, which allows the default behaviour when resizing objects to be aspect preserving. Added a checkbox to the KstViewPicture to enable this option. If this checkbox is enabled when the image source is selected, then the KstViewPicture will override the user's initial size choice to maintain the aspect ratio.

 M  +1 -0      kstborderedviewobject.h  
 M  +18 -17    ksttoplevelview.cpp  
 M  +5 -5      ksttoplevelview.h  
 M  +13 -0     kstviewobject.cpp  
 M  +4 -0      kstviewobject.h  
 M  +31 -0     kstviewpicture.cpp  
 M  +6 -0      kstviewpicture.h  
Comment 7 Andrew Walker 2006-05-17 02:59:55 UTC
The changes modify the aspect ratio correctly when the object is first created, but should continually maintain the aspect ratio as the parent object is resized (including printing, exporting, etc.)
Comment 8 George Staikos 2006-05-17 03:16:02 UTC
  Please don't commit this without posting a patch for review first.
Comment 9 Duncan Hanson 2006-05-19 00:56:29 UTC
Created attachment 16164 [details]
Proposed patch.

Maintains aspect when view objects or their parents are resized if
_maintainAspect is enabled.
Comment 10 Andrew Walker 2006-05-19 20:18:09 UTC
There are a few problems with this:

1) tha aspect ratio of the original picture is not maintained if I create a picture and then alter the size of the parent window
2) if I use the SHIFT key while resizing the picture the maintain aspect ratio should be unchecked
3) using the SHIFT key while resizing the picture does not create the size of picture I was expecting based on the preview of the resize
Comment 11 Duncan Hanson 2006-05-19 20:42:10 UTC
I can't reproduce (1).

I agree with (2).

(3) is a result of my not implementing (2). I would like to remove the
aspect maintaining code from the KstViewObject::resize part of the
patch, and just trust that the mouse graphics handler has ensured that
the new size will maintain aspect. This will effectively fix (2) as
well.
Comment 12 Duncan Hanson 2006-05-24 20:48:52 UTC
SVN commit 544402 by dhanson:

BUG:121159 objects with _maintainAspect == true will now maintain their aspect on parent resize.

 M  +6 -0      kstviewobject.cpp  


--- trunk/extragear/graphics/kst/src/libkstapp/kstviewobject.cpp #544401:544402
@@ -1455,6 +1455,12 @@
     _geom.setTop(geom.top() + int(_aspect.y * geom.height()));
     _geom.setRight(geom.left() + int((_aspect.x + _aspect.w) * geom.width()) - 1);
     _geom.setBottom(geom.top() + int((_aspect.y + _aspect.h) * geom.height()) - 1);
+
+    if (_maintainAspect == true) {
+      QSize maintaining_size(myOldGeom.size());
+      maintaining_size.scale(_geom.size(),QSize::ScaleMin);
+      _geom.setSize(maintaining_size);
+    }
   }
   if (_geom.width() < _minimumSize.width() || _geom.height() < _minimumSize.height()) {
     _geom.setSize(_geom.size().expandedTo(_minimumSize));