[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
---|
[2] | 6 | **
|
---|
| 7 | ** This file is part of the Qt3Support module of the Qt Toolkit.
|
---|
| 8 | **
|
---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
| 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
| 14 | ** a written agreement between you and Nokia.
|
---|
| 15 | **
|
---|
| 16 | ** GNU Lesser General Public License Usage
|
---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
| 20 | ** packaging of this file. Please review the following information to
|
---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
| 23 | **
|
---|
[561] | 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
[2] | 27 | **
|
---|
| 28 | ** GNU General Public License Usage
|
---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
| 32 | ** packaging of this file. Please review the following information to
|
---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
| 35 | **
|
---|
[561] | 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at [email protected].
|
---|
[2] | 38 | ** $QT_END_LICENSE$
|
---|
| 39 | **
|
---|
| 40 | ****************************************************************************/
|
---|
| 41 |
|
---|
| 42 | #include "q3grid.h"
|
---|
| 43 | #include "qlayout.h"
|
---|
| 44 | #include "qapplication.h"
|
---|
| 45 |
|
---|
| 46 | QT_BEGIN_NAMESPACE
|
---|
| 47 |
|
---|
| 48 | /*!
|
---|
| 49 | \class Q3Grid
|
---|
| 50 | \brief The Q3Grid widget provides simple geometry management of its children.
|
---|
| 51 |
|
---|
| 52 | \compat
|
---|
| 53 |
|
---|
| 54 | The grid places its widgets either in columns or in rows depending
|
---|
| 55 | on its orientation.
|
---|
| 56 |
|
---|
| 57 | The number of rows \e or columns is defined in the constructor.
|
---|
| 58 | All the grid's children will be placed and sized in accordance
|
---|
| 59 | with their sizeHint() and sizePolicy().
|
---|
| 60 |
|
---|
| 61 | Use setMargin() to add space around the grid itself, and
|
---|
| 62 | setSpacing() to add space between the widgets.
|
---|
| 63 |
|
---|
| 64 | \sa Q3VBox Q3HBox QGridLayout
|
---|
| 65 | */
|
---|
| 66 |
|
---|
| 67 | /*!
|
---|
| 68 | \typedef Q3Grid::Direction
|
---|
| 69 | \internal
|
---|
| 70 | */
|
---|
| 71 |
|
---|
| 72 | /*!
|
---|
| 73 | Constructs a grid widget with parent \a parent, called \a name.
|
---|
| 74 | If \a orient is \c Horizontal, \a n specifies the number of
|
---|
| 75 | columns. If \a orient is \c Vertical, \a n specifies the number of
|
---|
| 76 | rows. The widget flags \a f are passed to the Q3Frame constructor.
|
---|
| 77 | */
|
---|
| 78 | Q3Grid::Q3Grid(int n, Qt::Orientation orient, QWidget *parent, const char *name,
|
---|
| 79 | Qt::WindowFlags f)
|
---|
| 80 | : Q3Frame(parent, name, f)
|
---|
| 81 | {
|
---|
| 82 | int nCols, nRows;
|
---|
| 83 | if (orient == Qt::Horizontal) {
|
---|
| 84 | nCols = n;
|
---|
| 85 | nRows = -1;
|
---|
| 86 | } else {
|
---|
| 87 | nCols = -1;
|
---|
| 88 | nRows = n;
|
---|
| 89 | }
|
---|
| 90 | (new QGridLayout(this, nRows, nCols, 0, 0, name))->setAutoAdd(true);
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 |
|
---|
| 94 |
|
---|
| 95 | /*!
|
---|
| 96 | Constructs a grid widget with parent \a parent, called \a name.
|
---|
| 97 | \a n specifies the number of columns. The widget flags \a f are
|
---|
| 98 | passed to the Q3Frame constructor.
|
---|
| 99 | */
|
---|
| 100 | Q3Grid::Q3Grid(int n, QWidget *parent, const char *name, Qt::WindowFlags f)
|
---|
| 101 | : Q3Frame(parent, name, f)
|
---|
| 102 | {
|
---|
| 103 | (new QGridLayout(this, -1, n, 0, 0, name))->setAutoAdd(true);
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 |
|
---|
| 107 | /*!
|
---|
| 108 | Sets the spacing between the child widgets to \a space.
|
---|
| 109 | */
|
---|
| 110 |
|
---|
| 111 | void Q3Grid::setSpacing(int space)
|
---|
| 112 | {
|
---|
| 113 | if (layout())
|
---|
| 114 | layout()->setSpacing(space);
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 |
|
---|
| 118 | /*!\reimp
|
---|
| 119 | */
|
---|
| 120 | void Q3Grid::frameChanged()
|
---|
| 121 | {
|
---|
| 122 | if (layout())
|
---|
| 123 | layout()->setMargin(frameWidth());
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 |
|
---|
| 127 | /*!
|
---|
| 128 | \reimp
|
---|
| 129 | */
|
---|
| 130 |
|
---|
| 131 | QSize Q3Grid::sizeHint() const
|
---|
| 132 | {
|
---|
| 133 | QWidget *mThis = (QWidget*)this;
|
---|
| 134 | QApplication::sendPostedEvents(mThis, QEvent::ChildInserted);
|
---|
| 135 | return Q3Frame::sizeHint();
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 | QT_END_NAMESPACE
|
---|