| 1 |
/* |
| 2 |
* Copyright 2012 Canonical Ltd. |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU Lesser General Public License as published by |
| 6 |
* the Free Software Foundation; version 3. |
| 7 |
* |
| 8 |
* This program is distributed in the hope that it will be useful, |
| 9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
* GNU Lesser General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU Lesser General Public License |
| 14 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 |
* |
| 16 |
* Author: Juhapekka Piiroinen <[email protected]> |
| 17 |
*/ |
| 18 |
|
| 19 |
#include "testcaseexecutiondialog.h" |
| 20 |
#include "ui_testcaseexecutiondialog.h" |
| 21 |
|
| 22 |
#include <QGLWidget> |
| 23 |
|
| 24 |
|
| 25 |
TestCaseExecutionDialog::TestCaseExecutionDialog(QString testcase, |
| 26 |
QString testdata, |
| 27 |
QUrl qmlFile, |
| 28 |
QWidget *parent) : QDialog(parent), |
| 29 |
m_declarativeView(new QDeclarativeView), |
| 30 |
m_ui(new Ui::TestCaseExecutionDialog) { |
| 31 |
m_ui->setupUi(this); |
| 32 |
m_ui->plainTextEdit->setPlainText(testdata); |
| 33 |
this->setWindowTitle(testcase); |
| 34 |
m_ui->horizontalLayout->addWidget(m_declarativeView); |
| 35 |
|
| 36 |
QFile qmldata(qmlFile.toLocalFile()); |
| 37 |
QString data; |
| 38 |
if (qmldata.open(QIODevice::ReadOnly)) { |
| 39 |
data = qmldata.readAll(); |
| 40 |
qmldata.close(); |
| 41 |
} |
| 42 |
|
| 43 |
m_ui->plainTextEdit_2->setPlainText(data); |
| 44 |
|
| 45 |
QTemporaryFile tmpQmlFile; |
| 46 |
tmpQmlFile.open(); |
| 47 |
tmpQmlFile.write(data.toAscii()); |
| 48 |
tmpQmlFile.close(); |
| 49 |
qDebug() << "using temporary file" << tmpQmlFile.fileName(); |
| 50 |
|
| 51 |
m_declarativeView->engine()->addImportPath("../qml/"); |
| 52 |
QGLFormat format = QGLFormat::defaultFormat(); |
| 53 |
format.setSampleBuffers(false); |
| 54 |
format.setSwapInterval(1); |
| 55 |
|
| 56 |
QGLWidget *glWidget = new QGLWidget(format); |
| 57 |
glWidget->setAttribute(Qt::WA_TranslucentBackground, false); |
| 58 |
m_declarativeView->setAttribute(Qt::WA_TranslucentBackground, false); |
| 59 |
m_declarativeView->setAttribute(Qt::WA_NoSystemBackground, true); |
| 60 |
m_declarativeView->setAttribute(Qt::WA_OpaquePaintEvent, true); |
| 61 |
m_declarativeView->setViewport(glWidget); |
| 62 |
m_declarativeView->setViewportUpdateMode(QGraphicsView::FullViewportUpdate); |
| 63 |
m_declarativeView->setSource(QUrl::fromLocalFile(tmpQmlFile.fileName())); |
| 64 |
m_declarativeView->show(); |
| 65 |
m_declarativeView->viewport()->setFocusPolicy(Qt::StrongFocus); |
| 66 |
} |
| 67 |
|
| 68 |
void TestCaseExecutionDialog::on_pushButton_clicked() { |
| 69 |
QTemporaryFile tmpQmlFile; |
| 70 |
tmpQmlFile.open(); |
| 71 |
tmpQmlFile.write(m_ui->plainTextEdit_2->toPlainText().toAscii()); |
| 72 |
tmpQmlFile.close(); |
| 73 |
m_declarativeView->engine()->clearComponentCache(); |
| 74 |
m_declarativeView->setSource(QUrl::fromLocalFile(tmpQmlFile.fileName())); |
| 75 |
} |
| 76 |
|
| 77 |
TestCaseExecutionDialog::~TestCaseExecutionDialog() { |
| 78 |
delete m_ui; |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
void TestCaseExecutionDialog::on_pushButtonQuit_clicked() { |
| 83 |
QApplication::quit(); |
| 84 |
} |