[Kst] branches/work/kst/2.0.4-rc2/src/libkstapp

Peter Kümmel syntheticpp at gmx.net
Mon Sep 12 11:15:12 UTC 2011


SVN commit 1253021 by kuemmel:

baclport "When creating picture and svg annotation items, respect their fixed aspect ratio."

 M  +11 -0     pictureitem.cpp  
 M  +1 -0      pictureitem.h  
 M  +19 -1     svgitem.cpp  
 M  +1 -0      svgitem.h  
 M  +45 -0     viewitem.cpp  
 M  +1 -0      viewitem.h  


--- branches/work/kst/2.0.4-rc2/src/libkstapp/pictureitem.cpp #1253020:1253021
@@ -88,7 +88,18 @@
   CreateCommand::createItem();
 }
 
+void PictureItem::creationPolygonChanged(View::CreationEvent event) {
 
+  double aspect = 1.0;
+  if ((_image.width()>0) && (_image.height()>0)) {
+    aspect = double(_image.width())/double(_image.height());
+  }
+
+  creationPolygonChangedFixedAspect(event, aspect);
+
+}
+
+
 PictureItemFactory::PictureItemFactory()
 : GraphicsFactory() {
   registerFactory("picture", this);
--- branches/work/kst/2.0.4-rc2/src/libkstapp/pictureitem.h #1253020:1253021
@@ -33,6 +33,7 @@
 
     virtual void save(QXmlStreamWriter &xml);
     virtual void paint(QPainter *painter);
+    virtual void creationPolygonChanged(View::CreationEvent event);
 
     void setImage(const QImage &image);
 
--- branches/work/kst/2.0.4-rc2/src/libkstapp/svgitem.cpp #1253020:1253021
@@ -12,6 +12,7 @@
 
 #include "svgitem.h"
 #include "debug.h"
+#include "dialogdefaults.h"
 
 #include <QDebug>
 #include <QFileDialog>
@@ -65,16 +66,33 @@
 }
 
 
+void SvgItem::creationPolygonChanged(View::CreationEvent event) {
+
+  double aspect = 1.0;
+  if ((_svg->defaultSize().width()>0) && (_svg->defaultSize().height()>0)) {
+    aspect = double(_svg->defaultSize().width())/double(_svg->defaultSize().height());
+  }
+
+  creationPolygonChangedFixedAspect(event, aspect);
+
+}
+
+
+
 void SvgItem::setSvgData(const QByteArray &svgData) {
   _svg->load(svgData);
   _svgData = svgData;
 }
 
 void CreateSvgCommand::createItem() {
-  QString file = QFileDialog::getOpenFileName(_view, tr("Kst: Open Svg Image"));
+  QString start_dir = _dialogDefaults->value("svg/startdir", ".").toString();
+  QString filter = "SVG Images (*.svg *.SVG)";
+  QString file = QFileDialog::getOpenFileName(_view, tr("Kst: Open SVG Image"), start_dir, filter);
+
   if (file.isEmpty())
     return;
 
+  _dialogDefaults->setValue("svg/startdir", QFileInfo(file).path());
   _item = new SvgItem(_view, file);
   _view->setCursor(Qt::CrossCursor);
 
--- branches/work/kst/2.0.4-rc2/src/libkstapp/svgitem.h #1253020:1253021
@@ -37,6 +37,7 @@
     virtual void paint(QPainter *painter);
 
     void setSvgData(const QByteArray &svgData);
+    virtual void creationPolygonChanged(View::CreationEvent event);
 
   private:
     QSvgRenderer *_svg;
--- branches/work/kst/2.0.4-rc2/src/libkstapp/viewitem.cpp #1253020:1253021
@@ -944,6 +944,51 @@
 }
 
 
+
+void ViewItem::creationPolygonChangedFixedAspect(View::CreationEvent event, double aspect) {
+
+  if (event == View::EscapeEvent) {
+    ViewItem::creationPolygonChanged(event);
+    return;
+  }
+
+  if (event == View::MousePress) {
+    const QPolygonF poly = mapFromScene(view()->creationPolygon(View::MousePress));
+    setPos(poly.first().x(), poly.first().y());
+    setViewRect(QRectF(0.0, 0.0, 0.0, sizeOfGrip().height()));
+    setRect(0,0,4,4);
+    view()->scene()->addItem(this);
+    return;
+  }
+
+  if (event == View::MouseMove) {
+    const QPolygonF poly = mapFromScene(view()->creationPolygon(View::MouseMove));
+
+    QPointF offset = lockOffset(poly.last(), aspect, false);
+
+    if (offset.x()<5.0) {
+      offset.setX(5.0);
+      offset.setY(5.0/aspect);
+    }
+
+    setViewRect(0,0,offset.x(), offset.y());
+    return;
+  }
+
+  if (event == View::MouseRelease) {
+    view()->disconnect(this, SLOT(deleteLater())); //Don't delete ourself
+    view()->disconnect(this, SLOT(creationPolygonChanged(View::CreationEvent)));
+    view()->setMouseMode(View::Default);
+
+    updateViewItemParent();
+    _creationState = Completed;
+    setZValue(DRAWING_ZORDER);
+    emit creationComplete();
+    return;
+  }
+}
+
+
 void ViewItem::addTitle(QMenu *menu) const {
   QWidgetAction *action = new QWidgetAction(menu);
   action->setEnabled(false);
--- branches/work/kst/2.0.4-rc2/src/libkstapp/viewitem.h #1253020:1253021
@@ -285,6 +285,7 @@
 
   protected Q_SLOTS:
     virtual void creationPolygonChanged(View::CreationEvent event);
+    void creationPolygonChangedFixedAspect(View::CreationEvent even, double aspect);
 
   protected:
     virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);


More information about the Kst mailing list