⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 customlayout-main-cpp.html

📁 qtopiaphone英文帮助,用于初学者和开发人员,初学者可以用来学习,开发人员可以用来资料查询.
💻 HTML
📖 第 1 页 / 共 3 页
字号:
            item = i;            pos = p;        }        <a href="qlayoutitem.html">QLayoutItem</a> *item;        Position pos;    };    enum SizeType {        Minimum = 0,        SizeHint    };    BorderLayout( <a href="qwidget.html">QWidget</a> *parent, int border = 0, int autoBorder = -1,                  const char *name = 0 )        : <a href="qlayout.html">QLayout</a>( parent, border, autoBorder, name ), cached( 0, 0 ), mcached( 0, 0 ),          sizeDirty( TRUE ), msizeDirty( TRUE )    {}    BorderLayout( <a href="qlayout.html">QLayout</a>* parent, int autoBorder = -1, const char *name = 0 )        : <a href="qlayout.html">QLayout</a>( parent, autoBorder, name  ), cached( 0, 0 ), mcached( 0, 0 ),          sizeDirty( TRUE ), msizeDirty( TRUE )    {}    BorderLayout( int autoBorder = -1, const char *name = 0 )        : <a href="qlayout.html">QLayout</a>( autoBorder, name ), cached( 0, 0 ), mcached( 0, 0 ),          sizeDirty( TRUE ), msizeDirty( TRUE )    {}    ~BorderLayout();    void addItem( <a href="qlayoutitem.html">QLayoutItem</a> *item );    void addWidget( <a href="qwidget.html">QWidget</a> *widget, Position pos );    void add( <a href="qlayoutitem.html">QLayoutItem</a> *item, Position pos );    bool hasHeightForWidth() const;    <a href="qsize.html">QSize</a> sizeHint() const;    <a href="qsize.html">QSize</a> minimumSize() const;    <a href="qlayoutiterator.html">QLayoutIterator</a> iterator();    <a href="qsizepolicy.html#ExpandData">QSizePolicy::ExpandData</a> expanding() const;protected:    void setGeometry( const QRect &amp;rect );private:    void doLayout( const QRect &amp;rect, bool testonly = FALSE );    void calcSize( SizeType st );    <a href="qlist.html">QList</a>&lt;BorderLayoutStruct&gt; list;    <a href="qsize.html">QSize</a> cached, mcached;    bool sizeDirty, msizeDirty;};#endif</pre>  <hr>  Implementation of the Border-Layout: <pre>/****************************************************************************** &#36;Id&#58; qt/examples/customlayout/border.cpp   2.3.8   edited 2004-05-12 $**** Implementing your own layout: flow example**** Copyright (C) 1996 by Trolltech AS.  All rights reserved.**** This file is part of an example program for Qt.  This example** program may be used, distributed and modified without limitation.*******************************************************************************/#include "border.h"class BorderLayoutIterator : public QGLayoutIterator{public:    BorderLayoutIterator( const QList&lt;BorderLayout::BorderLayoutStruct&gt; *l )        : idx( 0 ) , list( (<a href="qlist.html">QList</a>&lt;BorderLayout::BorderLayoutStruct&gt;*)l )    {}    uint count() const;    <a href="qlayoutitem.html">QLayoutItem</a> *current();    BorderLayout::BorderLayoutStruct *currentStruct();    void toFirst();    <a href="qlayoutitem.html">QLayoutItem</a> *next();    <a href="qlayoutitem.html">QLayoutItem</a> *takeCurrent();    BorderLayoutIterator &amp;operator++();private:    int idx;    <a href="qlist.html">QList</a>&lt;BorderLayout::BorderLayoutStruct&gt; *list;};uint <a name="273"></a>BorderLayoutIterator::count() const{    return list-&gt;<a href="qlist.html#359d9f">count</a>();}<a href="qlayoutitem.html">QLayoutItem</a> *<a name="274"></a>BorderLayoutIterator::current(){    return idx &lt; (int)count() ? list-&gt;<a href="qlist.html#0e7e42">at</a>( idx )-&gt;item : 0;}BorderLayout::BorderLayoutStruct *<a name="275"></a>BorderLayoutIterator::currentStruct(){    return idx &lt; (int)count() ? list-&gt;<a href="qlist.html#0e7e42">at</a>( idx ) : 0;}void <a name="276"></a>BorderLayoutIterator::toFirst(){    idx = 0;}<a href="qlayoutitem.html">QLayoutItem</a> *<a name="277"></a>BorderLayoutIterator::next(){    idx++;    return current();}<a href="qlayoutitem.html">QLayoutItem</a> *<a name="278"></a>BorderLayoutIterator::takeCurrent(){    BorderLayout::BorderLayoutStruct *b        = idx &lt; int( list-&gt;<a href="qlist.html#359d9f">count</a>() ) ? list-&gt;<a href="qlist.html#0639ad">take</a>(  idx  ) : 0;    <a href="qlayoutitem.html">QLayoutItem</a> *item =  b ? b-&gt;item : 0;    delete b;    return item;}BorderLayoutIterator &amp;<a href=#279><a name="279"></a>BorderLayoutIterator::operator</a>++(){    <a href=#277>next</a>();    return *this;}BorderLayout::~BorderLayout(){    deleteAllItems();}void <a name="280"></a>BorderLayout::addItem( <a href="qlayoutitem.html">QLayoutItem</a> *item ){    <a href=#282>add</a>( item, West );}void <a name="281"></a>BorderLayout::addWidget( <a href="qwidget.html">QWidget</a> *widget, Position pos ){    <a href=#282>add</a>( new BorderWidgetItem( widget ), pos );}void <a name="282"></a>BorderLayout::add( <a href="qlayoutitem.html">QLayoutItem</a> *item, Position pos ){    list.<a href="qlist.html#c5746a">append</a>( new BorderLayoutStruct( item, pos ) );    sizeDirty = TRUE; msizeDirty = TRUE;    <a href=#290>calcSize</a>( SizeHint ); calcSize( Minimum );}bool <a name="283"></a>BorderLayout::hasHeightForWidth() const{    return FALSE;}<a href="qsize.html">QSize</a> <a name="284"></a>BorderLayout::sizeHint() const{    return cached;}<a href="qsize.html">QSize</a> <a name="285"></a>BorderLayout::minimumSize() const{    return cached;}<a href="qsizepolicy.html#ExpandData">QSizePolicy::ExpandData</a> <a name="286"></a>BorderLayout::expanding() const{    return QSizePolicy::BothDirections;}<a href="qlayoutiterator.html">QLayoutIterator</a> <a name="287"></a>BorderLayout::iterator(){    return QLayoutIterator( new BorderLayoutIterator( &amp;list ) );}void <a name="288"></a>BorderLayout::setGeometry( const QRect &amp;rct ){    <a href="qlayout.html#f1f752">QLayout::setGeometry</a>( rct );    <a href=#289>doLayout</a>( rct );}void <a name="289"></a>BorderLayout::doLayout( const QRect &amp;rct, bool /*testonly*/ ){    int ew = 0, ww = 0, nh = 0, sh = 0;    int h = 0;    BorderLayoutIterator it = BorderLayoutIterator( &amp;list );    BorderLayoutStruct *o;    BorderLayoutStruct *center = 0;    while ( ( o = it.currentStruct() ) != 0 ) {        ++it;        if ( o-&gt;pos == North ) {            o-&gt;item-&gt;setGeometry( <a href="qrect.html">QRect</a>( rct.x(), nh, rct.width(), o-&gt;item-&gt;sizeHint().height() ) );            nh += o-&gt;item-&gt;geometry().height() + spacing();        }        if ( o-&gt;pos == South ) {            o-&gt;item-&gt;setGeometry( <a href="qrect.html">QRect</a>( o-&gt;item-&gt;geometry().x(), o-&gt;item-&gt;geometry().y(),                                         rct.width(), o-&gt;item-&gt;sizeHint().height() ) );            sh += o-&gt;item-&gt;geometry().height() + spacing();            o-&gt;item-&gt;setGeometry( <a href="qrect.html">QRect</a>( rct.x(), rct.y() + rct.height() - sh + spacing(),                                         o-&gt;item-&gt;geometry().width(), o-&gt;item-&gt;geometry().height() ) );        }        if ( o-&gt;pos == Center )            center = o;    }    h = rct.height() - nh - sh;    it.toFirst();    while ( ( o = it.currentStruct() ) != 0 ) {        ++it;        if ( o-&gt;pos == West ) {            o-&gt;item-&gt;setGeometry( <a href="qrect.html">QRect</a>( rct.x() + ww, nh, o-&gt;item-&gt;sizeHint().width(), h ) );            ww += o-&gt;item-&gt;geometry().width() + spacing();        }        if ( o-&gt;pos == East ) {            o-&gt;item-&gt;setGeometry( <a href="qrect.html">QRect</a>( o-&gt;item-&gt;geometry().x(), o-&gt;item-&gt;geometry().y(),                                         o-&gt;item-&gt;sizeHint().width(), h ) );            ew += o-&gt;item-&gt;geometry().width() + spacing();            o-&gt;item-&gt;setGeometry( <a href="qrect.html">QRect</a>( rct.x() + rct.width() - ew + spacing(), nh,                                         o-&gt;item-&gt;geometry().width(), o-&gt;item-&gt;geometry().height() ) );        }    }    if ( center )        center-&gt;item-&gt;setGeometry( <a href="qrect.html">QRect</a>( ww, nh, rct.width() - ew - ww, h ) );}void <a name="290"></a>BorderLayout::calcSize( SizeType st ){    if ( ( st == Minimum &amp;&amp; !msizeDirty ) ||         ( st == SizeHint &amp;&amp; !sizeDirty ) )        return;    int w = 0, h = 0;    BorderLayoutIterator it = BorderLayoutIterator( &amp;list );    BorderLayoutStruct *o;    while ( ( o = it.currentStruct() ) != 0 ) {        ++it;        if ( o-&gt;pos == North ||             o-&gt;pos == South ) {            if ( st == Minimum )                h += o-&gt;item-&gt;minimumSize().height();            else                h += o-&gt;item-&gt;sizeHint().height();        }        else if ( o-&gt;pos == West ||                  o-&gt;pos == East ) {            if ( st == Minimum )                w += o-&gt;item-&gt;minimumSize().width();            else                w += o-&gt;item-&gt;sizeHint().width();        } else {            if ( st == Minimum ) {                h += o-&gt;item-&gt;minimumSize().height();                w += o-&gt;item-&gt;minimumSize().width();            }            else {                h += o-&gt;item-&gt;sizeHint().height();                w += o-&gt;item-&gt;sizeHint().width();            }        }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -