diff options
author | Bjørn Erik Nilsen <bjorn.nilsen@nokia.com> | 2010-02-08 16:08:01 (GMT) |
---|---|---|
committer | Bjørn Erik Nilsen <bjorn.nilsen@nokia.com> | 2010-02-11 17:28:47 (GMT) |
commit | 2f389a95f5b9e4c7130aa333586d803b639bf259 (patch) | |
tree | b74584ba8fba1a5e0878f74db5bbb14c098f9bf9 /tests/benchmarks/gui/graphicsview/functional/GraphicsViewBenchmark/widgets/mainview.cpp | |
parent | 5906f4dc55e52b233200f7196f4ce7094f764f6a (diff) | |
download | Qt-2f389a95f5b9e4c7130aa333586d803b639bf259.zip Qt-2f389a95f5b9e4c7130aa333586d803b639bf259.tar.gz Qt-2f389a95f5b9e4c7130aa333586d803b639bf259.tar.bz2 |
Add functional Graphics View benchmarks.
Widgets and use cases are externally developed and imported from:
git://gitorious.org/+qt-performance-test-developers/qt/qt-performance-test-developers-clone.git
(master branch, tests/benchmarks/uimodels/GraphicsViewBenchmark)
I couldn't simply import everything because the benchmarks were heavily
dependent on an internal measuring tool involving QtScripts and whatnot,
not suitable for inclusion in the Qt repository. Everything is now converted
into proper QTestLib compatible benchmark functions.
Diffstat (limited to 'tests/benchmarks/gui/graphicsview/functional/GraphicsViewBenchmark/widgets/mainview.cpp')
-rw-r--r-- | tests/benchmarks/gui/graphicsview/functional/GraphicsViewBenchmark/widgets/mainview.cpp | 348 |
1 files changed, 348 insertions, 0 deletions
diff --git a/tests/benchmarks/gui/graphicsview/functional/GraphicsViewBenchmark/widgets/mainview.cpp b/tests/benchmarks/gui/graphicsview/functional/GraphicsViewBenchmark/widgets/mainview.cpp new file mode 100644 index 0000000..2379714 --- /dev/null +++ b/tests/benchmarks/gui/graphicsview/functional/GraphicsViewBenchmark/widgets/mainview.cpp @@ -0,0 +1,348 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QDebug> +#include <QApplication> +#include <QGraphicsLinearLayout> +#if ENABLE_OPENGL +#ifndef QT_NO_OPENGL +#include <QGLWidget> +#endif +#endif +#include <QObject> + +#include "button.h" +#include "label.h" +#include "menu.h" +#include "topbar.h" +#include "backgrounditem.h" +#include "theme.h" +#include "mainview.h" +#include "gvbwidget.h" + +MainView::MainView(const bool enableOpenGL, const bool outputFps, const bool imageRendering, QWidget *parent) + : QGraphicsView(parent) + , m_scene(0) + , m_mainLayout(0) + , m_mainWidget(0) + , m_testWidget(0) + , m_imageBasedRendering(imageRendering) + , m_pixmapToRender(0) + , m_OutputFps(outputFps) + , m_fpsUpdated() + , m_Fpss() + , m_angle(0) + , m_enableOpenGL(enableOpenGL) +{ + construct(); +} + +MainView::~MainView() +{ + if (!m_scene->parent()) + delete m_scene; + + delete m_pixmapToRender; +} + +void MainView::setTestWidget(QGraphicsWidget *testWidget) +{ + if (!testWidget) + return; + + if (m_testWidget) { + m_mainLayout->removeItem(m_testWidget); + if (!m_testWidget->parent() && !m_testWidget->parentLayoutItem()) + delete m_testWidget; + } + m_testWidget = testWidget; + m_mainLayout->addItem(m_testWidget); + resizeContent(size()); +} + +QGraphicsWidget *MainView::takeTestWidget() +{ + if (m_testWidget) { + m_mainLayout->removeItem(m_testWidget); + QGraphicsWidget *tmp = m_testWidget; + m_testWidget = 0; + return tmp; + } + return 0; +} + +QGraphicsWidget *MainView::testWidget() +{ + return m_testWidget; +} + +void MainView::setImageBasedRendering(const bool imageBasedRendering) +{ + m_imageBasedRendering = imageBasedRendering; + delete m_pixmapToRender; + m_pixmapToRender = 0; + viewport()->update(); +} + +bool MainView::imageBasedRendering() const +{ + return m_imageBasedRendering; +} + +qreal MainView::fps() +{ + if (m_Fpss.count() <= 0) + updateFps(); + + if (m_Fpss.count() <= 0) + return 0.0; + + qreal sum = 0; + int count = m_Fpss.count(); + for (int i = 0; i<count; ++i) + sum += m_Fpss.at(i); + m_Fpss.clear(); + fpsReset(); + return sum/qreal(count); +} + +void MainView::fpsReset() +{ + m_frameCount = 0; + m_fpsFirstTs.start(); + m_fpsLatestTs = m_fpsFirstTs; + m_fpsUpdated.start(); +} + +void MainView::rotateContent(int angle) +{ + bool portrait = ((m_angle+angle)%90 == 0) && ((m_angle+angle)%180 != 0); + bool landscape = ((m_angle+angle)%180 == 0); + if (!portrait && !landscape) + return; + + m_angle = (m_angle + angle)%360; + + rotate(angle); + + resizeContent(size()); +} + +int MainView::rotationAngle() const +{ + return m_angle; +} + +void MainView::resizeContent(const QSize &s) +{ + QSizeF l_size(s); + QSizeF p_size(l_size.height(), l_size.width()); + bool portrait = (m_angle%90 == 0) && (m_angle%180 != 0); + if (portrait) { + m_mainWidget->resize(p_size); + m_backGround->resize(p_size); + } + else { + m_mainWidget->resize(l_size); + m_backGround->resize(l_size); + } + m_menu->setPos(m_topBar->getStatusBarLocation()); + setSceneRect(QRectF(m_mainWidget->pos(), m_mainWidget->size())); +} + +void MainView::resizeEvent(QResizeEvent * event) +{ + QGraphicsView::resizeEvent(event); + resizeContent(event->size()); +} + +void MainView::paintEvent (QPaintEvent *event) +{ + if (m_imageBasedRendering) { + if (!m_pixmapToRender) + m_pixmapToRender = new QPixmap(size()); + + if (m_pixmapToRender->size() != size()) { + delete m_pixmapToRender; + m_pixmapToRender = new QPixmap(size()); + } + QPainter p(m_pixmapToRender); + render(&p); + p.end(); + } + else { + QGraphicsView::paintEvent(event); + } + emit repainted(); + + m_frameCount++; + m_fpsLatestTs.start(); + if(m_fpsUpdated.elapsed() > 2000) { + updateFps(); + m_fpsUpdated.start(); + } +} + +void MainView::keyPressEvent(QKeyEvent *event) +{ + if (event->key() == Qt::Key_F) { + if (isFullScreen()) + showNormal(); + else + showFullScreen(); + } + + //S60 3.x specific + if(m_menu->menuVisible()) { + m_menu->keyPressEvent(event); + return; + } + + if(event->key() == 16777235 ) { //Up Arrow + GvbWidget* widget = qobject_cast<GvbWidget*>(m_testWidget); + if(widget) + widget->keyPressEvent(event); + } + + if(event->key() == 16777237 ) { //Down Arrow + GvbWidget* widget = qobject_cast<GvbWidget*>(m_testWidget); + if(widget) + widget->keyPressEvent(event); + } + + if(event->key() == 17825792 ) { //LSK + if(!m_menu->menuVisible()) + m_menu->menuShowHide(); + } + + if(event->key() == 17825793 ) { //RSK + QApplication::quit(); + } +} + +void MainView::construct() +{ + m_scene = new QGraphicsScene; + +#ifdef ENABLE_OPENGL +#ifndef QT_NO_OPENGL + if (m_enableOpenGL) { + qDebug() << "OpenGL enabled"; + m_scene->setSortCacheEnabled(false); + setViewport(new QGLWidget); + + // Qt doc says: This is the preferred update mode for + // viewports that do not support partial updates, such as QGLWidget... + setViewportUpdateMode(QGraphicsView::FullViewportUpdate); + } +#endif +#endif + + setScene(m_scene); + + if (!m_enableOpenGL) + setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); + m_scene->setItemIndexMethod(QGraphicsScene::NoIndex); + + //setCacheMode(QGraphicsView::CacheBackground); + setAlignment(Qt::AlignLeft | Qt::AlignTop); + + // Turn off automatic background + setAttribute(Qt::WA_OpaquePaintEvent); + setAttribute(Qt::WA_NoBackground); + setAttribute(Qt::WA_NoSystemBackground); + setAutoFillBackground(false); + + //Background + m_backGround = new BackgroundItem("background.svg"); + m_scene->addItem(m_backGround); + m_backGround->setZValue(0); + + //Menu + m_menu = new Menu(this); + m_scene->addItem(m_menu); //Add menu to the scene directly + m_menu->setZValue(10); //Bring to front + + m_mainLayout = new QGraphicsLinearLayout(Qt::Vertical); + m_mainLayout->setContentsMargins(0,0,0,0); + m_mainLayout->setSpacing(0); + + m_mainWidget = new QGraphicsWidget; + m_mainWidget->setLayout(m_mainLayout); + m_mainWidget->setZValue(1); + m_scene->addItem(m_mainWidget); + + //Topbar + m_topBar = new TopBar(this, 0); + m_mainLayout->addItem(m_topBar); + m_topBar->setZValue(1); + connect(m_topBar, SIGNAL(clicked(bool)), m_menu, SLOT(menuShowHide())); + + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setContentsMargins(0,0,0,0); + setViewportMargins(0,0,0,0); + setFrameShape(QFrame::NoFrame); + + fpsReset(); + m_fpsUpdated.start(); +} + +void MainView::updateFps() +{ + int msecs = m_fpsFirstTs.msecsTo(m_fpsLatestTs); + qreal fps = 0; + if (msecs > 0) { + fps = m_frameCount * 1000.0 / msecs; + + if (m_OutputFps) + qDebug() << "FPS: " << fps; + + m_Fpss.append(fps); + } + m_fpsFirstTs = m_fpsLatestTs; + m_frameCount = 0; +} + +Menu *MainView::menu() +{ + return m_menu; +} |