summaryrefslogtreecommitdiffstats
path: root/tests/arthur/lance
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar@trolltech.com>2009-07-29 10:15:57 (GMT)
committerGunnar Sletta <gunnar@trolltech.com>2009-07-30 12:31:52 (GMT)
commitaec91cf6fbfa6abd4a3548690fd22ebeb6237cf6 (patch)
tree610b37fa05fa8e82d70e3d0e813b4885c36dbb53 /tests/arthur/lance
parent9939ce88427b4d33f50b45a0da85266f9ee37927 (diff)
downloadQt-aec91cf6fbfa6abd4a3548690fd22ebeb6237cf6.zip
Qt-aec91cf6fbfa6abd4a3548690fd22ebeb6237cf6.tar.gz
Qt-aec91cf6fbfa6abd4a3548690fd22ebeb6237cf6.tar.bz2
updates...
Diffstat (limited to 'tests/arthur/lance')
-rw-r--r--tests/arthur/lance/interactivewidget.cpp2
-rw-r--r--tests/arthur/lance/lance.pro2
-rw-r--r--tests/arthur/lance/main.cpp16
-rw-r--r--tests/arthur/lance/widgets.h151
4 files changed, 150 insertions, 21 deletions
diff --git a/tests/arthur/lance/interactivewidget.cpp b/tests/arthur/lance/interactivewidget.cpp
index 0febbed..0c2c7a6 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..ee9e08b 100644
--- a/tests/arthur/lance/lance.pro
+++ b/tests/arthur/lance/lance.pro
@@ -6,7 +6,7 @@ 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
diff --git a/tests/arthur/lance/main.cpp b/tests/arthur/lance/main.cpp
index 07e5180..f95b426 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[] = {
@@ -282,7 +282,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;
}
@@ -403,12 +403,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 +416,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 +448,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();
diff --git a/tests/arthur/lance/widgets.h b/tests/arthur/lance/widgets.h
index 271c18a..7247608 100644
--- a/tests/arthur/lance/widgets.h
+++ b/tests/arthur/lance/widgets.h
@@ -57,15 +57,47 @@
#include <QTextStream>
#include <QPaintEngine>
+#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_view_mode(RenderView),
+ m_filename(file)
{
QSettings settings("Trolltech", "lance");
for (int i=0; i<10; ++i) {
@@ -78,11 +110,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()) {
+ setWindowTitle("Rendering: '" + file + "'. No baseline available");
+ } else {
+ setWindowTitle("Rendering: '" + file + "'. Shortcuts: 1=render, 2=baseline, 3=difference");
+
+ StupidWorkaround *workaround = new StupidWorkaround(this, &m_view_mode);
+
+ QSignalMapper *mapper = new QSignalMapper(this);
+ connect(mapper, SIGNAL(mapped(int)), workaround, SLOT(setViewMode(int)));
+ connect(mapper, SIGNAL(mapped(QString)), this, SLOT(setWindowTitle(QString)));
+
+ QAction *renderViewAction = new QAction("Render View", this);
+ renderViewAction->setShortcut(Qt::Key_1);
+ connect(renderViewAction, SIGNAL(triggered()), mapper, SLOT(map()));
+ mapper->setMapping(renderViewAction, RenderView);
+ mapper->setMapping(renderViewAction, "Render View: " + file);
+ addAction(renderViewAction);
+
+ QAction *baselineAction = new QAction("Baseline", this);
+ baselineAction->setShortcut(Qt::Key_2);
+ connect(baselineAction, SIGNAL(triggered()), mapper, SLOT(map()));
+ mapper->setMapping(baselineAction, BaselineView);
+ mapper->setMapping(baselineAction, "Baseline View: " + file);
+ addAction(baselineAction);
+
+ QAction *differenceAction = new QAction("Differenfe View", this);
+ differenceAction->setShortcut(Qt::Key_3);
+ connect(differenceAction, SIGNAL(triggered()), mapper, SLOT(map()));
+ mapper->setMapping(differenceAction, DifferenceView);
+ mapper->setMapping(differenceAction, "Difference View" + file);
+ addAction(differenceAction);
+
+ }
+
+ }
~OnScreenWidget()
{
@@ -93,12 +161,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 OnScreenWidget<T>::paintRenderView()
{
QPainter pt;
QPaintDevice *dev = this;
@@ -152,6 +232,57 @@ public:
}
}
+ if (m_render_view.isNull()) {
+ m_render_view = window()->windowSurface()->grabWidget(this);
+ m_render_view.save("renderView.png");
+ }
+ }
+
+ void paintBaselineView() {
+ QPainter p(this);
+
+ if (m_baseline.isNull()) {
+ p.drawText(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(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(rect(), Qt::AlignCenter,
+ "No baseline found\n"
+ "file '" + m_baseline_name + "' does not exist...");
+ return;
+ }
+
+ p.fillRect(rect(), Qt::black);
+ p.drawPixmap(0, 0, generateDifference());
}
@@ -190,8 +321,6 @@ public:
T::update();
}
-
-
QSize sizeHint() const { return QSize(800, 800); }
QVector<QPointF> m_controlPoints;
@@ -200,12 +329,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