From 62b9e16f87d012b407f95f13a8ff0e3fb027ecec Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Wed, 27 Mar 2013 06:57:57 +0100 Subject: Imported svgviewer from qt4.8 This is from commit 543486a41963f8d20d9771d2107cdd5a22894bdb in the Qt git repository: git://gitorious.org/qt/qt.git --- libs/svgviewer/files/bubbles.svg | 215 +++++++++++++++++++++++++++++++++++++++ libs/svgviewer/files/cubic.svg | 77 ++++++++++++++ libs/svgviewer/files/spheres.svg | 72 +++++++++++++ libs/svgviewer/main.cpp | 66 ++++++++++++ libs/svgviewer/mainwindow.cpp | 163 +++++++++++++++++++++++++++++ libs/svgviewer/mainwindow.h | 80 +++++++++++++++ libs/svgviewer/svgview.cpp | 188 ++++++++++++++++++++++++++++++++++ libs/svgviewer/svgview.h | 83 +++++++++++++++ libs/svgviewer/svgviewer.desktop | 11 ++ libs/svgviewer/svgviewer.pro | 33 ++++++ libs/svgviewer/svgviewer.qrc | 6 ++ 11 files changed, 994 insertions(+) create mode 100644 libs/svgviewer/files/bubbles.svg create mode 100644 libs/svgviewer/files/cubic.svg create mode 100644 libs/svgviewer/files/spheres.svg create mode 100644 libs/svgviewer/main.cpp create mode 100644 libs/svgviewer/mainwindow.cpp create mode 100644 libs/svgviewer/mainwindow.h create mode 100644 libs/svgviewer/svgview.cpp create mode 100644 libs/svgviewer/svgview.h create mode 100644 libs/svgviewer/svgviewer.desktop create mode 100644 libs/svgviewer/svgviewer.pro create mode 100644 libs/svgviewer/svgviewer.qrc diff --git a/libs/svgviewer/files/bubbles.svg b/libs/svgviewer/files/bubbles.svg new file mode 100644 index 00000000..51730124 --- /dev/null +++ b/libs/svgviewer/files/bubbles.svg @@ -0,0 +1,215 @@ + + + + Spheres + Semi-transparent bubbles on a colored background. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/svgviewer/files/cubic.svg b/libs/svgviewer/files/cubic.svg new file mode 100644 index 00000000..492bb72b --- /dev/null +++ b/libs/svgviewer/files/cubic.svg @@ -0,0 +1,77 @@ + + + Example cubic02 - cubic Bezier commands in path data + Picture showing examples of "C" and "S" commands, + along with annotations showing the control points + and end points + + + + + + + + + + + + M100,200 C100,100 400,100 400,200 + + + + + + + + + + M100,500 C25,400 475,400 400,500 + + + + + + + + + + M100,800 C175,700 325,700 400,800 + + + + + + + + + + M600,200 C675,100 975,100 900,200 + + + + + + + + + + M600,500 C600,350 900,650 900,500 + + + + + + + + + + + + + + + M600,800 C625,700 725,700 750,800 + S875,900 900,800 + diff --git a/libs/svgviewer/files/spheres.svg b/libs/svgviewer/files/spheres.svg new file mode 100644 index 00000000..b23164bc --- /dev/null +++ b/libs/svgviewer/files/spheres.svg @@ -0,0 +1,72 @@ + + + Spheres + Gradient filled spheres with different colors. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/svgviewer/main.cpp b/libs/svgviewer/main.cpp new file mode 100644 index 00000000..34866f85 --- /dev/null +++ b/libs/svgviewer/main.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#ifndef QT_NO_OPENGL +#include +#endif + +#include "mainwindow.h" + +int main(int argc, char **argv) +{ + Q_INIT_RESOURCE(svgviewer); + + QApplication app(argc, argv); + + MainWindow window; + if (argc == 2) + window.openFile(argv[1]); + else + window.openFile(":/files/bubbles.svg"); +#if defined(Q_OS_SYMBIAN) + window.showMaximized(); +#else + window.show(); +#endif + return app.exec(); +} diff --git a/libs/svgviewer/mainwindow.cpp b/libs/svgviewer/mainwindow.cpp new file mode 100644 index 00000000..7d4d303e --- /dev/null +++ b/libs/svgviewer/mainwindow.cpp @@ -0,0 +1,163 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "mainwindow.h" + +#include + +#include "svgview.h" + +MainWindow::MainWindow() + : QMainWindow() + , m_view(new SvgView) +{ + QMenu *fileMenu = new QMenu(tr("&File"), this); + QAction *openAction = fileMenu->addAction(tr("&Open...")); + openAction->setShortcut(QKeySequence(tr("Ctrl+O"))); + QAction *quitAction = fileMenu->addAction(tr("E&xit")); + quitAction->setShortcuts(QKeySequence::Quit); + + menuBar()->addMenu(fileMenu); + + QMenu *viewMenu = new QMenu(tr("&View"), this); + m_backgroundAction = viewMenu->addAction(tr("&Background")); + m_backgroundAction->setEnabled(false); + m_backgroundAction->setCheckable(true); + m_backgroundAction->setChecked(false); + connect(m_backgroundAction, SIGNAL(toggled(bool)), m_view, SLOT(setViewBackground(bool))); + + m_outlineAction = viewMenu->addAction(tr("&Outline")); + m_outlineAction->setEnabled(false); + m_outlineAction->setCheckable(true); + m_outlineAction->setChecked(true); + connect(m_outlineAction, SIGNAL(toggled(bool)), m_view, SLOT(setViewOutline(bool))); + + menuBar()->addMenu(viewMenu); + + QMenu *rendererMenu = new QMenu(tr("&Renderer"), this); + m_nativeAction = rendererMenu->addAction(tr("&Native")); + m_nativeAction->setCheckable(true); + m_nativeAction->setChecked(true); +#ifndef QT_NO_OPENGL + m_glAction = rendererMenu->addAction(tr("&OpenGL")); + m_glAction->setCheckable(true); +#endif + m_imageAction = rendererMenu->addAction(tr("&Image")); + m_imageAction->setCheckable(true); + +#ifndef QT_NO_OPENGL + rendererMenu->addSeparator(); + m_highQualityAntialiasingAction = rendererMenu->addAction(tr("&High Quality Antialiasing")); + m_highQualityAntialiasingAction->setEnabled(false); + m_highQualityAntialiasingAction->setCheckable(true); + m_highQualityAntialiasingAction->setChecked(false); + connect(m_highQualityAntialiasingAction, SIGNAL(toggled(bool)), m_view, SLOT(setHighQualityAntialiasing(bool))); +#endif + + QActionGroup *rendererGroup = new QActionGroup(this); + rendererGroup->addAction(m_nativeAction); +#ifndef QT_NO_OPENGL + rendererGroup->addAction(m_glAction); +#endif + rendererGroup->addAction(m_imageAction); + + menuBar()->addMenu(rendererMenu); + + connect(openAction, SIGNAL(triggered()), this, SLOT(openFile())); + connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); + connect(rendererGroup, SIGNAL(triggered(QAction*)), + this, SLOT(setRenderer(QAction*))); + + setCentralWidget(m_view); + setWindowTitle(tr("SVG Viewer")); +} + +void MainWindow::openFile(const QString &path) +{ + QString fileName; + if (path.isNull()) + fileName = QFileDialog::getOpenFileName(this, tr("Open SVG File"), + m_currentPath, "SVG files (*.svg *.svgz *.svg.gz)"); + else + fileName = path; + + if (!fileName.isEmpty()) { + QFile file(fileName); + if (!file.exists()) { + QMessageBox::critical(this, tr("Open SVG File"), + QString("Could not open file '%1'.").arg(fileName)); + + m_outlineAction->setEnabled(false); + m_backgroundAction->setEnabled(false); + return; + } + + m_view->openFile(file); + + if (!fileName.startsWith(":/")) { + m_currentPath = fileName; + setWindowTitle(tr("%1 - SVGViewer").arg(m_currentPath)); + } + + m_outlineAction->setEnabled(true); + m_backgroundAction->setEnabled(true); + + resize(m_view->sizeHint() + QSize(80, 80 + menuBar()->height())); + } +} + +void MainWindow::setRenderer(QAction *action) +{ +#ifndef QT_NO_OPENGL + m_highQualityAntialiasingAction->setEnabled(false); +#endif + + if (action == m_nativeAction) + m_view->setRenderer(SvgView::Native); +#ifndef QT_NO_OPENGL + else if (action == m_glAction) { + m_highQualityAntialiasingAction->setEnabled(true); + m_view->setRenderer(SvgView::OpenGL); + } +#endif + else if (action == m_imageAction) { + m_view->setRenderer(SvgView::Image); + } +} diff --git a/libs/svgviewer/mainwindow.h b/libs/svgviewer/mainwindow.h new file mode 100644 index 00000000..8bfb8853 --- /dev/null +++ b/libs/svgviewer/mainwindow.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include + +class SvgView; + +QT_BEGIN_NAMESPACE +class QAction; +class QGraphicsView; +class QGraphicsScene; +class QGraphicsRectItem; +QT_END_NAMESPACE + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +public slots: + void openFile(const QString &path = QString()); + void setRenderer(QAction *action); + +private: + QAction *m_nativeAction; + QAction *m_glAction; + QAction *m_imageAction; + QAction *m_highQualityAntialiasingAction; + QAction *m_backgroundAction; + QAction *m_outlineAction; + + SvgView *m_view; + + QString m_currentPath; +}; + +#endif diff --git a/libs/svgviewer/svgview.cpp b/libs/svgviewer/svgview.cpp new file mode 100644 index 00000000..da9a4aee --- /dev/null +++ b/libs/svgviewer/svgview.cpp @@ -0,0 +1,188 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "svgview.h" + +#include +#include +#include +#include +#include +#include +#include + +#ifndef QT_NO_OPENGL +#include +#endif + +SvgView::SvgView(QWidget *parent) + : QGraphicsView(parent) + , m_renderer(Native) + , m_svgItem(0) + , m_backgroundItem(0) + , m_outlineItem(0) +{ + setScene(new QGraphicsScene(this)); + setTransformationAnchor(AnchorUnderMouse); + setDragMode(ScrollHandDrag); + setViewportUpdateMode(FullViewportUpdate); + + // Prepare background check-board pattern + QPixmap tilePixmap(64, 64); + tilePixmap.fill(Qt::white); + QPainter tilePainter(&tilePixmap); + QColor color(220, 220, 220); + tilePainter.fillRect(0, 0, 32, 32, color); + tilePainter.fillRect(32, 32, 32, 32, color); + tilePainter.end(); + + setBackgroundBrush(tilePixmap); +} + +void SvgView::drawBackground(QPainter *p, const QRectF &) +{ + p->save(); + p->resetTransform(); + p->drawTiledPixmap(viewport()->rect(), backgroundBrush().texture()); + p->restore(); +} + +void SvgView::openFile(const QFile &file) +{ + if (!file.exists()) + return; + + QGraphicsScene *s = scene(); + + bool drawBackground = (m_backgroundItem ? m_backgroundItem->isVisible() : false); + bool drawOutline = (m_outlineItem ? m_outlineItem->isVisible() : true); + + s->clear(); + resetTransform(); + + m_svgItem = new QGraphicsSvgItem(file.fileName()); + m_svgItem->setFlags(QGraphicsItem::ItemClipsToShape); + m_svgItem->setCacheMode(QGraphicsItem::NoCache); + m_svgItem->setZValue(0); + + m_backgroundItem = new QGraphicsRectItem(m_svgItem->boundingRect()); + m_backgroundItem->setBrush(Qt::white); + m_backgroundItem->setPen(Qt::NoPen); + m_backgroundItem->setVisible(drawBackground); + m_backgroundItem->setZValue(-1); + + m_outlineItem = new QGraphicsRectItem(m_svgItem->boundingRect()); + QPen outline(Qt::black, 2, Qt::DashLine); + outline.setCosmetic(true); + m_outlineItem->setPen(outline); + m_outlineItem->setBrush(Qt::NoBrush); + m_outlineItem->setVisible(drawOutline); + m_outlineItem->setZValue(1); + + s->addItem(m_backgroundItem); + s->addItem(m_svgItem); + s->addItem(m_outlineItem); + + s->setSceneRect(m_outlineItem->boundingRect().adjusted(-10, -10, 10, 10)); +} + +void SvgView::setRenderer(RendererType type) +{ + m_renderer = type; + + if (m_renderer == OpenGL) { +#ifndef QT_NO_OPENGL + setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers))); +#endif + } else { + setViewport(new QWidget); + } +} + +void SvgView::setHighQualityAntialiasing(bool highQualityAntialiasing) +{ +#ifndef QT_NO_OPENGL + setRenderHint(QPainter::HighQualityAntialiasing, highQualityAntialiasing); +#else + Q_UNUSED(highQualityAntialiasing); +#endif +} + +void SvgView::setViewBackground(bool enable) +{ + if (!m_backgroundItem) + return; + + m_backgroundItem->setVisible(enable); +} + +void SvgView::setViewOutline(bool enable) +{ + if (!m_outlineItem) + return; + + m_outlineItem->setVisible(enable); +} + +void SvgView::paintEvent(QPaintEvent *event) +{ + if (m_renderer == Image) { + if (m_image.size() != viewport()->size()) { + m_image = QImage(viewport()->size(), QImage::Format_ARGB32_Premultiplied); + } + + QPainter imagePainter(&m_image); + QGraphicsView::render(&imagePainter); + imagePainter.end(); + + QPainter p(viewport()); + p.drawImage(0, 0, m_image); + + } else { + QGraphicsView::paintEvent(event); + } +} + +void SvgView::wheelEvent(QWheelEvent *event) +{ + qreal factor = qPow(1.2, event->delta() / 240.0); + scale(factor, factor); + event->accept(); +} + diff --git a/libs/svgviewer/svgview.h b/libs/svgviewer/svgview.h new file mode 100644 index 00000000..944401ac --- /dev/null +++ b/libs/svgviewer/svgview.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SVGVIEW_H +#define SVGVIEW_H + +#include + +QT_BEGIN_NAMESPACE +class QWheelEvent; +class QPaintEvent; +class QFile; +QT_END_NAMESPACE + +class SvgView : public QGraphicsView +{ + Q_OBJECT + +public: + enum RendererType { Native, OpenGL, Image }; + + SvgView(QWidget *parent = 0); + + void openFile(const QFile &file); + void setRenderer(RendererType type = Native); + void drawBackground(QPainter *p, const QRectF &rect); + +public slots: + void setHighQualityAntialiasing(bool highQualityAntialiasing); + void setViewBackground(bool enable); + void setViewOutline(bool enable); + +protected: + void wheelEvent(QWheelEvent *event); + void paintEvent(QPaintEvent *event); + +private: + RendererType m_renderer; + + QGraphicsItem *m_svgItem; + QGraphicsRectItem *m_backgroundItem; + QGraphicsRectItem *m_outlineItem; + + QImage m_image; +}; +#endif // SVGVIEW_H diff --git a/libs/svgviewer/svgviewer.desktop b/libs/svgviewer/svgviewer.desktop new file mode 100644 index 00000000..477ef789 --- /dev/null +++ b/libs/svgviewer/svgviewer.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Encoding=UTF-8 +Version=1.0 +Type=Application +Terminal=false +Name=SVG Viewer +Exec=/opt/usr/bin/svgviewer +Icon=svgviewer +X-Window-Icon= +X-HildonDesk-ShowInToolbar=true +X-Osso-Type=application/x-executable diff --git a/libs/svgviewer/svgviewer.pro b/libs/svgviewer/svgviewer.pro new file mode 100644 index 00000000..0d938f44 --- /dev/null +++ b/libs/svgviewer/svgviewer.pro @@ -0,0 +1,33 @@ +HEADERS = mainwindow.h \ + svgview.h +RESOURCES = svgviewer.qrc +SOURCES = main.cpp \ + mainwindow.cpp \ + svgview.cpp +QT += svg xml + +contains(QT_CONFIG, opengl): QT += opengl + +CONFIG += console + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/painting/svgviewer +sources.files = $$SOURCES $$HEADERS $$RESOURCES svgviewer.pro files +sources.path = $$[QT_INSTALL_EXAMPLES]/painting/svgviewer +INSTALLS += target sources + +wince*: { + addFiles.files = files\\*.svg + addFiles.path = "\\My Documents" + DEPLOYMENT += addFiles +} + +symbian: { + TARGET.UID3 = 0xA000A64E + include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) + addFiles.files = files\\*.svg + addFiles.path = . + DEPLOYMENT += addFiles +} +maemo5: include($$QT_SOURCE_TREE/examples/maemo5pkgrules.pri) + diff --git a/libs/svgviewer/svgviewer.qrc b/libs/svgviewer/svgviewer.qrc new file mode 100644 index 00000000..db611f51 --- /dev/null +++ b/libs/svgviewer/svgviewer.qrc @@ -0,0 +1,6 @@ + + + files/bubbles.svg + + + -- cgit v1.2.3