/*! Destroys the QGraphicsWidget instance. */ QGraphicsWidget::~QGraphicsWidget() { Q_D(QGraphicsWidget); #ifndef QT_NO_ACTION // Remove all actions from this widget for (int i = 0; i < d->actions.size(); ++i) { QActionPrivate *apriv = d->actions.at(i)->d_func(); apriv->graphicsWidgets.removeAll(this); } d->actions.clear(); #endif if (QGraphicsScene *scn = scene()) { QGraphicsScenePrivate *sceneD = scn->d_func(); if (sceneD->tabFocusFirst == this) sceneD->tabFocusFirst = (d->focusNext == this ? 0 : d->focusNext); } d->focusPrev->d_func()->focusNext = d->focusNext; d->focusNext->d_func()->focusPrev = d->focusPrev; // Play it really safe d->focusNext = this; d->focusPrev = this; clearFocus(); //we check if we have a layout previously if (d->layout) { QGraphicsLayout *temp = d->layout; foreach (QGraphicsItem * item, childItems()) { // In case of a custom layout which doesn't remove and delete items, we ensure that // the parent layout item does not point to the deleted layout. This code is here to // avoid regression from 4.4 to 4.5, because according to 4.5 docs it is not really needed. if (item->isWidget()) { QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(item); if (widget->parentLayoutItem() == d->layout) widget->setParentLayoutItem(0); } } d->layout = 0; delete temp; }
void GridLayoutItem::refreshAllItemViews() { prepareGeometryChange(); QList<QGraphicsItem *> itemList = childItems(); for( QList<QGraphicsItem *>::iterator it = itemList.begin(); it < itemList.end(); ++it ) { delete *it; } if( m_listController ) { for( int i = 0; i < m_listController->count(); i++ ) { insertItemView(i); } } }
void CDiagramItem::updateChildrenProperty(const QString &name, const QVariant &value) { QObject *obj = NULL; QMetaObject *meta = NULL; QList<QGraphicsItem*> items; items = childItems(); for (int i = 0; i < items.length(); ++i) { obj = dynamic_cast<QObject*>(items.at(i)); if (obj) { meta = const_cast<QMetaObject*>( obj->metaObject() ); if (meta && meta->indexOfProperty(name.toAscii().constData()) != -1 ) { obj->setProperty(name.toAscii().constData(), value); } } } }
GenTime AbstractGroupItem::duration() { QList <QGraphicsItem *> children = childItems(); GenTime start = GenTime(-1.0); GenTime end = GenTime(); for (int i = 0; i < children.count(); ++i) { if (children.at(i)->type() != GroupWidget) { AbstractClipItem *item = static_cast <AbstractClipItem *>(children.at(i)); if (item) { if (start < GenTime() || item->startPos() < start) start = item->startPos(); if (item->endPos() > end) end = item->endPos(); } } else { children << children.at(i)->childItems(); } } return end - start; }
/*! \internal */ void QDeclarativeGeoMapQuickItem::afterChildrenChanged() { QList<QQuickItem *> kids = childItems(); if (kids.size() > 0) { bool printedWarning = false; foreach (QQuickItem *i, kids) { if (i->flags() & QQuickItem::ItemHasContents && !qobject_cast<QQuickMouseArea *>(i) && sourceItem_.data() != i && opacityContainer_ != i) { if (!printedWarning) { qmlInfo(this) << "Use the sourceItem property for the contained item, direct children are not supported"; printedWarning = true; } qmlInfo(i) << "deleting this child"; i->deleteLater(); } } }
void Entity::initializeFixtures() { #if QT_VERSION >= 0x050000 QQuickItem *item; #else QGraphicsItem *item; #endif bool createSensor = true; foreach (item, childItems()) { if (Fixture *fixture = dynamic_cast<Fixture *>(item)) { createSensor = false; fixture->setWorld(m_world); fixture->setEntity(this); fixture->initialize(); } } if (createSensor) createSensorFixture(); }
void CellItem::updatePixmap() { QList<QGraphicsItem*> children = childItems(); qDeleteAll(children); QList<QString> spriteKeys = s_stateNames[m_state]; setSpriteKey(spriteKeys[0]); for(int i=1; i<spriteKeys.count(); i++) addOverlay(spriteKeys[i]); if(m_state == KMinesState::Revealed) { if(m_digit != 0) addOverlay(s_digitNames[m_digit]); else if(m_hasMine) { if(m_exploded) addOverlay(QStringLiteral( "explosion" )); addOverlay(QStringLiteral( "mine" )); } } }
/*! \internal */ void QDeclarativeGeoMap::populateMap() { QObjectList kids = children(); QList<QQuickItem *> quickKids = childItems(); for (int i=0; i < quickKids.count(); ++i) kids.append(quickKids.at(i)); for (int i = 0; i < kids.size(); ++i) { // dispatch items appropriately QDeclarativeGeoMapItemView *mapView = qobject_cast<QDeclarativeGeoMapItemView *>(kids.at(i)); if (mapView) { m_mapViews.append(mapView); setupMapView(mapView); continue; } QDeclarativeGeoMapItemBase *mapItem = qobject_cast<QDeclarativeGeoMapItemBase *>(kids.at(i)); if (mapItem) { addMapItem(mapItem); } } }
NodeAttr* NodeBlock::addAttr(const QString &name, bool isOutput, int flags, int ptr) { NodeAttr *port = new NodeAttr(this); port->setName(name); port->setIsOutput(isOutput); port->setNodeBlock(this); port->setAttrFlags(flags); port->setPtr(ptr); QFontMetrics fm(scene()->font()); int w = fm.width(name); int h = fm.height(); // port->setPos(0, height + h/2); if (w > width - horzMargin) width = w + horzMargin; height += h; QPainterPath p; p.addRoundedRect(-width/2, -height/2, width, height, 5, 5); setPath(p); int y = -height / 2 + vertMargin + port->radius(); foreach(QGraphicsItem *port_, childItems()) { if (port_->type() != NodeAttr::Type) continue; NodeAttr *port = (NodeAttr*) port_; if (port->isOutput()) port->setPos(width/2 + port->radius(), y); else port->setPos(-width/2 - port->radius(), y); y += h; } return port; }
QPainterPath AbstractGroupItem::groupShape(GraphicsRectItem type, const QPointF &offset) const { QPainterPath path; QList<QGraphicsItem *> children = childItems(); for (int i = 0; i < children.count(); ++i) { if (children.at(i)->type() == (int)type) { QRectF r(children.at(i)->sceneBoundingRect()); r.translate(offset); path.addRect(r); } else if (children.at(i)->type() == GroupWidget) { QList<QGraphicsItem *> subchildren = children.at(i)->childItems(); for (int j = 0; j < subchildren.count(); ++j) { if (subchildren.at(j)->type() == (int)type) { QRectF r(subchildren.at(j)->sceneBoundingRect()); r.translate(offset); path.addRect(r); } } } } return path; }
void Entity::update(const int &delta) { if ((m_updateInterval && m_updateTime.elapsed() >= m_updateInterval) || !m_updateInterval) { m_updateTime.restart(); if (m_behavior) { m_behavior->setDelta(delta); m_behavior->setEntity(this); m_behavior->update(delta); m_behavior->setEntity(0); } } #if QT_VERSION >= 0x050000 QQuickItem *child; #else QGraphicsItem *child; #endif foreach (child, childItems()) if (Entity *item = dynamic_cast<Entity *>(child)) item->update(delta); }
void GraphicsRectangularBranchItem::drawCollapsedRegion() { QList<QGraphicsItem*> items= childItems(); qreal xMin = 0; qreal yMin = 0; qreal yMax = 0; bool isFirstIteration = true; foreach(QGraphicsItem* graphItem, items) { GraphicsRectangularBranchItem* branchItem = dynamic_cast<GraphicsRectangularBranchItem*>(graphItem); if (!branchItem) continue; QPointF pos1 = branchItem ->pos(); if(isFirstIteration) { xMin = pos1.x(); yMin = yMax = pos1.y(); isFirstIteration = false; continue; } xMin = qMin(xMin, pos1.x()); yMin = qMin(yMin, pos1.y()); yMax = qMax(yMax, pos1.y()); }
/** Caller's child items will be reparented to the newParent */ void SN_LayoutWidget::reparentMyChildBasewidgets(SN_LayoutWidget *newParent) { if (_bar) { _firstChildLayout->reparentMyChildBasewidgets(newParent); _secondChildLayout->reparentMyChildBasewidgets(newParent); } else { foreach(QGraphicsItem *item, childItems()) { // exclude all the child but user application // if (item == _bar || item == _tileButton || item == _hButton || item == _vButton || item == _xButton || item==_firstChildLayout || item==_secondChildLayout) continue; if (item->type() < QGraphicsItem::UserType + BASEWIDGET_USER) continue; // // this item's pos() which is in this layoutWidget's coordinate to newParent's coordinate // QPointF newPos = mapToItem(newParent, item->pos()); // reparent item->setParentItem(newParent); item->setPos(newPos); } } }
bool StandardCategory::removeItself() { bool children_removed = true; // Remove all child items (feeds and categories) // from the database. foreach (RootItem *child, childItems()) { if (child->kind() == RootItemKind::Category) { children_removed &= static_cast<StandardCategory*>(child)->removeItself(); } else if (child->kind() == RootItemKind::Feed) { children_removed &= static_cast<StandardFeed*>(child)->removeItself(); } } if (children_removed) { // Children are removed, remove this standard category too. QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); return DatabaseQueries::deleteCategory(database, id()); } else { return false; } }
void StretchRow::layoutChildrenWithDefaultSize() { //static int count = 0; //qDebug() << "Row Default Size" << ++count; Q_ASSERT(m_defaultSize != 0); const QList<QQuickItem *> childrenList = childItems(); if (childrenList.isEmpty()) return; const int layoutHeight = height(); qreal currX = m_leftMargin; for (QList<QQuickItem *>::const_iterator it = childrenList.constBegin(); it != childrenList.constEnd(); ++it) { QQuickItem* child = (*it); if (child == Q_NULLPTR || !child->isVisible()) { continue; } // add spacing if it is not the first item: if (currX > 0) { currX += m_spacing; } if (currX != child->x()) child->setX(currX); // check if item has a stretch proportion set: if (child->implicitWidth() < 0) { // yes -> set it to default size: qreal newWidth = m_defaultSize * child->implicitWidth() * -1; if (newWidth != child->width()) child->setWidth(newWidth); } // set height of all items to fill the layout: if (layoutHeight != child->height()) child->setHeight(layoutHeight); currX += child->width(); } currX += m_rightMargin; // set implicit size to fit all items: if (currX != implicitWidth()) setImplicitWidth(currX); }
void StretchColumn::layoutChildrenWithDefaultSize() { //static int count = 0; //qDebug() << "Column Default Size" << ++count; Q_ASSERT(m_defaultSize != 0); const QList<QQuickItem *> childrenList = childItems(); if (childrenList.isEmpty()) return; const int contentWidth = width() - m_leftMargin - m_rightMargin; qreal currY = 0; for (QList<QQuickItem *>::const_iterator it = childrenList.constBegin(); it != childrenList.constEnd(); ++it) { QQuickItem* child = (*it); if (child == Q_NULLPTR || !child->isVisible()) { continue; } // add spacing if it is not the first item: if (currY > 0) { currY += m_spacing; } if (currY != child->y()) child->setY(currY); // check if item has a stretch proportion set: if (child->implicitHeight() < 0) { // yes -> set it to default size multiplied by relative size: qreal newHeight = m_defaultSize * child->implicitHeight() * -1; if (newHeight != child->height()) child->setHeight(newHeight); } // set width of all items to fill the layout: if (m_leftMargin != child->x()) child->setX(m_leftMargin); if (contentWidth != child->width()) child->setWidth(contentWidth); currY += child->height(); } // set implicit size to fit all items: if (currY != implicitHeight()) setImplicitHeight(currY); }
void StretchRow::layoutChildrenWithProportions() { //static int count = 0; //qDebug() << "Row Proportions" << ++count; const QList<QQuickItem*> childrenList = childItems(); if (childrenList.isEmpty()) return; if (width() <= 0) return; int visibleItems = 0; qreal availableForStretch = width() - m_leftMargin - m_rightMargin; qreal sumStretchProportions = 0.0; // iterate over all children and calculate available size to stretch items: for (QList<QQuickItem *>::const_iterator it = childrenList.constBegin(); it != childrenList.constEnd(); ++it) { QQuickItem* child = (*it); if (child == Q_NULLPTR || !child->isVisible()) { continue; } if (child->implicitWidth() >= 0) { // no stretch proportion set -> leave size and remove it from available space: availableForStretch -= child->width(); } else { // a stretch proportion is set -> add it to sum: sumStretchProportions += (child->implicitWidth() * -1); } visibleItems++; } // remove spacing from available space: availableForStretch -= m_spacing * (visibleItems - 1); const int layoutHeight = height(); QPointer<QQuickItem> lastStretchItem = nullptr; qreal currX = m_leftMargin; for (QList<QQuickItem *>::const_iterator it = childrenList.constBegin(); it != childrenList.constEnd(); ++it) { QQuickItem* child = (*it); if (child == Q_NULLPTR || !child->isVisible()) { continue; } // add spacing if it is not the first item: if (currX > 0) { currX += m_spacing; } if (currX != child->x()) child->setX(currX); // check if item has a stretch proportion set (if not do nothing): if (child->implicitWidth() < 0) { // get the stretch proportion: qreal stretchProportion = (child->implicitWidth() * -1); // calculate the relation of the total space available for stretched items // that this item will use: // (sumStretchProportion can not be 0 (in divison) because if this "if" is executed, // there has been at least one item with a stretch proportion set) qreal relationOfSpaceAvailableForStretch = stretchProportion / sumStretchProportions; qreal newWidth = qRound(availableForStretch * relationOfSpaceAvailableForStretch); if (newWidth != child->width()) child->setWidth(newWidth); lastStretchItem = child; } // set height of all items to fill the layout: if (layoutHeight != child->height()) child->setHeight(layoutHeight); currX += child->width(); } currX += m_rightMargin; // check if last item fills whole remaining space in this layout: // (can happen because of rounding mistakes) if (lastStretchItem) { double pxMissing = width() - currX; if (pxMissing > 0.0001) { // qInfo() << "StretchRow layout mismatch: " << pxMissing; // it does not -> adjust it: lastStretchItem->setWidth(lastStretchItem->width() + pxMissing); } } }
void QRecipeTableItem::compile(QSqlDatabase &db, int nSceneId,int &count,int index) { count++; QVisableItem::compile(db, nSceneId, count,index); int nItemID = count; if(sPro.enableTouch && !sPro.byGroups_T) { //触控受位控制 增一个地址表 count++; } if(sPro.bNotice) { //触控解锁通知到地址 增加一个地址表 count++; } if(sPro.enableVisable && !sPro.byGroups_V) { //显现受位控制 增加一个地址表 count++; } QRectF rect = this->sceneBoundingRect(); QSqlQuery sqlquery(db); bool bReasult = false; bReasult = sqlquery.prepare("INSERT INTO recipeDisplay(nItemId,nSceneId,nStartPosX,nStartPosY,nWidth," "nHeight,nRecipeGroupId,bShowRecipeID,bShowDescrip,eTextAlignType," "nLanguaId,nRowShowNum,nColumShowNum,nHHeadTextColor,nHHeadBackColor," "nHHeadFontSize,sHHeadFontFamily,nVHeadTextColor,nVHeadBackColor," "nVHeadFontSize,sVHeadFontFamily,nDataTextColor,nDataBackColor," "nDataFontSize,nLineColor,nTransparent,nZvalue,nCollidindId,nShowPropId)" "VALUES (:nItemId,:nSceneId,:nStartPosX,:nStartPosY,:nWidth," ":nHeight,:nRecipeGroupId,:bShowRecipeID,:bShowDescrip,:eTextAlignType," ":nLanguaId,:nRowShowNum,:nColumShowNum,:nHHeadTextColor,:nHHeadBackColor," ":nHHeadFontSize,:sHHeadFontFamily,:nVHeadTextColor,:nVHeadBackColor," ":nVHeadFontSize,:sVHeadFontFamily,:nDataTextColor,:nDataBackColor," ":nDataFontSize,:nLineColor,:nTransparent,:nZvalue,:nCollidindId,:nShowPropId)"); sqlquery.bindValue(":nItemId",QVariant(nItemID)); sqlquery.bindValue(":nSceneId",QVariant(nSceneId)); sqlquery.bindValue(":nStartPosX",QVariant(rect.x())); sqlquery.bindValue(":nStartPosY",QVariant(rect.y())); sqlquery.bindValue(":nWidth",QVariant(rect.width())); sqlquery.bindValue(":nHeight",QVariant(rect.height())); sqlquery.bindValue(":nRecipeGroupId",QVariant(m_SaveInfo.nRecipeGroupId)); sqlquery.bindValue(":bShowRecipeID",QVariant(m_SaveInfo.bShowRecipeID)); sqlquery.bindValue(":bShowDescrip",QVariant(m_SaveInfo.bShowDescrip)); int nAlign = 0; if(0 == m_SaveInfo.eTextAlignType)//center { nAlign = 2; } else if(1 == m_SaveInfo.eTextAlignType)//left { nAlign = 1; } else { nAlign = 3; } sqlquery.bindValue(":eTextAlignType",QVariant(nAlign)); sqlquery.bindValue(":nLanguaId",QVariant(m_SaveInfo.nLanguaId)); sqlquery.bindValue(":nRowShowNum",QVariant(m_SaveInfo.nRowShowNum)); sqlquery.bindValue(":nColumShowNum",QVariant(m_SaveInfo.nColumShowNum)); sqlquery.bindValue(":nHHeadTextColor",QVariant(ColorToInt(m_SaveInfo.nHHeadTextColor))); sqlquery.bindValue(":nHHeadBackColor",QVariant(ColorToInt(m_SaveInfo.nHHeadBackColor))); sqlquery.bindValue(":nHHeadFontSize",QVariant(m_SaveInfo.nHHeadFontSize + 5)); sqlquery.bindValue(":sHHeadFontFamily",QVariant(m_SaveInfo.sHHeadFontFamily)); sqlquery.bindValue(":nVHeadTextColor",QVariant(ColorToInt(m_SaveInfo.nVHeadTextColor))); sqlquery.bindValue(":nVHeadBackColor",QVariant(ColorToInt(m_SaveInfo.nVHeadBackColor))); sqlquery.bindValue(":nVHeadFontSize",QVariant(m_SaveInfo.nVHeadFontSize + 5)); sqlquery.bindValue(":sVHeadFontFamily",QVariant(m_SaveInfo.sVHeadFontFamily)); sqlquery.bindValue(":nDataTextColor",QVariant(ColorToInt(m_SaveInfo.nDataTextColor))); sqlquery.bindValue(":nDataBackColor",QVariant(ColorToInt(m_SaveInfo.nDataBackColor))); sqlquery.bindValue(":nDataFontSize",QVariant(m_SaveInfo.nDataFontSize + 5)); sqlquery.bindValue(":nLineColor",QVariant(ColorToInt(m_SaveInfo.nLineColor))); sqlquery.bindValue(":nTransparent",QVariant(ColorToInt(m_SaveInfo.nTransparent))); sqlquery.bindValue(":nZvalue",QVariant(zValue())); sqlquery.bindValue(":nCollidindId",QVariant(index)); sqlquery.bindValue(":nShowPropId",QVariant(-1)); bReasult = sqlquery.exec(); qDebug()<<"INSERT INTO recipeDisplay"<<bReasult; QList<QGraphicsItem *> list = childItems(); QString sName = ""; QVector<qreal> vVLine; //用来存垂直线的数据 QVector<qreal> vHLine; //用来存水平线的数据 vVLine.clear(); vHLine.clear(); vVLine.append(rect.x()); vHLine.append(rect.y()); //vTileTex.clear(); foreach(QGraphicsItem *pItem,list) { QPointF pos = pItem->boundingRect().topLeft()+pItem->scenePos(); sName = pItem->data(GROUP_NAME_KEY).toString(); if(sName.contains("VLine")) //垂直线 { vVLine.append(pos.x()); } if(sName.contains("HLine")) //水平线 { vHLine.append(pos.y()); } }
QGraphicsItem *QRecipeTableItem::Clone() { QGraphicsItem *pCopy = NULL; QGraphicsItem * pItem= NULL; QRecipeTableItem *itemGroup = new QRecipeTableItem(); QList<QGraphicsItem *> itemList; itemList = childItems(); int size = itemList.size(); for(int i=0;i<size;i++) { pItem = itemList.at(i); switch(pItem->type()) { case SAM_DRAW_OBJECT_RECT: //矩形 { QRectItem *rectItem = dynamic_cast<QRectItem *>(pItem); if(rectItem) { pCopy = rectItem->Clone(); itemGroup->addToGroup(pCopy); } break; } case SAM_DRAW_OBJECT_ELIPSE: //圆 { QElipseItem *elipseItem = dynamic_cast<QElipseItem *>(pItem); if(elipseItem) { pCopy = elipseItem->Clone(); itemGroup->addToGroup(pCopy); } break; } case SAM_DRAW_OBJECT_LINE: //直线 { QLineItem * lineItem = dynamic_cast<QLineItem *>(pItem); if(lineItem) { pCopy = lineItem->Clone(); itemGroup->addToGroup(pCopy); } break; } case SAM_DRAW_OBJECT_POLYGON: //多边形 { QPolygonItem *polygonItem = dynamic_cast<QPolygonItem *>(pItem); if(polygonItem) { pCopy = polygonItem->Clone(); itemGroup->addToGroup(pCopy); } break; } case SAM_DRAW_OBJECT_FOLDLINE: //19 { QFoldLineItem *foldlineItem = dynamic_cast<QFoldLineItem *>(pItem); if(foldlineItem) { pCopy = foldlineItem->Clone(); itemGroup->addToGroup(pCopy); } break; } case SAM_DRAW_OBJECT_FREELINE: //20 { QFreeLineItem * freelineItem = dynamic_cast<QFreeLineItem *>(pItem); if(freelineItem) { pCopy = freelineItem->Clone(); itemGroup->addToGroup(pCopy); } break; } case SAM_DRAW_OBJECT_TEXT: //22 { QSimpleTextItem * textItem = dynamic_cast<QSimpleTextItem *>(pItem); if(textItem) { pCopy = textItem->Clone(); itemGroup->addToGroup(pCopy); } break; } case SAM_DRAW_OBJECT_PIXMAP: { QPixmapItem *pixmapItem = dynamic_cast<QPixmapItem *>(pItem); if(pixmapItem) { pCopy = pixmapItem->Clone(); itemGroup->addToGroup(pCopy); } break; } case SAM_DRAW_OBJECT_LINECIRCLE: //25 { QLineCircleItem *circleItem = dynamic_cast<QLineCircleItem *>(pItem); if(circleItem) { pCopy = circleItem->Clone(); itemGroup->addToGroup(pCopy); } break; } case SAM_DRAW_OBJECT_ROUNDEDRECT: { QRoundedRect *roundedrectItem = dynamic_cast<QRoundedRect *>(pItem); if(roundedrectItem) { pCopy = roundedrectItem->Clone(); itemGroup->addToGroup(pCopy); } break; } case SAM_DRAW_OBJECT_ARC: { QArcItem *arcItem = dynamic_cast<QArcItem *>(pItem); if(arcItem) { pCopy = arcItem->Clone(); itemGroup->addToGroup(pCopy); } break; } case SAM_DRAW_OBJECT_GROUP: //23 { QItemGroup *group = dynamic_cast<QItemGroup *>(pItem); if(group) { pCopy = group->Clone(); itemGroup->addToGroup(pCopy); } break; } default: break; } if(pCopy) pCopy->setFlag(QGraphicsItem::ItemIsSelectable,false); } itemGroup->SaveSecurityPro(&sPro); itemGroup->SaveInfo(m_SaveInfo); itemGroup->setData(GROUP_NAME_KEY,data(GROUP_NAME_KEY).toString()); itemGroup->setData(GROUP_TYPE_KEY,data(GROUP_TYPE_KEY).toInt()); itemGroup->setId(id()); if(itemGroup->childItems().size() == 0) { delete itemGroup; itemGroup = NULL; } return itemGroup; //return QItemGroup::Clone(); //return 0; //需要在派生类实例化对象,复制部分无法重用基类代码 }
//virtual QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant &value) { if (change == QGraphicsItem::ItemSelectedChange) { if (value.toBool()) setZValue(3); else setZValue(1); } CustomTrackScene *scene = NULL; if (change == ItemPositionChange && parentItem() == 0) { scene = projectScene(); } if (scene) { // calculate new position. if (scene->isZooming) { // For some reason, mouse wheel on selected itm sometimes triggered // a position change event corrupting timeline, so discard it return pos(); } // calculate new position. const int trackHeight = KdenliveSettings::trackheight(); QPointF start = sceneBoundingRect().topLeft(); QPointF newPos = value.toPointF(); int xpos = projectScene()->getSnapPointForPos((int)(start.x() + newPos.x() - pos().x()), KdenliveSettings::snaptopoints()); xpos = qMax(xpos, 0); ////qDebug()<<"GRP XPOS:"<<xpos<<", START:"<<start.x()<<",NEW:"<<newPos.x()<<"; SCENE:"<<scenePos().x()<<",POS:"<<pos().x(); newPos.setX((int)(pos().x() + xpos - (int) start.x())); QStringList lockedTracks = property("locked_tracks").toStringList(); int proposedTrack = trackForPos(property("y_absolute").toInt() + newPos.y()); // Check if top item is a clip or a transition int offset = 0; int topTrack = -1; QList<int> groupTracks; QList<QGraphicsItem *> children = childItems(); for (int i = 0; i < children.count(); ++i) { int currentTrack = 0; if (children.at(i)->type() == AVWidget || children.at(i)->type() == TransitionWidget) { currentTrack = static_cast <AbstractClipItem*> (children.at(i))->track(); if (!groupTracks.contains(currentTrack)) groupTracks.append(currentTrack); } else if (children.at(i)->type() == GroupWidget) { currentTrack = static_cast <AbstractGroupItem*> (children.at(i))->track(); } else continue; if (children.at(i)->type() == AVWidget) { if (topTrack == -1 || currentTrack >= topTrack) { offset = 0; topTrack = currentTrack; } } else if (children.at(i)->type() == TransitionWidget) { if (topTrack == -1 || currentTrack > topTrack) { offset = (int)(trackHeight / 3 * 2 - 1); topTrack = currentTrack; } } else if (children.at(i)->type() == GroupWidget) { QList<QGraphicsItem *> subchildren = children.at(i)->childItems(); bool clipGroup = false; for (int j = 0; j < subchildren.count(); ++j) { if (subchildren.at(j)->type() == AVWidget || subchildren.at(j)->type() == TransitionWidget) { int subTrack = static_cast <AbstractClipItem*> (subchildren.at(j))->track(); if (!groupTracks.contains(subTrack)) groupTracks.append(subTrack); clipGroup = true; } } if (clipGroup) { if (topTrack == -1 || currentTrack >= topTrack) { offset = 0; topTrack = currentTrack; } } else { if (topTrack == -1 || currentTrack > topTrack) { offset = (int)(trackHeight / 3 * 2 - 1); topTrack = currentTrack; } } } } // Check no clip in the group goes outside of existing tracks int maximumTrack = projectScene()->tracksCount(); int groupHeight = 0; for (int i = 0; i < groupTracks.count(); ++i) { int offset = groupTracks.at(i) - topTrack; if (offset > groupHeight) groupHeight = offset; } maximumTrack -= groupHeight; proposedTrack = qMin(proposedTrack, maximumTrack); proposedTrack = qMax(proposedTrack, groupTracks.count()); int groupOffset = proposedTrack - topTrack; if (!lockedTracks.isEmpty()) { for (int i = 0; i < groupTracks.count(); ++i) { if (lockedTracks.contains(QString::number(groupTracks.at(i) + groupOffset))) { return pos(); } } } newPos.setY(posForTrack(proposedTrack) + offset); //if (newPos == start) return start; /*if (newPos.x() < 0) { // If group goes below 0, adjust position to 0 return QPointF(pos().x() - start.x(), pos().y()); }*/ QList<QGraphicsItem*> collidingItems; QPainterPath shape; if (projectScene()->editMode() == NormalEdit) { shape = clipGroupShape(newPos - pos()); collidingItems = scene->items(shape, Qt::IntersectsItemShape); collidingItems.removeAll(this); for (int i = 0; i < children.count(); ++i) { if (children.at(i)->type() == GroupWidget) { QList<QGraphicsItem *> subchildren = children.at(i)->childItems(); for (int j = 0; j < subchildren.count(); ++j) { collidingItems.removeAll(subchildren.at(j)); } } collidingItems.removeAll(children.at(i)); } } if (!collidingItems.isEmpty()) { bool forwardMove = xpos > start.x(); int offset = 0; for (int i = 0; i < collidingItems.count(); ++i) { QGraphicsItem *collision = collidingItems.at(i); if (collision->type() == AVWidget) { // Collision if (newPos.y() != pos().y()) { // Track change results in collision, restore original position return pos(); } AbstractClipItem *item = static_cast <AbstractClipItem *>(collision); // Determine best pos QPainterPath clipPath; clipPath.addRect(item->sceneBoundingRect()); QPainterPath res = shape.intersected(clipPath); offset = qMax(offset, (int)(res.boundingRect().width() + 0.5)); } } if (offset > 0) { if (forwardMove) { newPos.setX(newPos.x() - offset); } else { newPos.setX(newPos.x() + offset); } // If there is still a collision after our position adjust, restore original pos collidingItems = scene->items(clipGroupShape(newPos - pos()), Qt::IntersectsItemShape); collidingItems.removeAll(this); for (int i = 0; i < children.count(); ++i) { if (children.at(i)->type() == GroupWidget) { QList<QGraphicsItem *> subchildren = children.at(i)->childItems(); for (int j = 0; j < subchildren.count(); ++j) { collidingItems.removeAll(subchildren.at(j)); } } collidingItems.removeAll(children.at(i)); } for (int i = 0; i < collidingItems.count(); ++i) if (collidingItems.at(i)->type() == AVWidget) return pos(); } } if (projectScene()->editMode() == NormalEdit) { shape = transitionGroupShape(newPos - pos()); collidingItems = scene->items(shape, Qt::IntersectsItemShape); collidingItems.removeAll(this); for (int i = 0; i < children.count(); ++i) { if (children.at(i)->type() == GroupWidget) { QList<QGraphicsItem *> subchildren = children.at(i)->childItems(); for (int j = 0; j < subchildren.count(); ++j) { collidingItems.removeAll(subchildren.at(j)); } } collidingItems.removeAll(children.at(i)); } } if (collidingItems.isEmpty()) return newPos; else { bool forwardMove = xpos > start.x(); int offset = 0; for (int i = 0; i < collidingItems.count(); ++i) { QGraphicsItem *collision = collidingItems.at(i); if (collision->type() == TransitionWidget) { // Collision if (newPos.y() != pos().y()) { // Track change results in collision, restore original position return pos(); } AbstractClipItem *item = static_cast <AbstractClipItem *>(collision); // Determine best pos QPainterPath clipPath; clipPath.addRect(item->sceneBoundingRect()); QPainterPath res = shape.intersected(clipPath); offset = qMax(offset, (int)(res.boundingRect().width() + 0.5)); } } if (offset > 0) { if (forwardMove) { newPos.setX(newPos.x() - offset); } else { newPos.setX(newPos.x() + offset); } // If there is still a collision after our position adjust, restore original pos collidingItems = scene->items(transitionGroupShape(newPos - pos()), Qt::IntersectsItemShape); for (int i = 0; i < children.count(); ++i) { collidingItems.removeAll(children.at(i)); } for (int i = 0; i < collidingItems.count(); ++i) if (collidingItems.at(i)->type() == TransitionWidget) return pos(); } } return newPos; } return QGraphicsItemGroup::itemChange(change, value); }
DynCircleAttr* DynCircleAttr::Clone() //复制item { QGraphicsItem* pCopy = NULL; QGraphicsItem* pItem = NULL; DynCircleAttr *itemGroup = new DynCircleAttr; QList<QGraphicsItem *> itemList; itemList = childItems(); int size = itemList.size(); for(int i=0;i<size;i++) { pItem = itemList.at(i); switch(pItem->type()) { case SAM_DRAW_OBJECT_RECT: //矩形 { QRectItem *rectItem = dynamic_cast<QRectItem *>(pItem); if(rectItem) { pCopy = rectItem->Clone(); itemGroup->addToGroup(pCopy); } break; } case SAM_DRAW_OBJECT_ELIPSE: //圆 { QElipseItem *elipseItem = dynamic_cast<QElipseItem *>(pItem); if(elipseItem) { pCopy = elipseItem->Clone(); itemGroup->addToGroup(pCopy); } break; } case SAM_DRAW_OBJECT_LINE: //直线 { QLineItem * lineItem = dynamic_cast<QLineItem *>(pItem); if(lineItem) { pCopy = lineItem->Clone(); itemGroup->addToGroup(pCopy); } break; } case SAM_DRAW_OBJECT_POLYGON: //多边形 { QPolygonItem *polygonItem = dynamic_cast<QPolygonItem *>(pItem); if(polygonItem) { pCopy = polygonItem->Clone(); itemGroup->addToGroup(pCopy); } break; } case SAM_DRAW_OBJECT_FOLDLINE: //19 { QFoldLineItem *foldlineItem = dynamic_cast<QFoldLineItem *>(pItem); if(foldlineItem) { pCopy = foldlineItem->Clone(); itemGroup->addToGroup(pCopy); } break; } case SAM_DRAW_OBJECT_FREELINE: //20 { QFreeLineItem * freelineItem = dynamic_cast<QFreeLineItem *>(pItem); if(freelineItem) { pCopy = freelineItem->Clone(); itemGroup->addToGroup(pCopy); } break; } case SAM_DRAW_OBJECT_TEXT: //22 { QSimpleTextItem * textItem = dynamic_cast<QSimpleTextItem *>(pItem); if(textItem) { pCopy = textItem->Clone(); itemGroup->addToGroup(pCopy); } break; } case SAM_DRAW_OBJECT_PIXMAP: { QPixmapItem *pixmapItem = dynamic_cast<QPixmapItem *>(pItem); if(pixmapItem) { pCopy = pixmapItem->Clone(); itemGroup->addToGroup(pCopy); } break; } case SAM_DRAW_OBJECT_LINECIRCLE: //25 { QLineCircleItem *circleItem = dynamic_cast<QLineCircleItem *>(pItem); if(circleItem) { pCopy = circleItem->Clone(); itemGroup->addToGroup(pCopy); } break; } case SAM_DRAW_OBJECT_ROUNDEDRECT: { QRoundedRect *roundedrectItem = dynamic_cast<QRoundedRect *>(pItem); if(roundedrectItem) { pCopy = roundedrectItem->Clone(); itemGroup->addToGroup(pCopy); } break; } case SAM_DRAW_OBJECT_ARC: { QArcItem *arcItem = dynamic_cast<QArcItem *>(pItem); if(arcItem) { pCopy = arcItem->Clone(); itemGroup->addToGroup(pCopy); } break; } case SAM_DRAW_OBJECT_GROUP: //23 { QItemGroup *group = dynamic_cast<QItemGroup *>(pItem); if(group) { pCopy = group->Clone(); itemGroup->addToGroup(pCopy); } break; } default: break; } if(pCopy) { pCopy->setFlag(QGraphicsItem::ItemIsSelectable,false); } } itemGroup->setData(GROUP_NAME_KEY,data(GROUP_NAME_KEY).toString()); if(itemGroup->childItems().size() == 0) { delete itemGroup; itemGroup = NULL; } itemGroup->SaveSecurityPro(&sPro); //矩形外观 itemGroup->m_bFillColor = m_bFillColor; itemGroup->m_nFillColor = m_nFillColor; itemGroup->m_bFrameColor = m_bFrameColor; itemGroup->m_nFrameColor = m_nFrameColor; itemGroup->m_nFrameWidth = m_nFrameWidth; itemGroup->m_nAlpha = m_nAlpha; //显示区域设置 itemGroup->m_nBeginX = m_nBeginX; itemGroup->m_nBeginY = m_nBeginY; itemGroup->m_nWidth = m_nWidth; itemGroup->m_nHeight = m_nHeight; itemGroup->m_nBgColor = m_nBgColor; //位置控制 itemGroup->m_bPosCtrl = m_bPosCtrl; itemGroup->m_addrH = m_addrH; itemGroup->m_addrV = m_addrV; //大小控制 itemGroup->m_bSizeCtrl = m_bSizeCtrl; itemGroup->m_addrCircle = m_addrCircle; itemGroup->setId(id()); return itemGroup; }
/*! * \brief Sets the parent item of all child items to the parent of the GraphicsEmptyItem. */ void GraphicsEmptyItem::clearChildItems() { foreach (QGraphicsItem *item, childItems()) item->setParentItem(this->parentItem()); }
SCgPointObject::PointFVector SCgContour::minimizedPoints() const { // Collect items which is a scgObject: QSet<SCgObject *> scgObjects; foreach(QGraphicsItem* item, childItems()) { if (SCgObject::isSCgObjectType(item->type())) { SCgObject *scgObject = static_cast<SCgObject*>(item); scgObjects.insert(scgObject); } } if (!scgObjects.isEmpty()) { // Find min and max points: qreal minX, minY, maxX, maxY; QSet<SCgObject *>::const_iterator it; it = scgObjects.begin(); SCgObject *firstObj = *it; QRectF firstObjRect = firstObj->boundingRect(); minX = firstObj->mapToScene(firstObjRect.topLeft()).x(); minY = firstObj->mapToScene(firstObjRect.topLeft()).y(); maxX = firstObj->mapToScene(firstObjRect.bottomRight()).x(); maxY = firstObj->mapToScene(firstObjRect.bottomRight()).y(); for (++it; it != scgObjects.end(); ++it) { SCgObject *obj = *it; QRectF objRect = obj->boundingRect(); QPointF topLeft = obj->mapToScene(objRect.topLeft()); QPointF bottomRight = obj->mapToScene(objRect.bottomRight()); if (topLeft.x() < minX) { minX = topLeft.x(); } if (topLeft.y() < minY) { minY = topLeft.y(); } if (bottomRight.x() > maxX) { maxX = bottomRight.x(); } if (bottomRight.y() > maxY) { maxY = bottomRight.y(); } } // Increase distance from borders: minX -= borderDistance; minY -= borderDistance; maxX += borderDistance; maxY += borderDistance; // Remove all points and set only 4 corner points: PointFVector newPoints; newPoints << QPointF(minX, minY) << QPointF(maxX, minY) << QPointF(maxX, maxY) << QPointF(minX, maxY); return newPoints; } }
void UBGraphicsGroupContainerItem::addToGroup(QGraphicsItem *item) { if (!item) { qWarning("UBGraphicsGroupContainerItem::addToGroup: cannot add null item"); return; } if (item == this) { qWarning("UBGraphicsGroupContainerItem::addToGroup: cannot add a group to itself"); return; } //Check if group is allready rotatable or flippable if (childItems().count()) { if (UBGraphicsItem::isFlippable(this) && !UBGraphicsItem::isFlippable(item)) { Delegate()->setFlippable(false); } if (UBGraphicsItem::isRotatable(this) && !UBGraphicsItem::isRotatable(item)) { Delegate()->setRotatable(false); } } else { Delegate()->setFlippable(UBGraphicsItem::isFlippable(item)); Delegate()->setRotatable(UBGraphicsItem::isRotatable(item)); } // COMBINE bool ok; QTransform itemTransform = item->itemTransform(this, &ok); if (!ok) { qWarning("UBGraphicsGroupContainerItem::addToGroup: could not find a valid transformation from item to group coordinates"); return; } //setting item flags to given item item->setSelected(false); item->setFlag(QGraphicsItem::ItemIsSelectable, false); item->setFlag( QGraphicsItem::ItemIsMovable, false); item->setFlag(QGraphicsItem::ItemIsFocusable, true); QTransform newItemTransform(itemTransform); item->setPos(mapFromItem(item, 0, 0)); if (item->scene()) { item->scene()->removeItem(item); } if (corescene()) corescene()->removeItemFromDeletion(item); item->setParentItem(this); // removing position from translation component of the new transform if (!item->pos().isNull()) newItemTransform *= QTransform::fromTranslate(-item->x(), -item->y()); // removing additional transformations properties applied with itemTransform() QPointF origin = item->transformOriginPoint(); QMatrix4x4 m; QList<QGraphicsTransform*> transformList = item->transformations(); for (int i = 0; i < transformList.size(); ++i) transformList.at(i)->applyTo(&m); newItemTransform *= m.toTransform().inverted(); newItemTransform.translate(origin.x(), origin.y()); newItemTransform.rotate(-item->rotation()); newItemTransform.scale(1/item->scale(), 1/item->scale()); newItemTransform.translate(-origin.x(), -origin.y()); // ### Expensive, we could maybe use dirtySceneTransform bit for optimization item->setTransform(newItemTransform); // item->d_func()->setIsMemberOfGroup(true); prepareGeometryChange(); itemsBoundingRect |= itemTransform.mapRect(item->boundingRect() | item->childrenBoundingRect()); update(); }
int QAccessibleQuickItem::childCount() const { return childItems().count(); }
void OverlayUserGroup::updateUsers() { const QRectF &sr = scene()->sceneRect(); unsigned int uiHeight = iroundf(sr.height() + 0.5f); QList<QGraphicsItem *> items; foreach(QGraphicsItem *qgi, childItems()) items << qgi; QList<OverlayUser *> users; if (bShowExamples) { if (qlExampleUsers.isEmpty()) { qlExampleUsers << new OverlayUser(Settings::Passive, uiHeight, os); qlExampleUsers << new OverlayUser(Settings::Talking, uiHeight, os); qlExampleUsers << new OverlayUser(Settings::Whispering, uiHeight, os); qlExampleUsers << new OverlayUser(Settings::Shouting, uiHeight, os); } users = qlExampleUsers; foreach(OverlayUser *ou, users) items.removeAll(ou); if (! qgeiHandle) { qgeiHandle = new QGraphicsEllipseItem(QRectF(-4.0f, -4.0f, 8.0f, 8.0f)); qgeiHandle->setPen(QPen(Qt::darkRed, 0.0f)); qgeiHandle->setBrush(Qt::red); qgeiHandle->setZValue(0.5f); qgeiHandle->setFlag(QGraphicsItem::ItemIsMovable); qgeiHandle->setFlag(QGraphicsItem::ItemIsSelectable); qgeiHandle->setPos(sr.width() * os->fX, sr.height() * os->fY); scene()->addItem(qgeiHandle); qgeiHandle->show(); qgeiHandle->installSceneEventFilter(this); } } else { delete qgeiHandle; qgeiHandle = NULL; } ClientUser *self = ClientUser::get(g.uiSession); if (self) { QList<ClientUser *> showusers; Channel *home = ClientUser::get(g.uiSession)->cChannel; switch (os->osShow) { case OverlaySettings::LinkedChannels: foreach(Channel *c, home->allLinks()) foreach(User *p, c->qlUsers) showusers << static_cast<ClientUser *>(p); foreach(ClientUser *cu, ClientUser::getTalking()) if (! showusers.contains(cu)) showusers << cu; break; case OverlaySettings::HomeChannel: foreach(User *p, home->qlUsers) showusers << static_cast<ClientUser *>(p); foreach(ClientUser *cu, ClientUser::getTalking()) if (! showusers.contains(cu)) showusers << cu; break; case OverlaySettings::Active: showusers = ClientUser::getActive(); if (os->bAlwaysSelf && !showusers.contains(self)) showusers << self; break; default: showusers = ClientUser::getTalking(); if (os->bAlwaysSelf && (self->tsState == Settings::Passive)) showusers << self; break; } ClientUser::sortUsersOverlay(showusers); foreach(ClientUser *cu, showusers) { OverlayUser *ou = qmUsers.value(cu); if (! ou) { ou = new OverlayUser(cu, uiHeight, os); connect(cu, SIGNAL(destroyed(QObject *)), this, SLOT(userDestroyed(QObject *))); qmUsers.insert(cu, ou); ou->hide(); } else {
/* * Shamelessly stolen from qml-box2d project at gitorious * * https://gitorious.org/qml-box2d/qml-box2d */ void Box2DItem::initialize(b2World *world) { if (m_initialized) return; b2BodyDef bodyDef; bodyDef.type = static_cast<b2BodyType>(m_bodyType); bodyDef.position.Set((x() + width() / 2.0) / m_scaleRatio, (-y() - height() / 2.0) / m_scaleRatio); bodyDef.angle = -(rotation() * (2 * b2_pi)) / 360.0; bodyDef.linearDamping = m_linearDamping; bodyDef.angularDamping = m_angularDamping; bodyDef.bullet = m_bullet; bodyDef.allowSleep = m_sleepingAllowed; bodyDef.fixedRotation = m_fixedRotation; m_body = world->CreateBody(&bodyDef); b2Shape *shape; switch (m_shape){ case Quasi::RectangleBodyShape: shape = new b2PolygonShape; ((b2PolygonShape*)shape)->SetAsBox(width() / m_scaleRatio / 2.0, height() / m_scaleRatio / 2.0); break; case Quasi::PolygonBodyShape: { // TODO: check for b2_maxPolygonVertices b2Vec2 *vertices = b2Util::b2Vertices(m_vertices, boundingRect(), m_scaleRatio); shape = new b2PolygonShape; ((b2PolygonShape*)shape)->Set(vertices, m_vertices.length()); } break; case Quasi::CircleBodyShape: shape = new b2CircleShape; ((b2CircleShape*)shape)->m_radius = width() / m_scaleRatio / 2.0f; break; case Quasi::ChainBodyShape: { b2Vec2 *vertices = b2Util::b2Vertices(m_vertices, boundingRect(), m_scaleRatio); shape = new b2ChainShape; //TODO: create a way to decide to use CreateChain or CreateLoop ((b2ChainShape*)shape)->CreateChain(vertices, m_vertices.length()); } break; default: // TODO error handling break; } b2FixtureDef fixtureDef; fixtureDef.shape = shape; fixtureDef.density = m_density; fixtureDef.friction = m_friction; fixtureDef.restitution = m_restitution; m_fixture = m_body->CreateFixture(&fixtureDef); foreach (QQuickItem *item, childItems()) { if (Box2DBaseItem *box2DItem = dynamic_cast<Box2DBaseItem *>(item)) box2DItem->initialize(world); } m_initialized = true; }
BBox &zLayout::layoutSubProblems(LayoutProblem &prob, BBox &parent) { BBox &self = bbox; if(&parent == &self) self.parent = 0; else { self.clear(); self.parent = &parent; } Variable *rh = new Variable(); Variable *sv = new Variable(); Variable *ph = new Variable[getLayoutChildren()]; BBox **ch = new BBox*[getLayoutChildren()]; m_ch = ch; if(layoutH() == 0 || width() == 0) { printf("Impossible Layout...\n"); return self; } m_damaged_layout = false; rh->name = "row-height"; *rh = 100; sv->name = "scale-variable"; sv->priority = 200; prob.addBox(self); prob.addVariable(sv); prob.addVariable(rh); int j=0; for(int i=0; i<childItems().size(); ++i) { QObject *obj = childItems()[i]; //printf("layout = '%s'\n", obj->metaObject()->className()); if(QString("QQuickRepeater") == obj->metaObject()->className()) continue; if(QString("zImplicitLabel") == obj->metaObject()->className()) continue; QVariant aspect_ = obj->property("aspect"); QVariant scale_ = obj->property("zscale"); QVariant expandable_ = obj->property("expandable"); float aspect = 1.0; float scale = 1.0; bool expandable = false; if(aspect_.canConvert<double>()) aspect = aspect_.toDouble(); if(scale_.canConvert<double>()) scale = scale_.toDouble(); if(expandable_.canConvert<bool>()) expandable = expandable_.toBool(); zWidget *obj_ = dynamic_cast<zWidget*>(obj); if(obj_) ch[j] = &obj_->layoutSubProblems(prob, self); else ch[j] = new BBox; if(!expandable && !m_vertical) *sv = ch[j]->h/scale; else if(m_vertical) *sv = ch[j]->h/scale; if(m_vertical) { if(j == 0) { ch[j]->y = 0; } else { ch[j]->y = ch[j-1]->y + ch[j-1]->h; } } else { if(j == 0) { ch[j]->x = 0; } else { ch[j]->x = ch[j-1]->x + ch[j-1]->w; } } ch[j]->parent = &self; if(m_vertical) { ch[j]->x = 0.5*ph[j]; ch[j]->w <= self.w-ph[j]; } else { ch[j]->y = 0.5*ph[j]; ch[j]->h <= self.h-ph[j]; } ph[j].name = "pad-height"; ph[j].priority = 120; prob.addBox(*ch[j]); prob.addVariable(ph+j); //layoutBoundBox(layout, aspect, scale); //if(expandable) { // layoutExpandable(layout); //} j++; } return bbox; }
//virtual QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant &value) { if (change == ItemPositionChange && scene()) { // calculate new position. const int trackHeight = KdenliveSettings::trackheight(); QPointF start = sceneBoundingRect().topLeft(); QPointF newPos = value.toPointF(); //kDebug()<<"REAL:"<<start.x()<<", PROPOSED:"<<(int)(start.x() - pos().x() + newPos.x()); int xpos = projectScene()->getSnapPointForPos((int)(start.x() + newPos.x() - pos().x()), KdenliveSettings::snaptopoints()); xpos = qMax(xpos, 0); //kDebug()<<"GRP XPOS:"<<xpos<<", START:"<<start.x()<<",NEW:"<<newPos.x()<<"; SCENE:"<<scenePos().x()<<",POS:"<<pos().x(); newPos.setX((int)(pos().x() + xpos - (int) start.x())); //int startTrack = (start.y() + trackHeight / 2) / trackHeight; int realTrack = (start.y() + newPos.y() - pos().y()) / trackHeight; int proposedTrack = newPos.y() / trackHeight; int correctedTrack = qMin(realTrack, projectScene()->tracksCount() - (int)(boundingRect().height() + 5) / trackHeight); correctedTrack = qMax(correctedTrack, 0); proposedTrack += (correctedTrack - realTrack); // Check if top item is a clip or a transition int offset = 0; int topTrack = -1; QList<QGraphicsItem *> children = childItems(); for (int i = 0; i < children.count(); i++) { int currentTrack = (int)(children.at(i)->scenePos().y() / trackHeight); if (children.at(i)->type() == AVWIDGET) { if (topTrack == -1 || currentTrack <= topTrack) { offset = 0; topTrack = currentTrack; } } else if (children.at(i)->type() == TRANSITIONWIDGET) { if (topTrack == -1 || currentTrack < topTrack) { offset = (int)(trackHeight / 3 * 2 - 1); topTrack = currentTrack; } } } newPos.setY((int)((proposedTrack) * trackHeight) + offset); //if (newPos == start) return start; /*if (newPos.x() < 0) { // If group goes below 0, adjust position to 0 return QPointF(pos().x() - start.x(), pos().y()); }*/ QPainterPath shape = groupShape(newPos - pos()); QList<QGraphicsItem*> collindingItems = scene()->items(shape, Qt::IntersectsItemShape); for (int i = 0; i < children.count(); i++) { collindingItems.removeAll(children.at(i)); } if (collindingItems.isEmpty()) return newPos; else { bool forwardMove = xpos > start.x(); int offset = 0; for (int i = 0; i < collindingItems.count(); i++) { QGraphicsItem *collision = collindingItems.at(i); if (collision->type() == AVWIDGET) { // Collision //kDebug()<<"// COLLISION WIT:"<<collision->sceneBoundingRect(); if (newPos.y() != pos().y()) { // Track change results in collision, restore original position return pos(); } AbstractClipItem *item = static_cast <AbstractClipItem *>(collision); if (forwardMove) { // Moving forward, determine best pos QPainterPath clipPath; clipPath.addRect(item->sceneBoundingRect()); QPainterPath res = shape.intersected(clipPath); offset = qMax(offset, (int)(res.boundingRect().width() + 0.5)); } else { // Moving backward, determine best pos QPainterPath clipPath; clipPath.addRect(item->sceneBoundingRect()); QPainterPath res = shape.intersected(clipPath); offset = qMax(offset, (int)(res.boundingRect().width() + 0.5)); } } } if (offset > 0) { if (forwardMove) { newPos.setX(newPos.x() - offset); } else { newPos.setX(newPos.x() + offset); } // If there is still a collision after our position adjust, restore original pos collindingItems = scene()->items(groupShape(newPos - pos()), Qt::IntersectsItemShape); for (int i = 0; i < children.count(); i++) { collindingItems.removeAll(children.at(i)); } for (int i = 0; i < collindingItems.count(); i++) if (collindingItems.at(i)->type() == AVWIDGET) return pos(); } return newPos; } } return QGraphicsItemGroup::itemChange(change, value); }
int QAccessibleQuickItem::indexOfChild(const QAccessibleInterface *iface) const { QList<QQuickItem*> kids = childItems(); return kids.indexOf(static_cast<QQuickItem*>(iface->object())); }