| 1 | /**************************************************************************** | 
|---|
| 2 | ** | 
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | 
|---|
| 4 | ** Contact: Qt Software Information (qt-info@nokia.com) | 
|---|
| 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 qt-sales@nokia.com. | 
|---|
| 38 | ** $QT_END_LICENSE$ | 
|---|
| 39 | ** | 
|---|
| 40 | ****************************************************************************/ | 
|---|
| 41 |  | 
|---|
| 42 | #include <QtGui> | 
|---|
| 43 |  | 
|---|
| 44 | #include "window.h" | 
|---|
| 45 |  | 
|---|
| 46 | //! [0] | 
|---|
| 47 | Window::Window(QWidget *parent) | 
|---|
| 48 | : QWidget(parent) | 
|---|
| 49 | { | 
|---|
| 50 | QGridLayout *grid = new QGridLayout; | 
|---|
| 51 | grid->addWidget(createFirstExclusiveGroup(), 0, 0); | 
|---|
| 52 | grid->addWidget(createSecondExclusiveGroup(), 1, 0); | 
|---|
| 53 | grid->addWidget(createNonExclusiveGroup(), 0, 1); | 
|---|
| 54 | grid->addWidget(createPushButtonGroup(), 1, 1); | 
|---|
| 55 | setLayout(grid); | 
|---|
| 56 |  | 
|---|
| 57 | setWindowTitle(tr("Group Boxes")); | 
|---|
| 58 | resize(480, 320); | 
|---|
| 59 | } | 
|---|
| 60 | //! [0] | 
|---|
| 61 |  | 
|---|
| 62 | //! [1] | 
|---|
| 63 | QGroupBox *Window::createFirstExclusiveGroup() | 
|---|
| 64 | { | 
|---|
| 65 | //! [2] | 
|---|
| 66 | QGroupBox *groupBox = new QGroupBox(tr("Exclusive Radio Buttons")); | 
|---|
| 67 |  | 
|---|
| 68 | QRadioButton *radio1 = new QRadioButton(tr("&Radio button 1")); | 
|---|
| 69 | QRadioButton *radio2 = new QRadioButton(tr("R&adio button 2")); | 
|---|
| 70 | QRadioButton *radio3 = new QRadioButton(tr("Ra&dio button 3")); | 
|---|
| 71 |  | 
|---|
| 72 | radio1->setChecked(true); | 
|---|
| 73 | //! [1] //! [3] | 
|---|
| 74 |  | 
|---|
| 75 | QVBoxLayout *vbox = new QVBoxLayout; | 
|---|
| 76 | vbox->addWidget(radio1); | 
|---|
| 77 | vbox->addWidget(radio2); | 
|---|
| 78 | vbox->addWidget(radio3); | 
|---|
| 79 | vbox->addStretch(1); | 
|---|
| 80 | groupBox->setLayout(vbox); | 
|---|
| 81 | //! [2] | 
|---|
| 82 |  | 
|---|
| 83 | return groupBox; | 
|---|
| 84 | } | 
|---|
| 85 | //! [3] | 
|---|
| 86 |  | 
|---|
| 87 | //! [4] | 
|---|
| 88 | QGroupBox *Window::createSecondExclusiveGroup() | 
|---|
| 89 | { | 
|---|
| 90 | QGroupBox *groupBox = new QGroupBox(tr("E&xclusive Radio Buttons")); | 
|---|
| 91 | groupBox->setCheckable(true); | 
|---|
| 92 | groupBox->setChecked(false); | 
|---|
| 93 | //! [4] | 
|---|
| 94 |  | 
|---|
| 95 | //! [5] | 
|---|
| 96 | QRadioButton *radio1 = new QRadioButton(tr("Rad&io button 1")); | 
|---|
| 97 | QRadioButton *radio2 = new QRadioButton(tr("Radi&o button 2")); | 
|---|
| 98 | QRadioButton *radio3 = new QRadioButton(tr("Radio &button 3")); | 
|---|
| 99 | radio1->setChecked(true); | 
|---|
| 100 | QCheckBox *checkBox = new QCheckBox(tr("Ind&ependent checkbox")); | 
|---|
| 101 | checkBox->setChecked(true); | 
|---|
| 102 | //! [5] | 
|---|
| 103 |  | 
|---|
| 104 | //! [6] | 
|---|
| 105 | QVBoxLayout *vbox = new QVBoxLayout; | 
|---|
| 106 | vbox->addWidget(radio1); | 
|---|
| 107 | vbox->addWidget(radio2); | 
|---|
| 108 | vbox->addWidget(radio3); | 
|---|
| 109 | vbox->addWidget(checkBox); | 
|---|
| 110 | vbox->addStretch(1); | 
|---|
| 111 | groupBox->setLayout(vbox); | 
|---|
| 112 |  | 
|---|
| 113 | return groupBox; | 
|---|
| 114 | } | 
|---|
| 115 | //! [6] | 
|---|
| 116 |  | 
|---|
| 117 | //! [7] | 
|---|
| 118 | QGroupBox *Window::createNonExclusiveGroup() | 
|---|
| 119 | { | 
|---|
| 120 | QGroupBox *groupBox = new QGroupBox(tr("Non-Exclusive Checkboxes")); | 
|---|
| 121 | groupBox->setFlat(true); | 
|---|
| 122 | //! [7] | 
|---|
| 123 |  | 
|---|
| 124 | //! [8] | 
|---|
| 125 | QCheckBox *checkBox1 = new QCheckBox(tr("&Checkbox 1")); | 
|---|
| 126 | QCheckBox *checkBox2 = new QCheckBox(tr("C&heckbox 2")); | 
|---|
| 127 | checkBox2->setChecked(true); | 
|---|
| 128 | QCheckBox *tristateBox = new QCheckBox(tr("Tri-&state button")); | 
|---|
| 129 | tristateBox->setTristate(true); | 
|---|
| 130 | //! [8] | 
|---|
| 131 | tristateBox->setCheckState(Qt::PartiallyChecked); | 
|---|
| 132 |  | 
|---|
| 133 | //! [9] | 
|---|
| 134 | QVBoxLayout *vbox = new QVBoxLayout; | 
|---|
| 135 | vbox->addWidget(checkBox1); | 
|---|
| 136 | vbox->addWidget(checkBox2); | 
|---|
| 137 | vbox->addWidget(tristateBox); | 
|---|
| 138 | vbox->addStretch(1); | 
|---|
| 139 | groupBox->setLayout(vbox); | 
|---|
| 140 |  | 
|---|
| 141 | return groupBox; | 
|---|
| 142 | } | 
|---|
| 143 | //! [9] | 
|---|
| 144 |  | 
|---|
| 145 | //! [10] | 
|---|
| 146 | QGroupBox *Window::createPushButtonGroup() | 
|---|
| 147 | { | 
|---|
| 148 | QGroupBox *groupBox = new QGroupBox(tr("&Push Buttons")); | 
|---|
| 149 | groupBox->setCheckable(true); | 
|---|
| 150 | groupBox->setChecked(true); | 
|---|
| 151 | //! [10] | 
|---|
| 152 |  | 
|---|
| 153 | //! [11] | 
|---|
| 154 | QPushButton *pushButton = new QPushButton(tr("&Normal Button")); | 
|---|
| 155 | QPushButton *toggleButton = new QPushButton(tr("&Toggle Button")); | 
|---|
| 156 | toggleButton->setCheckable(true); | 
|---|
| 157 | toggleButton->setChecked(true); | 
|---|
| 158 | QPushButton *flatButton = new QPushButton(tr("&Flat Button")); | 
|---|
| 159 | flatButton->setFlat(true); | 
|---|
| 160 | //! [11] | 
|---|
| 161 |  | 
|---|
| 162 | //! [12] | 
|---|
| 163 | QPushButton *popupButton = new QPushButton(tr("Pop&up Button")); | 
|---|
| 164 | QMenu *menu = new QMenu(this); | 
|---|
| 165 | menu->addAction(tr("&First Item")); | 
|---|
| 166 | menu->addAction(tr("&Second Item")); | 
|---|
| 167 | menu->addAction(tr("&Third Item")); | 
|---|
| 168 | menu->addAction(tr("F&ourth Item")); | 
|---|
| 169 | popupButton->setMenu(menu); | 
|---|
| 170 | //! [12] | 
|---|
| 171 |  | 
|---|
| 172 | QAction *newAction = menu->addAction(tr("Submenu")); | 
|---|
| 173 | QMenu *subMenu = new QMenu(tr("Popup Submenu")); | 
|---|
| 174 | subMenu->addAction(tr("Item 1")); | 
|---|
| 175 | subMenu->addAction(tr("Item 2")); | 
|---|
| 176 | subMenu->addAction(tr("Item 3")); | 
|---|
| 177 | newAction->setMenu(subMenu); | 
|---|
| 178 |  | 
|---|
| 179 | //! [13] | 
|---|
| 180 | QVBoxLayout *vbox = new QVBoxLayout; | 
|---|
| 181 | vbox->addWidget(pushButton); | 
|---|
| 182 | vbox->addWidget(toggleButton); | 
|---|
| 183 | vbox->addWidget(flatButton); | 
|---|
| 184 | vbox->addWidget(popupButton); | 
|---|
| 185 | vbox->addStretch(1); | 
|---|
| 186 | groupBox->setLayout(vbox); | 
|---|
| 187 |  | 
|---|
| 188 | return groupBox; | 
|---|
| 189 | } | 
|---|
| 190 | //! [13] | 
|---|