| 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 QtGui 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 "qstackedlayout.h"
|
|---|
| 43 | #include "qlayout_p.h"
|
|---|
| 44 |
|
|---|
| 45 | #include <qlist.h>
|
|---|
| 46 | #include <qwidget.h>
|
|---|
| 47 | #include "private/qlayoutengine_p.h"
|
|---|
| 48 |
|
|---|
| 49 | QT_BEGIN_NAMESPACE
|
|---|
| 50 |
|
|---|
| 51 | class QStackedLayoutPrivate : public QLayoutPrivate
|
|---|
| 52 | {
|
|---|
| 53 | Q_DECLARE_PUBLIC(QStackedLayout)
|
|---|
| 54 | public:
|
|---|
| 55 | QStackedLayoutPrivate() : index(-1), stackingMode(QStackedLayout::StackOne) {}
|
|---|
| 56 | QList<QLayoutItem *> list;
|
|---|
| 57 | int index;
|
|---|
| 58 | QStackedLayout::StackingMode stackingMode;
|
|---|
| 59 | };
|
|---|
| 60 |
|
|---|
| 61 | /*!
|
|---|
| 62 | \class QStackedLayout
|
|---|
| 63 |
|
|---|
| 64 | \brief The QStackedLayout class provides a stack of widgets where
|
|---|
| 65 | only one widget is visible at a time.
|
|---|
| 66 |
|
|---|
| 67 | \ingroup geomanagement
|
|---|
| 68 | \ingroup appearance
|
|---|
| 69 | \mainclass
|
|---|
| 70 |
|
|---|
| 71 | QStackedLayout can be used to create a user interface similar to
|
|---|
| 72 | the one provided by QTabWidget. There is also a convenience
|
|---|
| 73 | QStackedWidget class built on top of QStackedLayout.
|
|---|
| 74 |
|
|---|
| 75 | A QStackedLayout can be populated with a number of child widgets
|
|---|
| 76 | ("pages"). For example:
|
|---|
| 77 |
|
|---|
| 78 | \snippet doc/src/snippets/qstackedlayout/main.cpp 0
|
|---|
| 79 | \codeline
|
|---|
| 80 | \snippet doc/src/snippets/qstackedlayout/main.cpp 2
|
|---|
| 81 | \snippet doc/src/snippets/qstackedlayout/main.cpp 3
|
|---|
| 82 |
|
|---|
| 83 | QStackedLayout provides no intrinsic means for the user to switch
|
|---|
| 84 | page. This is typically done through a QComboBox or a QListWidget
|
|---|
| 85 | that stores the titles of the QStackedLayout's pages. For
|
|---|
| 86 | example:
|
|---|
| 87 |
|
|---|
| 88 | \snippet doc/src/snippets/qstackedlayout/main.cpp 1
|
|---|
| 89 |
|
|---|
| 90 | When populating a layout, the widgets are added to an internal
|
|---|
| 91 | list. The indexOf() function returns the index of a widget in that
|
|---|
| 92 | list. The widgets can either be added to the end of the list using
|
|---|
| 93 | the addWidget() function, or inserted at a given index using the
|
|---|
| 94 | insertWidget() function. The removeWidget() function removes the
|
|---|
| 95 | widget at the given index from the layout. The number of widgets
|
|---|
| 96 | contained in the layout, can be obtained using the count()
|
|---|
| 97 | function.
|
|---|
| 98 |
|
|---|
| 99 | The widget() function returns the widget at a given index
|
|---|
| 100 | position. The index of the widget that is shown on screen is given
|
|---|
| 101 | by currentIndex() and can be changed using setCurrentIndex(). In a
|
|---|
| 102 | similar manner, the currently shown widget can be retrieved using
|
|---|
| 103 | the currentWidget() function, and altered using the
|
|---|
| 104 | setCurrentWidget() function.
|
|---|
| 105 |
|
|---|
| 106 | Whenever the current widget in the layout changes or a widget is
|
|---|
| 107 | removed from the layout, the currentChanged() and widgetRemoved()
|
|---|
| 108 | signals are emitted respectively.
|
|---|
| 109 |
|
|---|
| 110 | \sa QStackedWidget, QTabWidget
|
|---|
| 111 | */
|
|---|
| 112 |
|
|---|
| 113 | /*!
|
|---|
| 114 | \fn void QStackedLayout::currentChanged(int index)
|
|---|
| 115 |
|
|---|
| 116 | This signal is emitted whenever the current widget in the layout
|
|---|
| 117 | changes. The \a index specifies the index of the new current
|
|---|
| 118 | widget, or -1 if there isn't a new one (for example, if there
|
|---|
| 119 | are no widgets in the QStackedLayout)
|
|---|
| 120 |
|
|---|
| 121 | \sa currentWidget(), setCurrentWidget()
|
|---|
| 122 | */
|
|---|
| 123 |
|
|---|
| 124 | /*!
|
|---|
| 125 | \fn void QStackedLayout::widgetRemoved(int index)
|
|---|
| 126 |
|
|---|
| 127 | This signal is emitted whenever a widget is removed from the
|
|---|
| 128 | layout. The widget's \a index is passed as parameter.
|
|---|
| 129 |
|
|---|
| 130 | \sa removeWidget()
|
|---|
| 131 | */
|
|---|
| 132 |
|
|---|
| 133 | /*!
|
|---|
| 134 | \fn QWidget *QStackedLayout::widget()
|
|---|
| 135 | \internal
|
|---|
| 136 | */
|
|---|
| 137 |
|
|---|
| 138 | /*!
|
|---|
| 139 | Constructs a QStackedLayout with no parent.
|
|---|
| 140 |
|
|---|
| 141 | This QStackedLayout must be installed on a widget later on to
|
|---|
| 142 | become effective.
|
|---|
| 143 |
|
|---|
| 144 | \sa addWidget(), insertWidget()
|
|---|
| 145 | */
|
|---|
| 146 | QStackedLayout::QStackedLayout()
|
|---|
| 147 | : QLayout(*new QStackedLayoutPrivate, 0, 0)
|
|---|
| 148 | {
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | /*!
|
|---|
| 152 | Constructs a new QStackedLayout with the given \a parent.
|
|---|
| 153 |
|
|---|
| 154 | This layout will install itself on the \a parent widget and
|
|---|
| 155 | manage the geometry of its children.
|
|---|
| 156 | */
|
|---|
| 157 | QStackedLayout::QStackedLayout(QWidget *parent)
|
|---|
| 158 | : QLayout(*new QStackedLayoutPrivate, 0, parent)
|
|---|
| 159 | {
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | /*!
|
|---|
| 163 | Constructs a new QStackedLayout and inserts it into
|
|---|
| 164 | the given \a parentLayout.
|
|---|
| 165 | */
|
|---|
| 166 | QStackedLayout::QStackedLayout(QLayout *parentLayout)
|
|---|
| 167 | : QLayout(*new QStackedLayoutPrivate, parentLayout, 0)
|
|---|
|
|---|