| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information ([email protected])
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the Qt3Support module of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 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 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #include "q3hbox.h"
|
|---|
| 43 | #include "qlayout.h"
|
|---|
| 44 | #include "qapplication.h"
|
|---|
| 45 |
|
|---|
| 46 | QT_BEGIN_NAMESPACE
|
|---|
| 47 |
|
|---|
| 48 | /*!
|
|---|
| 49 | \class Q3HBox
|
|---|
| 50 | \brief The Q3HBox widget provides horizontal geometry management
|
|---|
| 51 | for its child widgets.
|
|---|
| 52 |
|
|---|
| 53 | \compat
|
|---|
| 54 |
|
|---|
| 55 | All the horizontal box's child widgets will be placed alongside
|
|---|
| 56 | each other and sized according to their sizeHint()s.
|
|---|
| 57 |
|
|---|
| 58 | Use setMargin() to add space around the edges, and use
|
|---|
| 59 | setSpacing() to add space between the widgets. Use
|
|---|
| 60 | setStretchFactor() if you want the widgets to be different sizes
|
|---|
| 61 | in proportion to one another. (See \link layout.html
|
|---|
| 62 | Layouts\endlink for more information on stretch factors.)
|
|---|
| 63 |
|
|---|
| 64 | \img qhbox-m.png Q3HBox
|
|---|
| 65 |
|
|---|
| 66 | \sa QHBoxLayout Q3VBox Q3Grid
|
|---|
| 67 | */
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 | /*!
|
|---|
| 71 | Constructs an hbox widget with parent \a parent, called \a name.
|
|---|
| 72 | The parent, name and widget flags, \a f, are passed to the Q3Frame
|
|---|
| 73 | constructor.
|
|---|
| 74 | */
|
|---|
| 75 | Q3HBox::Q3HBox(QWidget *parent, const char *name, Qt::WindowFlags f)
|
|---|
| 76 | :Q3Frame(parent, name, f)
|
|---|
| 77 | {
|
|---|
| 78 | (new QHBoxLayout(this, frameWidth(), frameWidth(), name))->setAutoAdd(true);
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 | /*!
|
|---|
| 83 | Constructs a horizontal hbox if \a horizontal is TRUE, otherwise
|
|---|
| 84 | constructs a vertical hbox (also known as a vbox).
|
|---|
| 85 |
|
|---|
| 86 | This constructor is provided for the QVBox class. You should never
|
|---|
| 87 | need to use it directly.
|
|---|
| 88 |
|
|---|
| 89 | The \a parent, \a name and widget flags, \a f, are passed to the
|
|---|
| 90 | Q3Frame constructor.
|
|---|
| 91 | */
|
|---|
| 92 |
|
|---|
| 93 | Q3HBox::Q3HBox(bool horizontal, QWidget *parent , const char *name, Qt::WindowFlags f)
|
|---|
| 94 | :Q3Frame(parent, name, f)
|
|---|
| 95 | {
|
|---|
| 96 | (new QBoxLayout(this, horizontal ? QBoxLayout::LeftToRight : QBoxLayout::Down,
|
|---|
| 97 | frameWidth(), frameWidth(), name))->setAutoAdd(true);
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | /*!\reimp
|
|---|
| 101 | */
|
|---|
| 102 | void Q3HBox::frameChanged()
|
|---|
| 103 | {
|
|---|
| 104 | if (layout())
|
|---|
| 105 | layout()->setMargin(frameWidth());
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 | /*!
|
|---|
| 110 | Sets the spacing between the child widgets to \a space.
|
|---|
| 111 | */
|
|---|
| 112 |
|
|---|
| 113 | void Q3HBox::setSpacing(int space)
|
|---|
| 114 | {
|
|---|
| 115 | if (layout())
|
|---|
| 116 | layout()->setSpacing(space);
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 | /*!
|
|---|
| 121 | \reimp
|
|---|
| 122 | */
|
|---|
| 123 |
|
|---|
| 124 | QSize Q3HBox::sizeHint() const
|
|---|
| 125 | {
|
|---|
| 126 | QWidget *mThis = (QWidget*)this;
|
|---|
| 127 | QApplication::sendPostedEvents(mThis, QEvent::ChildInserted);
|
|---|
| 128 | return Q3Frame::sizeHint();
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | /*!
|
|---|
| 132 | Sets the stretch factor of widget \a w to \a stretch. Returns true if
|
|---|
| 133 | \a w is found. Otherwise returns false.
|
|---|
| 134 |
|
|---|
| 135 | \sa QBoxLayout::setStretchFactor() \link layout.html Layouts\endlink
|
|---|
| 136 | */
|
|---|
| 137 | bool Q3HBox::setStretchFactor(QWidget* w, int stretch)
|
|---|
| 138 | {
|
|---|
| 139 | QApplication::sendPostedEvents(this, QEvent::ChildInserted);
|
|---|
| 140 | if (QBoxLayout *lay = qobject_cast<QBoxLayout *>(layout()))
|
|---|
| 141 | return lay->setStretchFactor(w, stretch);
|
|---|
| 142 | return false;
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | QT_END_NAMESPACE
|
|---|