Focus behavior
==============
--Prior to being added to a valid canvas items can set and clear focus with no
++Prior to being added to a valid canvas items can set and clear focus with no
effect. Only once items are added to a canvas (by way of having a parent set that
--already belongs to a canvas) do the focus rules apply. Focus goes back to
++already belongs to a canvas) do the focus rules apply. Focus goes back to
having no effect if an item is removed from a canvas.
When an item is moved into a new focus scope (either being added to a canvas
--for the first time, or having its parent changed), if the focus scope already has
++for the first time, or having its parent changed), if the focus scope already has
a scope focused item that takes precedence over the item being added. Otherwise,
--the focus of the added tree is used. In the case of of a tree of items being
++the focus of the added tree is used. In the case of of a tree of items being
added to a canvas for the first time, which may have a conflicted focus state (two
--or more items in one scope having focus set), the same rule is applied item by item -
++or more items in one scope having focus set), the same rule is applied item by item -
thus the first item that has focus will get it (assuming the scope doesn't already
have a scope focused item), and the other items will have their focus cleared.
*/
sceneEvent.setLastPos(transform.map(sceneEvent.lastScenePos()));
for (int ii = 0; ii < 5; ++ii) {
if (sceneEvent.buttons() & (1 << ii)) {
-- sceneEvent.setButtonDownPos((Qt::MouseButton)(1 << ii),
++ sceneEvent.setButtonDownPos((Qt::MouseButton)(1 << ii),
transform.map(sceneEvent.buttonDownScenePos((Qt::MouseButton)(1 << ii))));
}
}
updateInputMethodData();
QFocusEvent event(QEvent::FocusIn, Qt::OtherFocusReason);
-- q->sendEvent(newActiveFocusItem, &event);
++ q->sendEvent(newActiveFocusItem, &event);
} else {
updateInputMethodData();
}
updateInputMethodData();
QFocusEvent event(QEvent::FocusIn, Qt::OtherFocusReason);
-- q->sendEvent(newActiveFocusItem, &event);
++ q->sendEvent(newActiveFocusItem, &event);
} else {
updateInputMethodData();
}
-- if (!changed.isEmpty())
++ if (!changed.isEmpty())
notifyFocusChangesRecur(changed.data(), changed.count() - 1);
}
itemPrivate->itemChange(QSGItem::ItemActiveFocusHasChanged, itemPrivate->activeFocus);
emit item->activeFocusChanged(itemPrivate->activeFocus);
}
-- }
++ }
}
void QSGCanvasPrivate::updateInputMethodData()
QSGItem *QSGCanvas::rootItem() const
{
Q_D(const QSGCanvas);
--
++
return d->rootItem;
}
QSGItem *QSGCanvas::activeFocusItem() const
{
Q_D(const QSGCanvas);
--
++
return d->activeFocusItem;
}
QSGItem *QSGCanvas::mouseGrabberItem() const
{
Q_D(const QSGCanvas);
--
++
return d->mouseGrabberItem;
}
event->accept();
mouseGrabberItem = item;
q->sendEvent(item, event);
-- if (event->isAccepted())
++ if (event->isAccepted())
return true;
mouseGrabberItem->ungrabMouse();
mouseGrabberItem = 0;
{
Q_Q(QSGCanvas);
-- if (!mouseGrabberItem &&
++ if (!mouseGrabberItem &&
sceneEvent->type() == QEvent::GraphicsSceneMousePress &&
(sceneEvent->button() & sceneEvent->buttons()) == sceneEvent->buttons()) {
--
++
return deliverInitialMousePressEvent(rootItem, sceneEvent);
}
void QSGCanvas::mousePressEvent(QMouseEvent *event)
{
Q_D(QSGCanvas);
--
++
#ifdef MOUSE_DEBUG
qWarning() << "QSGCanvas::mousePressEvent()" << event->pos() << event->button() << event->buttons();
#endif
void QSGCanvas::mouseReleaseEvent(QMouseEvent *event)
{
Q_D(QSGCanvas);
--
++
#ifdef MOUSE_DEBUG
qWarning() << "QSGCanvas::mouseReleaseEvent()" << event->pos() << event->button() << event->buttons();
#endif
void QSGCanvas::mouseDoubleClickEvent(QMouseEvent *event)
{
Q_D(QSGCanvas);
--
++
#ifdef MOUSE_DEBUG
qWarning() << "QSGCanvas::mouseDoubleClickEvent()" << event->pos() << event->button() << event->buttons();
#endif
else
event->ignore();
return;
-- }
++ }
d->deliverMouseEvent(&sceneEvent);
event->setAccepted(sceneEvent.isAccepted());
void QSGCanvas::mouseMoveEvent(QMouseEvent *event)
{
Q_D(QSGCanvas);
--
++
#ifdef MOUSE_DEBUG
qWarning() << "QSGCanvas::mouseMoveEvent()" << event->pos() << event->button() << event->buttons();
#endif
return true;
QSGItemPrivate *targetPrivate = QSGItemPrivate::get(target);
-- if (targetPrivate->filtersChildMouseEvents)
++ if (targetPrivate->filtersChildMouseEvents)
if (target->childMouseEventFilter(item, event))
return true;
return false;
}
--bool QSGCanvas::sendEvent(QSGItem *item, QEvent *e)
--{
++bool QSGCanvas::sendEvent(QSGItem *item, QEvent *e)
++{
Q_D(QSGCanvas);
--
++
if (!item) {
qWarning("QSGCanvas::sendEvent: Cannot send event to a null item");
return false;
case QEvent::GraphicsSceneMouseRelease:
case QEvent::GraphicsSceneMouseDoubleClick:
case QEvent::GraphicsSceneMouseMove:
-- // XXX todo - should sendEvent be doing this? how does it relate to forwarded events?
++ // XXX todo - should sendEvent be doing this? how does it relate to forwarded events?
{
QGraphicsSceneMouseEvent *se = static_cast<QGraphicsSceneMouseEvent *>(e);
if (!d->sendFilteredMouseEvent(item->parentItem(), item, se)) {
break;
}
-- return false;
++ return false;
}
void QSGCanvasPrivate::cleanupNodes()
itemPriv->dirtyAttributes = 0;
if ((dirty & QSGItemPrivate::TransformUpdateMask) ||
-- (dirty & QSGItemPrivate::Size && itemPriv->origin != QSGItem::TopLeft &&
++ (dirty & QSGItemPrivate::Size && itemPriv->origin != QSGItem::TopLeft &&
(itemPriv->scale != 1. || itemPriv->rotation != 0.))) {
QMatrix4x4 matrix;
-- if (itemPriv->x != 0. || itemPriv->y != 0.)
++ if (itemPriv->x != 0. || itemPriv->y != 0.)
matrix.translate(itemPriv->x, itemPriv->y);
for (int ii = itemPriv->transforms.count() - 1; ii >= 0; --ii)
if (dirty & QSGItemPrivate::ContentUpdateMask) {
if (itemPriv->flags & QSGItem::ItemHasContents) {
-- updatePaintNodeData.transformNode = itemPriv->itemNode();
++ updatePaintNodeData.transformNode = itemPriv->itemNode();
itemPriv->paintNode = item->updatePaintNode(itemPriv->paintNode, &updatePaintNodeData);
-- Q_ASSERT(itemPriv->paintNode == 0 ||
++ Q_ASSERT(itemPriv->paintNode == 0 ||
itemPriv->paintNode->parent() == 0 ||
itemPriv->paintNode->parent() == itemPriv->childContainerNode());
qDebug("QML Rendering Thread Started");
#endif
- renderer->makeCurrent();
-
- if (!d->context->isReady())
- d->initializeSceneGraph();
+ if (!glContext()) {
+ createGLContext();
+ makeCurrent();
+ initializeSceneGraph();
+ } else {
+ makeCurrent();
+ }
-
+
-
while (!shouldExit) {
lock();
#include <private/qdeclarativeengine_p.h>
#include <QtCore/qbasictimer.h>
- // XXX todo - This whole class should probably be merged with QDeclarativeView for
+
-// XXX todo - This whole class should probably be merged with QDeclarativeView for
++// XXX todo - This whole class should probably be merged with QDeclarativeView for
// maximum seamlessness
QT_BEGIN_NAMESPACE
DEFINE_BOOL_CONFIG_OPTION(frameRateDebug, QML_SHOW_FRAMERATE)
- class QSGViewPrivate : public QSGCanvasPrivate,
- public QSGItemChangeListener
- {
- Q_DECLARE_PUBLIC(QSGView)
- public:
- QSGViewPrivate();
- ~QSGViewPrivate();
-
- void execute();
- void itemGeometryChanged(QSGItem *item, const QRectF &newGeometry, const QRectF &oldGeometry);
- void initResize();
- void updateSize();
- void setRootObject(QObject *);
-
- void init();
-
- QSize rootObjectSize() const;
-
- QPointer<QSGItem> root;
-
- QUrl source;
-
- QDeclarativeEngine engine;
- QDeclarativeComponent *component;
- QBasicTimer resizetimer;
-
- QSGView::ResizeMode resizeMode;
- QSize initialSize;
- QElapsedTimer frameTimer;
-
- bool resized;
- };
-
void QSGViewPrivate::init()
{
- q_func()->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
QDeclarativeEnginePrivate::get(&engine)->sgContext = QSGCanvasPrivate::context;
QDeclarativeInspectorService::instance()->addView(q_func());
{
}
--QSGViewPrivate::~QSGViewPrivate()
--{
++QSGViewPrivate::~QSGViewPrivate()
++{
QDeclarativeInspectorService::instance()->removeView(q_func());
delete root;
if (!component->isLoading()) {
q->continueExecute();
} else {
-- QObject::connect(component, SIGNAL(statusChanged(QDeclarativeComponent::Status)),
++ QObject::connect(component, SIGNAL(statusChanged(QDeclarativeComponent::Status)),
q, SLOT(continueExecute()));
}
}
void QSGView::resizeEvent(QResizeEvent *e)
{
Q_D(QSGView);
-- if (d->resizeMode == SizeRootObjectToView)
++ if (d->resizeMode == SizeRootObjectToView)
d->updateSize();
--
- QSGCanvas::resizeEvent(e);
-}
+
-/*!
- \internal
-*/
-void QSGView::paintEvent(QPaintEvent *event)
-{
- Q_D(QSGView);
- int time = 0;
- if (frameRateDebug())
- time = d->frameTimer.restart();
-
- QSGCanvas::paintEvent(event);
-
- if (frameRateDebug())
- qDebug() << "paintEvent:" << d->frameTimer.elapsed() << "time since last frame:" << time;
+ QSGCanvas::resizeEvent(e);
}
void QSGView::keyPressEvent(QKeyEvent *e)
QT_BEGIN_NAMESPACE
- class QJSEngine;
- class QDeclarativeEngine;
+ QT_MODULE(Declarative)
+
+ class QDeclarativeContext;
+ class QDeclarativeError;
+ class QSGItem;
+ class QDeclarativeComponent;
- // Helper methods to access private API through a stable interface
- // This is used in the qmljsdebugger library of QtCreator.
- class Q_DECLARATIVE_EXPORT QDeclarativeDebugHelper
+ class QSGViewPrivate : public QSGCanvasPrivate,
+ public QSGItemChangeListener
{
+ Q_DECLARE_PUBLIC(QSGView)
public:
- static QJSEngine *getScriptEngine(QDeclarativeEngine *engine);
- static void setAnimationSlowDownFactor(qreal factor);
+ static QSGViewPrivate* get(QSGView *view) { return view->d_func(); }
+ static const QSGViewPrivate* get(const QSGView *view) { return view->d_func(); }
+
+ QSGViewPrivate();
+ ~QSGViewPrivate();
+
+ void execute();
+ void itemGeometryChanged(QSGItem *item, const QRectF &newGeometry, const QRectF &oldGeometry);
+ void initResize();
+ void updateSize();
+ void setRootObject(QObject *);
+
+ void init();
+
+ QSize rootObjectSize() const;
+
+ QPointer<QSGItem> root;
+
+ QUrl source;
+
+ QDeclarativeEngine engine;
+ QDeclarativeComponent *component;
+ QBasicTimer resizetimer;
+
+ QSGView::ResizeMode resizeMode;
+ QSize initialSize;
+ QElapsedTimer frameTimer;
+
- // Enables remote debugging functionality
- // Only use this for debugging in a safe environment!
- static void enableDebugging();
++ bool resized;
};
QT_END_NAMESPACE