1 | /****************************************************************************
|
---|
2 | ** $Id: qgrid.cpp 2 2005-11-16 15:49:26Z dmik $
|
---|
3 | **
|
---|
4 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
|
---|
5 | **
|
---|
6 | ** This file is part of the widgets module of the Qt GUI Toolkit.
|
---|
7 | **
|
---|
8 | ** This file may be distributed under the terms of the Q Public License
|
---|
9 | ** as defined by Trolltech AS of Norway and appearing in the file
|
---|
10 | ** LICENSE.QPL included in the packaging of this file.
|
---|
11 | **
|
---|
12 | ** This file may be distributed and/or modified under the terms of the
|
---|
13 | ** GNU General Public License version 2 as published by the Free Software
|
---|
14 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
15 | ** packaging of this file.
|
---|
16 | **
|
---|
17 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
|
---|
18 | ** licenses may use this file in accordance with the Qt Commercial License
|
---|
19 | ** Agreement provided with the Software.
|
---|
20 | **
|
---|
21 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
---|
22 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
---|
23 | **
|
---|
24 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
---|
25 | ** information about Qt Commercial License Agreements.
|
---|
26 | ** See http://www.trolltech.com/qpl/ for QPL licensing information.
|
---|
27 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
---|
28 | **
|
---|
29 | ** Contact info@trolltech.com if any conditions of this licensing are
|
---|
30 | ** not clear to you.
|
---|
31 | **
|
---|
32 | **********************************************************************/
|
---|
33 |
|
---|
34 |
|
---|
35 | #include "qgrid.h"
|
---|
36 | #ifndef QT_NO_GRID
|
---|
37 | #include "qlayout.h"
|
---|
38 | #include "qapplication.h"
|
---|
39 |
|
---|
40 | /*!
|
---|
41 | \class QGrid qgrid.h
|
---|
42 | \brief The QGrid widget provides simple geometry management of its children.
|
---|
43 |
|
---|
44 | \ingroup geomanagement
|
---|
45 | \ingroup appearance
|
---|
46 |
|
---|
47 | The grid places its widgets either in columns or in rows depending
|
---|
48 | on its orientation.
|
---|
49 |
|
---|
50 | The number of rows \e or columns is defined in the constructor.
|
---|
51 | All the grid's children will be placed and sized in accordance
|
---|
52 | with their sizeHint() and sizePolicy().
|
---|
53 |
|
---|
54 | Use setMargin() to add space around the grid itself, and
|
---|
55 | setSpacing() to add space between the widgets.
|
---|
56 |
|
---|
57 | \img qgrid-m.png QGrid
|
---|
58 |
|
---|
59 | \sa QVBox QHBox QGridLayout
|
---|
60 | */
|
---|
61 |
|
---|
62 | /*! \enum QGrid::Direction
|
---|
63 | \internal
|
---|
64 | */
|
---|
65 |
|
---|
66 | /*!
|
---|
67 | Constructs a grid widget with parent \a parent, called \a name.
|
---|
68 | If \a orient is \c Horizontal, \a n specifies the number of
|
---|
69 | columns. If \a orient is \c Vertical, \a n specifies the number of
|
---|
70 | rows. The widget flags \a f are passed to the QFrame constructor.
|
---|
71 | */
|
---|
72 | QGrid::QGrid( int n, Orientation orient, QWidget *parent, const char *name,
|
---|
73 | WFlags f )
|
---|
74 | : QFrame( parent, name, f )
|
---|
75 | {
|
---|
76 | int nCols, nRows;
|
---|
77 | if ( orient == Horizontal ) {
|
---|
78 | nCols = n;
|
---|
79 | nRows = -1;
|
---|
80 | } else {
|
---|
81 | nCols = -1;
|
---|
82 | nRows = n;
|
---|
83 | }
|
---|
84 | lay = new QGridLayout( this, nRows, nCols, 0, 0, name );
|
---|
85 | lay->setAutoAdd( TRUE );
|
---|
86 | }
|
---|
87 |
|
---|
88 |
|
---|
89 |
|
---|
90 | /*!
|
---|
91 | Constructs a grid widget with parent \a parent, called \a name.
|
---|
92 | \a n specifies the number of columns. The widget flags \a f are
|
---|
93 | passed to the QFrame constructor.
|
---|
94 | */
|
---|
95 | QGrid::QGrid( int n, QWidget *parent, const char *name, WFlags f )
|
---|
96 | : QFrame( parent, name, f )
|
---|
97 | {
|
---|
98 | lay = new QGridLayout( this, -1, n, 0, 0, name );
|
---|
99 | lay->setAutoAdd( TRUE );
|
---|
100 | }
|
---|
101 |
|
---|
102 |
|
---|
103 | /*!
|
---|
104 | Sets the spacing between the child widgets to \a space.
|
---|
105 | */
|
---|
106 |
|
---|
107 | void QGrid::setSpacing( int space )
|
---|
108 | {
|
---|
109 | if ( layout() )
|
---|
110 | layout()->setSpacing( space );
|
---|
111 | }
|
---|
112 |
|
---|
113 |
|
---|
114 | /*!\reimp
|
---|
115 | */
|
---|
116 | void QGrid::frameChanged()
|
---|
117 | {
|
---|
118 | if ( !layout() )
|
---|
119 | return;
|
---|
120 | layout()->setMargin( frameWidth() );
|
---|
121 | }
|
---|
122 |
|
---|
123 |
|
---|
124 | /*!
|
---|
125 | \reimp
|
---|
126 | */
|
---|
127 |
|
---|
128 | QSize QGrid::sizeHint() const
|
---|
129 | {
|
---|
130 | QWidget *mThis = (QWidget*)this;
|
---|
131 | QApplication::sendPostedEvents( mThis, QEvent::ChildInserted );
|
---|
132 | return QFrame::sizeHint();
|
---|
133 | }
|
---|
134 | #endif
|
---|