[Kst] branches/work/kst/portto4/kst/src/libkstapp
Barth Netterfield
netterfield at astro.utoronto.ca
Sat Sep 10 19:58:38 UTC 2011
SVN commit 1252624 by netterfield:
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/portto4/kst/src/libkstapp/pictureitem.cpp #1252623:1252624
@@ -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/portto4/kst/src/libkstapp/pictureitem.h #1252623:1252624
@@ -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/portto4/kst/src/libkstapp/svgitem.cpp #1252623:1252624
@@ -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/portto4/kst/src/libkstapp/svgitem.h #1252623:1252624
@@ -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/portto4/kst/src/libkstapp/viewitem.cpp #1252623:1252624
@@ -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/portto4/kst/src/libkstapp/viewitem.h #1252623:1252624
@@ -286,6 +286,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