3 SVGViewer::SVGViewer(QWidget
*parent
) : QGraphicsView(parent
) {
5 setScene(new QGraphicsScene(this));
6 setTransformationAnchor(AnchorUnderMouse
);
7 setViewportUpdateMode(FullViewportUpdate
);
10 void SVGViewer::paintEvent(QPaintEvent
*event
) {
11 QGraphicsView::paintEvent(event
);
14 bool SVGViewer::openFile(QString fileName
) {
15 svgItem
= new QGraphicsSvgItem(fileName
);
17 /* Reject invalid SVG documents */
18 if (!svgItem
->renderer()->isValid()) {
19 /* TODO: Also show details in error message */
20 QMessageBox::critical(this, "Invalid SVG document",
21 "The selected file is not a valid SVG document and could not be opened.");
26 setDragMode(ScrollHandDrag
);
31 svgItem
->setFlags(QGraphicsItem::ItemClipsToShape
);
32 svgItem
->setCacheMode(QGraphicsItem::NoCache
);
35 scene()->addItem(svgItem
);
39 void SVGViewer::closeFile() {
42 /* Reset view parameters */
48 void SVGViewer::zoomIn() {
51 void SVGViewer::zoomOut() {
54 void SVGViewer::zoomReset() {
60 void SVGViewer::zoomChange(qreal factor
) {
62 scale(factor
, factor
);
66 void SVGViewer::wheelEvent(QWheelEvent
*event
) {
67 /* Change zoom on using the mouse wheel */
68 qreal factor
= qPow(1.2, event
->delta() / 240.0);