Added some svgviewer code for possible future switch to QGraphicsWebView

This commit is contained in:
Clifford Wolf 2013-11-27 20:43:42 +01:00
parent 18e52d81bf
commit 9826f6ae02
3 changed files with 20 additions and 6 deletions

View File

@ -109,7 +109,7 @@ MainWindow::MainWindow()
this, SLOT(setRenderer(QAction*))); this, SLOT(setRenderer(QAction*)));
setCentralWidget(m_view); setCentralWidget(m_view);
setWindowTitle(tr("SVG Viewer")); setWindowTitle(tr("Yosys SVG Viewer"));
} }
void MainWindow::openFile(const QString &path, bool reload) void MainWindow::openFile(const QString &path, bool reload)
@ -147,7 +147,7 @@ void MainWindow::openFile(const QString &path, bool reload)
if (!fileName.startsWith(":/")) if (!fileName.startsWith(":/"))
{ {
m_currentPath = fileName; m_currentPath = fileName;
setWindowTitle(tr("%1 - SVGViewer").arg(m_currentPath)); setWindowTitle(tr("%1 - Yosys SVG Viewer").arg(m_currentPath));
// just keep the file open so this process is found using 'fuser' // just keep the file open so this process is found using 'fuser'
m_filehandle = fopen(fileName.toAscii(), "r"); m_filehandle = fopen(fileName.toAscii(), "r");

View File

@ -44,6 +44,7 @@
#include <QMouseEvent> #include <QMouseEvent>
#include <QGraphicsRectItem> #include <QGraphicsRectItem>
#include <QGraphicsSvgItem> #include <QGraphicsSvgItem>
#include <QGraphicsWebView>
#include <QPaintEvent> #include <QPaintEvent>
#include <qmath.h> #include <qmath.h>
@ -96,16 +97,29 @@ void SvgView::openFile(const QFile &file)
s->clear(); s->clear();
resetTransform(); resetTransform();
#if 0
QGraphicsWebView *webview = new QGraphicsWebView();
QString fn = file.fileName();
if (fn[0] != '/') {
char cwd_buffer[4096];
if (getcwd(cwd_buffer, 4096) != NULL)
fn = cwd_buffer + ("/" + fn);
}
webview->load(QUrl::fromLocalFile(fn));
webview->setResizesToContents(true);
m_svgItem = webview;
#else
m_svgItem = new QGraphicsSvgItem(file.fileName()); m_svgItem = new QGraphicsSvgItem(file.fileName());
#endif
m_svgItem->setFlags(QGraphicsItem::ItemClipsToShape); m_svgItem->setFlags(QGraphicsItem::ItemClipsToShape);
m_svgItem->setCacheMode(QGraphicsItem::NoCache); m_svgItem->setCacheMode(QGraphicsItem::NoCache);
m_svgItem->setZValue(0); m_svgItem->setZValue(1);
m_backgroundItem = new QGraphicsRectItem(m_svgItem->boundingRect()); m_backgroundItem = new QGraphicsRectItem(m_svgItem->boundingRect());
m_backgroundItem->setBrush(Qt::white); m_backgroundItem->setBrush(Qt::white);
m_backgroundItem->setPen(Qt::NoPen); m_backgroundItem->setPen(Qt::NoPen);
m_backgroundItem->setVisible(drawBackground); m_backgroundItem->setVisible(drawBackground);
m_backgroundItem->setZValue(-1); m_backgroundItem->setZValue(0);
m_outlineItem = new QGraphicsRectItem(m_svgItem->boundingRect()); m_outlineItem = new QGraphicsRectItem(m_svgItem->boundingRect());
QPen outline(Qt::black, 2, Qt::DashLine); QPen outline(Qt::black, 2, Qt::DashLine);
@ -113,7 +127,7 @@ void SvgView::openFile(const QFile &file)
m_outlineItem->setPen(outline); m_outlineItem->setPen(outline);
m_outlineItem->setBrush(Qt::NoBrush); m_outlineItem->setBrush(Qt::NoBrush);
m_outlineItem->setVisible(drawOutline); m_outlineItem->setVisible(drawOutline);
m_outlineItem->setZValue(1); m_outlineItem->setZValue(2);
s->addItem(m_backgroundItem); s->addItem(m_backgroundItem);
s->addItem(m_svgItem); s->addItem(m_svgItem);

View File

@ -4,7 +4,7 @@ RESOURCES = svgviewer.qrc
SOURCES = main.cpp \ SOURCES = main.cpp \
mainwindow.cpp \ mainwindow.cpp \
svgview.cpp svgview.cpp
QT += svg xml QT += webkit svg xml
contains(QT_CONFIG, opengl): QT += opengl contains(QT_CONFIG, opengl): QT += opengl