コード例 #1
0
ファイル: visualizeritem.cpp プロジェクト: kammoh/kactus2
//-----------------------------------------------------------------------------
// Function: itemTotalRect()
//-----------------------------------------------------------------------------
QRectF VisualizerItem::itemTotalRect() const
{
	// the rectangle that contains this item
	QRectF totalRect(rect());

	// if there are children
	QList<QGraphicsItem*> children = childItems();
	foreach (QGraphicsItem* child, children)
    {
		// the rectangle must contain this item and also the child item
		VisualizerItem* childItem = dynamic_cast<VisualizerItem*>(child);
		if (childItem && childItem->isVisible())
        {
			totalRect = totalRect.united(mapRectFromItem(child, childItem->itemTotalRect()));
		}
	}
コード例 #2
0
ファイル: CGUIPanel.cpp プロジェクト: jivibounty/irrlicht
void CGUIPanel::resizeInnerPane()
{
	if (!HScrollBar || !VScrollBar || !InnerPane || !ClipPane)
		return;

    s32 newHPos = HScrollBar->getPos();
    s32 newVPos = VScrollBar->getPos();

	// get outer pane size
	core::rect<s32> outerRect = ClipPane->getRelativePosition();

	// resize flexible children depending on outer pane
	InnerPane->setRelativePosition(outerRect);
	
	// get desired size (total size of all children)
	core::rect<s32> totalRect(0,0,0,0);

	core::list<IGUIElement*>::ConstIterator it;
       
	for ( it = InnerPane->getChildren().begin();
		it != InnerPane->getChildren().end(); ++it )
	{
		core::rect<s32> rct = (*it)->getRelativePosition();
		totalRect.addInternalPoint(rct.UpperLeftCorner);
		totalRect.addInternalPoint(rct.LowerRightCorner);
	}

	// move children if pane needs to grow
	core::position2di adjustedMovement(0,0);

	if (totalRect.UpperLeftCorner.X < 0)
		adjustedMovement.X = -totalRect.UpperLeftCorner.X;
	if (totalRect.UpperLeftCorner.Y < 0)
		adjustedMovement.Y = -totalRect.UpperLeftCorner.Y;

	if (adjustedMovement.X > 0 || adjustedMovement.Y > 0)
	{
		totalRect += adjustedMovement;

		for (it = InnerPane->getChildren().begin();
			it != InnerPane->getChildren().end(); ++it )
		{
			(*it)->move(adjustedMovement);
		}
	}

	// make sure the inner pane is at least as big as the outer
	if (totalRect.getWidth() < outerRect.getWidth())
	{
		totalRect.UpperLeftCorner.X = 0;
		totalRect.LowerRightCorner.X = outerRect.getWidth();
	}
	if (totalRect.getHeight() < outerRect.getHeight())
	{
		totalRect.UpperLeftCorner.Y = 0;
		totalRect.LowerRightCorner.Y = outerRect.getHeight();
	}

	InnerPane->setRelativePosition(totalRect);
	
	// scrollbars
	if ( HScrollBarMode != ESBM_ALWAYS_INVISIBLE && 
		(totalRect.getWidth() > outerRect.getWidth() || HScrollBarMode == ESBM_ALWAYS_VISIBLE) )
	{
		HScrollBar->setVisible(true);
		HScrollBar->setMax(totalRect.getWidth() - outerRect.getWidth());
	}
	else
		HScrollBar->setVisible(false);
    
	if ( VScrollBarMode != ESBM_ALWAYS_INVISIBLE &&
		(totalRect.getHeight() > outerRect.getHeight() || VScrollBarMode == ESBM_ALWAYS_VISIBLE) )
	{
		VScrollBar->setVisible(true);
		VScrollBar->setMax(totalRect.getHeight() - outerRect.getHeight());
	}
	else
		VScrollBar->setVisible(false);

	// move to adjust for scrollbar pos
	moveInnerPane();
}