summaryrefslogtreecommitdiffstats
path: root/ksvg/test/external
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit47d455dd55be855e4cc691c32f687f723d9247ee (patch)
tree52e236aaa2576bdb3840ebede26619692fed6d7d /ksvg/test/external
downloadtdegraphics-47d455dd55be855e4cc691c32f687f723d9247ee.tar.gz
tdegraphics-47d455dd55be855e4cc691c32f687f723d9247ee.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegraphics@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'ksvg/test/external')
-rw-r--r--ksvg/test/external/Makefile.am13
-rw-r--r--ksvg/test/external/SVGTestWidget.cc206
-rw-r--r--ksvg/test/external/SVGTestWidget.h37
-rw-r--r--ksvg/test/external/printnodetest.cpp63
-rw-r--r--ksvg/test/external/printnodetest.h32
-rw-r--r--ksvg/test/external/svgdisplay.cc32
6 files changed, 383 insertions, 0 deletions
diff --git a/ksvg/test/external/Makefile.am b/ksvg/test/external/Makefile.am
new file mode 100644
index 00000000..77f763ac
--- /dev/null
+++ b/ksvg/test/external/Makefile.am
@@ -0,0 +1,13 @@
+INCLUDES = $(FREETYPE_CFLAGS) -I$(top_srcdir)/ksvg -I$(top_srcdir)/ksvg/dom -I$(top_srcdir)/ksvg/impl -I$(top_srcdir)/ksvg/ecma -I$(top_srcdir)/ksvg/core -I$(top_srcdir)/ksvg/impl/libs/libtext2path/src $(all_includes)
+METASOURCES = AUTO
+KDE_CXXFLAGS = $(USE_EXCEPTIONS)
+
+bin_PROGRAMS = svgdisplay printnodetest
+
+svgdisplay_SOURCES = SVGTestWidget.cc svgdisplay.cc
+svgdisplay_LDADD = $(LIB_KDECORE) ../../libksvg.la
+svgdisplay_LDFLAGS = $(KDE_RPATH) $(all_libraries)
+
+printnodetest_SOURCES = printnodetest.cpp
+printnodetest_LDADD = $(LIB_KDECORE) ../../libksvg.la
+printnodetest_LDFLAGS = $(KDE_RPATH) $(all_libraries)
diff --git a/ksvg/test/external/SVGTestWidget.cc b/ksvg/test/external/SVGTestWidget.cc
new file mode 100644
index 00000000..b954e94b
--- /dev/null
+++ b/ksvg/test/external/SVGTestWidget.cc
@@ -0,0 +1,206 @@
+// Very small test app to look at ksvg performance without konqueror overhead (Rob)
+
+#include "SVGTestWidget.moc"
+#include "DocumentFactory.h"
+#include "CanvasFactory.h"
+#include "SVGCircleElement.h"
+#include "SVGAnimatedLength.h"
+#include "SVGLength.h"
+#include "SVGSVGElement.h"
+#include "SVGEventImpl.h"
+#include "KSVGCanvas.h"
+#include "CanvasItem.h"
+#include <kcursor.h>
+
+using namespace KSVG;
+
+SVGTestWidget::SVGTestWidget(const KURL &url)
+{
+ setBackgroundColor(Qt::white);
+ setMouseTracking(true);
+ setFocusPolicy(WheelFocus);
+
+ m_doc = DocumentFactory::self()->requestDocument(this, SLOT(slotRenderingFinished()));
+ if(!m_doc)
+ return;
+
+ resize(450, 450);
+ m_canvas = CanvasFactory::self()->loadCanvas(450, 450);
+ if(!m_canvas)
+ return;
+
+ m_canvas->setup(this, this);
+
+ if(!DocumentFactory::self()->attachCanvas(m_canvas, m_doc))
+ return;
+
+ if(!DocumentFactory::self()->startParsing(m_doc, url))
+ return;
+}
+
+SVGTestWidget::~SVGTestWidget()
+{
+ delete m_canvas;
+ delete m_doc;
+}
+
+void SVGTestWidget::slotRenderingFinished()
+{
+ QRect rect(0, 0, width(), height());
+ m_canvas->blit(rect, true);
+
+ SVGElement test = m_doc->rootElement().getElementById("test");
+ if(test.nodeName() == "circle")
+ {
+ SVGCircleElement c = dom_cast(SVGCircleElement, test);
+ c.r().baseVal().setValue(150);
+ c.setAttribute("fill", "blue");
+ }
+}
+
+void SVGTestWidget::paintEvent(QPaintEvent *event)
+{
+ m_canvas->update();
+ m_canvas->blit(event->rect(), true);
+}
+
+void SVGTestWidget::resizeEvent(QResizeEvent *event)
+{
+ int w = event->size().width();
+ int h = event->size().height();
+
+ m_canvas->resize(w, h);
+ resize(w, h);
+ m_canvas->blit();
+}
+/*
+KSVG::SVGMouseEventImpl *newMouseEvent(SVGDocument *doc, KSVG::SVGEventImpl::EventId id, QMouseEvent *event)
+{
+ DOM::AbstractView temp;
+
+ int clientX = event->x();
+ int clientY = event->y();
+
+ if(doc && doc->rootElement())
+ {
+ clientX = int(clientX / doc->rootElement()->currentScale());
+ clientY = int(clientY / doc->rootElement()->currentScale());
+ }
+
+ int button = 0;
+ if(event->stateAfter() & Qt::LeftButton)
+ button = 1;
+ else if(event->stateAfter() & Qt::MidButton)
+ button = 2;
+ else if(event->stateAfter() & Qt::RightButton)
+ button = 3;
+
+ KSVG::SVGMouseEventImpl *mev = new KSVG::SVGMouseEventImpl(id, // type
+ true, // canBubbleArg
+ true, // cancelableArg
+ temp, // view
+ 0, // detail
+ event->globalX(), //screenXArg
+ event->globalY(), // screenYArg,
+ clientX, // clientXArg
+ clientY, // clientYArg
+ (event->state() & Qt::ControlButton), // ctrlKeyArg
+ (event->state() & Qt::AltButton), // altKeyArg
+ (event->state() & Qt::ShiftButton), // shiftKeyArg
+ (event->state() & Qt::MetaButton), // metaKeyArg
+ button, // buttonArg
+ 0);
+
+ mev->ref();
+
+ return mev;
+}
+
+void SVGTestWidget::mouseMoveEvent(QMouseEvent *event)
+{
+ if(event->state() & QMouseEvent::ControlButton && event->state() & QMouseEvent::LeftButton)
+ {
+ if(m_panningPos.isNull())
+ m_panningPos = event->pos();
+ else
+ {
+ QPoint panPoint = m_oldPanningPos - (m_panningPos - event->pos());
+ m_doc->rootElement()->setCurrentTranslate(panPoint);
+// m_doc->syncCachedMatrices(); FIXME
+ m_canvas->update(panPoint);
+ }
+ return;
+ }
+ else if(event->state() & QMouseEvent::ControlButton)
+ return;
+}
+
+void SVGTestWidget::mousePressEvent(QMouseEvent *event)
+{
+ if(event->state() & QMouseEvent::ControlButton)
+ return;
+
+ KSVG::SVGMouseEventImpl *mev = newMouseEvent(m_doc, KSVG::SVGEventImpl::MOUSEDOWN_EVENT, event);
+
+ if(m_doc && m_doc->rootElement())
+ m_doc->rootElement()->prepareMouseEvent(event->pos(), event->pos(), mev);
+ mev->deref();
+}
+
+void SVGTestWidget::mouseReleaseEvent(QMouseEvent *event)
+{
+ if(!m_panningPos.isNull())
+ {
+ m_oldPanningPos = m_oldPanningPos - (m_panningPos - event->pos());
+ m_panningPos.setX(0);
+ m_panningPos.setY(0);
+ }
+
+ if(event->state() & QMouseEvent::ControlButton)
+ return;
+
+ // only simulate mouse clicks for now
+ KSVG::SVGMouseEventImpl *mev = newMouseEvent(m_doc, KSVG::SVGEventImpl::MOUSEUP_EVENT, event);
+
+ if(m_doc && m_doc->rootElement())
+ m_doc->rootElement()->prepareMouseEvent(event->pos(), event->pos(), mev);
+ mev->deref();
+}
+
+void SVGTestWidget::keyPressEvent(QKeyEvent *event)
+{
+ if(event->stateAfter() & QMouseEvent::ControlButton)
+ {
+ setCursor(KCursor::sizeAllCursor());
+ return;
+ }
+}
+
+void SVGTestWidget::keyReleaseEvent(QKeyEvent *event)
+{
+ if(event->state() & QMouseEvent::ControlButton)
+ {
+ setCursor(KCursor::arrowCursor());
+ return;
+ }
+ SVGSVGElementImpl *root = m_doc->rootElement();
+ if(!root) return;
+ if(event->key() == Qt::Key_Minus)
+ {
+ erase(0, 0, m_canvas->width(), m_canvas->height());
+ float zoomFactor = root->currentScale() / 1.2;
+ root->setCurrentScale(zoomFactor);
+ m_doc->syncCachedMatrices();
+ m_canvas->update(zoomFactor);
+ }
+ else if(event->key() == Qt::Key_Plus)
+ {
+ float zoomFactor = root->currentScale() * 1.2;
+ root->setCurrentScale(zoomFactor);
+ m_doc->syncCachedMatrices();
+ m_canvas->update(zoomFactor);
+ }
+}
+*/
+
+// vim:ts=4:noet
diff --git a/ksvg/test/external/SVGTestWidget.h b/ksvg/test/external/SVGTestWidget.h
new file mode 100644
index 00000000..10ece576
--- /dev/null
+++ b/ksvg/test/external/SVGTestWidget.h
@@ -0,0 +1,37 @@
+#ifndef _SVGTESTWIDGET_H
+#define _SVGTESTWIDGET_H
+
+#include <qwidget.h>
+#include <qobject.h>
+#include "SVGDocument.h"
+#include "KSVGCanvas.h"
+
+class SVGTestWidget : public QWidget
+{
+Q_OBJECT
+public:
+ SVGTestWidget(const KURL &url);
+ ~SVGTestWidget();
+
+private slots:
+ void slotRenderingFinished();
+
+protected:
+ virtual void paintEvent(QPaintEvent *event);
+ virtual void resizeEvent(QResizeEvent *event);
+/* virtual void mousePressEvent(QMouseEvent *event);
+ virtual void mouseReleaseEvent(QMouseEvent *event);
+ virtual void keyPressEvent(QKeyEvent *event);
+ virtual void keyReleaseEvent(QKeyEvent *event);
+ virtual void mouseMoveEvent(QMouseEvent *event);
+*/
+private:
+ QPoint m_panningPos;
+ QPoint m_oldPanningPos;
+
+ KSVG::SVGDocument *m_doc;
+ KSVG::KSVGCanvas *m_canvas;
+};
+
+#endif
+
diff --git a/ksvg/test/external/printnodetest.cpp b/ksvg/test/external/printnodetest.cpp
new file mode 100644
index 00000000..b2547e7f
--- /dev/null
+++ b/ksvg/test/external/printnodetest.cpp
@@ -0,0 +1,63 @@
+#include <DocumentFactory.h>
+#include <SVGSVGElement.h>
+#include <SVGDocument.h>
+#include <SVGWindow.h>
+
+#include <kapplication.h>
+#include <kcmdlineargs.h>
+#include <klocale.h>
+#include <kaboutdata.h>
+#include <kdebug.h>
+
+#include "printnodetest.moc"
+
+using namespace KSVG;
+
+static KCmdLineOptions options[] =
+{
+ { "+URL", I18N_NOOP("SVG file to open"), 0 },
+ KCmdLineLastOption
+};
+
+Worker::Worker(const KURL &url)
+{
+ m_doc = DocumentFactory::self()->requestDocument(this, SLOT(slotParsingFinished(bool, const QString &)));
+
+ if(!m_doc)
+ return;
+
+ if(!DocumentFactory::self()->startParsing(m_doc, url))
+ return;
+}
+
+Worker::~Worker()
+{
+ delete m_doc;
+}
+
+void Worker::slotParsingFinished(bool, const QString &)
+{
+ SVGWindow win = m_doc->window();
+ SVGSVGElement root = m_doc->rootElement();
+
+ kdDebug() << win.printNode(root).string() << endl;
+ exit(0);
+}
+
+int main(int argc, char **argv)
+{
+ KAboutData *about = new KAboutData("KSVG printNode test app", I18N_NOOP("KSVG test"), "0.1", I18N_NOOP("KSVG printNode test app"));
+ KCmdLineArgs::init(argc, argv, about);
+ KCmdLineArgs::addCmdLineOptions(options);
+ KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+ if(args->count() == 0)
+ {
+ args->usage();
+ return -1;
+ }
+
+ KApplication a(argc, argv);
+ (void) new Worker(args->url(0));
+ return a.exec();
+}
+
diff --git a/ksvg/test/external/printnodetest.h b/ksvg/test/external/printnodetest.h
new file mode 100644
index 00000000..e95a46a9
--- /dev/null
+++ b/ksvg/test/external/printnodetest.h
@@ -0,0 +1,32 @@
+#ifndef PRINTNODETEST_H
+#define PRINTNODETEST_H
+
+#include <kurl.h>
+#include <qobject.h>
+
+namespace KSVG
+{
+
+class SVGDocument;
+class Worker : public QObject
+{
+Q_OBJECT
+public:
+ Worker(const KURL &url);
+ ~Worker();
+
+private slots:
+ void slotParsingFinished(bool error, const QString &errorDesc);
+
+private:
+ // It's not allowed to store a m_doc object here,
+ // because it's ctor is called before we can setup
+ // our 'DocumentFactory', in that case it'll just crash (Niko)
+ SVGDocument *m_doc;
+};
+
+}
+
+#endif
+
+// vim:ts=4:noet
diff --git a/ksvg/test/external/svgdisplay.cc b/ksvg/test/external/svgdisplay.cc
new file mode 100644
index 00000000..662fb542
--- /dev/null
+++ b/ksvg/test/external/svgdisplay.cc
@@ -0,0 +1,32 @@
+#include <kapplication.h>
+#include <kcmdlineargs.h>
+#include <klocale.h>
+#include <kaboutdata.h>
+#include "SVGTestWidget.h"
+
+static KCmdLineOptions options[] =
+{
+ { "+URL", I18N_NOOP("SVG file to open"), 0 },
+ KCmdLineLastOption
+};
+
+int main(int argc, char **argv)
+{
+
+ KAboutData *about = new KAboutData( "KSVG test app", I18N_NOOP("KSVG test"), "0.1", I18N_NOOP("KSVG standalone test app") );
+ KCmdLineArgs::init(argc, argv, about);
+ KCmdLineArgs::addCmdLineOptions( options );
+ KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+ if(args->count() == 0)
+ {
+ args->usage();
+ return 0;
+ }
+ KURL url = args->url(0);
+ KApplication a( argc, argv );
+ SVGTestWidget *w = new SVGTestWidget(url);
+ a.setMainWidget(w);
+ w->show();
+
+ return a.exec();
+}