[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[846] | 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
---|
[2] | 6 | **
|
---|
| 7 | ** This file is part of the examples of the Qt Toolkit.
|
---|
| 8 | **
|
---|
[846] | 9 | ** $QT_BEGIN_LICENSE:BSD$
|
---|
| 10 | ** You may use this file under the terms of the BSD license as follows:
|
---|
[2] | 11 | **
|
---|
[846] | 12 | ** "Redistribution and use in source and binary forms, with or without
|
---|
| 13 | ** modification, are permitted provided that the following conditions are
|
---|
| 14 | ** met:
|
---|
| 15 | ** * Redistributions of source code must retain the above copyright
|
---|
| 16 | ** notice, this list of conditions and the following disclaimer.
|
---|
| 17 | ** * Redistributions in binary form must reproduce the above copyright
|
---|
| 18 | ** notice, this list of conditions and the following disclaimer in
|
---|
| 19 | ** the documentation and/or other materials provided with the
|
---|
| 20 | ** distribution.
|
---|
| 21 | ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
---|
| 22 | ** the names of its contributors may be used to endorse or promote
|
---|
| 23 | ** products derived from this software without specific prior written
|
---|
| 24 | ** permission.
|
---|
[2] | 25 | **
|
---|
[846] | 26 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
---|
| 27 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
---|
| 28 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
---|
| 29 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
---|
| 30 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
---|
| 31 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
---|
| 32 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 33 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 34 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 35 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
---|
| 36 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
---|
[2] | 37 | ** $QT_END_LICENSE$
|
---|
| 38 | **
|
---|
| 39 | ****************************************************************************/
|
---|
| 40 |
|
---|
| 41 | #include <QtGui>
|
---|
| 42 |
|
---|
| 43 | #include "norwegianwoodstyle.h"
|
---|
| 44 | #include "widgetgallery.h"
|
---|
| 45 |
|
---|
| 46 | //! [0]
|
---|
| 47 | WidgetGallery::WidgetGallery(QWidget *parent)
|
---|
| 48 | : QDialog(parent)
|
---|
| 49 | {
|
---|
| 50 | originalPalette = QApplication::palette();
|
---|
| 51 |
|
---|
| 52 | styleComboBox = new QComboBox;
|
---|
| 53 | styleComboBox->addItem("NorwegianWood");
|
---|
| 54 | styleComboBox->addItems(QStyleFactory::keys());
|
---|
| 55 |
|
---|
| 56 | styleLabel = new QLabel(tr("&Style:"));
|
---|
| 57 | styleLabel->setBuddy(styleComboBox);
|
---|
| 58 |
|
---|
| 59 | useStylePaletteCheckBox = new QCheckBox(tr("&Use style's standard palette"));
|
---|
| 60 | useStylePaletteCheckBox->setChecked(true);
|
---|
| 61 |
|
---|
| 62 | disableWidgetsCheckBox = new QCheckBox(tr("&Disable widgets"));
|
---|
| 63 |
|
---|
| 64 | createTopLeftGroupBox();
|
---|
| 65 | createTopRightGroupBox();
|
---|
| 66 | createBottomLeftTabWidget();
|
---|
| 67 | createBottomRightGroupBox();
|
---|
| 68 | createProgressBar();
|
---|
| 69 | //! [0]
|
---|
| 70 |
|
---|
| 71 | //! [1]
|
---|
[561] | 72 | connect(styleComboBox, SIGNAL(activated(QString)),
|
---|
[2] | 73 | //! [1] //! [2]
|
---|
[561] | 74 | this, SLOT(changeStyle(QString)));
|
---|
[2] | 75 | connect(useStylePaletteCheckBox, SIGNAL(toggled(bool)),
|
---|
| 76 | this, SLOT(changePalette()));
|
---|
| 77 | connect(disableWidgetsCheckBox, SIGNAL(toggled(bool)),
|
---|
| 78 | topLeftGroupBox, SLOT(setDisabled(bool)));
|
---|
| 79 | connect(disableWidgetsCheckBox, SIGNAL(toggled(bool)),
|
---|
| 80 | topRightGroupBox, SLOT(setDisabled(bool)));
|
---|
| 81 | connect(disableWidgetsCheckBox, SIGNAL(toggled(bool)),
|
---|
| 82 | bottomLeftTabWidget, SLOT(setDisabled(bool)));
|
---|
| 83 | connect(disableWidgetsCheckBox, SIGNAL(toggled(bool)),
|
---|
| 84 | bottomRightGroupBox, SLOT(setDisabled(bool)));
|
---|
| 85 | //! [2]
|
---|
| 86 |
|
---|
| 87 | //! [3]
|
---|
| 88 | QHBoxLayout *topLayout = new QHBoxLayout;
|
---|
| 89 | //! [3] //! [4]
|
---|
| 90 | topLayout->addWidget(styleLabel);
|
---|
| 91 | topLayout->addWidget(styleComboBox);
|
---|
| 92 | topLayout->addStretch(1);
|
---|
| 93 | topLayout->addWidget(useStylePaletteCheckBox);
|
---|
| 94 | topLayout->addWidget(disableWidgetsCheckBox);
|
---|
| 95 |
|
---|
| 96 | QGridLayout *mainLayout = new QGridLayout;
|
---|
| 97 | mainLayout->addLayout(topLayout, 0, 0, 1, 2);
|
---|
| 98 | mainLayout->addWidget(topLeftGroupBox, 1, 0);
|
---|
| 99 | mainLayout->addWidget(topRightGroupBox, 1, 1);
|
---|
| 100 | mainLayout->addWidget(bottomLeftTabWidget, 2, 0);
|
---|
| 101 | mainLayout->addWidget(bottomRightGroupBox, 2, 1);
|
---|
| 102 | mainLayout->addWidget(progressBar, 3, 0, 1, 2);
|
---|
| 103 | mainLayout->setRowStretch(1, 1);
|
---|
| 104 | mainLayout->setRowStretch(2, 1);
|
---|
| 105 | mainLayout->setColumnStretch(0, 1);
|
---|
| 106 | mainLayout->setColumnStretch(1, 1);
|
---|
| 107 | setLayout(mainLayout);
|
---|
| 108 |
|
---|
| 109 | setWindowTitle(tr("Styles"));
|
---|
| 110 | changeStyle("NorwegianWood");
|
---|
| 111 | }
|
---|
| 112 | //! [4]
|
---|
| 113 |
|
---|
| 114 | //! [5]
|
---|
| 115 | void WidgetGallery::changeStyle(const QString &styleName)
|
---|
| 116 | //! [5] //! [6]
|
---|
| 117 | {
|
---|
| 118 | if (styleName == "NorwegianWood") {
|
---|
| 119 | QApplication::setStyle(new NorwegianWoodStyle);
|
---|
| 120 | } else {
|
---|
| 121 | QApplication::setStyle(QStyleFactory::create(styleName));
|
---|
| 122 | }
|
---|
| 123 | changePalette();
|
---|
| 124 | }
|
---|
| 125 | //! [6]
|
---|
| 126 |
|
---|
| 127 | //! [7]
|
---|
| 128 | void WidgetGallery::changePalette()
|
---|
| 129 | //! [7] //! [8]
|
---|
| 130 | {
|
---|
| 131 | if (useStylePaletteCheckBox->isChecked())
|
---|
| 132 | QApplication::setPalette(QApplication::style()->standardPalette());
|
---|
| 133 | else
|
---|
| 134 | QApplication::setPalette(originalPalette);
|
---|
| 135 | }
|
---|
| 136 | //! [8]
|
---|
| 137 |
|
---|
| 138 | //! [9]
|
---|
| 139 | void WidgetGallery::advanceProgressBar()
|
---|
| 140 | //! [9] //! [10]
|
---|
| 141 | {
|
---|
| 142 | int curVal = progressBar->value();
|
---|
| 143 | int maxVal = progressBar->maximum();
|
---|
| 144 | progressBar->setValue(curVal + (maxVal - curVal) / 100);
|
---|
| 145 | }
|
---|
| 146 | //! [10]
|
---|
| 147 |
|
---|
| 148 | //! [11]
|
---|
| 149 | void WidgetGallery::createTopLeftGroupBox()
|
---|
| 150 | //! [11] //! [12]
|
---|
| 151 | {
|
---|
| 152 | topLeftGroupBox = new QGroupBox(tr("Group 1"));
|
---|
| 153 |
|
---|
| 154 | radioButton1 = new QRadioButton(tr("Radio button 1"));
|
---|
| 155 | radioButton2 = new QRadioButton(tr("Radio button 2"));
|
---|
| 156 | radioButton3 = new QRadioButton(tr("Radio button 3"));
|
---|
| 157 | radioButton1->setChecked(true);
|
---|
| 158 |
|
---|
| 159 | checkBox = new QCheckBox(tr("Tri-state check box"));
|
---|
| 160 | checkBox->setTristate(true);
|
---|
| 161 | checkBox->setCheckState(Qt::PartiallyChecked);
|
---|
| 162 |
|
---|
| 163 | QVBoxLayout *layout = new QVBoxLayout;
|
---|
| 164 | layout->addWidget(radioButton1);
|
---|
| 165 | layout->addWidget(radioButton2);
|
---|
| 166 | layout->addWidget(radioButton3);
|
---|
| 167 | layout->addWidget(checkBox);
|
---|
| 168 | layout->addStretch(1);
|
---|
| 169 | topLeftGroupBox->setLayout(layout);
|
---|
| 170 | }
|
---|
| 171 | //! [12]
|
---|
| 172 |
|
---|
| 173 | void WidgetGallery::createTopRightGroupBox()
|
---|
| 174 | {
|
---|
| 175 | topRightGroupBox = new QGroupBox(tr("Group 2"));
|
---|
| 176 |
|
---|
| 177 | defaultPushButton = new QPushButton(tr("Default Push Button"));
|
---|
| 178 | defaultPushButton->setDefault(true);
|
---|
| 179 |
|
---|
| 180 | togglePushButton = new QPushButton(tr("Toggle Push Button"));
|
---|
| 181 | togglePushButton->setCheckable(true);
|
---|
| 182 | togglePushButton->setChecked(true);
|
---|
| 183 |
|
---|
| 184 | flatPushButton = new QPushButton(tr("Flat Push Button"));
|
---|
| 185 | flatPushButton->setFlat(true);
|
---|
| 186 |
|
---|
| 187 | QVBoxLayout *layout = new QVBoxLayout;
|
---|
| 188 | layout->addWidget(defaultPushButton);
|
---|
| 189 | layout->addWidget(togglePushButton);
|
---|
| 190 | layout->addWidget(flatPushButton);
|
---|
| 191 | layout->addStretch(1);
|
---|
| 192 | topRightGroupBox->setLayout(layout);
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | void WidgetGallery::createBottomLeftTabWidget()
|
---|
| 196 | {
|
---|
| 197 | bottomLeftTabWidget = new QTabWidget;
|
---|
| 198 | bottomLeftTabWidget->setSizePolicy(QSizePolicy::Preferred,
|
---|
| 199 | QSizePolicy::Ignored);
|
---|
| 200 |
|
---|
| 201 | QWidget *tab1 = new QWidget;
|
---|
| 202 | tableWidget = new QTableWidget(10, 10);
|
---|
| 203 |
|
---|
| 204 | QHBoxLayout *tab1hbox = new QHBoxLayout;
|
---|
| 205 | tab1hbox->setMargin(5);
|
---|
| 206 | tab1hbox->addWidget(tableWidget);
|
---|
| 207 | tab1->setLayout(tab1hbox);
|
---|
| 208 |
|
---|
| 209 | QWidget *tab2 = new QWidget;
|
---|
| 210 | textEdit = new QTextEdit;
|
---|
| 211 |
|
---|
| 212 | textEdit->setPlainText(tr("Twinkle, twinkle, little star,\n"
|
---|
| 213 | "How I wonder what you are.\n"
|
---|
| 214 | "Up above the world so high,\n"
|
---|
| 215 | "Like a diamond in the sky.\n"
|
---|
| 216 | "Twinkle, twinkle, little star,\n"
|
---|
| 217 | "How I wonder what you are!\n"));
|
---|
| 218 |
|
---|
| 219 | QHBoxLayout *tab2hbox = new QHBoxLayout;
|
---|
| 220 | tab2hbox->setMargin(5);
|
---|
| 221 | tab2hbox->addWidget(textEdit);
|
---|
| 222 | tab2->setLayout(tab2hbox);
|
---|
| 223 |
|
---|
| 224 | bottomLeftTabWidget->addTab(tab1, tr("&Table"));
|
---|
| 225 | bottomLeftTabWidget->addTab(tab2, tr("Text &Edit"));
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 | void WidgetGallery::createBottomRightGroupBox()
|
---|
| 229 | {
|
---|
| 230 | bottomRightGroupBox = new QGroupBox(tr("Group 3"));
|
---|
| 231 | bottomRightGroupBox->setCheckable(true);
|
---|
| 232 | bottomRightGroupBox->setChecked(true);
|
---|
| 233 |
|
---|
| 234 | lineEdit = new QLineEdit("s3cRe7");
|
---|
| 235 | lineEdit->setEchoMode(QLineEdit::Password);
|
---|
| 236 |
|
---|
| 237 | spinBox = new QSpinBox(bottomRightGroupBox);
|
---|
| 238 | spinBox->setValue(50);
|
---|
| 239 |
|
---|
| 240 | dateTimeEdit = new QDateTimeEdit(bottomRightGroupBox);
|
---|
| 241 | dateTimeEdit->setDateTime(QDateTime::currentDateTime());
|
---|
| 242 |
|
---|
| 243 | slider = new QSlider(Qt::Horizontal, bottomRightGroupBox);
|
---|
| 244 | slider->setValue(40);
|
---|
| 245 |
|
---|
| 246 | scrollBar = new QScrollBar(Qt::Horizontal, bottomRightGroupBox);
|
---|
| 247 | scrollBar->setValue(60);
|
---|
| 248 |
|
---|
| 249 | dial = new QDial(bottomRightGroupBox);
|
---|
| 250 | dial->setValue(30);
|
---|
| 251 | dial->setNotchesVisible(true);
|
---|
| 252 |
|
---|
| 253 | QGridLayout *layout = new QGridLayout;
|
---|
| 254 | layout->addWidget(lineEdit, 0, 0, 1, 2);
|
---|
| 255 | layout->addWidget(spinBox, 1, 0, 1, 2);
|
---|
| 256 | layout->addWidget(dateTimeEdit, 2, 0, 1, 2);
|
---|
| 257 | layout->addWidget(slider, 3, 0);
|
---|
| 258 | layout->addWidget(scrollBar, 4, 0);
|
---|
| 259 | layout->addWidget(dial, 3, 1, 2, 1);
|
---|
| 260 | layout->setRowStretch(5, 1);
|
---|
| 261 | bottomRightGroupBox->setLayout(layout);
|
---|
| 262 | }
|
---|
| 263 |
|
---|
| 264 | //! [13]
|
---|
| 265 | void WidgetGallery::createProgressBar()
|
---|
| 266 | {
|
---|
| 267 | progressBar = new QProgressBar;
|
---|
| 268 | progressBar->setRange(0, 10000);
|
---|
| 269 | progressBar->setValue(0);
|
---|
| 270 |
|
---|
| 271 | QTimer *timer = new QTimer(this);
|
---|
| 272 | connect(timer, SIGNAL(timeout()), this, SLOT(advanceProgressBar()));
|
---|
| 273 | timer->start(1000);
|
---|
| 274 | }
|
---|
| 275 | //! [13]
|
---|