diff options
Diffstat (limited to 'doc/layout.doc')
-rw-r--r-- | doc/layout.doc | 136 |
1 files changed, 68 insertions, 68 deletions
diff --git a/doc/layout.doc b/doc/layout.doc index e71c777f0..8595073d1 100644 --- a/doc/layout.doc +++ b/doc/layout.doc @@ -71,7 +71,7 @@ layouts and which generates the C++ layout code for you. \section1 Layout Widgets The easiest way to give your widgets a good layout is to use the -layout widgets: \l QHBox, \l QVBox and \l TQGrid. A layout widget +layout widgets: \l TQHBox, \l TQVBox and \l TQGrid. A layout widget automatically lays out its child widgets in the order they are constructed. To create more complex layouts, you can nest layout widgets inside each other. (Note that \l TQWidget does not have a @@ -79,13 +79,13 @@ layout by default, you must add one if you want to lay out widgets inside a \l TQWidget.) \list -\i A \l QHBox lays out its child widgets in a horizontal row, left to right. +\i A \l TQHBox lays out its child widgets in a horizontal row, left to right. - \img qhbox-m.png Horizontal box with five child widgets + \img tqhbox-m.png Horizontal box with five child widgets -\i A \l QVBox lays out its child widgets in a vertical column, top to bottom. +\i A \l TQVBox lays out its child widgets in a vertical column, top to bottom. - \img qvbox-m.png Vertical box with five child widgets + \img tqvbox-m.png Vertical box with five child widgets \i A \l TQGrid lays out its child widgets in a two dimensional grid. You can specify how many columns the grid has, and it is populated left to @@ -142,7 +142,7 @@ accordance with their TQWidget::sizePolicy() or their minimum size hint whichever is the greater. Stretch factors are used to change how much space widgets are given in proportion to one another. -If we have three widgets laid out using a QHBox with no stretch +If we have three widgets laid out using a TQHBox with no stretch factors set we will get a layout like this: \img layout1.png 3 widgets in a row @@ -153,13 +153,13 @@ proportion (but never less than their minimum size hint), e.g. \img layout2.png 3 stretch factored widgets in a row -\section1 QLayout subclassing +\section1 TQLayout subclassing -If you need more control over the layout, use a \link QLayout -QLayout\endlink subclass. The layout classes included in TQt are \link -TQGridLayout TQGridLayout\endlink and \link QBoxLayout -QBoxLayout\endlink. (\link QHBoxLayout QHBoxLayout\endlink and \link -QVBoxLayout QVBoxLayout\endlink are trivial subclasses of QBoxLayout, +If you need more control over the layout, use a \link TQLayout +TQLayout\endlink subclass. The layout classes included in TQt are \link +TQGridLayout TQGridLayout\endlink and \link TQBoxLayout +TQBoxLayout\endlink. (\link TQHBoxLayout TQHBoxLayout\endlink and \link +TQVBoxLayout TQVBoxLayout\endlink are trivial subclasses of TQBoxLayout, that are simpler to use and make the code easier to read.) When you use a layout, you must insert each child both into its parent @@ -202,12 +202,12 @@ a parameter in the constructor. TQLabel *label = new TQLabel( "Write once, compile everywhere.", main ); // a layout on a widget - QVBoxLayout *vbox = new QVBoxLayout( main ); + TQVBoxLayout *vbox = new TQVBoxLayout( main ); vbox->addWidget( label ); vbox->addWidget( field ); // a layout inside a layout - QHBoxLayout *buttons = new QHBoxLayout( vbox ); + TQHBoxLayout *buttons = new TQHBoxLayout( vbox ); buttons->addWidget( ok ); buttons->addWidget( cancel ); \endcode @@ -219,8 +219,8 @@ into. \section1 Custom Layouts If the built-in layout classes are not sufficient, you can define your -own. You must make a subclass of \l QLayout that handles resizing and -size calculations, as well as a subclass of \l QGLayoutIterator to +own. You must make a subclass of \l TQLayout that handles resizing and +size calculations, as well as a subclass of \l TQGLayoutIterator to iterate over your layout class. See the \link customlayout.html Custom Layout \endlink page for an @@ -229,7 +229,7 @@ in-depth description. \section1 Custom Widgets In Layouts When you make your own widget class, you should also communicate its -layout properties. If the widget has a QLayout, this is already taken +layout properties. If the widget has a TQLayout, this is already taken care of. If the widget does not have any child widgets, or uses manual layout, you should reimplement the following TQWidget member functions: @@ -252,8 +252,8 @@ TQWidget::heightForWidth(). Even if you implement heightForWidth(), it is still necessary to provide a good sizeHint(). The sizeHint() provides the preferred width -of the widget, and it is used by QLayout subclasses that do not -support heightForWidth() (both TQGridLayout and QBoxLayout support it). +of the widget, and it is used by TQLayout subclasses that do not +support heightForWidth() (both TQGridLayout and TQBoxLayout support it). For further guidance when implementing these functions, see their implementations in existing TQt classes that have similar layout @@ -275,7 +275,7 @@ TQWidget::event() to be notified of \c LayoutHint events. The use of rich text in a label widget can introduce some problems to the layout of its parent widget. Problems occur due to the way rich text is handled by Qt's layout managers when the label is word wrapped. -In certain cases the parent layout is put into QLayout::FreeResize mode, +In certain cases the parent layout is put into TQLayout::FreeResize mode, meaning that it will not adapt the layout of its contents to fit inside small sized windows, or even prevent the user from making the window too small to be usable. This can be overcome by subclassing @@ -292,24 +292,24 @@ minimumSizeHint() functions. 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 -QLayout::spacing(). +TQLayout::spacing(). To write your own layout class, you must define the following: \list \i A data structure to store the items handled by the layout. Each -item is a \link QLayoutItem QLayoutItem\endlink. We will use a +item is a \link TQLayoutItem TQLayoutItem\endlink. We will use a TQPtrList in this example. -\i \link QLayout::addItem() addItem() \endlink, how to add items to +\i \link TQLayout::addItem() addItem() \endlink, how to add items to the layout. -\i \link QLayout::setGeometry() setGeometry() \endlink, how to perform +\i \link TQLayout::setGeometry() setGeometry() \endlink, how to perform the layout. -\i \link QLayout::sizeHint() sizeHint() \endlink, the preferred size +\i \link TQLayout::sizeHint() sizeHint() \endlink, the preferred size of the layout. -\i \link QLayout::iterator() iterator() \endlink, how to iterate over +\i \link TQLayout::iterator() iterator() \endlink, how to iterate over the layout. \endlist -In most cases, you will also implement \link QLayout::minimumSize() +In most cases, you will also implement \link TQLayout::minimumSize() minimumSize\endlink(). \section1 card.h @@ -318,28 +318,28 @@ minimumSize\endlink(). #ifndef CARD_H #define CARD_H -#include <ntqlayout.h> +#include <tqlayout.h> #include <tqptrlist.h> -class CardLayout : public QLayout +class CardLayout : public TQLayout { public: CardLayout( TQWidget *parent, int dist ) - : QLayout( parent, 0, dist ) {} - CardLayout( QLayout* parent, int dist) - : QLayout( parent, dist ) { } + : TQLayout( parent, 0, dist ) {} + CardLayout( TQLayout* parent, int dist) + : TQLayout( parent, dist ) { } CardLayout( int dist ) - : QLayout( dist ) {} + : TQLayout( dist ) {} ~CardLayout(); - void addItem(QLayoutItem *item); + void addItem(TQLayoutItem *item); TQSize sizeHint() const; TQSize minimumSize() const; - QLayoutIterator iterator(); + TQLayoutIterator iterator(); void setGeometry(const TQRect &rect); private: - TQPtrList<QLayoutItem> list; + TQPtrList<TQLayoutItem> list; }; #endif @@ -355,69 +355,69 @@ 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. -There are two different classes involved: QLayoutIterator is the class +There are two different classes involved: TQLayoutIterator is the class that is visible to application programmers, it is explicitly shared. -The QLayoutIterator contains a QGLayoutIterator that does all the -work. We must create a subclass of QGLayoutIterator that knows how to +The TQLayoutIterator contains a TQGLayoutIterator that does all the +work. We must create a subclass of TQGLayoutIterator that knows how to iterate over our layout class. In this case, we choose a simple implementation: we store an integer index into the list and a pointer to the list. Every \l -QGLayoutIterator subclass must implement \link -QGLayoutIterator::current() current\endlink(), \link -QGLayoutIterator::next() next\endlink() and \link -QGLayoutIterator::takeCurrent() takeCurrent\endlink(), as well as a +TQGLayoutIterator subclass must implement \link +TQGLayoutIterator::current() current\endlink(), \link +TQGLayoutIterator::next() next\endlink() and \link +TQGLayoutIterator::takeCurrent() takeCurrent\endlink(), as well as a constructor. In our example we do not need a destructor. \code -class CardLayoutIterator : public QGLayoutIterator +class CardLayoutIterator : public TQGLayoutIterator { public: - CardLayoutIterator( TQPtrList<QLayoutItem> *l ) + CardLayoutIterator( TQPtrList<TQLayoutItem> *l ) : idx( 0 ), list( l ) {} - QLayoutItem *current() + TQLayoutItem *current() { return idx < int(list->count()) ? list->at(idx) : 0; } - QLayoutItem *next() + TQLayoutItem *next() { idx++; return current(); } - QLayoutItem *takeCurrent() + TQLayoutItem *takeCurrent() { return list->take( idx ); } private: int idx; - TQPtrList<QLayoutItem> *list; + TQPtrList<TQLayoutItem> *list; }; \endcode -We must implement QLayout:iterator() to return a QLayoutIterator over +We must implement TQLayout:iterator() to return a TQLayoutIterator over this layout. \code -QLayoutIterator CardLayout::iterator() +TQLayoutIterator CardLayout::iterator() { - return QLayoutIterator( new CardLayoutIterator(&list) ); + return TQLayoutIterator( new CardLayoutIterator(&list) ); } \endcode addItem() implements the default placement strategy for layout items. -It must be implemented. It is used by QLayout::add(), by the QLayout +It must be implemented. It is used by TQLayout::add(), by the TQLayout constructor that takes a layout as parent, and it is used to implement -the \link QLayout::autoAdd() auto-add\endlink feature. If your layout +the \link TQLayout::autoAdd() auto-add\endlink feature. If your layout has advanced placement options that require parameters, you must provide extra access functions such as \l TQGridLayout::addMultiCell(). \code -void CardLayout::addItem( QLayoutItem *item ) +void CardLayout::addItem( TQLayoutItem *item ) { list.append( item ); } \endcode The layout takes over responsibility of the items added. Since -QLayoutItem does not inherit TQObject, we must delete the items -manually. The function QLayout::deleteAllItems() uses the iterator we +TQLayoutItem does not inherit TQObject, we must delete the items +manually. The function TQLayout::deleteAllItems() uses the iterator we defined above to delete all the items in the layout. \code @@ -434,13 +434,13 @@ spacing() as the distance between items. \code void CardLayout::setGeometry( const TQRect &rect ) { - QLayout::setGeometry( rect ); + TQLayout::setGeometry( rect ); - TQPtrListIterator<QLayoutItem> it( list ); + TQPtrListIterator<TQLayoutItem> it( list ); if (it.count() == 0) return; - QLayoutItem *item; + TQLayoutItem *item; int i = 0; @@ -468,8 +468,8 @@ TQSize CardLayout::sizeHint() const int n = list.count(); if ( n > 0 ) s = TQSize( 100, 70 ); // start with a nice default size - TQPtrListIterator<QLayoutItem> it( list ); - QLayoutItem *item; + TQPtrListIterator<TQLayoutItem> it( list ); + TQLayoutItem *item; while ( (item = it.current()) != 0 ) { ++it; s = s.expandedTo( item->minimumSize() ); @@ -481,8 +481,8 @@ TQSize CardLayout::minimumSize() const { TQSize s( 0, 0 ); int n = list.count(); - TQPtrListIterator<QLayoutItem> it( list ); - QLayoutItem *item; + TQPtrListIterator<TQLayoutItem> it( list ); + TQLayoutItem *item; while ( (item = it.current()) != 0 ) { ++it; s = s.expandedTo( item->minimumSize() ); @@ -495,18 +495,18 @@ TQSize CardLayout::minimumSize() const This layout does not implement heightForWidth(). -We ignore QLayoutItem::isEmpty(), this means that the layout will +We ignore TQLayoutItem::isEmpty(), this means that the layout will treat hidden widgets as visible. For complex layouts, speed can be greatly increased by caching -calculated values. In that case, implement QLayoutItem::invalidate() +calculated values. In that case, implement TQLayoutItem::invalidate() to mark the cached data as dirty. -Calling QLayoutItem::sizeHint(), etc. may be expensive, so you should +Calling TQLayoutItem::sizeHint(), etc. may be expensive, so you should store the value in a local variable if you need it again later in the same function. -You should not call QLayoutItem::setGeometry() twice on the same item +You should not call TQLayoutItem::setGeometry() 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 |