diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-06-23 04:21:45 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-06-23 05:52:02 (GMT) |
commit | c1283b68d5b02afb5f225d455ae057753b91a5b9 (patch) | |
tree | b87644e9d326c5101b2c467c06d84a723e09ed53 /src | |
parent | 5d5ead94bc79a5364d8685707711673f5dc1a35a (diff) | |
download | Qt-c1283b68d5b02afb5f225d455ae057753b91a5b9.zip Qt-c1283b68d5b02afb5f225d455ae057753b91a5b9.tar.gz Qt-c1283b68d5b02afb5f225d455ae057753b91a5b9.tar.bz2 |
Remove simple canvas
Diffstat (limited to 'src')
57 files changed, 725 insertions, 4867 deletions
diff --git a/src/declarative/canvas/canvas.pri b/src/declarative/canvas/canvas.pri deleted file mode 100644 index e7cbb9d..0000000 --- a/src/declarative/canvas/canvas.pri +++ /dev/null @@ -1,12 +0,0 @@ -SOURCES += \ - canvas/qsimplecanvas.cpp \ - canvas/qsimplecanvasitem.cpp \ - canvas/qsimplecanvasdebugplugin.cpp - -HEADERS += \ - canvas/qsimplecanvas.h \ - canvas/qsimplecanvasitem.h \ - canvas/qsimplecanvas_p.h \ - canvas/qsimplecanvasitem_p.h \ - canvas/qsimplecanvasdebugplugin_p.h - diff --git a/src/declarative/canvas/qsimplecanvas.cpp b/src/declarative/canvas/qsimplecanvas.cpp deleted file mode 100644 index 327d10a..0000000 --- a/src/declarative/canvas/qsimplecanvas.cpp +++ /dev/null @@ -1,859 +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" -#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) -{ -} - -void QSimpleCanvasRootLayer::remDirty(QSimpleCanvasItem *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) -{ - mode = QSimpleCanvas::GraphicsView; - 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); - view->scene()->addItem(root); - - // These seem to give the best performance - view->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); - view->scene()->setItemIndexMethod(QGraphicsScene::NoIndex); - view->viewport()->setFocusPolicy(Qt::NoFocus); - } -} - -QSimpleCanvas::~QSimpleCanvas() -{ - delete d->root; - delete d; -} - -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 (d->isGraphicsView()) - d->view->setSceneRect(rect()); - - QWidget::showEvent(e); -} - -void QSimpleCanvas::resizeEvent(QResizeEvent *e) -{ - if (d->isGraphicsView()) - d->view->setSceneRect(rect()); - QWidget::resizeEvent(e); -} - -void QSimpleCanvas::queueUpdate() -{ - if (!d->timer) { - QCoreApplication::postEvent(this, new QEvent(QEvent::User)); - d->timer = 1; - } -} - -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::ShortcutOverride) { - if (QSimpleCanvasItem *focus = focusItem()) - return focus->event(e); - } - - return QWidget::event(e); -} - -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 -{ - 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 b260017..0000000 --- a/src/declarative/canvas/qsimplecanvas.h +++ /dev/null @@ -1,126 +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> - -#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) -class QSimpleCanvas; -class QSimpleCanvasLayer; - -class QGraphicsSceneMouseEvent; -class QSimpleCanvasItem; -class QSimpleCanvasPrivate; -class Q_DECLARATIVE_EXPORT QSimpleCanvas : public QWidget -{ -Q_OBJECT -public: - 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 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; - - void queueUpdate(); - QSimpleCanvasPrivate *d; -}; - - -QT_END_NAMESPACE - -QT_END_HEADER -#endif diff --git a/src/declarative/canvas/qsimplecanvas_p.h b/src/declarative/canvas/qsimplecanvas_p.h deleted file mode 100644 index 33c889f..0000000 --- a/src/declarative/canvas/qsimplecanvas_p.h +++ /dev/null @@ -1,137 +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> - - -#include <QGraphicsView> -#include <QGraphicsScene> - -struct QSimpleCanvasGraphicsView : public QGraphicsView -{ -public: - QSimpleCanvasGraphicsView(QSimpleCanvasPrivate *parent); - ~QSimpleCanvasGraphicsView(); - -protected: - virtual void paintEvent(QPaintEvent *); - virtual void focusInEvent(QFocusEvent *); - -private: - QSimpleCanvasPrivate *canvas; - QGraphicsScene _scene; -}; - -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) - , paintVersion(1) - { - } - - QSimpleCanvas *q; - QSimpleCanvas::CanvasMode mode; - bool isSimpleCanvas() const { return mode == QSimpleCanvas::SimpleCanvas; } - bool isGraphicsView() const { return mode == QSimpleCanvas::GraphicsView; } - - QRect oldDirty; - - 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; - - int paintVersion; -}; - -#endif - -QT_END_NAMESPACE diff --git a/src/declarative/canvas/qsimplecanvasdebugplugin.cpp b/src/declarative/canvas/qsimplecanvasdebugplugin.cpp deleted file mode 100644 index 81bfbfa..0000000 --- a/src/declarative/canvas/qsimplecanvasdebugplugin.cpp +++ /dev/null @@ -1,151 +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)0 - << item->transform() - << 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/qsimplecanvasitem.cpp b/src/declarative/canvas/qsimplecanvasitem.cpp deleted file mode 100644 index 65c0a45..0000000 --- a/src/declarative/canvas/qsimplecanvasitem.cpp +++ /dev/null @@ -1,1274 +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 - -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); -} - - -/*! - \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; -} - -bool QSimpleCanvasItem::sceneEvent(QEvent *event) -{ - bool rv = QGraphicsItem::sceneEvent(event); - if (event->type() == QEvent::UngrabMouse) - mouseUngrabEvent(); - return rv; -} - -QVariant QSimpleCanvasItem::itemChange(GraphicsItemChange change, - const QVariant &value) -{ - Q_D(QSimpleCanvasItem); - if (change == ItemSceneHasChanged) { - QSimpleCanvas *oldCanvas = d->canvas; - d->canvas = sceneMap[scene()]; - if (d->canvas){ - if (hasFocus()) - canvas()->d->setFocusItem(this, Qt::OtherFocusReason); - if (options() & QSimpleCanvasItem::IsFocusPanel) { - if (d->wantsActiveFocusPanelPendingCanvas) { - d->hasBeenActiveFocusPanel = true; - canvas()->d->setActiveFocusPanel(this); - d->wantsActiveFocusPanelPendingCanvas = false; - } - } - } - if (options() & QSimpleCanvasItem::MouseFilter) - d->gvRemoveMouseFilter(); - - if (oldCanvas != d->canvas) - canvasChanged(); - - if (options() & QSimpleCanvasItem::MouseFilter) - d->gvAddMouseFilter(); - } - - return QGraphicsItem::itemChange(change, value); -} - - -void QSimpleCanvasItem::mousePressEvent(QGraphicsSceneMouseEvent *e) -{ -#if 0 - QSimpleCanvasItem *p = owner->parent(); - while(p) { - if (p->options() & QSimpleCanvasItem::ChildMouseFilter) { - if (p->mouseFilter(event)) - return; - } - p = p->parent(); - } - owner->mousePressEvent(event); -#endif - e->ignore(); -} - -void QSimpleCanvasItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) -{ -#if 0 - QSimpleCanvasItem *p = owner->parent(); - while(p) { - if (p->options() & QSimpleCanvasItem::ChildMouseFilter) { - if (p->mouseFilter(event)) - return; - } - p = p->parent(); - } - owner->mouseReleaseEvent(event); - ungrabMouse(); -#endif - e->ignore(); -} - -void QSimpleCanvasItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e) -{ -#if 0 - QSimpleCanvasItem *p = owner->parent(); - while(p) { - if (p->options() & QSimpleCanvasItem::ChildMouseFilter) { - if (p->mouseFilter(event)) - return; - } - p = p->parent(); - } -#endif - e->ignore(); -} - -void QSimpleCanvasItem::mouseMoveEvent(QGraphicsSceneMouseEvent *e) -{ -#if 0 - QSimpleCanvasItem *p = owner->parent(); - while(p) { - if (p->options() & QSimpleCanvasItem::ChildMouseFilter) { - if (p->mouseFilter(event)) - return; - } - p = p->parent(); - } -#endif - 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) -{ - if (!hasFocus()) - setFocus(true); - 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::canvasChanged() -{ -} - -void QSimpleCanvasItem::focusChanged(bool) -{ -} - -void QSimpleCanvasItem::activeFocusChanged(bool) -{ -} - -void QSimpleCanvasItem::parentChanged(QSimpleCanvasItem *, QSimpleCanvasItem *) -{ -} - -/*! - 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::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::z() const -{ - Q_D(const QSimpleCanvasItem); - return zValue(); -} - -void QSimpleCanvasItem::setX(qreal x) -{ - Q_D(QSimpleCanvasItem); - 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 QSimpleCanvasItem::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 QSimpleCanvasItem::setZ(qreal z) -{ - if (z == this->z()) - return; - - if (z < 0) - setFlag(QGraphicsItem::ItemStacksBehindParent, true); - else - setFlag(QGraphicsItem::ItemStacksBehindParent, false); - - setZValue(z); -} - -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) -{ - qreal oldX = x(); - qreal oldY = y(); - - QGraphicsItem::setPos(point); - - 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; - 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); -} - -bool QSimpleCanvasItem::isVisible() const -{ - if (visible() <= 0) - return false; - else if (!parent()) - return true; - else - return parent()->isVisible(); -} - -qreal QSimpleCanvasItem::visible() const -{ - return opacity(); -} - -void QSimpleCanvasItem::setVisible(qreal v) -{ - setOpacity(v); -} - -void QSimpleCanvasItem::addChild(QSimpleCanvasItem *c) -{ - Q_D(QSimpleCanvasItem); - d->children.append(c); - childrenChanged(); -} - -void QSimpleCanvasItem::remChild(QSimpleCanvasItem *c) -{ - Q_D(QSimpleCanvasItem); - d->children.removeAll(c); - childrenChanged(); -} - -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; -} - -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; - setFlag(QGraphicsItem::ItemClipsChildrenToShape, bool(c)); -} - -QRect QSimpleCanvasItem::itemBoundingRect() -{ - return boundingRect().toAlignedRect(); -} - -QPointF QSimpleCanvasItem::mapFromScene(const QPointF &p) const -{ - return QGraphicsItem::mapFromScene(p); -} - -QRectF QSimpleCanvasItem::mapFromScene(const QRectF &r) const -{ - return QGraphicsItem::mapFromScene(r).boundingRect(); -} - -QPointF QSimpleCanvasItem::mapToScene(const QPointF &p) const -{ - return QGraphicsItem::mapToScene(p); -} - -QRectF QSimpleCanvasItem::mapToScene(const QRectF &r) const -{ - return QGraphicsItem::mapToScene(r).boundingRect(); -} - -QTransform QSimpleCanvasItem::transform() const -{ - Q_D(const QSimpleCanvasItem); - return d->transform; -} - -void QSimpleCanvasItem::setTransform(const QTransform &m) -{ - Q_D(QSimpleCanvasItem); - d->transform = m; - QGraphicsItem::setTransform(QTransform::fromScale(d->scale, d->scale) * d->transform); -} - -QSimpleCanvasItem *QSimpleCanvasItem::mouseGrabberItem() const -{ - QGraphicsScene *s = scene(); - if (s) { - QGraphicsItem *item = s->mouseGrabberItem(); - return static_cast<QSimpleCanvasItem*>(item); // ### - } - return 0; -} - -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) -{ - Q_Q(QSimpleCanvasItem); - hasActiveFocus = f; - - if (f) { - if (!(q->flags() & QGraphicsItem::ItemIsFocusable)) - q->setFlag(QGraphicsItem::ItemIsFocusable); - q->QGraphicsItem::setFocus(); - } else { - q->clearFocus(); - if ((q->flags() & QGraphicsItem::ItemIsFocusable) && !focusable) - q->setFlag(QGraphicsItem::ItemIsFocusable, false); - } -} - -bool QSimpleCanvasItem::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 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; - } - - setFlag(QGraphicsItem::ItemHasNoContents, !(d->options & HasContents)); - - if ((old & MouseFilter) != (d->options & MouseFilter)) { - if (d->options & MouseFilter) - d->gvAddMouseFilter(); - else - d->gvRemoveMouseFilter(); - } -} - -QSimpleCanvasItem::QSimpleCanvasItem(QSimpleCanvasItemPrivate &dd, QSimpleCanvasItem *parent) -: QGraphicsObject(dd, parent, 0) -{ - setFlag(QGraphicsItem::ItemHasNoContents, true); -} - -QSimpleCanvasItem::QSimpleCanvasItem(QSimpleCanvasItem *p) -: QGraphicsObject(*(new QSimpleCanvasItemPrivate), p, 0) -{ - setFlag(QGraphicsItem::ItemHasNoContents, true); -} - -QSimpleCanvasItem::~QSimpleCanvasItem() -{ - Q_D(QSimpleCanvasItem); - 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); - } - - qDeleteAll(children()); - if (parent()) - parent()->remChild(this); -} - -QSimpleCanvasItem::operator QGraphicsItem *() -{ - return this; -} - -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 (oldParent) - oldParent->remChild(q); - - parent = p; - q->setParentItem(p); - - if (parent) - p->addChild(q); -} - -/*! - \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); - - 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() << " " << " " << 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::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) -{ - paintContents(*p); -} - -void QSimpleCanvasItem::geometryChanged(const QRectF &, const QRectF &) -{ -} - -void QSimpleCanvasItemPrivate::gvRemoveMouseFilter() -{ - Q_Q(QSimpleCanvasItem); - QGraphicsScene *scene = q->scene(); - if (!scene) return; - - scene->removeEventFilter(q); -} - -void QSimpleCanvasItemPrivate::gvAddMouseFilter() -{ - Q_Q(QSimpleCanvasItem); - QGraphicsScene *scene = q->scene(); - if (!scene) return; - - scene->installEventFilter(q); -} - -QT_END_NAMESPACE diff --git a/src/declarative/canvas/qsimplecanvasitem.h b/src/declarative/canvas/qsimplecanvasitem.h deleted file mode 100644 index eb7bcea..0000000 --- a/src/declarative/canvas/qsimplecanvasitem.h +++ /dev/null @@ -1,255 +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> -#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 Q_DECLARATIVE_EXPORT QSimpleCanvasItem : public QGraphicsObject -{ - Q_OBJECT - Q_CAST_INTERFACES(QGraphicsItem) - Q_CAST_INTERFACES(QmlDebuggerStatus) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, 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); - - 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); - - qreal visible() const; - virtual void setVisible(qreal); - bool isVisible() const; - - QSimpleCanvas *canvas() const; - - QSimpleCanvasItem *parent() const; - void setParent(QSimpleCanvasItem *); - - QRect itemBoundingRect(); - - void setPaintMargin(qreal margin); - QRectF boundingRect() const; - virtual void paintContents(QPainter &); - - 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; - - QTransform transform() const; - void setTransform(const QTransform &); - - QSimpleCanvasItem *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; - - QSimpleCanvasItem *findFirstFocusChild() const; - QSimpleCanvasItem *findLastFocusChild() const; - static QSimpleCanvasItem *findPrevFocus(QSimpleCanvasItem *item); - static QSimpleCanvasItem *findNextFocus(QSimpleCanvasItem *item); - - static QPixmap string(const QString &, const QColor & = Qt::black, const QFont & = QFont()); - -protected: - virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); - 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 sceneEvent(QEvent *); - virtual QVariant itemChange(GraphicsItemChange, const QVariant &); - 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 QGraphicsQSimpleCanvasItem; - friend class QSimpleGraphicsItem; - -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(); -}; - - - -#endif // _GFXCANVASITEM_H_ - - -QT_END_NAMESPACE - -QT_END_HEADER diff --git a/src/declarative/canvas/qsimplecanvasitem_p.h b/src/declarative/canvas/qsimplecanvasitem_p.h deleted file mode 100644 index 39a1c48..0000000 --- a/src/declarative/canvas/qsimplecanvasitem_p.h +++ /dev/null @@ -1,147 +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 "private/qgraphicsitem_p.h" -#include "qsimplecanvas.h" -#include "qsimplecanvasitem.h" - -#include "qgraphicsitem.h" - - -QT_BEGIN_NAMESPACE -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 QGraphicsQSimpleCanvasItem; -class QSimpleCanvasItemPrivate : public QGraphicsItemPrivate -{ - Q_DECLARE_PUBLIC(QSimpleCanvasItem) -public: - QSimpleCanvasItemPrivate() - : parent(0), canvas(0), debuggerStatus(0), - clip(QSimpleCanvasItem::NoClip), - origin(QSimpleCanvasItem::TopLeft), options(QSimpleCanvasItem::NoOption), - focusable(false), wantsActiveFocusPanelPendingCanvas(false), - hasBeenActiveFocusPanel(false), - hasFocus(false), hasActiveFocus(false), - widthValid(false), heightValid(false), width(0), height(0), paintmargin(0), scale(1) - { - } - - virtual ~QSimpleCanvasItemPrivate() - { - if(debuggerStatus) delete debuggerStatus; - } - - QSimpleCanvasItem *parent; - QSimpleCanvas *canvas; - QList<QSimpleCanvasItem *> children; - - QSimpleCanvasItemDebuggerStatus *debuggerStatus; - - 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 widthValid:1; - bool heightValid:1; - - void setFocus(bool f); - void setActiveFocus(bool f); - - qreal width; - qreal height; - qreal paintmargin; - qreal scale; - - QTransform transform; - - void gvRemoveMouseFilter(); - void gvAddMouseFilter(); - - void canvasChanged(QSimpleCanvas *newCanvas, QSimpleCanvas *oldCanvas); - - QPointF transformOrigin() const; - - void setParentInternal(QSimpleCanvasItem *); - - // 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) - -#endif // QSIMPLECANVASITEM_P_H - -QT_END_NAMESPACE diff --git a/src/declarative/declarative.pro b/src/declarative/declarative.pro index 31830a0..e2954e5 100644 --- a/src/declarative/declarative.pro +++ b/src/declarative/declarative.pro @@ -18,12 +18,10 @@ include(../qbase.pri) include(3rdparty/3rdparty.pri) include(util/util.pri) include(fx/fx.pri) -include(canvas/canvas.pri) include(qml/qml.pri) include(timeline/timeline.pri) include(extra/extra.pri) include(widgets/widgets.pri) -include(test/test.pri) include(debugger/debugger.pri) symbian:TARGET.UID3=0x2001E623 diff --git a/src/declarative/fx/fx.pri b/src/declarative/fx/fx.pri index 801725d..7d8f565 100644 --- a/src/declarative/fx/fx.pri +++ b/src/declarative/fx/fx.pri @@ -10,8 +10,6 @@ HEADERS += \ fx/qfxflickable.h \ fx/qfxflickable_p.h \ fx/qfxflipable.h \ - fx/qfxfocuspanel.h \ - fx/qfxfocusrealm.h \ fx/qfxgridview.h \ fx/qfxflowview.h \ fx/qfximage.h \ @@ -54,8 +52,6 @@ SOURCES += \ fx/qfxevents.cpp \ fx/qfxflickable.cpp \ fx/qfxflipable.cpp \ - fx/qfxfocuspanel.cpp \ - fx/qfxfocusrealm.cpp \ fx/qfxgridview.cpp \ fx/qfxflowview.cpp \ fx/qfximage.cpp \ diff --git a/src/declarative/fx/qfxcontentwrapper.cpp b/src/declarative/fx/qfxcontentwrapper.cpp index 482442b..1fa0fde 100644 --- a/src/declarative/fx/qfxcontentwrapper.cpp +++ b/src/declarative/fx/qfxcontentwrapper.cpp @@ -106,7 +106,7 @@ void QFxContentWrapper::componentComplete() if (content()->size() < 1) return; - QList<QSimpleCanvasItem *> nodes; + QList<QGraphicsItem *> nodes; nodes.append(this); QFxItem *target = findContent(nodes); if (!target) @@ -118,9 +118,9 @@ void QFxContentWrapper::componentComplete() myContent.at(ii)->setParent(target); } -QFxItem *QFxContentWrapper::findContent(QList<QSimpleCanvasItem *> &nodes) +QFxItem *QFxContentWrapper::findContent(QList<QGraphicsItem *> &nodes) { - QSimpleCanvasItem *item = nodes.takeFirst(); + QGraphicsItem *item = nodes.takeFirst(); if (qobject_cast<QFxContent*>(item)) return static_cast<QFxItem *>(item); nodes << item->children(); diff --git a/src/declarative/fx/qfxcontentwrapper.h b/src/declarative/fx/qfxcontentwrapper.h index f1678d0..898d695 100644 --- a/src/declarative/fx/qfxcontentwrapper.h +++ b/src/declarative/fx/qfxcontentwrapper.h @@ -64,7 +64,7 @@ public: private: void create(); - QFxItem *findContent(QList<QSimpleCanvasItem *> &nodes); + QFxItem *findContent(QList<QGraphicsItem *> &nodes); protected: void componentComplete(); diff --git a/src/declarative/fx/qfxflickable.cpp b/src/declarative/fx/qfxflickable.cpp index bc4a5fc..f85f3dc 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(leftChanged()), q, SIGNAL(positionChanged())); QObject::connect(_flick, SIGNAL(topChanged()), q, SIGNAL(positionChanged())); QObject::connect(&elasticX, SIGNAL(updated()), q, SLOT(ticked())); 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 60f9118..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) -}; - -QML_DECLARE_TYPE(QFxFocusPanel) - -QT_END_NAMESPACE - -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 d2aadce..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(); -}; - -QML_DECLARE_TYPE(QFxFocusRealm) - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QFXFOCUSREALM_H diff --git a/src/declarative/fx/qfximage.cpp b/src/declarative/fx/qfximage.cpp index 2ac035d..48957e5 100644 --- a/src/declarative/fx/qfximage.cpp +++ b/src/declarative/fx/qfximage.cpp @@ -305,14 +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); -} - void QFxImage::paintContents(QPainter &p) { Q_D(QFxImage); diff --git a/src/declarative/fx/qfximage.h b/src/declarative/fx/qfximage.h index e2205e5..72530ee 100644 --- a/src/declarative/fx/qfximage.h +++ b/src/declarative/fx/qfximage.h @@ -91,7 +91,6 @@ public: QUrl source() const; virtual void setSource(const QUrl &url); - virtual void dump(int depth); virtual QString propertyInfo() const; void paintContents(QPainter &painter); diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index 7938c63..d4a5b06 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -151,9 +151,10 @@ void QFxContents::calcHeight() int top = INT_MAX; int bottom = 0; - const QList<QSimpleCanvasItem *> &children = _item->QSimpleCanvasItem::children(); + QList<QGraphicsItem *> children = _item->childItems(); + for (int i = 0; i < children.count(); ++i) { - const QSimpleCanvasItem *child = children.at(i); + QFxItem *child = qobject_cast<QFxItem *>(children.at(i)); int y = int(child->y()); if (y + child->height() > bottom) bottom = y + child->height(); @@ -173,9 +174,10 @@ void QFxContents::calcWidth() int left = INT_MAX; int right = 0; - const QList<QSimpleCanvasItem *> &children = _item->QSimpleCanvasItem::children(); + QList<QGraphicsItem *> children = _item->childItems(); + for (int i = 0; i < children.count(); ++i) { - const QSimpleCanvasItem *child = children.at(i); + QFxItem *child = qobject_cast<QFxItem *>(children.at(i)); int x = int(child->x()); if (x + child->width() > right) right = x + child->width(); @@ -192,9 +194,9 @@ void QFxContents::setItem(QFxItem *item) { _item = item; - const QList<QSimpleCanvasItem *> &children = _item->QSimpleCanvasItem::children(); + QList<QGraphicsItem *> children = _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(topChanged()), this, SLOT(calcHeight())); connect(child, SIGNAL(widthChanged()), this, SLOT(calcWidth())); @@ -372,7 +374,7 @@ void QFxContents::setItem(QFxItem *item) This signal is emitted when the item's focus state changes. - \sa QSimpleCanvasItem::setFocus() + \sa QFxItem::setFocus() */ /*! @@ -381,7 +383,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); @@ -390,7 +392,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); @@ -523,7 +525,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(); } /*! @@ -687,7 +694,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 *) @@ -775,6 +782,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 @@ -1493,18 +1510,6 @@ void QFxItem::setRotation(qreal rotation) Scaling is from the item's origin (0,0). */ -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 @@ -1562,19 +1567,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(); } @@ -1882,14 +1880,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(); @@ -1969,20 +1959,6 @@ void QFxItem::componentComplete() updateTransform(); } -/*! \internal -*/ -void QFxItem::parentChanged(QSimpleCanvasItem *, QSimpleCanvasItem *) -{ - emit parentChanged(); -} - -/*! \internal -*/ -void QFxItem::reparentItems() -{ - qFatal("EEK"); -} - /*! \internal */ @@ -2039,4 +2015,505 @@ 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) +{ + 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) +{ +} + +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 ef69fd3..050cc3e 100644 --- a/src/declarative/fx/qfxitem.h +++ b/src/declarative/fx/qfxitem.h @@ -49,10 +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 @@ -95,7 +95,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) @@ -134,16 +134,38 @@ class Q_DECLARATIVE_EXPORT QFxItem : public QSimpleCanvasItem, public QmlParserS 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); @@ -159,6 +181,9 @@ public: QFxContents *contents(); + bool clip() const; + void setClip(bool); + QmlList<QmlState *>* states(); QmlState *findState(const QString &name) const; @@ -180,15 +205,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; @@ -201,6 +224,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); @@ -224,12 +301,19 @@ Q_SIGNALS: void newChildCreated(const QString &url, QScriptValue); protected: + 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); @@ -260,6 +344,16 @@ private: Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxItem) }; QML_DECLARE_TYPE(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 diff --git a/src/declarative/fx/qfxitem_p.h b/src/declarative/fx/qfxitem_p.h index b38d877..113c860 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 a975778..67cf00a 100644 --- a/src/declarative/fx/qfxlayouts.cpp +++ b/src/declarative/fx/qfxlayouts.cpp @@ -314,8 +314,9 @@ void QFxBaseLayout::preLayout() delete d->stateGroup; d->stateGroup = 0; } 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)){ @@ -624,8 +625,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; @@ -790,8 +793,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; @@ -1019,15 +1023,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]) @@ -1047,7 +1053,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/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_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_p.h b/src/declarative/fx/qfxpainteditem_p.h index ec507fb..9d5733c 100644 --- a/src/declarative/fx/qfxpainteditem_p.h +++ b/src/declarative/fx/qfxpainteditem_p.h @@ -54,7 +54,6 @@ // #include <private/qfxitem_p.h> -#include <QtDeclarative/qsimplecanvas.h> QT_BEGIN_NAMESPACE diff --git a/src/declarative/fx/qfxparticles.cpp b/src/declarative/fx/qfxparticles.cpp index 5e84c88..0a6a628 100644 --- a/src/declarative/fx/qfxparticles.cpp +++ b/src/declarative/fx/qfxparticles.cpp @@ -1037,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); @@ -1057,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 @@ -1096,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); diff --git a/src/declarative/fx/qfxparticles.h b/src/declarative/fx/qfxparticles.h index bb84df2..be4dc91 100644 --- a/src/declarative/fx/qfxparticles.h +++ b/src/declarative/fx/qfxparticles.h @@ -207,7 +207,6 @@ public: QFxParticleMotion *motion() const; void setMotion(QFxParticleMotion *); - virtual void dump(int depth); virtual QString propertyInfo() const; void paintContents(QPainter &p); diff --git a/src/declarative/fx/qfxpath.cpp b/src/declarative/fx/qfxpath.cpp index be731b1..ee2a272 100644 --- a/src/declarative/fx/qfxpath.cpp +++ b/src/declarative/fx/qfxpath.cpp @@ -43,6 +43,7 @@ #include "qfxpath_p.h" #include <qfxperf.h> #include <private/qbezier_p.h> +#include <QSet> QT_BEGIN_NAMESPACE diff --git a/src/declarative/fx/qfxpathview_p.h b/src/declarative/fx/qfxpathview_p.h index b5c5ba2..fea207f 100644 --- a/src/declarative/fx/qfxpathview_p.h +++ b/src/declarative/fx/qfxpathview_p.h @@ -88,7 +88,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 0ea94f5..f2c6217 100644 --- a/src/declarative/fx/qfxpixmap.cpp +++ b/src/declarative/fx/qfxpixmap.cpp @@ -46,6 +46,7 @@ #include <qfxperf.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 03ab426..a068fd4 100644 --- a/src/declarative/fx/qfxrect.cpp +++ b/src/declarative/fx/qfxrect.cpp @@ -356,14 +356,6 @@ void QFxRect::setRadius(qreal radius) 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. diff --git a/src/declarative/fx/qfxrect.h b/src/declarative/fx/qfxrect.h index eee1f86..46f918b 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 @@ -159,7 +160,6 @@ public: qreal radius() const; void setRadius(qreal radius); - virtual void dump(int depth); void paintContents(QPainter &painter); private Q_SLOTS: diff --git a/src/declarative/fx/qfxrepeater.cpp b/src/declarative/fx/qfxrepeater.cpp index a6d68cb..3ed47cd 100644 --- a/src/declarative/fx/qfxrepeater.cpp +++ b/src/declarative/fx/qfxrepeater.cpp @@ -243,7 +243,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 17ffa57..2c903d1 100644 --- a/src/declarative/fx/qfxrepeater.h +++ b/src/declarative/fx/qfxrepeater.h @@ -73,7 +73,7 @@ private: protected: virtual void componentComplete(); - virtual void parentChanged(QSimpleCanvasItem *, QSimpleCanvasItem *); + virtual void parentChanged(QFxItem *, QFxItem *); QFxRepeater(QFxRepeaterPrivate &dd, QFxItem *parent); private: diff --git a/src/declarative/fx/qfxscalegrid.h b/src/declarative/fx/qfxscalegrid.h index c59cb32..4a9a72f 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/qfxtext.cpp b/src/declarative/fx/qfxtext.cpp index a5361e1..36c8b23 100644 --- a/src/declarative/fx/qfxtext.cpp +++ b/src/declarative/fx/qfxtext.cpp @@ -506,13 +506,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); diff --git a/src/declarative/fx/qfxtext.h b/src/declarative/fx/qfxtext.h index 83e7299..10b85f0 100644 --- a/src/declarative/fx/qfxtext.h +++ b/src/declarative/fx/qfxtext.h @@ -114,7 +114,6 @@ public: QString activeLink() const; - virtual void dump(int depth); virtual QString propertyInfo() const; void paintContents(QPainter &p); diff --git a/src/declarative/fx/qfxtextedit.cpp b/src/declarative/fx/qfxtextedit.cpp index 3c117ee..addbd58 100644 --- a/src/declarative/fx/qfxtextedit.cpp +++ b/src/declarative/fx/qfxtextedit.cpp @@ -495,16 +495,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 920bd04..93540a4 100644 --- a/src/declarative/fx/qfxtextedit.h +++ b/src/declarative/fx/qfxtextedit.h @@ -138,7 +138,6 @@ public: qreal textMargin() const; void setTextMargin(qreal margin); - virtual void dump(int depth); virtual QString propertyInfo() const; virtual void componentComplete(); diff --git a/src/declarative/fx/qfxvisualitemmodel.cpp b/src/declarative/fx/qfxvisualitemmodel.cpp index c60a379..7d260ab 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> QT_BEGIN_NAMESPACE diff --git a/src/declarative/fx/qfxwebview.cpp b/src/declarative/fx/qfxwebview.cpp index 91579e9..a9cb673 100644 --- a/src/declarative/fx/qfxwebview.cpp +++ b/src/declarative/fx/qfxwebview.cpp @@ -55,7 +55,6 @@ #include "qmlstate.h" #include "qfxtransform.h" #include "qfxscalegrid.h" -#include "qsimplecanvas.h" #include "qlistmodelinterface.h" #include "qfxwebview.h" @@ -535,13 +534,6 @@ void QFxWebView::setCacheSize(int pixels) d->max_imagecache_size = pixels; } -void QFxWebView::dump(int depth) -{ - QByteArray ba(depth * 4, ' '); - qWarning() << ba.constData() << "url:" << url(); - QFxPaintedItem::dump(depth); -} - void QFxWebView::drawContents(QPainter *p, const QRect &r) { page()->mainFrame()->render(p,r); diff --git a/src/declarative/fx/qfxwebview.h b/src/declarative/fx/qfxwebview.h index 115bddc..85c17d7 100644 --- a/src/declarative/fx/qfxwebview.h +++ b/src/declarative/fx/qfxwebview.h @@ -140,7 +140,6 @@ public: QAction *forwardAction() const; QAction *stopAction() const; - virtual void dump(int depth); virtual QString propertyInfo() const; QWebPage *page() const; 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/test/qfxtestengine.cpp b/src/declarative/test/qfxtestengine.cpp deleted file mode 100644 index 0d7e5df..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 <qmltimeline.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 44a140f..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; -}; - -#endif // _QFXTESTENGINE_H_ - - -QT_END_NAMESPACE - -QT_END_HEADER diff --git a/src/declarative/test/qfxtestobjects.cpp b/src/declarative/test/qfxtestobjects.cpp deleted file mode 100644 index 12fc7fb..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> - - -QT_BEGIN_NAMESPACE -QML_DECLARE_TYPE(TestObject) -QML_DEFINE_TYPE(TestObject,TestObject) -QML_DECLARE_TYPE(TestFrame) -QML_DEFINE_TYPE(TestFrame,TestFrame) -QML_DECLARE_TYPE(TestFullFrame) -QML_DEFINE_TYPE(TestFullFrame,TestFullFrame) -QML_DECLARE_TYPE(TestMouse) -QML_DEFINE_TYPE(TestMouse,TestMouse) -QML_DECLARE_TYPE(TestKey) -QML_DEFINE_TYPE(TestKey,TestKey) -QML_DECLARE_TYPE(TestLog) -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 80fcfe7..0000000 --- a/src/declarative/test/qfxtestobjects.h +++ /dev/null @@ -1,212 +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; -}; - -#endif // _QFXTESTOBJECTS_H_ - - -QT_END_NAMESPACE - -QT_END_HEADER 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 a8f78bf..0000000 --- a/src/declarative/test/qfxtestview.h +++ /dev/null @@ -1,74 +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; -}; - -#endif // _QFXTESTVIEW_H_ - - -QT_END_NAMESPACE - -QT_END_HEADER 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/qfxview.cpp b/src/declarative/util/qfxview.cpp index d8d9ba1..43c10bb 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,11 +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); |