diff options
106 files changed, 827 insertions, 13107 deletions
diff --git a/src/declarative/canvas/canvas.pri b/src/declarative/canvas/canvas.pri deleted file mode 100644 index 9bdd3fa..0000000 --- a/src/declarative/canvas/canvas.pri +++ /dev/null @@ -1,19 +0,0 @@ -SOURCES += \ - canvas/qsimplecanvas.cpp \ - canvas/qsimplecanvasitem.cpp \ - canvas/qsimplecanvasfilter.cpp \ - canvas/qsimplecanvasdebugplugin.cpp - -HEADERS += \ - canvas/qsimplecanvas.h \ - canvas/qsimplecanvasitem.h \ - canvas/qsimplecanvasfilter.h \ - canvas/qsimplecanvas_p.h \ - canvas/qsimplecanvasitem_p.h \ - canvas/qsimplecanvasfilter_p.h \ - canvas/qsimplecanvasdebugplugin_p.h - -contains(QT_CONFIG, opengles2): SOURCES += canvas/qsimplecanvas_opengl.cpp -else:contains(QT_CONFIG, opengles1): SOURCES += canvas/qsimplecanvas_opengl1.cpp -else:SOURCES += canvas/qsimplecanvas_software.cpp -SOURCES += canvas/qsimplecanvas_graphicsview.cpp diff --git a/src/declarative/canvas/qsimplecanvas.cpp b/src/declarative/canvas/qsimplecanvas.cpp deleted file mode 100644 index a4998dc..0000000 --- a/src/declarative/canvas/qsimplecanvas.cpp +++ /dev/null @@ -1,1034 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwidget.h" -#include "qmutex.h" -#include "qdebug.h" -#include "qcoreapplication.h" -#include "qsimplecanvasitem.h" -#include "qsimplecanvasitem_p.h" -#include "qsimplecanvas_p.h" -#include "qtimer.h" -#include "qdatetime.h" -#include "qgraphicssceneevent.h" -#if defined(QFX_RENDER_OPENGL) -#include <glheaders.h> -#endif -#include "qboxlayout.h" -#include "qsimplecanvasdebugplugin_p.h" -#include "qsimplecanvas.h" - - -QT_BEGIN_NAMESPACE -DEFINE_BOOL_CONFIG_OPTION(fullUpdate, GFX_CANVAS_FULL_UPDATE); -DEFINE_BOOL_CONFIG_OPTION(continuousUpdate, GFX_CANVAS_CONTINUOUS_UPDATE); -DEFINE_BOOL_CONFIG_OPTION(useSimpleCanvas, QFX_USE_SIMPLECANVAS); - -template<class T, int s = 60> -class CircularList -{ -public: - CircularList() - : _first(0), _size(0) {} - - void append(const T &t) - { - int entry = (_first + _size) % s; - _array[entry] = t; - if (_size == s) - _first = (_first + 1) % s; - else - _size++; - } - - int size() const - { - return _size; - } - - T &operator[](int idx) - { - Q_ASSERT(idx < _size); - int entry = (_first + idx) % s; - return _array[entry]; - } - - void clear() - { - _first = 0; - _size = 0; - } -private: - int _first; - int _size; - T _array[s]; -}; - - -class QSimpleCanvasRootLayer : public QSimpleCanvasLayer -{ -public: - QSimpleCanvasRootLayer(QSimpleCanvas *); - virtual void addDirty(QSimpleCanvasItem *); - virtual void remDirty(QSimpleCanvasItem *); - -private: - friend class QSimpleCanvasItem; - QSimpleCanvas *_canvas; -}; - -void QSimpleCanvasRootLayer::addDirty(QSimpleCanvasItem *i) -{ - _canvas->addDirty(i); -} - -void QSimpleCanvasRootLayer::remDirty(QSimpleCanvasItem *i) -{ - _canvas->remDirty(i); -} - -void QSimpleCanvasPrivate::clearFocusPanel(QSimpleCanvasItem *panel) -{ - if (q->activeFocusPanel() == panel) { - focusPanels.pop(); - - switchToFocusPanel(q->activeFocusPanel(), panel, Qt::OtherFocusReason); - panel->activePanelOutEvent(); - } else { - for (int ii = 0; ii < focusPanels.count(); ++ii) - if (focusPanels.at(ii) == panel) { - focusPanels.remove(ii); - break; - } - } -} - -void QSimpleCanvasPrivate::switchToFocusPanel(QSimpleCanvasItem *panel, QSimpleCanvasItem *wasPanel, Qt::FocusReason focusReason) -{ - if (panel) - panel->activePanelInEvent(); - - QSimpleCanvasItem *wasFocusRoot = focusPanelData.value(wasPanel); - if (wasFocusRoot) - clearActiveFocusItem(wasFocusRoot, focusReason); - - QSimpleCanvasItem *newFocusRoot = focusPanelData.value(panel); - if (newFocusRoot) - setFocusItem(newFocusRoot, focusReason); -} - -void QSimpleCanvasPrivate::setActiveFocusPanel(QSimpleCanvasItem *panel, Qt::FocusReason focusReason) -{ - if (q->activeFocusPanel() == panel) - return; - - if (panel) { - for (int ii = 0; ii < focusPanels.count(); ++ii) - if (focusPanels.at(ii) == panel) { - focusPanels.remove(ii); - break; - } - } - QSimpleCanvasItem *old = q->activeFocusPanel(); - if (panel) - focusPanels << panel; - switchToFocusPanel(panel, old, focusReason); - if (old) - old->activePanelOutEvent(); -} - -void QSimpleCanvasPrivate::clearActiveFocusItem(QSimpleCanvasItem *item, - Qt::FocusReason focusReason) -{ - if (!item || !item->d_func()) - return; - - if (!item->d_func()->hasActiveFocus) - return; - - item->d_func()->hasActiveFocus = false; - if (item->options() & QSimpleCanvasItem::IsFocusRealm) { - QSimpleCanvasItem *newItem = focusPanelData.value(item); - if (newItem) { - clearActiveFocusItem(newItem, focusReason); - } else { - focusItem = 0; - QFocusEvent event(QEvent::FocusOut, focusReason); - item->focusOutEvent(&event); - } - } else { - focusItem = 0; - QFocusEvent event(QEvent::FocusOut, focusReason); - item->focusOutEvent(&event); - } - - if (item->options() & QSimpleCanvasItem::AcceptsInputMethods){ - if (q->testAttribute(Qt::WA_InputMethodEnabled)) - q->setAttribute(Qt::WA_InputMethodEnabled,false); - } - item->activeFocusChanged(true); -} - -void QSimpleCanvasPrivate::setActiveFocusItem(QSimpleCanvasItem *item, - Qt::FocusReason focusReason) -{ - while(true) { - item->d_func()->setActiveFocus(true); - item->activeFocusChanged(true); - if (item->options() & QSimpleCanvasItem::IsFocusRealm) { - QSimpleCanvasItem *newItem = focusPanelData.value(item); - if (newItem) - item = newItem; - else - break; - } else { - break; - } - } - - if (item->options() & QSimpleCanvasItem::AcceptsInputMethods){ - if (!q->testAttribute(Qt::WA_InputMethodEnabled)) - q->setAttribute(Qt::WA_InputMethodEnabled,true); - } - focusItem = item; - QFocusEvent event(QEvent::FocusIn, focusReason); - focusItem->focusInEvent(&event); -} - -void QSimpleCanvasPrivate::clearFocusItem(QSimpleCanvasItem *item) -{ - // XXX -#if 0 - while(item->focusProxy()) - item = item->focusProxy(); -#endif - - QSimpleCanvasItem *scope = 0; - QSimpleCanvasItem *citem = item; - while(citem && !scope) { - if (citem->options() & QSimpleCanvasItem::IsFocusPanel) - scope = citem; - else if (citem != item && citem->options() & QSimpleCanvasItem::IsFocusRealm) - scope = citem; - citem = citem->parent(); - } - Q_ASSERT(scope); // At the very least we'll find the canvas root - - bool isActive = false; - - if (scope->options() & QSimpleCanvasItem::IsFocusPanel) - isActive = (scope == q->activeFocusPanel()); - else if (scope->options() & QSimpleCanvasItem::IsFocusRealm) - isActive = scope->hasActiveFocus(); - - if (isActive) clearActiveFocusItem(item, Qt::OtherFocusReason); - item->d_func()->setFocus(false); - item->focusChanged(false); - - focusPanelData.insert(scope, 0); - - if (lastFocusItem == item) - lastFocusItem = 0; - if (focusItem == item) - focusItem = 0; - - if (scope->options() & QSimpleCanvasItem::IsFocusRealm && scope->hasActiveFocus()) { - setActiveFocusItem(scope, Qt::OtherFocusReason); - } else { - QSimpleCanvasItem *item = QSimpleCanvasItem::findNextFocus(scope); - if (item) - item->setFocus(true); - } -} - -void QSimpleCanvasPrivate::setFocusItem(QSimpleCanvasItem *item, - Qt::FocusReason focusReason, - bool overwrite) -{ - Q_ASSERT(item); - - // XXX -#if 0 - while(item->focusProxy()) - item = item->focusProxy(); -#endif - - if (item == focusItem) - return; - - QSimpleCanvasItem *scope = 0; - QSimpleCanvasItem *citem = item; - while(citem && !scope) { - if (citem->options() & QSimpleCanvasItem::IsFocusPanel) - scope = citem; - else if (citem != item && citem->options() & QSimpleCanvasItem::IsFocusRealm) - scope = citem; - citem = citem->parent(); - } - Q_ASSERT(scope); // At the very least we'll find the canvas root - - if (!overwrite && focusPanelData.contains(scope)) { - item->d_func()->setFocus(false); - item->focusChanged(false); - return; - } - - QSimpleCanvasItem *oldFocus = focusPanelData.value(scope); - bool isActive = false; - - if (scope->options() & QSimpleCanvasItem::IsFocusPanel) - isActive = (scope == q->activeFocusPanel()); - else if (scope->options() & QSimpleCanvasItem::IsFocusRealm) - isActive = scope->hasActiveFocus(); - - if (oldFocus) { - if (isActive) clearActiveFocusItem(oldFocus, focusReason); - oldFocus->d_func()->setFocus(false); - oldFocus->focusChanged(false); - } - - focusPanelData.insert(scope, item); - - if (isActive) - lastFocusItem = item; - - if (item) { - item->d_func()->setFocus(true); - item->focusChanged(true); - if (isActive) - setActiveFocusItem(item, focusReason); - } -} - - -bool QSimpleCanvas::eventFilter(QObject *obj, QEvent *event) -{ - Q_UNUSED(obj); - switch (event->type()) { - case QEvent::GraphicsSceneMouseMove: { - QGraphicsSceneMouseEvent *me = (QGraphicsSceneMouseEvent*)event; - if (!me->buttons()) - break; - } - case QEvent::GraphicsSceneMousePress: - case QEvent::GraphicsSceneMouseRelease: { - //same logic as filter() function - for (int ii = 0; ii < d->mouseFilters.count(); ++ii) { - if (d->mouseFilters.at(ii)->mouseFilter((QGraphicsSceneMouseEvent*)event)) - return true; - } - break; - } - default: - break; - } - return false; -} - -void QSimpleCanvasPrivate::installMouseFilter(QSimpleCanvasItem *item) -{ - mouseFilters << item; -} - -void QSimpleCanvasPrivate::removeMouseFilter(QSimpleCanvasItem *item) -{ - mouseFilters.removeAll(item); -} - -bool QSimpleCanvasPrivate::filter(QMouseEvent *e) -{ - if (mouseFilters.isEmpty()) - return false; - - QGraphicsSceneMouseEvent *me = mouseEventToSceneMouseEvent(e, e->pos()); - for (int ii = 0; ii < mouseFilters.count(); ++ii) { - if (mouseFilters.at(ii)->mouseFilter(me)) { - delete me; - return true; - } - } - delete me; - return false; -} - -QGraphicsSceneMouseEvent *QSimpleCanvasPrivate::mouseEventToSceneMouseEvent(QMouseEvent *e, const QPoint &item) -{ - QEvent::Type t; - switch(e->type()) { - default: - case QEvent::MouseButtonPress: - t = QEvent::GraphicsSceneMousePress; - break; - case QEvent::MouseButtonRelease: - t = QEvent::GraphicsSceneMouseRelease; - break; - case QEvent::MouseMove: - t = QEvent::GraphicsSceneMouseMove; - break; - case QEvent::MouseButtonDblClick: - t = QGraphicsSceneEvent::GraphicsSceneMouseDoubleClick; - break; - } - - QGraphicsSceneMouseEvent *me = new QGraphicsSceneMouseEvent(t); - me->setButton(e->button()); - me->setButtons(e->buttons()); - me->setModifiers(e->modifiers()); - me->setPos(item); - me->setScreenPos(e->pos()); - me->setScenePos(e->pos()); - return me; -} - -bool QSimpleCanvasPrivate::deliverMousePress(QSimpleCanvasItem *base, QMouseEvent *e, bool seenChildFilter) -{ - if (base->clipType()) { - QRectF br = base->boundingRect(); - QPointF pos = base->mapFromScene(e->pos()); - if (!br.contains(pos.toPoint())) - return false; - } - - const QList<QSimpleCanvasItem *> &children = base->d_func()->children; - - if (base->options() & QSimpleCanvasItem::ChildMouseFilter) - seenChildFilter = true; - - for (int ii = children.count() - 1; ii >= 0; --ii) { - if (children.at(ii)->visible() != 0.) - if (deliverMousePress(children.at(ii), e, seenChildFilter)) - return true; - } - - if (base->acceptedMouseButtons() & e->button() || base->options() & QSimpleCanvasItem::ChildMouseFilter) { - - QRectF br = base->boundingRect(); - QPoint pos = base->mapFromScene(e->pos()).toPoint(); - - if (br.contains(pos)) { - QGraphicsSceneMouseEvent *me = mouseEventToSceneMouseEvent(e, pos); - - sendMouseEvent(base, me); - bool isAccepted = me->isAccepted(); - delete me; - if (isAccepted) { - lastMouseItem = base; - return true; - } - } - } - return false; -} - -// Delivers e to item -void QSimpleCanvasPrivate::sendMouseEvent(QSimpleCanvasItem *item, QGraphicsSceneMouseEvent *e) -{ - QSimpleCanvasItem *p = item->parent(); - while(p) { - if (p->options() & QSimpleCanvasItem::ChildMouseFilter) { - if (p->mouseFilter(e)) - return; - } - p = p->parent(); - } - switch(e->type()) { - case QEvent::GraphicsSceneMousePress: - item->mousePressEvent(e); - break; - case QEvent::GraphicsSceneMouseRelease: - item->mouseReleaseEvent(e); - break; - case QEvent::GraphicsSceneMouseMove: - item->mouseMoveEvent(e); - break; - case QEvent::GraphicsSceneMouseDoubleClick: - item->mouseDoubleClickEvent(e); - break; - default: - break; - } -} - - -QSimpleCanvasRootLayer::QSimpleCanvasRootLayer(QSimpleCanvas *c) -: _canvas(c) -{ - QSimpleCanvasItem::d_func()->canvas = c; - setOptions(IsFocusPanel); - update(); -} - - -struct QSimpleCanvasTiming -{ - QSimpleCanvasTiming() - : time(-1), paintTime(-1), timeBetweenFrames(-1) {} - QSimpleCanvasTiming(const QRegion &_r, int _time, int _paintTime, - int _timeBetweenFrames) - : region(_r), time(_time), paintTime(_paintTime), - timeBetweenFrames(_timeBetweenFrames) {} - QSimpleCanvasTiming(const QSimpleCanvasTiming &other) - : region(other.region), time(other.time), paintTime(other.paintTime), - timeBetweenFrames(other.timeBetweenFrames) {} - QSimpleCanvasTiming &operator=(const QSimpleCanvasTiming &other) { - region = other.region; time = other.time; paintTime = other.paintTime; - timeBetweenFrames = other.timeBetweenFrames; return *this; - } - QRegion region; - int time; - int paintTime; - int timeBetweenFrames; -}; - -// XXX -static CircularList<QSimpleCanvasTiming> gfxCanvasTiming; - -void QSimpleCanvasGraphicsView::paintEvent(QPaintEvent *pe) -{ - QRegion r = pe->region(); - int tbf = canvas->frameTimer.restart(); - - canvas->lrpTimer.start(); - QGraphicsView::paintEvent(pe); - canvas->lrpTime = canvas->lrpTimer.elapsed(); - - int frametimer = canvas->frameTimer.elapsed(); - gfxCanvasTiming.append(QSimpleCanvasTiming(r, frametimer, canvas->lrpTime, tbf)); - canvas->lrpTime = 0; - if (canvas->debugPlugin) - canvas->debugPlugin->addTiming(canvas->lrpTime, frametimer, tbf); -} - -void QSimpleCanvasGraphicsView::focusInEvent(QFocusEvent *) -{ -} - -/*! - \internal - \class QSimpleCanvas - \brief The QSimpleCanvas class implements the canvas used by Qt Declarative - */ - -QSimpleCanvas::QSimpleCanvas(CanvasMode mode, QWidget *parent) -: QWidget(parent), d(new QSimpleCanvasPrivate(this)) -{ - d->init(mode); -} - -QSimpleCanvas::QSimpleCanvas(QWidget *parent) -: QWidget(parent), d(new QSimpleCanvasPrivate(this)) -{ - d->init(useSimpleCanvas()?SimpleCanvas:GraphicsView); -} - -void QSimpleCanvasPrivate::init(QSimpleCanvas::CanvasMode mode) -{ - this->mode = mode; - - if (mode == QSimpleCanvas::SimpleCanvas) - qWarning("QSimpleCanvas: Using simple canvas"); - else - qWarning("QSimpleCanvas: Using GraphicsView canvas"); - - if (fullUpdate()) - qWarning("QSimpleCanvas: Full update enabled"); - if (continuousUpdate()) - qWarning("QSimpleCanvas: Continuous update enabled"); - - if (QmlDebugServerPlugin::isDebuggingEnabled()) { - debugPlugin = new QSimpleCanvasDebugPlugin(q); - new QSimpleCanvasSceneDebugPlugin(q); - } - - root = new QSimpleCanvasRootLayer(q); - root->setActiveFocusPanel(true); - q->setFocusPolicy(Qt::StrongFocus); - - if (mode == QSimpleCanvas::GraphicsView) { - view = new QSimpleCanvasGraphicsView(this); - QHBoxLayout *layout = new QHBoxLayout(q); - layout->setSpacing(0); - layout->setContentsMargins(0, 0, 0, 0); - q->setLayout(layout); - layout->addWidget(view); - view->setOptimizationFlags(QGraphicsView::DontSavePainterState); - view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - view->setFrameStyle(0); - static_cast<QSimpleCanvasItemPrivate*>(root->d_ptr)->convertToGraphicsItem(); - view->scene()->addItem(static_cast<QSimpleCanvasItemPrivate*>(root->d_ptr)->graphicsItem); - - // These seem to give the best performance - view->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); - view->scene()->setItemIndexMethod(QGraphicsScene::NoIndex); - view->viewport()->setFocusPolicy(Qt::NoFocus); - } - -#if defined(QFX_RENDER_OPENGL) && defined(Q_WS_X11) - QTimer *t = new QTimer(q); - t->setInterval(200); - QObject::connect(t, SIGNAL(timeout()), &egl, SLOT(updateGL())); - t->start(); -#endif -} - -QSimpleCanvas::~QSimpleCanvas() -{ - delete d->root; - delete d; -} - -void QSimpleCanvasPrivate::paint(QPainter &p) -{ -#if defined(QFX_RENDER_QPAINTER) - if (!isSetup) { - ++paintVersion; - root->d_func()->setupPainting(0, q->rect()); - } - - lrpTimer.start(); - - root->d_func()->paint(p); - - lrpTime = lrpTimer.elapsed(); -#else - Q_UNUSED(p); -#endif -} - -QSimpleCanvas::CanvasMode QSimpleCanvas::canvasMode() const -{ - return d->mode; -} - -QSimpleCanvasItem *QSimpleCanvas::root() -{ - return d->root; -} - -void QSimpleCanvas::keyPressEvent(QKeyEvent *event) -{ - if (d->focusItem) - d->focusItem->keyPressEvent(event); - QWidget::keyPressEvent(event); -} - -void QSimpleCanvas::keyReleaseEvent(QKeyEvent *event) -{ - if (d->focusItem) - d->focusItem->keyReleaseEvent(event); - QWidget::keyReleaseEvent(event); -} - -void QSimpleCanvas::inputMethodEvent(QInputMethodEvent *event) -{ - if (d->focusItem) - d->focusItem->inputMethodEvent(event); - else - QWidget::inputMethodEvent(event); -} - -QVariant QSimpleCanvas::inputMethodQuery(Qt::InputMethodQuery query) const -{ - if (d->focusItem) - return d->focusItem->inputMethodQuery(query); - return QWidget::inputMethodQuery(query); -} - -void QSimpleCanvas::mousePressEvent(QMouseEvent *e) -{ - if (d->isSimpleCanvas() && - (d->filter(e) || d->deliverMousePress(d->root, e))) { - e->accept(); - } else { - QWidget::mousePressEvent(e); - } -} - -void QSimpleCanvas::mouseDoubleClickEvent(QMouseEvent *e) -{ - if (d->isSimpleCanvas() && - (d->filter(e) || d->deliverMousePress(d->root, e))) { - e->accept(); - } else { - QWidget::mouseDoubleClickEvent(e); - } -} - -void QSimpleCanvas::mouseMoveEvent(QMouseEvent *e) -{ - if (d->isSimpleCanvas() && d->filter(e)) { - e->accept(); - } else if (d->isSimpleCanvas() && d->lastMouseItem) { - QPoint p = d->lastMouseItem->mapFromScene(e->pos()).toPoint(); - QGraphicsSceneMouseEvent *me = d->mouseEventToSceneMouseEvent(e, p); - d->sendMouseEvent(d->lastMouseItem, me); - e->setAccepted(me->isAccepted()); - delete me; - } else { - QWidget::mouseMoveEvent(e); - } -} - -void QSimpleCanvas::mouseReleaseEvent(QMouseEvent *e) -{ - if (d->isSimpleCanvas() && d->filter(e)) { - e->accept(); - } else if (d->isSimpleCanvas() && d->lastMouseItem) { - QPoint p = d->lastMouseItem->mapFromScene(e->pos()).toPoint(); - QGraphicsSceneMouseEvent *me = d->mouseEventToSceneMouseEvent(e, p); - d->sendMouseEvent(d->lastMouseItem, me); - d->lastMouseItem->mouseUngrabEvent(); - e->setAccepted(me->isAccepted()); - delete me; - d->lastMouseItem = 0; - } else { - QWidget::mouseReleaseEvent(e); - } -} - -void QSimpleCanvas::focusInEvent(QFocusEvent *event) -{ - // XXX -#if 0 - if (d->lastFocusItem && event->reason() == Qt::ActiveWindowFocusReason) { - d->setFocusItem(d->lastFocusItem, event->reason()); - } else { - QSimpleCanvasItem *panel = activeFocusPanel(); - QSimpleCanvasItem *focusItem = 0; - if (panel->isFocusable()) - focusItem = panel; - else - focusItem = QSimpleCanvasItem::findNextFocus(panel); - - if (focusItem) - d->setFocusItem(focusItem, event->reason()); - else - QWidget::focusNextPrevChild(true); - } -#endif - QWidget::focusInEvent(event); -} - -void QSimpleCanvas::focusOutEvent(QFocusEvent *event) -{ - // XXX -#if 0 - if (event->reason() == Qt::ActiveWindowFocusReason) { - d->lastFocusItem = activeFocusPanel(); - d->setActiveFocusPanel(0, Qt::ActiveWindowFocusReason); - } -#endif - QWidget::focusOutEvent(event); -} - -bool QSimpleCanvas::focusNextPrevChild(bool) -{ - // XXX -#if 0 - if (d->focusItem) { - QSimpleCanvasItem *item = next ? QSimpleCanvasItem::findNextFocus(d->focusItem) : QSimpleCanvasItem::findPrevFocus(d->focusItem); - if (item) { - d->setFocusItem(item, - next ? Qt::TabFocusReason : Qt::BacktabFocusReason); - return true; - } - } - - QSimpleCanvasItem *panel = activeFocusPanel(); - QSimpleCanvasItem *item = 0; - if (panel->isFocusable()) - item = panel; - else - item = next ? QSimpleCanvasItem::findNextFocus(panel) : QSimpleCanvasItem::findPrevFocus(panel); - if (item && item != d->focusItem) { - d->setFocusItem(item, - next ? Qt::TabFocusReason : Qt::BacktabFocusReason); - return true; - } - - if (d->focusItem) - d->setActiveFocusPanel(0, next ? Qt::TabFocusReason : Qt::BacktabFocusReason); - -#endif - return false; -} - - -void QSimpleCanvas::showEvent(QShowEvent *e) -{ -#if defined(QFX_RENDER_OPENGL) - d->egl.resize(width(), height()); -#endif - if (d->isGraphicsView()) - d->view->setSceneRect(rect()); - - QWidget::showEvent(e); -} - -void QSimpleCanvas::resizeEvent(QResizeEvent *e) -{ -#if defined(QFX_RENDER_OPENGL) - d->egl.resize(width(), height()); -#endif - if (d->isGraphicsView()) - d->view->setSceneRect(rect()); - QWidget::resizeEvent(e); -} - - -void QSimpleCanvas::remDirty(QSimpleCanvasItem *c) -{ - d->dirtyItems.removeAll(c); -} - -void QSimpleCanvas::queueUpdate() -{ - if (!d->timer) { - QCoreApplication::postEvent(this, new QEvent(QEvent::User)); - d->timer = 1; - } -} - -void QSimpleCanvas::addDirty(QSimpleCanvasItem *c) -{ - Q_ASSERT(d->isSimpleCanvas()); - queueUpdate(); - d->oldDirty |= c->d_func()->data()->lastPaintRect; -#if defined(QFX_RENDER_OPENGL) - // ### Is this parent crawl going to be a problem for scenes with nots - // of things changing? - // Check for filters - QSimpleCanvasItem *fi = c->parent(); - while(fi) { - if (fi->d_func()->data()->dirty) { - break; - } else if (fi->filter()) { - fi->update(); - break; - } - fi = fi->parent(); - } -#endif - d->dirtyItems.append(c); -} - -QRect QSimpleCanvasPrivate::dirtyItemClip() const -{ - QRect rv; - if (isSimpleCanvas()) { -#if defined(QFX_RENDER_OPENGL) - QRectF r; - for (int ii = 0; ii < dirtyItems.count(); ++ii) - r |= dirtyItems.at(ii)->d_func()->data()->lastPaintRect; - rv = egl.map(r); -#else - for (int ii = 0; ii < dirtyItems.count(); ++ii) - rv |= dirtyItems.at(ii)->d_func()->data()->lastPaintRect; -#endif - } - return rv; -} - -QRect QSimpleCanvasPrivate::resetDirty() -{ - if (isSimpleCanvas()) { -#if defined(QFX_RENDER_OPENGL) - QRect r = egl.map(oldDirty) | dirtyItemClip(); -#else - QRect r = oldDirty | dirtyItemClip(); -#endif - if (!r.isEmpty()) - r.adjust(-1,-1,2,2); //make sure we get everything (since we rounded from floats to ints) - for (int ii = 0; ii < dirtyItems.count(); ++ii) - static_cast<QSimpleCanvasItemPrivate*>(dirtyItems.at(ii)->d_ptr)->data()->dirty = false; - dirtyItems.clear(); - oldDirty = QRect(); - - /*if (fullUpdate()) - return QRect(); - else*/ - return r; - } else { - return QRect(); - } -} - -QSimpleCanvasItem *QSimpleCanvas::focusItem() const -{ - return d->focusItem; -} - -QSimpleCanvasItem *QSimpleCanvas::activeFocusPanel() const -{ - if (d->focusPanels.isEmpty()) - return 0; - else - return d->focusPanels.top(); -} - -QSimpleCanvasItem *QSimpleCanvas::focusItem(QSimpleCanvasItem *item) const -{ - while (item && d->focusPanelData.contains(item)) - item = d->focusPanelData.value(item); - return item; -} - -bool QSimpleCanvas::event(QEvent *e) -{ - if (e->type() == QEvent::User && d->isSimpleCanvas()) { - int tbf = d->frameTimer.restart(); - d->timer = 0; - d->isSetup = true; -#if defined(QFX_RENDER_OPENGL1) - unsigned int zero = 0; - d->root->d_func()->setupPainting(0, rect(), &zero); -#elif defined(QFX_RENDER_OPENGL2) - ++d->paintVersion; - d->opaqueList = 0; - int z = 0; - d->root->d_func()->setupPainting(0, z, &d->opaqueList); -#else - ++d->paintVersion; - d->root->d_func()->setupPainting(0, rect()); -#endif - - QRect r = d->resetDirty(); - -#if defined(QFX_RENDER_QPAINTER) - if (fullUpdate()) - repaint(); - else - repaint(r); - emit framePainted(); -#else - - QRect nr(r.x(), height() - r.y() - r.height(), r.width(), r.height()); - - if (r.isEmpty() || fullUpdate()) - d->egl.updateGL(); - else - d->egl.updateGL(nr); - emit framePainted(); -#endif - d->isSetup = false; - - int frametimer = d->frameTimer.elapsed(); - gfxCanvasTiming.append(QSimpleCanvasTiming(r, frametimer, d->lrpTime, tbf)); - if (d->debugPlugin) - d->debugPlugin->addTiming(d->lrpTime, frametimer, tbf); - d->lrpTime = 0; - if (continuousUpdate()) - queueUpdate(); - - return true; - } - - if (e->type() == QEvent::ShortcutOverride) { - if (QSimpleCanvasItem *focus = focusItem()) - return focus->event(e); - } - - return QWidget::event(e); -} - -void QSimpleCanvas::paintEvent(QPaintEvent *) -{ -#if defined(QFX_RENDER_QPAINTER) - if (d->mode == SimpleCanvas) { - QPainter p(this); - d->paint(p); - } -#endif -} - -void QSimpleCanvas::dumpTiming() -{ - for (int ii = 0; ii < gfxCanvasTiming.size(); ++ii) { - const QSimpleCanvasTiming &t = gfxCanvasTiming[ii]; - - qreal repaintFps = 1000. / qreal(t.time); - qreal paintFps = 1000. / qreal(t.paintTime); - qreal tbfFps = 1000. / qreal(t.timeBetweenFrames); - - qWarning() << "repaint():" << t.time << "ms," << repaintFps << "fps. paint():" << t.paintTime << "ms," << paintFps << "fps. timeSinceLastFrame:" << t.timeBetweenFrames << "ms," << tbfFps << "fps."; - qWarning() << t.region; - } - gfxCanvasTiming.clear(); -} - -void QSimpleCanvas::dumpItems() -{ - int items = d->root->d_func()->dump(0); - qWarning() << "Total:" << items; -} - -void QSimpleCanvas::checkState() -{ - if (d->isSimpleCanvas()) { - QSimpleCanvasItemPrivate::FocusStateCheckRDatas r; - if (d->root->d_func()->checkFocusState(0, &r)) - qWarning() << "State OK"; - } -} - -/*! - Returns canvas as an image. Not a fast operation. -*/ -QImage QSimpleCanvas::asImage() const -{ - if (d->isSimpleCanvas()) { -#if defined(QFX_RENDER_QPAINTER) - QImage img(width(),height(),QImage::Format_RGB32); - QPainter p(&img); - const_cast<QSimpleCanvas*>(this)->d->paint(p); - return img; -#elif defined(QFX_RENDER_OPENGL) - return d->egl.grabFrameBuffer(); -#endif - } else { - QImage img(width(),height(),QImage::Format_RGB32); - QPainter p(&img); - d->view->render(&p); - return img; - } -} -QT_END_NAMESPACE diff --git a/src/declarative/canvas/qsimplecanvas.h b/src/declarative/canvas/qsimplecanvas.h deleted file mode 100644 index 1cbd3c7..0000000 --- a/src/declarative/canvas/qsimplecanvas.h +++ /dev/null @@ -1,173 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSIMPLECANVAS_H -#define QSIMPLECANVAS_H - -#include <QtDeclarative/qfxglobal.h> - -#ifdef QFX_RENDER_OPENGL -#include <QtGui/qmatrix4x4.h> -#endif - -#include <QtGui/QTransform> -#include <QtGui/QPainter> -#include <QtCore/QDebug> -#include <QtGui/QWidget> -#include <QtGui/QImage> -#include <QtGui/QKeyEvent> - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -namespace QSimpleCanvasConfig -{ - enum ImageType { Opaque, Translucent }; - -#ifdef QFX_RENDER_OPENGL - typedef QMatrix4x4 Matrix; - typedef QImage Image; - - inline Matrix transformToMatrix(const QTransform &) - { - return Matrix(); // XXX - } - inline QTransform matrixToTransform(const Matrix &) - { - return QTransform(); // XXX - } - inline bool needConvert(ImageType, const Image &) - { return false; } - inline Image convert(ImageType, const Image &i) - { return i; } - inline Image create(const QSize &s) - { return QImage(s, QImage::Format_ARGB32); } - inline const Image &toImage(const QImage &i) - { return i; } - -#elif defined(QFX_RENDER_QPAINTER) - typedef QTransform Matrix; - - inline Matrix transformToMatrix(const QTransform &t) - { return t; } - inline QTransform matrixToTransform(const Matrix &t) - { return t; } -#endif -} - -class QSimpleCanvas; -class QSimpleCanvasLayer; - -class QGraphicsSceneMouseEvent; -class GLBasicShaders; -class QSimpleCanvasItem; -class QSimpleCanvasPrivate; -class Q_DECLARATIVE_EXPORT QSimpleCanvas : public QWidget -{ -Q_OBJECT -public: - typedef QSimpleCanvasConfig::Matrix Matrix; - - enum CanvasMode { GraphicsView, SimpleCanvas }; - - QSimpleCanvas(QWidget *parent = 0); - QSimpleCanvas(CanvasMode, QWidget *parent = 0); - virtual ~QSimpleCanvas(); - - CanvasMode canvasMode() const; - - QSimpleCanvasItem *root(); - - // Debugging - void dumpTiming(); - void dumpItems(); - void checkState(); - - QSimpleCanvasItem *focusItem() const; - QSimpleCanvasItem *focusItem(QSimpleCanvasItem *item) const; - - QSimpleCanvasItem *activeFocusPanel() const; - QImage asImage() const; - -Q_SIGNALS: - void framePainted(); - -protected: - virtual bool event(QEvent *); - virtual void paintEvent(QPaintEvent *); - virtual void keyPressEvent(QKeyEvent *); - virtual void keyReleaseEvent(QKeyEvent *); - virtual void mousePressEvent(QMouseEvent *); - virtual void mouseDoubleClickEvent(QMouseEvent *); - virtual void mouseMoveEvent(QMouseEvent *); - virtual void mouseReleaseEvent(QMouseEvent *); - virtual void focusInEvent(QFocusEvent *event); - virtual void focusOutEvent(QFocusEvent *event); - virtual bool focusNextPrevChild(bool next); - virtual bool eventFilter(QObject *obj, QEvent *event); - virtual void inputMethodEvent(QInputMethodEvent *event); - virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const; - - virtual void showEvent(QShowEvent *); - virtual void resizeEvent(QResizeEvent *); -private: - - friend class QSimpleCanvasRootLayer; - friend class QSimpleCanvasPrivate; - friend class QSimpleCanvasItem; - friend class QSimpleCanvasItemPrivate; - friend class QSimpleCanvasFilter; - friend class QSimpleGraphicsItem; - - void queueUpdate(); - QSimpleCanvasPrivate *d; - void addDirty(QSimpleCanvasItem *); - void remDirty(QSimpleCanvasItem *); -}; - - -QT_END_NAMESPACE - -QT_END_HEADER -#endif diff --git a/src/declarative/canvas/qsimplecanvas_graphicsview.cpp b/src/declarative/canvas/qsimplecanvas_graphicsview.cpp deleted file mode 100644 index dd4012b..0000000 --- a/src/declarative/canvas/qsimplecanvas_graphicsview.cpp +++ /dev/null @@ -1,213 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qsimplecanvas.h" -#include "qsimplecanvas_p.h" -#include "qsimplecanvasitem.h" -#include "qsimplecanvasitem_p.h" -#include <QGraphicsItem> -#include <QGraphicsSceneMouseEvent> - - -QT_BEGIN_NAMESPACE -static QHash<QGraphicsScene*,QSimpleCanvas*> sceneMap; - -QSimpleCanvasGraphicsView::QSimpleCanvasGraphicsView(QSimpleCanvasPrivate *parent) -: QGraphicsView(parent->q), canvas(parent) -{ - setScene(&_scene); - sceneMap[&_scene] = parent->q; - setFrameShape(QFrame::NoFrame); - viewport()->setAttribute(Qt::WA_OpaquePaintEvent); -} - -QSimpleCanvasGraphicsView::~QSimpleCanvasGraphicsView() -{ - sceneMap.remove(&_scene); -} - -QSimpleGraphicsItem::QSimpleGraphicsItem(QSimpleCanvasItem *canvasItem) -: /*scene(0),*/ owner(canvasItem) -{ - setAcceptedMouseButtons(Qt::NoButton); -} - -QSimpleGraphicsItem::~QSimpleGraphicsItem() -{ - owner->d_func()->graphicsItem = 0; -} - -void QSimpleGraphicsItem::paint(QPainter *painter, - const QStyleOptionGraphicsItem *, QWidget *) -{ - owner->paintContents(*painter); -} - -QRectF QSimpleGraphicsItem::boundingRect() const -{ - return owner->boundingRect(); -} - -void QSimpleGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - QSimpleCanvasItem *p = owner->parent(); - while(p) { - if (p->options() & QSimpleCanvasItem::ChildMouseFilter) { - if (p->mouseFilter(event)) - return; - } - p = p->parent(); - } - owner->mousePressEvent(event); -} - -void QSimpleGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) -{ - QSimpleCanvasItem *p = owner->parent(); - while(p) { - if (p->options() & QSimpleCanvasItem::ChildMouseFilter) { - if (p->mouseFilter(event)) - return; - } - p = p->parent(); - } - owner->mouseReleaseEvent(event); - ungrabMouse(); -} - -void QSimpleGraphicsItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) -{ - QSimpleCanvasItem *p = owner->parent(); - while(p) { - if (p->options() & QSimpleCanvasItem::ChildMouseFilter) { - if (p->mouseFilter(event)) - return; - } - p = p->parent(); - } - owner->mouseDoubleClickEvent(event); -} - -void QSimpleGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) -{ - QSimpleCanvasItem *p = owner->parent(); - while(p) { - if (p->options() & QSimpleCanvasItem::ChildMouseFilter) { - if (p->mouseFilter(event)) - return; - } - p = p->parent(); - } - owner->mouseMoveEvent(event); -} - -bool QSimpleGraphicsItem::sceneEvent(QEvent *event) -{ - bool rv = QGraphicsItem::sceneEvent(event); - if (event->type() == QEvent::UngrabMouse) - owner->mouseUngrabEvent(); - return rv; -} - -QVariant QSimpleGraphicsItem::itemChange(GraphicsItemChange change, const QVariant &value) -{ - if (change == ItemSceneHasChanged) { - QSimpleCanvasItemPrivate *owner_d = static_cast<QSimpleCanvasItemPrivate*>(owner->d_ptr); - QSimpleCanvas *oldCanvas = owner_d->canvas; - owner_d->canvas = sceneMap[scene()]; - if (owner_d->canvas){ - if (owner->hasFocus()) - owner->canvas()->d->setFocusItem(owner, Qt::OtherFocusReason); - if (owner->options() & QSimpleCanvasItem::IsFocusPanel) { - if (owner_d->wantsActiveFocusPanelPendingCanvas) { - owner_d->hasBeenActiveFocusPanel = true; - owner->canvas()->d->setActiveFocusPanel(owner); - owner_d->wantsActiveFocusPanelPendingCanvas = false; - } - } - } - if (owner->options() & QSimpleCanvasItem::MouseFilter) - owner_d->gvRemoveMouseFilter(); - - if (oldCanvas != owner_d->canvas) - owner->canvasChanged(); - - if (owner->options() & QSimpleCanvasItem::MouseFilter) - owner_d->gvAddMouseFilter(); - } - - return QGraphicsItem::itemChange(change, value); -} - -void QSimpleGraphicsItem::keyPressEvent(QKeyEvent *event) -{ - owner->keyPressEvent(event); - QGraphicsItem::keyPressEvent(event); -} - -void QSimpleGraphicsItem::keyReleaseEvent(QKeyEvent *event) -{ - owner->keyReleaseEvent(event); - QGraphicsItem::keyReleaseEvent(event); -} - -void QSimpleGraphicsItem::focusInEvent(QFocusEvent *) -{ - if (!owner->hasFocus()) - owner->setFocus(true); -} - -void QSimpleCanvasItemPrivate::gvRemoveMouseFilter() -{ - QGraphicsScene *scene = graphicsItem->scene(); - if (!scene) return; - - scene->removeEventFilter(q_ptr); -} - -void QSimpleCanvasItemPrivate::gvAddMouseFilter() -{ - QGraphicsScene *scene = graphicsItem->scene(); - if (!scene) return; - - scene->installEventFilter(q_ptr); -} -QT_END_NAMESPACE diff --git a/src/declarative/canvas/qsimplecanvas_opengl.cpp b/src/declarative/canvas/qsimplecanvas_opengl.cpp deleted file mode 100644 index 7969a2a..0000000 --- a/src/declarative/canvas/qsimplecanvas_opengl.cpp +++ /dev/null @@ -1,680 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qsimplecanvas.h" -#include "qsimplecanvas_p.h" -#include "qsimplecanvasitem_p.h" -#include "qsimplecanvasfilter_p.h" -#include <glsave.h> -#include <QtOpenGL/qglframebufferobject.h> -#include <gltexture.h> -#include <math.h> - - -QT_BEGIN_NAMESPACE -void CanvasEGLWidget::paintGL() -{ - glClearColor(0.0f, 0.0f, 0.0f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - _canvas->paintGL(); -} - -void CanvasEGLWidget::updateGL() -{ - _clip = QRect(); - QGLWidget::updateGL(); -} - -void CanvasEGLWidget::updateGL(const QRect &r) -{ - if (r.isEmpty()) - return; - - _clip = r; - QGLWidget::updateGL(); -} - -void CanvasEGLWidget::resizeGL(int w, int h) -{ - glViewport(0, 0, w, h); -} - -QRect CanvasEGLWidget::map(const QRectF &f) const -{ - return invDefaultTransform.mapRect(f).toAlignedRect(); -} - -void CanvasEGLWidget::resizeEvent(QResizeEvent *e) -{ - defaultTransform.setIdentity(); - defaultTransform.flipCoordinates(); - defaultTransform.translate(-1, -1, 0); - defaultTransform.scale(2. / width(), 2. / height(), 1. / (1024. * 1024.)); - invDefaultTransform = defaultTransform.inverted(); - _canvas->root->d_func()->data()->transformActive = defaultTransform; - _canvas->root->d_func()->data()->transformValid = true; - - QGLWidget::resizeEvent(e); -} - -void CanvasEGLWidget::initializeGL() -{ - glEnable(GL_BLEND); - glEnable(GL_STENCIL_TEST); - glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, - GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - - glStencilFunc(GL_EQUAL, 0, 0xFFFFFFFF); - glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); -} - -void QSimpleCanvasPrivate::paintGL() -{ - lrpTimer.start(); - - QSimpleCanvasItemPrivate::GLPaintParameters p; - QSimpleCanvasItem::GLPainter painter; - - p.sceneRect = QRect(0, 0, q->width(), q->height()); - p.clipRect = p.sceneRect; - p.stencilValue = 0; - p.opacity = 1; - p.forceParamRefresh = false; - p.painter = &painter; - if (!isSetup) { - opaqueList = 0; - int z = 0; - root->d_func()->setupPainting(0, z, &opaqueList); - } - - glEnable(GL_DEPTH_TEST); - - glDisable(GL_BLEND); - painter.blendEnabled = false; - painter.activeOpacity = 1; - while (opaqueList) { - painter.item = opaqueList; - painter.activeTransform = opaqueList->d_func()->data()->transformActive; - // ### - I don't think this is right - painter.sceneClipRect = p.clipRect; - - opaqueList->paintGLContents(painter); - opaqueList = opaqueList->d_func()->nextOpaque; - } - glEnable(GL_BLEND); - painter.blendEnabled = true; - - root->d_func()->paint(p); - - lrpTime = lrpTimer.elapsed(); -} - -QGLFramebufferObject *QSimpleCanvasPrivate::acquire(int w, int h) -{ - if (w <= 0 || h <= 0) - return 0; - - int size = qMax(w, h); - for (int ii = 0; ii < frameBuffers.count(); ++ii) { - if (frameBuffers.at(ii)->width() >= size) { - QGLFramebufferObject *rv = frameBuffers.at(ii); - frameBuffers.removeAt(ii); - return rv; - } - } - - // Find power of two - size--; - size |= size >> 1; - size |= size >> 2; - size |= size >> 4; - size |= size >> 8; - size |= size >> 16; - size++; - - QGLFramebufferObject *fbo = new QGLFramebufferObject(size, size); - return fbo; -} - -void QSimpleCanvasPrivate::release(QGLFramebufferObject *buf) -{ - int size = qMax(buf->width(), buf->height()); - for (int ii = 0; ii < frameBuffers.count(); ++ii) { - if (frameBuffers.at(ii)->width() >= size) { - frameBuffers.insert(ii, buf); - return; - } - } - frameBuffers.append(buf); -} - -GLBasicShaders *QSimpleCanvasItemPrivate::basicShaders() const -{ - return canvas->d->basicShaders(); -} - -QSimpleCanvas::Matrix QSimpleCanvasItemPrivate::localTransform() const -{ - Q_Q(const QSimpleCanvasItem); - - QSimpleCanvas::Matrix trans; - trans.translate(q->x(), q->y()); - QPointF to = transformOrigin(); - trans.translate(to.x(), to.y()); - trans.scale(q->scale(), q->scale()); - trans.translate(-to.x(), -to.y()); - if (data()->transformUser) - trans *= *data()->transformUser; - return trans; -} - -void QSimpleCanvasItemPrivate::simplePaintChild(const GLPaintParameters ¶ms, QSimpleCanvasItem *child) -{ - Q_Q(QSimpleCanvasItem); - - GLPaintParameters childParams = params; - if (clip) - ++childParams.stencilValue; - - if (child->d_func()->data()->activeOpacity != 0) { - childParams.boundingRect = child->boundingRect(); - - if (child->filter() && child->filter()->enabled()) { - QSimpleCanvasItem::GLPainter &painter = *params.painter; - painter.item = q; - painter.activeTransform = child->d_func()->data()->transformActive; - painter.activeOpacity = child->d_func()->data()->activeOpacity; - painter.sceneClipRect = params.clipRect; - child->filter()->d->doFilterGL(painter, childParams); - } else { - child->d_func()->paint(childParams); - } - } -} - -void QSimpleCanvasItemPrivate::paintChild(const GLPaintParameters ¶ms, - QSimpleCanvasItem *child) -{ - if (params.forceParamRefresh) { - QSimpleCanvas::Matrix t = child->d_func()->data()->transformActive; - qreal o = child->d_func()->data()->activeOpacity; - setupChildState(child); - simplePaintChild(params, child); - child->d_func()->data()->transformActive = t; - child->d_func()->data()->transformValid = true; - child->d_func()->data()->activeOpacity = o; - } else { - simplePaintChild(params, child); - } -} - -void QSimpleCanvasItemPrivate::setupChildState(QSimpleCanvasItem *child) -{ - QSimpleCanvasItemData *const myData = data(); - QSimpleCanvasItemPrivate *const childPrivate = child->d_func(); - QSimpleCanvasItemData *const childData = childPrivate->data(); - - childData->activeOpacity = myData->activeOpacity; - if (childData->visible != 1.) - childData->activeOpacity *= childData->visible; - - if (childData->activeOpacity != 0.) { - QSimpleCanvas::Matrix &am = childData->transformActive; - am = myData->transformActive; - - // Calculate child's transform - const qreal x = childData->x; - const qreal y = childData->y; - const qreal scale = childPrivate->scale; - QSimpleCanvasItem::Flip flip = childData->flip; - - if (x != 0. || y != 0.) - am.translate(x, y); - - if (scale != 1.) { - if (childPrivate->origin == QSimpleCanvasItem::TopLeft) { - am.scale(scale, scale); - } else { - QPointF to = childPrivate->transformOrigin(); - am.translate(to.x(), to.y()); - am.scale(scale, scale); - am.translate(-to.x(), -to.y()); - } - } - - if (childData->transformUser) - am *= *childData->transformUser; - if (flip) { - QRectF br = child->boundingRect(); - am.translate(br.width() / 2., br.height() / 2); - am.rotate(180, (flip & QSimpleCanvasItem::VerticalFlip)?1:0, (flip & QSimpleCanvasItem::HorizontalFlip)?1:0, 0); - am.translate(-br.width() / 2., -br.height() / 2); - } - - childData->transformValid = true; - } -} - -#define QSIMPLECANVAS_DISABLE_TREE_CLIPPING -QRectF QSimpleCanvasItemPrivate::setupPainting(int version, int &z, QSimpleCanvasItem **opaqueList) -{ - static QRectF scene(-1., -1., 2., 2.); - Q_Q(QSimpleCanvasItem); - - bool hasContents = options & QSimpleCanvasItem::HasContents; - - QSimpleCanvasItemData *myData = data(); - - QRectF rv; - if (hasContents) { - QRectF filteredBoundRect = q->boundingRect(); - if (filter) - filteredBoundRect = filter->itemBoundingRect(filteredBoundRect); - const QMatrix4x4 &active = myData->transformActive; - - rv = active.mapRect(filteredBoundRect); - } -#ifdef QSIMPLECANVAS_DISABLE_TREE_CLIPPING - myData->doNotPaint = false; - myData->doNotPaintChildren = false; -#else - myData->doNotPaint = !hasContents || !rv.intersects(scene); - myData->doNotPaintChildren = hasContents && myData->doNotPaint && - (clip != QSimpleCanvasItem::NoClip); -#endif - - if (!myData->doNotPaint && - (options & QSimpleCanvasItem::IsOpaque) && - (myData->activeOpacity == 1.) && - (clip == 0)) { - - nextOpaque = *opaqueList; - *opaqueList = q; - myData->doNotPaint = true; - - } - - int myZ = z++; - - if (myData->doNotPaintChildren) { - rv = QRectF(); - } else { - zOrderChildren(); - - for (int ii = 0; ii < children.count(); ++ii) { - QSimpleCanvasItem *child = children.at(ii); - setupChildState(child); - - QSimpleCanvasItemData *childData = child->d_func()->data(); - if (childData->activeOpacity != 0) - rv |= child->d_func()->setupPainting(version, z, opaqueList); - } - -#ifndef QSIMPLECANVAS_DISABLE_TREE_CLIPPING - myData->doNotPaintChildren |= !rv.intersects(scene); -#endif - } - - myData->transformActive.translate(0, 0, myZ); - - myData->lastPaintRect = rv; - - return rv; -} - - -void QSimpleCanvasItemPrivate::paint(GLPaintParameters &oldParams, QSimpleCanvasFilter::Layer layer) -{ - if (!layer) - return; - - Q_Q(QSimpleCanvasItem); - - bool doNotPaintChildren = data()->doNotPaintChildren; - if (doNotPaintChildren) - return; - - GLPaintParameters params = oldParams; - - qreal width = params.boundingRect.width(); - qreal height = params.boundingRect.height(); - - GLfloat vertices[] = { 0, height, - width, height, - 0, 0, - width, 0 }; - - // XXX Handle separate cliping modes - if (clip) { - if (params.stencilValue == 255) - qWarning() - << "OpenGL: Clip recursion greater than 255 not permitted."; - glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); - - glStencilFunc(GL_EQUAL, params.stencilValue, 0xFFFFFFFF); - glStencilOp(GL_KEEP, GL_KEEP, GL_INCR); - - ConstantColorShader *shader = basicShaders()->constantColor(); - params.painter->invalidate(); - shader->enable(); - shader->setTransform(data()->transformActive); - - shader->setAttributeArray(ConstantColorShader::Vertices, vertices, 2); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - - glStencilFunc(GL_EQUAL, params.stencilValue + 1, 0xFFFFFFFF); - glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); - - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - - // XXX Copied from qsimplecanvas_opengl1 scissor based clipping - QRectF r = data()->transformActive.mapRect(params.boundingRect); - r.translate(1, 1); - float xscale = 0.5 * float(params.sceneRect.width()); - float yscale = 0.5 * float(params.sceneRect.height()); - r.moveTo(r.x() * xscale, r.y() * yscale); - r.setSize(QSizeF(r.width() * xscale, r.height() * yscale)); - int sr_x = int(::floorf(r.x())); - int sr_y = int(::floorf(r.y())); - int sr_width = int(::ceilf(r.right())) - sr_x; - int sr_height = int(::ceilf(r.bottom())) - sr_y; - QRect sr(sr_x, sr_y, sr_width, sr_height); - sr.moveTo(sr.x(), params.sceneRect.height() - sr.y() - sr.height()); - sr &= params.clipRect; - params.clipRect = sr; - } - - int upto = 0; - for (upto = 0; upto < children.count(); ++upto) { - QSimpleCanvasItem *c = children.at(upto); - if (c->z() < 0) { - if (layer & QSimpleCanvasFilter::ChildrenUnderItem) - paintChild(params, c); - } else { - break; - } - } - - bool doNotPaint = data()->doNotPaint; - - if (!doNotPaint && layer & QSimpleCanvasFilter::Item) { - QSimpleCanvasItem::GLPainter &painter = *params.painter; - painter.item = q; - painter.activeTransform = data()->transformActive; - painter.activeOpacity = data()->activeOpacity; - painter.sceneClipRect = params.clipRect; - - q->paintGLContents(painter); - } - - if (layer & QSimpleCanvasFilter::ChildrenAboveItem) { - for (; upto < children.count(); ++upto) { - QSimpleCanvasItem *c = children.at(upto); - paintChild(params, c); - } - } - - if (clip) { - glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); - glStencilFunc(GL_EQUAL, params.stencilValue + 1, 0xFFFFFFFF); - glStencilOp(GL_KEEP, GL_KEEP, GL_DECR); - - params.painter->invalidate(); - ConstantColorShader *shader = basicShaders()->constantColor(); - shader->enable(); - shader->setTransform(data()->transformActive); - - shader->setAttributeArray(ConstantColorShader::Vertices, vertices, 2); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - - glStencilFunc(GL_EQUAL, params.stencilValue, 0xFFFFFFFF); - glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - } -} - -enum ShaderType { ST_None, ST_SingleTexture, ST_SingleTextureOpacity, ST_Color }; - -QSimpleCanvasItem::GLPainter::GLPainter() -: item(0), activeOpacity(1), blendEnabled(true), flags(0) -{ -} - -QSimpleCanvasItem::GLPainter::GLPainter(QSimpleCanvasItem *i) -: item(i), activeOpacity(1), blendEnabled(true), flags(0) -{ -} - -QGLShaderProgram *QSimpleCanvasItem::GLPainter::useTextureShader() -{ - if (activeOpacity == 1.) { - SingleTextureShader *shader = item->basicShaders()->singleTexture(); - if (flags != ST_SingleTexture) { - shader->enable(); - flags = ST_SingleTexture; - } - - shader->setTransform(activeTransform); - return shader; - } else { - SingleTextureOpacityShader *shader = item->basicShaders()->singleTextureOpacity(); - - if (flags != ST_SingleTextureOpacity) { - shader->enable(); - flags = ST_SingleTextureOpacity; - } - - shader->setTransform(activeTransform); - shader->setOpacity(activeOpacity); - return shader; - } -} - -void QSimpleCanvasItem::GLPainter::invalidate() -{ - flags = ST_None; -} - -QGLShaderProgram *QSimpleCanvasItem::GLPainter::useColorShader(const QColor &color) -{ - QColor c = color; - - ConstantColorShader *shader = item->basicShaders()->constantColor(); - - if (flags != ST_Color) { - shader->enable(); - flags = ST_Color; - } - - if (activeOpacity != 1.) - c.setAlpha(int(c.alpha() * activeOpacity)); - - shader->setColor(c); - shader->setTransform(activeTransform); - - return shader; -} - -void QSimpleCanvasItem::GLPainter::drawPixmap(const QPointF &point, - const GLTexture &texture) -{ - drawPixmap(QRectF(point, QSizeF(texture.width(), texture.height())), texture); -} - -void QSimpleCanvasItem::GLPainter::drawPixmap(const QRectF &rect, - const GLTexture &img) -{ - QGLShaderProgram *shader = useTextureShader(); - - GLfloat vertices[8]; - GLfloat texVertices[8]; - - float widthV = img.width(); - float heightV = img.height(); - - vertices[0] = rect.x(); vertices[1] = rect.y()+heightV; - vertices[2] = rect.x()+widthV; vertices[3] = rect.y()+heightV; - vertices[4] = rect.x(); vertices[5] = rect.y(); - vertices[6] = rect.x()+widthV; vertices[7] = rect.y(); - - texVertices[0] = 0; texVertices[1] = 0; - texVertices[2] = 1; texVertices[3] = 0; - texVertices[4] = 0; texVertices[5] = 1; - texVertices[6] = 1; texVertices[7] = 1; - - shader->setAttributeArray(SingleTextureShader::Vertices, vertices, 2); - shader->setAttributeArray(SingleTextureShader::TextureCoords, texVertices, 2); - - glBindTexture(GL_TEXTURE_2D, img.texture()); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); -} - -void QSimpleCanvasItem::GLPainter::fillRect(const QRectF &rect, - const QColor &color) -{ - if (color.alpha() == 0xFF) - glDisable(GL_BLEND); - - QGLShaderProgram *shader = useColorShader(color); - float x = rect.x(); - float y = rect.y(); - float width = rect.width(); - float height = rect.height(); - - GLfloat vertices[] = { x, height, - width, height, - x, y, - - width, height, - x, y, - width, y }; - - shader->setAttributeArray(ConstantColorShader::Vertices, vertices, 2); - glDrawArrays(GL_TRIANGLES, 0, 6); - - if (color.alpha() == 0xFF) - glEnable(GL_BLEND); -} - -void QSimpleCanvasItem::CachedTexture::addRef() -{ - ++r; -} - -void QSimpleCanvasItem::CachedTexture::release() -{ - Q_ASSERT(r > 0); - --r; - - if (r == 0) { - if (!s.isEmpty()) - d->cachedTextures.remove(s); - delete this; - } -} - -int QSimpleCanvasItem::CachedTexture::pixmapWidth() const -{ - return w; -} - -int QSimpleCanvasItem::CachedTexture::pixmapHeight() const -{ - return h; -} - -QSimpleCanvasItem::CachedTexture::CachedTexture() -: r(0), w(0), h(0) -{ -} - -QSimpleCanvasItem::CachedTexture * -QSimpleCanvasItem::cachedTexture(const QString &key) -{ - Q_D(QSimpleCanvasItem); - if (!d->canvas || key.isEmpty()) - return 0; - - QSimpleCanvasPrivate *canvas = d->canvas->d; - QHash<QString, QSimpleCanvasItem::CachedTexture *>::ConstIterator iter = - canvas->cachedTextures.find(key); - if (iter != canvas->cachedTextures.end()) { - (*iter)->addRef(); - return (*iter); - } else { - return 0; - } -} - -QSimpleCanvasItem::CachedTexture * -QSimpleCanvasItem::cachedTexture(const QString &key, const QPixmap &pix) -{ - Q_D(QSimpleCanvasItem); - if (!d->canvas) - return 0; - - QSimpleCanvasPrivate *canvas = d->canvas->d; - QHash<QString, QSimpleCanvasItem::CachedTexture *>::ConstIterator iter = - canvas->cachedTextures.end(); - if (!key.isEmpty()) - iter = canvas->cachedTextures.find(key); - - if (iter != canvas->cachedTextures.end()) { - (*iter)->addRef(); - return (*iter); - } else { - CachedTexture *rv = new CachedTexture; - rv->s = key; - rv->d = canvas; - rv->w = pix.width(); - rv->h = pix.height(); - rv->setImage(pix.toImage(), GLTexture::PowerOfTwo); - rv->setHorizontalWrap(GLTexture::Repeat); - rv->setVerticalWrap(GLTexture::Repeat); - rv->addRef(); - if (!key.isEmpty()) - canvas->cachedTextures.insert(key, rv); - return rv; - } -} - -QT_END_NAMESPACE diff --git a/src/declarative/canvas/qsimplecanvas_opengl1.cpp b/src/declarative/canvas/qsimplecanvas_opengl1.cpp deleted file mode 100644 index 6e50ef8..0000000 --- a/src/declarative/canvas/qsimplecanvas_opengl1.cpp +++ /dev/null @@ -1,401 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qsimplecanvas.h" -#include "qsimplecanvas_p.h" -#include "qsimplecanvasitem_p.h" -#include "qsimplecanvasfilter_p.h" -#include <gltexture.h> -#include <glsave.h> -#include <math.h> - - -QT_BEGIN_NAMESPACE -void CanvasEGLWidget::updateGL() -{ - _clip = QRect(); - QGLWidget::updateGL(); -} - -void CanvasEGLWidget::updateGL(const QRect &r) -{ - if (r.isEmpty()) - return; - - _clip = r; - QGLWidget::updateGL(); -} - -void CanvasEGLWidget::paintGL() -{ - if (!_clip.isEmpty()) { - glEnable(GL_SCISSOR_TEST); - glScissor(_clip.x(), _clip.y(), _clip.width(), _clip.height()); - } else { - glDisable(GL_SCISSOR_TEST); - } - - glDepthMask(GL_TRUE); - glClearColor(0.0f, 0.0f, 0.0f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glDepthMask(GL_FALSE); - - _canvas->paintGL(); -} - -QRect CanvasEGLWidget::map(const QRectF &f) -{ - return invDefaultTransform.mapRect(f).toAlignedRect(); -} - -void CanvasEGLWidget::resizeGL(int w, int h) -{ - glViewport(0, 0, w, h); -} - -void CanvasEGLWidget::resizeEvent(QResizeEvent *e) -{ - defaultTransform.identity(); - defaultTransform.flipCoordinates(); - defaultTransform.translate(-1, -1, 0); - defaultTransform.scale(2. / width(), 2. / height(), -2. / 65536.); - invDefaultTransform = defaultTransform.inverted(); - _canvas->root->d_func()->transformActive = defaultTransform; - QGLWidget::resizeEvent(e); -} - -void CanvasEGLWidget::initializeGL() -{ - glEnable(GL_BLEND); - glEnable(GL_DEPTH_TEST); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glDepthFunc(GL_GREATER); -#ifdef QT_OPENGL_ES - glClearDepthf(0); -#else - glClearDepth(0); -#endif -} - -void QSimpleCanvasPrivate::paintGL() -{ - lrpTimer.start(); - - QSimpleCanvasItemPrivate::GLPaintParameters p; - p.sceneRect = QRect(0, 0, q->width(), q->height()); - p.clipRect = p.sceneRect; - p.opacity = 1; - p.forceParamRefresh = false; - if (!isSetup) { - unsigned int zero = 0; - root->d_func()->setupPainting(0, QRect(), &zero); - } - root->d_func()->paint(p); - - lrpTime = lrpTimer.elapsed(); -} - -QSimpleCanvas::Matrix QSimpleCanvasItemPrivate::localTransform() const -{ - Q_Q(const QSimpleCanvasItem); - - QSimpleCanvas::Matrix trans; - trans.translate(q->x(), q->y()); - QPointF to = transformOrigin(); - trans.translate(to.x(), to.y()); - trans.scale(q->scale().value(), q->scale().value()); - trans.translate(-to.x(), -to.y()); - trans *= transformUser; - return trans; -} - -void QSimpleCanvasItemPrivate::simplePaintChild(const GLPaintParameters ¶ms, QSimpleCanvasItem *child) -{ - GLPaintParameters childParams = params; - - if (child->d_func()->activeOpacity != 0) { - childParams.boundingRect = child->boundingRect(); - child->d_func()->paint(childParams); - } -} - -void QSimpleCanvasItemPrivate::paintChild(const GLPaintParameters ¶ms, - QSimpleCanvasItem *child) -{ - if (params.forceParamRefresh) { - QSimpleCanvas::Matrix t = child->d_func()->transformActive; - qreal o = child->d_func()->activeOpacity; - setupChildState(child); - simplePaintChild(params, child); - child->d_func()->transformActive = t; - child->d_func()->activeOpacity = o; - } else { - simplePaintChild(params, child); - } -} - - -void QSimpleCanvasItemPrivate::setupChildState(QSimpleCanvasItem *child) -{ - qreal visible = child->visible().value(); - child->d_func()->activeOpacity = activeOpacity; - if (visible != 1) - child->d_func()->activeOpacity *= visible; - - if (child->d_func()->activeOpacity != 0) { - // Calculate child's transform - qreal x = child->x(); - qreal y = child->y(); - qreal scale = child->scale().value(); - QSimpleCanvasItem::Flip flip = child->flip(); - - QSimpleCanvas::Matrix &am = child->d_func()->transformActive; - am = transformActive; - if (x != 0 || y != 0) - am.translate(x, y); - if (scale != 1) { - QPointF to = child->d_func()->transformOrigin(); - if (to.x() != 0. || to.y() != 0.) - am.translate(to.x(), to.y()); - am.scale(scale, scale); - if (to.x() != 0. || to.y() != 0.) - am.translate(-to.x(), -to.y()); - } - if (child->d_func()->transformUserSet) - am *= child->d_func()->transformUser; - if (flip) { - QRectF br = child->boundingRect(); - am.translate(br.width() / 2., br.height() / 2); - am.rotate(180, (flip & QSimpleCanvasItem::VerticalFlip)?1:0, (flip & QSimpleCanvasItem::HorizontalFlip)?1:0, 0); - am.translate(-br.width() / 2., -br.height() / 2); - } - } -} - -QRectF QSimpleCanvasItemPrivate::setupPainting(int version, const QRect &bounding, unsigned int *zero) -{ - Q_Q(QSimpleCanvasItem); - - QRectF rv = transformActive.mapRect(q->boundingRect()); - - unsigned int oldZero = *zero; - - for (int ii = 0; ii < children.count(); ++ii) { - QSimpleCanvasItem *child = children.at(ii); - setupChildState(child); - - if (child->d_func()->activeOpacity != 0) - rv |= child->d_func()->setupPainting(version, bounding, zero); - } - - if (clip || oldZero != *zero) - (*zero)++; - transformActive.translate(0, 0, *zero); - - lastPaintRect = rv; - return rv; -} - -void QSimpleCanvasItemPrivate::paintNoClip(GLPaintParameters ¶ms, QSimpleCanvasFilter::Layer layer) -{ - Q_Q(QSimpleCanvasItem); - - zOrderChildren(); - - int upto = 0; - for (upto = 0; upto < children.count(); ++upto) { - QSimpleCanvasItem *c = children.at(upto); - if (c->zValue().value() < 0) { - if (layer & QSimpleCanvasFilter::ChildrenUnderItem) - paintChild(params, c); - } else { - break; - } - } - - if (layer & QSimpleCanvasFilter::Item && - q->options() & QSimpleCanvasItem::HasContents) { - QSimpleCanvasItem::GLPainter painter(q); - painter.activeTransform = transformActive; - painter.activeOpacity = activeOpacity; - painter.sceneClipRect = params.clipRect; - - q->paintGLContents(painter); - } - - if (layer & QSimpleCanvasFilter::ChildrenAboveItem) { - for (; upto < children.count(); ++upto) { - QSimpleCanvasItem *c = children.at(upto); - paintChild(params, c); - } - } -} - -void QSimpleCanvasItemPrivate::paint(GLPaintParameters ¶ms, QSimpleCanvasFilter::Layer layer) -{ - if (!layer) - return; - - // XXX Handle separate cliping modes - if (clip) { - - GLSaveScissor ss; - qreal width = params.boundingRect.width(); - qreal height = params.boundingRect.height(); - float margin = width + height; - - GLfloat clipvertices[] = - { - -margin, -margin, - margin, -margin, - margin, 0, - - -margin, -margin, - -margin, 0, - margin, 0, - - -margin, 0, - -margin, margin, - 0, 0, - - 0, 0, - 0, margin, - -margin, margin, - - 0, height, - 0, margin, - margin, margin, - - margin, margin, - 0, height, - margin, height, - - width, 0, - margin, 0, - margin, height, - - margin, height, - width, height, - width, 0 - }; - - QRectF r = transformActive.mapRect(params.boundingRect); - r.translate(1, 1); - float xscale = 0.5 * float(params.sceneRect.width()); - float yscale = 0.5 * float(params.sceneRect.height()); - r.moveTo(r.x() * xscale, r.y() * yscale); - r.setSize(QSizeF(r.width() * xscale, r.height() * yscale)); - - glEnable(GL_SCISSOR_TEST); - int sr_x = ::floorf(r.x()); - int sr_y = ::floorf(r.y()); - int sr_width = ::ceilf(r.right()) - sr_x; - int sr_height = ::ceilf(r.bottom()) - sr_y; - - QRect sr(sr_x, sr_y, sr_width, sr_height); - if (ss.wasEnabled()) - sr &= ss.rect(); - - glScissor(sr.x(), sr.y(), sr.width(), sr.height()); - - { - glMatrixMode(GL_MODELVIEW); - glLoadMatrixf(transformActive.data()); - glDepthMask(GL_TRUE); - glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(2, GL_FLOAT, 0, clipvertices); - glDrawArrays(GL_TRIANGLES, 0, 24); - glDisableClientState(GL_VERTEX_ARRAY); - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - glDepthMask(GL_FALSE); - } - - GLPaintParameters newParams = params; - newParams.clipRect = sr; - newParams.clipRect.moveTo(sr.x(), params.sceneRect.height() - sr.y() - sr.height()); - paintNoClip(newParams, layer); - } else { - paintNoClip(params, layer); - } -} - -QGLShaderProgram *QSimpleCanvasItem::GLPainter::useTextureShader() -{ - qFatal("Cannot call QSimpleCanvasItem::GLPainter::useTextureShader() when using OpenGL ES 1.1"); - return 0; -} - -QGLShaderProgram *QSimpleCanvasItem::GLPainter::useColorShader(const QColor &color) -{ - Q_UNUSED(color); - qFatal("Cannot call QSimpleCanvasItem::GLPainter::useColorShader() when using OpenGL ES 1.1"); - return 0; -} - -GLBasicShaders *QSimpleCanvasItemPrivate::basicShaders() const -{ - qFatal("Cannot call QSimpleCanvasItem::basicShaders() when using OpenGL ES 1.1"); - return 0; -} - -QGLFramebufferObject *QSimpleCanvasPrivate::acquire(int, int) -{ - return 0; -} - -void QSimpleCanvasPrivate::release(QGLFramebufferObject *) -{ -} - -void QSimpleCanvasItem::GLPainter::drawPixmap(const QPointF &point, - const GLTexture &texture) -{ - drawPixmap(QRectF(point, QSizeF(texture.width(), texture.height())), texture); -} - -void QSimpleCanvasItem::GLPainter::drawPixmap(const QRectF &rect, - const GLTexture &img) -{ - qFatal("Cannot call QSimpleCanvasItem::GLPainter::drawPixmap() when using OpenGL ES 1.1"); -} - -QT_END_NAMESPACE diff --git a/src/declarative/canvas/qsimplecanvas_p.h b/src/declarative/canvas/qsimplecanvas_p.h deleted file mode 100644 index c900ccf..0000000 --- a/src/declarative/canvas/qsimplecanvas_p.h +++ /dev/null @@ -1,206 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSIMPLECANVAS_P_H -#define QSIMPLECANVAS_P_H - -#include "qsimplecanvas.h" -#include "qsimplecanvasitem.h" -#include <qstack.h> -#include <qdatetime.h> - -#if defined(QFX_RENDER_OPENGL) - -#if defined(QFX_RENDER_OPENGL2) -#include "glbasicshaders.h" -#endif - -#include <QGLWidget> -QT_BEGIN_NAMESPACE - -class CanvasEGLWidget : public QGLWidget -{ -public: - CanvasEGLWidget(QSimpleCanvas *parent, QSimpleCanvasPrivate *canvas) - : - QGLWidget(parent), - _canvas(canvas) - { - } - - virtual void paintGL(); - virtual void resizeGL(int,int); - virtual void resizeEvent(QResizeEvent *e); - virtual void initializeGL(); - - void updateGL(); - void updateGL(const QRect &); - - QRect map(const QRectF &) const; -private: - QRect _clip; - QSimpleCanvasPrivate *_canvas; - QSimpleCanvas::Matrix defaultTransform; - QSimpleCanvas::Matrix invDefaultTransform; -}; -QT_END_NAMESPACE -#endif - -#include <QGraphicsView> -#include <QGraphicsScene> - -QT_BEGIN_NAMESPACE - -struct QSimpleCanvasGraphicsView : public QGraphicsView -{ -public: - QSimpleCanvasGraphicsView(QSimpleCanvasPrivate *parent); - ~QSimpleCanvasGraphicsView(); - -protected: - virtual void paintEvent(QPaintEvent *); - virtual void focusInEvent(QFocusEvent *); - -private: - QSimpleCanvasPrivate *canvas; - QGraphicsScene _scene; -}; - -class QGLFramebufferObject; -class QSimpleCanvasDebugPlugin; -class QSimpleCanvasPrivate -{ -public: - QSimpleCanvasPrivate(QSimpleCanvas *canvas) - : q(canvas), timer(0), root(0), lrpTime(0), debugPlugin(0), focusItem(0), - lastFocusItem(0), lastMouseItem(0), - isSetup(false), view(0) -#if defined(QFX_RENDER_OPENGL) - ,egl(q, this), basicShadersInstance(0) -#endif - , paintVersion(1) - { - } - - QSimpleCanvas *q; - QSimpleCanvas::CanvasMode mode; - bool isSimpleCanvas() const { return mode == QSimpleCanvas::SimpleCanvas; } - bool isGraphicsView() const { return mode == QSimpleCanvas::GraphicsView; } - -#if defined(QFX_RENDER_OPENGL) - QRectF oldDirty; -#else - QRect oldDirty; -#endif - QRect resetDirty(); - void paint(QPainter &p); - - QSimpleCanvasItem *opaqueList; - - int timer; - - QSimpleCanvasLayer *root; - QList<QSimpleCanvasItem *> dirtyItems; - int lrpTime; - - QTime frameTimer; - QTime lrpTimer; - - QSimpleCanvasDebugPlugin *debugPlugin; - - QStack<QSimpleCanvasItem *> focusPanels; - QHash<QSimpleCanvasItem *, QSimpleCanvasItem *> focusPanelData; - QSimpleCanvasItem *focusItem; - QSimpleCanvasItem *lastFocusItem; - - QRect dirtyItemClip() const; - void clearFocusPanel(QSimpleCanvasItem *); - void setActiveFocusPanel(QSimpleCanvasItem *, Qt::FocusReason focusReason = Qt::OtherFocusReason); - void switchToFocusPanel(QSimpleCanvasItem *, QSimpleCanvasItem *, Qt::FocusReason focusReason); - - void setFocusItem(QSimpleCanvasItem *item, Qt::FocusReason focusReason, - bool overwrite = true); - void clearFocusItem(QSimpleCanvasItem *item); - - void clearActiveFocusItem(QSimpleCanvasItem *, Qt::FocusReason focusReason); - void setActiveFocusItem(QSimpleCanvasItem *, Qt::FocusReason focusReason); - void installMouseFilter(QSimpleCanvasItem *); - void removeMouseFilter(QSimpleCanvasItem *); - QList<QSimpleCanvasItem *> mouseFilters; - bool filter(QMouseEvent *e); - bool deliverMousePress(QSimpleCanvasItem *, QMouseEvent *, bool = false); - QGraphicsSceneMouseEvent *mouseEventToSceneMouseEvent(QMouseEvent *, const QPoint &); - QSimpleCanvasItem *lastMouseItem; - void sendMouseEvent(QSimpleCanvasItem *, QGraphicsSceneMouseEvent *); - - bool isSetup; - - void init(QSimpleCanvas::CanvasMode mode); - - QSimpleCanvasGraphicsView *view; - -#if defined(QFX_RENDER_OPENGL) - CanvasEGLWidget egl; - GLBasicShaders *basicShaders() const - { -#if defined(QFX_RENDER_OPENGL2) - if (!basicShadersInstance) - basicShadersInstance = new GLBasicShaders; - return basicShadersInstance; -#else - return 0; -#endif - } - mutable GLBasicShaders *basicShadersInstance; - - QHash<QString, QSimpleCanvasItem::CachedTexture *> cachedTextures; - - QList<QGLFramebufferObject *> frameBuffers; - QGLFramebufferObject *acquire(int, int); - void release(QGLFramebufferObject *); - void paintGL(); -#endif - int paintVersion; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/declarative/canvas/qsimplecanvas_software.cpp b/src/declarative/canvas/qsimplecanvas_software.cpp deleted file mode 100644 index dd5e201..0000000 --- a/src/declarative/canvas/qsimplecanvas_software.cpp +++ /dev/null @@ -1,232 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qsimplecanvas.h" -#include "qsimplecanvasitem_p.h" -#include "qsimplecanvas_p.h" - - -QT_BEGIN_NAMESPACE -QRect QSimpleCanvasItemPrivate::setupPainting(int version, const QRect &bounding) -{ - Q_Q(QSimpleCanvasItem); - - bool hasContents = options & QSimpleCanvasItem::HasContents; - - QRect rv; - - if (hasContents || q->clip()) { - QRectF boundingRectActive = q->boundingRect(); - rv = data()->transformActive.mapRect(boundingRectActive).toAlignedRect() & bounding; - } - - data()->doNotPaint = rv.isEmpty(); - data()->doNotPaintChildren = data()->doNotPaint && q->clip(); - QRect myBounding = bounding; - if (q->clip()) - myBounding &= rv; - - if (!data()->doNotPaintChildren) { - for (int ii = 0; ii < children.count(); ++ii) { - QSimpleCanvasItem *child = children.at(ii); - - int childVersion = version; - if (!child->d_func()->data()->transformValid) - childVersion = canvas->d->paintVersion; - - bool recalcNeeded = - (childVersion > child->d_func()->data()->transformVersion); - - if (recalcNeeded) { - qreal visible = child->visible(); - child->d_func()->data()->activeOpacity = data()->activeOpacity; - if (visible != 1) - child->d_func()->data()->activeOpacity *= visible; - } - - if (child->d_func()->data()->activeOpacity != 0) { - if (recalcNeeded) { - // Calculate child's transform - qreal x = child->x(); - qreal y = child->y(); - qreal scale = child->scale(); - QSimpleCanvasItem::Flip flip = child->flip(); - - QSimpleCanvas::Matrix &am = - child->d_func()->data()->transformActive; - am = data()->transformActive; - if (x != 0 || y != 0) - am.translate(x, y); - if (scale != 1) { - QPointF to = child->d_func()->transformOrigin(); - if (to.x() != 0. || to.y() != 0.) - am.translate(to.x(), to.y()); - am.scale(scale, scale); - if (to.x() != 0. || to.y() != 0.) - am.translate(-to.x(), -to.y()); - } - - if (child->d_func()->data()->transformUser) - am = *child->d_func()->data()->transformUser * am; - - if (flip) { - QRectF br = child->boundingRect(); - am.translate(br.width() / 2., br.height() / 2); - am.scale((flip & QSimpleCanvasItem::HorizontalFlip)?-1:1, - (flip & QSimpleCanvasItem::VerticalFlip)?-1:1); - am.translate(-br.width() / 2., -br.height() / 2); - } - child->d_func()->data()->transformValid = true; - child->d_func()->data()->transformVersion = childVersion; - } - rv |= child->d_func()->setupPainting(child->d_func()->data()->transformVersion, myBounding); - } - } - } - - data()->lastPaintRect = rv; - if (!data()->doNotPaintChildren) { - if (!bounding.intersects(rv)) { - data()->doNotPaintChildren = true; - data()->doNotPaint = true; - } - } - - return rv; -} - -void QSimpleCanvasItemPrivate::paint(QPainter &p) -{ - Q_Q(QSimpleCanvasItem); - - QRect oldUcr; - if (clip) { - - p.save(); - QRectF boundingRectActive = q->boundingRect(); - - QRect cr; - switch(clip) { - case QSimpleCanvasItem::ClipToHeight: - { - qWarning("QSimpleCanvasItem: ClipToHeight not implemented"); - QRect r = p.clipRegion().boundingRect(); - cr = QRect(r.x(), 0, r.width(), - boundingRectActive.height()); - } - break; - case QSimpleCanvasItem::ClipToWidth: - { - qWarning("QSimpleCanvasItem: ClipToWidth not implemented"); - QRect r = p.clipRegion().boundingRect(); - cr = QRect(0, r.y(), boundingRectActive.width(), - r.height()); - } - break; - case QSimpleCanvasItem::ClipToRect: - cr = boundingRectActive.toAlignedRect(); - break; - default: - break; - } - - p.setWorldTransform(data()->transformActive); - if (p.clipRegion().isEmpty()) { - p.setClipRect(cr); - } else { - p.setClipRect(cr, Qt::IntersectClip); - } - - if (p.clipRegion().isEmpty()) { - p.restore(); - return; - } - } - - zOrderChildren(); - - int upto = 0; - if (!data()->doNotPaintChildren) { - for (upto = 0; upto < children.count(); ++upto) { - QSimpleCanvasItem *c = children.at(upto); - if (c->z() < 0) { - paintChild(p, c); - } else { - break; - } - } - } - - if (!data()->doNotPaint) { - p.setWorldTransform(data()->transformActive); - q->paintContents(p); - } - - if (!data()->doNotPaintChildren) { - for (; upto < children.count(); ++upto) { - QSimpleCanvasItem *c = children.at(upto); - paintChild(p, c); - } - } - - if (clip) - p.restore(); - - if (debuggerStatus && debuggerStatus->selected) { - p.setWorldTransform(data()->transformActive); - p.fillRect(q->boundingRect(), QColor(255, 0, 0, 80)); - } -} - -void QSimpleCanvasItemPrivate::paintChild(QPainter &p, QSimpleCanvasItem *c) -{ - if (c->d_func()->data()->activeOpacity != 0) { - - qreal op = p.opacity(); - p.setOpacity(c->d_func()->data()->activeOpacity); - - c->d_func()->paint(p); - - p.setOpacity(op); - } -} - -QT_END_NAMESPACE diff --git a/src/declarative/canvas/qsimplecanvasdebugplugin.cpp b/src/declarative/canvas/qsimplecanvasdebugplugin.cpp deleted file mode 100644 index 12088c1..0000000 --- a/src/declarative/canvas/qsimplecanvasdebugplugin.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qsimplecanvasdebugplugin_p.h" -#include "qdebug.h" -#include <QtCore/qabstractanimation.h> -#include <qsimplecanvas.h> -#include <qsimplecanvasitem.h> - -QT_BEGIN_NAMESPACE - -class FrameBreakAnimation : public QAbstractAnimation -{ -public: - FrameBreakAnimation(QSimpleCanvasDebugPlugin *s) - : QAbstractAnimation(s), server(s) - { - start(); - } - - virtual int duration() const { return -1; } - virtual void updateCurrentTime(int msecs) { - Q_UNUSED(msecs); - server->frameBreak(); - } - -private: - QSimpleCanvasDebugPlugin *server; -}; - -QSimpleCanvasDebugPlugin::QSimpleCanvasDebugPlugin(QObject *parent) -: QmlDebugServerPlugin(QLatin1String("CanvasFrameRate"), parent), _breaks(0) -{ - _time.start(); - new FrameBreakAnimation(this); -} - -void QSimpleCanvasDebugPlugin::addTiming(quint32 paint, - quint32 repaint, - quint32 timeBetweenFrames) -{ - if (!isEnabled()) - return; - - bool isFrameBreak = _breaks > 1; - _breaks = 0; - int e = _time.elapsed(); - QByteArray data; - QDataStream ds(&data, QIODevice::WriteOnly); - ds << (int)paint << (int)repaint << (int)timeBetweenFrames << (int)e - << (bool)isFrameBreak; - sendMessage(data); -} - -void QSimpleCanvasDebugPlugin::frameBreak() -{ - _breaks++; -} - -QSimpleCanvasSceneDebugPlugin::QSimpleCanvasSceneDebugPlugin(QSimpleCanvas *parent) -: QmlDebugServerPlugin(QLatin1String("CanvasScene"), parent), m_canvas(parent) -{ -} - -void QSimpleCanvasSceneDebugPlugin::messageReceived(const QByteArray &) -{ - refresh(); -} - -void QSimpleCanvasSceneDebugPlugin::refresh() -{ - QByteArray data; - QDataStream ds(&data, QIODevice::WriteOnly); - const QList<QSimpleCanvasItem *> &children = m_canvas->root()->children(); - ds << children.count(); - for (int ii = 0; ii < children.count(); ++ii) - refresh(ds, children.at(ii)); - - sendMessage(data); -} - -void QSimpleCanvasSceneDebugPlugin::refresh(QDataStream &ds, - QSimpleCanvasItem *item) -{ - ds << QmlDebugServerPlugin::objectToString(item) << item->x() << item->y() - << item->z() << item->width() << item->height() - << (int)item->transformOrigin() << item->scale() << (int)item->flip() -#ifdef QFX_RENDER_OPENGL - << item->transform().toTransform() -#elif defined(QFX_RENDER_QPAINTER) - << item->transform() -#endif - << item->hasActiveFocus() << (int)item->options(); - - QPixmap pix; - - if(item->options() & QSimpleCanvasItem::HasContents && - item->width() > 0 && item->height() > 0) { - - pix = QPixmap(item->width(), item->height()); - pix.fill(QColor(0,0,0,0)); - QPainter p(&pix); - item->paintContents(p); - - } - - ds << pix; - - const QList<QSimpleCanvasItem *> &children = item->children(); - ds << children.count(); - - for(int ii = 0; ii < children.count(); ++ii) - refresh(ds, children.at(ii)); -} - -QT_END_NAMESPACE - diff --git a/src/declarative/canvas/qsimplecanvasdebugplugin_p.h b/src/declarative/canvas/qsimplecanvasdebugplugin_p.h deleted file mode 100644 index 270b78c..0000000 --- a/src/declarative/canvas/qsimplecanvasdebugplugin_p.h +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSIMPLECANVASDEBUGPLUGIN_P_H -#define QSIMPLECANVASDEBUGPLUGIN_P_H - -#include "qobject.h" -#include "qtcpserver.h" -#include "qtcpsocket.h" -#include "qdatetime.h" -#include <QtDeclarative/qmldebugserver.h> - -QT_BEGIN_NAMESPACE -class QSimpleCanvasDebugPlugin : public QmlDebugServerPlugin -{ -public: - QSimpleCanvasDebugPlugin(QObject *parent = 0); - - void addTiming(quint32, quint32, quint32); - -private: - friend class FrameBreakAnimation; - void frameBreak(); - int _breaks; - QTime _time; -}; - -class QSimpleCanvas; -class QSimpleCanvasItem; -class QSimpleCanvasSceneDebugPlugin : public QmlDebugServerPlugin -{ -public: - QSimpleCanvasSceneDebugPlugin(QSimpleCanvas *parent = 0); - - virtual void messageReceived(const QByteArray &); - -private: - void refresh(); - void refresh(QDataStream &, QSimpleCanvasItem *); - QSimpleCanvas *m_canvas; -}; - - -QT_END_NAMESPACE - -#endif // QSIMPLECANVASDEBUGPLUGIN_P_H - diff --git a/src/declarative/canvas/qsimplecanvasfilter.cpp b/src/declarative/canvas/qsimplecanvasfilter.cpp deleted file mode 100644 index 5bc6b35..0000000 --- a/src/declarative/canvas/qsimplecanvasfilter.cpp +++ /dev/null @@ -1,323 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qsimplecanvasfilter.h" -#include "qsimplecanvasfilter_p.h" -#include "qsimplecanvasitem_p.h" -#include "qsimplecanvas.h" -#include "qsimplecanvas_p.h" - -#if defined(QFX_RENDER_OPENGL2) -#include <glsave.h> -#include <QtOpenGL/qglframebufferobject.h> -#endif - -QT_BEGIN_NAMESPACE - -/*! - \qmlclass Filter - \brief A Filter is a graphical filter that can be applied to items. -*/ - -QSimpleCanvasFilter::QSimpleCanvasFilter(QObject *parent) -: QObject(parent), d(new QSimpleCanvasFilterPrivate(this)) -{ -} - -QSimpleCanvasFilter::~QSimpleCanvasFilter() -{ - if (d->item) d->item->setFilter(0); - delete d; d = 0; -} - -bool QSimpleCanvasFilter::enabled() const -{ - return d->enabled; -} - -/*! - \qmlproperty bool Filter::enabled - \brief Controls whether the filter is applied. -*/ - -void QSimpleCanvasFilter::setEnabled(bool e) -{ - if (e == d->enabled) - return; - d->enabled = e; - emit enabledChanged(); - update(); -} - -QGLFramebufferObject *QSimpleCanvasFilter::renderToFBO(float scale, const QRectF &src, const QPoint &offset, Layer) -{ - // XXX - respect src -#if defined(QFX_RENDER_OPENGL2) - Q_UNUSED(src); - Q_UNUSED(offset); - - QSimpleCanvasItem *item = d->item; - QRect br = item->itemBoundingRect(); - if (br.isEmpty()) - return 0; - QGLFramebufferObject *fbo = - item->canvas()->d->acquire(int(br.width() * scale), int(br.height() * scale)); - - GLSaveViewport sv; GLSaveScissor ss; - qreal oldOpacity = item->d_func()->data()->activeOpacity; - item->d_func()->data()->activeOpacity = 1; - - fbo->bind(); - - glClearColor(0,0,0,0); - glEnable(GL_SCISSOR_TEST); - glScissor(0, 0, int(br.width() * scale), int(br.height() * scale)); - glClear(GL_COLOR_BUFFER_BIT); - glViewport(0, 0, int(br.width() * scale), int(br.height() * scale)); - - QMatrix4x4 mat; - mat.flipCoordinates(); - mat.translate(-1, -1, 0); - mat.scale(2. / (br.width()), 2. / (br.height()), 1. / (1024. * 1024.)); - - renderToScreen(mat); - - fbo->release(); - - item->d_func()->data()->activeOpacity = oldOpacity; - return fbo; -#else - Q_UNUSED(src); - Q_UNUSED(offset); - Q_UNUSED(scale); - return 0; -#endif -} - -QGLFramebufferObject *QSimpleCanvasFilter::renderToFBO(const QRectF &src, const QPoint &offset, Layer) -{ - // XXX - respect src -#if defined(QFX_RENDER_OPENGL2) - Q_UNUSED(src); - Q_UNUSED(offset); - - QSimpleCanvasItem *item = d->item; - QRect br = item->itemBoundingRect(); - if (br.isEmpty()) - return 0; - QGLFramebufferObject *fbo = - item->canvas()->d->acquire(br.width(), br.height()); - - GLSaveViewport sv; GLSaveScissor ss; - qreal oldOpacity = item->d_func()->data()->activeOpacity; - item->d_func()->data()->activeOpacity = 1; - - fbo->bind(); - - glClearColor(0,0,0,0); - glEnable(GL_SCISSOR_TEST); - glScissor(0, 0, br.width(), br.height()); - glClear(GL_COLOR_BUFFER_BIT); - glViewport(0, 0, br.width(), br.height()); - - QMatrix4x4 mat; - mat.flipCoordinates(); - mat.translate(-1, -1, 0); - mat.scale(2. / br.width(), 2. / br.height(), 1. / (1024. * 1024.)); - - renderToScreen(mat); - - fbo->release(); - - item->d_func()->data()->activeOpacity = oldOpacity; - return fbo; -#else - Q_UNUSED(src); - Q_UNUSED(offset); - return 0; -#endif -} - -QGLFramebufferObject *QSimpleCanvasFilter::acquireFBO(const QSize &s) -{ -#if defined(QFX_RENDER_OPENGL2) - QSize size; - QSimpleCanvasItem *item = d->item; - if (size.isNull()) { - QRect br = item->itemBoundingRect(); - size = br.size(); - } else { - size = s; - } - - QGLFramebufferObject *fbo = - item->canvas()->d->acquire(s.width(), s.height()); - - return fbo; -#else - Q_UNUSED(s); - return 0; -#endif -} - -void QSimpleCanvasFilter::releaseFBO(QGLFramebufferObject *fbo) -{ -#if defined(QFX_RENDER_OPENGL2) - d->item->d_func()->canvas->d->release(fbo); -#else - Q_UNUSED(fbo); -#endif -} - -void QSimpleCanvasFilter::renderToScreen(const QRectF &src, Layer layer) -{ - // XXX - respect src -#if defined(QFX_RENDER_OPENGL2) - Q_UNUSED(src); - Q_UNUSED(layer); - d->item->d_func()->paint(d->params, layer); -#else - Q_UNUSED(src); - Q_UNUSED(layer); -#endif -} - -void QSimpleCanvasFilter::renderToScreen(const QSimpleCanvas::Matrix &trans, const QRectF &src, Layer layer) -{ - // XXX - respect src -#if defined(QFX_RENDER_OPENGL2) - Q_UNUSED(src); - QSimpleCanvas::Matrix old = d->item->d_func()->data()->transformActive; - d->item->d_func()->data()->transformActive = trans; - QSimpleCanvasItemPrivate::GLPaintParameters params = d->params; - params.forceParamRefresh = true; - d->item->d_func()->paint(params, layer); - d->item->d_func()->data()->transformActive = old; -#else - Q_UNUSED(trans); - Q_UNUSED(src); - Q_UNUSED(layer); -#endif -} - -QSimpleCanvasItem *QSimpleCanvasFilter::item() const -{ - return d->item; -} - -void QSimpleCanvasFilter::setItem(QSimpleCanvasItem *i) -{ - if (d->item == i) - return; - if (d->item) { - d->item->setFilter(0); - d->item = 0; - } - - if (i->filter() != this) { - i->setFilter(this); - } else { - d->item = i; - } -} - -#if defined(QFX_RENDER_OPENGL2) -void QSimpleCanvasFilterPrivate::doFilterGL(QSimpleCanvasItem::GLPainter &p, const QSimpleCanvasItemPrivate::GLPaintParameters &prms) -{ - params = prms; - q->filterGL(p); -} -#endif - -QRectF QSimpleCanvasFilter::itemBoundingRect(const QRectF &r) const -{ - return r; -} - -void QSimpleCanvasFilter::filterGL(QSimpleCanvasItem::GLPainter &p) -{ - Q_UNUSED(p); -} - -void QSimpleCanvasFilter::filter(QPainter &) -{ -} - -void QSimpleCanvasFilter::update() -{ - if (d->item) - d->item->update(); -} - -#if defined(QFX_RENDER_OPENGL2) -bool QSimpleCanvasFilterPrivate::isSimpleItem(QSimpleCanvasItem *item, QSimpleCanvasItem **out, QSimpleCanvas::Matrix *mout) -{ - if (item->options() & QSimpleCanvasItem::SimpleItem && !item->hasChildren()) { - *out = item; - return true; - } else if (!(item->options() & QSimpleCanvasItem::HasContents) && - item->children().count() == 1) { - QSimpleCanvasItem *child = item->children().first(); - if (child->filter() && child->filter()->enabled()) - return false; - bool rv = isSimpleItem(child, out, mout); - if (rv) - *mout *= child->d_func()->localTransform(); - return rv; - } else { - return false; - } -} -#endif - -bool QSimpleCanvasFilter::isSimpleItem(QSimpleCanvasItem **out, QSimpleCanvas::Matrix *mout) -{ -#if defined(QFX_RENDER_OPENGL2) - return d->isSimpleItem(item(), out, mout); -#else - Q_UNUSED(out); - Q_UNUSED(mout); -#endif - - return false; -} - -QT_END_NAMESPACE diff --git a/src/declarative/canvas/qsimplecanvasfilter.h b/src/declarative/canvas/qsimplecanvasfilter.h deleted file mode 100644 index 14bb765..0000000 --- a/src/declarative/canvas/qsimplecanvasfilter.h +++ /dev/null @@ -1,113 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSIMPLECANVASFILTER_H -#define QSIMPLECANVASFILTER_H - -#include <QtCore/qobject.h> -#include <QtDeclarative/qfxglobal.h> -#include <QtDeclarative/qsimplecanvasitem.h> -#include <QtDeclarative/qsimplecanvas.h> - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class QSimpleCanvasFilterPrivate; -class QRectF; -class QPoint; -class QGLFramebufferObject; -class GLShaderProgram; -class Q_DECLARATIVE_EXPORT QSimpleCanvasFilter : public QObject -{ -Q_OBJECT -public: - QSimpleCanvasFilter(QObject *parent); - virtual ~QSimpleCanvasFilter(); - - enum Layer { ChildrenUnderItem = 0x01, - Item = 0x02, - ChildrenAboveItem = 0x04, - All = 0x07 }; - - Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) - bool enabled() const; - void setEnabled(bool); - - QSimpleCanvasItem *item() const; - void setItem(QSimpleCanvasItem *); -Q_SIGNALS: - void enabledChanged(); - -protected: - - virtual QRectF itemBoundingRect(const QRectF &) const; - virtual void filterGL(QSimpleCanvasItem::GLPainter &p); - virtual void filter(QPainter &p); - - QGLFramebufferObject *renderToFBO(const QRectF &src = QRect(), const QPoint &offset = QPoint(), Layer = All); - QGLFramebufferObject *renderToFBO(float scale, const QRectF &src = QRect(), const QPoint &offset = QPoint(), Layer = All); - QGLFramebufferObject *acquireFBO(const QSize & = QSize()); - void releaseFBO(QGLFramebufferObject *); - - void renderToScreen(const QRectF &src = QRect(), Layer = All); - void renderToScreen(const QSimpleCanvas::Matrix &trans, const QRectF &src = QRect(), Layer = All); - - void update(); - - bool isSimpleItem(QSimpleCanvasItem **, QSimpleCanvas::Matrix *); - -private: - friend class QSimpleCanvasFilterPrivate; - friend class QSimpleCanvasItemPrivate; - friend class QSimpleCanvasItem; - - QSimpleCanvasFilterPrivate *d; -}; - - - -QT_END_NAMESPACE - -QT_END_HEADER -#endif diff --git a/src/declarative/canvas/qsimplecanvasfilter_p.h b/src/declarative/canvas/qsimplecanvasfilter_p.h deleted file mode 100644 index 1c72993..0000000 --- a/src/declarative/canvas/qsimplecanvasfilter_p.h +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSIMPLECANVASFILTER_P_H -#define QSIMPLECANVASFILTER_P_H - -#include "qsimplecanvasitem.h" -#include "qsimplecanvasitem_p.h" - - -QT_BEGIN_NAMESPACE -class QSimpleCanvasFilterPrivate -{ -public: - QSimpleCanvasFilterPrivate(QSimpleCanvasFilter *_q) - : q(_q), item(0), enabled(true) {} - - QSimpleCanvasFilter *q; - - QSimpleCanvasItem *item; - bool enabled; -#if defined(QFX_RENDER_OPENGL) - QSimpleCanvasItemPrivate::GLPaintParameters params; - - void doFilterGL(QSimpleCanvasItem::GLPainter &, const QSimpleCanvasItemPrivate::GLPaintParameters &); - - bool isSimpleItem(QSimpleCanvasItem *item, QSimpleCanvasItem **out, QSimpleCanvas::Matrix *mout); -#endif -}; - -QT_END_NAMESPACE -#endif diff --git a/src/declarative/canvas/qsimplecanvasitem.cpp b/src/declarative/canvas/qsimplecanvasitem.cpp deleted file mode 100644 index 0ceb7b7..0000000 --- a/src/declarative/canvas/qsimplecanvasitem.cpp +++ /dev/null @@ -1,1885 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qsimplecanvasitem.h" -#include "qsimplecanvas.h" -#include "qsimplecanvasitem_p.h" -#include "qsimplecanvas_p.h" -#include <qfxitem.h> -#include <QGraphicsSceneEvent> - - -QT_BEGIN_NAMESPACE -QSimpleCanvasItemData::QSimpleCanvasItemData() -: buttons(Qt::NoButton), flip(QSimpleCanvasItem::NoFlip), - dirty(false), transformValid(true), doNotPaint(false), - doNotPaintChildren(false), x(0), y(0), z(0), - visible(1), transformUser(0), transformVersion(0), activeOpacity(1) -{ -} - -QSimpleCanvasItemData::~QSimpleCanvasItemData() -{ - if (transformUser) - delete transformUser; -} - -/*! - \internal - \class QSimpleCanvasItem - \brief The QSimpleCanvasItem class is the base class of canvas items. - */ -QSimpleCanvasLayer::QSimpleCanvasLayer() -{ -} - -QSimpleCanvasLayer::QSimpleCanvasLayer(QSimpleCanvasItem *parent) -: QSimpleCanvasItem(parent) -{ -} - -void QSimpleCanvasLayer::addChild(QSimpleCanvasItem *c) -{ - QSimpleCanvasItem::addChild(c); -} - -void QSimpleCanvasLayer::addDirty(QSimpleCanvasItem *) -{ -} - -void QSimpleCanvasLayer::remDirty(QSimpleCanvasItem *) -{ -} - -QSimpleCanvasLayer *QSimpleCanvasLayer::layer() -{ - return this; -} - -QSimpleCanvasItem::Options QSimpleCanvasItem::options() const -{ - Q_D(const QSimpleCanvasItem); - return (QSimpleCanvasItem::Options)d->options; -} - -bool QSimpleCanvasItem::mouseFilter(QGraphicsSceneMouseEvent *) -{ - return false; -} - -void QSimpleCanvasItem::mousePressEvent(QGraphicsSceneMouseEvent *e) -{ - e->ignore(); -} - -void QSimpleCanvasItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) -{ - e->ignore(); -} - -void QSimpleCanvasItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e) -{ - e->ignore(); -} - -void QSimpleCanvasItem::mouseMoveEvent(QGraphicsSceneMouseEvent *e) -{ - e->ignore(); -} - -void QSimpleCanvasItem::hoverEnterEvent(QGraphicsSceneHoverEvent *e) -{ - e->ignore(); -} - -void QSimpleCanvasItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *e) -{ - e->ignore(); -} - -void QSimpleCanvasItem::mouseUngrabEvent() -{ -} - -void QSimpleCanvasItem::keyPressEvent(QKeyEvent *e) -{ - e->ignore(); -} - -void QSimpleCanvasItem::keyReleaseEvent(QKeyEvent *e) -{ - e->ignore(); -} - -void QSimpleCanvasItem::focusOutEvent(QFocusEvent *e) -{ - e->ignore(); -} - -void QSimpleCanvasItem::focusInEvent(QFocusEvent *e) -{ - e->ignore(); -} - -void QSimpleCanvasItem::activePanelInEvent() -{ -} - -void QSimpleCanvasItem::activePanelOutEvent() -{ -} - -void QSimpleCanvasItem::inputMethodEvent(QInputMethodEvent *e) -{ - e->ignore(); -} - -QVariant QSimpleCanvasItem::inputMethodQuery(Qt::InputMethodQuery) const -{ - return QVariant(); -} - -void QSimpleCanvasItem::childrenChanged() -{ -} - -void QSimpleCanvasItem::setPaintMargin(qreal margin) -{ - Q_D(QSimpleCanvasItem); - if (margin < d->paintmargin) - update(); // schedule repaint of old boundingRect - d->paintmargin = margin; -} - -QRectF QSimpleCanvasItem::boundingRect() const -{ - Q_D(const QSimpleCanvasItem); - return QRectF(-d->paintmargin, -d->paintmargin, d->width+d->paintmargin*2, d->height+d->paintmargin*2); -} - -void QSimpleCanvasItem::paintContents(QPainter &) -{ -} - -void QSimpleCanvasItem::paintGLContents(GLPainter &) -{ -} - -uint QSimpleCanvasItem::glSimpleItemData(float *vertices, float *texVertices, - GLTexture **texture, uint count) -{ - Q_UNUSED(vertices); - Q_UNUSED(texVertices); - Q_UNUSED(texture); - Q_UNUSED(count); - return 0; -} - -void QSimpleCanvasItem::canvasChanged() -{ -} - -void QSimpleCanvasItem::focusChanged(bool) -{ -} - -void QSimpleCanvasItem::activeFocusChanged(bool) -{ -} - -void QSimpleCanvasItem::parentChanged(QSimpleCanvasItem *, QSimpleCanvasItem *) -{ -} - -GLBasicShaders *QSimpleCanvasItem::basicShaders() const -{ -#if defined(QFX_RENDER_OPENGL2) - return canvas()->d->basicShaders(); -#else - return 0; -#endif -} - -/*! - Returns the item's (0, 0) point relative to its parent. - */ -QPointF QSimpleCanvasItem::pos() const -{ - return QPointF(x(),y()); -} - -/*! - Returns the item's (0, 0) point mapped to scene coordinates. - */ -QPointF QSimpleCanvasItem::scenePos() const -{ - return mapToScene(QPointF(0, 0)); -} - -/*! - \enum QSimpleCanvasItem::TransformOrigin - - Controls the point about which simple transforms like scale apply. - - \value TopLeft The top-left corner of the item. - \value TopCenter The center point of the top of the item. - \value TopRight The top-right corner of the item. - \value MiddleLeft The left most point of the vertical middle. - \value Center The center of the item. - \value MiddleRight The right most point of the vertical middle. - \value BottomLeft The bottom-left corner of the item. - \value BottomCenter The center point of the bottom of the item. - \value BottomRight The bottom-right corner of the item. -*/ - -/*! - Returns the current transform origin. -*/ -QSimpleCanvasItem::TransformOrigin QSimpleCanvasItem::transformOrigin() const -{ - Q_D(const QSimpleCanvasItem); - return d->origin; -} - -/*! - Set the transform \a origin. -*/ -void QSimpleCanvasItem::setTransformOrigin(TransformOrigin origin) -{ - Q_D(QSimpleCanvasItem); - if (origin != d->origin) { - d->origin = origin; - update(); - } -} - -QPointF QSimpleCanvasItem::transformOriginPoint() const -{ - Q_D(const QSimpleCanvasItem); - return d->transformOrigin(); -} - -/*! - Returns the canvas the item is on, or 0 if the item is not on a canvas. - */ -QSimpleCanvas *QSimpleCanvasItem::canvas() const -{ - Q_D(const QSimpleCanvasItem); - return d->canvas; -} - -/*! - Returns the parent if the item, or 0 if the item has no parent. - */ -QSimpleCanvasItem *QSimpleCanvasItem::parent() const -{ - Q_D(const QSimpleCanvasItem); - return d->parent; -} - -void QSimpleCanvasItemPrivate::zOrderChildren() -{ - if (!needsZOrder || children.count() <= 1) - return; - - needsZOrder = false; - // This is a bubble sort for a reason - it is the fastest sort for a mostly - // ordered list. We only expect z ordering to change infrequently. - bool swap = true; - int c = 0; - while(swap) { - ++c; - swap = false; - QSimpleCanvasItem *item = children.first(); - qreal z = item->z(); - for (int ii = 1; ii < children.count(); ++ii) { - QSimpleCanvasItem *i2 = children.at(ii); - qreal z2 = i2->z(); - if (z2 < z) { - swap = true; - children[ii] = item; - children[ii - 1] = i2; - } else { - item = i2; - z = z2; - } - } - } -} - -void QSimpleCanvasItemPrivate::canvasChanged(QSimpleCanvas *newCanvas, QSimpleCanvas *oldCanvas) -{ - Q_Q(QSimpleCanvasItem); - canvas = newCanvas; - if (options & QSimpleCanvasItem::MouseFilter) { - if (oldCanvas) oldCanvas->d->removeMouseFilter(q); - if (newCanvas) newCanvas->d->installMouseFilter(q); - } - if (newCanvas) { - if (!oldCanvas && hasFocus) - newCanvas->d->setFocusItem(q, Qt::OtherFocusReason, false); - if (wantsActiveFocusPanelPendingCanvas) { - hasBeenActiveFocusPanel = true; - newCanvas->d->setActiveFocusPanel(q); - wantsActiveFocusPanelPendingCanvas = false; - } - } - - for (int ii = 0; ii < children.count(); ++ii) - children.at(ii)->d_func()->canvasChanged(newCanvas, oldCanvas); - q->canvasChanged(); -} - -void QSimpleCanvasItem::setFocus(bool focus) -{ - Q_D(QSimpleCanvasItem); - if (d->hasFocus == focus) - return; - QSimpleCanvas *c = canvas(); - - if (c) { - if (focus) - c->d->setFocusItem(this, Qt::OtherFocusReason); - else - c->d->clearFocusItem(this); - } else { - d->setFocus(focus); - focusChanged(d->hasFocus); - } -} - -qreal QSimpleCanvasItem::x() const -{ - Q_D(const QSimpleCanvasItem); - if (d->graphicsItem) - return d->graphicsItem->x(); - else if (d->data_ptr) - return d->data()->x; - else - return 0; -} - -qreal QSimpleCanvasItem::y() const -{ - Q_D(const QSimpleCanvasItem); - if (d->graphicsItem) - return d->graphicsItem->y(); - else if (d->data_ptr) - return d->data()->y; - else - return 0; -} - -qreal QSimpleCanvasItem::z() const -{ - Q_D(const QSimpleCanvasItem); - if (d->graphicsItem) - return d->graphicsItem->zValue(); - else if (d->data_ptr) - return d->data()->z; - else - return 0; -} - -void QSimpleCanvasItem::setX(qreal x) -{ - Q_D(QSimpleCanvasItem); - if (x == this->x()) - return; - - qreal oldX = this->x(); - - if (d->graphicsItem) { - d->graphicsItem->setPos(x, y()); - } else { - d->data()->x = x; - update(); - } - - geometryChanged(QRectF(this->x(), y(), width(), height()), - QRectF(oldX, y(), width(), height())); -} - -void QSimpleCanvasItem::setY(qreal y) -{ - Q_D(QSimpleCanvasItem); - if (y == this->y()) - return; - - qreal oldY = this->y(); - - if (d->graphicsItem) { - d->graphicsItem->setPos(x(), y); - } else { - d->data()->y = y; - update(); - } - - geometryChanged(QRectF(x(), this->y(), width(), height()), - QRectF(x(), oldY, width(), height())); -} - -void QSimpleCanvasItem::setZ(qreal z) -{ - Q_D(QSimpleCanvasItem); - if (z == this->z()) - return; - - if (d->graphicsItem) { - - if (z < 0) - d->graphicsItem->setFlag(QGraphicsItem::ItemStacksBehindParent, - true); - else - d->graphicsItem->setFlag(QGraphicsItem::ItemStacksBehindParent, - false); - - d->graphicsItem->setZValue(z); - - } else { - if (d->data()->z == z) - return; - - d->data()->z = z; - if (parent()) - static_cast<QSimpleCanvasItemPrivate*>(parent()->d_ptr)->needsZOrder = true; - update(); - } -} - -qreal QSimpleCanvasItem::width() const -{ - Q_D(const QSimpleCanvasItem); - return d->width; -} - -void QSimpleCanvasItem::setWidth(qreal w) -{ - Q_D(QSimpleCanvasItem); - d->widthValid = true; - if (d->width == w) - return; - - qreal oldWidth = d->width; - - d->width = w; - update(); - - geometryChanged(QRectF(x(), y(), width(), height()), - QRectF(x(), y(), oldWidth, height())); -} - -void QSimpleCanvasItem::setImplicitWidth(qreal w) -{ - Q_D(QSimpleCanvasItem); - if (d->width == w || widthValid()) - return; - - qreal oldWidth = d->width; - - d->width = w; - update(); - - geometryChanged(QRectF(x(), y(), width(), height()), - QRectF(x(), y(), oldWidth, height())); -} - -bool QSimpleCanvasItem::widthValid() const -{ - Q_D(const QSimpleCanvasItem); - return d->widthValid; -} - -qreal QSimpleCanvasItem::height() const -{ - Q_D(const QSimpleCanvasItem); - return d->height; -} - -void QSimpleCanvasItem::setHeight(qreal h) -{ - Q_D(QSimpleCanvasItem); - d->heightValid = true; - if (d->height == h) - return; - - qreal oldHeight = d->height; - - d->height = h; - update(); - - geometryChanged(QRectF(x(), y(), width(), height()), - QRectF(x(), y(), width(), oldHeight)); -} - -void QSimpleCanvasItem::setImplicitHeight(qreal h) -{ - Q_D(QSimpleCanvasItem); - if (d->height == h || heightValid()) - return; - - qreal oldHeight = d->height; - - d->height = h; - update(); - - geometryChanged(QRectF(x(), y(), width(), height()), - QRectF(x(), y(), width(), oldHeight)); -} - -bool QSimpleCanvasItem::heightValid() const -{ - Q_D(const QSimpleCanvasItem); - return d->heightValid; -} - -void QSimpleCanvasItem::setPos(const QPointF &point) -{ - Q_D(QSimpleCanvasItem); - qreal oldX = x(); - qreal oldY = y(); - - if (d->graphicsItem) { - d->graphicsItem->setPos(point); - } else { - d->data()->x = point.x(); - d->data()->y = point.y(); - update(); - } - - geometryChanged(QRectF(x(), y(), width(), height()), - QRectF(oldX, oldY, width(), height())); -} - -qreal QSimpleCanvasItem::scale() const -{ - Q_D(const QSimpleCanvasItem); - return d->scale; -} - -void QSimpleCanvasItem::setScale(qreal s) -{ - Q_D(QSimpleCanvasItem); - d->scale = s; - if (d->graphicsItem) { - QTransform t; - QPointF to = transformOriginPoint(); - if (to.x() != 0. || to.y() != 0.) - t.translate(to.x(), to.y()); - t.scale(s, s); - if (to.x() != 0. || to.y() != 0.) - t.translate(-to.x(), -to.y()); - d->graphicsItem->setTransform(t * d->graphicsItem->transform); - } else { - update(); - } -} - -bool QSimpleCanvasItem::isVisible() const -{ - if (visible() <= 0) - return false; - else if (!parent()) - return true; - else - return parent()->isVisible(); -} - -qreal QSimpleCanvasItem::visible() const -{ - Q_D(const QSimpleCanvasItem); - if (d->graphicsItem) - return d->graphicsItem->opacity(); - else if (d->data_ptr) - return d->data()->visible; - else - return 1; -} - -void QSimpleCanvasItem::setVisible(qreal v) -{ - Q_D(QSimpleCanvasItem); - if (d->graphicsItem) { - d->graphicsItem->setOpacity(v); - } else { - if (v == visible()) - return; - if (v == 0) - update(); - - d->data()->visible = v; - - if (v != 0) - update(); - } -} - -void QSimpleCanvasItem::addChild(QSimpleCanvasItem *c) -{ - Q_D(QSimpleCanvasItem); - d->children.append(c); - if (!d->graphicsItem) - d->needsZOrder = true; - childrenChanged(); -} - -void QSimpleCanvasItem::remChild(QSimpleCanvasItem *c) -{ - Q_D(QSimpleCanvasItem); - d->children.removeAll(c); - childrenChanged(); -} - -QSimpleCanvasFilter *QSimpleCanvasItem::filter() const -{ - Q_D(const QSimpleCanvasItem); - return d->filter; -} - -/*! -QSimpleCanvasItem takes ownership of filter. -*/ -void QSimpleCanvasItem::setFilter(QSimpleCanvasFilter *f) -{ - Q_D(QSimpleCanvasItem); - if (!d || f == d->filter) - return; - - d->filter = f; - if (d->filter) - d->filter->setItem(this); - update(); -} - -const QList<QSimpleCanvasItem *> &QSimpleCanvasItem::children() const -{ - Q_D(const QSimpleCanvasItem); - return d->children; -} - -bool QSimpleCanvasItem::hasChildren() const -{ - Q_D(const QSimpleCanvasItem); - return !d->children.isEmpty(); -} - -QSimpleCanvasLayer *QSimpleCanvasItem::layer() -{ - if (parent()) - return parent()->layer(); - else - return 0; -} - -void QSimpleCanvasItem::update() -{ - Q_D(QSimpleCanvasItem); - if (d->graphicsItem) { - d->graphicsItem->update(); - } else { - if (!parent()) - return; - - if (d->data()->dirty || 0. == d->data()->visible) return; - - QSimpleCanvasLayer *l = layer(); - if (l == this && parent()) - l = parent()->layer(); - if (l) { - l->addDirty(this); - d->data()->dirty = true; - d->data()->transformValid = false; - } - } -} - -bool QSimpleCanvasItem::clip() const -{ - Q_D(const QSimpleCanvasItem); - return d->clip; -} - -void QSimpleCanvasItem::setClip(bool c) -{ - Q_D(const QSimpleCanvasItem); - if (bool(d->clip) == c) - return; - - if (c) - setClipType(ClipToRect); - else - setClipType(NoClip); - - update(); -} - -QSimpleCanvasItem::ClipType QSimpleCanvasItem::clipType() const -{ - Q_D(const QSimpleCanvasItem); - return d->clip; -} - -void QSimpleCanvasItem::setClipType(ClipType c) -{ - Q_D(QSimpleCanvasItem); - d->clip = c; - if (d->graphicsItem) - d->graphicsItem->setFlag(QGraphicsItem::ItemClipsChildrenToShape, bool(c)); - else - update(); -} - -Qt::MouseButtons QSimpleCanvasItem::acceptedMouseButtons() const -{ - Q_D(const QSimpleCanvasItem); - if (d->graphicsItem) - return d->graphicsItem->acceptedMouseButtons(); - else if (d->data_ptr) - return (Qt::MouseButtons)d->data()->buttons; - else - return Qt::NoButton; -} - -void QSimpleCanvasItem::setAcceptedMouseButtons(Qt::MouseButtons buttons) -{ - Q_D(QSimpleCanvasItem); - if (d->graphicsItem) - d->graphicsItem->setAcceptedMouseButtons(buttons); - else - d->data()->buttons = buttons; -} - - -QRect QSimpleCanvasItem::itemBoundingRect() -{ - return boundingRect().toAlignedRect(); -} - -QPointF QSimpleCanvasItemPrivate::adjustFrom(const QPointF &p) const -{ -#if defined(QFX_RENDER_OPENGL) - if (!canvas) - return p; - - QPointF rv(-1. + 2. * p.x() / qreal(canvas->width()), - 1 - 2. * p.y() / qreal(canvas->height())); - - return rv; -#else - return p; -#endif -} - -QRectF QSimpleCanvasItemPrivate::adjustFrom(const QRectF &r) const -{ -#if defined(QFX_RENDER_OPENGL) - if (!canvas) - return r; - - qreal width = r.width() * 2. / qreal(canvas->width()); - qreal height = r.height() * 2. / qreal(canvas->height()); - qreal x = -1. + 2. * r.x() / qreal(canvas->width()); - qreal y = 1. - 2. * r.y() / qreal(canvas->height()) - height; - - return QRectF(x, y, width, height); -#else - return r; -#endif -} - -QPointF QSimpleCanvasItemPrivate::adjustTo(const QPointF &p) const -{ -#if defined(QFX_RENDER_OPENGL) - if (!canvas) - return p; - - QPointF rv(0.5 * (p.x() + 1.) * qreal(canvas->width()), - 0.5 * (1. - p.y()) * qreal(canvas->height())); - - return rv; -#else - return p; -#endif -} - -QRectF QSimpleCanvasItemPrivate::adjustTo(const QRectF &r) const -{ -#if defined(QFX_RENDER_OPENGL) - if (!canvas) - return r; - - qreal width = 0.5 * r.width() * qreal(canvas->width()); - qreal height = 0.5 * r.height() * qreal(canvas->height()); - qreal x = 0.5 * (r.x() + 1.) * qreal(canvas->width()); - qreal y = 0.5 * (1. - r.y()) * qreal(canvas->height()) - height; - - return QRectF(x, y, width, height); -#else - return r; -#endif -} - -QPointF QSimpleCanvasItem::mapFromScene(const QPointF &p) const -{ - Q_D(const QSimpleCanvasItem); - if (d->graphicsItem) { - return d->graphicsItem->mapFromScene(p); - } else { - QPointF mp = d->adjustFrom(p); - d->freshenTransforms(); -#if defined(QFX_RENDER_OPENGL) - // m20X + m21Y + m22Z + m23 = 1 - // Z = (1 - m23 - m20X - m21Y) / m22 - - QMatrix4x4 inv = d->data()->transformActive.inverted(); - qreal z_s = (1 - inv(2,3) - inv(2,0) * mp.x() - inv(2, 1) * mp.y()) / inv(2, 2); - - QVector3D vec(mp.x(), mp.y(), z_s); - QVector3D r = inv.map(vec); - - return r.toPointF(); -#else - return d->data()->transformActive.inverted().map(mp); -#endif - } -} - -QRectF QSimpleCanvasItem::mapFromScene(const QRectF &r) const -{ - Q_D(const QSimpleCanvasItem); - if (d->graphicsItem) { - return d->graphicsItem->mapFromScene(r).boundingRect(); - } else { - QRectF mr = d->adjustFrom(r); - d->freshenTransforms(); -#if defined(QFX_RENDER_OPENGL) - // m20X + m21Y + m22Z + m23 = 1 - // Z = (1 - m23 - m20X - m21Y) / m22 - - QMatrix4x4 inv = d->data()->transformActive.inverted(); - qreal tl_z_s = (1 - inv(2,3) - inv(2,0) * mr.topLeft().x() - inv(2, 1) * mr.topLeft().y()) / inv(2, 2); - qreal tr_z_s = (1 - inv(2,3) - inv(2,0) * mr.topRight().x() - inv(2, 1) * mr.topRight().y()) / inv(2, 2); - qreal bl_z_s = (1 - inv(2,3) - inv(2,0) * mr.bottomLeft().x() - inv(2, 1) * mr.bottomLeft().y()) / inv(2, 2); - qreal br_z_s = (1 - inv(2,3) - inv(2,0) * mr.bottomRight().x() - inv(2, 1) * mr.bottomRight().y()) / inv(2, 2); - - QVector3D tl(mr.topLeft().x(), mr.topLeft().y(), tl_z_s); - QVector3D tr(mr.topRight().x(), mr.topRight().y(), tr_z_s); - QVector3D bl(mr.bottomLeft().x(), mr.bottomLeft().y(), bl_z_s); - QVector3D br(mr.bottomRight().x(), mr.bottomRight().y(), br_z_s); - - tl = inv.map(tl); tr = inv.map(tr); bl = inv.map(bl); br = inv.map(br); - - qreal xmin = qMin(qMin(tl.x(), tr.x()), qMin(bl.x(), br.x())); - qreal xmax = qMax(qMax(tl.x(), tr.x()), qMax(bl.x(), br.x())); - qreal ymin = qMin(qMin(tl.y(), tr.y()), qMin(bl.y(), br.y())); - qreal ymax = qMax(qMax(tl.y(), tr.y()), qMax(bl.y(), br.y())); - - return QRectF(QPointF(xmin, ymin), QPointF(xmax, ymax)); -#else - return d->data()->transformActive.inverted().mapRect(mr); -#endif - } -} - -QPointF QSimpleCanvasItem::mapToScene(const QPointF &p) const -{ - Q_D(const QSimpleCanvasItem); - if (d->graphicsItem) { - return d->graphicsItem->mapToScene(p); - } else { - d->freshenTransforms(); - QPointF rp = d->data()->transformActive.map(p); - return d->adjustTo(rp); - } -} - -QRectF QSimpleCanvasItem::mapToScene(const QRectF &r) const -{ - Q_D(const QSimpleCanvasItem); - if (d->graphicsItem) { - return d->graphicsItem->mapToScene(r).boundingRect(); - } else { - d->freshenTransforms(); - QRectF rr = d->data()->transformActive.mapRect(r); - return d->adjustTo(rr); - } -} - -void QSimpleCanvasItemPrivate::freshenTransforms() const -{ - if (freshenNeeded()) - doFreshenTransforms(); -} - -bool QSimpleCanvasItemPrivate::freshenNeeded() const -{ -#if 0 - return parent && - (data()->transformVersion == -1 || - data()->parentTransformVersion == -1 || - parent->d_func()->data()->transformVersion != data()->parentTransformVersion); -#else - const QSimpleCanvasItemPrivate *me = this; - while(me) { - if (me->data_ptr && !me->data_ptr->transformValid) - return true; - if (me->parent) - me = me->parent->d_func(); - else - me = 0; - } - return false; -#endif -} - -void QSimpleCanvasItemPrivate::doFreshenTransforms() const -{ - Q_Q(const QSimpleCanvasItem); - if (parent) - parent->d_func()->doFreshenTransforms(); - - if (freshenNeeded()) { - if (parent) - data()->transformActive = parent->d_func()->data()->transformActive; - else - data()->transformActive = QSimpleCanvas::Matrix(); - data()->transformActive.translate(q->x(), q->y()); - if (scale != 1.) { - QPointF to = transformOrigin(); - if (to.x() != 0. || to.y() != 0.) - data()->transformActive.translate(to.x(), to.y()); - data()->transformActive.scale(scale, scale); - if (to.x() != 0. || to.y() != 0.) - data()->transformActive.translate(-to.x(), -to.y()); - } - - Q_Q(const QSimpleCanvasItem); -#if defined(QFX_RENDER_OPENGL) - if (q->d_func()->data()->transformUser) - data()->transformActive *= *q->d_func()->data()->transformUser; -#endif - - if (data()->flip) { - QRectF br = q->boundingRect(); - data()->transformActive.translate(br.width() / 2., br.height() / 2); -#if defined(QFX_RENDER_OPENGL) - data()->transformActive.rotate(180, (data()->flip & QSimpleCanvasItem::VerticalFlip)?1:0, (data()->flip & QSimpleCanvasItem::HorizontalFlip)?1:0, 0); -#else - data()->transformActive.scale((data()->flip & QSimpleCanvasItem::HorizontalFlip)?-1:1, - (data()->flip & QSimpleCanvasItem::VerticalFlip)?-1:1); -#endif - data()->transformActive.translate(-br.width() / 2., -br.height() / 2); - } - } -} - -QSimpleCanvas::Matrix QSimpleCanvasItem::transform() const -{ - Q_D(const QSimpleCanvasItem); - if (d->graphicsItem) - return QSimpleCanvasConfig::transformToMatrix(d->graphicsItem->transform); - else if (d->data()->transformUser) - return *d->data()->transformUser; - else - return QSimpleCanvas::Matrix(); -} - -void QSimpleCanvasItem::setTransform(const QSimpleCanvas::Matrix &m) -{ - Q_D(QSimpleCanvasItem); - if (d->graphicsItem) { - d->graphicsItem->transform = QSimpleCanvasConfig::matrixToTransform(m); - QTransform t; - if (d->scale != 1) { - QPointF to = transformOriginPoint(); - if (to.x() != 0. || to.y() != 0.) - t.translate(to.x(), to.y()); - t.scale(d->scale, d->scale); - if (to.x() != 0. || to.y() != 0.) - t.translate(-to.x(), -to.y()); - } - d->graphicsItem->setTransform(t * d->graphicsItem->transform); - } else { - if (!d->data()->transformUser) - d->data()->transformUser = new QSimpleCanvas::Matrix; - *d->data()->transformUser = m; - update(); - } -} - -QSimpleCanvasItem *QSimpleCanvasItem::mouseGrabberItem() const -{ - Q_D(const QSimpleCanvasItem); - if (d->graphicsItem) { - QGraphicsScene *s = d->graphicsItem->scene(); - if (s) { - QGraphicsItem *item = s->mouseGrabberItem(); - QSimpleGraphicsItem *dgi = static_cast<QSimpleGraphicsItem *>(item); - return dgi?static_cast<QSimpleCanvasItem*>(dgi->owner):0; - } - } else { - QSimpleCanvas *c = canvas(); - if (c) - return c->d->lastMouseItem; - } - return 0; -} - -void QSimpleCanvasItem::ungrabMouse() -{ - Q_D(QSimpleCanvasItem); - if (d->graphicsItem) { - d->graphicsItem->ungrabMouse(); - } else { - QSimpleCanvas *c = canvas(); - if (c && c->d->lastMouseItem == this) { - c->d->lastMouseItem->mouseUngrabEvent(); - c->d->lastMouseItem = 0; - } - } -} - -void QSimpleCanvasItem::grabMouse() -{ - Q_D(QSimpleCanvasItem); - if (d->graphicsItem) { - d->graphicsItem->grabMouse(); - } else { - QSimpleCanvas *c = canvas(); - if (c) { - if (c->d->lastMouseItem != this) { - if (c->d->lastMouseItem) - c->d->lastMouseItem->mouseUngrabEvent(); - c->d->lastMouseItem = this; - } - } - } -} - -bool QSimpleCanvasItem::isFocusable() const -{ - Q_D(const QSimpleCanvasItem); - return d->focusable; -} - -void QSimpleCanvasItem::setFocusable(bool f) -{ - Q_D(QSimpleCanvasItem); - d->focusable = f; -} - -bool QSimpleCanvasItem::hasFocus() const -{ - Q_D(const QSimpleCanvasItem); - return d->hasFocus; -} - -void QSimpleCanvasItemPrivate::setFocus(bool f) -{ - hasFocus = f; -} - -void QSimpleCanvasItemPrivate::setActiveFocus(bool f) -{ - hasActiveFocus = f; - - if (graphicsItem) { - if (f) { - if (!(graphicsItem->flags() & QGraphicsItem::ItemIsFocusable)) - graphicsItem->setFlag(QGraphicsItem::ItemIsFocusable); - graphicsItem->setFocus(); - } else { - graphicsItem->clearFocus(); - if ((graphicsItem->flags() & QGraphicsItem::ItemIsFocusable) && !focusable) - graphicsItem->setFlag(QGraphicsItem::ItemIsFocusable, false); - } - - } -} - -QSimpleCanvasItem::Flip QSimpleCanvasItem::flip() const -{ - Q_D(const QSimpleCanvasItem); - if (d->graphicsItem) - return NoFlip; - else if (d->data_ptr) - return d->data()->flip; - else - return NoFlip; -} - -void QSimpleCanvasItem::setFlip(Flip f) -{ - Q_D(QSimpleCanvasItem); - if (d->graphicsItem) - return; - - if (d->data()->flip == f) - return; - - d->data()->flip = f; - update(); -} - -/*! - Places the item under \a item in the parent item's stack. - - The item itself and \a item must be siblings, or this method has no effect. - - \sa stackOver(), stackAt() - */ -void QSimpleCanvasItem::stackUnder(QSimpleCanvasItem *item) -{ - Q_D(QSimpleCanvasItem); - if (d->graphicsItem) - return; // XXX - - QSimpleCanvasItem *p = parent(); - if (!p || !item || item == this) return; - - QSimpleCanvasItemPrivate *parent_d_ptr = static_cast<QSimpleCanvasItemPrivate*>(p->d_ptr); - int idx = parent_d_ptr->children.indexOf(item); - if (idx == -1) return; - - parent_d_ptr->children.removeAll(this); - idx = parent_d_ptr->children.indexOf(item); - parent_d_ptr->children.insert(idx + 1, this); - parent_d_ptr->needsZOrder = true; - - p->childrenChanged(); -} - -/*! - Places the item over \a item in the parent item's stack. - - The item itself and \a item must be siblings, or this method has no effect. - - \sa stackUnder(), stackAt() - */ -void QSimpleCanvasItem::stackOver(QSimpleCanvasItem *item) -{ - Q_D(QSimpleCanvasItem); - if (d->graphicsItem) - return; // XXX - - QSimpleCanvasItem *p = parent(); - if (!p || !item || item == this) return; - - QSimpleCanvasItemPrivate *parent_d_ptr = static_cast<QSimpleCanvasItemPrivate*>(p->d_ptr); - int idx = parent_d_ptr->children.indexOf(item); - if (idx == -1) return; - - parent_d_ptr->children.removeAll(this); - idx = parent_d_ptr->children.indexOf(item); - parent_d_ptr->children.insert(idx, this); - parent_d_ptr->needsZOrder = true; - - p->childrenChanged(); -} - -/*! - Places the item at position \a index in the parent item's stack. - - If index is zero or less, the item is placed at the beginning of the - stack. If the index is greater than the number of items in the stack, the - item is placed at the end. - - \sa stackOver(), stackUnder() - */ -void QSimpleCanvasItem::stackAt(int index) -{ - Q_D(QSimpleCanvasItem); - if (d->graphicsItem) - return; // XXX - - QSimpleCanvasItem *p = parent(); - if (!p) return; - - QSimpleCanvasItemPrivate *parent_d_ptr = static_cast<QSimpleCanvasItemPrivate*>(p->d_ptr); - parent_d_ptr->children.removeAll(this); - - if (index < 0) index = 0; - if (index > parent_d_ptr->children.size()) index = parent_d_ptr->children.size(); - - parent_d_ptr->children.insert(index, this); - parent_d_ptr->needsZOrder = true; - p->childrenChanged(); -} - -/*! - Returns the current stacking index for the child \a item. - - If \a item is not a child, -1 is returned. - - \sa stackAt() - */ -int QSimpleCanvasItem::indexForChild(QSimpleCanvasItem *item) -{ - Q_D(QSimpleCanvasItem); - return d->children.indexOf(item); -} - -bool QSimpleCanvasItem::eventFilter(QObject *o, QEvent *e) -{ - Q_D(QSimpleCanvasItem); - if (d->graphicsItem) { - switch(e->type()) { - case QEvent::GraphicsSceneMouseDoubleClick: - case QEvent::GraphicsSceneMouseMove: - case QEvent::GraphicsSceneMousePress: - case QEvent::GraphicsSceneMouseRelease: - if (mouseFilter(static_cast<QGraphicsSceneMouseEvent *>(e))) - return true; - break; - default: - break; - } - } - - return QObject::eventFilter(o, e); -} - -void QSimpleCanvasItem::setOptions(Options options, bool set) -{ - Q_D(QSimpleCanvasItem); - Options old = (Options)d->options; - - if (options & IsFocusPanel) { - if (!set) { - qWarning("QSimpleCanvasItem::setOptions: Cannot unset IsFocusPanel"); - return; - } else if (hasChildren()) { - qWarning("QSimpleCanvasItem::setOptions: Cannot set IsFocusPanel once item has children"); - return; - } - } - - if (options & IsFocusRealm) { - if (!set) { - qWarning("QSimpleCanvasItem::setOptions: Cannot unset IsFocusRealm"); - return; - } - } - - if (set) - d->options |= options; - else - d->options &= ~options; - - if ((d->options & IsFocusPanel) && (d->options & IsFocusRealm)) { - qWarning("QSimpleCanvasItem::setOptions: Cannot set both IsFocusPanel and IsFocusRealm. IsFocusRealm will be unset."); - d->options &= ~IsFocusRealm; - } - - if (d->graphicsItem) - d->graphicsItem->setFlag(QGraphicsItem::ItemHasNoContents, !(d->options & HasContents)); - - if ((old & MouseFilter) != (d->options & MouseFilter)) { - if (d->graphicsItem) { - if (d->options & MouseFilter) - d->gvAddMouseFilter(); - else - d->gvRemoveMouseFilter(); - - } else { - QSimpleCanvas *c = canvas(); - if (c) { - if (d->options & MouseFilter) - c->d->installMouseFilter(this); - else - c->d->removeMouseFilter(this); - } - } - } -} - -QSimpleCanvasItem::QSimpleCanvasItem(QSimpleCanvasItemPrivate &dd, QSimpleCanvasItem *parent) -: QObject(dd, parent) -{ -} - -QSimpleCanvasItem::QSimpleCanvasItem(QSimpleCanvasItem *p) -: QObject(*(new QSimpleCanvasItemPrivate), p) -{ -} - -QSimpleCanvasItem::~QSimpleCanvasItem() -{ - Q_D(QSimpleCanvasItem); - if (d->graphicsItem) { - if ((d->options & (IsFocusPanel|IsFocusRealm)) && d->canvas) - d->canvas->d->focusPanelData.remove(this); - if (d->hasFocus && d->canvas) { - QSimpleCanvasItem *prnt = parent(); - while (prnt && !(prnt->options() & (IsFocusPanel|IsFocusRealm))) - prnt = prnt->parent(); - if (prnt && d->canvas->d->focusPanelData.value(prnt) == this) - d->canvas->d->focusPanelData.remove(prnt); - } - if (d->filter) - delete d->filter; - - qDeleteAll(children()); - if (parent()) - parent()->remChild(this); - delete d->graphicsItem; - } else { - update(); - setOptions(MouseFilter, false); - - if (d->canvas){ - if (d->canvas->focusItem() == this) - d->canvas->d->focusItem = 0; - if (d->canvas->d->lastFocusItem == this) - d->canvas->d->lastFocusItem = 0; - if (d->hasBeenActiveFocusPanel) - d->canvas->d->clearFocusPanel(this); - if (d->hasFocus) - d->canvas->d->clearFocusItem(this); - } - - while(!d->children.isEmpty()) { - QSimpleCanvasItem *child = d->children.takeFirst(); - delete child; - } - - delete d->filter; - - if (parent() && d->data_ptr && d->data()->dirty) { - QSimpleCanvasLayer *l = parent()->layer(); - if (l) { - l->remDirty(this); - } - } - if (d->parent) - d->parent->remChild(this); - - - if (d->data_ptr) - delete d->data_ptr; - } -} - -QSimpleCanvasItem::operator QGraphicsItem *() -{ - Q_D(QSimpleCanvasItem); - if (!d->graphicsItem) { - if (parent()) { - qWarning("QSimpleCanvasItem: Only the root item can be converted into a QGraphicsItem"); - return 0; - } - d->convertToGraphicsItem(); - } - return d->graphicsItem; -} - -QSimpleCanvasItem::operator QmlDebuggerStatus *() -{ - Q_D(QSimpleCanvasItem); - if(!d->debuggerStatus) - d->debuggerStatus = new QSimpleCanvasItemDebuggerStatus(this); - return d->debuggerStatus; -} - -QPointF QSimpleCanvasItemPrivate::transformOrigin() const -{ - Q_Q(const QSimpleCanvasItem); - - QRectF br = q->boundingRect(); - - switch(origin) { - default: - case QSimpleCanvasItem::TopLeft: - return QPointF(0, 0); - case QSimpleCanvasItem::TopCenter: - return QPointF(br.width() / 2., 0); - case QSimpleCanvasItem::TopRight: - return QPointF(br.width(), 0); - case QSimpleCanvasItem::MiddleLeft: - return QPointF(0, br.height() / 2.); - case QSimpleCanvasItem::Center: - return QPointF(br.width() / 2., br.height() / 2.); - case QSimpleCanvasItem::MiddleRight: - return QPointF(br.width(), br.height() / 2.); - case QSimpleCanvasItem::BottomLeft: - return QPointF(0, br.height()); - case QSimpleCanvasItem::BottomCenter: - return QPointF(br.width() / 2., br.height()); - case QSimpleCanvasItem::BottomRight: - return QPointF(br.width(), br.height()); - } -} - -void QSimpleCanvasItemPrivate::setParentInternal(QSimpleCanvasItem *p) -{ - Q_Q(QSimpleCanvasItem); - QSimpleCanvasItem *oldParent = parent; - if (graphicsItem) { - if (oldParent) - oldParent->remChild(q); - - parent = p; - graphicsItem->setParentItem(p->d_func()->graphicsItem); - - if (parent) - p->addChild(q); - - } else { - bool canvasChange = false; - if (p) - canvasChange = (p->d_func()->canvas != canvas); - QSimpleCanvas *old = canvas; - - QSimpleCanvasLayer *o = q->layer(); - if (q->parent()) { - q->update(); - q->parent()->remChild(q); - } - parent = p; - QSimpleCanvasLayer *n = 0; - if (q->parent()) { - q->parent()->addChild(q); - n = q->layer(); - } - - if (o != n) { - data()->dirty = false; - data()->transformValid = false; - if (o) o->remDirty(q); - if (n) n->addDirty(q); - } - - if (canvasChange) - canvasChanged(p->d_func()->canvas, old); - - q->update(); - } -} - -void QSimpleCanvasItemPrivate::convertToGraphicsItem(QGraphicsItem *parent) -{ - Q_Q(QSimpleCanvasItem); - Q_ASSERT(!graphicsItem); - graphicsItem = new QSimpleGraphicsItem(q); - graphicsItem->setFlag(QGraphicsItem::ItemHasNoContents, !(q->options() & QSimpleCanvasItem::HasContents)); - if (parent) - graphicsItem->setParentItem(parent); - - QSimpleCanvasItemData *old = data_ptr; - data_ptr = 0; - - if (old) { - q->QSimpleCanvasItem::setX(old->x); - q->QSimpleCanvasItem::setY(old->y); - q->QSimpleCanvasItem::setZ(old->z); - q->QSimpleCanvasItem::setVisible(old->visible); - if (old->transformUser) - q->QSimpleCanvasItem::setTransform(*old->transformUser); - q->QSimpleCanvasItem::setFlip(old->flip); - q->QSimpleCanvasItem::setAcceptedMouseButtons((Qt::MouseButtons)old->buttons); - delete old; - } - - if (scale != 1) { - qreal s = scale; - scale = 1; - q->QSimpleCanvasItem::setScale(s); - } - - q->setClipType(clip); - - for (int ii = 0; ii < children.count(); ++ii) - static_cast<QSimpleCanvasItemPrivate*>(children.at(ii)->d_ptr)->convertToGraphicsItem(graphicsItem); -} - -/*! - \fn void QSimpleCanvasItem::setParent(QSimpleCanvasItem *parent) - - Sets the parent of the item to \a parent. - */ -void QSimpleCanvasItem::setParent(QSimpleCanvasItem *p) -{ - Q_D(QSimpleCanvasItem); - if (p == parent() || !p) return; - - QObject::setParent(p); - - if (d->graphicsItem && !static_cast<QSimpleCanvasItemPrivate*>(p->d_ptr)->graphicsItem) - qWarning("QSimpleCanvasItem: Cannot reparent a QGraphicsView item to a QSimpleCanvas item"); - - if (static_cast<QSimpleCanvasItemPrivate*>(p->d_ptr)->graphicsItem && !d->graphicsItem) { - d->setParentInternal(0); - d->convertToGraphicsItem(); - } - - QSimpleCanvasItem *oldParent = d->parent; - d->setParentInternal(p); - parentChanged(p, oldParent); -} - -int QSimpleCanvasItemPrivate::dump(int indent) -{ - Q_Q(QSimpleCanvasItem); - QByteArray ba(indent * 2, ' '); - - QByteArray state; - if (options & QSimpleCanvasItem::MouseFilter) - state.append("i"); - else - state.append("-"); - if (options & QSimpleCanvasItem::HoverEvents) - state.append("h"); - else - state.append("-"); - if (options & QSimpleCanvasItem::MouseEvents) - state.append("m"); - else - state.append("-"); - if (options & QSimpleCanvasItem::HasContents) - state.append("c"); - else - state.append("-"); - if (options & QSimpleCanvasItem::SimpleItem) - state.append("s"); - else - state.append("-"); - if (options & QSimpleCanvasItem::IsFocusPanel) { - if (q->activeFocusPanel()) - state.append("P"); - else - state.append("p"); - } else { - state.append("-"); - } - if (options & QSimpleCanvasItem::IsFocusRealm) - state.append("r"); - else - state.append("-"); - if (q->hasFocus()) { - if (q->hasActiveFocus()) - state.append("F"); - else - state.append("f"); - } else { - if (q->hasActiveFocus()) - state.append("X"); - else - state.append("-"); - } - - QByteArray name; - QFxItem *i = qobject_cast<QFxItem *>(q); - if (i) - name = i->id().toLatin1(); - qWarning().nospace() << ba.constData() << state.constData() << " " << children.count() << " " << q << " " << name.constData(); - - int rv = 0; - - for (int ii = 0; ii < children.count(); ++ii) - rv += children.at(ii)->d_func()->dump(indent + 1); - - return rv + 1; -} - -bool QSimpleCanvasItemPrivate::checkFocusState(FocusStateCheckDatas d, - FocusStateCheckRDatas *r) -{ - Q_Q(QSimpleCanvasItem); - - bool rv = true; - bool isRealm = (options & QSimpleCanvasItem::IsFocusPanel || - options & QSimpleCanvasItem::IsFocusRealm); - - if (options & QSimpleCanvasItem::IsFocusPanel) { - - if (q->activeFocusPanel()) { - if (d & InActivePanel) { - qWarning() << "State ERROR: Nested active focus panels"; - rv = false; - } - - d |= InActivePanel; - } else { - d &= ~InActivePanel; - } - - } - - if (q->hasActiveFocus()) { - if (!(d & InActivePanel)) { - qWarning() << "State ERROR: Active focus in non-active panel"; - rv = false; - } - - if (d & InRealm && !(d & InActiveFocusedRealm)) { - qWarning() << "State ERROR: Active focus in non-active-focused realm"; - rv = false; - } - - if (!q->hasFocus()) { - qWarning() << "State ERROR: Active focus on element that does not have focus"; - rv = false; - } - - if (*r & SeenActiveFocus) { - qWarning() << "State ERROR: Two active focused elements in same realm"; - rv = false; - } - - *r |= SeenActiveFocus; - } - - if (q->hasFocus()) { - if (*r & SeenFocus) { - qWarning() << "State ERROR: Two focused elements in same realm"; - rv = false; - } - - *r |= SeenFocus; - } - - if (options & QSimpleCanvasItem::IsFocusRealm) { - d |= InRealm; - - if (q->hasActiveFocus()) - d |= InActiveFocusedRealm; - else - d &= ~InActiveFocusedRealm; - } - - FocusStateCheckRDatas newR = NoCheckRData; - if (isRealm) - r = &newR; - - for (int ii = 0; ii < children.count(); ++ii) - rv &= children.at(ii)->d_func()->checkFocusState(d, r); - - return rv; -} - -bool QSimpleCanvasItem::activeFocusPanel() const -{ - QSimpleCanvas *c = canvas(); - if (!c) { - Q_D(const QSimpleCanvasItem); - return d->wantsActiveFocusPanelPendingCanvas; - } else { - return c->activeFocusPanel() == this; - } -} - -void QSimpleCanvasItem::setActiveFocusPanel(bool b) -{ - if (!(options() & IsFocusPanel)) { - qWarning("QSimpleCanvasItem::setActiveFocusPanel: Item is not a focus panel"); - return; - } - - QSimpleCanvas *c = canvas(); - Q_D(QSimpleCanvasItem); - if (c) { - if (b) { - d->hasBeenActiveFocusPanel = true; - c->d->setActiveFocusPanel(this); - } else if (d->hasBeenActiveFocusPanel) { - d->hasBeenActiveFocusPanel = false; - c->d->clearFocusPanel(this); - } - } else { - d->wantsActiveFocusPanelPendingCanvas = b; - } -} - -bool QSimpleCanvasItem::hasActiveFocus() const -{ - Q_D(const QSimpleCanvasItem); - return d->hasActiveFocus; -} - -QSimpleCanvasItem *QSimpleCanvasItem::findFirstFocusChild() const -{ - Q_D(const QSimpleCanvasItem); - - const QList<QSimpleCanvasItem *> &children = d->children; - - for (int i = 0; i < children.count(); ++i) { - QSimpleCanvasItem *child = children.at(i); - if (child->options() & IsFocusPanel) - continue; - - if (child->isFocusable()) - return child; - - QSimpleCanvasItem *testFocus = child->findFirstFocusChild(); - if (testFocus) - return testFocus; - } - - return 0; -} - -QSimpleCanvasItem *QSimpleCanvasItem::findLastFocusChild() const -{ - Q_D(const QSimpleCanvasItem); - - const QList<QSimpleCanvasItem *> &children = d->children; - - for (int i = children.count()-1; i >= 0; --i) { - QSimpleCanvasItem *child = children.at(i); - if (child->options() & IsFocusPanel) - continue; - - if (child->isFocusable()) - return child; - QSimpleCanvasItem *testFocus = child->findLastFocusChild(); - if (testFocus) - return testFocus; - } - - return 0; -} - -QSimpleCanvasItem *QSimpleCanvasItem::findPrevFocus(QSimpleCanvasItem *item) -{ - QSimpleCanvasItem *focusChild = item->findLastFocusChild(); - if (focusChild) - return focusChild; - - if (item->options() & IsFocusPanel) { - if (item->isFocusable()) - return item; - else - return 0; - } - - QSimpleCanvasItem *parent = item->parent(); - while (parent) { - const QList<QSimpleCanvasItem *> &children = parent->d_func()->children; - - int idx = children.indexOf(item); - QSimpleCanvasItem *testFocus = 0; - if (idx > 0) { - while (--idx >= 0) { - testFocus = children.at(idx); - if (testFocus->options() & IsFocusPanel) - continue; - if (testFocus->isFocusable()) - return testFocus; - testFocus = testFocus->findLastFocusChild(); - if (testFocus) - return testFocus; - } - } - if (parent->options() & IsFocusPanel) { - if (parent->isFocusable()) - return parent; - else - return 0; - } - item = parent; - parent = parent->parent(); - } - - return 0; -} - -QSimpleCanvasItem *QSimpleCanvasItem::findNextFocus(QSimpleCanvasItem *item) -{ - QSimpleCanvasItem *focusChild = item->findFirstFocusChild(); - if (focusChild) - return focusChild; - - if (item->options() & IsFocusPanel) { - if (item->isFocusable()) - return item; - else - return 0; - } - - QSimpleCanvasItem *parent = item->parent(); - while (parent) { - const QList<QSimpleCanvasItem *> &children = parent->d_func()->children; - - int idx = children.indexOf(item); - QSimpleCanvasItem *testFocus = 0; - if (idx >= 0) { - while (++idx < children.count()) { - testFocus = children.at(idx); - if (testFocus->options() & IsFocusPanel) - continue; - if (testFocus->isFocusable()) - return testFocus; - testFocus = testFocus->findFirstFocusChild(); - if (testFocus) - return testFocus; - } - } - if (parent->options() & IsFocusPanel) { - if (parent->isFocusable()) - return parent; - else - return 0; - } - item = parent; - parent = parent->parent(); - } - - return 0; -} - -QPixmap QSimpleCanvasItem::string(const QString &str, const QColor &c, const QFont &f) -{ - QFontMetrics fm(f); - QSize size(fm.width(str), fm.height()*(str.count(QLatin1Char('\n'))+1)); //fm.boundingRect(str).size(); - QPixmap img(size); - img.fill(Qt::transparent); - QPainter p(&img); - p.setPen(c); - p.setFont(f); - p.drawText(img.rect(), Qt::AlignVCenter, str); - return img; -} - -void QSimpleCanvasItem::geometryChanged(const QRectF &, const QRectF &) -{ -} - -QT_END_NAMESPACE diff --git a/src/declarative/canvas/qsimplecanvasitem.h b/src/declarative/canvas/qsimplecanvasitem.h deleted file mode 100644 index 6452aa4..0000000 --- a/src/declarative/canvas/qsimplecanvasitem.h +++ /dev/null @@ -1,335 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSIMPLECANVASITEM_H -#define QSIMPLECANVASITEM_H - -#include <QtDeclarative/qfxglobal.h> -#include <QtDeclarative/qmldebuggerstatus.h> -#include <QtDeclarative/qsimplecanvas.h> -#if defined(QFX_RENDER_OPENGL) -#include <QtDeclarative/gltexture.h> -#endif -#include <QtCore/qobject.h> -#include <QtGui/qgraphicsitem.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class QPainter; -class QRect; -class QSimpleCanvas; -class QMouseEvent; -class QKeyEvent; -class QSimpleCanvasItemPrivate; -class QSimpleCanvasLayer; -class QPointF; -class QRectF; -class QGraphicsSceneHoverEvent; -class QSimpleCanvasFilter; -class GLTexture; -class QGLShaderProgram; - -class Q_DECLARATIVE_EXPORT QSimpleCanvasItem : public QObject -{ - Q_OBJECT - Q_CAST_INTERFACES(QGraphicsItem) - Q_CAST_INTERFACES(QmlDebuggerStatus) - Q_DECLARE_PRIVATE(QSimpleCanvasItem) - Q_ENUMS(TransformOrigin) - Q_PROPERTY(TransformOrigin transformOrigin READ transformOrigin WRITE setTransformOrigin) - -public: - enum ClipType { NoClip = 0x00, - ClipToHeight = 0x01, - ClipToWidth = 0x02, - ClipToRect = 0x03 }; - enum Option { NoOption = 0x00000000, - MouseFilter = 0x00000001, - ChildMouseFilter = 0x00000002, - HoverEvents = 0x00000004, - MouseEvents = 0x00000008, - HasContents = 0x00000010, - SimpleItem = 0x00000020, - IsFocusPanel = 0x00000040, - IsFocusRealm = 0x00000080, - AcceptsInputMethods = 0x00000100, - IsOpaque = 0x00000200 }; - Q_DECLARE_FLAGS(Options, Option) - - QSimpleCanvasItem(QSimpleCanvasItem *parent=0); - virtual ~QSimpleCanvasItem(); - operator QGraphicsItem *(); - operator QmlDebuggerStatus *(); - - bool clip() const; - void setClip(bool); - ClipType clipType() const; - void setClipType(ClipType); - - Options options() const; - void setOptions(Options, bool set = true); - - Qt::MouseButtons acceptedMouseButtons() const; - void setAcceptedMouseButtons(Qt::MouseButtons buttons); - - qreal x() const; - qreal y() const; - qreal z() const; - QPointF pos() const; - void setX(qreal); - void setY(qreal); - virtual void setZ(qreal); - void setPos(const QPointF &); - - qreal width() const; - void setWidth(qreal); - void setImplicitWidth(qreal); - bool widthValid() const; - qreal height() const; - void setHeight(qreal); - void setImplicitHeight(qreal); - bool heightValid() const; - - QPointF scenePos() const; - - enum TransformOrigin { - TopLeft, TopCenter, TopRight, - MiddleLeft, Center, MiddleRight, - BottomLeft, BottomCenter, BottomRight - }; - TransformOrigin transformOrigin() const; - void setTransformOrigin(TransformOrigin); - QPointF transformOriginPoint() const; - - - qreal scale() const; - virtual void setScale(qreal); - - enum Flip { NoFlip = 0, - VerticalFlip = 0x01, - HorizontalFlip = 0x02, - VerticalAndHorizontalFlip = 0x03 }; - Flip flip() const; - void setFlip(Flip); - - qreal visible() const; - virtual void setVisible(qreal); - bool isVisible() const; - - QSimpleCanvas *canvas() const; - - QSimpleCanvasItem *parent() const; - void setParent(QSimpleCanvasItem *); - void stackUnder(QSimpleCanvasItem *); - void stackOver(QSimpleCanvasItem *); - void stackAt(int idx); - int indexForChild(QSimpleCanvasItem *); - - QRect itemBoundingRect(); - - class GLPainter - { - public: - GLPainter(); - GLPainter(QSimpleCanvasItem *i); - QSimpleCanvasItem *item; - QSimpleCanvas::Matrix activeTransform; - qreal activeOpacity; - QRect sceneClipRect; - - QGLShaderProgram *useTextureShader(); - QGLShaderProgram *useColorShader(const QColor &); - void drawPixmap(const QPointF &, const GLTexture &); - void drawPixmap(const QRectF &, const GLTexture &); - void fillRect(const QRectF &, const QColor &); - - void invalidate(); - - bool blendEnabled; - - private: - int flags; - GLPainter(const GLPainter &); - GLPainter &operator=(const GLPainter &); - }; - - - void setPaintMargin(qreal margin); - QRectF boundingRect() const; - virtual void paintContents(QPainter &); - virtual void paintGLContents(GLPainter &); - virtual uint glSimpleItemData(float *vertices, float *texVertices, - GLTexture **texture, uint count); - - void update(); - - virtual QSimpleCanvasLayer *layer(); - - bool hasChildren() const; - const QList<QSimpleCanvasItem *> &children() const; - - QPointF mapFromScene(const QPointF &) const; - QRectF mapFromScene(const QRectF &) const; - QPointF mapToScene(const QPointF &) const; - QRectF mapToScene(const QRectF &) const; - - QSimpleCanvas::Matrix transform() const; - void setTransform(const QSimpleCanvas::Matrix &); - - QSimpleCanvasFilter *filter() const; - void setFilter(QSimpleCanvasFilter *); - - QSimpleCanvasItem *mouseGrabberItem() const; - void ungrabMouse(); - void grabMouse(); - - virtual bool isFocusable() const; - void setFocusable(bool); - virtual bool hasFocus() const; - void setFocus(bool); - bool activeFocusPanel() const; - void setActiveFocusPanel(bool); - - bool hasActiveFocus() const; - - QSimpleCanvasItem *findFirstFocusChild() const; - QSimpleCanvasItem *findLastFocusChild() const; - static QSimpleCanvasItem *findPrevFocus(QSimpleCanvasItem *item); - static QSimpleCanvasItem *findNextFocus(QSimpleCanvasItem *item); - - GLBasicShaders *basicShaders() const; - -#if defined(QFX_RENDER_OPENGL) - class CachedTexture : public GLTexture - { - public: - void addRef(); - void release(); - - int pixmapWidth() const; - int pixmapHeight() const; - - private: - CachedTexture(); - friend class QSimpleCanvasItem; - QSimpleCanvasPrivate *d; - QString s; - int r, w, h; - }; - - CachedTexture *cachedTexture(const QString &); - CachedTexture *cachedTexture(const QString &, const QPixmap &); -#endif - - static QPixmap string(const QString &, const QColor & = Qt::black, const QFont & = QFont()); - -protected: - virtual void geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry); - virtual void addChild(QSimpleCanvasItem *); - virtual void remChild(QSimpleCanvasItem *); - virtual void canvasChanged(); - virtual void childrenChanged(); - virtual void parentChanged(QSimpleCanvasItem *, QSimpleCanvasItem *); - virtual void focusChanged(bool); - virtual void activeFocusChanged(bool); - virtual bool eventFilter(QObject *, QEvent *); - -public: - // Events - virtual bool mouseFilter(QGraphicsSceneMouseEvent *); - virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); - virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); - virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); - virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *); - virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *); - virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - virtual void mouseUngrabEvent(); - virtual void keyPressEvent(QKeyEvent *event); - virtual void keyReleaseEvent(QKeyEvent *event); - virtual void focusOutEvent(QFocusEvent *e); - virtual void focusInEvent(QFocusEvent *e); - virtual void activePanelInEvent(); - virtual void activePanelOutEvent(); - virtual void inputMethodEvent(QInputMethodEvent* event); - virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const; - -private: - friend class QSimpleCanvas; - friend class QSimpleCanvasPrivate; - friend class QSimpleCanvasRootLayer; - friend class QSimpleCanvasItem::GLPainter; - friend class QSimpleCanvasFilter; - friend class QGraphicsQSimpleCanvasItem; - friend class QSimpleGraphicsItem; - friend class CanvasEGLWidget; - friend class QSimpleCanvasFilterPrivate; - -public: - QSimpleCanvasItem(QSimpleCanvasItemPrivate &dd, QSimpleCanvasItem *parent); -}; - -Q_DECLARE_OPERATORS_FOR_FLAGS(QSimpleCanvasItem::Options) - -class QSimpleCanvasLayer : public QSimpleCanvasItem -{ -public: - QSimpleCanvasLayer(QSimpleCanvasItem *parent); - - virtual void addChild(QSimpleCanvasItem *); - virtual void addDirty(QSimpleCanvasItem *); - virtual void remDirty(QSimpleCanvasItem *); - virtual QSimpleCanvasLayer *layer(); - -private: - friend class QSimpleCanvas; - friend class QSimpleCanvasRootLayer; - QSimpleCanvasLayer(); -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QSIMPLECANVASITEM_H diff --git a/src/declarative/canvas/qsimplecanvasitem_p.h b/src/declarative/canvas/qsimplecanvasitem_p.h deleted file mode 100644 index 7a8f40a..0000000 --- a/src/declarative/canvas/qsimplecanvasitem_p.h +++ /dev/null @@ -1,270 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSIMPLECANVASITEM_P_H -#define QSIMPLECANVASITEM_P_H - -#include "private/qobject_p.h" -#include "qsimplecanvas.h" -#include "qsimplecanvasitem.h" -#include "qsimplecanvasfilter.h" - -#if defined(QFX_RENDER_OPENGL2) -#include <glbasicshaders.h> -#endif - -#include "qgraphicsitem.h" - -QT_BEGIN_NAMESPACE - -class QSimpleGraphicsItem : public QGraphicsItem -{ -public: - QSimpleGraphicsItem(QSimpleCanvasItem *); - virtual ~QSimpleGraphicsItem(); - - virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); - virtual QRectF boundingRect() const; - - QTransform transform; -protected: - virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); - virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); - virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); - virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - virtual bool sceneEvent(QEvent *); - virtual QVariant itemChange(GraphicsItemChange, const QVariant &); - virtual void keyPressEvent(QKeyEvent *event); - virtual void keyReleaseEvent(QKeyEvent *event); - virtual void focusInEvent(QFocusEvent *event); - -private: - friend class QSimpleCanvasItem; - QSimpleCanvasItem *owner; -}; - -class QSimpleCanvasItemData -{ -public: - QSimpleCanvasItemData(); - ~QSimpleCanvasItemData(); - - // 5 bits is all that's needed to store Qt::MouseButtons - int buttons:5; - QSimpleCanvasItem::Flip flip:2; - bool dirty:1; - bool transformValid:1; - bool doNotPaint:1; - bool doNotPaintChildren:1; - - qreal x; - qreal y; - qreal z; - float visible; - - QSimpleCanvas::Matrix *transformUser; - QSimpleCanvas::Matrix transformActive; - int transformVersion; - - float activeOpacity; - -#if defined(QFX_RENDER_OPENGL) - QRectF lastPaintRect; -#else - QRect lastPaintRect; -#endif -}; - -class QSimpleCanvasItemDebuggerStatus : public QmlDebuggerStatus -{ -public: - QSimpleCanvasItemDebuggerStatus(QSimpleCanvasItem *i) - : item(i), selected(false) {} - - virtual void setSelectedState(bool state) - { - selected = state; - item->update(); - } - - QSimpleCanvasItem *item; - bool selected; -}; - -class QSimpleCanvasFilter; -class QGraphicsQSimpleCanvasItem; -class QSimpleCanvasItemPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QSimpleCanvasItem) -public: - QSimpleCanvasItemPrivate() - : parent(0), canvas(0), debuggerStatus(0), filter(0), - clip(QSimpleCanvasItem::NoClip), - origin(QSimpleCanvasItem::TopLeft), options(QSimpleCanvasItem::NoOption), - focusable(false), wantsActiveFocusPanelPendingCanvas(false), - hasBeenActiveFocusPanel(false), - hasFocus(false), hasActiveFocus(false), needsZOrder(false), - widthValid(false), heightValid(false), width(0), height(0), paintmargin(0), scale(1), - graphicsItem(0), data_ptr(0) - { - } - - virtual ~QSimpleCanvasItemPrivate() - { - if(debuggerStatus) delete debuggerStatus; - } - - QSimpleCanvasItem *parent; - QSimpleCanvas *canvas; - QList<QSimpleCanvasItem *> children; - - QSimpleCanvasItemDebuggerStatus *debuggerStatus; - QSimpleCanvasFilter *filter; - - QSimpleCanvasItem::ClipType clip:3; - QSimpleCanvasItem::TransformOrigin origin:4; - int options:10; - bool focusable:1; - bool wantsActiveFocusPanelPendingCanvas:1; - bool hasBeenActiveFocusPanel:1; - bool hasFocus:1; - bool hasActiveFocus:1; - bool needsZOrder:1; - bool widthValid:1; - bool heightValid:1; - - void setFocus(bool f); - void setActiveFocus(bool f); - - qreal width; - qreal height; - qreal paintmargin; - qreal scale; - - QSimpleGraphicsItem *graphicsItem; - inline QSimpleCanvasItemData *data() const { - if (!data_ptr) data_ptr = new QSimpleCanvasItemData; - return data_ptr; - } - mutable QSimpleCanvasItemData *data_ptr; - - void gvRemoveMouseFilter(); - void gvAddMouseFilter(); - - void canvasChanged(QSimpleCanvas *newCanvas, QSimpleCanvas *oldCanvas); - - void freshenTransforms() const; - - QPointF adjustFrom(const QPointF &) const; - QRectF adjustFrom(const QRectF &) const; - QPointF adjustTo(const QPointF &) const; - QRectF adjustTo(const QRectF &) const; - - QPointF transformOrigin() const; - - void setParentInternal(QSimpleCanvasItem *); - void convertToGraphicsItem(QGraphicsItem * = 0); - -#if defined(QFX_RENDER_QPAINTER) - void paint(QPainter &); - void paintChild(QPainter &, QSimpleCanvasItem *); - QRect setupPainting(int version, const QRect &bounding); -#else - struct GLPaintParameters - { - QRect sceneRect; - QRectF boundingRect; - QRect clipRect; -#if defined(QFX_RENDER_OPENGL2) - uchar stencilValue; -#endif - float opacity; - bool forceParamRefresh; - - QSimpleCanvasItem::GLPainter *painter; - }; -#if defined(QFX_RENDER_OPENGL2) - QRectF setupPainting(int version, int &z, QSimpleCanvasItem **); -#elif defined(QFX_RENDER_OPENGL1) - QRectF setupPainting(int version, const QRect &bounding, unsigned int *zero); -#endif - void setupChildState(QSimpleCanvasItem *); - - void paint(GLPaintParameters &, QSimpleCanvasFilter::Layer = QSimpleCanvasFilter::All); -#if defined(QFX_RENDER_OPENGL1) - void paintNoClip(GLPaintParameters &, QSimpleCanvasFilter::Layer = QSimpleCanvasFilter::All); -#endif - void paintChild(const GLPaintParameters &, QSimpleCanvasItem *); - void simplePaintChild(const GLPaintParameters &, QSimpleCanvasItem *); - - inline GLBasicShaders *basicShaders() const; - - QSimpleCanvas::Matrix localTransform() const; - -#endif - - QSimpleCanvasItem *nextOpaque; - - void zOrderChildren(); - bool freshenNeeded() const; - void doFreshenTransforms() const; - - // Debugging - int dump(int); - enum FocusStateCheckData { NoCheckData = 0x00, - InActivePanel = 0x01, - InRealm = 0x02, - InActiveFocusedRealm = 0x04 - }; - Q_DECLARE_FLAGS(FocusStateCheckDatas, FocusStateCheckData) - enum FocusStateCheckRData { NoCheckRData = 0x00, - SeenFocus = 0x01, - SeenActiveFocus = 0x02 }; - Q_DECLARE_FLAGS(FocusStateCheckRDatas, FocusStateCheckRData) - bool checkFocusState(FocusStateCheckDatas, FocusStateCheckRDatas *); -}; - -Q_DECLARE_OPERATORS_FOR_FLAGS(QSimpleCanvasItemPrivate::FocusStateCheckDatas) -Q_DECLARE_OPERATORS_FOR_FLAGS(QSimpleCanvasItemPrivate::FocusStateCheckRDatas) - -QT_END_NAMESPACE - -#endif // QSIMPLECANVASITEM_P_H diff --git a/src/declarative/declarative.pro b/src/declarative/declarative.pro index 4bf267c..f52d893 100644 --- a/src/declarative/declarative.pro +++ b/src/declarative/declarative.pro @@ -17,13 +17,9 @@ include(../qbase.pri) include(3rdparty/3rdparty.pri) include(util/util.pri) include(fx/fx.pri) -include(canvas/canvas.pri) include(qml/qml.pri) include(extra/extra.pri) include(widgets/widgets.pri) -include(test/test.pri) include(debugger/debugger.pri) -contains(QT_CONFIG, opengles2)|contains(QT_CONFIG, opengles1):include(opengl/opengl.pri) - symbian:TARGET.UID3=0x2001E623 diff --git a/src/declarative/extra/extra.pri b/src/declarative/extra/extra.pri index fca8ec8..fc21d0f 100644 --- a/src/declarative/extra/extra.pri +++ b/src/declarative/extra/extra.pri @@ -6,7 +6,6 @@ SOURCES += \ extra/qmlfolderlistmodel.cpp \ extra/qmltimer.cpp \ extra/qfxanimatedimageitem.cpp \ - extra/qfxblendedimage.cpp \ extra/qfxflowview.cpp \ extra/qfxparticles.cpp \ extra/qmlbehaviour.cpp \ @@ -21,7 +20,6 @@ HEADERS += \ extra/qmltimer.h \ extra/qfxanimatedimageitem.h \ extra/qfxanimatedimageitem_p.h \ - extra/qfxblendedimage.h \ extra/qfxflowview.h \ extra/qfxparticles.h \ extra/qmlbehaviour.h \ diff --git a/src/declarative/extra/qfxanimatedimageitem.h b/src/declarative/extra/qfxanimatedimageitem.h index 86ded86..720d187 100644 --- a/src/declarative/extra/qfxanimatedimageitem.h +++ b/src/declarative/extra/qfxanimatedimageitem.h @@ -88,7 +88,7 @@ protected: private: Q_DISABLE_COPY(QFxAnimatedImageItem) - Q_DECLARE_PRIVATE(QFxAnimatedImageItem) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxAnimatedImageItem) }; QT_END_NAMESPACE diff --git a/src/declarative/extra/qfxblendedimage.cpp b/src/declarative/extra/qfxblendedimage.cpp deleted file mode 100644 index 0c93fef..0000000 --- a/src/declarative/extra/qfxblendedimage.cpp +++ /dev/null @@ -1,308 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qfxblendedimage.h" -#include <QtDeclarative/qmlcontext.h> - -#if defined(QFX_RENDER_OPENGL2) -#include <glbasicshaders.h> -#endif - -QT_BEGIN_NAMESPACE - -/*! - \qmlclass BlendedImage - \brief The BlendedImage elements blends two different images depending on a blend ratio. - - This element can be used to simulate blur on slow devices by setting secondaryUrl with - a pre-rendered blurred version of primaryUrl. - - Note that this class will only work under OpenGL. On the software canvas it will display - only the primary image unless the blend is > 0.75, in which case it will display only the - secondary image. -*/ - -/*! - \internal - \class QFxBlendedImage - \brief The QFxBlendedImage blends two different images depending on a blend ratio. - - This class can be used to simulate blur on slow devices by setting secondaryUrl with - a pre-rendered blurred version of primaryUrl. - - Note that this class will only work under OpenGL. On the software canvas it will display - only the primary image unless the blend is > 0.75, in which case it will display only the - secondary image. -*/ -QFxBlendedImage::QFxBlendedImage(QFxItem *parent) -: QFxItem(parent), _blend(0), _smooth(false), dirty(false) -{ -#if defined(QFX_RENDER_OPENGL2) - setOptions(HasContents); -#endif -} - -/*! - Cancels any pending image loads and destroys the image. -*/ -QFxBlendedImage::~QFxBlendedImage() -{ - if (!primUrl.isEmpty()) - QFxPixmap::cancelGet(primUrl,this); - if (!secUrl.isEmpty()) - QFxPixmap::cancelGet(secUrl,this); -} - -/*! - \qmlproperty string BlendedImage::primaryUrl - The URL of the first image to be displayed in this item. -*/ -QUrl QFxBlendedImage::primaryUrl() const -{ - return primUrl; -} - -void QFxBlendedImage::primaryLoaded() -{ - primPix = QFxPixmap(primUrl); - dirty = true; - update(); -} - -void QFxBlendedImage::setPrimaryUrl(const QUrl &url) -{ - if (primUrl == url) - return; - if (!primUrl.isEmpty()) - QFxPixmap::cancelGet(primUrl,this); - Q_ASSERT(!url.isRelative()); - primUrl = url; - if (!primUrl.isEmpty()) - QFxPixmap::get(qmlEngine(this), primUrl,this,SLOT(primaryLoaded())); -} - -/*! - \qmlproperty string BlendedImage::secondaryUrl - The URL of the second image to be displayed in this item. -*/ -QUrl QFxBlendedImage::secondaryUrl() const -{ - return secUrl; -} - -void QFxBlendedImage::secondaryLoaded() -{ - secPix = QFxPixmap(secUrl); - dirty = true; - update(); -} - -void QFxBlendedImage::setSecondaryUrl(const QUrl &url) -{ - if (secUrl == url) - return; - if (!secUrl.isEmpty()) - QFxPixmap::cancelGet(secUrl,this); - Q_ASSERT(!url.isRelative()); - secUrl = url; - if (!secUrl.isEmpty()) - QFxPixmap::get(qmlEngine(this), secUrl,this,SLOT(secondaryLoaded())); -} - -/*! - \qmlproperty real BlendedImage::blend - The ratio used to blend the two images. - - If blend has a value of 0, only the first image will be displayed. - If blend has a value of 1, only the second image will be displayed. -*/ -qreal QFxBlendedImage::blend() const -{ - return _blend; -} - -void QFxBlendedImage::setBlend(qreal b) -{ - _blend = b; - update(); -} - -/*! - \qmlproperty bool BlendedImage::smooth - - Set this property if you want the image to be smoothly filtered when scaled or - transformed. Smooth filtering gives better visual quality, but is slower. If - the BlendedImage is displayed at its natural size, this property has no visual or - performance effect. - - \note Generally scaling artifacts are only visible if the image is stationary on - the screen. A common pattern when animating an image is to disable smooth - filtering at the beginning of the animation and reenable it at the conclusion. - */ -bool QFxBlendedImage::smoothTransform() const -{ - return _smooth; -} - -void QFxBlendedImage::setSmoothTransform(bool s) -{ - if (_smooth == s) - return; - _smooth = s; - update(); -} - -#if defined(QFX_RENDER_QPAINTER) - -void QFxBlendedImage::paintContents(QPainter &p) -{ - if (primUrl.isEmpty() && secUrl.isEmpty()) - return; - - if (_smooth) { - p.save(); - p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, _smooth); - } - - if (_blend < 0.75) - p.drawPixmap(0, 0, primPix); - else - p.drawPixmap(0, 0, secPix); - - if (_smooth) { - p.restore(); - } -} - -#elif defined(QFX_RENDER_OPENGL2) - -void QFxBlendedImage::paintGLContents(GLPainter &p) -{ - static DualTextureBlendShader *shader = 0; - if (!shader) - shader = new DualTextureBlendShader(); - - if (dirty) { - prim.clear(); - sec.clear(); - prim.setImage(primPix.toImage()); - sec.setImage(secPix.toImage()); - - dirty = false; - } - - if (prim.isNull() || sec.isNull()) { - - return; - } - - GLfloat vertices[8]; - GLfloat texVertices[8]; - - float widthV = width(); - float heightV = height(); - if (!widthV) - widthV = qMax(primPix.width(), secPix.width()); - if (!heightV) - heightV = qMax(primPix.height(), secPix.height()); - - vertices[0] = 0; vertices[1] = heightV; - vertices[2] = widthV; vertices[3] = heightV; - vertices[4] = 0; vertices[5] = 0; - vertices[6] = widthV; vertices[7] = 0; - - texVertices[0] = 0; texVertices[1] = 0; - texVertices[2] = 1; texVertices[3] = 0; - texVertices[4] = 0; texVertices[5] = 1; - texVertices[6] = 1; texVertices[7] = 1; - - if (_blend == 0 || _blend == 1) { - QGLShaderProgram *tshader = p.useTextureShader(); - - GLTexture *tex = 0; - - if (_blend == 0) - tex = &prim; - else - tex = &sec; - - tshader->setAttributeArray(SingleTextureShader::Vertices, vertices, 2); - tshader->setAttributeArray(SingleTextureShader::TextureCoords, texVertices, 2); - - glBindTexture(GL_TEXTURE_2D, tex->texture()); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - - tshader->disableAttributeArray(SingleTextureShader::Vertices); - tshader->disableAttributeArray(SingleTextureShader::TextureCoords); - } else { - - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, prim.texture()); - glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, sec.texture()); - - shader->enable(); - shader->setOpacity(1); - qreal b = _blend; - if (b > 1) b = 1; - else if (b < 0) b = 0; - shader->setBlend(b); - shader->setTransform(p.activeTransform); - - shader->setAttributeArray(DualTextureBlendShader::Vertices, vertices, 2); - shader->setAttributeArray(DualTextureBlendShader::TextureCoords, texVertices, 2); - shader->setAttributeArray(DualTextureBlendShader::BlendTextureCoords, texVertices, 2); - - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - - shader->disableAttributeArray(DualTextureBlendShader::Vertices); - shader->disableAttributeArray(DualTextureBlendShader::TextureCoords); - shader->disableAttributeArray(DualTextureBlendShader::BlendTextureCoords); - - glBindTexture(GL_TEXTURE_2D, 0); - glActiveTexture(GL_TEXTURE0); - } -} -#endif - -QML_DEFINE_TYPE(QFxBlendedImage,BlendedImage) - -QT_END_NAMESPACE diff --git a/src/declarative/extra/qfxblendedimage.h b/src/declarative/extra/qfxblendedimage.h deleted file mode 100644 index 44de94c..0000000 --- a/src/declarative/extra/qfxblendedimage.h +++ /dev/null @@ -1,111 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QFXBLENDEDIMAGE_H -#define QFXBLENDEDIMAGE_H - -#include <QtDeclarative/qfxitem.h> -#if defined(QFX_RENDER_OPENGL2) -#include <gltexture.h> -#endif - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class Q_DECLARATIVE_EXPORT QFxBlendedImage : public QFxItem -{ - Q_OBJECT - - Q_PROPERTY(QUrl primaryUrl READ primaryUrl WRITE setPrimaryUrl) - Q_PROPERTY(QUrl secondaryUrl READ secondaryUrl WRITE setSecondaryUrl) - Q_PROPERTY(qreal blend READ blend WRITE setBlend) - Q_PROPERTY(bool smooth READ smoothTransform WRITE setSmoothTransform) -public: - QFxBlendedImage(QFxItem *parent=0); - ~QFxBlendedImage(); - - QUrl primaryUrl() const; - void setPrimaryUrl(const QUrl &); - - QUrl secondaryUrl() const; - void setSecondaryUrl(const QUrl &); - - qreal blend() const; - void setBlend(qreal); - - bool smoothTransform() const; - void setSmoothTransform(bool); - -#if defined(QFX_RENDER_QPAINTER) - void paintContents(QPainter &painter); -#elif defined(QFX_RENDER_OPENGL2) - void paintGLContents(GLPainter &); -#endif - -private Q_SLOTS: - void primaryLoaded(); - void secondaryLoaded(); - -private: - QUrl primUrl; - QUrl secUrl; - - qreal _blend; - bool _smooth; - bool dirty; -#if defined(QFX_RENDER_OPENGL2) - GLTexture prim; - GLTexture sec; -#endif - QPixmap primPix; - QPixmap secPix; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QFxBlendedImage) - -QT_END_HEADER - -#endif // QFXBLENDEDIMAGE_H diff --git a/src/declarative/extra/qfxparticles.cpp b/src/declarative/extra/qfxparticles.cpp index 3130f06..322ec53 100644 --- a/src/declarative/extra/qfxparticles.cpp +++ b/src/declarative/extra/qfxparticles.cpp @@ -40,9 +40,6 @@ ****************************************************************************/ #include "private/qfxitem_p.h" -#if defined(QFX_RENDER_OPENGL) -#include "gltexture.h" -#endif #include <stdlib.h> #include <math.h> @@ -350,11 +347,7 @@ public: maxX = minX = maxY = minY = 0; } -#if defined(QFX_RENDER_QPAINTER) void paintContents(QPainter &p); -#elif defined(QFX_RENDER_OPENGL2) - void paintGLContents(GLPainter &); -#endif void updateSize(); @@ -375,9 +368,6 @@ public: , angle(0), angleDev(0), velocity(0), velocityDev(0) , addParticleTime(0), addParticleCount(0), lastAdvTime(0), stream(false), streamDelay(0) , emitting(true), motion(0), clock(this) -#if defined(QFX_RENDER_OPENGL) - , texDirty(true) -#endif { } @@ -418,10 +408,6 @@ public: QList<QFxParticle> particles; QTickAnimationProxy<QFxParticlesPrivate, &QFxParticlesPrivate::tick> clock; -#if defined(QFX_RENDER_OPENGL) - bool texDirty; - GLTexture tex; -#endif }; //TODO: Stop the clock if no visible particles and not emitting (restart on emittingChanged) @@ -654,10 +640,6 @@ void QFxParticles::imageLoaded() { Q_D(QFxParticles); d->image = QFxPixmap(d->url); -#if defined(QFX_RENDER_OPENGL) - d->texDirty = true; - d->tex.clear(); -#endif update(); } @@ -673,10 +655,6 @@ void QFxParticles::setSource(const QUrl &name) if (name.isEmpty()) { d->url = name; d->image = QPixmap(); -#if defined(QFX_RENDER_OPENGL) - d->texDirty = true; - d->tex.clear(); -#endif update(); } else { d->url = name; @@ -1059,14 +1037,6 @@ void QFxParticles::setMotion(QFxParticleMotion *motion) d->motion = motion; } -void QFxParticles::dump(int depth) -{ - Q_D(QFxParticles); - QByteArray ba(depth * 4, ' '); - qWarning() << ba.constData() << "URL:" << d->url << "Count:" << d->count; - QFxItem::dump(depth); -} - QString QFxParticles::propertyInfo() const { Q_D(const QFxParticles); @@ -1079,8 +1049,8 @@ void QFxParticlesPainter::updateSize(){ setWidth(1000); setHeight(1000); return ; - const int parentX = parent()->x(); - const int parentY = parent()->y(); + const int parentX = parentItem()->x(); + const int parentY = parentItem()->y(); //Have to use statistical approach to needed size as arbitrary particle //motions make it impossible to calculate. //max/min vars stored to give a never shrinking rect @@ -1106,7 +1076,6 @@ void QFxParticlesPainter::updateSize(){ setY(myY); } -#if defined(QFX_RENDER_QPAINTER) void QFxParticles::paintContents(QPainter &p) { Q_UNUSED(p); @@ -1119,8 +1088,8 @@ void QFxParticlesPainter::paintContents(QPainter &p) return; updateSize(); - const int myX = x() + parent()->x(); - const int myY = y() + parent()->y(); + const int myX = x() + parentItem()->x(); + const int myY = y() + parentItem()->y(); for (int i = 0; i < d->particles.count(); ++i) { const QFxParticle &particle = d->particles.at(i); @@ -1129,64 +1098,6 @@ void QFxParticlesPainter::paintContents(QPainter &p) } update();//Should I need this? (GV does) } -#elif defined(QFX_RENDER_OPENGL2) -void QFxParticles::paintGLContents(GLPainter &) -{ - //painting is done by the ParticlesPainter, so it can have the right size -} - -void QFxParticlesPainter::paintGLContents(GLPainter &p) -{ - - if (d->image.isNull()) - return; - - updateSize(); - - if (d->texDirty && !d->image.isNull()) { - d->tex.setImage(d->image.toImage()); - d->tex.setHorizontalWrap(GLTexture::Repeat); - d->tex.setVerticalWrap(GLTexture::Repeat); - } - d->texDirty = false; - - SingleTextureOpacityShader *shader = basicShaders()->singleTextureOpacity(); - shader->enable(); - shader->setTransform(p.activeTransform); - - glBindTexture(GL_TEXTURE_2D, d->tex.texture()); - - const int myX = (int)(x() + parent()->x()); - const int myY = (int)(y() + parent()->y()); - float widthV = d->image.width(); - float heightV = d->image.height(); - for (int i = 0; i < d->particles.count(); ++i) { - const QFxParticle &particle = d->particles.at(i); - float left = particle.x - myX; - float right = particle.x - myX + widthV; - float top = particle.y - myY; - float bottom = particle.y - myY + heightV; - - GLfloat vertices[] = { left, bottom, - right, bottom, - left, top, - right, top }; - - GLfloat texVertices[] = { 0, 0, - 1, 0, - 0, 1, - 1, 1 }; - - shader->setAttributeArray(SingleTextureShader::Vertices, vertices, 2); - shader->setAttributeArray(SingleTextureShader::TextureCoords, texVertices, 2); - shader->setOpacity(particle.opacity * p.activeOpacity); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - } - - shader->disableAttributeArray(SingleTextureShader::Vertices); - shader->disableAttributeArray(SingleTextureShader::TextureCoords); -} -#endif void QFxParticles::componentComplete() { diff --git a/src/declarative/extra/qfxparticles.h b/src/declarative/extra/qfxparticles.h index cfaffa7..9f085cd 100644 --- a/src/declarative/extra/qfxparticles.h +++ b/src/declarative/extra/qfxparticles.h @@ -44,10 +44,6 @@ #include <QtDeclarative/qfxitem.h> -#if defined(QFX_RENDER_OPENGL) -#include "gltexture.h" -#endif - QT_BEGIN_HEADER QT_BEGIN_NAMESPACE @@ -207,14 +203,9 @@ public: QFxParticleMotion *motion() const; void setMotion(QFxParticleMotion *); - virtual void dump(int depth); virtual QString propertyInfo() const; -#if defined(QFX_RENDER_QPAINTER) void paintContents(QPainter &p); -#elif defined(QFX_RENDER_OPENGL2) - void paintGLContents(GLPainter &); -#endif protected: virtual void componentComplete(); @@ -225,7 +216,7 @@ private Q_SLOTS: private: Q_DISABLE_COPY(QFxParticles) - Q_DECLARE_PRIVATE(QFxParticles) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxParticles) }; QT_END_NAMESPACE diff --git a/src/declarative/fx/fx.pri b/src/declarative/fx/fx.pri index 0c26356..71517fd 100644 --- a/src/declarative/fx/fx.pri +++ b/src/declarative/fx/fx.pri @@ -1,17 +1,13 @@ HEADERS += \ fx/qfxanchors.h \ fx/qfxanchors_p.h \ - fx/qfxblurfilter.h \ fx/qfxcomponentinstance.h \ fx/qfxcomponentinstance_p.h \ fx/qfxevents_p.h \ fx/qfxflickable.h \ fx/qfxflickable_p.h \ fx/qfxflipable.h \ - fx/qfxfocuspanel.h \ - fx/qfxfocusrealm.h \ fx/qfxgridview.h \ - fx/qfxhighlightfilter.h \ fx/qfximage.h \ fx/qfxpainteditem.h \ fx/qfxpainteditem_p.h \ @@ -30,11 +26,9 @@ HEADERS += \ fx/qfxpathview_p.h \ fx/qfxrect.h \ fx/qfxrect_p.h \ - fx/qfxreflectionfilter.h \ fx/qfxrepeater.h \ fx/qfxrepeater_p.h \ fx/qfxscalegrid.h \ - fx/qfxshadowfilter.h \ fx/qfxtextedit.h \ fx/qfxtextedit_p.h \ fx/qfxtext.h \ @@ -47,15 +41,11 @@ HEADERS += \ SOURCES += \ fx/qfxanchors.cpp \ - fx/qfxblurfilter.cpp \ fx/qfxcomponentinstance.cpp \ fx/qfxevents.cpp \ fx/qfxflickable.cpp \ fx/qfxflipable.cpp \ - fx/qfxfocuspanel.cpp \ - fx/qfxfocusrealm.cpp \ fx/qfxgridview.cpp \ - fx/qfxhighlightfilter.cpp \ fx/qfximage.cpp \ fx/qfxpainteditem.cpp \ fx/qfxitem.cpp \ @@ -66,10 +56,8 @@ SOURCES += \ fx/qfxpath.cpp \ fx/qfxpathview.cpp \ fx/qfxrect.cpp \ - fx/qfxreflectionfilter.cpp \ fx/qfxrepeater.cpp \ fx/qfxscalegrid.cpp \ - fx/qfxshadowfilter.cpp \ fx/qfxtext.cpp \ fx/qfxtextedit.cpp \ fx/qfxtransform.cpp \ diff --git a/src/declarative/fx/qfxanchors.cpp b/src/declarative/fx/qfxanchors.cpp index 9a5c516..22b9b08 100644 --- a/src/declarative/fx/qfxanchors.cpp +++ b/src/declarative/fx/qfxanchors.cpp @@ -222,7 +222,7 @@ void QFxAnchorsPrivate::addDepend(QFxItem *item) if (!item) return; QFxItemPrivate *p = - static_cast<QFxItemPrivate *>(QObjectPrivate::get(item)); + static_cast<QFxItemPrivate *>(QGraphicsItemPrivate::get(item)); p->dependantAnchors.append(q); } @@ -232,7 +232,7 @@ void QFxAnchorsPrivate::remDepend(QFxItem *item) if (!item) return; QFxItemPrivate *p = - static_cast<QFxItemPrivate *>(QObjectPrivate::get(item)); + static_cast<QFxItemPrivate *>(QGraphicsItemPrivate::get(item)); p->dependantAnchors.removeAll(q); } diff --git a/src/declarative/fx/qfxblurfilter.cpp b/src/declarative/fx/qfxblurfilter.cpp deleted file mode 100644 index 84799ec..0000000 --- a/src/declarative/fx/qfxblurfilter.cpp +++ /dev/null @@ -1,467 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qfxblurfilter.h" -#include <private/qsimplecanvasitem_p.h> - -#if defined(QFX_RENDER_OPENGL2) -#include <glsave.h> -#include <QtOpenGL/qglframebufferobject.h> -#include <glbasicshaders.h> -#endif - -QT_BEGIN_NAMESPACE -class QFxBlurFilterPrivate -{ -public: - QFxBlurFilterPrivate() - : radius(0) - { - } - qreal radius; -}; - -/*! - \qmlclass Blur - \brief The Blur filter blurs an item and its contents. - \inherits Filter - - Blurring reduces the clarity of a visual item. The following example - shows an icon at a blur radius of 0, 5 and 10. - - \table - \row - \o - \qml -HorizontalLayout { - Image { - source: "icon.png" - filter: Blur { radius: 0 } - } - Image { - source: "icon.png" - filter: Blur { radius: 5 } - } - Image { - source: "icon.png" - filter: Blur { radius: 10 } - } -} - \endqml - \row - \o \image blur_example.png - \endtable - - Bluring is only supported when Qt Declarative is compiled for OpenGL ES 2.0. - Otherwise the Blur filter has no effect. - */ -/*! - \internal - \class QFxBlurFilter - \ingroup group_effects - \brief The QFxBlurFilter class allows you to blur an item. -*/ - -QFxBlurFilter::QFxBlurFilter(QObject *parent) -: QSimpleCanvasFilter(parent), d(new QFxBlurFilterPrivate) -{ -} - -QFxBlurFilter::~QFxBlurFilter() -{ - delete d; d = 0; -} - -/*! - \qmlproperty real Blur::radius - - Sets the blur kernel radius. - The larger the radius the more blurry the item will appear. - A radius of 0 (or less) is equivalent to no blur. - */ - -/*! - \property QFxBlurFilter::radius - \brief the radius of the blur. -*/ -qreal QFxBlurFilter::radius() const -{ - return d->radius; -} - -void QFxBlurFilter::setRadius(qreal radius) -{ - if (d->radius == radius) return; - d->radius = radius; - emit radiusChanged(radius); - update(); -} - -QRectF QFxBlurFilter::itemBoundingRect(const QRectF &r) const -{ - QRectF rv = r; - if (d->radius > 0) - rv.adjust(-d->radius, -d->radius, d->radius, d->radius); - return rv; -} - -#include <math.h> -void QFxBlurFilter::filterGL(QSimpleCanvasItem::GLPainter &p) -{ -#if defined(QFX_RENDER_OPENGL2) -#if 1 - if (d->radius <= 0) { - renderToScreen(); - return; - } - float radius = d->radius; - QSimpleCanvasItem *item = this->item(); - - QRect r = item->itemBoundingRect(); - float blurScale = 1.0; - QRect tr = QRect(QPoint(0, 0), r.size() * blurScale); - radius *= blurScale; - - QGLFramebufferObject *fbo = renderToFBO(blurScale); - if (!fbo) - return; - - float height = r.height(); - float width = r.width(); - - float texWidth = float(tr.width()) / float(fbo->width()); - float texHeight = float(tr.height()) / float(fbo->height()); - - int steps = int(::ceil(radius)); - int dispSteps = int(::ceil(d->radius)); - float xstep = texWidth * radius / float(steps * fbo->width()); - float xinc = steps / float(fbo->width()); - - glDisable(GL_BLEND); - - // Render x pass - QSize xSize(tr.width() + 2 * steps, tr.height()); - QGLFramebufferObject *xBlur = acquireFBO(xSize); - float xWidth = float(xSize.width()) / float(xBlur->width()); - float xHeight = float(xSize.height()) / float(xBlur->height()); - { - xBlur->bind(); - - GLSaveViewport sv; GLSaveScissor ss; - glClearColor(0,0,0,0); - glDisable(GL_SCISSOR_TEST); - glViewport(0, 0, xBlur->width(), xBlur->height()); - glClear(GL_COLOR_BUFFER_BIT); - - float vert[] = { 0, xHeight, - xWidth, xHeight, - 0, 0, - xWidth, 0 }; - float texVert[] = { -xinc, 0, - texWidth + xinc, 0, - -xinc, texHeight, - texWidth + xinc, texHeight }; - - QMatrix4x4 trans; - trans.translate(-1, -1); - trans.scale(2, 2); - BlurTextureShader *shader = item->basicShaders()->blurTexture(); - shader->enable(); - shader->setTransform(trans); - if (steps > 1) { - shader->setStep(xstep * 2); - shader->setSteps(steps / 2); - } else { - shader->setStep(xstep); - shader->setSteps(steps); - } - shader->setMode(BlurTextureShader::Horizontal); - - glBindTexture(GL_TEXTURE_2D, fbo->texture()); - - shader->setAttributeArray(BlurTextureShader::Vertices, vert, 2); - shader->setAttributeArray(BlurTextureShader::TextureCoords, texVert, 2); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - shader->disableAttributeArray(BlurTextureShader::Vertices); - shader->disableAttributeArray(BlurTextureShader::TextureCoords); - xBlur->release(); - } - - // Render y pass - QSize ySize(xSize.width(), tr.height() + 2 * steps); - QGLFramebufferObject *yBlur = acquireFBO(ySize); - - float yWidth = float(ySize.width()) / float(yBlur->width()); - float yHeight = float(ySize.height()) / float(yBlur->height()); - float ystep = radius / float(steps * xBlur->height()); - float yinc = steps / float(xBlur->height()); - { - yBlur->bind(); - - GLSaveViewport sv; GLSaveScissor ss; - glClearColor(0,0,0,0); - glDisable(GL_SCISSOR_TEST); - glViewport(0, 0, yBlur->width(), yBlur->height()); - glClear(GL_COLOR_BUFFER_BIT); - - float vert[] = { 0, yHeight, - yWidth, yHeight, - 0, 0, - yWidth, 0 }; - float texVert[] = { 0, -yinc, - xWidth, -yinc, - 0, xHeight + yinc, - xWidth, xHeight + yinc }; - - QMatrix4x4 trans; - trans.translate(-1, -1); - trans.scale(2, 2); - BlurTextureShader *shader = item->basicShaders()->blurTexture(); - shader->enable(); - shader->setTransform(trans); - if (steps > 1) { - shader->setStep(ystep * 2); - shader->setSteps(steps / 2); - } else { - shader->setStep(ystep); - shader->setSteps(steps); - } - shader->setMode(BlurTextureShader::Vertical); - - glBindTexture(GL_TEXTURE_2D, xBlur->texture()); - - shader->setAttributeArray(BlurTextureShader::Vertices, vert, 2); - shader->setAttributeArray(BlurTextureShader::TextureCoords, texVert, 2); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - shader->disableAttributeArray(BlurTextureShader::Vertices); - shader->disableAttributeArray(BlurTextureShader::TextureCoords); - yBlur->release(); - } - - glEnable(GL_BLEND); - - // Render display pass - { - glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - float vert[] = { -dispSteps, height + dispSteps, - width + dispSteps, height + dispSteps, - -dispSteps, -dispSteps, - width + dispSteps, -dispSteps }; - float texVert[] = { 0, 0, - yWidth, 0, - 0, yHeight, - yWidth, yHeight }; - SingleTextureShader *shader = item->basicShaders()->singleTexture(); - shader->enable(); - shader->setTransform(p.activeTransform); - - glBindTexture(GL_TEXTURE_2D, yBlur->texture()); - - shader->setAttributeArray(SingleTextureShader::Vertices, vert, 2); - shader->setAttributeArray(SingleTextureShader::TextureCoords, texVert, 2); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - shader->disableAttributeArray(SingleTextureShader::Vertices); - shader->disableAttributeArray(SingleTextureShader::TextureCoords); - glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - } - - releaseFBO(yBlur); - releaseFBO(xBlur); - releaseFBO(fbo); -#else -#if 0 - if (d->radius <= 0) { - renderToScreen(); - return; - } - QSimpleCanvasItem *item = this->item(); - - QRect r = item->itemBoundingRect(); - - float scale = 0.5; - float scalePercent = scale / d->radius; - QGLFramebufferObject *fbo = renderToFBO(scalePercent); - if (!fbo) - return; - - QGLFramebufferObject *xfbo = acquireFBO(QSize(scale * r.width(), fbo->height())); - QGLFramebufferObject *yfbo = acquireFBO(QSize(scale * r.width(), scale * r.height())); - - - BlurTextureShader *shader = item->basicShaders()->blurTexture(); - shader->enable(); - shader->setTransform(QMatrix4x4()); - - // Render up - x - { - shader->setMode(BlurTextureShader::Horizontal); - shader->setStep(1. / float(xfbo->width())); - - GLSaveViewport vp; - xfbo->bind(); - glClearColor(0,0,0,0); - glViewport(0, 0, xfbo->width(), xfbo->height()); - glClear(GL_COLOR_BUFFER_BIT); - - float oWidth = -1. + 2. * float(r.width()) * scale / float(xfbo->width()); - float oHeight = -1. + 2. * float(r.height()) * scalePercent / float(xfbo->height()); - float vert[] = { - -1, -1, - oWidth, -1, - -1, oHeight, - - -1, oHeight, - oWidth, oHeight, - oWidth, -1 - }; - - float tWidth = r.width() * scalePercent / fbo->width(); - float tHeight = r.height() * scalePercent / fbo->height(); - float texVert[] = { - 0, 0, - tWidth, 0, - 0, tHeight, - - 0, tHeight, - tWidth, tHeight, - tWidth, 0 - }; - - glBindTexture(GL_TEXTURE_2D, fbo->texture()); - shader->setAttributeArray(BlurTextureShader::Vertices, vert, 2); - shader->setAttributeArray(BlurTextureShader::TextureCoords, texVert, 2); - - glDrawArrays(GL_TRIANGLES, 0, 6); - - xfbo->release(); - } - - // Render up - y - { - shader->setMode(BlurTextureShader::Vertical); - shader->setStep(1. / float(yfbo->height())); - - GLSaveViewport vp; - yfbo->bind(); - glClearColor(0,0,0,0); - glViewport(0, 0, yfbo->width(), yfbo->height()); - glClear(GL_COLOR_BUFFER_BIT); - - float oWidth = -1. + 2. * r.width() * scale / yfbo->width(); - float oHeight = -1. + 2. * r.height() * scale / yfbo->height(); - float vert[] = { - -1, -1, - oWidth, -1, - -1, oHeight, - - -1, oHeight, - oWidth, oHeight, - oWidth, -1 - }; - - float tWidth = r.width() * scale / xfbo->width(); - float tHeight = r.height() * scalePercent / xfbo->height(); - float texVert[] = { - 0, 0, - tWidth, 0, - 0, tHeight, - - 0, tHeight, - tWidth, tHeight, - tWidth, 0 - }; - - glBindTexture(GL_TEXTURE_2D, xfbo->texture()); - shader->setAttributeArray(BlurTextureShader::Vertices, vert, 2); - shader->setAttributeArray(BlurTextureShader::TextureCoords, texVert, 2); - - glDrawArrays(GL_TRIANGLES, 0, 6); - - yfbo->release(); - } - - shader->disableAttributeArray(BlurTextureShader::Vertices); - shader->disableAttributeArray(BlurTextureShader::TextureCoords); - - float width = r.width(); - float height = r.height(); - //paint to screen - { - float texWidth = r.width() * scale / float(yfbo->width()); - float texHeight = r.height() * scale / float(yfbo->height()); - - GLfloat vertices[] = { 0, height, - width, height, - 0, 0, - width, 0 }; - GLfloat texVertices[] = { 0, 0, - texWidth, 0, - 0, texHeight, - texWidth, texHeight }; - - glBindTexture(GL_TEXTURE_2D, yfbo->texture()); - - SingleTextureOpacityShader *shader = - item->basicShaders()->singleTextureOpacity(); - shader->enable(); - shader->setTransform(p.activeTransform); - shader->setOpacity(p.activeOpacity); - shader->setAttributeArray(SingleTextureVertexOpacityShader::Vertices, vertices, 2); - shader->setAttributeArray(SingleTextureVertexOpacityShader::TextureCoords, texVertices, 2); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - shader->disableAttributeArray(SingleTextureVertexOpacityShader::Vertices); - shader->disableAttributeArray(SingleTextureVertexOpacityShader::TextureCoords); - } - - - releaseFBO(fbo); - releaseFBO(xfbo); - releaseFBO(yfbo); -#endif -#endif -#else - Q_UNUSED(p); -#endif - -} - -QML_DEFINE_TYPE(QFxBlurFilter,Blur) -QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxblurfilter.h b/src/declarative/fx/qfxblurfilter.h deleted file mode 100644 index 830663f..0000000 --- a/src/declarative/fx/qfxblurfilter.h +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QFXBLURFILTER_H -#define QFXBLURFILTER_H - -#include <QtDeclarative/qsimplecanvasfilter.h> -#include <QtDeclarative/qml.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QFxBlurFilterPrivate; -class Q_DECLARATIVE_EXPORT QFxBlurFilter : public QSimpleCanvasFilter -{ - Q_OBJECT - Q_PROPERTY(qreal radius READ radius WRITE setRadius NOTIFY radiusChanged) -public: - QFxBlurFilter(QObject *parent=0); - virtual ~QFxBlurFilter(); - - qreal radius() const; - void setRadius(qreal); - -Q_SIGNALS: - void radiusChanged(qreal); - -protected: - virtual QRectF itemBoundingRect(const QRectF &) const; - virtual void filterGL(QSimpleCanvasItem::GLPainter &p); - -private: - QFxBlurFilterPrivate *d; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QFxBlurFilter) - -QT_END_HEADER - -#endif // QFXBLURFILTER_H diff --git a/src/declarative/fx/qfxcomponentinstance.h b/src/declarative/fx/qfxcomponentinstance.h index f3bf6b3..940fb6d 100644 --- a/src/declarative/fx/qfxcomponentinstance.h +++ b/src/declarative/fx/qfxcomponentinstance.h @@ -78,7 +78,7 @@ protected: QFxComponentInstance(QFxComponentInstancePrivate &dd, QFxItem *parent); private: - Q_DECLARE_PRIVATE(QFxComponentInstance) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxComponentInstance) }; QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxflickable.cpp b/src/declarative/fx/qfxflickable.cpp index a82385a..59191c9 100644 --- a/src/declarative/fx/qfxflickable.cpp +++ b/src/declarative/fx/qfxflickable.cpp @@ -111,7 +111,7 @@ void QFxFlickablePrivate::init() QObject::connect(&_tl, SIGNAL(updated()), q, SLOT(ticked())); QObject::connect(&_tl, SIGNAL(completed()), q, SLOT(movementEnding())); q->setAcceptedMouseButtons(Qt::LeftButton); - q->setOptions(QSimpleCanvasItem::ChildMouseFilter | QSimpleCanvasItem::MouseEvents); + q->setOptions(QFxItem::ChildMouseFilter | QFxItem::MouseEvents); QObject::connect(_flick, SIGNAL(xChanged()), q, SIGNAL(positionChanged())); QObject::connect(_flick, SIGNAL(yChanged()), q, SIGNAL(positionChanged())); QObject::connect(&elasticX, SIGNAL(updated()), q, SLOT(ticked())); diff --git a/src/declarative/fx/qfxflickable.h b/src/declarative/fx/qfxflickable.h index da38df8..a6c2a6c 100644 --- a/src/declarative/fx/qfxflickable.h +++ b/src/declarative/fx/qfxflickable.h @@ -184,7 +184,7 @@ protected: private: Q_DISABLE_COPY(QFxFlickable) - Q_DECLARE_PRIVATE(QFxFlickable) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxFlickable) }; QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxflipable.cpp b/src/declarative/fx/qfxflipable.cpp index 7672858..6089d0a 100644 --- a/src/declarative/fx/qfxflipable.cpp +++ b/src/declarative/fx/qfxflipable.cpp @@ -221,22 +221,13 @@ void QFxFlipablePrivate::setBackTransform() p3 = axisRotation.transform().map(p3); axisRotation.setAngle(rotation); - QSimpleCanvas::Matrix mat; -#ifdef QFX_RENDER_OPENGL - mat.translate(back->width()/2,back->height()/2, 0); - if (back->width() && p1.x() >= p2.x()) - mat.rotate(180, 0, 1, 0); - if (back->height() && p2.y() >= p3.y()) - mat.rotate(180, 1, 0, 0); - mat.translate(-back->width()/2,-back->height()/2, 0); -#else + QTransform mat; mat.translate(back->width()/2,back->height()/2); if (back->width() && p1.x() >= p2.x()) mat.rotate(180, Qt::YAxis); if (back->height() && p2.y() >= p3.y()) mat.rotate(180, Qt::XAxis); mat.translate(-back->width()/2,-back->height()/2); -#endif back->setTransform(mat); } @@ -295,7 +286,7 @@ QFxFlipable::Side QFxFlipable::side() const //in some cases the user may want to specify a more complex transformation. //in that case, we still allow the generic use of transform. //(the logic here should be kept in sync with setBackTransform and setRotation) -void QFxFlipable::transformChanged(const QSimpleCanvas::Matrix &trans) +void QFxFlipable::transformChanged(const QTransform &trans) { Q_D(QFxFlipable); QPointF p1(0, 0); @@ -319,22 +310,13 @@ void QFxFlipable::transformChanged(const QSimpleCanvas::Matrix &trans) if (newSide != d->current) { d->current = newSide; if (d->current==Back) { - QSimpleCanvas::Matrix mat; -#ifdef QFX_RENDER_OPENGL - mat.translate(d->back->width()/2,d->back->height()/2, 0); - if (d->back->width() && p1.x() >= p2.x()) - mat.rotate(180, 0, 1, 0); - if (d->back->height() && p2.y() >= p3.y()) - mat.rotate(180, 1, 0, 0); - mat.translate(-d->back->width()/2,-d->back->height()/2, 0); -#else + QTransform mat; mat.translate(d->back->width()/2,d->back->height()/2); if (d->back->width() && p1.x() >= p2.x()) mat.rotate(180, Qt::YAxis); if (d->back->height() && p2.y() >= p3.y()) mat.rotate(180, Qt::XAxis); mat.translate(-d->back->width()/2,-d->back->height()/2); -#endif d->back->setTransform(mat); } if (d->front) diff --git a/src/declarative/fx/qfxflipable.h b/src/declarative/fx/qfxflipable.h index 06f8b93..5aa038d 100644 --- a/src/declarative/fx/qfxflipable.h +++ b/src/declarative/fx/qfxflipable.h @@ -44,9 +44,6 @@ #include <QtCore/QObject> #include <QtGui/QTransform> -#if defined(QFX_RENDER_OPENGL) -#include <QtGui/qmatrix4x4.h> -#endif #include <QtDeclarative/qfxitem.h> QT_BEGIN_HEADER @@ -87,7 +84,7 @@ public: Side side() const; protected: - virtual void transformChanged(const QSimpleCanvas::Matrix &); + virtual void transformChanged(const QTransform &); Q_SIGNALS: void sideChanged(); @@ -95,7 +92,7 @@ Q_SIGNALS: private: Q_PRIVATE_SLOT(d_func(), void _q_updateAxis()) Q_DISABLE_COPY(QFxFlipable) - Q_DECLARE_PRIVATE(QFxFlipable) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxFlipable) }; QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxfocuspanel.cpp b/src/declarative/fx/qfxfocuspanel.cpp deleted file mode 100644 index 6da8564..0000000 --- a/src/declarative/fx/qfxfocuspanel.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qfxfocuspanel.h" - - -QT_BEGIN_NAMESPACE -QML_DEFINE_TYPE(QFxFocusPanel,FocusPanel) - -/*! - \qmlclass FocusPanel - \brief The FocusPanel object explicitly creates a focus panel. - \inherits Item - - Focus panels assist in keyboard focus handling when building QML - applications. All the details are covered in the - \l {qmlfocus}{keyboard focus documentation}. -*/ - -/*! - \internal - \class QFxFocusPanel -*/ - -QFxFocusPanel::QFxFocusPanel(QFxItem *parent) : - QFxItem(parent) -{ - setOptions(IsFocusPanel); -} - -QFxFocusPanel::~QFxFocusPanel() -{ -} - -/*! - \qmlproperty bool FocusPanel::active - - Sets whether the object is the active focus panel. -*/ - -bool QFxFocusPanel::isActive() const -{ - QSimpleCanvas *canvas = QSimpleCanvasItem::canvas(); - if (canvas) - return canvas->activeFocusPanel() == this; - else - return false; -} - -void QFxFocusPanel::setActive(bool a) -{ - setActiveFocusPanel(a); -} - -void QFxFocusPanel::activePanelInEvent() -{ - QFxItem::activePanelInEvent(); - emit activeChanged(); -} - -void QFxFocusPanel::activePanelOutEvent() -{ - QFxItem::activePanelOutEvent(); - emit activeChanged(); -} -QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxfocuspanel.h b/src/declarative/fx/qfxfocuspanel.h deleted file mode 100644 index 623c9fb..0000000 --- a/src/declarative/fx/qfxfocuspanel.h +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QFXFOCUSPANEL_H -#define QFXFOCUSPANEL_H - -#include <QtDeclarative/qfxitem.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class Q_DECLARATIVE_EXPORT QFxFocusPanel : public QFxItem -{ - Q_OBJECT - Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged) -public: - QFxFocusPanel(QFxItem *parent=0); - virtual ~QFxFocusPanel(); - - bool isActive() const; - void setActive(bool); - -Q_SIGNALS: - void activeChanged(); - -protected: - virtual void activePanelInEvent(); - virtual void activePanelOutEvent(); - -private: - Q_DISABLE_COPY(QFxFocusPanel) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QFxFocusPanel) - -QT_END_HEADER - -#endif // QFXFOCUSPANEL_H diff --git a/src/declarative/fx/qfxfocusrealm.cpp b/src/declarative/fx/qfxfocusrealm.cpp deleted file mode 100644 index 9270bb2..0000000 --- a/src/declarative/fx/qfxfocusrealm.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qfxfocusrealm.h" - - -QT_BEGIN_NAMESPACE -QML_DEFINE_TYPE(QFxFocusRealm,FocusRealm) - -/*! - \qmlclass FocusRealm - \brief The FocusRealm object explicitly creates a focus realm. - \inherits Item - - Focus realms assist in keyboard focus handling when building reusable QML - components. All the details are covered in the - \l {qmlfocus}{keyboard focus documentation}. -*/ - -/*! - \internal - \class QFxFocusRealm -*/ - -QFxFocusRealm::QFxFocusRealm(QFxItem *parent) : - QFxItem(parent) -{ - setOptions(IsFocusRealm); -} - -QFxFocusRealm::~QFxFocusRealm() -{ -} -QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxfocusrealm.h b/src/declarative/fx/qfxfocusrealm.h deleted file mode 100644 index 20fc5ad..0000000 --- a/src/declarative/fx/qfxfocusrealm.h +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QFXFOCUSREALM_H -#define QFXFOCUSREALM_H - -#include <QtDeclarative/qfxitem.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class Q_DECLARATIVE_EXPORT QFxFocusRealm : public QFxItem -{ - Q_OBJECT -public: - QFxFocusRealm(QFxItem *parent=0); - virtual ~QFxFocusRealm(); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QFxFocusRealm) - -QT_END_HEADER - -#endif // QFXFOCUSREALM_H diff --git a/src/declarative/fx/qfxgridview.h b/src/declarative/fx/qfxgridview.h index b6d585e..8f443e1 100644 --- a/src/declarative/fx/qfxgridview.h +++ b/src/declarative/fx/qfxgridview.h @@ -54,7 +54,7 @@ class QFxGridViewPrivate; class Q_DECLARATIVE_EXPORT QFxGridView : public QFxFlickable { Q_OBJECT - Q_DECLARE_PRIVATE(QFxGridView) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxGridView) Q_PROPERTY(QVariant model READ model WRITE setModel) Q_CLASSINFO("DefaultProperty", "delegate") diff --git a/src/declarative/fx/qfxhighlightfilter.cpp b/src/declarative/fx/qfxhighlightfilter.cpp deleted file mode 100644 index 78a91af..0000000 --- a/src/declarative/fx/qfxhighlightfilter.cpp +++ /dev/null @@ -1,320 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qfxhighlightfilter.h" -#include <qfxpixmap.h> -#include <qmlcontext.h> - -#if defined(QFX_RENDER_OPENGL2) -#include <gltexture.h> -#include <glbasicshaders.h> -#include <QtOpenGL/qglframebufferobject.h> -#include <glsave.h> -#endif - -QT_BEGIN_NAMESPACE - -class QFxHighlightFilterPrivate -{ -public: - QFxHighlightFilterPrivate() - : xOffset(0), yOffset(0), tiled(false) {} - - QUrl url; - int xOffset; - int yOffset; - bool tiled; -#if defined(QFX_RENDER_OPENGL2) - GLTexture tex; -#endif -}; - -/*! - \qmlclass Highlight - \brief The Highlight filter adds a highlight to an item. - \inherits Filter - - \qml -Text { - id: highlighttext - color: "red" - font.size: 32 - text: "Highlight" - filter: Highlight { - source: "pics/highlight.png" - xOffset: NumberAnimation { - running: true - repeat: true - from: 320 - to: -320 - duration: 2000 - } - } -} - \endqml - \image highlight.gif - - Highlighting is only supported when Qt Declarative is compiled for OpenGL ES 2.0. - Otherwise the Highlight filter has no effect. -*/ - -/*! - \internal - \class QFxHighlightFilter - \ingroup group_effects - \brief The QFxHightlightFilter class allows you to add a highlight to an item. -*/ - -QFxHighlightFilter::QFxHighlightFilter(QObject *parent) -: QSimpleCanvasFilter(parent), d(new QFxHighlightFilterPrivate) -{ -#if defined(QFX_RENDER_OPENGL2) - d->tex.setHorizontalWrap(GLTexture::ClampToEdge); - d->tex.setVerticalWrap(GLTexture::ClampToEdge); -#endif -} - -QFxHighlightFilter::~QFxHighlightFilter() -{ - if (!d->url.isEmpty()) - QFxPixmap::cancelGet(d->url, this); - delete d; - d = 0; -} - -/*! - \qmlproperty string Highlight::source - This property holds the URL of the image to be used as the highlight. -*/ - -/*! - \property QFxHighlightFilter::source - \brief the URL of the image to be used as the highlight. -*/ -QUrl QFxHighlightFilter::source() const -{ - return d->url; -} - -void QFxHighlightFilter::imageLoaded() -{ - QPixmap img = QFxPixmap(d->url); -#if defined(QFX_RENDER_OPENGL2) - if (!img.isNull()) - d->tex.setImage(img.toImage()); -#endif - emit sourceChanged(d->url); - update(); -} - -void QFxHighlightFilter::setSource(const QUrl &f) -{ - if (d->url == f) - return; - if (!d->url.isEmpty()) - QFxPixmap::cancelGet(d->url, this); - Q_ASSERT(!f.isRelative()); - d->url = f; -#if defined(QFX_RENDER_OPENGL2) - d->tex.clear(); -#endif - if (!f.isEmpty()) - QFxPixmap::get(qmlEngine(this), d->url, this, SLOT(imageLoaded())); - else - emit sourceChanged(d->url); -} - -/*! - \qmlproperty bool Highlight::tiled - This property holds whether or not the highlight should be tiled. -*/ - -/*! - \property QFxHighlightFilter::tiled - \brief whether or not the highlight should be tiled. -*/ -bool QFxHighlightFilter::tiled() const -{ - return d->tiled; -} - -void QFxHighlightFilter::setTiled(bool t) -{ - if (t == d->tiled) - return; - - d->tiled = t; - -#if defined(QFX_RENDER_OPENGL2) - if (d->tiled) { - d->tex.setHorizontalWrap(GLTexture::ClampToEdge); - d->tex.setVerticalWrap(GLTexture::ClampToEdge); - } else { - d->tex.setHorizontalWrap(GLTexture::Repeat); - d->tex.setVerticalWrap(GLTexture::Repeat); - } -#endif - - emit tiledChanged(d->tiled); -} - -/*! - \qmlproperty int Highlight::xOffset - \qmlproperty int Highlight::yOffset - These properties hold the position of the highlight, relative to the item. -*/ - -/*! - \property QFxHighlightFilter::xOffset - \brief the x position of the highlight, relative to the item. -*/ -int QFxHighlightFilter::xOffset() const -{ - return d->xOffset; -} - -void QFxHighlightFilter::setXOffset(int x) -{ - if (x == d->xOffset) - return; - - d->xOffset = x; - emit offsetChanged(d->xOffset, d->yOffset); -#if defined(QFX_RENDER_OPENGL2) - update(); -#endif -} - -/*! - \property QFxHighlightFilter::yOffset - \brief the y position of the highlight, relative to the item. -*/ -int QFxHighlightFilter::yOffset() const -{ - return d->yOffset; -} - -void QFxHighlightFilter::setYOffset(int y) -{ - if (y == d->yOffset) - return; - - d->yOffset = y; - emit offsetChanged(d->xOffset, d->yOffset); -#if defined(QFX_RENDER_OPENGL2) - update(); -#endif -} - -void QFxHighlightFilter::filterGL(QSimpleCanvasItem::GLPainter &p) -{ -#if defined(QFX_RENDER_OPENGL2) - if (d->tex.isNull()) { - renderToScreen(); - } else { - QSimpleCanvasItem *item = this->item(); - - QRect r = item->itemBoundingRect(); - - QGLFramebufferObject *fbo = renderToFBO(); - - float width = r.width(); - float height = r.height(); - - float texWidth = width / float(fbo->width()); - float texHeight = height / float(fbo->height()); - - GLfloat vert[] = { 0, height, - width, height, - 0, 0, - width, 0 }; - GLfloat texVert[] = { 0, 0, - texWidth, 0, - 0, texHeight, - texWidth, texHeight }; - float texXOffset = 0; - float texYOffset = 0; - - if (xOffset()) - texXOffset = float(xOffset()) / float(d->tex.width()); - if (yOffset()) - texYOffset = float(yOffset()) / float(d->tex.height()); - - GLfloat addTexVert[] = { texXOffset, texYOffset, - 1 + texXOffset, texYOffset, - texXOffset, 1 + texYOffset, - 1 + texXOffset, 1 + texYOffset }; - - glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, fbo->texture()); - glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, d->tex.texture()); - - DualTextureAddShader *shader = item->basicShaders()->dualTextureAdd(); - shader->enable(); - shader->setTransform(p.activeTransform); - shader->setOpacity(p.activeOpacity); - - shader->setAttributeArray(DualTextureAddShader::Vertices, vert, 2); - shader->setAttributeArray(DualTextureAddShader::TextureCoords, texVert, 2); - shader->setAttributeArray(DualTextureAddShader::AddTextureCoords, addTexVert, 2); - - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - - shader->disableAttributeArray(DualTextureAddShader::Vertices); - shader->disableAttributeArray(DualTextureAddShader::TextureCoords); - shader->disableAttributeArray(DualTextureAddShader::AddTextureCoords); - - glActiveTexture(GL_TEXTURE0); - glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - - releaseFBO(fbo); - } -#else - Q_UNUSED(p); -#endif -} - -QML_DEFINE_TYPE(QFxHighlightFilter,Highlight) - -QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxhighlightfilter.h b/src/declarative/fx/qfxhighlightfilter.h deleted file mode 100644 index 56509a3..0000000 --- a/src/declarative/fx/qfxhighlightfilter.h +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QFXHIGHLIGHTFILTER_H -#define QFXHIGHLIGHTFILTER_H - -#include <QtDeclarative/qsimplecanvasfilter.h> -#include <QtDeclarative/qml.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QFxHighlightFilterPrivate; -class Q_DECLARATIVE_EXPORT QFxHighlightFilter : public QSimpleCanvasFilter -{ - Q_OBJECT - - Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) - Q_PROPERTY(bool tiled READ tiled WRITE setTiled NOTIFY tiledChanged) - Q_PROPERTY(int xOffset READ xOffset WRITE setXOffset NOTIFY offsetChanged) - Q_PROPERTY(int yOffset READ yOffset WRITE setYOffset NOTIFY offsetChanged) -public: - QFxHighlightFilter(QObject *parent=0); - virtual ~QFxHighlightFilter(); - - QUrl source() const; - void setSource(const QUrl &); - - bool tiled() const; - void setTiled(bool); - - int xOffset() const; - void setXOffset(int); - int yOffset() const; - void setYOffset(int); - -Q_SIGNALS: - void sourceChanged(const QUrl &); - void offsetChanged(int x, int y); - void tiledChanged(bool); - -private Q_SLOTS: - void imageLoaded(); - -protected: - virtual void filterGL(QSimpleCanvasItem::GLPainter &p); - -private: - QFxHighlightFilterPrivate *d; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QFxHighlightFilter) - -QT_END_HEADER - -#endif // QFXHIGHLIGHTFILTER_H diff --git a/src/declarative/fx/qfximage.cpp b/src/declarative/fx/qfximage.cpp index 539ad02..148c269 100644 --- a/src/declarative/fx/qfximage.cpp +++ b/src/declarative/fx/qfximage.cpp @@ -42,9 +42,6 @@ #include "qfximage.h" #include "qfximage_p.h" #include <private/qfxperf_p.h> -#if defined(QFX_RENDER_OPENGL) -#include <glsave.h> -#endif #include <QNetworkRequest> #include <QNetworkReply> #include <QFile> @@ -131,12 +128,6 @@ QFxImage::~QFxImage() QFxPixmap::cancelGet(d->url, this); if (!d->sciurl.isEmpty()) QFxPixmap::cancelGet(d->sciurl, this); -#if defined(QFX_RENDER_OPENGL) - if (d->tex) { - d->tex->release(); - d->tex = 0; - } -#endif } /*! @@ -164,13 +155,6 @@ void QFxImage::setPixmap(const QPixmap &pix) setImplicitWidth(d->pix.width()); setImplicitHeight(d->pix.height()); -#if defined(QFX_RENDER_OPENGL) - d->texDirty = true; - if (d->tex) { - d->tex->release(); - d->tex = 0; - } -#endif update(); } @@ -321,15 +305,6 @@ void QFxImage::setSmoothTransform(bool s) update(); } -void QFxImage::dump(int depth) -{ - Q_D(QFxImage); - QByteArray ba(depth * 4, ' '); - qWarning() << ba.constData() << "URL:" << d->url; - QFxItem::dump(depth); -} - -#if defined(QFX_RENDER_QPAINTER) void QFxImage::paintContents(QPainter &p) { Q_D(QFxImage); @@ -434,333 +409,6 @@ void QFxImage::paintContents(QPainter &p) p.setRenderHint(QPainter::SmoothPixmapTransform, oldSmooth); } } -#elif defined(QFX_RENDER_OPENGL) -uint QFxImage::glSimpleItemData(float *vertices, float *texVertices, - GLTexture **texture, uint count) -{ - Q_D(QFxImage); - - if (d->pix.isNull() || (d->scaleGrid && !d->scaleGrid->isNull())) - return 0; - - if (count < 8) - return 8; - - d->checkDirty(); - - float widthV = width(); - float heightV = height(); - - vertices[0] = 0; vertices[1] = heightV; - vertices[2] = widthV; vertices[3] = heightV; - vertices[4] = 0; vertices[5] = 0; - vertices[6] = widthV; vertices[7] = 0; - - *texture = d->tex; - - if (d->tiled) { - float tileWidth = widthV / d->pix.width(); - float tileHeight = heightV / d->pix.height(); - texVertices[0] = 0; texVertices[1] = 0; - texVertices[2] = tileWidth; texVertices[3] = 0; - texVertices[4] = 0; texVertices[5] = tileHeight; - texVertices[6] = tileWidth; texVertices[7] = tileHeight; - } else { - texVertices[0] = 0; texVertices[1] = 0; - texVertices[2] = d->tex->glWidth(); texVertices[3] = 0; - texVertices[4] = 0; texVertices[5] = d->tex->glHeight(); - texVertices[6] = d->tex->glWidth(); texVertices[7] = d->tex->glHeight(); - } - - return 8; -} - -void QFxImagePrivate::checkDirty() -{ - Q_Q(QFxImage); - if (texDirty && !pix.isNull()) - tex = q->cachedTexture(url.toString(), pix); - texDirty = false; -} - -#if defined(QFX_RENDER_OPENGL2) -void QFxImage::paintGLContents(GLPainter &p) -{ - Q_D(QFxImage); - if (d->pix.isNull()) - return; - - QGLShaderProgram *shader = p.useTextureShader(); - - bool restoreBlend = false; - if (p.blendEnabled && isOpaque() && p.activeOpacity == 1) { - glDisable(GL_BLEND); - restoreBlend = true; - } - - d->checkDirty(); - - if (d->tiled || (!d->scaleGrid || d->scaleGrid->isNull())) { - - if (!d->tiled) { - - float widthV = width(); - float heightV = height(); - float glWidth = d->tex->glWidth(); - float glHeight = d->tex->glHeight(); - - float deltaX = 0.5 / qreal(d->tex->glSize().width()); - float deltaY = 0.5 / qreal(d->tex->glSize().height()); - glWidth -= deltaX; - glHeight -= deltaY; - - - float vert[] = { - 0, heightV, - widthV, heightV, - 0, 0, - - widthV, heightV, - 0, 0, - widthV, 0 }; - - float tex[] = { - deltaX, deltaY, - glWidth, deltaY, - deltaX, glHeight, - - glWidth, deltaY, - deltaX, glHeight, - glWidth, glHeight - }; - - shader->setAttributeArray(SingleTextureShader::Vertices, vert, 2); - shader->setAttributeArray(SingleTextureShader::TextureCoords, tex, 2); - glBindTexture(GL_TEXTURE_2D, d->tex->texture()); - glDrawArrays(GL_TRIANGLES, 0, 6); - - } else { - - GLfloat vertices[8]; - GLfloat texVertices[8]; - GLTexture *tex = 0; - - QFxImage::glSimpleItemData(vertices, texVertices, &tex, 8); - - shader->setAttributeArray(SingleTextureShader::Vertices, vertices, 2); - shader->setAttributeArray(SingleTextureShader::TextureCoords, texVertices, 2); - - glBindTexture(GL_TEXTURE_2D, tex->texture()); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - } - - } else { - - float imgWidth = d->pix.width(); - float imgHeight = d->pix.height(); - if (!imgWidth || !imgHeight) { - if (restoreBlend) - glEnable(GL_BLEND); - return; - } - - float widthV = width(); - float heightV = height(); - float glWidth = d->tex->glWidth(); - float glHeight = d->tex->glHeight(); - float deltaX = 0.5 / qreal(d->tex->glSize().width()); - float deltaY = 0.5 / qreal(d->tex->glSize().height()); - glHeight -= deltaY; - glWidth -= deltaX; - - float texleft = deltaX; - float texright = glWidth; - float textop = glHeight; - float texbottom = deltaY; - float imgleft = 0; - float imgright = widthV; - float imgtop = 0; - float imgbottom = heightV; - - const int sgl = d->scaleGrid->left(); - const int sgr = d->scaleGrid->right(); - const int sgt = d->scaleGrid->top(); - const int sgb = d->scaleGrid->bottom(); - - if (sgl) { - texleft = deltaX + d->tex->glWidth() * float(sgl) / imgWidth; - imgleft = sgl; - } - if (sgr) { - texright = d->tex->glWidth() - float(sgr) / imgWidth - deltaX; - imgright = widthV - sgr; - } - if (sgt) { - textop = d->tex->glHeight() - float(sgb) / imgHeight - deltaY; - imgtop = sgt; - } - if (sgb) { - texbottom = deltaY + d->tex->glHeight() * float(sgt) / imgHeight; - imgbottom = heightV - sgb; - } - - float vert1[] = { 0, 0, - 0, imgtop, - imgleft, 0, - - 0, imgtop, - imgleft, 0, - imgleft, imgtop, - - imgleft, 0, - imgleft, imgtop, - imgright, 0, - - imgleft, imgtop, - imgright, 0, - imgright, imgtop, - - imgright, 0, - imgright, imgtop, - widthV, 0, - - imgright, imgtop, - widthV, 0, - widthV, imgtop, - - 0, imgtop, - 0, imgbottom, - imgleft, imgtop, - - 0, imgbottom, - imgleft, imgtop, - imgleft, imgbottom, - - imgleft, imgtop, - imgleft, imgbottom, - imgright, imgtop, - - imgleft, imgbottom, - imgright, imgtop, - imgright, imgbottom, - - imgright, imgtop, - imgright, imgbottom, - widthV, imgtop, - - imgright, imgbottom, - widthV, imgtop, - widthV, imgbottom, - - 0, imgbottom, - 0, heightV, - imgleft, imgbottom, - - 0, heightV, - imgleft, imgbottom, - imgleft, heightV, - - imgleft, imgbottom, - imgleft, heightV, - imgright, imgbottom, - - imgleft, heightV, - imgright, imgbottom, - imgright, heightV, - - imgright, imgbottom, - imgright, heightV, - widthV, imgbottom, - - imgright, heightV, - widthV, imgbottom, - widthV, heightV }; - - float tex1[] = { deltaX, glHeight, - deltaX, textop, - texleft, glHeight, - - deltaX, textop, - texleft, glHeight, - texleft, textop, - - texleft, glHeight, - texleft, textop, - texright, glHeight, - - texleft, textop, - texright, glHeight, - texright, textop, - - texright, glHeight, - texright, textop, - glWidth, glHeight, - - texright, textop, - glWidth, glHeight, - glWidth, textop, - - deltaX, textop, - deltaX, texbottom, - texleft, textop, - - deltaX, texbottom, - texleft, textop, - texleft, texbottom, - - texleft, textop, - texleft, texbottom, - texright, textop, - - texleft, texbottom, - texright, textop, - texright, texbottom, - - texright, textop, - texright, texbottom, - glWidth, textop, - - texright, texbottom, - glWidth, textop, - glWidth, texbottom, - - deltaX, texbottom, - deltaX, deltaY, - texleft, texbottom, - - deltaX, deltaY, - texleft, texbottom, - texleft, deltaY, - - texleft, texbottom, - texleft, deltaY, - texright, texbottom, - - texleft, deltaY, - texright, texbottom, - texright, deltaY, - - texright, texbottom, - texright, deltaY, - glWidth, texbottom, - - texright, deltaY, - glWidth, texbottom, - glWidth, deltaY }; - - glBindTexture(GL_TEXTURE_2D, d->tex->texture()); - - shader->setAttributeArray(SingleTextureShader::Vertices, vert1, 2); - shader->setAttributeArray(SingleTextureShader::TextureCoords, tex1, 2); - glDrawArrays(GL_TRIANGLES, 0, 54); - } - - if (restoreBlend) - glEnable(GL_BLEND); -} -#endif - -#endif QString QFxImage::propertyInfo() const { @@ -870,13 +518,6 @@ void QFxImage::setSource(const QUrl &url) d->progress = 1.0; setImplicitWidth(0); setImplicitHeight(0); -#if defined(QFX_RENDER_OPENGL) - d->texDirty = true; - if (d->tex) { - d->tex->release(); - d->tex = 0; - } -#endif emit statusChanged(d->status); emit sourceChanged(d->url); emit progressChanged(1.0); @@ -934,13 +575,6 @@ void QFxImage::requestFinished() if (d->status == Loading) d->status = Idle; d->progress = 1.0; -#if defined(QFX_RENDER_OPENGL) - d->texDirty = true; - if (d->tex) { - d->tex->release(); - d->tex = 0; - } -#endif emit statusChanged(d->status); emit sourceChanged(d->url); emit progressChanged(1.0); diff --git a/src/declarative/fx/qfximage.h b/src/declarative/fx/qfximage.h index 3071a9e..925a520 100644 --- a/src/declarative/fx/qfximage.h +++ b/src/declarative/fx/qfximage.h @@ -91,15 +91,8 @@ public: QUrl source() const; virtual void setSource(const QUrl &url); - virtual void dump(int depth); virtual QString propertyInfo() const; -#if defined(QFX_RENDER_QPAINTER) void paintContents(QPainter &painter); -#elif defined(QFX_RENDER_OPENGL) - void paintGLContents(GLPainter &); - uint glSimpleItemData(float *vertices, float *texVertices, - GLTexture **texture, uint count); -#endif Q_SIGNALS: void sourceChanged(const QUrl &); @@ -117,7 +110,7 @@ private Q_SLOTS: private: Q_DISABLE_COPY(QFxImage) - Q_DECLARE_PRIVATE(QFxImage) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxImage) void setGridScaledImage(const QFxGridScaledImage& sci); }; diff --git a/src/declarative/fx/qfximage_p.h b/src/declarative/fx/qfximage_p.h index 1785abb..e4a3a90 100644 --- a/src/declarative/fx/qfximage_p.h +++ b/src/declarative/fx/qfximage_p.h @@ -55,10 +55,6 @@ #include "qfxitem_p.h" -#if defined(QFX_RENDER_OPENGL) -#include "gltexture.h" -#endif - QT_BEGIN_NAMESPACE class QSvgRenderer; @@ -73,9 +69,6 @@ class QFxImagePrivate : public QFxItemPrivate public: QFxImagePrivate() : scaleGrid(0), tiled(false), smooth(false), opaque(false), -#if defined(QFX_RENDER_OPENGL) - texDirty(true), tex(0), -#endif status(QFxImage::Idle), sciReply(0), progress(0.0) { } @@ -99,11 +92,6 @@ public: bool tiled : 1; bool smooth : 1; bool opaque : 1; -#if defined(QFX_RENDER_OPENGL) - bool texDirty : 1; - void checkDirty(); - QSimpleCanvasItem::CachedTexture *tex; -#endif QFxImage::Status status; QUrl url; diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index 223af60..da4f1b3 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -62,7 +62,6 @@ #include "qfxitem_p.h" #include "qfxitem.h" #include "qfxevents_p.h" -#include <qsimplecanvasfilter.h> #include <qmlcomponent.h> QT_BEGIN_NAMESPACE @@ -73,7 +72,6 @@ QT_BEGIN_NAMESPACE QML_DEFINE_NOCREATE_TYPE(QFxContents) QML_DEFINE_TYPE(QFxItem,Item) -QML_DEFINE_NOCREATE_TYPE(QSimpleCanvasFilter) /*! \group group_animation @@ -162,9 +160,9 @@ void QFxContents::calcHeight() qreal top = FLT_MAX; qreal bottom = 0; - const QList<QSimpleCanvasItem *> &children = m_item->QSimpleCanvasItem::children(); + QList<QGraphicsItem *> children = m_item->childItems(); for (int i = 0; i < children.count(); ++i) { - const QSimpleCanvasItem *child = children.at(i); + QFxItem *child = qobject_cast<QFxItem *>(children.at(i)); qreal y = child->y(); if (y + child->height() > bottom) bottom = y + child->height(); @@ -185,10 +183,10 @@ void QFxContents::calcWidth() qreal left = FLT_MAX; qreal right = 0; - const QList<QSimpleCanvasItem *> &children = m_item->QSimpleCanvasItem::children(); + QList<QGraphicsItem *> children = m_item->childItems(); for (int i = 0; i < children.count(); ++i) { - const QSimpleCanvasItem *child = children.at(i); - qreal x = int(child->x()); + QFxItem *child = qobject_cast<QFxItem *>(children.at(i)); + qreal x = child->x(); if (x + child->width() > right) right = x + child->width(); if (x < left) @@ -204,9 +202,9 @@ void QFxContents::setItem(QFxItem *item) { m_item = item; - const QList<QSimpleCanvasItem *> &children = m_item->QSimpleCanvasItem::children(); + QList<QGraphicsItem *> children = m_item->childItems(); for (int i = 0; i < children.count(); ++i) { - const QSimpleCanvasItem *child = children.at(i); + QFxItem *child = qobject_cast<QFxItem *>(children.at(i)); connect(child, SIGNAL(heightChanged()), this, SLOT(calcHeight())); connect(child, SIGNAL(yChanged()), this, SLOT(calcHeight())); connect(child, SIGNAL(widthChanged()), this, SLOT(calcWidth())); @@ -384,7 +382,7 @@ void QFxContents::setItem(QFxItem *item) This signal is emitted when the item's focus state changes. - \sa QSimpleCanvasItem::setFocus() + \sa QFxItem::setFocus() */ /*! @@ -393,7 +391,7 @@ void QFxContents::setItem(QFxItem *item) Constructs a QFxItem with the given \a parent. */ QFxItem::QFxItem(QFxItem* parent) - : QSimpleCanvasItem(*(new QFxItemPrivate), parent) + : QGraphicsObject(*(new QFxItemPrivate), parent, 0) { Q_D(QFxItem); d->init(parent); @@ -402,7 +400,7 @@ QFxItem::QFxItem(QFxItem* parent) /*! \internal */ QFxItem::QFxItem(QFxItemPrivate &dd, QFxItem *parent) - : QSimpleCanvasItem(dd, parent) + : QGraphicsObject(dd, parent, 0) { Q_D(QFxItem); d->init(parent); @@ -535,7 +533,12 @@ void QFxItem::moveToParent(QFxItem *parent) */ QFxItem *QFxItem::itemParent() const { - return qobject_cast<QFxItem *>(QObject::parent()); + return qobject_cast<QFxItem *>(QGraphicsItem::parentItem()); +} + +QFxItem *QFxItem::parentItem() const +{ + return itemParent(); } /*! @@ -699,7 +702,7 @@ int QFxItemPrivate::children_count() const void QFxItemPrivate::children_append(QFxItem *i) { Q_Q(QFxItem); - i->setParent(q); + i->setParentItem(q); } void QFxItemPrivate::children_insert(int, QFxItem *) @@ -787,6 +790,16 @@ QFxContents *QFxItem::contents() return d->_contents; } +bool QFxItem::clip() const +{ + return flags() & ItemClipsChildrenToShape; +} + +void QFxItem::setClip(bool c) +{ + setFlag(ItemClipsChildrenToShape, c); +} + /*! \internal \property QFxItem::qmlItem @@ -1091,52 +1104,6 @@ void QFxItem::geometryChanged(const QRectF &newGeometry, } } -/*! - \qmlproperty bool Item::flipVertically - \qmlproperty bool Item::flipHorizontally - - When set, the item will be displayed flipped horizontally or vertically - about its center. - */ - -/*! - \property QFxItem::flipVertically - - When set, the item will be displayed flipped horizontally or vertically - about its center. - */ -bool QFxItem::flipVertically() const -{ - return flip() & VerticalFlip; -} - -void QFxItem::setFlipVertically(bool v) -{ - if (v) - setFlip((QSimpleCanvasItem::Flip)(flip() | VerticalFlip)); - else - setFlip((QSimpleCanvasItem::Flip)(flip() & ~VerticalFlip)); -} - -/*! - \property QFxItem::flipHorizontally - - When set, the item will be displayed flipped horizontally or vertically - about its center. - */ -bool QFxItem::flipHorizontally() const -{ - return flip() & HorizontalFlip; -} - -void QFxItem::setFlipHorizontally(bool v) -{ - if (v) - setFlip((QSimpleCanvasItem::Flip)(flip() | HorizontalFlip)); - else - setFlip((QSimpleCanvasItem::Flip)(flip() & ~HorizontalFlip)); -} - /*! \fn void QFxItem::keyPress(QFxKeyEvent *event) This signal is emitted by keyPressEvent() for the \a event. */ @@ -1503,18 +1470,10 @@ void QFxItem::setRotation(qreal rotation) if (d->_rotation == rotation) return; d->_rotation = rotation; -#if defined(QFX_RENDER_OPENGL) - QMatrix4x4 trans; - QPointF to = transformOriginPoint(); - trans.translate(to.x(), to.y()); - trans.rotate(d->_rotation, 0, 0, 1); - trans.translate(-to.x(), -to.y()); -#else QPointF to = d->transformOrigin(); QTransform trans = QTransform::fromTranslate(to.x(), to.y()); trans.rotate(d->_rotation); trans.translate(-to.x(), -to.y()); -#endif setTransform(trans); emit rotationChanged(); } @@ -1569,18 +1528,6 @@ void QFxItem::setRotation(qreal rotation) Scaling is from the item's transformOrigin. */ -qreal QFxItem::scale() const -{ - return QSimpleCanvasItem::scale(); -} - -void QFxItem::setScale(qreal s) -{ - if (QSimpleCanvasItem::scale() == s) return; - QSimpleCanvasItem::setScale(s); - emit scaleChanged(); - update(); -} /*! \qmlproperty real Item::opacity @@ -1638,19 +1585,12 @@ void QFxItem::setScale(qreal s) also applied individually to child items. */ -qreal QFxItem::opacity() const -{ - return QSimpleCanvasItem::visible(); -} - void QFxItem::setOpacity(qreal v) { - if (v == QSimpleCanvasItem::visible()) + if (v == opacity()) return; - if (v < 0) v = 0; - else if (v > 1) v = 1; - QSimpleCanvasItem::setVisible(v); + QGraphicsItem::setOpacity(v); emit opacityChanged(); } @@ -1958,14 +1898,6 @@ void QFxItem::setVisible(bool visible) /*! \internal */ -void QFxItem::dump(int depth) -{ - QByteArray ba(depth * 4, ' '); - qWarning() << ba.constData() << metaObject()->className() << "(" << (void *)static_cast<QFxItem*>(this) << ", " << (void *)static_cast<QSimpleCanvasItem*>(this) << "):" << x() << y() << width() << height() << (void *) itemParent(); -} - -/*! \internal -*/ QString QFxItem::propertyInfo() const { return QString(); @@ -2045,27 +1977,13 @@ void QFxItem::componentComplete() updateTransform(); } -/*! \internal -*/ -void QFxItem::parentChanged(QSimpleCanvasItem *, QSimpleCanvasItem *) -{ - emit parentChanged(); -} - -/*! \internal -*/ -void QFxItem::reparentItems() -{ - qFatal("EEK"); -} - /*! \internal */ void QFxItem::updateTransform() { Q_D(QFxItem); - QSimpleCanvas::Matrix trans; + QTransform trans; for (int ii = d->_transform.count() - 1; ii >= 0; --ii) { QFxTransform *a = d->_transform.at(ii); if (!a->isIdentity()) @@ -2079,7 +1997,7 @@ void QFxItem::updateTransform() /*! \internal */ -void QFxItem::transformChanged(const QSimpleCanvas::Matrix &) +void QFxItem::transformChanged(const QTransform &) { } @@ -2115,4 +2033,507 @@ QFxItemPrivate::AnchorLines::AnchorLines(QFxItem *q) baseline.anchorLine = QFxAnchorLine::Baseline; } +QPointF QFxItemPrivate::transformOrigin() const +{ + Q_Q(const QFxItem); + + QRectF br = q->boundingRect(); + + switch(origin) { + default: + case QFxItem::TopLeft: + return QPointF(0, 0); + case QFxItem::TopCenter: + return QPointF(br.width() / 2., 0); + case QFxItem::TopRight: + return QPointF(br.width(), 0); + case QFxItem::MiddleLeft: + return QPointF(0, br.height() / 2.); + case QFxItem::Center: + return QPointF(br.width() / 2., br.height() / 2.); + case QFxItem::MiddleRight: + return QPointF(br.width(), br.height() / 2.); + case QFxItem::BottomLeft: + return QPointF(0, br.height()); + case QFxItem::BottomCenter: + return QPointF(br.width() / 2., br.height()); + case QFxItem::BottomRight: + return QPointF(br.width(), br.height()); + } +} + +QFxItem::Options QFxItem::options() const +{ + Q_D(const QFxItem); + return (QFxItem::Options)d->options; +} + +bool QFxItem::mouseFilter(QGraphicsSceneMouseEvent *) +{ + return false; +} + +bool QFxItem::sceneEvent(QEvent *event) +{ + bool rv = QGraphicsItem::sceneEvent(event); + if (event->type() == QEvent::UngrabMouse) + mouseUngrabEvent(); + return rv; +} + +QVariant QFxItem::itemChange(GraphicsItemChange change, + const QVariant &value) +{ + Q_D(QFxItem); + if (change == ItemSceneHasChanged) { + if (options() & QFxItem::MouseFilter) + d->gvRemoveMouseFilter(); + + d->canvas = qvariant_cast<QGraphicsScene *>(value); + + if (options() & QFxItem::MouseFilter) + d->gvAddMouseFilter(); + } else if (change == ItemChildAddedChange || + change == ItemChildRemovedChange) { + childrenChanged(); + } + + return QGraphicsItem::itemChange(change, value); +} + + +void QFxItem::mouseUngrabEvent() +{ +} + +void QFxItem::childrenChanged() +{ +} + +void QFxItem::setPaintMargin(qreal margin) +{ + Q_D(QFxItem); + if (margin < d->paintmargin) + update(); // schedule repaint of old boundingRect + d->paintmargin = margin; +} + +QRectF QFxItem::boundingRect() const +{ + Q_D(const QFxItem); + return QRectF(-d->paintmargin, -d->paintmargin, d->width+d->paintmargin*2, d->height+d->paintmargin*2); +} + +void QFxItem::paintContents(QPainter &) +{ +} + +void QFxItem::parentChanged(QFxItem *, QFxItem *) +{ + emit parentChanged(); +} + +/*! + Returns the item's (0, 0) point relative to its parent. + */ +QPointF QFxItem::pos() const +{ + return QPointF(x(),y()); +} + +/*! + Returns the item's (0, 0) point mapped to scene coordinates. + */ +QPointF QFxItem::scenePos() const +{ + return mapToScene(QPointF(0, 0)); +} + +/*! + \enum QFxItem::TransformOrigin + + Controls the point about which simple transforms like scale apply. + + \value TopLeft The top-left corner of the item. + \value TopCenter The center point of the top of the item. + \value TopRight The top-right corner of the item. + \value MiddleLeft The left most point of the vertical middle. + \value Center The center of the item. + \value MiddleRight The right most point of the vertical middle. + \value BottomLeft The bottom-left corner of the item. + \value BottomCenter The center point of the bottom of the item. + \value BottomRight The bottom-right corner of the item. +*/ + +/*! + Returns the current transform origin. +*/ +QFxItem::TransformOrigin QFxItem::transformOrigin() const +{ + Q_D(const QFxItem); + return d->origin; +} + +/*! + Set the transform \a origin. +*/ +void QFxItem::setTransformOrigin(TransformOrigin origin) +{ + Q_D(QFxItem); + if (origin != d->origin) { + d->origin = origin; + update(); + } +} + +QPointF QFxItem::transformOriginPoint() const +{ + Q_D(const QFxItem); + return d->transformOrigin(); +} + +void QFxItem::setFocus(bool focus) +{ + Q_UNUSED(focus) + return; +} + +qreal QFxItem::z() const +{ + Q_D(const QFxItem); + return zValue(); +} + +void QFxItem::setX(qreal x) +{ + Q_D(QFxItem); + if (x == this->x()) + return; + + qreal oldX = this->x(); + + QGraphicsItem::setPos(x, y()); + + geometryChanged(QRectF(this->x(), y(), width(), height()), + QRectF(oldX, y(), width(), height())); +} + +void QFxItem::setY(qreal y) +{ + if (y == this->y()) + return; + + qreal oldY = this->y(); + + QGraphicsItem::setPos(x(), y); + + geometryChanged(QRectF(x(), this->y(), width(), height()), + QRectF(x(), oldY, width(), height())); +} + +void QFxItem::setZ(qreal z) +{ + if (z == this->z()) + return; + + if (z < 0) + setFlag(QGraphicsItem::ItemStacksBehindParent, true); + else + setFlag(QGraphicsItem::ItemStacksBehindParent, false); + + setZValue(z); +} + +qreal QFxItem::width() const +{ + Q_D(const QFxItem); + return d->width; +} + +void QFxItem::setWidth(qreal w) +{ + Q_D(QFxItem); + d->widthValid = true; + if (d->width == w) + return; + + qreal oldWidth = d->width; + + d->width = w; + update(); + + geometryChanged(QRectF(x(), y(), width(), height()), + QRectF(x(), y(), oldWidth, height())); +} + +void QFxItem::setImplicitWidth(qreal w) +{ + Q_D(QFxItem); + if (d->width == w || widthValid()) + return; + + qreal oldWidth = d->width; + + d->width = w; + update(); + + geometryChanged(QRectF(x(), y(), width(), height()), + QRectF(x(), y(), oldWidth, height())); +} + +bool QFxItem::widthValid() const +{ + Q_D(const QFxItem); + return d->widthValid; +} + +qreal QFxItem::height() const +{ + Q_D(const QFxItem); + return d->height; +} + +void QFxItem::setHeight(qreal h) +{ + Q_D(QFxItem); + d->heightValid = true; + if (d->height == h) + return; + + qreal oldHeight = d->height; + + d->height = h; + update(); + + geometryChanged(QRectF(x(), y(), width(), height()), + QRectF(x(), y(), width(), oldHeight)); +} + +void QFxItem::setImplicitHeight(qreal h) +{ + Q_D(QFxItem); + if (d->height == h || heightValid()) + return; + + qreal oldHeight = d->height; + + d->height = h; + update(); + + geometryChanged(QRectF(x(), y(), width(), height()), + QRectF(x(), y(), width(), oldHeight)); +} + +bool QFxItem::heightValid() const +{ + Q_D(const QFxItem); + return d->heightValid; +} + +void QFxItem::setPos(const QPointF &point) +{ + qreal oldX = x(); + qreal oldY = y(); + + QGraphicsItem::setPos(point); + + geometryChanged(QRectF(x(), y(), width(), height()), + QRectF(oldX, oldY, width(), height())); +} + +qreal QFxItem::scale() const +{ + Q_D(const QFxItem); + return d->scale; +} + +void QFxItem::setScale(qreal s) +{ + Q_D(QFxItem); + if (d->scale == s) + return; + + d->scale = s; + QTransform t; + QPointF to = transformOriginPoint(); + if (to.x() != 0. || to.y() != 0.) + t.translate(to.x(), to.y()); + t.scale(s, s); + if (to.x() != 0. || to.y() != 0.) + t.translate(-to.x(), -to.y()); + setTransform(t * d->transform); + + emit scaleChanged(); +} + +QRect QFxItem::itemBoundingRect() +{ + return boundingRect().toAlignedRect(); +} + +QPointF QFxItem::mapFromScene(const QPointF &p) const +{ + return QGraphicsItem::mapFromScene(p); +} + +QRectF QFxItem::mapFromScene(const QRectF &r) const +{ + return QGraphicsItem::mapFromScene(r).boundingRect(); +} + +QPointF QFxItem::mapToScene(const QPointF &p) const +{ + return QGraphicsItem::mapToScene(p); +} + +QRectF QFxItem::mapToScene(const QRectF &r) const +{ + return QGraphicsItem::mapToScene(r).boundingRect(); +} + +QTransform QFxItem::transform() const +{ + Q_D(const QFxItem); + return d->transform; +} + +void QFxItem::setTransform(const QTransform &m) +{ + Q_D(QFxItem); + d->transform = m; + QGraphicsItem::setTransform(QTransform::fromScale(d->scale, d->scale) * d->transform); +} + +QFxItem *QFxItem::mouseGrabberItem() const +{ + QGraphicsScene *s = scene(); + if (s) { + QGraphicsItem *item = s->mouseGrabberItem(); + return static_cast<QFxItem*>(item); // ### + } + return 0; +} + +bool QFxItem::isFocusable() const +{ + return false; +} + +void QFxItem::setFocusable(bool) +{ +} + +bool QFxItem::hasFocus() const +{ + return false; +} + +bool QFxItem::eventFilter(QObject *o, QEvent *e) +{ + switch(e->type()) { + case QEvent::GraphicsSceneMouseDoubleClick: + case QEvent::GraphicsSceneMouseMove: + case QEvent::GraphicsSceneMousePress: + case QEvent::GraphicsSceneMouseRelease: + if (mouseFilter(static_cast<QGraphicsSceneMouseEvent *>(e))) + return true; + break; + default: + break; + } + + return QObject::eventFilter(o, e); +} + +void QFxItem::setOptions(Options options, bool set) +{ + Q_D(QFxItem); + Options old = (Options)d->options; + + if (set) + d->options |= options; + else + d->options &= ~options; + + if ((d->options & IsFocusPanel) && (d->options & IsFocusRealm)) { + qWarning("QFxItem::setOptions: Cannot set both IsFocusPanel and IsFocusRealm. IsFocusRealm will be unset."); + d->options &= ~IsFocusRealm; + } + + setFlag(QGraphicsItem::ItemHasNoContents, !(d->options & HasContents)); + + if ((old & MouseFilter) != (d->options & MouseFilter)) { + if (d->options & MouseFilter) + d->gvAddMouseFilter(); + else + d->gvRemoveMouseFilter(); + } +} + +/*! + \fn void QFxItem::setParent(QFxItem *parent) + + Sets the parent of the item to \a parent. + */ +void QFxItem::setParent(QFxItem *p) +{ + Q_D(QFxItem); + if (p == parent() || !p) return; + + QObject::setParent(p); + + QFxItem *oldParent = itemParent(); + setParentItem(p); + parentChanged(p, oldParent); +} + +bool QFxItem::activeFocusPanel() const +{ + return false; +} + +void QFxItem::setActiveFocusPanel(bool b) +{ + Q_UNUSED(b) +} + +bool QFxItem::hasActiveFocus() const +{ + return false; +} + +void QFxItem::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) +{ + paintContents(*p); +} + +void QFxItemPrivate::gvRemoveMouseFilter() +{ + Q_Q(QFxItem); + if (!canvas) return; + + canvas->removeEventFilter(q); +} + +void QFxItemPrivate::gvAddMouseFilter() +{ + Q_Q(QFxItem); + if (!canvas) return; + + canvas->installEventFilter(q); +} + +QPixmap QFxItem::string(const QString &str, const QColor &c, const QFont &f) +{ + QFontMetrics fm(f); + QSize size(fm.width(str), fm.height()*(str.count(QLatin1Char('\n'))+1)); //fm.boundingRect(str).size(); + QPixmap img(size); + img.fill(Qt::transparent); + QPainter p(&img); + p.setPen(c); + p.setFont(f); + p.drawText(img.rect(), Qt::AlignVCenter, str); + return img; +} + QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxitem.h b/src/declarative/fx/qfxitem.h index 5fb4eff..bb48d16 100644 --- a/src/declarative/fx/qfxitem.h +++ b/src/declarative/fx/qfxitem.h @@ -49,9 +49,10 @@ #include <QtDeclarative/qfxglobal.h> #include <QtDeclarative/qml.h> #include <QtDeclarative/qfxscalegrid.h> -#include <QtDeclarative/qsimplecanvasitem.h> #include <QtDeclarative/qmlcomponent.h> #include <QtDeclarative/qmlstate.h> +#include <QtGui/qgraphicsitem.h> +#include <QtGui/qfont.h> QT_BEGIN_HEADER @@ -93,7 +94,7 @@ class QmlTransition; class QFxTransform; class QFxKeyEvent; class QFxItemPrivate; -class Q_DECLARATIVE_EXPORT QFxItem : public QSimpleCanvasItem, public QmlParserStatus +class Q_DECLARATIVE_EXPORT QFxItem : public QGraphicsObject, public QmlParserStatus { Q_OBJECT Q_INTERFACES(QmlParserStatus) @@ -124,27 +125,46 @@ class Q_DECLARATIVE_EXPORT QFxItem : public QSimpleCanvasItem, public QmlParserS Q_PROPERTY(QFxAnchorLine verticalCenter READ verticalCenter CONSTANT) Q_PROPERTY(QFxAnchorLine baseline READ baseline CONSTANT) Q_PROPERTY(qreal baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged) - Q_PROPERTY(bool flipVertically READ flipVertically WRITE setFlipVertically) - Q_PROPERTY(bool flipHorizontally READ flipHorizontally WRITE setFlipHorizontally) Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged) Q_PROPERTY(qreal scale READ scale WRITE setScale NOTIFY scaleChanged) Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged) - Q_PROPERTY(QSimpleCanvasFilter *filter READ filter WRITE setFilter) Q_PROPERTY(bool clip READ clip WRITE setClip) Q_PROPERTY(bool focusable READ isFocusable WRITE setFocusable) Q_PROPERTY(bool focus READ hasFocus WRITE setFocus NOTIFY focusChanged) Q_PROPERTY(bool activeFocus READ hasActiveFocus NOTIFY activeFocusChanged) Q_PROPERTY(QList<QFxTransform *>* transform READ transform) - Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibleChanged) + Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) + Q_PROPERTY(TransformOrigin transformOrigin READ transformOrigin WRITE setTransformOrigin) + Q_ENUMS(TransformOrigin) Q_CLASSINFO("DefaultProperty", "data") typedef QHash<QString, QFxItem *> QmlChildren; public: + enum Option { NoOption = 0x00000000, + MouseFilter = 0x00000003, // ### GV + ChildMouseFilter = 0x00000002, + HoverEvents = 0x00000004, + MouseEvents = 0x00000008, + HasContents = 0x00000010, + SimpleItem = 0x00000020, + IsFocusPanel = 0x00000040, + IsFocusRealm = 0x00000080, + AcceptsInputMethods = 0x00000100, + IsOpaque = 0x00000200 }; + Q_DECLARE_FLAGS(Options, Option) + + enum TransformOrigin { + TopLeft, TopCenter, TopRight, + MiddleLeft, Center, MiddleRight, + BottomLeft, BottomCenter, BottomRight + }; + QFxItem(QFxItem *parent = 0); virtual ~QFxItem(); QFxItem *itemParent() const; + QFxItem *parentItem() const; void setItemParent(QFxItem *parent); void moveToParent(QFxItem *parent); @@ -160,6 +180,9 @@ public: QFxContents *contents(); + bool clip() const; + void setClip(bool); + QmlList<QmlState *>* states(); QmlState *findState(const QString &name) const; @@ -172,11 +195,6 @@ public: QUrl qml() const; void setQml(const QUrl &); - bool flipVertically() const; - void setFlipVertically(bool); - bool flipHorizontally() const; - void setFlipHorizontally(bool); - qreal baselineOffset() const; void setBaselineOffset(qreal); @@ -186,15 +204,13 @@ public: qreal scale() const; void setScale(qreal); - qreal opacity() const; - virtual void setOpacity(qreal); + void setOpacity(qreal); QList<QFxTransform *> *transform(); bool isVisible() const; void setVisible(bool); - virtual void dump(int depth = 0); virtual QString propertyInfo() const; bool isClassComplete() const; @@ -207,6 +223,60 @@ public: bool keepMouseGrab() const; void setKeepMouseGrab(bool); + Options options() const; + void setOptions(Options, bool set = true); + + qreal z() const; + QPointF pos() const; + void setX(qreal); + void setY(qreal); + virtual void setZ(qreal); + void setPos(const QPointF &); + + qreal width() const; + void setWidth(qreal); + void setImplicitWidth(qreal); + bool widthValid() const; + qreal height() const; + void setHeight(qreal); + void setImplicitHeight(qreal); + bool heightValid() const; + + QPointF scenePos() const; + + TransformOrigin transformOrigin() const; + void setTransformOrigin(TransformOrigin); + QPointF transformOriginPoint() const; + + void setParent(QFxItem *); + + QRect itemBoundingRect(); + + void setPaintMargin(qreal margin); + QRectF boundingRect() const; + virtual void paintContents(QPainter &); + + QPointF mapFromScene(const QPointF &) const; + QRectF mapFromScene(const QRectF &) const; + QPointF mapToScene(const QPointF &) const; + QRectF mapToScene(const QRectF &) const; + + QTransform transform() const; + void setTransform(const QTransform &); + + QFxItem *mouseGrabberItem() const; + + virtual bool isFocusable() const; + void setFocusable(bool); + virtual bool hasFocus() const; + void setFocus(bool); + bool activeFocusPanel() const; + void setActiveFocusPanel(bool); + + bool hasActiveFocus() const; + + static QPixmap string(const QString &, const QColor & = Qt::black, const QFont & = QFont()); + public Q_SLOTS: void newChild(const QString &url); @@ -230,12 +300,19 @@ Q_SIGNALS: void newChildCreated(const QString &url, QScriptValue); protected: - virtual void transformChanged(const QSimpleCanvas::Matrix &); + virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); + virtual void childrenChanged(); + virtual bool eventFilter(QObject *, QEvent *); + virtual bool sceneEvent(QEvent *); + virtual QVariant itemChange(GraphicsItemChange, const QVariant &); + virtual bool mouseFilter(QGraphicsSceneMouseEvent *); + virtual void mouseUngrabEvent(); + + virtual void transformChanged(const QTransform &); virtual void classBegin(); virtual void classComplete(); virtual void componentComplete(); - virtual void parentChanged(QSimpleCanvasItem *, QSimpleCanvasItem *); - virtual void reparentItems(); + virtual void parentChanged(QFxItem *, QFxItem *); virtual void focusChanged(bool); virtual void activeFocusChanged(bool); void keyPressEvent(QKeyEvent *event); @@ -263,14 +340,23 @@ private: friend class QmlStatePrivate; friend class QFxAnchors; Q_DISABLE_COPY(QFxItem) - Q_DECLARE_PRIVATE(QFxItem) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxItem) }; +Q_DECLARE_OPERATORS_FOR_FLAGS(QFxItem::Options) + +template<typename T> +T qobject_cast(QGraphicsItem *item) +{ + if (!item) return 0; + QObject *o = item->toGraphicsObject(); + return qobject_cast<T>(o); +} + QT_END_NAMESPACE QML_DECLARE_TYPE(QFxContents) QML_DECLARE_TYPE(QFxItem) -QML_DECLARE_TYPE(QSimpleCanvasFilter) QT_END_HEADER diff --git a/src/declarative/fx/qfxitem_p.h b/src/declarative/fx/qfxitem_p.h index 32e8aef..93bcf6c 100644 --- a/src/declarative/fx/qfxitem_p.h +++ b/src/declarative/fx/qfxitem_p.h @@ -54,17 +54,18 @@ // #include <QtDeclarative/qfxitem.h> -#include <private/qsimplecanvasitem_p.h> #include <private/qmlnullablevalue_p.h> #include <QtDeclarative/qml.h> #include <QtDeclarative/qmlcontext.h> #include <QtCore/qlist.h> +#include <private/qgraphicsitem_p.h> +#include <QtCore/qdebug.h> QT_BEGIN_NAMESPACE class QNetworkReply; -class QFxItemPrivate : public QSimpleCanvasItemPrivate +class QFxItemPrivate : public QGraphicsItemPrivate { Q_DECLARE_PUBLIC(QFxItem) @@ -75,8 +76,11 @@ public: : _anchors(0), _contents(0), qmlItem(0), _qmlcomp(0), _baselineOffset(0), _rotation(0.), _classComplete(true), _componentComplete(true), _keepMouse(false), - visible(true), _anchorLines(0), visibleOp(1), reparentedChildren(0), - _stateGroup(0) + visible(true), _anchorLines(0), visibleOp(1), + _stateGroup(0), canvas(0), origin(QFxItem::TopLeft), + options(QFxItem::NoOption), + widthValid(false), heightValid(false), width(0), height(0), + paintmargin(0), scale(1) {} ~QFxItemPrivate() { delete _anchors; } @@ -89,6 +93,7 @@ public: q->setItemParent(parent); _baselineOffset.invalidate(); q->setAcceptedMouseButtons(Qt::NoButton); + q->setFlag(QGraphicsItem::ItemHasNoContents, true); } QString _id; @@ -168,10 +173,27 @@ public: float visibleOp; - int reparentedChildren; - QmlStateGroup *states(); QmlStateGroup *_stateGroup; + + + QGraphicsScene *canvas; + + QFxItem::TransformOrigin origin:4; + int options:10; + bool widthValid:1; + bool heightValid:1; + + qreal width; + qreal height; + qreal paintmargin; + qreal scale; + + QPointF transformOrigin() const; + QTransform transform; + + void gvRemoveMouseFilter(); + void gvAddMouseFilter(); }; QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxkeyactions.cpp b/src/declarative/fx/qfxkeyactions.cpp index 4aae74f..2c662a6 100644 --- a/src/declarative/fx/qfxkeyactions.cpp +++ b/src/declarative/fx/qfxkeyactions.cpp @@ -41,7 +41,7 @@ #include "qfxkeyactions.h" #include <qmlexpression.h> - +#include <QKeyEvent> QT_BEGIN_NAMESPACE QML_DEFINE_TYPE(QFxKeyActions,KeyActions) diff --git a/src/declarative/fx/qfxkeyproxy.cpp b/src/declarative/fx/qfxkeyproxy.cpp index e80f2c7..e76a9b7 100644 --- a/src/declarative/fx/qfxkeyproxy.cpp +++ b/src/declarative/fx/qfxkeyproxy.cpp @@ -93,24 +93,12 @@ QList<QFxItem *> *QFxKeyProxy::targets() const void QFxKeyProxy::keyPressEvent(QKeyEvent *e) { - for (int ii = 0; ii < d->targets.count(); ++ii) { - QSimpleCanvasItem *i = canvas()->focusItem(d->targets.at(ii)); - if (i) - i->keyPressEvent(e); - if (e->isAccepted()) - return; - } + // ### GV } void QFxKeyProxy::keyReleaseEvent(QKeyEvent *e) { - for (int ii = 0; ii < d->targets.count(); ++ii) { - QSimpleCanvasItem *i = canvas()->focusItem(d->targets.at(ii)); - if (i) - i->keyReleaseEvent(e); - if (e->isAccepted()) - return; - } + // ### GV } QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxlayouts.cpp b/src/declarative/fx/qfxlayouts.cpp index 20e7c7c..f71b35a 100644 --- a/src/declarative/fx/qfxlayouts.cpp +++ b/src/declarative/fx/qfxlayouts.cpp @@ -311,8 +311,9 @@ void QFxBaseLayout::preLayout() QCoreApplication::postEvent(this, new QEvent(QEvent::User)); } QSet<QFxItem *> allItems; - for (int ii = 0; ii < this->QSimpleCanvasItem::children().count(); ++ii) { - QFxItem *child = qobject_cast<QFxItem *>(this->QSimpleCanvasItem::children().at(ii)); + QList<QGraphicsItem *> children = childItems(); + for (int ii = 0; ii < children.count(); ++ii) { + QFxItem *child = qobject_cast<QFxItem *>(children.at(ii)); if (!child) continue; if (!d->_items.contains(child)){ @@ -618,8 +619,10 @@ void QFxVerticalLayout::doLayout() applyRemove(changes, item); } } - for (int ii = 0; ii < this->QSimpleCanvasItem::children().count(); ++ii) { - QFxItem *child = qobject_cast<QFxItem *>(this->QSimpleCanvasItem::children().at(ii)); + + QList<QGraphicsItem *> children = childItems(); + for (int ii = 0; ii < children.count(); ++ii) { + QFxItem *child = qobject_cast<QFxItem *>(children.at(ii)); if (!child || !child->isVisible()) continue; @@ -784,8 +787,9 @@ void QFxHorizontalLayout::doLayout() applyRemove(changes, item); } } - for (int ii = 0; ii < this->QSimpleCanvasItem::children().count(); ++ii) { - QFxItem *child = qobject_cast<QFxItem *>(this->QSimpleCanvasItem::children().at(ii)); + QList<QGraphicsItem *> children = childItems(); + for (int ii = 0; ii < children.count(); ++ii) { + QFxItem *child = qobject_cast<QFxItem *>(children.at(ii)); if (!child || !child->isVisible()) continue; @@ -1013,15 +1017,17 @@ void QFxGridLayout::doLayout() QList<int> maxColWidth; QList<int> maxRowHeight; int childIndex =0; + QList<QGraphicsItem *> children = childItems(); for (int i=0; i<r; i++){ for (int j=0; j<c; j++){ if (j==0) maxRowHeight << 0; if (i==0) maxColWidth << 0; - if (childIndex == this->QSimpleCanvasItem::children().count()) + + if (childIndex == children.count()) continue; - QFxItem *child = qobject_cast<QFxItem *>(this->QSimpleCanvasItem::children().at(childIndex++)); + QFxItem *child = qobject_cast<QFxItem *>(children.at(childIndex++)); if (!child || !child->isVisible()) continue; if (child->width() > maxColWidth[j]) @@ -1041,7 +1047,7 @@ void QFxGridLayout::doLayout() applyRemove(changes, item); } } - foreach(QSimpleCanvasItem* schild, this->QSimpleCanvasItem::children()){ + foreach(QGraphicsItem* schild, children){ QFxItem *child = qobject_cast<QFxItem *>(schild); if (!child || !child->isVisible()) continue; diff --git a/src/declarative/fx/qfxlayouts.h b/src/declarative/fx/qfxlayouts.h index 112fe85..5767bc5 100644 --- a/src/declarative/fx/qfxlayouts.h +++ b/src/declarative/fx/qfxlayouts.h @@ -115,7 +115,7 @@ private: void applyTransition(const QList<QPair<QString, QVariant> >& changes, QFxItem* target, QmlTransition* transition); Q_DISABLE_COPY(QFxBaseLayout) - Q_DECLARE_PRIVATE(QFxBaseLayout) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxBaseLayout) }; class Q_DECLARATIVE_EXPORT QFxVerticalLayout : public QFxBaseLayout diff --git a/src/declarative/fx/qfxlistview.h b/src/declarative/fx/qfxlistview.h index 6e9451e..2a70af0 100644 --- a/src/declarative/fx/qfxlistview.h +++ b/src/declarative/fx/qfxlistview.h @@ -55,7 +55,7 @@ class QFxListViewPrivate; class Q_DECLARATIVE_EXPORT QFxListView : public QFxFlickable { Q_OBJECT - Q_DECLARE_PRIVATE(QFxListView) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxListView) Q_ENUMS(CurrentItemPositioning) Q_PROPERTY(QVariant model READ model WRITE setModel) diff --git a/src/declarative/fx/qfxmouseregion.cpp b/src/declarative/fx/qfxmouseregion.cpp index 6eb358b..38a0bd1 100644 --- a/src/declarative/fx/qfxmouseregion.cpp +++ b/src/declarative/fx/qfxmouseregion.cpp @@ -373,8 +373,8 @@ void QFxMouseRegion::mouseMoveEvent(QGraphicsSceneMouseEvent *event) QPointF startLocalPos; QPointF curLocalPos; if (drag()->target()->parent()) { - startLocalPos = drag()->target()->parent()->mapFromScene(d->startScene); - curLocalPos = drag()->target()->parent()->mapFromScene(event->scenePos()); + startLocalPos = drag()->target()->parentItem()->mapFromScene(d->startScene); + curLocalPos = drag()->target()->parentItem()->mapFromScene(event->scenePos()); } else { startLocalPos = d->startScene; curLocalPos = event->scenePos(); diff --git a/src/declarative/fx/qfxmouseregion.h b/src/declarative/fx/qfxmouseregion.h index 429ad00..224dd54 100644 --- a/src/declarative/fx/qfxmouseregion.h +++ b/src/declarative/fx/qfxmouseregion.h @@ -151,7 +151,7 @@ protected: private: Q_DISABLE_COPY(QFxMouseRegion) - Q_DECLARE_PRIVATE(QFxMouseRegion) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxMouseRegion) }; QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxmouseregion_p.h b/src/declarative/fx/qfxmouseregion_p.h index e444bf2..ad0866f 100644 --- a/src/declarative/fx/qfxmouseregion_p.h +++ b/src/declarative/fx/qfxmouseregion_p.h @@ -74,7 +74,7 @@ public: { Q_Q(QFxMouseRegion); q->setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton); - q->setOptions(QSimpleCanvasItem::HoverEvents | QSimpleCanvasItem::MouseEvents); + q->setOptions(QFxItem::HoverEvents | QFxItem::MouseEvents); } void saveEvent(QGraphicsSceneMouseEvent *event) { diff --git a/src/declarative/fx/qfxpainteditem.cpp b/src/declarative/fx/qfxpainteditem.cpp index 65589f2..8323628 100644 --- a/src/declarative/fx/qfxpainteditem.cpp +++ b/src/declarative/fx/qfxpainteditem.cpp @@ -49,11 +49,6 @@ #include <QApplication> #include <QGraphicsSceneMouseEvent> -#if defined(QFX_RENDER_OPENGL2) -#include <QtOpenGL/qglframebufferobject.h> -#include <glsave.h> -#endif - QT_BEGIN_NAMESPACE /*! @@ -210,26 +205,16 @@ void QFxPaintedItem::init() connect(this,SIGNAL(visibleChanged()),this,SLOT(clearCache())); } -#if defined(QFX_RENDER_QPAINTER) /*! \reimp */ void QFxPaintedItem::paintContents(QPainter &p) -#elif defined(QFX_RENDER_OPENGL) -/*! - \reimp -*/ -void QFxPaintedItem::paintGLContents(GLPainter &p) -#else -#error "What render?" -#endif { Q_D(QFxPaintedItem); const QRect content(QPoint(0,0),d->contentsSize); if (content.width() <= 0 || content.height() <= 0) return; -#if defined(QFX_RENDER_QPAINTER) bool oldAntiAliasing = p.testRenderHint(QPainter::Antialiasing); bool oldSmoothPixmap = p.testRenderHint(QPainter::SmoothPixmapTransform); if (d->smooth) { @@ -242,29 +227,12 @@ void QFxPaintedItem::paintGLContents(GLPainter &p) else clipf = mapToScene(clipf); -#elif defined(QFX_RENDER_OPENGL2) - p.useTextureShader(); - const QRectF clipf = p.sceneClipRect; - -#elif defined(QFX_RENDER_OPENGL1) - p.useTextureShader(); - const QRectF clipf = p.sceneClipRect; -#endif - const QRect clip = mapFromScene(clipf).toRect(); QRegion topaint(clip); topaint &= content; QRegion uncached(content); -#if defined(QFX_RENDER_OPENGL2) - glEnableVertexAttribArray(SingleTextureShader::Vertices); - glEnableVertexAttribArray(SingleTextureShader::TextureCoords); -#elif defined(QFX_RENDER_OPENGL1) - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); -#endif - int cachesize=0; for (int i=0; i<d->imagecache.count(); ++i) { QRect area = d->imagecache[i]->area; @@ -312,29 +280,16 @@ void QFxPaintedItem::paintGLContents(GLPainter &p) } QFxPaintedItemPrivate::ImageCacheItem *newitem = new QFxPaintedItemPrivate::ImageCacheItem; newitem->area = r; -#if defined(QFX_RENDER_QPAINTER) newitem->image = img; -#else - newitem->image.setImage(img.toImage()); -#endif d->imagecache.append(newitem); QRectF target(r.x(), r.y(), r.width(), r.height()); p.drawPixmap(target.toRect(), newitem->image); } } -#if defined(QFX_RENDER_OPENGL2) - glDisableVertexAttribArray(SingleTextureShader::Vertices); - glDisableVertexAttribArray(SingleTextureShader::TextureCoords); -#elif defined(QFX_RENDER_OPENGL1) - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); -#endif -#if defined(QFX_RENDER_QPAINTER) if (d->smooth) { p.setRenderHints(QPainter::Antialiasing, oldAntiAliasing); p.setRenderHints(QPainter::SmoothPixmapTransform, oldSmoothPixmap); } -#endif } /*! diff --git a/src/declarative/fx/qfxpainteditem.h b/src/declarative/fx/qfxpainteditem.h index 7a0a9a9..e74ead0 100644 --- a/src/declarative/fx/qfxpainteditem.h +++ b/src/declarative/fx/qfxpainteditem.h @@ -66,11 +66,7 @@ public: QFxPaintedItem(QFxItem *parent=0); ~QFxPaintedItem(); -#if defined(QFX_RENDER_QPAINTER) void paintContents(QPainter &painter); -#elif defined(QFX_RENDER_OPENGL) - void paintGLContents(GLPainter &); -#endif bool isSmooth() const; QSize contentsSize() const; @@ -99,7 +95,7 @@ protected Q_SLOTS: private: void init(); Q_DISABLE_COPY(QFxPaintedItem) - Q_DECLARE_PRIVATE(QFxPaintedItem) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxPaintedItem) }; QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxpainteditem_p.h b/src/declarative/fx/qfxpainteditem_p.h index 4e953a0..06e80ff 100644 --- a/src/declarative/fx/qfxpainteditem_p.h +++ b/src/declarative/fx/qfxpainteditem_p.h @@ -54,11 +54,6 @@ // #include <private/qfxitem_p.h> -#include <QtDeclarative/qsimplecanvas.h> - -#if defined(QFX_RENDER_OPENGL) -#include "gltexture.h" -#endif QT_BEGIN_NAMESPACE @@ -77,11 +72,7 @@ public: ~ImageCacheItem() { } int age; QRect area; -#if defined(QFX_RENDER_QPAINTER) QPixmap image; -#else - GLTexture image; -#endif }; QList<ImageCacheItem*> imagecache; diff --git a/src/declarative/fx/qfxpath.cpp b/src/declarative/fx/qfxpath.cpp index 4c241d3..a1b6032 100644 --- a/src/declarative/fx/qfxpath.cpp +++ b/src/declarative/fx/qfxpath.cpp @@ -43,6 +43,7 @@ #include "qfxpath_p.h" #include <private/qfxperf_p.h> #include <private/qbezier_p.h> +#include <QSet> QT_BEGIN_NAMESPACE diff --git a/src/declarative/fx/qfxpathview.h b/src/declarative/fx/qfxpathview.h index 159c865..9d91006 100644 --- a/src/declarative/fx/qfxpathview.h +++ b/src/declarative/fx/qfxpathview.h @@ -125,7 +125,7 @@ private: friend class QFxPathViewAttached; static QHash<QObject*, QObject*> attachedProperties; Q_DISABLE_COPY(QFxPathView) - Q_DECLARE_PRIVATE(QFxPathView) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxPathView) }; QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxpathview_p.h b/src/declarative/fx/qfxpathview_p.h index b77c2a0..f996d1d 100644 --- a/src/declarative/fx/qfxpathview_p.h +++ b/src/declarative/fx/qfxpathview_p.h @@ -87,7 +87,7 @@ public: Q_Q(QFxPathView); _offset = 0; q->setAcceptedMouseButtons(Qt::NoButton); - q->setOptions(QSimpleCanvasItem::MouseFilter | QSimpleCanvasItem::MouseEvents | QSimpleCanvasItem::IsFocusRealm); + q->setOptions(QFxItem::MouseFilter | QFxItem::MouseEvents | QFxItem::IsFocusRealm); q->connect(&tl, SIGNAL(updated()), q, SLOT(ticked())); } diff --git a/src/declarative/fx/qfxpixmap.cpp b/src/declarative/fx/qfxpixmap.cpp index 5ee6528..ac8a701 100644 --- a/src/declarative/fx/qfxpixmap.cpp +++ b/src/declarative/fx/qfxpixmap.cpp @@ -46,6 +46,7 @@ #include <private/qfxperf_p.h> #include <QtDeclarative/qmlengine.h> #include <QFile> +#include <QtCore/qdebug.h> QT_BEGIN_NAMESPACE class QSharedNetworkReply; diff --git a/src/declarative/fx/qfxpixmap.h b/src/declarative/fx/qfxpixmap.h index ae693c1..f63299b 100644 --- a/src/declarative/fx/qfxpixmap.h +++ b/src/declarative/fx/qfxpixmap.h @@ -44,9 +44,8 @@ #include <QtCore/QString> #include <QtGui/QPixmap> -#include <QtDeclarative/qsimplecanvas.h> #include <QtDeclarative/qfxglobal.h> - +#include <QtCore/qurl.h> QT_BEGIN_HEADER diff --git a/src/declarative/fx/qfxrect.cpp b/src/declarative/fx/qfxrect.cpp index b521d00..2ad8536 100644 --- a/src/declarative/fx/qfxrect.cpp +++ b/src/declarative/fx/qfxrect.cpp @@ -251,17 +251,8 @@ QFxRect::QFxRect(QFxRectPrivate &dd, QFxItem *parent) void QFxRect::doUpdate() { -#if defined(QFX_RENDER_QPAINTER) Q_D(QFxRect); d->rectImage = QPixmap(); -#endif -#if defined(QFX_RENDER_OPENGL) - Q_D(QFxRect); - if (d->rectTexture) { - d->rectTexture->release(); - d->rectTexture = 0; - } -#endif const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0; setPaintMargin((pw+1)/2); update(); @@ -361,25 +352,10 @@ void QFxRect::setRadius(qreal radius) return; d->radius = radius; -#if defined(QFX_RENDER_QPAINTER) d->rectImage = QPixmap(); -#elif defined(QFX_RENDER_OPENGL) - if (d->rectTexture) { - d->rectTexture->release(); - d->rectTexture = 0; - } -#endif update(); } -void QFxRect::dump(int depth) -{ - Q_D(QFxRect); - QByteArray ba(depth * 4, ' '); - qWarning() << ba.constData() << "QFxRect:" << d->color; - QFxItem::dump(depth); -} - /*! \qmlproperty color Rect::color This property holds the color used to fill the rect. @@ -412,15 +388,7 @@ void QFxRect::setColor(const QColor &c) return; d->color = c; -#if defined(QFX_RENDER_QPAINTER) d->rectImage = QPixmap(); -#endif -#if defined(QFX_RENDER_OPENGL) - if (d->rectTexture) { - d->rectTexture->release(); - d->rectTexture = 0; - } -#endif update(); } @@ -488,7 +456,6 @@ QColor QFxRectPrivate::getColor() } -#if defined(QFX_RENDER_QPAINTER) void QFxRect::generateRoundedRect() { Q_D(QFxRect); @@ -535,72 +502,7 @@ void QFxRect::generateBorderedRect() p.drawRect(QRectF(qreal(pw)/2, qreal(pw)/2, d->rectImage.width()-pw, d->rectImage.height()-pw)); } } -#elif defined(QFX_RENDER_OPENGL) -void QFxRect::generateRoundedRect() -{ - Q_D(QFxRect); - if (!d->rectTexture) { - const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0; - QString key = QString("QFxRect://r_%1_%2_%3_%4").arg(pw).arg(d->radius).arg((d->pen && d->pen->isValid())?d->pen->color().name():QString()).arg(d->color.name()); - - d->rectTexture = cachedTexture(key); - - if (!d->rectTexture) { - QPixmap roundRect(d->radius*2 + 4 + pw*2, d->radius*2 + 4 + pw*2); - roundRect.fill(Qt::transparent); - QPainter p(&roundRect); - p.setRenderHint(QPainter::Antialiasing); - if (d->pen && d->pen->isValid()) { - QPen pn(QColor(pen()->color()), pen()->width()); - p.setPen(pn); - } else { - p.setPen(Qt::NoPen); - } - p.setBrush(d->color); - if (pw%2) - p.drawRoundedRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, roundRect.width()-(pw+1), roundRect.height()-(pw+1)), d->radius, d->radius); - else - p.drawRoundedRect(QRectF(qreal(pw)/2, qreal(pw)/2, roundRect.width()-pw, roundRect.height()-pw), d->radius, d->radius); - - d->rectTexture = cachedTexture(key, roundRect); - } - } -} - -void QFxRect::generateBorderedRect() -{ - Q_D(QFxRect); - if (!d->rectTexture) { - const int pw = d->pen && d->pen->isValid() ? d->pen->width() : 0; - QString key = QString("QFxRect://b_%1_%2_%3_%4").arg(pw).arg(d->radius).arg((d->pen && d->pen->isValid())?d->pen->color().name():QString()).arg(d->color.name()); - - d->rectTexture = cachedTexture(key); - - if (!d->rectTexture) { - QPixmap borderedRect(pw*2 + 4, pw*2 + 4); - borderedRect.fill(Qt::transparent); - QPainter p(&(borderedRect)); - p.setRenderHint(QPainter::Antialiasing); - if (d->pen && d->pen->isValid()) { - QPen pn(QColor(pen()->color()), pen()->width()); - pn.setJoinStyle(Qt::MiterJoin); - p.setPen(pn); - } else { - p.setPen(Qt::NoPen); - } - p.setBrush(d->color); - if (pw%2) - p.drawRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, borderedRect.width()-(pw+1), borderedRect.height()-(pw+1))); - else - p.drawRect(QRectF(qreal(pw)/2, qreal(pw)/2, borderedRect.width()-pw, borderedRect.height()-pw)); - d->rectTexture = cachedTexture(key, borderedRect); - } - } -} -#endif - -#if defined(QFX_RENDER_QPAINTER) void QFxRect::paintContents(QPainter &p) { Q_D(QFxRect); @@ -701,258 +603,5 @@ void QFxRect::drawRect(QPainter &p) QRect(d->rectImage.width()-xOffset, d->rectImage.height() - yOffset, xOffset, yOffset)); } } -#endif - -#if defined(QFX_RENDER_OPENGL2) -#include "glbasicshaders.h" - -void QFxRect::paintGLContents(GLPainter &p) -{ - Q_D(QFxRect); - if (d->radius == 0 && (!d->pen || !d->pen->isValid())) { - if (d->gradient) { - float widthV = width(); - float heightV = height(); - - GLfloat vertices[] = { 0, heightV, - widthV, heightV, - 0, 0, - widthV, 0 }; - - int count = d->gradient->stops()->size(); - GLfloat colors[count*8]; - for (int i = 0; i < count; i += 8) { - QFxGradientStop *g = d->gradient->stops()->at(i); - QColor c = g->color(); - colors[i] = c.redF(); colors[i+4] = colors[i]; - colors[i+1] = c.greenF(); colors[i+5] = colors[i+1]; - colors[i+2] = c.blueF(); colors[i+6] = colors[i+2]; - colors[i+3] = c.alphaF() * p.activeOpacity; colors[i+7] = colors[i+3]; - } - - p.invalidate(); - ColorShader *shader = basicShaders()->color(); - shader->enable(); - shader->setTransform(p.activeTransform); - - shader->setAttributeArray(ColorShader::Vertices, vertices, 2); - shader->setAttributeArray(ColorShader::Colors, colors, 4); - glDrawArrays(GL_TRIANGLE_STRIP, 0, count*2); - shader->disableAttributeArray(ColorShader::Vertices); - shader->disableAttributeArray(ColorShader::Colors); - } else { - - p.fillRect(QRectF(0, 0, width(), height()), d->getColor()); - - } - } else { - qreal offset = 0; - qreal pw = d->pen && d->pen->isValid() ? d->pen->width() : 0.0; - - if (d->radius > 0) { - generateRoundedRect(); - offset = d->radius + pw+1.5; - } else { - generateBorderedRect(); - offset = pw+1.5; - } - - QGLShaderProgram *shader = p.useTextureShader(); - - float texWidth = d->rectTexture->width(); - float texHeight = d->rectTexture->height(); - if (!texWidth || !texHeight) - return; - - float widthV = qreal(width())+pw/2; - float heightV = qreal(height())+pw/2; - - float xOffset = offset; - bool xMiddles = true; - if (xOffset*2 > width()+pw) { - xMiddles = false; - xOffset = (width()+pw)/2; - } - float yOffset = offset; - bool yMiddles = true; - if (yOffset*2 > height()+pw) { - yMiddles = false; - yOffset = (height()+pw)/2; - } - - float texleft = xOffset / texWidth; - float imgleft = xOffset-pw/2; - float texright = (texWidth-xOffset) / texWidth; - float imgright = widthV - xOffset; - - float textop = yOffset / texHeight; - float imgtop = yOffset-pw/2; - float texbottom = (texHeight-yOffset) / texHeight; - float imgbottom = heightV - yOffset; - - //Bug 231768: Inappropriate interpolation was occuring on 3x3 textures - if (offset==1) - texleft=texright=textop=texbottom=0.5; - - texleft *= d->rectTexture->glWidth(); - texright *= d->rectTexture->glWidth(); - textop *= d->rectTexture->glHeight(); - texbottom *= d->rectTexture->glHeight(); - - float vert1[] = { -pw/2, -pw/2, - -pw/2, imgtop, - imgleft, -pw/2, - - -pw/2, imgtop, - imgleft, -pw/2, - imgleft, imgtop, - - imgleft, -pw/2, - imgleft, imgtop, - imgright, -pw/2, - - imgleft, imgtop, - imgright, -pw/2, - imgright, imgtop, - - imgright, -pw/2, - imgright, imgtop, - widthV, -pw/2, - - imgright, imgtop, - widthV, -pw/2, - widthV, imgtop, - - -pw/2, heightV, - -pw/2, imgbottom, - imgleft, heightV, - - -pw/2, imgbottom, - imgleft, heightV, - imgleft, imgbottom, - - imgleft, heightV, - imgleft, imgbottom, - imgright, heightV, - - imgleft, imgbottom, - imgright, heightV, - imgright, imgbottom, - - imgright, heightV, - imgright, imgbottom, - widthV, heightV, - - imgright, imgbottom, - widthV, heightV, - widthV, imgbottom, - - -pw/2, imgtop, - -pw/2, imgbottom, - imgleft, imgtop, - - -pw/2, imgbottom, - imgleft, imgtop, - imgleft, imgbottom, - - imgleft, imgtop, - imgleft, imgbottom, - imgright, imgtop, - - imgleft, imgbottom, - imgright, imgtop, - imgright, imgbottom, - - imgright, imgtop, - imgright, imgbottom, - widthV, imgtop, - - imgright, imgbottom, - widthV, imgtop, - widthV, imgbottom }; - - - float tex1[] = { 0, 0, - 0, textop, - texleft, 0, - - 0, textop, - texleft, 0, - texleft, textop, - - texleft, 0, - texleft, textop, - texright, 0, - - texleft, textop, - texright, 0, - texright, textop, - - texright, 0, - texright, textop, - d->rectTexture->glWidth(), 0, - - texright, textop, - d->rectTexture->glWidth(), 0, - d->rectTexture->glWidth(), textop, - - 0, d->rectTexture->glHeight(), - 0, texbottom, - texleft, d->rectTexture->glHeight(), - - 0, texbottom, - texleft, d->rectTexture->glHeight(), - texleft, texbottom, - - texleft, d->rectTexture->glHeight(), - texleft, texbottom, - texright, d->rectTexture->glHeight(), - - texleft, texbottom, - texright, d->rectTexture->glHeight(), - texright, texbottom, - - texright, d->rectTexture->glHeight(), - texright, texbottom, - d->rectTexture->glWidth(), d->rectTexture->glHeight(), - - texright, texbottom, - d->rectTexture->glWidth(), d->rectTexture->glHeight(), - d->rectTexture->glWidth(), texbottom, - - 0, textop, - 0, texbottom, - texleft, textop, - - 0, texbottom, - texleft, textop, - texleft, texbottom, - - texleft, textop, - texleft, texbottom, - texright, textop, - - texleft, texbottom, - texright, textop, - texright, texbottom, - - texright, textop, - texright, texbottom, - d->rectTexture->glWidth(), textop, - - texright, texbottom, - d->rectTexture->glWidth(), textop, - d->rectTexture->glWidth(), texbottom }; - - - - glBindTexture(GL_TEXTURE_2D, d->rectTexture->texture()); - - shader->setAttributeArray(SingleTextureShader::Vertices, vert1, 2); - shader->setAttributeArray(SingleTextureShader::TextureCoords, tex1, 2); - glDrawArrays(GL_TRIANGLES, 0, 36 + (yMiddles?18:0)); - } -} -#endif QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxrect.h b/src/declarative/fx/qfxrect.h index 2b35d8d..7790af1 100644 --- a/src/declarative/fx/qfxrect.h +++ b/src/declarative/fx/qfxrect.h @@ -43,6 +43,7 @@ #define QFXRECT_H #include <QtDeclarative/qfxitem.h> +#include <QtGui/qbrush.h> QT_BEGIN_HEADER @@ -156,14 +157,7 @@ public: qreal radius() const; void setRadius(qreal radius); - virtual void dump(int depth); -#if defined(QFX_RENDER_QPAINTER) void paintContents(QPainter &painter); -#endif - -#if defined(QFX_RENDER_OPENGL) - void paintGLContents(GLPainter &); -#endif private Q_SLOTS: void doUpdate(); @@ -179,7 +173,7 @@ protected: private: Q_DISABLE_COPY(QFxRect) - Q_DECLARE_PRIVATE(QFxRect) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxRect) }; QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxrect_p.h b/src/declarative/fx/qfxrect_p.h index 23bb944..3544d36 100644 --- a/src/declarative/fx/qfxrect_p.h +++ b/src/declarative/fx/qfxrect_p.h @@ -55,10 +55,6 @@ #include "qfxitem_p.h" -#if defined(QFX_RENDER_OPENGL) -#include "gltexture.h" -#endif - QT_BEGIN_NAMESPACE class QFxGradient; @@ -69,9 +65,6 @@ class QFxRectPrivate : public QFxItemPrivate public: QFxRectPrivate() : -#if defined(QFX_RENDER_OPENGL) - rectTexture(0), -#endif //QFX_RENDER_OPENGL color(Qt::white), gradient(0), pen(0), radius(0) { } @@ -85,9 +78,6 @@ public: { } -#if defined(QFX_RENDER_OPENGL) - QSimpleCanvasItem::CachedTexture *rectTexture; -#endif QColor getColor(); QColor color; QFxGradient *gradient; diff --git a/src/declarative/fx/qfxreflectionfilter.cpp b/src/declarative/fx/qfxreflectionfilter.cpp deleted file mode 100644 index c66deb7..0000000 --- a/src/declarative/fx/qfxreflectionfilter.cpp +++ /dev/null @@ -1,352 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qfxreflectionfilter.h" - -#if defined(QFX_RENDER_OPENGL2) -#include <glsave.h> -#include <QtOpenGL/qglframebufferobject.h> -#include <glbasicshaders.h> -#include <gltexture.h> -#endif - -QT_BEGIN_NAMESPACE -class QFxReflectionFilterPrivate -{ -public: - QFxReflectionFilterPrivate() - : alpha(1), height(-1), offset(0), scale(1) - { - } - qreal alpha; - int height; - int offset; - qreal scale; -}; - -/*! - \qmlclass Reflection - \inherits Filter - \brief The Reflection filter reflects an item and its contents. - - Here is an example of various Reflections applied to an image. - - \qml -HorizontalLayout { - Image { - source: "icon.png" - filter: Reflection { } - } - Image { - source: "icon.png" - filter: Reflection { offset: 1 } - } - Image { - source: "icon.png" - filter: Reflection { offset: 1; alpha: 0.5 } - } - Image { - source: "icon.png" - filter: Reflection { offset: 1; alpha: 0.5; height: 50 } - } - Image { - source: "icon.png" - filter: Reflection { offset: 1; alpha: 0.5; height: 50; scale: 0.5 } - } -} - \endqml - - \image reflection_example.png - - Reflection is only supported when Qt Declarative is compiled for OpenGL ES 2.0. - Otherwise the Reflection filter has no effect. -*/ - -/*! - \internal - \class QFxReflectionFilter - \ingroup group_effects - \brief The QFxReflectionFilter class allows you to add a reflection to an item. -*/ -QFxReflectionFilter::QFxReflectionFilter(QObject *parent) -: QSimpleCanvasFilter(parent), d(new QFxReflectionFilterPrivate) -{ -} - -QFxReflectionFilter::~QFxReflectionFilter() -{ - delete d; d = 0; -} - -/*! - \property QFxReflectionFilter::alpha - \brief the starting opacity of the reflection. - - The starting opacity is the opacity closest to the item. The opacity will fade - from this value to zero over the height of the reflection. -*/ -qreal QFxReflectionFilter::alpha() const -{ - return d->alpha; -} - -void QFxReflectionFilter::setAlpha(qreal a) -{ - if (d->alpha == a) return; - d->alpha = a; - emit alphaChanged(a); - update(); -} - -/*! - \qmlproperty int Reflection::height - - The height property controls how much of the item, in pixels, to reflect. - If it is set to the default value of -1, the whole item is reflected. If - it is set to 50, the bottom 50 pixels of the item are reflected. Data - binding could be used to reflect a percentage of the item. - - \qml -Image { - id: myImage - source: "album.png" - filter: Reflection { - height: myImage.height * 0.5 - } -} - \endqml - */ -/*! - \qmlproperty int Reflection::offset - - The offset controls how far from the base of the item, in pixels, the - start of the reflection is placed. This can be used to create a nice - sliver of space between the item and its reflection or for more advanced - effects. - - The default offset is 0 pixels. -*/ - -/*! - \qmlproperty real Reflection::alpha - - The alpha value controls the starting opacity of the reflected item. If - set to the default value of 1, the reflected item starts completely opaque - and gradually fades to completely transparent. If set to less than one, the - reflection starts out partially transparent as though the item was sitting - on a visually less reflective surface. - - Valid values are from 0 (which would be silly, but is allowed) to 1. -*/ -/*! - \qmlproperty real Reflection::scale - - When set to the default value of 1, the reflection is a 1:1 reflection of - the item. That is, each horizontal pixel in the item corresponds to one - horizontal pixel in the reflection. - - When set a value other than 1, the reflection is scaled acordingly - less - than 1 scales it down and greater than 1 scales it up. The scale is applied - after the height parameter and does not effect the reflection offset. -*/ - -/*! - \property QFxReflectionFilter::height - \brief the height of the reflection, in pixels. -*/ -int QFxReflectionFilter::height() const -{ - return d->height; -} - -void QFxReflectionFilter::setHeight(int h) -{ - if (d->height == h) return; - d->height = h; - emit heightChanged(h); - update(); -} - -/*! - \property QFxReflectionFilter::offset - \brief the distance of the reflection from the item, in pixels. -*/ -int QFxReflectionFilter::offset() -{ - return d->offset; -} - -void QFxReflectionFilter::setOffset(int o) -{ - if (d->offset == o) return; - d->offset = o; - emit offsetChanged(o); - update(); -} - -/*! - \property QFxReflectionFilter::scale - \brief the scale of the reflection relative to the item. -*/ -qreal QFxReflectionFilter::scale() const -{ - return d->scale; -} - -void QFxReflectionFilter::setScale(qreal s) -{ - if (d->scale == s) return; - d->scale = s; - emit scaleChanged(s); - update(); -} - -static inline float floatmin(float a, float b) -{ - return (a < b)?a:b; -} - -void QFxReflectionFilter::filterGL(QSimpleCanvasItem::GLPainter &p) -{ -#if defined(QFX_RENDER_OPENGL2) - QSimpleCanvasItem *item = this->item(); - - QRect r = item->itemBoundingRect(); - if (r.isEmpty()) - return; - float width = r.width(); - float height = r.height(); - - float refHeight = height; - if (d->height > 0) - refHeight = floatmin(height, d->height); - - QSimpleCanvas::Matrix simpMat; - QSimpleCanvasItem *simpItem = 0; - if (isSimpleItem(&simpItem, &simpMat) && - simpItem->glSimpleItemData(0, 0, 0, 0)) { - - GLfloat vertices[8]; - GLfloat texVertices[8]; - GLTexture *texture = 0; - - simpItem->glSimpleItemData(vertices, texVertices, &texture, 8); - - GLfloat opacity[4]; - - float invRefHeight = 1. / refHeight; - for (int ii = 0; ii < 4; ++ii) { - float vertex = vertices[ii * 2 + 1]; - float o = (1. - (height - vertex) * invRefHeight); - opacity[ii] = o * d->alpha * p.activeOpacity; - } - - QSimpleCanvas::Matrix trans = p.activeTransform; - trans.rotate(180, 1, 0, 0); - trans.translate(0, -r.height() - d->offset); - if (d->scale != 1) - trans.scale(1, d->scale, 1); - trans.translate(0, -r.height()); - trans *= simpMat; - - glBindTexture(GL_TEXTURE_2D, texture->texture()); - - SingleTextureVertexOpacityShader *shader = - item->basicShaders()->singleTextureVertexOpacity(); - shader->enable(); - shader->setTransform(trans); - shader->setAttributeArray(SingleTextureVertexOpacityShader::Vertices, vertices, 2); - shader->setAttributeArray(SingleTextureVertexOpacityShader::TextureCoords, texVertices, 2); - shader->setAttributeArray(SingleTextureVertexOpacityShader::OpacityCoords, opacity, 1); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - shader->disableAttributeArray(SingleTextureVertexOpacityShader::Vertices); - shader->disableAttributeArray(SingleTextureVertexOpacityShader::TextureCoords); - shader->disableAttributeArray(SingleTextureVertexOpacityShader::OpacityCoords); - - } else { - QGLFramebufferObject *fbo = renderToFBO(); - - float texWidth = width / float(fbo->width()); - float texHeight = refHeight / float(fbo->height()); - - GLfloat invVertices[] = { width, height + d->scale * refHeight + d->offset, - 0, height + d->scale * refHeight + d->offset, - width, height + d->offset, - 0, height + d->offset }; - GLfloat invTexVertices[] = { texWidth, texHeight, - 0, texHeight, - texWidth, 0, - 0, 0 }; - GLfloat invOpacity[] = { 0, 0, d->alpha * p.activeOpacity, d->alpha * p.activeOpacity}; - - glBindTexture(GL_TEXTURE_2D, fbo->texture()); - - SingleTextureVertexOpacityShader *shader = - item->basicShaders()->singleTextureVertexOpacity(); - shader->enable(); - shader->setTransform(p.activeTransform); - shader->setAttributeArray(SingleTextureVertexOpacityShader::Vertices, invVertices, 2); - shader->setAttributeArray(SingleTextureVertexOpacityShader::TextureCoords, invTexVertices, 2); - shader->setAttributeArray(SingleTextureVertexOpacityShader::OpacityCoords, invOpacity, 1); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - shader->disableAttributeArray(SingleTextureVertexOpacityShader::Vertices); - shader->disableAttributeArray(SingleTextureVertexOpacityShader::TextureCoords); - shader->disableAttributeArray(SingleTextureVertexOpacityShader::OpacityCoords); - - releaseFBO(fbo); - } - - renderToScreen(); - -#else - Q_UNUSED(p); -#endif -} - -QRectF QFxReflectionFilter::itemBoundingRect(const QRectF &r) const -{ - QRectF rv = r; - rv |= r.translated(0, r.height() + d->offset); - return rv; -} - -QML_DEFINE_TYPE(QFxReflectionFilter,Reflection) -QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxreflectionfilter.h b/src/declarative/fx/qfxreflectionfilter.h deleted file mode 100644 index d862040..0000000 --- a/src/declarative/fx/qfxreflectionfilter.h +++ /dev/null @@ -1,97 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QFXREFLECTIONFILTER_H -#define QFXREFLECTIONFILTER_H - -#include <QtDeclarative/qsimplecanvasfilter.h> -#include <QtDeclarative/qml.h> - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class QFxReflectionFilterPrivate; -class Q_DECLARATIVE_EXPORT QFxReflectionFilter : public QSimpleCanvasFilter -{ - Q_OBJECT - - Q_PROPERTY(qreal alpha READ alpha WRITE setAlpha NOTIFY alphaChanged) - Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightChanged) - Q_PROPERTY(int offset READ offset WRITE setOffset NOTIFY offsetChanged) - Q_PROPERTY(qreal scale READ scale WRITE setScale NOTIFY scaleChanged) -public: - QFxReflectionFilter(QObject *parent=0); - virtual ~QFxReflectionFilter(); - - qreal alpha() const; - void setAlpha(qreal); - int height() const; - void setHeight(int); - int offset(); - void setOffset(int); - qreal scale() const; - void setScale(qreal); - -Q_SIGNALS: - void alphaChanged(qreal); - void heightChanged(int); - void offsetChanged(int); - void scaleChanged(qreal); - -protected: - virtual void filterGL(QSimpleCanvasItem::GLPainter &p); - virtual QRectF itemBoundingRect(const QRectF &r) const; - -private: - Q_DISABLE_COPY(QFxReflectionFilter) - QFxReflectionFilterPrivate *d; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QFxReflectionFilter) - -QT_END_HEADER - -#endif // QFXREFLECTIONFILTER_H diff --git a/src/declarative/fx/qfxrepeater.cpp b/src/declarative/fx/qfxrepeater.cpp index 0211ebb..a4dc809 100644 --- a/src/declarative/fx/qfxrepeater.cpp +++ b/src/declarative/fx/qfxrepeater.cpp @@ -57,12 +57,13 @@ QFxRepeaterPrivate::~QFxRepeaterPrivate() QFxItem *QFxRepeaterPrivate::addItem(QmlContext *ctxt, QFxItem *lastItem) { + Q_UNUSED(lastItem) Q_Q(QFxRepeater); QObject *nobj = component->create(ctxt); QFxItem *item = qobject_cast<QFxItem *>(nobj); if (item) { item->setParent(q->itemParent()); - item->stackUnder(lastItem); +// item->stackUnder(lastItem); deletables << nobj; } else { delete nobj; @@ -243,7 +244,7 @@ void QFxRepeater::componentComplete() /*! \internal */ -void QFxRepeater::parentChanged(QSimpleCanvasItem *o, QSimpleCanvasItem *n) +void QFxRepeater::parentChanged(QFxItem *o, QFxItem *n) { QFxItem::parentChanged(o, n); regenerate(); diff --git a/src/declarative/fx/qfxrepeater.h b/src/declarative/fx/qfxrepeater.h index b82b9b0..6f950d3 100644 --- a/src/declarative/fx/qfxrepeater.h +++ b/src/declarative/fx/qfxrepeater.h @@ -73,12 +73,12 @@ private: protected: virtual void componentComplete(); - virtual void parentChanged(QSimpleCanvasItem *, QSimpleCanvasItem *); + virtual void parentChanged(QFxItem *, QFxItem *); QFxRepeater(QFxRepeaterPrivate &dd, QFxItem *parent); private: Q_DISABLE_COPY(QFxRepeater) - Q_DECLARE_PRIVATE(QFxRepeater) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxRepeater) }; QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxscalegrid.h b/src/declarative/fx/qfxscalegrid.h index 03b2dd3..986bcda 100644 --- a/src/declarative/fx/qfxscalegrid.h +++ b/src/declarative/fx/qfxscalegrid.h @@ -45,7 +45,6 @@ #include <QtCore/QString> #include <QtCore/QObject> #include <QtDeclarative/qfxglobal.h> -#include <QtDeclarative/qsimplecanvas.h> #include <QtDeclarative/qfxpixmap.h> #include <QtDeclarative/qml.h> diff --git a/src/declarative/fx/qfxshadowfilter.cpp b/src/declarative/fx/qfxshadowfilter.cpp deleted file mode 100644 index d37d565..0000000 --- a/src/declarative/fx/qfxshadowfilter.cpp +++ /dev/null @@ -1,214 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qfxshadowfilter.h" - -#if defined(QFX_RENDER_OPENGL2) -#include <glsave.h> -#include <QtOpenGL/qglframebufferobject.h> -#include <glbasicshaders.h> -#endif - -QT_BEGIN_NAMESPACE - -class QFxShadowFilterPrivate -{ -public: - QFxShadowFilterPrivate() - : x(0), y(0) - { - } - - int x; - int y; -}; - -/*! - \qmlclass Shadow - \brief The Shadow filter casts a drop shadow. - \inherits Filter - - Shadows work on all visual elements - including transparent and masked - images. - - \table - \row - \o \image shadow_example.png - \o - \qml -Rect { - radius: 5 - color: "lightsteelblue" - width: 100 - height: 100 - filter: Shadow { - yOffset: 8 - xOffset: 8 - } -} - -Image { - source: "pics/qtlogo.png" - filter: Shadow { - yOffset: 8 - xOffset: 8 - } -} - \endqml - \endtable - - Shadows are only supported when Qt Qt Declarative is compiled for OpenGL ES 2.0. - Otherwise the Shadow filter has no effect. -*/ - -/*! - \internal - \class QFxShadowFilter - \ingroup group_effects - \brief The QFxShadowFilter class allows you to add a shadow to an item. -*/ - -QFxShadowFilter::QFxShadowFilter(QObject *parent) -: QSimpleCanvasFilter(parent), d(new QFxShadowFilterPrivate) -{ -} - -QFxShadowFilter::~QFxShadowFilter() -{ - delete d; d = 0; -} - -/*! - \qmlproperty int Shadow::xOffset - \qmlproperty int Shadow::yOffset - - Specify the x and y offset of the shadow relative to the item. -*/ - -int QFxShadowFilter::xOffset() const -{ - return d->x; -} - -/*! - \property QFxShadowFilter::xOffset - \brief the x offset of the shadow relative to the item. -*/ -void QFxShadowFilter::setXOffset(int offset) -{ - if (d->x == offset) return; - d->x = offset; - emit offsetChanged(d->x, d->y); -} - -/*! - \property QFxShadowFilter::yOffset - \brief the y offset of the shadow relative to the item. -*/ -int QFxShadowFilter::yOffset() const -{ - return d->y; -} - -void QFxShadowFilter::setYOffset(int offset) -{ - if (d->y == offset) return; - d->y = offset; - emit offsetChanged(d->x, d->y); -} - -QRectF QFxShadowFilter::itemBoundingRect(const QRectF &r) const -{ - QRectF rv = r; - rv |= r.translated(xOffset(), yOffset()); - return rv; -} - -void QFxShadowFilter::filterGL(QSimpleCanvasItem::GLPainter &p) -{ -#if defined(QFX_RENDER_OPENGL2) - - QSimpleCanvasItem *item = this->item(); - - QRect r = item->itemBoundingRect(); - - QGLFramebufferObject *fbo = renderToFBO(); - - float width = r.width(); - float height = r.height(); - - float texWidth = width / float(fbo->width()); - float texHeight = height / float(fbo->height()); - - GLfloat vertices[] = { d->x, height + d->y, - width + d->x, height + d->y, - d->x, d->y, - d->x + width, d->y }; - GLfloat texVertices[] = { 0, 0, - texWidth, 0, - 0, texHeight, - texWidth, texHeight }; - - SingleTextureShadowShader *shader = item->basicShaders()->singleTextureShadow(); - shader->enable(); - shader->setOpacity(0.8 * p.activeOpacity); - shader->setTransform(p.activeTransform); - - shader->setAttributeArray(SingleTextureShadowShader::Vertices, vertices, 2); - shader->setAttributeArray(SingleTextureShadowShader::TextureCoords, texVertices, 2); - - glBindTexture(GL_TEXTURE_2D, fbo->texture()); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - - shader->disableAttributeArray(SingleTextureShadowShader::Vertices); - shader->disableAttributeArray(SingleTextureShadowShader::TextureCoords); - - releaseFBO(fbo); - - renderToScreen(); -#else - Q_UNUSED(p); -#endif -} - -QML_DEFINE_TYPE(QFxShadowFilter,Shadow) - -QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxshadowfilter.h b/src/declarative/fx/qfxshadowfilter.h deleted file mode 100644 index 1cbe54f..0000000 --- a/src/declarative/fx/qfxshadowfilter.h +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QFXSHADOWFILTER_H -#define QFXSHADOWFILTER_H - -#include <QtDeclarative/qsimplecanvasfilter.h> -#include <QtDeclarative/qml.h> - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class QFxShadowFilterPrivate; -class Q_DECLARATIVE_EXPORT QFxShadowFilter : public QSimpleCanvasFilter -{ - Q_OBJECT - Q_PROPERTY(int xOffset READ xOffset WRITE setXOffset NOTIFY offsetChanged) - Q_PROPERTY(int yOffset READ yOffset WRITE setYOffset NOTIFY offsetChanged) -public: - QFxShadowFilter(QObject *parent=0); - virtual ~QFxShadowFilter(); - - int xOffset() const; - void setXOffset(int offset); - - int yOffset() const; - void setYOffset(int offset); - -Q_SIGNALS: - void offsetChanged(int, int); - -protected: - virtual QRectF itemBoundingRect(const QRectF &) const; - virtual void filterGL(QSimpleCanvasItem::GLPainter &p); - -private: - QFxShadowFilterPrivate *d; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QFxShadowFilter) - -QT_END_HEADER - -#endif // QFXSHADOWFILTER_H diff --git a/src/declarative/fx/qfxtext.cpp b/src/declarative/fx/qfxtext.cpp index 57897ed..8618b87 100644 --- a/src/declarative/fx/qfxtext.cpp +++ b/src/declarative/fx/qfxtext.cpp @@ -43,11 +43,6 @@ #include "qfxtext_p.h" #include <private/qtextcontrol_p.h> - -#if defined(QFX_RENDER_OPENGL2) -#include "glbasicshaders.h" -#endif - #include <private/qfxperf_p.h> #include <QTextLayout> #include <QTextLine> @@ -580,13 +575,6 @@ void QFxTextPrivate::updateSize() // ### text layout handling should be profiled and optimized as needed // what about QStackTextEngine engine(tmp, d->font.font()); QTextLayout textLayout(&engine); -void QFxText::dump(int depth) -{ - QByteArray ba(depth * 4, ' '); - qWarning() << ba.constData() << propertyInfo(); - QFxItem::dump(depth); -} - QString QFxText::propertyInfo() const { Q_D(const QFxText); @@ -765,10 +753,6 @@ void QFxTextPrivate::checkImgCache() break; } -#if defined(QFX_RENDER_OPENGL) - tex.setImage(imgCache.toImage(), GLTexture::PowerOfTwo); -#endif - imgDirty = false; } @@ -787,7 +771,6 @@ void QFxText::setSmoothTransform(bool s) update(); } -#if defined(QFX_RENDER_QPAINTER) void QFxText::paintContents(QPainter &p) { Q_D(QFxText); @@ -847,85 +830,6 @@ void QFxText::paintContents(QPainter &p) } } -#elif defined(QFX_RENDER_OPENGL2) -void QFxText::paintGLContents(GLPainter &p) -{ - //return; - Q_D(QFxText); - d->checkImgCache(); - if (d->imgCache.isNull()) - return; - - int w = width(); - int h = height(); - - float x = 0; - float y = 0; - - switch (d->hAlign) { - case AlignLeft: - x = 0; - break; - case AlignRight: - x = w - d->imgCache.width(); - break; - case AlignHCenter: - x = (w - d->imgCache.width()) / 2; - break; - } - - switch (d->vAlign) { - case AlignTop: - y = 0; - break; - case AlignBottom: - y = h - d->imgCache.height(); - break; - case AlignVCenter: - y = (h - d->imgCache.height()) / 2; - break; - } - - float widthV = d->imgCache.width(); - float heightV = d->imgCache.height(); - float glWidth = d->tex.glWidth(); - float glHeight = d->tex.glHeight(); - - QGLShaderProgram *shader = p.useTextureShader(); - - float deltaX = 0.5 / qreal(d->tex.glSize().width()); - float deltaY = 0.5 / qreal(d->tex.glSize().height()); - glWidth -= deltaX; - glHeight -= deltaY; - - GLfloat vertices[] = { x, y + heightV, - x + widthV, y + heightV, - x, y, - - x + widthV, y + heightV, - x, y, - x + widthV, y }; - - GLfloat texVertices[] = { deltaX, deltaY, - glWidth, deltaY, - deltaX, glHeight, - - glWidth, deltaY, - deltaX, glHeight, - glWidth, glHeight }; - - shader->setAttributeArray(SingleTextureShader::Vertices, vertices, 2); - shader->setAttributeArray(SingleTextureShader::TextureCoords, texVertices, 2); - - glBindTexture(GL_TEXTURE_2D, d->tex.texture()); - glDrawArrays(GL_TRIANGLES, 0, 6); - - shader->disableAttributeArray(SingleTextureShader::Vertices); - shader->disableAttributeArray(SingleTextureShader::TextureCoords); -} - -#endif - void QFxText::componentComplete() { Q_D(QFxText); diff --git a/src/declarative/fx/qfxtext.h b/src/declarative/fx/qfxtext.h index bd91f0e..b7ec333 100644 --- a/src/declarative/fx/qfxtext.h +++ b/src/declarative/fx/qfxtext.h @@ -125,14 +125,9 @@ public: bool smoothTransform() const; void setSmoothTransform(bool); - virtual void dump(int depth); virtual QString propertyInfo() const; -#if defined(QFX_RENDER_QPAINTER) void paintContents(QPainter &p); -#elif defined(QFX_RENDER_OPENGL) - void paintGLContents(GLPainter &); -#endif virtual void componentComplete(); @@ -153,7 +148,7 @@ protected: private: Q_DISABLE_COPY(QFxText) - Q_DECLARE_PRIVATE(QFxText) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxText) }; QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxtext_p.h b/src/declarative/fx/qfxtext_p.h index 670b685..6692d9e 100644 --- a/src/declarative/fx/qfxtext_p.h +++ b/src/declarative/fx/qfxtext_p.h @@ -58,10 +58,6 @@ #include "qml.h" #include <QtGui/qtextlayout.h> -#if defined(QFX_RENDER_OPENGL) -#include "gltexture.h" -#endif - QT_BEGIN_NAMESPACE class QTextLayout; @@ -116,9 +112,6 @@ public: QColor styleColor; QString activeLink; bool imgDirty; -#if defined(QFX_RENDER_OPENGL) - GLTexture tex; -#endif QPixmap imgCache; QPixmap imgStyleCache; QFxText::HAlignment hAlign; diff --git a/src/declarative/fx/qfxtextedit.cpp b/src/declarative/fx/qfxtextedit.cpp index c2bda6f..cdd94b5 100644 --- a/src/declarative/fx/qfxtextedit.cpp +++ b/src/declarative/fx/qfxtextedit.cpp @@ -41,13 +41,7 @@ #include <qfxtextedit.h> #include "qfxtextedit_p.h" - #include <private/qtextcontrol_p.h> - -#if defined(QFX_RENDER_OPENGL2) -#include "glbasicshaders.h" -#endif - #include <private/qfxperf_p.h> #include "qfxevents_p.h" #include <QTextLayout> @@ -686,16 +680,6 @@ void QFxTextEdit::geometryChanged(const QRectF &newGeometry, } /*! - \internal -*/ -void QFxTextEdit::dump(int depth) -{ - QByteArray ba(depth * 4, ' '); - qWarning() << ba.constData() << propertyInfo(); - QFxPaintedItem::dump(depth); -} - -/*! \internal */ QString QFxTextEdit::propertyInfo() const diff --git a/src/declarative/fx/qfxtextedit.h b/src/declarative/fx/qfxtextedit.h index 80636e2..77fac29 100644 --- a/src/declarative/fx/qfxtextedit.h +++ b/src/declarative/fx/qfxtextedit.h @@ -161,7 +161,6 @@ public: qreal textMargin() const; void setTextMargin(qreal margin); - virtual void dump(int depth); virtual QString propertyInfo() const; virtual void componentComplete(); @@ -229,7 +228,7 @@ private: friend class QmlFont; Q_DISABLE_COPY(QFxTextEdit) - Q_DECLARE_PRIVATE(QFxTextEdit) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxTextEdit) }; QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxtextedit_p.h b/src/declarative/fx/qfxtextedit_p.h index b7d667e..267e48b 100644 --- a/src/declarative/fx/qfxtextedit_p.h +++ b/src/declarative/fx/qfxtextedit_p.h @@ -89,9 +89,6 @@ public: QString style; QColor styleColor; bool imgDirty; -#if defined(QFX_RENDER_OPENGL) - GLTexture texture; -#endif QPixmap imgCache; QPixmap imgStyleCache; QFxTextEdit::HAlignment hAlign; diff --git a/src/declarative/fx/qfxtransform.cpp b/src/declarative/fx/qfxtransform.cpp index 0f0ce80..f08d830 100644 --- a/src/declarative/fx/qfxtransform.cpp +++ b/src/declarative/fx/qfxtransform.cpp @@ -71,9 +71,9 @@ bool QFxTransform::isIdentity() const return true; } -QSimpleCanvas::Matrix QFxTransform::transform() const +QTransform QFxTransform::transform() const { - return QSimpleCanvas::Matrix(); + return QTransform(); } void QFxTransform::update() @@ -181,7 +181,6 @@ bool QFxScale::isIdentity() const return (_xScale == 1. && _yScale == 1.); } -#if defined(QFX_RENDER_QPAINTER) QTransform QFxScale::transform() const { if (_dirty) { @@ -193,19 +192,6 @@ QTransform QFxScale::transform() const } return _transform; } -#elif defined(QFX_RENDER_OPENGL) -QMatrix4x4 QFxScale::transform() const -{ - if (_dirty) { - _transform = QMatrix4x4(); - _dirty = false; - _transform.translate(_originX, _originY); - _transform.scale(_xScale, _yScale); - _transform.translate(-_originX, -_originY); - } - return _transform; -} -#endif void QFxScale::update() { @@ -387,7 +373,6 @@ bool QFxRotation::isIdentity() const return (_angle == 0.); } -#if defined(QFX_RENDER_QPAINTER) QTransform QFxRotation::transform() const { if (_dirty) { @@ -399,19 +384,6 @@ QTransform QFxRotation::transform() const } return _transform; } -#elif defined(QFX_RENDER_OPENGL) -QMatrix4x4 QFxRotation::transform() const -{ - if (_dirty) { - _transform = QMatrix4x4(); - _dirty = false; - _transform.translate(_originX, _originY); - _transform.rotate(_angle, 0, 0, 1); - _transform.translate(-_originX, -_originY); - } - return _transform; -} -#endif void QFxRotation::update() { @@ -484,7 +456,6 @@ bool QFxRotation3D::isIdentity() const return (_angle == 0.) || (_axis.endZ() == 0. && _axis.endY() == _axis.startY() && _axis.endX() == _axis.startX()); } -#if defined(QFX_RENDER_QPAINTER) const qreal inv_dist_to_plane = 1. / 1024.; QTransform QFxRotation3D::transform() const { @@ -529,29 +500,6 @@ QTransform QFxRotation3D::transform() const return _transform; } -#elif defined(QFX_RENDER_OPENGL) -QMatrix4x4 QFxRotation3D::transform() const -{ - if (_dirty) { - _dirty = false; - _transform = QMatrix4x4(); - - if (!isIdentity()) { - if (angle() != 0.) { - qreal x = _axis.endX() - _axis.startX(); - qreal y = _axis.endY() - _axis.startY(); - qreal z = _axis.endZ(); - - _transform.translate(_axis.startX(), _axis.startY(), 0); - _transform.rotate(angle(), x, y, z); - _transform.translate(-_axis.startX(), -_axis.startY(), 0); - } - } - } - - return _transform; -} -#endif void QFxRotation3D::update() { @@ -639,7 +587,6 @@ bool QFxTranslation3D::isIdentity() const return (_distance == 0.) || (_axis.endZ() == 0. && _axis.endY() == _axis.startY() && _axis.endX() == _axis.startX()); } -#if defined(QFX_RENDER_QPAINTER) QTransform QFxTranslation3D::transform() const { if (_dirty) { @@ -659,35 +606,14 @@ QTransform QFxTranslation3D::transform() const return _transform; } -#elif defined(QFX_RENDER_OPENGL) -QMatrix4x4 QFxTranslation3D::transform() const -{ - if (_dirty) { - _dirty = false; - _transform = QMatrix4x4(); - - if (!isIdentity()) { - if (distance() != 0.) - _transform.translate((_axis.endX() - _axis.startX()) * distance(), - (_axis.endY() - _axis.startY()) * distance(), - (_axis.endZ()) * distance()); - - } - } - - return _transform; -} -#endif void QFxTranslation3D::update() { _dirty = true; -#if !defined(QFX_RENDER_OPENGL) if (_axis.endZ() != 0. && distance() != 0.) { qmlInfo(this) << "QTransform cannot translate along Z-axis."; } -#endif QFxTransform::update(); } @@ -712,24 +638,6 @@ QFxPerspective::~QFxPerspective() { } -#if defined(QFX_RENDER_OPENGL) -bool QFxPerspective::isIdentity() const -{ - return false; -} - -QMatrix4x4 QFxPerspective::transform() const -{ - QMatrix4x4 rv; - rv.translate(_x, _y); - rv.perspective(_angle, _aspect, 1, 1024 * 1024); - rv.translate(-_x, -_y, -1); - rv.scale(1, 1, 1. / _scale); - - return rv; -} -#endif - /*! \qmlproperty real Perspective::angle */ @@ -996,7 +904,6 @@ bool QFxSquish::isIdentity() const return false; } -#if defined(QFX_RENDER_QPAINTER) QTransform QFxSquish::transform() const { QPolygonF poly; @@ -1008,21 +915,5 @@ QTransform QFxSquish::transform() const QTransform::quadToQuad(poly, poly2, t); return t; } -#elif defined(QFX_RENDER_OPENGL) -QMatrix4x4 QFxSquish::transform() const -{ - QPolygonF poly; - poly << p << QPointF(p.x() + s.width(), p.y()) << QPointF(p.x() + s.width(), p.y() + s.height()) << QPointF(p.x(), p.y() + s.height()); - QPolygonF poly2; - poly2 << p1 << p2 << p4 << p3; - - QTransform t; - QMatrix4x4 rv; - if (QTransform::quadToQuad(poly, poly2, t)) - rv = QMatrix4x4(t); - - return rv; -} -#endif QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxtransform.h b/src/declarative/fx/qfxtransform.h index e0bd276..fb49294 100644 --- a/src/declarative/fx/qfxtransform.h +++ b/src/declarative/fx/qfxtransform.h @@ -44,9 +44,6 @@ #include <QtCore/QObject> #include <QtGui/QTransform> -#if defined(QFX_RENDER_OPENGL) -#include <QtGui/qmatrix4x4.h> -#endif #include <QtDeclarative/qfxitem.h> QT_BEGIN_HEADER @@ -65,7 +62,7 @@ public: void update(); virtual bool isIdentity() const; - virtual QSimpleCanvas::Matrix transform() const; + virtual QTransform transform() const; }; class Q_DECLARATIVE_EXPORT QFxScale : public QFxTransform @@ -93,7 +90,7 @@ public: void setYScale(qreal); virtual bool isIdentity() const; - virtual QSimpleCanvas::Matrix transform() const; + virtual QTransform transform() const; Q_SIGNALS: void scaleChanged(); @@ -107,7 +104,7 @@ private: qreal _yScale; mutable bool _dirty; - mutable QSimpleCanvas::Matrix _transform; + mutable QTransform _transform; }; class Q_DECLARATIVE_EXPORT QFxAxis : public QObject @@ -170,7 +167,7 @@ public: void setAngle(qreal); virtual bool isIdentity() const; - virtual QSimpleCanvas::Matrix transform() const; + virtual QTransform transform() const; Q_SIGNALS: void angleChanged(); @@ -183,7 +180,7 @@ private: qreal _angle; mutable bool _dirty; - mutable QSimpleCanvas::Matrix _transform; + mutable QTransform _transform; }; class Q_DECLARATIVE_EXPORT QFxRotation3D : public QFxTransform @@ -202,7 +199,7 @@ public: void setAngle(qreal); virtual bool isIdentity() const; - virtual QSimpleCanvas::Matrix transform() const; + virtual QTransform transform() const; private Q_SLOTS: void update(); @@ -211,7 +208,7 @@ private: qreal _angle; mutable bool _dirty; - mutable QSimpleCanvas::Matrix _transform; + mutable QTransform _transform; }; class Q_DECLARATIVE_EXPORT QFxTranslation3D : public QFxTransform @@ -230,7 +227,7 @@ public: void setDistance(qreal); virtual bool isIdentity() const; - virtual QSimpleCanvas::Matrix transform() const; + virtual QTransform transform() const; private Q_SLOTS: void update(); @@ -239,7 +236,7 @@ private: qreal _distance; mutable bool _dirty; - mutable QSimpleCanvas::Matrix _transform; + mutable QTransform _transform; }; class Q_DECLARATIVE_EXPORT QFxPerspective : public QFxTransform @@ -270,10 +267,6 @@ public: qreal scale() const { return _scale; } void setScale(qreal v) { _scale = v; update(); } -#if defined(QFX_RENDER_OPENGL) - virtual bool isIdentity() const; - virtual QMatrix4x4 transform() const; -#endif private: qreal _scale; qreal _x; @@ -339,7 +332,7 @@ public: void setbottomRight_x(qreal); virtual bool isIdentity() const; - virtual QSimpleCanvas::Matrix transform() const; + virtual QTransform transform() const; private: QPointF p; diff --git a/src/declarative/fx/qfxvisualitemmodel.cpp b/src/declarative/fx/qfxvisualitemmodel.cpp index d3ab4cc..eb10df3 100644 --- a/src/declarative/fx/qfxvisualitemmodel.cpp +++ b/src/declarative/fx/qfxvisualitemmodel.cpp @@ -51,6 +51,7 @@ #include "qmlopenmetaobject.h" #include "qmllistaccessor.h" #include "qfxvisualitemmodel.h" +#include <QtCore/qdebug.h> QML_DECLARE_TYPE(QListModelInterface) diff --git a/src/declarative/fx/qfxwebview.cpp b/src/declarative/fx/qfxwebview.cpp index 3ab64bc..da10004 100644 --- a/src/declarative/fx/qfxwebview.cpp +++ b/src/declarative/fx/qfxwebview.cpp @@ -56,19 +56,9 @@ #include "qmlstate.h" #include "qfxtransform.h" #include "qfxscalegrid.h" -#include "qsimplecanvas.h" #include "qlistmodelinterface.h" -#if defined(QFX_RENDER_OPENGL2) -#include <QtOpenGL/qglframebufferobject.h> -#include <glsave.h> -#endif -#if defined(QFX_RENDER_OPENGL) -#include <gltexture.h> -#endif - #include "qfxwebview.h" -#include <qsimplecanvasfilter.h> #include <private/qfxpainteditem_p.h> QT_BEGIN_NAMESPACE @@ -465,11 +455,51 @@ void QFxWebView::paintPage(const QRect& r) update(); } -void QFxWebView::dump(int depth) +/*! + \qmlproperty int WebView::cacheSize + + This property holds the maximum number of pixels of image cache to + allow. The default is 0.1 megapixels. The cache will not be larger + than the (unscaled) size of the WebView. +*/ + +/*! + \property QFxWebView::cacheSize + + The maximum number of pixels of image cache to allow. The default + is 0.1 megapixels. The cache will not be larger than the (unscaled) + size of the QFxWebView. +*/ +int QFxWebView::cacheSize() const { - QByteArray ba(depth * 4, ' '); - qWarning() << ba.constData() << "url:" << url(); - QFxPaintedItem::dump(depth); + Q_D(const QFxWebView); + return d->max_imagecache_size; +} + +void QFxWebView::setCacheSize(int pixels) +{ + Q_D(QFxWebView); + if (pixels < d->max_imagecache_size) { + int cachesize=0; + for (int i=0; i<d->imagecache.count(); ++i) { + QRect area = d->imagecache[i]->area; + cachesize += area.width()*area.height(); + } + while (d->imagecache.count() && cachesize > pixels) { + int oldest=-1; + int age=-1; + for (int i=0; i<d->imagecache.count(); ++i) { + int a = d->imagecache[i]->age; + if (a > age) { + oldest = i; + age = a; + } + } + cachesize -= d->imagecache[oldest]->area.width()*d->imagecache[oldest]->area.height(); + d->imagecache.removeAt(oldest); + } + } + d->max_imagecache_size = pixels; } void QFxWebView::drawContents(QPainter *p, const QRect &r) diff --git a/src/declarative/fx/qfxwebview.h b/src/declarative/fx/qfxwebview.h index f5fd721..ab20281 100644 --- a/src/declarative/fx/qfxwebview.h +++ b/src/declarative/fx/qfxwebview.h @@ -139,7 +139,6 @@ public: QAction *forwardAction() const; QAction *stopAction() const; - virtual void dump(int depth); virtual QString propertyInfo() const; QWebPage *page() const; @@ -160,6 +159,9 @@ public: QString status() const; + int cacheSize() const; + void setCacheSize(int pixels); + Q_SIGNALS: void idealWidthChanged(); void idealHeightChanged(); @@ -204,7 +206,7 @@ private: void init(); virtual void componentComplete(); Q_DISABLE_COPY(QFxWebView) - Q_DECLARE_PRIVATE(QFxWebView) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxWebView) }; QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxwidgetcontainer.cpp b/src/declarative/fx/qfxwidgetcontainer.cpp index 421c2f7..ea702db 100644 --- a/src/declarative/fx/qfxwidgetcontainer.cpp +++ b/src/declarative/fx/qfxwidgetcontainer.cpp @@ -40,7 +40,6 @@ ****************************************************************************/ #include "qfxwidgetcontainer.h" -#include <qsimplecanvas.h> #include <qgraphicswidget.h> QT_BEGIN_NAMESPACE @@ -83,17 +82,7 @@ void QFxWidgetContainer::setGraphicsWidget(QGraphicsWidget *widget) _graphicsWidget = widget; - QSimpleCanvas *c = canvas(); - if (!c) - return; - - if (c->canvasMode() != QSimpleCanvas::GraphicsView) { - qWarning("QFxWidgetContainer: Cannot add a widget to a non-graphicsview canvas. You might need to set QFX_USE_GRAPHICSVIEW=1"); - return; - } - - QGraphicsItem *item = (QGraphicsItem *)(*this); - _graphicsWidget->setParentItem(item); + _graphicsWidget->setParentItem(this); } void QFxWidgetContainer::canvasChanged() diff --git a/src/declarative/opengl/glbasicshaders.cpp b/src/declarative/opengl/glbasicshaders.cpp deleted file mode 100644 index 7c1d730..0000000 --- a/src/declarative/opengl/glbasicshaders.cpp +++ /dev/null @@ -1,707 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "glbasicshaders.h" -#include <QDebug> -#include <QColor> - - -QT_BEGIN_NAMESPACE -SingleTextureVertexOpacityShader::SingleTextureVertexOpacityShader() -{ - QGLShader vert(QGLShader::VertexShader); - QGLShader frag(QGLShader::FragmentShader); - - vert.compile("\ - attribute highp vec4 myVertex;\ - attribute lowp float myOpacity;\ - attribute mediump vec4 myUV;\ - uniform mediump mat4 myPMVMatrix;\ - varying mediump vec2 myTexCoord;\ - varying lowp float myFragOpacity;\ - void main(void)\ - {\ - gl_Position = myPMVMatrix * myVertex;\ - myTexCoord = myUV.st;\ - myFragOpacity = myOpacity;\ - }" - ); - - frag.compile("\ - uniform sampler2D sampler2d;\ - varying mediump vec2 myTexCoord;\ - varying lowp float myFragOpacity;\ - void main(void)\ - {\ - mediump vec4 frag = texture2D(sampler2d,myTexCoord);\ - gl_FragColor = vec4(frag.rgb, frag.a * myFragOpacity);\ - }" - ); - - addShader(&vert); - addShader(&frag); - - bindAttributeLocation("myVertex", Vertices); - bindAttributeLocation("myUV", TextureCoords); - bindAttributeLocation("myOpacity", OpacityCoords); -} - -bool SingleTextureVertexOpacityShader::link() -{ - if (!QGLShaderProgram::link()) - return false; - transform = uniformLocation("myPMVMatrix"); - enable(); - setUniformValue("sampler2d", 0); - disable(); - return true; -} - -void SingleTextureVertexOpacityShader::setTransform(const QMatrix4x4 &matrix) -{ - setUniformValue(transform, matrix); -} - -BlurTextureShader::BlurTextureShader() -{ - QGLShader vert(QGLShader::VertexShader); - QGLShader frag(QGLShader::FragmentShader); - - vert.compile("\ - attribute highp vec4 myVertex;\ - attribute mediump vec4 myUV;\ - uniform mediump mat4 myPMVMatrix;\ - varying mediump vec2 myTexCoord;\ - void main(void)\ - {\ - gl_Position = myPMVMatrix * myVertex;\ - myTexCoord = myUV.st;\ - }" - ); - -#if 0 - frag.compile("\ - uniform sampler2D sampler2d;\ - uniform bool horizontal; \ - uniform mediump float blurStep; \ - varying mediump vec2 myTexCoord;\ - void main(void)\ - {\ - mediump vec4 accum = vec4(0, 0, 0, 0); \ - mediump vec2 offset; \ - if (horizontal) \ - offset = vec2(blurStep, 0); \ - else \ - offset = vec2(0, blurStep); \ - accum += texture2D(sampler2d, myTexCoord + 2.0 * offset); \ - accum += 2.0 * texture2D(sampler2d, myTexCoord + 1.0 * offset); \ - accum += 4.0 * texture2D(sampler2d, myTexCoord + 0.0 * offset); \ - accum += 2.0 * texture2D(sampler2d, myTexCoord - 1.0 * offset); \ - accum += texture2D(sampler2d, myTexCoord - 2.0 * offset); \ - gl_FragColor = accum / 10.0; \ - }" - ); -#else - frag.compile("\ - uniform sampler2D sampler2d;\ - uniform bool horizontal; \ - uniform mediump float blurStep; \ - uniform int blurSteps; \ - varying mediump vec2 myTexCoord;\ - void main(void)\ - {\ - mediump vec4 accum = vec4(0, 0, 0, 0); \ - mediump vec2 offset; \ - if (horizontal) \ - offset = vec2(blurStep, 0); \ - else \ - offset = vec2(0, blurStep); \ - mediump float sum = 0.0; \ - for (int ii = 0; ii < blurSteps; ++ii) { \ - mediump float frac = float(blurSteps - ii) / float(blurSteps); \ - mediump vec2 coord = myTexCoord + -float(ii) * offset; \ - if (coord.x >= 0.0 && coord.y >= 0.0 && coord.y <= 1.0 && coord.x <=1.0) \ - accum += texture2D(sampler2d, coord) * frac; \ - sum += frac; \ - } \ - for (int ii = 1; ii < blurSteps; ++ii) { \ - mediump float frac = float(blurSteps - ii) / float(blurSteps); \ - mediump vec2 coord = myTexCoord + float(ii) * offset; \ - if (coord.x <= 1.0 && coord.y <= 1.0 && coord.x >= 0.0 && coord.y >= 0.0) \ - accum += texture2D(sampler2d, coord) * frac; \ - sum += frac; \ - } \ - gl_FragColor = accum / sum; \ - }" - ); -#endif - - addShader(&vert); - addShader(&frag); - - bindAttributeLocation("myVertex", Vertices); - bindAttributeLocation("myUV", TextureCoords); -} - -bool BlurTextureShader::link() -{ - if (!QGLShaderProgram::link()) - return false; - transform = uniformLocation("myPMVMatrix"); - mode = uniformLocation("horizontal"); - step = uniformLocation("blurStep"); - steps = uniformLocation("blurSteps"); - enable(); - setUniformValue("sampler2d", 0); - disable(); - return true; -} - -void BlurTextureShader::setStep(float f) -{ - setUniformValue(step, f); -} - -void BlurTextureShader::setSteps(int s) -{ - setUniformValue(steps, s); -} - -void BlurTextureShader::setMode(Mode m) -{ - if (m == Horizontal) - setUniformValue(mode, 1); - else - setUniformValue(mode, 0); -} - -void BlurTextureShader::setTransform(const QMatrix4x4 &matrix) -{ - setUniformValue(transform, matrix); -} - -DualTextureBlendShader::DualTextureBlendShader() -{ - QGLShader vert(QGLShader::VertexShader); - QGLShader frag(QGLShader::FragmentShader); - - vert.compile("\ - attribute highp vec4 myVertex;\ - attribute mediump vec4 myUV;\ - attribute mediump vec4 myBlendUV;\ - uniform mediump mat4 myPMVMatrix;\ - varying mediump vec2 myTexCoord;\ - varying mediump vec2 myBlendTexCoord;\ - void main(void)\ - {\ - gl_Position = myPMVMatrix * myVertex;\ - myTexCoord = myUV.st;\ - myBlendTexCoord = myBlendUV.st;\ - }" - ); - - frag.compile("\ - uniform sampler2D sampler2d;\ - uniform sampler2D sampler2dBlend;\ - uniform lowp float myOpacity;\ - uniform lowp float myBlend; \ - varying mediump vec2 myTexCoord;\ - varying mediump vec2 myBlendTexCoord;\ - void main(void)\ - {\ - mediump vec4 tex = texture2D(sampler2d,myTexCoord);\ - mediump vec4 blendtex = texture2D(sampler2dBlend, myBlendTexCoord);\ - gl_FragColor = mix(tex, blendtex, myBlend) * myOpacity; \ - }" - ); - - addShader(&vert); - addShader(&frag); - - bindAttributeLocation("myVertex", Vertices); - bindAttributeLocation("myUV", TextureCoords); - bindAttributeLocation("myBlendUV", BlendTextureCoords); -} - -bool DualTextureBlendShader::link() -{ - if (!QGLShaderProgram::link()) - return false; - transform = uniformLocation("myPMVMatrix"); - opacity = uniformLocation("myOpacity"); - blend = uniformLocation("myBlend"); - enable(); - setUniformValue("sampler2d", 0); - setUniformValue("sampler2dBlend", 1); - disable(); - return true; -} - -void DualTextureBlendShader::setOpacity(GLfloat o) -{ - setUniformValue(opacity, o); -} - -void DualTextureBlendShader::setBlend(GLfloat b) -{ - setUniformValue(blend, b); -} - -void DualTextureBlendShader::setTransform(const QMatrix4x4 &matrix) -{ - setUniformValue(transform, matrix); -} - -DualTextureAddShader::DualTextureAddShader() -{ - QGLShader vert(QGLShader::VertexShader); - QGLShader frag(QGLShader::FragmentShader); - - vert.compile("\ - attribute highp vec4 myVertex;\ - attribute mediump vec4 myUV;\ - attribute mediump vec4 myAddUV;\ - uniform mediump mat4 myPMVMatrix;\ - varying mediump vec2 myTexCoord;\ - varying mediump vec2 myAddTexCoord;\ - void main(void)\ - {\ - gl_Position = myPMVMatrix * myVertex;\ - myTexCoord = myUV.st;\ - myAddTexCoord = myAddUV.st;\ - }" - ); - - frag.compile("\ - uniform sampler2D sampler2d;\ - uniform sampler2D sampler2dAdd;\ - uniform lowp float myOpacity;\ - varying mediump vec2 myTexCoord;\ - varying mediump vec2 myAddTexCoord;\ - void main(void)\ - {\ - mediump vec4 tex = texture2D(sampler2d,myTexCoord);\ - mediump vec4 addtex = texture2D(sampler2dAdd, myAddTexCoord);\ - tex = tex + vec4(addtex.rgb * addtex.a * tex.a, 0); \ - tex = min(tex, vec4(1, 1, 1, 1)); \ - gl_FragColor = vec4(tex.rgb, tex.a) * myOpacity;\ - }" - ); - - addShader(&vert); - addShader(&frag); - - bindAttributeLocation("myVertex", Vertices); - bindAttributeLocation("myUV", TextureCoords); - bindAttributeLocation("myAddUV", AddTextureCoords); -} - -void DualTextureAddShader::setOpacity(GLfloat f) -{ - setUniformValue(opacity, f); -} - -void DualTextureAddShader::setTransform(const QMatrix4x4 &matrix) -{ - setUniformValue(transform, matrix); -} - -bool DualTextureAddShader::link() -{ - if (!QGLShaderProgram::link()) - return false; - transform = uniformLocation("myPMVMatrix"); - opacity = uniformLocation("myOpacity"); - enable(); - setUniformValue("sampler2d", 0); - setUniformValue("sampler2dAdd", 1); - disable(); - return true; -} - -SingleTextureShader::SingleTextureShader() -{ - QGLShader vert(QGLShader::VertexShader); - QGLShader frag(QGLShader::FragmentShader); - - vert.compile("\ - attribute highp vec4 myVertex;\ - attribute mediump vec4 myUV;\ - uniform mediump mat4 myPMVMatrix;\ - varying mediump vec2 myTexCoord;\ - void main(void)\ - {\ - gl_Position = myPMVMatrix * myVertex;\ - myTexCoord = myUV.st;\ - }" - ); - - frag.compile("\ - uniform sampler2D sampler2d;\ - varying mediump vec2 myTexCoord;\ - void main(void)\ - {\ - gl_FragColor = texture2D(sampler2d,myTexCoord);\ - }" - ); - - addShader(&vert); - addShader(&frag); - - bindAttributeLocation("myVertex", Vertices); - bindAttributeLocation("myUV", TextureCoords); -} - -bool SingleTextureShader::link() -{ - if (!QGLShaderProgram::link()) - return false; - transform = uniformLocation("myPMVMatrix"); - enable(); - setUniformValue("sampler2d", 0); - disable(); - return true; -} - -void SingleTextureShader::setTransform(const QMatrix4x4 &matrix) -{ - setUniformValue(transform, matrix); -} - -ConstantColorShader::ConstantColorShader() -{ - QGLShader vert(QGLShader::VertexShader); - QGLShader frag(QGLShader::FragmentShader); - - vert.compile("\ - uniform mediump mat4 myPMVMatrix;\ - attribute highp vec4 myVertex;\ - void main(void)\ - {\ - gl_Position = myPMVMatrix * myVertex; \ - }" - ); - - frag.compile("\ - uniform lowp vec4 myColor;\ - void main(void)\ - {\ - gl_FragColor = myColor;\ - }" - ); - - addShader(&vert); - addShader(&frag); - - bindAttributeLocation("myVertex", Vertices); -} - -void ConstantColorShader::setColor(const QColor &c) -{ - setUniformValue(color, c); -} - -void ConstantColorShader::setTransform(const QMatrix4x4 &matrix) -{ - setUniformValue(transform, matrix); -} - -bool ConstantColorShader::link() -{ - if (!QGLShaderProgram::link()) - return false; - transform = uniformLocation("myPMVMatrix"); - color = uniformLocation("myColor"); - return true; -} - -ColorShader::ColorShader() -{ - QGLShader vert(QGLShader::VertexShader); - QGLShader frag(QGLShader::FragmentShader); - - vert.compile("\ - uniform mediump mat4 myPMVMatrix;\ - attribute highp vec4 myVertex;\ - attribute lowp vec4 myColors;\ - varying lowp vec4 myColor;\ - void main(void)\ - {\ - gl_Position = myPMVMatrix * myVertex; \ - myColor = myColors; \ - }" - ); - - frag.compile("\ - varying lowp vec4 myColor;\ - void main(void)\ - {\ - gl_FragColor = myColor;\ - }" - ); - - addShader(&vert); - addShader(&frag); - - bindAttributeLocation("myVertex", Vertices); - bindAttributeLocation("myColors", Colors); -} - -void ColorShader::setTransform(const QMatrix4x4 &matrix) -{ - setUniformValue(transform, matrix); -} - -bool ColorShader::link() -{ - if (!QGLShaderProgram::link()) - return false; - transform = uniformLocation("myPMVMatrix"); - return true; -} - -class GLBasicShadersPrivate -{ -public: - GLBasicShadersPrivate(); - ~GLBasicShadersPrivate(); - - BlurTextureShader *blurTexture; - SingleTextureShader *singleTexture; - SingleTextureOpacityShader *singleTextureOpacity; - DualTextureAddShader *dualTextureAdd; - SingleTextureShadowShader *singleTextureShadow; - SingleTextureVertexOpacityShader *singleTextureVertexOpacity; - ConstantColorShader *constantColor; - ColorShader *color; -}; - -GLBasicShadersPrivate::GLBasicShadersPrivate() -: blurTexture(0), singleTexture(0), singleTextureOpacity(0), - dualTextureAdd(0), singleTextureShadow(0), singleTextureVertexOpacity(0), - constantColor(0), color(0) -{ -} - -GLBasicShadersPrivate::~GLBasicShadersPrivate() -{ - delete blurTexture; - delete singleTexture; - delete singleTextureOpacity; - delete dualTextureAdd; - delete singleTextureVertexOpacity; - delete singleTextureShadow; - delete constantColor; - delete color; -} - -GLBasicShaders::GLBasicShaders() -: d(new GLBasicShadersPrivate) -{ -} - -GLBasicShaders::~GLBasicShaders() -{ - delete d; -} - -BlurTextureShader *GLBasicShaders::blurTexture() -{ - if (!d->blurTexture) d->blurTexture = new BlurTextureShader(); - return d->blurTexture; -} - -SingleTextureShader *GLBasicShaders::singleTexture() -{ - if (!d->singleTexture) d->singleTexture = new SingleTextureShader(); - return d->singleTexture; -} - -SingleTextureOpacityShader *GLBasicShaders::singleTextureOpacity() -{ - if (!d->singleTextureOpacity) d->singleTextureOpacity = new SingleTextureOpacityShader(); - return d->singleTextureOpacity; -} - -DualTextureAddShader *GLBasicShaders::dualTextureAdd() -{ - if (!d->dualTextureAdd) d->dualTextureAdd = new DualTextureAddShader(); - return d->dualTextureAdd; -} - -SingleTextureVertexOpacityShader *GLBasicShaders::singleTextureVertexOpacity() -{ - if (!d->singleTextureVertexOpacity) d->singleTextureVertexOpacity = new SingleTextureVertexOpacityShader(); - return d->singleTextureVertexOpacity; -} - -SingleTextureShadowShader *GLBasicShaders::singleTextureShadow() -{ - if (!d->singleTextureShadow) d->singleTextureShadow = new SingleTextureShadowShader(); - return d->singleTextureShadow; -} - -ConstantColorShader *GLBasicShaders::constantColor() -{ - if (!d->constantColor) d->constantColor = new ConstantColorShader(); - return d->constantColor; -} - -ColorShader *GLBasicShaders::color() -{ - if (!d->color) d->color = new ColorShader(); - return d->color; -} - -SingleTextureOpacityShader::SingleTextureOpacityShader() -{ - QGLShader vert(QGLShader::VertexShader); - QGLShader frag(QGLShader::FragmentShader); - - vert.compile("\ - attribute highp vec4 myVertex;\ - attribute mediump vec4 myUV;\ - uniform mediump mat4 myPMVMatrix;\ - varying mediump vec2 myTexCoord;\ - void main(void)\ - {\ - gl_Position = myPMVMatrix * myVertex;\ - myTexCoord = myUV.st;\ - }" - ); - - frag.compile("\ - uniform sampler2D sampler2d;\ - uniform lowp float myOpacity;\ - varying mediump vec2 myTexCoord;\ - void main(void)\ - {\ - mediump vec4 tex = texture2D(sampler2d,myTexCoord);\ - gl_FragColor = vec4(tex.rgb, myOpacity * tex.a);\ - }" - ); - - addShader(&vert); - addShader(&frag); - - bindAttributeLocation("myVertex", Vertices); - bindAttributeLocation("myUV", TextureCoords); -} - -bool SingleTextureOpacityShader::link() -{ - if (!QGLShaderProgram::link()) - return false; - transform = uniformLocation("myPMVMatrix"); - opacity = uniformLocation("myOpacity"); - enable(); - setUniformValue("sampler2d", 0); - disable(); - return true; -} - -void SingleTextureOpacityShader::setTransform(const QMatrix4x4 &matrix) -{ - setUniformValue(transform, matrix); -} - -void SingleTextureOpacityShader::setOpacity(GLfloat f) -{ - setUniformValue(opacity, f); -} - -SingleTextureShadowShader::SingleTextureShadowShader() -{ - QGLShader vert(QGLShader::VertexShader); - QGLShader frag(QGLShader::FragmentShader); - - vert.compile("\ - attribute highp vec4 myVertex;\ - attribute mediump vec4 myUV;\ - uniform mediump mat4 myPMVMatrix;\ - varying mediump vec2 myTexCoord;\ - void main(void)\ - {\ - gl_Position = myPMVMatrix * myVertex;\ - myTexCoord = myUV.st;\ - }" - ); - - frag.compile("\ - uniform sampler2D sampler2d;\ - uniform lowp float myOpacity;\ - varying mediump vec2 myTexCoord;\ - void main(void)\ - {\ - mediump vec4 tex = texture2D(sampler2d,myTexCoord);\ - gl_FragColor = vec4(0, 0, 0, myOpacity * tex.a * .75);\ - }" - ); - - addShader(&vert); - addShader(&frag); - - bindAttributeLocation("myVertex", Vertices); - bindAttributeLocation("myUV", TextureCoords); -} - -bool SingleTextureShadowShader::link() -{ - if (!QGLShaderProgram::link()) - return false; - transform = uniformLocation("myPMVMatrix"); - opacity = uniformLocation("myOpacity"); - enable(); - setUniformValue("sampler2d", 0); - disable(); - return true; -} - -void SingleTextureShadowShader::setTransform(const QMatrix4x4 &matrix) -{ - setUniformValue(transform, matrix); -} - -void SingleTextureShadowShader::setOpacity(GLfloat f) -{ - setUniformValue(opacity, f); -} -QT_END_NAMESPACE diff --git a/src/declarative/opengl/glbasicshaders.h b/src/declarative/opengl/glbasicshaders.h deleted file mode 100644 index 877f0fc..0000000 --- a/src/declarative/opengl/glbasicshaders.h +++ /dev/null @@ -1,243 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef _GLBASICSHADERS_H_ -#define _GLBASICSHADERS_H_ - -#include <QtOpenGL/qglshaderprogram.h> -#include <QtGui/qmatrix4x4.h> - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class BlurTextureShader : public QGLShaderProgram -{ - Q_OBJECT -public: - BlurTextureShader(); - - enum { Vertices = 0, - TextureCoords = 1 }; - - enum Mode { Horizontal, Vertical }; - void setMode(Mode); - void setStep(float); - void setSteps(int); - void setTransform(const QMatrix4x4 &); - virtual bool link(); - -private: - GLint mode; - GLint step; - GLint steps; - GLint transform; -}; - -class SingleTextureShader : public QGLShaderProgram -{ - Q_OBJECT -public: - SingleTextureShader(); - - enum { Vertices = 0, - TextureCoords = 1 }; - - void setTransform(const QMatrix4x4 &); - virtual bool link(); - -private: - GLint transform; -}; - -class DualTextureBlendShader : public QGLShaderProgram -{ - Q_OBJECT -public: - DualTextureBlendShader(); - enum { Vertices = 0, - TextureCoords = 1, - BlendTextureCoords = 2 }; - - void setOpacity(GLfloat); - void setBlend(GLfloat); - void setTransform(const QMatrix4x4 &); - virtual bool link(); - -private: - GLint transform; - GLint opacity; - GLint blend; -}; - -class DualTextureAddShader : public QGLShaderProgram -{ - Q_OBJECT -public: - DualTextureAddShader(); - enum { Vertices = 0, - TextureCoords = 1, - AddTextureCoords = 2 }; - - void setOpacity(GLfloat); - void setTransform(const QMatrix4x4 &); - virtual bool link(); - -private: - GLint transform; - GLint opacity; -}; - -class SingleTextureOpacityShader : public QGLShaderProgram -{ - Q_OBJECT -public: - SingleTextureOpacityShader(); - - enum { Vertices = 0, - TextureCoords = 1 }; - - void setOpacity(GLfloat); - void setTransform(const QMatrix4x4 &); - virtual bool link(); - -private: - GLint transform; - GLint opacity; -}; - -class SingleTextureVertexOpacityShader : public QGLShaderProgram -{ - Q_OBJECT -public: - SingleTextureVertexOpacityShader(); - - enum { Vertices = 0, - TextureCoords = 1, - OpacityCoords = 2 }; - - void setTransform(const QMatrix4x4 &); - virtual bool link(); - -private: - GLint transform; -}; - - -class SingleTextureShadowShader : public QGLShaderProgram -{ - Q_OBJECT -public: - SingleTextureShadowShader(); - - enum { Vertices = 0, - TextureCoords = 1 }; - - void setOpacity(GLfloat); - void setTransform(const QMatrix4x4 &); - virtual bool link(); - -private: - GLint transform; - GLint opacity; -}; - - -class QColor; -class ConstantColorShader : public QGLShaderProgram -{ - Q_OBJECT -public: - ConstantColorShader(); - - enum { Vertices = 0 }; - - void setColor(const QColor &); - void setTransform(const QMatrix4x4 &); - virtual bool link(); - -private: - GLint transform; - GLint color; -}; - -class ColorShader : public QGLShaderProgram -{ - Q_OBJECT -public: - ColorShader(); - - enum { Vertices = 0, Colors = 1 }; - - void setTransform(const QMatrix4x4 &); - virtual bool link(); - -private: - GLint transform; -}; - -class GLBasicShadersPrivate; -class GLBasicShaders -{ -public: - GLBasicShaders(); - virtual ~GLBasicShaders(); - - BlurTextureShader *blurTexture(); - SingleTextureShader *singleTexture(); - SingleTextureOpacityShader *singleTextureOpacity(); - DualTextureAddShader *dualTextureAdd(); - SingleTextureVertexOpacityShader *singleTextureVertexOpacity(); - SingleTextureShadowShader *singleTextureShadow(); - ConstantColorShader *constantColor(); - ColorShader *color(); - -private: - GLBasicShadersPrivate *d; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // _GLBASICSHADERS_H_ diff --git a/src/declarative/opengl/glheaders.h b/src/declarative/opengl/glheaders.h deleted file mode 100644 index fd1da18..0000000 --- a/src/declarative/opengl/glheaders.h +++ /dev/null @@ -1,49 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef _GLHEADERS_H_ -#define _GLHEADERS_H_ - -#include <QtDeclarative/qfxglobal.h> -#define GL_GLEXT_PROTOTYPES 1 -#include <QtOpenGL/qgl.h> - -#endif // _GLHEADERS_H_ diff --git a/src/declarative/opengl/glsave.cpp b/src/declarative/opengl/glsave.cpp deleted file mode 100644 index 125e81b..0000000 --- a/src/declarative/opengl/glsave.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "glsave.h" diff --git a/src/declarative/opengl/glsave.h b/src/declarative/opengl/glsave.h deleted file mode 100644 index ad6c0ec..0000000 --- a/src/declarative/opengl/glsave.h +++ /dev/null @@ -1,111 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef _GLSAVE_H_ -#define _GLSAVE_H_ - -#include <QtCore/qglobal.h> -#include <QtDeclarative/qfxglobal.h> -#include <QtCore/QRect> -#include "glheaders.h" - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class GLSaveViewport -{ -public: - GLSaveViewport() - { - glGetIntegerv(GL_VIEWPORT, viewport); - } - - ~GLSaveViewport() - { - glViewport(viewport[0], viewport[1], viewport[2], viewport[3]); - } - -private: - Q_DISABLE_COPY(GLSaveViewport) - GLint viewport[4]; -}; - -class GLSaveScissor -{ -public: - GLSaveScissor() - { - enabled = glIsEnabled(GL_SCISSOR_TEST); - glGetIntegerv(GL_SCISSOR_BOX, box); - } - - ~GLSaveScissor() - { - if (enabled) - glEnable(GL_SCISSOR_TEST); - else - glDisable(GL_SCISSOR_TEST); - glScissor(box[0], box[1], box[2], box[3]); - } - - bool wasEnabled() const - { - return enabled == GL_TRUE; - } - - QRect rect() const - { - return QRect(box[0], box[1], box[2], box[3]); - } - -private: - Q_DISABLE_COPY(GLSaveScissor) - GLint box[4]; - GLboolean enabled; -}; - -QT_END_NAMESPACE - -QT_END_HEADER -#endif // _GLSAVE_H_ diff --git a/src/declarative/opengl/gltexture.cpp b/src/declarative/opengl/gltexture.cpp deleted file mode 100644 index c2a02df..0000000 --- a/src/declarative/opengl/gltexture.cpp +++ /dev/null @@ -1,384 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "gltexture.h" -#include <QImage> - - -QT_BEGIN_NAMESPACE -/*! - \internal - \class GLTexture - \brief The GLTexture class simplifies the use of OpenGL textures. -*/ - -// Copied from QGLWidget::convertToGLFormat -static QImage QGLWidget_convertToGLFormat(const QImage& img) -{ - QImage res = img.convertToFormat(QImage::Format_ARGB32); - res = res.mirrored(); - - if (QSysInfo::ByteOrder == QSysInfo::BigEndian) { - // Qt has ARGB; OpenGL wants RGBA - for (int i=0; i < res.height(); i++) { - uint *p = (uint*)res.scanLine(i); - uint *end = p + res.width(); - while (p < end) { - *p = (*p << 8) | ((*p >> 24) & 0xFF); - p++; - } - } - } - else { - // Qt has ARGB; OpenGL wants ABGR (i.e. RGBA backwards) - res = res.rgbSwapped(); - } - return res; -} -class GLTexturePrivate -{ -public: - GLTexturePrivate(GLTexture *_q) - : q(_q), texture(0), width(0), height(0), - horizWrap(GLTexture::Repeat), vertWrap(GLTexture::Repeat), - minFilter(GLTexture::Linear), magFilter(GLTexture::Linear), - glWidth(1.), glHeight(1.) - { - } - - GLTexture *q; - GLuint texture; - int width; - int height; - GLTexture::WrapMode horizWrap; - GLTexture::WrapMode vertWrap; - GLTexture::FilterMode minFilter; - GLTexture::FilterMode magFilter; - - qreal glWidth; - qreal glHeight; - QSize glSize; - - void genTexture(); -}; - -void GLTexturePrivate::genTexture() -{ - if (texture) - return; - - glGenTextures(1, &texture); - glBindTexture(GL_TEXTURE_2D, texture); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter); - q->setHorizontalWrap(horizWrap); - q->setVerticalWrap(vertWrap); -} - -GLTexture::GLTexture() -: d(new GLTexturePrivate(this)) -{ -} - -GLTexture::GLTexture(const QString &file) -: d(new GLTexturePrivate(this)) -{ - QImage img(file); - if (!img.isNull()) - setImage(img); -} - -GLTexture::GLTexture(const QImage &img) -: d(new GLTexturePrivate(this)) -{ - setImage(img); -} - -GLTexture::~GLTexture() -{ - if (d->texture) - glDeleteTextures(1, &d->texture); - delete d; - d = 0; -} - -bool GLTexture::isNull() const -{ - return d->texture == 0; -} - -void GLTexture::clear() -{ - if (d->texture) { - glDeleteTextures(1, &d->texture); - d->texture = 0; - d->width = 0; - d->height = 0; - } -} - -static inline int npot(int size) -{ - size--; - size |= size >> 1; - size |= size >> 2; - size |= size >> 4; - size |= size >> 8; - size |= size >> 16; - size++; - return size; -} - -/*! - Set the texture to \a img. If the texture has already been created (either - by explicitly setting the size, or by previously setting an image), it will - be destroyed and a new texture created with \a img's contents and size. - */ -void GLTexture::setImage(const QImage &img, ImageMode mode) -{ - if (img.isNull()) - return; - - d->genTexture(); - - glBindTexture(GL_TEXTURE_2D, d->texture); - - if (mode == NonPowerOfTwo) { - - if (img.format() == QImage::Format_RGB16) { - QImage dataImage = img.mirrored(); - - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, dataImage.width(), - dataImage.height(), 0, - GL_RGB, - GL_UNSIGNED_SHORT_5_6_5, dataImage.bits()); - } else { - QImage dataImage = QGLWidget_convertToGLFormat(img); - - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, dataImage.width(), - dataImage.height(), 0, - (dataImage.format() == QImage::Format_ARGB32)?GL_RGBA:GL_RGB, - GL_UNSIGNED_BYTE, dataImage.bits()); - } - d->glWidth = 1.; - d->glHeight = 1.; - d->glSize = img.size(); - - } else { - // mode == PowerOfTwo - int max = (img.width() > img.height())?img.width():img.height(); - max = npot(max); - - if (img.format() == QImage::Format_RGB16) { - QImage dataImage = img.mirrored(); - - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, max, - max, 0, - GL_RGB, - GL_UNSIGNED_SHORT_5_6_5, 0); - - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, dataImage.width(), - dataImage.height(), GL_RGB, GL_UNSIGNED_SHORT_5_6_5, - dataImage.bits()); - - } else { - QImage dataImage = QGLWidget_convertToGLFormat(img); - - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, max, - max, 0, - (dataImage.format() == QImage::Format_ARGB32)?GL_RGBA:GL_RGB, - GL_UNSIGNED_BYTE, 0); - - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, dataImage.width(), - dataImage.height(), - (dataImage.format() == QImage::Format_ARGB32)?GL_RGBA:GL_RGB, - GL_UNSIGNED_BYTE, dataImage.bits()); - } - - d->glWidth = qreal(img.width()) / qreal(max); - d->glHeight = qreal(img.height()) / qreal(max); - d->glSize = QSize(max, max); - } - - d->width = img.width(); - d->height = img.height(); -} - -void GLTexture::copyImage(const QImage &img, const QPoint &point, - const QRect &srcRect) -{ - qFatal("Not implemented"); - Q_UNUSED(img); - Q_UNUSED(point); - Q_UNUSED(srcRect); -} - -QSize GLTexture::size() const -{ - return QSize(d->width, d->height); -} - -int GLTexture::width() const -{ - return d->width; -} - -int GLTexture::height() const -{ - return d->height; -} - -qreal GLTexture::glWidth() const -{ - return d->glWidth; -} - -qreal GLTexture::glHeight() const -{ - return d->glHeight; -} - -QSize GLTexture::glSize() const -{ - return d->glSize; -} - -/*! - Sets the \a size of the texture. This will destroy the current contents of - the texture. If an image has been assigned, it will need to be reassigned - using either setImage() or copyImage(). - - If size is invalid (width or height is less than or equal to 0) the texture - will be destroyed. This is equivalent to calling clear(). -*/ -void GLTexture::setSize(const QSize &size) -{ - if (size.width() <= 0 || size.height() <= 0) { - clear(); - return; - } - - d->genTexture(); - glBindTexture(GL_TEXTURE_2D, d->texture); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.width(), size.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); - d->width = size.width(); - d->height = size.height(); -} - -GLTexture::WrapMode GLTexture::horizontalWrap() const -{ - return d->horizWrap; -} - -GLTexture::WrapMode GLTexture::verticalWrap() const -{ - return d->vertWrap; -} - -void GLTexture::setHorizontalWrap(WrapMode mode) -{ - d->horizWrap = mode; - if (d->texture) { - GLint last; - glGetIntegerv(GL_TEXTURE_BINDING_2D, &last); - if (GLuint(last) != d->texture) - glBindTexture(GL_TEXTURE_2D, d->texture); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mode); - if (GLuint(last) != d->texture) - glBindTexture(GL_TEXTURE_2D, last); - } -} - -/*! - Set the veritcal wrap mode to \a mode. - */ -void GLTexture::setVerticalWrap(WrapMode mode) -{ - d->vertWrap = mode; - if (d->texture) { - GLint last; - glGetIntegerv(GL_TEXTURE_BINDING_2D, &last); - if (GLuint(last) != d->texture) - glBindTexture(GL_TEXTURE_2D, d->texture); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mode); - if (GLuint(last) != d->texture) - glBindTexture(GL_TEXTURE_2D, last); - } -} - -GLTexture::FilterMode GLTexture::minFilter() const -{ - return d->minFilter; -} - -GLTexture::FilterMode GLTexture::magFilter() const -{ - return d->magFilter; -} - -void GLTexture::setMinFilter(FilterMode f) -{ - if (d->minFilter == f) - return; - d->minFilter = f; - if (d->texture) { - glBindTexture(GL_TEXTURE_2D, d->texture); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, d->minFilter); - } -} - -void GLTexture::setMagFilter(FilterMode f) -{ - if (d->magFilter == f) - return; - d->magFilter = f; - if (d->texture) { - glBindTexture(GL_TEXTURE_2D, d->texture); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, d->magFilter); - } -} - -GLuint GLTexture::texture() const -{ - return d->texture; -} - -QT_END_NAMESPACE diff --git a/src/declarative/opengl/gltexture.h b/src/declarative/opengl/gltexture.h deleted file mode 100644 index c08d68f..0000000 --- a/src/declarative/opengl/gltexture.h +++ /dev/null @@ -1,120 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef _GLTEXTURE_H_ -#define _GLTEXTURE_H_ - -#include <QtDeclarative/qfxglobal.h> - -#include <QtCore/QRect> -#include <QtCore/QPoint> -#include "glheaders.h" - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QString; -class QImage; -class GLTexturePrivate; -class Q_DECLARATIVE_EXPORT GLTexture -{ -public: - GLTexture(); - GLTexture(const QString &file); - GLTexture(const QImage &img); - virtual ~GLTexture(); - - bool isNull() const; - void clear(); - - enum ImageMode { NonPowerOfTwo, PowerOfTwo }; - void setImage(const QImage &, ImageMode = NonPowerOfTwo); - void copyImage(const QImage &, const QPoint & = QPoint(0, 0), const QRect & = QRect()); - - int width() const; - int height() const; - qreal glWidth() const; - qreal glHeight() const; - QSize glSize() const; - QSize size() const; - void setSize(const QSize &); - - enum WrapMode { - Repeat = GL_REPEAT, - ClampToEdge = GL_CLAMP_TO_EDGE, -#if defined(QFX_RENDER_OPENGL2) - MirroredRepeat = GL_MIRRORED_REPEAT, -#else - MirroredRepeat = Repeat -#endif - }; - - WrapMode horizontalWrap() const; - WrapMode verticalWrap() const; - void setHorizontalWrap(WrapMode); - void setVerticalWrap(WrapMode); - - enum FilterMode { - Nearest = GL_NEAREST, - Linear = GL_LINEAR, - MipmapLinear = GL_LINEAR_MIPMAP_LINEAR - }; - - FilterMode minFilter() const; - FilterMode magFilter() const; - void setMinFilter(FilterMode); - void setMagFilter(FilterMode); - - GLuint texture() const; -private: - Q_DISABLE_COPY(GLTexture) - GLTexturePrivate *d; -}; - - -QT_END_NAMESPACE - -QT_END_HEADER -#endif // _GLTEXTURE_H_ diff --git a/src/declarative/opengl/opengl.pri b/src/declarative/opengl/opengl.pri deleted file mode 100644 index c9ccefb..0000000 --- a/src/declarative/opengl/opengl.pri +++ /dev/null @@ -1,20 +0,0 @@ -DEPENDPATH += opengl -INCLUDEPATH += opengl -INCLUDEPATH += $$QMAKE_INCDIR_OPENGL -QT += opengl - -contains(QT_CONFIG, opengles1) { - SOURCES += gltexture.cpp \ - glsave.cpp - - HEADERS += gltexture.h \ - glsave.h -} else:contains(QT_CONFIG, opengles2) { - SOURCES += gltexture.cpp \ - glbasicshaders.cpp \ - glsave.cpp - - HEADERS += gltexture.h \ - glbasicshaders.h \ - glsave.h -} diff --git a/src/declarative/qml/qml.pri b/src/declarative/qml/qml.pri index fa09935..310632e 100644 --- a/src/declarative/qml/qml.pri +++ b/src/declarative/qml/qml.pri @@ -69,7 +69,7 @@ HEADERS += qml/qmlparser_p.h \ qml/qpodvector_p.h # for qtscript debugger -QT += scripttools +contains(QT_CONFIG, scripttools):QT += scripttools include(script/script.pri) include(parser/parser.pri) diff --git a/src/declarative/test/qfxtestengine.cpp b/src/declarative/test/qfxtestengine.cpp deleted file mode 100644 index cf746db..0000000 --- a/src/declarative/test/qfxtestengine.cpp +++ /dev/null @@ -1,463 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QFile> -#include <QmlComponent> -#include <private/qmltimeline_p.h> -#include "qfxtestengine.h" -#include "qfxtestobjects.h" -#include <QCryptographicHash> -#include <QApplication> -#include <QKeyEvent> -#include <QSimpleCanvas> -#include <QMouseEvent> -#include <qmlengine.h> -#include <private/qabstractanimation_p.h> -#include <QAbstractAnimation> - -QT_BEGIN_NAMESPACE - -#define MAX_MISMATCHED_FRAMES 5 -#define MAX_MISMATCHED_PIXELS 5 - -class QFxTestEnginePrivate : public QAbstractAnimation -{ -public: - QFxTestEnginePrivate(QFxTestEngine *p) - : q(p), canvas(0), testMode(QFxTestEngine::NoTest), fullFrame(true), - status(Working), exitOnFail(true), mismatchedFrames(0), - lastFrameMismatch(false) {} - - QFxTestEngine *q; - - QmlEngine engine; - QSimpleCanvas *canvas; - QFxTestEngine::TestMode testMode; - QString testDirectory; - - TestLog testData; - TestLog playbackTestData; - bool fullFrame; - QList<QImage> fullFrames; - - virtual void updateCurrentTime(int); - - void recordFrameEvent(const QImage &img); - void recordFullFrameEvent(const QImage &img); - void recordKeyEvent(QKeyEvent *e); - void recordMouseEvent(QMouseEvent *e); - void testPass(); - void save(const QString &filename, bool = true); - - enum MessageType { Success, Fail }; - void message(MessageType t, const char *); - - enum Status { Working, Failed, Passed }; - Status status; - bool exitOnFail; - - QList<TestObject *> toPost; - QSet<QEvent *> postedEvents; - - // OpenGL seems to give inconsistent rendering results. We allow a small - // tolerance to compensate - a maximum number of mismatched frames and only - // one mismatch in a row - int mismatchedFrames; - bool lastFrameMismatch; - - bool compare(const QImage &img1, const QImage &img2); - - virtual int duration() const { return -1; } - - int elapsed() { return currentTime(); } -}; - -bool QFxTestEnginePrivate::compare(const QImage &img1, const QImage &img2) -{ - if (img1.size() != img2.size()) { - qWarning() << "Image size mismatch" << img1.size() << img2.size(); - return false; - } - - int errorCount = 0; - for (int yy = 0; yy < img1.height(); ++yy) { - for (int xx = 0; xx < img1.width(); ++xx) { - if (img1.pixel(xx, yy) != img2.pixel(xx, yy)) { - errorCount++; - if (errorCount > MAX_MISMATCHED_PIXELS) { - return false; - } - } - } - } - - return true; -} - -QFxTestEngine::QFxTestEngine(TestMode mode, const QString &dir, - QSimpleCanvas *canvas, QObject *parent) -: QObject(parent), d(new QFxTestEnginePrivate(this)) -{ - Q_ASSERT(canvas); - - d->canvas = canvas; - d->start(); - - d->testDirectory = dir; - d->testMode = mode; - if (d->testMode == RecordTest) { - qWarning("QFxTestEngine: Record ON"); - } else if (d->testMode == PlaybackTest) { - - QString fileName(d->testDirectory + QLatin1String("/manifest.qml")); - QFile f(fileName); - if (!f.open(QIODevice::ReadOnly)) { - qWarning() << "QFxTestEngine: Unable to open file" << fileName; - return; - } - - QByteArray data = f.readAll(); - QmlComponent c(&d->engine, data, QUrl(d->testDirectory + QLatin1String("/manifest.qml"))); - QObject *o = c.create(); - TestLog *log = qobject_cast<TestLog *>(o); - if (log) { - log->setParent(this); - d->playbackTestData.actions() = log->actions(); - qWarning() << "QFxTestEngine: Playback ON," << d->playbackTestData.actions().count() << "actions"; - } else { - delete o; - qWarning() << "QFxTestEngine: File" << fileName << "is corrupt."; - return; - } - } - - if (d->testMode != NoTest) { - QUnifiedTimer::instance()->setConsistentTiming(true); - QObject::connect(canvas, SIGNAL(framePainted()), - this, SLOT(framePainted())); - - canvas->installEventFilter(this); - for (int ii = 0; ii < d->playbackTestData.actions().count(); ++ii) { - TestObject *o = d->playbackTestData.actions().at(ii); - if (TestMouse *m = qobject_cast<TestMouse *>(o)) - d->toPost << m; - else if (TestKey *k = qobject_cast<TestKey *>(o)) - d->toPost << k; - } - } -} - -QFxTestEngine::~QFxTestEngine() -{ - delete d; d = 0; -} - -void QFxTestEngine::framePainted() -{ - QImage img = d->canvas->asImage(); - - if (d->fullFrame) { - d->fullFrame = false; - d->recordFullFrameEvent(img); - } else { - d->recordFrameEvent(img); - } -} - -void QFxTestEnginePrivate::recordFullFrameEvent(const QImage &img) -{ - TestFullFrame *ff = new TestFullFrame(q); - ff->setTime(elapsed()); - ff->setFrameId(fullFrames.count()); - - fullFrames << img; - testData.actions() << ff; - - if (testMode == QFxTestEngine::PlaybackTest) { - TestFullFrame *pf = qobject_cast<TestFullFrame *>(playbackTestData.next()); - QString filename = testDirectory + QLatin1String("/image") + QString::number(pf->frameId()) + QLatin1String(".png"); - QImage recImg(filename); - if (!pf || !compare(recImg, img) || pf->time() != elapsed()) { - qDebug() << pf << pf->time() << elapsed(); - message(Fail, "FFrame mismatch"); - } else { - message(Success, "FFrame OK"); - } - - testPass(); - } -} - -static QByteArray toHex(uchar c) -{ - QByteArray rv; - uint h = c / 16; - uint l = c % 16; - if (h >= 10) - rv.append(h - 10 + 'A'); - else - rv.append(h + '0'); - if (l >= 10) - rv.append(l - 10 + 'A'); - else - rv.append(l + '0'); - return rv; -} - -void QFxTestEnginePrivate::recordFrameEvent(const QImage &img) -{ - QCryptographicHash hash(QCryptographicHash::Md5); - - hash.addData((const char *)img.bits(), img.bytesPerLine() * img.height()); - - QByteArray result = hash.result(); - QByteArray hexResult; - for (int ii = 0; ii < result.count(); ++ii) - hexResult.append(toHex(result.at(ii))); - - TestFrame *f = new TestFrame(q); - f->setTime(elapsed()); - - f->setHash(QLatin1String(hexResult)); - testData.actions() << f; - if (testMode == QFxTestEngine::PlaybackTest) { - TestObject *o = playbackTestData.next(); - TestFrame *f = qobject_cast<TestFrame *>(o); - if (!f || f->time() != elapsed() || - f->hash() != QLatin1String(hexResult)) { - mismatchedFrames++; - if (mismatchedFrames > MAX_MISMATCHED_FRAMES || - lastFrameMismatch) - message(Fail, "Frame mismatch"); - else - message(Success, "Frame mismatch - within tolerance"); - lastFrameMismatch = true; - } else { - message(Success, "Frame OK"); - lastFrameMismatch = false; - } - - testPass(); - } -} - -void QFxTestEnginePrivate::updateCurrentTime(int) -{ - if (status != Working) - return; - - while(!toPost.isEmpty()) { - int t = elapsed(); - TestObject *o = toPost.first(); - if (testMode == QFxTestEngine::RecordTest) - o->setTime(t); - else if (o->time() != t) - return; - toPost.takeFirst(); - if (TestMouse *m = qobject_cast<TestMouse *>(o)) { - QMouseEvent e((QEvent::Type)m->type(), m->pos(), m->globalPos(), (Qt::MouseButton)m->button(), (Qt::MouseButtons)m->buttons(), (Qt::KeyboardModifiers)0); - postedEvents.insert(&e); - QApplication::sendEvent(canvas, &e); - } else if (TestKey *k = qobject_cast<TestKey *>(o)) { - QKeyEvent e((QEvent::Type)k->type(), k->key(), (Qt::KeyboardModifiers)k->modifiers(), k->text()); - postedEvents.insert(&e); - QApplication::sendEvent(canvas, &e); - } - } -} - -bool QFxTestEngine::eventFilter(QObject *, QEvent *event) -{ - if (d->status != QFxTestEnginePrivate::Working) - return false; - - if (event->type() == QEvent::MouseButtonPress || - event->type() == QEvent::MouseButtonDblClick || - event->type() == QEvent::MouseButtonRelease || - event->type() == QEvent::MouseMove) { - if (d->testMode == RecordTest && d->postedEvents.contains(event)) { - d->postedEvents.remove(event); - } else { - d->recordMouseEvent(static_cast<QMouseEvent *>(event)); - return d->testMode == RecordTest; - } - } else if (event->type() == QEvent::KeyPress || - event->type() == QEvent::KeyRelease) { - QKeyEvent *key = static_cast<QKeyEvent *>(event); - if (key->key() < Qt::Key_F1 || key->key() > Qt::Key_F9) { - - if (d->testMode == RecordTest && d->postedEvents.contains(event)) { - d->postedEvents.remove(event); - } else { - d->recordKeyEvent(key); - return d->testMode == RecordTest; - } - - } - } - - return false; -} - -void QFxTestEnginePrivate::recordMouseEvent(QMouseEvent *e) -{ - TestMouse *m = new TestMouse(q); - m->setTime(elapsed()); - m->setType(e->type()); - m->setButton(e->button()); - m->setButtons(e->buttons()); - m->setGlobalPos(e->globalPos()); - m->setPos(e->pos()); - testData.actions() << m; - - if (testMode == QFxTestEngine::PlaybackTest) { - TestMouse *m = qobject_cast<TestMouse *>(playbackTestData.next()); - if (!m || m->time() != elapsed() || - m->type() != e->type() || - m->button() != e->button() || - m->buttons() != e->buttons() || -// m->globalPos() != e->globalPos() || - m->pos() != e->pos()) { - if (m) - qWarning() << m->time() << elapsed(); - message(Fail, "Mouse mismatch"); - } else - message(Success, "Mouse OK"); - - testPass(); - } else { - toPost << m; - } - -} - -void QFxTestEnginePrivate::recordKeyEvent(QKeyEvent *e) -{ - TestKey *k = new TestKey(q); - k->setTime(elapsed()); - k->setType(e->type()); - k->setModifiers(e->QInputEvent::modifiers()); - k->setText(e->text()); - k->setKey(e->key()); - testData.actions() << k; - if (testMode == QFxTestEngine::PlaybackTest) { - TestKey *f = qobject_cast<TestKey *>(playbackTestData.next()); - if (!f || f->time() != elapsed() || - f->type() != e->type() || - f->modifiers() != e->QInputEvent::modifiers() || - f->text() != e->text() || - f->key() != e->key()) - message(Fail, "Key mismatch"); - else - message(Success, "Key OK"); - - testPass(); - } else { - toPost << k; - } -} - -void QFxTestEngine::captureFullFrame() -{ - d->fullFrame = true; -} - -void QFxTestEnginePrivate::message(MessageType t, const char *message) -{ - if (exitOnFail) - qWarning("%s", message); - if (t == Fail) { - if (exitOnFail) { - save(QLatin1String("manifest-fail.qml"), false); - qFatal("Failed"); - } else { - status = Failed; - } - } -} - -void QFxTestEnginePrivate::save(const QString &filename, bool images) -{ - qWarning() << "QFxTestEngine: Writing test data"; - - QFile manifest(testDirectory + QLatin1String("/") + filename); - manifest.open(QIODevice::WriteOnly); - testData.save(&manifest); - manifest.close(); - - if (images) { - for (int ii = 0; ii < fullFrames.count(); ++ii) - fullFrames.at(ii).save(testDirectory + QLatin1String("/image") + QString::number(ii) + QLatin1String(".png")); - } -} - -void QFxTestEngine::save() -{ - if (d->testMode != RecordTest) - return; - - d->save(QLatin1String("manifest.qml")); -} - -void QFxTestEnginePrivate::testPass() -{ - if (playbackTestData.atEnd()) { - qWarning("Test PASSED"); - if (exitOnFail) { - save(QLatin1String("manifest-play.qml")); - exit(0); - } else { - status = Passed; - } - } -} - -bool QFxTestEngine::runTest() -{ - d->exitOnFail = false; - while(d->status == QFxTestEnginePrivate::Working) - QApplication::processEvents(); - d->exitOnFail = true; - qWarning() << d->status; - return d->status == QFxTestEnginePrivate::Passed; -} - -QT_END_NAMESPACE diff --git a/src/declarative/test/qfxtestengine.h b/src/declarative/test/qfxtestengine.h deleted file mode 100644 index bce8eec..0000000 --- a/src/declarative/test/qfxtestengine.h +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef _QFXTESTENGINE_H_ -#define _QFXTESTENGINE_H_ - -#include <QtCore/QObject> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QSimpleCanvas; -class QFxTestEnginePrivate; -class Q_DECLARATIVE_EXPORT QFxTestEngine : public QObject -{ -Q_OBJECT -public: - enum TestMode { NoTest, RecordTest, PlaybackTest }; - - QFxTestEngine(TestMode, const QString &, - QSimpleCanvas *canvas, QObject * = 0); - virtual ~QFxTestEngine(); - - void captureFullFrame(); - void save(); - - bool runTest(); - -protected: - virtual bool eventFilter(QObject *, QEvent *); - -private Q_SLOTS: - void framePainted(); - -private: - QFxTestEnginePrivate *d; -}; - - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // _QFXTESTENGINE_H_ diff --git a/src/declarative/test/qfxtestobjects.cpp b/src/declarative/test/qfxtestobjects.cpp deleted file mode 100644 index 5035b28..0000000 --- a/src/declarative/test/qfxtestobjects.cpp +++ /dev/null @@ -1,354 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include "qfxtestobjects.h" -#include <qml.h> -#include <QDebug> -#include <QTextStream> - -QML_DECLARE_TYPE(TestObject) -QML_DECLARE_TYPE(TestFrame) -QML_DECLARE_TYPE(TestFullFrame) -QML_DECLARE_TYPE(TestMouse) -QML_DECLARE_TYPE(TestKey) -QML_DECLARE_TYPE(TestLog) - -QT_BEGIN_NAMESPACE -QML_DEFINE_TYPE(TestObject,TestObject) -QML_DEFINE_TYPE(TestFrame,TestFrame) -QML_DEFINE_TYPE(TestFullFrame,TestFullFrame) -QML_DEFINE_TYPE(TestMouse,TestMouse) -QML_DEFINE_TYPE(TestKey,TestKey) -QML_DEFINE_TYPE(TestLog,TestLog) - -static QString padding(int pad) -{ - QString p; - while (pad--) - p += QLatin1Char(' '); - return p; -} - -TestObject::TestObject(QObject *parent) -: QObject(parent), _time(-1) -{ -} - -int TestObject::time() const -{ - return _time; -} - -void TestObject::setTime(int t) -{ - if (t == _time) - return; - _time = t; - emit dataChanged(); -} - -void TestObject::save(QTextStream &device, int pad) -{ - device << padding(pad) << QLatin1String("TestObject {") << endl; - device << padding(pad) << QLatin1String("time: ") << QString::number(time()) << endl; - device << padding(pad) << QLatin1String("}") << endl; -} - - -TestFrame::TestFrame(QObject *parent) -: TestObject(parent) -{ -} - -QString TestFrame::hash() const -{ - return _hash; -} - -void TestFrame::setHash(const QString &h) -{ - if (_hash == h) - return; - _hash = h; - emit frameChanged(); -} - -void TestFrame::save(QTextStream &device, int pad) -{ - device << padding(pad) << QLatin1String("TestFrame {") << endl; - device << padding(pad+4) << QLatin1String("time: ") << QLatin1String(QByteArray::number(time())) << endl; - device << padding(pad+4)<< QLatin1String("hash: '") << hash() << QLatin1String("'") << endl; - device << padding(pad) << QLatin1Char('}') << endl; -} - -TestFullFrame::TestFullFrame(QObject *parent) -: TestObject(parent), _frameId(-1) -{ -} - -int TestFullFrame::frameId() const -{ - return _frameId; -} - -void TestFullFrame::setFrameId(int id) -{ - if (id == _frameId) - return; - _frameId = id; - emit frameChanged(); -} - -void TestFullFrame::save(QTextStream &device, int pad) -{ - device << padding(pad) << QLatin1String("TestFullFrame {") << endl; - device << padding(pad+4) << QLatin1String("time: ") << QLatin1String(QByteArray::number(time())) << endl; - device << padding(pad+4) << QLatin1String("frameId: ") << QLatin1String(QByteArray::number(frameId())) << endl; - device << padding(pad) << QLatin1String("}") << endl; -} - -TestMouse::TestMouse(QObject *parent) -: TestObject(parent), _type(-1), _button(-1), _buttons(-1) -{ -} - -int TestMouse::type() const -{ - return _type; -} - -void TestMouse::setType(int t) -{ - if (_type == t) - return; - _type = t; - emit mouseChanged(); -} - -int TestMouse::button() const -{ - return _button; -} - -void TestMouse::setButton(int b) -{ - if (b == _button) - return; - _button = b; - emit mouseChanged(); -} - -int TestMouse::buttons() const -{ - return _buttons; -} - -void TestMouse::setButtons(int buttons) -{ - if (_buttons == buttons) - return; - _buttons = buttons; - emit mouseChanged(); -} - -QPoint TestMouse::globalPos() const -{ - return _globalPos; -} - -void TestMouse::setGlobalPos(const QPoint &g) -{ - if (_globalPos == g) - return; - _globalPos = g; - emit mouseChanged(); -} - -QPoint TestMouse::pos() const -{ - return _pos; -} - -void TestMouse::setPos(const QPoint &p) -{ - if (p == _pos) - return; - _pos = p; - emit mouseChanged(); -} - -void TestMouse::save(QTextStream &device, int pad) -{ - device << padding(pad) << QLatin1String("TestMouse {") << endl; - device << padding(pad+4) << QLatin1String("time: ") << QString::number(time()) << endl; - device << padding(pad+4) << QLatin1String("type: ") << QString::number(type()) << endl; - device << padding(pad+4) << QLatin1String("button: ") << QString::number(button()) << endl; - device << padding(pad+4) << QLatin1String("buttons: ") << QString::number(buttons()) << endl; - device << padding(pad+4) << QLatin1String("globalPos: '") << QString::number(globalPos().x()) + QLatin1String(",") + QString::number(globalPos().y()) << QLatin1String("'") << endl; - device << padding(pad+4) << QLatin1String("pos: '") << QString::number(pos().x()) + QLatin1String(",") + QString::number(pos().y()) << QLatin1String("'") << endl; - device << padding(pad) << QLatin1String("}") << endl; -} - -TestKey::TestKey(QObject *parent) -: TestObject(parent), _type(-1), _modifiers(-1), _key(-1) -{ -} - -int TestKey::type() const -{ - return _type; -} - -void TestKey::setType(int t) -{ - if (t == _type) - return; - _type = t; - emit keyChanged(); -} - -int TestKey::modifiers() const -{ - return _modifiers; -} - -void TestKey::setModifiers(int m) -{ - if (m == _modifiers) - return; - _modifiers = m; - emit keyChanged(); -} - -QString TestKey::text() const -{ - return _text; -} - -void TestKey::setText(const QString &t) -{ - if (_text == t) - return; - _text = t; - emit keyChanged(); -} - -int TestKey::key() const -{ - return _key; -} - -void TestKey::setKey(int k) -{ - if (_key == k) - return; - _key = k; - emit keyChanged(); -} - -void TestKey::save(QTextStream &device, int pad) -{ - device << padding(pad) << QLatin1String("TestKey {") << endl; - device << padding(pad+4) << QLatin1String("time: ") << QString::number(time()) << endl; - device << padding(pad+4) << QLatin1String("type: ") << QString::number(type()) << endl; - device << padding(pad+4) << QLatin1String("modifiers: ") << QString::number(modifiers()) << endl; - device << padding(pad+4) << QLatin1String("key: ") << QString::number(key()) << endl; - if (key() != Qt::Key_Escape) - device << padding(pad+4) << QLatin1String("text: '") << text() << QLatin1String("'")<< endl; - device << padding(pad) << QLatin1String("}") << endl; -} - -TestLog::TestLog(QObject *parent) -: QObject(parent), _current(0) -{ -} - -QList<TestObject *> *TestLog::qmlActions() -{ - return &_actions; -} - -QList<TestObject *> &TestLog::actions() -{ - return _actions; -} - -bool lessThan(TestObject *lhs, TestObject *rhs) -{ - return lhs->time() < rhs->time(); -} - -void TestLog::save(QIODevice *device) -{ - // Order correctly - qStableSort(_actions.begin(), _actions.end(), lessThan); - - QTextStream writer(device); - writer << QLatin1String("TestLog {") << endl; - for (int ii = 0; ii < _actions.count(); ++ii) - _actions.at(ii)->save(writer, 4); - writer << QLatin1String("}") << endl; -} - -TestObject *TestLog::next() -{ - if (atEnd()) - return 0; - TestObject *rv = _actions.at(_current); - _current++; - return rv; -} - -bool TestLog::atEnd() const -{ - if (_current >= _actions.count()) - return true; - else - return false; -} - -int TestLog::current() const -{ - return _current; -} - -QT_END_NAMESPACE diff --git a/src/declarative/test/qfxtestobjects.h b/src/declarative/test/qfxtestobjects.h deleted file mode 100644 index c8686ad..0000000 --- a/src/declarative/test/qfxtestobjects.h +++ /dev/null @@ -1,211 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef _QFXTESTOBJECTS_H_ -#define _QFXTESTOBJECTS_H_ - -#include <QtCore/QObject> -#include <QtCore/QPoint> -#include <QtCore/QList> -#include <QtCore/QTextStream> - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class QIODevice; -class TestObject : public QObject -{ -Q_OBJECT -public: - TestObject(QObject * = 0); - - Q_PROPERTY(int time READ time WRITE setTime NOTIFY dataChanged) - int time() const; - void setTime(int); - - virtual void save(QTextStream &, int pad); -Q_SIGNALS: - void dataChanged(); - -private: - int _time; -}; - -class TestFrame : public TestObject -{ -Q_OBJECT -public: - TestFrame(QObject * = 0); - - Q_PROPERTY(QString hash READ hash WRITE setHash NOTIFY frameChanged) - QString hash() const; - void setHash(const QString &); - - virtual void save(QTextStream &, int pad); -Q_SIGNALS: - void frameChanged(); - -private: - QString _hash; -}; - -class TestFullFrame : public TestObject -{ -Q_OBJECT -public: - TestFullFrame(QObject * = 0); - - Q_PROPERTY(int frameId READ frameId WRITE setFrameId NOTIFY frameChanged) - int frameId() const; - void setFrameId(int); - - virtual void save(QTextStream &, int pad); -Q_SIGNALS: - void frameChanged(); - -private: - int _frameId; -}; - -class TestMouse : public TestObject -{ -Q_OBJECT -public: - TestMouse(QObject * = 0); - - Q_PROPERTY(int type READ type WRITE setType NOTIFY mouseChanged) - int type() const; - void setType(int); - - Q_PROPERTY(int button READ button WRITE setButton NOTIFY mouseChanged) - int button() const; - void setButton(int); - - Q_PROPERTY(int buttons READ buttons WRITE setButtons NOTIFY mouseChanged) - int buttons() const; - void setButtons(int); - - Q_PROPERTY(QPoint globalPos READ globalPos WRITE setGlobalPos NOTIFY mouseChanged) - QPoint globalPos() const; - void setGlobalPos(const QPoint &); - - Q_PROPERTY(QPoint pos READ pos WRITE setPos NOTIFY mouseChanged) - QPoint pos() const; - void setPos(const QPoint &); - - virtual void save(QTextStream &, int pad); - -Q_SIGNALS: - void mouseChanged(); - -private: - int _type; - int _button; - int _buttons; - QPoint _globalPos; - QPoint _pos; -}; - -class TestKey : public TestObject -{ -Q_OBJECT -public: - TestKey(QObject * = 0); - - Q_PROPERTY(int type READ type WRITE setType NOTIFY keyChanged) - int type() const; - void setType(int); - - Q_PROPERTY(int modifiers READ modifiers WRITE setModifiers NOTIFY keyChanged) - int modifiers() const; - void setModifiers(int); - - Q_PROPERTY(QString text READ text WRITE setText NOTIFY keyChanged) - QString text() const; - void setText(const QString &); - - Q_PROPERTY(int key READ key WRITE setKey NOTIFY keyChanged) - int key() const; - void setKey(int); - - virtual void save(QTextStream &, int pad); - -Q_SIGNALS: - void keyChanged(); - -private: - int _type; - int _modifiers; - int _key; - QString _text; -}; - -class TestLog : public QObject -{ -Q_OBJECT -public: - TestLog(QObject * = 0); - - Q_CLASSINFO("DefaultProperty", "actions") - Q_PROPERTY(QList<TestObject *> *actions READ qmlActions) - QList<TestObject *> *qmlActions(); - - QList<TestObject *> &actions(); - - int current() const; - void save(QIODevice *); - - TestObject *next(); - bool atEnd() const; - -private: - int _current; - QList<TestObject *> _actions; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // _QFXTESTOBJECTS_H_ diff --git a/src/declarative/test/qfxtestview.cpp b/src/declarative/test/qfxtestview.cpp deleted file mode 100644 index 0bd5a6b..0000000 --- a/src/declarative/test/qfxtestview.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qfxtestview.h" -#include <QFile> -#include <QmlComponent> -#include <QFileInfo> -#include <QFxItem> -#include <QmlContext> -#include <QFxTestEngine> - - -QT_BEGIN_NAMESPACE -QFxTestView::QFxTestView(const QString &filename, const QString &testdir) -: testEngine(0) -{ - QObject::connect(this, SIGNAL(sceneResized(QSize)), - this, SLOT(setSceneSize(QSize))); - - testEngine = new QFxTestEngine(QFxTestEngine::PlaybackTest, testdir, this, this); - - qWarning() << "Testing:" << filename; - QFile file(filename); - file.open(QFile::ReadOnly); - QString qml = QString::fromUtf8(file.readAll()); - setQml(qml, filename); - - execute(); -} - -void QFxTestView::setSceneSize(QSize s) -{ - if (s.isNull()) - qWarning() << "Scene size is invalid"; - setFixedSize(s); -} - -bool QFxTestView::runTest() -{ - show(); - return testEngine->runTest(); -} - -QT_END_NAMESPACE diff --git a/src/declarative/test/qfxtestview.h b/src/declarative/test/qfxtestview.h deleted file mode 100644 index 353494d..0000000 --- a/src/declarative/test/qfxtestview.h +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef _QFXTESTVIEW_H_ -#define _QFXTESTVIEW_H_ - -#include <QtDeclarative/QFxView> - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class QFxTestEngine; -class Q_DECLARATIVE_EXPORT QFxTestView : public QFxView -{ -Q_OBJECT -public: - QFxTestView(const QString &filename, const QString &testdir); - - bool runTest(); - -private Q_SLOTS: - void setSceneSize(QSize); - -private: - QFxTestEngine *testEngine; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // _QFXTESTVIEW_H_ diff --git a/src/declarative/test/test.pri b/src/declarative/test/test.pri deleted file mode 100644 index eacd00f..0000000 --- a/src/declarative/test/test.pri +++ /dev/null @@ -1,9 +0,0 @@ -SOURCES += \ - test/qfxtestengine.cpp \ - test/qfxtestobjects.cpp \ - test/qfxtestview.cpp - -HEADERS += \ - test/qfxtestengine.h \ - test/qfxtestobjects.h \ - test/qfxtestview.h diff --git a/src/declarative/util/qfxglobal.h b/src/declarative/util/qfxglobal.h index 6f2a9fb..9b4aee1 100644 --- a/src/declarative/util/qfxglobal.h +++ b/src/declarative/util/qfxglobal.h @@ -51,39 +51,9 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -#if defined(QT_OPENGL_ES_1) -#define QFX_CONFIGURATION_OPENGL1 -#elif defined(QT_OPENGL_ES_2) -#define QFX_CONFIGURATION_OPENGL2 -#else #define QFX_CONFIGURATION_SOFTWARE -#endif - -/* - The choices of renderer are: - QFX_RENDER_QPAINTER - QFX_RENDER_OPENGL1 - QFX_RENDER_OPENGL2 - To simplify code, if either of the OpenGL renderers are used, - QFX_RENDER_OPENGL is also defined. -*/ - -#if defined(QFX_CONFIGURATION_OPENGL2) - -#define QFX_RENDER_OPENGL -#define QFX_RENDER_OPENGL2 - -#elif defined(QFX_CONFIGURATION_OPENGL1) - -#define QFX_RENDER_OPENGL -#define QFX_RENDER_OPENGL1 - -#elif defined(QFX_CONFIGURATION_SOFTWARE) - #define QFX_RENDER_QPAINTER -#endif - #define DEFINE_BOOL_CONFIG_OPTION(name, var) \ static bool name() \ { \ diff --git a/src/declarative/util/qfxview.cpp b/src/declarative/util/qfxview.cpp index 0a3afda..e8b324c 100644 --- a/src/declarative/util/qfxview.cpp +++ b/src/declarative/util/qfxview.cpp @@ -64,7 +64,6 @@ QT_BEGIN_NAMESPACE -DEFINE_BOOL_CONFIG_OPTION(itemTreeDump, ITEMTREE_DUMP); DEFINE_BOOL_CONFIG_OPTION(qmlDebugger, QML_DEBUGGER); static QVariant stringToPixmap(const QString &str) @@ -104,6 +103,8 @@ public: bool resizable; void init(); + + QGraphicsScene scene; }; /*! @@ -133,21 +134,7 @@ public: Constructs a QFxView with the given \a parent. */ QFxView::QFxView(QWidget *parent) -: QSimpleCanvas(parent), d(new QFxViewPrivate(this)) -{ - setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred); - d->init(); -} - -/*! - \fn QFxView::QFxView(QSimpleCanvas::CanvasMode mode, QWidget *parent) - \internal - Constructs a QFxView with the given \a parent. The canvas - \a mode can be QSimpleCanvas::GraphicsView or - QSimpleCanvas::SimpleCanvas. -*/ -QFxView::QFxView(QSimpleCanvas::CanvasMode mode, QWidget *parent) -: QSimpleCanvas(mode, parent), d(new QFxViewPrivate(this)) +: QGraphicsView(parent), d(new QFxViewPrivate(this)) { setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred); d->init(); @@ -166,6 +153,20 @@ void QFxViewPrivate::init() QFxPerfTimer<QFxPerf::FontDatabase> perf; #endif QFontDatabase database; + + q->setScene(&scene); + + q->setOptimizationFlags(QGraphicsView::DontSavePainterState); + q->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + q->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + q->setFrameStyle(0); + + // These seem to give the best performance + q->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); + scene.setItemIndexMethod(QGraphicsScene::NoIndex); + q->viewport()->setFocusPolicy(Qt::NoFocus); + + } /*! @@ -320,15 +321,14 @@ void QFxView::continueExecute() if (obj) { if (QFxItem *item = qobject_cast<QFxItem *>(obj)) { - item->QSimpleCanvasItem::setParent(QSimpleCanvas::root()); - if (itemTreeDump()) - item->dump(); + d->scene.addItem(item); if(qmlDebugger()) { QmlDebugger *debugger = new QmlDebugger; debugger->setDebugObject(item); - debugger->setCanvas(this); + // ### GV + //debugger->setCanvas(this); debugger->show(); raise(); debugger->raise(); @@ -532,7 +532,8 @@ void QFxView::resizeEvent(QResizeEvent *e) d->root->setWidth(width()); d->root->setHeight(height()); } - QSimpleCanvas::resizeEvent(e); + setSceneRect(rect()); + QGraphicsView::resizeEvent(e); } /*! \fn void QFxView::focusInEvent(QFocusEvent *e) @@ -554,12 +555,4 @@ void QFxView::focusOutEvent(QFocusEvent *) // Do nothing (do not call QWidget::update()) } -/*! - \internal - */ -void QFxView::dumpRoot() -{ - root()->dump(); -} - QT_END_NAMESPACE diff --git a/src/declarative/util/qfxview.h b/src/declarative/util/qfxview.h index 05bf005..b1386a2 100644 --- a/src/declarative/util/qfxview.h +++ b/src/declarative/util/qfxview.h @@ -44,9 +44,9 @@ #include <QtCore/qdatetime.h> #include <QtGui/qgraphicssceneevent.h> +#include <QtGui/qgraphicsview.h> #include <QtGui/qwidget.h> #include <QtDeclarative/qfxglobal.h> -#include <QtDeclarative/qsimplecanvas.h> QT_BEGIN_HEADER @@ -60,12 +60,11 @@ class QmlContext; class QmlError; class QFxViewPrivate; -class Q_DECLARATIVE_EXPORT QFxView : public QSimpleCanvas +class Q_DECLARATIVE_EXPORT QFxView : public QGraphicsView { Q_OBJECT public: explicit QFxView(QWidget *parent = 0); - QFxView(QSimpleCanvas::CanvasMode mode, QWidget* parent = 0); virtual ~QFxView(); @@ -86,8 +85,6 @@ public: bool contentResizable() const; QSize sizeHint() const; - void dumpRoot(); - static void printErrorLine(const QmlError &); Q_SIGNALS: void sceneResized(QSize size); diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h index a0d061b..c121cc0 100644 --- a/src/gui/graphicsview/qgraphicsitem_p.h +++ b/src/gui/graphicsview/qgraphicsitem_p.h @@ -99,7 +99,7 @@ public: QSet<int> gestures; }; -class Q_AUTOTEST_EXPORT QGraphicsItemPrivate +class Q_GUI_EXPORT QGraphicsItemPrivate { Q_DECLARE_PUBLIC(QGraphicsItem) public: @@ -462,6 +462,10 @@ public: // Optional stacking order int globalStackingOrder; QGraphicsItem *q_ptr; + + static QGraphicsItemPrivate *get(QGraphicsItem *o) { + return o->d_func(); + } }; struct QGraphicsItemPrivate::TransformData { diff --git a/tools/qmlviewer/main.cpp b/tools/qmlviewer/main.cpp index 0b370fb..db0a28f 100644 --- a/tools/qmlviewer/main.cpp +++ b/tools/qmlviewer/main.cpp @@ -15,7 +15,6 @@ #include "qmlviewer.h" #include <QWidget> #include <QDir> -#include "qfxtestengine.h" #include <QApplication> #include <QTranslator> #include <QDebug> @@ -76,8 +75,6 @@ int main(int argc, char ** argv) QString skin; bool devkeys = false; bool cache = false; - QFxTestEngine::TestMode testMode = QFxTestEngine::NoTest; - QString testDir; QString translationFile; for (int i = 1; i < argc; ++i) { @@ -104,18 +101,6 @@ int main(int argc, char ** argv) autorecord_to = range.mid(dash+1).toInt(); } else if (arg == "-devicekeys") { devkeys = true; - } else if (arg == "-recordtest") { - testMode = QFxTestEngine::RecordTest; - if(i + 1 >= argc) - usage(); - testDir = argv[i + 1]; - ++i; - } else if (arg == "-runtest") { - testMode = QFxTestEngine::PlaybackTest; - if(i + 1 >= argc) - usage(); - testDir = argv[i + 1]; - ++i; } else if (arg == QLatin1String("-v") || arg == QLatin1String("-version")) { fprintf(stderr, "Qt Declarative UI Viewer version %s\n", QT_VERSION_STR); return 0; @@ -139,7 +124,7 @@ int main(int argc, char ** argv) app.installTranslator(&qmlTranslator); } - QmlViewer viewer(testMode, testDir, 0, frameless ? Qt::FramelessWindowHint : Qt::Widget); + QmlViewer viewer(0, frameless ? Qt::FramelessWindowHint : Qt::Widget); foreach (QString lib, libraries) viewer.addLibraryPath(lib); viewer.setCacheEnabled(cache); diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp index db0dc18..d489412 100644 --- a/tools/qmlviewer/qmlviewer.cpp +++ b/tools/qmlviewer/qmlviewer.cpp @@ -19,7 +19,6 @@ #include <QtDeclarative/qmlengine.h> #include "qml.h" #include <private/qperformancelog_p.h> -#include "qfxtestengine.h" #include "deviceskin.h" #include <QNetworkDiskCache> @@ -40,6 +39,7 @@ #include <QFileDialog> #include <QTimer> #include <QNetworkProxyFactory> +#include <QKeyEvent> QT_BEGIN_NAMESPACE @@ -126,10 +126,9 @@ void PreviewDeviceSkin::slotPopupMenu() } -QmlViewer::QmlViewer(QFxTestEngine::TestMode testMode, const QString &testDir, QWidget *parent, Qt::WindowFlags flags) +QmlViewer::QmlViewer(QWidget *parent, Qt::WindowFlags flags) : QWidget(parent, flags), frame_stream(0), scaleSkin(true), mb(0) { - testEngine = 0; devicemode = false; skin = 0; canvas = 0; @@ -144,9 +143,6 @@ QmlViewer::QmlViewer(QFxTestEngine::TestMode testMode, const QString &testDir, Q canvas->setAttribute(Qt::WA_NoSystemBackground); canvas->setContentResizable(!skin || !scaleSkin); - if(testMode != QFxTestEngine::NoTest) - testEngine = new QFxTestEngine(testMode, testDir, canvas, this); - QObject::connect(canvas, SIGNAL(sceneResized(QSize)), this, SLOT(sceneResized(QSize))); QVBoxLayout *layout = new QVBoxLayout; @@ -296,7 +292,8 @@ void QmlViewer::takeSnapShot() { static int snapshotcount = 1; QString snapFileName = QString(QLatin1String("snapshot%1.png")).arg(snapshotcount); - canvas->asImage().save(snapFileName); + // ### GV + // canvas->asImage().save(snapFileName); qDebug() << "Wrote" << snapFileName; ++snapshotcount; } @@ -518,22 +515,11 @@ void QmlViewer::keyPressEvent(QKeyEvent *event) toggleRecording(); } else if (event->key() == Qt::Key_F3 || (event->key() == Qt::Key_3 && devicemode)) { takeSnapShot(); - } else if (event->key() == Qt::Key_F4 || (event->key() == Qt::Key_4 && devicemode)) { - canvas->dumpItems(); - canvas->checkState(); } else if (event->key() == Qt::Key_F5 || (event->key() == Qt::Key_5 && devicemode)) { reload(); - } else if (event->key() == Qt::Key_F6 || (event->key() == Qt::Key_6 && devicemode)) { - canvas->dumpRoot(); - } else if (event->key() == Qt::Key_F7 || (event->key() == Qt::Key_7 && devicemode)) { - canvas->dumpTiming(); } else if (event->key() == Qt::Key_F8 || (event->key() == Qt::Key_8 && devicemode)) { QPerformanceLog::displayData(); QPerformanceLog::clear(); - } else if (event->key() == Qt::Key_F9) { - if(testEngine) testEngine->save(); - } else if (event->key() == Qt::Key_F10) { - if(testEngine) testEngine->captureFullFrame(); } QWidget::keyPressEvent(event); @@ -661,10 +647,12 @@ void QmlViewer::timerEvent(QTimerEvent *event) { if (event->timerId() == recordTimer.timerId()) { if (frame_stream) { - QImage frame(canvas->asImage()); - frame_stream->write((char*)frame.bits(),frame.numBytes()); + // ### GV + // QImage frame(canvas->asImage()); + // frame_stream->write((char*)frame.bits(),frame.numBytes()); } else { - frames.append(new QImage(canvas->asImage())); + // ### GV + // frames.append(new QImage(canvas->asImage())); } if (record_autotime && autoTimer.elapsed() >= record_autotime) setRecording(false); diff --git a/tools/qmlviewer/qmlviewer.h b/tools/qmlviewer/qmlviewer.h index c533fe0..c46f185 100644 --- a/tools/qmlviewer/qmlviewer.h +++ b/tools/qmlviewer/qmlviewer.h @@ -17,7 +17,6 @@ #include <QMenuBar> #include <QBasicTimer> #include <QTime> -#include <qfxtestengine.h> #include <QList> QT_BEGIN_NAMESPACE @@ -31,7 +30,7 @@ class QmlViewer : public QWidget { Q_OBJECT public: - QmlViewer(QFxTestEngine::TestMode = QFxTestEngine::NoTest, const QString &testDir = QString(), QWidget *parent=0, Qt::WindowFlags flags=0); + QmlViewer(QWidget *parent=0, Qt::WindowFlags flags=0); void setRecordDither(const QString& s) { record_dither = s; } void setRecordPeriod(int ms); @@ -75,7 +74,6 @@ private: PreviewDeviceSkin *skin; QSize skinscreensize; QFxView *canvas; - void init(QFxTestEngine::TestMode, const QString &, const QString& fileName); QBasicTimer recordTimer; QList<QImage*> frames; QProcess* frame_stream; @@ -91,8 +89,6 @@ private: QString currentSkin; bool scaleSkin; mutable QMenuBar *mb; - - QFxTestEngine *testEngine; }; QT_END_NAMESPACE |