diff options
author | axis <qt-info@nokia.com> | 2009-04-24 11:34:15 (GMT) |
---|---|---|
committer | axis <qt-info@nokia.com> | 2009-04-24 11:34:15 (GMT) |
commit | 8f427b2b914d5b575a4a7c0ed65d2fb8f45acc76 (patch) | |
tree | a17e1a767a89542ab59907462206d7dcf2e504b2 /examples/painting/concentriccircles | |
download | Qt-8f427b2b914d5b575a4a7c0ed65d2fb8f45acc76.zip Qt-8f427b2b914d5b575a4a7c0ed65d2fb8f45acc76.tar.gz Qt-8f427b2b914d5b575a4a7c0ed65d2fb8f45acc76.tar.bz2 |
Long live Qt for S60!
Diffstat (limited to 'examples/painting/concentriccircles')
-rw-r--r-- | examples/painting/concentriccircles/circlewidget.cpp | 125 | ||||
-rw-r--r-- | examples/painting/concentriccircles/circlewidget.h | 74 | ||||
-rw-r--r-- | examples/painting/concentriccircles/concentriccircles.pro | 15 | ||||
-rw-r--r-- | examples/painting/concentriccircles/main.cpp | 52 | ||||
-rw-r--r-- | examples/painting/concentriccircles/window.cpp | 94 | ||||
-rw-r--r-- | examples/painting/concentriccircles/window.h | 71 |
6 files changed, 431 insertions, 0 deletions
diff --git a/examples/painting/concentriccircles/circlewidget.cpp b/examples/painting/concentriccircles/circlewidget.cpp new file mode 100644 index 0000000..ab62a88 --- /dev/null +++ b/examples/painting/concentriccircles/circlewidget.cpp @@ -0,0 +1,125 @@ +/**************************************************************************** +** +** 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 "circlewidget.h" + +#include <stdlib.h> + +//! [0] +CircleWidget::CircleWidget(QWidget *parent) + : QWidget(parent) +{ + floatBased = false; + antialiased = false; + frameNo = 0; + + setBackgroundRole(QPalette::Base); + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); +} +//! [0] + +//! [1] +void CircleWidget::setFloatBased(bool floatBased) +{ + this->floatBased = floatBased; + update(); +} +//! [1] + +//! [2] +void CircleWidget::setAntialiased(bool antialiased) +{ + this->antialiased = antialiased; + update(); +} +//! [2] + +//! [3] +QSize CircleWidget::minimumSizeHint() const +{ + return QSize(50, 50); +} +//! [3] + +//! [4] +QSize CircleWidget::sizeHint() const +{ + return QSize(180, 180); +} +//! [4] + +//! [5] +void CircleWidget::nextAnimationFrame() +{ + ++frameNo; + update(); +} +//! [5] + +//! [6] +void CircleWidget::paintEvent(QPaintEvent *) +{ + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing, antialiased); + painter.translate(width() / 2, height() / 2); +//! [6] + +//! [7] + for (int diameter = 0; diameter < 256; diameter += 9) { + int delta = abs((frameNo % 128) - diameter / 2); + int alpha = 255 - (delta * delta) / 4 - diameter; +//! [7] //! [8] + if (alpha > 0) { + painter.setPen(QPen(QColor(0, diameter / 2, 127, alpha), 3)); + + if (floatBased) { + painter.drawEllipse(QRectF(-diameter / 2.0, -diameter / 2.0, + diameter, diameter)); + } else { + painter.drawEllipse(QRect(-diameter / 2, -diameter / 2, + diameter, diameter)); + } + } + } +} +//! [8] diff --git a/examples/painting/concentriccircles/circlewidget.h b/examples/painting/concentriccircles/circlewidget.h new file mode 100644 index 0000000..c5acaa8 --- /dev/null +++ b/examples/painting/concentriccircles/circlewidget.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** 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 CIRCLEWIDGET_H +#define CIRCLEWIDGET_H + +#include <QWidget> + +//! [0] +class CircleWidget : public QWidget +{ + Q_OBJECT + +public: + CircleWidget(QWidget *parent = 0); + + void setFloatBased(bool floatBased); + void setAntialiased(bool antialiased); + + QSize minimumSizeHint() const; + QSize sizeHint() const; + +public slots: + void nextAnimationFrame(); + +protected: + void paintEvent(QPaintEvent *event); + +private: + bool floatBased; + bool antialiased; + int frameNo; +}; +//! [0] + +#endif diff --git a/examples/painting/concentriccircles/concentriccircles.pro b/examples/painting/concentriccircles/concentriccircles.pro new file mode 100644 index 0000000..bf8398f --- /dev/null +++ b/examples/painting/concentriccircles/concentriccircles.pro @@ -0,0 +1,15 @@ +HEADERS = circlewidget.h \ + window.h +SOURCES = circlewidget.cpp \ + main.cpp \ + window.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/painting/concentriccircles +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS concentriccircles.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/painting/concentriccircles +INSTALLS += target sources + +include($$QT_SOURCE_TREE/examples/examplebase.pri) + +symbian:TARGET.UID3 = 0xA000A64A
\ No newline at end of file diff --git a/examples/painting/concentriccircles/main.cpp b/examples/painting/concentriccircles/main.cpp new file mode 100644 index 0000000..fa8b0ab --- /dev/null +++ b/examples/painting/concentriccircles/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/painting/concentriccircles/window.cpp b/examples/painting/concentriccircles/window.cpp new file mode 100644 index 0000000..dd5e6e5 --- /dev/null +++ b/examples/painting/concentriccircles/window.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 "circlewidget.h" +#include "window.h" + +//! [0] +Window::Window() +{ + aliasedLabel = createLabel(tr("Aliased")); + antialiasedLabel = createLabel(tr("Antialiased")); + intLabel = createLabel(tr("Int")); + floatLabel = createLabel(tr("Float")); + + QGridLayout *layout = new QGridLayout; + layout->addWidget(aliasedLabel, 0, 1); + layout->addWidget(antialiasedLabel, 0, 2); + layout->addWidget(intLabel, 1, 0); + layout->addWidget(floatLabel, 2, 0); +//! [0] + +//! [1] + QTimer *timer = new QTimer(this); + + for (int i = 0; i < 2; ++i) { + for (int j = 0; j < 2; ++j) { + circleWidgets[i][j] = new CircleWidget; + circleWidgets[i][j]->setAntialiased(j != 0); + circleWidgets[i][j]->setFloatBased(i != 0); + + connect(timer, SIGNAL(timeout()), + circleWidgets[i][j], SLOT(nextAnimationFrame())); + + layout->addWidget(circleWidgets[i][j], i + 1, j + 1); + } + } +//! [1] //! [2] + timer->start(100); + setLayout(layout); + + setWindowTitle(tr("Concentric Circles")); +} +//! [2] + +//! [3] +QLabel *Window::createLabel(const QString &text) +{ + QLabel *label = new QLabel(text); + label->setAlignment(Qt::AlignCenter); + label->setMargin(2); + label->setFrameStyle(QFrame::Box | QFrame::Sunken); + return label; +} +//! [3] diff --git a/examples/painting/concentriccircles/window.h b/examples/painting/concentriccircles/window.h new file mode 100644 index 0000000..2b3ad67 --- /dev/null +++ b/examples/painting/concentriccircles/window.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 WINDOW_H +#define WINDOW_H + +#include <QWidget> + +QT_BEGIN_NAMESPACE +class QLabel; +QT_END_NAMESPACE +class CircleWidget; + +//! [0] +class Window : public QWidget +{ + Q_OBJECT + +public: + Window(); + +private: + QLabel *createLabel(const QString &text); + + QLabel *aliasedLabel; + QLabel *antialiasedLabel; + QLabel *intLabel; + QLabel *floatLabel; + CircleWidget *circleWidgets[2][2]; +}; +//! [0] + +#endif |