void AbstractClipItem::resizeEnd(int posx, bool /*emitChange*/) { GenTime durationDiff = GenTime(posx, m_fps) - endPos(); if (durationDiff == GenTime()) return; if (cropDuration() + durationDiff <= GenTime()) { durationDiff = GenTime() - (cropDuration() - GenTime(3, m_fps)); } m_info.cropDuration += durationDiff; m_info.endPos += durationDiff; setRect(0, 0, cropDuration().frames(m_fps) - 0.02, rect().height()); if (durationDiff > GenTime()) { QList <QGraphicsItem *> collisionList = collidingItems(Qt::IntersectsItemBoundingRect); bool fixItem = false; for (int i = 0; i < collisionList.size(); ++i) { if (!collisionList.at(i)->isEnabled()) continue; QGraphicsItem *item = collisionList.at(i); if (item->type() == type() && item->pos().x() > pos().x()) { GenTime diff = static_cast<AbstractClipItem*>(item)->startPos() - startPos(); if (fixItem == false || diff < m_info.cropDuration) { fixItem = true; m_info.cropDuration = diff; } } } if (fixItem) setRect(0, 0, cropDuration().frames(m_fps) - 0.02, rect().height()); } }
QPointF RelationItem::calcEndPoint(const Uid &end, const QPointF &otherEndPos, int nearestIntermediatePointIndex) { QGraphicsItem *endItem = m_diagramSceneModel->graphicsItem(end); QMT_CHECK(endItem); IIntersectionable *endObjectItem = dynamic_cast<IIntersectionable *>(endItem); QPointF endPos; if (endObjectItem) { DObject *endObject = m_diagramSceneModel->diagramController()->findElement<DObject>(end, m_diagramSceneModel->diagram()); QMT_CHECK(endObject); bool preferAxis = false; QPointF otherPos; if (nearestIntermediatePointIndex >= 0 && nearestIntermediatePointIndex < m_relation->intermediatePoints().size()) { otherPos = m_relation->intermediatePoints().at(nearestIntermediatePointIndex).pos(); preferAxis = true; } else { otherPos = otherEndPos; } bool ok = false; QLineF directLine(endObject->pos(), otherPos); if (preferAxis) { { QPointF axisDirection = GeometryUtilities::calcPrimaryAxisDirection(directLine); QLineF axis(otherPos, otherPos + axisDirection); QPointF projection = GeometryUtilities::calcProjection(axis, endObject->pos()); QLineF projectedLine(projection, otherPos); ok = endObjectItem->intersectShapeWithLine(projectedLine, &endPos); } if (!ok) { QPointF axisDirection = GeometryUtilities::calcSecondaryAxisDirection(directLine); QLineF axis(otherPos, otherPos + axisDirection); QPointF projection = GeometryUtilities::calcProjection(axis, endObject->pos()); QLineF projectedLine(projection, otherPos); ok = endObjectItem->intersectShapeWithLine(projectedLine, &endPos); } } if (!ok) { ok = endObjectItem->intersectShapeWithLine(directLine, &endPos); } if (!ok) { endPos = endItem->pos(); } } else { endPos = endItem->pos(); } return endPos; }
QImage * FusionCalques::fusionCalques(QList<QGraphicsItem *> list, QImage * im){ //copie image QImage * image = new QImage(*im); //variable QPoint origine; int w; int h; QGraphicsItem * it; QGraphicsPixmapItem * it2; QPixmap map; QImage item; float nivFusion, r, g, b, alpha; //récupération du niveau de transparence Contraste *fenetre = new Contraste; fenetre->show(); fenetre->activateWindow(); fenetre->exec(); if( fenetre->getCanceled() ){ fenetre->close(); return NULL; } else{ nivFusion= fenetre->getValue(); nivFusion= nivFusion/100.0; } //insertion for( int i=0; i<list.size(); i++){ it = list[i]; origine = it->pos().toPoint(); w = it->boundingRect().width(); h = it->boundingRect().height(); if( it->type() == 7 ){ it2 = (QGraphicsPixmapItem *)it; } else{ return NULL; } map = it2->pixmap(); item = map.toImage(); for (int j = origine.y(); j < origine.y()+h-1; ++j) { for (int i = origine.x(); i < origine.x()+w-1; ++i) { r = QColor(item.pixel(i-origine.x(),j-origine.y())).red()*(nivFusion) + (QColor(image->pixel(i,j)).red()*(1-nivFusion)); g = QColor(item.pixel(i-origine.x(),j-origine.y())).green()*(nivFusion) + (QColor(image->pixel(i,j)).green()*(1-nivFusion)); b = QColor(item.pixel(i-origine.x(),j-origine.y())).blue()*(nivFusion) + (QColor(image->pixel(i,j)).blue()*(1-nivFusion)); alpha = QColor(item.pixel(i-origine.x(),j-origine.y())).alpha()*(nivFusion) + (QColor(image->pixel(i,j)).alpha()*(1-nivFusion)); image->setPixel(i,j,qRgba(int(r+0.5),int(g+0.5),int(b+0.5),int(alpha+0.5))); } } } return image; }
void QGraphicsVolumeView::fitToImage(int sliceIdx, int volumeId) { if (_airImages != NULL && _airImages->Count() > 0) { // clear scene rect to recompute bounding box QRectF sceneRect = scene()->sceneRect(); if (_volumeDisplays.size() > 0) { QGraphicsItem* item = _volumeDisplays[0].GetSliceData<QGraphicsItem>(sliceIdx); QRectF viewport = item->boundingRect(); if (item != NULL) { if (sceneRect.width() > sceneRect.height()) { viewport.setHeight(sceneRect.height()); } else { viewport.setWidth(sceneRect.width()); } } fitInView(viewport, Qt::KeepAspectRatio); centerOn(item->pos().x() + viewport.width()/2, item->pos().y() + viewport.height()/2); } } }
void DigitizeStateSelect::showCoordinatesIfSinglePointIsSelected () { // See if there is a single point selected QList<QGraphicsItem*> items = context().mainWindow().scene().selectedItems(); if (items.size () == 1) { // There is a single item selected but we must see if it is a point QGraphicsItem *item = * (items.begin ()); if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE) == GRAPHICS_ITEM_TYPE_POINT) { // Show the coordinates of the point in the status bar QString coordsScreen, coordsGraph, resolutionGraph; context().mainWindow().transformation().coordTextForStatusBar (item->pos(), coordsScreen, coordsGraph, resolutionGraph, context().mainWindow().modeMap()); context().mainWindow().showTemporaryMessage(coordsGraph); } } }
QVariant Pin::itemChange(GraphicsItemChange change, const QVariant &value) { // Note that pins are only movable within the symbol editor. PageScene *pageScene = dynamic_cast<PageScene *>(scene()); if (ItemPositionChange == change && pageScene) { QPointF p = value.toPointF() + pageScene->reparentOffset(this); // p is now the position relative to the current parent. SymbolEditor *se = dynamic_cast<SymbolEditor *>(pageScene->parent()); if (se) { QGraphicsItem *anchor = se->closestPinAnchor(parentItem()->mapToScene(p), this); if (parentItem() != anchor) { pageScene->reparentWhileDragging(this, anchor); p = value.toPointF() + pageScene->reparentOffset(this); setData(FreeSCH::SectionChanged, true); } if (QGraphicsLineItem::Type == anchor->type()) { p.setX(anchor->pos().x()); if (position.side() != PinPosition::Right) { position.setSide(PinPosition::Right); attributes.setValue("side", PinPosition::sideNames.at(PinPosition::Right)); reorient(); } } else if (Section::Type == anchor->type()) { Section *section = qgraphicsitem_cast<Section *>(anchor); if (section) { QRectF r = QRectF(QPointF(0,0), section->rect().size()); PinPosition::PinSide newside = PinPosition::sideIndex(r, p); switch (newside) { case PinPosition::Right: p.setX(r.right()); break; case PinPosition::Bottom: p.setY(r.bottom()); break; case PinPosition::Left: p.setX(r.left()); break; default: // top p.setY(r.top()); break; } if (p.x() < 0) p.setX(0); if (p.x() > r.width()) p.setX(r.width()); if (p.y() < 0) p.setY(0); if (p.y() > r.height()) p.setY(r.height()); if (position.side() != newside) { position.setSide(newside); attributes.setValue("side", PinPosition::sideNames.at(newside)); updateOffset(snap(p).toPoint()); reorient(); // As the pin moves around a corner of a section, it can switch sides without its pos() changing. // In that case the ItemPositionHasChanged event doesn't occur. So we need to emit the moved signal here. emit moved(); } } } } return snap(p); } if (ItemPositionHasChanged == change && pageScene) { updateOffset(pos().toPoint()); if (data(FreeSCH::SectionChanged).toBool()) { setData(FreeSCH::SectionChanged, false); emit sectionChanged(this, parentItem()); } emit moved(); } return QGraphicsItem::itemChange(change, value); }
void PSV_TreeItem::paintLine(const QLineF &parentVLine, PSV_TreeItemData *itemData) { if(itemData == NULL) { return; } QPointF point2 = parentVLine.p2(); QList<PSV_TreeItemData*> children = itemData->children(); int leafCount = itemData->leafCount(); int count = children.count(); QPen pen; pen.setColor(QColor(Qt::red)); QPen pen_vLine; pen_vLine.setColor(QColor(Qt::blue)); QPen pen_hLine; QString tempText = itemData->text().trimmed(); QString text; for(int i = 0; i < tempText.length(); ++i) { text.append(tempText.at(i)); if(i != tempText.length() - 1) { text.append("\n"); } } QGraphicsItem* nodeItem = new QGraphicsEllipseItem(QRectF(0,0,1,1),this); nodeItem->setToolTip(tempText); QSizeF size = nodeItem->boundingRect().size(); nodeItem->setPos(point2.x() - size.width() * 0.5,point2.y() - size.height() * 0.5); QRectF rect = QRectF(nodeItem->pos().x(),nodeItem->pos().y(),size.width(),size.height()); // QGraphicsRectItem* rectItem = new QGraphicsRectItem(rect,this); // rectItem->setPen(pen); if(parentVLine.length() > PSV_ZEOR) { QLineF line = parentVLine; line.setP2(QPointF(line.x2(),rect.top())); QGraphicsLineItem* item = new QGraphicsLineItem(line,this); PSV_NOUSED(item); } if(count > 0) { QLineF leftHLine(point2.x() - leafCount * 0.5 * m_dw ,point2.y() ,rect.left() ,point2.y()); QLineF rightHLine(rect.right() ,point2.y() ,point2.x() + leafCount * 0.5 * m_dw ,point2.y()); double curX1 = leftHLine.x1(); for(int i = 0; i < count; ++i) { PSV_TreeItemData* tempItemData = children.at(i); int tempLeafCount = tempItemData->leafCount(); curX1 += tempLeafCount * 0.5 * m_dw; if(i == 0) { leftHLine.setP1(QPointF(curX1,leftHLine.y1())); } if(i == count - 1) { rightHLine.setP2(QPointF(curX1,leftHLine.y2())); } double y1 = point2.y(); double y2 = point2.y() + tempItemData->distance() * m_dhRatio; if(curX1 > rect.left() && curX1 < rect.right()) { y1 = rect.bottom(); } QLineF lineV(curX1,y1,curX1,y2); curX1 += tempLeafCount * 0.5 * m_dw; paintLine(lineV,tempItemData); } if(count > 1) { QGraphicsLineItem* leftHLineItem = new QGraphicsLineItem(leftHLine,this); leftHLineItem->setPen(pen_hLine); QGraphicsLineItem* rightHLineItem = new QGraphicsLineItem(rightHLine,this); rightHLineItem->setPen(pen_hLine); } } }