diff options
Diffstat (limited to 'examples/widgets')
192 files changed, 15021 insertions, 0 deletions
diff --git a/examples/widgets/README b/examples/widgets/README new file mode 100644 index 0000000..fd16c67 --- /dev/null +++ b/examples/widgets/README @@ -0,0 +1,44 @@ +Qt comes with a large range of standard widgets that users of modern +applications have come to expect. + +You can also develop your own custom widgets and controls, and use them +alongside standard widgets. + +It is even possible to provide custom styles and themes for widgets that can +be used to change the appearance of standard widgets and appropriately +written custom widgets. + + +The example launcher provided with Qt can be used to explore each of the +examples in this directory. + +Documentation for these examples can be found via the Tutorial and Examples +link in the main Qt documentation. + + +Finding the Qt Examples and Demos launcher +========================================== + +On Windows: + +The launcher can be accessed via the Windows Start menu. Select the menu +entry entitled "Qt Examples and Demos" entry in the submenu containing +the Qt tools. + +On Mac OS X: + +For the binary distribution, the qtdemo executable is installed in the +/Developer/Applications/Qt directory. For the source distribution, it is +installed alongside the other Qt tools on the path specified when Qt is +configured. + +On Unix/Linux: + +The qtdemo executable is installed alongside the other Qt tools on the path +specified when Qt is configured. + +On all platforms: + +The source code for the launcher can be found in the demos/qtdemo directory +in the Qt package. This example is built at the same time as the Qt libraries, +tools, examples, and demonstrations. diff --git a/examples/widgets/analogclock/analogclock.cpp b/examples/widgets/analogclock/analogclock.cpp new file mode 100644 index 0000000..5856ec9 --- /dev/null +++ b/examples/widgets/analogclock/analogclock.cpp @@ -0,0 +1,146 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "analogclock.h" + +//! [0] //! [1] +AnalogClock::AnalogClock(QWidget *parent) +//! [0] //! [2] + : QWidget(parent) +//! [2] //! [3] +{ +//! [3] //! [4] + QTimer *timer = new QTimer(this); +//! [4] //! [5] + connect(timer, SIGNAL(timeout()), this, SLOT(update())); +//! [5] //! [6] + timer->start(1000); +//! [6] + + setWindowTitle(tr("Analog Clock")); + resize(200, 200); +//! [7] +} +//! [1] //! [7] + +//! [8] //! [9] +void AnalogClock::paintEvent(QPaintEvent *) +//! [8] //! [10] +{ + static const QPoint hourHand[3] = { + QPoint(7, 8), + QPoint(-7, 8), + QPoint(0, -40) + }; + static const QPoint minuteHand[3] = { + QPoint(7, 8), + QPoint(-7, 8), + QPoint(0, -70) + }; + + QColor hourColor(127, 0, 127); + QColor minuteColor(0, 127, 127, 191); + + int side = qMin(width(), height()); + QTime time = QTime::currentTime(); +//! [10] + +//! [11] + QPainter painter(this); +//! [11] //! [12] + painter.setRenderHint(QPainter::Antialiasing); +//! [12] //! [13] + painter.translate(width() / 2, height() / 2); +//! [13] //! [14] + painter.scale(side / 200.0, side / 200.0); +//! [9] //! [14] + +//! [15] + painter.setPen(Qt::NoPen); +//! [15] //! [16] + painter.setBrush(hourColor); +//! [16] + +//! [17] //! [18] + painter.save(); +//! [17] //! [19] + painter.rotate(30.0 * ((time.hour() + time.minute() / 60.0))); + painter.drawConvexPolygon(hourHand, 3); + painter.restore(); +//! [18] //! [19] + +//! [20] + painter.setPen(hourColor); +//! [20] //! [21] + + for (int i = 0; i < 12; ++i) { + painter.drawLine(88, 0, 96, 0); + painter.rotate(30.0); + } +//! [21] + +//! [22] + painter.setPen(Qt::NoPen); +//! [22] //! [23] + painter.setBrush(minuteColor); + +//! [24] + painter.save(); + painter.rotate(6.0 * (time.minute() + time.second() / 60.0)); + painter.drawConvexPolygon(minuteHand, 3); + painter.restore(); +//! [23] //! [24] + +//! [25] + painter.setPen(minuteColor); +//! [25] //! [26] + +//! [27] + for (int j = 0; j < 60; ++j) { + if ((j % 5) != 0) + painter.drawLine(92, 0, 96, 0); + painter.rotate(6.0); + } +//! [27] +} +//! [26] diff --git a/examples/widgets/analogclock/analogclock.h b/examples/widgets/analogclock/analogclock.h new file mode 100644 index 0000000..4a32219 --- /dev/null +++ b/examples/widgets/analogclock/analogclock.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ANALOGCLOCK_H +#define ANALOGCLOCK_H + +#include <QWidget> + +//! [0] +class AnalogClock : public QWidget +{ + Q_OBJECT + +public: + AnalogClock(QWidget *parent = 0); + +protected: + void paintEvent(QPaintEvent *event); +}; +//! [0] + +#endif diff --git a/examples/widgets/analogclock/analogclock.pro b/examples/widgets/analogclock/analogclock.pro new file mode 100644 index 0000000..62a1806 --- /dev/null +++ b/examples/widgets/analogclock/analogclock.pro @@ -0,0 +1,9 @@ +HEADERS = analogclock.h +SOURCES = analogclock.cpp \ + main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/widgets/analogclock +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS analogclock.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/analogclock +INSTALLS += target sources diff --git a/examples/widgets/analogclock/main.cpp b/examples/widgets/analogclock/main.cpp new file mode 100644 index 0000000..e8fa08b --- /dev/null +++ b/examples/widgets/analogclock/main.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> + +#include "analogclock.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + AnalogClock clock; + clock.show(); + return app.exec(); +} diff --git a/examples/widgets/calculator/button.cpp b/examples/widgets/calculator/button.cpp new file mode 100644 index 0000000..e77442e --- /dev/null +++ b/examples/widgets/calculator/button.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "button.h" + +//! [0] +Button::Button(const QString &text, QWidget *parent) + : QToolButton(parent) +{ + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + setText(text); +} +//! [0] + +//! [1] +QSize Button::sizeHint() const +//! [1] //! [2] +{ + QSize size = QToolButton::sizeHint(); + size.rheight() += 20; + size.rwidth() = qMax(size.width(), size.height()); + return size; +} +//! [2] diff --git a/examples/widgets/calculator/button.h b/examples/widgets/calculator/button.h new file mode 100644 index 0000000..5637e6b --- /dev/null +++ b/examples/widgets/calculator/button.h @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef BUTTON_H +#define BUTTON_H + +#include <QToolButton> + +//! [0] +class Button : public QToolButton +{ + Q_OBJECT + +public: + Button(const QString &text, QWidget *parent = 0); + + QSize sizeHint() const; +}; +//! [0] + +#endif diff --git a/examples/widgets/calculator/calculator.cpp b/examples/widgets/calculator/calculator.cpp new file mode 100644 index 0000000..9c2ef4a --- /dev/null +++ b/examples/widgets/calculator/calculator.cpp @@ -0,0 +1,398 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include <math.h> + +#include "button.h" +#include "calculator.h" + +//! [0] +Calculator::Calculator(QWidget *parent) + : QDialog(parent) +{ + sumInMemory = 0.0; + sumSoFar = 0.0; + factorSoFar = 0.0; + waitingForOperand = true; +//! [0] + +//! [1] + display = new QLineEdit("0"); +//! [1] //! [2] + display->setReadOnly(true); + display->setAlignment(Qt::AlignRight); + display->setMaxLength(15); + + QFont font = display->font(); + font.setPointSize(font.pointSize() + 8); + display->setFont(font); +//! [2] + +//! [4] + for (int i = 0; i < NumDigitButtons; ++i) { + digitButtons[i] = createButton(QString::number(i), SLOT(digitClicked())); + } + + Button *pointButton = createButton(tr("."), SLOT(pointClicked())); + Button *changeSignButton = createButton(tr("\261"), SLOT(changeSignClicked())); + + Button *backspaceButton = createButton(tr("Backspace"), SLOT(backspaceClicked())); + Button *clearButton = createButton(tr("Clear"), SLOT(clear())); + Button *clearAllButton = createButton(tr("Clear All"), SLOT(clearAll())); + + Button *clearMemoryButton = createButton(tr("MC"), SLOT(clearMemory())); + Button *readMemoryButton = createButton(tr("MR"), SLOT(readMemory())); + Button *setMemoryButton = createButton(tr("MS"), SLOT(setMemory())); + Button *addToMemoryButton = createButton(tr("M+"), SLOT(addToMemory())); + + Button *divisionButton = createButton(tr("\367"), SLOT(multiplicativeOperatorClicked())); + Button *timesButton = createButton(tr("\327"), SLOT(multiplicativeOperatorClicked())); + Button *minusButton = createButton(tr("-"), SLOT(additiveOperatorClicked())); + Button *plusButton = createButton(tr("+"), SLOT(additiveOperatorClicked())); + + Button *squareRootButton = createButton(tr("Sqrt"), SLOT(unaryOperatorClicked())); + Button *powerButton = createButton(tr("x\262"), SLOT(unaryOperatorClicked())); + Button *reciprocalButton = createButton(tr("1/x"), SLOT(unaryOperatorClicked())); + Button *equalButton = createButton(tr("="), SLOT(equalClicked())); +//! [4] + +//! [5] + QGridLayout *mainLayout = new QGridLayout; +//! [5] //! [6] + mainLayout->setSizeConstraint(QLayout::SetFixedSize); + + mainLayout->addWidget(display, 0, 0, 1, 6); + mainLayout->addWidget(backspaceButton, 1, 0, 1, 2); + mainLayout->addWidget(clearButton, 1, 2, 1, 2); + mainLayout->addWidget(clearAllButton, 1, 4, 1, 2); + + mainLayout->addWidget(clearMemoryButton, 2, 0); + mainLayout->addWidget(readMemoryButton, 3, 0); + mainLayout->addWidget(setMemoryButton, 4, 0); + mainLayout->addWidget(addToMemoryButton, 5, 0); + + for (int i = 1; i < NumDigitButtons; ++i) { + int row = ((9 - i) / 3) + 2; + int column = ((i - 1) % 3) + 1; + mainLayout->addWidget(digitButtons[i], row, column); + } + + mainLayout->addWidget(digitButtons[0], 5, 1); + mainLayout->addWidget(pointButton, 5, 2); + mainLayout->addWidget(changeSignButton, 5, 3); + + mainLayout->addWidget(divisionButton, 2, 4); + mainLayout->addWidget(timesButton, 3, 4); + mainLayout->addWidget(minusButton, 4, 4); + mainLayout->addWidget(plusButton, 5, 4); + + mainLayout->addWidget(squareRootButton, 2, 5); + mainLayout->addWidget(powerButton, 3, 5); + mainLayout->addWidget(reciprocalButton, 4, 5); + mainLayout->addWidget(equalButton, 5, 5); + setLayout(mainLayout); + + setWindowTitle(tr("Calculator")); +} +//! [6] + +//! [7] +void Calculator::digitClicked() +{ + Button *clickedButton = qobject_cast<Button *>(sender()); + int digitValue = clickedButton->text().toInt(); + if (display->text() == "0" && digitValue == 0.0) + return; + + if (waitingForOperand) { + display->clear(); + waitingForOperand = false; + } + display->setText(display->text() + QString::number(digitValue)); +} +//! [7] + +//! [8] +void Calculator::unaryOperatorClicked() +//! [8] //! [9] +{ + Button *clickedButton = qobject_cast<Button *>(sender()); + QString clickedOperator = clickedButton->text(); + double operand = display->text().toDouble(); + double result = 0.0; + + if (clickedOperator == tr("Sqrt")) { + if (operand < 0.0) { + abortOperation(); + return; + } + result = sqrt(operand); + } else if (clickedOperator == tr("x\262")) { + result = pow(operand, 2.0); + } else if (clickedOperator == tr("1/x")) { + if (operand == 0.0) { + abortOperation(); + return; + } + result = 1.0 / operand; + } + display->setText(QString::number(result)); + waitingForOperand = true; +} +//! [9] + +//! [10] +void Calculator::additiveOperatorClicked() +//! [10] //! [11] +{ + Button *clickedButton = qobject_cast<Button *>(sender()); + QString clickedOperator = clickedButton->text(); + double operand = display->text().toDouble(); + +//! [11] //! [12] + if (!pendingMultiplicativeOperator.isEmpty()) { +//! [12] //! [13] + if (!calculate(operand, pendingMultiplicativeOperator)) { + abortOperation(); + return; + } + display->setText(QString::number(factorSoFar)); + operand = factorSoFar; + factorSoFar = 0.0; + pendingMultiplicativeOperator.clear(); + } + +//! [13] //! [14] + if (!pendingAdditiveOperator.isEmpty()) { +//! [14] //! [15] + if (!calculate(operand, pendingAdditiveOperator)) { + abortOperation(); + return; + } + display->setText(QString::number(sumSoFar)); + } else { + sumSoFar = operand; + } + +//! [15] //! [16] + pendingAdditiveOperator = clickedOperator; +//! [16] //! [17] + waitingForOperand = true; +} +//! [17] + +//! [18] +void Calculator::multiplicativeOperatorClicked() +{ + Button *clickedButton = qobject_cast<Button *>(sender()); + QString clickedOperator = clickedButton->text(); + double operand = display->text().toDouble(); + + if (!pendingMultiplicativeOperator.isEmpty()) { + if (!calculate(operand, pendingMultiplicativeOperator)) { + abortOperation(); + return; + } + display->setText(QString::number(factorSoFar)); + } else { + factorSoFar = operand; + } + + pendingMultiplicativeOperator = clickedOperator; + waitingForOperand = true; +} +//! [18] + +//! [20] +void Calculator::equalClicked() +{ + double operand = display->text().toDouble(); + + if (!pendingMultiplicativeOperator.isEmpty()) { + if (!calculate(operand, pendingMultiplicativeOperator)) { + abortOperation(); + return; + } + operand = factorSoFar; + factorSoFar = 0.0; + pendingMultiplicativeOperator.clear(); + } + if (!pendingAdditiveOperator.isEmpty()) { + if (!calculate(operand, pendingAdditiveOperator)) { + abortOperation(); + return; + } + pendingAdditiveOperator.clear(); + } else { + sumSoFar = operand; + } + + display->setText(QString::number(sumSoFar)); + sumSoFar = 0.0; + waitingForOperand = true; +} +//! [20] + +//! [22] +void Calculator::pointClicked() +{ + if (waitingForOperand) + display->setText("0"); + if (!display->text().contains(".")) + display->setText(display->text() + tr(".")); + waitingForOperand = false; +} +//! [22] + +//! [24] +void Calculator::changeSignClicked() +{ + QString text = display->text(); + double value = text.toDouble(); + + if (value > 0.0) { + text.prepend(tr("-")); + } else if (value < 0.0) { + text.remove(0, 1); + } + display->setText(text); +} +//! [24] + +//! [26] +void Calculator::backspaceClicked() +{ + if (waitingForOperand) + return; + + QString text = display->text(); + text.chop(1); + if (text.isEmpty()) { + text = "0"; + waitingForOperand = true; + } + display->setText(text); +} +//! [26] + +//! [28] +void Calculator::clear() +{ + if (waitingForOperand) + return; + + display->setText("0"); + waitingForOperand = true; +} +//! [28] + +//! [30] +void Calculator::clearAll() +{ + sumSoFar = 0.0; + factorSoFar = 0.0; + pendingAdditiveOperator.clear(); + pendingMultiplicativeOperator.clear(); + display->setText("0"); + waitingForOperand = true; +} +//! [30] + +//! [32] +void Calculator::clearMemory() +{ + sumInMemory = 0.0; +} + +void Calculator::readMemory() +{ + display->setText(QString::number(sumInMemory)); + waitingForOperand = true; +} + +void Calculator::setMemory() +{ + equalClicked(); + sumInMemory = display->text().toDouble(); +} + +void Calculator::addToMemory() +{ + equalClicked(); + sumInMemory += display->text().toDouble(); +} +//! [32] +//! [34] +Button *Calculator::createButton(const QString &text, const char *member) +{ + Button *button = new Button(text); + connect(button, SIGNAL(clicked()), this, member); + return button; +} +//! [34] + +//! [36] +void Calculator::abortOperation() +{ + clearAll(); + display->setText(tr("####")); +} +//! [36] + +//! [38] +bool Calculator::calculate(double rightOperand, const QString &pendingOperator) +{ + if (pendingOperator == tr("+")) { + sumSoFar += rightOperand; + } else if (pendingOperator == tr("-")) { + sumSoFar -= rightOperand; + } else if (pendingOperator == tr("\327")) { + factorSoFar *= rightOperand; + } else if (pendingOperator == tr("\367")) { + if (rightOperand == 0.0) + return false; + factorSoFar /= rightOperand; + } + return true; +} +//! [38] diff --git a/examples/widgets/calculator/calculator.h b/examples/widgets/calculator/calculator.h new file mode 100644 index 0000000..4955c28 --- /dev/null +++ b/examples/widgets/calculator/calculator.h @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef CALCULATOR_H +#define CALCULATOR_H + +#include <QDialog> + +QT_BEGIN_NAMESPACE +class QLineEdit; +QT_END_NAMESPACE +class Button; + +//! [0] +class Calculator : public QDialog +{ + Q_OBJECT + +public: + Calculator(QWidget *parent = 0); + +private slots: + void digitClicked(); + void unaryOperatorClicked(); + void additiveOperatorClicked(); + void multiplicativeOperatorClicked(); + void equalClicked(); + void pointClicked(); + void changeSignClicked(); + void backspaceClicked(); + void clear(); + void clearAll(); + void clearMemory(); + void readMemory(); + void setMemory(); + void addToMemory(); +//! [0] + +//! [1] +private: +//! [1] //! [2] + Button *createButton(const QString &text, const char *member); + void abortOperation(); + bool calculate(double rightOperand, const QString &pendingOperator); +//! [2] + +//! [3] + double sumInMemory; +//! [3] //! [4] + double sumSoFar; +//! [4] //! [5] + double factorSoFar; +//! [5] //! [6] + QString pendingAdditiveOperator; +//! [6] //! [7] + QString pendingMultiplicativeOperator; +//! [7] //! [8] + bool waitingForOperand; +//! [8] + +//! [9] + QLineEdit *display; +//! [9] //! [10] + + enum { NumDigitButtons = 10 }; + Button *digitButtons[NumDigitButtons]; +}; +//! [10] + +#endif diff --git a/examples/widgets/calculator/calculator.pro b/examples/widgets/calculator/calculator.pro new file mode 100644 index 0000000..a9a50d6 --- /dev/null +++ b/examples/widgets/calculator/calculator.pro @@ -0,0 +1,11 @@ +HEADERS = button.h \ + calculator.h +SOURCES = button.cpp \ + calculator.cpp \ + main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/widgets/calculator +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS calculator.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/calculator +INSTALLS += target sources diff --git a/examples/widgets/calculator/main.cpp b/examples/widgets/calculator/main.cpp new file mode 100644 index 0000000..ddb0028 --- /dev/null +++ b/examples/widgets/calculator/main.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> + +#include "calculator.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + Calculator calc; + calc.show(); + return app.exec(); +} diff --git a/examples/widgets/calendarwidget/calendarwidget.pro b/examples/widgets/calendarwidget/calendarwidget.pro new file mode 100644 index 0000000..9326989 --- /dev/null +++ b/examples/widgets/calendarwidget/calendarwidget.pro @@ -0,0 +1,9 @@ +HEADERS = window.h +SOURCES = main.cpp \ + window.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/widgets/calendarwidget +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS calendarwidget.pro resources +sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/calendarwidget +INSTALLS += target sources diff --git a/examples/widgets/calendarwidget/main.cpp b/examples/widgets/calendarwidget/main.cpp new file mode 100644 index 0000000..a2fa399 --- /dev/null +++ b/examples/widgets/calendarwidget/main.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "window.h" + +int main(int argv, char *args[]) +{ + QApplication app(argv, args); + Window window; + window.show(); + return app.exec(); +} diff --git a/examples/widgets/calendarwidget/window.cpp b/examples/widgets/calendarwidget/window.cpp new file mode 100644 index 0000000..613a30a --- /dev/null +++ b/examples/widgets/calendarwidget/window.cpp @@ -0,0 +1,462 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "window.h" + +//! [0] +Window::Window() +{ + createPreviewGroupBox(); + createGeneralOptionsGroupBox(); + createDatesGroupBox(); + createTextFormatsGroupBox(); + + QGridLayout *layout = new QGridLayout; + layout->addWidget(previewGroupBox, 0, 0); + layout->addWidget(generalOptionsGroupBox, 0, 1); + layout->addWidget(datesGroupBox, 1, 0); + layout->addWidget(textFormatsGroupBox, 1, 1); + layout->setSizeConstraint(QLayout::SetFixedSize); + setLayout(layout); + + previewLayout->setRowMinimumHeight(0, calendar->sizeHint().height()); + previewLayout->setColumnMinimumWidth(0, calendar->sizeHint().width()); + + setWindowTitle(tr("Calendar Widget")); +} +//! [0] + +void Window::localeChanged(int index) +{ + calendar->setLocale(localeCombo->itemData(index).toLocale()); +} + +//! [1] +void Window::firstDayChanged(int index) +{ + calendar->setFirstDayOfWeek(Qt::DayOfWeek( + firstDayCombo->itemData(index).toInt())); +} +//! [1] + +void Window::selectionModeChanged(int index) +{ + calendar->setSelectionMode(QCalendarWidget::SelectionMode( + selectionModeCombo->itemData(index).toInt())); +} + +void Window::horizontalHeaderChanged(int index) +{ + calendar->setHorizontalHeaderFormat(QCalendarWidget::HorizontalHeaderFormat( + horizontalHeaderCombo->itemData(index).toInt())); +} + +void Window::verticalHeaderChanged(int index) +{ + calendar->setVerticalHeaderFormat(QCalendarWidget::VerticalHeaderFormat( + verticalHeaderCombo->itemData(index).toInt())); +} + +//! [2] +void Window::selectedDateChanged() +{ + currentDateEdit->setDate(calendar->selectedDate()); +} +//! [2] + +//! [3] +void Window::minimumDateChanged(const QDate &date) +{ + calendar->setMinimumDate(date); + maximumDateEdit->setDate(calendar->maximumDate()); +} +//! [3] + +//! [4] +void Window::maximumDateChanged(const QDate &date) +{ + calendar->setMaximumDate(date); + minimumDateEdit->setDate(calendar->minimumDate()); +} +//! [4] + +//! [5] +void Window::weekdayFormatChanged() +{ + QTextCharFormat format; + + format.setForeground(qvariant_cast<QColor>( + weekdayColorCombo->itemData(weekdayColorCombo->currentIndex()))); + calendar->setWeekdayTextFormat(Qt::Monday, format); + calendar->setWeekdayTextFormat(Qt::Tuesday, format); + calendar->setWeekdayTextFormat(Qt::Wednesday, format); + calendar->setWeekdayTextFormat(Qt::Thursday, format); + calendar->setWeekdayTextFormat(Qt::Friday, format); +} +//! [5] + +//! [6] +void Window::weekendFormatChanged() +{ + QTextCharFormat format; + + format.setForeground(qvariant_cast<QColor>( + weekendColorCombo->itemData(weekendColorCombo->currentIndex()))); + calendar->setWeekdayTextFormat(Qt::Saturday, format); + calendar->setWeekdayTextFormat(Qt::Sunday, format); +} +//! [6] + +//! [7] +void Window::reformatHeaders() +{ + QString text = headerTextFormatCombo->currentText(); + QTextCharFormat format; + + if (text == tr("Bold")) { + format.setFontWeight(QFont::Bold); + } else if (text == tr("Italic")) { + format.setFontItalic(true); + } else if (text == tr("Green")) { + format.setForeground(Qt::green); + } + calendar->setHeaderTextFormat(format); +} +//! [7] + +//! [8] +void Window::reformatCalendarPage() +{ + QTextCharFormat mayFirstFormat; + if (mayFirstCheckBox->isChecked()) + mayFirstFormat.setForeground(Qt::red); + + QTextCharFormat firstFridayFormat; + if (firstFridayCheckBox->isChecked()) + firstFridayFormat.setForeground(Qt::blue); + + QDate date(calendar->yearShown(), calendar->monthShown(), 1); + + calendar->setDateTextFormat(QDate(date.year(), 5, 1), mayFirstFormat); + + date.setDate(date.year(), date.month(), 1); + while (date.dayOfWeek() != Qt::Friday) + date = date.addDays(1); + calendar->setDateTextFormat(date, firstFridayFormat); +} +//! [8] + +//! [9] +void Window::createPreviewGroupBox() +{ + previewGroupBox = new QGroupBox(tr("Preview")); + + calendar = new QCalendarWidget; + calendar->setMinimumDate(QDate(1900, 1, 1)); + calendar->setMaximumDate(QDate(3000, 1, 1)); + calendar->setGridVisible(true); + + connect(calendar, SIGNAL(currentPageChanged(int, int)), + this, SLOT(reformatCalendarPage())); + + previewLayout = new QGridLayout; + previewLayout->addWidget(calendar, 0, 0, Qt::AlignCenter); + previewGroupBox->setLayout(previewLayout); +} +//! [9] + +//! [10] +void Window::createGeneralOptionsGroupBox() +{ + generalOptionsGroupBox = new QGroupBox(tr("General Options")); + + localeCombo = new QComboBox; + int curLocaleIndex = -1; + int index = 0; + for (int _lang = QLocale::C; _lang <= QLocale::LastLanguage; ++_lang) { + QLocale::Language lang = static_cast<QLocale::Language>(_lang); + QList<QLocale::Country> countries = QLocale::countriesForLanguage(lang); + for (int i = 0; i < countries.count(); ++i) { + QLocale::Country country = countries.at(i); + QString label = QLocale::languageToString(lang); + label += QLatin1Char('/'); + label += QLocale::countryToString(country); + QLocale locale(lang, country); + if (this->locale().language() == lang && this->locale().country() == country) + curLocaleIndex = index; + localeCombo->addItem(label, locale); + ++index; + } + } + if (curLocaleIndex != -1) + localeCombo->setCurrentIndex(curLocaleIndex); + localeLabel = new QLabel(tr("&Locale")); + localeLabel->setBuddy(localeCombo); + + firstDayCombo = new QComboBox; + firstDayCombo->addItem(tr("Sunday"), Qt::Sunday); + firstDayCombo->addItem(tr("Monday"), Qt::Monday); + firstDayCombo->addItem(tr("Tuesday"), Qt::Tuesday); + firstDayCombo->addItem(tr("Wednesday"), Qt::Wednesday); + firstDayCombo->addItem(tr("Thursday"), Qt::Thursday); + firstDayCombo->addItem(tr("Friday"), Qt::Friday); + firstDayCombo->addItem(tr("Saturday"), Qt::Saturday); + + firstDayLabel = new QLabel(tr("Wee&k starts on:")); + firstDayLabel->setBuddy(firstDayCombo); +//! [10] + + selectionModeCombo = new QComboBox; + selectionModeCombo->addItem(tr("Single selection"), + QCalendarWidget::SingleSelection); + selectionModeCombo->addItem(tr("None"), QCalendarWidget::NoSelection); + + selectionModeLabel = new QLabel(tr("&Selection mode:")); + selectionModeLabel->setBuddy(selectionModeCombo); + + gridCheckBox = new QCheckBox(tr("&Grid")); + gridCheckBox->setChecked(calendar->isGridVisible()); + + navigationCheckBox = new QCheckBox(tr("&Navigation bar")); + navigationCheckBox->setChecked(true); + + horizontalHeaderCombo = new QComboBox; + horizontalHeaderCombo->addItem(tr("Single letter day names"), + QCalendarWidget::SingleLetterDayNames); + horizontalHeaderCombo->addItem(tr("Short day names"), + QCalendarWidget::ShortDayNames); + horizontalHeaderCombo->addItem(tr("None"), + QCalendarWidget::NoHorizontalHeader); + horizontalHeaderCombo->setCurrentIndex(1); + + horizontalHeaderLabel = new QLabel(tr("&Horizontal header:")); + horizontalHeaderLabel->setBuddy(horizontalHeaderCombo); + + verticalHeaderCombo = new QComboBox; + verticalHeaderCombo->addItem(tr("ISO week numbers"), + QCalendarWidget::ISOWeekNumbers); + verticalHeaderCombo->addItem(tr("None"), QCalendarWidget::NoVerticalHeader); + + verticalHeaderLabel = new QLabel(tr("&Vertical header:")); + verticalHeaderLabel->setBuddy(verticalHeaderCombo); + +//! [11] + connect(localeCombo, SIGNAL(currentIndexChanged(int)), + this, SLOT(localeChanged(int))); + connect(firstDayCombo, SIGNAL(currentIndexChanged(int)), + this, SLOT(firstDayChanged(int))); + connect(selectionModeCombo, SIGNAL(currentIndexChanged(int)), + this, SLOT(selectionModeChanged(int))); + connect(gridCheckBox, SIGNAL(toggled(bool)), + calendar, SLOT(setGridVisible(bool))); + connect(navigationCheckBox, SIGNAL(toggled(bool)), + calendar, SLOT(setNavigationBarVisible(bool))); + connect(horizontalHeaderCombo, SIGNAL(currentIndexChanged(int)), + this, SLOT(horizontalHeaderChanged(int))); + connect(verticalHeaderCombo, SIGNAL(currentIndexChanged(int)), + this, SLOT(verticalHeaderChanged(int))); +//! [11] + + QHBoxLayout *checkBoxLayout = new QHBoxLayout; + checkBoxLayout->addWidget(gridCheckBox); + checkBoxLayout->addStretch(); + checkBoxLayout->addWidget(navigationCheckBox); + + QGridLayout *outerLayout = new QGridLayout; + outerLayout->addWidget(localeLabel, 0, 0); + outerLayout->addWidget(localeCombo, 0, 1); + outerLayout->addWidget(firstDayLabel, 1, 0); + outerLayout->addWidget(firstDayCombo, 1, 1); + outerLayout->addWidget(selectionModeLabel, 2, 0); + outerLayout->addWidget(selectionModeCombo, 2, 1); + outerLayout->addLayout(checkBoxLayout, 3, 0, 1, 2); + outerLayout->addWidget(horizontalHeaderLabel, 4, 0); + outerLayout->addWidget(horizontalHeaderCombo, 4, 1); + outerLayout->addWidget(verticalHeaderLabel, 5, 0); + outerLayout->addWidget(verticalHeaderCombo, 5, 1); + generalOptionsGroupBox->setLayout(outerLayout); + +//! [12] + firstDayChanged(firstDayCombo->currentIndex()); + selectionModeChanged(selectionModeCombo->currentIndex()); + horizontalHeaderChanged(horizontalHeaderCombo->currentIndex()); + verticalHeaderChanged(verticalHeaderCombo->currentIndex()); +} +//! [12] + +//! [13] +void Window::createDatesGroupBox() +{ + datesGroupBox = new QGroupBox(tr("Dates")); + + minimumDateEdit = new QDateEdit; + minimumDateEdit->setDisplayFormat("MMM d yyyy"); + minimumDateEdit->setDateRange(calendar->minimumDate(), + calendar->maximumDate()); + minimumDateEdit->setDate(calendar->minimumDate()); + + minimumDateLabel = new QLabel(tr("&Minimum Date:")); + minimumDateLabel->setBuddy(minimumDateEdit); + + currentDateEdit = new QDateEdit; + currentDateEdit->setDisplayFormat("MMM d yyyy"); + currentDateEdit->setDate(calendar->selectedDate()); + currentDateEdit->setDateRange(calendar->minimumDate(), + calendar->maximumDate()); + + currentDateLabel = new QLabel(tr("&Current Date:")); + currentDateLabel->setBuddy(currentDateEdit); + + maximumDateEdit = new QDateEdit; + maximumDateEdit->setDisplayFormat("MMM d yyyy"); + maximumDateEdit->setDateRange(calendar->minimumDate(), + calendar->maximumDate()); + maximumDateEdit->setDate(calendar->maximumDate()); + + maximumDateLabel = new QLabel(tr("Ma&ximum Date:")); + maximumDateLabel->setBuddy(maximumDateEdit); + +//! [13] //! [14] + connect(currentDateEdit, SIGNAL(dateChanged(const QDate &)), + calendar, SLOT(setSelectedDate(const QDate &))); + connect(calendar, SIGNAL(selectionChanged()), + this, SLOT(selectedDateChanged())); + connect(minimumDateEdit, SIGNAL(dateChanged(const QDate &)), + this, SLOT(minimumDateChanged(const QDate &))); + connect(maximumDateEdit, SIGNAL(dateChanged(const QDate &)), + this, SLOT(maximumDateChanged(const QDate &))); + +//! [14] + QGridLayout *dateBoxLayout = new QGridLayout; + dateBoxLayout->addWidget(currentDateLabel, 1, 0); + dateBoxLayout->addWidget(currentDateEdit, 1, 1); + dateBoxLayout->addWidget(minimumDateLabel, 0, 0); + dateBoxLayout->addWidget(minimumDateEdit, 0, 1); + dateBoxLayout->addWidget(maximumDateLabel, 2, 0); + dateBoxLayout->addWidget(maximumDateEdit, 2, 1); + dateBoxLayout->setRowStretch(3, 1); + + datesGroupBox->setLayout(dateBoxLayout); +//! [15] +} +//! [15] + +//! [16] +void Window::createTextFormatsGroupBox() +{ + textFormatsGroupBox = new QGroupBox(tr("Text Formats")); + + weekdayColorCombo = createColorComboBox(); + weekdayColorCombo->setCurrentIndex( + weekdayColorCombo->findText(tr("Black"))); + + weekdayColorLabel = new QLabel(tr("&Weekday color:")); + weekdayColorLabel->setBuddy(weekdayColorCombo); + + weekendColorCombo = createColorComboBox(); + weekendColorCombo->setCurrentIndex( + weekendColorCombo->findText(tr("Red"))); + + weekendColorLabel = new QLabel(tr("Week&end color:")); + weekendColorLabel->setBuddy(weekendColorCombo); + +//! [16] //! [17] + headerTextFormatCombo = new QComboBox; + headerTextFormatCombo->addItem(tr("Bold")); + headerTextFormatCombo->addItem(tr("Italic")); + headerTextFormatCombo->addItem(tr("Plain")); + + headerTextFormatLabel = new QLabel(tr("&Header text:")); + headerTextFormatLabel->setBuddy(headerTextFormatCombo); + + firstFridayCheckBox = new QCheckBox(tr("&First Friday in blue")); + + mayFirstCheckBox = new QCheckBox(tr("May &1 in red")); + +//! [17] //! [18] + connect(weekdayColorCombo, SIGNAL(currentIndexChanged(int)), + this, SLOT(weekdayFormatChanged())); + connect(weekendColorCombo, SIGNAL(currentIndexChanged(int)), + this, SLOT(weekendFormatChanged())); + connect(headerTextFormatCombo, SIGNAL(currentIndexChanged(const QString &)), + this, SLOT(reformatHeaders())); + connect(firstFridayCheckBox, SIGNAL(toggled(bool)), + this, SLOT(reformatCalendarPage())); + connect(mayFirstCheckBox, SIGNAL(toggled(bool)), + this, SLOT(reformatCalendarPage())); + +//! [18] + QHBoxLayout *checkBoxLayout = new QHBoxLayout; + checkBoxLayout->addWidget(firstFridayCheckBox); + checkBoxLayout->addStretch(); + checkBoxLayout->addWidget(mayFirstCheckBox); + + QGridLayout *outerLayout = new QGridLayout; + outerLayout->addWidget(weekdayColorLabel, 0, 0); + outerLayout->addWidget(weekdayColorCombo, 0, 1); + outerLayout->addWidget(weekendColorLabel, 1, 0); + outerLayout->addWidget(weekendColorCombo, 1, 1); + outerLayout->addWidget(headerTextFormatLabel, 2, 0); + outerLayout->addWidget(headerTextFormatCombo, 2, 1); + outerLayout->addLayout(checkBoxLayout, 3, 0, 1, 2); + textFormatsGroupBox->setLayout(outerLayout); + + weekdayFormatChanged(); + weekendFormatChanged(); +//! [19] + reformatHeaders(); + reformatCalendarPage(); +} +//! [19] + +//! [20] +QComboBox *Window::createColorComboBox() +{ + QComboBox *comboBox = new QComboBox; + comboBox->addItem(tr("Red"), Qt::red); + comboBox->addItem(tr("Blue"), Qt::blue); + comboBox->addItem(tr("Black"), Qt::black); + comboBox->addItem(tr("Magenta"), Qt::magenta); + return comboBox; +} +//! [20] diff --git a/examples/widgets/calendarwidget/window.h b/examples/widgets/calendarwidget/window.h new file mode 100644 index 0000000..a483cf5 --- /dev/null +++ b/examples/widgets/calendarwidget/window.h @@ -0,0 +1,128 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include <QWidget> + +QT_BEGIN_NAMESPACE +class QCalendarWidget; +class QCheckBox; +class QComboBox; +class QDate; +class QDateEdit; +class QGridLayout; +class QGroupBox; +class QLabel; +QT_END_NAMESPACE + +//! [0] +class Window : public QWidget +{ + Q_OBJECT + +public: + Window(); + +private slots: + void localeChanged(int index); + void firstDayChanged(int index); + void selectionModeChanged(int index); + void horizontalHeaderChanged(int index); + void verticalHeaderChanged(int index); + void selectedDateChanged(); + void minimumDateChanged(const QDate &date); + void maximumDateChanged(const QDate &date); + void weekdayFormatChanged(); + void weekendFormatChanged(); + void reformatHeaders(); + void reformatCalendarPage(); + +private: + void createPreviewGroupBox(); + void createGeneralOptionsGroupBox(); + void createDatesGroupBox(); + void createTextFormatsGroupBox(); + QComboBox *createColorComboBox(); + + QGroupBox *previewGroupBox; + QGridLayout *previewLayout; + QCalendarWidget *calendar; + + QGroupBox *generalOptionsGroupBox; + QLabel *localeLabel; + QLabel *firstDayLabel; +//! [0] + QLabel *selectionModeLabel; + QLabel *horizontalHeaderLabel; + QLabel *verticalHeaderLabel; + QComboBox *localeCombo; + QComboBox *firstDayCombo; + QComboBox *selectionModeCombo; + QCheckBox *gridCheckBox; + QCheckBox *navigationCheckBox; + QComboBox *horizontalHeaderCombo; + QComboBox *verticalHeaderCombo; + + QGroupBox *datesGroupBox; + QLabel *currentDateLabel; + QLabel *minimumDateLabel; + QLabel *maximumDateLabel; + QDateEdit *currentDateEdit; + QDateEdit *minimumDateEdit; + QDateEdit *maximumDateEdit; + + QGroupBox *textFormatsGroupBox; + QLabel *weekdayColorLabel; + QLabel *weekendColorLabel; + QLabel *headerTextFormatLabel; + QComboBox *weekdayColorCombo; + QComboBox *weekendColorCombo; + QComboBox *headerTextFormatCombo; + + QCheckBox *firstFridayCheckBox; +//! [1] + QCheckBox *mayFirstCheckBox; +}; +//! [1] + +#endif diff --git a/examples/widgets/charactermap/charactermap.pro b/examples/widgets/charactermap/charactermap.pro new file mode 100644 index 0000000..fe0733d --- /dev/null +++ b/examples/widgets/charactermap/charactermap.pro @@ -0,0 +1,11 @@ +HEADERS = characterwidget.h \ + mainwindow.h +SOURCES = characterwidget.cpp \ + mainwindow.cpp \ + main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/widgets/charactermap +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS charactermap.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/charactermap +INSTALLS += target sources diff --git a/examples/widgets/charactermap/characterwidget.cpp b/examples/widgets/charactermap/characterwidget.cpp new file mode 100644 index 0000000..3409169 --- /dev/null +++ b/examples/widgets/charactermap/characterwidget.cpp @@ -0,0 +1,178 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "characterwidget.h" + +//! [0] +CharacterWidget::CharacterWidget(QWidget *parent) + : QWidget(parent) +{ + squareSize = 24; + columns = 16; + lastKey = -1; + setMouseTracking(true); +} +//! [0] + +//! [1] +void CharacterWidget::updateFont(const QFont &font) +{ + displayFont.setFamily(font.family()); + squareSize = qMax(24, QFontMetrics(displayFont).xHeight() * 3); + adjustSize(); + update(); +} +//! [1] + +//! [2] +void CharacterWidget::updateSize(const QString &fontSize) +{ + displayFont.setPointSize(fontSize.toInt()); + squareSize = qMax(24, QFontMetrics(displayFont).xHeight() * 3); + adjustSize(); + update(); +} +//! [2] + +void CharacterWidget::updateStyle(const QString &fontStyle) +{ + QFontDatabase fontDatabase; + const QFont::StyleStrategy oldStrategy = displayFont.styleStrategy(); + displayFont = fontDatabase.font(displayFont.family(), fontStyle, displayFont.pointSize()); + displayFont.setStyleStrategy(oldStrategy); + squareSize = qMax(24, QFontMetrics(displayFont).xHeight() * 3); + adjustSize(); + update(); +} + +void CharacterWidget::updateFontMerging(bool enable) +{ + if (enable) + displayFont.setStyleStrategy(QFont::PreferDefault); + else + displayFont.setStyleStrategy(QFont::NoFontMerging); + adjustSize(); + update(); +} + +//! [3] +QSize CharacterWidget::sizeHint() const +{ + return QSize(columns*squareSize, (65536/columns)*squareSize); +} +//! [3] + +//! [4] +void CharacterWidget::mouseMoveEvent(QMouseEvent *event) +{ + QPoint widgetPosition = mapFromGlobal(event->globalPos()); + uint key = (widgetPosition.y()/squareSize)*columns + widgetPosition.x()/squareSize; + + QString text = QString::fromLatin1("<p>Character: <span style=\"font-size: 24pt; font-family: %1\">").arg(displayFont.family()) + + QChar(key) + + QString::fromLatin1("</span><p>Value: 0x") + + QString::number(key, 16); + QToolTip::showText(event->globalPos(), text, this); +} +//! [4] + +//! [5] +void CharacterWidget::mousePressEvent(QMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) { + lastKey = (event->y()/squareSize)*columns + event->x()/squareSize; + if (QChar(lastKey).category() != QChar::NoCategory) + emit characterSelected(QString(QChar(lastKey))); + update(); + } + else + QWidget::mousePressEvent(event); +} +//! [5] + +//! [6] +void CharacterWidget::paintEvent(QPaintEvent *event) +{ + QPainter painter(this); + painter.fillRect(event->rect(), QBrush(Qt::white)); + painter.setFont(displayFont); +//! [6] + +//! [7] + QRect redrawRect = event->rect(); + int beginRow = redrawRect.top()/squareSize; + int endRow = redrawRect.bottom()/squareSize; + int beginColumn = redrawRect.left()/squareSize; + int endColumn = redrawRect.right()/squareSize; +//! [7] + +//! [8] + painter.setPen(QPen(Qt::gray)); + for (int row = beginRow; row <= endRow; ++row) { + for (int column = beginColumn; column <= endColumn; ++column) { + painter.drawRect(column*squareSize, row*squareSize, squareSize, squareSize); + } +//! [8] //! [9] + } +//! [9] + +//! [10] + QFontMetrics fontMetrics(displayFont); + painter.setPen(QPen(Qt::black)); + for (int row = beginRow; row <= endRow; ++row) { + + for (int column = beginColumn; column <= endColumn; ++column) { + + int key = row*columns + column; + painter.setClipRect(column*squareSize, row*squareSize, squareSize, squareSize); + + if (key == lastKey) + painter.fillRect(column*squareSize + 1, row*squareSize + 1, squareSize, squareSize, QBrush(Qt::red)); + + painter.drawText(column*squareSize + (squareSize / 2) - fontMetrics.width(QChar(key))/2, + row*squareSize + 4 + fontMetrics.ascent(), + QString(QChar(key))); + } + } +} +//! [10] diff --git a/examples/widgets/charactermap/characterwidget.h b/examples/widgets/charactermap/characterwidget.h new file mode 100644 index 0000000..aa95963 --- /dev/null +++ b/examples/widgets/charactermap/characterwidget.h @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef CHARACTERWIDGET_H +#define CHARACTERWIDGET_H + +#include <QFont> +#include <QPoint> +#include <QSize> +#include <QString> +#include <QWidget> + +QT_BEGIN_NAMESPACE +class QMouseEvent; +class QPaintEvent; +QT_END_NAMESPACE + +//! [0] +class CharacterWidget : public QWidget +{ + Q_OBJECT + +public: + CharacterWidget(QWidget *parent = 0); + QSize sizeHint() const; + +public slots: + void updateFont(const QFont &font); + void updateSize(const QString &fontSize); + void updateStyle(const QString &fontStyle); + void updateFontMerging(bool enable); + +signals: + void characterSelected(const QString &character); + +protected: + void mouseMoveEvent(QMouseEvent *event); + void mousePressEvent(QMouseEvent *event); + void paintEvent(QPaintEvent *event); + +private: + QFont displayFont; + int columns; + int lastKey; + int squareSize; +}; +//! [0] + +#endif diff --git a/examples/widgets/charactermap/main.cpp b/examples/widgets/charactermap/main.cpp new file mode 100644 index 0000000..1d51376 --- /dev/null +++ b/examples/widgets/charactermap/main.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow window; + window.show(); + return app.exec(); +} diff --git a/examples/widgets/charactermap/mainwindow.cpp b/examples/widgets/charactermap/mainwindow.cpp new file mode 100644 index 0000000..a1e206b --- /dev/null +++ b/examples/widgets/charactermap/mainwindow.cpp @@ -0,0 +1,196 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "characterwidget.h" +#include "mainwindow.h" + +//! [0] +MainWindow::MainWindow() +{ + QWidget *centralWidget = new QWidget; + + QLabel *fontLabel = new QLabel(tr("Font:")); + fontCombo = new QFontComboBox; + QLabel *sizeLabel = new QLabel(tr("Size:")); + sizeCombo = new QComboBox; + QLabel *styleLabel = new QLabel(tr("Style:")); + styleCombo = new QComboBox; + QLabel *fontMergingLabel = new QLabel(tr("Automatic Font Merging:")); + fontMerging = new QCheckBox; + fontMerging->setChecked(true); + + scrollArea = new QScrollArea; + characterWidget = new CharacterWidget; + scrollArea->setWidget(characterWidget); +//! [0] + +//! [1] + findStyles(fontCombo->currentFont()); +//! [1] + findSizes(fontCombo->currentFont()); + +//! [2] + lineEdit = new QLineEdit; + QPushButton *clipboardButton = new QPushButton(tr("&To clipboard")); +//! [2] + +//! [3] + clipboard = QApplication::clipboard(); +//! [3] + +//! [4] + connect(fontCombo, SIGNAL(currentFontChanged(const QFont &)), + this, SLOT(findStyles(const QFont &))); + connect(fontCombo, SIGNAL(currentFontChanged(const QFont &)), + this, SLOT(findSizes(const QFont &))); + connect(fontCombo, SIGNAL(currentFontChanged(const QFont &)), + characterWidget, SLOT(updateFont(const QFont &))); + connect(sizeCombo, SIGNAL(currentIndexChanged(const QString &)), + characterWidget, SLOT(updateSize(const QString &))); + connect(styleCombo, SIGNAL(currentIndexChanged(const QString &)), + characterWidget, SLOT(updateStyle(const QString &))); +//! [4] //! [5] + connect(characterWidget, SIGNAL(characterSelected(const QString &)), + this, SLOT(insertCharacter(const QString &))); + connect(clipboardButton, SIGNAL(clicked()), this, SLOT(updateClipboard())); +//! [5] + connect(fontMerging, SIGNAL(toggled(bool)), characterWidget, SLOT(updateFontMerging(bool))); + +//! [6] + QHBoxLayout *controlsLayout = new QHBoxLayout; + controlsLayout->addWidget(fontLabel); + controlsLayout->addWidget(fontCombo, 1); + controlsLayout->addWidget(sizeLabel); + controlsLayout->addWidget(sizeCombo, 1); + controlsLayout->addWidget(styleLabel); + controlsLayout->addWidget(styleCombo, 1); + controlsLayout->addWidget(fontMergingLabel); + controlsLayout->addWidget(fontMerging, 1); + controlsLayout->addStretch(1); + + QHBoxLayout *lineLayout = new QHBoxLayout; + lineLayout->addWidget(lineEdit, 1); + lineLayout->addSpacing(12); + lineLayout->addWidget(clipboardButton); + + QVBoxLayout *centralLayout = new QVBoxLayout; + centralLayout->addLayout(controlsLayout); + centralLayout->addWidget(scrollArea, 1); + centralLayout->addSpacing(4); + centralLayout->addLayout(lineLayout); + centralWidget->setLayout(centralLayout); + + setCentralWidget(centralWidget); + setWindowTitle(tr("Character Map")); +} +//! [6] + +//! [7] +void MainWindow::findStyles(const QFont &font) +{ + QFontDatabase fontDatabase; + QString currentItem = styleCombo->currentText(); + styleCombo->clear(); +//! [7] + +//! [8] + QString style; + foreach (style, fontDatabase.styles(font.family())) + styleCombo->addItem(style); + + int styleIndex = styleCombo->findText(currentItem); + + if (styleIndex == -1) + styleCombo->setCurrentIndex(0); + else + styleCombo->setCurrentIndex(styleIndex); +} +//! [8] + +void MainWindow::findSizes(const QFont &font) +{ + QFontDatabase fontDatabase; + QString currentSize = sizeCombo->currentText(); + sizeCombo->blockSignals(true); + sizeCombo->clear(); + + int size; + if(fontDatabase.isSmoothlyScalable(font.family(), fontDatabase.styleString(font))) { + foreach(size, QFontDatabase::standardSizes()) { + sizeCombo->addItem(QVariant(size).toString()); + sizeCombo->setEditable(true); + } + + } else { + foreach(size, fontDatabase.smoothSizes(font.family(), fontDatabase.styleString(font))) { + sizeCombo->addItem(QVariant(size).toString()); + sizeCombo->setEditable(false); + } + } + + sizeCombo->blockSignals(false); + + int sizeIndex = sizeCombo->findText(currentSize); + + if(sizeIndex == -1) + sizeCombo->setCurrentIndex(qMax(0, sizeCombo->count() / 3)); + else + sizeCombo->setCurrentIndex(sizeIndex); +} + +//! [9] +void MainWindow::insertCharacter(const QString &character) +{ + lineEdit->insert(character); +} +//! [9] + +//! [10] +void MainWindow::updateClipboard() +{ +//! [11] + clipboard->setText(lineEdit->text(), QClipboard::Clipboard); +//! [11] + clipboard->setText(lineEdit->text(), QClipboard::Selection); +} +//! [10] diff --git a/examples/widgets/charactermap/mainwindow.h b/examples/widgets/charactermap/mainwindow.h new file mode 100644 index 0000000..3f3208c --- /dev/null +++ b/examples/widgets/charactermap/mainwindow.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include <QMainWindow> +#include <QString> + +QT_BEGIN_NAMESPACE +class QClipboard; +class QComboBox; +class QFontComboBox; +class QLineEdit; +class QScrollArea; +class QCheckBox; +QT_END_NAMESPACE +class CharacterWidget; + +//! [0] +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +public slots: + void findStyles(const QFont &font); + void findSizes(const QFont &font); + void insertCharacter(const QString &character); + void updateClipboard(); + +private: + CharacterWidget *characterWidget; + QClipboard *clipboard; + QComboBox *styleCombo; + QComboBox *sizeCombo; + QFontComboBox *fontCombo; + QLineEdit *lineEdit; + QScrollArea *scrollArea; + QCheckBox *fontMerging; +}; +//! [0] + +#endif diff --git a/examples/widgets/codeeditor/codeeditor.cpp b/examples/widgets/codeeditor/codeeditor.cpp new file mode 100644 index 0000000..b855c7a --- /dev/null +++ b/examples/widgets/codeeditor/codeeditor.cpp @@ -0,0 +1,171 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include <codeeditor.h> + +//![constructor] + +CodeEditor::CodeEditor(QWidget *parent) : QPlainTextEdit(parent) +{ + lineNumberArea = new LineNumberArea(this); + + connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int))); + connect(this, SIGNAL(updateRequest(const QRect &, int)), this, SLOT(updateLineNumberArea(const QRect &, int))); + connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine())); + + updateLineNumberAreaWidth(0); + highlightCurrentLine(); +} + +//![constructor] + +//![extraAreaWidth] + +int CodeEditor::lineNumberAreaWidth() +{ + int digits = 1; + int max = qMax(1, blockCount()); + while (max >= 10) { + max /= 10; + ++digits; + } + + int space = 3 + fontMetrics().width(QLatin1Char('9')) * digits; + + return space; +} + +//![extraAreaWidth] + +//![slotUpdateExtraAreaWidth] + +void CodeEditor::updateLineNumberAreaWidth(int /* newBlockCount */) +{ + setViewportMargins(lineNumberAreaWidth(), 0, 0, 0); +} + +//![slotUpdateExtraAreaWidth] + +//![slotUpdateRequest] + +void CodeEditor::updateLineNumberArea(const QRect &rect, int dy) +{ + if (dy) + lineNumberArea->scroll(0, dy); + else + lineNumberArea->update(0, rect.y(), lineNumberArea->width(), rect.height()); + + if (rect.contains(viewport()->rect())) + updateLineNumberAreaWidth(0); +} + +//![slotUpdateRequest] + +//![resizeEvent] + +void CodeEditor::resizeEvent(QResizeEvent *e) +{ + QPlainTextEdit::resizeEvent(e); + + QRect cr = contentsRect(); + lineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height())); +} + +//![resizeEvent] + +//![cursorPositionChanged] + +void CodeEditor::highlightCurrentLine() +{ + QList<QTextEdit::ExtraSelection> extraSelections; + + if (!isReadOnly()) { + QTextEdit::ExtraSelection selection; + + QColor lineColor = QColor(Qt::yellow).lighter(160); + + selection.format.setBackground(lineColor); + selection.format.setProperty(QTextFormat::FullWidthSelection, true); + selection.cursor = textCursor(); + selection.cursor.clearSelection(); + extraSelections.append(selection); + } + + setExtraSelections(extraSelections); +} + +//![cursorPositionChanged] + +//![extraAreaPaintEvent_0] + +void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event) +{ + QPainter painter(lineNumberArea); + painter.fillRect(event->rect(), Qt::lightGray); + +//![extraAreaPaintEvent_0] + +//![extraAreaPaintEvent_1] + QTextBlock block = firstVisibleBlock(); + int blockNumber = block.blockNumber(); + int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top(); + int bottom = top + (int) blockBoundingRect(block).height(); +//![extraAreaPaintEvent_1] + +//![extraAreaPaintEvent_2] + while (block.isValid() && top <= event->rect().bottom()) { + if (block.isVisible() && bottom >= event->rect().top()) { + QString number = QString::number(blockNumber + 1); + painter.setPen(Qt::black); + painter.drawText(0, top, lineNumberArea->width(), fontMetrics().height(), + Qt::AlignRight, number); + } + + block = block.next(); + top = bottom; + bottom = top + (int) blockBoundingRect(block).height(); + ++blockNumber; + } +} +//![extraAreaPaintEvent_2] + diff --git a/examples/widgets/codeeditor/codeeditor.h b/examples/widgets/codeeditor/codeeditor.h new file mode 100644 index 0000000..51ecf11 --- /dev/null +++ b/examples/widgets/codeeditor/codeeditor.h @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef CODEEDITOR_H +#define CODEEDITOR_H + +#include <QPlainTextEdit> +#include <QObject> + +QT_BEGIN_NAMESPACE +class QPaintEvent; +class QResizeEvent; +class QSize; +class QWidget; +QT_END_NAMESPACE + +class LineNumberArea; + +//![codeeditordefinition] + +class CodeEditor : public QPlainTextEdit +{ + Q_OBJECT + +public: + CodeEditor(QWidget *parent = 0); + + void lineNumberAreaPaintEvent(QPaintEvent *event); + int lineNumberAreaWidth(); + +protected: + void resizeEvent(QResizeEvent *event); + +private slots: + void updateLineNumberAreaWidth(int newBlockCount); + void highlightCurrentLine(); + void updateLineNumberArea(const QRect &, int); + +private: + QWidget *lineNumberArea; +}; + +//![codeeditordefinition] +//![extraarea] + +class LineNumberArea : public QWidget +{ +public: + LineNumberArea(CodeEditor *editor) : QWidget(editor) { + codeEditor = editor; + } + + QSize sizeHint() const { + return QSize(codeEditor->lineNumberAreaWidth(), 0); + } + +protected: + void paintEvent(QPaintEvent *event) { + codeEditor->lineNumberAreaPaintEvent(event); + } + +private: + CodeEditor *codeEditor; +}; + +//![extraarea] + +#endif diff --git a/examples/widgets/codeeditor/codeeditor.pro b/examples/widgets/codeeditor/codeeditor.pro new file mode 100644 index 0000000..a94a5e0 --- /dev/null +++ b/examples/widgets/codeeditor/codeeditor.pro @@ -0,0 +1,9 @@ +HEADERS = codeeditor.h +SOURCES = main.cpp \ + codeeditor.cpp +# install +target.path = $$[QT_INSTALL_EXAMPLES]/widgets/codeeditor +sources.files = $$SOURCES $$HEADERS *.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/codeeditor +INSTALLS += target sources + diff --git a/examples/widgets/codeeditor/main.cpp b/examples/widgets/codeeditor/main.cpp new file mode 100644 index 0000000..a8b26c9 --- /dev/null +++ b/examples/widgets/codeeditor/main.cpp @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "codeeditor.h" + +int main(int argv, char **args) +{ + QApplication app(argv, args); + + CodeEditor editor; + editor.setWindowTitle(QObject::tr("Code Editor Example")); + editor.show(); + + return app.exec(); +} + diff --git a/examples/widgets/digitalclock/digitalclock.cpp b/examples/widgets/digitalclock/digitalclock.cpp new file mode 100644 index 0000000..5bc9292 --- /dev/null +++ b/examples/widgets/digitalclock/digitalclock.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "digitalclock.h" + +//! [0] +DigitalClock::DigitalClock(QWidget *parent) + : QLCDNumber(parent) +{ + setSegmentStyle(Filled); + + QTimer *timer = new QTimer(this); + connect(timer, SIGNAL(timeout()), this, SLOT(showTime())); + timer->start(1000); + + showTime(); + + setWindowTitle(tr("Digital Clock")); + resize(150, 60); +} +//! [0] + +//! [1] +void DigitalClock::showTime() +//! [1] //! [2] +{ + QTime time = QTime::currentTime(); + QString text = time.toString("hh:mm"); + if ((time.second() % 2) == 0) + text[2] = ' '; + display(text); +} +//! [2] diff --git a/examples/widgets/digitalclock/digitalclock.h b/examples/widgets/digitalclock/digitalclock.h new file mode 100644 index 0000000..4bf26bc --- /dev/null +++ b/examples/widgets/digitalclock/digitalclock.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef DIGITALCLOCK_H +#define DIGITALCLOCK_H + +#include <QLCDNumber> + +//! [0] +class DigitalClock : public QLCDNumber +{ + Q_OBJECT + +public: + DigitalClock(QWidget *parent = 0); + +private slots: + void showTime(); +}; +//! [0] + +#endif diff --git a/examples/widgets/digitalclock/digitalclock.pro b/examples/widgets/digitalclock/digitalclock.pro new file mode 100644 index 0000000..b87b4a0 --- /dev/null +++ b/examples/widgets/digitalclock/digitalclock.pro @@ -0,0 +1,9 @@ +HEADERS = digitalclock.h +SOURCES = digitalclock.cpp \ + main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/widgets/digitalclock +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS digitalclock.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/digitalclock +INSTALLS += target sources diff --git a/examples/widgets/digitalclock/main.cpp b/examples/widgets/digitalclock/main.cpp new file mode 100644 index 0000000..9e7e16d --- /dev/null +++ b/examples/widgets/digitalclock/main.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> + +#include "digitalclock.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + DigitalClock clock; + clock.show(); + return app.exec(); +} diff --git a/examples/widgets/groupbox/groupbox.pro b/examples/widgets/groupbox/groupbox.pro new file mode 100644 index 0000000..7175f66 --- /dev/null +++ b/examples/widgets/groupbox/groupbox.pro @@ -0,0 +1,9 @@ +HEADERS = window.h +SOURCES = window.cpp \ + main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/widgets/groupbox +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS groupbox.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/groupbox +INSTALLS += target sources diff --git a/examples/widgets/groupbox/main.cpp b/examples/widgets/groupbox/main.cpp new file mode 100644 index 0000000..fa8b0ab --- /dev/null +++ b/examples/widgets/groupbox/main.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> + +#include "window.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + Window window; + window.show(); + return app.exec(); +} diff --git a/examples/widgets/groupbox/window.cpp b/examples/widgets/groupbox/window.cpp new file mode 100644 index 0000000..8acc307 --- /dev/null +++ b/examples/widgets/groupbox/window.cpp @@ -0,0 +1,190 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "window.h" + +//! [0] +Window::Window(QWidget *parent) + : QWidget(parent) +{ + QGridLayout *grid = new QGridLayout; + grid->addWidget(createFirstExclusiveGroup(), 0, 0); + grid->addWidget(createSecondExclusiveGroup(), 1, 0); + grid->addWidget(createNonExclusiveGroup(), 0, 1); + grid->addWidget(createPushButtonGroup(), 1, 1); + setLayout(grid); + + setWindowTitle(tr("Group Boxes")); + resize(480, 320); +} +//! [0] + +//! [1] +QGroupBox *Window::createFirstExclusiveGroup() +{ +//! [2] + QGroupBox *groupBox = new QGroupBox(tr("Exclusive Radio Buttons")); + + QRadioButton *radio1 = new QRadioButton(tr("&Radio button 1")); + QRadioButton *radio2 = new QRadioButton(tr("R&adio button 2")); + QRadioButton *radio3 = new QRadioButton(tr("Ra&dio button 3")); + + radio1->setChecked(true); +//! [1] //! [3] + + QVBoxLayout *vbox = new QVBoxLayout; + vbox->addWidget(radio1); + vbox->addWidget(radio2); + vbox->addWidget(radio3); + vbox->addStretch(1); + groupBox->setLayout(vbox); +//! [2] + + return groupBox; +} +//! [3] + +//! [4] +QGroupBox *Window::createSecondExclusiveGroup() +{ + QGroupBox *groupBox = new QGroupBox(tr("E&xclusive Radio Buttons")); + groupBox->setCheckable(true); + groupBox->setChecked(false); +//! [4] + +//! [5] + QRadioButton *radio1 = new QRadioButton(tr("Rad&io button 1")); + QRadioButton *radio2 = new QRadioButton(tr("Radi&o button 2")); + QRadioButton *radio3 = new QRadioButton(tr("Radio &button 3")); + radio1->setChecked(true); + QCheckBox *checkBox = new QCheckBox(tr("Ind&ependent checkbox")); + checkBox->setChecked(true); +//! [5] + +//! [6] + QVBoxLayout *vbox = new QVBoxLayout; + vbox->addWidget(radio1); + vbox->addWidget(radio2); + vbox->addWidget(radio3); + vbox->addWidget(checkBox); + vbox->addStretch(1); + groupBox->setLayout(vbox); + + return groupBox; +} +//! [6] + +//! [7] +QGroupBox *Window::createNonExclusiveGroup() +{ + QGroupBox *groupBox = new QGroupBox(tr("Non-Exclusive Checkboxes")); + groupBox->setFlat(true); +//! [7] + +//! [8] + QCheckBox *checkBox1 = new QCheckBox(tr("&Checkbox 1")); + QCheckBox *checkBox2 = new QCheckBox(tr("C&heckbox 2")); + checkBox2->setChecked(true); + QCheckBox *tristateBox = new QCheckBox(tr("Tri-&state button")); + tristateBox->setTristate(true); +//! [8] + tristateBox->setCheckState(Qt::PartiallyChecked); + +//! [9] + QVBoxLayout *vbox = new QVBoxLayout; + vbox->addWidget(checkBox1); + vbox->addWidget(checkBox2); + vbox->addWidget(tristateBox); + vbox->addStretch(1); + groupBox->setLayout(vbox); + + return groupBox; +} +//! [9] + +//! [10] +QGroupBox *Window::createPushButtonGroup() +{ + QGroupBox *groupBox = new QGroupBox(tr("&Push Buttons")); + groupBox->setCheckable(true); + groupBox->setChecked(true); +//! [10] + +//! [11] + QPushButton *pushButton = new QPushButton(tr("&Normal Button")); + QPushButton *toggleButton = new QPushButton(tr("&Toggle Button")); + toggleButton->setCheckable(true); + toggleButton->setChecked(true); + QPushButton *flatButton = new QPushButton(tr("&Flat Button")); + flatButton->setFlat(true); +//! [11] + +//! [12] + QPushButton *popupButton = new QPushButton(tr("Pop&up Button")); + QMenu *menu = new QMenu(this); + menu->addAction(tr("&First Item")); + menu->addAction(tr("&Second Item")); + menu->addAction(tr("&Third Item")); + menu->addAction(tr("F&ourth Item")); + popupButton->setMenu(menu); +//! [12] + + QAction *newAction = menu->addAction(tr("Submenu")); + QMenu *subMenu = new QMenu(tr("Popup Submenu")); + subMenu->addAction(tr("Item 1")); + subMenu->addAction(tr("Item 2")); + subMenu->addAction(tr("Item 3")); + newAction->setMenu(subMenu); + +//! [13] + QVBoxLayout *vbox = new QVBoxLayout; + vbox->addWidget(pushButton); + vbox->addWidget(toggleButton); + vbox->addWidget(flatButton); + vbox->addWidget(popupButton); + vbox->addStretch(1); + groupBox->setLayout(vbox); + + return groupBox; +} +//! [13] diff --git a/examples/widgets/groupbox/window.h b/examples/widgets/groupbox/window.h new file mode 100644 index 0000000..9f196fd --- /dev/null +++ b/examples/widgets/groupbox/window.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include <QWidget> + +QT_BEGIN_NAMESPACE +class QGroupBox; +QT_END_NAMESPACE + +//! [0] +class Window : public QWidget +{ + Q_OBJECT + +public: + Window(QWidget *parent = 0); + +private: + QGroupBox *createFirstExclusiveGroup(); + QGroupBox *createSecondExclusiveGroup(); + QGroupBox *createNonExclusiveGroup(); + QGroupBox *createPushButtonGroup(); +}; +//! [0] + +#endif diff --git a/examples/widgets/icons/iconpreviewarea.cpp b/examples/widgets/icons/iconpreviewarea.cpp new file mode 100644 index 0000000..d80d41d --- /dev/null +++ b/examples/widgets/icons/iconpreviewarea.cpp @@ -0,0 +1,142 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "iconpreviewarea.h" + +//! [0] +IconPreviewArea::IconPreviewArea(QWidget *parent) + : QWidget(parent) +{ + QGridLayout *mainLayout = new QGridLayout; + setLayout(mainLayout); + + stateLabels[0] = createHeaderLabel(tr("Off")); + stateLabels[1] = createHeaderLabel(tr("On")); + Q_ASSERT(NumStates == 2); + + modeLabels[0] = createHeaderLabel(tr("Normal")); + modeLabels[1] = createHeaderLabel(tr("Active")); + modeLabels[2] = createHeaderLabel(tr("Disabled")); + modeLabels[3] = createHeaderLabel(tr("Selected")); + Q_ASSERT(NumModes == 4); + + for (int j = 0; j < NumStates; ++j) + mainLayout->addWidget(stateLabels[j], j + 1, 0); + + for (int i = 0; i < NumModes; ++i) { + mainLayout->addWidget(modeLabels[i], 0, i + 1); + + for (int j = 0; j < NumStates; ++j) { + pixmapLabels[i][j] = createPixmapLabel(); + mainLayout->addWidget(pixmapLabels[i][j], j + 1, i + 1); + } + } +} +//! [0] + +//! [1] +void IconPreviewArea::setIcon(const QIcon &icon) +{ + this->icon = icon; + updatePixmapLabels(); +} +//! [1] + +//! [2] +void IconPreviewArea::setSize(const QSize &size) +{ + if (size != this->size) { + this->size = size; + updatePixmapLabels(); + } +} +//! [2] + +//! [3] +QLabel *IconPreviewArea::createHeaderLabel(const QString &text) +{ + QLabel *label = new QLabel(tr("<b>%1</b>").arg(text)); + label->setAlignment(Qt::AlignCenter); + return label; +} +//! [3] + +//! [4] +QLabel *IconPreviewArea::createPixmapLabel() +{ + QLabel *label = new QLabel; + label->setEnabled(false); + label->setAlignment(Qt::AlignCenter); + label->setFrameShape(QFrame::Box); + label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + label->setBackgroundRole(QPalette::Base); + label->setAutoFillBackground(true); + label->setMinimumSize(132, 132); + return label; +} +//! [4] + +//! [5] +void IconPreviewArea::updatePixmapLabels() +{ + for (int i = 0; i < NumModes; ++i) { + QIcon::Mode mode; + if (i == 0) { + mode = QIcon::Normal; + } else if (i == 1) { + mode = QIcon::Active; + } else if (i == 2) { + mode = QIcon::Disabled; + } else { + mode = QIcon::Selected; + } + + for (int j = 0; j < NumStates; ++j) { + QIcon::State state = (j == 0) ? QIcon::Off : QIcon::On; + QPixmap pixmap = icon.pixmap(size, mode, state); + pixmapLabels[i][j]->setPixmap(pixmap); + pixmapLabels[i][j]->setEnabled(!pixmap.isNull()); + } + } +} +//! [5] diff --git a/examples/widgets/icons/iconpreviewarea.h b/examples/widgets/icons/iconpreviewarea.h new file mode 100644 index 0000000..9b915a4 --- /dev/null +++ b/examples/widgets/icons/iconpreviewarea.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ICONPREVIEWAREA_H +#define ICONPREVIEWAREA_H + +#include <QIcon> +#include <QWidget> + +QT_BEGIN_NAMESPACE +class QLabel; +QT_END_NAMESPACE + +//! [0] +class IconPreviewArea : public QWidget +{ + Q_OBJECT + +public: + IconPreviewArea(QWidget *parent = 0); + + void setIcon(const QIcon &icon); + void setSize(const QSize &size); + +private: + QLabel *createHeaderLabel(const QString &text); + QLabel *createPixmapLabel(); + void updatePixmapLabels(); + + enum { NumModes = 4, NumStates = 2 }; + + QIcon icon; + QSize size; + QLabel *stateLabels[NumStates]; + QLabel *modeLabels[NumModes]; + QLabel *pixmapLabels[NumModes][NumStates]; +}; +//! [0] + +#endif diff --git a/examples/widgets/icons/icons.pro b/examples/widgets/icons/icons.pro new file mode 100644 index 0000000..3b432d9 --- /dev/null +++ b/examples/widgets/icons/icons.pro @@ -0,0 +1,25 @@ +HEADERS = iconpreviewarea.h \ + iconsizespinbox.h \ + imagedelegate.h \ + mainwindow.h +SOURCES = iconpreviewarea.cpp \ + iconsizespinbox.cpp \ + imagedelegate.cpp \ + main.cpp \ + mainwindow.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/widgets/icons +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS icons.pro images +sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/icons +INSTALLS += target sources + +wince*: { + imageFiles.sources = images/* + wincewm*: { + imageFiles.path = "/My Documents/My Pictures" + } else { + imageFiles.path = images + } + DEPLOYMENT += imageFiles +} diff --git a/examples/widgets/icons/iconsizespinbox.cpp b/examples/widgets/icons/iconsizespinbox.cpp new file mode 100644 index 0000000..22f45e9 --- /dev/null +++ b/examples/widgets/icons/iconsizespinbox.cpp @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "iconsizespinbox.h" + +//! [0] +IconSizeSpinBox::IconSizeSpinBox(QWidget *parent) + : QSpinBox(parent) +{ +} +//! [0] + +//! [1] +int IconSizeSpinBox::valueFromText(const QString &text) const +{ + QRegExp regExp(tr("(\\d+)(\\s*[xx]\\s*\\d+)?")); + + if (regExp.exactMatch(text)) { + return regExp.cap(1).toInt(); + } else { + return 0; + } +} +//! [1] + +//! [2] +QString IconSizeSpinBox::textFromValue(int value) const +{ + return tr("%1 x %1").arg(value); +} +//! [2] diff --git a/examples/widgets/icons/iconsizespinbox.h b/examples/widgets/icons/iconsizespinbox.h new file mode 100644 index 0000000..ea84dc7 --- /dev/null +++ b/examples/widgets/icons/iconsizespinbox.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ICONSIZESPINBOX_H +#define ICONSIZESPINBOX_H + +#include <QSpinBox> + +//! [0] +class IconSizeSpinBox : public QSpinBox +{ + Q_OBJECT + +public: + IconSizeSpinBox(QWidget *parent = 0); + + int valueFromText(const QString &text) const; + QString textFromValue(int value) const; +}; +//! [0] + +#endif diff --git a/examples/widgets/icons/imagedelegate.cpp b/examples/widgets/icons/imagedelegate.cpp new file mode 100644 index 0000000..e8e79b3 --- /dev/null +++ b/examples/widgets/icons/imagedelegate.cpp @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "imagedelegate.h" + +//! [0] +ImageDelegate::ImageDelegate(QObject *parent) + : QItemDelegate(parent) +{ +} +//! [0] + +//! [1] +QWidget *ImageDelegate::createEditor(QWidget *parent, + const QStyleOptionViewItem & /* option */, + const QModelIndex &index) const +{ + QComboBox *comboBox = new QComboBox(parent); + if (index.column() == 1) { + comboBox->addItem(tr("Normal")); + comboBox->addItem(tr("Active")); + comboBox->addItem(tr("Disabled")); + comboBox->addItem(tr("Selected")); + } else if (index.column() == 2) { + comboBox->addItem(tr("Off")); + comboBox->addItem(tr("On")); + } + + connect(comboBox, SIGNAL(activated(int)), this, SLOT(emitCommitData())); + + return comboBox; +} +//! [1] + +//! [2] +void ImageDelegate::setEditorData(QWidget *editor, + const QModelIndex &index) const +{ + QComboBox *comboBox = qobject_cast<QComboBox *>(editor); + if (!comboBox) + return; + + int pos = comboBox->findText(index.model()->data(index).toString(), + Qt::MatchExactly); + comboBox->setCurrentIndex(pos); +} +//! [2] + +//! [3] +void ImageDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, + const QModelIndex &index) const +{ + QComboBox *comboBox = qobject_cast<QComboBox *>(editor); + if (!comboBox) + return; + + model->setData(index, comboBox->currentText()); +} +//! [3] + +//! [4] +void ImageDelegate::emitCommitData() +{ + emit commitData(qobject_cast<QWidget *>(sender())); +} +//! [4] diff --git a/examples/widgets/icons/imagedelegate.h b/examples/widgets/icons/imagedelegate.h new file mode 100644 index 0000000..638c0eb --- /dev/null +++ b/examples/widgets/icons/imagedelegate.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef IMAGEDELEGATE_H +#define IMAGEDELEGATE_H + +#include <QItemDelegate> + +//! [0] +class ImageDelegate : public QItemDelegate +{ + Q_OBJECT + +public: + ImageDelegate(QObject *parent = 0); +//! [0] + +//! [1] + QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, + const QModelIndex &index) const; + void setEditorData(QWidget *editor, const QModelIndex &index) const; + void setModelData(QWidget *editor, QAbstractItemModel *model, + const QModelIndex &index) const; + +//! [1] //! [2] +private slots: + void emitCommitData(); +}; +//! [2] + +#endif diff --git a/examples/widgets/icons/images/designer.png b/examples/widgets/icons/images/designer.png Binary files differnew file mode 100644 index 0000000..0988fce --- /dev/null +++ b/examples/widgets/icons/images/designer.png diff --git a/examples/widgets/icons/images/find_disabled.png b/examples/widgets/icons/images/find_disabled.png Binary files differnew file mode 100644 index 0000000..e85e33f --- /dev/null +++ b/examples/widgets/icons/images/find_disabled.png diff --git a/examples/widgets/icons/images/find_normal.png b/examples/widgets/icons/images/find_normal.png Binary files differnew file mode 100644 index 0000000..728c27f --- /dev/null +++ b/examples/widgets/icons/images/find_normal.png diff --git a/examples/widgets/icons/images/monkey_off_128x128.png b/examples/widgets/icons/images/monkey_off_128x128.png Binary files differnew file mode 100644 index 0000000..f878267 --- /dev/null +++ b/examples/widgets/icons/images/monkey_off_128x128.png diff --git a/examples/widgets/icons/images/monkey_off_16x16.png b/examples/widgets/icons/images/monkey_off_16x16.png Binary files differnew file mode 100644 index 0000000..0ac57d7 --- /dev/null +++ b/examples/widgets/icons/images/monkey_off_16x16.png diff --git a/examples/widgets/icons/images/monkey_off_32x32.png b/examples/widgets/icons/images/monkey_off_32x32.png Binary files differnew file mode 100644 index 0000000..1f7fab6 --- /dev/null +++ b/examples/widgets/icons/images/monkey_off_32x32.png diff --git a/examples/widgets/icons/images/monkey_off_64x64.png b/examples/widgets/icons/images/monkey_off_64x64.png Binary files differnew file mode 100644 index 0000000..47d8f6d --- /dev/null +++ b/examples/widgets/icons/images/monkey_off_64x64.png diff --git a/examples/widgets/icons/images/monkey_on_128x128.png b/examples/widgets/icons/images/monkey_on_128x128.png Binary files differnew file mode 100644 index 0000000..8e1c746 --- /dev/null +++ b/examples/widgets/icons/images/monkey_on_128x128.png diff --git a/examples/widgets/icons/images/monkey_on_16x16.png b/examples/widgets/icons/images/monkey_on_16x16.png Binary files differnew file mode 100644 index 0000000..082e852 --- /dev/null +++ b/examples/widgets/icons/images/monkey_on_16x16.png diff --git a/examples/widgets/icons/images/monkey_on_32x32.png b/examples/widgets/icons/images/monkey_on_32x32.png Binary files differnew file mode 100644 index 0000000..bf9acc6 --- /dev/null +++ b/examples/widgets/icons/images/monkey_on_32x32.png diff --git a/examples/widgets/icons/images/monkey_on_64x64.png b/examples/widgets/icons/images/monkey_on_64x64.png Binary files differnew file mode 100644 index 0000000..990f604 --- /dev/null +++ b/examples/widgets/icons/images/monkey_on_64x64.png diff --git a/examples/widgets/icons/images/qt_extended_16x16.png b/examples/widgets/icons/images/qt_extended_16x16.png Binary files differnew file mode 100644 index 0000000..95d3bae --- /dev/null +++ b/examples/widgets/icons/images/qt_extended_16x16.png diff --git a/examples/widgets/icons/images/qt_extended_32x32.png b/examples/widgets/icons/images/qt_extended_32x32.png Binary files differnew file mode 100644 index 0000000..7b7a790 --- /dev/null +++ b/examples/widgets/icons/images/qt_extended_32x32.png diff --git a/examples/widgets/icons/images/qt_extended_48x48.png b/examples/widgets/icons/images/qt_extended_48x48.png Binary files differnew file mode 100644 index 0000000..8434dc2 --- /dev/null +++ b/examples/widgets/icons/images/qt_extended_48x48.png diff --git a/examples/widgets/icons/main.cpp b/examples/widgets/icons/main.cpp new file mode 100644 index 0000000..4856752 --- /dev/null +++ b/examples/widgets/icons/main.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow mainWin; + mainWin.show(); + return app.exec(); +} diff --git a/examples/widgets/icons/mainwindow.cpp b/examples/widgets/icons/mainwindow.cpp new file mode 100644 index 0000000..00ce8b0 --- /dev/null +++ b/examples/widgets/icons/mainwindow.cpp @@ -0,0 +1,443 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "iconpreviewarea.h" +#include "iconsizespinbox.h" +#include "imagedelegate.h" +#include "mainwindow.h" + +//! [0] +MainWindow::MainWindow() +{ + centralWidget = new QWidget; + setCentralWidget(centralWidget); + + createPreviewGroupBox(); + createImagesGroupBox(); + createIconSizeGroupBox(); + + createActions(); + createMenus(); + createContextMenu(); + + QGridLayout *mainLayout = new QGridLayout; + mainLayout->addWidget(previewGroupBox, 0, 0, 1, 2); + mainLayout->addWidget(imagesGroupBox, 1, 0); + mainLayout->addWidget(iconSizeGroupBox, 1, 1); + centralWidget->setLayout(mainLayout); + + setWindowTitle(tr("Icons")); + checkCurrentStyle(); + otherRadioButton->click(); + + resize(minimumSizeHint()); +} +//! [0] + +//! [1] +void MainWindow::about() +{ + QMessageBox::about(this, tr("About Icons"), + tr("The <b>Icons</b> example illustrates how Qt renders an icon in " + "different modes (active, normal, disabled, and selected) and " + "states (on and off) based on a set of images.")); +} +//! [1] + +//! [2] +void MainWindow::changeStyle(bool checked) +{ + if (!checked) + return; + + QAction *action = qobject_cast<QAction *>(sender()); +//! [2] //! [3] + QStyle *style = QStyleFactory::create(action->data().toString()); +//! [3] //! [4] + Q_ASSERT(style); + QApplication::setStyle(style); + + smallRadioButton->setText(tr("Small (%1 x %1)") + .arg(style->pixelMetric(QStyle::PM_SmallIconSize))); + largeRadioButton->setText(tr("Large (%1 x %1)") + .arg(style->pixelMetric(QStyle::PM_LargeIconSize))); + toolBarRadioButton->setText(tr("Toolbars (%1 x %1)") + .arg(style->pixelMetric(QStyle::PM_ToolBarIconSize))); + listViewRadioButton->setText(tr("List views (%1 x %1)") + .arg(style->pixelMetric(QStyle::PM_ListViewIconSize))); + iconViewRadioButton->setText(tr("Icon views (%1 x %1)") + .arg(style->pixelMetric(QStyle::PM_IconViewIconSize))); + tabBarRadioButton->setText(tr("Tab bars (%1 x %1)") + .arg(style->pixelMetric(QStyle::PM_TabBarIconSize))); + + changeSize(); +} +//! [4] + +//! [5] +void MainWindow::changeSize(bool checked) +{ + if (!checked) + return; + + int extent; + + if (otherRadioButton->isChecked()) { + extent = otherSpinBox->value(); + } else { + QStyle::PixelMetric metric; + + if (smallRadioButton->isChecked()) { + metric = QStyle::PM_SmallIconSize; + } else if (largeRadioButton->isChecked()) { + metric = QStyle::PM_LargeIconSize; + } else if (toolBarRadioButton->isChecked()) { + metric = QStyle::PM_ToolBarIconSize; + } else if (listViewRadioButton->isChecked()) { + metric = QStyle::PM_ListViewIconSize; + } else if (iconViewRadioButton->isChecked()) { + metric = QStyle::PM_IconViewIconSize; + } else { + metric = QStyle::PM_TabBarIconSize; + } + extent = QApplication::style()->pixelMetric(metric); + } + previewArea->setSize(QSize(extent, extent)); + otherSpinBox->setEnabled(otherRadioButton->isChecked()); +} +//! [5] + +//! [6] +void MainWindow::changeIcon() +{ + QIcon icon; + + for (int row = 0; row < imagesTable->rowCount(); ++row) { + QTableWidgetItem *item0 = imagesTable->item(row, 0); + QTableWidgetItem *item1 = imagesTable->item(row, 1); + QTableWidgetItem *item2 = imagesTable->item(row, 2); + + if (item0->checkState() == Qt::Checked) { + QIcon::Mode mode; + if (item1->text() == tr("Normal")) { + mode = QIcon::Normal; + } else if (item1->text() == tr("Active")) { + mode = QIcon::Active; + } else if (item1->text() == tr("Disabled")) { + mode = QIcon::Disabled; + } else { + mode = QIcon::Selected; + } + + QIcon::State state; + if (item2->text() == tr("On")) { + state = QIcon::On; + } else { + state = QIcon::Off; +//! [6] //! [7] + } +//! [7] + +//! [8] + QString fileName = item0->data(Qt::UserRole).toString(); + QImage image(fileName); + if (!image.isNull()) + icon.addPixmap(QPixmap::fromImage(image), mode, state); +//! [8] //! [9] + } +//! [9] //! [10] + } +//! [10] + +//! [11] + previewArea->setIcon(icon); +} +//! [11] + +//! [12] +void MainWindow::addImages() +{ + QStringList fileNames = QFileDialog::getOpenFileNames(this, + tr("Open Images"), "", + tr("Images (*.png *.xpm *.jpg);;" + "All Files (*)")); + if (!fileNames.isEmpty()) { + foreach (QString fileName, fileNames) { + int row = imagesTable->rowCount(); + imagesTable->setRowCount(row + 1); +//! [12] + +//! [13] + QString imageName = QFileInfo(fileName).baseName(); +//! [13] //! [14] + QTableWidgetItem *item0 = new QTableWidgetItem(imageName); + item0->setData(Qt::UserRole, fileName); + item0->setFlags(item0->flags() & ~Qt::ItemIsEditable); +//! [14] + +//! [15] + QTableWidgetItem *item1 = new QTableWidgetItem(tr("Normal")); +//! [15] //! [16] + QTableWidgetItem *item2 = new QTableWidgetItem(tr("Off")); + + if (guessModeStateAct->isChecked()) { + if (fileName.contains("_act")) { + item1->setText(tr("Active")); + } else if (fileName.contains("_dis")) { + item1->setText(tr("Disabled")); + } else if (fileName.contains("_sel")) { + item1->setText(tr("Selected")); + } + + if (fileName.contains("_on")) + item2->setText(tr("On")); +//! [16] //! [17] + } +//! [17] + +//! [18] + imagesTable->setItem(row, 0, item0); +//! [18] //! [19] + imagesTable->setItem(row, 1, item1); + imagesTable->setItem(row, 2, item2); + imagesTable->openPersistentEditor(item1); + imagesTable->openPersistentEditor(item2); + + item0->setCheckState(Qt::Checked); + } + } +} +//! [19] + +//! [20] +void MainWindow::removeAllImages() +{ + imagesTable->setRowCount(0); + changeIcon(); +} +//! [20] + +void MainWindow::createPreviewGroupBox() +{ + previewGroupBox = new QGroupBox(tr("Preview")); + + previewArea = new IconPreviewArea; + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(previewArea); + previewGroupBox->setLayout(layout); +} + +//! [21] +void MainWindow::createImagesGroupBox() +{ + imagesGroupBox = new QGroupBox(tr("Images")); + + imagesTable = new QTableWidget; + imagesTable->setSelectionMode(QAbstractItemView::NoSelection); + imagesTable->setItemDelegate(new ImageDelegate(this)); +//! [21] + +//! [22] + QStringList labels; +//! [22] //! [23] + labels << tr("Image") << tr("Mode") << tr("State"); + + imagesTable->horizontalHeader()->setDefaultSectionSize(90); + imagesTable->setColumnCount(3); + imagesTable->setHorizontalHeaderLabels(labels); + imagesTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch); + imagesTable->horizontalHeader()->setResizeMode(1, QHeaderView::Fixed); + imagesTable->horizontalHeader()->setResizeMode(2, QHeaderView::Fixed); + imagesTable->verticalHeader()->hide(); +//! [23] + +//! [24] + connect(imagesTable, SIGNAL(itemChanged(QTableWidgetItem *)), +//! [24] //! [25] + this, SLOT(changeIcon())); + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(imagesTable); + imagesGroupBox->setLayout(layout); +} +//! [25] + +//! [26] +void MainWindow::createIconSizeGroupBox() +{ + iconSizeGroupBox = new QGroupBox(tr("Icon Size")); + + smallRadioButton = new QRadioButton; + largeRadioButton = new QRadioButton; + toolBarRadioButton = new QRadioButton; + listViewRadioButton = new QRadioButton; + iconViewRadioButton = new QRadioButton; + tabBarRadioButton = new QRadioButton; + otherRadioButton = new QRadioButton(tr("Other:")); + + otherSpinBox = new IconSizeSpinBox; + otherSpinBox->setRange(8, 128); + otherSpinBox->setValue(64); +//! [26] + +//! [27] + connect(smallRadioButton, SIGNAL(toggled(bool)), + this, SLOT(changeSize(bool))); + connect(largeRadioButton, SIGNAL(toggled(bool)), + this, SLOT(changeSize(bool))); + connect(toolBarRadioButton, SIGNAL(toggled(bool)), + this, SLOT(changeSize(bool))); + connect(listViewRadioButton, SIGNAL(toggled(bool)), + this, SLOT(changeSize(bool))); + connect(iconViewRadioButton, SIGNAL(toggled(bool)), + this, SLOT(changeSize(bool))); + connect(tabBarRadioButton, SIGNAL(toggled(bool)), + this, SLOT(changeSize(bool))); + connect(otherRadioButton, SIGNAL(toggled(bool)), + this, SLOT(changeSize(bool))); + connect(otherSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changeSize())); + + QHBoxLayout *otherSizeLayout = new QHBoxLayout; + otherSizeLayout->addWidget(otherRadioButton); + otherSizeLayout->addWidget(otherSpinBox); + otherSizeLayout->addStretch(); + + QGridLayout *layout = new QGridLayout; + layout->addWidget(smallRadioButton, 0, 0); + layout->addWidget(largeRadioButton, 1, 0); + layout->addWidget(toolBarRadioButton, 2, 0); + layout->addWidget(listViewRadioButton, 0, 1); + layout->addWidget(iconViewRadioButton, 1, 1); + layout->addWidget(tabBarRadioButton, 2, 1); + layout->addLayout(otherSizeLayout, 3, 0, 1, 2); + layout->setRowStretch(4, 1); + iconSizeGroupBox->setLayout(layout); +} +//! [27] + +//! [28] +void MainWindow::createActions() +{ + addImagesAct = new QAction(tr("&Add Images..."), this); + addImagesAct->setShortcut(tr("Ctrl+A")); + connect(addImagesAct, SIGNAL(triggered()), this, SLOT(addImages())); + + removeAllImagesAct = new QAction(tr("&Remove All Images"), this); + removeAllImagesAct->setShortcut(tr("Ctrl+R")); + connect(removeAllImagesAct, SIGNAL(triggered()), + this, SLOT(removeAllImages())); + + exitAct = new QAction(tr("&Quit"), this); + exitAct->setShortcut(tr("Ctrl+Q")); + connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); + + styleActionGroup = new QActionGroup(this); + foreach (QString styleName, QStyleFactory::keys()) { + QAction *action = new QAction(styleActionGroup); + action->setText(tr("%1 Style").arg(styleName)); + action->setData(styleName); + action->setCheckable(true); + connect(action, SIGNAL(triggered(bool)), this, SLOT(changeStyle(bool))); + } + + guessModeStateAct = new QAction(tr("&Guess Image Mode/State"), this); + guessModeStateAct->setCheckable(true); + guessModeStateAct->setChecked(true); + + aboutAct = new QAction(tr("&About"), this); + connect(aboutAct, SIGNAL(triggered()), this, SLOT(about())); + + aboutQtAct = new QAction(tr("About &Qt"), this); + connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt())); +} +//! [28] + +//! [29] +void MainWindow::createMenus() +{ + fileMenu = menuBar()->addMenu(tr("&File")); + fileMenu->addAction(addImagesAct); + fileMenu->addAction(removeAllImagesAct); + fileMenu->addSeparator(); + fileMenu->addAction(exitAct); + + viewMenu = menuBar()->addMenu(tr("&View")); + foreach (QAction *action, styleActionGroup->actions()) + viewMenu->addAction(action); + viewMenu->addSeparator(); + viewMenu->addAction(guessModeStateAct); + + menuBar()->addSeparator(); + + helpMenu = menuBar()->addMenu(tr("&Help")); + helpMenu->addAction(aboutAct); + helpMenu->addAction(aboutQtAct); +} +//! [29] + +//! [30] +void MainWindow::createContextMenu() +{ + imagesTable->setContextMenuPolicy(Qt::ActionsContextMenu); + imagesTable->addAction(addImagesAct); + imagesTable->addAction(removeAllImagesAct); +} +//! [30] + +//! [31] +void MainWindow::checkCurrentStyle() +{ + foreach (QAction *action, styleActionGroup->actions()) { + QString styleName = action->data().toString(); + QStyle *candidate = QStyleFactory::create(styleName); + Q_ASSERT(candidate); + if (candidate->metaObject()->className() + == QApplication::style()->metaObject()->className()) { + action->trigger(); + return; + } + delete candidate; + } +} +//! [31] diff --git a/examples/widgets/icons/mainwindow.h b/examples/widgets/icons/mainwindow.h new file mode 100644 index 0000000..3494359 --- /dev/null +++ b/examples/widgets/icons/mainwindow.h @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include <QIcon> +#include <QList> +#include <QMainWindow> +#include <QPixmap> + +QT_BEGIN_NAMESPACE +class QAction; +class QActionGroup; +class QGroupBox; +class QMenu; +class QRadioButton; +class QTableWidget; +QT_END_NAMESPACE +class IconPreviewArea; +class IconSizeSpinBox; + +//! [0] +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +private slots: + void about(); + void changeStyle(bool checked); + void changeSize(bool checked = true); + void changeIcon(); + void addImages(); + void removeAllImages(); + +private: + void createPreviewGroupBox(); + void createImagesGroupBox(); + void createIconSizeGroupBox(); + void createActions(); + void createMenus(); + void createContextMenu(); + void checkCurrentStyle(); + + QWidget *centralWidget; + + QGroupBox *previewGroupBox; + IconPreviewArea *previewArea; + + QGroupBox *imagesGroupBox; + QTableWidget *imagesTable; + + QGroupBox *iconSizeGroupBox; + QRadioButton *smallRadioButton; + QRadioButton *largeRadioButton; + QRadioButton *toolBarRadioButton; + QRadioButton *listViewRadioButton; + QRadioButton *iconViewRadioButton; + QRadioButton *tabBarRadioButton; + QRadioButton *otherRadioButton; + IconSizeSpinBox *otherSpinBox; + + QMenu *fileMenu; + QMenu *viewMenu; + QMenu *helpMenu; + QAction *addImagesAct; + QAction *removeAllImagesAct; + QAction *exitAct; + QAction *guessModeStateAct; + QActionGroup *styleActionGroup; + QAction *aboutAct; + QAction *aboutQtAct; +}; +//! [0] + +#endif diff --git a/examples/widgets/imageviewer/imageviewer.cpp b/examples/widgets/imageviewer/imageviewer.cpp new file mode 100644 index 0000000..39d1b35 --- /dev/null +++ b/examples/widgets/imageviewer/imageviewer.cpp @@ -0,0 +1,278 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "imageviewer.h" + +//! [0] +ImageViewer::ImageViewer() +{ + imageLabel = new QLabel; + imageLabel->setBackgroundRole(QPalette::Base); + imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); + imageLabel->setScaledContents(true); + + scrollArea = new QScrollArea; + scrollArea->setBackgroundRole(QPalette::Dark); + scrollArea->setWidget(imageLabel); + setCentralWidget(scrollArea); + + createActions(); + createMenus(); + + setWindowTitle(tr("Image Viewer")); + resize(500, 400); +} +//! [0] + +//! [1] +void ImageViewer::open() +//! [1] //! [2] +{ + QString fileName = QFileDialog::getOpenFileName(this, + tr("Open File"), QDir::currentPath()); + if (!fileName.isEmpty()) { + QImage image(fileName); + if (image.isNull()) { + QMessageBox::information(this, tr("Image Viewer"), + tr("Cannot load %1.").arg(fileName)); + return; + } +//! [2] //! [3] + imageLabel->setPixmap(QPixmap::fromImage(image)); +//! [3] //! [4] + scaleFactor = 1.0; + + printAct->setEnabled(true); + fitToWindowAct->setEnabled(true); + updateActions(); + + if (!fitToWindowAct->isChecked()) + imageLabel->adjustSize(); + } +} +//! [4] + +//! [5] +void ImageViewer::print() +//! [5] //! [6] +{ + Q_ASSERT(imageLabel->pixmap()); +#ifndef QT_NO_PRINTER +//! [6] //! [7] + QPrintDialog dialog(&printer, this); +//! [7] //! [8] + if (dialog.exec()) { + QPainter painter(&printer); + QRect rect = painter.viewport(); + QSize size = imageLabel->pixmap()->size(); + size.scale(rect.size(), Qt::KeepAspectRatio); + painter.setViewport(rect.x(), rect.y(), size.width(), size.height()); + painter.setWindow(imageLabel->pixmap()->rect()); + painter.drawPixmap(0, 0, *imageLabel->pixmap()); + } +#endif +} +//! [8] + +//! [9] +void ImageViewer::zoomIn() +//! [9] //! [10] +{ + scaleImage(1.25); +} + +void ImageViewer::zoomOut() +{ + scaleImage(0.8); +} + +//! [10] //! [11] +void ImageViewer::normalSize() +//! [11] //! [12] +{ + imageLabel->adjustSize(); + scaleFactor = 1.0; +} +//! [12] + +//! [13] +void ImageViewer::fitToWindow() +//! [13] //! [14] +{ + bool fitToWindow = fitToWindowAct->isChecked(); + scrollArea->setWidgetResizable(fitToWindow); + if (!fitToWindow) { + normalSize(); + } + updateActions(); +} +//! [14] + + +//! [15] +void ImageViewer::about() +//! [15] //! [16] +{ + QMessageBox::about(this, tr("About Image Viewer"), + tr("<p>The <b>Image Viewer</b> example shows how to combine QLabel " + "and QScrollArea to display an image. QLabel is typically used " + "for displaying a text, but it can also display an image. " + "QScrollArea provides a scrolling view around another widget. " + "If the child widget exceeds the size of the frame, QScrollArea " + "automatically provides scroll bars. </p><p>The example " + "demonstrates how QLabel's ability to scale its contents " + "(QLabel::scaledContents), and QScrollArea's ability to " + "automatically resize its contents " + "(QScrollArea::widgetResizable), can be used to implement " + "zooming and scaling features. </p><p>In addition the example " + "shows how to use QPainter to print an image.</p>")); +} +//! [16] + +//! [17] +void ImageViewer::createActions() +//! [17] //! [18] +{ + openAct = new QAction(tr("&Open..."), this); + openAct->setShortcut(tr("Ctrl+O")); + connect(openAct, SIGNAL(triggered()), this, SLOT(open())); + + printAct = new QAction(tr("&Print..."), this); + printAct->setShortcut(tr("Ctrl+P")); + printAct->setEnabled(false); + connect(printAct, SIGNAL(triggered()), this, SLOT(print())); + + exitAct = new QAction(tr("E&xit"), this); + exitAct->setShortcut(tr("Ctrl+Q")); + connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); + + zoomInAct = new QAction(tr("Zoom &In (25%)"), this); + zoomInAct->setShortcut(tr("Ctrl++")); + zoomInAct->setEnabled(false); + connect(zoomInAct, SIGNAL(triggered()), this, SLOT(zoomIn())); + + zoomOutAct = new QAction(tr("Zoom &Out (25%)"), this); + zoomOutAct->setShortcut(tr("Ctrl+-")); + zoomOutAct->setEnabled(false); + connect(zoomOutAct, SIGNAL(triggered()), this, SLOT(zoomOut())); + + normalSizeAct = new QAction(tr("&Normal Size"), this); + normalSizeAct->setShortcut(tr("Ctrl+S")); + normalSizeAct->setEnabled(false); + connect(normalSizeAct, SIGNAL(triggered()), this, SLOT(normalSize())); + + fitToWindowAct = new QAction(tr("&Fit to Window"), this); + fitToWindowAct->setEnabled(false); + fitToWindowAct->setCheckable(true); + fitToWindowAct->setShortcut(tr("Ctrl+F")); + connect(fitToWindowAct, SIGNAL(triggered()), this, SLOT(fitToWindow())); + + aboutAct = new QAction(tr("&About"), this); + connect(aboutAct, SIGNAL(triggered()), this, SLOT(about())); + + aboutQtAct = new QAction(tr("About &Qt"), this); + connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt())); +} +//! [18] + +//! [19] +void ImageViewer::createMenus() +//! [19] //! [20] +{ + fileMenu = new QMenu(tr("&File"), this); + fileMenu->addAction(openAct); + fileMenu->addAction(printAct); + fileMenu->addSeparator(); + fileMenu->addAction(exitAct); + + viewMenu = new QMenu(tr("&View"), this); + viewMenu->addAction(zoomInAct); + viewMenu->addAction(zoomOutAct); + viewMenu->addAction(normalSizeAct); + viewMenu->addSeparator(); + viewMenu->addAction(fitToWindowAct); + + helpMenu = new QMenu(tr("&Help"), this); + helpMenu->addAction(aboutAct); + helpMenu->addAction(aboutQtAct); + + menuBar()->addMenu(fileMenu); + menuBar()->addMenu(viewMenu); + menuBar()->addMenu(helpMenu); +} +//! [20] + +//! [21] +void ImageViewer::updateActions() +//! [21] //! [22] +{ + zoomInAct->setEnabled(!fitToWindowAct->isChecked()); + zoomOutAct->setEnabled(!fitToWindowAct->isChecked()); + normalSizeAct->setEnabled(!fitToWindowAct->isChecked()); +} +//! [22] + +//! [23] +void ImageViewer::scaleImage(double factor) +//! [23] //! [24] +{ + Q_ASSERT(imageLabel->pixmap()); + scaleFactor *= factor; + imageLabel->resize(scaleFactor * imageLabel->pixmap()->size()); + + adjustScrollBar(scrollArea->horizontalScrollBar(), factor); + adjustScrollBar(scrollArea->verticalScrollBar(), factor); + + zoomInAct->setEnabled(scaleFactor < 3.0); + zoomOutAct->setEnabled(scaleFactor > 0.333); +} +//! [24] + +//! [25] +void ImageViewer::adjustScrollBar(QScrollBar *scrollBar, double factor) +//! [25] //! [26] +{ + scrollBar->setValue(int(factor * scrollBar->value() + + ((factor - 1) * scrollBar->pageStep()/2))); +} +//! [26] diff --git a/examples/widgets/imageviewer/imageviewer.h b/examples/widgets/imageviewer/imageviewer.h new file mode 100644 index 0000000..b84f7d5 --- /dev/null +++ b/examples/widgets/imageviewer/imageviewer.h @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef IMAGEVIEWER_H +#define IMAGEVIEWER_H + +#include <QMainWindow> +#include <QPrinter> + +QT_BEGIN_NAMESPACE +class QAction; +class QLabel; +class QMenu; +class QScrollArea; +class QScrollBar; +QT_END_NAMESPACE + +//! [0] +class ImageViewer : public QMainWindow +{ + Q_OBJECT + +public: + ImageViewer(); + +private slots: + void open(); + void print(); + void zoomIn(); + void zoomOut(); + void normalSize(); + void fitToWindow(); + void about(); + +private: + void createActions(); + void createMenus(); + void updateActions(); + void scaleImage(double factor); + void adjustScrollBar(QScrollBar *scrollBar, double factor); + + QLabel *imageLabel; + QScrollArea *scrollArea; + double scaleFactor; + +#ifndef QT_NO_PRINTER + QPrinter printer; +#endif + + QAction *openAct; + QAction *printAct; + QAction *exitAct; + QAction *zoomInAct; + QAction *zoomOutAct; + QAction *normalSizeAct; + QAction *fitToWindowAct; + QAction *aboutAct; + QAction *aboutQtAct; + + QMenu *fileMenu; + QMenu *viewMenu; + QMenu *helpMenu; +}; +//! [0] + +#endif diff --git a/examples/widgets/imageviewer/imageviewer.pro b/examples/widgets/imageviewer/imageviewer.pro new file mode 100644 index 0000000..31c9d47 --- /dev/null +++ b/examples/widgets/imageviewer/imageviewer.pro @@ -0,0 +1,13 @@ +HEADERS = imageviewer.h +SOURCES = imageviewer.cpp \ + main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/widgets/imageviewer +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS imageviewer.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/imageviewer +INSTALLS += target sources + +wince*: { + DEPLOYMENT_PLUGIN += qjpeg qmng qgif +} diff --git a/examples/widgets/imageviewer/main.cpp b/examples/widgets/imageviewer/main.cpp new file mode 100644 index 0000000..090580c --- /dev/null +++ b/examples/widgets/imageviewer/main.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> + +#include "imageviewer.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + ImageViewer imageViewer; + imageViewer.show(); + return app.exec(); +} diff --git a/examples/widgets/lineedits/lineedits.pro b/examples/widgets/lineedits/lineedits.pro new file mode 100644 index 0000000..e963024 --- /dev/null +++ b/examples/widgets/lineedits/lineedits.pro @@ -0,0 +1,9 @@ +HEADERS = window.h +SOURCES = main.cpp \ + window.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/widgets/lineedits +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS lineedits.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/lineedits +INSTALLS += target sources diff --git a/examples/widgets/lineedits/main.cpp b/examples/widgets/lineedits/main.cpp new file mode 100644 index 0000000..fa8b0ab --- /dev/null +++ b/examples/widgets/lineedits/main.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> + +#include "window.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + Window window; + window.show(); + return app.exec(); +} diff --git a/examples/widgets/lineedits/window.cpp b/examples/widgets/lineedits/window.cpp new file mode 100644 index 0000000..13acffd --- /dev/null +++ b/examples/widgets/lineedits/window.cpp @@ -0,0 +1,257 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "window.h" + +//! [0] +Window::Window() +{ + QGroupBox *echoGroup = new QGroupBox(tr("Echo")); + + QLabel *echoLabel = new QLabel(tr("Mode:")); + QComboBox *echoComboBox = new QComboBox; + echoComboBox->addItem(tr("Normal")); + echoComboBox->addItem(tr("Password")); + echoComboBox->addItem(tr("PasswordEchoOnEdit")); + echoComboBox->addItem(tr("No Echo")); + + echoLineEdit = new QLineEdit; + echoLineEdit->setFocus(); +//! [0] + +//! [1] + QGroupBox *validatorGroup = new QGroupBox(tr("Validator")); + + QLabel *validatorLabel = new QLabel(tr("Type:")); + QComboBox *validatorComboBox = new QComboBox; + validatorComboBox->addItem(tr("No validator")); + validatorComboBox->addItem(tr("Integer validator")); + validatorComboBox->addItem(tr("Double validator")); + + validatorLineEdit = new QLineEdit; +//! [1] + +//! [2] + QGroupBox *alignmentGroup = new QGroupBox(tr("Alignment")); + + QLabel *alignmentLabel = new QLabel(tr("Type:")); + QComboBox *alignmentComboBox = new QComboBox; + alignmentComboBox->addItem(tr("Left")); + alignmentComboBox->addItem(tr("Centered")); + alignmentComboBox->addItem(tr("Right")); + + alignmentLineEdit = new QLineEdit; +//! [2] + +//! [3] + QGroupBox *inputMaskGroup = new QGroupBox(tr("Input mask")); + + QLabel *inputMaskLabel = new QLabel(tr("Type:")); + QComboBox *inputMaskComboBox = new QComboBox; + inputMaskComboBox->addItem(tr("No mask")); + inputMaskComboBox->addItem(tr("Phone number")); + inputMaskComboBox->addItem(tr("ISO date")); + inputMaskComboBox->addItem(tr("License key")); + + inputMaskLineEdit = new QLineEdit; +//! [3] + +//! [4] + QGroupBox *accessGroup = new QGroupBox(tr("Access")); + + QLabel *accessLabel = new QLabel(tr("Read-only:")); + QComboBox *accessComboBox = new QComboBox; + accessComboBox->addItem(tr("False")); + accessComboBox->addItem(tr("True")); + + accessLineEdit = new QLineEdit; +//! [4] + +//! [5] + connect(echoComboBox, SIGNAL(activated(int)), + this, SLOT(echoChanged(int))); + connect(validatorComboBox, SIGNAL(activated(int)), + this, SLOT(validatorChanged(int))); + connect(alignmentComboBox, SIGNAL(activated(int)), + this, SLOT(alignmentChanged(int))); + connect(inputMaskComboBox, SIGNAL(activated(int)), + this, SLOT(inputMaskChanged(int))); + connect(accessComboBox, SIGNAL(activated(int)), + this, SLOT(accessChanged(int))); +//! [5] + +//! [6] + QGridLayout *echoLayout = new QGridLayout; + echoLayout->addWidget(echoLabel, 0, 0); + echoLayout->addWidget(echoComboBox, 0, 1); + echoLayout->addWidget(echoLineEdit, 1, 0, 1, 2); + echoGroup->setLayout(echoLayout); +//! [6] + +//! [7] + QGridLayout *validatorLayout = new QGridLayout; + validatorLayout->addWidget(validatorLabel, 0, 0); + validatorLayout->addWidget(validatorComboBox, 0, 1); + validatorLayout->addWidget(validatorLineEdit, 1, 0, 1, 2); + validatorGroup->setLayout(validatorLayout); + + QGridLayout *alignmentLayout = new QGridLayout; + alignmentLayout->addWidget(alignmentLabel, 0, 0); + alignmentLayout->addWidget(alignmentComboBox, 0, 1); + alignmentLayout->addWidget(alignmentLineEdit, 1, 0, 1, 2); + alignmentGroup-> setLayout(alignmentLayout); + + QGridLayout *inputMaskLayout = new QGridLayout; + inputMaskLayout->addWidget(inputMaskLabel, 0, 0); + inputMaskLayout->addWidget(inputMaskComboBox, 0, 1); + inputMaskLayout->addWidget(inputMaskLineEdit, 1, 0, 1, 2); + inputMaskGroup->setLayout(inputMaskLayout); + + QGridLayout *accessLayout = new QGridLayout; + accessLayout->addWidget(accessLabel, 0, 0); + accessLayout->addWidget(accessComboBox, 0, 1); + accessLayout->addWidget(accessLineEdit, 1, 0, 1, 2); + accessGroup->setLayout(accessLayout); +//! [7] + +//! [8] + QGridLayout *layout = new QGridLayout; + layout->addWidget(echoGroup, 0, 0); + layout->addWidget(validatorGroup, 1, 0); + layout->addWidget(alignmentGroup, 2, 0); + layout->addWidget(inputMaskGroup, 0, 1); + layout->addWidget(accessGroup, 1, 1); + setLayout(layout); + + setWindowTitle(tr("Line Edits")); +} +//! [8] + +//! [9] +void Window::echoChanged(int index) +{ + switch (index) { + case 0: + echoLineEdit->setEchoMode(QLineEdit::Normal); + break; + case 1: + echoLineEdit->setEchoMode(QLineEdit::Password); + break; + case 2: + echoLineEdit->setEchoMode(QLineEdit::PasswordEchoOnEdit); + break; + case 3: + echoLineEdit->setEchoMode(QLineEdit::NoEcho); + } +} +//! [9] + +//! [10] +void Window::validatorChanged(int index) +{ + switch (index) { + case 0: + validatorLineEdit->setValidator(0); + break; + case 1: + validatorLineEdit->setValidator(new QIntValidator( + validatorLineEdit)); + break; + case 2: + validatorLineEdit->setValidator(new QDoubleValidator(-999.0, + 999.0, 2, validatorLineEdit)); + } + + validatorLineEdit->clear(); +} +//! [10] + +//! [11] +void Window::alignmentChanged(int index) +{ + switch (index) { + case 0: + alignmentLineEdit->setAlignment(Qt::AlignLeft); + break; + case 1: + alignmentLineEdit->setAlignment(Qt::AlignCenter); + break; + case 2: + alignmentLineEdit->setAlignment(Qt::AlignRight); + } +} +//! [11] + +//! [12] +void Window::inputMaskChanged(int index) +{ + switch (index) { + case 0: + inputMaskLineEdit->setInputMask(""); + break; + case 1: + inputMaskLineEdit->setInputMask("+99 99 99 99 99;_"); + break; + case 2: + inputMaskLineEdit->setInputMask("0000-00-00"); + inputMaskLineEdit->setText("00000000"); + inputMaskLineEdit->setCursorPosition(0); + break; + case 3: + inputMaskLineEdit->setInputMask(">AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;#"); + } +} +//! [12] + +//! [13] +void Window::accessChanged(int index) +{ + switch (index) { + case 0: + accessLineEdit->setReadOnly(false); + break; + case 1: + accessLineEdit->setReadOnly(true); + } +} +//! [13] diff --git a/examples/widgets/lineedits/window.h b/examples/widgets/lineedits/window.h new file mode 100644 index 0000000..2d10d78 --- /dev/null +++ b/examples/widgets/lineedits/window.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include <QWidget> + +QT_BEGIN_NAMESPACE +class QComboBox; +class QLineEdit; +QT_END_NAMESPACE + +//! [0] +class Window : public QWidget +{ + Q_OBJECT + +public: + Window(); + +public slots: + void echoChanged(int); + void validatorChanged(int); + void alignmentChanged(int); + void inputMaskChanged(int); + void accessChanged(int); + +private: + QLineEdit *echoLineEdit; + QLineEdit *validatorLineEdit; + QLineEdit *alignmentLineEdit; + QLineEdit *inputMaskLineEdit; + QLineEdit *accessLineEdit; +}; +//! [0] + +#endif diff --git a/examples/widgets/movie/animation.mng b/examples/widgets/movie/animation.mng Binary files differnew file mode 100644 index 0000000..12b688a --- /dev/null +++ b/examples/widgets/movie/animation.mng diff --git a/examples/widgets/movie/main.cpp b/examples/widgets/movie/main.cpp new file mode 100644 index 0000000..50bec73 --- /dev/null +++ b/examples/widgets/movie/main.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> + +#include "movieplayer.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MoviePlayer player; + player.show(); + return app.exec(); +} diff --git a/examples/widgets/movie/movie.pro b/examples/widgets/movie/movie.pro new file mode 100644 index 0000000..b5f0a7a --- /dev/null +++ b/examples/widgets/movie/movie.pro @@ -0,0 +1,9 @@ +HEADERS = movieplayer.h +SOURCES = main.cpp \ + movieplayer.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/widgets/movie +sources.files = $$SOURCES $$HEADERS $$RESOURCES movie.pro movies +sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/movie +INSTALLS += target sources diff --git a/examples/widgets/movie/movieplayer.cpp b/examples/widgets/movie/movieplayer.cpp new file mode 100644 index 0000000..1ffc233 --- /dev/null +++ b/examples/widgets/movie/movieplayer.cpp @@ -0,0 +1,211 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "movieplayer.h" + +MoviePlayer::MoviePlayer(QWidget *parent) + : QWidget(parent) +{ + movie = new QMovie(this); + movie->setCacheMode(QMovie::CacheAll); + + movieLabel = new QLabel(tr("No movie loaded")); + movieLabel->setAlignment(Qt::AlignCenter); + movieLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); + movieLabel->setBackgroundRole(QPalette::Dark); + movieLabel->setAutoFillBackground(true); + + currentMovieDirectory = "movies"; + + createControls(); + createButtons(); + + connect(movie, SIGNAL(frameChanged(int)), this, SLOT(updateFrameSlider())); + connect(movie, SIGNAL(stateChanged(QMovie::MovieState)), + this, SLOT(updateButtons())); + connect(fitCheckBox, SIGNAL(clicked()), this, SLOT(fitToWindow())); + connect(frameSlider, SIGNAL(valueChanged(int)), this, SLOT(goToFrame(int))); + connect(speedSpinBox, SIGNAL(valueChanged(int)), + movie, SLOT(setSpeed(int))); + + mainLayout = new QVBoxLayout; + mainLayout->addWidget(movieLabel); + mainLayout->addLayout(controlsLayout); + mainLayout->addLayout(buttonsLayout); + setLayout(mainLayout); + + updateFrameSlider(); + updateButtons(); + + setWindowTitle(tr("Movie Player")); + resize(400, 400); +} + +void MoviePlayer::open() +{ + QString fileName = QFileDialog::getOpenFileName(this, tr("Open a Movie"), + currentMovieDirectory); + if (!fileName.isEmpty()) + openFile(fileName); +} + +void MoviePlayer::openFile(const QString &fileName) +{ + currentMovieDirectory = QFileInfo(fileName).path(); + + movie->stop(); + movieLabel->setMovie(movie); + movie->setFileName(fileName); + movie->start(); + + updateFrameSlider(); + updateButtons(); +} + +void MoviePlayer::goToFrame(int frame) +{ + movie->jumpToFrame(frame); +} + +void MoviePlayer::fitToWindow() +{ + movieLabel->setScaledContents(fitCheckBox->isChecked()); +} + +void MoviePlayer::updateFrameSlider() +{ + bool hasFrames = (movie->currentFrameNumber() >= 0); + + if (hasFrames) { + if (movie->frameCount() > 0) { + frameSlider->setMaximum(movie->frameCount() - 1); + } else { + if (movie->currentFrameNumber() > frameSlider->maximum()) + frameSlider->setMaximum(movie->currentFrameNumber()); + } + frameSlider->setValue(movie->currentFrameNumber()); + } else { + frameSlider->setMaximum(0); + } + frameLabel->setEnabled(hasFrames); + frameSlider->setEnabled(hasFrames); +} + +void MoviePlayer::updateButtons() +{ + playButton->setEnabled(movie->isValid() && movie->frameCount() != 1 + && movie->state() == QMovie::NotRunning); + pauseButton->setEnabled(movie->state() != QMovie::NotRunning); + pauseButton->setChecked(movie->state() == QMovie::Paused); + stopButton->setEnabled(movie->state() != QMovie::NotRunning); +} + +void MoviePlayer::createControls() +{ + fitCheckBox = new QCheckBox(tr("Fit to Window")); + + frameLabel = new QLabel(tr("Current frame:")); + + frameSlider = new QSlider(Qt::Horizontal); + frameSlider->setTickPosition(QSlider::TicksBelow); + frameSlider->setTickInterval(10); + + speedLabel = new QLabel(tr("Speed:")); + + speedSpinBox = new QSpinBox; + speedSpinBox->setRange(1, 9999); + speedSpinBox->setValue(100); + speedSpinBox->setSuffix(tr("%")); + + controlsLayout = new QGridLayout; + controlsLayout->addWidget(fitCheckBox, 0, 0, 1, 2); + controlsLayout->addWidget(frameLabel, 1, 0); + controlsLayout->addWidget(frameSlider, 1, 1, 1, 2); + controlsLayout->addWidget(speedLabel, 2, 0); + controlsLayout->addWidget(speedSpinBox, 2, 1); +} + +void MoviePlayer::createButtons() +{ + QSize iconSize(36, 36); + + openButton = new QToolButton; + openButton->setIcon(style()->standardIcon(QStyle::SP_DialogOpenButton)); + openButton->setIconSize(iconSize); + openButton->setToolTip(tr("Open File")); + connect(openButton, SIGNAL(clicked()), this, SLOT(open())); + + playButton = new QToolButton; + playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); + playButton->setIconSize(iconSize); + playButton->setToolTip(tr("Play")); + connect(playButton, SIGNAL(clicked()), movie, SLOT(start())); + + pauseButton = new QToolButton; + pauseButton->setCheckable(true); + pauseButton->setIcon(style()->standardIcon(QStyle::SP_MediaPause)); + pauseButton->setIconSize(iconSize); + pauseButton->setToolTip(tr("Pause")); + connect(pauseButton, SIGNAL(clicked(bool)), movie, SLOT(setPaused(bool))); + + stopButton = new QToolButton; + stopButton->setIcon(style()->standardIcon(QStyle::SP_MediaStop)); + stopButton->setIconSize(iconSize); + stopButton->setToolTip(tr("Stop")); + connect(stopButton, SIGNAL(clicked()), movie, SLOT(stop())); + + quitButton = new QToolButton; + quitButton->setIcon(style()->standardIcon(QStyle::SP_DialogCloseButton)); + quitButton->setIconSize(iconSize); + quitButton->setToolTip(tr("Quit")); + connect(quitButton, SIGNAL(clicked()), this, SLOT(close())); + + buttonsLayout = new QHBoxLayout; + buttonsLayout->addStretch(); + buttonsLayout->addWidget(openButton); + buttonsLayout->addWidget(playButton); + buttonsLayout->addWidget(pauseButton); + buttonsLayout->addWidget(stopButton); + buttonsLayout->addWidget(quitButton); + buttonsLayout->addStretch(); +} diff --git a/examples/widgets/movie/movieplayer.h b/examples/widgets/movie/movieplayer.h new file mode 100644 index 0000000..123c2e2 --- /dev/null +++ b/examples/widgets/movie/movieplayer.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOVIEPLAYER_H +#define MOVIEPLAYER_H + +#include <QWidget> + +QT_BEGIN_NAMESPACE +class QCheckBox; +class QGridLayout; +class QHBoxLayout; +class QLabel; +class QMovie; +class QSlider; +class QSpinBox; +class QToolButton; +class QVBoxLayout; +QT_END_NAMESPACE + +class MoviePlayer : public QWidget +{ + Q_OBJECT + +public: + MoviePlayer(QWidget *parent = 0); + void openFile(const QString &fileName); + +private slots: + void open(); + void goToFrame(int frame); + void fitToWindow(); + void updateButtons(); + void updateFrameSlider(); + +private: + void createControls(); + void createButtons(); + + QString currentMovieDirectory; + QLabel *movieLabel; + QMovie *movie; + QToolButton *openButton; + QToolButton *playButton; + QToolButton *pauseButton; + QToolButton *stopButton; + QToolButton *quitButton; + QCheckBox *fitCheckBox; + QSlider *frameSlider; + QSpinBox *speedSpinBox; + QLabel *frameLabel; + QLabel *speedLabel; + + QGridLayout *controlsLayout; + QHBoxLayout *buttonsLayout; + QVBoxLayout *mainLayout; +}; + +#endif diff --git a/examples/widgets/scribble/main.cpp b/examples/widgets/scribble/main.cpp new file mode 100644 index 0000000..1d51376 --- /dev/null +++ b/examples/widgets/scribble/main.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow window; + window.show(); + return app.exec(); +} diff --git a/examples/widgets/scribble/mainwindow.cpp b/examples/widgets/scribble/mainwindow.cpp new file mode 100644 index 0000000..ad1a837 --- /dev/null +++ b/examples/widgets/scribble/mainwindow.cpp @@ -0,0 +1,251 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "mainwindow.h" +#include "scribblearea.h" + +//! [0] +MainWindow::MainWindow() +{ + scribbleArea = new ScribbleArea; + setCentralWidget(scribbleArea); + + createActions(); + createMenus(); + + setWindowTitle(tr("Scribble")); + resize(500, 500); +} +//! [0] + +//! [1] +void MainWindow::closeEvent(QCloseEvent *event) +//! [1] //! [2] +{ + if (maybeSave()) { + event->accept(); + } else { + event->ignore(); + } +} +//! [2] + +//! [3] +void MainWindow::open() +//! [3] //! [4] +{ + if (maybeSave()) { + QString fileName = QFileDialog::getOpenFileName(this, + tr("Open File"), QDir::currentPath()); + if (!fileName.isEmpty()) + scribbleArea->openImage(fileName); + } +} +//! [4] + +//! [5] +void MainWindow::save() +//! [5] //! [6] +{ + QAction *action = qobject_cast<QAction *>(sender()); + QByteArray fileFormat = action->data().toByteArray(); + saveFile(fileFormat); +} +//! [6] + +//! [7] +void MainWindow::penColor() +//! [7] //! [8] +{ + QColor newColor = QColorDialog::getColor(scribbleArea->penColor()); + if (newColor.isValid()) + scribbleArea->setPenColor(newColor); +} +//! [8] + +//! [9] +void MainWindow::penWidth() +//! [9] //! [10] +{ + bool ok; + int newWidth = QInputDialog::getInteger(this, tr("Scribble"), + tr("Select pen width:"), + scribbleArea->penWidth(), + 1, 50, 1, &ok); + if (ok) + scribbleArea->setPenWidth(newWidth); +} +//! [10] + +//! [11] +void MainWindow::about() +//! [11] //! [12] +{ + QMessageBox::about(this, tr("About Scribble"), + tr("<p>The <b>Scribble</b> example shows how to use QMainWindow as the " + "base widget for an application, and how to reimplement some of " + "QWidget's event handlers to receive the events generated for " + "the application's widgets:</p><p> We reimplement the mouse event " + "handlers to facilitate drawing, the paint event handler to " + "update the application and the resize event handler to optimize " + "the application's appearance. In addition we reimplement the " + "close event handler to intercept the close events before " + "terminating the application.</p><p> The example also demonstrates " + "how to use QPainter to draw an image in real time, as well as " + "to repaint widgets.</p>")); +} +//! [12] + +//! [13] +void MainWindow::createActions() +//! [13] //! [14] +{ + openAct = new QAction(tr("&Open..."), this); + openAct->setShortcut(tr("Ctrl+O")); + connect(openAct, SIGNAL(triggered()), this, SLOT(open())); + + foreach (QByteArray format, QImageWriter::supportedImageFormats()) { + QString text = tr("%1...").arg(QString(format).toUpper()); + + QAction *action = new QAction(text, this); + action->setData(format); + connect(action, SIGNAL(triggered()), this, SLOT(save())); + saveAsActs.append(action); + } + + printAct = new QAction(tr("&Print..."), this); + connect(printAct, SIGNAL(triggered()), scribbleArea, SLOT(print())); + + exitAct = new QAction(tr("E&xit"), this); + exitAct->setShortcut(tr("Ctrl+Q")); + connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); + + penColorAct = new QAction(tr("&Pen Color..."), this); + connect(penColorAct, SIGNAL(triggered()), this, SLOT(penColor())); + + penWidthAct = new QAction(tr("Pen &Width..."), this); + connect(penWidthAct, SIGNAL(triggered()), this, SLOT(penWidth())); + + clearScreenAct = new QAction(tr("&Clear Screen"), this); + clearScreenAct->setShortcut(tr("Ctrl+L")); + connect(clearScreenAct, SIGNAL(triggered()), + scribbleArea, SLOT(clearImage())); + + aboutAct = new QAction(tr("&About"), this); + connect(aboutAct, SIGNAL(triggered()), this, SLOT(about())); + + aboutQtAct = new QAction(tr("About &Qt"), this); + connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt())); +} +//! [14] + +//! [15] +void MainWindow::createMenus() +//! [15] //! [16] +{ + saveAsMenu = new QMenu(tr("&Save As"), this); + foreach (QAction *action, saveAsActs) + saveAsMenu->addAction(action); + + fileMenu = new QMenu(tr("&File"), this); + fileMenu->addAction(openAct); + fileMenu->addMenu(saveAsMenu); + fileMenu->addAction(printAct); + fileMenu->addSeparator(); + fileMenu->addAction(exitAct); + + optionMenu = new QMenu(tr("&Options"), this); + optionMenu->addAction(penColorAct); + optionMenu->addAction(penWidthAct); + optionMenu->addSeparator(); + optionMenu->addAction(clearScreenAct); + + helpMenu = new QMenu(tr("&Help"), this); + helpMenu->addAction(aboutAct); + helpMenu->addAction(aboutQtAct); + + menuBar()->addMenu(fileMenu); + menuBar()->addMenu(optionMenu); + menuBar()->addMenu(helpMenu); +} +//! [16] + +//! [17] +bool MainWindow::maybeSave() +//! [17] //! [18] +{ + if (scribbleArea->isModified()) { + QMessageBox::StandardButton ret; + ret = QMessageBox::warning(this, tr("Scribble"), + tr("The image has been modified.\n" + "Do you want to save your changes?"), + QMessageBox::Save | QMessageBox::Discard + | QMessageBox::Cancel); + if (ret == QMessageBox::Save) { + return saveFile("png"); + } else if (ret == QMessageBox::Cancel) { + return false; + } + } + return true; +} +//! [18] + +//! [19] +bool MainWindow::saveFile(const QByteArray &fileFormat) +//! [19] //! [20] +{ + QString initialPath = QDir::currentPath() + "/untitled." + fileFormat; + + QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), + initialPath, + tr("%1 Files (*.%2);;All Files (*)") + .arg(QString(fileFormat.toUpper())) + .arg(QString(fileFormat))); + if (fileName.isEmpty()) { + return false; + } else { + return scribbleArea->saveImage(fileName, fileFormat); + } +} +//! [20] diff --git a/examples/widgets/scribble/mainwindow.h b/examples/widgets/scribble/mainwindow.h new file mode 100644 index 0000000..0c3b2a4 --- /dev/null +++ b/examples/widgets/scribble/mainwindow.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include <QList> +#include <QMainWindow> + +class ScribbleArea; + +//! [0] +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +protected: + void closeEvent(QCloseEvent *event); + +private slots: + void open(); + void save(); + void penColor(); + void penWidth(); + void about(); + +private: + void createActions(); + void createMenus(); + bool maybeSave(); + bool saveFile(const QByteArray &fileFormat); + + ScribbleArea *scribbleArea; + + QMenu *saveAsMenu; + QMenu *fileMenu; + QMenu *optionMenu; + QMenu *helpMenu; + + QAction *openAct; + QList<QAction *> saveAsActs; + QAction *exitAct; + QAction *penColorAct; + QAction *penWidthAct; + QAction *printAct; + QAction *clearScreenAct; + QAction *aboutAct; + QAction *aboutQtAct; +}; +//! [0] + +#endif diff --git a/examples/widgets/scribble/scribble.pro b/examples/widgets/scribble/scribble.pro new file mode 100644 index 0000000..21f24cc --- /dev/null +++ b/examples/widgets/scribble/scribble.pro @@ -0,0 +1,11 @@ +HEADERS = mainwindow.h \ + scribblearea.h +SOURCES = main.cpp \ + mainwindow.cpp \ + scribblearea.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/widgets/scribble +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS scribble.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/scribble +INSTALLS += target sources diff --git a/examples/widgets/scribble/scribblearea.cpp b/examples/widgets/scribble/scribblearea.cpp new file mode 100644 index 0000000..0d10fcd --- /dev/null +++ b/examples/widgets/scribble/scribblearea.cpp @@ -0,0 +1,215 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "scribblearea.h" + +//! [0] +ScribbleArea::ScribbleArea(QWidget *parent) + : QWidget(parent) +{ + setAttribute(Qt::WA_StaticContents); + modified = false; + scribbling = false; + myPenWidth = 1; + myPenColor = Qt::blue; +} +//! [0] + +//! [1] +bool ScribbleArea::openImage(const QString &fileName) +//! [1] //! [2] +{ + QImage loadedImage; + if (!loadedImage.load(fileName)) + return false; + + QSize newSize = loadedImage.size().expandedTo(size()); + resizeImage(&loadedImage, newSize); + image = loadedImage; + modified = false; + update(); + return true; +} +//! [2] + +//! [3] +bool ScribbleArea::saveImage(const QString &fileName, const char *fileFormat) +//! [3] //! [4] +{ + QImage visibleImage = image; + resizeImage(&visibleImage, size()); + + if (visibleImage.save(fileName, fileFormat)) { + modified = false; + return true; + } else { + return false; + } +} +//! [4] + +//! [5] +void ScribbleArea::setPenColor(const QColor &newColor) +//! [5] //! [6] +{ + myPenColor = newColor; +} +//! [6] + +//! [7] +void ScribbleArea::setPenWidth(int newWidth) +//! [7] //! [8] +{ + myPenWidth = newWidth; +} +//! [8] + +//! [9] +void ScribbleArea::clearImage() +//! [9] //! [10] +{ + image.fill(qRgb(255, 255, 255)); + modified = true; + update(); +} +//! [10] + +//! [11] +void ScribbleArea::mousePressEvent(QMouseEvent *event) +//! [11] //! [12] +{ + if (event->button() == Qt::LeftButton) { + lastPoint = event->pos(); + scribbling = true; + } +} + +void ScribbleArea::mouseMoveEvent(QMouseEvent *event) +{ + if ((event->buttons() & Qt::LeftButton) && scribbling) + drawLineTo(event->pos()); +} + +void ScribbleArea::mouseReleaseEvent(QMouseEvent *event) +{ + if (event->button() == Qt::LeftButton && scribbling) { + drawLineTo(event->pos()); + scribbling = false; + } +} + +//! [12] //! [13] +void ScribbleArea::paintEvent(QPaintEvent * /* event */) +//! [13] //! [14] +{ + QPainter painter(this); + painter.drawImage(QPoint(0, 0), image); +} +//! [14] + +//! [15] +void ScribbleArea::resizeEvent(QResizeEvent *event) +//! [15] //! [16] +{ + if (width() > image.width() || height() > image.height()) { + int newWidth = qMax(width() + 128, image.width()); + int newHeight = qMax(height() + 128, image.height()); + resizeImage(&image, QSize(newWidth, newHeight)); + update(); + } + QWidget::resizeEvent(event); +} +//! [16] + +//! [17] +void ScribbleArea::drawLineTo(const QPoint &endPoint) +//! [17] //! [18] +{ + QPainter painter(&image); + painter.setPen(QPen(myPenColor, myPenWidth, Qt::SolidLine, Qt::RoundCap, + Qt::RoundJoin)); + painter.drawLine(lastPoint, endPoint); + modified = true; + + int rad = (myPenWidth / 2) + 2; + update(QRect(lastPoint, endPoint).normalized() + .adjusted(-rad, -rad, +rad, +rad)); + lastPoint = endPoint; +} +//! [18] + +//! [19] +void ScribbleArea::resizeImage(QImage *image, const QSize &newSize) +//! [19] //! [20] +{ + if (image->size() == newSize) + return; + + QImage newImage(newSize, QImage::Format_RGB32); + newImage.fill(qRgb(255, 255, 255)); + QPainter painter(&newImage); + painter.drawImage(QPoint(0, 0), *image); + *image = newImage; +} +//! [20] + +//! [21] +void ScribbleArea::print() +{ +#ifndef QT_NO_PRINTER + QPrinter printer(QPrinter::HighResolution); + + QPrintDialog *printDialog = new QPrintDialog(&printer, this); +//! [21] //! [22] + if (printDialog->exec() == QDialog::Accepted) { + QPainter painter(&printer); + QRect rect = painter.viewport(); + QSize size = image.size(); + size.scale(rect.size(), Qt::KeepAspectRatio); + painter.setViewport(rect.x(), rect.y(), size.width(), size.height()); + painter.setWindow(image.rect()); + painter.drawImage(0, 0, image); + } +#endif // QT_NO_PRINTER +} +//! [22] diff --git a/examples/widgets/scribble/scribblearea.h b/examples/widgets/scribble/scribblearea.h new file mode 100644 index 0000000..afa3cbc --- /dev/null +++ b/examples/widgets/scribble/scribblearea.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SCRIBBLEAREA_H +#define SCRIBBLEAREA_H + +#include <QColor> +#include <QImage> +#include <QPoint> +#include <QWidget> + +//! [0] +class ScribbleArea : public QWidget +{ + Q_OBJECT + +public: + ScribbleArea(QWidget *parent = 0); + + bool openImage(const QString &fileName); + bool saveImage(const QString &fileName, const char *fileFormat); + void setPenColor(const QColor &newColor); + void setPenWidth(int newWidth); + + bool isModified() const { return modified; } + QColor penColor() const { return myPenColor; } + int penWidth() const { return myPenWidth; } + +public slots: + void clearImage(); + void print(); + +protected: + void mousePressEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + void paintEvent(QPaintEvent *event); + void resizeEvent(QResizeEvent *event); + +private: + void drawLineTo(const QPoint &endPoint); + void resizeImage(QImage *image, const QSize &newSize); + + bool modified; + bool scribbling; + int myPenWidth; + QColor myPenColor; + QImage image; + QPoint lastPoint; +}; +//! [0] + +#endif diff --git a/examples/widgets/shapedclock/main.cpp b/examples/widgets/shapedclock/main.cpp new file mode 100644 index 0000000..889aac1 --- /dev/null +++ b/examples/widgets/shapedclock/main.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> + +#include "shapedclock.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + ShapedClock clock; + clock.show(); + return app.exec(); +} diff --git a/examples/widgets/shapedclock/shapedclock.cpp b/examples/widgets/shapedclock/shapedclock.cpp new file mode 100644 index 0000000..9b8a282 --- /dev/null +++ b/examples/widgets/shapedclock/shapedclock.cpp @@ -0,0 +1,159 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "shapedclock.h" + +//! [0] +ShapedClock::ShapedClock(QWidget *parent) + : QWidget(parent, Qt::FramelessWindowHint | Qt::WindowSystemMenuHint) +{ + QTimer *timer = new QTimer(this); + connect(timer, SIGNAL(timeout()), this, SLOT(update())); + timer->start(1000); + + QAction *quitAction = new QAction(tr("E&xit"), this); + quitAction->setShortcut(tr("Ctrl+Q")); + connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); + addAction(quitAction); + + setContextMenuPolicy(Qt::ActionsContextMenu); + setToolTip(tr("Drag the clock with the left mouse button.\n" + "Use the right mouse button to open a context menu.")); + setWindowTitle(tr("Shaped Analog Clock")); +} +//! [0] + +//! [1] +void ShapedClock::mousePressEvent(QMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) { + dragPosition = event->globalPos() - frameGeometry().topLeft(); + event->accept(); + } +} +//! [1] + +//! [2] +void ShapedClock::mouseMoveEvent(QMouseEvent *event) +{ + if (event->buttons() & Qt::LeftButton) { + move(event->globalPos() - dragPosition); + event->accept(); + } +} +//! [2] + +//! [3] +void ShapedClock::paintEvent(QPaintEvent *) +{ + static const QPoint hourHand[3] = { + QPoint(7, 8), + QPoint(-7, 8), + QPoint(0, -40) + }; + static const QPoint minuteHand[3] = { + QPoint(7, 8), + QPoint(-7, 8), + QPoint(0, -70) + }; + + QColor hourColor(127, 0, 127); + QColor minuteColor(0, 127, 127, 191); + + int side = qMin(width(), height()); + QTime time = QTime::currentTime(); + + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); + painter.translate(width() / 2, height() / 2); + painter.scale(side / 200.0, side / 200.0); + + painter.setPen(Qt::NoPen); + painter.setBrush(hourColor); + + painter.save(); + painter.rotate(30.0 * ((time.hour() + time.minute() / 60.0))); + painter.drawConvexPolygon(hourHand, 3); + painter.restore(); + + painter.setPen(hourColor); + + for (int i = 0; i < 12; ++i) { + painter.drawLine(88, 0, 96, 0); + painter.rotate(30.0); + } + + painter.setPen(Qt::NoPen); + painter.setBrush(minuteColor); + + painter.save(); + painter.rotate(6.0 * (time.minute() + time.second() / 60.0)); + painter.drawConvexPolygon(minuteHand, 3); + painter.restore(); + + painter.setPen(minuteColor); + + for (int j = 0; j < 60; ++j) { + if ((j % 5) != 0) + painter.drawLine(92, 0, 96, 0); + painter.rotate(6.0); + } +} +//! [3] + +//! [4] +void ShapedClock::resizeEvent(QResizeEvent * /* event */) +{ + int side = qMin(width(), height()); + QRegion maskedRegion(width() / 2 - side / 2, height() / 2 - side / 2, side, + side, QRegion::Ellipse); + setMask(maskedRegion); +} +//! [4] + +//! [5] +QSize ShapedClock::sizeHint() const +{ + return QSize(100, 100); +} +//! [5] diff --git a/examples/widgets/shapedclock/shapedclock.h b/examples/widgets/shapedclock/shapedclock.h new file mode 100644 index 0000000..1de52e7 --- /dev/null +++ b/examples/widgets/shapedclock/shapedclock.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SHAPEDCLOCK_H +#define SHAPEDCLOCK_H + +#include <QWidget> + +//! [0] +class ShapedClock : public QWidget +{ + Q_OBJECT + +public: + ShapedClock(QWidget *parent = 0); + QSize sizeHint() const; + +protected: + void mouseMoveEvent(QMouseEvent *event); + void mousePressEvent(QMouseEvent *event); + void paintEvent(QPaintEvent *event); + void resizeEvent(QResizeEvent *event); + +private: + QPoint dragPosition; +}; +//! [0] + +#endif diff --git a/examples/widgets/shapedclock/shapedclock.pro b/examples/widgets/shapedclock/shapedclock.pro new file mode 100644 index 0000000..6ef5dd0 --- /dev/null +++ b/examples/widgets/shapedclock/shapedclock.pro @@ -0,0 +1,9 @@ +HEADERS = shapedclock.h +SOURCES = shapedclock.cpp \ + main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/widgets/shapedclock +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS shapedclock.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/shapedclock +INSTALLS += target sources diff --git a/examples/widgets/sliders/main.cpp b/examples/widgets/sliders/main.cpp new file mode 100644 index 0000000..fa8b0ab --- /dev/null +++ b/examples/widgets/sliders/main.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> + +#include "window.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + Window window; + window.show(); + return app.exec(); +} diff --git a/examples/widgets/sliders/sliders.pro b/examples/widgets/sliders/sliders.pro new file mode 100644 index 0000000..b845554 --- /dev/null +++ b/examples/widgets/sliders/sliders.pro @@ -0,0 +1,11 @@ +HEADERS = slidersgroup.h \ + window.h +SOURCES = main.cpp \ + slidersgroup.cpp \ + window.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/widgets/sliders +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS sliders.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/sliders +INSTALLS += target sources diff --git a/examples/widgets/sliders/slidersgroup.cpp b/examples/widgets/sliders/slidersgroup.cpp new file mode 100644 index 0000000..9a0b98b --- /dev/null +++ b/examples/widgets/sliders/slidersgroup.cpp @@ -0,0 +1,133 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "slidersgroup.h" + +//! [0] +SlidersGroup::SlidersGroup(Qt::Orientation orientation, const QString &title, + QWidget *parent) + : QGroupBox(title, parent) +{ + slider = new QSlider(orientation); + slider->setFocusPolicy(Qt::StrongFocus); + slider->setTickPosition(QSlider::TicksBothSides); + slider->setTickInterval(10); + slider->setSingleStep(1); + + scrollBar = new QScrollBar(orientation); + scrollBar->setFocusPolicy(Qt::StrongFocus); + + dial = new QDial; + dial->setFocusPolicy(Qt::StrongFocus); + + connect(slider, SIGNAL(valueChanged(int)), scrollBar, SLOT(setValue(int))); + connect(scrollBar, SIGNAL(valueChanged(int)), dial, SLOT(setValue(int))); + connect(dial, SIGNAL(valueChanged(int)), slider, SLOT(setValue(int))); +//! [0] //! [1] + connect(dial, SIGNAL(valueChanged(int)), this, SIGNAL(valueChanged(int))); +//! [1] //! [2] + +//! [2] //! [3] + QBoxLayout::Direction direction; +//! [3] //! [4] + + if (orientation == Qt::Horizontal) + direction = QBoxLayout::TopToBottom; + else + direction = QBoxLayout::LeftToRight; + + QBoxLayout *slidersLayout = new QBoxLayout(direction); + slidersLayout->addWidget(slider); + slidersLayout->addWidget(scrollBar); + slidersLayout->addWidget(dial); + setLayout(slidersLayout); +} +//! [4] + +//! [5] +void SlidersGroup::setValue(int value) +//! [5] //! [6] +{ + slider->setValue(value); +} +//! [6] + +//! [7] +void SlidersGroup::setMinimum(int value) +//! [7] //! [8] +{ + slider->setMinimum(value); + scrollBar->setMinimum(value); + dial->setMinimum(value); +} +//! [8] + +//! [9] +void SlidersGroup::setMaximum(int value) +//! [9] //! [10] +{ + slider->setMaximum(value); + scrollBar->setMaximum(value); + dial->setMaximum(value); +} +//! [10] + +//! [11] +void SlidersGroup::invertAppearance(bool invert) +//! [11] //! [12] +{ + slider->setInvertedAppearance(invert); + scrollBar->setInvertedAppearance(invert); + dial->setInvertedAppearance(invert); +} +//! [12] + +//! [13] +void SlidersGroup::invertKeyBindings(bool invert) +//! [13] //! [14] +{ + slider->setInvertedControls(invert); + scrollBar->setInvertedControls(invert); + dial->setInvertedControls(invert); +} +//! [14] diff --git a/examples/widgets/sliders/slidersgroup.h b/examples/widgets/sliders/slidersgroup.h new file mode 100644 index 0000000..1f2ea82 --- /dev/null +++ b/examples/widgets/sliders/slidersgroup.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SLIDERSGROUP_H +#define SLIDERSGROUP_H + +#include <QGroupBox> + +QT_BEGIN_NAMESPACE +class QDial; +class QScrollBar; +class QSlider; +QT_END_NAMESPACE + +//! [0] +class SlidersGroup : public QGroupBox +{ + Q_OBJECT + +public: + SlidersGroup(Qt::Orientation orientation, const QString &title, + QWidget *parent = 0); + +signals: + void valueChanged(int value); + +public slots: + void setValue(int value); + void setMinimum(int value); + void setMaximum(int value); + void invertAppearance(bool invert); + void invertKeyBindings(bool invert); + +private: + QSlider *slider; + QScrollBar *scrollBar; + QDial *dial; +}; +//! [0] + +#endif diff --git a/examples/widgets/sliders/window.cpp b/examples/widgets/sliders/window.cpp new file mode 100644 index 0000000..f74af74 --- /dev/null +++ b/examples/widgets/sliders/window.cpp @@ -0,0 +1,146 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "slidersgroup.h" +#include "window.h" + +//! [0] +Window::Window() +{ + horizontalSliders = new SlidersGroup(Qt::Horizontal, tr("Horizontal")); + verticalSliders = new SlidersGroup(Qt::Vertical, tr("Vertical")); + + stackedWidget = new QStackedWidget; + stackedWidget->addWidget(horizontalSliders); + stackedWidget->addWidget(verticalSliders); + + createControls(tr("Controls")); +//! [0] + +//! [1] + connect(horizontalSliders, SIGNAL(valueChanged(int)), +//! [1] //! [2] + verticalSliders, SLOT(setValue(int))); + connect(verticalSliders, SIGNAL(valueChanged(int)), + valueSpinBox, SLOT(setValue(int))); + connect(valueSpinBox, SIGNAL(valueChanged(int)), + horizontalSliders, SLOT(setValue(int))); + + QHBoxLayout *layout = new QHBoxLayout; + layout->addWidget(controlsGroup); + layout->addWidget(stackedWidget); + setLayout(layout); + + minimumSpinBox->setValue(0); + maximumSpinBox->setValue(20); + valueSpinBox->setValue(5); + + setWindowTitle(tr("Sliders")); +} +//! [2] + +//! [3] +void Window::createControls(const QString &title) +//! [3] //! [4] +{ + controlsGroup = new QGroupBox(title); + + minimumLabel = new QLabel(tr("Minimum value:")); + maximumLabel = new QLabel(tr("Maximum value:")); + valueLabel = new QLabel(tr("Current value:")); + + invertedAppearance = new QCheckBox(tr("Inverted appearance")); + invertedKeyBindings = new QCheckBox(tr("Inverted key bindings")); + +//! [4] //! [5] + minimumSpinBox = new QSpinBox; +//! [5] //! [6] + minimumSpinBox->setRange(-100, 100); + minimumSpinBox->setSingleStep(1); + + maximumSpinBox = new QSpinBox; + maximumSpinBox->setRange(-100, 100); + maximumSpinBox->setSingleStep(1); + + valueSpinBox = new QSpinBox; + valueSpinBox->setRange(-100, 100); + valueSpinBox->setSingleStep(1); + + orientationCombo = new QComboBox; + orientationCombo->addItem(tr("Horizontal slider-like widgets")); + orientationCombo->addItem(tr("Vertical slider-like widgets")); + +//! [6] //! [7] + connect(orientationCombo, SIGNAL(activated(int)), +//! [7] //! [8] + stackedWidget, SLOT(setCurrentIndex(int))); + connect(minimumSpinBox, SIGNAL(valueChanged(int)), + horizontalSliders, SLOT(setMinimum(int))); + connect(minimumSpinBox, SIGNAL(valueChanged(int)), + verticalSliders, SLOT(setMinimum(int))); + connect(maximumSpinBox, SIGNAL(valueChanged(int)), + horizontalSliders, SLOT(setMaximum(int))); + connect(maximumSpinBox, SIGNAL(valueChanged(int)), + verticalSliders, SLOT(setMaximum(int))); + connect(invertedAppearance, SIGNAL(toggled(bool)), + horizontalSliders, SLOT(invertAppearance(bool))); + connect(invertedAppearance, SIGNAL(toggled(bool)), + verticalSliders, SLOT(invertAppearance(bool))); + connect(invertedKeyBindings, SIGNAL(toggled(bool)), + horizontalSliders, SLOT(invertKeyBindings(bool))); + connect(invertedKeyBindings, SIGNAL(toggled(bool)), + verticalSliders, SLOT(invertKeyBindings(bool))); + + QGridLayout *controlsLayout = new QGridLayout; + controlsLayout->addWidget(minimumLabel, 0, 0); + controlsLayout->addWidget(maximumLabel, 1, 0); + controlsLayout->addWidget(valueLabel, 2, 0); + controlsLayout->addWidget(minimumSpinBox, 0, 1); + controlsLayout->addWidget(maximumSpinBox, 1, 1); + controlsLayout->addWidget(valueSpinBox, 2, 1); + controlsLayout->addWidget(invertedAppearance, 0, 2); + controlsLayout->addWidget(invertedKeyBindings, 1, 2); + controlsLayout->addWidget(orientationCombo, 3, 0, 1, 3); + controlsGroup->setLayout(controlsLayout); +} +//! [8] diff --git a/examples/widgets/sliders/window.h b/examples/widgets/sliders/window.h new file mode 100644 index 0000000..e8854fb --- /dev/null +++ b/examples/widgets/sliders/window.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include <QWidget> + +QT_BEGIN_NAMESPACE +class QCheckBox; +class QComboBox; +class QGroupBox; +class QLabel; +class QSpinBox; +class QStackedWidget; +QT_END_NAMESPACE +class SlidersGroup; + +//! [0] +class Window : public QWidget +{ + Q_OBJECT + +public: + Window(); + +private: + void createControls(const QString &title); + + SlidersGroup *horizontalSliders; + SlidersGroup *verticalSliders; + QStackedWidget *stackedWidget; + + QGroupBox *controlsGroup; + QLabel *minimumLabel; + QLabel *maximumLabel; + QLabel *valueLabel; + QCheckBox *invertedAppearance; + QCheckBox *invertedKeyBindings; + QSpinBox *minimumSpinBox; + QSpinBox *maximumSpinBox; + QSpinBox *valueSpinBox; + QComboBox *orientationCombo; +}; +//! [0] + +#endif diff --git a/examples/widgets/spinboxes/main.cpp b/examples/widgets/spinboxes/main.cpp new file mode 100644 index 0000000..fa8b0ab --- /dev/null +++ b/examples/widgets/spinboxes/main.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> + +#include "window.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + Window window; + window.show(); + return app.exec(); +} diff --git a/examples/widgets/spinboxes/spinboxes.pro b/examples/widgets/spinboxes/spinboxes.pro new file mode 100644 index 0000000..4edb79a --- /dev/null +++ b/examples/widgets/spinboxes/spinboxes.pro @@ -0,0 +1,9 @@ +HEADERS = window.h +SOURCES = main.cpp \ + window.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/widgets/spinboxes +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS spinboxes.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/spinboxes +INSTALLS += target sources diff --git a/examples/widgets/spinboxes/window.cpp b/examples/widgets/spinboxes/window.cpp new file mode 100644 index 0000000..0dae9c5 --- /dev/null +++ b/examples/widgets/spinboxes/window.cpp @@ -0,0 +1,252 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "window.h" + +//! [0] +Window::Window() +{ + createSpinBoxes(); + createDateTimeEdits(); + createDoubleSpinBoxes(); + + QHBoxLayout *layout = new QHBoxLayout; + layout->addWidget(spinBoxesGroup); + layout->addWidget(editsGroup); + layout->addWidget(doubleSpinBoxesGroup); + setLayout(layout); + + setWindowTitle(tr("Spin Boxes")); +} +//! [0] + +//! [1] +void Window::createSpinBoxes() +{ + spinBoxesGroup = new QGroupBox(tr("Spinboxes")); + + QLabel *integerLabel = new QLabel(tr("Enter a value between " + "%1 and %2:").arg(-20).arg(20)); + QSpinBox *integerSpinBox = new QSpinBox; + integerSpinBox->setRange(-20, 20); + integerSpinBox->setSingleStep(1); + integerSpinBox->setValue(0); +//! [1] + +//! [2] + QLabel *zoomLabel = new QLabel(tr("Enter a zoom value between " + "%1 and %2:").arg(0).arg(1000)); +//! [3] + QSpinBox *zoomSpinBox = new QSpinBox; + zoomSpinBox->setRange(0, 1000); + zoomSpinBox->setSingleStep(10); + zoomSpinBox->setSuffix("%"); + zoomSpinBox->setSpecialValueText(tr("Automatic")); + zoomSpinBox->setValue(100); +//! [2] //! [3] + +//! [4] + QLabel *priceLabel = new QLabel(tr("Enter a price between " + "%1 and %2:").arg(0).arg(999)); + QSpinBox *priceSpinBox = new QSpinBox; + priceSpinBox->setRange(0, 999); + priceSpinBox->setSingleStep(1); + priceSpinBox->setPrefix("$"); + priceSpinBox->setValue(99); +//! [4] //! [5] + + QVBoxLayout *spinBoxLayout = new QVBoxLayout; + spinBoxLayout->addWidget(integerLabel); + spinBoxLayout->addWidget(integerSpinBox); + spinBoxLayout->addWidget(zoomLabel); + spinBoxLayout->addWidget(zoomSpinBox); + spinBoxLayout->addWidget(priceLabel); + spinBoxLayout->addWidget(priceSpinBox); + spinBoxesGroup->setLayout(spinBoxLayout); +} +//! [5] + +//! [6] +void Window::createDateTimeEdits() +{ + editsGroup = new QGroupBox(tr("Date and time spin boxes")); + + QLabel *dateLabel = new QLabel; + QDateEdit *dateEdit = new QDateEdit(QDate::currentDate()); + dateEdit->setDateRange(QDate(2005, 1, 1), QDate(2010, 12, 31)); + dateLabel->setText(tr("Appointment date (between %0 and %1):") + .arg(dateEdit->minimumDate().toString(Qt::ISODate)) + .arg(dateEdit->maximumDate().toString(Qt::ISODate))); +//! [6] + +//! [7] + QLabel *timeLabel = new QLabel; + QTimeEdit *timeEdit = new QTimeEdit(QTime::currentTime()); + timeEdit->setTimeRange(QTime(9, 0, 0, 0), QTime(16, 30, 0, 0)); + timeLabel->setText(tr("Appointment time (between %0 and %1):") + .arg(timeEdit->minimumTime().toString(Qt::ISODate)) + .arg(timeEdit->maximumTime().toString(Qt::ISODate))); +//! [7] + +//! [8] + meetingLabel = new QLabel; + meetingEdit = new QDateTimeEdit(QDateTime::currentDateTime()); +//! [8] + +//! [9] + QLabel *formatLabel = new QLabel(tr("Format string for the meeting date " + "and time:")); + QComboBox *formatComboBox = new QComboBox; + formatComboBox->addItem("yyyy-MM-dd hh:mm:ss (zzz 'ms')"); + formatComboBox->addItem("hh:mm:ss MM/dd/yyyy"); + formatComboBox->addItem("hh:mm:ss dd/MM/yyyy"); + formatComboBox->addItem("hh:mm:ss"); + formatComboBox->addItem("hh:mm ap"); +//! [9] //! [10] + + connect(formatComboBox, SIGNAL(activated(const QString &)), + this, SLOT(setFormatString(const QString &))); +//! [10] + + setFormatString(formatComboBox->currentText()); + +//! [11] + QVBoxLayout *editsLayout = new QVBoxLayout; + editsLayout->addWidget(dateLabel); + editsLayout->addWidget(dateEdit); + editsLayout->addWidget(timeLabel); + editsLayout->addWidget(timeEdit); + editsLayout->addWidget(meetingLabel); + editsLayout->addWidget(meetingEdit); + editsLayout->addWidget(formatLabel); + editsLayout->addWidget(formatComboBox); + editsGroup->setLayout(editsLayout); +} +//! [11] + +//! [12] +void Window::setFormatString(const QString &formatString) +{ + meetingEdit->setDisplayFormat(formatString); +//! [12] //! [13] + if (meetingEdit->displayedSections() & QDateTimeEdit::DateSections_Mask) { + meetingEdit->setDateRange(QDate(2004, 11, 1), QDate(2005, 11, 30)); + meetingLabel->setText(tr("Meeting date (between %0 and %1):") + .arg(meetingEdit->minimumDate().toString(Qt::ISODate)) + .arg(meetingEdit->maximumDate().toString(Qt::ISODate))); + } else { + meetingEdit->setTimeRange(QTime(0, 7, 20, 0), QTime(21, 0, 0, 0)); + meetingLabel->setText(tr("Meeting time (between %0 and %1):") + .arg(meetingEdit->minimumTime().toString(Qt::ISODate)) + .arg(meetingEdit->maximumTime().toString(Qt::ISODate))); + } +} +//! [13] + +//! [14] +void Window::createDoubleSpinBoxes() +{ + doubleSpinBoxesGroup = new QGroupBox(tr("Double precision spinboxes")); + + QLabel *precisionLabel = new QLabel(tr("Number of decimal places " + "to show:")); + QSpinBox *precisionSpinBox = new QSpinBox; + precisionSpinBox->setRange(0, 100); + precisionSpinBox->setValue(2); +//! [14] + +//! [15] + QLabel *doubleLabel = new QLabel(tr("Enter a value between " + "%1 and %2:").arg(-20).arg(20)); + doubleSpinBox = new QDoubleSpinBox; + doubleSpinBox->setRange(-20.0, 20.0); + doubleSpinBox->setSingleStep(1.0); + doubleSpinBox->setValue(0.0); +//! [15] + +//! [16] + QLabel *scaleLabel = new QLabel(tr("Enter a scale factor between " + "%1 and %2:").arg(0).arg(1000.0)); + scaleSpinBox = new QDoubleSpinBox; + scaleSpinBox->setRange(0.0, 1000.0); + scaleSpinBox->setSingleStep(10.0); + scaleSpinBox->setSuffix("%"); + scaleSpinBox->setSpecialValueText(tr("No scaling")); + scaleSpinBox->setValue(100.0); +//! [16] + +//! [17] + QLabel *priceLabel = new QLabel(tr("Enter a price between " + "%1 and %2:").arg(0).arg(1000)); + priceSpinBox = new QDoubleSpinBox; + priceSpinBox->setRange(0.0, 1000.0); + priceSpinBox->setSingleStep(1.0); + priceSpinBox->setPrefix("$"); + priceSpinBox->setValue(99.99); + + connect(precisionSpinBox, SIGNAL(valueChanged(int)), +//! [17] + this, SLOT(changePrecision(int))); + +//! [18] + QVBoxLayout *spinBoxLayout = new QVBoxLayout; + spinBoxLayout->addWidget(precisionLabel); + spinBoxLayout->addWidget(precisionSpinBox); + spinBoxLayout->addWidget(doubleLabel); + spinBoxLayout->addWidget(doubleSpinBox); + spinBoxLayout->addWidget(scaleLabel); + spinBoxLayout->addWidget(scaleSpinBox); + spinBoxLayout->addWidget(priceLabel); + spinBoxLayout->addWidget(priceSpinBox); + doubleSpinBoxesGroup->setLayout(spinBoxLayout); +} +//! [18] + +//! [19] +void Window::changePrecision(int decimals) +{ + doubleSpinBox->setDecimals(decimals); + scaleSpinBox->setDecimals(decimals); + priceSpinBox->setDecimals(decimals); +} +//! [19] diff --git a/examples/widgets/spinboxes/window.h b/examples/widgets/spinboxes/window.h new file mode 100644 index 0000000..68055f6 --- /dev/null +++ b/examples/widgets/spinboxes/window.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include <QWidget> + +QT_BEGIN_NAMESPACE +class QDateTimeEdit; +class QDoubleSpinBox; +class QGroupBox; +class QLabel; +QT_END_NAMESPACE + +//! [0] +class Window : public QWidget +{ + Q_OBJECT + +public: + Window(); + +public slots: + void changePrecision(int decimals); + void setFormatString(const QString &formatString); + +private: + void createSpinBoxes(); + void createDateTimeEdits(); + void createDoubleSpinBoxes(); + + QDateTimeEdit *meetingEdit; + QDoubleSpinBox *doubleSpinBox; + QDoubleSpinBox *priceSpinBox; + QDoubleSpinBox *scaleSpinBox; + QGroupBox *spinBoxesGroup; + QGroupBox *editsGroup; + QGroupBox *doubleSpinBoxesGroup; + QLabel *meetingLabel; +}; +//! [0] + +#endif diff --git a/examples/widgets/styles/images/woodbackground.png b/examples/widgets/styles/images/woodbackground.png Binary files differnew file mode 100644 index 0000000..8be3366 --- /dev/null +++ b/examples/widgets/styles/images/woodbackground.png diff --git a/examples/widgets/styles/images/woodbutton.png b/examples/widgets/styles/images/woodbutton.png Binary files differnew file mode 100644 index 0000000..adb59ef --- /dev/null +++ b/examples/widgets/styles/images/woodbutton.png diff --git a/examples/widgets/styles/main.cpp b/examples/widgets/styles/main.cpp new file mode 100644 index 0000000..8998858 --- /dev/null +++ b/examples/widgets/styles/main.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> + +#include "widgetgallery.h" + +int main(int argc, char *argv[]) +{ + Q_INIT_RESOURCE(styles); + + QApplication app(argc, argv); + WidgetGallery gallery; + gallery.show(); + return app.exec(); +} diff --git a/examples/widgets/styles/norwegianwoodstyle.cpp b/examples/widgets/styles/norwegianwoodstyle.cpp new file mode 100644 index 0000000..1be5db0 --- /dev/null +++ b/examples/widgets/styles/norwegianwoodstyle.cpp @@ -0,0 +1,331 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "norwegianwoodstyle.h" + +//! [0] +void NorwegianWoodStyle::polish(QPalette &palette) +{ + QColor brown(212, 140, 95); + QColor beige(236, 182, 120); + QColor slightlyOpaqueBlack(0, 0, 0, 63); + + QPixmap backgroundImage(":/images/woodbackground.png"); + QPixmap buttonImage(":/images/woodbutton.png"); + QPixmap midImage = buttonImage; + + QPainter painter; + painter.begin(&midImage); + painter.setPen(Qt::NoPen); + painter.fillRect(midImage.rect(), slightlyOpaqueBlack); + painter.end(); +//! [0] + +//! [1] + palette = QPalette(brown); + + palette.setBrush(QPalette::BrightText, Qt::white); + palette.setBrush(QPalette::Base, beige); + palette.setBrush(QPalette::Highlight, Qt::darkGreen); + setTexture(palette, QPalette::Button, buttonImage); + setTexture(palette, QPalette::Mid, midImage); + setTexture(palette, QPalette::Window, backgroundImage); + + QBrush brush = palette.background(); + brush.setColor(brush.color().dark()); + + palette.setBrush(QPalette::Disabled, QPalette::WindowText, brush); + palette.setBrush(QPalette::Disabled, QPalette::Text, brush); + palette.setBrush(QPalette::Disabled, QPalette::ButtonText, brush); + palette.setBrush(QPalette::Disabled, QPalette::Base, brush); + palette.setBrush(QPalette::Disabled, QPalette::Button, brush); + palette.setBrush(QPalette::Disabled, QPalette::Mid, brush); +} +//! [1] + +//! [3] +void NorwegianWoodStyle::polish(QWidget *widget) +//! [3] //! [4] +{ + if (qobject_cast<QPushButton *>(widget) + || qobject_cast<QComboBox *>(widget)) + widget->setAttribute(Qt::WA_Hover, true); +} +//! [4] + +//! [5] +void NorwegianWoodStyle::unpolish(QWidget *widget) +//! [5] //! [6] +{ + if (qobject_cast<QPushButton *>(widget) + || qobject_cast<QComboBox *>(widget)) + widget->setAttribute(Qt::WA_Hover, false); +} +//! [6] + +//! [7] +int NorwegianWoodStyle::pixelMetric(PixelMetric metric, +//! [7] //! [8] + const QStyleOption *option, + const QWidget *widget) const +{ + switch (metric) { + case PM_ComboBoxFrameWidth: + return 8; + case PM_ScrollBarExtent: + return QMotifStyle::pixelMetric(metric, option, widget) + 4; + default: + return QMotifStyle::pixelMetric(metric, option, widget); + } +} +//! [8] + +//! [9] +int NorwegianWoodStyle::styleHint(StyleHint hint, const QStyleOption *option, +//! [9] //! [10] + const QWidget *widget, + QStyleHintReturn *returnData) const +{ + switch (hint) { + case SH_DitherDisabledText: + return int(false); + case SH_EtchDisabledText: + return int(true); + default: + return QMotifStyle::styleHint(hint, option, widget, returnData); + } +} +//! [10] + +//! [11] +void NorwegianWoodStyle::drawPrimitive(PrimitiveElement element, +//! [11] //! [12] + const QStyleOption *option, + QPainter *painter, + const QWidget *widget) const +{ + switch (element) { + case PE_PanelButtonCommand: + { + int delta = (option->state & State_MouseOver) ? 64 : 0; + QColor slightlyOpaqueBlack(0, 0, 0, 63); + QColor semiTransparentWhite(255, 255, 255, 127 + delta); + QColor semiTransparentBlack(0, 0, 0, 127 - delta); + + int x, y, width, height; + option->rect.getRect(&x, &y, &width, &height); +//! [12] + +//! [13] + QPainterPath roundRect = roundRectPath(option->rect); +//! [13] //! [14] + int radius = qMin(width, height) / 2; +//! [14] + +//! [15] + QBrush brush; +//! [15] //! [16] + bool darker; + + const QStyleOptionButton *buttonOption = + qstyleoption_cast<const QStyleOptionButton *>(option); + if (buttonOption + && (buttonOption->features & QStyleOptionButton::Flat)) { + brush = option->palette.background(); + darker = (option->state & (State_Sunken | State_On)); + } else { + if (option->state & (State_Sunken | State_On)) { + brush = option->palette.mid(); + darker = !(option->state & State_Sunken); + } else { + brush = option->palette.button(); + darker = false; +//! [16] //! [17] + } +//! [17] //! [18] + } +//! [18] + +//! [19] + painter->save(); +//! [19] //! [20] + painter->setRenderHint(QPainter::Antialiasing, true); +//! [20] //! [21] + painter->fillPath(roundRect, brush); +//! [21] //! [22] + if (darker) +//! [22] //! [23] + painter->fillPath(roundRect, slightlyOpaqueBlack); +//! [23] + +//! [24] + int penWidth; +//! [24] //! [25] + if (radius < 10) + penWidth = 3; + else if (radius < 20) + penWidth = 5; + else + penWidth = 7; + + QPen topPen(semiTransparentWhite, penWidth); + QPen bottomPen(semiTransparentBlack, penWidth); + + if (option->state & (State_Sunken | State_On)) + qSwap(topPen, bottomPen); +//! [25] + +//! [26] + int x1 = x; + int x2 = x + radius; + int x3 = x + width - radius; + int x4 = x + width; + + if (option->direction == Qt::RightToLeft) { + qSwap(x1, x4); + qSwap(x2, x3); + } + + QPolygon topHalf; + topHalf << QPoint(x1, y) + << QPoint(x4, y) + << QPoint(x3, y + radius) + << QPoint(x2, y + height - radius) + << QPoint(x1, y + height); + + painter->setClipPath(roundRect); + painter->setClipRegion(topHalf, Qt::IntersectClip); + painter->setPen(topPen); + painter->drawPath(roundRect); +//! [26] //! [32] + + QPolygon bottomHalf = topHalf; + bottomHalf[0] = QPoint(x4, y + height); + + painter->setClipPath(roundRect); + painter->setClipRegion(bottomHalf, Qt::IntersectClip); + painter->setPen(bottomPen); + painter->drawPath(roundRect); + + painter->setPen(option->palette.foreground().color()); + painter->setClipping(false); + painter->drawPath(roundRect); + + painter->restore(); + } + break; +//! [32] //! [33] + default: +//! [33] //! [34] + QMotifStyle::drawPrimitive(element, option, painter, widget); + } +} +//! [34] + +//! [35] +void NorwegianWoodStyle::drawControl(ControlElement element, +//! [35] //! [36] + const QStyleOption *option, + QPainter *painter, + const QWidget *widget) const +{ + switch (element) { + case CE_PushButtonLabel: + { + QStyleOptionButton myButtonOption; + const QStyleOptionButton *buttonOption = + qstyleoption_cast<const QStyleOptionButton *>(option); + if (buttonOption) { + myButtonOption = *buttonOption; + if (myButtonOption.palette.currentColorGroup() + != QPalette::Disabled) { + if (myButtonOption.state & (State_Sunken | State_On)) { + myButtonOption.palette.setBrush(QPalette::ButtonText, + myButtonOption.palette.brightText()); + } + } + } + QMotifStyle::drawControl(element, &myButtonOption, painter, widget); + } + break; + default: + QMotifStyle::drawControl(element, option, painter, widget); + } +} +//! [36] + +//! [37] +void NorwegianWoodStyle::setTexture(QPalette &palette, QPalette::ColorRole role, +//! [37] //! [38] + const QPixmap &pixmap) +{ + for (int i = 0; i < QPalette::NColorGroups; ++i) { + QColor color = palette.brush(QPalette::ColorGroup(i), role).color(); + palette.setBrush(QPalette::ColorGroup(i), role, QBrush(color, pixmap)); + } +} +//! [38] + +//! [39] +QPainterPath NorwegianWoodStyle::roundRectPath(const QRect &rect) +//! [39] //! [40] +{ + int radius = qMin(rect.width(), rect.height()) / 2; + int diam = 2 * radius; + + int x1, y1, x2, y2; + rect.getCoords(&x1, &y1, &x2, &y2); + + QPainterPath path; + path.moveTo(x2, y1 + radius); + path.arcTo(QRect(x2 - diam, y1, diam, diam), 0.0, +90.0); + path.lineTo(x1 + radius, y1); + path.arcTo(QRect(x1, y1, diam, diam), 90.0, +90.0); + path.lineTo(x1, y2 - radius); + path.arcTo(QRect(x1, y2 - diam, diam, diam), 180.0, +90.0); + path.lineTo(x1 + radius, y2); + path.arcTo(QRect(x2 - diam, y2 - diam, diam, diam), 270.0, +90.0); + path.closeSubpath(); + return path; +} +//! [40] diff --git a/examples/widgets/styles/norwegianwoodstyle.h b/examples/widgets/styles/norwegianwoodstyle.h new file mode 100644 index 0000000..07c7797 --- /dev/null +++ b/examples/widgets/styles/norwegianwoodstyle.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef NORWEGIANWOODSTYLE_H +#define NORWEGIANWOODSTYLE_H + +#include <QMotifStyle> +#include <QPalette> + +QT_BEGIN_NAMESPACE +class QPainterPath; +QT_END_NAMESPACE + +//! [0] +class NorwegianWoodStyle : public QMotifStyle +{ + Q_OBJECT + +public: + NorwegianWoodStyle() {} + + void polish(QPalette &palette); + void polish(QWidget *widget); + void unpolish(QWidget *widget); + int pixelMetric(PixelMetric metric, const QStyleOption *option, + const QWidget *widget) const; + int styleHint(StyleHint hint, const QStyleOption *option, + const QWidget *widget, QStyleHintReturn *returnData) const; + void drawPrimitive(PrimitiveElement element, const QStyleOption *option, + QPainter *painter, const QWidget *widget) const; + void drawControl(ControlElement control, const QStyleOption *option, + QPainter *painter, const QWidget *widget) const; + +private: + static void setTexture(QPalette &palette, QPalette::ColorRole role, + const QPixmap &pixmap); + static QPainterPath roundRectPath(const QRect &rect); +}; +//! [0] + +#endif diff --git a/examples/widgets/styles/styles.pro b/examples/widgets/styles/styles.pro new file mode 100644 index 0000000..4c6c682 --- /dev/null +++ b/examples/widgets/styles/styles.pro @@ -0,0 +1,14 @@ +HEADERS = norwegianwoodstyle.h \ + widgetgallery.h +SOURCES = main.cpp \ + norwegianwoodstyle.cpp \ + widgetgallery.cpp +RESOURCES = styles.qrc + +REQUIRES += "contains(styles, motif)" + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/widgets/styles +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS styles.pro images +sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/styles +INSTALLS += target sources diff --git a/examples/widgets/styles/styles.qrc b/examples/widgets/styles/styles.qrc new file mode 100644 index 0000000..4fdad8d --- /dev/null +++ b/examples/widgets/styles/styles.qrc @@ -0,0 +1,6 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>images/woodbutton.png</file> + <file>images/woodbackground.png</file> +</qresource> +</RCC> diff --git a/examples/widgets/styles/widgetgallery.cpp b/examples/widgets/styles/widgetgallery.cpp new file mode 100644 index 0000000..9a071a6 --- /dev/null +++ b/examples/widgets/styles/widgetgallery.cpp @@ -0,0 +1,276 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "norwegianwoodstyle.h" +#include "widgetgallery.h" + +//! [0] +WidgetGallery::WidgetGallery(QWidget *parent) + : QDialog(parent) +{ + originalPalette = QApplication::palette(); + + styleComboBox = new QComboBox; + styleComboBox->addItem("NorwegianWood"); + styleComboBox->addItems(QStyleFactory::keys()); + + styleLabel = new QLabel(tr("&Style:")); + styleLabel->setBuddy(styleComboBox); + + useStylePaletteCheckBox = new QCheckBox(tr("&Use style's standard palette")); + useStylePaletteCheckBox->setChecked(true); + + disableWidgetsCheckBox = new QCheckBox(tr("&Disable widgets")); + + createTopLeftGroupBox(); + createTopRightGroupBox(); + createBottomLeftTabWidget(); + createBottomRightGroupBox(); + createProgressBar(); +//! [0] + +//! [1] + connect(styleComboBox, SIGNAL(activated(const QString &)), +//! [1] //! [2] + this, SLOT(changeStyle(const QString &))); + connect(useStylePaletteCheckBox, SIGNAL(toggled(bool)), + this, SLOT(changePalette())); + connect(disableWidgetsCheckBox, SIGNAL(toggled(bool)), + topLeftGroupBox, SLOT(setDisabled(bool))); + connect(disableWidgetsCheckBox, SIGNAL(toggled(bool)), + topRightGroupBox, SLOT(setDisabled(bool))); + connect(disableWidgetsCheckBox, SIGNAL(toggled(bool)), + bottomLeftTabWidget, SLOT(setDisabled(bool))); + connect(disableWidgetsCheckBox, SIGNAL(toggled(bool)), + bottomRightGroupBox, SLOT(setDisabled(bool))); +//! [2] + +//! [3] + QHBoxLayout *topLayout = new QHBoxLayout; +//! [3] //! [4] + topLayout->addWidget(styleLabel); + topLayout->addWidget(styleComboBox); + topLayout->addStretch(1); + topLayout->addWidget(useStylePaletteCheckBox); + topLayout->addWidget(disableWidgetsCheckBox); + + QGridLayout *mainLayout = new QGridLayout; + mainLayout->addLayout(topLayout, 0, 0, 1, 2); + mainLayout->addWidget(topLeftGroupBox, 1, 0); + mainLayout->addWidget(topRightGroupBox, 1, 1); + mainLayout->addWidget(bottomLeftTabWidget, 2, 0); + mainLayout->addWidget(bottomRightGroupBox, 2, 1); + mainLayout->addWidget(progressBar, 3, 0, 1, 2); + mainLayout->setRowStretch(1, 1); + mainLayout->setRowStretch(2, 1); + mainLayout->setColumnStretch(0, 1); + mainLayout->setColumnStretch(1, 1); + setLayout(mainLayout); + + setWindowTitle(tr("Styles")); + changeStyle("NorwegianWood"); +} +//! [4] + +//! [5] +void WidgetGallery::changeStyle(const QString &styleName) +//! [5] //! [6] +{ + if (styleName == "NorwegianWood") { + QApplication::setStyle(new NorwegianWoodStyle); + } else { + QApplication::setStyle(QStyleFactory::create(styleName)); + } + changePalette(); +} +//! [6] + +//! [7] +void WidgetGallery::changePalette() +//! [7] //! [8] +{ + if (useStylePaletteCheckBox->isChecked()) + QApplication::setPalette(QApplication::style()->standardPalette()); + else + QApplication::setPalette(originalPalette); +} +//! [8] + +//! [9] +void WidgetGallery::advanceProgressBar() +//! [9] //! [10] +{ + int curVal = progressBar->value(); + int maxVal = progressBar->maximum(); + progressBar->setValue(curVal + (maxVal - curVal) / 100); +} +//! [10] + +//! [11] +void WidgetGallery::createTopLeftGroupBox() +//! [11] //! [12] +{ + topLeftGroupBox = new QGroupBox(tr("Group 1")); + + radioButton1 = new QRadioButton(tr("Radio button 1")); + radioButton2 = new QRadioButton(tr("Radio button 2")); + radioButton3 = new QRadioButton(tr("Radio button 3")); + radioButton1->setChecked(true); + + checkBox = new QCheckBox(tr("Tri-state check box")); + checkBox->setTristate(true); + checkBox->setCheckState(Qt::PartiallyChecked); + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(radioButton1); + layout->addWidget(radioButton2); + layout->addWidget(radioButton3); + layout->addWidget(checkBox); + layout->addStretch(1); + topLeftGroupBox->setLayout(layout); +} +//! [12] + +void WidgetGallery::createTopRightGroupBox() +{ + topRightGroupBox = new QGroupBox(tr("Group 2")); + + defaultPushButton = new QPushButton(tr("Default Push Button")); + defaultPushButton->setDefault(true); + + togglePushButton = new QPushButton(tr("Toggle Push Button")); + togglePushButton->setCheckable(true); + togglePushButton->setChecked(true); + + flatPushButton = new QPushButton(tr("Flat Push Button")); + flatPushButton->setFlat(true); + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(defaultPushButton); + layout->addWidget(togglePushButton); + layout->addWidget(flatPushButton); + layout->addStretch(1); + topRightGroupBox->setLayout(layout); +} + +void WidgetGallery::createBottomLeftTabWidget() +{ + bottomLeftTabWidget = new QTabWidget; + bottomLeftTabWidget->setSizePolicy(QSizePolicy::Preferred, + QSizePolicy::Ignored); + + QWidget *tab1 = new QWidget; + tableWidget = new QTableWidget(10, 10); + + QHBoxLayout *tab1hbox = new QHBoxLayout; + tab1hbox->setMargin(5); + tab1hbox->addWidget(tableWidget); + tab1->setLayout(tab1hbox); + + QWidget *tab2 = new QWidget; + textEdit = new QTextEdit; + + textEdit->setPlainText(tr("Twinkle, twinkle, little star,\n" + "How I wonder what you are.\n" + "Up above the world so high,\n" + "Like a diamond in the sky.\n" + "Twinkle, twinkle, little star,\n" + "How I wonder what you are!\n")); + + QHBoxLayout *tab2hbox = new QHBoxLayout; + tab2hbox->setMargin(5); + tab2hbox->addWidget(textEdit); + tab2->setLayout(tab2hbox); + + bottomLeftTabWidget->addTab(tab1, tr("&Table")); + bottomLeftTabWidget->addTab(tab2, tr("Text &Edit")); +} + +void WidgetGallery::createBottomRightGroupBox() +{ + bottomRightGroupBox = new QGroupBox(tr("Group 3")); + bottomRightGroupBox->setCheckable(true); + bottomRightGroupBox->setChecked(true); + + lineEdit = new QLineEdit("s3cRe7"); + lineEdit->setEchoMode(QLineEdit::Password); + + spinBox = new QSpinBox(bottomRightGroupBox); + spinBox->setValue(50); + + dateTimeEdit = new QDateTimeEdit(bottomRightGroupBox); + dateTimeEdit->setDateTime(QDateTime::currentDateTime()); + + slider = new QSlider(Qt::Horizontal, bottomRightGroupBox); + slider->setValue(40); + + scrollBar = new QScrollBar(Qt::Horizontal, bottomRightGroupBox); + scrollBar->setValue(60); + + dial = new QDial(bottomRightGroupBox); + dial->setValue(30); + dial->setNotchesVisible(true); + + QGridLayout *layout = new QGridLayout; + layout->addWidget(lineEdit, 0, 0, 1, 2); + layout->addWidget(spinBox, 1, 0, 1, 2); + layout->addWidget(dateTimeEdit, 2, 0, 1, 2); + layout->addWidget(slider, 3, 0); + layout->addWidget(scrollBar, 4, 0); + layout->addWidget(dial, 3, 1, 2, 1); + layout->setRowStretch(5, 1); + bottomRightGroupBox->setLayout(layout); +} + +//! [13] +void WidgetGallery::createProgressBar() +{ + progressBar = new QProgressBar; + progressBar->setRange(0, 10000); + progressBar->setValue(0); + + QTimer *timer = new QTimer(this); + connect(timer, SIGNAL(timeout()), this, SLOT(advanceProgressBar())); + timer->start(1000); +} +//! [13] diff --git a/examples/widgets/styles/widgetgallery.h b/examples/widgets/styles/widgetgallery.h new file mode 100644 index 0000000..f9f1723 --- /dev/null +++ b/examples/widgets/styles/widgetgallery.h @@ -0,0 +1,122 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WIDGETGALLERY_H +#define WIDGETGALLERY_H + +#include <QDialog> + +QT_BEGIN_NAMESPACE +class QCheckBox; +class QComboBox; +class QDateTimeEdit; +class QDial; +class QGroupBox; +class QLabel; +class QLineEdit; +class QProgressBar; +class QPushButton; +class QRadioButton; +class QScrollBar; +class QSlider; +class QSpinBox; +class QTabWidget; +class QTableWidget; +class QTextEdit; +QT_END_NAMESPACE + +//! [0] +class WidgetGallery : public QDialog +{ + Q_OBJECT + +public: + WidgetGallery(QWidget *parent = 0); + +private slots: + void changeStyle(const QString &styleName); + void changePalette(); + void advanceProgressBar(); + +private: + void createTopLeftGroupBox(); + void createTopRightGroupBox(); + void createBottomLeftTabWidget(); + void createBottomRightGroupBox(); + void createProgressBar(); + + QPalette originalPalette; + + QLabel *styleLabel; + QComboBox *styleComboBox; + QCheckBox *useStylePaletteCheckBox; + QCheckBox *disableWidgetsCheckBox; +//! [0] + + QGroupBox *topLeftGroupBox; + QRadioButton *radioButton1; + QRadioButton *radioButton2; + QRadioButton *radioButton3; + QCheckBox *checkBox; + + QGroupBox *topRightGroupBox; + QPushButton *defaultPushButton; + QPushButton *togglePushButton; + QPushButton *flatPushButton; + + QTabWidget *bottomLeftTabWidget; + QTableWidget *tableWidget; + QTextEdit *textEdit; + + QGroupBox *bottomRightGroupBox; + QLineEdit *lineEdit; + QSpinBox *spinBox; + QDateTimeEdit *dateTimeEdit; + QSlider *slider; + QScrollBar *scrollBar; + QDial *dial; + + QProgressBar *progressBar; +//! [1] +}; +//! [1] + +#endif diff --git a/examples/widgets/stylesheet/images/checkbox_checked.png b/examples/widgets/stylesheet/images/checkbox_checked.png Binary files differnew file mode 100644 index 0000000..cbf06f6 --- /dev/null +++ b/examples/widgets/stylesheet/images/checkbox_checked.png diff --git a/examples/widgets/stylesheet/images/checkbox_checked_hover.png b/examples/widgets/stylesheet/images/checkbox_checked_hover.png Binary files differnew file mode 100644 index 0000000..fb4d4d3 --- /dev/null +++ b/examples/widgets/stylesheet/images/checkbox_checked_hover.png diff --git a/examples/widgets/stylesheet/images/checkbox_checked_pressed.png b/examples/widgets/stylesheet/images/checkbox_checked_pressed.png Binary files differnew file mode 100644 index 0000000..852fcc0 --- /dev/null +++ b/examples/widgets/stylesheet/images/checkbox_checked_pressed.png diff --git a/examples/widgets/stylesheet/images/checkbox_unchecked.png b/examples/widgets/stylesheet/images/checkbox_unchecked.png Binary files differnew file mode 100644 index 0000000..5f54655 --- /dev/null +++ b/examples/widgets/stylesheet/images/checkbox_unchecked.png diff --git a/examples/widgets/stylesheet/images/checkbox_unchecked_hover.png b/examples/widgets/stylesheet/images/checkbox_unchecked_hover.png Binary files differnew file mode 100644 index 0000000..6873644 --- /dev/null +++ b/examples/widgets/stylesheet/images/checkbox_unchecked_hover.png diff --git a/examples/widgets/stylesheet/images/checkbox_unchecked_pressed.png b/examples/widgets/stylesheet/images/checkbox_unchecked_pressed.png Binary files differnew file mode 100644 index 0000000..6a768c4 --- /dev/null +++ b/examples/widgets/stylesheet/images/checkbox_unchecked_pressed.png diff --git a/examples/widgets/stylesheet/images/down_arrow.png b/examples/widgets/stylesheet/images/down_arrow.png Binary files differnew file mode 100644 index 0000000..85004ae --- /dev/null +++ b/examples/widgets/stylesheet/images/down_arrow.png diff --git a/examples/widgets/stylesheet/images/down_arrow_disabled.png b/examples/widgets/stylesheet/images/down_arrow_disabled.png Binary files differnew file mode 100644 index 0000000..d9eefed --- /dev/null +++ b/examples/widgets/stylesheet/images/down_arrow_disabled.png diff --git a/examples/widgets/stylesheet/images/frame.png b/examples/widgets/stylesheet/images/frame.png Binary files differnew file mode 100644 index 0000000..05a6005 --- /dev/null +++ b/examples/widgets/stylesheet/images/frame.png diff --git a/examples/widgets/stylesheet/images/pagefold.png b/examples/widgets/stylesheet/images/pagefold.png Binary files differnew file mode 100644 index 0000000..69be8f2 --- /dev/null +++ b/examples/widgets/stylesheet/images/pagefold.png diff --git a/examples/widgets/stylesheet/images/pushbutton.png b/examples/widgets/stylesheet/images/pushbutton.png Binary files differnew file mode 100644 index 0000000..c7529ba --- /dev/null +++ b/examples/widgets/stylesheet/images/pushbutton.png diff --git a/examples/widgets/stylesheet/images/pushbutton_hover.png b/examples/widgets/stylesheet/images/pushbutton_hover.png Binary files differnew file mode 100644 index 0000000..af0ef9d --- /dev/null +++ b/examples/widgets/stylesheet/images/pushbutton_hover.png diff --git a/examples/widgets/stylesheet/images/pushbutton_pressed.png b/examples/widgets/stylesheet/images/pushbutton_pressed.png Binary files differnew file mode 100644 index 0000000..f7381f7 --- /dev/null +++ b/examples/widgets/stylesheet/images/pushbutton_pressed.png diff --git a/examples/widgets/stylesheet/images/radiobutton_checked.png b/examples/widgets/stylesheet/images/radiobutton_checked.png Binary files differnew file mode 100644 index 0000000..8ab9157 --- /dev/null +++ b/examples/widgets/stylesheet/images/radiobutton_checked.png diff --git a/examples/widgets/stylesheet/images/radiobutton_checked_hover.png b/examples/widgets/stylesheet/images/radiobutton_checked_hover.png Binary files differnew file mode 100644 index 0000000..d68cb00 --- /dev/null +++ b/examples/widgets/stylesheet/images/radiobutton_checked_hover.png diff --git a/examples/widgets/stylesheet/images/radiobutton_checked_pressed.png b/examples/widgets/stylesheet/images/radiobutton_checked_pressed.png Binary files differnew file mode 100644 index 0000000..e3cd5a5 --- /dev/null +++ b/examples/widgets/stylesheet/images/radiobutton_checked_pressed.png diff --git a/examples/widgets/stylesheet/images/radiobutton_unchecked.png b/examples/widgets/stylesheet/images/radiobutton_unchecked.png Binary files differnew file mode 100644 index 0000000..321a9a1 --- /dev/null +++ b/examples/widgets/stylesheet/images/radiobutton_unchecked.png diff --git a/examples/widgets/stylesheet/images/radiobutton_unchecked_hover.png b/examples/widgets/stylesheet/images/radiobutton_unchecked_hover.png Binary files differnew file mode 100644 index 0000000..666a3b0 --- /dev/null +++ b/examples/widgets/stylesheet/images/radiobutton_unchecked_hover.png diff --git a/examples/widgets/stylesheet/images/radiobutton_unchecked_pressed.png b/examples/widgets/stylesheet/images/radiobutton_unchecked_pressed.png Binary files differnew file mode 100644 index 0000000..c4b0567 --- /dev/null +++ b/examples/widgets/stylesheet/images/radiobutton_unchecked_pressed.png diff --git a/examples/widgets/stylesheet/images/sizegrip.png b/examples/widgets/stylesheet/images/sizegrip.png Binary files differnew file mode 100644 index 0000000..350583a --- /dev/null +++ b/examples/widgets/stylesheet/images/sizegrip.png diff --git a/examples/widgets/stylesheet/images/spindown.png b/examples/widgets/stylesheet/images/spindown.png Binary files differnew file mode 100644 index 0000000..7ff3c64 --- /dev/null +++ b/examples/widgets/stylesheet/images/spindown.png diff --git a/examples/widgets/stylesheet/images/spindown_hover.png b/examples/widgets/stylesheet/images/spindown_hover.png Binary files differnew file mode 100644 index 0000000..1486c4d --- /dev/null +++ b/examples/widgets/stylesheet/images/spindown_hover.png diff --git a/examples/widgets/stylesheet/images/spindown_off.png b/examples/widgets/stylesheet/images/spindown_off.png Binary files differnew file mode 100644 index 0000000..a90ab3f --- /dev/null +++ b/examples/widgets/stylesheet/images/spindown_off.png diff --git a/examples/widgets/stylesheet/images/spindown_pressed.png b/examples/widgets/stylesheet/images/spindown_pressed.png Binary files differnew file mode 100644 index 0000000..f6271cb --- /dev/null +++ b/examples/widgets/stylesheet/images/spindown_pressed.png diff --git a/examples/widgets/stylesheet/images/spinup.png b/examples/widgets/stylesheet/images/spinup.png Binary files differnew file mode 100644 index 0000000..1069dd0 --- /dev/null +++ b/examples/widgets/stylesheet/images/spinup.png diff --git a/examples/widgets/stylesheet/images/spinup_hover.png b/examples/widgets/stylesheet/images/spinup_hover.png Binary files differnew file mode 100644 index 0000000..884c8d7 --- /dev/null +++ b/examples/widgets/stylesheet/images/spinup_hover.png diff --git a/examples/widgets/stylesheet/images/spinup_off.png b/examples/widgets/stylesheet/images/spinup_off.png Binary files differnew file mode 100644 index 0000000..02dad1f --- /dev/null +++ b/examples/widgets/stylesheet/images/spinup_off.png diff --git a/examples/widgets/stylesheet/images/spinup_pressed.png b/examples/widgets/stylesheet/images/spinup_pressed.png Binary files differnew file mode 100644 index 0000000..b1843e2 --- /dev/null +++ b/examples/widgets/stylesheet/images/spinup_pressed.png diff --git a/examples/widgets/stylesheet/images/up_arrow.png b/examples/widgets/stylesheet/images/up_arrow.png Binary files differnew file mode 100644 index 0000000..e7f7ddb --- /dev/null +++ b/examples/widgets/stylesheet/images/up_arrow.png diff --git a/examples/widgets/stylesheet/images/up_arrow_disabled.png b/examples/widgets/stylesheet/images/up_arrow_disabled.png Binary files differnew file mode 100644 index 0000000..4d2c277 --- /dev/null +++ b/examples/widgets/stylesheet/images/up_arrow_disabled.png diff --git a/examples/widgets/stylesheet/layouts/default.ui b/examples/widgets/stylesheet/layouts/default.ui new file mode 100644 index 0000000..431a409 --- /dev/null +++ b/examples/widgets/stylesheet/layouts/default.ui @@ -0,0 +1,329 @@ +<ui version="4.0" > + <class>MainWindow</class> + <widget class="QMainWindow" name="MainWindow" > + <property name="geometry" > + <rect> + <x>0</x> + <y>0</y> + <width>388</width> + <height>413</height> + </rect> + </property> + <property name="windowTitle" > + <string>MainWindow</string> + </property> + <widget class="QWidget" name="centralwidget" > + <layout class="QGridLayout" > + <property name="margin" > + <number>9</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item row="0" column="0" > + <widget class="QLabel" name="nameLabel" > + <property name="text" > + <string>&Name:</string> + </property> + <property name="buddy" > + <cstring>nameCombo</cstring> + </property> + </widget> + </item> + <item row="0" column="1" colspan="3" > + <widget class="QComboBox" name="nameCombo" > + <property name="toolTip" > + <string>Specify your name</string> + </property> + <property name="editable" > + <bool>true</bool> + </property> + <property name="currentIndex" > + <number>-1</number> + </property> + <item> + <property name="text" > + <string>Girish</string> + </property> + </item> + <item> + <property name="text" > + <string>Jasmin</string> + </property> + </item> + <item> + <property name="text" > + <string>Simon</string> + </property> + </item> + <item> + <property name="text" > + <string>Zack</string> + </property> + </item> + </widget> + </item> + <item row="1" column="3" > + <spacer> + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" > + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item row="1" column="2" > + <widget class="QRadioButton" name="femaleRadioButton" > + <property name="toolTip" > + <string>Check this if you are female</string> + </property> + <property name="text" > + <string>&Female</string> + </property> + </widget> + </item> + <item row="6" column="0" colspan="4" > + <widget class="QCheckBox" name="agreeCheckBox" > + <property name="toolTip" > + <string>Please read the license before checking this</string> + </property> + <property name="text" > + <string>I &accept the terms and conditions</string> + </property> + </widget> + </item> + <item row="1" column="1" > + <widget class="QRadioButton" name="maleRadioButton" > + <property name="toolTip" > + <string>Check this if you are male</string> + </property> + <property name="text" > + <string>&Male</string> + </property> + </widget> + </item> + <item row="1" column="0" > + <widget class="QLabel" name="genderLabel" > + <property name="text" > + <string>Gender:</string> + </property> + </widget> + </item> + <item row="2" column="1" colspan="3" > + <widget class="QSpinBox" name="ageSpinBox" > + <property name="toolTip" > + <string>Specify your age</string> + </property> + <property name="statusTip" > + <string>Specify your age here</string> + </property> + <property name="minimum" > + <number>12</number> + </property> + <property name="value" > + <number>22</number> + </property> + </widget> + </item> + <item row="7" column="2" colspan="2" > + <widget class="QDialogButtonBox" name="buttonBox" > + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons" > + <set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + <item row="2" column="0" > + <widget class="QLabel" name="ageLabel" > + <property name="text" > + <string>&Age:</string> + </property> + <property name="buddy" > + <cstring>ageSpinBox</cstring> + </property> + </widget> + </item> + <item row="3" column="0" > + <widget class="QLabel" name="passwordLabel" > + <property name="text" > + <string>&Password:</string> + </property> + <property name="buddy" > + <cstring>passwordEdit</cstring> + </property> + </widget> + </item> + <item row="3" column="1" colspan="3" > + <widget class="QLineEdit" name="passwordEdit" > + <property name="toolTip" > + <string>Specify your password</string> + </property> + <property name="statusTip" > + <string>Specify your password here</string> + </property> + <property name="text" > + <string>Password</string> + </property> + <property name="echoMode" > + <enum>QLineEdit::Password</enum> + </property> + </widget> + </item> + <item row="5" column="0" > + <widget class="QLabel" name="label" > + <property name="text" > + <string>Profession</string> + </property> + <property name="buddy" > + <cstring>professionList</cstring> + </property> + </widget> + </item> + <item row="4" column="0" > + <widget class="QLabel" name="countryLabel" > + <property name="text" > + <string>&Country</string> + </property> + <property name="buddy" > + <cstring>professionList</cstring> + </property> + </widget> + </item> + <item row="5" column="1" colspan="3" > + <widget class="QListWidget" name="professionList" > + <property name="toolTip" > + <string>Select your profession</string> + </property> + <property name="statusTip" > + <string>Select your profession</string> + </property> + <property name="whatsThis" > + <string>Select your profession</string> + </property> + <property name="currentRow" > + <number>1</number> + </property> + <item> + <property name="text" > + <string>Developer</string> + </property> + </item> + <item> + <property name="text" > + <string>Student</string> + </property> + </item> + <item> + <property name="text" > + <string>Fisherman</string> + </property> + </item> + </widget> + </item> + <item row="4" column="1" colspan="3" > + <widget class="QComboBox" name="countryCombo" > + <property name="toolTip" > + <string>Specify your country</string> + </property> + <property name="statusTip" > + <string>Specify your country here</string> + </property> + <property name="currentIndex" > + <number>2</number> + </property> + <item> + <property name="text" > + <string>Germany</string> + </property> + </item> + <item> + <property name="text" > + <string>India</string> + </property> + </item> + <item> + <property name="text" > + <string>Norway</string> + </property> + </item> + <item> + <property name="text" > + <string>United States Of America</string> + </property> + </item> + <item> + <property name="text" > + <string>United Kingdom</string> + </property> + </item> + </widget> + </item> + </layout> + </widget> + <widget class="QMenuBar" name="menubar" > + <property name="geometry" > + <rect> + <x>0</x> + <y>0</y> + <width>388</width> + <height>21</height> + </rect> + </property> + <widget class="QMenu" name="menu_File" > + <property name="title" > + <string>&File</string> + </property> + <addaction name="editStyleAction" /> + <addaction name="separator" /> + <addaction name="exitAction" /> + </widget> + <widget class="QMenu" name="menu_Help" > + <property name="title" > + <string>&Help</string> + </property> + <addaction name="aboutAction" /> + <addaction name="separator" /> + <addaction name="aboutQtAction" /> + </widget> + <addaction name="menu_File" /> + <addaction name="menu_Help" /> + </widget> + <widget class="QStatusBar" name="statusbar" /> + <action name="exitAction" > + <property name="text" > + <string>&Exit</string> + </property> + </action> + <action name="aboutQtAction" > + <property name="text" > + <string>About Qt</string> + </property> + </action> + <action name="editStyleAction" > + <property name="text" > + <string>Edit &Style</string> + </property> + </action> + <action name="aboutAction" > + <property name="text" > + <string>About</string> + </property> + </action> + </widget> + <tabstops> + <tabstop>maleRadioButton</tabstop> + <tabstop>femaleRadioButton</tabstop> + <tabstop>ageSpinBox</tabstop> + <tabstop>passwordEdit</tabstop> + <tabstop>professionList</tabstop> + <tabstop>agreeCheckBox</tabstop> + </tabstops> + <resources/> + <connections/> +</ui> diff --git a/examples/widgets/stylesheet/layouts/pagefold.ui b/examples/widgets/stylesheet/layouts/pagefold.ui new file mode 100644 index 0000000..7ae313c --- /dev/null +++ b/examples/widgets/stylesheet/layouts/pagefold.ui @@ -0,0 +1,349 @@ +<ui version="4.0" > + <class>MainWindow</class> + <widget class="QMainWindow" name="MainWindow" > + <property name="geometry" > + <rect> + <x>0</x> + <y>0</y> + <width>392</width> + <height>412</height> + </rect> + </property> + <property name="windowTitle" > + <string>MainWindow</string> + </property> + <widget class="QWidget" name="centralwidget" > + <layout class="QVBoxLayout" > + <property name="margin" > + <number>9</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <widget class="QFrame" name="mainFrame" > + <property name="frameShape" > + <enum>QFrame::StyledPanel</enum> + </property> + <property name="frameShadow" > + <enum>QFrame::Raised</enum> + </property> + <layout class="QGridLayout" > + <property name="margin" > + <number>9</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item row="0" column="1" colspan="3" > + <widget class="QComboBox" name="nameCombo" > + <property name="toolTip" > + <string>Specify your name</string> + </property> + <property name="editable" > + <bool>true</bool> + </property> + <property name="currentIndex" > + <number>-1</number> + </property> + <item> + <property name="text" > + <string>Girish</string> + </property> + </item> + <item> + <property name="text" > + <string>Jasmin</string> + </property> + </item> + <item> + <property name="text" > + <string>Simon</string> + </property> + </item> + <item> + <property name="text" > + <string>Zack</string> + </property> + </item> + </widget> + </item> + <item row="1" column="3" > + <spacer> + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" > + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item row="1" column="2" > + <widget class="QRadioButton" name="femaleRadioButton" > + <property name="styleSheet" > + <string>Check this if you are female</string> + </property> + <property name="text" > + <string>&Female</string> + </property> + </widget> + </item> + <item row="1" column="0" > + <widget class="QLabel" name="genderLabel" > + <property name="text" > + <string>Gender:</string> + </property> + </widget> + </item> + <item row="2" column="0" > + <widget class="QLabel" name="ageLabel" > + <property name="text" > + <string>&Age:</string> + </property> + <property name="buddy" > + <cstring>ageSpinBox</cstring> + </property> + </widget> + </item> + <item row="1" column="1" > + <widget class="QRadioButton" name="maleRadioButton" > + <property name="toolTip" > + <string>Check this if you are male</string> + </property> + <property name="text" > + <string>&Male</string> + </property> + </widget> + </item> + <item row="0" column="0" > + <widget class="QLabel" name="nameLabel" > + <property name="text" > + <string>&Name:</string> + </property> + <property name="buddy" > + <cstring>nameCombo</cstring> + </property> + </widget> + </item> + <item row="3" column="0" > + <widget class="QLabel" name="passwordLabel" > + <property name="text" > + <string>&Password:</string> + </property> + <property name="buddy" > + <cstring>passwordEdit</cstring> + </property> + </widget> + </item> + <item row="2" column="1" colspan="3" > + <widget class="QSpinBox" name="ageSpinBox" > + <property name="toolTip" > + <string>Specify your age</string> + </property> + <property name="statusTip" > + <string>Specify your age</string> + </property> + <property name="minimum" > + <number>12</number> + </property> + <property name="value" > + <number>22</number> + </property> + </widget> + </item> + <item row="7" column="2" colspan="2" > + <widget class="QDialogButtonBox" name="buttonBox" > + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons" > + <set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + <item row="6" column="0" colspan="4" > + <widget class="QCheckBox" name="agreeCheckBox" > + <property name="toolTip" > + <string>Please read the LICENSE file before checking</string> + </property> + <property name="text" > + <string>I &accept the terms and &conditions</string> + </property> + </widget> + </item> + <item row="3" column="1" colspan="3" > + <widget class="QLineEdit" name="passwordEdit" > + <property name="toolTip" > + <string>Specify your password</string> + </property> + <property name="statusTip" > + <string>Specify your password</string> + </property> + <property name="text" > + <string>Password</string> + </property> + <property name="echoMode" > + <enum>QLineEdit::Password</enum> + </property> + </widget> + </item> + <item row="5" column="1" colspan="3" > + <widget class="QListWidget" name="professionList" > + <property name="toolTip" > + <string>Select your profession</string> + </property> + <property name="statusTip" > + <string>Specify your name here</string> + </property> + <property name="whatsThis" > + <string>Specify your name here</string> + </property> + <property name="currentRow" > + <number>0</number> + </property> + <item> + <property name="text" > + <string>Developer</string> + </property> + </item> + <item> + <property name="text" > + <string>Student</string> + </property> + </item> + <item> + <property name="text" > + <string>Fisherman</string> + </property> + </item> + </widget> + </item> + <item row="5" column="0" > + <widget class="QLabel" name="label" > + <property name="text" > + <string>Profession:</string> + </property> + <property name="buddy" > + <cstring>professionList</cstring> + </property> + </widget> + </item> + <item row="4" column="1" colspan="3" > + <widget class="QComboBox" name="countryCombo" > + <property name="toolTip" > + <string>Specify country of origin</string> + </property> + <property name="statusTip" > + <string>Specify country of origin</string> + </property> + <property name="currentIndex" > + <number>6</number> + </property> + <item> + <property name="text" > + <string>Egypt</string> + </property> + </item> + <item> + <property name="text" > + <string>France</string> + </property> + </item> + <item> + <property name="text" > + <string>Germany</string> + </property> + </item> + <item> + <property name="text" > + <string>India</string> + </property> + </item> + <item> + <property name="text" > + <string>Italy</string> + </property> + </item> + <item> + <property name="text" > + <string>Korea</string> + </property> + </item> + <item> + <property name="text" > + <string>Norway</string> + </property> + </item> + </widget> + </item> + <item row="4" column="0" > + <widget class="QLabel" name="countryLabel" > + <property name="text" > + <string>Pro&fession</string> + </property> + <property name="buddy" > + <cstring>professionList</cstring> + </property> + </widget> + </item> + </layout> + </widget> + </item> + </layout> + </widget> + <widget class="QMenuBar" name="menubar" > + <property name="geometry" > + <rect> + <x>0</x> + <y>0</y> + <width>392</width> + <height>25</height> + </rect> + </property> + <widget class="QMenu" name="menu_File" > + <property name="title" > + <string>&File</string> + </property> + <addaction name="editStyleAction" /> + <addaction name="separator" /> + <addaction name="exitAction" /> + </widget> + <widget class="QMenu" name="menu_Help" > + <property name="title" > + <string>&Help</string> + </property> + <addaction name="aboutAction" /> + <addaction name="separator" /> + <addaction name="aboutQtAction" /> + </widget> + <addaction name="menu_File" /> + <addaction name="menu_Help" /> + </widget> + <widget class="QStatusBar" name="statusbar" /> + <action name="exitAction" > + <property name="text" > + <string>&Exit</string> + </property> + </action> + <action name="aboutQtAction" > + <property name="text" > + <string>About Qt</string> + </property> + </action> + <action name="editStyleAction" > + <property name="text" > + <string>Edit &Style</string> + </property> + </action> + <action name="aboutAction" > + <property name="text" > + <string>About</string> + </property> + </action> + </widget> + <resources/> + <connections/> +</ui> diff --git a/examples/widgets/stylesheet/main.cpp b/examples/widgets/stylesheet/main.cpp new file mode 100644 index 0000000..931a89b --- /dev/null +++ b/examples/widgets/stylesheet/main.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + Q_INIT_RESOURCE(stylesheet); + + QApplication app(argc, argv); + MainWindow window; + window.show(); + return app.exec(); +} diff --git a/examples/widgets/stylesheet/mainwindow.cpp b/examples/widgets/stylesheet/mainwindow.cpp new file mode 100644 index 0000000..a1307a8 --- /dev/null +++ b/examples/widgets/stylesheet/mainwindow.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "mainwindow.h" +#include "stylesheeteditor.h" + +MainWindow::MainWindow() +{ + ui.setupUi(this); + + ui.nameLabel->setProperty("class", "mandatory QLabel"); + + styleSheetEditor = new StyleSheetEditor(this); + + statusBar()->addWidget(new QLabel(tr("Ready"))); + + connect(ui.exitAction, SIGNAL(triggered()), qApp, SLOT(quit())); + connect(ui.aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt())); +} + +void MainWindow::on_editStyleAction_triggered() +{ + styleSheetEditor->show(); + styleSheetEditor->activateWindow(); +} + +void MainWindow::on_aboutAction_triggered() +{ + QMessageBox::about(this, tr("About Style sheet"), + tr("The <b>Style Sheet</b> example shows how widgets can be styled " + "using <a href=\"http://doc.trolltech.com/4.5/stylesheet.html\">Qt " + "Style Sheets</a>. Click <b>File|Edit Style Sheet</b> to pop up the " + "style editor, and either choose an existing style sheet or design " + "your own.")); +} diff --git a/examples/widgets/stylesheet/mainwindow.h b/examples/widgets/stylesheet/mainwindow.h new file mode 100644 index 0000000..eedca88 --- /dev/null +++ b/examples/widgets/stylesheet/mainwindow.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include <QtGui> + +#include "ui_mainwindow.h" + +class StyleSheetEditor; + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +private slots: + void on_editStyleAction_triggered(); + void on_aboutAction_triggered(); + +private: + StyleSheetEditor *styleSheetEditor; + Ui::MainWindow ui; +}; + +#endif diff --git a/examples/widgets/stylesheet/mainwindow.ui b/examples/widgets/stylesheet/mainwindow.ui new file mode 100644 index 0000000..740d37b --- /dev/null +++ b/examples/widgets/stylesheet/mainwindow.ui @@ -0,0 +1,356 @@ +<ui version="4.0" > + <class>MainWindow</class> + <widget class="QMainWindow" name="MainWindow" > + <property name="geometry" > + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>413</height> + </rect> + </property> + <property name="windowTitle" > + <string>Style Sheet</string> + </property> + <widget class="QWidget" name="centralwidget" > + <layout class="QVBoxLayout" > + <property name="margin" > + <number>9</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <widget class="QFrame" name="mainFrame" > + <property name="frameShape" > + <enum>QFrame::StyledPanel</enum> + </property> + <property name="frameShadow" > + <enum>QFrame::Raised</enum> + </property> + <layout class="QGridLayout" > + <property name="margin" > + <number>9</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item row="6" column="0" colspan="5" > + <widget class="QCheckBox" name="agreeCheckBox" > + <property name="toolTip" > + <string>Please read the LICENSE file before checking</string> + </property> + <property name="text" > + <string>I &accept the terms and &conditions</string> + </property> + </widget> + </item> + <item row="5" column="0" > + <widget class="QLabel" name="label" > + <property name="text" > + <string>Profession:</string> + </property> + <property name="alignment" > + <set>Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing</set> + </property> + <property name="buddy" > + <cstring>professionList</cstring> + </property> + </widget> + </item> + <item row="0" column="0" > + <widget class="QLabel" name="nameLabel" > + <property name="text" > + <string>&Name:</string> + </property> + <property name="alignment" > + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + <property name="buddy" > + <cstring>nameCombo</cstring> + </property> + </widget> + </item> + <item row="1" column="1" > + <widget class="QRadioButton" name="maleRadioButton" > + <property name="toolTip" > + <string>Check this if you are male</string> + </property> + <property name="text" > + <string>&Male</string> + </property> + </widget> + </item> + <item row="3" column="0" > + <widget class="QLabel" name="passwordLabel" > + <property name="text" > + <string>&Password:</string> + </property> + <property name="alignment" > + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + <property name="buddy" > + <cstring>passwordEdit</cstring> + </property> + </widget> + </item> + <item row="4" column="1" colspan="4" > + <widget class="QComboBox" name="countryCombo" > + <property name="toolTip" > + <string>Specify country of origin</string> + </property> + <property name="statusTip" > + <string>Specify country of origin</string> + </property> + <property name="currentIndex" > + <number>6</number> + </property> + <item> + <property name="text" > + <string>Egypt</string> + </property> + </item> + <item> + <property name="text" > + <string>France</string> + </property> + </item> + <item> + <property name="text" > + <string>Germany</string> + </property> + </item> + <item> + <property name="text" > + <string>India</string> + </property> + </item> + <item> + <property name="text" > + <string>Italy</string> + </property> + </item> + <item> + <property name="text" > + <string>Norway</string> + </property> + </item> + <item> + <property name="text" > + <string>Pakistan</string> + </property> + </item> + </widget> + </item> + <item row="2" column="0" > + <widget class="QLabel" name="ageLabel" > + <property name="text" > + <string>&Age:</string> + </property> + <property name="alignment" > + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + <property name="buddy" > + <cstring>ageSpinBox</cstring> + </property> + </widget> + </item> + <item row="4" column="0" > + <widget class="QLabel" name="countryLabel" > + <property name="text" > + <string>Country:</string> + </property> + <property name="alignment" > + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + <property name="buddy" > + <cstring>countryCombo</cstring> + </property> + </widget> + </item> + <item row="1" column="0" > + <widget class="QLabel" name="genderLabel" > + <property name="text" > + <string>Gender:</string> + </property> + <property name="alignment" > + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item row="3" column="1" colspan="4" > + <widget class="QLineEdit" name="passwordEdit" > + <property name="toolTip" > + <string>Specify your password</string> + </property> + <property name="statusTip" > + <string>Specify your password</string> + </property> + <property name="text" > + <string>Password</string> + </property> + <property name="echoMode" > + <enum>QLineEdit::Password</enum> + </property> + </widget> + </item> + <item row="1" column="2" colspan="2" > + <widget class="QRadioButton" name="femaleRadioButton" > + <property name="styleSheet" > + <string>Check this if you are female</string> + </property> + <property name="text" > + <string>&Female</string> + </property> + </widget> + </item> + <item row="2" column="1" colspan="2" > + <widget class="QSpinBox" name="ageSpinBox" > + <property name="toolTip" > + <string>Specify your age</string> + </property> + <property name="statusTip" > + <string>Specify your age</string> + </property> + <property name="minimum" > + <number>12</number> + </property> + <property name="value" > + <number>22</number> + </property> + </widget> + </item> + <item row="0" column="1" colspan="4" > + <widget class="QComboBox" name="nameCombo" > + <property name="toolTip" > + <string>Specify your name</string> + </property> + <property name="editable" > + <bool>true</bool> + </property> + </widget> + </item> + <item row="1" column="4" > + <spacer> + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" > + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item row="2" column="3" colspan="2" > + <spacer> + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" > + <size> + <width>61</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item row="7" column="3" colspan="2" > + <widget class="QDialogButtonBox" name="buttonBox" > + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons" > + <set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + <item row="5" column="1" colspan="4" > + <widget class="QListWidget" name="professionList" > + <property name="toolTip" > + <string>Select your profession</string> + </property> + <property name="statusTip" > + <string>Specify your name here</string> + </property> + <property name="whatsThis" > + <string>Specify your name here</string> + </property> + <property name="currentRow" > + <number>0</number> + </property> + <item> + <property name="text" > + <string>Developer</string> + </property> + </item> + <item> + <property name="text" > + <string>Student</string> + </property> + </item> + <item> + <property name="text" > + <string>Fisherman</string> + </property> + </item> + </widget> + </item> + </layout> + </widget> + </item> + </layout> + </widget> + <widget class="QMenuBar" name="menubar" > + <property name="geometry" > + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>29</height> + </rect> + </property> + <widget class="QMenu" name="menu_File" > + <property name="title" > + <string>&File</string> + </property> + <addaction name="editStyleAction" /> + <addaction name="separator" /> + <addaction name="exitAction" /> + </widget> + <widget class="QMenu" name="menu_Help" > + <property name="title" > + <string>&Help</string> + </property> + <addaction name="aboutAction" /> + <addaction name="aboutQtAction" /> + </widget> + <addaction name="menu_File" /> + <addaction name="menu_Help" /> + </widget> + <widget class="QStatusBar" name="statusbar" /> + <action name="exitAction" > + <property name="text" > + <string>&Exit</string> + </property> + </action> + <action name="aboutQtAction" > + <property name="text" > + <string>About Qt</string> + </property> + </action> + <action name="editStyleAction" > + <property name="text" > + <string>Edit &Style...</string> + </property> + </action> + <action name="aboutAction" > + <property name="text" > + <string>About</string> + </property> + </action> + </widget> + <resources/> + <connections/> +</ui> diff --git a/examples/widgets/stylesheet/qss/coffee.qss b/examples/widgets/stylesheet/qss/coffee.qss new file mode 100644 index 0000000..4571d42 --- /dev/null +++ b/examples/widgets/stylesheet/qss/coffee.qss @@ -0,0 +1,112 @@ +.QWidget { + background-color: beige; +} + +/* Nice Windows-XP-style password character. */ +QLineEdit[echoMode="2"] { + lineedit-password-character: 9679; +} + +/* We provide a min-width and min-height for push buttons + so that they look elegant regardless of the width of the text. */ +QPushButton { + background-color: palegoldenrod; + border-width: 2px; + border-color: darkkhaki; + border-style: solid; + border-radius: 5; + padding: 3px; + min-width: 9ex; + min-height: 2.5ex; +} + +QPushButton:hover { + background-color: khaki; +} + +/* Increase the padding, so the text is shifted when the button is + pressed. */ +QPushButton:pressed { + padding-left: 5px; + padding-top: 5px; + background-color: #d0d67c; +} + +QLabel, QAbstractButton { + font: bold; +} + +/* Mark mandatory fields with a brownish color. */ +.mandatory { + color: brown; +} + +/* Bold text on status bar looks awful. */ +QStatusBar QLabel { + font: normal; +} + +QStatusBar::item { + border-width: 1; + border-color: darkkhaki; + border-style: solid; + border-radius: 2; +} + +QComboBox, QLineEdit, QSpinBox, QTextEdit, QListView { + background-color: cornsilk; + selection-color: #0a214c; + selection-background-color: #C19A6B; +} + +QListView { + show-decoration-selected: 1; +} + +QListView::item:hover { + background-color: wheat; +} + +/* We reserve 1 pixel space in padding. When we get the focus, + we kill the padding and enlarge the border. This makes the items + glow. */ +QLineEdit, QFrame { + border-width: 2px; + padding: 1px; + border-style: solid; + border-color: darkkhaki; + border-radius: 5px; +} + +/* As mentioned above, eliminate the padding and increase the border. */ +QLineEdit:focus, QFrame:focus { + border-width: 3px; + padding: 0px; +} + +/* A QLabel is a QFrame ... */ +QLabel { + border: none; + padding: 0; + background: none; +} + +/* A QToolTip is a QLabel ... */ +QToolTip { + border: 2px solid darkkhaki; + padding: 5px; + border-radius: 3px; + opacity: 200; +} + +/* Nice to have the background color change when hovered. */ +QRadioButton:hover, QCheckBox:hover { + background-color: wheat; +} + +/* Force the dialog's buttons to follow the Windows guidelines. */ +QDialogButtonBox { + button-layout: 0; +} + + diff --git a/examples/widgets/stylesheet/qss/default.qss b/examples/widgets/stylesheet/qss/default.qss new file mode 100644 index 0000000..84eb5e0 --- /dev/null +++ b/examples/widgets/stylesheet/qss/default.qss @@ -0,0 +1 @@ +/* empty stylesheet */ diff --git a/examples/widgets/stylesheet/qss/pagefold.qss b/examples/widgets/stylesheet/qss/pagefold.qss new file mode 100644 index 0000000..3701fc7 --- /dev/null +++ b/examples/widgets/stylesheet/qss/pagefold.qss @@ -0,0 +1,299 @@ +/* Customize any plain widget that is a child of a QMainWindow. */ +QMainWindow > .QWidget { + background-color: gainsboro; + background-image: url(:/images/pagefold.png); + background-position: top right; + background-repeat: no-repeat +} + +/* Provide a padding for the layout inside the frame. The frame + exists only to provide a padding for the top-right image, so we + explicitly disable the border. */ +#mainFrame { + padding-right: 30px; + border-style: none; + border-image: none; /* since we set a border-image below */ +} + +/* mainFrame won't have this border-image since we have + explicitly set it to 'none' using a more specific selector. */ +QFrame, QLineEdit, QComboBox[editable="true"], QSpinBox { + border-image: url(:/images/frame.png) 4; + border-width: 3; +} + +QLabel { + border: none; + border-image: none; + padding: 0; + background: none; +} + +/* Make text in message boxes selectable. */ +QMessageBox { + /* LinksAccessibleByMouse | TextSelectableByMouse */ + messagebox-text-interaction-flags: 5; +} + +/* Set the selection colors for all widgets. */ +QWidget { + selection-color: black; + selection-background-color: Silver; + color: black; +} + +/* Make the entire row selected in item views. */ +QAbstractItemView { + show-decoration-selected: 1; +} + +/* Nice WindowsXP-style password character for password line edits. */ +QLineEdit[echoMode="2"] { + lineedit-password-character: 9679; +} + +/* Customize tooltips. */ +QToolTip { + background-color: rgb(200,200,255); + border-color: darkslategray; + border-width: 1px; + border-style: solid; + padding: 3px; + font: bold; + border-radius: 3px; + opacity: 200; +} + +/* Customize radio buttons. */ + +QRadioButton { + spacing: 5px; +} + +QRadioButton::indicator { + width: 13px; + height: 13px; +} + +QRadioButton::indicator::unchecked { + image: url(:/images/radiobutton_unchecked.png); +} + +QRadioButton::indicator:unchecked:hover { + image: url(:/images/radiobutton_unchecked_hover.png); +} + +QRadioButton::indicator:unchecked:pressed { + image: url(:/images/radiobutton_unchecked_pressed.png); +} + +QRadioButton::indicator::checked { + image: url(:/images/radiobutton_checked.png); +} + +QRadioButton::indicator:checked:hover { + image: url(:/images/radiobutton_checked_hover.png); +} + +QRadioButton::indicator:checked:pressed { + image: url(:/images/radiobutton_checked_pressed.png); +} + +/* Customize arrows. */ + +*::down-arrow, *::menu-indicator { + image: url(:/images/down_arrow.png); + width: 7px; + height: 7px; +} + +*::down-arrow:disabled, *::down-arrow:off { + image: url(:/images/down_arrow_disabled.png); +} + +*::up-arrow { + image: url(:/images/up_arrow.png); + width: 7px; + height: 7px; +} + +*::up-arrow:disabled, *::up-arrow:off { + image: url(:/images/up_arrow_disabled.png); +} + +/* Customize push buttons and comboboxes. Our read-only combobox + is very similar to a push button, so they share the same border image. */ + +QPushButton { + min-width: 4em; +} + +QPushButton, QComboBox[editable="false"], +QComboBox[editable="true"]::drop-down { + border-image: url(:/images/pushbutton.png) 5; + border-width: 5; +} + +QPushButton:hover, QComboBox[editable="false"]:hover, +QComboBox[editable="true"]::drop-down:hover, QMenuBar::item:hover { + border-image: url(:/images/pushbutton_hover.png) 5; + border-width: 5; +} + +QPushButton:pressed, QComboBox[editable="false"]:on, +QComboBox[editable="true"]::drop-down:on, QMenuBar::item:on { + border-image: url(:/images/pushbutton_pressed.png) 5; + border-width: 5; +} + +/* Customize read-only comboboxes. */ + +QComboBox[editable="false"] { + padding-left: 3px; + padding-right: 20px; /* space for the arrow */ +} + +QComboBox[editable="false"]::drop-down { + subcontrol-origin: padding; + subcontrol-position: top right; + width: 15px; + border-left-style: solid; + border-left-color: darkgray; + border-left-width: 1px; +} + +QComboBox[editable="false"]::down-arrow { + subcontrol-origin: content; + subcontrol-position: center; + position: relative; + left: 1px; /* 1 pixel dropdown border */ +} + +/* The combobox arrow is on when the popup is open. */ +QComboBox[editable="false"]::down-arrow:on { + position: relative; + top: 1px; + left: 2px; +} + +/* Customize editable comboboxes. */ + +QComboBox[editable="true"] { + padding-right: 16px; +} + +QComboBox[editable="true"]::drop-down { + subcontrol-origin: border; + subcontrol-position: top right; + width: 13px; + position: absolute; + top: 2px; + bottom: 2px; + right: 2px; +} + +QComboBox[editable="true"]::drop-down, +QComboBox[editable="true"]::drop-down:hover, +QComboBox[editable="true"]::drop-down:on { + border-width: 0px; + border-left-width: 3px; /* we need only left and center part */ +} + +/* Shift the arrow when it's open. */ +QComboBox[editable="true"]::down-arrow:on { + position: relative; + top: 1px; + left: 1px; +} + +/* Customize check boxes. */ +QCheckBox { + spacing: 5px; +} + +QCheckBox::indicator { + width: 13px; + height: 13px; +} + +QCheckBox::indicator:unchecked { + image: url(:/images/checkbox_unchecked.png); +} + +QCheckBox::indicator:unchecked:hover { + image: url(:/images/checkbox_unchecked_hover.png); +} + +QCheckBox::indicator:unchecked:pressed { + image: url(:/images/checkbox_unchecked_pressed.png); +} + +QCheckBox::indicator:checked { + image: url(:/images/checkbox_checked.png); +} + +QCheckBox::indicator:checked:hover { + image: url(:/images/checkbox_checked_hover.png); +} + +QCheckBox::indicator:checked:pressed { + image: url(:/images/checkbox_checked_pressed.png); +} + +/* Customize the size grip. */ +QSizeGrip { + image: url(:/images/sizegrip.png); + width: 16px; + height: 16px; +} + +/* Customize the menu bar. */ +QMenuBar { + border-image: none; + border-style: none; + border-width: 1px; + border-bottom-style: solid; + border-bottom-color: darkslategray; + padding: 2px; +} + +/* Customize spin boxes. */ + +QSpinBox { + padding-right: 15px; +} + +QSpinBox::up-button { + subcontrol-origin: border; + subcontrol-position: top right; + + width: 16px; /* 16 + 2*1px border-width = 15px padding + 3px parent border */ + border-image: url(:/images/spinup.png) 1; + border-width: 1px; +} + +QSpinBox::up-button:hover { + border-image: url(:/images/spinup_hover.png) 1; +} + +QSpinBox::up-button:pressed { + border-image: url(:/images/spinup_pressed.png) 1; +} + +QSpinBox::down-button { + subcontrol-origin: border; + subcontrol-position: bottom right; + + width: 16px; + border-image: url(:/images/spindown.png) 1; + border-width: 1px; + border-top-width: 0; +} + +QSpinBox::down-button:hover { + border-image: url(:/images/spindown_hover.png) 1; +} + +QSpinBox::down-button:pressed { + border-image: url(:/images/spindown_pressed.png) 1; +} diff --git a/examples/widgets/stylesheet/stylesheet.pro b/examples/widgets/stylesheet/stylesheet.pro new file mode 100644 index 0000000..9a64c00 --- /dev/null +++ b/examples/widgets/stylesheet/stylesheet.pro @@ -0,0 +1,14 @@ +HEADERS = mainwindow.h \ + stylesheeteditor.h +FORMS = mainwindow.ui \ + stylesheeteditor.ui +RESOURCES = stylesheet.qrc +SOURCES = main.cpp \ + mainwindow.cpp \ + stylesheeteditor.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/widgets/stylesheet +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro images layouts qss +sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/stylesheet +INSTALLS += target sources diff --git a/examples/widgets/stylesheet/stylesheet.qrc b/examples/widgets/stylesheet/stylesheet.qrc new file mode 100644 index 0000000..e1e61a9 --- /dev/null +++ b/examples/widgets/stylesheet/stylesheet.qrc @@ -0,0 +1,39 @@ +<RCC> +<qresource prefix="/"> + <file>layouts/default.ui</file> + <file>layouts/pagefold.ui</file> + <file>qss/coffee.qss</file> + <file>qss/default.qss</file> + <file>qss/pagefold.qss</file> + <file>images/pagefold.png</file> + <file>images/frame.png</file> + <file>images/radiobutton_unchecked.png</file> + <file>images/radiobutton_unchecked_pressed.png</file> + <file>images/radiobutton_unchecked_hover.png</file> + <file>images/radiobutton_checked.png</file> + <file>images/radiobutton_checked_pressed.png</file> + <file>images/radiobutton_checked_hover.png</file> + <file>images/pushbutton.png</file> + <file>images/pushbutton_hover.png</file> + <file>images/pushbutton_pressed.png</file> + <file>images/checkbox_unchecked.png</file> + <file>images/checkbox_unchecked_pressed.png</file> + <file>images/checkbox_unchecked_hover.png</file> + <file>images/checkbox_checked.png</file> + <file>images/checkbox_checked_pressed.png</file> + <file>images/checkbox_checked_hover.png</file> + <file>images/down_arrow.png</file> + <file>images/down_arrow_disabled.png</file> + <file>images/up_arrow.png</file> + <file>images/up_arrow_disabled.png</file> + <file>images/sizegrip.png</file> + <file>images/spinup.png</file> + <file>images/spinup_off.png</file> + <file>images/spinup_hover.png</file> + <file>images/spinup_pressed.png</file> + <file>images/spindown.png</file> + <file>images/spindown_off.png</file> + <file>images/spindown_hover.png</file> + <file>images/spindown_pressed.png</file> +</qresource> +</RCC> diff --git a/examples/widgets/stylesheet/stylesheeteditor.cpp b/examples/widgets/stylesheet/stylesheeteditor.cpp new file mode 100644 index 0000000..1210415 --- /dev/null +++ b/examples/widgets/stylesheet/stylesheeteditor.cpp @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "stylesheeteditor.h" + +StyleSheetEditor::StyleSheetEditor(QWidget *parent) + : QDialog(parent) +{ + ui.setupUi(this); + + QRegExp regExp(".(.*)\\+?Style"); + QString defaultStyle = QApplication::style()->metaObject()->className(); + + if (regExp.exactMatch(defaultStyle)) + defaultStyle = regExp.cap(1); + + ui.styleCombo->addItems(QStyleFactory::keys()); + ui.styleCombo->setCurrentIndex(ui.styleCombo->findText(defaultStyle, Qt::MatchContains)); + ui.styleSheetCombo->setCurrentIndex(ui.styleSheetCombo->findText("Coffee")); + loadStyleSheet("Coffee"); +} + +void StyleSheetEditor::on_styleCombo_activated(const QString &styleName) +{ + qApp->setStyle(styleName); + ui.applyButton->setEnabled(false); +} + +void StyleSheetEditor::on_styleSheetCombo_activated(const QString &sheetName) +{ + loadStyleSheet(sheetName); +} + +void StyleSheetEditor::on_styleTextEdit_textChanged() +{ + ui.applyButton->setEnabled(true); +} + +void StyleSheetEditor::on_applyButton_clicked() +{ + qApp->setStyleSheet(ui.styleTextEdit->toPlainText()); + ui.applyButton->setEnabled(false); +} + +void StyleSheetEditor::loadStyleSheet(const QString &sheetName) +{ + QFile file(":/qss/" + sheetName.toLower() + ".qss"); + file.open(QFile::ReadOnly); + QString styleSheet = QLatin1String(file.readAll()); + + ui.styleTextEdit->setPlainText(styleSheet); + qApp->setStyleSheet(styleSheet); + ui.applyButton->setEnabled(false); +} diff --git a/examples/widgets/stylesheet/stylesheeteditor.h b/examples/widgets/stylesheet/stylesheeteditor.h new file mode 100644 index 0000000..bd90f9e --- /dev/null +++ b/examples/widgets/stylesheet/stylesheeteditor.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef STYLESHEETEDITOR_H +#define STYLESHEETEDITOR_H + +#include <QDialog> + +#include "ui_stylesheeteditor.h" + +class StyleSheetEditor : public QDialog +{ + Q_OBJECT + +public: + StyleSheetEditor(QWidget *parent = 0); + +private slots: + void on_styleCombo_activated(const QString &styleName); + void on_styleSheetCombo_activated(const QString &styleSheetName); + void on_styleTextEdit_textChanged(); + void on_applyButton_clicked(); + +private: + void loadStyleSheet(const QString &sheetName); + + Ui::StyleSheetEditor ui; +}; + +#endif diff --git a/examples/widgets/stylesheet/stylesheeteditor.ui b/examples/widgets/stylesheet/stylesheeteditor.ui new file mode 100644 index 0000000..34cd7f6 --- /dev/null +++ b/examples/widgets/stylesheet/stylesheeteditor.ui @@ -0,0 +1,171 @@ +<ui version="4.0" > + <class>StyleSheetEditor</class> + <widget class="QWidget" name="StyleSheetEditor" > + <property name="geometry" > + <rect> + <x>0</x> + <y>0</y> + <width>445</width> + <height>289</height> + </rect> + </property> + <property name="windowTitle" > + <string>Style Editor</string> + </property> + <layout class="QGridLayout" > + <property name="margin" > + <number>9</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item row="0" column="6" > + <spacer> + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType" > + <enum>QSizePolicy::MinimumExpanding</enum> + </property> + <property name="sizeHint" > + <size> + <width>32</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item row="0" column="0" > + <spacer> + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType" > + <enum>QSizePolicy::MinimumExpanding</enum> + </property> + <property name="sizeHint" > + <size> + <width>32</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item row="0" column="5" > + <widget class="QComboBox" name="styleSheetCombo" > + <item> + <property name="text" > + <string>Default</string> + </property> + </item> + <item> + <property name="text" > + <string>Coffee</string> + </property> + </item> + <item> + <property name="text" > + <string>Pagefold</string> + </property> + </item> + </widget> + </item> + <item row="0" column="3" > + <spacer> + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType" > + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" > + <size> + <width>10</width> + <height>16</height> + </size> + </property> + </spacer> + </item> + <item row="0" column="2" > + <widget class="QComboBox" name="styleCombo" > + <property name="sizePolicy" > + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </item> + <item row="0" column="1" > + <widget class="QLabel" name="label_7" > + <property name="sizePolicy" > + <sizepolicy> + <hsizetype>0</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text" > + <string>Style:</string> + </property> + </widget> + </item> + <item row="2" column="0" colspan="7" > + <layout class="QHBoxLayout" > + <property name="margin" > + <number>0</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" > + <size> + <width>321</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QPushButton" name="applyButton" > + <property name="enabled" > + <bool>false</bool> + </property> + <property name="text" > + <string>&Apply</string> + </property> + </widget> + </item> + </layout> + </item> + <item row="1" column="0" colspan="7" > + <widget class="QTextEdit" name="styleTextEdit" /> + </item> + <item row="0" column="4" > + <widget class="QLabel" name="label_8" > + <property name="sizePolicy" > + <sizepolicy> + <hsizetype>0</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text" > + <string>Style Sheet:</string> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/examples/widgets/tablet/main.cpp b/examples/widgets/tablet/main.cpp new file mode 100644 index 0000000..15043a6 --- /dev/null +++ b/examples/widgets/tablet/main.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "mainwindow.h" +#include "tabletapplication.h" +#include "tabletcanvas.h" + +//! [0] +int main(int argv, char *args[]) +{ + TabletApplication app(argv, args); + TabletCanvas *canvas = new TabletCanvas; + app.setCanvas(canvas); + + MainWindow mainWindow(canvas); + mainWindow.resize(500, 500); + mainWindow.show(); + + return app.exec(); +} +//! [0] diff --git a/examples/widgets/tablet/mainwindow.cpp b/examples/widgets/tablet/mainwindow.cpp new file mode 100644 index 0000000..56a10cd --- /dev/null +++ b/examples/widgets/tablet/mainwindow.cpp @@ -0,0 +1,275 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "mainwindow.h" +#include "tabletcanvas.h" + +//! [0] +MainWindow::MainWindow(TabletCanvas *canvas) +{ + myCanvas = canvas; + createActions(); + createMenus(); + + myCanvas->setColor(Qt::red); + myCanvas->setLineWidthType(TabletCanvas::LineWidthPressure); + myCanvas->setAlphaChannelType(TabletCanvas::NoAlpha); + myCanvas->setColorSaturationType(TabletCanvas::NoSaturation); + + setWindowTitle(tr("Tablet Example")); + setCentralWidget(myCanvas); +} +//! [0] + +//! [1] +void MainWindow::brushColorAct() +{ + QColor color = QColorDialog::getColor(myCanvas->color()); + + if (color.isValid()) + myCanvas->setColor(color); +} +//! [1] + +//! [2] +void MainWindow::alphaActionTriggered(QAction *action) +{ + if (action == alphaChannelPressureAction) { + myCanvas->setAlphaChannelType(TabletCanvas::AlphaPressure); + } else if (action == alphaChannelTiltAction) { + myCanvas->setAlphaChannelType(TabletCanvas::AlphaTilt); + } else { + myCanvas->setAlphaChannelType(TabletCanvas::NoAlpha); + } +} +//! [2] + +//! [3] +void MainWindow::lineWidthActionTriggered(QAction *action) +{ + if (action == lineWidthPressureAction) { + myCanvas->setLineWidthType(TabletCanvas::LineWidthPressure); + } else if (action == lineWidthTiltAction) { + myCanvas->setLineWidthType(TabletCanvas::LineWidthTilt); + } else { + myCanvas->setLineWidthType(TabletCanvas::NoLineWidth); + } +} +//! [3] + +//! [4] +void MainWindow::saturationActionTriggered(QAction *action) +{ + if (action == colorSaturationVTiltAction) { + myCanvas->setColorSaturationType(TabletCanvas::SaturationVTilt); + } else if (action == colorSaturationHTiltAction) { + myCanvas->setColorSaturationType(TabletCanvas::SaturationHTilt); + } else if (action == colorSaturationPressureAction) { + myCanvas->setColorSaturationType(TabletCanvas::SaturationPressure); + } else { + myCanvas->setColorSaturationType(TabletCanvas::NoSaturation); + } +} +//! [4] + +//! [5] +void MainWindow::saveAct() +{ + QString path = QDir::currentPath() + "/untitled.png"; + QString fileName = QFileDialog::getSaveFileName(this, tr("Save Picture"), + path); + + if (!myCanvas->saveImage(fileName)) + QMessageBox::information(this, "Error Saving Picture", + "Could not save the image"); +} +//! [5] + +//! [6] +void MainWindow::loadAct() +{ + QString fileName = QFileDialog::getOpenFileName(this, tr("Open Picture"), + QDir::currentPath()); + + if (!myCanvas->loadImage(fileName)) + QMessageBox::information(this, "Error Opening Picture", + "Could not open picture"); +} +//! [6] + +//! [7] +void MainWindow::aboutAct() +{ + QMessageBox::about(this, tr("About Tablet Example"), + tr("This example shows use of a Wacom tablet in Qt")); +} +//! [7] + +//! [8] +void MainWindow::createActions() +{ +//! [8] + brushColorAction = new QAction(tr("&Brush Color..."), this); + brushColorAction->setShortcut(tr("Ctrl+C")); + connect(brushColorAction, SIGNAL(triggered()), + this, SLOT(brushColorAct())); + +//! [9] + alphaChannelPressureAction = new QAction(tr("&Pressure"), this); + alphaChannelPressureAction->setCheckable(true); + + alphaChannelTiltAction = new QAction(tr("&Tilt"), this); + alphaChannelTiltAction->setCheckable(true); + + noAlphaChannelAction = new QAction(tr("No Alpha Channel"), this); + noAlphaChannelAction->setCheckable(true); + noAlphaChannelAction->setChecked(true); + + alphaChannelGroup = new QActionGroup(this); + alphaChannelGroup->addAction(alphaChannelPressureAction); + alphaChannelGroup->addAction(alphaChannelTiltAction); + alphaChannelGroup->addAction(noAlphaChannelAction); + connect(alphaChannelGroup, SIGNAL(triggered(QAction *)), + this, SLOT(alphaActionTriggered(QAction *))); + +//! [9] + colorSaturationVTiltAction = new QAction(tr("&Vertical Tilt"), this); + colorSaturationVTiltAction->setCheckable(true); + + colorSaturationHTiltAction = new QAction(tr("&Horizontal Tilt"), this); + colorSaturationHTiltAction->setCheckable(true); + + colorSaturationPressureAction = new QAction(tr("&Pressure"), this); + colorSaturationPressureAction->setCheckable(true); + + noColorSaturationAction = new QAction(tr("&No Color Saturation"), this); + noColorSaturationAction->setCheckable(true); + noColorSaturationAction->setChecked(true); + + colorSaturationGroup = new QActionGroup(this); + colorSaturationGroup->addAction(colorSaturationVTiltAction); + colorSaturationGroup->addAction(colorSaturationHTiltAction); + colorSaturationGroup->addAction(colorSaturationPressureAction); + colorSaturationGroup->addAction(noColorSaturationAction); + connect(colorSaturationGroup, SIGNAL(triggered(QAction *)), + this, SLOT(saturationActionTriggered(QAction *))); + + lineWidthPressureAction = new QAction(tr("&Pressure"), this); + lineWidthPressureAction->setCheckable(true); + lineWidthPressureAction->setChecked(true); + + lineWidthTiltAction = new QAction(tr("&Tilt"), this); + lineWidthTiltAction->setCheckable(true); + + lineWidthFixedAction = new QAction(tr("&Fixed"), this); + lineWidthFixedAction->setCheckable(true); + + lineWidthGroup = new QActionGroup(this); + lineWidthGroup->addAction(lineWidthPressureAction); + lineWidthGroup->addAction(lineWidthTiltAction); + lineWidthGroup->addAction(lineWidthFixedAction); + connect(lineWidthGroup, SIGNAL(triggered(QAction *)), + this, SLOT(lineWidthActionTriggered(QAction *))); + + exitAction = new QAction(tr("E&xit"), this); + exitAction->setShortcut(tr("Ctrl+X")); + connect(exitAction, SIGNAL(triggered()), + this, SLOT(close())); + + loadAction = new QAction(tr("&Open..."), this); + loadAction->setShortcut(tr("Ctrl+O")); + connect(loadAction, SIGNAL(triggered()), + this, SLOT(loadAct())); + + saveAction = new QAction(tr("&Save As..."), this); + saveAction->setShortcut(tr("Ctrl+S")); + connect(saveAction, SIGNAL(triggered()), + this, SLOT(saveAct())); + + aboutAction = new QAction(tr("A&bout"), this); + aboutAction->setShortcut(tr("Ctrl+B")); + connect(aboutAction, SIGNAL(triggered()), + this, SLOT(aboutAct())); + + aboutQtAction = new QAction(tr("About &Qt"), this); + aboutQtAction->setShortcut(tr("Ctrl+Q")); + connect(aboutQtAction, SIGNAL(triggered()), + qApp, SLOT(aboutQt())); +//! [10] +} +//! [10] + +//! [11] +void MainWindow::createMenus() +{ + fileMenu = menuBar()->addMenu(tr("&File")); + fileMenu->addAction(loadAction); + fileMenu->addAction(saveAction); + fileMenu->addSeparator(); + fileMenu->addAction(exitAction); + + brushMenu = menuBar()->addMenu(tr("&Brush")); + brushMenu->addAction(brushColorAction); + + tabletMenu = menuBar()->addMenu(tr("&Tablet")); + + lineWidthMenu = tabletMenu->addMenu(tr("&Line Width")); + lineWidthMenu->addAction(lineWidthPressureAction); + lineWidthMenu->addAction(lineWidthTiltAction); + lineWidthMenu->addAction(lineWidthFixedAction); + + alphaChannelMenu = tabletMenu->addMenu(tr("&Alpha Channel")); + alphaChannelMenu->addAction(alphaChannelPressureAction); + alphaChannelMenu->addAction(alphaChannelTiltAction); + alphaChannelMenu->addAction(noAlphaChannelAction); + + colorSaturationMenu = tabletMenu->addMenu(tr("&Color Saturation")); + colorSaturationMenu->addAction(colorSaturationVTiltAction); + colorSaturationMenu->addAction(colorSaturationHTiltAction); + colorSaturationMenu->addAction(noColorSaturationAction); + + helpMenu = menuBar()->addMenu("&Help"); + helpMenu->addAction(aboutAction); + helpMenu->addAction(aboutQtAction); +} +//! [11] diff --git a/examples/widgets/tablet/mainwindow.h b/examples/widgets/tablet/mainwindow.h new file mode 100644 index 0000000..85be425 --- /dev/null +++ b/examples/widgets/tablet/mainwindow.h @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include <QMainWindow> + +QT_BEGIN_NAMESPACE +class QAction; +class QActionGroup; +class QMenu; +class QStatusBar; +QT_END_NAMESPACE +class TabletCanvas; + +//! [0] +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(TabletCanvas *canvas); + +private slots: + void brushColorAct(); + void alphaActionTriggered(QAction *action); + void lineWidthActionTriggered(QAction *action); + void saturationActionTriggered(QAction *action); + void saveAct(); + void loadAct(); + void aboutAct(); + +private: + void createActions(); + void createMenus(); + + TabletCanvas *myCanvas; + + QAction *brushColorAction; + QActionGroup *brushActionGroup; + + QActionGroup *alphaChannelGroup; + QAction *alphaChannelPressureAction; + QAction *alphaChannelTiltAction; + QAction *noAlphaChannelAction; + + QActionGroup *colorSaturationGroup; + QAction *colorSaturationVTiltAction; + QAction *colorSaturationHTiltAction; + QAction *colorSaturationPressureAction; + QAction *noColorSaturationAction; + + QActionGroup *lineWidthGroup; + QAction *lineWidthPressureAction; + QAction *lineWidthTiltAction; + QAction *lineWidthFixedAction; + + QAction *exitAction; + QAction *saveAction; + QAction *loadAction; + + QAction *aboutAction; + QAction *aboutQtAction; + + QMenu *fileMenu; + QMenu *brushMenu; + QMenu *tabletMenu; + QMenu *helpMenu; + QMenu *colorSaturationMenu; + QMenu *lineWidthMenu; + QMenu *alphaChannelMenu; +}; +//! [0] + +#endif diff --git a/examples/widgets/tablet/tablet.pro b/examples/widgets/tablet/tablet.pro new file mode 100644 index 0000000..27d8d2c --- /dev/null +++ b/examples/widgets/tablet/tablet.pro @@ -0,0 +1,13 @@ +HEADERS = mainwindow.h \ + tabletcanvas.h \ + tabletapplication.h +SOURCES = mainwindow.cpp \ + main.cpp \ + tabletcanvas.cpp \ + tabletapplication.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/widgets/tablet +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS tablet.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/tablet +INSTALLS += target sources diff --git a/examples/widgets/tablet/tabletapplication.cpp b/examples/widgets/tablet/tabletapplication.cpp new file mode 100644 index 0000000..c318b85 --- /dev/null +++ b/examples/widgets/tablet/tabletapplication.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "tabletapplication.h" + +//! [0] +bool TabletApplication::event(QEvent *event) +{ + if (event->type() == QEvent::TabletEnterProximity || + event->type() == QEvent::TabletLeaveProximity) { + myCanvas->setTabletDevice( + static_cast<QTabletEvent *>(event)->device()); + return true; + } + return QApplication::event(event); +} +//! [0] diff --git a/examples/widgets/tablet/tabletapplication.h b/examples/widgets/tablet/tabletapplication.h new file mode 100644 index 0000000..acbaa50 --- /dev/null +++ b/examples/widgets/tablet/tabletapplication.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TABLETAPPLICATION_H +#define TABLETAPPLICATION_H + +#include <QApplication> + +#include "tabletcanvas.h" + +//! [0] +class TabletApplication : public QApplication +{ + Q_OBJECT + +public: + TabletApplication(int &argv, char **args) + : QApplication(argv, args) {} + + bool event(QEvent *event); + void setCanvas(TabletCanvas *canvas) + { myCanvas = canvas; } + +private: + TabletCanvas *myCanvas; +}; +//! [0] + +#endif diff --git a/examples/widgets/tablet/tabletcanvas.cpp b/examples/widgets/tablet/tabletcanvas.cpp new file mode 100644 index 0000000..dc42c3c --- /dev/null +++ b/examples/widgets/tablet/tabletcanvas.cpp @@ -0,0 +1,257 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> +#include <math.h> + +#include "tabletcanvas.h" + +//! [0] +TabletCanvas::TabletCanvas() +{ + resize(500, 500); + myBrush = QBrush(); + myPen = QPen(); + initImage(); + setAutoFillBackground(true); + deviceDown = false; + myColor = Qt::red; + myTabletDevice = QTabletEvent::Stylus; + alphaChannelType = NoAlpha; + colorSaturationType = NoSaturation; + lineWidthType = LineWidthPressure; +} + +void TabletCanvas::initImage() +{ + QImage newImage = QImage(width(), height(), QImage::Format_ARGB32); + QPainter painter(&newImage); + painter.fillRect(0, 0, newImage.width(), newImage.height(), Qt::white); + if (!image.isNull()) + painter.drawImage(0, 0, image); + painter.end(); + image = newImage; +} +//! [0] + +//! [1] +bool TabletCanvas::saveImage(const QString &file) +{ + return image.save(file); +} +//! [1] + +//! [2] +bool TabletCanvas::loadImage(const QString &file) +{ + bool success = image.load(file); + + if (success) { + update(); + return true; + } + return false; +} +//! [2] + +//! [3] +void TabletCanvas::tabletEvent(QTabletEvent *event) +{ + + switch (event->type()) { + case QEvent::TabletPress: + if (!deviceDown) + deviceDown = true; + break; + case QEvent::TabletRelease: + if (deviceDown) + deviceDown = false; + break; + case QEvent::TabletMove: + polyLine[2] = polyLine[1]; + polyLine[1] = polyLine[0]; + polyLine[0] = event->pos(); + + if (deviceDown) { + updateBrush(event); + QPainter painter(&image); + paintImage(painter, event); + } + break; + default: + break; + } + update(); +} +//! [3] + +//! [4] +void TabletCanvas::paintEvent(QPaintEvent *) +{ + QPainter painter(this); + painter.drawImage(QPoint(0, 0), image); +} +//! [4] + +//! [5] +void TabletCanvas::paintImage(QPainter &painter, QTabletEvent *event) +{ + QPoint brushAdjust(10, 10); + + switch (myTabletDevice) { + case QTabletEvent::Stylus: + painter.setBrush(myBrush); + painter.setPen(myPen); + painter.drawLine(polyLine[1], event->pos()); + break; + case QTabletEvent::Airbrush: + myBrush.setColor(myColor); + myBrush.setStyle(brushPattern(event->pressure())); + painter.setPen(Qt::NoPen); + painter.setBrush(myBrush); + + for (int i = 0; i < 3; ++i) { + painter.drawEllipse(QRect(polyLine[i] - brushAdjust, + polyLine[i] + brushAdjust)); + } + break; + case QTabletEvent::Puck: + case QTabletEvent::FourDMouse: + case QTabletEvent::RotationStylus: + qWarning("This input device is not supported by the example."); + break; + default: + qWarning("Unknown tablet device."); + } +} +//! [5] + +//! [6] +Qt::BrushStyle TabletCanvas::brushPattern(qreal value) +{ + int pattern = int((value) * 100.0) % 7; + + switch (pattern) { + case 0: + return Qt::SolidPattern; + case 1: + return Qt::Dense1Pattern; + case 2: + return Qt::Dense2Pattern; + case 3: + return Qt::Dense3Pattern; + case 4: + return Qt::Dense4Pattern; + case 5: + return Qt::Dense5Pattern; + case 6: + return Qt::Dense6Pattern; + default: + return Qt::Dense7Pattern; + } +} +//! [6] + +//! [7] +void TabletCanvas::updateBrush(QTabletEvent *event) +{ + int hue, saturation, value, alpha; + myColor.getHsv(&hue, &saturation, &value, &alpha); + + int vValue = int(((event->yTilt() + 60.0) / 120.0) * 255); + int hValue = int(((event->xTilt() + 60.0) / 120.0) * 255); +//! [7] //! [8] + + switch (alphaChannelType) { + case AlphaPressure: + myColor.setAlpha(int(event->pressure() * 255.0)); + break; + case AlphaTilt: + myColor.setAlpha(maximum(abs(vValue - 127), abs(hValue - 127))); + break; + default: + myColor.setAlpha(255); + } + +//! [8] //! [9] + switch (colorSaturationType) { + case SaturationVTilt: + myColor.setHsv(hue, vValue, value, alpha); + break; + case SaturationHTilt: + myColor.setHsv(hue, hValue, value, alpha); + break; + case SaturationPressure: + myColor.setHsv(hue, int(event->pressure() * 255.0), value, alpha); + break; + default: + ; + } + +//! [9] //! [10] + switch (lineWidthType) { + case LineWidthPressure: + myPen.setWidthF(event->pressure() * 10 + 1); + break; + case LineWidthTilt: + myPen.setWidthF(maximum(abs(vValue - 127), abs(hValue - 127)) / 12); + break; + default: + myPen.setWidthF(1); + } + +//! [10] //! [11] + if (event->pointerType() == QTabletEvent::Eraser) { + myBrush.setColor(Qt::white); + myPen.setColor(Qt::white); + myPen.setWidthF(event->pressure() * 10 + 1); + } else { + myBrush.setColor(myColor); + myPen.setColor(myColor); + } +} +//! [11] + +void TabletCanvas::resizeEvent(QResizeEvent *event) +{ + initImage(); + polyLine[0] = polyLine[1] = polyLine[2] = QPoint(); +} diff --git a/examples/widgets/tablet/tabletcanvas.h b/examples/widgets/tablet/tabletcanvas.h new file mode 100644 index 0000000..90eb1db --- /dev/null +++ b/examples/widgets/tablet/tabletcanvas.h @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TABLETCANVAS_H +#define TABLETCANVAS_H + +#include <QWidget> +#include <QImage> +#include <QPoint> +#include <QTabletEvent> +#include <QColor> +#include <QBrush> +#include <QPen> +#include <QPoint> + +QT_BEGIN_NAMESPACE +class QPaintEvent; +class QString; +QT_END_NAMESPACE + +//! [0] +class TabletCanvas : public QWidget +{ + Q_OBJECT + +public: + enum AlphaChannelType { AlphaPressure, AlphaTilt, NoAlpha }; + enum ColorSaturationType { SaturationVTilt, SaturationHTilt, + SaturationPressure, NoSaturation }; + enum LineWidthType { LineWidthPressure, LineWidthTilt, NoLineWidth }; + + TabletCanvas(); + + bool saveImage(const QString &file); + bool loadImage(const QString &file); + void setAlphaChannelType(AlphaChannelType type) + { alphaChannelType = type; } + void setColorSaturationType(ColorSaturationType type) + { colorSaturationType = type; } + void setLineWidthType(LineWidthType type) + { lineWidthType = type; } + void setColor(const QColor &color) + { myColor = color; } + QColor color() const + { return myColor; } + void setTabletDevice(QTabletEvent::TabletDevice device) + { myTabletDevice = device; } + int maximum(int a, int b) + { return a > b ? a : b; } + +protected: + void tabletEvent(QTabletEvent *event); + void paintEvent(QPaintEvent *event); + void resizeEvent(QResizeEvent *event); + +private: + void initImage(); + void paintImage(QPainter &painter, QTabletEvent *event); + Qt::BrushStyle brushPattern(qreal value); + void updateBrush(QTabletEvent *event); + + AlphaChannelType alphaChannelType; + ColorSaturationType colorSaturationType; + LineWidthType lineWidthType; + QTabletEvent::PointerType pointerType; + QTabletEvent::TabletDevice myTabletDevice; + QColor myColor; + + QImage image; + QBrush myBrush; + QPen myPen; + bool deviceDown; + QPoint polyLine[3]; +}; +//! [0] + +#endif diff --git a/examples/widgets/tetrix/main.cpp b/examples/widgets/tetrix/main.cpp new file mode 100644 index 0000000..c9bf49a --- /dev/null +++ b/examples/widgets/tetrix/main.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include <stdlib.h> + +#include "tetrixwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + TetrixWindow window; + window.show(); + qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); + return app.exec(); +} diff --git a/examples/widgets/tetrix/tetrix.pro b/examples/widgets/tetrix/tetrix.pro new file mode 100644 index 0000000..59392fa --- /dev/null +++ b/examples/widgets/tetrix/tetrix.pro @@ -0,0 +1,13 @@ +HEADERS = tetrixboard.h \ + tetrixpiece.h \ + tetrixwindow.h +SOURCES = main.cpp \ + tetrixboard.cpp \ + tetrixpiece.cpp \ + tetrixwindow.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/widgets/tetrix +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS tetrix.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/tetrix +INSTALLS += target sources diff --git a/examples/widgets/tetrix/tetrixboard.cpp b/examples/widgets/tetrix/tetrixboard.cpp new file mode 100644 index 0000000..e8ef4bf --- /dev/null +++ b/examples/widgets/tetrix/tetrixboard.cpp @@ -0,0 +1,409 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "tetrixboard.h" + +//! [0] +TetrixBoard::TetrixBoard(QWidget *parent) + : QFrame(parent) +{ + setFrameStyle(QFrame::Panel | QFrame::Sunken); + setFocusPolicy(Qt::StrongFocus); + isStarted = false; + isPaused = false; + clearBoard(); + + nextPiece.setRandomShape(); +} +//! [0] + +//! [1] +void TetrixBoard::setNextPieceLabel(QLabel *label) +{ + nextPieceLabel = label; +} +//! [1] + +//! [2] +QSize TetrixBoard::sizeHint() const +{ + return QSize(BoardWidth * 15 + frameWidth() * 2, + BoardHeight * 15 + frameWidth() * 2); +} + +QSize TetrixBoard::minimumSizeHint() const +//! [2] //! [3] +{ + return QSize(BoardWidth * 5 + frameWidth() * 2, + BoardHeight * 5 + frameWidth() * 2); +} +//! [3] + +//! [4] +void TetrixBoard::start() +{ + if (isPaused) + return; + + isStarted = true; + isWaitingAfterLine = false; + numLinesRemoved = 0; + numPiecesDropped = 0; + score = 0; + level = 1; + clearBoard(); + + emit linesRemovedChanged(numLinesRemoved); + emit scoreChanged(score); + emit levelChanged(level); + + newPiece(); + timer.start(timeoutTime(), this); +} +//! [4] + +//! [5] +void TetrixBoard::pause() +{ + if (!isStarted) + return; + + isPaused = !isPaused; + if (isPaused) { + timer.stop(); + } else { + timer.start(timeoutTime(), this); + } + update(); +//! [5] //! [6] +} +//! [6] + +//! [7] +void TetrixBoard::paintEvent(QPaintEvent *event) +{ + QFrame::paintEvent(event); + + QPainter painter(this); + QRect rect = contentsRect(); +//! [7] + + if (isPaused) { + painter.drawText(rect, Qt::AlignCenter, tr("Pause")); + return; + } + +//! [8] + int boardTop = rect.bottom() - BoardHeight*squareHeight(); + + for (int i = 0; i < BoardHeight; ++i) { + for (int j = 0; j < BoardWidth; ++j) { + TetrixShape shape = shapeAt(j, BoardHeight - i - 1); + if (shape != NoShape) + drawSquare(painter, rect.left() + j * squareWidth(), + boardTop + i * squareHeight(), shape); + } +//! [8] //! [9] + } +//! [9] + +//! [10] + if (curPiece.shape() != NoShape) { + for (int i = 0; i < 4; ++i) { + int x = curX + curPiece.x(i); + int y = curY - curPiece.y(i); + drawSquare(painter, rect.left() + x * squareWidth(), + boardTop + (BoardHeight - y - 1) * squareHeight(), + curPiece.shape()); + } +//! [10] //! [11] + } +//! [11] //! [12] +} +//! [12] + +//! [13] +void TetrixBoard::keyPressEvent(QKeyEvent *event) +{ + if (!isStarted || isPaused || curPiece.shape() == NoShape) { + QFrame::keyPressEvent(event); + return; + } +//! [13] + +//! [14] + switch (event->key()) { + case Qt::Key_Left: + tryMove(curPiece, curX - 1, curY); + break; + case Qt::Key_Right: + tryMove(curPiece, curX + 1, curY); + break; + case Qt::Key_Down: + tryMove(curPiece.rotatedRight(), curX, curY); + break; + case Qt::Key_Up: + tryMove(curPiece.rotatedLeft(), curX, curY); + break; + case Qt::Key_Space: + dropDown(); + break; + case Qt::Key_D: + oneLineDown(); + break; + default: + QFrame::keyPressEvent(event); + } +//! [14] +} + +//! [15] +void TetrixBoard::timerEvent(QTimerEvent *event) +{ + if (event->timerId() == timer.timerId()) { + if (isWaitingAfterLine) { + isWaitingAfterLine = false; + newPiece(); + timer.start(timeoutTime(), this); + } else { + oneLineDown(); + } + } else { + QFrame::timerEvent(event); +//! [15] //! [16] + } +//! [16] //! [17] +} +//! [17] + +//! [18] +void TetrixBoard::clearBoard() +{ + for (int i = 0; i < BoardHeight * BoardWidth; ++i) + board[i] = NoShape; +} +//! [18] + +//! [19] +void TetrixBoard::dropDown() +{ + int dropHeight = 0; + int newY = curY; + while (newY > 0) { + if (!tryMove(curPiece, curX, newY - 1)) + break; + --newY; + ++dropHeight; + } + pieceDropped(dropHeight); +//! [19] //! [20] +} +//! [20] + +//! [21] +void TetrixBoard::oneLineDown() +{ + if (!tryMove(curPiece, curX, curY - 1)) + pieceDropped(0); +} +//! [21] + +//! [22] +void TetrixBoard::pieceDropped(int dropHeight) +{ + for (int i = 0; i < 4; ++i) { + int x = curX + curPiece.x(i); + int y = curY - curPiece.y(i); + shapeAt(x, y) = curPiece.shape(); + } + + ++numPiecesDropped; + if (numPiecesDropped % 25 == 0) { + ++level; + timer.start(timeoutTime(), this); + emit levelChanged(level); + } + + score += dropHeight + 7; + emit scoreChanged(score); + removeFullLines(); + + if (!isWaitingAfterLine) + newPiece(); +//! [22] //! [23] +} +//! [23] + +//! [24] +void TetrixBoard::removeFullLines() +{ + int numFullLines = 0; + + for (int i = BoardHeight - 1; i >= 0; --i) { + bool lineIsFull = true; + + for (int j = 0; j < BoardWidth; ++j) { + if (shapeAt(j, i) == NoShape) { + lineIsFull = false; + break; + } + } + + if (lineIsFull) { +//! [24] //! [25] + ++numFullLines; + for (int k = i; k < BoardHeight - 1; ++k) { + for (int j = 0; j < BoardWidth; ++j) + shapeAt(j, k) = shapeAt(j, k + 1); + } +//! [25] //! [26] + for (int j = 0; j < BoardWidth; ++j) + shapeAt(j, BoardHeight - 1) = NoShape; + } +//! [26] //! [27] + } +//! [27] + +//! [28] + if (numFullLines > 0) { + numLinesRemoved += numFullLines; + score += 10 * numFullLines; + emit linesRemovedChanged(numLinesRemoved); + emit scoreChanged(score); + + timer.start(500, this); + isWaitingAfterLine = true; + curPiece.setShape(NoShape); + update(); + } +//! [28] //! [29] +} +//! [29] + +//! [30] +void TetrixBoard::newPiece() +{ + curPiece = nextPiece; + nextPiece.setRandomShape(); + showNextPiece(); + curX = BoardWidth / 2 + 1; + curY = BoardHeight - 1 + curPiece.minY(); + + if (!tryMove(curPiece, curX, curY)) { + curPiece.setShape(NoShape); + timer.stop(); + isStarted = false; + } +//! [30] //! [31] +} +//! [31] + +//! [32] +void TetrixBoard::showNextPiece() +{ + if (!nextPieceLabel) + return; + + int dx = nextPiece.maxX() - nextPiece.minX() + 1; + int dy = nextPiece.maxY() - nextPiece.minY() + 1; + + QPixmap pixmap(dx * squareWidth(), dy * squareHeight()); + QPainter painter(&pixmap); + painter.fillRect(pixmap.rect(), nextPieceLabel->palette().background()); + + for (int i = 0; i < 4; ++i) { + int x = nextPiece.x(i) - nextPiece.minX(); + int y = nextPiece.y(i) - nextPiece.minY(); + drawSquare(painter, x * squareWidth(), y * squareHeight(), + nextPiece.shape()); + } + nextPieceLabel->setPixmap(pixmap); +//! [32] //! [33] +} +//! [33] + +//! [34] +bool TetrixBoard::tryMove(const TetrixPiece &newPiece, int newX, int newY) +{ + for (int i = 0; i < 4; ++i) { + int x = newX + newPiece.x(i); + int y = newY - newPiece.y(i); + if (x < 0 || x >= BoardWidth || y < 0 || y >= BoardHeight) + return false; + if (shapeAt(x, y) != NoShape) + return false; + } +//! [34] + +//! [35] + curPiece = newPiece; + curX = newX; + curY = newY; + update(); + return true; +} +//! [35] + +//! [36] +void TetrixBoard::drawSquare(QPainter &painter, int x, int y, TetrixShape shape) +{ + static const QRgb colorTable[8] = { + 0x000000, 0xCC6666, 0x66CC66, 0x6666CC, + 0xCCCC66, 0xCC66CC, 0x66CCCC, 0xDAAA00 + }; + + QColor color = colorTable[int(shape)]; + painter.fillRect(x + 1, y + 1, squareWidth() - 2, squareHeight() - 2, + color); + + painter.setPen(color.light()); + painter.drawLine(x, y + squareHeight() - 1, x, y); + painter.drawLine(x, y, x + squareWidth() - 1, y); + + painter.setPen(color.dark()); + painter.drawLine(x + 1, y + squareHeight() - 1, + x + squareWidth() - 1, y + squareHeight() - 1); + painter.drawLine(x + squareWidth() - 1, y + squareHeight() - 1, + x + squareWidth() - 1, y + 1); +} +//! [36] diff --git a/examples/widgets/tetrix/tetrixboard.h b/examples/widgets/tetrix/tetrixboard.h new file mode 100644 index 0000000..5d71125 --- /dev/null +++ b/examples/widgets/tetrix/tetrixboard.h @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TETRIXBOARD_H +#define TETRIXBOARD_H + +#include <QBasicTimer> +#include <QFrame> +#include <QPointer> + +#include "tetrixpiece.h" + +QT_BEGIN_NAMESPACE +class QLabel; +QT_END_NAMESPACE + +//! [0] +class TetrixBoard : public QFrame +{ + Q_OBJECT + +public: + TetrixBoard(QWidget *parent = 0); + + void setNextPieceLabel(QLabel *label); + QSize sizeHint() const; + QSize minimumSizeHint() const; + +public slots: + void start(); + void pause(); + +signals: + void scoreChanged(int score); + void levelChanged(int level); + void linesRemovedChanged(int numLines); + +protected: + void paintEvent(QPaintEvent *event); + void keyPressEvent(QKeyEvent *event); + void timerEvent(QTimerEvent *event); +//! [0] + +//! [1] +private: + enum { BoardWidth = 10, BoardHeight = 22 }; + + TetrixShape &shapeAt(int x, int y) { return board[(y * BoardWidth) + x]; } + int timeoutTime() { return 1000 / (1 + level); } + int squareWidth() { return contentsRect().width() / BoardWidth; } + int squareHeight() { return contentsRect().height() / BoardHeight; } + void clearBoard(); + void dropDown(); + void oneLineDown(); + void pieceDropped(int dropHeight); + void removeFullLines(); + void newPiece(); + void showNextPiece(); + bool tryMove(const TetrixPiece &newPiece, int newX, int newY); + void drawSquare(QPainter &painter, int x, int y, TetrixShape shape); + + QBasicTimer timer; + QPointer<QLabel> nextPieceLabel; + bool isStarted; + bool isPaused; + bool isWaitingAfterLine; + TetrixPiece curPiece; + TetrixPiece nextPiece; + int curX; + int curY; + int numLinesRemoved; + int numPiecesDropped; + int score; + int level; + TetrixShape board[BoardWidth * BoardHeight]; +}; +//! [1] + +#endif diff --git a/examples/widgets/tetrix/tetrixpiece.cpp b/examples/widgets/tetrix/tetrixpiece.cpp new file mode 100644 index 0000000..eeaab53 --- /dev/null +++ b/examples/widgets/tetrix/tetrixpiece.cpp @@ -0,0 +1,146 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtCore> + +#include <stdlib.h> + +#include "tetrixpiece.h" + +//! [0] +void TetrixPiece::setRandomShape() +{ + setShape(TetrixShape(qrand() % 7 + 1)); +} +//! [0] + +//! [1] +void TetrixPiece::setShape(TetrixShape shape) +{ + static const int coordsTable[8][4][2] = { + { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } }, + { { 0, -1 }, { 0, 0 }, { -1, 0 }, { -1, 1 } }, + { { 0, -1 }, { 0, 0 }, { 1, 0 }, { 1, 1 } }, + { { 0, -1 }, { 0, 0 }, { 0, 1 }, { 0, 2 } }, + { { -1, 0 }, { 0, 0 }, { 1, 0 }, { 0, 1 } }, + { { 0, 0 }, { 1, 0 }, { 0, 1 }, { 1, 1 } }, + { { -1, -1 }, { 0, -1 }, { 0, 0 }, { 0, 1 } }, + { { 1, -1 }, { 0, -1 }, { 0, 0 }, { 0, 1 } } + }; + + for (int i = 0; i < 4 ; i++) { + for (int j = 0; j < 2; ++j) + coords[i][j] = coordsTable[shape][i][j]; + } + pieceShape = shape; +//! [1] //! [2] +} +//! [2] + +//! [3] +int TetrixPiece::minX() const +{ + int min = coords[0][0]; + for (int i = 1; i < 4; ++i) + min = qMin(min, coords[i][0]); + return min; +} + +int TetrixPiece::maxX() const +//! [3] //! [4] +{ + int max = coords[0][0]; + for (int i = 1; i < 4; ++i) + max = qMax(max, coords[i][0]); + return max; +} +//! [4] + +//! [5] +int TetrixPiece::minY() const +{ + int min = coords[0][1]; + for (int i = 1; i < 4; ++i) + min = qMin(min, coords[i][1]); + return min; +} + +int TetrixPiece::maxY() const +//! [5] //! [6] +{ + int max = coords[0][1]; + for (int i = 1; i < 4; ++i) + max = qMax(max, coords[i][1]); + return max; +} +//! [6] + +//! [7] +TetrixPiece TetrixPiece::rotatedLeft() const +{ + if (pieceShape == SquareShape) + return *this; + + TetrixPiece result; + result.pieceShape = pieceShape; + for (int i = 0; i < 4; ++i) { + result.setX(i, y(i)); + result.setY(i, -x(i)); + } +//! [7] + return result; +} + +//! [9] +TetrixPiece TetrixPiece::rotatedRight() const +{ + if (pieceShape == SquareShape) + return *this; + + TetrixPiece result; + result.pieceShape = pieceShape; + for (int i = 0; i < 4; ++i) { + result.setX(i, -y(i)); + result.setY(i, x(i)); + } +//! [9] + return result; +} diff --git a/examples/widgets/tetrix/tetrixpiece.h b/examples/widgets/tetrix/tetrixpiece.h new file mode 100644 index 0000000..cbf5583 --- /dev/null +++ b/examples/widgets/tetrix/tetrixpiece.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TETRIXPIECE_H +#define TETRIXPIECE_H + +enum TetrixShape { NoShape, ZShape, SShape, LineShape, TShape, SquareShape, + LShape, MirroredLShape }; + +//! [0] +class TetrixPiece +{ +public: + TetrixPiece() { setShape(NoShape); } + + void setRandomShape(); + void setShape(TetrixShape shape); + + TetrixShape shape() const { return pieceShape; } + int x(int index) const { return coords[index][0]; } + int y(int index) const { return coords[index][1]; } + int minX() const; + int maxX() const; + int minY() const; + int maxY() const; + TetrixPiece rotatedLeft() const; + TetrixPiece rotatedRight() const; + +private: + void setX(int index, int x) { coords[index][0] = x; } + void setY(int index, int y) { coords[index][1] = y; } + + TetrixShape pieceShape; + int coords[4][2]; +}; +//! [0] + +#endif diff --git a/examples/widgets/tetrix/tetrixwindow.cpp b/examples/widgets/tetrix/tetrixwindow.cpp new file mode 100644 index 0000000..98e460a --- /dev/null +++ b/examples/widgets/tetrix/tetrixwindow.cpp @@ -0,0 +1,116 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "tetrixboard.h" +#include "tetrixwindow.h" + +//! [0] +TetrixWindow::TetrixWindow() +{ + board = new TetrixBoard; +//! [0] + + nextPieceLabel = new QLabel; + nextPieceLabel->setFrameStyle(QFrame::Box | QFrame::Raised); + nextPieceLabel->setAlignment(Qt::AlignCenter); + board->setNextPieceLabel(nextPieceLabel); + +//! [1] + scoreLcd = new QLCDNumber(5); + scoreLcd->setSegmentStyle(QLCDNumber::Filled); +//! [1] + levelLcd = new QLCDNumber(2); + levelLcd->setSegmentStyle(QLCDNumber::Filled); + linesLcd = new QLCDNumber(5); + linesLcd->setSegmentStyle(QLCDNumber::Filled); + +//! [2] + startButton = new QPushButton(tr("&Start")); + startButton->setFocusPolicy(Qt::NoFocus); + quitButton = new QPushButton(tr("&Quit")); + quitButton->setFocusPolicy(Qt::NoFocus); + pauseButton = new QPushButton(tr("&Pause")); +//! [2] //! [3] + pauseButton->setFocusPolicy(Qt::NoFocus); +//! [3] //! [4] + + connect(startButton, SIGNAL(clicked()), board, SLOT(start())); +//! [4] //! [5] + connect(quitButton , SIGNAL(clicked()), qApp, SLOT(quit())); + connect(pauseButton, SIGNAL(clicked()), board, SLOT(pause())); + connect(board, SIGNAL(scoreChanged(int)), scoreLcd, SLOT(display(int))); + connect(board, SIGNAL(levelChanged(int)), levelLcd, SLOT(display(int))); + connect(board, SIGNAL(linesRemovedChanged(int)), + linesLcd, SLOT(display(int))); +//! [5] + +//! [6] + QGridLayout *layout = new QGridLayout; + layout->addWidget(createLabel(tr("NEXT")), 0, 0); + layout->addWidget(nextPieceLabel, 1, 0); + layout->addWidget(createLabel(tr("LEVEL")), 2, 0); + layout->addWidget(levelLcd, 3, 0); + layout->addWidget(startButton, 4, 0); + layout->addWidget(board, 0, 1, 6, 1); + layout->addWidget(createLabel(tr("SCORE")), 0, 2); + layout->addWidget(scoreLcd, 1, 2); + layout->addWidget(createLabel(tr("LINES REMOVED")), 2, 2); + layout->addWidget(linesLcd, 3, 2); + layout->addWidget(quitButton, 4, 2); + layout->addWidget(pauseButton, 5, 2); + setLayout(layout); + + setWindowTitle(tr("Tetrix")); + resize(550, 370); +} +//! [6] + +//! [7] +QLabel *TetrixWindow::createLabel(const QString &text) +{ + QLabel *lbl = new QLabel(text); + lbl->setAlignment(Qt::AlignHCenter | Qt::AlignBottom); + return lbl; +} +//! [7] + diff --git a/examples/widgets/tetrix/tetrixwindow.h b/examples/widgets/tetrix/tetrixwindow.h new file mode 100644 index 0000000..ad22b0f --- /dev/null +++ b/examples/widgets/tetrix/tetrixwindow.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TETRIXWINDOW_H +#define TETRIXWINDOW_H + +#include <QFrame> +#include <QWidget> + +QT_BEGIN_NAMESPACE +class QLCDNumber; +class QLabel; +class QPushButton; +QT_END_NAMESPACE +class TetrixBoard; + +//! [0] +class TetrixWindow : public QWidget +{ + Q_OBJECT + +public: + TetrixWindow(); + +private: + QLabel *createLabel(const QString &text); + + TetrixBoard *board; + QLabel *nextPieceLabel; + QLCDNumber *scoreLcd; + QLCDNumber *levelLcd; + QLCDNumber *linesLcd; + QPushButton *startButton; + QPushButton *quitButton; + QPushButton *pauseButton; +}; +//! [0] + +#endif diff --git a/examples/widgets/tooltips/images/circle.png b/examples/widgets/tooltips/images/circle.png Binary files differnew file mode 100644 index 0000000..dc392cb --- /dev/null +++ b/examples/widgets/tooltips/images/circle.png diff --git a/examples/widgets/tooltips/images/square.png b/examples/widgets/tooltips/images/square.png Binary files differnew file mode 100644 index 0000000..c0fd2d5 --- /dev/null +++ b/examples/widgets/tooltips/images/square.png diff --git a/examples/widgets/tooltips/images/triangle.png b/examples/widgets/tooltips/images/triangle.png Binary files differnew file mode 100644 index 0000000..2ee15f8 --- /dev/null +++ b/examples/widgets/tooltips/images/triangle.png diff --git a/examples/widgets/tooltips/main.cpp b/examples/widgets/tooltips/main.cpp new file mode 100644 index 0000000..2f4c713 --- /dev/null +++ b/examples/widgets/tooltips/main.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "sortingbox.h" + +int main(int argc, char *argv[]) +{ + Q_INIT_RESOURCE(tooltips); + + QApplication app(argc, argv); + qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); + SortingBox sortingBox; + sortingBox.show(); + return app.exec(); +} diff --git a/examples/widgets/tooltips/shapeitem.cpp b/examples/widgets/tooltips/shapeitem.cpp new file mode 100644 index 0000000..a8d8f3a --- /dev/null +++ b/examples/widgets/tooltips/shapeitem.cpp @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "shapeitem.h" + +//! [0] +QPainterPath ShapeItem::path() const +{ + return myPath; +} +//! [0] + +//! [1] +QPoint ShapeItem::position() const +{ + return myPosition; +} +//! [1] + +//! [2] +QColor ShapeItem::color() const +{ + return myColor; +} +//! [2] + +//! [3] +QString ShapeItem::toolTip() const +{ + return myToolTip; +} +//! [3] + +//! [4] +void ShapeItem::setPath(const QPainterPath &path) +{ + myPath = path; +} +//! [4] + +//! [5] +void ShapeItem::setToolTip(const QString &toolTip) +{ + myToolTip = toolTip; +} +//! [5] + +//! [6] +void ShapeItem::setPosition(const QPoint &position) +{ + myPosition = position; +} +//! [6] + +//! [7] +void ShapeItem::setColor(const QColor &color) +{ + myColor = color; +} +//! [7] diff --git a/examples/widgets/tooltips/shapeitem.h b/examples/widgets/tooltips/shapeitem.h new file mode 100644 index 0000000..d41b990 --- /dev/null +++ b/examples/widgets/tooltips/shapeitem.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SHAPEITEM_H +#define SHAPEITEM_H + +#include <QColor> +#include <QPainterPath> +#include <QPoint> + +//! [0] +class ShapeItem +{ +public: + void setPath(const QPainterPath &path); + void setToolTip(const QString &toolTip); + void setPosition(const QPoint &position); + void setColor(const QColor &color); + + QPainterPath path() const; + QPoint position() const; + QColor color() const; + QString toolTip() const; + +private: + QPainterPath myPath; + QPoint myPosition; + QColor myColor; + QString myToolTip; +}; +//! [0] + +#endif diff --git a/examples/widgets/tooltips/sortingbox.cpp b/examples/widgets/tooltips/sortingbox.cpp new file mode 100644 index 0000000..995da3e --- /dev/null +++ b/examples/widgets/tooltips/sortingbox.cpp @@ -0,0 +1,302 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include <stdlib.h> + +#include "sortingbox.h" + +//! [0] +SortingBox::SortingBox() +{ +//! [0] //! [1] + setMouseTracking(true); +//! [1] //! [2] + setBackgroundRole(QPalette::Base); +//! [2] + + itemInMotion = 0; + +//! [3] + newCircleButton = createToolButton(tr("New Circle"), + QIcon(":/images/circle.png"), + SLOT(createNewCircle())); + + newSquareButton = createToolButton(tr("New Square"), + QIcon(":/images/square.png"), + SLOT(createNewSquare())); + + newTriangleButton = createToolButton(tr("New Triangle"), + QIcon(":/images/triangle.png"), + SLOT(createNewTriangle())); + + circlePath.addEllipse(QRect(0, 0, 100, 100)); + squarePath.addRect(QRect(0, 0, 100, 100)); + + qreal x = trianglePath.currentPosition().x(); + qreal y = trianglePath.currentPosition().y(); + trianglePath.moveTo(x + 120 / 2, y); + trianglePath.lineTo(0, 100); + trianglePath.lineTo(120, 100); + trianglePath.lineTo(x + 120 / 2, y); + +//! [3] //! [4] + setWindowTitle(tr("Tool Tips")); + resize(500, 300); + + createShapeItem(circlePath, tr("Circle"), initialItemPosition(circlePath), + initialItemColor()); + createShapeItem(squarePath, tr("Square"), initialItemPosition(squarePath), + initialItemColor()); + createShapeItem(trianglePath, tr("Triangle"), + initialItemPosition(trianglePath), initialItemColor()); +} +//! [4] + +//! [5] +bool SortingBox::event(QEvent *event) +{ +//! [5] //! [6] + if (event->type() == QEvent::ToolTip) { + QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event); + int index = itemAt(helpEvent->pos()); + if (index != -1) { + QToolTip::showText(helpEvent->globalPos(), shapeItems[index].toolTip()); + } else { + QToolTip::hideText(); + event->ignore(); + } + + return true; + } + return QWidget::event(event); +} +//! [6] + +//! [7] +void SortingBox::resizeEvent(QResizeEvent * /* event */) +{ + int margin = style()->pixelMetric(QStyle::PM_DefaultTopLevelMargin); + int x = width() - margin; + int y = height() - margin; + + y = updateButtonGeometry(newCircleButton, x, y); + y = updateButtonGeometry(newSquareButton, x, y); + updateButtonGeometry(newTriangleButton, x, y); +} +//! [7] + +//! [8] +void SortingBox::paintEvent(QPaintEvent * /* event */) +{ + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); + foreach (ShapeItem shapeItem, shapeItems) { +//! [8] //! [9] + painter.translate(shapeItem.position()); +//! [9] //! [10] + painter.setBrush(shapeItem.color()); + painter.drawPath(shapeItem.path()); + painter.translate(-shapeItem.position()); + } +} +//! [10] + +//! [11] +void SortingBox::mousePressEvent(QMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) { + int index = itemAt(event->pos()); + if (index != -1) { + itemInMotion = &shapeItems[index]; + previousPosition = event->pos(); + shapeItems.move(index, shapeItems.size() - 1); + update(); + } + } +} +//! [11] + +//! [12] +void SortingBox::mouseMoveEvent(QMouseEvent *event) +{ + if ((event->buttons() & Qt::LeftButton) && itemInMotion) + moveItemTo(event->pos()); +} +//! [12] + +//! [13] +void SortingBox::mouseReleaseEvent(QMouseEvent *event) +{ + if (event->button() == Qt::LeftButton && itemInMotion) { + moveItemTo(event->pos()); + itemInMotion = 0; + } +} +//! [13] + +//! [14] +void SortingBox::createNewCircle() +{ + static int count = 1; + createShapeItem(circlePath, tr("Circle <%1>").arg(++count), + randomItemPosition(), randomItemColor()); +} +//! [14] + +//! [15] +void SortingBox::createNewSquare() +{ + static int count = 1; + createShapeItem(squarePath, tr("Square <%1>").arg(++count), + randomItemPosition(), randomItemColor()); +} +//! [15] + +//! [16] +void SortingBox::createNewTriangle() +{ + static int count = 1; + createShapeItem(trianglePath, tr("Triangle <%1>").arg(++count), + randomItemPosition(), randomItemColor()); +} +//! [16] + +//! [17] +int SortingBox::itemAt(const QPoint &pos) +{ + for (int i = shapeItems.size() - 1; i >= 0; --i) { + const ShapeItem &item = shapeItems[i]; + if (item.path().contains(pos - item.position())) + return i; + } + return -1; +} +//! [17] + +//! [18] +void SortingBox::moveItemTo(const QPoint &pos) +{ + QPoint offset = pos - previousPosition; + itemInMotion->setPosition(itemInMotion->position() + offset); +//! [18] //! [19] + previousPosition = pos; + update(); +} +//! [19] + +//! [20] +int SortingBox::updateButtonGeometry(QToolButton *button, int x, int y) +{ + QSize size = button->sizeHint(); + button->setGeometry(x - size.rwidth(), y - size.rheight(), + size.rwidth(), size.rheight()); + + return y - size.rheight() + - style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing); +} +//! [20] + +//! [21] +void SortingBox::createShapeItem(const QPainterPath &path, + const QString &toolTip, const QPoint &pos, + const QColor &color) +{ + ShapeItem shapeItem; + shapeItem.setPath(path); + shapeItem.setToolTip(toolTip); + shapeItem.setPosition(pos); + shapeItem.setColor(color); + shapeItems.append(shapeItem); + update(); +} +//! [21] + +//! [22] +QToolButton *SortingBox::createToolButton(const QString &toolTip, + const QIcon &icon, const char *member) +{ + QToolButton *button = new QToolButton(this); + button->setToolTip(toolTip); + button->setIcon(icon); + button->setIconSize(QSize(32, 32)); + connect(button, SIGNAL(clicked()), this, member); + + return button; +} +//! [22] + +//! [23] +QPoint SortingBox::initialItemPosition(const QPainterPath &path) +{ + int x; + int y = (height() - (int)path.controlPointRect().height()) / 2; + if (shapeItems.size() == 0) + x = ((3 * width()) / 2 - (int)path.controlPointRect().width()) / 2; + else + x = (width() / shapeItems.size() + - (int)path.controlPointRect().width()) / 2; + + return QPoint(x, y); +} +//! [23] + +//! [24] +QPoint SortingBox::randomItemPosition() +{ + return QPoint(qrand() % (width() - 120), qrand() % (height() - 120)); +} +//! [24] + +//! [25] +QColor SortingBox::initialItemColor() +{ + return QColor::fromHsv(((shapeItems.size() + 1) * 85) % 256, 255, 190); +} +//! [25] + +//! [26] +QColor SortingBox::randomItemColor() +{ + return QColor::fromHsv(qrand() % 256, 255, 190); +} +//! [26] diff --git a/examples/widgets/tooltips/sortingbox.h b/examples/widgets/tooltips/sortingbox.h new file mode 100644 index 0000000..fb565cd --- /dev/null +++ b/examples/widgets/tooltips/sortingbox.h @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SORTINGBOX_H +#define SORTINGBOX_H + +#include <QWidget> + +#include "shapeitem.h" + +QT_BEGIN_NAMESPACE +class QAction; +class QPoint; +class QToolButton; +QT_END_NAMESPACE + +//! [0] +class SortingBox : public QWidget +{ + Q_OBJECT + +public: + SortingBox(); + +protected: + bool event(QEvent *event); + void resizeEvent(QResizeEvent *event); + void paintEvent(QPaintEvent *event); + void mousePressEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + +private slots: + void createNewCircle(); + void createNewSquare(); + void createNewTriangle(); +//! [0] + +//! [1] +private: + int updateButtonGeometry(QToolButton *button, int x, int y); + void createShapeItem(const QPainterPath &path, const QString &toolTip, + const QPoint &pos, const QColor &color); + int itemAt(const QPoint &pos); + void moveItemTo(const QPoint &pos); + QPoint initialItemPosition(const QPainterPath &path); + QPoint randomItemPosition(); + QColor initialItemColor(); + QColor randomItemColor(); + QToolButton *createToolButton(const QString &toolTip, const QIcon &icon, +//! [1] + const char *member); + +//! [2] + QList<ShapeItem> shapeItems; + QPainterPath circlePath; + QPainterPath squarePath; + QPainterPath trianglePath; + + QPoint previousPosition; + ShapeItem *itemInMotion; + + QToolButton *newCircleButton; + QToolButton *newSquareButton; + QToolButton *newTriangleButton; +}; +//! [2] + +#endif diff --git a/examples/widgets/tooltips/tooltips.pro b/examples/widgets/tooltips/tooltips.pro new file mode 100644 index 0000000..9f0bf41 --- /dev/null +++ b/examples/widgets/tooltips/tooltips.pro @@ -0,0 +1,12 @@ +HEADERS = shapeitem.h \ + sortingbox.h +SOURCES = main.cpp \ + shapeItem.cpp \ + sortingbox.cpp +RESOURCES = tooltips.qrc + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/widgets/tooltips +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS tooltips.pro images +sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/tooltips +INSTALLS += target sources diff --git a/examples/widgets/tooltips/tooltips.qrc b/examples/widgets/tooltips/tooltips.qrc new file mode 100644 index 0000000..dabc894 --- /dev/null +++ b/examples/widgets/tooltips/tooltips.qrc @@ -0,0 +1,7 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>images/circle.png</file> + <file>images/square.png</file> + <file>images/triangle.png</file> +</qresource> +</RCC> diff --git a/examples/widgets/validators/ledoff.png b/examples/widgets/validators/ledoff.png Binary files differnew file mode 100644 index 0000000..8b1f2ed --- /dev/null +++ b/examples/widgets/validators/ledoff.png diff --git a/examples/widgets/validators/ledon.png b/examples/widgets/validators/ledon.png Binary files differnew file mode 100644 index 0000000..601c34d --- /dev/null +++ b/examples/widgets/validators/ledon.png diff --git a/examples/widgets/validators/ledwidget.cpp b/examples/widgets/validators/ledwidget.cpp new file mode 100644 index 0000000..9213755 --- /dev/null +++ b/examples/widgets/validators/ledwidget.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "ledwidget.h" + +LEDWidget::LEDWidget(QWidget *parent) + : QLabel(parent), onPixmap(":/ledon.png"), offPixmap(":/ledoff.png") +{ + setPixmap(offPixmap); + flashTimer.setInterval(200); + flashTimer.setSingleShot(true); + connect(&flashTimer, SIGNAL(timeout()), this, SLOT(extinguish())); +}; + +void LEDWidget::extinguish() +{ + setPixmap(offPixmap); +} + +void LEDWidget::flash() +{ + setPixmap(onPixmap); + flashTimer.start(); +} + diff --git a/examples/widgets/validators/ledwidget.h b/examples/widgets/validators/ledwidget.h new file mode 100644 index 0000000..08992f9 --- /dev/null +++ b/examples/widgets/validators/ledwidget.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef LEDWIDGET_H +#define LEDWIDGET_H + +#include <QLabel> +#include <QPixmap> +#include <QTimer> + +class LEDWidget : public QLabel +{ + Q_OBJECT +public: + LEDWidget(QWidget *parent = 0); +public slots: + void flash(); + +private slots: + void extinguish(); + +private: + QPixmap onPixmap, offPixmap; + QTimer flashTimer; +}; + +#endif // LEDWIDGET_H diff --git a/examples/widgets/validators/localeselector.cpp b/examples/widgets/validators/localeselector.cpp new file mode 100644 index 0000000..b725d26 --- /dev/null +++ b/examples/widgets/validators/localeselector.cpp @@ -0,0 +1,313 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "localeselector.h" +#include <QLocale> + +struct SupportedLocale +{ + int lang, country; +}; + +const SupportedLocale SUPPORTED_LOCALES[] = { + { 1, 0 }, // C/AnyCountry + { 3, 69 }, // Afan/Ethiopia + { 3, 111 }, // Afan/Kenya + { 4, 59 }, // Afar/Djibouti + { 4, 67 }, // Afar/Eritrea + { 4, 69 }, // Afar/Ethiopia + { 5, 195 }, // Afrikaans/SouthAfrica + { 5, 148 }, // Afrikaans/Namibia + { 6, 2 }, // Albanian/Albania + { 7, 69 }, // Amharic/Ethiopia + { 8, 186 }, // Arabic/SaudiArabia + { 8, 3 }, // Arabic/Algeria + { 8, 17 }, // Arabic/Bahrain + { 8, 64 }, // Arabic/Egypt + { 8, 103 }, // Arabic/Iraq + { 8, 109 }, // Arabic/Jordan + { 8, 115 }, // Arabic/Kuwait + { 8, 119 }, // Arabic/Lebanon + { 8, 122 }, // Arabic/LibyanArabJamahiriya + { 8, 145 }, // Arabic/Morocco + { 8, 162 }, // Arabic/Oman + { 8, 175 }, // Arabic/Qatar + { 8, 201 }, // Arabic/Sudan + { 8, 207 }, // Arabic/SyrianArabRepublic + { 8, 216 }, // Arabic/Tunisia + { 8, 223 }, // Arabic/UnitedArabEmirates + { 8, 237 }, // Arabic/Yemen + { 9, 11 }, // Armenian/Armenia + { 10, 100 }, // Assamese/India + { 12, 15 }, // Azerbaijani/Azerbaijan + { 14, 197 }, // Basque/Spain + { 15, 18 }, // Bengali/Bangladesh + { 15, 100 }, // Bengali/India + { 16, 25 }, // Bhutani/Bhutan + { 20, 33 }, // Bulgarian/Bulgaria + { 22, 20 }, // Byelorussian/Belarus + { 23, 36 }, // Cambodian/Cambodia + { 24, 197 }, // Catalan/Spain + { 25, 44 }, // Chinese/China + { 25, 97 }, // Chinese/HongKong + { 25, 126 }, // Chinese/Macau + { 25, 190 }, // Chinese/Singapore + { 25, 208 }, // Chinese/Taiwan + { 27, 54 }, // Croatian/Croatia + { 28, 57 }, // Czech/CzechRepublic + { 29, 58 }, // Danish/Denmark + { 30, 151 }, // Dutch/Netherlands + { 30, 21 }, // Dutch/Belgium + { 31, 225 }, // English/UnitedStates + { 31, 4 }, // English/AmericanSamoa + { 31, 13 }, // English/Australia + { 31, 21 }, // English/Belgium + { 31, 22 }, // English/Belize + { 31, 28 }, // English/Botswana + { 31, 38 }, // English/Canada + { 31, 89 }, // English/Guam + { 31, 97 }, // English/HongKong + { 31, 100 }, // English/India + { 31, 104 }, // English/Ireland + { 31, 107 }, // English/Jamaica + { 31, 133 }, // English/Malta + { 31, 134 }, // English/MarshallIslands + { 31, 148 }, // English/Namibia + { 31, 154 }, // English/NewZealand + { 31, 160 }, // English/NorthernMarianaIslands + { 31, 163 }, // English/Pakistan + { 31, 170 }, // English/Philippines + { 31, 190 }, // English/Singapore + { 31, 195 }, // English/SouthAfrica + { 31, 215 }, // English/TrinidadAndTobago + { 31, 224 }, // English/UnitedKingdom + { 31, 226 }, // English/UnitedStatesMinorOutlyingIslands + { 31, 234 }, // English/USVirginIslands + { 31, 240 }, // English/Zimbabwe + { 33, 68 }, // Estonian/Estonia + { 34, 71 }, // Faroese/FaroeIslands + { 36, 73 }, // Finnish/Finland + { 37, 74 }, // French/France + { 37, 21 }, // French/Belgium + { 37, 38 }, // French/Canada + { 37, 125 }, // French/Luxembourg + { 37, 142 }, // French/Monaco + { 37, 206 }, // French/Switzerland + { 40, 197 }, // Galician/Spain + { 41, 81 }, // Georgian/Georgia + { 42, 82 }, // German/Germany + { 42, 14 }, // German/Austria + { 42, 21 }, // German/Belgium + { 42, 123 }, // German/Liechtenstein + { 42, 125 }, // German/Luxembourg + { 42, 206 }, // German/Switzerland + { 43, 85 }, // Greek/Greece + { 43, 56 }, // Greek/Cyprus + { 44, 86 }, // Greenlandic/Greenland + { 46, 100 }, // Gujarati/India + { 47, 83 }, // Hausa/Ghana + { 47, 156 }, // Hausa/Niger + { 47, 157 }, // Hausa/Nigeria + { 48, 105 }, // Hebrew/Israel + { 49, 100 }, // Hindi/India + { 50, 98 }, // Hungarian/Hungary + { 51, 99 }, // Icelandic/Iceland + { 52, 101 }, // Indonesian/Indonesia + { 57, 104 }, // Irish/Ireland + { 58, 106 }, // Italian/Italy + { 58, 206 }, // Italian/Switzerland + { 59, 108 }, // Japanese/Japan + { 61, 100 }, // Kannada/India + { 63, 110 }, // Kazakh/Kazakhstan + { 64, 179 }, // Kinyarwanda/Rwanda + { 65, 116 }, // Kirghiz/Kyrgyzstan + { 66, 114 }, // Korean/RepublicOfKorea + { 67, 102 }, // Kurdish/Iran + { 67, 103 }, // Kurdish/Iraq + { 67, 207 }, // Kurdish/SyrianArabRepublic + { 67, 217 }, // Kurdish/Turkey + { 69, 117 }, // Laothian/Lao + { 71, 118 }, // Latvian/Latvia + { 72, 49 }, // Lingala/DemocraticRepublicOfCongo + { 72, 50 }, // Lingala/PeoplesRepublicOfCongo + { 73, 124 }, // Lithuanian/Lithuania + { 74, 127 }, // Macedonian/Macedonia + { 76, 130 }, // Malay/Malaysia + { 76, 32 }, // Malay/BruneiDarussalam + { 77, 100 }, // Malayalam/India + { 78, 133 }, // Maltese/Malta + { 80, 100 }, // Marathi/India + { 82, 143 }, // Mongolian/Mongolia + { 84, 150 }, // Nepali/Nepal + { 85, 161 }, // Norwegian/Norway + { 87, 100 }, // Oriya/India + { 88, 1 }, // Pashto/Afghanistan + { 89, 102 }, // Persian/Iran + { 89, 1 }, // Persian/Afghanistan + { 90, 172 }, // Polish/Poland + { 91, 173 }, // Portuguese/Portugal + { 91, 30 }, // Portuguese/Brazil + { 92, 100 }, // Punjabi/India + { 92, 163 }, // Punjabi/Pakistan + { 95, 177 }, // Romanian/Romania + { 96, 178 }, // Russian/RussianFederation + { 96, 222 }, // Russian/Ukraine + { 99, 100 }, // Sanskrit/India + { 100, 241 }, // Serbian/SerbiaAndMontenegro + { 100, 27 }, // Serbian/BosniaAndHerzegowina + { 100, 238 }, // Serbian/Yugoslavia + { 101, 241 }, // SerboCroatian/SerbiaAndMontenegro + { 101, 27 }, // SerboCroatian/BosniaAndHerzegowina + { 101, 238 }, // SerboCroatian/Yugoslavia + { 102, 195 }, // Sesotho/SouthAfrica + { 103, 195 }, // Setswana/SouthAfrica + { 107, 195 }, // Siswati/SouthAfrica + { 108, 191 }, // Slovak/Slovakia + { 109, 192 }, // Slovenian/Slovenia + { 110, 194 }, // Somali/Somalia + { 110, 59 }, // Somali/Djibouti + { 110, 69 }, // Somali/Ethiopia + { 110, 111 }, // Somali/Kenya + { 111, 197 }, // Spanish/Spain + { 111, 10 }, // Spanish/Argentina + { 111, 26 }, // Spanish/Bolivia + { 111, 43 }, // Spanish/Chile + { 111, 47 }, // Spanish/Colombia + { 111, 52 }, // Spanish/CostaRica + { 111, 61 }, // Spanish/DominicanRepublic + { 111, 63 }, // Spanish/Ecuador + { 111, 65 }, // Spanish/ElSalvador + { 111, 90 }, // Spanish/Guatemala + { 111, 96 }, // Spanish/Honduras + { 111, 139 }, // Spanish/Mexico + { 111, 155 }, // Spanish/Nicaragua + { 111, 166 }, // Spanish/Panama + { 111, 168 }, // Spanish/Paraguay + { 111, 169 }, // Spanish/Peru + { 111, 174 }, // Spanish/PuertoRico + { 111, 225 }, // Spanish/UnitedStates + { 111, 227 }, // Spanish/Uruguay + { 111, 231 }, // Spanish/Venezuela + { 113, 111 }, // Swahili/Kenya + { 113, 210 }, // Swahili/Tanzania + { 114, 205 }, // Swedish/Sweden + { 114, 73 }, // Swedish/Finland + { 116, 209 }, // Tajik/Tajikistan + { 117, 100 }, // Tamil/India + { 118, 178 }, // Tatar/RussianFederation + { 119, 100 }, // Telugu/India + { 120, 211 }, // Thai/Thailand + { 122, 67 }, // Tigrinya/Eritrea + { 122, 69 }, // Tigrinya/Ethiopia + { 124, 195 }, // Tsonga/SouthAfrica + { 125, 217 }, // Turkish/Turkey + { 129, 222 }, // Ukrainian/Ukraine + { 130, 100 }, // Urdu/India + { 130, 163 }, // Urdu/Pakistan + { 131, 228 }, // Uzbek/Uzbekistan + { 131, 1 }, // Uzbek/Afghanistan + { 132, 232 }, // Vietnamese/VietNam + { 134, 224 }, // Welsh/UnitedKingdom + { 136, 195 }, // Xhosa/SouthAfrica + { 138, 157 }, // Yoruba/Nigeria + { 140, 195 }, // Zulu/SouthAfrica + { 141, 161 }, // Nynorsk/Norway + { 142, 27 }, // Bosnian/BosniaAndHerzegowina + { 143, 131 }, // Divehi/Maldives + { 144, 224 }, // Manx/UnitedKingdom + { 145, 224 }, // Cornish/UnitedKingdom + { 146, 83 }, // Akan/Ghana + { 147, 100 }, // Konkani/India + { 148, 83 }, // Ga/Ghana + { 149, 157 }, // Igbo/Nigeria + { 150, 111 }, // Kamba/Kenya + { 151, 207 }, // Syriac/SyrianArabRepublic + { 152, 67 }, // Blin/Eritrea + { 153, 67 }, // Geez/Eritrea + { 153, 69 }, // Geez/Ethiopia + { 154, 157 }, // Koro/Nigeria + { 155, 69 }, // Sidamo/Ethiopia + { 156, 157 }, // Atsam/Nigeria + { 157, 67 }, // Tigre/Eritrea + { 158, 157 }, // Jju/Nigeria + { 159, 106 }, // Friulian/Italy + { 160, 195 }, // Venda/SouthAfrica + { 161, 83 }, // Ewe/Ghana + { 161, 212 }, // Ewe/Togo + { 163, 225 }, // Hawaiian/UnitedStates + { 164, 157 }, // Tyap/Nigeria + { 165, 129 } // Chewa/Malawi +}; + +const int SUPPORTED_LOCALES_COUNT = sizeof(SUPPORTED_LOCALES)/sizeof(SupportedLocale); + +typedef QPair<int, int> IntPair; +Q_DECLARE_METATYPE(SupportedLocale) + +LocaleSelector::LocaleSelector(QWidget *parent) + : QComboBox(parent) +{ + int curIndex = -1; + QLocale curLocale; + + for (int i = 0; i < SUPPORTED_LOCALES_COUNT; ++i) { + const SupportedLocale &l = SUPPORTED_LOCALES[i]; + if (l.lang == curLocale.language() && l.country == curLocale.country()) + curIndex = i; + QString text = QLocale::languageToString(QLocale::Language(l.lang)) + + QLatin1Char('/') + + QLocale::countryToString(QLocale::Country(l.country)); + addItem(text, qVariantFromValue(l)); + } + + setCurrentIndex(curIndex); + + connect(this, SIGNAL(activated(int)), this, SLOT(emitLocaleSelected(int))); +} + +void LocaleSelector::emitLocaleSelected(int index) +{ + QVariant v = itemData(index); + if (!v.isValid()) + return; + SupportedLocale l = qVariantValue<SupportedLocale>(v); + emit localeSelected(QLocale(QLocale::Language(l.lang), QLocale::Country(l.country))); +} diff --git a/examples/widgets/validators/localeselector.h b/examples/widgets/validators/localeselector.h new file mode 100644 index 0000000..763b58b --- /dev/null +++ b/examples/widgets/validators/localeselector.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef LOCALESELECTOR_H +#define LOCALESELECTOR_H + +#include <QComboBox> + +class LocaleSelector : public QComboBox +{ + Q_OBJECT + +public: + LocaleSelector(QWidget *parent = 0); + +signals: + void localeSelected(const QLocale &locale); + +private slots: + void emitLocaleSelected(int index); +}; + +#endif //LOCALESELECTOR_H diff --git a/examples/widgets/validators/main.cpp b/examples/widgets/validators/main.cpp new file mode 100644 index 0000000..6822b62 --- /dev/null +++ b/examples/widgets/validators/main.cpp @@ -0,0 +1,137 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <qdebug.h> +#include <QApplication> +#include <QLineEdit> +#include <QValidator> + +#include "ui_validators.h" + +class ValidatorWidget : public QWidget, public Ui::ValidatorsForm +{ + Q_OBJECT +public: + ValidatorWidget(QWidget *parent = 0); + +private slots: + void updateValidator(); + void updateDoubleValidator(); + void _setLocale(const QLocale &l) { setLocale(l); updateValidator(); updateDoubleValidator(); } + +private: + QIntValidator *validator; + QDoubleValidator *doubleValidator; +}; + +ValidatorWidget::ValidatorWidget(QWidget *parent) + : QWidget(parent) +{ + setupUi(this); + + connect(localeSelector, SIGNAL(localeSelected(QLocale)), this, SLOT(_setLocale(QLocale))); + + connect(minVal, SIGNAL(editingFinished()), this, SLOT(updateValidator())); + connect(maxVal, SIGNAL(editingFinished()), this, SLOT(updateValidator())); + connect(editor, SIGNAL(editingFinished()), ledWidget, SLOT(flash())); + + connect(doubleMaxVal, SIGNAL(editingFinished()), this, SLOT(updateDoubleValidator())); + connect(doubleMinVal, SIGNAL(editingFinished()), this, SLOT(updateDoubleValidator())); + connect(doubleDecimals, SIGNAL(valueChanged(int)), this, SLOT(updateDoubleValidator())); + connect(doubleFormat, SIGNAL(activated(int)), this, SLOT(updateDoubleValidator())); + connect(doubleEditor, SIGNAL(editingFinished()), doubleLedWidget, SLOT(flash())); + + validator = 0; + doubleValidator = 0; + updateValidator(); + updateDoubleValidator(); +}; + +void ValidatorWidget::updateValidator() +{ + QIntValidator *v = new QIntValidator(minVal->value(), maxVal->value(), this); + v->setLocale(locale()); + editor->setValidator(v); + delete validator; + validator = v; + + QString s = editor->text(); + int i = 0; + if (validator->validate(s, i) == QValidator::Invalid) { + editor->clear(); + } else { + editor->setText(s); + } +} + +void ValidatorWidget::updateDoubleValidator() +{ + QDoubleValidator *v + = new QDoubleValidator(doubleMinVal->value(), doubleMaxVal->value(), + doubleDecimals->value(), this); + v->setNotation(static_cast<QDoubleValidator::Notation>(doubleFormat->currentIndex())); + v->setLocale(locale()); + doubleEditor->setValidator(v); + delete doubleValidator; + doubleValidator = v; + + QString s = doubleEditor->text(); + int i = 0; + if (doubleValidator->validate(s, i) == QValidator::Invalid) { + doubleEditor->clear(); + } else { + doubleEditor->setText(s); + } +} + +int main(int argc, char **argv) +{ + Q_INIT_RESOURCE(validators); + + QApplication app(argc, argv); + + ValidatorWidget w; + w.show(); + + return app.exec(); +} + +#include "main.moc" diff --git a/examples/widgets/validators/validators.pro b/examples/widgets/validators/validators.pro new file mode 100644 index 0000000..8e7884d --- /dev/null +++ b/examples/widgets/validators/validators.pro @@ -0,0 +1,21 @@ +###################################################################### +# Automatically generated by qmake (2.01a) Tue Nov 28 13:20:04 2006 +###################################################################### + +TEMPLATE = app +TARGET = validators +DEPENDPATH += . +INCLUDEPATH += . + +FORMS += validators.ui +RESOURCES += validators.qrc + +# Input +SOURCES += main.cpp ledwidget.cpp localeselector.cpp +HEADERS += ledwidget.h localeselector.h + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/widgets/validators +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro *.png +sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/validators +INSTALLS += target sources diff --git a/examples/widgets/validators/validators.qrc b/examples/widgets/validators/validators.qrc new file mode 100644 index 0000000..9487431 --- /dev/null +++ b/examples/widgets/validators/validators.qrc @@ -0,0 +1,6 @@ +<RCC> + <qresource prefix="/" > + <file>ledoff.png</file> + <file>ledon.png</file> + </qresource> +</RCC> diff --git a/examples/widgets/validators/validators.ui b/examples/widgets/validators/validators.ui new file mode 100644 index 0000000..f05b96f --- /dev/null +++ b/examples/widgets/validators/validators.ui @@ -0,0 +1,467 @@ +<ui version="4.0" > + <class>ValidatorsForm</class> + <widget class="QWidget" name="ValidatorsForm" > + <property name="geometry" > + <rect> + <x>0</x> + <y>0</y> + <width>526</width> + <height>668</height> + </rect> + </property> + <property name="windowTitle" > + <string>Form</string> + </property> + <layout class="QVBoxLayout" > + <property name="margin" > + <number>9</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <layout class="QHBoxLayout" > + <property name="margin" > + <number>0</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <widget class="LocaleSelector" name="localeSelector" /> + </item> + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" > + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + <item> + <widget class="QGroupBox" name="groupBox" > + <property name="title" > + <string>QIntValidator</string> + </property> + <layout class="QVBoxLayout" > + <property name="margin" > + <number>9</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <layout class="QHBoxLayout" > + <property name="margin" > + <number>0</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <layout class="QGridLayout" > + <property name="margin" > + <number>0</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item row="0" column="0" > + <widget class="QLabel" name="label" > + <property name="text" > + <string>Min:</string> + </property> + <property name="alignment" > + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item row="0" column="1" > + <widget class="QSpinBox" name="minVal" > + <property name="sizePolicy" > + <sizepolicy vsizetype="Fixed" hsizetype="Minimum" > + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimum" > + <number>-1000000</number> + </property> + <property name="maximum" > + <number>1000000</number> + </property> + </widget> + </item> + <item row="1" column="0" > + <widget class="QLabel" name="label_2" > + <property name="text" > + <string>Max:</string> + </property> + <property name="alignment" > + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item row="1" column="1" > + <widget class="QSpinBox" name="maxVal" > + <property name="sizePolicy" > + <sizepolicy vsizetype="Fixed" hsizetype="Minimum" > + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimum" > + <number>-1000000</number> + </property> + <property name="maximum" > + <number>1000000</number> + </property> + <property name="value" > + <number>1000</number> + </property> + </widget> + </item> + </layout> + </item> + <item> + <widget class="QFrame" name="frame" > + <property name="frameShape" > + <enum>QFrame::StyledPanel</enum> + </property> + <property name="frameShadow" > + <enum>QFrame::Sunken</enum> + </property> + <layout class="QVBoxLayout" > + <property name="margin" > + <number>9</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <widget class="LEDWidget" name="ledWidget" > + <property name="sizePolicy" > + <sizepolicy vsizetype="Fixed" hsizetype="Preferred" > + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="pixmap" > + <pixmap resource="validators.qrc" >:/ledoff.png</pixmap> + </property> + <property name="alignment" > + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="label_7" > + <property name="text" > + <string>editingFinished()</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + </layout> + </item> + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Vertical</enum> + </property> + <property name="sizeType" > + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" > + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QLineEdit" name="editor" /> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QGroupBox" name="groupBox_2" > + <property name="title" > + <string>QDoubleValidator</string> + </property> + <layout class="QVBoxLayout" > + <property name="margin" > + <number>9</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <layout class="QHBoxLayout" > + <property name="margin" > + <number>0</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <layout class="QGridLayout" > + <property name="margin" > + <number>0</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item row="0" column="0" > + <widget class="QLabel" name="label_3" > + <property name="text" > + <string>Min:</string> + </property> + <property name="alignment" > + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item row="0" column="1" > + <widget class="QDoubleSpinBox" name="doubleMinVal" > + <property name="sizePolicy" > + <sizepolicy vsizetype="Fixed" hsizetype="Minimum" > + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimum" > + <double>-100000.000000000000000</double> + </property> + <property name="maximum" > + <double>100000.000000000000000</double> + </property> + <property name="value" > + <double>0.000000000000000</double> + </property> + </widget> + </item> + <item row="0" column="2" > + <widget class="QLabel" name="label_5" > + <property name="text" > + <string>Format:</string> + </property> + <property name="alignment" > + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item row="0" column="3" > + <widget class="QComboBox" name="doubleFormat" > + <item> + <property name="text" > + <string>Standard</string> + </property> + </item> + <item> + <property name="text" > + <string>Scientific</string> + </property> + </item> + </widget> + </item> + <item row="1" column="0" > + <widget class="QLabel" name="label_4" > + <property name="text" > + <string>Max:</string> + </property> + <property name="alignment" > + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item row="1" column="1" > + <widget class="QDoubleSpinBox" name="doubleMaxVal" > + <property name="sizePolicy" > + <sizepolicy vsizetype="Fixed" hsizetype="Minimum" > + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimum" > + <double>-100000.000000000000000</double> + </property> + <property name="maximum" > + <double>100000.000000000000000</double> + </property> + <property name="value" > + <double>1000.000000000000000</double> + </property> + </widget> + </item> + <item row="1" column="2" > + <widget class="QLabel" name="label_6" > + <property name="text" > + <string>Decimals:</string> + </property> + <property name="alignment" > + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item row="1" column="3" > + <widget class="QSpinBox" name="doubleDecimals" > + <property name="value" > + <number>2</number> + </property> + </widget> + </item> + </layout> + </item> + <item> + <widget class="QFrame" name="frame_2" > + <property name="frameShape" > + <enum>QFrame::StyledPanel</enum> + </property> + <property name="frameShadow" > + <enum>QFrame::Sunken</enum> + </property> + <layout class="QVBoxLayout" > + <property name="margin" > + <number>9</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <widget class="LEDWidget" name="doubleLedWidget" > + <property name="text" > + <string/> + </property> + <property name="pixmap" > + <pixmap resource="validators.qrc" >:/ledoff.png</pixmap> + </property> + <property name="alignment" > + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="label_8" > + <property name="text" > + <string>editingFinished()</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + </layout> + </item> + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Vertical</enum> + </property> + <property name="sizeType" > + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" > + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QLineEdit" name="doubleEditor" /> + </item> + </layout> + </widget> + </item> + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" > + <size> + <width>20</width> + <height>111</height> + </size> + </property> + </spacer> + </item> + <item> + <layout class="QHBoxLayout" > + <property name="margin" > + <number>0</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" > + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QPushButton" name="pushButton" > + <property name="text" > + <string>Quit</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + <customwidgets> + <customwidget> + <class>LEDWidget</class> + <extends>QLabel</extends> + <header>ledwidget.h</header> + </customwidget> + <customwidget> + <class>LocaleSelector</class> + <extends>QComboBox</extends> + <header>localeselector.h</header> + </customwidget> + </customwidgets> + <resources> + <include location="validators.qrc" /> + </resources> + <connections> + <connection> + <sender>pushButton</sender> + <signal>clicked()</signal> + <receiver>ValidatorsForm</receiver> + <slot>close()</slot> + <hints> + <hint type="sourcelabel" > + <x>94</x> + <y>274</y> + </hint> + <hint type="destinationlabel" > + <x>131</x> + <y>260</y> + </hint> + </hints> + </connection> + </connections> +</ui> diff --git a/examples/widgets/widgets.pro b/examples/widgets/widgets.pro new file mode 100644 index 0000000..0af83c7 --- /dev/null +++ b/examples/widgets/widgets.pro @@ -0,0 +1,31 @@ +TEMPLATE = subdirs +SUBDIRS = analogclock \ + calculator \ + calendarwidget \ + charactermap \ + codeeditor \ + digitalclock \ + groupbox \ + icons \ + imageviewer \ + lineedits \ + movie \ + scribble \ + shapedclock \ + sliders \ + spinboxes \ + stylesheet \ + tablet \ + tetrix \ + tooltips \ + validators \ + wiggly \ + windowflags + +contains(styles, motif): SUBDIRS += styles + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/widgets +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS widgets.pro README +sources.path = $$[QT_INSTALL_EXAMPLES]/widgets +INSTALLS += target sources diff --git a/examples/widgets/wiggly/dialog.cpp b/examples/widgets/wiggly/dialog.cpp new file mode 100644 index 0000000..2f4191d --- /dev/null +++ b/examples/widgets/wiggly/dialog.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "dialog.h" +#include "wigglywidget.h" + +//! [0] +Dialog::Dialog(QWidget *parent) + : QDialog(parent) +{ + WigglyWidget *wigglyWidget = new WigglyWidget; + QLineEdit *lineEdit = new QLineEdit; + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(wigglyWidget); + layout->addWidget(lineEdit); + setLayout(layout); + + connect(lineEdit, SIGNAL(textChanged(QString)), + wigglyWidget, SLOT(setText(QString))); + + lineEdit->setText(tr("Hello world!")); + + setWindowTitle(tr("Wiggly")); + resize(360, 145); +} +//! [0] diff --git a/examples/widgets/wiggly/dialog.h b/examples/widgets/wiggly/dialog.h new file mode 100644 index 0000000..9c209e1 --- /dev/null +++ b/examples/widgets/wiggly/dialog.h @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef DIALOG_H +#define DIALOG_H + +#include <QDialog> + +//! [0] +class Dialog : public QDialog +{ + Q_OBJECT + +public: + Dialog(QWidget *parent = 0); +}; +//! [0] + +#endif diff --git a/examples/widgets/wiggly/main.cpp b/examples/widgets/wiggly/main.cpp new file mode 100644 index 0000000..872dce6 --- /dev/null +++ b/examples/widgets/wiggly/main.cpp @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> + +#include "dialog.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + Dialog dialog; + dialog.show(); + return app.exec(); +} diff --git a/examples/widgets/wiggly/wiggly.pro b/examples/widgets/wiggly/wiggly.pro new file mode 100644 index 0000000..5288dd3 --- /dev/null +++ b/examples/widgets/wiggly/wiggly.pro @@ -0,0 +1,11 @@ +HEADERS = wigglywidget.h \ + dialog.h +SOURCES = wigglywidget.cpp \ + dialog.cpp \ + main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/widgets/wiggly +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS wiggly.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/wiggly +INSTALLS += target sources diff --git a/examples/widgets/wiggly/wigglywidget.cpp b/examples/widgets/wiggly/wigglywidget.cpp new file mode 100644 index 0000000..e89fdde --- /dev/null +++ b/examples/widgets/wiggly/wigglywidget.cpp @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "wigglywidget.h" + +//! [0] +WigglyWidget::WigglyWidget(QWidget *parent) + : QWidget(parent) +{ + setBackgroundRole(QPalette::Midlight); + setAutoFillBackground(true); + + QFont newFont = font(); + newFont.setPointSize(newFont.pointSize() + 20); + setFont(newFont); + + step = 0; + timer.start(60, this); +} +//! [0] + +//! [1] +void WigglyWidget::paintEvent(QPaintEvent * /* event */) +//! [1] //! [2] +{ + static const int sineTable[16] = { + 0, 38, 71, 92, 100, 92, 71, 38, 0, -38, -71, -92, -100, -92, -71, -38 + }; + + QFontMetrics metrics(font()); + int x = (width() - metrics.width(text)) / 2; + int y = (height() + metrics.ascent() - metrics.descent()) / 2; + QColor color; +//! [2] + +//! [3] + QPainter painter(this); +//! [3] //! [4] + for (int i = 0; i < text.size(); ++i) { + int index = (step + i) % 16; + color.setHsv((15 - index) * 16, 255, 191); + painter.setPen(color); + painter.drawText(x, y - ((sineTable[index] * metrics.height()) / 400), + QString(text[i])); + x += metrics.width(text[i]); + } +} +//! [4] + +//! [5] +void WigglyWidget::timerEvent(QTimerEvent *event) +//! [5] //! [6] +{ + if (event->timerId() == timer.timerId()) { + ++step; + update(); + } else { + QWidget::timerEvent(event); + } +//! [6] +} diff --git a/examples/widgets/wiggly/wigglywidget.h b/examples/widgets/wiggly/wigglywidget.h new file mode 100644 index 0000000..8b6a137 --- /dev/null +++ b/examples/widgets/wiggly/wigglywidget.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WIGGLYWIDGET_H +#define WIGGLYWIDGET_H + +#include <QBasicTimer> +#include <QWidget> + +//! [0] +class WigglyWidget : public QWidget +{ + Q_OBJECT + +public: + WigglyWidget(QWidget *parent = 0); + +public slots: + void setText(const QString &newText) { text = newText; } + +protected: + void paintEvent(QPaintEvent *event); + void timerEvent(QTimerEvent *event); + +private: + QBasicTimer timer; + QString text; + int step; +}; +//! [0] + +#endif diff --git a/examples/widgets/windowflags/controllerwindow.cpp b/examples/widgets/windowflags/controllerwindow.cpp new file mode 100644 index 0000000..075bcb3 --- /dev/null +++ b/examples/widgets/windowflags/controllerwindow.cpp @@ -0,0 +1,221 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "controllerwindow.h" + +//! [0] +ControllerWindow::ControllerWindow() +{ + previewWindow = new PreviewWindow(this); + + createTypeGroupBox(); + createHintsGroupBox(); + + quitButton = new QPushButton(tr("&Quit")); + connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit())); + + QHBoxLayout *bottomLayout = new QHBoxLayout; + bottomLayout->addStretch(); + bottomLayout->addWidget(quitButton); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addWidget(typeGroupBox); + mainLayout->addWidget(hintsGroupBox); + mainLayout->addLayout(bottomLayout); + setLayout(mainLayout); + + setWindowTitle(tr("Window Flags")); + updatePreview(); +} +//! [0] + +//! [1] +void ControllerWindow::updatePreview() +{ + Qt::WindowFlags flags = 0; + + if (windowRadioButton->isChecked()) { + flags = Qt::Window; + } else if (dialogRadioButton->isChecked()) { + flags = Qt::Dialog; + } else if (sheetRadioButton->isChecked()) { + flags = Qt::Sheet; + } else if (drawerRadioButton->isChecked()) { + flags = Qt::Drawer; + } else if (popupRadioButton->isChecked()) { + flags = Qt::Popup; + } else if (toolRadioButton->isChecked()) { + flags = Qt::Tool; + } else if (toolTipRadioButton->isChecked()) { + flags = Qt::ToolTip; + } else if (splashScreenRadioButton->isChecked()) { + flags = Qt::SplashScreen; +//! [1] //! [2] + } +//! [2] //! [3] + + if (msWindowsFixedSizeDialogCheckBox->isChecked()) + flags |= Qt::MSWindowsFixedSizeDialogHint; + if (x11BypassWindowManagerCheckBox->isChecked()) + flags |= Qt::X11BypassWindowManagerHint; + if (framelessWindowCheckBox->isChecked()) + flags |= Qt::FramelessWindowHint; + if (windowTitleCheckBox->isChecked()) + flags |= Qt::WindowTitleHint; + if (windowSystemMenuCheckBox->isChecked()) + flags |= Qt::WindowSystemMenuHint; + if (windowMinimizeButtonCheckBox->isChecked()) + flags |= Qt::WindowMinimizeButtonHint; + if (windowMaximizeButtonCheckBox->isChecked()) + flags |= Qt::WindowMaximizeButtonHint; + if (windowCloseButtonCheckBox->isChecked()) + flags |= Qt::WindowCloseButtonHint; + if (windowContextHelpButtonCheckBox->isChecked()) + flags |= Qt::WindowContextHelpButtonHint; + if (windowShadeButtonCheckBox->isChecked()) + flags |= Qt::WindowShadeButtonHint; + if (windowStaysOnTopCheckBox->isChecked()) + flags |= Qt::WindowStaysOnTopHint; + if (windowStaysOnBottomCheckBox->isChecked()) + flags |= Qt::WindowStaysOnBottomHint; + if (customizeWindowHintCheckBox->isChecked()) + flags |= Qt::CustomizeWindowHint; + + previewWindow->setWindowFlags(flags); +//! [3] //! [4] + + QPoint pos = previewWindow->pos(); + if (pos.x() < 0) + pos.setX(0); + if (pos.y() < 0) + pos.setY(0); + previewWindow->move(pos); + previewWindow->show(); +} +//! [4] + +//! [5] +void ControllerWindow::createTypeGroupBox() +{ + typeGroupBox = new QGroupBox(tr("Type")); + + windowRadioButton = createRadioButton(tr("Window")); + dialogRadioButton = createRadioButton(tr("Dialog")); + sheetRadioButton = createRadioButton(tr("Sheet")); + drawerRadioButton = createRadioButton(tr("Drawer")); + popupRadioButton = createRadioButton(tr("Popup")); + toolRadioButton = createRadioButton(tr("Tool")); + toolTipRadioButton = createRadioButton(tr("Tooltip")); + splashScreenRadioButton = createRadioButton(tr("Splash screen")); + windowRadioButton->setChecked(true); + + QGridLayout *layout = new QGridLayout; + layout->addWidget(windowRadioButton, 0, 0); + layout->addWidget(dialogRadioButton, 1, 0); + layout->addWidget(sheetRadioButton, 2, 0); + layout->addWidget(drawerRadioButton, 3, 0); + layout->addWidget(popupRadioButton, 0, 1); + layout->addWidget(toolRadioButton, 1, 1); + layout->addWidget(toolTipRadioButton, 2, 1); + layout->addWidget(splashScreenRadioButton, 3, 1); + typeGroupBox->setLayout(layout); +} +//! [5] + +//! [6] +void ControllerWindow::createHintsGroupBox() +{ + hintsGroupBox = new QGroupBox(tr("Hints")); + + msWindowsFixedSizeDialogCheckBox = + createCheckBox(tr("MS Windows fixed size dialog")); + x11BypassWindowManagerCheckBox = + createCheckBox(tr("X11 bypass window manager")); + framelessWindowCheckBox = createCheckBox(tr("Frameless window")); + windowTitleCheckBox = createCheckBox(tr("Window title")); + windowSystemMenuCheckBox = createCheckBox(tr("Window system menu")); + windowMinimizeButtonCheckBox = createCheckBox(tr("Window minimize button")); + windowMaximizeButtonCheckBox = createCheckBox(tr("Window maximize button")); + windowCloseButtonCheckBox = createCheckBox(tr("Window close button")); + windowContextHelpButtonCheckBox = + createCheckBox(tr("Window context help button")); + windowShadeButtonCheckBox = createCheckBox(tr("Window shade button")); + windowStaysOnTopCheckBox = createCheckBox(tr("Window stays on top")); + windowStaysOnBottomCheckBox = createCheckBox(tr("Window stays on bottom")); + customizeWindowHintCheckBox= createCheckBox(tr("Customize window")); + + QGridLayout *layout = new QGridLayout; + layout->addWidget(msWindowsFixedSizeDialogCheckBox, 0, 0); + layout->addWidget(x11BypassWindowManagerCheckBox, 1, 0); + layout->addWidget(framelessWindowCheckBox, 2, 0); + layout->addWidget(windowTitleCheckBox, 3, 0); + layout->addWidget(windowSystemMenuCheckBox, 4, 0); + layout->addWidget(windowMinimizeButtonCheckBox, 0, 1); + layout->addWidget(windowMaximizeButtonCheckBox, 1, 1); + layout->addWidget(windowCloseButtonCheckBox, 2, 1); + layout->addWidget(windowContextHelpButtonCheckBox, 3, 1); + layout->addWidget(windowShadeButtonCheckBox, 4, 1); + layout->addWidget(windowStaysOnTopCheckBox, 5, 1); + layout->addWidget(windowStaysOnBottomCheckBox, 6, 1); + layout->addWidget(customizeWindowHintCheckBox, 5, 0); + hintsGroupBox->setLayout(layout); +} +//! [6] + +//! [7] +QCheckBox *ControllerWindow::createCheckBox(const QString &text) +{ + QCheckBox *checkBox = new QCheckBox(text); + connect(checkBox, SIGNAL(clicked()), this, SLOT(updatePreview())); + return checkBox; +} +//! [7] + +//! [8] +QRadioButton *ControllerWindow::createRadioButton(const QString &text) +{ + QRadioButton *button = new QRadioButton(text); + connect(button, SIGNAL(clicked()), this, SLOT(updatePreview())); + return button; +} +//! [8] diff --git a/examples/widgets/windowflags/controllerwindow.h b/examples/widgets/windowflags/controllerwindow.h new file mode 100644 index 0000000..467ab7d --- /dev/null +++ b/examples/widgets/windowflags/controllerwindow.h @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef CONTROLLERWINDOW_H +#define CONTROLLERWINDOW_H + +#include <QWidget> + +#include "previewwindow.h" + +QT_BEGIN_NAMESPACE +class QCheckBox; +class QGroupBox; +class QLabel; +class QPushButton; +class QRadioButton; +QT_END_NAMESPACE + +//! [0] +class ControllerWindow : public QWidget +{ + Q_OBJECT + +public: + ControllerWindow(); + +private slots: + void updatePreview(); + +private: + void createTypeGroupBox(); + void createHintsGroupBox(); + QCheckBox *createCheckBox(const QString &text); + QRadioButton *createRadioButton(const QString &text); + + PreviewWindow *previewWindow; + + QGroupBox *typeGroupBox; + QGroupBox *hintsGroupBox; + QPushButton *quitButton; + + QRadioButton *windowRadioButton; + QRadioButton *dialogRadioButton; + QRadioButton *sheetRadioButton; + QRadioButton *drawerRadioButton; + QRadioButton *popupRadioButton; + QRadioButton *toolRadioButton; + QRadioButton *toolTipRadioButton; + QRadioButton *splashScreenRadioButton; + + QCheckBox *msWindowsFixedSizeDialogCheckBox; + QCheckBox *x11BypassWindowManagerCheckBox; + QCheckBox *framelessWindowCheckBox; + QCheckBox *windowTitleCheckBox; + QCheckBox *windowSystemMenuCheckBox; + QCheckBox *windowMinimizeButtonCheckBox; + QCheckBox *windowMaximizeButtonCheckBox; + QCheckBox *windowCloseButtonCheckBox; + QCheckBox *windowContextHelpButtonCheckBox; + QCheckBox *windowShadeButtonCheckBox; + QCheckBox *windowStaysOnTopCheckBox; + QCheckBox *windowStaysOnBottomCheckBox; + QCheckBox *customizeWindowHintCheckBox; +}; +//! [0] + +#endif diff --git a/examples/widgets/windowflags/main.cpp b/examples/widgets/windowflags/main.cpp new file mode 100644 index 0000000..338da56 --- /dev/null +++ b/examples/widgets/windowflags/main.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> + +#include "controllerwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + ControllerWindow controller; + controller.show(); + return app.exec(); +} diff --git a/examples/widgets/windowflags/previewwindow.cpp b/examples/widgets/windowflags/previewwindow.cpp new file mode 100644 index 0000000..6fbd654 --- /dev/null +++ b/examples/widgets/windowflags/previewwindow.cpp @@ -0,0 +1,119 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "previewwindow.h" + +//! [0] +PreviewWindow::PreviewWindow(QWidget *parent) + : QWidget(parent) +{ + textEdit = new QTextEdit; + textEdit->setReadOnly(true); + textEdit->setLineWrapMode(QTextEdit::NoWrap); + + closeButton = new QPushButton(tr("&Close")); + connect(closeButton, SIGNAL(clicked()), this, SLOT(close())); + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(textEdit); + layout->addWidget(closeButton); + setLayout(layout); + + setWindowTitle(tr("Preview")); +} +//! [0] + +//! [1] +void PreviewWindow::setWindowFlags(Qt::WindowFlags flags) +{ + QWidget::setWindowFlags(flags); + + QString text; + + Qt::WindowFlags type = (flags & Qt::WindowType_Mask); + if (type == Qt::Window) { + text = "Qt::Window"; + } else if (type == Qt::Dialog) { + text = "Qt::Dialog"; + } else if (type == Qt::Sheet) { + text = "Qt::Sheet"; + } else if (type == Qt::Drawer) { + text = "Qt::Drawer"; + } else if (type == Qt::Popup) { + text = "Qt::Popup"; + } else if (type == Qt::Tool) { + text = "Qt::Tool"; + } else if (type == Qt::ToolTip) { + text = "Qt::ToolTip"; + } else if (type == Qt::SplashScreen) { + text = "Qt::SplashScreen"; + } + + if (flags & Qt::MSWindowsFixedSizeDialogHint) + text += "\n| Qt::MSWindowsFixedSizeDialogHint"; + if (flags & Qt::X11BypassWindowManagerHint) + text += "\n| Qt::X11BypassWindowManagerHint"; + if (flags & Qt::FramelessWindowHint) + text += "\n| Qt::FramelessWindowHint"; + if (flags & Qt::WindowTitleHint) + text += "\n| Qt::WindowTitleHint"; + if (flags & Qt::WindowSystemMenuHint) + text += "\n| Qt::WindowSystemMenuHint"; + if (flags & Qt::WindowMinimizeButtonHint) + text += "\n| Qt::WindowMinimizeButtonHint"; + if (flags & Qt::WindowMaximizeButtonHint) + text += "\n| Qt::WindowMaximizeButtonHint"; + if (flags & Qt::WindowCloseButtonHint) + text += "\n| Qt::WindowCloseButtonHint"; + if (flags & Qt::WindowContextHelpButtonHint) + text += "\n| Qt::WindowContextHelpButtonHint"; + if (flags & Qt::WindowShadeButtonHint) + text += "\n| Qt::WindowShadeButtonHint"; + if (flags & Qt::WindowStaysOnTopHint) + text += "\n| Qt::WindowStaysOnTopHint"; + if (flags & Qt::CustomizeWindowHint) + text += "\n| Qt::CustomizeWindowHint"; + + textEdit->setPlainText(text); +} +//! [1] diff --git a/examples/widgets/windowflags/previewwindow.h b/examples/widgets/windowflags/previewwindow.h new file mode 100644 index 0000000..22ec649 --- /dev/null +++ b/examples/widgets/windowflags/previewwindow.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PREVIEWWINDOW_H +#define PREVIEWWINDOW_H + +#include <QWidget> + +QT_BEGIN_NAMESPACE +class QPushButton; +class QTextEdit; +QT_END_NAMESPACE + +//! [0] +class PreviewWindow : public QWidget +{ + Q_OBJECT + +public: + PreviewWindow(QWidget *parent = 0); + + void setWindowFlags(Qt::WindowFlags flags); + +private: + QTextEdit *textEdit; + QPushButton *closeButton; +}; +//! [0] + +#endif diff --git a/examples/widgets/windowflags/windowflags.pro b/examples/widgets/windowflags/windowflags.pro new file mode 100644 index 0000000..fa8a567 --- /dev/null +++ b/examples/widgets/windowflags/windowflags.pro @@ -0,0 +1,11 @@ +HEADERS = controllerwindow.h \ + previewwindow.h +SOURCES = controllerwindow.cpp \ + previewwindow.cpp \ + main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/widgets/windowflags +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS windowflags.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/windowflags +INSTALLS += target sources |