diff options
author | David Boddie <dboddie@trolltech.com> | 2009-10-09 16:45:44 (GMT) |
---|---|---|
committer | David Boddie <dboddie@trolltech.com> | 2009-10-09 16:57:41 (GMT) |
commit | 7566a1f15ea32504c10d9467fb69a6399a06c325 (patch) | |
tree | c14591fa1e662f1d61233c1af580b4db6b7cab84 /doc/src/snippets | |
parent | db77c5b9c74dc022fc2b37fae73ddbbe89e89c07 (diff) | |
download | Qt-7566a1f15ea32504c10d9467fb69a6399a06c325.zip Qt-7566a1f15ea32504c10d9467fb69a6399a06c325.tar.gz Qt-7566a1f15ea32504c10d9467fb69a6399a06c325.tar.bz2 |
Doc: Created a snippet to generate the global colors image.
Reviewed-by: Trust Me
Diffstat (limited to 'doc/src/snippets')
-rw-r--r-- | doc/src/snippets/colors/colors.pro | 2 | ||||
-rw-r--r-- | doc/src/snippets/colors/main.cpp | 52 | ||||
-rw-r--r-- | doc/src/snippets/colors/window.cpp | 131 | ||||
-rw-r--r-- | doc/src/snippets/colors/window.h | 53 |
4 files changed, 238 insertions, 0 deletions
diff --git a/doc/src/snippets/colors/colors.pro b/doc/src/snippets/colors/colors.pro new file mode 100644 index 0000000..b2cc87d --- /dev/null +++ b/doc/src/snippets/colors/colors.pro @@ -0,0 +1,2 @@ +HEADERS = window.h +SOURCES = main.cpp window.cpp diff --git a/doc/src/snippets/colors/main.cpp b/doc/src/snippets/colors/main.cpp new file mode 100644 index 0000000..4e09036 --- /dev/null +++ b/doc/src/snippets/colors/main.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the documentation 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> +#include "window.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + Window window; + window.setFixedSize(640, 215); + window.show(); + return app.exec(); +} diff --git a/doc/src/snippets/colors/window.cpp b/doc/src/snippets/colors/window.cpp new file mode 100644 index 0000000..0cec5f5 --- /dev/null +++ b/doc/src/snippets/colors/window.cpp @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the documentation 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> +#include "window.h" + +Window::Window(QWidget *parent) + : QWidget(parent) +{ + QFont font; + font.setPixelSize(12); + setFont(font); +} + +void Window::closeEvent(QCloseEvent *event) +{ + QPixmap pixmap(size()); + render(&pixmap); + pixmap.save("qt-colors.png"); + + event->accept(); +} + +void Window::paintEvent(QPaintEvent *) +{ + QPainter painter; + painter.begin(this); + + int h = 216 / 5; + QRect r = QRect(0, 0, 160, h); + painter.fillRect(r, Qt::white); + painter.setPen(Qt::black); + painter.drawText(r, Qt::AlignCenter, QLatin1String("white")); + r = QRect(0, h, 160, h); + painter.fillRect(r, Qt::red); + painter.drawText(r, Qt::AlignCenter, QLatin1String("red")); + r = QRect(0, h*2, 160, h); + painter.fillRect(r, Qt::green); + painter.drawText(r, Qt::AlignCenter, QLatin1String("green")); + r = QRect(0, h*3, 160, h); + painter.fillRect(r, Qt::blue); + painter.setPen(Qt::white); + painter.drawText(r, Qt::AlignCenter, QLatin1String("blue")); + + r = QRect(160, 0, 160, h); + painter.fillRect(r, Qt::black); + painter.drawText(r, Qt::AlignCenter, QLatin1String("black")); + r = QRect(160, h, 160, h); + painter.fillRect(r, Qt::darkRed); + painter.drawText(r, Qt::AlignCenter, QLatin1String("darkRed")); + r = QRect(160, h*2, 160, h); + painter.fillRect(r, Qt::darkGreen); + painter.drawText(r, Qt::AlignCenter, QLatin1String("darkGreen")); + r = QRect(160, h*3, 160, h); + painter.fillRect(r, Qt::darkBlue); + painter.drawText(r, Qt::AlignCenter, QLatin1String("darkBlue")); + + r = QRect(320, 0, 160, h); + painter.fillRect(r, Qt::cyan); + painter.setPen(Qt::black); + painter.drawText(r, Qt::AlignCenter, QLatin1String("cyan")); + r = QRect(320, h, 160, h); + painter.fillRect(r, Qt::magenta); + painter.drawText(r, Qt::AlignCenter, QLatin1String("magenta")); + r = QRect(320, h*2, 160, h); + painter.fillRect(r, Qt::yellow); + painter.drawText(r, Qt::AlignCenter, QLatin1String("yellow")); + r = QRect(320, h*3, 160, h); + painter.fillRect(r, Qt::gray); + painter.setPen(Qt::white); + painter.drawText(r, Qt::AlignCenter, QLatin1String("gray")); + + r = QRect(480, 0, 160, h); + painter.fillRect(r, Qt::darkCyan); + painter.drawText(r, Qt::AlignCenter, QLatin1String("darkCyan")); + r = QRect(480, h, 160, h); + painter.fillRect(r, Qt::darkMagenta); + painter.drawText(r, Qt::AlignCenter, QLatin1String("darkMagenta")); + r = QRect(480, h*2, 160, h); + painter.fillRect(r, Qt::darkYellow); + painter.drawText(r, Qt::AlignCenter, QLatin1String("darkYellow")); + r = QRect(480, h*3, 160, h); + painter.fillRect(r, Qt::darkGray); + painter.drawText(r, Qt::AlignCenter, QLatin1String("darkGray")); + + r = QRect(0, h*4, 640, h); + painter.fillRect(r, Qt::lightGray); + painter.setPen(Qt::black); + painter.drawText(r, Qt::AlignCenter, QLatin1String("lightGray")); + + painter.end(); +} + diff --git a/doc/src/snippets/colors/window.h b/doc/src/snippets/colors/window.h new file mode 100644 index 0000000..3b08b90 --- /dev/null +++ b/doc/src/snippets/colors/window.h @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the documentation 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QWidget> + +class Window : public QWidget +{ +public: + Window(QWidget *parent = 0); + +protected: + void closeEvent(QCloseEvent *event); + void paintEvent(QPaintEvent *event); +}; + |