void QDeclarativeAnchorsPrivate::fillChanged() { Q_Q(QDeclarativeAnchors); if (!fill || !isItemComplete()) return; if (updatingFill < 2) { ++updatingFill; qreal horizontalMargin = q->mirrored() ? rightMargin : leftMargin; if (fill == item->parentItem()) { //child-parent setItemPos(QPointF(horizontalMargin, topMargin)); } else if (fill->parentItem() == item->parentItem()) { //siblings setItemPos(QPointF(fill->x()+horizontalMargin, fill->y()+topMargin)); } QGraphicsItemPrivate *fillPrivate = QGraphicsItemPrivate::get(fill); setItemSize(QSizeF(fillPrivate->width()-leftMargin-rightMargin, fillPrivate->height()-topMargin-bottomMargin)); --updatingFill; } else { // ### Make this certain :) qmlInfo(item) << QDeclarativeAnchors::tr("Possible anchor loop detected on fill."); } }
void QDeclarativeAnchorsPrivate::centerInChanged() { Q_Q(QDeclarativeAnchors); if (!centerIn || fill || !isItemComplete()) return; if (updatingCenterIn < 2) { ++updatingCenterIn; qreal effectiveHCenterOffset = q->mirrored() ? -hCenterOffset : hCenterOffset; if (centerIn == item->parentItem()) { QPointF p(hcenter(item->parentItem()) - hcenter(item) + effectiveHCenterOffset, vcenter(item->parentItem()) - vcenter(item) + vCenterOffset); setItemPos(p); } else if (centerIn->parentItem() == item->parentItem()) { QPointF p(centerIn->x() + hcenter(centerIn) - hcenter(item) + effectiveHCenterOffset, centerIn->y() + vcenter(centerIn) - vcenter(item) + vCenterOffset); setItemPos(p); } --updatingCenterIn; } else { // ### Make this certain :) qmlInfo(item) << QDeclarativeAnchors::tr("Possible anchor loop detected on centerIn."); } }
void QDeclarativeAnchorsPrivate::centerInChanged() { if (!centerIn || fill || !isItemComplete()) return; if (updatingCenterIn < 2) { ++updatingCenterIn; QGraphicsItemPrivate *itemPrivate = QGraphicsItemPrivate::get(item); if (centerIn == item->parentItem()) { QGraphicsItemPrivate *parentPrivate = QGraphicsItemPrivate::get(item->parentItem()); QPointF p((parentPrivate->width() - itemPrivate->width()) / 2. + hCenterOffset, (parentPrivate->height() - itemPrivate->height()) / 2. + vCenterOffset); setItemPos(p); } else if (centerIn->parentItem() == item->parentItem()) { QGraphicsItemPrivate *centerPrivate = QGraphicsItemPrivate::get(centerIn); QPointF p(centerIn->x() + (centerPrivate->width() - itemPrivate->width()) / 2. + hCenterOffset, centerIn->y() + (centerPrivate->height() - itemPrivate->height()) / 2. + vCenterOffset); setItemPos(p); } --updatingCenterIn; } else { // ### Make this certain :) qmlInfo(item) << QDeclarativeAnchors::tr("Possible anchor loop detected on centerIn."); } }
void DataVisualizer::setItemPos(QGraphicsItem * item, QPointF pos) { typedef QList<QGraphicsItem *> QGraphicsItemList; SceneType scene(gvDisplay->scene()); if (!item || !scene) return; // set the desired position item->setPos(pos); // check for collisions with other items QList<QGraphicsItem *> collides = scene->collidingItems(item); if (collides.size() == 0) return; QGraphicsItem * cItem = 0; QGraphicsItemList::const_iterator it = collides.constBegin(); while(it != collides.constEnd()) { cItem = *it; if (cItem && !cItem->parentItem()) break; it++; } if (!cItem || cItem->parentItem()) return; // item has no parent => top-level, bounding rect qreal newYPos = cItem->y() + 0.5*cItem->boundingRect().height() + 0.5*item->boundingRect().height() + itemMargin; QPointF newPos(pos); newPos.setY(newYPos); setItemPos(item, newPos); }
/********************************** * 2.接收线程发送过来的半张和全张缩略图 * * 分别添加到midpixitem和allpixitem * ***********************************/ void smallPictureView::itemAddImgpre(QImage fullImg, QImage img, QSize size, int i){ all_Qimg[i] = img; all_size[i] = size; QImage halfImg = fullImg.copy(18,0,36,48); midPixItems.at(i)->setPixmap(QPixmap::fromImage(fullImg)); allPixItem.at(i)->setPixmap(QPixmap::fromImage(halfImg)); allPixItem.at(i)->setData(1001,allImgs.at(i).absoluteFilePath()); allPixItem.at(i)->setToolTip( "<span style=\"color: white; background-color: transparent;\">" + allImgs.at(i).fileName() + "</span>"); midPixItems.at(i)->setToolTip( "<span style=\"color: white; background-color:transparent;\">" + allImgs.at(i).fileName() + "</span>"); setItemPos(i); }
void DataVisualizer::draw(SceneType scene, qreal& lastXPos, Element::Ptr e, int propertyIndex) { if (e.isNull()) return; // see if item should be drawn Element::Property p(Element::getProperty(propertyIndex)); Element::PropertyType type(Element::propertyType(p)); Element::PropertyVariant var(e->propertyConst(p)); if (p == Element::NUCLEONS_PROPERTY && !e->isIsotope()) return; if (!Element::isValidVariant(var)) return; // build the text item QGraphicsItem * item(0); QGraphicsTextItem * text = new QGraphicsTextItem(); text->setHtml( getLinkText(*e) + "<br>" + mMainWindow->toString(var)); text->setTextInteractionFlags(Qt::TextBrowserInteraction); text->setToolTip(tr("formattedFormulaToolTip")); connect(text, SIGNAL(linkActivated(const QString&)), this, SLOT(emitElementLinkActivated(const QString&))); item = text; // build the encapsulating box item QGraphicsRectItem * rect = new QGraphicsRectItem( item->boundingRect() ); rect->setBrush(QBrush(QColor(196, 255, 196))); // combine both and add them to the scene item->setParentItem(rect); scene->addItem(rect); QPointF pos(boost::apply_visitor(DrawingPositionFromPropertyVariant(), var)); if (type == Element::COMPLEX_TYPE || type == Element::STRING_TYPE) { // no stacking for 2D drawing // item positions are stretched in X direction if (lastXPos > pos.x()) { pos.setX(lastXPos); } rect->setPos(pos); // update drawing position for the next item lastXPos = pos.x() + rect->boundingRect().width() + itemMargin; } else { setItemPos(rect, pos); } }
ItemAnimation::ItemAnimation(QGraphicsItem *item, QObject *parent) : QObject(parent),mHide(false),mFade(None) { mMachine = new TransformMachine;//QGraphicsItemAnimation; QTimeLine *timer = new QTimeLine(1000); timer->setEasingCurve(QEasingCurve::OutQuad); timer->setFrameRange(0, 100); mMachine->setTimeLine(timer); connect(mMachine, SIGNAL(transformChanged(QTransform)), this, SLOT(setTransform(QTransform))); connect(mMachine, SIGNAL(zValueChanged(qreal)), this, SLOT(setZValue(qreal))); connect(mMachine, SIGNAL(posChanged(QPointF)), this, SLOT(setItemPos(QPointF))); connect(mMachine->timeLine(), SIGNAL(finished()), this, SLOT(tryHide())); connect(mMachine->timeLine(), SIGNAL(finished()), this, SIGNAL(finished())); setItem(item); }