1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
/*
* Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include "widget.h"
#include "qwebelement.h"
#include "qwebframe.h"
#include "ui_widget.h"
#include <QPainter>
#include <QtTest/QtTest>
Widget::Widget(QWidget* parent) :
QWidget(parent),
ui(new Ui::Widget),
abcFilledImage(32, 32, QImage::Format_ARGB32)
{
ui->setupUi(this);
abcFilledImage.fill(qRgba(0xaa, 0xbb, 0xcc, 0xff));
}
void Widget::refreshJS()
{
ui->webView->page()->mainFrame()->addToJavaScriptWindowObject("myWidget", this);
}
void Widget::start()
{
ui->webView->load(QUrl("qrc:///test.html"));
connect(ui->webView->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(refreshJS()));
ui->webView->page()->mainFrame()->addToJavaScriptWindowObject("myWidget", this);
}
void Widget::completeTest()
{
QCOMPARE(ui->lbl1->pixmap()->size(), ui->lbl2->size());
QCOMPARE(ui->lbl3->size(), ui->lbl4->pixmap()->size());
QCOMPARE(ui->lbl2->size().width(), ui->webView->page()->mainFrame()->findFirstElement("#img1").evaluateJavaScript("this.width").toInt());
QCOMPARE(ui->lbl3->size().width(), ui->webView->page()->mainFrame()->findFirstElement("#img2").evaluateJavaScript("this.width").toInt());
emit testComplete();
}
void Widget::setPixmap(const QPixmap& p)
{
ui->lbl1->setPixmap(p);
}
QPixmap Widget::pixmap() const
{
QPixmap px(ui->lbl3->size());
{
QPainter p(&px);
ui->lbl3->render(&p);
}
return px;
}
void Widget::setImage(const QImage& img)
{
ui->lbl4->setPixmap(QPixmap::fromImage(img));
}
QImage Widget::image() const
{
QImage img(ui->lbl2->size(), QImage::Format_ARGB32);
{
QPainter p(&img);
ui->lbl2->render(&p);
}
return img;
}
QImage Widget::abcImage(int format)
{
return abcFilledImage.convertToFormat(static_cast<QImage::Format>(format));
}
Widget::~Widget()
{
delete ui;
}
void Widget::changeEvent(QEvent* e)
{
QWidget::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void Widget::compare(const QVariant& a, const QVariant& b)
{
QCOMPARE(a, b);
}
void Widget::imageSlot(const QImage& img)
{
QCOMPARE(img.size(), ui->lbl3->size());
emit pixmapSignal(QPixmap::fromImage(img));
}
void Widget::pixmapSlot(const QPixmap& pxm)
{
QCOMPARE(pxm.size(), ui->lbl2->size());
emit imageSignal(ui->lbl4->pixmap()->toImage());
}
void Widget::randomSlot(const QPixmap& pxm)
{
QVERIFY(pxm.isNull());
}
|