Qt 4.8
qdeclarativepathview.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 "private/qdeclarativepathview_p.h"
43 #include "private/qdeclarativepathview_p_p.h"
44 
45 #include <qdeclarativestate_p.h>
47 #include <QDebug>
48 #include <QEvent>
49 #include <qlistmodelinterface_p.h>
50 #include <QGraphicsSceneEvent>
51 
52 #include <qmath.h>
53 #include <math.h>
54 
56 
57 inline qreal qmlMod(qreal x, qreal y)
58 {
59 #ifdef QT_USE_MATH_H_FLOATS
60  if(sizeof(qreal) == sizeof(float))
61  return fmodf(float(x), float(y));
62  else
63 #endif
64  return fmod(x, y);
65 }
66 
68 
70 : QObject(parent), m_percent(-1), m_view(0), m_onPath(false), m_isCurrent(false)
71 {
72  if (qPathViewAttachedType) {
73  m_metaobject = new QDeclarativeOpenMetaObject(this, qPathViewAttachedType);
74  m_metaobject->setCached(true);
75  } else {
77  }
78 }
79 
81 {
82 }
83 
85 {
86  return m_metaobject->value(name);
87 }
89 {
90  m_metaobject->setValue(name, val);
91 }
92 
93 
95 {
97  offset = 0;
98  q->setAcceptedMouseButtons(Qt::LeftButton);
100  q->setFiltersChildEvents(true);
101  q->connect(&tl, SIGNAL(updated()), q, SLOT(ticked()));
102  lastPosTime.invalidate();
103  static int timelineCompletedIdx = -1;
104  static int movementEndingIdx = -1;
105  if (timelineCompletedIdx == -1) {
106  timelineCompletedIdx = QDeclarativeTimeLine::staticMetaObject.indexOfSignal("completed()");
107  movementEndingIdx = QDeclarativePathView::staticMetaObject.indexOfSlot("movementEnding()");
108  }
109  QMetaObject::connect(&tl, timelineCompletedIdx,
110  q, movementEndingIdx, Qt::DirectConnection);
111 }
112 
114 {
116  requestedIndex = modelIndex;
117  QDeclarativeItem *item = model->item(modelIndex, false);
118  if (item) {
119  if (!attType) {
120  // pre-create one metatype to share with all attached objects
122  foreach(const QString &attr, path->attributes())
123  attType->createProperty(attr.toUtf8());
124  }
125  qPathViewAttachedType = attType;
126  QDeclarativePathViewAttached *att = static_cast<QDeclarativePathViewAttached *>(qmlAttachedPropertiesObject<QDeclarativePathView>(item));
127  qPathViewAttachedType = 0;
128  if (att) {
129  att->m_view = q;
130  att->setOnPath(true);
131  }
132  item->setParentItem(q);
135  }
136  requestedIndex = -1;
137  return item;
138 }
139 
141 {
142  if (!item || !model)
143  return;
146  if (model->release(item) == 0) {
147  // item was not destroyed, and we no longer reference it.
148  if (QDeclarativePathViewAttached *att = attached(item))
149  att->setOnPath(false);
150  }
151 }
152 
154 {
155  return static_cast<QDeclarativePathViewAttached *>(qmlAttachedPropertiesObject<QDeclarativePathView>(item, false));
156 }
157 
159 {
160  for (int i=0; i<items.count(); i++){
161  QDeclarativeItem *p = items[i];
162  releaseItem(p);
163  }
164  items.clear();
165  tl.clear();
166 }
167 
169 {
170  if (model && pathItems != -1 && pathItems < modelCount)
171  mappedRange = qreal(pathItems)/modelCount;
172  else
173  mappedRange = 1.0;
174 }
175 
177 {
178  qreal pos = -1.0;
179 
180  if (model && index >= 0 && index < modelCount) {
181  qreal start = 0.0;
182  if (haveHighlightRange && highlightRangeMode != QDeclarativePathView::NoHighlightRange)
183  start = highlightRangeStart;
184  qreal globalPos = index + offset;
185  globalPos = qmlMod(globalPos, qreal(modelCount)) / modelCount;
186  if (pathItems != -1 && pathItems < modelCount) {
187  globalPos += start * mappedRange;
188  globalPos = qmlMod(globalPos, 1.0);
189  if (globalPos < mappedRange)
190  pos = globalPos / mappedRange;
191  } else {
192  pos = qmlMod(globalPos + start, 1.0);
193  }
194  }
195 
196  return pos;
197 }
198 
200 {
202  if (!q->isComponentComplete())
203  return;
204 
205  bool changed = false;
206  if (highlightItem) {
207  if (highlightItem->scene())
208  highlightItem->scene()->removeItem(highlightItem);
209  highlightItem->deleteLater();
210  highlightItem = 0;
211  changed = true;
212  }
213 
214  QDeclarativeItem *item = 0;
215  if (highlightComponent) {
216  QDeclarativeContext *highlightContext = new QDeclarativeContext(qmlContext(q));
217  QObject *nobj = highlightComponent->create(highlightContext);
218  if (nobj) {
219  QDeclarative_setParent_noEvent(highlightContext, nobj);
220  item = qobject_cast<QDeclarativeItem *>(nobj);
221  if (!item)
222  delete nobj;
223  } else {
224  delete highlightContext;
225  }
226  } else {
227  item = new QDeclarativeItem;
228  }
229  if (item) {
231  item->setParentItem(q);
232  highlightItem = item;
233  changed = true;
234  }
235  if (changed)
236  emit q->highlightItemChanged();
237 }
238 
240 {
242  if (!q->isComponentComplete() || !isValid())
243  return;
244  if (highlightItem) {
245  if (haveHighlightRange && highlightRangeMode == QDeclarativePathView::StrictlyEnforceRange) {
246  updateItem(highlightItem, highlightRangeStart);
247  } else {
248  qreal target = currentIndex;
249 
250  offsetAdj = qreal(0.0);
251  tl.reset(moveHighlight);
252  moveHighlight.setValue(highlightPosition);
253 
254  const int duration = highlightMoveDuration;
255 
256  if (target - highlightPosition > modelCount/2) {
257  highlightUp = false;
258  qreal distance = modelCount - target + highlightPosition;
259  tl.move(moveHighlight, qreal(0.0), QEasingCurve(QEasingCurve::InQuad), int(duration * highlightPosition / distance));
260  tl.set(moveHighlight, modelCount-qreal(0.01));
261  tl.move(moveHighlight, target, QEasingCurve(QEasingCurve::OutQuad), int(duration * (modelCount-target) / distance));
262  } else if (target - highlightPosition <= -modelCount/2) {
263  highlightUp = true;
264  qreal distance = modelCount - highlightPosition + target;
265  tl.move(moveHighlight, modelCount-qreal(0.01), QEasingCurve(QEasingCurve::InQuad), int(duration * (modelCount-highlightPosition) / distance));
266  tl.set(moveHighlight, qreal(0.0));
267  tl.move(moveHighlight, target, QEasingCurve(QEasingCurve::OutQuad), int(duration * target / distance));
268  } else {
269  highlightUp = highlightPosition - target < 0;
270  tl.move(moveHighlight, target, QEasingCurve(QEasingCurve::InOutQuad), duration);
271  }
272  }
273  }
274 }
275 
277 {
278  if (pos != highlightPosition) {
279  qreal start = 0.0;
280  qreal end = 1.0;
281  if (haveHighlightRange && highlightRangeMode != QDeclarativePathView::NoHighlightRange) {
282  start = highlightRangeStart;
283  end = highlightRangeEnd;
284  }
285 
286  qreal range = qreal(modelCount);
287  // calc normalized position of highlight relative to offset
288  qreal relativeHighlight = qmlMod(pos + offset, range) / range;
289 
290  if (!highlightUp && relativeHighlight > end * mappedRange) {
291  qreal diff = qreal(1.0) - relativeHighlight;
292  setOffset(offset + diff * range);
293  } else if (highlightUp && relativeHighlight >= (end - start) * mappedRange) {
294  qreal diff = relativeHighlight - (end - start) * mappedRange;
295  setOffset(offset - diff * range - qreal(0.00001));
296  }
297 
298  highlightPosition = pos;
299  qreal pathPos = positionOfIndex(pos);
300  updateItem(highlightItem, pathPos);
301  if (QDeclarativePathViewAttached *att = attached(highlightItem))
302  att->setOnPath(pathPos != qreal(-1.0));
303  }
304 }
305 
307 {
309  QList<QDeclarativeItem*>::iterator it = d->items.begin();
310  while (it != d->items.end()) {
311  QDeclarativeItem *item = *it;
312  if (QDeclarativePathViewAttached *att = d->attached(item))
313  att->m_percent = -1;
314  ++it;
315  }
316  refill();
317 }
318 
320 {
321  if (QDeclarativePathViewAttached *att = attached(item)) {
322  if (qFuzzyCompare(att->m_percent, percent))
323  return;
324  att->m_percent = percent;
325  foreach(const QString &attr, path->attributes())
326  att->setValue(attr.toUtf8(), path->attributeAt(attr, percent));
327  }
328  QPointF pf = path->pointAt(percent);
329  item->setX(qRound(pf.x() - item->width()/2));
330  item->setY(qRound(pf.y() - item->height()/2));
331 }
332 
334 {
336  if (!q->isComponentComplete())
337  return;
338 
339  clear();
340 
341  if (!isValid())
342  return;
343 
344  firstIndex = -1;
345  updateMappedRange();
346  q->refill();
347 }
348 
419 {
421  d->init();
422 }
423 
425 {
427  d->clear();
428  if (d->attType)
429  d->attType->release();
430  if (d->ownModel)
431  delete d->model;
432 }
433 
497 {
498  Q_D(const QDeclarativePathView);
499  return d->modelVariant;
500 }
501 
503 {
505  if (d->modelVariant == model)
506  return;
507 
508  if (d->model) {
509  disconnect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int)));
510  disconnect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int)));
511  disconnect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int)));
512  disconnect(d->model, SIGNAL(modelReset()), this, SLOT(modelReset()));
514  d->clear();
515  }
516 
517  d->modelVariant = model;
518  QObject *object = qvariant_cast<QObject*>(model);
519  QDeclarativeVisualModel *vim = 0;
520  if (object && (vim = qobject_cast<QDeclarativeVisualModel *>(object))) {
521  if (d->ownModel) {
522  delete d->model;
523  d->ownModel = false;
524  }
525  d->model = vim;
526  } else {
527  if (!d->ownModel) {
528  d->model = new QDeclarativeVisualDataModel(qmlContext(this), this);
529  d->ownModel = true;
530  }
531  if (QDeclarativeVisualDataModel *dataModel = qobject_cast<QDeclarativeVisualDataModel*>(d->model))
532  dataModel->setModel(model);
533  }
534  int oldModelCount = d->modelCount;
535  d->modelCount = 0;
536  if (d->model) {
537  connect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int)));
538  connect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int)));
539  connect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int)));
540  connect(d->model, SIGNAL(modelReset()), this, SLOT(modelReset()));
542  d->modelCount = d->model->count();
543  }
544  if (isComponentComplete()) {
545  if (d->currentIndex != 0) {
546  d->currentIndex = 0;
548  }
549  if (d->offset != 0.0) {
550  d->offset = 0;
552  }
553  }
554  d->regenerate();
555  if (d->modelCount != oldModelCount)
556  emit countChanged();
557  emit modelChanged();
558 }
559 
567 int QDeclarativePathView::count() const
568 {
569  Q_D(const QDeclarativePathView);
570  return d->model ? d->modelCount : 0;
571 }
572 
582 {
583  Q_D(const QDeclarativePathView);
584  return d->path;
585 }
586 
588 {
590  if (d->path == path)
591  return;
592  if (d->path)
593  disconnect(d->path, SIGNAL(changed()), this, SLOT(pathUpdated()));
594  d->path = path;
595  connect(d->path, SIGNAL(changed()), this, SLOT(pathUpdated()));
596  if (d->isValid() && isComponentComplete()) {
597  d->clear();
598  if (d->attType) {
599  d->attType->release();
600  d->attType = 0;
601  }
602  d->regenerate();
603  }
604  emit pathChanged();
605 }
606 
615 {
616  Q_D(const QDeclarativePathView);
617  return d->currentIndex;
618 }
619 
621 {
623  if (!isComponentComplete()) {
624  if (idx != d->currentIndex) {
625  d->currentIndex = idx;
627  }
628  return;
629  }
630 
631  idx = d->modelCount
632  ? ((idx % d->modelCount) + d->modelCount) % d->modelCount
633  : 0;
634  if (d->model && idx != d->currentIndex) {
635  if (d->modelCount) {
636  int itemIndex = (d->currentIndex - d->firstIndex + d->modelCount) % d->modelCount;
637  if (itemIndex < d->items.count()) {
638  if (QDeclarativeItem *item = d->items.at(itemIndex)) {
639  if (QDeclarativePathViewAttached *att = d->attached(item))
640  att->setIsCurrentItem(false);
641  }
642  }
643  }
644  d->currentItem = 0;
646  d->currentIndex = idx;
647  if (d->modelCount) {
648  if (d->haveHighlightRange && d->highlightRangeMode == QDeclarativePathView::StrictlyEnforceRange)
649  d->snapToCurrent();
650  int itemIndex = (idx - d->firstIndex + d->modelCount) % d->modelCount;
651  if (itemIndex < d->items.count()) {
652  d->currentItem = d->items.at(itemIndex);
653  d->currentItem->setFocus(true);
654  if (QDeclarativePathViewAttached *att = d->attached(d->currentItem))
655  att->setIsCurrentItem(true);
656  }
657  d->currentItemOffset = d->positionOfIndex(d->currentIndex);
658  d->updateHighlight();
659  }
661  }
662 }
663 
675 {
677  d->moveDirection = QDeclarativePathViewPrivate::Positive;
679 }
680 
681 
693 {
695  d->moveDirection = QDeclarativePathViewPrivate::Negative;
697 }
698 
709 {
710  Q_D(const QDeclarativePathView);
711  return d->offset;
712 }
713 
715 {
717  d->setOffset(offset);
718  d->updateCurrent();
719 }
720 
722 {
724  if (offset != o) {
725  if (isValid() && q->isComponentComplete()) {
726  offset = qmlMod(o, qreal(modelCount));
727  if (offset < 0)
728  offset += qreal(modelCount);
729  q->refill();
730  } else {
731  offset = o;
732  }
733  emit q->offsetChanged();
734  }
735 }
736 
738 {
739  setOffset(o+offsetAdj);
740 }
741 
770 {
771  Q_D(const QDeclarativePathView);
772  return d->highlightComponent;
773 }
774 
776 {
778  if (highlight != d->highlightComponent) {
779  d->highlightComponent = highlight;
780  d->createHighlight();
781  d->updateHighlight();
783  }
784 }
785 
795 {
796  Q_D(const QDeclarativePathView);
797  return d->highlightItem;
798 }
838 {
839  Q_D(const QDeclarativePathView);
840  return d->highlightRangeStart;
841 }
842 
844 {
846  if (d->highlightRangeStart == start || start < 0 || start > 1.0)
847  return;
848  d->highlightRangeStart = start;
849  d->haveHighlightRange = d->highlightRangeMode != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd;
850  refill();
852 }
853 
855 {
856  Q_D(const QDeclarativePathView);
857  return d->highlightRangeEnd;
858 }
859 
861 {
863  if (d->highlightRangeEnd == end || end < 0 || end > 1.0)
864  return;
865  d->highlightRangeEnd = end;
866  d->haveHighlightRange = d->highlightRangeMode != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd;
867  refill();
869 }
870 
872 {
873  Q_D(const QDeclarativePathView);
874  return d->highlightRangeMode;
875 }
876 
878 {
880  if (d->highlightRangeMode == mode)
881  return;
882  d->highlightRangeMode = mode;
883  d->haveHighlightRange = d->highlightRangeMode != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd;
885 }
886 
887 
901 {
902  Q_D(const QDeclarativePathView);
903  return d->highlightMoveDuration;
904 }
905 
907 {
909  if (d->highlightMoveDuration == duration)
910  return;
911  d->highlightMoveDuration = duration;
913 }
914 
927 {
928  Q_D(const QDeclarativePathView);
929  return d->dragMargin;
930 }
931 
933 {
935  if (d->dragMargin == dragMargin)
936  return;
937  d->dragMargin = dragMargin;
939 }
940 
951 {
952  Q_D(const QDeclarativePathView);
953  return d->deceleration;
954 }
955 
957 {
959  if (d->deceleration == dec)
960  return;
961  d->deceleration = dec;
963 }
964 
977 {
978  Q_D(const QDeclarativePathView);
979  return d->interactive;
980 }
981 
983 {
985  if (interactive != d->interactive) {
986  d->interactive = interactive;
987  if (!interactive)
988  d->tl.clear();
990  }
991 }
992 
1003 {
1004  Q_D(const QDeclarativePathView);
1005  return d->moving;
1006 }
1007 
1018 {
1019  Q_D(const QDeclarativePathView);
1020  return d->flicking;
1021 }
1022 
1088 {
1089  Q_D(const QDeclarativePathView);
1090  if (d->model) {
1091  if (QDeclarativeVisualDataModel *dataModel = qobject_cast<QDeclarativeVisualDataModel*>(d->model))
1092  return dataModel->delegate();
1093  }
1094 
1095  return 0;
1096 }
1097 
1099 {
1101  if (delegate == this->delegate())
1102  return;
1103  if (!d->ownModel) {
1104  d->model = new QDeclarativeVisualDataModel(qmlContext(this));
1105  d->ownModel = true;
1106  }
1107  if (QDeclarativeVisualDataModel *dataModel = qobject_cast<QDeclarativeVisualDataModel*>(d->model)) {
1108  int oldCount = dataModel->count();
1109  dataModel->setDelegate(delegate);
1110  d->modelCount = dataModel->count();
1111  d->regenerate();
1112  if (oldCount != dataModel->count())
1113  emit countChanged();
1115  }
1116 }
1117 
1126 {
1127  Q_D(const QDeclarativePathView);
1128  return d->pathItems;
1129 }
1130 
1132 {
1134  if (i == d->pathItems)
1135  return;
1136  if (i < 1)
1137  i = 1;
1138  d->pathItems = i;
1139  d->updateMappedRange();
1140  if (d->isValid() && isComponentComplete()) {
1141  d->regenerate();
1142  }
1144 }
1145 
1147 {
1148  //XXX maybe do recursively at increasing resolution.
1149  qreal mindist = 1e10; // big number
1150  QPointF nearPoint = path->pointAt(0);
1151  qreal nearPc = 0;
1152  for (qreal i=1; i < 1000; i++) {
1153  QPointF pt = path->pointAt(i/1000.0);
1154  QPointF diff = pt - point;
1155  qreal dist = diff.x()*diff.x() + diff.y()*diff.y();
1156  if (dist < mindist) {
1157  nearPoint = pt;
1158  nearPc = i;
1159  mindist = dist;
1160  }
1161  }
1162 
1163  if (nearPercent)
1164  *nearPercent = nearPc / 1000.0;
1165 
1166  return nearPoint;
1167 }
1168 
1170 {
1172  if (d->interactive) {
1173  d->handleMousePressEvent(event);
1174  event->accept();
1175  } else {
1177  }
1178 }
1179 
1181 {
1183  if (!interactive || !items.count())
1184  return;
1185  QPointF scenePoint = q->mapToScene(event->pos());
1186  int idx = 0;
1187  for (; idx < items.count(); ++idx) {
1188  QRectF rect = items.at(idx)->boundingRect();
1189  rect = items.at(idx)->mapToScene(rect).boundingRect();
1190  if (rect.contains(scenePoint))
1191  break;
1192  }
1193  if (idx == items.count() && dragMargin == 0.) // didn't click on an item
1194  return;
1195 
1196  startPoint = pointNear(event->pos(), &startPc);
1197  if (idx == items.count()) {
1198  qreal distance = qAbs(event->pos().x() - startPoint.x()) + qAbs(event->pos().y() - startPoint.y());
1199  if (distance > dragMargin)
1200  return;
1201  }
1202 
1203  if (tl.isActive() && flicking)
1204  stealMouse = true; // If we've been flicked then steal the click.
1205  else
1206  stealMouse = false;
1207 
1208  lastElapsed = 0;
1209  lastDist = 0;
1210  QDeclarativeItemPrivate::start(lastPosTime);
1211  tl.clear();
1212 }
1213 
1215 {
1217  if (d->interactive) {
1218  d->handleMouseMoveEvent(event);
1219  if (d->stealMouse)
1220  setKeepMouseGrab(true);
1221  event->accept();
1222  } else {
1224  }
1225 }
1226 
1228 {
1230  if (!interactive || !lastPosTime.isValid())
1231  return;
1232 
1233  qreal newPc;
1234  QPointF pathPoint = pointNear(event->pos(), &newPc);
1235  if (!stealMouse) {
1236  QPointF delta = pathPoint - startPoint;
1237  if (qAbs(delta.x()) > QApplication::startDragDistance() || qAbs(delta.y()) > QApplication::startDragDistance()) {
1238  stealMouse = true;
1239  startPc = newPc;
1240  }
1241  }
1242 
1243  if (stealMouse) {
1245  qreal diff = (newPc - startPc)*modelCount*mappedRange;
1246  if (diff) {
1247  q->setOffset(offset + diff);
1248 
1249  if (diff > modelCount/2)
1250  diff -= modelCount;
1251  else if (diff < -modelCount/2)
1252  diff += modelCount;
1253 
1254  lastElapsed = QDeclarativeItemPrivate::restart(lastPosTime);
1255  lastDist = diff;
1256  startPc = newPc;
1257  }
1258  if (!moving) {
1259  moving = true;
1260  emit q->movingChanged();
1261  emit q->movementStarted();
1262  }
1263  }
1264 }
1265 
1267 {
1269  if (d->interactive) {
1270  d->handleMouseReleaseEvent(event);
1271  event->accept();
1272  ungrabMouse();
1273  } else {
1275  }
1276 }
1277 
1279 {
1281  stealMouse = false;
1282  q->setKeepMouseGrab(false);
1283  if (!interactive || !lastPosTime.isValid())
1284  return;
1285 
1286  qreal elapsed = qreal(lastElapsed + QDeclarativeItemPrivate::elapsed(lastPosTime)) / 1000.;
1287  qreal velocity = elapsed > 0. ? lastDist / elapsed : 0;
1288  if (model && modelCount && qAbs(velocity) > qreal(1.)) {
1289  qreal count = pathItems == -1 ? modelCount : pathItems;
1290  if (qAbs(velocity) > count * 2) // limit velocity
1291  velocity = (velocity > 0 ? count : -count) * 2;
1292  // Calculate the distance to be travelled
1293  qreal v2 = velocity*velocity;
1294  qreal accel = deceleration/10;
1295  // + 0.25 to encourage moving at least one item in the flick direction
1296  qreal dist = qMin(qreal(modelCount-1), qreal(v2 / (accel * qreal(2.0)) + qreal(0.25)));
1297  if (haveHighlightRange && highlightRangeMode == QDeclarativePathView::StrictlyEnforceRange) {
1298  // round to nearest item.
1299  if (velocity > 0.)
1300  dist = qRound(dist + offset) - offset;
1301  else
1302  dist = qRound(dist - offset) + offset;
1303  // Calculate accel required to stop on item boundary
1304  if (dist <= 0.) {
1305  dist = qreal(0.);
1306  accel = qreal(0.);
1307  } else {
1308  accel = v2 / (2.0f * qAbs(dist));
1309  }
1310  }
1311  offsetAdj = qreal(0.0);
1312  moveOffset.setValue(offset);
1313  tl.accel(moveOffset, velocity, accel, dist);
1314  tl.callback(QDeclarativeTimeLineCallback(&moveOffset, fixOffsetCallback, this));
1315  if (!flicking) {
1316  flicking = true;
1317  emit q->flickingChanged();
1318  emit q->flickStarted();
1319  }
1320  } else {
1321  fixOffset();
1322  }
1323 
1324  lastPosTime.invalidate();
1325  if (!tl.isActive())
1326  q->movementEnding();
1327 }
1328 
1330 {
1333  QRectF myRect = mapToScene(QRectF(0, 0, width(), height())).boundingRect();
1334  QGraphicsScene *s = scene();
1336  bool stealThisEvent = d->stealMouse;
1337  if ((stealThisEvent || myRect.contains(event->scenePos().toPoint())) && (!grabber || !grabber->keepMouseGrab())) {
1338  mouseEvent.setAccepted(false);
1339  for (int i = 0x1; i <= 0x10; i <<= 1) {
1340  if (event->buttons() & i) {
1341  Qt::MouseButton button = Qt::MouseButton(i);
1342  mouseEvent.setButtonDownPos(button, mapFromScene(event->buttonDownPos(button)));
1343  }
1344  }
1345  mouseEvent.setScenePos(event->scenePos());
1346  mouseEvent.setLastScenePos(event->lastScenePos());
1347  mouseEvent.setPos(mapFromScene(event->scenePos()));
1348  mouseEvent.setLastPos(mapFromScene(event->lastScenePos()));
1349 
1350  switch(mouseEvent.type()) {
1352  d->handleMouseMoveEvent(&mouseEvent);
1353  break;
1355  d->handleMousePressEvent(&mouseEvent);
1356  stealThisEvent = d->stealMouse; // Update stealThisEvent in case changed by function call above
1357  break;
1359  d->handleMouseReleaseEvent(&mouseEvent);
1360  break;
1361  default:
1362  break;
1363  }
1365  if (grabber && stealThisEvent && !grabber->keepMouseGrab() && grabber != this)
1366  grabMouse();
1367 
1368  return d->stealMouse;
1369  } else if (d->lastPosTime.isValid()) {
1370  d->lastPosTime.invalidate();
1371  }
1373  d->stealMouse = false;
1374  return false;
1375 }
1376 
1378 {
1380  if (!isVisible() || !d->interactive)
1382 
1383  switch (e->type()) {
1387  return sendMouseEvent(static_cast<QGraphicsSceneMouseEvent *>(e));
1388  default:
1389  break;
1390  }
1391 
1393 }
1394 
1396 {
1397  if (event->type() == QEvent::User) {
1398  refill();
1399  return true;
1400  }
1401 
1402  return QDeclarativeItem::event(event);
1403 }
1404 
1406 {
1409 
1410  if (d->model) {
1411  d->modelCount = d->model->count();
1412  if (d->modelCount && d->currentIndex != 0) // an initial value has been provided for currentIndex
1413  d->offset = qmlMod(d->modelCount - d->currentIndex, d->modelCount);
1414  }
1415 
1416  d->createHighlight();
1417  d->regenerate();
1418  d->updateHighlight();
1419  d->updateCurrent();
1420 
1421  if (d->modelCount)
1422  emit countChanged();
1423 }
1424 
1426 {
1428  if (!d->isValid() || !isComponentComplete())
1429  return;
1430 
1431  d->layoutScheduled = false;
1432  bool currentVisible = false;
1433 
1434  // first move existing items and remove items off path
1435  int idx = d->firstIndex;
1436  QList<QDeclarativeItem*>::iterator it = d->items.begin();
1437  while (it != d->items.end()) {
1438  qreal pos = d->positionOfIndex(idx);
1439  QDeclarativeItem *item = *it;
1440  if (pos >= 0.0) {
1441  d->updateItem(item, pos);
1442  if (idx == d->currentIndex) {
1443  currentVisible = true;
1444  d->currentItemOffset = pos;
1445  }
1446  ++it;
1447  } else {
1448 // qDebug() << "release";
1449  d->updateItem(item, 1.0);
1450  d->releaseItem(item);
1451  if (it == d->items.begin()) {
1452  if (++d->firstIndex >= d->modelCount)
1453  d->firstIndex = 0;
1454  }
1455  it = d->items.erase(it);
1456  }
1457  ++idx;
1458  if (idx >= d->modelCount)
1459  idx = 0;
1460  }
1461  if (!d->items.count())
1462  d->firstIndex = -1;
1463 
1464  if (d->modelCount) {
1465  // add items to beginning and end
1466  int count = d->pathItems == -1 ? d->modelCount : qMin(d->pathItems, d->modelCount);
1467  if (d->items.count() < count) {
1468  int idx = qRound(d->modelCount - d->offset) % d->modelCount;
1469  qreal startPos = 0.0;
1470  if (d->haveHighlightRange && d->highlightRangeMode != QDeclarativePathView::NoHighlightRange)
1471  startPos = d->highlightRangeStart;
1472  if (d->firstIndex >= 0) {
1473  startPos = d->positionOfIndex(d->firstIndex);
1474  idx = (d->firstIndex + d->items.count()) % d->modelCount;
1475  }
1476  qreal pos = d->positionOfIndex(idx);
1477  while ((pos > startPos || !d->items.count()) && d->items.count() < count) {
1478  // qDebug() << "append" << idx;
1479  QDeclarativeItem *item = d->getItem(idx);
1480  if (d->model->completePending())
1481  item->setZValue(idx+1);
1482  if (d->currentIndex == idx) {
1483  item->setFocus(true);
1484  if (QDeclarativePathViewAttached *att = d->attached(item))
1485  att->setIsCurrentItem(true);
1486  currentVisible = true;
1487  d->currentItemOffset = pos;
1488  d->currentItem = item;
1489  }
1490  if (d->items.count() == 0)
1491  d->firstIndex = idx;
1492  d->items.append(item);
1493  d->updateItem(item, pos);
1494  if (d->model->completePending())
1495  d->model->completeItem();
1496  ++idx;
1497  if (idx >= d->modelCount)
1498  idx = 0;
1499  pos = d->positionOfIndex(idx);
1500  }
1501 
1502  idx = d->firstIndex - 1;
1503  if (idx < 0)
1504  idx = d->modelCount - 1;
1505  pos = d->positionOfIndex(idx);
1506  while (pos >= 0.0 && pos < startPos) {
1507  // qDebug() << "prepend" << idx;
1508  QDeclarativeItem *item = d->getItem(idx);
1509  if (d->model->completePending())
1510  item->setZValue(idx+1);
1511  if (d->currentIndex == idx) {
1512  item->setFocus(true);
1513  if (QDeclarativePathViewAttached *att = d->attached(item))
1514  att->setIsCurrentItem(true);
1515  currentVisible = true;
1516  d->currentItemOffset = pos;
1517  d->currentItem = item;
1518  }
1519  d->items.prepend(item);
1520  d->updateItem(item, pos);
1521  if (d->model->completePending())
1522  d->model->completeItem();
1523  d->firstIndex = idx;
1524  idx = d->firstIndex - 1;
1525  if (idx < 0)
1526  idx = d->modelCount - 1;
1527  pos = d->positionOfIndex(idx);
1528  }
1529  }
1530  }
1531 
1532  if (!currentVisible)
1533  d->currentItemOffset = 1.0;
1534 
1535  if (d->highlightItem && d->haveHighlightRange && d->highlightRangeMode == QDeclarativePathView::StrictlyEnforceRange) {
1536  d->updateItem(d->highlightItem, d->highlightRangeStart);
1537  if (QDeclarativePathViewAttached *att = d->attached(d->highlightItem))
1538  att->setOnPath(true);
1539  } else if (d->highlightItem && d->moveReason != QDeclarativePathViewPrivate::SetIndex) {
1540  d->updateItem(d->highlightItem, d->currentItemOffset);
1541  if (QDeclarativePathViewAttached *att = d->attached(d->highlightItem))
1542  att->setOnPath(currentVisible);
1543  }
1544  while (d->itemCache.count())
1545  d->releaseItem(d->itemCache.takeLast());
1546 }
1547 
1549 {
1550  //XXX support animated insertion
1552  if (!d->isValid() || !isComponentComplete())
1553  return;
1554 
1555  if (d->modelCount) {
1556  d->itemCache += d->items;
1557  d->items.clear();
1558  if (modelIndex <= d->currentIndex) {
1559  d->currentIndex += count;
1561  } else if (d->offset != 0) {
1562  d->offset += count;
1563  d->offsetAdj += count;
1564  }
1565  }
1566  d->modelCount += count;
1567  if (d->flicking || d->moving) {
1568  d->regenerate();
1569  d->updateCurrent();
1570  } else {
1571  d->firstIndex = -1;
1572  d->updateMappedRange();
1573  d->scheduleLayout();
1574  }
1575  emit countChanged();
1576 }
1577 
1579 {
1580  //XXX support animated removal
1582  if (!d->model || !d->modelCount || !d->model->isValid() || !d->path || !isComponentComplete())
1583  return;
1584 
1585  // fix current
1586  bool currentChanged = false;
1587  if (d->currentIndex >= modelIndex + count) {
1588  d->currentIndex -= count;
1589  currentChanged = true;
1590  } else if (d->currentIndex >= modelIndex && d->currentIndex < modelIndex + count) {
1591  // current item has been removed.
1592  d->currentIndex = qMin(modelIndex, d->modelCount-count-1);
1593  if (d->currentItem) {
1594  if (QDeclarativePathViewAttached *att = d->attached(d->currentItem))
1595  att->setIsCurrentItem(true);
1596  }
1597  currentChanged = true;
1598  }
1599 
1600  d->itemCache += d->items;
1601  d->items.clear();
1602 
1603  bool changedOffset = false;
1604  if (modelIndex > d->currentIndex) {
1605  if (d->offset >= count) {
1606  changedOffset = true;
1607  d->offset -= count;
1608  d->offsetAdj -= count;
1609  }
1610  }
1611 
1612  d->modelCount -= count;
1613 
1614  if (d->currentIndex == -1)
1615  d->currentIndex = d->calcCurrentIndex();
1616 
1617  if (!d->modelCount) {
1618  while (d->itemCache.count())
1619  d->releaseItem(d->itemCache.takeLast());
1620  d->offset = 0;
1621  changedOffset = true;
1622  d->tl.reset(d->moveOffset);
1623  update();
1624  } else {
1625  d->regenerate();
1626  d->updateCurrent();
1627  if (!d->flicking && !d->moving && d->haveHighlightRange && d->highlightRangeMode == QDeclarativePathView::StrictlyEnforceRange)
1628  d->snapToCurrent();
1629  }
1630  if (changedOffset)
1631  emit offsetChanged();
1632  if (currentChanged)
1634  emit countChanged();
1635 }
1636 
1637 void QDeclarativePathView::itemsMoved(int /*from*/, int /*to*/, int /*count*/)
1638 {
1640  if (!d->isValid() || !isComponentComplete())
1641  return;
1642 
1643  int oldCurrent = d->currentIndex;
1644  // Fix current index
1645  if (d->currentIndex >= 0 && d->currentItem)
1646  d->currentIndex = d->model->indexOf(d->currentItem, this);
1647 
1648  QList<QDeclarativeItem *> removedItems = d->items;
1649  d->items.clear();
1650  d->regenerate();
1651  while (removedItems.count())
1652  d->releaseItem(removedItems.takeLast());
1653 
1654  if (oldCurrent != d->currentIndex)
1656  d->updateCurrent();
1657 }
1658 
1660 {
1662  d->modelCount = d->model->count();
1663  d->regenerate();
1664  emit countChanged();
1665 }
1666 
1668 {
1670  if (d->requestedIndex != index) {
1671  if (!d->attType) {
1672  // pre-create one metatype to share with all attached objects
1674  foreach(const QString &attr, d->path->attributes())
1675  d->attType->createProperty(attr.toUtf8());
1676  }
1677  qPathViewAttachedType = d->attType;
1678  QDeclarativePathViewAttached *att = static_cast<QDeclarativePathViewAttached *>(qmlAttachedPropertiesObject<QDeclarativePathView>(item));
1679  qPathViewAttachedType = 0;
1680  if (att) {
1681  att->m_view = this;
1682  att->setOnPath(false);
1683  }
1684  item->setParentItem(this);
1685  d->updateItem(item, index < d->firstIndex ? qreal(0.0) : qreal(1.0));
1686  }
1687 }
1688 
1690 {
1691  Q_UNUSED(item);
1692 }
1693 
1695 {
1697  d->updateCurrent();
1698 }
1699 
1701 {
1703  if (d->flicking) {
1704  d->flicking = false;
1706  emit flickEnded();
1707  }
1708  if (d->moving && !d->stealMouse) {
1709  d->moving = false;
1710  emit movingChanged();
1711  emit movementEnded();
1712  }
1713 }
1714 
1715 // find the item closest to the snap position
1717 {
1718  int current = 0;
1719  if (modelCount && model && items.count()) {
1720  offset = qmlMod(offset, modelCount);
1721  if (offset < 0)
1722  offset += modelCount;
1723  current = qRound(qAbs(qmlMod(modelCount - offset, modelCount)));
1724  current = current % modelCount;
1725  }
1726 
1727  return current;
1728 }
1729 
1731 {
1733  if (moveReason != Mouse)
1734  return;
1735  if (!modelCount || !haveHighlightRange || highlightRangeMode != QDeclarativePathView::StrictlyEnforceRange)
1736  return;
1737 
1738  int idx = calcCurrentIndex();
1739  if (model && (idx != currentIndex || !currentItem)) {
1740  int itemIndex = (currentIndex - firstIndex + modelCount) % modelCount;
1741  if (itemIndex < items.count()) {
1742  if (QDeclarativeItem *item = items.at(itemIndex)) {
1743  if (QDeclarativePathViewAttached *att = attached(item))
1744  att->setIsCurrentItem(false);
1745  }
1746  }
1747  int oldCurrentIndex = currentIndex;
1748  currentIndex = idx;
1749  currentItem = 0;
1750  itemIndex = (idx - firstIndex + modelCount) % modelCount;
1751  if (itemIndex < items.count()) {
1752  currentItem = items.at(itemIndex);
1753  currentItem->setFocus(true);
1754  if (QDeclarativePathViewAttached *att = attached(currentItem))
1755  att->setIsCurrentItem(true);
1756  }
1757  if (oldCurrentIndex != currentIndex)
1758  emit q->currentIndexChanged();
1759  }
1760 }
1761 
1763 {
1764  ((QDeclarativePathViewPrivate *)d)->fixOffset();
1765 }
1766 
1768 {
1770  if (model && items.count()) {
1771  if (haveHighlightRange && highlightRangeMode == QDeclarativePathView::StrictlyEnforceRange) {
1772  int curr = calcCurrentIndex();
1773  if (curr != currentIndex)
1774  q->setCurrentIndex(curr);
1775  else
1776  snapToCurrent();
1777  }
1778  }
1779 }
1780 
1782 {
1783  if (!model || modelCount <= 0)
1784  return;
1785 
1786  qreal targetOffset = qmlMod(modelCount - currentIndex, modelCount);
1787 
1788  moveReason = Other;
1789  offsetAdj = 0.0;
1790  tl.reset(moveOffset);
1791  moveOffset.setValue(offset);
1792 
1793  const int duration = highlightMoveDuration;
1794 
1795  if (moveDirection == Positive || (moveDirection == Shortest && targetOffset - offset > modelCount/2)) {
1796  qreal distance = modelCount - targetOffset + offset;
1797  if (targetOffset > moveOffset) {
1798  tl.move(moveOffset, 0.0, QEasingCurve(QEasingCurve::InQuad), int(duration * offset / distance));
1799  tl.set(moveOffset, modelCount);
1800  tl.move(moveOffset, targetOffset, QEasingCurve(offset == 0.0 ? QEasingCurve::InOutQuad : QEasingCurve::OutQuad), int(duration * (modelCount-targetOffset) / distance));
1801  } else {
1802  tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::InOutQuad), duration);
1803  }
1804  } else if (moveDirection == Negative || targetOffset - offset <= -modelCount/2) {
1805  qreal distance = modelCount - offset + targetOffset;
1806  if (targetOffset < moveOffset) {
1807  tl.move(moveOffset, modelCount, QEasingCurve(targetOffset == 0 ? QEasingCurve::InOutQuad : QEasingCurve::InQuad), int(duration * (modelCount-offset) / distance));
1808  tl.set(moveOffset, 0.0);
1809  tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::OutQuad), int(duration * targetOffset / distance));
1810  } else {
1811  tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::InOutQuad), duration);
1812  }
1813  } else {
1814  tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::InOutQuad), duration);
1815  }
1816  moveDirection = Shortest;
1817 }
1818 
1820 {
1821  return new QDeclarativePathViewAttached(obj);
1822 }
1823 
1825 
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
double d
Definition: qnumeric_p.h:62
void handleMouseMoveEvent(QGraphicsSceneMouseEvent *event)
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
friend class QDeclarativePathViewAttached
void setHighlightRangeMode(HighlightRangeMode mode)
double qreal
Definition: qglobal.h:1193
static bool connect(const QObject *sender, int signal_index, const QObject *receiver, int method_index, int type=0, int *types=0)
Definition: qobject.cpp:3194
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
static double elapsed(qint64 after, qint64 before)
void preferredHighlightBeginChanged()
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
static qint64 elapsed(QElapsedTimer &)
qreal flickDeceleration() const
void setValue(const QByteArray &, const QVariant &)
QDeclarativeParserStatus ** d
The QEasingCurve class provides easing curves for controlling animation.
Definition: qeasingcurve.h:55
qreal dragMargin() const
#define it(className, varName)
bool sceneEventFilter(QGraphicsItem *, QEvent *)
Filters events for the item watched.
void setHighlight(QDeclarativeComponent *highlight)
bool isComponentComplete() const
Returns true if construction of the QML component is complete; otherwise returns false.
QVariant value(const QByteArray &name) const
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
QDeclarativePathView(QDeclarativeItem *parent=0)
virtual bool event(QEvent *)
static QDeclarativePathViewAttached * qmlAttachedProperties(QObject *)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define SLOT(a)
Definition: qobjectdefs.h:226
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
The QGraphicsSceneMouseEvent class provides mouse events in the graphics view framework.
bool isVisible() const
Returns true if the item is visible; otherwise, false is returned.
static void clear(QVariant::Private *d)
Definition: qvariant.cpp:197
void itemsRemoved(int index, int count)
static const QMetaObject staticMetaObject
This variable stores the meta-object for the class.
Definition: qobject.h:128
void updateItem(QDeclarativeItem *, qreal)
bool sendMouseEvent(QGraphicsSceneMouseEvent *event)
static Q_DECL_CONSTEXPR bool qFuzzyCompare(double p1, double p2)
Definition: qglobal.h:2030
void flickDecelerationChanged()
QPointF pos() const
Returns the position of the item in parent coordinates.
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
void preferredHighlightEndChanged()
QDeclarativePath * path() const
The QString class provides a Unicode character string.
Definition: qstring.h:83
T * qobject_cast(QObject *object)
Definition: qobject.h:375
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse press events for this item...
QGraphicsItem * mouseGrabberItem() const
Returns the current mouse grabber item, or 0 if no item is currently grabbing the mouse...
void update(const QRectF &rect=QRectF())
Schedules a redraw of the area covered by rect in this item.
void releaseItem(QDeclarativeItem *item)
QPointF pointAt(qreal) const
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
Q_DECLARATIVE_EXPORT QDeclarativeContext * qmlContext(const QObject *)
qreal preferredHighlightEnd() const
#define Q_D(Class)
Definition: qglobal.h:2482
void handleMouseReleaseEvent(QGraphicsSceneMouseEvent *)
Q_CORE_EXPORT QTextStream & dec(QTextStream &s)
void mouseReleaseEvent(QGraphicsSceneMouseEvent *)
This event handler, for event event, can be reimplemented to receive mouse release events for this it...
qreal preferredHighlightBegin() const
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
#define Q_Q(Class)
Definition: qglobal.h:2483
HighlightRangeMode highlightRangeMode() const
void highlightMoveDurationChanged()
void setModel(const QVariant &)
QVariant value(const QByteArray &) const
void setParentItem(QDeclarativeItem *parent)
bool contains(const QPointF &p) const
Returns true if the given point is inside or on the edge of the rectangle; otherwise returns false...
Definition: qrect.cpp:2349
#define SIGNAL(a)
Definition: qobjectdefs.h:227
int currentIndex() const
QPointF pointNear(const QPointF &point, qreal *nearPercent=0) const
QDeclarativeOpenMetaObject * m_metaobject
QPointF lastScenePos() const
Returns the last recorded mouse cursor position in scene coordinates.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void setZValue(qreal z)
Sets the Z-value of the item to z.
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void destroyingItem(QDeclarativeItem *item)
The QDeclarativeComponent class encapsulates a QML component definition.
void setPath(QDeclarativePath *)
The QDeclarativeItem class provides the most basic of all visual items in QML.
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse move events for this item...
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)
const char * name
QDeclarativeComponent * delegate() const
#define emit
Definition: qobjectdefs.h:76
static QDeclarativeOpenMetaObjectType * qPathViewAttachedType
static Bigint * diff(Bigint *a, Bigint *b)
void setDragMargin(qreal margin)
static int distance(QWidget *source, QWidget *target, QAccessible::RelationFlag relation)
int indexOfSlot(const char *slot) const
Finds slot and returns its index; otherwise returns -1.
int indexOfSignal(const char *signal) const
Finds signal and returns its index; otherwise returns -1.
void setValue(const QByteArray &name, const QVariant &val)
static int startDragDistance()
void setX(qreal x)
Set&#39;s the x coordinate of the item&#39;s position.
void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse move events for this item...
void highlightRangeModeChanged()
int highlightMoveDuration() const
QPointF mapFromScene(const QPointF &point) const
Maps the point point, which is in this item&#39;s scene&#39;s coordinate system, to this item&#39;s coordinate sy...
The QList::iterator class provides an STL-style non-const iterator for QList and QQueue.
Definition: qlist.h:181
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
void removeItemChangeListener(QDeclarativeItemChangeListener *, ChangeTypes types)
void itemsMoved(int, int, int)
static void start(QElapsedTimer &)
qreal offset() const
QVariant model() const
Q_DECLARATIVE_EXPORT QDeclarativeEngine * qmlEngine(const QObject *)
void setFlickDeceleration(qreal dec)
QPointF scenePos() const
Returns the mouse cursor position in scene coordinates.
void mousePressEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse press events for this item...
static qint64 restart(QElapsedTimer &)
QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
Definition: qpoint.h:376
void QDeclarative_setParent_noEvent(QObject *object, QObject *parent)
Makes the object a child of parent.
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
void setY(qreal y)
Set&#39;s the y coordinate of the item&#39;s position.
virtual void componentComplete()
if(void) toggleToolbarShown
QDeclarativePathViewAttached * attached(QDeclarativeItem *item)
void itemsInserted(int index, int count)
void handleMousePressEvent(QGraphicsSceneMouseEvent *event)
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
static void mouseEvent(MouseAction action, QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey, QPoint pos, int delay=-1)
Definition: qtestmouse.h:71
The QDeclarativeContext class defines a context within a QML engine.
static const QGraphicsItemPrivate * get(const QGraphicsItem *item)
QDeclarativeItem * getItem(int modelIndex)
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
quint16 index
bool keepMouseGrab() const
Returns a value indicating whether mouse input should remain with this item exclusively.
QPointF pos() const
Returns the mouse cursor position in item coordinates.
QPointF buttonDownPos(Qt::MouseButton button) const
Returns the mouse cursor position in item coordinates where the specified button was clicked...
T takeLast()
Removes the last item in the list and returns it.
Definition: qlist.h:492
QDeclarativeItem * highlightItem()
QGraphicsScene * scene() const
Returns the current scene for the item, or 0 if the item is not stored in a scene.
QDeclarativeComponent * highlight() const
void ungrabMouse()
Releases the mouse grab.
void setOffset(qreal offset)
void createdItem(int index, QDeclarativeItem *item)
static const KeyPair *const end
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
virtual bool sceneEventFilter(QGraphicsItem *watched, QEvent *event)
Filters events for the item watched.
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
int pathItemCount() const
QPointF mapToScene(const QPointF &point) const
Maps the point point, which is in this item&#39;s coordinate system, to the scene&#39;s coordinate system...
#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
qreal qmlMod(qreal x, qreal y)
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse release events for this it...
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
qreal positionOfIndex(qreal index) const
void grabMouse()
Grabs the mouse input.
Qt::MouseButtons buttons() const
Returns the combination of mouse buttons that were pressed at the time the event was sent...
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
QDeclarativePathViewAttached(QObject *parent)
void setDelegate(QDeclarativeComponent *)
MouseButton
Definition: qnamespace.h:150