QSpacerItem *QLayoutItemProto::spacerItem() { QLayoutItem *item = qscriptvalue_cast<QLayoutItem*>(thisObject()); if (item) return item->spacerItem(); return 0; }
void PropertyToolBox::addPage( QWidget* page ) { QBoxLayout* pageLayout = qobject_cast<QBoxLayout*>( page->layout() ); if ( pageLayout && pageLayout->direction() == QBoxLayout::TopToBottom ) { pageLayout->setContentsMargins( 5, 5, 5, 5 ); pageLayout->setSpacing( 3 ); for ( int i = 0; i < pageLayout->count(); i++ ) { QLayoutItem* item = pageLayout->itemAt( i ); if ( item->spacerItem() ) continue; QLabel* label = qobject_cast<QLabel*>( item->widget() ); if ( label ) { QString style = "border: none; border-bottom: 1px solid palette(dark);"; if ( i > 0 ) style += "margin-top: 2px;"; label->setStyleSheet( style ); continue; } QBoxLayout* itemLayout = qobject_cast<QBoxLayout*>( item->layout() ); if ( itemLayout && itemLayout->direction() == QBoxLayout::LeftToRight ) { itemLayout->insertSpacing( 0, 10 ); } else { pageLayout->removeItem( item ); QHBoxLayout* wrapperLayout = new QHBoxLayout(); wrapperLayout->addSpacing( 10 ); wrapperLayout->addItem( item ); pageLayout->insertLayout( i, wrapperLayout ); } } } page->setBackgroundRole( QPalette::Base ); addItem( page, page->windowTitle() ); }
void StatusBar::clearSpacing(QLayout *lp) { // Traverse the structure of the given layout ensuring that each object takes // no extra space. Start with the layout itself. lp->setMargin(0); lp->setSpacing(0); // Now examine its children, if any. int numItems = lp->count(); for (int i = 0; i < numItems; ++i) { QLayoutItem *child = lp->itemAt(i); // Recursively examine any nested layouts. QLayout *l = child->layout(); if (l) { clearSpacing(l); continue; } // Remove any spacer items. // Careful!! The list will shrink! QSpacerItem *s = child->spacerItem(); if (s) { lp->removeItem(s); delete s; --numItems; --i; } } }
int QIDialogButtonBox::findEmptySpace (QBoxLayout *aLayout) const { /* Search for the first occurrence of QSpacerItem and return the index. * Please note that this is Qt internal, so it may change at any time. */ int i=0; for (; i < aLayout->count(); ++i) { QLayoutItem *item = aLayout->itemAt(i); if (item->spacerItem()) break; } return i; }
bool layoutOperations::removeLastSpacing( QLayout *Layout ) { if ( Layout == NULL ) return false; int Count = Layout->count(); if ( Count <= 0 ) return false; QLayoutItem *LastLayoutItem = Layout->itemAt( Count-1 ); if ( LastLayoutItem == NULL || LastLayoutItem->spacerItem() == NULL ) return false; delete Layout->takeAt( Count-1 ); return true; }
QWidget* layoutOperations::lastWidgetAfterSpacing( QLayout* Layout ) { if ( Layout == NULL ) return NULL; int Count = Layout->count(); if ( Count <= 0 ) return NULL; QLayoutItem *LastLayoutItem = Layout->itemAt( Count-1 ); if ( LastLayoutItem == NULL ) return NULL; if ( LastLayoutItem->spacerItem() != NULL && Count > 1 ) LastLayoutItem = Layout->itemAt( Count-2 ); if ( LastLayoutItem == NULL ) return NULL; return LastLayoutItem->widget(); }
void layoutOperations::clearLayout( QLayout *Layout ) { if ( Layout == NULL ) return; while ( true ) { QLayoutItem *Item = Layout->takeAt(0); //qDebug() << "clearLayout: item = " << Item; if ( Item == NULL ) break; //qDebug() << "clearLayout: this is " << " " << Item->layout() << Item->spacerItem() << Item->widget(); QLayout *ItemLayout = Item->layout(); QSpacerItem *ItemSpacer = Item->spacerItem(); QWidget *ItemWidget = Item->widget(); if ( ItemLayout != NULL ) { clearLayout( ItemLayout ); ItemLayout->deleteLater(); delete Item; } else if ( ItemSpacer != NULL ) { delete Item; } else if ( ItemWidget != NULL ) { ItemWidget->deleteLater(); delete Item; } } }
//----------------------------------------------------------------------------- //! //----------------------------------------------------------------------------- void tMediaButtonBox::paintEvent( QPaintEvent* /*pEvent*/ ) { QPainter painter( this ); const QRect rect = contentsRect(); // background painter.fillRect( rect, palette().window() ); // separator drawing is supported only for QBoxLayout QBoxLayout* pLayout = qobject_cast< QBoxLayout* >( layout() ); if( !pLayout ) return; // if there is no space between the items, we don't draw any separator int halfSpacing = qRound( pLayout->spacing() * 0.5 ); if( halfSpacing == 0 ) return; // setup the pen to draw separators tNOSStyle* pNosStyle = qobject_cast< tNOSStyle* >( style() ); if( pNosStyle ) { QColor c = pNosStyle->GetColor( tNOSStyle::eNCR_Alternative1 ); c.setAlpha( 127 ); QPen pen( c ); pen.setCosmetic( true ); painter.setPen( pen ); } // separator bounds (X for horizontal sep, Y for vertical sep) int separatorOffset; if( pLayout->direction() == QBoxLayout::LeftToRight || pLayout->direction() == QBoxLayout::RightToLeft ) { separatorOffset = rect.height() / 7; } else { separatorOffset = rect.width() / 8; } int separatorX1 = rect.left() + separatorOffset; int separatorX2 = rect.right() - separatorOffset; int separatorY1 = rect.top() + separatorOffset; int separatorY2 = rect.bottom() - separatorOffset; // find the first visible widget or spacer (layouts are not handled yet, see below) int from = 0; QLayoutItem* fromItem = 0; for( from = 0; from < pLayout->count(); ++from ) { fromItem = pLayout->itemAt( from ); if( ( fromItem->widget() && fromItem->widget()->isVisible() ) || fromItem->spacerItem() ) break; } // iterate over each item and draw a separator between: // - two visible widgets // - a spacer and a visible widget // - a visible widget and a spacer // to be noted that embedded layouts are not handled yet (must be wrapped in a widget) for( int to = from + 1; to < pLayout->count(); ++to ) { QLayoutItem* toItem = pLayout->itemAt( to ); if( toItem->widget() ) { // if toItem is a visible widget, process it; if it is hidden, skip it if( toItem->widget()->isHidden() ) continue; } else if( toItem->spacerItem() ) { // skip empty spacer if( toItem->geometry().isEmpty() ) continue; if( fromItem->spacerItem() ) { // if fromItem and toItem are spacers, just take toItem as // the new reference but don't draw any separator from = to; fromItem = toItem; continue; } } // because a spacer item "eat" the spacing (i.e. there is no spacing added after a spacer) // we need to adjust the separator offset int tunedHalfSpacing = halfSpacing; if( fromItem->spacerItem() ) tunedHalfSpacing -= pLayout->spacing(); switch( pLayout->direction() ) { case QBoxLayout::LeftToRight: { int x = fromItem->geometry().right() + tunedHalfSpacing; painter.drawLine( x, separatorY1, x, separatorY2 ); } break; case QBoxLayout::RightToLeft: { int x = fromItem->geometry().left() - tunedHalfSpacing; painter.drawLine( x, separatorY1, x, separatorY2 ); } break; case QBoxLayout::TopToBottom: { int y = fromItem->geometry().bottom() + tunedHalfSpacing; painter.drawLine( separatorX1, y, separatorX2, y ); } break; case QBoxLayout::BottomToTop: { int y = fromItem->geometry().top() - tunedHalfSpacing; painter.drawLine( separatorX1, y, separatorX2, y ); } break; } from = to; fromItem = toItem; } }