Commit 8ad4c28e authored by Aurélien Gâteau's avatar Aurélien Gâteau
Browse files

Implemented zooming in and out.

svn path=/trunk/playground/graphics/svgpart/; revision=737285
parent 3e831420
......@@ -25,6 +25,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <QSvgRenderer>
// KDE
#include <kactioncollection.h>
#include <kstandardaction.h>
#include <kparts/genericfactory.h>
// Local
......@@ -42,6 +44,9 @@ SvgPart::SvgPart(QWidget* parentWidget, QObject* parent, const QStringList&)
mView->setDragMode(QGraphicsView::ScrollHandDrag);
mItem = 0;
setWidget(mView);
KStandardAction::zoomIn(this, SLOT(zoomIn()), actionCollection());
KStandardAction::zoomOut(this, SLOT(zoomOut()), actionCollection());
setXMLFile("svgpart/svgpart.rc");
}
......@@ -61,3 +66,25 @@ KAboutData* SvgPart::createAboutData() {
ki18n("Copyright 2007, Aurélien Gâteau <aurelien.gateau@free.fr>"));
return aboutData;
}
void SvgPart::zoomIn() {
setZoom(zoom() * 2);
}
void SvgPart::zoomOut() {
setZoom(zoom() / 2);
}
qreal SvgPart::zoom() const {
return mView->matrix().m11();
}
void SvgPart::setZoom(qreal value) {
QMatrix matrix;
matrix.scale(value, value);
mView->setMatrix(matrix);
}
......@@ -38,10 +38,17 @@ public:
protected:
virtual bool openFile();
private Q_SLOTS:
void zoomIn();
void zoomOut();
private:
QGraphicsScene* mScene;
QGraphicsView* mView;
QGraphicsSvgItem* mItem;
qreal zoom() const;
void setZoom(qreal);
};
#endif /* SVGPART_H */
<!DOCTYPE kpartgui>
<kpartgui name="SvgPart" version="1">
<!--
<kpartgui name="SvgPart" version="2">
<MenuBar>
<Menu name="view"><Text>&amp;View</Text>
<Action name="view_actual_size"/>
<!--
<Action name="view_zoom_to_fit"/>
-->
<Action name="view_zoom_in"/>
<Action name="view_zoom_out"/>
</Menu>
</MenuBar>
<ToolBar name="mainToolBar"><text>Main Toolbar</text>
<Action name="view_actual_size"/>
<!--
<Action name="view_zoom_to_fit"/>
-->
<Action name="view_zoom_in"/>
<Action name="view_zoom_out"/>
</ToolBar>
-->
</kpartgui>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment