Пример #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);
}
/* Sets geometry to given size. */
void SquareItemWithSidePaneLayout::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->hasBothItems() ||
		areRectsEqual(*this->lastReceivedRect, rect))
	{
		return;
	}
	/* Replace the last received rectangle. */
	setLastReceivedRect(rect);

	// calculate proper size
	const int sidepane_width = dynamic_cast<SidePane *>(sidepane_item->widget())->desiredWidth();
	//const int total_width = rect.width() - sidepane_width;
	
	// calculate all the sizes
	int height;
	QPoint pos;

	float aspect_ratio=1.5;

	if(rect.height()*aspect_ratio < rect.width() - sidepane_width)
	{
		height = rect.height() - this->margin();
		pos.setX(rect.width()/2 - (height*aspect_ratio + sidepane_width)/2);
	}
	else
	{
		height = (rect.width() - sidepane_width - this->margin())/aspect_ratio;
		pos.setY(rect.height()/2 - height/2);
	}
	QSize glwidget_size(height*aspect_ratio, height);
	QSize sidepane_size(sidepane_width, height);
	QSize total_size(height + sidepane_width, height);

	// calculate positions
	QPoint glwidget_pos(pos);
	QPoint sidepane_pos(pos + QPoint(height*aspect_ratio, 0));
	QPoint total_pos(glwidget_pos);

	// backup
	QRect* oldRect = this->_geometry;
	delete oldRect;

	// set geometries
	this->glwidget_item->setGeometry(QRect(glwidget_pos, glwidget_size));
	this->sidepane_item->setGeometry(QRect(sidepane_pos, sidepane_size));
	this->_geometry = new QRect(total_pos, total_size);
	QLayout::setGeometry(*this->_geometry);
}
Пример #3
0
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 );
	///////////////////////////////////
}