Exemple #1
0
/* Sets geometry to given size. */
void QAspectRatioLayout::setGeometry(const QRect& rect) {
        /*
         * We check if the item is set and
         * if size is the same previously received.
         * If either is false nothing is done.
         */
        if(!this->hasItem() ||
           areRectsEqual(*this->lastReceivedRect, rect)) {
                return;
        }
        /* Replace the last received rectangle. */
        setLastReceivedRect(rect);
        /* Calculate proper size for the item relative to the received size. */
        QSize properSize = calculateProperSize(rect.size());
        /* Calculate center location in the rect and with item size. */
        QPoint properLocation = calculateCenterLocation(rect.size(), properSize);
        /* Set items geometry */
        this->item->setGeometry(QRect(properLocation, properSize));
        QRect* oldRect = this->_geometry;
        /* Cache the calculated geometry. */
        this->_geometry = new QRect(properLocation, properSize);
        delete oldRect;
        /* Super classes setGeometry */
        QLayout::setGeometry(*this->_geometry);
}
void LayoutSquare::setGeometry( const QRect &rect )
{

	if ( !hasItem() || areRectsEqual( *m_rectLast, rect ) ) return;

	setRectLast( rect );

	QSize  properSize  = calculateProperSize( rect.size() );
	QPoint centerPoint = calculateCenterPnt( rect.size(), properSize );

	m_item->setGeometry( QRect( centerPoint, properSize ) );

	QRect *tempRect = m_geometry;

	m_geometry = new QRect( centerPoint, properSize );

	delete tempRect;

	///////////////////////////////////
	QLayout::setGeometry( *m_geometry );
	///////////////////////////////////
}