diff options
Diffstat (limited to 'doc/html/customlayout.html')
-rw-r--r-- | doc/html/customlayout.html | 76 |
1 files changed, 38 insertions, 38 deletions
diff --git a/doc/html/customlayout.html b/doc/html/customlayout.html index ec772f1c6..3341c0de6 100644 --- a/doc/html/customlayout.html +++ b/doc/html/customlayout.html @@ -35,46 +35,46 @@ body { background: #ffffff; color: black; } <p> Here we present an example in detail. The class CardLayout is inspired by the Java layout manager of the same name. It lays out the items (widgets or nested layouts) on top of each other, each item offset by -<a href="ntqlayout.html#spacing">TQLayout::spacing</a>(). +<a href="tqlayout.html#spacing">TQLayout::spacing</a>(). <p> To write your own layout class, you must define the following: <ul> <li> A data structure to store the items handled by the layout. Each -item is a <a href="qlayoutitem.html">TQLayoutItem</a>. We will use a +item is a <a href="tqlayoutitem.html">TQLayoutItem</a>. We will use a <a href="tqptrlist.html">TQPtrList</a> in this example. -<li> <a href="ntqlayout.html#addItem">addItem()</a>, how to add items to +<li> <a href="tqlayout.html#addItem">addItem()</a>, how to add items to the layout. -<li> <a href="ntqlayout.html#setGeometry">setGeometry()</a>, how to perform +<li> <a href="tqlayout.html#setGeometry">setGeometry()</a>, how to perform the layout. -<li> <a href="qlayoutitem.html#sizeHint">sizeHint()</a>, the preferred size +<li> <a href="tqlayoutitem.html#sizeHint">sizeHint()</a>, the preferred size of the layout. -<li> <a href="ntqlayout.html#iterator">iterator()</a>, how to iterate over +<li> <a href="tqlayout.html#iterator">iterator()</a>, how to iterate over the layout. </ul> -<p> In most cases, you will also implement <a href="ntqlayout.html#minimumSize">minimumSize</a>(). +<p> In most cases, you will also implement <a href="tqlayout.html#minimumSize">minimumSize</a>(). <p> <h2> card.h </h2> <a name="1"></a><p> <pre> #ifndef CARD_H #define CARD_H -#include <<a href="qlayout-h.html">ntqlayout.h</a>> +#include <<a href="tqlayout-h.html">tqlayout.h</a>> #include <<a href="tqptrlist-h.html">tqptrlist.h</a>> -class CardLayout : public <a href="ntqlayout.html">TQLayout</a> +class CardLayout : public <a href="tqlayout.html">TQLayout</a> { public: CardLayout( <a href="tqwidget.html">TQWidget</a> *parent, int dist ) - : <a href="ntqlayout.html">TQLayout</a>( parent, 0, dist ) {} - CardLayout( <a href="ntqlayout.html">TQLayout</a>* parent, int dist) - : <a href="ntqlayout.html">TQLayout</a>( parent, dist ) { } + : <a href="tqlayout.html">TQLayout</a>( parent, 0, dist ) {} + CardLayout( <a href="tqlayout.html">TQLayout</a>* parent, int dist) + : <a href="tqlayout.html">TQLayout</a>( parent, dist ) { } CardLayout( int dist ) - : <a href="ntqlayout.html">TQLayout</a>( dist ) {} + : <a href="tqlayout.html">TQLayout</a>( dist ) {} ~CardLayout(); void addItem(TQLayoutItem *item); <a href="tqsize.html">TQSize</a> sizeHint() const; <a href="tqsize.html">TQSize</a> minimumSize() const; - <a href="qlayoutiterator.html">TQLayoutIterator</a> iterator(); + <a href="tqlayoutiterator.html">TQLayoutIterator</a> iterator(); void setGeometry(const <a href="tqrect.html">TQRect</a> &rect); private: @@ -93,28 +93,28 @@ private: <p> First we define an iterator over the layout. Layout iterators are used internally by the layout system to handle deletion of widgets. They are also available for application programmers. -<p> There are two different classes involved: <a href="qlayoutiterator.html">TQLayoutIterator</a> is the class +<p> There are two different classes involved: <a href="tqlayoutiterator.html">TQLayoutIterator</a> is the class that is visible to application programmers, it is <a href="shclass.html#explicitly-shared">explicitly shared</a>. -The TQLayoutIterator contains a <a href="qglayoutiterator.html">TQGLayoutIterator</a> that does all the +The TQLayoutIterator contains a <a href="tqglayoutiterator.html">TQGLayoutIterator</a> that does all the work. We must create a subclass of TQGLayoutIterator that knows how to iterate over our layout class. <p> In this case, we choose a simple implementation: we store an integer -index into the list and a pointer to the list. Every <a href="qglayoutiterator.html">TQGLayoutIterator</a> subclass must implement <a href="qglayoutiterator.html#current">current</a>(), <a href="qglayoutiterator.html#next">next</a>() and <a href="qglayoutiterator.html#takeCurrent">takeCurrent</a>(), as well as a +index into the list and a pointer to the list. Every <a href="tqglayoutiterator.html">TQGLayoutIterator</a> subclass must implement <a href="tqglayoutiterator.html#current">current</a>(), <a href="tqglayoutiterator.html#next">next</a>() and <a href="tqglayoutiterator.html#takeCurrent">takeCurrent</a>(), as well as a constructor. In our example we do not need a destructor. <p> <pre> -class CardLayoutIterator : public <a href="qglayoutiterator.html">TQGLayoutIterator</a> +class CardLayoutIterator : public <a href="tqglayoutiterator.html">TQGLayoutIterator</a> { public: CardLayoutIterator( <a href="tqptrlist.html">TQPtrList</a><TQLayoutItem> *l ) : idx( 0 ), list( l ) {} - <a href="qlayoutitem.html">TQLayoutItem</a> *current() + <a href="tqlayoutitem.html">TQLayoutItem</a> *current() { return idx < int(list-><a href="tqptrlist.html#count">count</a>()) ? list-><a href="tqptrlist.html#at">at</a>(idx) : 0; } - <a href="qlayoutitem.html">TQLayoutItem</a> *next() + <a href="tqlayoutitem.html">TQLayoutItem</a> *next() { idx++; return current(); } - <a href="qlayoutitem.html">TQLayoutItem</a> *takeCurrent() + <a href="tqlayoutitem.html">TQLayoutItem</a> *takeCurrent() { return list-><a href="tqptrlist.html#take">take</a>( idx ); } private: @@ -123,7 +123,7 @@ private: }; </pre> -<p> We must implement TQLayout:iterator() to return a <a href="qlayoutiterator.html">TQLayoutIterator</a> over +<p> We must implement TQLayout:iterator() to return a <a href="tqlayoutiterator.html">TQLayoutIterator</a> over this layout. <p> <pre> TQLayoutIterator CardLayout::iterator() @@ -133,21 +133,21 @@ TQLayoutIterator CardLayout::iterator() </pre> <p> addItem() implements the default placement strategy for layout items. -It must be implemented. It is used by <a href="ntqlayout.html#add">TQLayout::add</a>(), by the <a href="ntqlayout.html">TQLayout</a> +It must be implemented. It is used by <a href="tqlayout.html#add">TQLayout::add</a>(), by the <a href="tqlayout.html">TQLayout</a> constructor that takes a layout as parent, and it is used to implement -the <a href="ntqlayout.html#autoAdd">auto-add</a> feature. If your layout +the <a href="tqlayout.html#autoAdd">auto-add</a> feature. If your layout has advanced placement options that require parameters, you must provide extra access functions such as <a href="tqgridlayout.html#addMultiCell">TQGridLayout::addMultiCell</a>(). <p> <pre> -void CardLayout::addItem( <a href="qlayoutitem.html">TQLayoutItem</a> *item ) +void CardLayout::addItem( <a href="tqlayoutitem.html">TQLayoutItem</a> *item ) { list.append( item ); } </pre> <p> The layout takes over responsibility of the items added. Since -<a href="qlayoutitem.html">TQLayoutItem</a> does not inherit <a href="tqobject.html">TQObject</a>, we must delete the items -manually. The function <a href="ntqlayout.html#deleteAllItems">TQLayout::deleteAllItems</a>() uses the iterator we +<a href="tqlayoutitem.html">TQLayoutItem</a> does not inherit <a href="tqobject.html">TQObject</a>, we must delete the items +manually. The function <a href="tqlayout.html#deleteAllItems">TQLayout::deleteAllItems</a>() uses the iterator we defined above to delete all the items in the layout. <p> <pre> CardLayout::~CardLayout() @@ -162,13 +162,13 @@ spacing() as the distance between items. <p> <pre> void CardLayout::setGeometry( const <a href="tqrect.html">TQRect</a> &rect ) { - TQLayout::<a href="ntqlayout.html#setGeometry">setGeometry</a>( rect ); + TQLayout::<a href="tqlayout.html#setGeometry">setGeometry</a>( rect ); <a href="tqptrlistiterator.html">TQPtrListIterator</a><TQLayoutItem> it( list ); if (it.<a href="tqptrlistiterator.html#count">count</a>() == 0) return; - <a href="qlayoutitem.html">TQLayoutItem</a> *item; + <a href="tqlayoutitem.html">TQLayoutItem</a> *item; int i = 0; @@ -179,7 +179,7 @@ void CardLayout::setGeometry( const <a href="tqrect.html">TQRect</a> &rect ) ++it; <a href="tqrect.html">TQRect</a> geom( rect.<a href="tqrect.html#x">x</a>() + i * spacing(), rect.<a href="tqrect.html#y">y</a>() + i * spacing(), w, h ); - item-><a href="qlayoutitem.html#setGeometry">setGeometry</a>( geom ); + item-><a href="tqlayoutitem.html#setGeometry">setGeometry</a>( geom ); ++i; } } @@ -196,10 +196,10 @@ TQSize CardLayout::sizeHint() const if ( n > 0 ) s = TQSize( 100, 70 ); // start with a nice default size <a href="tqptrlistiterator.html">TQPtrListIterator</a><TQLayoutItem> it( list ); - <a href="qlayoutitem.html">TQLayoutItem</a> *item; + <a href="tqlayoutitem.html">TQLayoutItem</a> *item; while ( (item = it.<a href="tqptrlistiterator.html#current">current</a>()) != 0 ) { ++it; - s = s.<a href="tqsize.html#expandedTo">expandedTo</a>( item-><a href="qlayoutitem.html#minimumSize">minimumSize</a>() ); + s = s.<a href="tqsize.html#expandedTo">expandedTo</a>( item-><a href="tqlayoutitem.html#minimumSize">minimumSize</a>() ); } return s + n * TQSize( spacing(), spacing() ); } @@ -209,10 +209,10 @@ TQSize CardLayout::minimumSize() const <a href="tqsize.html">TQSize</a> s( 0, 0 ); int n = list.count(); <a href="tqptrlistiterator.html">TQPtrListIterator</a><TQLayoutItem> it( list ); - <a href="qlayoutitem.html">TQLayoutItem</a> *item; + <a href="tqlayoutitem.html">TQLayoutItem</a> *item; while ( (item = it.<a href="tqptrlistiterator.html#current">current</a>()) != 0 ) { ++it; - s = s.<a href="tqsize.html#expandedTo">expandedTo</a>( item-><a href="qlayoutitem.html#minimumSize">minimumSize</a>() ); + s = s.<a href="tqsize.html#expandedTo">expandedTo</a>( item-><a href="tqlayoutitem.html#minimumSize">minimumSize</a>() ); } return s + n * TQSize( spacing(), spacing() ); } @@ -221,15 +221,15 @@ TQSize CardLayout::minimumSize() const <p> <h2> Further Notes </h2> <a name="2"></a><p> This layout does not implement heightForWidth(). -<p> We ignore <a href="qlayoutitem.html#isEmpty">TQLayoutItem::isEmpty</a>(), this means that the layout will +<p> We ignore <a href="tqlayoutitem.html#isEmpty">TQLayoutItem::isEmpty</a>(), this means that the layout will treat hidden widgets as visible. <p> For complex layouts, speed can be greatly increased by caching -calculated values. In that case, implement <a href="qlayoutitem.html#invalidate">TQLayoutItem::invalidate</a>() +calculated values. In that case, implement <a href="tqlayoutitem.html#invalidate">TQLayoutItem::invalidate</a>() to mark the cached data as dirty. -<p> Calling <a href="qlayoutitem.html#sizeHint">TQLayoutItem::sizeHint</a>(), etc. may be expensive, so you should +<p> Calling <a href="tqlayoutitem.html#sizeHint">TQLayoutItem::sizeHint</a>(), etc. may be expensive, so you should store the value in a local variable if you need it again later in the same function. -<p> You should not call <a href="qlayoutitem.html#setGeometry">TQLayoutItem::setGeometry</a>() twice on the same item +<p> You should not call <a href="tqlayoutitem.html#setGeometry">TQLayoutItem::setGeometry</a>() twice on the same item in the same function. That can be very expensive if the item has several child widgets, because it will have to do a complete layout every time. Instead, calculate the geometry and then set it. (This |