void MapScene::addTrack(const QVector<QPointF>& points, const QVector<float>& metaData, QVariant idTrack) { if (points.isEmpty()) return; QPainterPath route; TrackItem* track = new TrackItem; track->setId(idTrack); // Add each CoordinateItems which constitute the track for (int i(0); i < points.count(); i++) { qreal sx = points[i].x() * this->_amplificationRatio; qreal sy = points[i].y() * -this->_amplificationRatio; CoordinateItem* ci = new CoordinateItem; ci->setPos(sx, sy); ci->setAcceptHoverEvents(this->_trackAcceptHoverEvents); track->insertCoordinate(ci, metaData.value(i)); if (i == 0) route.moveTo(sx, sy); else route.lineTo(sx, sy); } this->_tracks << track; this->addItem(track); QGraphicsItem* path = this->addPath(route, QPen(Qt::white)); path->setParentItem(track); this->setSceneRect(this->itemsBoundingRect()); }
void dmz::QtPluginCanvasObject::unlink_objects ( const Handle LinkHandle, const Handle AttributeHandle, const UUID &SuperIdentity, const Handle SuperHandle, const UUID &SubIdentity, const Handle SubHandle) { if (_canvasModule) { if (AttributeHandle == _linkAttributeHandle) { QGraphicsItem *superItem (_canvasModule->lookup_item (SuperHandle)); QGraphicsItem *subItem (_canvasModule->lookup_item (SubHandle)); if (superItem) { QGraphicsItemGroup *group ( qgraphicsitem_cast <QGraphicsItemGroup *>(subItem)); if (group) { superItem->setGroup (0); } else { superItem->setParentItem (0); } } } } }
double SystemRenderer::drawDirections(const System &system, const LayoutInfo &layout, double height) { double maxHeight = 0; for (const Direction &direction : system.getDirections()) { double localHeight = 0; const double x = layout.getPositionX(direction.getPosition()); for (const DirectionSymbol &symbol : direction.getSymbols()) { QGraphicsItem *item = nullptr; switch (symbol.getSymbolType()) { case DirectionSymbol::Coda: item = new SimpleTextItem(QChar(MusicFont::Coda), myMusicNotationFont); break; case DirectionSymbol::DoubleCoda: item = new SimpleTextItem(QString(2, MusicFont::Coda), myMusicNotationFont); break; case DirectionSymbol::Segno: item = new SimpleTextItem(QChar(MusicFont::Segno), myMusicNotationFont); break; case DirectionSymbol::SegnoSegno: item = new SimpleTextItem(QString(2, MusicFont::Segno), myMusicNotationFont); break; default: // Display plain text. QFont font = myPlainTextFont; font.setItalic(true); item = new SimpleTextItem( theDirectionText[symbol.getSymbolType()], font); break; } centerHorizontally(*item, x, x + layout.getPositionSpacing()); centerSymbolVertically(*item, height + localHeight); // Compensate a bit for the alignment of the music notation font. if (symbol.getSymbolType() <= DirectionSymbol::SegnoSegno) item->setY(item->y() + 4); item->setParentItem(myParentSystem); localHeight += LayoutInfo::SYSTEM_SYMBOL_SPACING; } maxHeight = std::max(maxHeight, localHeight); } return maxHeight; }
void SCgCommandDeleteContour::undo() { SCgBaseCommand::undo(); QList<QGraphicsItem*>::iterator it; for (it = mChilds.begin(); it != mChilds.end(); ++it) { QGraphicsItem *item = *it; item->setParentItem(mContour); } }
void HomeScreen::initSprite() { _sprite = new QGraphicsWidget(); QGraphicsItem* item; QGraphicsSimpleTextItem* text; QGraphicsProxyWidget* proxy; QLabel* label; QFont font; item = new QGraphicsPixmapItem(); item->setParentItem(_sprite); item->setPos((BACKGROUND_W - (400.0f / 0.75f)) * 0.5f, BACKGROUND_H - 400.0f); _avatar = static_cast<QGraphicsPixmapItem*>(item); item = new QGraphicsPixmapItem(LoaderThread::instance()->getCachedPixmap(IMAGE_TITLE)); item->setParentItem(_sprite); item->setPos(232.0f, 128.0f); font = QFont("Arial"); font.setPixelSize(12); font.setWeight(QFont::Normal); font.setStretch(80); text = new QGraphicsSimpleTextItem("http://conanchen.com/Kinetris"); text->setBrush(QColor::fromRgb(0xFF, 0xFF, 0xFF)); text->setFont(font); text->setParentItem(_sprite); text->setPos(248.0f, 264.0f - 3.0f); label = new QLabel(); label->resize(784, 24); label->setStyleSheet("background-color: transparent; color: #FFFFFF;"); label->setAlignment(Qt::AlignTop | Qt::AlignHCenter); proxy = new QGraphicsProxyWidget(); proxy->setParentItem(_sprite); proxy->setWidget(label); proxy->setPos(248.0f, 592.0f - 6.0f); _sprite_status = proxy; _status = label; }
void Letter::createSideArrow() { QPainterPath path; path.moveTo(0, 0); path.lineTo(22, 0); path.moveTo(16, -6); path.lineTo(22, 0); path.lineTo(16, 6); m_arrow = scene()->addPath(path, QPen(Qt::black, 5, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); QGraphicsItem* fill = scene()->addPath(path, QPen(Qt::white, 3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); fill->setParentItem(m_arrow); }
int main(int argc, char *argv[]) { QApplication a(argc, argv); QGraphicsView gv; QGraphicsScene *scene = new QGraphicsScene(&gv); gv.setScene(scene); QGraphicsItem *rect = scene->addRect(0, 0, 200, 200, QPen(Qt::NoPen), QBrush(Qt::yellow)); rect->setFlag(QGraphicsItem::ItemHasNoContents); rect->setFlag(QGraphicsItem::ItemClipsChildrenToShape); QGraphicsItem *childRect = scene->addRect(0, 0, 100, 100, QPen(Qt::NoPen), QBrush(Qt::red)); childRect->setParentItem(rect); gv.show(); MyObject o(rect); QMessageBox::information(0, "What you should see", "The red rectangle should toggle visiblity, so you should see it flash on and off"); return a.exec(); }
void QGraphicsWebViewPrivate::setRootGraphicsLayer(QGraphicsItem* layer) { if (rootGraphicsLayer) { rootGraphicsLayer->setParentItem(0); q->scene()->removeItem(rootGraphicsLayer); QWebFramePrivate::core(q->page()->mainFrame())->view()->syncCompositingStateRecursive(); } rootGraphicsLayer = layer; if (layer) { layer->setFlag(QGraphicsItem::ItemClipsChildrenToShape, true); layer->setParentItem(q); layer->setZValue(RootGraphicsLayerZValue); updateCompositingScrollPosition(); } createOrDeleteOverlay(); }
void AbstractDataPlugin::handleViewportChange( const ViewportParams *viewport ) { QList<AbstractDataPluginItem*> orphane = d->m_delegateInstances.keys(); QList<AbstractDataPluginItem*> const items = d->m_model->items( viewport, numberOfItems() ); foreach( AbstractDataPluginItem* item, items ) { qreal x, y; Marble::GeoDataCoordinates const coordinates = item->coordinate(); bool const visible = viewport->screenCoordinates( coordinates.longitude(), coordinates.latitude(), x, y ); if ( !d->m_delegateInstances.contains( item ) ) { if ( !visible ) { // We don't have, but don't need it either. Shouldn't happen though as the model checks for it already. continue; } // Create a new QML object instance using the delegate as the factory. The original // data plugin item is set as the context object, i.e. all its properties are available // to QML directly with their names QQmlContext *context = new QQmlContext( qmlContext( d->m_delegate ) ); context->setContextObject( item ); QList<QByteArray> const dynamicProperties = item->dynamicPropertyNames(); foreach( const QByteArray &property, dynamicProperties ) { context->setContextProperty( property, item->property( property ) ); } QObject* component = d->m_delegate->create( context ); QQuickItem* newItem = qobject_cast<QQuickItem*>( component ); QGraphicsItem* graphicsItem = qobject_cast<QGraphicsItem*>( component ); if ( graphicsItem && newItem ) { graphicsItem->setParentItem( d->m_delegateParent ); } if ( newItem ) { d->m_delegateInstances[item] = newItem; } else { mDebug() << "Failed to create delegate"; continue; } } else if ( !visible ) {
void SCgCommandDeleteContour::redo() { mChilds.clear(); QGraphicsItem *parent = mContour->parentItem(); QList<QGraphicsItem*> childs = mContour->childItems(); QList<QGraphicsItem*>::iterator it; for (it = childs.begin(); it != childs.end(); ++it) { QGraphicsItem *item = *it; if (!SCgObject::isSCgObjectType(item->type())) continue; mChilds.push_back(item); item->setParentItem(parent); } if (childCount() == 0) new SCgCommandObjectDelete(mScene, mContour, this); SCgBaseCommand::redo(); }
void VisualMatrix::initSprite() { _sprite = new QGraphicsWidget(); QGraphicsItem* item; QGraphicsWidget* widget; QGraphicsRectItem* rect; QGraphicsColorizeEffect* effect; QGraphicsSimpleTextItem* text; QGraphicsProxyWidget* proxy; QLabel* label; QFont font; // Frame { item = new QGraphicsPixmapItem(LoaderThread::instance()->getCachedPixmap(IMAGE_FRAME_BG)); item->setParentItem(_sprite); item->setPos(0.0f, 0.0f); } // Frame { item = new QGraphicsPixmapItem(LoaderThread::instance()->getCachedPixmap(IMAGE_FRAME_MG)); item->setParentItem(_sprite); item->setPos(0.0f, 0.0f); } // Avatar { widget = new QGraphicsWidget(); widget->resize(BLOCK_LARGE * 10, BLOCK_LARGE * 20); widget->setFlags(QGraphicsItem::ItemClipsChildrenToShape); widget->setParentItem(_sprite); widget->setPos(170.0f, 50.0f); item = new QGraphicsPixmapItem(); item->setParentItem(widget); item->setPos(((BLOCK_LARGE * 10) - (320.0f / 0.75f)) * 0.5f, (BLOCK_LARGE * 20) - 320.0f); _avatar = widget; } // Help { widget = new QGraphicsWidget(); widget->resize(BLOCK_LARGE * 10, BLOCK_LARGE * 20); widget->setFlags(QGraphicsItem::ItemClipsChildrenToShape); widget->setParentItem(_sprite); widget->setPos(170.0f, 50.0f); rect = new QGraphicsRectItem(0.0f, 0.0f, BLOCK_LARGE * 10, BLOCK_LARGE * 20); rect->setBrush(QBrush(QColor::fromRgb(0x00, 0x00, 0x00, 0xC0))); rect->setParentItem(widget); font = QApplication::font(); font.setFamily("Arial"); font.setPixelSize(16); font.setWeight(QFont::Bold); font.setStretch(80); text = new QGraphicsSimpleTextItem(tr("Slide left and right: Move.")); text->setBrush(QColor::fromRgb(0xC0, 0xC0, 0xC0)); text->setFont(font); text->setParentItem(widget); text->setPos(((BLOCK_LARGE * 10) - text->boundingRect().width()) * 0.5f, 217.0f - 6.0f); text = new QGraphicsSimpleTextItem(tr("Swipe up: Hold. Swipe down: Drop.")); text->setBrush(QColor::fromRgb(0xC0, 0xC0, 0xC0)); text->setFont(font); text->setParentItem(widget); text->setPos(((BLOCK_LARGE * 10) - text->boundingRect().width()) * 0.5f, 237.0f - 6.0f); text = new QGraphicsSimpleTextItem(tr("Pull back, and make circles: Rotate.")); text->setBrush(QColor::fromRgb(0xC0, 0xC0, 0xC0)); text->setFont(font); text->setParentItem(widget); text->setPos(((BLOCK_LARGE * 10) - text->boundingRect().width()) * 0.5f, 257.0f - 6.0f); // widget->setVisible(false); _sprite_help = widget; } // Lines { rect = new QGraphicsRectItem(120.0f - 1.0f, 220.0f - 1.0f, 8.0f + 2.0f, 144.0f + 2.0f); rect->setBrush(QBrush(LoaderThread::instance()->getCachedPixmap(IMAGE_LINES_PROGRESS))); rect->setParentItem(_sprite); _sprite_lines = rect; } // Frame { item = new QGraphicsPixmapItem(LoaderThread::instance()->getCachedPixmap(IMAGE_FRAME_FG)); item->setParentItem(_sprite); item->setPos(0.0f, 0.0f); } // Field { widget = new QGraphicsWidget(); widget->resize(BLOCK_LARGE * 10, BLOCK_LARGE * 20); widget->setFlags(QGraphicsItem::ItemClipsChildrenToShape); widget->setParentItem(_sprite); widget->setPos(170.0f, 50.0f); _sprite_field = widget; _sprite_space.fill(NULL, _rows * _cols); } // Ghost { widget = new QGraphicsWidget(); widget->resize(BLOCK_LARGE * 4, BLOCK_LARGE * 4); widget->setParentItem(_sprite_field); widget->setPos(BLOCK_LARGE * getShapePositionInField(18, 3)); for (int i = 0; i < 4; ++i) { item = new QGraphicsPixmapItem(LoaderThread::instance()->getCachedPixmap(IMAGE_BLOCK_GHOST)); item->setParentItem(widget); } _sprite_ghost = widget; } // Tetromino { widget = new QGraphicsWidget(); widget->resize(BLOCK_LARGE * 4, BLOCK_LARGE * 4); widget->setParentItem(_sprite_field); widget->setPos(BLOCK_LARGE * getShapePositionInField(18, 3)); widget->setZValue(1.0f); effect = new QGraphicsColorizeEffect(widget); effect->setColor(QColor::fromRgb(0xFF, 0xFF, 0xFF)); effect->setStrength(0.0f); widget->setGraphicsEffect(effect); for (int i = 0; i < 4; ++i) { item = new QGraphicsPixmapItem(); item->setParentItem(widget); } _sprite_tetromino = widget; } // Hold { widget = new QGraphicsWidget(); widget->resize(BLOCK_LARGE * 4, BLOCK_LARGE * 2); widget->setScale(BLOCK_SMALL / BLOCK_LARGE); widget->setParentItem(_sprite); widget->setPos(56.0f, 108.0f + BLOCK_SMALL); effect = new QGraphicsColorizeEffect(widget); effect->setColor(QColor::fromRgb(0xFF, 0xFF, 0xFF)); effect->setStrength(0.0f); widget->setGraphicsEffect(effect); for (int i = 0; i < 4; ++i) { item = new QGraphicsPixmapItem(); item->setParentItem(widget); } _sprite_hold = widget; } // Hold fail { item = new QGraphicsPixmapItem(LoaderThread::instance()->getCachedPixmap(IMAGE_FAIL)); item->setScale(BLOCK_SMALL / BLOCK_LARGE); item->setParentItem(_sprite); item->setPos(56.0f + (BLOCK_SMALL * 3), 108.0f + (BLOCK_SMALL * 3)); item->setVisible(false); _sprite_holdFail = item; } // Next { widget = new QGraphicsWidget(); widget->resize(BLOCK_LARGE * 4, BLOCK_LARGE * 2); widget->setScale(BLOCK_SMALL / BLOCK_LARGE); widget->setParentItem(_sprite); widget->setPos(460.0f, 108.0f + BLOCK_SMALL); effect = new QGraphicsColorizeEffect(widget); effect->setColor(QColor::fromRgb(0xFF, 0xFF, 0xFF)); effect->setStrength(0.0f); widget->setGraphicsEffect(effect); for (int i = 0; i < 4; ++i) { item = new QGraphicsPixmapItem(); item->setParentItem(widget); } _sprite_next << widget; } // Next { widget = new QGraphicsWidget(); widget->resize(BLOCK_LARGE * 4, BLOCK_LARGE * 2); widget->setScale(BLOCK_SMALL / BLOCK_LARGE); widget->setParentItem(_sprite); widget->setPos(460.0f, 228.0f + BLOCK_SMALL); effect = new QGraphicsColorizeEffect(widget); effect->setColor(QColor::fromRgb(0xFF, 0xFF, 0xFF)); effect->setStrength(0.0f); widget->setGraphicsEffect(effect); for (int i = 0; i < 4; ++i) { item = new QGraphicsPixmapItem(); item->setParentItem(widget); } _sprite_next << widget; } // Next { widget = new QGraphicsWidget(); widget->resize(BLOCK_LARGE * 4, BLOCK_LARGE * 2); widget->setScale(BLOCK_SMALL / BLOCK_LARGE); widget->setParentItem(_sprite); widget->setPos(460.0f, 292.0f + BLOCK_SMALL); effect = new QGraphicsColorizeEffect(widget); effect->setColor(QColor::fromRgb(0xFF, 0xFF, 0xFF)); effect->setStrength(0.0f); widget->setGraphicsEffect(effect); for (int i = 0; i < 4; ++i) { item = new QGraphicsPixmapItem(); item->setParentItem(widget); } _sprite_next << widget; } // Font { font = QApplication::font(); font.setCapitalization(QFont::AllUppercase); } // Hold { text = new QGraphicsSimpleTextItem(tr("Hold")); text->setBrush(QColor::fromRgb(0x00, 0x00, 0x00)); text->setFont(font); text->setParentItem(_sprite); text->setPos(56.0f, 80.0f - 6.0f); } // Next { text = new QGraphicsSimpleTextItem(tr("Next")); text->setBrush(QColor::fromRgb(0x00, 0x00, 0x00)); text->setFont(font); text->setParentItem(_sprite); text->setPos(526.0f - text->boundingRect().width(), 80.0f - 6.0f); } // Level { text = new QGraphicsSimpleTextItem(tr("Level")); text->setBrush(QColor::fromRgb(0x00, 0x00, 0x00)); text->setFont(font); text->setParentItem(_sprite); text->setPos(56.0f, 316.0f - 6.0f); } // Level { label = new QLabel(); label->resize(48, 24); label->setStyleSheet("background-color: transparent; color: #FFFFFF;"); label->setAlignment(Qt::AlignTop | Qt::AlignLeft); proxy = new QGraphicsProxyWidget(); proxy->setParentItem(_sprite); proxy->setWidget(label); proxy->setPos(56.0f, 344.0f - 6.0f); _sprite_level = label; } // Score { text = new QGraphicsSimpleTextItem(tr("Score")); text->setBrush(QColor::fromRgb(0x00, 0x00, 0x00)); text->setFont(font); text->setParentItem(_sprite); text->setPos(176.0f, 564.0f - 6.0f); } // Score { label = new QLabel(); label->resize(148, 24); label->setStyleSheet("background-color: transparent; color: #FFFFFF;"); label->setAlignment(Qt::AlignTop | Qt::AlignRight); proxy = new QGraphicsProxyWidget(); proxy->setParentItem(_sprite); proxy->setWidget(label); proxy->setPos(256.0f, 564.0f - 6.0f); _sprite_score = label; } // Countdown { widget = new QGraphicsWidget(); widget->resize(BLOCK_LARGE * 10, BLOCK_LARGE * 20); widget->setFlags(QGraphicsItem::ItemClipsChildrenToShape); widget->setParentItem(_sprite); widget->setPos(170.0f, 50.0f); rect = new QGraphicsRectItem(0.0f, 0.0f, BLOCK_LARGE * 10, BLOCK_LARGE * 20); rect->setBrush(QBrush(QColor::fromRgb(0x00, 0x00, 0x00, 0xC0))); rect->setParentItem(widget); item = new QGraphicsPixmapItem(LoaderThread::instance()->getCachedPixmap(IMAGE_COUNT[0])); item->setParentItem(widget); item->setPos(77.0f, 197.0f); item->setVisible(false); _sprite_count << item; item = new QGraphicsPixmapItem(LoaderThread::instance()->getCachedPixmap(IMAGE_COUNT[1])); item->setParentItem(widget); item->setPos(77.0f, 197.0f); item->setVisible(false); _sprite_count << item; item = new QGraphicsPixmapItem(LoaderThread::instance()->getCachedPixmap(IMAGE_COUNT[2])); item->setParentItem(widget); item->setPos(77.0f, 197.0f); item->setVisible(false); _sprite_count << item; widget->setVisible(false); _sprite_countdown = widget; } // Game over { widget = new QGraphicsWidget(); widget->resize(BLOCK_LARGE * 10, BLOCK_LARGE * 20); widget->setFlags(QGraphicsItem::ItemClipsChildrenToShape); widget->setParentItem(_sprite); widget->setPos(170.0f, 50.0f); widget->setZValue(8.0f); rect = new QGraphicsRectItem(0.0f, 0.0f, BLOCK_LARGE * 10, BLOCK_LARGE * 20); rect->setBrush(QBrush(QColor::fromRgb(0x00, 0x00, 0x00, 0xC0))); rect->setParentItem(widget); item = new QGraphicsPixmapItem(LoaderThread::instance()->getCachedPixmap(IMAGE_OVER)); item->setParentItem(widget); item->setPos(4.0f, 172.0f); rect = new QGraphicsRectItem(0.0f, 0.0f, BLOCK_LARGE * 10, BLOCK_LARGE * 20); rect->setBrush(QBrush(QColor::fromRgb(0xFF, 0xFF, 0xFF))); rect->setParentItem(widget); _sprite_overFlash = rect; widget->setVisible(false); _sprite_over = widget; } }