int AbstractClipItem::mouseOverKeyFrames(QPointF pos, double maxOffset) { const QRectF br = sceneBoundingRect(); double maxw = br.width() / cropDuration().frames(m_fps); double maxh = br.height() / 100.0 * m_keyframeFactor; if (m_keyframes.count() > 0) { QMap<int, int>::const_iterator i = m_keyframes.constBegin(); double x1; double y1; while (i != m_keyframes.constEnd()) { x1 = br.x() + maxw * (i.key() - cropStart().frames(m_fps)); y1 = br.bottom() - (i.value() - m_keyframeOffset) * maxh; if (qAbs(pos.x() - x1) < maxOffset && qAbs(pos.y() - y1) < 10) { setToolTip('[' + QString::number((GenTime(i.key(), m_fps) - cropStart()).seconds(), 'f', 2) + i18n("seconds") + ", " + QString::number(i.value(), 'f', 1) + ']'); return i.key(); } else if (x1 > pos.x()) { break; } ++i; } } setToolTip(QString()); return -1; }
void AutoBlend::init() { // Add widget auto toolsWidgetContainer = new QWidget(); widget = new Ui::AutoBlendWidget(); widget->setupUi(toolsWidgetContainer); widgetProxy = new QGraphicsProxyWidget(this); widgetProxy->setWidget(toolsWidgetContainer); // Place at bottom left corner auto delta = widgetProxy->sceneBoundingRect().bottomLeft() - scene()->views().front()->rect().bottomLeft(); widgetProxy->moveBy(-delta.x(), -delta.y()); // Fill categories box { for(auto cat : document->categories.keys()){ widget->categoriesBox->insertItem(widget->categoriesBox->count(), cat); } int idx = widget->categoriesBox->findText(document->categoryOf(document->firstModelName())); widget->categoriesBox->setCurrentIndex(idx); } // Create gallery of shapes gallery = new Gallery(this, QRectF(0,0,this->bounds.width(), 220)); // Create container that holds results results = new Gallery(this, QRectF(0,0, this->bounds.width(), bounds.height() - gallery->boundingRect().height()), QRectF(0,0,256,256), true); results->moveBy(0, gallery->boundingRect().height()); // Gallery on top of results gallery->setZValue(results->zValue() + 10); auto dropShadow = new QGraphicsDropShadowEffect(); dropShadow->setOffset(0, 5); dropShadow->setColor(QColor(0, 0, 0, 150)); dropShadow->setBlurRadius(10); gallery->setGraphicsEffect(dropShadow); // Connect UI with actions { connect(widget->categoriesBox, &QComboBox::currentTextChanged, [&](QString text){ document->currentCategory = text; }); connect(widget->analyzeButton, &QPushButton::pressed, [&](){ document->computePairwise(widget->categoriesBox->currentText()); }); // Default view angle { // Camera target and initial position auto camera = new Eigen::Camera(); auto frame = camera->frame(); frame.position = Eigen::Vector3f(-1, 0, 0.5); camera->setTarget(Eigen::Vector3f(0, 0, 0.5)); camera->setFrame(frame); int deltaZoom = document->extent().length() * 1.0; // Default view angle double theta1 = acos(-1) * 0.75; double theta2 = acos(-1) * 0.10; camera->rotateAroundTarget(Eigen::Quaternionf(Eigen::AngleAxisf(theta1, Eigen::Vector3f::UnitY()))); camera->zoom(-(4+deltaZoom)); camera->rotateAroundTarget(Eigen::Quaternionf(Eigen::AngleAxisf(theta2, Eigen::Vector3f::UnitX()))); auto cp = camera->position(); cameraPos = QVector3D(cp[0], cp[1], cp[2]); // Camera settings camera->setViewport(128, 128); Eigen::Matrix4f p = camera->projectionMatrix(); Eigen::Matrix4f v = camera->viewMatrix().matrix(); p.transposeInPlace(); v.transposeInPlace(); cameraMatrix = QMatrix4x4(p.data()) * QMatrix4x4(v.data()); } connect(document, &Document::categoryAnalysisDone, [=](){ if (gallery == nullptr) return; // Fill gallery gallery->clearThumbnails(); auto catModels = document->categories[document->currentCategory].toStringList(); for (auto targetName : catModels) { auto targetModel = document->cacheModel(targetName); auto t = gallery->addTextItem(targetName); QVariantMap data = t->data; data["targetName"].setValue(targetName); t->setData(data); t->setCamera(cameraPos, cameraMatrix); t->setFlag(QGraphicsItem::ItemIsSelectable); // Add parts of target shape for (auto n : targetModel->nodes){ t->addAuxMesh(toBasicMesh(targetModel->getMesh(n->id), n->vis_property["color"].value<QColor>())); } scene()->update(t->sceneBoundingRect()); } scene()->update(this->sceneBoundingRect()); QTimer::singleShot(500, [=]{ gallery->update(); }); }); // Do blend connect(widget->blendButton, SIGNAL(pressed()), SLOT(doBlend())); } }
void PianoKey::press(bool f){ if(f != is_pressed){ is_pressed = f; scene()->update(sceneBoundingRect());//important! }// to be continued to add sound }
void k9CanvasSprite::mouseMoveEvent ( QGraphicsSceneMouseEvent * event ) { QRectF oldRect=sceneBoundingRect(); //oldRect.adjust(pos().x(),pos().y(),pos().x(),pos().y()); QPointF offset; QSizeF s(m_pixmap->pixmap().size()); switch(m_resize) { case STL: offset= event->scenePos() - event->lastScenePos(); setPos(pos()+offset); s-=QSize(offset.x(),offset.y()); if (s.width()>0 && s.height()>0) { m_pixmap->setPixmap(m_bPixmap.scaled(s.toSize())); } break; case SBL: offset= event->scenePos() - event->lastScenePos(); setPos(pos().x()+offset.x(),pos().y()); s-=QSize(offset.x(),-offset.y()); if (s.width()>0 && s.height()>0) { m_pixmap->setPixmap(m_bPixmap.scaled(s.toSize())); } break; case STR: offset= event->scenePos() - event->lastScenePos(); setPos(pos().x(),pos().y()+offset.y()); s+=QSize(offset.x(),-offset.y()); if (s.width()>0 && s.height()>0) { m_pixmap->setPixmap(m_bPixmap.scaled(s.toSize())); } break; case SBR: offset= event->scenePos() - event->lastScenePos(); s+=QSize(offset.x(),offset.y()); if (s.width()>0 && s.height()>0) { m_pixmap->setPixmap(m_bPixmap.scaled(s.toSize())); } break; case STC: offset=QPointF(0,event->scenePos().y()-event->lastScenePos().y()); setPos(pos().x(),pos().y()+offset.y()); s-=QSize(offset.x(),offset.y()); if (s.width()>0 && s.height()>0) { m_pixmap->setPixmap(m_bPixmap.scaled(s.toSize())); } break; case SBC: offset=QPointF(0,event->scenePos().y()-event->lastScenePos().y()); s+=QSize(offset.x(),offset.y()); if (s.width()>0 && s.height()>0) { m_pixmap->setPixmap(m_bPixmap.scaled(s.toSize())); } break; case SML: offset=QPointF(event->scenePos().x()-event->lastScenePos().x(),0); setPos(pos().x()+offset.x(),pos().y()); s-=QSize(offset.x(),offset.y()); if (s.width()>0 && s.height()>0) { m_pixmap->setPixmap(m_bPixmap.scaled(s.toSize())); } break; case SMR: offset=QPointF(event->scenePos().x()-event->lastScenePos().x(),0); s+=QSize(offset.x(),offset.y()); m_pixmap->setPixmap(m_bPixmap.scaled(s.toSize())); break; default: break; } if (m_resize != SNONE) { setTextPosition(m_textPosition); update(boundingRect()); scene()->update(oldRect); }else QGraphicsItemGroup::mouseMoveEvent(event); }
QPointF GraphicsPortItem::getConnectionScenePos() const { QRectF sceneRect = sceneBoundingRect(); return (isInput ? QPointF(sceneRect.center().x(), sceneRect.top()) : QPointF(sceneRect.center().x(), sceneRect.bottom())); }
bool GraphicsItemRenderer::write() { scene()->update(sceneBoundingRect()); //update(); //does not cause an immediate paint. my not redraw. return true; }
/** @return the minimum, margin-less rectangle this part can fit into, in scene coordinates. It is different from boundingRect() because it is not supposed to imply any margin, and it is different from shape because it is a regular rectangle, not a complex shape. */ QRectF PartTerminal::sceneGeometricRect() const { return(sceneBoundingRect()); }
//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); }
QPoint LabelCanvas::center() const { return sceneBoundingRect().center().toPoint(); }
void Thumbnail::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *widget) { QRectF parentRect = parentItem()->sceneBoundingRect(); // Skip drawing thumbnails outside their parents if (!sceneBoundingRect().intersects(parentRect)) return; prePaint(painter, widget); // Draw image if(!img.isNull()) { auto imgRect = QRectF(img.rect()); imgRect.moveCenter(rect.center()); painter->drawImage(imgRect.topLeft(), img); } // Draw 3D mesh if(mesh.points.size() || auxMeshes.size()) { if (img.isNull() || isTempImage) { auto glwidget = (Viewer*)widget; if (glwidget) { QOpenGLContext context; context.setShareContext(glwidget->context()); context.setFormat(glwidget->format()); context.create(); QOffscreenSurface m_offscreenSurface; m_offscreenSurface.setFormat(context.format()); m_offscreenSurface.create(); context.makeCurrent(&m_offscreenSurface); QOpenGLFramebufferObjectFormat fboformat; fboformat.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); QOpenGLFramebufferObject renderFbo(rect.width() * 2, rect.height() * 2, fboformat); renderFbo.bind(); glwidget->glEnable(GL_DEPTH_TEST); glwidget->glEnable(GL_BLEND); glwidget->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glwidget->glCullFace(GL_BACK); glwidget->glClearColor(0,0,0,0); glwidget->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glwidget->glViewport(0, 0, renderFbo.size().width(), renderFbo.size().height()); if(mesh.points.size()) glwidget->drawTriangles(mesh.color, mesh.points, mesh.normals, pvm); // Draw aux meshes for (auto auxmesh : auxMeshes) glwidget->drawTriangles(auxmesh.color, auxmesh.points, auxmesh.normals, pvm); glwidget->glDisable(GL_DEPTH_TEST); glwidget->glFlush(); renderFbo.release(); this->setImage( renderFbo.toImage().scaledToWidth(rect.width(), Qt::SmoothTransformation) ); // Thanks for sharing! glwidget->makeCurrent(); } /*painter->beginNativePainting(); auto glwidget = (Viewer*)widget; if (glwidget) { // Draw mesh auto r = sceneBoundingRect(); auto v = scene()->views().first(); QPoint viewDelta = v->mapFromScene(r.topLeft()); if (viewDelta.manhattanLength() > 5) r.moveTopLeft(viewDelta); glwidget->eyePos = eye; glwidget->pvm = pvm; glwidget->glViewport(r.left(), v->height() - r.height() - r.top(), r.width(), r.height()); // Clipping OpenGL glwidget->glEnable(GL_SCISSOR_TEST); glwidget->glScissor(parentRect.x(), v->height() - parentRect.height() - parentRect.top(), parentRect.width(), parentRect.height()); glwidget->glClear(GL_DEPTH_BUFFER_BIT); glwidget->drawTriangles(mesh.color, mesh.points, mesh.normals, pvm); // Draw aux meshes for (auto auxmesh : auxMeshes) { glwidget->drawTriangles(auxmesh.color, auxmesh.points, auxmesh.normals, pvm); } glwidget->glDisable(GL_SCISSOR_TEST); } painter->endNativePainting();*/ } } // Draw the caption if(caption.size()) { painter->setPen(QPen(Qt::white,1)); auto textRect = rect; textRect.setHeight(painter->fontMetrics().height() * 1.25); textRect.moveBottom(rect.height() - textRect.height() * 0.5); painter->drawText(textRect, caption, Qt::AlignVCenter | Qt::AlignHCenter); } postPaint(painter, widget); }
void ArrangeItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) { m_prevPos = pos(); m_prevRect = m_rect; qreal x = event->scenePos().x(); qreal y = event->scenePos().y(); QPointF position = pos(); qreal diffx = (x - position.x()) / 2.0; qreal diffy = (y - position.y()) / 2.0; qreal diffxw = (x - (position.x() + m_rect.width())); qreal diffyw = (y - (position.y() + m_rect.height())); prepareGeometryChange(); switch (m_mode) { case C_TL: setPos(position.x() + diffx, position.y() + diffy); m_rect.setHeight(m_rect.height() - diffy); m_rect.setWidth(m_rect.width() - diffx); break; case C_TR: setPos(position.x(), position.y() + diffy); m_rect.setHeight(m_rect.height() - diffy); m_rect.setWidth(m_rect.width() + diffxw/2.0); break; case C_BL: setPos(position.x() + diffxw/2.0, position.y()); m_rect.setHeight(m_rect.height() + diffyw/2.0); m_rect.setWidth(m_rect.width() - diffxw/2.0); break; case C_BR: m_rect.setHeight(m_rect.height() + diffyw/2.0); m_rect.setWidth(m_rect.width() + diffxw/2.0); break; case C_T: setPos(position.x(), position.y() + diffy); m_rect.setHeight(m_rect.height() - diffy); break; case C_B: m_rect.setHeight(m_rect.height() + diffyw); break; case C_L: setPos(position.x()+diffx, position.y()); m_rect.setWidth(m_rect.width() - diffx); break; case C_R: m_rect.setWidth(m_rect.width() + diffxw); break; case C_C: default: QGraphicsItem::mouseMoveEvent(event); } // scene boundaries QRectF sc(scene()->sceneRect()); QRectF it(sceneBoundingRect()); if (it.x() < sc.x() || it.y() < sc.y() || it.width()+it.x() > sc.width() || it.height()+it.y() > sc.height()) { setPos(m_prevPos); m_rect = m_prevRect; return; } // colliding plugins/items QList<QGraphicsItem*> colliding = collidingItems(); foreach (QGraphicsItem* i, colliding) { ArrangeItem * item = dynamic_cast<ArrangeItem*>(i); if (item && item->editable()) { setPos(m_prevPos); m_rect = m_prevRect; return; } }
void DynCircleAttr::compile(QSqlDatabase &db, int nSceneId, int &count, int index)//编译的时候保存item到数据库 { count++; QVisableItem::compile(db, nSceneId, count, index); int itemId = count; if(sPro.enableTouch && !sPro.byGroups_T) { //触控受位控制 增一个地址表 count++; } if(sPro.bNotice) { //触控解锁通知到地址 增加一个地址表 count++; } if(sPro.enableVisable && !sPro.byGroups_V) { //显现受位控制 增加一个地址表 count++; } QSqlQuery sqlquery(db); bool result = sqlquery.prepare("INSERT INTO dynamicRound(nItemId,nSceneId,nAlpha," "nCpXpos,nCpYpos,nRadius,nFillColor,nUseFill,nRimColor," "nRimWidth,nUsePosCtrl,mCpXDataAddr,mCpYDataAddr," "mRadiusDataAddr,nUseSizeCtrl,nAreaLp,nAreaTp,nAreaWidth," "nAreaHeight,nAreaColor,nZvalue,nCollidindId,nShowPropId)" "VALUES(:nItemId,:nSceneId,:nAlpha," ":nCpXpos,:nCpYpos,:nRadius,:nFillColor,:nUseFill,:nRimColor," ":nRimWidth,:nUsePosCtrl,:mCpXDataAddr,:mCpYDataAddr," ":mRadiusDataAddr,:nUseSizeCtrl,:nAreaLp,:nAreaTp,:nAreaWidth," ":nAreaHeight,:nAreaColor,:nZvalue,:nCollidindId,:nShowPropId)"); qDebug() << "sqlquery.prepare" << result; int num = count; int temp; short leftCp; short topCp; short width; short height; short radius; sqlquery.bindValue(":nItemId", QVariant(itemId)); //表id sqlquery.bindValue(":nSceneId", QVariant(nSceneId)); //scene id sqlquery.bindValue(":nAlpha", QVariant(m_nAlpha)); //alpha QRectF rect = sceneBoundingRect();//相对场景的坐标及高宽 width = rect.width(); height = rect.height(); leftCp = rect.left() + width/2; topCp = rect.top() + height/2; radius = width < height ? (width/2) : (height/2); sqlquery.bindValue(":nCpXpos", QVariant(leftCp));//left sqlquery.bindValue(":nCpYpos", QVariant(topCp));//top sqlquery.bindValue(":nRadius", QVariant(radius));//radius temp =ColorToInt(m_nFillColor); sqlquery.bindValue(":nFillColor", QVariant(temp));// if(m_bFillColor) { sqlquery.bindValue(":nUseFill", QVariant(1));// } else { sqlquery.bindValue(":nUseFill", QVariant(0));// } temp =ColorToInt(m_nFrameColor); sqlquery.bindValue(":nRimColor", QVariant(temp));// sqlquery.bindValue(":nRimWidth", QVariant(m_nFrameWidth));// if(m_bPosCtrl)//位置控制开 { sqlquery.bindValue(":nUsePosCtrl", QVariant(1));// num++; sqlquery.bindValue(":mCpXDataAddr", QVariant(num));// num++; sqlquery.bindValue(":mCpYDataAddr", QVariant(num));// } else { sqlquery.bindValue(":nUsePosCtrl", QVariant(0));// sqlquery.bindValue(":mCpXDataAddr", QVariant(0));// sqlquery.bindValue(":mCpYDataAddr", QVariant(0));// } if(m_bSizeCtrl) { sqlquery.bindValue(":nUseSizeCtrl", QVariant(1));// num++; sqlquery.bindValue(":mRadiusDataAddr", QVariant(num));// } else { sqlquery.bindValue(":nUseSizeCtrl", QVariant(0));// sqlquery.bindValue(":mRadiusDataAddr", QVariant(0));// } //sqlquery.bindValue(":nAreaLp", QVariant(m_nBeginX));// //sqlquery.bindValue(":nAreaTp", QVariant(m_nBeginY));// //sqlquery.bindValue(":nAreaWidth", QVariant(m_nWidth));// //sqlquery.bindValue(":nAreaHeight", QVariant(m_nHeight));// sqlquery.bindValue(":nAreaLp", QVariant(rect.left()));// sqlquery.bindValue(":nAreaTp", QVariant(rect.top()));// sqlquery.bindValue(":nAreaWidth", QVariant(rect.width()));// sqlquery.bindValue(":nAreaHeight", QVariant(rect.height()));// temp =ColorToInt(m_nBgColor); sqlquery.bindValue(":nAreaColor", QVariant(temp));// sqlquery.bindValue(":nZvalue", QVariant(zValue()));// sqlquery.bindValue(":nCollidindId", QVariant(index));// sqlquery.bindValue(":nShowPropId", QVariant(0));// bool result1 = false; result1 = sqlquery.exec(); qDebug() << "insert table :" << result1 << endl; int id = count; if(m_bPosCtrl)//位置控制开 { count++; //修改地址编译参数 ADDR_PARAMENTS stParams; stParams.id = count; stParams.itemId = itemId; stParams.eType = OBJ_ITEM; stParams.eRWtype = SCENE_CONTROL_LOOP_R; stParams.addrNum = -1; m_addrH.compile(db, stParams); //m_addrH.compile(db, count, 0, OBJ_ITEM); count++; //修改地址编译参数 //ADDR_PARAMENTS stParams; stParams.id = count; stParams.itemId = itemId; stParams.eType = OBJ_ITEM; stParams.eRWtype = SCENE_CONTROL_LOOP_R; stParams.addrNum = -1; m_addrV.compile(db, stParams); //m_addrV.compile(db, count, 0, OBJ_ITEM); } if(m_bSizeCtrl) { count++; //修改地址编译参数 ADDR_PARAMENTS stParams; stParams.id = count; stParams.itemId = itemId; stParams.eType = OBJ_ITEM; stParams.eRWtype = SCENE_CONTROL_LOOP_R; stParams.addrNum = -1; m_addrCircle.compile(db, stParams); //m_addrCircle.compile(db, count, 0, OBJ_ITEM); } }
void CalloutPointerItem::drawPointerPoly() { QLineF linef = QLineF(points[Base],points[Tip]); removeFromGroup(shaft); shaft->setLine(linef); addToGroup(shaft); QPolygonF poly; poly << QPointF(-2*grabSize(), 0); poly << QPointF(-2*grabSize(),grabSize()/2); poly << QPointF(grabSize()/2,0); poly << QPointF(-2*grabSize(),-grabSize()/2); poly << QPointF(-2*grabSize(),0); removeFromGroup(head); head->setPolygon(poly); qreal x = points[Tip].x()-points[Base].x(); qreal y = points[Tip].y()-points[Base].y(); qreal h = sqrt(x*x+y*y); qreal angle = 180*acos(x/h); qreal pi = 22.0/7; if (x == 0) { if (y < 0) { angle = 270.0; } else { angle = 90.0; } } else if (y == 0) { if (x < 0) { angle = 180.0; } else { angle = 0.0; } } else { volatile qreal h = sqrt(x*x+y*y); if (x > 0) { if (y > 0) { angle = 180-180*acos(-x/h)/pi; } else { angle = 180+180*acos(-x/h)/pi; } } else { if (y > 0) { angle = 180*acos(x/h)/pi; } else { angle = -180*acos(x/h)/pi; } } } head->resetTransform(); head->rotate(angle); head->setPos(points[Tip]); addToGroup(head); QRectF rect = sceneBoundingRect(); view->updateSceneRect(sceneBoundingRect()); }
void QLineItem::compile(QSqlDatabase &db, int nSceneId,int &count,int index) { count++; //QBasicGraphicsItem::compile(db, nSceneId, count, index); QSqlQuery sqlquery(db); sqlquery.prepare("INSERT INTO line(nItemNumber ,nSceneId ,eLineClass ,eLineType ,nLineWidth ," "nLineColor ,eLineArrow ,nAlpha , eLinePointType ,nZvalue,nCollidindId," "nStartX ,nStartY ,nWidth ,nHeight )" "VALUES (:nItemNumber ,:nSceneId ,:eLineClass ,:eLineType ,:nLineWidth ," ":nLineColor ,:eLineArrow ,:nAlpha , :eLinePointType,:nZvalue,:nCollidindId," ":nStartX ,:nStartY ,:nWidth ,:nHeight)"); sqlquery.bindValue(":nItemNumber",QVariant(count));// 表 id sqlquery.bindValue(":nSceneId",QVariant(nSceneId));// 所在场景 id sqlquery.bindValue(":eLineClass",QVariant(1)); //1 代表类型为直线 sqlquery.bindValue(":eLineType",QVariant(nLineType+1));// 线形 sqlquery.bindValue(":nLineWidth",QVariant(getLineWidth()));// 线宽 sqlquery.bindValue(":nLineColor",QVariant(ColorToInt(getLineColor()))); //颜色 sqlquery.bindValue(":eLineArrow",QVariant(m_eLineEndArrowType+1));// 箭头 sqlquery.bindValue(":nAlpha",QVariant(getAlpha()));// 透明度 sqlquery.bindValue(":eLinePointType",QVariant(m_eLineEndArrowType+1)); //端点类型 sqlquery.bindValue(":nZvalue",QVariant(zValue()));//层次 sqlquery.bindValue(":nCollidindId",QVariant(index));//碰撞ID QRectF rect = sceneBoundingRect(); if(getLineWidth() == 1) { sqlquery.bindValue(":nStartX",QVariant(rect.x()-1));//x sqlquery.bindValue(":nStartY",QVariant(rect.y()-1));//y sqlquery.bindValue(":nWidth",QVariant(rect.width()+2));//w sqlquery.bindValue(":nHeight",QVariant(rect.height()+2));//h } else { sqlquery.bindValue(":nStartX",QVariant(rect.x()));//x sqlquery.bindValue(":nStartY",QVariant(rect.y()));//y sqlquery.bindValue(":nWidth",QVariant(rect.width()));//w sqlquery.bindValue(":nHeight",QVariant(rect.height()));//h } bool result = false; result = sqlquery.exec(); qDebug() << "insert line table :"<<result; sqlquery.prepare("INSERT INTO point(nItemId,nPosX,nPosY,nOrder,ePointType)" "VALUES (:nItemId ,:nPosX ,:nPosY ,:nOrder ,:ePointType )"); for(int i=0; i<2; i++) { QPointF pt = this->path().pointAtPercent(i); pt = mapToScene(pt); sqlquery.bindValue(":nItemId",QVariant(count));// item表 id sqlquery.bindValue(":nPosX",QVariant((int)pt.x()));// X sqlquery.bindValue(":nPosY",QVariant((int)pt.y())); //Y sqlquery.bindValue(":nOrder",QVariant(i));// 顺序 sqlquery.bindValue(":ePointType",QVariant(1));// 显示点 result = sqlquery.exec(); qDebug() << "insert point table :"<<result; } SamDrawScene *pScene = dynamic_cast<SamDrawScene *>(scene()); if(pScene && pScene->nIsSceneOrWindow == 2) { //是自定义键盘的item //先新建键盘——item关联表 item表在派生类中创建 //QSqlQuery sqlquery(db); sqlquery.prepare("INSERT INTO kbAndItem(nKeyBoardId , nItemId ,nId,nItemTableType ) " "VALUES (:nKeyBoardId ,:nItemId ,:nId,:nItemTableType)"); sqlquery.bindValue(":nKeyBoardId",QVariant(nSceneId)); sqlquery.bindValue(":nItemId",QVariant(count)); sqlquery.bindValue(":nId",QVariant(id())); sqlquery.bindValue(":nItemTableType",QVariant((int)SAM_DRAW_OBJECT_LINE)); bool result = false; result = sqlquery.exec(); qDebug() << "insert kbAndItem table :"<<result; } if(pScene && pScene->nIsSceneOrWindow != 2) { //窗口或者场景item //先新建键盘——item关联表 //item表在派生类中创建 //QSqlQuery sqlquery(db); sqlquery.prepare("INSERT INTO sceneAndItem(nSceneId,nItemId,nId,nItemTableType)" "VALUES(:nSceneId,:nItemId,:nId,:nItemTableType)"); sqlquery.bindValue(":nSceneId",QVariant(nSceneId)); sqlquery.bindValue(":nItemId",QVariant(count)); sqlquery.bindValue(":nId",QVariant(id())); //int t = this->GroupType(); sqlquery.bindValue(":nItemTableType",QVariant((int)SAM_DRAW_OBJECT_LINE)); bool result = false; result = sqlquery.exec(); qDebug() << "insert sceneAndItem table :"<<result; } }
void Sketch::init() { // Add four views int numViews = 4; for(int i = 0; i < numViews; i++){ auto type = SketchViewType(SketchViewType::VIEW_TOP + i); auto view = new SketchView(document, this, type); views << view; } resizeViews(); // Add sketching UI elements auto toolsWidgetContainer = new QWidget(); toolsWidget = new Ui::SketchToolsWidget(); toolsWidget->setupUi(toolsWidgetContainer); auto toolsWidgetProxy = new QGraphicsProxyWidget(this); toolsWidgetProxy->setWidget(toolsWidgetContainer); // Place at bottom left corner auto delta = toolsWidgetProxy->sceneBoundingRect().bottomLeft() - scene()->views().front()->rect().bottomLeft(); toolsWidgetProxy->moveBy(-delta.x(), -delta.y()); // Add duplication tool dupToolWidget = new SketchDuplicate(); dupToolWidgetProxy = new QGraphicsProxyWidget(this); dupToolWidgetProxy->setWidget(dupToolWidget); auto dupDelta = toolsWidgetProxy->pos() + QPointF(toolsWidgetProxy->size().width(),0); dupToolWidgetProxy->moveBy(dupDelta.x(), dupDelta.y()); dupToolWidgetProxy->setVisible(false); dupToolWidgetProxy->setFlags(QGraphicsItem::ItemIsMovable); //dupToolWidgetProxy->setWindowFlags(Qt::Window); // Connect UI with sketch views { // Sketching new parts { connect(toolsWidget->curveButton, &QPushButton::pressed, [&](){ for(auto & v : views) v->setSketchOp(SKETCH_CURVE); }); connect(toolsWidget->sheetButton, &QPushButton::pressed, [&](){ for (auto & v : views) v->setSketchOp(SKETCH_SHEET); }); // Sketching options connect(toolsWidget->isFlat, &QCheckBox::toggled, [&](bool checked){ for(auto & v : views) v->setProperty("meshingIsFlat", checked); }); connect(toolsWidget->isSquare, &QCheckBox::toggled, [&](bool checked){ for(auto & v : views) v->setProperty("meshingIsSquare", checked); }); connect(toolsWidget->isThick, static_cast<void (QComboBox::*)(int index)>(&QComboBox::currentIndexChanged), [&](int level){ for(auto & v : views) v->setProperty("meshingIsThick", QVariant::fromValue(level)); }); } // Modify { // Select parts connect(toolsWidget->selectButton, &QPushButton::pressed, [&](){ for (auto & v : views) v->setSketchOp(SELECT_PART); }); // Deform parts connect(toolsWidget->deformButton, &QPushButton::pressed, [&](){ for (auto & v : views) v->setSketchOp(DEFORM_SKETCH); }); // Transform parts connect(toolsWidget->transformButton, &QPushButton::pressed, [&](){ for (auto & v : views) v->setSketchOp(TRANSFORM_PART); }); // Normalize and place on ground connect(toolsWidget->placeGroundButton, &QPushButton::pressed, [&](){ document->placeOnGround(document->firstModelName()); }); // Find all possible edges connect(toolsWidget->edgesButton, &QPushButton::pressed, [&](){ ModelConnector m(document->getModel(document->firstModelName())); }); } // IO { connect(toolsWidget->loadButton, &QPushButton::pressed, [&](){ QString filename = QFileDialog::getOpenFileName(0, "Load shape", "", "Shape graph (*.xml)"); if(filename.size()){ document->clearModels(); document->loadModel(filename); } }); connect(toolsWidget->saveButton, &QPushButton::pressed, [&](){ QString filename = QFileDialog::getSaveFileName(0, "Save shape", "", "Shape graph (*.xml)"); document->saveModel(document->firstModelName(), filename); }); } } // Duplicate tool UI { connect(toolsWidget->replicateButton, &QPushButton::toggled, [&](bool checked){ if(checked){ dupToolWidgetProxy->setVisible(true); emit(dupToolWidget->settingsChanged()); }else{ dupToolWidgetProxy->setVisible(false); } }); connect(dupToolWidget, &SketchDuplicate::settingsChanged, [&](){ QString dupOperation = dupToolWidget->dupOperation(); document->duplicateActiveNodeViz(document->firstModelName(), dupOperation); scene()->update(); }); connect(dupToolWidget, &SketchDuplicate::acceptedOperation, [&](){ dupToolWidgetProxy->setVisible(false); QString dupOperation = dupToolWidget->dupOperation(); document->duplicateActiveNode(document->firstModelName(), dupOperation); toolsWidget->replicateButton->setChecked(false); scene()->update(); }); } }
void MyShip::cllsn_dtctn() { QList<QGraphicsItem *> clldng_items = collidingItems(Qt::ItemSelectionMode::IntersectsItemShape); foreach(QGraphicsItem *i, clldng_items) { if (dynamic_cast<MyLife *>(i) && dynamic_cast<MyLife *>(i)->isVisible()) { ply_sf(const_cast<QString &>(MyRes::sf_lf_add)); lf++; dynamic_cast<MyLife *>(i)->hide(); } else if (dynamic_cast<MyMagic *>(i) && dynamic_cast<MyMagic *>(i)->isVisible()) { ply_sf(const_cast<QString &>(MyRes::sf_mgc_add)); activate_mgc(); dynamic_cast<MyMagic *>(i)->hide(); } else if (dynamic_cast<MyShield *>(i) && dynamic_cast<MyShield *>(i)->isVisible()) { ply_sf(const_cast<QString &>(MyRes::sf_shld_add)); activate_shld(); dynamic_cast<MyShield *>(i)->hide(); } else if (dynamic_cast<MyShip *>(i) && dynamic_cast<MyShip *>(i)->isVisible() && !lf_tmr->isActive()) { ply_sf(const_cast<QString &>(MyRes::sf_shp_shp_add)); lf--; activate_lf(); } else if (dynamic_cast<MyShipShield *>(i) && dynamic_cast<MyShipShield *>(i)->isVisible() && dynamic_cast<MyShipShield *>(i) != shpshld) { ply_sf(const_cast<QString &>(MyRes::sf_expln_shpshld_add)); if (!lf_tmr->isActive()) { lf--; activate_lf(); } dynamic_cast<MyShipShield *>(i)->dstry(); } else if (dynamic_cast<MyStar *>(i) && dynamic_cast<MyStar *>(i)->isVisible()) { ply_sf(const_cast<QString &>(MyRes::sf_str_add)); scr++; dynamic_cast<MyStar *>(i)->hide(); } else if (dynamic_cast<MyAlien *>(i) && dynamic_cast<MyAlien *>(i)->isVisible()) { if (dynamic_cast<MyAlien *>(i)->getTyp() == 0) { ply_sf(const_cast<QString &>(MyRes::sf_expln_aln_bg_add)); MyExplosion *expln = new MyExplosion(const_cast<QSize *>(&MyRes::expln_aln_bg_size)); expln->setPos(dynamic_cast<MyAlien *>(i)->x() + (dynamic_cast<MyAlien *>(i)->pixmap().width() / 2) - (MyRes::expln_aln_bg_size.width() / 2), dynamic_cast<MyAlien *>(i)->y() + (dynamic_cast<MyAlien *>(i)->pixmap().height() / 2) - (MyRes::expln_aln_bg_size.height() / 2) + MyRes::expln_aln_bg_crrctn); scene()->addItem(expln); } else { ply_sf(const_cast<QString &>(MyRes::sf_expln_aln_smll_add)); MyExplosion *expln = new MyExplosion(const_cast<QSize *>(&MyRes::expln_aln_smll_size)); expln->setPos(dynamic_cast<MyAlien *>(i)->x() + (dynamic_cast<MyAlien *>(i)->pixmap().width() / 2) - (MyRes::expln_aln_smll_size.width() / 2), dynamic_cast<MyAlien *>(i)->y() + (dynamic_cast<MyAlien *>(i)->pixmap().height() / 2) - (MyRes::expln_aln_smll_size.height() / 2) + MyRes::expln_aln_smll_crrctn); scene()->addItem(expln); } if (!lf_tmr->isActive()) { lf--; activate_lf(); } dynamic_cast<MyAlien *>(i)->killTimer(dynamic_cast<MyAlien *>(i)->getTmr_id()); dynamic_cast<MyAlien *>(i)->hide(); } else if (dynamic_cast<MyAlienBoss *>(i) && dynamic_cast<MyAlienBoss *>(i)->isVisible()) { ply_sf(const_cast<QString &>(MyRes::sf_expln_astrd_add)); if (dynamic_cast<MyAlienBoss *>(i)->getStg() == 0) { MyExplosion *expln = new MyExplosion(const_cast<QSize *>(&MyRes::expln_astrd_size)); expln->setPos( dynamic_cast<MyAlienBoss *>(i)->x() + (dynamic_cast<MyAlienBoss *>(i)->pixmap().width() / 2) - (MyRes::expln_astrd_size.width() / 2), dynamic_cast<MyAlienBoss *>(i)->y() + (dynamic_cast<MyAlienBoss *>(i)->pixmap().height() / 2) - (MyRes::expln_astrd_size.height() / 2) + MyRes::expln_astrd_crrctn); expln->updt(); scene()->addItem(expln); } if (!lf_tmr->isActive()) { lf--; activate_lf(); } dynamic_cast<MyAlienBoss *>(i)->hide(); if (dynamic_cast<MyAlienBoss *>(i)->getStg() != 0) { for (int j = -1; j <= 1; j += 2) { MyAlienBoss *bss = new MyAlienBoss(dynamic_cast<MyAlienBoss *>(i)->getStg() - 1, j, j); if (j == -1) { bss->setPos(dynamic_cast<MyAlienBoss *>(i)->pos().x(), sceneBoundingRect().top() - 100); } else { bss->setPos(dynamic_cast<MyAlienBoss *>(i)->pos().x(), sceneBoundingRect().bottom()); } scene()->addItem(bss); } } } else if (dynamic_cast<MyAsteroid *>(i) && dynamic_cast<MyAsteroid *>(i)->isVisible()) { ply_sf(const_cast<QString &>(MyRes::sf_expln_astrd_add)); MyExplosion *expln = new MyExplosion(const_cast<QSize *>(&MyRes::expln_astrd_size)); expln->setPos( dynamic_cast<MyAsteroid *>(i)->x() + (dynamic_cast<MyAsteroid *>(i)->pixmap().width() / 2) - (MyRes::expln_astrd_size.width() / 2), dynamic_cast<MyAsteroid *>(i)->y() + (dynamic_cast<MyAsteroid *>(i)->pixmap().height() / 2) - (MyRes::expln_astrd_size.height() / 2) + MyRes::expln_astrd_crrctn); expln->updt(); scene()->addItem(expln); if (!lf_tmr->isActive()) { lf--; activate_lf(); } dynamic_cast<MyAsteroid *>(i)->hide(); } else if (dynamic_cast<MyBullet *>(i) && dynamic_cast<MyBullet *>(i)->getDir() == -1 && dynamic_cast<MyBullet *>(i)->isVisible()) { ply_sf(const_cast<QString &>(MyRes::sf_expln_lsr_add)); MyExplosion *expln = new MyExplosion(const_cast<QSize *>(&MyRes::expln_lsr_size)); expln->setPos(dynamic_cast<MyBullet *>(i)->x() + (dynamic_cast<MyBullet *>(i)->pixmap().width() / 2) - (MyRes::expln_lsr_size.width() / 2), dynamic_cast<MyBullet *>(i)->y() + (dynamic_cast<MyBullet *>(i)->pixmap().height() / 2) - (MyRes::expln_lsr_size.height() / 2) + MyRes::expln_lsr_crrctn); expln->updt(); scene()->addItem(expln); if (!lf_tmr->isActive()) { lf--; activate_lf(); } dynamic_cast<MyBullet *>(i)->hide(); } else if (dynamic_cast<MyGravityField *>(i) && dynamic_cast<MyGravityField *>(i)->isVisible()) { dynamic_cast<MyGravityField *>(i)->getPar()->setPos(pos().x() + pixmap().width() / 2 - dynamic_cast<MyGravityField *>(i)->boundingRect().width() / 2, pos().y() + pixmap().height() / 2 - dynamic_cast<MyGravityField *>(i)->boundingRect().height() / 2); } } }
//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); }
void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { if (None == mCurrentTool) return; QLineF move = QLineF(mStartingPoint, event->scenePos()); qreal moveX = move.length() * cos((move.angle() - mAngle) * PI / 180); qreal moveY = -move.length() * sin((move.angle() - mAngle) * PI / 180); qreal width = delegated()->boundingRect().width() * mTotalScaleX; qreal height = delegated()->boundingRect().height() * mTotalScaleY; if (mOperationMode == Scaling) { if(!rotating()) { mTranslateX = moveX; // Perform the resize if (resizingBottomRight()) { // ----------------------------------------------------- // ! We want to keep the aspect ratio with this resize ! // ----------------------------------------------------- qreal scaleX; qreal scaleY; if(!mMirrorX) { scaleX = (width + moveX) / width; } else { scaleX = (width - moveX) / width; } if(!mMirrorY) { scaleY = (height + moveY) / height; } else { scaleY = (height - moveY) / height; } qreal scaleFactor = (scaleX + scaleY) / 2; // Do not allow resizing of image size under frame size if (canResizeBottomRight(width, height, scaleFactor)) { if (mRespectRatio) { mScaleX = scaleFactor; mScaleY = scaleFactor; } else { mScaleX = scaleX; mScaleY = scaleY; } } } else if (resizingLeft() || resizingRight()) { if(width != 0) { qreal scaleX = 0.0; if(resizingLeft()) { scaleX = (width - moveX) / width; } else if(resizingRight()) { scaleX = (width + moveX) / width; } if(mDelegate->isFlippable() && qAbs(scaleX) != 0) { if((qAbs(width * scaleX)) < 2*mFrameWidth) { bool negative = (scaleX < 0)?true:false; if(negative) { if(mMirrorX) scaleX = 2*mFrameWidth/width; else scaleX = -2*mFrameWidth/width; } else { scaleX = -1; mFlippedX = !mFlippedX; } } mScaleX = scaleX; } else if (scaleX > 1 || (width * scaleX) > 2 * mFrameWidth) { mScaleX = scaleX; if(resizingLeft()) { mTranslateX = moveX; } } } } else if(resizingTop() || resizingBottom()) { if(height != 0) { qreal scaleY = 0.0; if(resizingTop()) { scaleY = (height - moveY) / height; } else if(resizingBottom()) { scaleY = (height + moveY) / height; } if(mDelegate->isFlippable() && qAbs(scaleY) != 0) { if((qAbs(height * scaleY)) < 2*mFrameWidth) { bool negative = (scaleY < 0)?true:false; if(negative) { if(mMirrorY) scaleY = 2*mFrameWidth/width; else scaleY = -2*mFrameWidth/width; } else { scaleY = -1; mFlippedY = !mFlippedY; } } mScaleY = scaleY; } else if (scaleY > 1 || (height * scaleY) > 2 * mFrameWidth) { mScaleY = scaleY; if(resizingTop()) { mTranslateY = moveY; } } } } } } if (rotating()) { mTranslateX = 0; mTranslateY = 0; QLineF startLine(sceneBoundingRect().center(), event->lastScenePos()); QLineF currentLine(sceneBoundingRect().center(), event->scenePos()); mAngle += startLine.angleTo(currentLine); if ((int)mAngle % 45 >= 45 - mAngleTolerance || (int)mAngle % 45 <= mAngleTolerance) { mAngle = qRound(mAngle / 45) * 45; mAngleOffset += startLine.angleTo(currentLine); if ((int)mAngleOffset % 360 > mAngleTolerance && (int)mAngleOffset % 360 < 360 - mAngleTolerance) { mAngle += mAngleOffset; mAngleOffset = 0; } } else if ((int)mAngle % 30 >= 30 - mAngleTolerance || (int)mAngle % 30 <= mAngleTolerance) { mAngle = qRound(mAngle / 30) * 30; mAngleOffset += startLine.angleTo(currentLine); if ((int)mAngleOffset % 360 > mAngleTolerance && (int)mAngleOffset % 360 < 360 - mAngleTolerance) { mAngle += mAngleOffset; mAngleOffset = 0; } } setCursorFromAngle(QString::number((int)mAngle % 360)); } else if (moving()) { mTranslateX = move.dx(); mTranslateY = move.dy(); moveLinkedItems(move); } if (mOperationMode == Scaling || moving() || rotating()) { QTransform tr = buildTransform(); if (resizingRight() || resizingBottom() || resizingBottomRight()) { QPointF ref; // we just detects coordinates of corner before and after scaling and then moves object at diff between them. if (resizingBottomRight() && (mMirrorX || mMirrorY)) { if (mFlippedX && !mMirrorX && mFlippedY)// && !mMirrorY) { mTranslateX += mInitialTransform.map(delegated()->boundingRect().bottomLeft()).x() - tr.map(delegated()->boundingRect().bottomLeft()).x(); mTranslateY += mInitialTransform.map(delegated()->boundingRect().bottomLeft()).y() - tr.map(delegated()->boundingRect().bottomLeft()).y(); } else if ((mFlippedX || mMirrorX) && (mFlippedY || mMirrorY)) { mTranslateX += mInitialTransform.map(delegated()->boundingRect().bottomRight()).x() - tr.map(delegated()->boundingRect().bottomRight()).x(); mTranslateY += mInitialTransform.map(delegated()->boundingRect().bottomRight()).y() - tr.map(delegated()->boundingRect().bottomRight()).y(); } else if (mFlippedX || mMirrorX) { mTranslateX += mInitialTransform.map(delegated()->boundingRect().topRight()).x() - tr.map(delegated()->boundingRect().topRight()).x(); mTranslateY += mInitialTransform.map(delegated()->boundingRect().topRight()).y() - tr.map(delegated()->boundingRect().topRight()).y(); } else if (mFlippedY || mMirrorY) { mTranslateX += mInitialTransform.map(delegated()->boundingRect().bottomLeft()).x() - tr.map(delegated()->boundingRect().bottomLeft()).x(); mTranslateY += mInitialTransform.map(delegated()->boundingRect().bottomLeft()).y() - tr.map(delegated()->boundingRect().bottomLeft()).y(); } else { mTranslateX += mInitialTransform.map(delegated()->boundingRect().bottomRight()).x() - tr.map(delegated()->boundingRect().bottomRight()).x(); mTranslateY += mInitialTransform.map(delegated()->boundingRect().bottomRight()).y() - tr.map(delegated()->boundingRect().bottomRight()).y(); } } else { mTranslateX += mInitialTransform.map(delegated()->boundingRect().topLeft()).x() - tr.map(delegated()->boundingRect().topLeft()).x(); mTranslateY += mInitialTransform.map(delegated()->boundingRect().topLeft()).y() - tr.map(delegated()->boundingRect().topLeft()).y(); } } else if (resizingTop() || resizingLeft()) { QPointF bottomRight = tr.map(delegated()->boundingRect().bottomRight()); QPointF fixedPoint = mInitialTransform.map(delegated()->boundingRect().bottomRight()); mTranslateX += fixedPoint.x() - bottomRight.x(); mTranslateY += fixedPoint.y() - bottomRight.y(); } delegated()->setTransform(buildTransform()); } else // resizing/resizing horizontally { if (resizingBottomRight()) { static QSizeF incV = QSizeF(); static QSizeF incH = QSizeF(); if (mMirrorX && mMirrorY) mCurrentTool = ResizeTop; else mCurrentTool = ResizeBottom; incV = resizeDelegate(moveX, moveY); mOriginalSize += incV; if (mMirrorX && mMirrorY) mCurrentTool = ResizeLeft; else mCurrentTool = ResizeRight; move = QLineF(event->lastScenePos(), event->scenePos()); moveX = move.length() * cos((move.angle() - mAngle) * PI / 180); moveY = -move.length() * sin((move.angle() - mAngle) * PI / 180); mFixedPoint = getFixedPointFromPos(); incH = resizeDelegate(moveX, moveY); mOriginalSize -= incV; mOriginalSize += incH; mCurrentTool = ResizeBottomRight; } else resizeDelegate(moveX, moveY); } event->accept(); }
void SeasideListItemLarge::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { Q_UNUSED(event); if (sceneBoundingRect().contains(event->scenePos())) emit clicked(); }