summaryrefslogtreecommitdiffstats
path: root/tests/arthur/lance
diff options
context:
space:
mode:
Diffstat (limited to 'tests/arthur/lance')
-rw-r--r--tests/arthur/lance/interactivewidget.cpp2
-rw-r--r--tests/arthur/lance/lance.pro10
-rw-r--r--tests/arthur/lance/main.cpp27
-rw-r--r--tests/arthur/lance/widgets.h154
4 files changed, 166 insertions, 27 deletions
diff --git a/tests/arthur/lance/interactivewidget.cpp b/tests/arthur/lance/interactivewidget.cpp
index ab7691a..8f40cc5 100644
--- a/tests/arthur/lance/interactivewidget.cpp
+++ b/tests/arthur/lance/interactivewidget.cpp
@@ -43,7 +43,7 @@
InteractiveWidget::InteractiveWidget()
{
- m_onScreenWidget = new OnScreenWidget<QWidget>();
+ m_onScreenWidget = new OnScreenWidget<QWidget>("");
m_onScreenWidget->setMinimumSize(320, 240);
setCentralWidget(m_onScreenWidget);
diff --git a/tests/arthur/lance/lance.pro b/tests/arthur/lance/lance.pro
index 193dbd2..3692f21 100644
--- a/tests/arthur/lance/lance.pro
+++ b/tests/arthur/lance/lance.pro
@@ -6,12 +6,18 @@ INCLUDEPATH += .
# Input
HEADERS += widgets.h interactivewidget.h
-SOURCES += interactivewidget.cpp main.cpp
+SOURCES += interactivewidget.cpp main.cpp
RESOURCES += icons.qrc
contains(QT_CONFIG, opengl)|contains(QT_CONFIG, opengles1)|contains(QT_CONFIG, opengles2):QT += opengl
contains(QT_CONFIG, qt3support):QT += qt3support
-QT += xml svg
+symbian*: {
+ testData.sources = $$QT_BUILD_TREE/tests/arthur/data/qps
+ testData.path = .
+ DEPLOYMENT += testData
+}
+
+QT += xml svg
diff --git a/tests/arthur/lance/main.cpp b/tests/arthur/lance/main.cpp
index eeaa4a1..4f0d96d 100644
--- a/tests/arthur/lance/main.cpp
+++ b/tests/arthur/lance/main.cpp
@@ -66,7 +66,7 @@ extern bool qt_show_painter_debug_output = false;
//#define CONSOLE_APPLICATION
-static const struct {
+static const struct {
const char *name;
QImage::Format format;
} imageFormats[] = {
@@ -199,7 +199,6 @@ static void displayCommands()
" pixmap_load filename name_in_script\n"
" image_load filename name_in_script\n");
}
-
static InteractiveWidget *interactive_widget = 0;
static void runInteractive()
@@ -271,7 +270,7 @@ int main(int argc, char **argv)
QString format = QString(argv[++i]).toLower();
imageFormat = QImage::Format_Invalid;
- static const unsigned int formatCount =
+ static const int formatCount =
sizeof(imageFormats) / sizeof(imageFormats[0]);
for (int ff = 0; ff < formatCount; ++ff) {
if (QLatin1String(imageFormats[ff].name) == format) {
@@ -282,7 +281,7 @@ int main(int argc, char **argv)
if (imageFormat == QImage::Format_Invalid) {
printf("Invalid image format. Available formats are:\n");
- for (int ff = 0; ff < formatCount; ++ff)
+ for (int ff = 0; ff < formatCount; ++ff)
printf("\t%s\n", imageFormats[ff].name);
return -1;
}
@@ -381,7 +380,7 @@ int main(int argc, char **argv)
QString script = textFile.readAll();
content = script.split("\n", QString::SkipEmptyParts);
} else {
- printf("failed to read file: '%s'\n", qPrintable(fileName));
+ printf("failed to read file: '%s'\n", qPrintable(fileinfo.absoluteFilePath()));
continue;
}
pcmd.setContents(content);
@@ -403,12 +402,10 @@ int main(int argc, char **argv)
case WidgetType:
{
OnScreenWidget<QWidget> *qWidget =
- new OnScreenWidget<QWidget>;
+ new OnScreenWidget<QWidget>(files.at(j));
qWidget->setVerboseMode(verboseMode);
qWidget->setType(type);
qWidget->setCheckersBackground(checkers_background);
- qWidget->m_filename = files.at(j);
- qWidget->setWindowTitle(fileinfo.filePath());
qWidget->m_commands = content;
qWidget->resize(width, height);
qWidget->show();
@@ -418,12 +415,10 @@ int main(int argc, char **argv)
case ImageWidgetType:
{
- OnScreenWidget<QWidget> *qWidget = new OnScreenWidget<QWidget>;
+ OnScreenWidget<QWidget> *qWidget = new OnScreenWidget<QWidget>(files.at(j));
qWidget->setVerboseMode(verboseMode);
qWidget->setType(type);
qWidget->setCheckersBackground(checkers_background);
- qWidget->m_filename = files.at(j);
- qWidget->setWindowTitle(fileinfo.filePath());
qWidget->m_commands = content;
qWidget->resize(width, height);
qWidget->show();
@@ -452,12 +447,10 @@ int main(int argc, char **argv)
}
case OpenGLType:
{
- OnScreenWidget<QGLWidget> *qGLWidget = new OnScreenWidget<QGLWidget>;
+ OnScreenWidget<QGLWidget> *qGLWidget = new OnScreenWidget<QGLWidget>(files.at(j));
qGLWidget->setVerboseMode(verboseMode);
qGLWidget->setType(type);
qGLWidget->setCheckersBackground(checkers_background);
- qGLWidget->m_filename = files.at(j);
- qGLWidget->setWindowTitle(fileinfo.filePath());
qGLWidget->m_commands = content;
qGLWidget->resize(width, height);
qGLWidget->show();
@@ -587,6 +580,7 @@ int main(int argc, char **argv)
case PrinterType:
{
+#ifndef QT_NO_PRINTER
PaintCommands pcmd(QStringList(), 800, 800);
pcmd.setVerboseMode(verboseMode);
pcmd.setType(type);
@@ -614,11 +608,13 @@ int main(int argc, char **argv)
}
Q_ASSERT(!p.paintingActive());
+#endif
break;
}
case PsType:
case PdfType:
{
+#ifndef QT_NO_PRINTER
PaintCommands pcmd(QStringList(), 800, 800);
pcmd.setVerboseMode(verboseMode);
pcmd.setType(type);
@@ -641,6 +637,7 @@ int main(int argc, char **argv)
pt.end();
printf("write file: %s\n", qPrintable(file));
+#endif
break;
}
case GrabType:
@@ -663,7 +660,6 @@ int main(int argc, char **argv)
printf("%s grabbed to %s\n", qPrintable(files.at(j)), qPrintable(filename));
break;
}
-
default:
break;
}
@@ -674,7 +670,6 @@ int main(int argc, char **argv)
QObject::connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
app.exec();
}
-
delete activeWidget;
#endif
return 0;
diff --git a/tests/arthur/lance/widgets.h b/tests/arthur/lance/widgets.h
index 09fe884..dba2ae1 100644
--- a/tests/arthur/lance/widgets.h
+++ b/tests/arthur/lance/widgets.h
@@ -56,16 +56,51 @@
#include <QFileDialog>
#include <QTextStream>
#include <QPaintEngine>
+#include <QSignalMapper>
+#include <QAction>
+
+
+#include <private/qwindowsurface_p.h>
#include <qmath.h>
const int CP_RADIUS = 10;
+class StupidWorkaround : public QObject
+{
+ Q_OBJECT
+public:
+ StupidWorkaround(QWidget *widget, int *value)
+ : QObject(widget), w(widget), mode(value)
+ {
+ }
+
+public slots:
+ void setViewMode(int m) {
+ *mode = m;
+ w->update();
+ }
+
+private:
+ QWidget *w;
+ int *mode;
+};
+
template <class T>
class OnScreenWidget : public T
{
public:
- OnScreenWidget(QWidget *parent = 0) : T(parent)
+
+ enum ViewMode {
+ RenderView,
+ BaselineView,
+ DifferenceView
+ };
+
+ OnScreenWidget(const QString &file, QWidget *parent = 0)
+ : T(parent),
+ m_filename(file),
+ m_view_mode(RenderView)
{
QSettings settings("Trolltech", "lance");
for (int i=0; i<10; ++i) {
@@ -78,11 +113,47 @@ public:
m_deviceType = WidgetType;
m_checkersBackground = true;
m_verboseMode = false;
- }
- void setVerboseMode(bool v) { m_verboseMode = v; }
- void setCheckersBackground(bool b) { m_checkersBackground = b; }
- void setType(DeviceType t) { m_deviceType = t; }
+ m_baseline_name = QString(m_filename).replace(".qps", "_qps") + ".png";
+ if (QFileInfo(m_baseline_name).exists()) {
+ m_baseline = QPixmap(m_baseline_name);
+ }
+
+ if (m_baseline.isNull()) {
+ T::setWindowTitle("Rendering: '" + file + "'. No baseline available");
+ } else {
+ T::setWindowTitle("Rendering: '" + file + "'. Shortcuts: 1=render, 2=baseline, 3=difference");
+
+ StupidWorkaround *workaround = new StupidWorkaround(this, &m_view_mode);
+
+ QSignalMapper *mapper = new QSignalMapper(this);
+ T::connect(mapper, SIGNAL(mapped(int)), workaround, SLOT(setViewMode(int)));
+ T::connect(mapper, SIGNAL(mapped(QString)), this, SLOT(setWindowTitle(QString)));
+
+ QAction *renderViewAction = new QAction("Render View", this);
+ renderViewAction->setShortcut(Qt::Key_1);
+ T::connect(renderViewAction, SIGNAL(triggered()), mapper, SLOT(map()));
+ mapper->setMapping(renderViewAction, RenderView);
+ mapper->setMapping(renderViewAction, "Render View: " + file);
+ T::addAction(renderViewAction);
+
+ QAction *baselineAction = new QAction("Baseline", this);
+ baselineAction->setShortcut(Qt::Key_2);
+ T::connect(baselineAction, SIGNAL(triggered()), mapper, SLOT(map()));
+ mapper->setMapping(baselineAction, BaselineView);
+ mapper->setMapping(baselineAction, "Baseline View: " + file);
+ T::addAction(baselineAction);
+
+ QAction *differenceAction = new QAction("Differenfe View", this);
+ differenceAction->setShortcut(Qt::Key_3);
+ T::connect(differenceAction, SIGNAL(triggered()), mapper, SLOT(map()));
+ mapper->setMapping(differenceAction, DifferenceView);
+ mapper->setMapping(differenceAction, "Difference View" + file);
+ T::addAction(differenceAction);
+
+ }
+
+ }
~OnScreenWidget()
{
@@ -93,12 +164,24 @@ public:
settings.sync();
}
+ void setVerboseMode(bool v) { m_verboseMode = v; }
+ void setCheckersBackground(bool b) { m_checkersBackground = b; }
+ void setType(DeviceType t) { m_deviceType = t; }
+
void resizeEvent(QResizeEvent *e) {
m_image = QImage();
T::resizeEvent(e);
}
- void paintEvent(QPaintEvent *)
+ void paintEvent(QPaintEvent *) {
+ switch (m_view_mode) {
+ case RenderView: paintRenderView(); break;
+ case BaselineView: paintBaselineView(); break;
+ case DifferenceView: paintDifferenceView(); break;
+ }
+ }
+
+ void paintRenderView()
{
QPainter pt;
QPaintDevice *dev = this;
@@ -152,6 +235,57 @@ public:
}
}
+ if (m_render_view.isNull()) {
+ m_render_view = T::window()->windowSurface()->grabWidget(this);
+ m_render_view.save("renderView.png");
+ }
+ }
+
+ void paintBaselineView() {
+ QPainter p(this);
+
+ if (m_baseline.isNull()) {
+ p.drawText(T::rect(), Qt::AlignCenter,
+ "No baseline found\n"
+ "file '" + m_baseline_name + "' does not exist...");
+ return;
+ }
+
+ p.drawPixmap(0, 0, m_baseline);
+
+ p.setPen(QColor::fromRgb(0, 0, 0, 0.1));
+ p.setFont(QFont("Arial", 128));
+ p.rotate(45);
+ p.drawText(100, 0, "BASELINE");
+ }
+
+ QPixmap generateDifference()
+ {
+ QImage img(T::size(), QImage::Format_RGB32);
+ img.fill(0);
+
+ QPainter p(&img);
+ p.drawPixmap(0, 0, m_render_view);
+
+ p.setCompositionMode(QPainter::RasterOp_SourceXorDestination);
+ p.drawPixmap(0, 0, m_baseline);
+
+ p.end();
+
+ return QPixmap::fromImage(img);
+ }
+
+ void paintDifferenceView() {
+ QPainter p(this);
+ if (m_baseline.isNull()) {
+ p.drawText(T::rect(), Qt::AlignCenter,
+ "No baseline found\n"
+ "file '" + m_baseline_name + "' does not exist...");
+ return;
+ }
+
+ p.fillRect(T::rect(), Qt::black);
+ p.drawPixmap(0, 0, generateDifference());
}
@@ -190,8 +324,6 @@ public:
T::update();
}
-
-
QSize sizeHint() const { return QSize(800, 800); }
QVector<QPointF> m_controlPoints;
@@ -200,12 +332,18 @@ public:
QStringList m_commands;
QString m_filename;
+ QString m_baseline_name;
bool m_verboseMode;
bool m_checkersBackground;
DeviceType m_deviceType;
+ int m_view_mode;
+
QImage m_image;
+
+ QPixmap m_baseline;
+ QPixmap m_render_view;
};
#endif