void QDeclarativeLoaderPrivate::_q_updateSize(bool loaderGeometryChanged) { Q_Q(QDeclarativeLoader); if (!item || updatingSize) return; updatingSize = true; if (QDeclarativeItem *qmlItem = qobject_cast<QDeclarativeItem*>(item)) { if (!itemWidthValid) q->setImplicitWidth(qmlItem->implicitWidth()); else q->setImplicitWidth(qmlItem->width()); if (loaderGeometryChanged && q->widthValid()) qmlItem->setWidth(q->width()); if (!itemHeightValid) q->setImplicitHeight(qmlItem->implicitHeight()); else q->setImplicitHeight(qmlItem->height()); if (loaderGeometryChanged && q->heightValid()) qmlItem->setHeight(q->height()); } else if (item && item->isWidget()) { QGraphicsWidget *widget = static_cast<QGraphicsWidget*>(item); QSizeF widgetSize = widget->size(); q->setImplicitWidth(widgetSize.width()); if (loaderGeometryChanged && q->widthValid()) widgetSize.setWidth(q->width()); q->setImplicitHeight(widgetSize.height()); if (loaderGeometryChanged && q->heightValid()) widgetSize.setHeight(q->height()); if (widget->size() != widgetSize) widget->resize(widgetSize); } updatingSize = false; }
void tst_QGraphicsLayout::moveAndResizeWidgetInWidget() { QFETCH(bool, instantInvalidatePropagation); QGraphicsLayout::setInstantInvalidatePropagation(instantInvalidatePropagation); QGraphicsScene scene; QGraphicsWidget *widget = new QGraphicsWidget; QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(widget); layout->setContentsMargins(0,0,0,0); WidgetToTestResizeEvents *innerWidget = new WidgetToTestResizeEvents; QGraphicsLinearLayout *innerLayout = new QGraphicsLinearLayout(innerWidget); innerLayout->setContentsMargins(0,0,0,0); QCOMPARE(widget->maximumSize(), QSizeF(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)); layout->addItem(innerWidget); widget->setMinimumSize(1,1); widget->setPreferredSize(1000,1000); widget->setMaximumSize(2000,2000); widget->resize(widget->preferredSize()); innerWidget->setMinimumSize(1,1); qApp->processEvents(); innerWidget->resizeEventCalled = false; QCOMPARE(widget->size(), QSizeF(1000, 1000)); QCOMPARE(layout->geometry().size(), QSizeF(1000, 1000)); QCOMPARE(innerWidget->size(), QSizeF(1000, 1000)); innerLayout->invalidate(); widget->setMaximumHeight(500); widget->setX(1); qApp->processEvents(); QCOMPARE(widget->size(), QSizeF(1000, 500)); QCOMPARE(innerWidget->size(), QSizeF(1000, 500)); QVERIFY(innerWidget->resizeEventCalled); }
void WaitWidget::setupScene() { // Creamos el objeto efecto d->m_effect = new QGraphicsOpacityEffect; d->m_effect->setOpacity(0); d->m_effect->setEnabled(true); // Ahora creamos los proxys para gráficos que nos permita incluirlos en la escena QGraphicsProxyWidget *pFrame = d->m_scene.addWidget(d->m_widget); pFrame->resize(d->m_widget->width(), d->m_widget->height()); // Y lo agregamos a un layout gráfico QGraphicsLinearLayout *gLayout = new QGraphicsLinearLayout; gLayout->setOrientation(Qt::Vertical); gLayout->addItem(pFrame); // Creamos finalmente un objeto gráfico que lo contiene todo, y lo agregamos a la escena QGraphicsWidget *form = new QGraphicsWidget; form->setLayout(gLayout); form->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); d->m_scene.addItem(form); // Agregamos el efecto de opacidad al aparecer form->setGraphicsEffect(d->m_effect); form->resize(d->m_widget->width(), d->m_widget->height()); }
/*! Activates the layout, causing all items in the layout to be immediately rearranged. This function is based on calling count() and itemAt(), and then calling setGeometry() on all items sequentially. When activated, the layout will adjust its geometry to its parent's contentsRect(). The parent will then invalidate any layout of its own. If called in sequence or recursively, e.g., by one of the arranged items in response to being resized, this function will do nothing. Note that the layout is free to use geometry caching to optimize this process. To forcefully invalidate any such cache, you can call invalidate() before calling activate(). \sa invalidate() */ void QGraphicsLayout::activate() { Q_D(QGraphicsLayout); if (d->activated) return; d->activateRecursive(this); // we don't call activate on a sublayout, but somebody might. // Therefore, we walk to the parentitem of the toplevel layout. QGraphicsLayoutItem *parentItem = this; while (parentItem && parentItem->isLayout()) parentItem = parentItem->parentLayoutItem(); if (!parentItem) return; Q_ASSERT(!parentItem->isLayout()); if (QGraphicsLayout::instantInvalidatePropagation()) { QGraphicsWidget *parentWidget = static_cast<QGraphicsWidget*>(parentItem); if (!parentWidget->parentLayoutItem()) { // we've reached the topmost widget, resize it bool wasResized = parentWidget->testAttribute(Qt::WA_Resized); parentWidget->resize(parentWidget->size()); parentWidget->setAttribute(Qt::WA_Resized, wasResized); } setGeometry(parentItem->contentsRect()); // relayout children } else { setGeometry(parentItem->contentsRect()); // relayout children parentLayoutItem()->updateGeometry(); } }
QGraphicsWidget *DesignerActionManager::createFormEditorToolBar(QGraphicsItem *parent) { QList<ActionInterface* > actions = Utils::filtered(designerActions(), [](ActionInterface *action) { return action->type() == ActionInterface::FormEditorAction && action->action()->isVisible(); }); Utils::sort(actions, [](ActionInterface *l, ActionInterface *r) { return l->priority() > r->priority(); }); QGraphicsWidget *toolbar = new QGraphicsWidget(parent); auto layout = new QGraphicsLinearLayout; layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(0); toolbar->setLayout(layout); for (ActionInterface *action : actions) { auto button = new FormEditorToolButton(action->action(), toolbar); layout->addItem(button); } toolbar->resize(toolbar->preferredSize()); layout->invalidate(); layout->activate(); toolbar->update(); return toolbar; }
ChromeSnippet *ChromeDOM::getSnippet(const QString &docElementId, QGraphicsItem* parent) { Q_UNUSED(parent) ChromeSnippet * snippet = 0; QWebElement doc = m_page->mainFrame()->documentElement(); QWebElement element = doc.findFirst("#" + docElementId); QRect rect = element.geometry(); //TODO: This may not be accurate since final heights may not have been computed at this point!! m_height += rect.height(); // qDebug() << "Snippet: ID: " << docElementId << " Owner Area: " << rect << " Element Rect: " << element.geometry(); if (!rect.isNull()) { QString className = element.attribute("data-GinebraNativeClass", "__NO_CLASS__"); if (className == "__NO_CLASS__") { if (element.attribute("data-GinebraContainer", "false") == "true") { snippet = new WebChromeContainerSnippet(docElementId, m_chrome, element); snippet->setChromeWidget(new ChromeItem(snippet)); } else { snippet = new WebChromeSnippet(docElementId, m_chrome, element); m_renderer->addRenderItem((static_cast<WebChromeSnippet*> (snippet))->item()); } } else { snippet = nativeSnippetForClassName(className, docElementId, element); //TODO: Is the following still needed? QGraphicsWidget * widget = snippet->widget(); //Have snippet determine its own size when in anchor layout. Again, these will not //necessarily be accurate at this point. widget->resize(rect.width(), rect.height()); widget->setPreferredSize(rect.width(), rect.height()); widget->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred)); //Have snippet determine its own location when NOT in anchor layout widget->setPos(rect.x(), rect.y()); } QWebElement parentElem; if (!(parentElem = findChromeParent(element)).isNull()) { snippet->setParentId(parentElem.attribute("id")); } //Set auto-layout attributes snippet->setAnchor(element.attribute("data-GinebraAnchor", "AnchorNone"), false); snippet->setAnchorOffset(element.attribute("data-GinebraAnchorOffset", "0").toInt()); snippet->setInitiallyVisible(element.attribute("data-GinebraVisible", "false") == "true"); snippet->setHidesContent(element.attribute("data-GinebraHidesContent", "false") == "true"); } return snippet; }
void tst_QGraphicsLayout::invalidateAndMove() { // Check that if we set the position of an item and invalidate its layout at the same // time, the widget keeps its correct size QFETCH(bool, instantInvalidatePropagation); QGraphicsLayout::setInstantInvalidatePropagation(instantInvalidatePropagation); QGraphicsScene scene; QGraphicsWidget *widget = new QGraphicsWidget; new QGraphicsLinearLayout(widget); widget->setMinimumSize(1,1); widget->setPreferredSize(34,34); widget->setMaximumSize(100,100); widget->resize(widget->preferredSize()); scene.addItem(widget); qApp->processEvents(); /* Invalidate and reactivate. The size should not have changed */ widget->layout()->invalidate(); widget->layout()->activate(); QCOMPARE(widget->geometry().size(), widget->preferredSize()); QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize()); qApp->processEvents(); QCOMPARE(widget->geometry().size(), widget->preferredSize()); QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize()); widget->layout()->invalidate(); widget->setX(1); //Change just the position using setX QCOMPARE(widget->geometry().size(), widget->preferredSize()); QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize()); qApp->processEvents(); QCOMPARE(widget->geometry().size(), widget->preferredSize()); QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize()); widget->layout()->invalidate(); widget->setGeometry(1,1,34,34); //Change just the position using setGeometry QCOMPARE(widget->geometry().size(), widget->preferredSize()); QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize()); qApp->processEvents(); QCOMPARE(widget->geometry().size(), widget->preferredSize()); QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize()); widget->layout()->invalidate(); widget->setGeometry(1,1,60,60); //Change just the size using setGeometry QCOMPARE(widget->geometry().size(), QSizeF(60,60)); QCOMPARE(widget->layout()->geometry().size(), QSizeF(60,60)); qApp->processEvents(); QCOMPARE(widget->geometry().size(), QSizeF(60,60)); QCOMPARE(widget->layout()->geometry().size(), QSizeF(60,60)); widget->layout()->invalidate(); widget->setGeometry(0,0,34,34); //Change the size and position using setGeometry QCOMPARE(widget->geometry().size(), widget->preferredSize()); QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize()); qApp->processEvents(); QCOMPARE(widget->geometry().size(), widget->preferredSize()); QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize()); QGraphicsLayout::setInstantInvalidatePropagation(false); }
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; } }