#include "mainwindow.h"
#include <QtGui>
+#include <unistd.h>
#include <QFileSystemWatcher>
#include "svgview.h"
menuBar()->addMenu(fileMenu);
QMenu *viewMenu = new QMenu(tr("&View"), this);
+
+ m_interactiveAction = viewMenu->addAction(tr("&Interactive"));
+ m_interactiveAction->setEnabled(false);
+ m_interactiveAction->setCheckable(true);
+ m_interactiveAction->setChecked(false);
+ connect(m_interactiveAction, SIGNAL(toggled(bool)), m_view, SLOT(setViewInteractive(bool)));
+
m_backgroundAction = viewMenu->addAction(tr("&Background"));
m_backgroundAction->setEnabled(false);
m_backgroundAction->setCheckable(true);
m_backgroundAction->setChecked(false);
+ m_backgroundAction->setVisible(false);
connect(m_backgroundAction, SIGNAL(toggled(bool)), m_view, SLOT(setViewBackground(bool)));
m_outlineAction = viewMenu->addAction(tr("&Outline"));
QMessageBox::critical(this, tr("Open SVG File"),
QString("Could not open file '%1'.").arg(fileName));
+ m_interactiveAction->setEnabled(false);
m_outlineAction->setEnabled(false);
m_backgroundAction->setEnabled(false);
return;
connect(m_watcher, SIGNAL(fileChanged(const QString&)), this, SLOT(reloadFile()));
}
+ m_interactiveAction->setEnabled(true);
m_outlineAction->setEnabled(true);
m_backgroundAction->setEnabled(true);
void MainWindow::reloadFile()
{
+ // give the writer ~100 ms to finish writing
+ usleep(100000);
openFile(m_currentPath, true);
}
: QGraphicsView(parent)
, m_renderer(Native)
, m_svgItem(0)
+ , m_webview(0)
, m_backgroundItem(0)
, m_outlineItem(0)
{
QGraphicsScene *s = scene();
+ fn = file.fileName();
+ if (fn[0] != '/') {
+ char cwd_buffer[4096];
+ if (getcwd(cwd_buffer, 4096) != NULL)
+ fn = cwd_buffer + ("/" + fn);
+ }
+
bool drawBackground = (m_backgroundItem ? m_backgroundItem->isVisible() : false);
bool drawOutline = (m_outlineItem ? m_outlineItem->isVisible() : true);
+ bool useWebview = (m_webview ? m_webview->isVisible() : false);
s->clear();
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());
-#endif
m_svgItem->setFlags(QGraphicsItem::ItemClipsToShape);
m_svgItem->setCacheMode(QGraphicsItem::NoCache);
+ m_svgItem->setVisible(!useWebview);
m_svgItem->setZValue(1);
+ s->addItem(m_svgItem);
+
+ if (useWebview) {
+ m_webview = new QGraphicsWebView();
+ m_webview->load(QUrl::fromLocalFile(fn));
+ m_webview->setResizesToContents(true);
+ m_webview->setZoomFactor(0.75);
+ m_webview->setVisible(useWebview);
+ m_webview->setZValue(1);
+ s->addItem(m_webview);
+ } else
+ m_webview = NULL;
m_backgroundItem = new QGraphicsRectItem(m_svgItem->boundingRect());
m_backgroundItem->setBrush(Qt::white);
m_backgroundItem->setPen(Qt::NoPen);
m_backgroundItem->setVisible(drawBackground);
m_backgroundItem->setZValue(0);
+ s->addItem(m_backgroundItem);
m_outlineItem = new QGraphicsRectItem(m_svgItem->boundingRect());
QPen outline(Qt::black, 2, Qt::DashLine);
m_outlineItem->setBrush(Qt::NoBrush);
m_outlineItem->setVisible(drawOutline);
m_outlineItem->setZValue(2);
-
- s->addItem(m_backgroundItem);
- s->addItem(m_svgItem);
s->addItem(m_outlineItem);
s->setSceneRect(m_outlineItem->boundingRect().adjusted(-10, -10, 10, 10));
#endif
}
+void SvgView::setViewInteractive(bool enable)
+{
+ if (!m_svgItem)
+ return;
+ if (!m_webview) {
+ m_webview = new QGraphicsWebView();
+ m_webview->load(QUrl::fromLocalFile(fn));
+ m_webview->setResizesToContents(true);
+ m_webview->setZoomFactor(0.75);
+ m_webview->setVisible(false);
+ m_webview->setZValue(1);
+ m_svgItem->scene()->addItem(m_webview);
+ }
+ m_svgItem->setVisible(!enable);
+ m_webview->setVisible(enable);
+}
+
void SvgView::setViewBackground(bool enable)
{
if (!m_backgroundItem)