source: trunk/examples/layouts/basiclayouts/dialog.cpp@ 342

Last change on this file since 342 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 4.6 KB
Line 
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 examples 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 <QtGui>
43
44#include "dialog.h"
45
46//! [0]
47Dialog::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]
85void 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]
98void 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]
112void 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]
141void 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]
Note: See TracBrowser for help on using the repository browser.