Esempio n. 1
0
void StatusBarLayout::updateLayoutStructs() const
{
    if( ! mIsDirty )
        return;

    StatusBarLayout* that = const_cast<StatusBarLayout*>( this );

//     const int margin = this->margin();
    const int spacing = this->spacing();

    QSize sizeHint( 0, 0 );

    int visibleCount = 0;
    for( int i = 0; i < mWidgetList.count(); ++i )
    {
        QWidgetItem* item = mWidgetList.at( i );

        if( ! item->isEmpty() )
        {
            const QSize itemSizeHint = item->sizeHint();

            sizeHint.rwidth() += (visibleCount == 0 ? 0 : spacing) + itemSizeHint.width();
            sizeHint.rheight() = qMax( sizeHint.height(), itemSizeHint.height() );
            ++visibleCount;
        }
    }
//     sizeHint += QSize( 2*margin, 2*margin );

    that->mIsEmpty =         ( visibleCount == 0 );
    that->mSizeHint =        sizeHint;
    that->mIsDirty =         false;
}
Esempio n. 2
0
void StatusBarLayout::setGeometry( const QRect& _rect )
{
    QLayout::setGeometry( _rect );

    if( mIsDirty )
        updateLayoutStructs();

    QRect rect( 0, 0, _rect.width(), _rect.height() );

    const int margin = 0;//this->margin();
    const int spacing = this->spacing();

    int availableWidth =        rect.size().width()  - 2*margin;
    const int availableHeight = rect.size().height() - 2*margin;

    int usedWidth = 0;
    int visibleCount = 0;
    int i;
    for( i = 0; i<mWidgetList.count(); ++i )
    {
        QWidgetItem* item = mWidgetList.at( i );
        QWidget* widget = item->widget();

        // TODO: is there really no way to get to the geometry data if a widget is hidden?
        if( widget->isHidden() )
            widget->show();

        const int itemWidth = item->sizeHint().width();
        const int itemSpacing = ( visibleCount == 0 ) ? 0 : spacing;
        const int newUsedWidth = usedWidth + itemSpacing + itemWidth;
// kDebug()<<widget<<<<availableWidth<<usedWidth<<itemWidth<<itemSpacing<<newUsedWidth;

        const bool isTooWide = ( newUsedWidth > availableWidth );

        if( isTooWide )
            break;

        const QPoint pos( margin + usedWidth, margin );
        const QSize size( itemWidth, availableHeight );
        QRect r( pos, size );

        r = QStyle::visualRect( parentWidget()->layoutDirection(), rect, r );

        item->setGeometry( r );

        usedWidth = newUsedWidth;

        ++visibleCount;
    }
    // hide the rest if needed
    for( ; i<mWidgetList.count(); ++i )
    {
        QWidgetItem* item = mWidgetList.at( i );
        QWidget* widget = item->widget();

        if( ! widget->isHidden() )
            widget->hide();
    }
}
static PyObject *meth_QWidgetItem_sizeHint(PyObject *sipSelf, PyObject *sipArgs)
{
    PyObject *sipParseErr = NULL;
    bool sipSelfWasArg = (!sipSelf || sipIsDerived((sipSimpleWrapper *)sipSelf));

    {
        QWidgetItem *sipCpp;

        if (sipParseArgs(&sipParseErr, sipArgs, "B", &sipSelf, sipType_QWidgetItem, &sipCpp))
        {
            QSize *sipRes;

            Py_BEGIN_ALLOW_THREADS
            sipRes = new QSize((sipSelfWasArg ? sipCpp->QWidgetItem::sizeHint() : sipCpp->sizeHint()));
            Py_END_ALLOW_THREADS

            return sipConvertFromNewType(sipRes,sipType_QSize,NULL);
        }
    }