void PeopleGroupedView::removeCard(int row) { qDebug() << "removeCard" << row; // NOTE: this is relying on the model sort order matching our order // count the items that appear before this one int items = 0; for (int i=0; i<=m_numSections; i++) { if (row - items < m_sectionCounts[i]) { QGraphicsLayout *layout = static_cast<QGraphicsLayout *>(m_mainLayout->itemAt(i, 0)); qDebug() << "layout for " << i; removeAndDelete(layout, row - items +1); layout->updateGeometry(); m_sectionCounts[i]--; // if empty, remove the heading as well if (m_sectionCounts[i] == 0) { removeAndDelete(layout, 0); delete layout; } return; } items += m_sectionCounts[i]; } }
/*! \internal \a mw is the new parent. all items in the layout will be a child of \a mw. */ void QGraphicsLayoutPrivate::reparentChildWidgets(QGraphicsWidget *mw) { Q_Q(QGraphicsLayout); int n = q->count(); //bool mwVisible = mw && mw->isVisible(); for (int i = 0; i < n; ++i) { QGraphicsLayoutItem *item = q->itemAt(i); if (item->isLayout()) { QGraphicsLayout *l = static_cast<QGraphicsLayout*>(item); l->d_func()->reparentChildWidgets(mw); } else { QGraphicsWidget *w = static_cast<QGraphicsWidget*>(item); QGraphicsWidget *pw = w->parentWidget(); #ifdef QT_DEBUG if (pw && pw != mw && qt_graphicsLayoutDebug()) { qWarning("QGraphicsLayout::addChildLayout: widget %s \"%s\" in wrong parent; moved to correct parent", w->metaObject()->className(), w->objectName().toLocal8Bit().constData()); } #endif //bool needShow = mwVisible && !(w->isHidden() && w->testAttribute(Qt::WA_WState_ExplicitShowHide)); if (pw != mw) w->setParentItem(mw); //if (needShow) // QMetaObject::invokeMethod(w, "_q_showIfNotHidden", Qt::QueuedConnection); //show later } } }
QT_BEGIN_NAMESPACE /*! \internal \a mw is the new parent. all items in the layout will be a child of \a mw. */ void QGraphicsLayoutPrivate::reparentChildItems(QGraphicsItem *newParent) { Q_Q(QGraphicsLayout); int n = q->count(); //bool mwVisible = mw && mw->isVisible(); for (int i = 0; i < n; ++i) { QGraphicsLayoutItem *layoutChild = q->itemAt(i); if (!layoutChild) { // Skip stretch items continue; } if (layoutChild->isLayout()) { QGraphicsLayout *l = static_cast<QGraphicsLayout*>(layoutChild); l->d_func()->reparentChildItems(newParent); } else if (QGraphicsItem *itemChild = layoutChild->graphicsItem()){ QGraphicsItem *childParent = itemChild->parentItem(); #ifdef QT_DEBUG if (childParent && childParent != newParent && itemChild->isWidget() && qt_graphicsLayoutDebug()) { QGraphicsWidget *w = static_cast<QGraphicsWidget*>(layoutChild); qWarning("QGraphicsLayout::addChildLayout: widget %s \"%s\" in wrong parent; moved to correct parent", w->metaObject()->className(), w->objectName().toLocal8Bit().constData()); } #endif if (childParent != newParent) itemChild->setParentItem(newParent); } } }
void Context::Applet::cleanUpAndDelete() { QGraphicsWidget *parent = dynamic_cast<QGraphicsWidget *>( parentItem() ); //it probably won't matter, but right now if there are applethandles, *they* are the parent. //not the containment. //is the applet in a containment and is the containment have a layout? if yes, we remove the applet in the layout if ( parent && parent->layout() ) { QGraphicsLayout *l = parent->layout(); for ( int i = 0; i < l->count(); ++i ) { if ( this == l->itemAt( i ) ) { l->removeAt( i ); break; } } } if ( Plasma::Applet::configScheme() ) { Plasma::Applet::configScheme()->setDefaults(); } Plasma::Applet::scene()->removeItem( this ); Plasma::Applet::deleteLater(); }
static PyObject *meth_QGraphicsLayout_setContentsMargins(PyObject *sipSelf, PyObject *sipArgs) { PyObject *sipParseErr = NULL; { qreal a0; qreal a1; qreal a2; qreal a3; QGraphicsLayout *sipCpp; if (sipParseArgs(&sipParseErr, sipArgs, "Bdddd", &sipSelf, sipType_QGraphicsLayout, &sipCpp, &a0, &a1, &a2, &a3)) { Py_BEGIN_ALLOW_THREADS sipCpp->setContentsMargins(a0,a1,a2,a3); Py_END_ALLOW_THREADS Py_INCREF(Py_None); return Py_None; } } /* Raise an exception if the arguments couldn't be parsed. */ sipNoMethod(sipParseErr, sipName_QGraphicsLayout, sipName_setContentsMargins, doc_QGraphicsLayout_setContentsMargins); return NULL; }
void KWidget::setMargins( const QMargins& m ) { QGraphicsLayout *tmpLayout = layout(); if(tmpLayout == NULL) return; tmpLayout->setContentsMargins(m.left(), m.top(), m.right(), m.bottom()); }
QMargins KWidget::margins() { QGraphicsLayout *tmpLayout = layout(); if(tmpLayout == NULL) return QMargins(); qreal l, t, r, b; tmpLayout->getContentsMargins(&l, &t, &r, &b); return QMargins(l, t, r, b); }
void HGLayout::setAlignment(Qt::Alignment align) { HLayout::setAlignment(align); if (!layout()) return ; QGraphicsLayout* l = layout(); if (!l) return ; for (int i = 0; i <l->count(); i++) setAlignment(l->itemAt(i), align); }
/*! Destroys the QGraphicsLayoutItem object. */ QGraphicsLayoutItem::~QGraphicsLayoutItem() { QGraphicsLayoutItem *parentLI = parentLayoutItem(); if (parentLI && parentLI->isLayout()) { QGraphicsLayout *lay = static_cast<QGraphicsLayout*>(parentLI); // this is not optimal for (int i = lay->count() - 1; i >= 0; --i) { if (lay->itemAt(i) == this) { lay->removeAt(i); break; } } } }
bool KWidget::bylayout() { KWidget *itemParent = qobject_cast<KWidget*>(parent()); if(itemParent == NULL) return false; QGraphicsLayoutItem *item = dynamic_cast<QGraphicsLayoutItem*>(this); QGraphicsLayout *layout = itemParent->layout(); for(int i = 0; i < layout->count(); i++) { if(layout->itemAt(i) == item) return true; } return false; }
static void clearLayout(QGraphicsGridLayout *grid) { int rows = grid->rowCount(); for (int i=0; i<rows; i++) { QGraphicsLayout *child = static_cast<QGraphicsLayout *>(grid->itemAt(i, 0)); if (child) { int childCount = child->count(); for (int j=0; j<childCount; j++) { QGraphicsLayoutItem *item = child->itemAt(0); child->removeAt(0); delete item; } delete child; } } }
void KWidget::invalidateLayout() { QGraphicsLayout *layout = this->layout(); if(layout == NULL) return; layout->invalidate(); QList<QGraphicsItem *> childs = childItems(); for(int i = 0; i < childs.count(); i++) { QGraphicsItem *item = childs[i]; KWidget *widget = qobject_cast<KWidget*>(item->toGraphicsObject()); if(widget == NULL) continue; widget->invalidateLayout(); } }
void tst_QGraphicsAnchorLayout::linearVsAnchorSetGeometry() { QFETCH(int, whichLayout); QGraphicsLayout *l = createLayouts(whichLayout); QRectF sizeHint; qreal maxWidth; qreal increment; // warm up instruction cache l->invalidate(); sizeHint.setSize(l->effectiveSizeHint(Qt::MinimumSize)); maxWidth = l->effectiveSizeHint(Qt::MaximumSize).width(); increment = (maxWidth - sizeHint.width()) / 100; l->setGeometry(sizeHint); // ...then measure... QBENCHMARK { l->invalidate(); for (qreal width = sizeHint.width(); width <= maxWidth; width += increment) { sizeHint.setWidth(width); l->setGeometry(sizeHint); } } }
void KWidget::removeLayoutItem( KWidget *item ) { Q_D(KWidget); if(item == NULL) return; QGraphicsLayout *tmpLayout = layout(); if(tmpLayout == NULL) return; d->bAddToAnchor = false; for(int i = 0; i < tmpLayout->count(); i++) { if(tmpLayout->itemAt(i) == item) { tmpLayout->removeAt(i); break; } } }
void tst_QGraphicsAnchorLayout::linearVsAnchorSizeHints() { QFETCH(int, whichSizeHint); QFETCH(int, whichLayout); QGraphicsLayout *l = createLayouts(whichLayout); QSizeF sizeHint; // warm up instruction cache l->invalidate(); sizeHint = l->effectiveSizeHint((Qt::SizeHint)whichSizeHint); // ...then measure... QBENCHMARK { l->invalidate(); sizeHint = l->effectiveSizeHint((Qt::SizeHint)whichSizeHint); } }
void MScenePrivate::sendEventToAllSubLayouts(QGraphicsLayout *layout, QEvent *event) { for (int i = layout->count()-1; i >= 0; --i) { // QGraphicsLayout::itemAt allows the subclasses to assume that item index is valid (within the count boundaries). // The items might be removed from layout when it'll process the orientation change event. if (i >= layout->count()) i = layout->count() - 1; // The layout may end up empty, thus we should early out if it happens if (i < 0) return; QGraphicsLayoutItem * layoutItem = layout->itemAt(i); if (layoutItem->isLayout()) { QGraphicsLayout *layout = static_cast<QGraphicsLayout *>(layoutItem); layout->widgetEvent(event); MScenePrivate::sendEventToAllSubLayouts(layout, event); } } }
/*! \reimp Invalidates parent layout when ItemTransformHasChanged is received. */ QVariant HbAbstractViewItem::itemChange(GraphicsItemChange change, const QVariant &value) { switch (change) { case ItemTransformHasChanged: { QGraphicsLayoutItem *parentLayoutItem = this->parentLayoutItem(); if (parentLayoutItem && parentLayoutItem->isLayout()) { QGraphicsLayout *parentLayout = static_cast<QGraphicsLayout *>(parentLayoutItem); parentLayout->invalidate(); } break; } case ItemEnabledHasChanged: { updateChildItems(); break; } default: break; } return HbWidget::itemChange(change, value); }
void QGraphicsLayoutPrivate::activateRecursive(QGraphicsLayoutItem *item) { if (item->isLayout()) { QGraphicsLayout *layout = static_cast<QGraphicsLayout *>(item); if (layout->d_func()->activated) layout->invalidate(); for (int i = layout->count() - 1; i >= 0; --i) { QGraphicsLayoutItem *childItem = layout->itemAt(i); if (childItem) activateRecursive(childItem); } layout->d_func()->activated = true; } }
void QGraphicsLayoutPrivate::activateRecursive(QGraphicsLayoutItem *item) { if (item->isLayout()) { QGraphicsLayout *layout = static_cast<QGraphicsLayout *>(item); if (layout->d_func()->activated) { if (QGraphicsLayout::instantInvalidatePropagation()) { return; } else { layout->invalidate(); // ### LOOKS SUSPICIOUSLY WRONG!!??? } } for (int i = layout->count() - 1; i >= 0; --i) { QGraphicsLayoutItem *childItem = layout->itemAt(i); if (childItem) activateRecursive(childItem); } layout->d_func()->activated = true; } }
void KWidget::activateLayout() { QGraphicsLayout *layout = this->layout(); layout->activate(); }
void Ut_MGridLayoutPolicy::testHeightForWidthInSubLayout() { QFETCH(bool, useMLayout); QFETCH(bool, useInnerMLayout); QFETCH(bool, putInnerWidgetInWidget); QGraphicsWidget *form = new QGraphicsWidget; MGridLayoutPolicy *mpolicy = NULL; QGraphicsGridLayout *qlayout = NULL; if (useMLayout) { MLayout *mlayout = new MLayout(form); mlayout->setContentsMargins(0, 0, 0, 0); mpolicy = new MGridLayoutPolicy(mlayout); mpolicy->setSpacing(0); } else { qlayout = new QGraphicsGridLayout(form); qlayout->setContentsMargins(0, 0, 0, 0); qlayout->setSpacing(0); } QGraphicsWidget *topSpacer = createSpacer(); QGraphicsWidget *leftSpacer = createSpacer(); QGraphicsWidget *rightSpacer = createSpacer(); leftSpacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); rightSpacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); QGraphicsWidget *square = new SquareWidget; QGraphicsLayout *innerLayout = NULL; if (useInnerMLayout) { innerLayout = new MLayout(); MLinearLayoutPolicy *policy = new MLinearLayoutPolicy(static_cast<MLayout *>(innerLayout), Qt::Horizontal); policy->addItem(square); } else { innerLayout = new QGraphicsLinearLayout(Qt::Horizontal); static_cast<QGraphicsLinearLayout *>(innerLayout)->addItem(square); } innerLayout->setContentsMargins(0,0,0,0); QGraphicsLayoutItem *innerItem; if (putInnerWidgetInWidget) { QGraphicsWidget *innerWidget = new QGraphicsWidget; innerWidget->setLayout(innerLayout); innerItem = innerWidget; } else { innerItem = innerLayout; } if (useMLayout) { mpolicy->addItem(topSpacer, 0, 1); mpolicy->addItem(leftSpacer, 1, 0); mpolicy->addItem(rightSpacer, 1, 2); mpolicy->addItem(innerItem, 1, 1); } else { qlayout->addItem(topSpacer, 0, 1); qlayout->addItem(leftSpacer, 1, 0); qlayout->addItem(rightSpacer, 1, 2); qlayout->addItem(innerItem, 1, 1); } QCOMPARE(form->preferredSize(), QSizeF(500,500)); QCOMPARE(form->effectiveSizeHint(Qt::PreferredSize, QSizeF(100,-1)), QSizeF(100,100)); delete form; }
void tst_QGraphicsAnchorLayout::linearVsAnchorNested() { QFETCH(int, whichLayout); QSizeF min(10, 10); QSizeF pref(80, 80); QSizeF max(150, 150); QGraphicsWidget *a = createItem(min, pref, max, "a"); QGraphicsWidget *b = createItem(min, pref, max, "b"); QGraphicsWidget *c = createItem(min, pref, max, "c"); QGraphicsWidget *d = createItem(min, pref, max, "d"); QGraphicsLayout *layout; if (whichLayout == 0) { QGraphicsLinearLayout *linear1 = new QGraphicsLinearLayout; QGraphicsLinearLayout *linear2 = new QGraphicsLinearLayout(Qt::Vertical); QGraphicsLinearLayout *linear3 = new QGraphicsLinearLayout; linear1->addItem(a); linear1->addItem(linear2); linear2->addItem(b); linear2->addItem(linear3); linear3->addItem(c); linear3->addItem(d); layout = linear1; } else if (whichLayout == 1) { QGraphicsAnchorLayout *anchor = new QGraphicsAnchorLayout; // A anchor->addCornerAnchors(a, Qt::TopLeftCorner, anchor, Qt::TopLeftCorner); anchor->addCornerAnchors(a, Qt::TopRightCorner, b, Qt::TopLeftCorner); anchor->addCornerAnchors(a, Qt::BottomLeftCorner, anchor, Qt::BottomLeftCorner); anchor->addCornerAnchors(a, Qt::BottomRightCorner, c, Qt::BottomLeftCorner); // B anchor->addCornerAnchors(b, Qt::TopRightCorner, anchor, Qt::TopRightCorner); anchor->addCornerAnchors(b, Qt::BottomLeftCorner, c, Qt::TopLeftCorner); anchor->addCornerAnchors(b, Qt::BottomRightCorner, d, Qt::TopRightCorner); // C anchor->addCornerAnchors(c, Qt::TopRightCorner, d, Qt::TopLeftCorner); anchor->addCornerAnchors(c, Qt::BottomRightCorner, d, Qt::BottomLeftCorner); // D anchor->addCornerAnchors(d, Qt::BottomRightCorner, anchor, Qt::BottomRightCorner); layout = anchor; } else { QGraphicsAnchorLayout *anchor = new QGraphicsAnchorLayout; // A anchor->addAnchor(a, Qt::AnchorLeft, anchor, Qt::AnchorLeft); anchor->addAnchors(a, anchor, Qt::Vertical); anchor->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorLeft); anchor->addAnchor(a, Qt::AnchorRight, c, Qt::AnchorLeft); // B anchor->addAnchor(b, Qt::AnchorTop, anchor, Qt::AnchorTop); anchor->addAnchor(b, Qt::AnchorRight, anchor, Qt::AnchorRight); anchor->addAnchor(b, Qt::AnchorBottom, c, Qt::AnchorTop); anchor->addAnchor(b, Qt::AnchorBottom, d, Qt::AnchorTop); // C anchor->addAnchor(c, Qt::AnchorRight, d, Qt::AnchorLeft); anchor->addAnchor(c, Qt::AnchorBottom, anchor, Qt::AnchorBottom); // D anchor->addAnchor(d, Qt::AnchorRight, anchor, Qt::AnchorRight); anchor->addAnchor(d, Qt::AnchorBottom, anchor, Qt::AnchorBottom); layout = anchor; } QSizeF sizeHint; // warm up instruction cache layout->invalidate(); sizeHint = layout->effectiveSizeHint(Qt::PreferredSize); // ...then measure... QBENCHMARK { // To ensure that all sizeHints caches are invalidated in // the LinearLayout setup, we must call updateGeometry on the // children. If we didn't, only the top level layout would be // re-calculated. static_cast<QGraphicsLayoutItem *>(a)->updateGeometry(); static_cast<QGraphicsLayoutItem *>(b)->updateGeometry(); static_cast<QGraphicsLayoutItem *>(c)->updateGeometry(); static_cast<QGraphicsLayoutItem *>(d)->updateGeometry(); layout->invalidate(); sizeHint = layout->effectiveSizeHint(Qt::PreferredSize); } }
/*! View layout loading from XML */ void NmViewerView::loadViewLayout() { NM_FUNCTION; // Use document loader to load the view bool ok(false); setObjectName(QString(NMUI_MESSAGE_VIEWER_VIEW)); QObjectList objectList; objectList.append(this); // Pass the view to documentloader. Document loader uses this view // when docml is parsed, instead of creating new view. // documentloader is created in constructor mDocumentLoader->setObjectTree(objectList); mWidgetList = mDocumentLoader->load(NMUI_MESSAGE_VIEWER_XML, &ok); if (ok) { // Create content and content layout // qobject_cast not work in this case, using reinterpret_cast mViewerContent = reinterpret_cast<HbWidget *>( mDocumentLoader->findObject(NMUI_MESSAGE_VIEWER_CONTENT)); // Find scroll area mScrollArea = reinterpret_cast<HbScrollArea *>( mDocumentLoader->findObject(NMUI_MESSAGE_VIEWER_SCROLL_AREA)); if (mScrollArea) { mScrollArea->setParentItem(this); mScrollArea->setScrollDirections(Qt::Vertical | Qt::Horizontal); connect(mScrollArea, SIGNAL(scrollPositionChanged(QPointF)), this, SLOT(contentScrollPositionChanged(QPointF))); // Get scroll area contents and set layout margins mScrollAreaContents = qobject_cast<HbWidget *>( mDocumentLoader->findObject(NMUI_MESSAGE_VIEWER_SCROLL_AREA_CONTENTS)); if (mScrollAreaContents) { QGraphicsLayout *layout = mScrollAreaContents->layout(); if (layout){ layout->setContentsMargins(0,0,0,0); } // Set white pixmap to backgrounditem QPixmap whitePixmap(NmWhitePixmapSize,NmWhitePixmapSize); whitePixmap.fill(Qt::white); QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem(whitePixmap); mScrollAreaContents->setBackgroundItem(pixmapItem); } // Load headerwidget mHeaderWidget = qobject_cast<NmViewerHeader *>( mDocumentLoader->findObject(NMUI_MESSAGE_VIEWER_HEADER)); if (mHeaderWidget) { mHeaderWidget->setView(this); mHeaderWidget->rescaleHeader(mScreenSize); mHeaderWidget->setMessage(mMessage); QPointF headerStartPos = mHeaderWidget->scenePos(); mHeaderStartScenePos = QPointF(0,headerStartPos.y()); } // Load webview mWebView = reinterpret_cast<NmMailViewerWK *>( mDocumentLoader->findObject(QString(NMUI_MESSAGE_VIEWER_SCROLL_WEB_VIEW))); if (mWebView) { // Set auto load images and private browsing(no history) attributes QWebSettings *settings = mWebView->settings(); if (settings) { settings->setAttribute(QWebSettings::AutoLoadImages, true); settings->setAttribute(QWebSettings::PrivateBrowsingEnabled, true); } QWebPage *page = mWebView->page(); if (page) { QWebFrame *frame = page->mainFrame(); if (frame) { frame->setScrollBarPolicy(Qt::Vertical,Qt::ScrollBarAlwaysOff); frame->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff); frame->setTextSizeMultiplier(NmZoomFactor); connect(mWebView->page()->mainFrame(), SIGNAL(contentsSizeChanged(const QSize&)), this, SLOT(scaleWebViewWhenLoading(const QSize&))); } } } } } }