void setTwoColumns(const bool twoColumns)
    {
        if(twoColumns == m_twoColumns)
            return;

        Q_Q(SimpleListView);
        m_twoColumns = twoColumns;

#if (QT_VERSION >= 0x040600)
        bool cache = q->listItemCaching();
        q->setListItemCaching(false);
#endif
        QList<QGraphicsLayoutItem *> moveditems;
        if(twoColumns) {
            int half = m_layout->count()/2;
            for (int i = m_layout->count()-1; i>=half; --i) {
                QGraphicsLayoutItem *item = m_layout->itemAt(i);
                m_layout->removeAt(i);
                moveditems.append(item);
            }            
            for ( int i = 0; i < moveditems.count(); ++i)
                m_layout->addItem(moveditems.at(i), i, 1);

            m_layout->setColumnSpacing(0,0);
            m_layout->setColumnSpacing(1,0);
            m_layout->setRowSpacing(0,0);
            m_layout->setRowSpacing(1,0);
        }
        else {
            int count = m_layout->count()/2;
            for (int i = m_layout->count()-1;  i>=0; --i) {
                if (i >= count)
                    moveditems.append(m_layout->itemAt(i));
                else
                    moveditems.insert(moveditems.begin(), m_layout->itemAt(i));
                m_layout->removeAt(i);                
            }
            for (int i = 0; i<moveditems.count(); ++i) {
                m_layout->addItem(moveditems.at(i), m_layout->count(), 0);
            }
        }

        resizeContents(q->size());
        resizeScrollBars();

#if (QT_VERSION >= 0x040600)
        q->setListItemCaching(cache);
#endif
    }
Example #2
0
/*!
 Move such that (x,y) is visible and with at least the given
 pixel margins (if possible, otherwise, centered).
*/
void QwViewport::ensureVisible(int x, int y, int xmargin, int ymargin)
{
	// Algorithm taken from my WAX++ original

	int pw=portHole()->width();
	int ph=portHole()->height();

	QWidget* child=viewedWidget();
	if (!child) return;

	int cx=child->x();
	int cy=child->y();
	int cw=child->width();
	int ch=child->height();

	// int mbw=0; // XXX border width - is this a problem in Qt?

	if (pw < xmargin*2) xmargin=pw/2;
	if (ph < ymargin*2) ymargin=ph/2;

	if (cw <= pw) { xmargin=0; cx=0; }
	if (ch <= ph) { ymargin=0; cy=0; }

	if (x < -cx+xmargin) {
		cx = -x+pw-xmargin;
	} else if (x >= -cx+pw-xmargin) {
		cx = -x+xmargin;
	}

	if (y < -cy+ymargin) {
		cy = -y+ph-ymargin;
	} else if (y >= -cy+ph-ymargin) {
		cy = -y+ymargin;
	}

	if (cx > 0) cx=0;
	else if (cx < pw-cw && cw>pw) cx=pw-cw;
	if (cy > 0) cy=0;
	else if (cy < ph-ch && ch>ph) cy=ph-ch;

	// Choke signal handling while we update BOTH sliders.
	signal_choke=true;
	child->move(cx,cy);
	vbar.setValue(-cy);
	hbar.setValue(-cx);
	resizeScrollBars();
	signal_choke=false;
}
Example #3
0
/*!
An override - ensures scrollbars are correct size upon resize.
*/
void QwViewport::resizeEvent(QResizeEvent* event)
{
	QWidget::resizeEvent(event);
	resizeScrollBars();
}
Example #4
0
/*!
An override - ensures scrollbars are correct size upon showing.
*/
void QwViewport::show()
{
	resizeScrollBars();
	QWidget::show();
}