| 1 | /**************************************************************************** | 
|---|
| 2 | ** | 
|---|
| 3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). | 
|---|
| 4 | ** All rights reserved. | 
|---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | 
|---|
| 6 | ** | 
|---|
| 7 | ** This file is part of the examples 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 | ** | 
|---|
| 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. | 
|---|
| 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 have questions regarding the use of this file, please contact | 
|---|
| 37 | ** Nokia at qt-info@nokia.com. | 
|---|
| 38 | ** $QT_END_LICENSE$ | 
|---|
| 39 | ** | 
|---|
| 40 | ****************************************************************************/ | 
|---|
| 41 |  | 
|---|
| 42 | #include <QtGui> | 
|---|
| 43 |  | 
|---|
| 44 | #include "dialog.h" | 
|---|
| 45 |  | 
|---|
| 46 | //! [0] | 
|---|
| 47 | Dialog::Dialog() | 
|---|
| 48 | { | 
|---|
| 49 | createMenu(); | 
|---|
| 50 | createHorizontalGroupBox(); | 
|---|
| 51 | createGridGroupBox(); | 
|---|
| 52 | createFormGroupBox(); | 
|---|
| 53 | //! [0] | 
|---|
| 54 |  | 
|---|
| 55 | //! [1] | 
|---|
| 56 | bigEditor = new QTextEdit; | 
|---|
| 57 | bigEditor->setPlainText(tr("This widget takes up all the remaining space " | 
|---|
| 58 | "in the top-level layout.")); | 
|---|
| 59 |  | 
|---|
| 60 | buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | 
|---|
| 61 | | QDialogButtonBox::Cancel); | 
|---|
| 62 |  | 
|---|
| 63 | connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); | 
|---|
| 64 | connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); | 
|---|
| 65 | //! [1] | 
|---|
| 66 |  | 
|---|
| 67 | //! [2] | 
|---|
| 68 | QVBoxLayout *mainLayout = new QVBoxLayout; | 
|---|
| 69 | //! [2] //! [3] | 
|---|
| 70 | mainLayout->setMenuBar(menuBar); | 
|---|
| 71 | //! [3] //! [4] | 
|---|
| 72 | mainLayout->addWidget(horizontalGroupBox); | 
|---|
| 73 | mainLayout->addWidget(gridGroupBox); | 
|---|
| 74 | mainLayout->addWidget(formGroupBox); | 
|---|
| 75 | mainLayout->addWidget(bigEditor); | 
|---|
| 76 | mainLayout->addWidget(buttonBox); | 
|---|
| 77 | //! [4] //! [5] | 
|---|
| 78 | setLayout(mainLayout); | 
|---|
| 79 |  | 
|---|
| 80 | setWindowTitle(tr("Basic Layouts")); | 
|---|
| 81 | } | 
|---|
| 82 | //! [5] | 
|---|
| 83 |  | 
|---|
| 84 | //! [6] | 
|---|
| 85 | void Dialog::createMenu() | 
|---|
| 86 | { | 
|---|
| 87 | menuBar = new QMenuBar; | 
|---|
| 88 |  | 
|---|
| 89 | fileMenu = new QMenu(tr("&File"), this); | 
|---|
| 90 | exitAction = fileMenu->addAction(tr("E&xit")); | 
|---|
| 91 | menuBar->addMenu(fileMenu); | 
|---|
| 92 |  | 
|---|
| 93 | connect(exitAction, SIGNAL(triggered()), this, SLOT(accept())); | 
|---|
| 94 | } | 
|---|
| 95 | //! [6] | 
|---|
| 96 |  | 
|---|
| 97 | //! [7] | 
|---|
| 98 | void Dialog::createHorizontalGroupBox() | 
|---|
| 99 | { | 
|---|
| 100 | horizontalGroupBox = new QGroupBox(tr("Horizontal layout")); | 
|---|
| 101 | QHBoxLayout *layout = new QHBoxLayout; | 
|---|
| 102 |  | 
|---|
| 103 | for (int i = 0; i < NumButtons; ++i) { | 
|---|
| 104 | buttons[i] = new QPushButton(tr("Button %1").arg(i + 1)); | 
|---|
| 105 | layout->addWidget(buttons[i]); | 
|---|
| 106 | } | 
|---|
| 107 | horizontalGroupBox->setLayout(layout); | 
|---|
| 108 | } | 
|---|
| 109 | //! [7] | 
|---|
| 110 |  | 
|---|
| 111 | //! [8] | 
|---|
| 112 | void Dialog::createGridGroupBox() | 
|---|
| 113 | { | 
|---|
| 114 | gridGroupBox = new QGroupBox(tr("Grid layout")); | 
|---|
| 115 | //! [8] | 
|---|
| 116 | QGridLayout *layout = new QGridLayout; | 
|---|
| 117 |  | 
|---|
| 118 | //! [9] | 
|---|
| 119 | for (int i = 0; i < NumGridRows; ++i) { | 
|---|
| 120 | labels[i] = new QLabel(tr("Line %1:").arg(i + 1)); | 
|---|
| 121 | lineEdits[i] = new QLineEdit; | 
|---|
| 122 | layout->addWidget(labels[i], i + 1, 0); | 
|---|
| 123 | layout->addWidget(lineEdits[i], i + 1, 1); | 
|---|
| 124 | } | 
|---|
| 125 |  | 
|---|
| 126 | //! [9] //! [10] | 
|---|
| 127 | smallEditor = new QTextEdit; | 
|---|
| 128 | smallEditor->setPlainText(tr("This widget takes up about two thirds of the " | 
|---|
| 129 | "grid layout.")); | 
|---|
| 130 | layout->addWidget(smallEditor, 0, 2, 4, 1); | 
|---|
| 131 | //! [10] | 
|---|
| 132 |  | 
|---|
| 133 | //! [11] | 
|---|
| 134 | layout->setColumnStretch(1, 10); | 
|---|
| 135 | layout->setColumnStretch(2, 20); | 
|---|
| 136 | gridGroupBox->setLayout(layout); | 
|---|
| 137 | } | 
|---|
| 138 | //! [11] | 
|---|
| 139 |  | 
|---|
| 140 | //! [12] | 
|---|
| 141 | void Dialog::createFormGroupBox() | 
|---|
| 142 | { | 
|---|
| 143 | formGroupBox = new QGroupBox(tr("Form layout")); | 
|---|
| 144 | QFormLayout *layout = new QFormLayout; | 
|---|
| 145 | layout->addRow(new QLabel(tr("Line 1:")), new QLineEdit); | 
|---|
| 146 | layout->addRow(new QLabel(tr("Line 2, long text:")), new QComboBox); | 
|---|
| 147 | layout->addRow(new QLabel(tr("Line 3:")), new QSpinBox); | 
|---|
| 148 | formGroupBox->setLayout(layout); | 
|---|
| 149 | } | 
|---|
| 150 | //! [12] | 
|---|