From 67ad0519fd165acee4a4d2a94fa502e9e4847bd0 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 23 Mar 2009 10:34:13 +0100 Subject: Long live Qt! --- examples/designer/README | 37 +++ .../calculatorbuilder/calculatorbuilder.pro | 14 + .../calculatorbuilder/calculatorbuilder.qrc | 5 + .../designer/calculatorbuilder/calculatorform.cpp | 92 +++++++ .../designer/calculatorbuilder/calculatorform.h | 71 +++++ .../designer/calculatorbuilder/calculatorform.ui | 303 +++++++++++++++++++++ examples/designer/calculatorbuilder/main.cpp | 54 ++++ .../designer/calculatorform/calculatorform.cpp | 66 +++++ examples/designer/calculatorform/calculatorform.h | 66 +++++ .../designer/calculatorform/calculatorform.pro | 13 + examples/designer/calculatorform/calculatorform.ui | 284 +++++++++++++++++++ examples/designer/calculatorform/main.cpp | 53 ++++ .../containerextension/containerextension.pro | 26 ++ .../containerextension/multipagewidget.cpp | 131 +++++++++ .../designer/containerextension/multipagewidget.h | 88 ++++++ .../multipagewidgetcontainerextension.cpp | 101 +++++++ .../multipagewidgetcontainerextension.h | 75 +++++ .../multipagewidgetextensionfactory.cpp | 65 +++++ .../multipagewidgetextensionfactory.h | 64 +++++ .../containerextension/multipagewidgetplugin.cpp | 197 ++++++++++++++ .../containerextension/multipagewidgetplugin.h | 81 ++++++ .../designer/customwidgetplugin/analogclock.cpp | 111 ++++++++ examples/designer/customwidgetplugin/analogclock.h | 59 ++++ .../customwidgetplugin/customwidgetplugin.cpp | 156 +++++++++++ .../customwidgetplugin/customwidgetplugin.h | 73 +++++ .../customwidgetplugin/customwidgetplugin.pro | 21 ++ examples/designer/designer.pro | 19 ++ .../taskmenuextension/taskmenuextension.pro | 25 ++ examples/designer/taskmenuextension/tictactoe.cpp | 176 ++++++++++++ examples/designer/taskmenuextension/tictactoe.h | 83 ++++++ .../designer/taskmenuextension/tictactoedialog.cpp | 99 +++++++ .../designer/taskmenuextension/tictactoedialog.h | 73 +++++ .../designer/taskmenuextension/tictactoeplugin.cpp | 142 ++++++++++ .../designer/taskmenuextension/tictactoeplugin.h | 78 ++++++ .../taskmenuextension/tictactoetaskmenu.cpp | 104 +++++++ .../designer/taskmenuextension/tictactoetaskmenu.h | 88 ++++++ examples/designer/worldtimeclockbuilder/form.ui | 162 +++++++++++ examples/designer/worldtimeclockbuilder/main.cpp | 70 +++++ .../worldtimeclockbuilder.pro | 11 + .../worldtimeclockbuilder.qrc | 5 + .../worldtimeclockplugin/worldtimeclock.cpp | 122 +++++++++ .../designer/worldtimeclockplugin/worldtimeclock.h | 73 +++++ .../worldtimeclockplugin/worldtimeclockplugin.cpp | 124 +++++++++ .../worldtimeclockplugin/worldtimeclockplugin.h | 74 +++++ .../worldtimeclockplugin/worldtimeclockplugin.pro | 21 ++ 45 files changed, 3855 insertions(+) create mode 100644 examples/designer/README create mode 100644 examples/designer/calculatorbuilder/calculatorbuilder.pro create mode 100644 examples/designer/calculatorbuilder/calculatorbuilder.qrc create mode 100644 examples/designer/calculatorbuilder/calculatorform.cpp create mode 100644 examples/designer/calculatorbuilder/calculatorform.h create mode 100644 examples/designer/calculatorbuilder/calculatorform.ui create mode 100644 examples/designer/calculatorbuilder/main.cpp create mode 100644 examples/designer/calculatorform/calculatorform.cpp create mode 100644 examples/designer/calculatorform/calculatorform.h create mode 100644 examples/designer/calculatorform/calculatorform.pro create mode 100644 examples/designer/calculatorform/calculatorform.ui create mode 100644 examples/designer/calculatorform/main.cpp create mode 100644 examples/designer/containerextension/containerextension.pro create mode 100644 examples/designer/containerextension/multipagewidget.cpp create mode 100644 examples/designer/containerextension/multipagewidget.h create mode 100644 examples/designer/containerextension/multipagewidgetcontainerextension.cpp create mode 100644 examples/designer/containerextension/multipagewidgetcontainerextension.h create mode 100644 examples/designer/containerextension/multipagewidgetextensionfactory.cpp create mode 100644 examples/designer/containerextension/multipagewidgetextensionfactory.h create mode 100644 examples/designer/containerextension/multipagewidgetplugin.cpp create mode 100644 examples/designer/containerextension/multipagewidgetplugin.h create mode 100644 examples/designer/customwidgetplugin/analogclock.cpp create mode 100644 examples/designer/customwidgetplugin/analogclock.h create mode 100644 examples/designer/customwidgetplugin/customwidgetplugin.cpp create mode 100644 examples/designer/customwidgetplugin/customwidgetplugin.h create mode 100644 examples/designer/customwidgetplugin/customwidgetplugin.pro create mode 100644 examples/designer/designer.pro create mode 100644 examples/designer/taskmenuextension/taskmenuextension.pro create mode 100644 examples/designer/taskmenuextension/tictactoe.cpp create mode 100644 examples/designer/taskmenuextension/tictactoe.h create mode 100644 examples/designer/taskmenuextension/tictactoedialog.cpp create mode 100644 examples/designer/taskmenuextension/tictactoedialog.h create mode 100644 examples/designer/taskmenuextension/tictactoeplugin.cpp create mode 100644 examples/designer/taskmenuextension/tictactoeplugin.h create mode 100644 examples/designer/taskmenuextension/tictactoetaskmenu.cpp create mode 100644 examples/designer/taskmenuextension/tictactoetaskmenu.h create mode 100644 examples/designer/worldtimeclockbuilder/form.ui create mode 100644 examples/designer/worldtimeclockbuilder/main.cpp create mode 100644 examples/designer/worldtimeclockbuilder/worldtimeclockbuilder.pro create mode 100644 examples/designer/worldtimeclockbuilder/worldtimeclockbuilder.qrc create mode 100644 examples/designer/worldtimeclockplugin/worldtimeclock.cpp create mode 100644 examples/designer/worldtimeclockplugin/worldtimeclock.h create mode 100644 examples/designer/worldtimeclockplugin/worldtimeclockplugin.cpp create mode 100644 examples/designer/worldtimeclockplugin/worldtimeclockplugin.h create mode 100644 examples/designer/worldtimeclockplugin/worldtimeclockplugin.pro (limited to 'examples/designer') diff --git a/examples/designer/README b/examples/designer/README new file mode 100644 index 0000000000..fb9443caed --- /dev/null +++ b/examples/designer/README @@ -0,0 +1,37 @@ +Qt Designer is a capable graphical user interface designer that lets you +create and configure forms without writing code. GUIs created with +Qt Designer can be compiled into an application or created at run-time. + + +Some of the examples in this directory can be run from the example launcher; +others can only be used from within Qt Designer. + +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/designer/calculatorbuilder/calculatorbuilder.pro b/examples/designer/calculatorbuilder/calculatorbuilder.pro new file mode 100644 index 0000000000..1d69cc856f --- /dev/null +++ b/examples/designer/calculatorbuilder/calculatorbuilder.pro @@ -0,0 +1,14 @@ +#! [0] +CONFIG += uitools + +HEADERS = calculatorform.h +RESOURCES = calculatorbuilder.qrc +SOURCES = calculatorform.cpp \ + main.cpp +#! [0] + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/designer/calculatorbuilder +sources.files = $$SOURCES $$HEADERS $$RESOURCES *.ui *.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/designer/calculatorbuilder +INSTALLS += target sources diff --git a/examples/designer/calculatorbuilder/calculatorbuilder.qrc b/examples/designer/calculatorbuilder/calculatorbuilder.qrc new file mode 100644 index 0000000000..19b39059e7 --- /dev/null +++ b/examples/designer/calculatorbuilder/calculatorbuilder.qrc @@ -0,0 +1,5 @@ + + + calculatorform.ui + + diff --git a/examples/designer/calculatorbuilder/calculatorform.cpp b/examples/designer/calculatorbuilder/calculatorform.cpp new file mode 100644 index 0000000000..92d75c5d45 --- /dev/null +++ b/examples/designer/calculatorbuilder/calculatorform.cpp @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +//! [0] +#include +//! [0] +#include + +#include "calculatorform.h" + +//! [1] +CalculatorForm::CalculatorForm(QWidget *parent) + : QWidget(parent) +{ + QUiLoader loader; + + QFile file(":/forms/calculatorform.ui"); + file.open(QFile::ReadOnly); + QWidget *formWidget = loader.load(&file, this); + file.close(); +//! [1] + +//! [2] + ui_inputSpinBox1 = qFindChild(this, "inputSpinBox1"); + ui_inputSpinBox2 = qFindChild(this, "inputSpinBox2"); + ui_outputWidget = qFindChild(this, "outputWidget"); +//! [2] + +//! [3] + QMetaObject::connectSlotsByName(this); +//! [3] + +//! [4] + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(formWidget); + setLayout(layout); + + setWindowTitle(tr("Calculator Builder")); +} +//! [4] + +//! [5] +void CalculatorForm::on_inputSpinBox1_valueChanged(int value) +{ + ui_outputWidget->setText(QString::number(value + ui_inputSpinBox2->value())); +} +//! [5] //! [6] + +//! [6] //! [7] +void CalculatorForm::on_inputSpinBox2_valueChanged(int value) +{ + ui_outputWidget->setText(QString::number(value + ui_inputSpinBox1->value())); +} +//! [7] diff --git a/examples/designer/calculatorbuilder/calculatorform.h b/examples/designer/calculatorbuilder/calculatorform.h new file mode 100644 index 0000000000..8b322b707e --- /dev/null +++ b/examples/designer/calculatorbuilder/calculatorform.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 CALCULATORFORM_H +#define CALCULATORFORM_H + +#include + +QT_BEGIN_NAMESPACE +class QLabel; +class QSpinBox; +QT_END_NAMESPACE + +//! [0] +class CalculatorForm : public QWidget +{ + Q_OBJECT + +public: + CalculatorForm(QWidget *parent = 0); + +private slots: + void on_inputSpinBox1_valueChanged(int value); + void on_inputSpinBox2_valueChanged(int value); + +private: + QSpinBox *ui_inputSpinBox1; + QSpinBox *ui_inputSpinBox2; + QLabel *ui_outputWidget; +}; +//! [0] + +#endif diff --git a/examples/designer/calculatorbuilder/calculatorform.ui b/examples/designer/calculatorbuilder/calculatorform.ui new file mode 100644 index 0000000000..dda0e62ddd --- /dev/null +++ b/examples/designer/calculatorbuilder/calculatorform.ui @@ -0,0 +1,303 @@ + + + + + CalculatorForm + + + CalculatorForm + + + + 0 + 0 + 276 + 98 + + + + + 5 + 5 + 0 + 0 + + + + Calculator Builder + + + + + + + 9 + + + 6 + + + + + + + + 1 + + + 6 + + + + + + + + 1 + + + 6 + + + + + label + + + + 1 + 1 + 45 + 19 + + + + Input 1 + + + + + + + inputSpinBox1 + + + + 1 + 26 + 45 + 25 + + + + true + + + + + + + + + label_3 + + + + 54 + 1 + 7 + 52 + + + + + + + + Qt::AlignCenter + + + + + + + + + + 1 + + + 6 + + + + + label_2 + + + + 1 + 1 + 45 + 19 + + + + Input 2 + + + + + + + inputSpinBox2 + + + + 1 + 26 + 45 + 25 + + + + true + + + + + + + + + label_3_2 + + + + 120 + 1 + 7 + 52 + + + + = + + + Qt::AlignCenter + + + + + + + + + + 1 + + + 6 + + + + + label_2_2_2 + + + + 1 + 1 + 37 + 17 + + + + Output + + + + + + + outputWidget + + + + 1 + 24 + 37 + 27 + + + + QFrame::Box + + + QFrame::Sunken + + + 0 + + + Qt::AlignAbsolute|Qt::AlignBottom|Qt::AlignCenter|Qt::AlignHCenter|Qt::AlignHorizontal_Mask|Qt::AlignJustify|Qt::AlignLeading|Qt::AlignLeft|Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing|Qt::AlignVCenter|Qt::AlignVertical_Mask + + + + + + + + + + + verticalSpacer + + + + 85 + 69 + 20 + 20 + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + horizontalSpacer + + + + 188 + 26 + 79 + 20 + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + diff --git a/examples/designer/calculatorbuilder/main.cpp b/examples/designer/calculatorbuilder/main.cpp new file mode 100644 index 0000000000..56358b8845 --- /dev/null +++ b/examples/designer/calculatorbuilder/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 + +#include "calculatorform.h" + +int main(int argc, char *argv[]) +{ + Q_INIT_RESOURCE(calculatorbuilder); + + QApplication app(argc, argv); + CalculatorForm calculator; + calculator.show(); + return app.exec(); +} diff --git a/examples/designer/calculatorform/calculatorform.cpp b/examples/designer/calculatorform/calculatorform.cpp new file mode 100644 index 0000000000..3de2852db8 --- /dev/null +++ b/examples/designer/calculatorform/calculatorform.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** 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 + +#include "calculatorform.h" + +//! [0] +CalculatorForm::CalculatorForm(QWidget *parent) + : QWidget(parent) +{ + ui.setupUi(this); +} +//! [0] + +//! [1] +void CalculatorForm::on_inputSpinBox1_valueChanged(int value) +{ + ui.outputWidget->setText(QString::number(value + ui.inputSpinBox2->value())); +} +//! [1] + +//! [2] +void CalculatorForm::on_inputSpinBox2_valueChanged(int value) +{ + ui.outputWidget->setText(QString::number(value + ui.inputSpinBox1->value())); +} +//! [2] diff --git a/examples/designer/calculatorform/calculatorform.h b/examples/designer/calculatorform/calculatorform.h new file mode 100644 index 0000000000..37f0a18774 --- /dev/null +++ b/examples/designer/calculatorform/calculatorform.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** 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 CALCULATORFORM_H +#define CALCULATORFORM_H + +//! [0] +#include "ui_calculatorform.h" +//! [0] + +//! [1] +class CalculatorForm : public QWidget +{ + Q_OBJECT + +public: + CalculatorForm(QWidget *parent = 0); + +private slots: + void on_inputSpinBox1_valueChanged(int value); + void on_inputSpinBox2_valueChanged(int value); + +private: + Ui::CalculatorForm ui; +}; +//! [1] + +#endif diff --git a/examples/designer/calculatorform/calculatorform.pro b/examples/designer/calculatorform/calculatorform.pro new file mode 100644 index 0000000000..73f4351325 --- /dev/null +++ b/examples/designer/calculatorform/calculatorform.pro @@ -0,0 +1,13 @@ +#! [0] +HEADERS = calculatorform.h +#! [0] #! [1] +FORMS = calculatorform.ui +#! [1] +SOURCES = calculatorform.cpp \ + main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/designer/calculatorform +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/designer/calculatorform +INSTALLS += target sources diff --git a/examples/designer/calculatorform/calculatorform.ui b/examples/designer/calculatorform/calculatorform.ui new file mode 100644 index 0000000000..3a956399ae --- /dev/null +++ b/examples/designer/calculatorform/calculatorform.ui @@ -0,0 +1,284 @@ + + + + + CalculatorForm + + + CalculatorForm + + + + 0 + 0 + 400 + 300 + + + + + 5 + 5 + 0 + 0 + + + + Calculator Form + + + + + + + 9 + + + 6 + + + + + horizontalSpacer + + + + 239 + 9 + 152 + 52 + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + label_3_2 + + + + 169 + 9 + 20 + 52 + + + + = + + + Qt::AlignCenter + + + + + + + + + + 1 + + + 6 + + + + + label_2_2_2 + + + + 1 + 1 + 36 + 17 + + + + Output + + + + + + + outputWidget + + + + 1 + 24 + 36 + 27 + + + + QFrame::Box + + + QFrame::Sunken + + + 0 + + + Qt::AlignAbsolute|Qt::AlignBottom|Qt::AlignCenter|Qt::AlignHCenter|Qt::AlignHorizontal_Mask|Qt::AlignJustify|Qt::AlignLeading|Qt::AlignLeft|Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing|Qt::AlignVCenter|Qt::AlignVertical_Mask + + + + + + + + + verticalSpacer + + + + 89 + 67 + 20 + 224 + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + 1 + + + 6 + + + + + label_2 + + + + 1 + 1 + 46 + 19 + + + + Input 2 + + + + + + + inputSpinBox2 + + + + 1 + 26 + 46 + 25 + + + + + + + + + + label_3 + + + + 63 + 9 + 20 + 52 + + + + + + + + Qt::AlignCenter + + + + + + + + + + 1 + + + 6 + + + + + label + + + + 1 + 1 + 46 + 19 + + + + Input 1 + + + + + + + inputSpinBox1 + + + + 1 + 26 + 46 + 25 + + + + + + + + + + + + diff --git a/examples/designer/calculatorform/main.cpp b/examples/designer/calculatorform/main.cpp new file mode 100644 index 0000000000..dcb7366cb9 --- /dev/null +++ b/examples/designer/calculatorform/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 + +#include "calculatorform.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + CalculatorForm calculator; + calculator.show(); + return app.exec(); +} + diff --git a/examples/designer/containerextension/containerextension.pro b/examples/designer/containerextension/containerextension.pro new file mode 100644 index 0000000000..6a2cb58d12 --- /dev/null +++ b/examples/designer/containerextension/containerextension.pro @@ -0,0 +1,26 @@ +#! [0] +TEMPLATE = lib +#! [0] +TARGET = $$qtLibraryTarget($$TARGET) +#! [1] +CONFIG += designer plugin +#! [1] +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/designer + +#! [2] +HEADERS += multipagewidget.h \ + multipagewidgetplugin.h \ + multipagewidgetcontainerextension.h \ + multipagewidgetextensionfactory.h + +SOURCES += multipagewidget.cpp \ + multipagewidgetplugin.cpp \ + multipagewidgetcontainerextension.cpp \ + multipagewidgetextensionfactory.cpp +#! [2] + +# install +target.path = $$[QT_INSTALL_PLUGINS]/designer +sources.files = $$SOURCES $$HEADERS *.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/designer/containerextension +INSTALLS += target sources diff --git a/examples/designer/containerextension/multipagewidget.cpp b/examples/designer/containerextension/multipagewidget.cpp new file mode 100644 index 0000000000..5a3697b358 --- /dev/null +++ b/examples/designer/containerextension/multipagewidget.cpp @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** 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 + +#include "multipagewidget.h" + +MultiPageWidget::MultiPageWidget(QWidget *parent) + : QWidget(parent) +{ + comboBox = new QComboBox(); + comboBox->setObjectName("__qt__passive_comboBox"); + stackWidget = new QStackedWidget(); + + connect(comboBox, SIGNAL(activated(int)), + this, SLOT(setCurrentIndex(int))); + + layout = new QVBoxLayout(); + layout->addWidget(comboBox); + layout->addWidget(stackWidget); + setLayout(layout); +} + +QSize MultiPageWidget::sizeHint() const +{ + return QSize(200, 150); +} + +void MultiPageWidget::addPage(QWidget *page) +{ + insertPage(count(), page); +} + +void MultiPageWidget::removePage(int index) +{ + QWidget *widget = stackWidget->widget(index); + stackWidget->removeWidget(widget); + + comboBox->removeItem(index); +} + +int MultiPageWidget::count() const +{ + return stackWidget->count(); +} + +int MultiPageWidget::currentIndex() const +{ + return stackWidget->currentIndex(); +} + +void MultiPageWidget::insertPage(int index, QWidget *page) +{ + page->setParent(stackWidget); + + stackWidget->insertWidget(index, page); + + QString title = page->windowTitle(); + if (title.isEmpty()) { + title = tr("Page %1").arg(comboBox->count() + 1); + page->setWindowTitle(title); + } + comboBox->insertItem(index, title); +} + +void MultiPageWidget::setCurrentIndex(int index) +{ + if (index != currentIndex()) { + stackWidget->setCurrentIndex(index); + comboBox->setCurrentIndex(index); + emit currentIndexChanged(index); + } +} + +QWidget* MultiPageWidget::widget(int index) +{ + return stackWidget->widget(index); +} + +QString MultiPageWidget::pageTitle() const +{ + if (const QWidget *currentWidget = stackWidget->currentWidget()) + return currentWidget->windowTitle(); + return QString(); +} + +void MultiPageWidget::setPageTitle(QString const &newTitle) +{ + comboBox->setItemText(currentIndex(), newTitle); + if (QWidget *currentWidget = stackWidget->currentWidget()) + currentWidget->setWindowTitle(newTitle); + emit pageTitleChanged(newTitle); +} diff --git a/examples/designer/containerextension/multipagewidget.h b/examples/designer/containerextension/multipagewidget.h new file mode 100644 index 0000000000..77a09c5ff4 --- /dev/null +++ b/examples/designer/containerextension/multipagewidget.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** 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 MULTIPAGEWIDGET_H +#define MULTIPAGEWIDGET_H + +#include + +QT_BEGIN_NAMESPACE +class QComboBox; +class QStackedWidget; +class QVBoxLayout; +QT_END_NAMESPACE + +//! [0] +class MultiPageWidget : public QWidget +{ + Q_OBJECT + Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex) + Q_PROPERTY(QString pageTitle READ pageTitle WRITE setPageTitle STORED false) + +public: + MultiPageWidget(QWidget *parent = 0); + + QSize sizeHint() const; + + int count() const; + int currentIndex() const; + QWidget *widget(int index); + QString pageTitle() const; + +public slots: + void addPage(QWidget *page); + void insertPage(int index, QWidget *page); + void removePage(int index); + void setPageTitle(QString const &newTitle); + void setCurrentIndex(int index); + +signals: + void currentIndexChanged(int index); + void pageTitleChanged(const QString &title); + +private: + QStackedWidget *stackWidget; + QComboBox *comboBox; + QVBoxLayout *layout; +}; +//! [0] + +#endif diff --git a/examples/designer/containerextension/multipagewidgetcontainerextension.cpp b/examples/designer/containerextension/multipagewidgetcontainerextension.cpp new file mode 100644 index 0000000000..b61da3daf5 --- /dev/null +++ b/examples/designer/containerextension/multipagewidgetcontainerextension.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 "multipagewidgetcontainerextension.h" +#include "multipagewidget.h" + +//! [0] +MultiPageWidgetContainerExtension::MultiPageWidgetContainerExtension(MultiPageWidget *widget, + QObject *parent) + :QObject(parent) +{ + myWidget = widget; +} +//! [0] + +//! [1] +void MultiPageWidgetContainerExtension::addWidget(QWidget *widget) +{ + myWidget->addPage(widget); +} +//! [1] + +//! [2] +int MultiPageWidgetContainerExtension::count() const +{ + return myWidget->count(); +} +//! [2] + +//! [3] +int MultiPageWidgetContainerExtension::currentIndex() const +{ + return myWidget->currentIndex(); +} +//! [3] + +//! [4] +void MultiPageWidgetContainerExtension::insertWidget(int index, QWidget *widget) +{ + myWidget->insertPage(index, widget); +} +//! [4] + +//! [5] +void MultiPageWidgetContainerExtension::remove(int index) +{ + myWidget->removePage(index); +} +//! [5] + +//! [6] +void MultiPageWidgetContainerExtension::setCurrentIndex(int index) +{ + myWidget->setCurrentIndex(index); +} +//! [6] + +//! [7] +QWidget* MultiPageWidgetContainerExtension::widget(int index) const +{ + return myWidget->widget(index); +} +//! [7] diff --git a/examples/designer/containerextension/multipagewidgetcontainerextension.h b/examples/designer/containerextension/multipagewidgetcontainerextension.h new file mode 100644 index 0000000000..661146e0d1 --- /dev/null +++ b/examples/designer/containerextension/multipagewidgetcontainerextension.h @@ -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$ +** +****************************************************************************/ + +#ifndef MULTIPAGEWIDGETCONTAINEREXTENSION_H +#define MULTIPAGEWIDGETCONTAINEREXTENSION_H + +#include + +QT_BEGIN_NAMESPACE +class QExtensionManager; +QT_END_NAMESPACE +class MultiPageWidget; + +//! [0] +class MultiPageWidgetContainerExtension: public QObject, + public QDesignerContainerExtension +{ + Q_OBJECT + Q_INTERFACES(QDesignerContainerExtension) + +public: + MultiPageWidgetContainerExtension(MultiPageWidget *widget, QObject *parent); + + void addWidget(QWidget *widget); + int count() const; + int currentIndex() const; + void insertWidget(int index, QWidget *widget); + void remove(int index); + void setCurrentIndex(int index); + QWidget *widget(int index) const; + +private: + MultiPageWidget *myWidget; +}; +//! [0] + +#endif diff --git a/examples/designer/containerextension/multipagewidgetextensionfactory.cpp b/examples/designer/containerextension/multipagewidgetextensionfactory.cpp new file mode 100644 index 0000000000..4a1e81b3d8 --- /dev/null +++ b/examples/designer/containerextension/multipagewidgetextensionfactory.cpp @@ -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$ +** +****************************************************************************/ + +#include "multipagewidgetextensionfactory.h" +#include "multipagewidgetcontainerextension.h" +#include "multipagewidget.h" + +//! [0] +MultiPageWidgetExtensionFactory::MultiPageWidgetExtensionFactory(QExtensionManager *parent) + : QExtensionFactory(parent) +{} +//! [0] + +//! [1] +QObject *MultiPageWidgetExtensionFactory::createExtension(QObject *object, + const QString &iid, + QObject *parent) const +{ + MultiPageWidget *widget = qobject_cast(object); + + if (widget && (iid == Q_TYPEID(QDesignerContainerExtension))) { + return new MultiPageWidgetContainerExtension(widget, parent); + } else { + return 0; + } +} +//! [1] diff --git a/examples/designer/containerextension/multipagewidgetextensionfactory.h b/examples/designer/containerextension/multipagewidgetextensionfactory.h new file mode 100644 index 0000000000..9a96b37023 --- /dev/null +++ b/examples/designer/containerextension/multipagewidgetextensionfactory.h @@ -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$ +** +****************************************************************************/ + +#ifndef MULTIPAGEWIDGETEXTENSIONFACTORY_H +#define MULTIPAGEWIDGETEXTENSIONFACTORY_H + +#include + +QT_BEGIN_NAMESPACE +class QExtensionManager; +QT_END_NAMESPACE + +//! [0] +class MultiPageWidgetExtensionFactory: public QExtensionFactory +{ + Q_OBJECT + +public: + MultiPageWidgetExtensionFactory(QExtensionManager *parent = 0); + +protected: + QObject *createExtension(QObject *object, const QString &iid, QObject *parent) const; +}; +//! [0] + +#endif diff --git a/examples/designer/containerextension/multipagewidgetplugin.cpp b/examples/designer/containerextension/multipagewidgetplugin.cpp new file mode 100644 index 0000000000..c09ed3afab --- /dev/null +++ b/examples/designer/containerextension/multipagewidgetplugin.cpp @@ -0,0 +1,197 @@ +/**************************************************************************** +** +** 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 +#include +#include +#include +#include +#include + +#include +#include + +#include "multipagewidget.h" +#include "multipagewidgetplugin.h" +#include "multipagewidgetextensionfactory.h" + +//! [0] +MultiPageWidgetPlugin::MultiPageWidgetPlugin(QObject *parent) + :QObject(parent) +{ + initialized = false; +} + +QString MultiPageWidgetPlugin::name() const +{ + return QLatin1String("MultiPageWidget"); +} + +QString MultiPageWidgetPlugin::group() const +{ + return QLatin1String("Display Widgets [Examples]"); +} + +QString MultiPageWidgetPlugin::toolTip() const +{ + return QString(); +} + +QString MultiPageWidgetPlugin::whatsThis() const +{ + return QString(); +} + +QString MultiPageWidgetPlugin::includeFile() const +{ + return QLatin1String("multipagewidget.h"); +} + +QIcon MultiPageWidgetPlugin::icon() const +{ + return QIcon(); +} + +//! [0] //! [1] +bool MultiPageWidgetPlugin::isContainer() const +{ + return true; +} + +//! [1] //! [2] +QWidget *MultiPageWidgetPlugin::createWidget(QWidget *parent) +{ + MultiPageWidget *widget = new MultiPageWidget(parent); + connect(widget, SIGNAL(currentIndexChanged(int)), + this, SLOT(currentIndexChanged(int))); + connect(widget, SIGNAL(pageTitleChanged(const QString &)), + this, SLOT(pageTitleChanged(const QString &))); + return widget; +} + +//! [2] //! [3] +bool MultiPageWidgetPlugin::isInitialized() const +{ + return initialized; +} +//! [3] + +//! [4] +void MultiPageWidgetPlugin::initialize(QDesignerFormEditorInterface *formEditor) +{ + if (initialized) + return; +//! [4] + +//! [5] + QExtensionManager *manager = formEditor->extensionManager(); +//! [5] //! [6] + QExtensionFactory *factory = new MultiPageWidgetExtensionFactory(manager); + + Q_ASSERT(manager != 0); + manager->registerExtensions(factory, Q_TYPEID(QDesignerContainerExtension)); + + initialized = true; +} +//! [6] + +//! [7] +QString MultiPageWidgetPlugin::domXml() const +{ + return QLatin1String("\ +\ + \ + \ + \ + \ + \ + MultiPageWidget\ + QWidget\ + addPage\ + \ + \ +"); +} +//! [7] + +//! [8] +void MultiPageWidgetPlugin::currentIndexChanged(int index) +{ + Q_UNUSED(index); + MultiPageWidget *widget = qobject_cast(sender()); +//! [8] //! [9] + if (widget) { + QDesignerFormWindowInterface *form = QDesignerFormWindowInterface::findFormWindow(widget); + if (form) + form->emitSelectionChanged(); + } +} +//! [9] + +//! [10] +void MultiPageWidgetPlugin::pageTitleChanged(const QString &title) +{ + Q_UNUSED(title); + MultiPageWidget *widget = qobject_cast(sender()); +//! [10] //! [11] + if (widget) { + QWidget *page = widget->widget(widget->currentIndex()); + QDesignerFormWindowInterface *form; + form = QDesignerFormWindowInterface::findFormWindow(widget); +//! [11] + if (form) { +//! [12] + QDesignerFormEditorInterface *editor = form->core(); + QExtensionManager *manager = editor->extensionManager(); +//! [12] //! [13] + QDesignerPropertySheetExtension *sheet; + sheet = qt_extension(manager, page); + const int propertyIndex = sheet->indexOf(QLatin1String("windowTitle")); + sheet->setChanged(propertyIndex, true); + } + } +} + +//! [13] + +//! [14] +Q_EXPORT_PLUGIN2(containerextension, MultiPageWidgetPlugin) +//! [14] diff --git a/examples/designer/containerextension/multipagewidgetplugin.h b/examples/designer/containerextension/multipagewidgetplugin.h new file mode 100644 index 0000000000..1431c8a3ef --- /dev/null +++ b/examples/designer/containerextension/multipagewidgetplugin.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +//! [0] +#ifndef MULTIPAGEWIDGETPLUGIN_H +#define MULTIPAGEWIDGETPLUGIN_H + +#include + +QT_BEGIN_NAMESPACE +class QIcon; +class QWidget; +QT_END_NAMESPACE + +class MultiPageWidgetPlugin: public QObject, public QDesignerCustomWidgetInterface +{ + Q_OBJECT + Q_INTERFACES(QDesignerCustomWidgetInterface) +public: + MultiPageWidgetPlugin(QObject *parent = 0); + + QString name() const; + QString group() const; + QString toolTip() const; + QString whatsThis() const; + QString includeFile() const; + QIcon icon() const; + bool isContainer() const; + QWidget *createWidget(QWidget *parent); + bool isInitialized() const; + void initialize(QDesignerFormEditorInterface *formEditor); + QString domXml() const; + +private slots: + void currentIndexChanged(int index); + void pageTitleChanged(const QString &title); + +private: + bool initialized; +}; + +#endif +//! [0] diff --git a/examples/designer/customwidgetplugin/analogclock.cpp b/examples/designer/customwidgetplugin/analogclock.cpp new file mode 100644 index 0000000000..28155ba0e7 --- /dev/null +++ b/examples/designer/customwidgetplugin/analogclock.cpp @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** 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 + +#include "analogclock.h" + +AnalogClock::AnalogClock(QWidget *parent) + : QWidget(parent) +{ + QTimer *timer = new QTimer(this); + connect(timer, SIGNAL(timeout()), this, SLOT(update())); + timer->start(1000); + + setWindowTitle(tr("Analog Clock")); + resize(200, 200); +} + +void AnalogClock::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); + } +} diff --git a/examples/designer/customwidgetplugin/analogclock.h b/examples/designer/customwidgetplugin/analogclock.h new file mode 100644 index 0000000000..4d843ad6dd --- /dev/null +++ b/examples/designer/customwidgetplugin/analogclock.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 ANALOGCLOCK_H +#define ANALOGCLOCK_H + +#include +#include + +class QDESIGNER_WIDGET_EXPORT AnalogClock : public QWidget +{ + Q_OBJECT + +public: + AnalogClock(QWidget *parent = 0); + +protected: + void paintEvent(QPaintEvent *event); +}; + +#endif diff --git a/examples/designer/customwidgetplugin/customwidgetplugin.cpp b/examples/designer/customwidgetplugin/customwidgetplugin.cpp new file mode 100644 index 0000000000..bcea3b84a1 --- /dev/null +++ b/examples/designer/customwidgetplugin/customwidgetplugin.cpp @@ -0,0 +1,156 @@ +/**************************************************************************** +** +** 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 "analogclock.h" +#include "customwidgetplugin.h" + +#include + +//! [0] +AnalogClockPlugin::AnalogClockPlugin(QObject *parent) + : QObject(parent) +{ + initialized = false; +} +//! [0] + +//! [1] +void AnalogClockPlugin::initialize(QDesignerFormEditorInterface * /* core */) +{ + if (initialized) + return; + + initialized = true; +} +//! [1] + +//! [2] +bool AnalogClockPlugin::isInitialized() const +{ + return initialized; +} +//! [2] + +//! [3] +QWidget *AnalogClockPlugin::createWidget(QWidget *parent) +{ + return new AnalogClock(parent); +} +//! [3] + +//! [4] +QString AnalogClockPlugin::name() const +{ + return "AnalogClock"; +} +//! [4] + +//! [5] +QString AnalogClockPlugin::group() const +{ + return "Display Widgets [Examples]"; +} +//! [5] + +//! [6] +QIcon AnalogClockPlugin::icon() const +{ + return QIcon(); +} +//! [6] + +//! [7] +QString AnalogClockPlugin::toolTip() const +{ + return ""; +} +//! [7] + +//! [8] +QString AnalogClockPlugin::whatsThis() const +{ + return ""; +} +//! [8] + +//! [9] +bool AnalogClockPlugin::isContainer() const +{ + return false; +} +//! [9] + +//! [10] +QString AnalogClockPlugin::domXml() const +{ + return "\n" + " \n" +//! [11] + " \n" + " \n" + " 0\n" + " 0\n" + " 100\n" + " 100\n" + " \n" + " \n" +//! [11] + " \n" + " The current time\n" + " \n" + " \n" + " The analog clock widget displays the current time.\n" + " \n" + " \n" + "\n"; +} +//! [10] + +//! [12] +QString AnalogClockPlugin::includeFile() const +{ + return "analogclock.h"; +} +//! [12] + +//! [13] +Q_EXPORT_PLUGIN2(customwidgetplugin, AnalogClockPlugin) +//! [13] diff --git a/examples/designer/customwidgetplugin/customwidgetplugin.h b/examples/designer/customwidgetplugin/customwidgetplugin.h new file mode 100644 index 0000000000..4438690bce --- /dev/null +++ b/examples/designer/customwidgetplugin/customwidgetplugin.h @@ -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$ +** +****************************************************************************/ + +#ifndef CUSTOMWIDGETPLUGIN_H +#define CUSTOMWIDGETPLUGIN_H + +#include + +//! [0] +class AnalogClockPlugin : public QObject, public QDesignerCustomWidgetInterface +{ + Q_OBJECT + Q_INTERFACES(QDesignerCustomWidgetInterface) + +public: + AnalogClockPlugin(QObject *parent = 0); + + bool isContainer() const; + bool isInitialized() const; + QIcon icon() const; + QString domXml() const; + QString group() const; + QString includeFile() const; + QString name() const; + QString toolTip() const; + QString whatsThis() const; + QWidget *createWidget(QWidget *parent); + void initialize(QDesignerFormEditorInterface *core); + +private: + bool initialized; +}; +//! [0] + +#endif diff --git a/examples/designer/customwidgetplugin/customwidgetplugin.pro b/examples/designer/customwidgetplugin/customwidgetplugin.pro new file mode 100644 index 0000000000..4feee59f6a --- /dev/null +++ b/examples/designer/customwidgetplugin/customwidgetplugin.pro @@ -0,0 +1,21 @@ +#! [0] #! [1] +CONFIG += designer plugin +#! [0] +TARGET = $$qtLibraryTarget($$TARGET) +#! [2] +TEMPLATE = lib +#! [1] #! [2] +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/designer + +#! [3] +HEADERS = analogclock.h \ + customwidgetplugin.h +SOURCES = analogclock.cpp \ + customwidgetplugin.cpp +#! [3] + +# install +target.path = $$[QT_INSTALL_PLUGINS]/designer +sources.files = $$SOURCES $$HEADERS *.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/designer/customwidgetplugin +INSTALLS += target sources diff --git a/examples/designer/designer.pro b/examples/designer/designer.pro new file mode 100644 index 0000000000..0f30421aca --- /dev/null +++ b/examples/designer/designer.pro @@ -0,0 +1,19 @@ +TEMPLATE = subdirs +SUBDIRS = calculatorform + +!static:SUBDIRS += calculatorbuilder \ + containerextension \ + customwidgetplugin \ + taskmenuextension \ + worldtimeclockbuilder \ + worldtimeclockplugin + +# the sun cc compiler has a problem with the include lines for the form.prf +solaris-cc*:SUBDIRS -= calculatorbuilder \ + worldtimeclockbuilder + + +# install +sources.files = README *.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/designer +INSTALLS += sources diff --git a/examples/designer/taskmenuextension/taskmenuextension.pro b/examples/designer/taskmenuextension/taskmenuextension.pro new file mode 100644 index 0000000000..83dd8788c3 --- /dev/null +++ b/examples/designer/taskmenuextension/taskmenuextension.pro @@ -0,0 +1,25 @@ +#! [0] +TEMPLATE = lib +#! [0] +TARGET = $$qtLibraryTarget($$TARGET) +#! [1] +CONFIG += designer plugin +#! [1] +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/designer + +#! [2] +HEADERS += tictactoe.h \ + tictactoedialog.h \ + tictactoeplugin.h \ + tictactoetaskmenu.h +SOURCES += tictactoe.cpp \ + tictactoedialog.cpp \ + tictactoeplugin.cpp \ + tictactoetaskmenu.cpp +#! [2] + +# install +target.path = $$[QT_INSTALL_PLUGINS]/designer +sources.files = $$SOURCES $$HEADERS *.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/designer/taskmenuextension +INSTALLS += target sources diff --git a/examples/designer/taskmenuextension/tictactoe.cpp b/examples/designer/taskmenuextension/tictactoe.cpp new file mode 100644 index 0000000000..ba766ccd36 --- /dev/null +++ b/examples/designer/taskmenuextension/tictactoe.cpp @@ -0,0 +1,176 @@ +/**************************************************************************** +** +** 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 + +#include "tictactoe.h" + +TicTacToe::TicTacToe(QWidget *parent) + : QWidget(parent) +{ +} + +QSize TicTacToe::minimumSizeHint() const +{ + return QSize(200, 200); +} + +QSize TicTacToe::sizeHint() const +{ + return QSize(200, 200); +} + +void TicTacToe::setState(const QString &newState) +{ + turnNumber = 0; + myState = "---------"; + int position = 0; + while (position < 9 && position < newState.length()) { + QChar mark = newState.at(position); + if (mark == Cross || mark == Nought) { + ++turnNumber; + myState.replace(position, 1, mark); + } + position++; + } + update(); +} + +QString TicTacToe::state() const +{ + return myState; +} + +void TicTacToe::clearBoard() +{ + myState = "---------"; + turnNumber = 0; + update(); +} + +void TicTacToe::mousePressEvent(QMouseEvent *event) +{ + if (turnNumber == 9) { + clearBoard(); + update(); + } else { + for (int position = 0; position < 9; ++position) { + QRect cell = cellRect(position / 3, position % 3); + if (cell.contains(event->pos())) { + if (myState.at(position) == Empty) { + if (turnNumber % 2 == 0) + myState.replace(position, 1, Cross); + else + myState.replace(position, 1, Nought); + ++turnNumber; + update(); + } + } + } + } +} + +void TicTacToe::paintEvent(QPaintEvent * /* event */) +{ + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); + + painter.setPen(QPen(Qt::darkGreen, 1)); + painter.drawLine(cellWidth(), 0, cellWidth(), height()); + painter.drawLine(2 * cellWidth(), 0, 2 * cellWidth(), height()); + painter.drawLine(0, cellHeight(), width(), cellHeight()); + painter.drawLine(0, 2 * cellHeight(), width(), 2 * cellHeight()); + + painter.setPen(QPen(Qt::darkBlue, 2)); + + for (int position = 0; position < 9; ++position) { + QRect cell = cellRect(position / 3, position % 3); + + if (myState.at(position) == Cross) { + painter.drawLine(cell.topLeft(), cell.bottomRight()); + painter.drawLine(cell.topRight(), cell.bottomLeft()); + } else if (myState.at(position) == Nought) { + painter.drawEllipse(cell); + } + } + + painter.setPen(QPen(Qt::yellow, 3)); + + for (int position = 0; position < 9; position = position + 3) { + if (myState.at(position) != Empty + && myState.at(position + 1) == myState.at(position) + && myState.at(position + 2) == myState.at(position)) { + int y = cellRect((position / 3), 0).center().y(); + painter.drawLine(0, y, width(), y); + turnNumber = 9; + } + } + + for (int position = 0; position < 3; ++position) { + if (myState.at(position) != Empty + && myState.at(position + 3) == myState.at(position) + && myState.at(position + 6) == myState.at(position)) { + int x = cellRect(0, position).center().x(); + painter.drawLine(x, 0, x, height()); + turnNumber = 9; + } + } + if (myState.at(0) != Empty && myState.at(4) == myState.at(0) + && myState.at(8) == myState.at(0)) { + painter.drawLine(0, 0, width(), height()); + turnNumber = 9; + } + if (myState.at(2) != Empty && myState.at(4) == myState.at(2) + && myState.at(6) == myState.at(2)) { + painter.drawLine(0, height(), width(), 0); + turnNumber = 9; + } +} + +QRect TicTacToe::cellRect(int row, int column) const +{ + const int HMargin = width() / 30; + const int VMargin = height() / 30; + return QRect(column * cellWidth() + HMargin, + row * cellHeight() + VMargin, + cellWidth() - 2 * HMargin, + cellHeight() - 2 * VMargin); +} diff --git a/examples/designer/taskmenuextension/tictactoe.h b/examples/designer/taskmenuextension/tictactoe.h new file mode 100644 index 0000000000..ef3c533e57 --- /dev/null +++ b/examples/designer/taskmenuextension/tictactoe.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** 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 TICTACTOE_H +#define TICTACTOE_H + +#include + +QT_BEGIN_NAMESPACE +class QRect; +class QSize; +QT_END_NAMESPACE + +//! [0] +class TicTacToe : public QWidget +{ + Q_OBJECT + Q_PROPERTY(QString state READ state WRITE setState) + +public: + TicTacToe(QWidget *parent = 0); + + QSize minimumSizeHint() const; + QSize sizeHint() const; + void setState(const QString &newState); + QString state() const; + void clearBoard(); + +protected: + void mousePressEvent(QMouseEvent *event); + void paintEvent(QPaintEvent *event); + +private: + enum { Empty = '-', Cross = 'X', Nought = 'O' }; + + QRect cellRect(int row, int col) const; + int cellWidth() const { return width() / 3; } + int cellHeight() const { return height() / 3; } + + QString myState; + int turnNumber; +}; +//! [0] + +#endif diff --git a/examples/designer/taskmenuextension/tictactoedialog.cpp b/examples/designer/taskmenuextension/tictactoedialog.cpp new file mode 100644 index 0000000000..a9bd16a084 --- /dev/null +++ b/examples/designer/taskmenuextension/tictactoedialog.cpp @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** 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 +#include + +#include "tictactoe.h" +#include "tictactoedialog.h" + +//! [0] +TicTacToeDialog::TicTacToeDialog(TicTacToe *tic, QWidget *parent) + : QDialog(parent) +{ + ticTacToe = tic; + editor = new TicTacToe; + editor->setState(ticTacToe->state()); + + buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok + | QDialogButtonBox::Cancel + | QDialogButtonBox::Reset); + + connect(buttonBox->button(QDialogButtonBox::Reset), SIGNAL(clicked()), + this, SLOT(resetState())); + connect(buttonBox, SIGNAL(accepted()), this, SLOT(saveState())); + connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addWidget(editor); + mainLayout->addWidget(buttonBox); + + setLayout(mainLayout); + setWindowTitle(tr("Edit State")); +} +//! [0] + +//! [1] +QSize TicTacToeDialog::sizeHint() const +{ + return QSize(250, 250); +} +//! [1] + +//! [2] +void TicTacToeDialog::resetState() +{ + editor->clearBoard(); +} +//! [2] + +//! [3] +void TicTacToeDialog::saveState() +{ +//! [3] //! [4] + if (QDesignerFormWindowInterface *formWindow + = QDesignerFormWindowInterface::findFormWindow(ticTacToe)) { + formWindow->cursor()->setProperty("state", editor->state()); + } +//! [4] //! [5] + accept(); +} +//! [5] diff --git a/examples/designer/taskmenuextension/tictactoedialog.h b/examples/designer/taskmenuextension/tictactoedialog.h new file mode 100644 index 0000000000..55b25d29b5 --- /dev/null +++ b/examples/designer/taskmenuextension/tictactoedialog.h @@ -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$ +** +****************************************************************************/ + +#ifndef TICTACTOEDIALOG_H +#define TICTACTOEDIALOG_H + +#include + +QT_BEGIN_NAMESPACE +class QDialogButtonBox; +QT_END_NAMESPACE +class TicTacToe; + +//! [0] +class TicTacToeDialog : public QDialog +{ + Q_OBJECT + +public: + TicTacToeDialog(TicTacToe *plugin = 0, QWidget *parent = 0); + + QSize sizeHint() const; + +private slots: + void resetState(); + void saveState(); + +private: + TicTacToe *editor; + TicTacToe *ticTacToe; + QDialogButtonBox *buttonBox; +}; +//! [0] + +#endif diff --git a/examples/designer/taskmenuextension/tictactoeplugin.cpp b/examples/designer/taskmenuextension/tictactoeplugin.cpp new file mode 100644 index 0000000000..0a2d13b0b7 --- /dev/null +++ b/examples/designer/taskmenuextension/tictactoeplugin.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 +#include +#include + +#include "tictactoe.h" +#include "tictactoeplugin.h" +#include "tictactoetaskmenu.h" + +//! [0] +TicTacToePlugin::TicTacToePlugin(QObject *parent) + : QObject(parent) +{ + initialized = false; +} + +QString TicTacToePlugin::name() const +{ + return "TicTacToe"; +} + +QString TicTacToePlugin::group() const +{ + return "Display Widgets [Examples]"; +} + +QString TicTacToePlugin::toolTip() const +{ + return ""; +} + +QString TicTacToePlugin::whatsThis() const +{ + return ""; +} + +QString TicTacToePlugin::includeFile() const +{ + return "tictactoe.h"; +} + +QIcon TicTacToePlugin::icon() const +{ + return QIcon(); +} + +bool TicTacToePlugin::isContainer() const +{ + return false; +} + +QWidget *TicTacToePlugin::createWidget(QWidget *parent) +{ + TicTacToe *ticTacToe = new TicTacToe(parent); + ticTacToe->setState("-X-XO----"); + return ticTacToe; +} + +bool TicTacToePlugin::isInitialized() const +{ + return initialized; +} + +//! [0] //! [1] +void TicTacToePlugin::initialize(QDesignerFormEditorInterface *formEditor) +{ +//! [1] //! [2] + if (initialized) + return; + + QExtensionManager *manager = formEditor->extensionManager(); + Q_ASSERT(manager != 0); +//! [2] + +//! [3] + manager->registerExtensions(new TicTacToeTaskMenuFactory(manager), + Q_TYPEID(QDesignerTaskMenuExtension)); + + initialized = true; +} + +QString TicTacToePlugin::domXml() const +{ + return QLatin1String("\ +\ + \ + \ + \ + TicTacToe\ + \ + \ + \ + \ + \ +"); +} + +//! [3] + +//! [4] +Q_EXPORT_PLUGIN2(taskmenuextension, TicTacToePlugin) +//! [4] diff --git a/examples/designer/taskmenuextension/tictactoeplugin.h b/examples/designer/taskmenuextension/tictactoeplugin.h new file mode 100644 index 0000000000..b51540ef63 --- /dev/null +++ b/examples/designer/taskmenuextension/tictactoeplugin.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$ +** +****************************************************************************/ + +//! [0] +#ifndef TICTACTOEPLUGIN_H +#define TICTACTOEPLUGIN_H + +#include + +QT_BEGIN_NAMESPACE +class QIcon; +class QWidget; +QT_END_NAMESPACE + +class TicTacToePlugin : public QObject, public QDesignerCustomWidgetInterface +{ + Q_OBJECT + Q_INTERFACES(QDesignerCustomWidgetInterface) + +public: + TicTacToePlugin(QObject *parent = 0); + + QString name() const; + QString group() const; + QString toolTip() const; + QString whatsThis() const; + QString includeFile() const; + QIcon icon() const; + bool isContainer() const; + QWidget *createWidget(QWidget *parent); + bool isInitialized() const; + void initialize(QDesignerFormEditorInterface *formEditor); + QString domXml() const; + +private: + bool initialized; +}; + +#endif +//! [0] diff --git a/examples/designer/taskmenuextension/tictactoetaskmenu.cpp b/examples/designer/taskmenuextension/tictactoetaskmenu.cpp new file mode 100644 index 0000000000..af5401a899 --- /dev/null +++ b/examples/designer/taskmenuextension/tictactoetaskmenu.cpp @@ -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$ +** +****************************************************************************/ + +#include +#include + +#include "tictactoe.h" +#include "tictactoedialog.h" +#include "tictactoetaskmenu.h" + +//! [0] +TicTacToeTaskMenu::TicTacToeTaskMenu(TicTacToe *tic, QObject *parent) + : QObject(parent) +{ + ticTacToe = tic; + + editStateAction = new QAction(tr("Edit State..."), this); + connect(editStateAction, SIGNAL(triggered()), this, SLOT(editState())); +} +//! [0] + +//! [1] +void TicTacToeTaskMenu::editState() +{ + TicTacToeDialog dialog(ticTacToe); + dialog.exec(); +} +//! [1] + +//! [2] +QAction *TicTacToeTaskMenu::preferredEditAction() const +{ + return editStateAction; +} +//! [2] + +//! [3] +QList TicTacToeTaskMenu::taskActions() const +{ + QList list; + list.append(editStateAction); + return list; +} +//! [3] + +//! [4] +TicTacToeTaskMenuFactory::TicTacToeTaskMenuFactory(QExtensionManager *parent) + : QExtensionFactory(parent) +{ +} +//! [4] + +//! [5] +QObject *TicTacToeTaskMenuFactory::createExtension(QObject *object, + const QString &iid, + QObject *parent) const +{ + if (iid != Q_TYPEID(QDesignerTaskMenuExtension)) + return 0; + + if (TicTacToe *tic = qobject_cast(object)) + return new TicTacToeTaskMenu(tic, parent); + + return 0; +} +//! [5] diff --git a/examples/designer/taskmenuextension/tictactoetaskmenu.h b/examples/designer/taskmenuextension/tictactoetaskmenu.h new file mode 100644 index 0000000000..4bd317022f --- /dev/null +++ b/examples/designer/taskmenuextension/tictactoetaskmenu.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** 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 TICTACTOETASKMENU_H +#define TICTACTOETASKMENU_H + +#include +#include + +QT_BEGIN_NAMESPACE +class QAction; +class QExtensionManager; +QT_END_NAMESPACE +class TicTacToe; + +//! [0] +class TicTacToeTaskMenu : public QObject, public QDesignerTaskMenuExtension +{ + Q_OBJECT + Q_INTERFACES(QDesignerTaskMenuExtension) + +public: + TicTacToeTaskMenu(TicTacToe *tic, QObject *parent); + + QAction *preferredEditAction() const; + QList taskActions() const; + +private slots: + void editState(); + +private: + QAction *editStateAction; + TicTacToe *ticTacToe; +}; +//! [0] + +//! [1] +class TicTacToeTaskMenuFactory : public QExtensionFactory +{ + Q_OBJECT + +public: + TicTacToeTaskMenuFactory(QExtensionManager *parent = 0); + +protected: + QObject *createExtension(QObject *object, const QString &iid, QObject *parent) const; +}; +//! [1] + +#endif diff --git a/examples/designer/worldtimeclockbuilder/form.ui b/examples/designer/worldtimeclockbuilder/form.ui new file mode 100644 index 0000000000..e5be1d911f --- /dev/null +++ b/examples/designer/worldtimeclockbuilder/form.ui @@ -0,0 +1,162 @@ + + + + + WorldTimeForm + + + + 0 + 0 + 400 + 300 + + + + World Time Clock + + + + 9 + + + 6 + + + + + + + + 1 + + + 6 + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + 1 + + + 6 + + + + + Current time: + + + + + + + true + + + + + + + + + 1 + + + 6 + + + + + Set time zone: + + + + + + + 12 + + + -12 + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + WorldTimeClock + +
worldtimeclock.h
+ 0 + +
+
+ + + + spinBox + valueChanged(int) + worldTimeClock + setTimeZone(int) + + + 339 + 166 + + + 157 + 230 + + + + + worldTimeClock + updated(QTime) + timeEdit + setTime(QTime) + + + 141 + 59 + + + 291 + 133 + + + + +
diff --git a/examples/designer/worldtimeclockbuilder/main.cpp b/examples/designer/worldtimeclockbuilder/main.cpp new file mode 100644 index 0000000000..35f7dc05d0 --- /dev/null +++ b/examples/designer/worldtimeclockbuilder/main.cpp @@ -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$ +** +****************************************************************************/ + +//! [0] +#include +//! [0] +#include + +//! [1] +int main(int argc, char *argv[]) +{ + Q_INIT_RESOURCE(worldtimeclockbuilder); + + QApplication app(argc, argv); + + QUiLoader loader; +//! [1] + +//! [2] + QFile file(":/forms/form.ui"); + file.open(QFile::ReadOnly); + + QWidget *widget = loader.load(&file); + + file.close(); + widget->show(); +//! [2] + +//! [3] + return app.exec(); +} +//! [3] diff --git a/examples/designer/worldtimeclockbuilder/worldtimeclockbuilder.pro b/examples/designer/worldtimeclockbuilder/worldtimeclockbuilder.pro new file mode 100644 index 0000000000..2690921673 --- /dev/null +++ b/examples/designer/worldtimeclockbuilder/worldtimeclockbuilder.pro @@ -0,0 +1,11 @@ +#! [0] +CONFIG += uitools +SOURCES = main.cpp +RESOURCES = worldtimeclockbuilder.qrc +#! [0] + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/designer/worldtimeclockbuilder +sources.files = $$SOURCES $$HEADERS $$RESOURCES *.ui *.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/designer/worldtimeclockbuilder +INSTALLS += target sources diff --git a/examples/designer/worldtimeclockbuilder/worldtimeclockbuilder.qrc b/examples/designer/worldtimeclockbuilder/worldtimeclockbuilder.qrc new file mode 100644 index 0000000000..89d5ac3c22 --- /dev/null +++ b/examples/designer/worldtimeclockbuilder/worldtimeclockbuilder.qrc @@ -0,0 +1,5 @@ + + + form.ui + + diff --git a/examples/designer/worldtimeclockplugin/worldtimeclock.cpp b/examples/designer/worldtimeclockplugin/worldtimeclock.cpp new file mode 100644 index 0000000000..77eff54765 --- /dev/null +++ b/examples/designer/worldtimeclockplugin/worldtimeclock.cpp @@ -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$ +** +****************************************************************************/ + +#include + +#include "worldtimeclock.h" + +WorldTimeClock::WorldTimeClock(QWidget *parent) + : QWidget(parent) +{ + timeZoneOffset = 0; + + QTimer *timer = new QTimer(this); + connect(timer, SIGNAL(timeout()), this, SLOT(update())); + timer->start(1000); + + setWindowTitle(tr("World Time Clock")); + resize(200, 200); +} + +void WorldTimeClock::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(); + time = time.addSecs(timeZoneOffset); + + 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); + } + + emit updated(time); +} + +void WorldTimeClock::setTimeZone(int hourOffset) +{ + timeZoneOffset = qMin(qMax(-12, hourOffset), 12) * 3600; + update(); +} diff --git a/examples/designer/worldtimeclockplugin/worldtimeclock.h b/examples/designer/worldtimeclockplugin/worldtimeclock.h new file mode 100644 index 0000000000..7bfe8c5fab --- /dev/null +++ b/examples/designer/worldtimeclockplugin/worldtimeclock.h @@ -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$ +** +****************************************************************************/ + +#ifndef WORLDTIMECLOCK_H +#define WORLDTIMECLOCK_H + +#include +#include +#include + +//! [0] //! [1] +class QDESIGNER_WIDGET_EXPORT WorldTimeClock : public QWidget +{ + Q_OBJECT +//! [0] + +public: + WorldTimeClock(QWidget *parent = 0); + +public slots: + void setTimeZone(int hourOffset); + +signals: + void updated(QTime currentTime); + +protected: + void paintEvent(QPaintEvent *event); + +private: + int timeZoneOffset; +//! [2] +}; +//! [1] //! [2] + +#endif diff --git a/examples/designer/worldtimeclockplugin/worldtimeclockplugin.cpp b/examples/designer/worldtimeclockplugin/worldtimeclockplugin.cpp new file mode 100644 index 0000000000..e73c45bc34 --- /dev/null +++ b/examples/designer/worldtimeclockplugin/worldtimeclockplugin.cpp @@ -0,0 +1,124 @@ +/**************************************************************************** +** +** 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 "worldtimeclock.h" +#include "worldtimeclockplugin.h" + +#include + +WorldTimeClockPlugin::WorldTimeClockPlugin(QObject *parent) + : QObject(parent) +{ + initialized = false; +} + +void WorldTimeClockPlugin::initialize(QDesignerFormEditorInterface * /* core */) +{ + if (initialized) + return; + + initialized = true; +} + +bool WorldTimeClockPlugin::isInitialized() const +{ + return initialized; +} + +QWidget *WorldTimeClockPlugin::createWidget(QWidget *parent) +{ + return new WorldTimeClock(parent); +} + +QString WorldTimeClockPlugin::name() const +{ + return "WorldTimeClock"; +} + +QString WorldTimeClockPlugin::group() const +{ + return "Display Widgets [Examples]"; +} + +QIcon WorldTimeClockPlugin::icon() const +{ + return QIcon(); +} + +QString WorldTimeClockPlugin::toolTip() const +{ + return ""; +} + +QString WorldTimeClockPlugin::whatsThis() const +{ + return ""; +} + +bool WorldTimeClockPlugin::isContainer() const +{ + return false; +} + +QString WorldTimeClockPlugin::domXml() const +{ + return "\n" + " \n" + " \n" + " \n" + " 0\n" + " 0\n" + " 100\n" + " 100\n" + " \n" + " \n" + " \n" + ""; +} + +QString WorldTimeClockPlugin::includeFile() const +{ + return "worldtimeclock.h"; +} + +//! [0] +Q_EXPORT_PLUGIN2(worldtimeclockplugin, WorldTimeClockPlugin) +//! [0] diff --git a/examples/designer/worldtimeclockplugin/worldtimeclockplugin.h b/examples/designer/worldtimeclockplugin/worldtimeclockplugin.h new file mode 100644 index 0000000000..87d797a9bd --- /dev/null +++ b/examples/designer/worldtimeclockplugin/worldtimeclockplugin.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 WORLDTIMECLOCKPLUGIN_H +#define WORLDTIMECLOCKPLUGIN_H + +#include + +//! [0] +class WorldTimeClockPlugin : public QObject, + public QDesignerCustomWidgetInterface +{ + Q_OBJECT + Q_INTERFACES(QDesignerCustomWidgetInterface) + +public: + WorldTimeClockPlugin(QObject *parent = 0); + + bool isContainer() const; + bool isInitialized() const; + QIcon icon() const; + QString domXml() const; + QString group() const; + QString includeFile() const; + QString name() const; + QString toolTip() const; + QString whatsThis() const; + QWidget *createWidget(QWidget *parent); + void initialize(QDesignerFormEditorInterface *core); + +private: + bool initialized; +}; +//! [0] + +#endif diff --git a/examples/designer/worldtimeclockplugin/worldtimeclockplugin.pro b/examples/designer/worldtimeclockplugin/worldtimeclockplugin.pro new file mode 100644 index 0000000000..cd117dc05d --- /dev/null +++ b/examples/designer/worldtimeclockplugin/worldtimeclockplugin.pro @@ -0,0 +1,21 @@ +#! [0] +CONFIG += designer plugin +#! [0] +TARGET = $$qtLibraryTarget($$TARGET) +#! [1] +TEMPLATE = lib +#! [1] +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/designer + +#! [2] +HEADERS = worldtimeclock.h \ + worldtimeclockplugin.h +SOURCES = worldtimeclock.cpp \ + worldtimeclockplugin.cpp +#! [2] + +# install +target.path = $$[QT_INSTALL_PLUGINS]/designer +sources.files = $$SOURCES $$HEADERS *.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/designer/worldtimeclockplugin +INSTALLS += target sources -- cgit v1.2.3