Qt 4.8
qdeclarativeitem.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qdeclarativeitem.h"
43 
44 #include "private/qdeclarativeevents_p_p.h"
45 #include <private/qdeclarativeengine_p.h>
46 #include <private/qgraphicsitem_p.h>
47 #include <QtDeclarative/private/qdeclarativeitem_p.h>
48 
49 #include <qdeclarativeengine.h>
51 #include <qdeclarativestate_p.h>
52 #include <qdeclarativeview.h>
54 #include <qdeclarativecomponent.h>
55 #include <qdeclarativeinfo.h>
56 
57 #include <QDebug>
58 #include <QPen>
59 #include <QEvent>
60 #include <QGraphicsSceneMouseEvent>
61 #include <QtCore/qnumeric.h>
62 #include <QtScript/qscriptengine.h>
63 #include <QtGui/qgraphicstransform.h>
64 #include <qlistmodelinterface_p.h>
65 
66 #include <float.h>
67 
69 
268 QDeclarativeContents::QDeclarativeContents(QDeclarativeItem *item) : m_item(item), m_x(0), m_y(0), m_width(0), m_height(0)
269 {
270  //### optimize
271  connect(this, SIGNAL(rectChanged(QRectF)), m_item, SIGNAL(childrenRectChanged(QRectF)));
272 }
273 
275 {
277  for (int i = 0; i < children.count(); ++i) {
278  QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(children.at(i));
279  if(!child)//### Should this be ignoring non-QDeclarativeItem graphicsobjects?
280  continue;
282  }
283 }
284 
286 {
287  return QRectF(m_x, m_y, m_width, m_height);
288 }
289 
291 {
292  qreal oldy = m_y;
293  qreal oldheight = m_height;
294 
295  if (changed) {
296  qreal top = oldy;
297  qreal bottom = oldy + oldheight;
298  qreal y = changed->y();
299  if (y + changed->height() > bottom)
300  bottom = y + changed->height();
301  if (y < top)
302  top = y;
303  m_y = top;
304  m_height = bottom - top;
305  } else {
306  qreal top = FLT_MAX;
307  qreal bottom = 0;
309  for (int i = 0; i < children.count(); ++i) {
310  QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(children.at(i));
311  if(!child)//### Should this be ignoring non-QDeclarativeItem graphicsobjects?
312  continue;
313  qreal y = child->y();
314  if (y + child->height() > bottom)
315  bottom = y + child->height();
316  if (y < top)
317  top = y;
318  }
319  if (!children.isEmpty())
320  m_y = top;
321  m_height = qMax(bottom - top, qreal(0.0));
322  }
323 
324  if (m_height != oldheight || m_y != oldy)
326 }
327 
329 {
330  qreal oldx = m_x;
331  qreal oldwidth = m_width;
332 
333  if (changed) {
334  qreal left = oldx;
335  qreal right = oldx + oldwidth;
336  qreal x = changed->x();
337  if (x + changed->width() > right)
338  right = x + changed->width();
339  if (x < left)
340  left = x;
341  m_x = left;
342  m_width = right - left;
343  } else {
344  qreal left = FLT_MAX;
345  qreal right = 0;
347  for (int i = 0; i < children.count(); ++i) {
348  QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(children.at(i));
349  if(!child)//### Should this be ignoring non-QDeclarativeItem graphicsobjects?
350  continue;
351  qreal x = child->x();
352  if (x + child->width() > right)
353  right = x + child->width();
354  if (x < left)
355  left = x;
356  }
357  if (!children.isEmpty())
358  m_x = left;
359  m_width = qMax(right - left, qreal(0.0));
360  }
361 
362  if (m_width != oldwidth || m_x != oldx)
364 }
365 
367 {
369  for (int i = 0; i < children.count(); ++i) {
370  QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(children.at(i));
371  if(!child)//### Should this be ignoring non-QDeclarativeItem graphicsobjects?
372  continue;
374  //###what about changes to visibility?
375  }
376 
377  calcGeometry();
378 }
379 
380 void QDeclarativeContents::itemGeometryChanged(QDeclarativeItem *changed, const QRectF &newGeometry, const QRectF &oldGeometry)
381 {
382  Q_UNUSED(changed)
383  //### we can only pass changed if the left edge has moved left, or the right edge has moved right
384  if (newGeometry.width() != oldGeometry.width() || newGeometry.x() != oldGeometry.x())
385  calcWidth(/*changed*/);
386  if (newGeometry.height() != oldGeometry.height() || newGeometry.y() != oldGeometry.y())
387  calcHeight(/*changed*/);
388 }
389 
391 {
392  if (item)
394  calcGeometry();
395 }
396 
398 {
399  if (item)
401  calcGeometry();
402 }
403 
405 {
406  if (item)
408  calcWidth(item);
409  calcHeight(item);
410 }
411 
413 : m_processPost(false), m_next(0)
414 {
416  item?static_cast<QDeclarativeItemPrivate *>(QGraphicsItemPrivate::get(item)):0;
417  if (p) {
418  m_next = p->keyHandler;
419  p->keyHandler = this;
420  }
421 }
422 
424 {
425 }
426 
428 {
429  if (m_next) m_next->keyPressed(event, post);
430 }
431 
433 {
434  if (m_next) m_next->keyReleased(event, post);
435 }
436 
438 {
439  if (m_next) m_next->inputMethodEvent(event, post);
440 }
441 
443 {
444  if (m_next) return m_next->inputMethodQuery(query);
445  return QVariant();
446 }
447 
449 {
451 }
452 
453 
524 {
525  m_processPost = true;
526 }
527 
530 {
531  return new QDeclarativeKeyNavigationAttached(obj);
532 }
533 
535 {
537  return d->left;
538 }
539 
541 {
543  if (d->left == i)
544  return;
545  d->left = i;
546  emit leftChanged();
547 }
548 
550 {
552  return d->right;
553 }
554 
556 {
558  if (d->right == i)
559  return;
560  d->right = i;
561  emit rightChanged();
562 }
563 
565 {
567  return d->up;
568 }
569 
571 {
573  if (d->up == i)
574  return;
575  d->up = i;
576  emit upChanged();
577 }
578 
580 {
582  return d->down;
583 }
584 
586 {
588  if (d->down == i)
589  return;
590  d->down = i;
591  emit downChanged();
592 }
593 
595 {
597  return d->tab;
598 }
599 
601 {
603  if (d->tab == i)
604  return;
605  d->tab = i;
606  emit tabChanged();
607 }
608 
610 {
612  return d->backtab;
613 }
614 
616 {
618  if (d->backtab == i)
619  return;
620  d->backtab = i;
622 }
623 
643 {
645 }
646 
648 {
649  bool processPost = order == AfterItem;
650  if (processPost != m_processPost) {
651  m_processPost = processPost;
653  }
654 }
655 
657 {
659  event->ignore();
660 
661  if (post != m_processPost) {
663  return;
664  }
665 
666  bool mirror = false;
667  switch(event->key()) {
668  case Qt::Key_Left: {
669  if (QDeclarativeItem *parentItem = qobject_cast<QDeclarativeItem*>(parent()))
671  QDeclarativeItem* leftItem = mirror ? d->right : d->left;
672  if (leftItem) {
673  setFocusNavigation(leftItem, mirror ? "right" : "left");
674  event->accept();
675  }
676  break;
677  }
678  case Qt::Key_Right: {
679  if (QDeclarativeItem *parentItem = qobject_cast<QDeclarativeItem*>(parent()))
681  QDeclarativeItem* rightItem = mirror ? d->left : d->right;
682  if (rightItem) {
683  setFocusNavigation(rightItem, mirror ? "left" : "right");
684  event->accept();
685  }
686  break;
687  }
688  case Qt::Key_Up:
689  if (d->up) {
690  setFocusNavigation(d->up, "up");
691  event->accept();
692  }
693  break;
694  case Qt::Key_Down:
695  if (d->down) {
696  setFocusNavigation(d->down, "down");
697  event->accept();
698  }
699  break;
700  case Qt::Key_Tab:
701  if (d->tab) {
702  setFocusNavigation(d->tab, "tab");
703  event->accept();
704  }
705  break;
706  case Qt::Key_Backtab:
707  if (d->backtab) {
708  setFocusNavigation(d->backtab, "backtab");
709  event->accept();
710  }
711  break;
712  default:
713  break;
714  }
715 
716  if (!event->isAccepted()) QDeclarativeItemKeyFilter::keyPressed(event, post);
717 }
718 
720 {
722  event->ignore();
723 
724  if (post != m_processPost) {
726  return;
727  }
728 
729  bool mirror = false;
730  switch(event->key()) {
731  case Qt::Key_Left:
732  if (QDeclarativeItem *parentItem = qobject_cast<QDeclarativeItem*>(parent()))
734  if (mirror ? d->right : d->left)
735  event->accept();
736  break;
737  case Qt::Key_Right:
738  if (QDeclarativeItem *parentItem = qobject_cast<QDeclarativeItem*>(parent()))
740  if (mirror ? d->left : d->right)
741  event->accept();
742  break;
743  case Qt::Key_Up:
744  if (d->up) {
745  event->accept();
746  }
747  break;
748  case Qt::Key_Down:
749  if (d->down) {
750  event->accept();
751  }
752  break;
753  case Qt::Key_Tab:
754  if (d->tab) {
755  event->accept();
756  }
757  break;
758  case Qt::Key_Backtab:
759  if (d->backtab) {
760  event->accept();
761  }
762  break;
763  default:
764  break;
765  }
766 
767  if (!event->isAccepted()) QDeclarativeItemKeyFilter::keyReleased(event, post);
768 }
769 
771 {
772  QDeclarativeItem *initialItem = currentItem;
773  bool isNextItem = false;
774  do {
775  isNextItem = false;
776  if (currentItem->isVisible() && currentItem->isEnabled()) {
777  currentItem->setFocus(true);
778  } else {
779  QObject *attached =
780  qmlAttachedPropertiesObject<QDeclarativeKeyNavigationAttached>(currentItem, false);
781  if (attached) {
782  QDeclarativeItem *tempItem = qvariant_cast<QDeclarativeItem*>(attached->property(dir));
783  if (tempItem) {
784  currentItem = tempItem;
785  isNextItem = true;
786  }
787  }
788  }
789  }
790  while (currentItem != initialItem && isNextItem);
791 }
792 
866 {
867  if (QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(parent)) {
870  } else
871  qmlInfo(parent) << tr("LayoutDirection attached property only works with Items");
872 }
873 
875 {
876  return new QDeclarativeLayoutMirroringAttached(object);
877 }
878 
880 {
882 }
883 
885 {
886  if (!itemPrivate)
887  return;
888 
889  itemPrivate->isMirrorImplicit = false;
890  if (enabled != itemPrivate->effectiveLayoutMirror) {
891  itemPrivate->setLayoutMirror(enabled);
894  }
895 }
896 
898 {
902  }
903 }
904 
906 {
908 }
909 
911  if (itemPrivate && childrenInherit != itemPrivate->inheritMirrorFromItem) {
915  }
916 }
917 
919 {
921  if (QDeclarativeItem *parentItem = q->parentItem()) {
922  QDeclarativeItemPrivate *parentPrivate = QDeclarativeItemPrivate::get(parentItem);
923  setImplicitLayoutMirror(parentPrivate->inheritedLayoutMirror, parentPrivate->inheritMirrorFromParent);
924  } else {
925  setImplicitLayoutMirror(isMirrorImplicit ? false : effectiveLayoutMirror, inheritMirrorFromItem);
926  }
927 }
928 
930 {
931  inherit = inherit || inheritMirrorFromItem;
932  if (!isMirrorImplicit && inheritMirrorFromItem)
933  mirror = effectiveLayoutMirror;
934  if (mirror == inheritedLayoutMirror && inherit == inheritMirrorFromParent)
935  return;
936 
937  inheritMirrorFromParent = inherit;
938  inheritedLayoutMirror = inheritMirrorFromParent ? mirror : false;
939 
940  if (isMirrorImplicit)
941  setLayoutMirror(inherit ? inheritedLayoutMirror : false);
942  for (int i = 0; i < children.count(); ++i) {
943  if (QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(children.at(i))) {
945  childPrivate->setImplicitLayoutMirror(inheritedLayoutMirror, inheritMirrorFromParent);
946  }
947  }
948 }
949 
951 {
952  if (mirror != effectiveLayoutMirror) {
953  effectiveLayoutMirror = mirror;
954  if (_anchors) {
955  _anchors->d_func()->fillChanged();
956  _anchors->d_func()->centerInChanged();
957  _anchors->d_func()->updateHorizontalAnchors();
958  }
959  mirrorChange();
960  if (attachedLayoutDirection) {
961  emit attachedLayoutDirection->enabledChanged();
962  }
963  }
964 }
965 
1480  { Qt::Key_Left, "leftPressed" },
1481  { Qt::Key_Right, "rightPressed" },
1482  { Qt::Key_Up, "upPressed" },
1483  { Qt::Key_Down, "downPressed" },
1484  { Qt::Key_Tab, "tabPressed" },
1485  { Qt::Key_Backtab, "backtabPressed" },
1486  { Qt::Key_Asterisk, "asteriskPressed" },
1487  { Qt::Key_NumberSign, "numberSignPressed" },
1488  { Qt::Key_Escape, "escapePressed" },
1489  { Qt::Key_Return, "returnPressed" },
1490  { Qt::Key_Enter, "enterPressed" },
1491  { Qt::Key_Delete, "deletePressed" },
1492  { Qt::Key_Space, "spacePressed" },
1493  { Qt::Key_Back, "backPressed" },
1494  { Qt::Key_Cancel, "cancelPressed" },
1495  { Qt::Key_Select, "selectPressed" },
1496  { Qt::Key_Yes, "yesPressed" },
1497  { Qt::Key_No, "noPressed" },
1498  { Qt::Key_Context1, "context1Pressed" },
1499  { Qt::Key_Context2, "context2Pressed" },
1500  { Qt::Key_Context3, "context3Pressed" },
1501  { Qt::Key_Context4, "context4Pressed" },
1502  { Qt::Key_Call, "callPressed" },
1503  { Qt::Key_Hangup, "hangupPressed" },
1504  { Qt::Key_Flip, "flipPressed" },
1505  { Qt::Key_Menu, "menuPressed" },
1506  { Qt::Key_VolumeUp, "volumeUpPressed" },
1507  { Qt::Key_VolumeDown, "volumeDownPressed" },
1508  { 0, 0 }
1509 };
1510 
1512 {
1513  return isSignalConnected(signalIndex(signalName));
1514 }
1515 
1517 : QObject(*(new QDeclarativeKeysAttachedPrivate), parent),
1519 {
1521  m_processPost = false;
1523 }
1524 
1526 {
1527 }
1528 
1530 {
1531  return m_processPost ? AfterItem : BeforeItem;
1532 }
1533 
1535 {
1536  bool processPost = order == AfterItem;
1537  if (processPost != m_processPost) {
1538  m_processPost = processPost;
1540  }
1541 }
1542 
1544 {
1546  if (d->item) {
1547  for (int ii = 0; ii < d->targets.count(); ++ii) {
1548  QGraphicsItem *targetItem = d->finalFocusProxy(d->targets.at(ii));
1549  if (targetItem && (targetItem->flags() & QGraphicsItem::ItemAcceptsInputMethod)) {
1550  d->item->setFlag(QGraphicsItem::ItemAcceptsInputMethod);
1551  break;
1552  }
1553  }
1554  }
1555 }
1556 
1558 {
1560  if (post != m_processPost || !d->enabled || d->inPress) {
1561  event->ignore();
1563  return;
1564  }
1565 
1566  // first process forwards
1567  if (d->item && d->item->scene()) {
1568  d->inPress = true;
1569  for (int ii = 0; ii < d->targets.count(); ++ii) {
1570  QGraphicsItem *i = d->finalFocusProxy(d->targets.at(ii));
1571  if (i && i->isVisible()) {
1572  d->item->scene()->sendEvent(i, event);
1573  if (event->isAccepted()) {
1574  d->inPress = false;
1575  return;
1576  }
1577  }
1578  }
1579  d->inPress = false;
1580  }
1581 
1582  QDeclarativeKeyEvent ke(*event);
1583  QByteArray keySignal = keyToSignal(event->key());
1584  if (!keySignal.isEmpty()) {
1585  keySignal += "(QDeclarativeKeyEvent*)";
1586  if (d->isConnected(keySignal)) {
1587  // If we specifically handle a key then default to accepted
1588  ke.setAccepted(true);
1591  }
1592  }
1593  if (!ke.isAccepted())
1594  emit pressed(&ke);
1595  event->setAccepted(ke.isAccepted());
1596 
1597  if (!event->isAccepted()) QDeclarativeItemKeyFilter::keyPressed(event, post);
1598 }
1599 
1601 {
1603  if (post != m_processPost || !d->enabled || d->inRelease) {
1604  event->ignore();
1606  return;
1607  }
1608 
1609  if (d->item && d->item->scene()) {
1610  d->inRelease = true;
1611  for (int ii = 0; ii < d->targets.count(); ++ii) {
1612  QGraphicsItem *i = d->finalFocusProxy(d->targets.at(ii));
1613  if (i && i->isVisible()) {
1614  d->item->scene()->sendEvent(i, event);
1615  if (event->isAccepted()) {
1616  d->inRelease = false;
1617  return;
1618  }
1619  }
1620  }
1621  d->inRelease = false;
1622  }
1623 
1624  QDeclarativeKeyEvent ke(*event);
1625  emit released(&ke);
1626  event->setAccepted(ke.isAccepted());
1627 
1628  if (!event->isAccepted()) QDeclarativeItemKeyFilter::keyReleased(event, post);
1629 }
1630 
1632 {
1634  if (post == m_processPost && d->item && !d->inIM && d->item->scene()) {
1635  d->inIM = true;
1636  for (int ii = 0; ii < d->targets.count(); ++ii) {
1637  QGraphicsItem *i = d->finalFocusProxy(d->targets.at(ii));
1638  if (i && i->isVisible() && (i->flags() & QGraphicsItem::ItemAcceptsInputMethod)) {
1639  d->item->scene()->sendEvent(i, event);
1640  if (event->isAccepted()) {
1641  d->imeItem = i;
1642  d->inIM = false;
1643  return;
1644  }
1645  }
1646  }
1647  d->inIM = false;
1648  }
1649  if (!event->isAccepted()) QDeclarativeItemKeyFilter::inputMethodEvent(event, post);
1650 }
1651 
1653 {
1654 public:
1656  return QGraphicsItem::inputMethodQuery(query);
1657  }
1658 };
1659 
1661 {
1663  if (d->item) {
1664  for (int ii = 0; ii < d->targets.count(); ++ii) {
1665  QGraphicsItem *i = d->finalFocusProxy(d->targets.at(ii));
1666  if (i && i->isVisible() && (i->flags() & QGraphicsItem::ItemAcceptsInputMethod) && i == d->imeItem) { //### how robust is i == d->imeItem check?
1667  QVariant v = static_cast<QDeclarativeItemAccessor *>(i)->doInputMethodQuery(query);
1668  if (v.userType() == QVariant::RectF)
1669  v = d->item->mapRectFromItem(i, v.toRectF()); //### cost?
1670  return v;
1671  }
1672  }
1673  }
1675 }
1676 
1678 {
1679  return new QDeclarativeKeysAttached(obj);
1680 }
1681 
1816 // ### Must fix
1819  qRegisterMetaType<QDeclarativeAnchorLine>("QDeclarativeAnchorLine");
1820  }
1821 };
1823 
1824 
1831  : QGraphicsObject(*(new QDeclarativeItemPrivate), parent, 0)
1832 {
1834  d->init(parent);
1835 }
1836 
1840  : QGraphicsObject(dd, parent, 0)
1841 {
1843  d->init(parent);
1844 }
1845 
1850 {
1852  for (int ii = 0; ii < d->changeListeners.count(); ++ii) {
1853  QDeclarativeAnchorsPrivate *anchor = d->changeListeners.at(ii).listener->anchorPrivate();
1854  if (anchor)
1855  anchor->clearItem(this);
1856  }
1857  if (!d->parent || (parentItem() && !parentItem()->QGraphicsItem::d_ptr->inDestructor)) {
1858  for (int ii = 0; ii < d->changeListeners.count(); ++ii) {
1859  QDeclarativeAnchorsPrivate *anchor = d->changeListeners.at(ii).listener->anchorPrivate();
1860  if (anchor && anchor->item && anchor->item->parentItem() != this) //child will be deleted anyway
1861  anchor->updateOnComplete();
1862  }
1863  }
1864  for(int ii = 0; ii < d->changeListeners.count(); ++ii) {
1865  const QDeclarativeItemPrivate::ChangeListener &change = d->changeListeners.at(ii);
1867  change.listener->itemDestroyed(this);
1868  }
1869  d->changeListeners.clear();
1870  delete d->_anchorLines; d->_anchorLines = 0;
1871  delete d->_anchors; d->_anchors = 0;
1872  delete d->_stateGroup; d->_stateGroup = 0;
1873  delete d->_contents; d->_contents = 0;
1874 }
1875 
1918 {
1920 }
1921 
1926 {
1928 }
1929 
1985 {
1986  Q_D(const QDeclarativeItem);
1987  return d->componentComplete;
1988 }
1989 
1991 {
1992  if (!o)
1993  return;
1994 
1995  QDeclarativeItem *that = static_cast<QDeclarativeItem *>(prop->object);
1996 
1997  // This test is measurably (albeit only slightly) faster than qobject_cast<>()
1998  const QMetaObject *mo = o->metaObject();
1999  while (mo && mo != &QGraphicsObject::staticMetaObject) mo = mo->d.superdata;
2000 
2001  if (mo) {
2002  QGraphicsObject *graphicsObject = static_cast<QGraphicsObject *>(o);
2003  QDeclarativeItemPrivate *contentItemPrivate = static_cast<QDeclarativeItemPrivate *>(QGraphicsItemPrivate::get(graphicsObject));
2004  if (contentItemPrivate->componentComplete) {
2005  graphicsObject->setParentItem(that);
2006  } else {
2007  contentItemPrivate->setParentItemHelper(that, /*newParentVariant=*/0, /*thisPointerVariant=*/0);
2008  }
2009  } else {
2010  o->setParent(that);
2011  }
2012 }
2013 
2015 {
2016  QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(static_cast<QGraphicsObject *>(prop->object));
2017  return d->children.count();
2018 }
2019 
2021 {
2022  QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(static_cast<QGraphicsObject *>(prop->object));
2023  if (index >= 0 && index < d->children.count())
2024  return d->children.at(index)->toGraphicsObject();
2025  else
2026  return 0;
2027 }
2028 
2030 {
2031  QDeclarativeItemPrivate *d = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(static_cast<QGraphicsObject *>(prop->object)));
2032  int childCount = d->children.count();
2033  if (d->componentComplete) {
2034  for (int index = 0 ;index < childCount; index++)
2035  d->children.at(0)->setParentItem(0);
2036  } else {
2037  for (int index = 0 ;index < childCount; index++)
2038  QGraphicsItemPrivate::get(d->children.at(0))->setParentItemHelper(0, /*newParentVariant=*/0, /*thisPointerVariant=*/0);
2039  }
2040 }
2041 
2043 {
2044  return resources_count(prop) + children_count_helper(prop);
2045 }
2046 
2048 {
2049  int resourcesCount = resources_count(prop);
2050  if (i < resourcesCount)
2051  return resources_at(prop, i);
2052  const int j = i - resourcesCount;
2053  if (j < children_count_helper(prop))
2054  return children_at_helper(prop, j);
2055  return 0;
2056 }
2057 
2059 {
2060  resources_clear(prop);
2061  children_clear_helper(prop);
2062 }
2063 
2065 {
2066  const QObjectList children = prop->object->children();
2067  if (index < children.count())
2068  return children.at(index);
2069  else
2070  return 0;
2071 }
2072 
2074 {
2075  o->setParent(prop->object);
2076 }
2077 
2079 {
2080  return prop->object->children().count();
2081 }
2082 
2084 {
2085  const QObjectList children = prop->object->children();
2086  for (int index = 0; index < children.count(); index++)
2087  children.at(index)->setParent(0);
2088 }
2089 
2091 {
2092  QGraphicsObject *object = qobject_cast<QGraphicsObject *>(list->object);
2093  if (object) {
2095  return d->transformData ? d->transformData->graphicsTransforms.size() : 0;
2096  } else {
2097  return 0;
2098  }
2099 }
2100 
2102 {
2103  QGraphicsObject *object = qobject_cast<QGraphicsObject *>(list->object);
2104  if (object && item) // QGraphicsItem applies the list in the wrong order, so we prepend.
2106 }
2107 
2109 {
2110  QGraphicsObject *object = qobject_cast<QGraphicsObject *>(list->object);
2111  if (object) {
2113  if (!d->transformData)
2114  return 0;
2115  return d->transformData->graphicsTransforms.at(idx);
2116  } else {
2117  return 0;
2118  }
2119 }
2120 
2122 {
2123  QGraphicsObject *object = qobject_cast<QGraphicsObject *>(list->object);
2124  if (object) {
2126  if (!d->transformData)
2127  return;
2128  object->setTransformations(QList<QGraphicsTransform *>());
2129  }
2130 }
2131 
2133 {
2134  QDeclarativeItem *item = static_cast<QDeclarativeItem*>(o);
2135  if (e)
2136  e->connect(&item->d_func()->parentNotifier);
2137  *((QDeclarativeItem **)rv) = item->parentItem();
2138 }
2139 
2178 {
2183  );
2184 }
2185 
2196 {
2198  if (!d->_contents) {
2199  d->_contents = new QDeclarativeContents(this);
2200  if (d->componentComplete)
2201  d->_contents->complete();
2202  }
2203  return d->_contents->rectF();
2204 }
2205 
2206 bool QDeclarativeItem::clip() const
2207 {
2208  return flags() & ItemClipsChildrenToShape;
2209 }
2210 
2212 {
2213  if (clip() == c)
2214  return;
2216  emit clipChanged(c);
2217 }
2218 
2351  const QRectF &oldGeometry)
2352 {
2354 
2355  if (d->_anchors)
2356  d->_anchors->d_func()->updateMe();
2357 
2359  && (newGeometry.width() != oldGeometry.width() || newGeometry.height() != oldGeometry.height())) {
2360  if (d->transformData) {
2361  QPointF origin = d->computeTransformOrigin();
2362  if (transformOriginPoint() != origin)
2363  setTransformOriginPoint(origin);
2364  } else {
2365  d->transformOriginDirty = true;
2366  }
2367  }
2368 
2369  for(int ii = 0; ii < d->changeListeners.count(); ++ii) {
2370  const QDeclarativeItemPrivate::ChangeListener &change = d->changeListeners.at(ii);
2372  change.listener->itemGeometryChanged(this, newGeometry, oldGeometry);
2373  }
2374 
2375  if (newGeometry.width() != oldGeometry.width())
2376  emit widthChanged();
2377  if (newGeometry.height() != oldGeometry.height())
2378  emit heightChanged();
2379 }
2380 
2382 {
2383  ChangeListener change(listener, types);
2384  changeListeners.removeOne(change);
2385 }
2386 
2389 {
2391  keyPressPreHandler(event);
2392  if (event->isAccepted())
2393  return;
2394  if (d->keyHandler)
2395  d->keyHandler->keyPressed(event, true);
2396  else
2397  event->ignore();
2398 }
2399 
2402 {
2404  keyReleasePreHandler(event);
2405  if (event->isAccepted())
2406  return;
2407  if (d->keyHandler)
2408  d->keyHandler->keyReleased(event, true);
2409  else
2410  event->ignore();
2411 }
2412 
2415 {
2417  inputMethodPreHandler(event);
2418  if (event->isAccepted())
2419  return;
2420  if (d->keyHandler)
2421  d->keyHandler->inputMethodEvent(event, true);
2422  else
2423  event->ignore();
2424 }
2425 
2428 {
2429  Q_D(const QDeclarativeItem);
2430  QVariant v;
2431  if (d->keyHandler)
2432  v = d->keyHandler->inputMethodQuery(query);
2433 
2434  if (!v.isValid())
2436 
2437  return v;
2438 }
2439 
2444 {
2446  if (d->keyHandler && !d->doneEventPreHandler)
2447  d->keyHandler->keyPressed(event, false);
2448  else
2449  event->ignore();
2450  d->doneEventPreHandler = true;
2451 }
2452 
2457 {
2459  if (d->keyHandler && !d->doneEventPreHandler)
2460  d->keyHandler->keyReleased(event, false);
2461  else
2462  event->ignore();
2463  d->doneEventPreHandler = true;
2464 }
2465 
2470 {
2472  if (d->keyHandler && !d->doneEventPreHandler)
2473  d->keyHandler->inputMethodEvent(event, false);
2474  else
2475  event->ignore();
2476  d->doneEventPreHandler = true;
2477 }
2478 
2483 {
2484  return anchorLines()->left;
2485 }
2486 
2491 {
2492  return anchorLines()->right;
2493 }
2494 
2499 {
2500  return anchorLines()->hCenter;
2501 }
2502 
2507 {
2508  return anchorLines()->top;
2509 }
2510 
2515 {
2516  return anchorLines()->bottom;
2517 }
2518 
2523 {
2524  return anchorLines()->vCenter;
2525 }
2526 
2527 
2532 {
2533  return anchorLines()->baseline;
2534 }
2535 
2639 {
2640  Q_D(const QDeclarativeItem);
2641  if (!d->baselineOffset.isValid()) {
2642  return 0.0;
2643  } else
2644  return d->baselineOffset;
2645 }
2646 
2648 {
2650  if (offset == d->baselineOffset)
2651  return;
2652 
2653  d->baselineOffset = offset;
2654 
2655  for(int ii = 0; ii < d->changeListeners.count(); ++ii) {
2656  const QDeclarativeItemPrivate::ChangeListener &change = d->changeListeners.at(ii);
2659  if (anchor)
2660  anchor->updateVerticalAnchors();
2661  }
2662  }
2663  emit baselineOffsetChanged(offset);
2664 }
2665 
2797 {
2798  Q_D(const QDeclarativeItem);
2799  return d->keepMouse;
2800 }
2801 
2821 {
2823  d->keepMouse = keep;
2824 }
2825 
2851 {
2853  if (!itemObj && !item.isNull()) {
2854  qmlInfo(this) << "mapFromItem() given argument \"" << item.toString() << "\" which is neither null nor an Item";
2855  return 0;
2856  }
2857 
2858  // If QGraphicsItem::mapFromItem() is called with 0, behaves the same as mapFromScene()
2859  QPointF p = qobject_cast<QGraphicsItem*>(this)->mapFromItem(itemObj, x, y);
2860 
2861  // Use the script engine from the passed item, if available. Use this item's one otherwise.
2862  QScriptEngine* const se = itemObj ? item.engine() : QDeclarativeEnginePrivate::getScriptEngine(qmlEngine(this));
2863 
2864  // Engine-less items are unlikely, but nevertheless possible. Handle them.
2865  if (0 == se)
2867 
2868  QScriptValue sv = se->newObject();
2869  sv.setProperty(QLatin1String("x"), p.x());
2870  sv.setProperty(QLatin1String("y"), p.y());
2871  return sv;
2872 }
2873 
2899 {
2901  if (!itemObj && !item.isNull()) {
2902  qmlInfo(this) << "mapToItem() given argument \"" << item.toString() << "\" which is neither null nor an Item";
2903  return 0;
2904  }
2905 
2906  // If QGraphicsItem::mapToItem() is called with 0, behaves the same as mapToScene()
2907  QPointF p = qobject_cast<QGraphicsItem*>(this)->mapToItem(itemObj, x, y);
2908 
2909  // Use the script engine from the passed item, if available. Use this item's one otherwise.
2910  QScriptEngine* const se = itemObj ? item.engine() : QDeclarativeEnginePrivate::getScriptEngine(qmlEngine(this));
2911 
2912  // Engine-less items are unlikely, but nevertheless possible. Handle them.
2913  if (0 == se)
2915 
2916  QScriptValue sv = se->newObject();
2917  sv.setProperty(QLatin1String("x"), p.x());
2918  sv.setProperty(QLatin1String("y"), p.y());
2919  return sv;
2920 }
2921 
2941 {
2942  setFocus(true);
2944  while (parent) {
2945  if (parent->flags() & QGraphicsItem::ItemIsFocusScope)
2946  parent->setFocus(Qt::OtherFocusReason);
2947  parent = parent->parentItem();
2948  }
2949 }
2950 
2951 
2967 {
2969  for (int i = children.count()-1; i >= 0; --i) {
2970  if (QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(children.at(i))) {
2971  if (child->isVisible() && child->x() <= x
2972  && child->x() + child->width() >= x
2973  && child->y() <= y
2974  && child->y() + child->height() >= y)
2975  return child;
2976  }
2977  }
2978  return 0;
2979 }
2980 
2982 {
2984 
2985  if (hadActiveFocus != flag) {
2986  hadActiveFocus = flag;
2987  emit q->activeFocusChanged(flag);
2988  }
2989 
2991  for (QDeclarativeItem *p = q->parentItem(); p; p = p->parentItem()) {
2992  if (p->flags() & QGraphicsItem::ItemIsFocusScope) {
2994  break;
2995  if (p->d_func()->hadActiveFocus != flag) {
2996  p->d_func()->hadActiveFocus = flag;
2997  emit p->activeFocusChanged(flag);
2998  }
2999  focusItem = p;
3000  }
3001  }
3002 
3003  // For all but the top most focus scope/item this will be called for us by QGraphicsItem.
3004  focusItem->d_func()->focusScopeItemChange(flag);
3005 }
3006 
3008 {
3013  );
3014 }
3015 
3041 {
3042  return _states()->statesProperty();
3043 }
3044 
3071 {
3072  return _states()->transitionsProperty();
3073 }
3074 
3075 /*
3076  \qmlproperty list<Filter> Item::filter
3077  This property holds a list of graphical filters to be applied to the item.
3078 
3079  \link Filter \endlink{Filters} include things like \link Blur \endlink{blurring}
3080  the item, or giving it a \link Reflection \endlink . Some
3081  filters may not be available on all canvases; if a filter is not
3082  available on a certain canvas, it will simply not be applied for
3083  that canvas (but the QML will still be considered valid).
3084 
3085  \qml
3086  Item {
3087  filter: [
3088  Blur {
3089  // ...
3090  },
3091  Reflection {
3092  // ...
3093  }
3094  // ...
3095  ]
3096  }
3097  \endqml
3098 */
3099 
3156 {
3157  if (!_stateGroup)
3158  return QString();
3159  else
3160  return _stateGroup->state();
3161 }
3162 
3164 {
3165  _states()->setState(state);
3166 }
3167 
3180 {
3182  return QDeclarativeListProperty<QGraphicsTransform>(this, 0, d->transform_append, d->transform_count,
3183  d->transform_at, d->transform_clear);
3184 }
3185 
3195 {
3197  d->componentComplete = false;
3198  if (d->_stateGroup)
3199  d->_stateGroup->classBegin();
3200  if (d->_anchors)
3201  d->_anchors->classBegin();
3202 }
3203 
3213 {
3215  d->componentComplete = true;
3216  if (d->_stateGroup)
3217  d->_stateGroup->componentComplete();
3218  if (d->_anchors) {
3219  d->_anchors->componentComplete();
3220  d->_anchors->d_func()->updateOnComplete();
3221  }
3222  if (d->keyHandler)
3223  d->keyHandler->componentComplete();
3224  if (d->_contents)
3225  d->_contents->complete();
3226 }
3227 
3229 {
3231  if (!_stateGroup) {
3232  _stateGroup = new QDeclarativeStateGroup;
3233  if (!componentComplete)
3234  _stateGroup->classBegin();
3236  q, SIGNAL(stateChanged(QString)));
3237  }
3238 
3239  return _stateGroup;
3240 }
3241 
3243 {
3244  left.item = q;
3245  left.anchorLine = QDeclarativeAnchorLine::Left;
3246  right.item = q;
3247  right.anchorLine = QDeclarativeAnchorLine::Right;
3248  hCenter.item = q;
3249  hCenter.anchorLine = QDeclarativeAnchorLine::HCenter;
3250  top.item = q;
3251  top.anchorLine = QDeclarativeAnchorLine::Top;
3252  bottom.item = q;
3253  bottom.anchorLine = QDeclarativeAnchorLine::Bottom;
3254  vCenter.item = q;
3255  vCenter.anchorLine = QDeclarativeAnchorLine::VCenter;
3256  baseline.item = q;
3257  baseline.anchorLine = QDeclarativeAnchorLine::Baseline;
3258 }
3259 
3261 {
3262  Q_Q(const QDeclarativeItem);
3263 
3264  QRectF br = q->boundingRect();
3265 
3266  switch(origin) {
3267  default:
3269  return QPointF(0, 0);
3270  case QDeclarativeItem::Top:
3271  return QPointF(br.width() / 2., 0);
3273  return QPointF(br.width(), 0);
3275  return QPointF(0, br.height() / 2.);
3277  return QPointF(br.width() / 2., br.height() / 2.);
3279  return QPointF(br.width(), br.height() / 2.);
3281  return QPointF(0, br.height());
3283  return QPointF(br.width() / 2., br.height());
3285  return QPointF(br.width(), br.height());
3286  }
3287 }
3288 
3291 {
3293  if (event->type() == QEvent::KeyPress) {
3294  QKeyEvent *k = static_cast<QKeyEvent *>(event);
3295  if ((k->key() == Qt::Key_Tab || k->key() == Qt::Key_Backtab) &&
3297  keyPressEvent(static_cast<QKeyEvent *>(event));
3298  if (!event->isAccepted())
3299  return QGraphicsItem::sceneEvent(event);
3300  else
3301  return true;
3302  } else {
3303  return QGraphicsItem::sceneEvent(event);
3304  }
3305  } else {
3306  bool rv = QGraphicsItem::sceneEvent(event);
3307 
3308  if (event->type() == QEvent::FocusIn ||
3309  event->type() == QEvent::FocusOut) {
3310  d->focusChanged(hasActiveFocus());
3311  }
3312  return rv;
3313  }
3314 }
3315 
3327  const QVariant &value)
3328 {
3330  switch (change) {
3331  case ItemParentHasChanged:
3332  d->resolveLayoutMirror();
3334  d->parentNotifier.notify();
3335  break;
3336  case ItemVisibleHasChanged: {
3337  for(int ii = 0; ii < d->changeListeners.count(); ++ii) {
3338  const QDeclarativeItemPrivate::ChangeListener &change = d->changeListeners.at(ii);
3340  change.listener->itemVisibilityChanged(this);
3341  }
3342  }
3343  }
3344  break;
3345  case ItemOpacityHasChanged: {
3346  for(int ii = 0; ii < d->changeListeners.count(); ++ii) {
3347  const QDeclarativeItemPrivate::ChangeListener &change = d->changeListeners.at(ii);
3348  if (change.types & QDeclarativeItemPrivate::Opacity) {
3349  change.listener->itemOpacityChanged(this);
3350  }
3351  }
3352  }
3353  break;
3354  case ItemChildAddedChange:
3355  if (d->_contents && d->componentComplete)
3356  d->_contents->childAdded(qobject_cast<QDeclarativeItem*>(
3357  value.value<QGraphicsItem*>()));
3358  break;
3360  if (d->_contents && d->componentComplete)
3361  d->_contents->childRemoved(qobject_cast<QDeclarativeItem*>(
3362  value.value<QGraphicsItem*>()));
3363  break;
3364  default:
3365  break;
3366  }
3367 
3368  return QGraphicsItem::itemChange(change, value);
3369 }
3370 
3373 {
3374  Q_D(const QDeclarativeItem);
3375  return QRectF(0, 0, d->mWidth, d->mHeight);
3376 }
3377 
3401 {
3402  Q_D(const QDeclarativeItem);
3403  return d->origin;
3404 }
3405 
3410 {
3412  if (origin != d->origin) {
3413  d->origin = origin;
3414  if (d->transformData)
3415  QGraphicsItem::setTransformOriginPoint(d->computeTransformOrigin());
3416  else
3417  d->transformOriginDirty = true;
3418  emit transformOriginChanged(d->origin);
3419  }
3420 }
3421 
3423 {
3425  if (transformOriginDirty) {
3426  q->QGraphicsItem::setTransformOriginPoint(computeTransformOrigin());
3427  transformOriginDirty = false;
3428  }
3429 }
3430 
3453 bool QDeclarativeItem::smooth() const
3454 {
3455  Q_D(const QDeclarativeItem);
3456  return d->smooth;
3457 }
3458 
3466 {
3468  if (d->smooth == smooth)
3469  return;
3470  d->smooth = smooth;
3471  emit smoothChanged(smooth);
3472  update();
3473 }
3474 
3570 {
3571  Q_D(const QDeclarativeItem);
3572  return d->width();
3573 }
3574 
3580 {
3582  d->setWidth(w);
3583 }
3584 
3590 {
3592  d->resetWidth();
3593 }
3594 
3600 {
3601  return mWidth;
3602 }
3603 
3608 {
3610  if (qIsNaN(w))
3611  return;
3612 
3613  widthValid = true;
3614  if (mWidth == w)
3615  return;
3616 
3617  qreal oldWidth = mWidth;
3618 
3619  q->prepareGeometryChange();
3620  mWidth = w;
3621 
3622  q->geometryChanged(QRectF(q->x(), q->y(), width(), height()),
3623  QRectF(q->x(), q->y(), oldWidth, height()));
3624 }
3625 
3630 {
3632  widthValid = false;
3633  q->setImplicitWidth(q->implicitWidth());
3634 }
3635 
3637 {
3639  emit q->implicitWidthChanged();
3640 }
3641 
3643 {
3644  return mImplicitWidth;
3645 }
3646 
3651 {
3652  Q_D(const QDeclarativeItem);
3653  return d->implicitWidth();
3654 }
3655 
3661 {
3663  bool changed = w != d->mImplicitWidth;
3664  d->mImplicitWidth = w;
3665  if (d->mWidth == w || widthValid()) {
3666  if (changed)
3667  d->implicitWidthChanged();
3668  return;
3669  }
3670 
3671  qreal oldWidth = d->mWidth;
3672 
3674  d->mWidth = w;
3675 
3676  geometryChanged(QRectF(x(), y(), width(), height()),
3677  QRectF(x(), y(), oldWidth, height()));
3678 
3679  if (changed)
3680  d->implicitWidthChanged();
3681 }
3682 
3687 {
3688  Q_D(const QDeclarativeItem);
3689  return d->widthValid;
3690 }
3691 
3697 {
3698  Q_D(const QDeclarativeItem);
3699  return d->height();
3700 }
3701 
3707 {
3709  d->setHeight(h);
3710 }
3711 
3717 {
3719  d->resetHeight();
3720 }
3721 
3726 {
3727  return mHeight;
3728 }
3729 
3734 {
3736  if (qIsNaN(h))
3737  return;
3738 
3739  heightValid = true;
3740  if (mHeight == h)
3741  return;
3742 
3743  qreal oldHeight = mHeight;
3744 
3745  q->prepareGeometryChange();
3746  mHeight = h;
3747 
3748  q->geometryChanged(QRectF(q->x(), q->y(), width(), height()),
3749  QRectF(q->x(), q->y(), width(), oldHeight));
3750 }
3751 
3756 {
3758  heightValid = false;
3759  q->setImplicitHeight(q->implicitHeight());
3760 }
3761 
3763 {
3765  emit q->implicitHeightChanged();
3766 }
3767 
3769 {
3770  return mImplicitHeight;
3771 }
3772 
3777 {
3778  Q_D(const QDeclarativeItem);
3779  return d->implicitHeight();
3780 }
3781 
3827 {
3829  bool changed = h != d->mImplicitHeight;
3830  d->mImplicitHeight = h;
3831  if (d->mHeight == h || heightValid()) {
3832  if (changed)
3833  d->implicitHeightChanged();
3834  return;
3835  }
3836 
3837  qreal oldHeight = d->mHeight;
3838 
3840  d->mHeight = h;
3841 
3842  geometryChanged(QRectF(x(), y(), width(), height()),
3843  QRectF(x(), y(), width(), oldHeight));
3844 
3845  if (changed)
3846  d->implicitHeightChanged();
3847 }
3848 
3853 {
3854  Q_D(const QDeclarativeItem);
3855  return d->heightValid;
3856 }
3857 
3860 {
3862  d->heightValid = true;
3863  d->widthValid = true;
3864 
3865  if (d->height() == size.height() && d->width() == size.width())
3866  return;
3867 
3868  qreal oldHeight = d->height();
3869  qreal oldWidth = d->width();
3870 
3872  d->setHeight(size.height());
3873  d->setWidth(size.width());
3874 
3875  geometryChanged(QRectF(x(), y(), width(), height()),
3876  QRectF(x(), y(), oldWidth, oldHeight));
3877 }
3878 
3909 {
3910  Q_D(const QDeclarativeItem);
3911  QGraphicsItem *fi = focusItem();
3912  QGraphicsScene *s = scene();
3913  bool hasOrWillGainFocus = fi && fi->isVisible() && (!s || s->focusItem() == fi);
3914  bool isOrIsScopeOfFocusItem = (fi == this || (d->flags & QGraphicsItem::ItemIsFocusScope));
3915  return hasOrWillGainFocus && isOrIsScopeOfFocusItem;
3916 }
3917 
3955 {
3956  Q_D(const QDeclarativeItem);
3957  QGraphicsItem *p = d->parent;
3958  while (p) {
3960  return p->focusScopeItem() == this;
3961  }
3962  p = p->parentItem();
3963  }
3964 
3965  return hasActiveFocus();
3966 }
3967 
3970 {
3971  if (focus)
3973  else
3975 }
3976 
3981 {
3982 }
3983 
3988 {
3990  switch (ev->type()) {
3991  case QEvent::KeyPress:
3992  case QEvent::KeyRelease:
3993  case QEvent::InputMethod:
3994  d->doneEventPreHandler = false;
3995  break;
3996  default:
3997  break;
3998  }
3999 
4000  return QGraphicsObject::event(ev);
4001 }
4002 
4003 #ifndef QT_NO_DEBUG_STREAM
4005 {
4006  if (!item) {
4007  debug << "QDeclarativeItem(0)";
4008  return debug;
4009  }
4010 
4011  debug << item->metaObject()->className() << "(this =" << ((void*)item)
4012  << ", parent =" << ((void*)item->parentItem())
4013  << ", geometry =" << QRectF(item->pos(), QSizeF(item->width(), item->height()))
4014  << ", z =" << item->zValue() << ')';
4015  return debug;
4016 }
4017 #endif
4018 
4021 {
4022  consistentTime = t;
4023 }
4024 
4026 {
4027 public:
4028  void start() {
4030  t2 = 0;
4031  }
4034  }
4038  t2 = 0;
4039  return val;
4040  }
4041 
4042 private:
4045 };
4046 
4048 {
4050  t.start();
4051  else
4052  ((QElapsedTimerConsistentTimeHack*)&t)->start();
4053 }
4054 
4056 {
4058  return t.elapsed();
4059  else
4060  return ((QElapsedTimerConsistentTimeHack*)&t)->elapsed();
4061 }
4062 
4064 {
4066  return t.restart();
4067  else
4068  return ((QElapsedTimerConsistentTimeHack*)&t)->restart();
4069 }
4070 
4072 
4073 #include <moc_qdeclarativeitem.cpp>
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
static int resources_count(QDeclarativeListProperty< QObject > *)
T qobject_cast(QObject *object)
Definition: qobject.h:375
static void data_append(QDeclarativeListProperty< QObject > *, QObject *)
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:62
static QScriptEngine * getScriptEngine(QDeclarativeEngine *e)
double d
Definition: qnumeric_p.h:62
qreal implicitHeight() const
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
void released(QDeclarativeKeyEvent *event)
QPointF transformOriginPoint() const
Returns the origin point for the transformation in item coordinates.
void setParentItemHelper(QGraphicsItem *parent, const QVariant *newParentVariant, const QVariant *thisPointerVariant)
Make sure not to trigger any pure virtual function calls (e.
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
qreal y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:667
bool isNull() const
Returns true if this QScriptValue is of the primitive type Null; otherwise returns false...
QDeclarativeStateGroup * _states()
The QKeyEvent class describes a key event.
Definition: qevent.h:224
virtual bool sceneEvent(QEvent *event)
This virtual function receives events to this item.
QGraphicsItem * focusScopeItem() const
Returns this item&#39;s focus scope item.
virtual ~QDeclarativeItem()
Destroys the QDeclarativeItem.
double qreal
Definition: qglobal.h:1193
qreal implicitWidth() const
void setLeft(QDeclarativeItem *)
QGraphicsItem * focusItem() const
If this item, a child or descendant of this item currently has input focus, this function will return...
unsigned char c[8]
Definition: qnumeric_p.h:62
virtual void implicitHeightChanged()
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
static qint64 elapsed(QElapsedTimer &)
void calcHeight(QDeclarativeItem *changed=0)
EventRef event
QDeclarativeParserStatus ** d
QList< QGraphicsItem * > childItems() const
Returns a list of this item&#39;s children.
QDeclarativeItemKeyFilter * m_next
QScopedPointer< QGraphicsItemPrivate > d_ptr
QDeclarativeListProperty< QObject > resources()
QDeclarativeKeysAttached(QObject *parent=0)
Q_INVOKABLE QScriptValue mapFromItem(const QScriptValue &item, qreal x, qreal y) const
Maps the point (x, y), which is in item&#39;s coordinate system, to this item&#39;s coordinate system...
virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const
bool widthValid() const
Returns whether the width property has been set explicitly.
virtual void keyReleased(QKeyEvent *event, bool post)
void heightChanged()
bool isComponentComplete() const
Returns true if construction of the QML component is complete; otherwise returns false.
qreal width() const
Returns the width.
Definition: qsize.h:284
virtual void keyPressed(QKeyEvent *event, bool post)
virtual bool event(QEvent *)
void clearFocus()
Takes keyboard input focus from the item.
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QDeclarativeItem(QDeclarativeItem *parent=0)
Constructs a QDeclarativeItem with the given parent.
static QGraphicsTransform * transform_at(QDeclarativeListProperty< QGraphicsTransform > *list, int)
void setParentItem(QGraphicsItem *parent)
Sets this item&#39;s parent item to newParent.
QDebug operator<<(QDebug debug, QDeclarativeItem *item)
void setBaselineOffset(qreal)
static QObject * resources_at(QDeclarativeListProperty< QObject > *, int)
QVariant doInputMethodQuery(Qt::InputMethodQuery query) const
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
qreal height() const
Returns the height.
Definition: qsize.h:287
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value)
This virtual function is called by QGraphicsItem to notify custom items that some part of the item&#39;s ...
static void children_clear_helper(QDeclarativeListProperty< QObject > *prop)
QDeclarativeItem * m_item
static QDeclarativeKeysAttached * qmlAttachedProperties(QObject *)
virtual qreal implicitHeight() const
bool isVisible() const
Returns true if the item is visible; otherwise, false is returned.
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QString toString() const
Returns the string value of this QScriptValue, as defined in ECMA-262 section 9.8, "ToString".
void setSmooth(bool)
Sets whether the item should be drawn with antialiasing and smooth pixmap filtering to smooth...
static QObject * data_at(QDeclarativeListProperty< QObject > *, int)
static void transform_append(QDeclarativeListProperty< QGraphicsTransform > *list, QGraphicsTransform *)
bool heightValid() const
Returns whether the height property has been set explicitly.
virtual void implicitWidthChanged()
static const QMetaObject staticMetaObject
This variable stores the meta-object for the class.
Definition: qobject.h:128
QDeclarativeListProperty< QDeclarativeState > states()
virtual void keyPressEvent(QKeyEvent *event)
QDeclarativeAnchorLine right() const
#define Q_ARG(type, data)
Definition: qobjectdefs.h:246
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
void setSize(const QSizeF &size)
virtual void itemOpacityChanged(QDeclarativeItem *)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static QDeclarativeLayoutMirroringAttached * qmlAttachedProperties(QObject *)
QPointF pos() const
Returns the position of the item in parent coordinates.
void childAdded(QDeclarativeItem *item)
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
GraphicsItemChange
This enum describes the state changes that are notified by QGraphicsItem::itemChange().
QDeclarativeAnchorLine baseline() const
static int children_count_helper(QDeclarativeListProperty< QObject > *prop)
QObject * toQObject() const
If this QScriptValue is a QObject, returns the QObject pointer that the QScriptValue represents; othe...
virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const
This method is only relevant for input items.
The QString class provides a Unicode character string.
Definition: qstring.h:83
QDeclarativeItemPrivate * itemPrivate
T * qobject_cast(QObject *object)
Definition: qobject.h:375
QRectF toRectF() const
Returns the variant as a QRectF if the variant has type() Rect or RectF ; otherwise returns an invali...
Definition: qvariant.cpp:2463
void rectChanged(QRectF)
bool isEnabled() const
Returns true if the item is enabled; otherwise, false is returned.
void update(const QRectF &rect=QRectF())
Schedules a redraw of the area covered by rect in this item.
void connect(QObject *source, int sourceSignal)
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition: qobject.cpp:1200
void setFocusNavigation(QDeclarativeItem *currentItem, const char *dir)
#define Q_D(Class)
Definition: qglobal.h:2482
Priority priority() const
The QElapsedTimer class provides a fast way to calculate elapsed times.
Definition: qelapsedtimer.h:53
QDeclarativeAnchorLine left() const
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
virtual void inputMethodEvent(QInputMethodEvent *event, bool post)
virtual void keyPressed(QKeyEvent *event, bool post)
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
qint64 elapsed() const
Returns the number of milliseconds since this QElapsedTimer was last started.
void clipChanged(bool)
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
void setImplicitLayoutMirror(bool mirror, bool inherit)
TransformOrigin transformOrigin() const
QDeclarativeContents(QDeclarativeItem *item)
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
void pressed(QDeclarativeKeyEvent *event)
void setParent(QObject *)
Makes the object a child of parent.
Definition: qobject.cpp:1950
#define Q_Q(Class)
Definition: qglobal.h:2483
qreal zValue() const
Returns the Z-value of the item.
QRectF boundingRect() const
virtual void keyPressed(QKeyEvent *event, bool post)
bool isConnected(const char *signalName)
static void resources_clear(QDeclarativeListProperty< QObject > *)
virtual void componentComplete()=0
Invoked after the root component that caused this instantiation has completed construction.
QGraphicsObject * toGraphicsObject()
Return the graphics item cast to a QGraphicsObject, if the class is actually a graphics object...
void setParentItem(QDeclarativeItem *parent)
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
Definition: qevent.cpp:999
int key() const
Returns the code of the key that was pressed or released.
Definition: qevent.h:231
#define SIGNAL(a)
Definition: qobjectdefs.h:227
The QScriptEngine class provides an environment for evaluating Qt Script code.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QDeclarativeItemPrivate::ChangeTypes types
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
qint64 restart()
Restarts the timer and returns the time elapsed since the previous start.
bool isAccepted() const
Definition: qcoreevent.h:307
QGraphicsItem * focusItem() const
When the scene is active, this functions returns the scene&#39;s current focus item, or 0 if no item curr...
void setRight(QDeclarativeItem *)
static void resources_append(QDeclarativeListProperty< QObject > *, QObject *)
The QDeclarativeItem class provides the most basic of all visual items in QML.
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
void addItemChangeListener(QDeclarativeItemChangeListener *listener, ChangeTypes types)
void setBacktab(QDeclarativeItem *)
void parentChanged()
This signal gets emitted whenever the parent of the item changes.
QDeclarativeItem * backtab() const
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
void transformOriginChanged(TransformOrigin)
void calcWidth(QDeclarativeItem *changed=0)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
QScriptEngine * engine() const
Returns the QScriptEngine that created this QScriptValue, or 0 if this QScriptValue is invalid or the...
bool hasActiveFocus() const
static QDeclarativeItemPrivate * get(QDeclarativeItem *item)
void inputMethodPreHandler(QInputMethodEvent *)
QRectF childrenRect()
void setTransformOrigin(TransformOrigin)
Set the transform origin.
bool clip() const
static void data_clear(QDeclarativeListProperty< QObject > *)
void childRemoved(QDeclarativeItem *item)
static int data_count(QDeclarativeListProperty< QObject > *)
QDeclarativeLayoutMirroringAttached * attachedLayoutDirection
virtual qreal implicitWidth() const
QScriptValue newObject()
Creates a QtScript object of class Object.
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
void itemGeometryChanged(QDeclarativeItem *item, const QRectF &newGeometry, const QRectF &oldGeometry)
virtual void inputMethodEvent(QInputMethodEvent *, bool post)
void clearItem(QGraphicsObject *)
int indexOfSignal(const char *signal) const
Finds signal and returns its index; otherwise returns -1.
static QDeclarativeKeyNavigationAttached * qmlAttachedProperties(QObject *)
__int64 qint64
Definition: qglobal.h:942
qreal baselineOffset() const
GraphicsItemFlags flags() const
Returns this item&#39;s flags.
void keyReleasePreHandler(QKeyEvent *)
void setImplicitWidth(qreal)
Sets the implied width of the item to w.
void smoothChanged(bool)
virtual void itemGeometryChanged(QDeclarativeItem *, const QRectF &, const QRectF &)
QDeclarativeListProperty< QDeclarativeTransition > transitions()
static QObject * children_at_helper(QDeclarativeListProperty< QObject > *prop, int index)
virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
This function is called to handle this item&#39;s changes in geometry from oldGeometry to newGeometry...
Q_CORE_EXPORT bool qIsNaN(double d)
Returns true if the double {d} is not a number (NaN).
Definition: qnumeric.cpp:55
QDeclarativeAnchorLine verticalCenter() const
QDeclarativeItemKeyFilter(QDeclarativeItem *=0)
void setTransformOriginPoint(const QPointF &origin)
Sets the origin point for the transformation in item coordinates.
virtual void focusChanged(bool)
static void parentProperty(QObject *o, void *rv, QDeclarativeNotifierEndpoint *e)
virtual void keyReleaseEvent(QKeyEvent *event)
InputMethodQuery
Definition: qnamespace.h:1541
The QInputMethodEvent class provides parameters for input method events.
Definition: qevent.h:431
void setState(const QString &)
virtual void itemDestroyed(QDeclarativeItem *)
QDeclarativeItem * down() const
void removeItemChangeListener(QDeclarativeItemChangeListener *, ChangeTypes types)
Q_INVOKABLE QScriptValue mapToItem(const QScriptValue &item, qreal x, qreal y) const
Maps the point (x, y), which is in this item&#39;s coordinate system, to item&#39;s coordinate system...
QGraphicsItem * parentItem() const
Returns a pointer to this item&#39;s parent item.
void setProperty(const QString &name, const QScriptValue &value, const PropertyFlags &flags=KeepExistingFlags)
Sets the value of this QScriptValue&#39;s property with the given name to the given value.
TransformOrigin
Controls the point about which simple transforms like scale apply.
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
static void start(QElapsedTimer &)
virtual void keyReleased(QKeyEvent *event, bool post)
qreal y() const
This convenience function is equivalent to calling pos().
virtual void inputMethodEvent(QInputMethodEvent *)
virtual void classBegin()=0
Invoked after class creation, but before any properties have been set.
bool smooth() const
QDeclarativeItem * parentItem() const
Returns the QDeclarativeItem parent of this item.
Q_DECLARATIVE_EXPORT QDeclarativeEngine * qmlEngine(const QObject *)
virtual QVariant itemChange(GraphicsItemChange, const QVariant &)
Note that unlike QGraphicsItems, QDeclarativeItem::itemChange() is not called during initial widget p...
virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const
static const struct @32 types[]
void prepareGeometryChange()
Prepares the item for a geometry change.
static qint64 restart(QElapsedTimer &)
QDeclarativeAnchorLine bottom() const
QDeclarativeLayoutMirroringAttached(QObject *parent=0)
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664
QList< QGraphicsTransform * > graphicsTransforms
static void setConsistentTime(qint64 t)
static int transform_count(QDeclarativeListProperty< QGraphicsTransform > *list)
virtual void itemVisibilityChanged(QDeclarativeItem *)
void prependGraphicsTransform(QGraphicsTransform *t)
QGraphicsItem * focusScopeItem
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
qreal x() const
This convenience function is equivalent to calling pos().
virtual void componentComplete()
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *)
QDeclarativeItem * left() const
const QMetaObject * superdata
Definition: qobjectdefs.h:469
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QDeclarativeItem * tab() const
QDeclarativeItem * up() const
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
struct QMetaObject::@38 d
static RegisterAnchorLineAtStartup registerAnchorLineAtStartup
const QObjectList & children() const
Returns a list of child objects.
Definition: qobject.h:197
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
virtual bool sceneEvent(QEvent *)
Q_INVOKABLE QDeclarativeItem * childAt(qreal x, qreal y) const
Returns the visible child item at point (x, y), which is in this item&#39;s coordinate system...
QPointF computeTransformOrigin() const
static const QGraphicsItemPrivate * get(const QGraphicsItem *item)
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
quint16 index
QVariant property(const char *name) const
Returns the value of the object&#39;s name property.
Definition: qobject.cpp:3807
void setAccepted(bool accepted)
QDeclarativeListProperty< QGraphicsTransform > transform()
bool keepMouseGrab() const
Returns a value indicating whether mouse input should remain with this item exclusively.
virtual void keyReleased(QKeyEvent *event, bool post)
QDeclarativeItemKeyFilter * keyHandler
TransformData * transformData
void setLayoutMirror(bool mirror)
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
QGraphicsScene * scene() const
Returns the current scene for the item, or 0 if the item is not stored in a scene.
void baselineOffsetChanged(qreal)
static const SigMap sigMap[]
This handler is called when a key has been pressed.
static QNSListener * listener
QList< QGraphicsItem * > children
const QByteArray keyToSignal(int key)
QDeclarativeInfo qmlInfo(const QObject *me)
virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const
void setImplicitHeight(qreal)
Sets the implied height of the item to h.
T value() const
Returns the stored value converted to the template type T.
Definition: qvariant.h:332
void setDown(QDeclarativeItem *)
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
bool invoke(QObject *object, Qt::ConnectionType connectionType, QGenericReturnArgument returnValue, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument()) const
Invokes this method on the object object.
The QGraphicsObject class provides a base class for all graphics items that require signals...
void setFlag(GraphicsItemFlag flag, bool enabled=true)
If enabled is true, the item flag flag is enabled; otherwise, it is disabled.
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
static void transform_clear(QDeclarativeListProperty< QGraphicsTransform > *list)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
virtual QDeclarativeAnchorsPrivate * anchorPrivate()
The QStyleOptionGraphicsItem class is used to describe the parameters needed to draw a QGraphicsItem...
Definition: qstyleoption.h:867
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
virtual void classBegin()
Invoked after class creation, but before any properties have been set.
void itemDestroyed(QDeclarativeItem *item)
void start()
Starts this timer.
QDeclarativeListProperty< QObject > data()
Q_INVOKABLE void forceActiveFocus()
Forces active focus on the item.
QDeclarativeAnchorLine top() const
QDeclarativeItemChangeListener * listener
The QGraphicsTransform class is an abstract base class for building advanced transformations on QGrap...
QDeclarativeAnchorLine horizontalCenter() const
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
QDeclarativeItem * right() const
void stateChanged(const QString &)
void setKeepMouseGrab(bool)
The flag indicating whether the mouse should remain with this item is set to keep.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
void keyPressPreHandler(QKeyEvent *)
virtual void classBegin()
void setFocus(Qt::FocusReason focusReason=Qt::OtherFocusReason)
Gives keyboard input focus to this item.