summaryrefslogtreecommitdiffstats
path: root/examples/tools
diff options
context:
space:
mode:
authoraxis <qt-info@nokia.com>2009-04-24 13:34:15 +0200
committeraxis <qt-info@nokia.com>2009-04-24 13:34:15 +0200
commit8f427b2b914d5b575a4a7c0ed65d2fb8f45acc76 (patch)
treea17e1a767a89542ab59907462206d7dcf2e504b2 /examples/tools
Long live Qt for S60!
Diffstat (limited to 'examples/tools')
-rw-r--r--examples/tools/README40
-rw-r--r--examples/tools/codecs/codecs.pro13
-rw-r--r--examples/tools/codecs/encodedfiles/.gitattributes2
-rw-r--r--examples/tools/codecs/encodedfiles/iso-8859-1.txt6
-rw-r--r--examples/tools/codecs/encodedfiles/iso-8859-15.txt8
-rw-r--r--examples/tools/codecs/encodedfiles/utf-16.txtbin0 -> 162 bytes
-rw-r--r--examples/tools/codecs/encodedfiles/utf-16be.txtbin0 -> 160 bytes
-rw-r--r--examples/tools/codecs/encodedfiles/utf-16le.txtbin0 -> 160 bytes
-rw-r--r--examples/tools/codecs/encodedfiles/utf-8.txt6
-rw-r--r--examples/tools/codecs/main.cpp52
-rw-r--r--examples/tools/codecs/mainwindow.cpp203
-rw-r--r--examples/tools/codecs/mainwindow.h88
-rw-r--r--examples/tools/codecs/previewform.cpp102
-rw-r--r--examples/tools/codecs/previewform.h80
-rw-r--r--examples/tools/completer/completer.pro14
-rw-r--r--examples/tools/completer/completer.qrc6
-rw-r--r--examples/tools/completer/dirmodel.cpp63
-rw-r--r--examples/tools/completer/dirmodel.h61
-rw-r--r--examples/tools/completer/main.cpp55
-rw-r--r--examples/tools/completer/mainwindow.cpp264
-rw-r--r--examples/tools/completer/mainwindow.h87
-rw-r--r--examples/tools/completer/resources/countries.txt241
-rw-r--r--examples/tools/completer/resources/wordlist.txt1486
-rw-r--r--examples/tools/customcompleter/customcompleter.pro14
-rw-r--r--examples/tools/customcompleter/customcompleter.qrc5
-rw-r--r--examples/tools/customcompleter/main.cpp55
-rw-r--r--examples/tools/customcompleter/mainwindow.cpp118
-rw-r--r--examples/tools/customcompleter/mainwindow.h77
-rw-r--r--examples/tools/customcompleter/resources/wordlist.txt1455
-rw-r--r--examples/tools/customcompleter/textedit.cpp174
-rw-r--r--examples/tools/customcompleter/textedit.h79
-rw-r--r--examples/tools/customtype/customtype.pro3
-rw-r--r--examples/tools/customtype/main.cpp74
-rw-r--r--examples/tools/customtype/message.cpp90
-rw-r--r--examples/tools/customtype/message.h76
-rw-r--r--examples/tools/customtypesending/customtypesending.pro5
-rw-r--r--examples/tools/customtypesending/main.cpp68
-rw-r--r--examples/tools/customtypesending/message.cpp72
-rw-r--r--examples/tools/customtypesending/message.h72
-rw-r--r--examples/tools/customtypesending/window.cpp80
-rw-r--r--examples/tools/customtypesending/window.h73
-rw-r--r--examples/tools/echoplugin/echoplugin.pro13
-rw-r--r--examples/tools/echoplugin/echowindow/echointerface.h62
-rw-r--r--examples/tools/echoplugin/echowindow/echowindow.cpp119
-rw-r--r--examples/tools/echoplugin/echowindow/echowindow.h80
-rw-r--r--examples/tools/echoplugin/echowindow/echowindow.pro20
-rw-r--r--examples/tools/echoplugin/echowindow/main.cpp57
-rw-r--r--examples/tools/echoplugin/plugin/echoplugin.cpp55
-rw-r--r--examples/tools/echoplugin/plugin/echoplugin.h60
-rw-r--r--examples/tools/echoplugin/plugin/plugin.pro19
-rw-r--r--examples/tools/i18n/i18n.pro28
-rw-r--r--examples/tools/i18n/i18n.qrc18
-rw-r--r--examples/tools/i18n/languagechooser.cpp167
-rw-r--r--examples/tools/i18n/languagechooser.h86
-rw-r--r--examples/tools/i18n/main.cpp55
-rw-r--r--examples/tools/i18n/mainwindow.cpp96
-rw-r--r--examples/tools/i18n/mainwindow.h77
-rw-r--r--examples/tools/i18n/translations/i18n_ar.qmbin0 -> 736 bytes
-rw-r--r--examples/tools/i18n/translations/i18n_ar.ts57
-rw-r--r--examples/tools/i18n/translations/i18n_cs.qmbin0 -> 796 bytes
-rw-r--r--examples/tools/i18n/translations/i18n_cs.ts57
-rw-r--r--examples/tools/i18n/translations/i18n_de.qmbin0 -> 848 bytes
-rw-r--r--examples/tools/i18n/translations/i18n_de.ts57
-rw-r--r--examples/tools/i18n/translations/i18n_el.qmbin0 -> 804 bytes
-rw-r--r--examples/tools/i18n/translations/i18n_el.ts57
-rw-r--r--examples/tools/i18n/translations/i18n_en.qmbin0 -> 810 bytes
-rw-r--r--examples/tools/i18n/translations/i18n_en.ts57
-rw-r--r--examples/tools/i18n/translations/i18n_eo.qmbin0 -> 806 bytes
-rw-r--r--examples/tools/i18n/translations/i18n_eo.ts57
-rw-r--r--examples/tools/i18n/translations/i18n_fr.qmbin0 -> 844 bytes
-rw-r--r--examples/tools/i18n/translations/i18n_fr.ts57
-rw-r--r--examples/tools/i18n/translations/i18n_it.qmbin0 -> 808 bytes
-rw-r--r--examples/tools/i18n/translations/i18n_it.ts57
-rw-r--r--examples/tools/i18n/translations/i18n_jp.qmbin0 -> 722 bytes
-rw-r--r--examples/tools/i18n/translations/i18n_jp.ts57
-rw-r--r--examples/tools/i18n/translations/i18n_ko.qmbin0 -> 690 bytes
-rw-r--r--examples/tools/i18n/translations/i18n_ko.ts57
-rw-r--r--examples/tools/i18n/translations/i18n_no.qmbin0 -> 804 bytes
-rw-r--r--examples/tools/i18n/translations/i18n_no.ts57
-rw-r--r--examples/tools/i18n/translations/i18n_ru.qmbin0 -> 806 bytes
-rw-r--r--examples/tools/i18n/translations/i18n_ru.ts59
-rw-r--r--examples/tools/i18n/translations/i18n_sv.qmbin0 -> 814 bytes
-rw-r--r--examples/tools/i18n/translations/i18n_sv.ts57
-rw-r--r--examples/tools/i18n/translations/i18n_zh.qmbin0 -> 700 bytes
-rw-r--r--examples/tools/i18n/translations/i18n_zh.ts57
-rw-r--r--examples/tools/plugandpaint/interfaces.h111
-rw-r--r--examples/tools/plugandpaint/main.cpp58
-rw-r--r--examples/tools/plugandpaint/mainwindow.cpp310
-rw-r--r--examples/tools/plugandpaint/mainwindow.h104
-rw-r--r--examples/tools/plugandpaint/paintarea.cpp196
-rw-r--r--examples/tools/plugandpaint/paintarea.h92
-rw-r--r--examples/tools/plugandpaint/plugandpaint.pro28
-rw-r--r--examples/tools/plugandpaint/plugindialog.cpp157
-rw-r--r--examples/tools/plugandpaint/plugindialog.h77
-rw-r--r--examples/tools/plugandpaintplugins/basictools/basictools.pro17
-rw-r--r--examples/tools/plugandpaintplugins/basictools/basictoolsplugin.cpp198
-rw-r--r--examples/tools/plugandpaintplugins/basictools/basictoolsplugin.h88
-rw-r--r--examples/tools/plugandpaintplugins/extrafilters/extrafilters.pro19
-rw-r--r--examples/tools/plugandpaintplugins/extrafilters/extrafiltersplugin.cpp125
-rw-r--r--examples/tools/plugandpaintplugins/extrafilters/extrafiltersplugin.h64
-rw-r--r--examples/tools/plugandpaintplugins/plugandpaintplugins.pro11
-rw-r--r--examples/tools/regexp/main.cpp52
-rw-r--r--examples/tools/regexp/regexp.pro11
-rw-r--r--examples/tools/regexp/regexpdialog.cpp188
-rw-r--r--examples/tools/regexp/regexpdialog.h86
-rw-r--r--examples/tools/settingseditor/inifiles/licensepage.ini46
-rw-r--r--examples/tools/settingseditor/inifiles/qsa.ini26
-rw-r--r--examples/tools/settingseditor/locationdialog.cpp217
-rw-r--r--examples/tools/settingseditor/locationdialog.h85
-rw-r--r--examples/tools/settingseditor/main.cpp52
-rw-r--r--examples/tools/settingseditor/mainwindow.cpp223
-rw-r--r--examples/tools/settingseditor/mainwindow.h92
-rw-r--r--examples/tools/settingseditor/settingseditor.pro17
-rw-r--r--examples/tools/settingseditor/settingstree.cpp263
-rw-r--r--examples/tools/settingseditor/settingstree.h91
-rw-r--r--examples/tools/settingseditor/variantdelegate.cpp317
-rw-r--r--examples/tools/settingseditor/variantdelegate.h82
-rw-r--r--examples/tools/styleplugin/plugin/plugin.pro25
-rw-r--r--examples/tools/styleplugin/plugin/simplestyle.cpp49
-rw-r--r--examples/tools/styleplugin/plugin/simplestyle.h61
-rw-r--r--examples/tools/styleplugin/plugin/simplestyleplugin.cpp65
-rw-r--r--examples/tools/styleplugin/plugin/simplestyleplugin.h65
-rw-r--r--examples/tools/styleplugin/styleplugin.pro11
-rw-r--r--examples/tools/styleplugin/stylewindow/main.cpp58
-rw-r--r--examples/tools/styleplugin/stylewindow/stylewindow.cpp61
-rw-r--r--examples/tools/styleplugin/stylewindow/stylewindow.h55
-rw-r--r--examples/tools/styleplugin/stylewindow/stylewindow.pro19
-rw-r--r--examples/tools/tools.pro24
-rw-r--r--examples/tools/treemodelcompleter/main.cpp55
-rw-r--r--examples/tools/treemodelcompleter/mainwindow.cpp247
-rw-r--r--examples/tools/treemodelcompleter/mainwindow.h89
-rw-r--r--examples/tools/treemodelcompleter/resources/treemodel.txt20
-rw-r--r--examples/tools/treemodelcompleter/treemodelcompleter.cpp98
-rw-r--r--examples/tools/treemodelcompleter/treemodelcompleter.h71
-rw-r--r--examples/tools/treemodelcompleter/treemodelcompleter.pro14
-rw-r--r--examples/tools/treemodelcompleter/treemodelcompleter.qrc5
-rw-r--r--examples/tools/undoframework/commands.cpp163
-rw-r--r--examples/tools/undoframework/commands.h104
-rw-r--r--examples/tools/undoframework/diagramitem.cpp66
-rw-r--r--examples/tools/undoframework/diagramitem.h73
-rw-r--r--examples/tools/undoframework/diagramscene.cpp76
-rw-r--r--examples/tools/undoframework/diagramscene.h75
-rw-r--r--examples/tools/undoframework/images/cross.pngbin0 -> 114 bytes
-rw-r--r--examples/tools/undoframework/main.cpp58
-rw-r--r--examples/tools/undoframework/mainwindow.cpp209
-rw-r--r--examples/tools/undoframework/mainwindow.h100
-rw-r--r--examples/tools/undoframework/undoframework.pro18
-rw-r--r--examples/tools/undoframework/undoframework.qrc6
148 files changed, 12822 insertions, 0 deletions
diff --git a/examples/tools/README b/examples/tools/README
new file mode 100644
index 0000000000..b0926f2fb6
--- /dev/null
+++ b/examples/tools/README
@@ -0,0 +1,40 @@
+Qt is equipped with a range of capable tool classes, from containers and
+iterators to classes for string handling and manipulation.
+
+Other classes provide application infrastructure support, handling plugin
+loading and managing configuration files.
+
+
+The example launcher provided with Qt can be used to explore each of the
+examples in this directory.
+
+Documentation for these examples can be found via the Tutorial and Examples
+link in the main Qt documentation.
+
+
+Finding the Qt Examples and Demos launcher
+==========================================
+
+On Windows:
+
+The launcher can be accessed via the Windows Start menu. Select the menu
+entry entitled "Qt Examples and Demos" entry in the submenu containing
+the Qt tools.
+
+On Mac OS X:
+
+For the binary distribution, the qtdemo executable is installed in the
+/Developer/Applications/Qt directory. For the source distribution, it is
+installed alongside the other Qt tools on the path specified when Qt is
+configured.
+
+On Unix/Linux:
+
+The qtdemo executable is installed alongside the other Qt tools on the path
+specified when Qt is configured.
+
+On all platforms:
+
+The source code for the launcher can be found in the demos/qtdemo directory
+in the Qt package. This example is built at the same time as the Qt libraries,
+tools, examples, and demonstrations.
diff --git a/examples/tools/codecs/codecs.pro b/examples/tools/codecs/codecs.pro
new file mode 100644
index 0000000000..7cc0ae836c
--- /dev/null
+++ b/examples/tools/codecs/codecs.pro
@@ -0,0 +1,13 @@
+HEADERS += mainwindow.h \
+ previewform.h
+SOURCES += main.cpp \
+ mainwindow.cpp \
+ previewform.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/tools/codecs
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS encodedfiles codecs.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/codecs
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/tools/codecs/encodedfiles/.gitattributes b/examples/tools/codecs/encodedfiles/.gitattributes
new file mode 100644
index 0000000000..996aab2a08
--- /dev/null
+++ b/examples/tools/codecs/encodedfiles/.gitattributes
@@ -0,0 +1,2 @@
+iso-8859-15.txt -crlf
+iso-8859-1.txt -crlf
diff --git a/examples/tools/codecs/encodedfiles/iso-8859-1.txt b/examples/tools/codecs/encodedfiles/iso-8859-1.txt
new file mode 100644
index 0000000000..4a7ebe3c8b
--- /dev/null
+++ b/examples/tools/codecs/encodedfiles/iso-8859-1.txt
@@ -0,0 +1,6 @@
+Paulo Coelho: O Gênio e as Rosas
+Anna Hallström, Urban Östberg: Svår svenska
+Darrell Huff: How to Lie with Statistics
+Franz Kafka: Das Schloß
+Walter Moers: Die 13½ Leben des Käpt'n Blaubär
+Dag Solstad: Forsøk på å beskrive det ugjennomtrengelige
diff --git a/examples/tools/codecs/encodedfiles/iso-8859-15.txt b/examples/tools/codecs/encodedfiles/iso-8859-15.txt
new file mode 100644
index 0000000000..cd43ea3e00
--- /dev/null
+++ b/examples/tools/codecs/encodedfiles/iso-8859-15.txt
@@ -0,0 +1,8 @@
+Paulo Coelho: O Gênio e as Rosas
+Jean-Pierre Coffe: À table en famille avec 15 ¤ par jour
+Anna Hallström, Urban Östberg: Svår svenska
+Darrell Huff: How to Lie with Statistics
+Franz Kafka: Das Schloß
+Helena Lehecková: T¨ekkiä suomalaisille
+Arthur Rimbaud: ¼uvres complètes
+Dag Solstad: Forsøk på å beskrive det ugjennomtrengelige
diff --git a/examples/tools/codecs/encodedfiles/utf-16.txt b/examples/tools/codecs/encodedfiles/utf-16.txt
new file mode 100644
index 0000000000..371f06f7fa
--- /dev/null
+++ b/examples/tools/codecs/encodedfiles/utf-16.txt
Binary files differ
diff --git a/examples/tools/codecs/encodedfiles/utf-16be.txt b/examples/tools/codecs/encodedfiles/utf-16be.txt
new file mode 100644
index 0000000000..d8ae6428bc
--- /dev/null
+++ b/examples/tools/codecs/encodedfiles/utf-16be.txt
Binary files differ
diff --git a/examples/tools/codecs/encodedfiles/utf-16le.txt b/examples/tools/codecs/encodedfiles/utf-16le.txt
new file mode 100644
index 0000000000..3779264c7c
--- /dev/null
+++ b/examples/tools/codecs/encodedfiles/utf-16le.txt
Binary files differ
diff --git a/examples/tools/codecs/encodedfiles/utf-8.txt b/examples/tools/codecs/encodedfiles/utf-8.txt
new file mode 100644
index 0000000000..a5e4ae6fa7
--- /dev/null
+++ b/examples/tools/codecs/encodedfiles/utf-8.txt
@@ -0,0 +1,6 @@
+Språk: Norsk
+Γλώσσα: Ελληνικά
+Язык: РуÑÑкий
+언어 : 한국어
+言語: 日本語
+Langage : Français
diff --git a/examples/tools/codecs/main.cpp b/examples/tools/codecs/main.cpp
new file mode 100644
index 0000000000..4856752c8c
--- /dev/null
+++ b/examples/tools/codecs/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow mainWin;
+ mainWin.show();
+ return app.exec();
+}
diff --git a/examples/tools/codecs/mainwindow.cpp b/examples/tools/codecs/mainwindow.cpp
new file mode 100644
index 0000000000..1e6fa69546
--- /dev/null
+++ b/examples/tools/codecs/mainwindow.cpp
@@ -0,0 +1,203 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "mainwindow.h"
+#include "previewform.h"
+
+MainWindow::MainWindow()
+{
+ textEdit = new QTextEdit;
+ textEdit->setLineWrapMode(QTextEdit::NoWrap);
+ setCentralWidget(textEdit);
+
+ findCodecs();
+
+ previewForm = new PreviewForm(this);
+ previewForm->setCodecList(codecs);
+
+ createActions();
+ createMenus();
+
+ setWindowTitle(tr("Codecs"));
+ resize(500, 400);
+}
+
+void MainWindow::open()
+{
+ QString fileName = QFileDialog::getOpenFileName(this);
+ if (!fileName.isEmpty()) {
+ QFile file(fileName);
+ if (!file.open(QFile::ReadOnly)) {
+ QMessageBox::warning(this, tr("Codecs"),
+ tr("Cannot read file %1:\n%2")
+ .arg(fileName)
+ .arg(file.errorString()));
+ return;
+ }
+
+ QByteArray data = file.readAll();
+
+ previewForm->setEncodedData(data);
+ if (previewForm->exec())
+ textEdit->setPlainText(previewForm->decodedString());
+ }
+}
+
+void MainWindow::save()
+{
+ QString fileName = QFileDialog::getSaveFileName(this);
+ if (!fileName.isEmpty()) {
+ QFile file(fileName);
+ if (!file.open(QFile::WriteOnly | QFile::Text)) {
+ QMessageBox::warning(this, tr("Codecs"),
+ tr("Cannot write file %1:\n%2")
+ .arg(fileName)
+ .arg(file.errorString()));
+ return;
+ }
+
+ QAction *action = qobject_cast<QAction *>(sender());
+ QByteArray codecName = action->data().toByteArray();
+
+ QTextStream out(&file);
+ out.setCodec(codecName);
+ out << textEdit->toPlainText();
+ }
+}
+
+void MainWindow::about()
+{
+ QMessageBox::about(this, tr("About Codecs"),
+ tr("The <b>Codecs</b> example demonstrates how to read and write "
+ "files using various encodings."));
+}
+
+void MainWindow::aboutToShowSaveAsMenu()
+{
+ QString currentText = textEdit->toPlainText();
+
+ foreach (QAction *action, saveAsActs) {
+ QByteArray codecName = action->data().toByteArray();
+ QTextCodec *codec = QTextCodec::codecForName(codecName);
+ action->setVisible(codec && codec->canEncode(currentText));
+ }
+}
+
+void MainWindow::findCodecs()
+{
+ QMap<QString, QTextCodec *> codecMap;
+ QRegExp iso8859RegExp("ISO[- ]8859-([0-9]+).*");
+
+ foreach (int mib, QTextCodec::availableMibs()) {
+ QTextCodec *codec = QTextCodec::codecForMib(mib);
+
+ QString sortKey = codec->name().toUpper();
+ int rank;
+
+ if (sortKey.startsWith("UTF-8")) {
+ rank = 1;
+ } else if (sortKey.startsWith("UTF-16")) {
+ rank = 2;
+ } else if (iso8859RegExp.exactMatch(sortKey)) {
+ if (iso8859RegExp.cap(1).size() == 1)
+ rank = 3;
+ else
+ rank = 4;
+ } else {
+ rank = 5;
+ }
+ sortKey.prepend(QChar('0' + rank));
+
+ codecMap.insert(sortKey, codec);
+ }
+ codecs = codecMap.values();
+}
+
+void MainWindow::createActions()
+{
+ openAct = new QAction(tr("&Open..."), this);
+ openAct->setShortcut(tr("Ctrl+O"));
+ connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
+
+ foreach (QTextCodec *codec, codecs) {
+ QString text = tr("%1...").arg(QString(codec->name()));
+
+ QAction *action = new QAction(text, this);
+ action->setData(codec->name());
+ connect(action, SIGNAL(triggered()), this, SLOT(save()));
+ saveAsActs.append(action);
+ }
+
+ exitAct = new QAction(tr("E&xit"), this);
+ exitAct->setShortcut(tr("Ctrl+Q"));
+ connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
+
+ aboutAct = new QAction(tr("&About"), this);
+ connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+
+ aboutQtAct = new QAction(tr("About &Qt"), this);
+ connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+}
+
+void MainWindow::createMenus()
+{
+ saveAsMenu = new QMenu(tr("&Save As"), this);
+ foreach (QAction *action, saveAsActs)
+ saveAsMenu->addAction(action);
+ connect(saveAsMenu, SIGNAL(aboutToShow()),
+ this, SLOT(aboutToShowSaveAsMenu()));
+
+ fileMenu = new QMenu(tr("&File"), this);
+ fileMenu->addAction(openAct);
+ fileMenu->addMenu(saveAsMenu);
+ fileMenu->addSeparator();
+ fileMenu->addAction(exitAct);
+
+ helpMenu = new QMenu(tr("&Help"), this);
+ helpMenu->addAction(aboutAct);
+ helpMenu->addAction(aboutQtAct);
+
+ menuBar()->addMenu(fileMenu);
+ menuBar()->addSeparator();
+ menuBar()->addMenu(helpMenu);
+}
diff --git a/examples/tools/codecs/mainwindow.h b/examples/tools/codecs/mainwindow.h
new file mode 100644
index 0000000000..1702d5c586
--- /dev/null
+++ b/examples/tools/codecs/mainwindow.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 MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QList>
+#include <QMainWindow>
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QMenu;
+class QTextCodec;
+class QTextEdit;
+QT_END_NAMESPACE
+class PreviewForm;
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+private slots:
+ void open();
+ void save();
+ void about();
+ void aboutToShowSaveAsMenu();
+
+private:
+ void findCodecs();
+ void createActions();
+ void createMenus();
+
+ QTextEdit *textEdit;
+ PreviewForm *previewForm;
+ QList<QTextCodec *> codecs;
+
+ QMenu *fileMenu;
+ QMenu *helpMenu;
+ QMenu *saveAsMenu;
+ QAction *openAct;
+ QList<QAction *> saveAsActs;
+ QAction *exitAct;
+ QAction *aboutAct;
+ QAction *aboutQtAct;
+};
+
+#endif
diff --git a/examples/tools/codecs/previewform.cpp b/examples/tools/codecs/previewform.cpp
new file mode 100644
index 0000000000..cbe084f043
--- /dev/null
+++ b/examples/tools/codecs/previewform.cpp
@@ -0,0 +1,102 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "previewform.h"
+
+PreviewForm::PreviewForm(QWidget *parent)
+ : QDialog(parent)
+{
+ encodingComboBox = new QComboBox;
+
+ encodingLabel = new QLabel(tr("&Encoding:"));
+ encodingLabel->setBuddy(encodingComboBox);
+
+ textEdit = new QTextEdit;
+ textEdit->setLineWrapMode(QTextEdit::NoWrap);
+ textEdit->setReadOnly(true);
+
+ buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
+ | QDialogButtonBox::Cancel);
+
+ connect(encodingComboBox, SIGNAL(activated(int)),
+ this, SLOT(updateTextEdit()));
+ connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
+ connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
+
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->addWidget(encodingLabel, 0, 0);
+ mainLayout->addWidget(encodingComboBox, 0, 1);
+ mainLayout->addWidget(textEdit, 1, 0, 1, 2);
+ mainLayout->addWidget(buttonBox, 2, 0, 1, 2);
+ setLayout(mainLayout);
+
+ setWindowTitle(tr("Choose Encoding"));
+ resize(400, 300);
+}
+
+void PreviewForm::setCodecList(const QList<QTextCodec *> &list)
+{
+ encodingComboBox->clear();
+ foreach (QTextCodec *codec, list)
+ encodingComboBox->addItem(codec->name(), codec->mibEnum());
+}
+
+void PreviewForm::setEncodedData(const QByteArray &data)
+{
+ encodedData = data;
+ updateTextEdit();
+}
+
+void PreviewForm::updateTextEdit()
+{
+ int mib = encodingComboBox->itemData(
+ encodingComboBox->currentIndex()).toInt();
+ QTextCodec *codec = QTextCodec::codecForMib(mib);
+
+ QTextStream in(&encodedData);
+ in.setAutoDetectUnicode(false);
+ in.setCodec(codec);
+ decodedStr = in.readAll();
+
+ textEdit->setPlainText(decodedStr);
+}
diff --git a/examples/tools/codecs/previewform.h b/examples/tools/codecs/previewform.h
new file mode 100644
index 0000000000..130cb79296
--- /dev/null
+++ b/examples/tools/codecs/previewform.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** 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 PREVIEWFORM_H
+#define PREVIEWFORM_H
+
+#include <QDialog>
+#include <QList>
+
+QT_BEGIN_NAMESPACE
+class QComboBox;
+class QDialogButtonBox;
+class QLabel;
+class QTextCodec;
+class QTextEdit;
+QT_END_NAMESPACE
+
+class PreviewForm : public QDialog
+{
+ Q_OBJECT
+
+public:
+ PreviewForm(QWidget *parent = 0);
+
+ void setCodecList(const QList<QTextCodec *> &list);
+ void setEncodedData(const QByteArray &data);
+ QString decodedString() const { return decodedStr; }
+
+private slots:
+ void updateTextEdit();
+
+private:
+ QByteArray encodedData;
+ QString decodedStr;
+
+ QComboBox *encodingComboBox;
+ QLabel *encodingLabel;
+ QTextEdit *textEdit;
+ QDialogButtonBox *buttonBox;
+};
+
+#endif
diff --git a/examples/tools/completer/completer.pro b/examples/tools/completer/completer.pro
new file mode 100644
index 0000000000..4f3145438d
--- /dev/null
+++ b/examples/tools/completer/completer.pro
@@ -0,0 +1,14 @@
+HEADERS = dirmodel.h \
+ mainwindow.h
+SOURCES = dirmodel.cpp \
+ main.cpp \
+ mainwindow.cpp
+RESOURCES = completer.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/tools/completer
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS completer.pro resources
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/completer
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/tools/completer/completer.qrc b/examples/tools/completer/completer.qrc
new file mode 100644
index 0000000000..4f57e1a824
--- /dev/null
+++ b/examples/tools/completer/completer.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/">
+ <file>resources/countries.txt</file>
+ <file>resources/wordlist.txt</file>
+</qresource>
+</RCC>
diff --git a/examples/tools/completer/dirmodel.cpp b/examples/tools/completer/dirmodel.cpp
new file mode 100644
index 0000000000..1daf03ce73
--- /dev/null
+++ b/examples/tools/completer/dirmodel.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "dirmodel.h"
+
+//! [0]
+DirModel::DirModel(QObject *parent)
+ : QDirModel(parent)
+{
+}
+//! [0]
+
+//! [1]
+QVariant DirModel::data(const QModelIndex &index, int role) const
+{
+ if (role == Qt::DisplayRole && index.column() == 0) {
+ QString path = QDir::toNativeSeparators(filePath(index));
+ if (path.endsWith(QDir::separator()))
+ path.chop(1);
+ return path;
+ }
+
+ return QDirModel::data(index, role);
+}
+//! [1]
diff --git a/examples/tools/completer/dirmodel.h b/examples/tools/completer/dirmodel.h
new file mode 100644
index 0000000000..bd49ca9290
--- /dev/null
+++ b/examples/tools/completer/dirmodel.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DIRMODEL_H
+#define DIRMODEL_H
+
+#include <QDirModel>
+
+// With a QDirModel, set on a view, you will see "Program Files" in the view
+// But with this model, you will see "C:\Program Files" in the view.
+// We acheive this, by having the data() return the entire file path for
+// the display role. Note that the Qt::EditRole over which the QCompleter
+// looks for matches is left unchanged
+//! [0]
+class DirModel : public QDirModel
+{
+public:
+ DirModel(QObject *parent = 0);
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+};
+//! [0]
+
+#endif
diff --git a/examples/tools/completer/main.cpp b/examples/tools/completer/main.cpp
new file mode 100644
index 0000000000..a414cd571b
--- /dev/null
+++ b/examples/tools/completer/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "mainwindow.h"
+
+//! [0]
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(completer);
+
+ QApplication app(argc, argv);
+ MainWindow window;
+ window.show();
+ return app.exec();
+}
+//! [0]
diff --git a/examples/tools/completer/mainwindow.cpp b/examples/tools/completer/mainwindow.cpp
new file mode 100644
index 0000000000..862967a7f8
--- /dev/null
+++ b/examples/tools/completer/mainwindow.cpp
@@ -0,0 +1,264 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "dirmodel.h"
+#include "mainwindow.h"
+
+//! [0]
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent), completer(0), lineEdit(0)
+{
+ createMenu();
+
+ QWidget *centralWidget = new QWidget;
+
+ QLabel *modelLabel = new QLabel;
+ modelLabel->setText(tr("Model"));
+
+ modelCombo = new QComboBox;
+ modelCombo->addItem(tr("QDirModel"));
+ modelCombo->addItem(tr("QDirModel that shows full path"));
+ modelCombo->addItem(tr("Country list"));
+ modelCombo->addItem(tr("Word list"));
+ modelCombo->setCurrentIndex(0);
+
+ QLabel *modeLabel = new QLabel;
+ modeLabel->setText(tr("Completion Mode"));
+ modeCombo = new QComboBox;
+ modeCombo->addItem(tr("Inline"));
+ modeCombo->addItem(tr("Filtered Popup"));
+ modeCombo->addItem(tr("Unfiltered Popup"));
+ modeCombo->setCurrentIndex(1);
+
+ QLabel *caseLabel = new QLabel;
+ caseLabel->setText(tr("Case Sensitivity"));
+ caseCombo = new QComboBox;
+ caseCombo->addItem(tr("Case Insensitive"));
+ caseCombo->addItem(tr("Case Sensitive"));
+ caseCombo->setCurrentIndex(0);
+//! [0]
+
+//! [1]
+ wrapCheckBox = new QCheckBox;
+ wrapCheckBox->setText(tr("Wrap around completions"));
+ wrapCheckBox->setChecked(true);
+//! [1]
+
+//! [2]
+ contentsLabel = new QLabel;
+ contentsLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+
+ connect(modelCombo, SIGNAL(activated(int)), this, SLOT(changeModel()));
+ connect(modeCombo, SIGNAL(activated(int)), this, SLOT(changeMode(int)));
+ connect(caseCombo, SIGNAL(activated(int)), this, SLOT(changeCase(int)));
+//! [2]
+
+//! [3]
+ lineEdit = new QLineEdit;
+
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(modelLabel, 0, 0); layout->addWidget(modelCombo, 0, 1);
+ layout->addWidget(modeLabel, 1, 0); layout->addWidget(modeCombo, 1, 1);
+ layout->addWidget(caseLabel, 2, 0); layout->addWidget(caseCombo, 2, 1);
+ layout->addWidget(wrapCheckBox, 3, 0);
+ layout->addWidget(contentsLabel, 4, 0, 1, 2);
+ layout->addWidget(lineEdit, 5, 0, 1, 2);
+ centralWidget->setLayout(layout);
+ setCentralWidget(centralWidget);
+
+ changeModel();
+
+ setWindowTitle(tr("Completer"));
+ lineEdit->setFocus();
+}
+//! [3]
+
+//! [4]
+void MainWindow::createMenu()
+{
+ QAction *exitAction = new QAction(tr("Exit"), this);
+ QAction *aboutAct = new QAction(tr("About"), this);
+ QAction *aboutQtAct = new QAction(tr("About Qt"), this);
+
+ connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
+ connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+ connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+
+ QMenu* fileMenu = menuBar()->addMenu(tr("File"));
+ fileMenu->addAction(exitAction);
+
+ QMenu* helpMenu = menuBar()->addMenu(tr("About"));
+ helpMenu->addAction(aboutAct);
+ helpMenu->addAction(aboutQtAct);
+}
+//! [4]
+
+//! [5]
+QAbstractItemModel *MainWindow::modelFromFile(const QString& fileName)
+{
+ QFile file(fileName);
+ if (!file.open(QFile::ReadOnly))
+ return new QStringListModel(completer);
+//! [5]
+
+//! [6]
+#ifndef QT_NO_CURSOR
+ QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
+#endif
+ QStringList words;
+
+ while (!file.atEnd()) {
+ QByteArray line = file.readLine();
+ if (!line.isEmpty())
+ words << line.trimmed();
+ }
+
+#ifndef QT_NO_CURSOR
+ QApplication::restoreOverrideCursor();
+#endif
+//! [6]
+
+//! [7]
+ if (!fileName.contains(QLatin1String("countries.txt")))
+ return new QStringListModel(words, completer);
+//! [7]
+
+ // The last two chars of the countries.txt file indicate the country
+ // symbol. We put that in column 2 of a standard item model
+//! [8]
+ QStandardItemModel *m = new QStandardItemModel(words.count(), 2, completer);
+//! [8] //! [9]
+ for (int i = 0; i < words.count(); ++i) {
+ QModelIndex countryIdx = m->index(i, 0);
+ QModelIndex symbolIdx = m->index(i, 1);
+ QString country = words[i].mid(0, words[i].length() - 2).trimmed();
+ QString symbol = words[i].right(2);
+ m->setData(countryIdx, country);
+ m->setData(symbolIdx, symbol);
+ }
+
+ return m;
+}
+//! [9]
+
+//! [10]
+void MainWindow::changeMode(int index)
+{
+ QCompleter::CompletionMode mode;
+ if (index == 0)
+ mode = QCompleter::InlineCompletion;
+ else if (index == 1)
+ mode = QCompleter::PopupCompletion;
+ else
+ mode = QCompleter::UnfilteredPopupCompletion;
+
+ completer->setCompletionMode(mode);
+}
+//! [10]
+
+void MainWindow::changeCase(int cs)
+{
+ completer->setCaseSensitivity(cs ? Qt::CaseSensitive : Qt::CaseInsensitive);
+}
+
+//! [11]
+void MainWindow::changeModel()
+{
+ delete completer;
+ completer = new QCompleter(this);
+
+ switch (modelCombo->currentIndex()) {
+ default:
+ case 0:
+ { // Unsorted QDirModel
+ QDirModel *dirModel = new QDirModel(completer);
+ completer->setModel(dirModel);
+ contentsLabel->setText(tr("Enter file path"));
+ }
+ break;
+//! [11] //! [12]
+ case 1:
+ { // DirModel that shows full paths
+ DirModel *dirModel = new DirModel(completer);
+ completer->setModel(dirModel);
+ contentsLabel->setText(tr("Enter file path"));
+ }
+ break;
+//! [12] //! [13]
+ case 2:
+ { // Country List
+ completer->setModel(modelFromFile(":/resources/countries.txt"));
+ QTreeView *treeView = new QTreeView;
+ completer->setPopup(treeView);
+ treeView->setRootIsDecorated(false);
+ treeView->header()->hide();
+ treeView->header()->setStretchLastSection(false);
+ treeView->header()->setResizeMode(0, QHeaderView::Stretch);
+ treeView->header()->setResizeMode(1, QHeaderView::ResizeToContents);
+ contentsLabel->setText(tr("Enter name of your country"));
+ }
+ break;
+//! [13] //! [14]
+ case 3:
+ { // Word list
+ completer->setModel(modelFromFile(":/resources/wordlist.txt"));
+ completer->setModelSorting(QCompleter::CaseInsensitivelySortedModel);
+ contentsLabel->setText(tr("Enter a word"));
+ }
+ break;
+ }
+
+ changeMode(modeCombo->currentIndex());
+ changeCase(caseCombo->currentIndex());
+ completer->setWrapAround(wrapCheckBox->isChecked());
+ lineEdit->setCompleter(completer);
+ connect(wrapCheckBox, SIGNAL(clicked(bool)), completer, SLOT(setWrapAround(bool)));
+}
+//! [14]
+
+//! [15]
+void MainWindow::about()
+{
+ QMessageBox::about(this, tr("About"), tr("This example demonstrates the "
+ "different features of the QCompleter class."));
+}
+//! [15]
diff --git a/examples/tools/completer/mainwindow.h b/examples/tools/completer/mainwindow.h
new file mode 100644
index 0000000000..f6fba9c29e
--- /dev/null
+++ b/examples/tools/completer/mainwindow.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+QT_BEGIN_NAMESPACE
+class QAbstractItemModel;
+class QComboBox;
+class QCompleter;
+class QLabel;
+class QLineEdit;
+class QProgressBar;
+class QCheckBox;
+QT_END_NAMESPACE
+
+//! [0]
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow(QWidget *parent = 0);
+
+private slots:
+ void about();
+ void changeCase(int);
+ void changeMode(int);
+ void changeModel();
+//! [0]
+
+//! [1]
+private:
+ void createMenu();
+ QAbstractItemModel *modelFromFile(const QString& fileName);
+
+ QComboBox *caseCombo;
+ QComboBox *modeCombo;
+ QComboBox *modelCombo;
+ QCheckBox *wrapCheckBox;
+ QCompleter *completer;
+ QLabel *contentsLabel;
+ QLineEdit *lineEdit;
+};
+//! [1]
+
+#endif // MAINWINDOW_H
diff --git a/examples/tools/completer/resources/countries.txt b/examples/tools/completer/resources/countries.txt
new file mode 100644
index 0000000000..5854fbc977
--- /dev/null
+++ b/examples/tools/completer/resources/countries.txt
@@ -0,0 +1,241 @@
+Afghanistan AF
+Albania AL
+Algeria DZ
+American Samoa AS
+Andorra AD
+Angola AO
+Anguilla AI
+Antarctica AQ
+Antigua And Barbuda AG
+Argentina AR
+Armenia AM
+Aruba AW
+Australia AU
+Austria AT
+Azerbaijan AZ
+Bahamas BS
+Bahrain BH
+Bangladesh BD
+Barbados BB
+Belarus BY
+Belgium BE
+Belize BZ
+Benin BJ
+Bermuda BM
+Bhutan BT
+Bolivia BO
+Bosnia And Herzegowina BA
+Botswana BW
+Bouvet Island BV
+Brazil BR
+British Indian Ocean Territory IO
+British Virgin Islands VG
+Brunei Darussalam BN
+Bulgaria BG
+Burkina Faso BF
+Burundi BI
+Cambodia KH
+Cameroon CM
+Canada CA
+Cape Verde CV
+Cayman Islands KY
+Central African Republic CF
+Chad TD
+Chile CL
+China CN
+Christmas Island CX
+Cocos Islands CC
+Colombia CO
+Comoros KM
+Cook Islands CK
+Costa Rica CR
+Croatia HR
+Cuba CU
+Cyprus CY
+Czech Republic CZ
+Democratic Republic Of Congo CD
+Democratic Republic Of Korea KP
+Denmark DK
+Djibouti DJ
+Dominica DM
+Dominican Republic DO
+EastTimor TL
+Ecuador EC
+Egypt EG
+El Salvador SV
+Equatorial Guinea GQ
+Eritrea ER
+Estonia EE
+Ethiopia ET
+Falkland Islands FK
+Faroe Islands FO
+Fiji FJ
+Finland FI
+France FR
+French Guiana GF
+French Polynesia PF
+French Southern Territories TF
+Gabon GA
+Gambia GM
+Georgia GE
+Germany DE
+Ghana GH
+Gibraltar GI
+Greece GR
+Greenland GL
+Grenada GD
+Guadeloupe GP
+Guam GU
+Guatemala GT
+Guinea GN
+Guinea Bissau GW
+Guyana GY
+Haiti HT
+Heard And McDonald Islands HM
+Honduras HN
+Hong Kong HK
+Hungary HU
+Iceland IS
+India IN
+Indonesia ID
+Iran IR
+Iraq IQ
+Ireland IE
+Israel IL
+Italy IT
+Ivory Coast CI
+Jamaica JM
+Japan JP
+Jordan JO
+Kazakhstan KZ
+Kenya KE
+Kiribati KI
+Kuwait KW
+Kyrgyzstan KG
+Lao LA
+Latvia LV
+Lebanon LB
+Lesotho LS
+Liberia LR
+Libyan Arab Jamahiriya LY
+Liechtenstein LI
+Lithuania LT
+Luxembourg LU
+Macau MO
+Macedonia MK
+Madagascar MG
+Malawi MW
+Malaysia MY
+Maldives MV
+Mali ML
+Malta MT
+Marshall Islands MH
+Martinique MQ
+Mauritania MR
+Mauritius MU
+Mayotte YT
+Metropolitan France FX
+Mexico MX
+Micronesia FM
+Moldova MD
+Monaco MC
+Mongolia MN
+Montserrat MS
+Morocco MA
+Mozambique MZ
+Myanmar MM
+Namibia NA
+Nauru NR
+Nepal NP
+Netherlands NL
+Netherlands Antilles AN
+New Caledonia NC
+New Zealand NZ
+Nicaragua NI
+Niger NE
+Nigeria NG
+Niue NU
+Norfolk Island NF
+Northern Mariana Islands MP
+Norway NO
+Oman OM
+Pakistan PK
+Palau PW
+Palestinian Territory PS
+Panama PA
+Papua New Guinea PG
+Paraguay PY
+Peoples Republic Of Congo CG
+Peru PE
+Philippines PH
+Pitcairn PN
+Poland PL
+Portugal PT
+Puerto Rico PR
+Qatar QA
+Republic Of Korea KR
+Reunion RE
+Romania RO
+Russian Federation RU
+Rwanda RW
+Saint Kitts And Nevis KN
+Samoa WS
+San Marino SM
+Sao Tome And Principe ST
+Saudi Arabia SA
+Senegal SN
+Serbia And Montenegro CS
+Seychelles SC
+Sierra Leone SL
+Singapore SG
+Slovakia SK
+Slovenia SI
+Solomon Islands SB
+Somalia SO
+South Africa ZA
+South Georgia And The South Sandwich Islands GS
+Spain ES
+Sri Lanka LK
+St Helena SH
+St Lucia LC
+St Pierre And Miquelon PM
+St Vincent And The Grenadines VC
+Sudan SD
+Suriname SR
+Svalbard And Jan Mayen Islands SJ
+Swaziland SZ
+Sweden SE
+Switzerland CH
+Syrian Arab Republic SY
+Taiwan TW
+Tajikistan TJ
+Tanzania TZ
+Thailand TH
+Togo TG
+Tokelau TK
+Tonga TO
+Trinidad And Tobago TT
+Tunisia TN
+Turkey TR
+Turkmenistan TM
+Turks And Caicos Islands TC
+Tuvalu TV
+US Virgin Islands VI
+Uganda UG
+Ukraine UA
+United Arab Emirates AE
+United Kingdom GB
+United States US
+United States Minor Outlying Islands UM
+Uruguay UY
+Uzbekistan UZ
+Vanuatu VU
+Vatican City State VA
+Venezuela VE
+Viet Nam VN
+Wallis And Futuna Islands WF
+Western Sahara EH
+Yemen YE
+Yugoslavia YU
+Zambia ZM
+Zimbabwe ZW
diff --git a/examples/tools/completer/resources/wordlist.txt b/examples/tools/completer/resources/wordlist.txt
new file mode 100644
index 0000000000..e598a19b59
--- /dev/null
+++ b/examples/tools/completer/resources/wordlist.txt
@@ -0,0 +1,1486 @@
+A4
+able
+about
+above
+absence
+absolutely
+abstract
+access
+according
+accumulated
+achieve
+achieving
+activity
+acts
+actual
+actually
+add
+added
+adding
+addition
+additionally
+additions
+addresses
+adjust
+adjustments
+advanced
+advice
+after
+afterwards
+again
+agenda
+aim
+algorithm
+all
+allocated
+allow
+allowed
+allowing
+allows
+along
+alpha
+already
+also
+alternative
+alternatively
+although
+American
+an
+and
+announced
+annoy
+another
+answer
+answers
+any
+anything
+anyway
+apart
+API
+appear
+appears
+appendices
+appendix
+appends
+application
+applications
+apply
+approach
+approaches
+appropriate
+Arabic
+arbitrary
+are
+areas
+ARGB
+argument
+arguments
+around
+arrangements
+arrive
+arrived
+Arthur
+article
+articles
+as
+asked
+aspects
+assume
+at
+attachment
+attempt
+attempting
+attend
+attendees
+attributes
+authors
+auto-detect
+auto-detecting
+availability
+available
+avoid
+away
+back
+background
+backgrounds
+bandwidth
+bandwidths
+Barcelona
+base
+based
+basic
+basically
+basics
+be
+because
+been
+before
+behave
+behavior
+behind
+being
+below
+benefits
+Berkeley
+between
+bit
+bits
+bitwise
+black
+blended
+blending
+blends
+block
+blue
+BMP
+body
+bold
+booking
+bool
+Boston
+both
+bottom
+box
+boxes
+braces
+break
+breaks
+broad
+browsers
+buffer
+buffers
+build
+builds
+built
+bundled
+burdens
+busy
+but
+by
+bypass
+bypassing
+bytes
+calendar
+call
+called
+calling
+calls
+Cambridge
+can
+canonical
+canonicalised
+cap
+capabilities
+capacity
+caption
+card
+care
+case
+cast
+catch
+causing
+centre
+certain
+challenges
+chance
+change
+changes
+changing
+channel
+channels
+chapter
+char
+chart
+charts
+check
+checks
+Chicago
+chit-chat
+chosen
+chunk
+circle
+citation
+city
+claim
+class
+classes
+clause
+clauses
+clear
+clearing
+client
+clients
+close
+closed
+co-author
+code
+colon
+color
+color-coded
+colorize
+colorizer
+colors
+colour
+column
+columns
+combine
+combined
+combines
+combining
+comes
+command
+commands
+comment
+common
+communicate
+community
+compiled
+complement
+complete
+completely
+completeness
+completes
+completion
+complex
+compliant
+component
+components
+compositing
+composition
+compression
+computation
+computer
+concepts
+conclusion
+concurrent
+configurable
+congested
+congestion
+connect
+connected
+connection
+connections
+cons
+consider
+consisting
+consists
+construct
+constructed
+constructing
+constructor
+constructs
+consume
+contact
+contain
+containing
+contains
+contents
+contents
+continue
+continued
+contributors
+control
+controlled
+controller
+controller
+controlling
+controls
+controls
+conventions
+cook
+cooperation
+copy
+copyright
+core
+cores
+corollary
+correct
+correctly
+corresponding
+could
+couple
+coworkers
+CPU
+create
+creates
+creating
+cross-platform
+crucial
+cultures
+current
+currently
+custom
+customized
+cut
+data
+database
+datasets
+datum
+day
+days
+deal
+dealing
+decide
+decouple
+decoupled
+deeply
+def
+default
+define
+defines
+definition
+definitions
+delegate
+delete
+demo
+demonstrate
+demonstrations
+deployed
+describe
+describes
+design
+desktop
+desktops
+destination
+destinations
+destructor
+details
+detect
+determine
+determines
+developer
+developers
+development
+developments
+device
+devices
+diagram
+dialogs
+dictionary
+did
+difference
+differences
+different
+differs
+digital
+direct
+direct
+directions
+directly
+directory
+discuss
+display
+displaying
+displays
+distribute
+distribution
+disturbing
+divide
+do
+documentation
+documents
+does
+done
+down
+downLimit
+download
+downloaded
+downloading
+draw
+drawing
+drawn
+drop
+drop-in
+Duff
+during
+DVD
+dynamic
+dynamically
+dynamics
+each
+earlier
+easily
+editing
+editors
+education
+effect
+effectively
+effects
+either
+ellipse
+ellipses
+elliptical
+else
+email
+e-mail
+embedded
+emit
+emits
+empty
+enable
+enables
+encapsulates
+enclose
+end
+endnote
+endnotes
+end-user
+engineer
+engineering
+English
+enjoys
+enough
+ensure
+ensures
+entails
+enter
+entire
+entitled
+entries
+entry
+environment
+erases
+error
+errors
+especially
+established
+etc.
+Europe
+even
+evenly
+event
+events
+eventually
+every
+everyone
+example
+examples
+except
+exception
+excessive
+exclusive
+existing
+exists
+expand
+expected
+expense
+export
+exposes
+extend
+extended
+extending
+extensible
+extension
+external
+extra
+extract
+faces
+facilities
+factory
+fade
+failure
+fairness
+falls
+false
+family
+fashion
+fast
+faster
+features
+February
+feedback
+feel
+fetch
+fetching
+few
+fields
+figure
+figures
+file
+file name
+files
+filled
+filler
+final
+finally
+find
+fine
+finish
+finished
+first
+flow
+fly
+focus
+followed
+following
+font
+foot
+footnote
+footnotes
+for
+form
+format
+formats
+format-specific
+forms
+formula
+formulas
+forum
+found
+framework
+France
+from
+front
+full
+fully
+function
+functionality
+function-based
+functions
+future
+gain
+games
+gap
+general
+generic
+Germany
+get
+gill
+give
+given
+gives
+giving
+global
+go
+goes
+got
+gradient
+gradient-filled
+graph
+graphical
+graphics
+gray
+great
+greatly
+green
+grey
+group
+growing
+gui
+GUI
+hack
+had
+half
+Hamburg
+hand
+handing
+handle
+handler
+handlers
+handles
+handling
+happens
+hardware
+harmonica
+has
+have
+having
+he
+head
+header
+headers
+hear
+height
+help
+helper
+here
+high
+high-complexity
+high-level
+highlight
+highly
+hints
+his
+hold
+holder
+holding
+hole
+home
+horizontal
+host
+hosting
+hours
+Houston
+how
+however
+huge
+hyphen
+ID
+idea
+ideally
+if
+Illinois
+illustrate
+illustrated
+illustrates
+image
+images
+impact
+implement
+implementation
+implementations
+implemented
+implementing
+implements
+import
+important
+improvements
+in
+include
+included
+includes
+including
+inclusion
+incoming
+inconvenient
+indent
+index
+indicate
+inexpensively
+influence
+info
+information
+ingenious
+inherits
+initial
+initially
+inner
+input
+inspired
+install
+installs
+instance
+instead
+instructs
+integer
+integers
+integration
+intended
+intensive
+interest
+interests
+interface
+interfaces
+interfere
+internal
+interval
+into
+intriguing
+intro
+introduce
+introduced
+invalid
+invented
+inverse
+invocation
+involved
+Irish
+irregular
+is
+ISO
+ISPs
+issue
+issues
+it
+items
+iterate
+its
+itself
+job
+join
+JPEG
+jungle
+just
+Karaoke
+keep
+keeping
+key
+kind
+king
+known
+label
+labels
+landscape
+language
+large
+last
+later
+latest
+lawn
+layout
+lead
+leader
+leaders
+lean
+leaves
+leaving
+left
+lemma
+length
+less
+let
+level
+levels
+libraries
+library
+lies
+like
+likely
+limit
+limiting
+limits
+line
+linear
+lines
+linewidth
+link
+linked
+linking
+Linux
+list
+lists
+little
+lives
+load
+loading
+loads
+located
+location
+locations
+logo
+long
+longer
+look
+looked
+looking
+looks
+lookup
+lookups
+loop
+lout
+low
+lower-case
+low-level
+macro
+made
+magazine
+magic
+main
+major
+make
+makes
+making
+manage
+managed
+managing
+mandatory
+manipulate
+manipulation
+manner
+many
+map
+maps
+March
+margin
+mask
+masking
+Massachusetts
+match
+mathematical
+maximum
+may
+means
+meet
+member
+members
+memory
+merged
+method
+might
+milliseconds
+minimize
+minimum
+minor
+mix
+MNG
+mode
+model
+models
+modes
+modified
+module
+moments
+monitored
+monthly
+more
+most
+mostly
+move
+much
+multitude
+Munich
+must
+name
+named
+names
+necessary
+need
+needed
+needs
+network
+new
+news
+newsletter
+next
+nicely
+no
+none
+non-Qt
+non-trivial
+non-zero
+normally
+Norway
+not
+note
+notes
+nothing
+notifies
+notify
+now
+null
+number
+numbered
+numbering
+numbers
+Nydalen
+object
+objects
+obtain
+obtaining
+odd
+of
+off
+office
+offset
+offsets
+often
+old
+on
+once
+one
+ones
+online
+only
+on-screen
+onto
+opacity
+opaque
+open
+opens
+operates
+operating
+operation
+operations
+operator
+opportunity
+opposed
+optimize
+option
+optionally
+options
+or
+OR
+order
+ordinary
+original
+originally
+Oslo
+other
+otherwise
+our
+out
+outer
+outgoing
+output
+outside
+over
+overcoming
+overrides
+overview
+own
+owner
+owners
+pace
+Pacific
+package
+packages
+packets
+page
+pages
+paint
+painted
+painting
+paragraph
+paragraphs
+parameters
+parent
+Paris
+parse
+part
+partial
+partially
+particular
+partners
+parts
+party
+passed
+passing
+patches
+path
+pattern
+patterns
+pause
+PDF
+peek
+pending
+perform
+performed
+performs
+permission
+permutations
+personal
+pick
+pie
+pipe
+pixel
+pixels
+place
+places
+planning
+platform-independent
+platforms
+play
+players
+playing
+please
+pleasing
+plugin
+plugin-enabled
+plugins
+plus
+PNG
+pointer
+pop
+popular
+populates
+porter
+Porter
+portrait
+possibility
+possible
+potential
+potentially
+power
+powers
+preceded
+presence
+present
+prevent
+prevents
+previous
+previously
+primarily
+primary
+primitives
+printed
+printing
+prior
+probably
+problem
+process
+processes
+processing
+produce
+produced
+produces
+products
+programming
+programs
+project
+projects
+proof
+proper
+properly
+properties
+property
+proposed
+proposition
+pros
+protocols
+proud
+provide
+provided
+provides
+provision
+proxy
+public
+published
+punch
+punches
+pursuing
+put
+Qt
+Qtopia
+Qt-related
+quality
+quarter
+quarterly
+queried
+queries
+query
+question
+questions
+radial
+ragged
+range
+rate
+rate-controlled
+rates
+rather
+ratio
+raw
+read
+reader
+reading
+reads
+ready
+real
+realistic
+really
+real-time
+received
+recent
+recognized
+recommended
+recompile
+rectangle
+rectangular
+red
+redistribute
+reducing
+reference
+references
+reflect
+regardless
+regional
+register
+registered
+registration
+reimplement
+reimplementation
+reimplemented
+release
+released
+releases
+reliable
+rely
+remains
+remember
+removed
+removes
+repeatedly
+replace
+report
+represent
+represented
+represents
+reproduced
+requested
+require
+required
+requires
+resetting
+resides
+resolve
+respective
+respectively
+response
+rest
+restart
+result
+resulting
+resume
+return
+returning
+returns
+reuse
+revealing
+rich
+riches
+right
+roadshow
+role
+Roman
+round-trip
+router
+routers
+rule
+run
+runner
+runners
+running
+runs
+run-time
+sake
+sales
+salespeople
+same
+sample
+San Jose
+save
+saved
+saves
+say
+scalable
+scale
+scanline
+scanline-level
+scene
+scenes
+schedule
+school
+script
+seam
+seamless
+search
+searches
+searching
+second
+seconds
+section
+sections
+security
+see
+seen
+selection
+seminar
+seminars
+sending
+separated
+separates
+series
+service
+services
+set
+setting
+setup
+seven
+seventh
+several
+shade
+shadow
+shape
+shares
+shaves
+shine
+shorter
+should
+show
+shown
+shows
+side
+signal
+signals
+signature
+significantly
+similar
+similarily
+similarly
+simple
+simplest
+simplified
+simplifying
+simply
+simulate
+simultaneous
+since
+single
+size
+sizes
+slightly
+slope
+slot
+slowing
+small
+smaller
+so
+socket
+sockets
+software
+solutions
+solved
+some
+soon
+sort
+sorting
+source
+sources
+south
+space
+special
+specialized
+specific
+specifically
+specification
+specifications
+specified
+specify
+speed
+spend
+split
+SQL
+standard
+standards
+start
+starts
+starve
+state
+states
+static
+steady
+stealing
+step
+still
+stop
+stopwatch
+store
+stored
+stores
+straightforward
+stream
+string
+strings
+structure
+structured
+strut
+style
+styles
+styling
+subclass
+subclassing
+subdirectory
+subsection
+subsections
+succeeds
+success
+successful
+successfully
+such
+suggestion
+suggestions
+suitable
+support
+supported
+supports
+suppose
+supposes
+sure
+switch
+switches
+symbol
+symbols
+synonyms
+system
+systems
+table
+tables
+tags
+take
+takes
+tap
+target
+targets
+TCP
+team
+technically-focused
+technique
+technology
+template
+templates
+Texas
+text
+than
+that
+the
+their
+them
+then
+theorem
+there
+these
+they
+thickness
+thin
+third
+this
+those
+three
+throttling
+through
+tightly
+time
+timer
+times
+tiny
+tips
+title
+titles
+to
+together
+too
+top
+torrent
+total
+tour
+trademarks
+traffic
+training
+transaction
+transfer
+transferred
+transferring
+transfers
+translucency
+translucent
+transparency
+transparent
+travel
+traveled
+Trolltech
+true
+try
+turn
+twice
+two
+type
+typed
+typical
+typically
+unable
+under
+underlying
+understanding
+undoes
+unique
+united
+unlike
+unpack
+unsigned
+until
+untouched
+up
+update
+updated
+updates
+upload
+uploading
+uploads
+up-to-date
+us
+use
+used
+useful
+user
+user-friendly
+users
+uses
+using
+usual
+usually
+valid
+value
+values
+variable
+variation
+variety
+various
+vector
+venturing
+verifying
+versa
+version
+versions
+vertical
+very
+via
+vice
+virtual
+visual
+void
+VP
+waiting
+Wales
+want
+wants
+was
+way
+ways
+we
+web
+website
+well
+were
+what
+when
+whenever
+where
+whether
+which
+while
+whistle
+white
+who
+whole
+why
+widget
+widgets
+width
+widths
+will
+window
+windows
+wish
+with
+without
+word
+words
+work
+working
+works
+would
+wrap
+wrapper
+write
+writes
+writing
+writings
+written
+X
+X11
+XOR
+year
+years
+yes
+you
+your
+zero
diff --git a/examples/tools/customcompleter/customcompleter.pro b/examples/tools/customcompleter/customcompleter.pro
new file mode 100644
index 0000000000..8a11cf15d7
--- /dev/null
+++ b/examples/tools/customcompleter/customcompleter.pro
@@ -0,0 +1,14 @@
+HEADERS = mainwindow.h \
+ textedit.h
+SOURCES = main.cpp \
+ mainwindow.cpp \
+ textedit.cpp
+RESOURCES = customcompleter.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/tools/customcompleter
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS customcompleter.pro resources
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/customcompleter
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/tools/customcompleter/customcompleter.qrc b/examples/tools/customcompleter/customcompleter.qrc
new file mode 100644
index 0000000000..d7da1bf9a6
--- /dev/null
+++ b/examples/tools/customcompleter/customcompleter.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/">
+ <file>resources/wordlist.txt</file>
+</qresource>
+</RCC>
diff --git a/examples/tools/customcompleter/main.cpp b/examples/tools/customcompleter/main.cpp
new file mode 100644
index 0000000000..8e64f6cea1
--- /dev/null
+++ b/examples/tools/customcompleter/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "mainwindow.h"
+
+//! [0]
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(customcompleter);
+
+ QApplication app(argc, argv);
+ MainWindow window;
+ window.show();
+ return app.exec();
+}
+//! [0]
diff --git a/examples/tools/customcompleter/mainwindow.cpp b/examples/tools/customcompleter/mainwindow.cpp
new file mode 100644
index 0000000000..8d75ddd7bd
--- /dev/null
+++ b/examples/tools/customcompleter/mainwindow.cpp
@@ -0,0 +1,118 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "mainwindow.h"
+#include "textedit.h"
+
+//! [0]
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent), completer(0)
+{
+ createMenu();
+
+ completingTextEdit = new TextEdit;
+ completer = new QCompleter(this);
+ completer->setModel(modelFromFile(":/resources/wordlist.txt"));
+ completer->setModelSorting(QCompleter::CaseInsensitivelySortedModel);
+ completer->setCaseSensitivity(Qt::CaseInsensitive);
+ completer->setWrapAround(false);
+ completingTextEdit->setCompleter(completer);
+
+ setCentralWidget(completingTextEdit);
+ resize(500, 300);
+ setWindowTitle(tr("Completer"));
+}
+//! [0]
+
+//! [1]
+void MainWindow::createMenu()
+{
+ QAction *exitAction = new QAction(tr("Exit"), this);
+ QAction *aboutAct = new QAction(tr("About"), this);
+ QAction *aboutQtAct = new QAction(tr("About Qt"), this);
+
+ connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
+ connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+ connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+
+ QMenu* fileMenu = menuBar()->addMenu(tr("File"));
+ fileMenu->addAction(exitAction);
+
+ QMenu* helpMenu = menuBar()->addMenu(tr("About"));
+ helpMenu->addAction(aboutAct);
+ helpMenu->addAction(aboutQtAct);
+}
+//! [1]
+
+//! [2]
+QAbstractItemModel *MainWindow::modelFromFile(const QString& fileName)
+{
+ QFile file(fileName);
+ if (!file.open(QFile::ReadOnly))
+ return new QStringListModel(completer);
+
+#ifndef QT_NO_CURSOR
+ QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
+#endif
+ QStringList words;
+
+ while (!file.atEnd()) {
+ QByteArray line = file.readLine();
+ if (!line.isEmpty())
+ words << line.trimmed();
+ }
+
+#ifndef QT_NO_CURSOR
+ QApplication::restoreOverrideCursor();
+#endif
+ return new QStringListModel(words, completer);
+}
+//! [2]
+
+//! [3]
+void MainWindow::about()
+{
+ QMessageBox::about(this, tr("About"), tr("This example demonstrates the "
+ "different features of the QCompleter class."));
+}
+//! [3]
+
diff --git a/examples/tools/customcompleter/mainwindow.h b/examples/tools/customcompleter/mainwindow.h
new file mode 100644
index 0000000000..77089c265b
--- /dev/null
+++ b/examples/tools/customcompleter/mainwindow.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+QT_BEGIN_NAMESPACE
+class QAbstractItemModel;
+class QComboBox;
+class QCompleter;
+class QLabel;
+class QLineEdit;
+class QProgressBar;
+QT_END_NAMESPACE
+class TextEdit;
+
+//! [0]
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow(QWidget *parent = 0);
+
+private slots:
+ void about();
+
+private:
+ void createMenu();
+ QAbstractItemModel *modelFromFile(const QString& fileName);
+
+ QCompleter *completer;
+ TextEdit *completingTextEdit;
+};
+//! [0]
+
+#endif // MAINWINDOW_H
diff --git a/examples/tools/customcompleter/resources/wordlist.txt b/examples/tools/customcompleter/resources/wordlist.txt
new file mode 100644
index 0000000000..a5de826396
--- /dev/null
+++ b/examples/tools/customcompleter/resources/wordlist.txt
@@ -0,0 +1,1455 @@
+A4
+able
+about
+above
+absence
+absolutely
+abstract
+access
+according
+accumulated
+achieve
+achieving
+activity
+acts
+actual
+actually
+add
+added
+adding
+addition
+additionally
+additions
+addresses
+adjust
+adjustments
+advanced
+advice
+after
+afterwards
+again
+agenda
+aim
+algorithm
+all
+allocated
+allow
+allowed
+allowing
+allows
+along
+alpha
+already
+also
+alternative
+alternatively
+although
+American
+an
+and
+announced
+annoy
+another
+answer
+answers
+any
+anything
+anyway
+apart
+API
+appear
+appears
+appendices
+appendix
+appends
+application
+applications
+apply
+approach
+approaches
+appropriate
+Arabic
+arbitrary
+are
+areas
+ARGB
+argument
+arguments
+around
+arrangements
+arrive
+arrived
+Arthur
+article
+articles
+as
+asked
+aspects
+assume
+at
+attachment
+attempt
+attempting
+attend
+attendees
+attributes
+authors
+availability
+available
+avoid
+away
+back
+background
+backgrounds
+bandwidth
+bandwidths
+Barcelona
+base
+based
+basic
+basically
+basics
+be
+because
+been
+before
+behave
+behavior
+behind
+being
+below
+benefits
+Berkeley
+between
+bit
+bits
+bitwise
+black
+blended
+blending
+blends
+block
+blue
+BMP
+body
+bold
+booking
+bool
+Boston
+both
+bottom
+box
+boxes
+braces
+break
+breaks
+broad
+browsers
+buffer
+buffers
+build
+builds
+built
+bundled
+burdens
+busy
+but
+by
+bypass
+bypassing
+bytes
+calendar
+call
+called
+calling
+calls
+Cambridge
+can
+canonical
+canonicalised
+cap
+capabilities
+capacity
+caption
+card
+care
+case
+cast
+catch
+causing
+centre
+certain
+challenges
+chance
+change
+changes
+changing
+channel
+channels
+chapter
+char
+chart
+charts
+check
+checks
+Chicago
+chosen
+chunk
+circle
+citation
+city
+claim
+class
+classes
+clause
+clauses
+clear
+clearing
+client
+clients
+close
+closed
+code
+colon
+color
+colorize
+colorizer
+colors
+colour
+column
+columns
+combine
+combined
+combines
+combining
+comes
+command
+commands
+comment
+common
+communicate
+community
+compiled
+complement
+complete
+completely
+completeness
+completes
+completion
+complex
+compliant
+component
+components
+compositing
+composition
+compression
+computation
+computer
+concepts
+conclusion
+concurrent
+configurable
+congested
+congestion
+connect
+connected
+connection
+connections
+cons
+consider
+consisting
+consists
+construct
+constructed
+constructing
+constructor
+constructs
+consume
+contact
+contain
+containing
+contains
+contents
+contents
+continue
+continued
+contributors
+control
+controlled
+controller
+controller
+controlling
+controls
+controls
+conventions
+cook
+cooperation
+copy
+copyright
+core
+cores
+corollary
+correct
+correctly
+corresponding
+could
+couple
+coworkers
+CPU
+create
+creates
+creating
+crucial
+cultures
+current
+currently
+custom
+customized
+cut
+data
+database
+datasets
+datum
+day
+days
+deal
+dealing
+decide
+decouple
+decoupled
+deeply
+def
+default
+define
+defines
+definition
+definitions
+delegate
+delete
+demo
+demonstrate
+demonstrations
+deployed
+describe
+describes
+design
+desktop
+desktops
+destination
+destinations
+destructor
+details
+detect
+determine
+determines
+developer
+developers
+development
+developments
+device
+devices
+diagram
+dialogs
+dictionary
+did
+difference
+differences
+different
+differs
+digital
+direct
+direct
+directions
+directly
+directory
+discuss
+display
+displaying
+displays
+distribute
+distribution
+disturbing
+divide
+do
+documentation
+documents
+does
+done
+down
+downLimit
+download
+downloaded
+downloading
+draw
+drawing
+drawn
+drop
+Duff
+during
+DVD
+dynamic
+dynamically
+dynamics
+each
+earlier
+easily
+editing
+editors
+education
+effect
+effectively
+effects
+either
+ellipse
+ellipses
+elliptical
+else
+email
+embedded
+emit
+emits
+empty
+enable
+enables
+encapsulates
+enclose
+end
+endnote
+endnotes
+engineer
+engineering
+English
+enjoys
+enough
+ensure
+ensures
+entails
+enter
+entire
+entitled
+entries
+entry
+environment
+erases
+error
+errors
+especially
+established
+etc.
+Europe
+even
+evenly
+event
+events
+eventually
+every
+everyone
+example
+examples
+except
+exception
+excessive
+exclusive
+existing
+exists
+expand
+expected
+expense
+export
+exposes
+extend
+extended
+extending
+extensible
+extension
+external
+extra
+extract
+faces
+facilities
+factory
+fade
+failure
+fairness
+falls
+false
+family
+fashion
+fast
+faster
+features
+February
+feedback
+feel
+fetch
+fetching
+few
+fields
+figure
+figures
+file
+file name
+files
+filled
+filler
+final
+finally
+find
+fine
+finish
+finished
+first
+flow
+fly
+focus
+followed
+following
+font
+foot
+footnote
+footnotes
+for
+form
+format
+formats
+forms
+formula
+formulas
+forum
+found
+framework
+France
+from
+front
+full
+fully
+function
+functionality
+functions
+future
+gain
+games
+gap
+general
+generic
+Germany
+get
+gill
+give
+given
+gives
+giving
+global
+go
+goes
+got
+gradient
+graph
+graphical
+graphics
+gray
+great
+greatly
+green
+grey
+group
+growing
+gui
+GUI
+hack
+had
+half
+Hamburg
+hand
+handing
+handle
+handler
+handlers
+handles
+handling
+happens
+hardware
+harmonica
+has
+have
+having
+he
+head
+header
+headers
+hear
+height
+help
+helper
+here
+high
+highlight
+highly
+hints
+his
+hold
+holder
+holding
+hole
+home
+horizontal
+host
+hosting
+hours
+Houston
+how
+however
+huge
+hyphen
+ID
+idea
+ideally
+if
+Illinois
+illustrate
+illustrated
+illustrates
+image
+images
+impact
+implement
+implementation
+implementations
+implemented
+implementing
+implements
+import
+important
+improvements
+in
+include
+included
+includes
+including
+inclusion
+incoming
+inconvenient
+indent
+index
+indicate
+inexpensively
+influence
+info
+information
+ingenious
+inherits
+initial
+initially
+inner
+input
+inspired
+install
+installs
+instance
+instead
+instructs
+integer
+integers
+integration
+intended
+intensive
+interest
+interests
+interface
+interfaces
+interfere
+internal
+interval
+into
+intriguing
+intro
+introduce
+introduced
+invalid
+invented
+inverse
+invocation
+involved
+Irish
+irregular
+is
+ISO
+ISPs
+issue
+issues
+it
+items
+iterate
+its
+itself
+job
+join
+JPEG
+jungle
+just
+Karaoke
+keep
+keeping
+key
+kind
+king
+known
+label
+labels
+landscape
+language
+large
+last
+later
+latest
+lawn
+layout
+lead
+leader
+leaders
+lean
+leaves
+leaving
+left
+lemma
+length
+less
+let
+level
+levels
+libraries
+library
+lies
+like
+likely
+limit
+limiting
+limits
+line
+linear
+lines
+linewidth
+link
+linked
+linking
+Linux
+list
+lists
+little
+lives
+load
+loading
+loads
+located
+location
+locations
+logo
+long
+longer
+look
+looked
+looking
+looks
+lookup
+lookups
+loop
+lout
+low
+macro
+made
+magazine
+magic
+main
+major
+make
+makes
+making
+manage
+managed
+managing
+mandatory
+manipulate
+manipulation
+manner
+many
+map
+maps
+March
+margin
+mask
+masking
+Massachusetts
+match
+mathematical
+maximum
+may
+means
+meet
+member
+members
+memory
+merged
+method
+might
+milliseconds
+minimize
+minimum
+minor
+mix
+MNG
+mode
+model
+models
+modes
+modified
+module
+moments
+monitored
+monthly
+more
+most
+mostly
+move
+much
+multitude
+Munich
+must
+name
+named
+names
+necessary
+need
+needed
+needs
+network
+new
+news
+newsletter
+next
+nicely
+no
+none
+normally
+Norway
+not
+note
+notes
+nothing
+notifies
+notify
+now
+null
+number
+numbered
+numbering
+numbers
+Nydalen
+object
+objects
+obtain
+obtaining
+odd
+of
+off
+office
+offset
+offsets
+often
+old
+on
+once
+one
+ones
+online
+only
+onto
+opacity
+opaque
+open
+opens
+operates
+operating
+operation
+operations
+operator
+opportunity
+opposed
+optimize
+option
+optionally
+options
+or
+OR
+order
+ordinary
+original
+originally
+Oslo
+other
+otherwise
+our
+out
+outer
+outgoing
+output
+outside
+over
+overcoming
+overrides
+overview
+own
+owner
+owners
+pace
+Pacific
+package
+packages
+packets
+page
+pages
+paint
+painted
+painting
+paragraph
+paragraphs
+parameters
+parent
+Paris
+parse
+part
+partial
+partially
+particular
+partners
+parts
+party
+passed
+passing
+patches
+path
+pattern
+patterns
+pause
+PDF
+peek
+pending
+perform
+performed
+performs
+permission
+permutations
+personal
+pick
+pie
+pipe
+pixel
+pixels
+place
+places
+planning
+platforms
+play
+players
+playing
+please
+pleasing
+plugin
+plugins
+plus
+PNG
+pointer
+pop
+popular
+populates
+porter
+Porter
+portrait
+possibility
+possible
+potential
+potentially
+power
+powers
+preceded
+presence
+present
+prevent
+prevents
+previous
+previously
+primarily
+primary
+primitives
+printed
+printing
+prior
+probably
+problem
+process
+processes
+processing
+produce
+produced
+produces
+products
+programming
+programs
+project
+projects
+proof
+proper
+properly
+properties
+property
+proposed
+proposition
+pros
+protocols
+proud
+provide
+provided
+provides
+provision
+proxy
+public
+published
+punch
+punches
+pursuing
+put
+Qt
+Qtopia
+quality
+quarter
+quarterly
+queried
+queries
+query
+question
+questions
+radial
+ragged
+range
+rate
+rates
+rather
+ratio
+raw
+read
+reader
+reading
+reads
+ready
+real
+realistic
+really
+received
+recent
+recognized
+recommended
+recompile
+rectangle
+rectangular
+red
+redistribute
+reducing
+reference
+references
+reflect
+regardless
+regional
+register
+registered
+registration
+reimplement
+reimplementation
+reimplemented
+release
+released
+releases
+reliable
+rely
+remains
+remember
+removed
+removes
+repeatedly
+replace
+report
+represent
+represented
+represents
+reproduced
+requested
+require
+required
+requires
+resetting
+resides
+resolve
+respective
+respectively
+response
+rest
+restart
+result
+resulting
+resume
+return
+returning
+returns
+reuse
+revealing
+rich
+riches
+right
+roadshow
+role
+Roman
+router
+routers
+rule
+run
+runner
+runners
+running
+runs
+sake
+sales
+salespeople
+same
+sample
+San Jose
+save
+saved
+saves
+say
+scalable
+scale
+scanline
+scene
+scenes
+schedule
+school
+script
+seam
+seamless
+search
+searches
+searching
+second
+seconds
+section
+sections
+security
+see
+seen
+selection
+seminar
+seminars
+sending
+separated
+separates
+series
+service
+services
+set
+setting
+setup
+seven
+seventh
+several
+shade
+shadow
+shape
+shares
+shaves
+shine
+shorter
+should
+show
+shown
+shows
+side
+signal
+signals
+signature
+significantly
+similar
+similarily
+similarly
+simple
+simplest
+simplified
+simplifying
+simply
+simulate
+simultaneous
+since
+single
+size
+sizes
+slightly
+slope
+slot
+slowing
+small
+smaller
+so
+socket
+sockets
+software
+solutions
+solved
+some
+soon
+sort
+sorting
+source
+sources
+south
+space
+special
+specialized
+specific
+specifically
+specification
+specifications
+specified
+specify
+speed
+spend
+split
+SQL
+standard
+standards
+start
+starts
+starve
+state
+states
+static
+steady
+stealing
+step
+still
+stop
+stopwatch
+store
+stored
+stores
+straightforward
+stream
+string
+strings
+structure
+structured
+strut
+style
+styles
+styling
+subclass
+subclassing
+subdirectory
+subsection
+subsections
+succeeds
+success
+successful
+successfully
+such
+suggestion
+suggestions
+suitable
+support
+supported
+supports
+suppose
+supposes
+sure
+switch
+switches
+symbol
+symbols
+synonyms
+system
+systems
+table
+tables
+tags
+take
+takes
+tap
+target
+targets
+TCP
+team
+technique
+technology
+template
+templates
+Texas
+text
+than
+that
+the
+their
+them
+then
+theorem
+there
+these
+they
+thickness
+thin
+third
+this
+those
+three
+throttling
+through
+tightly
+time
+timer
+times
+tiny
+tips
+title
+titles
+to
+together
+too
+top
+torrent
+total
+tour
+trademarks
+traffic
+training
+transaction
+transfer
+transferred
+transferring
+transfers
+translucency
+translucent
+transparency
+transparent
+travel
+traveled
+Trolltech
+true
+try
+turn
+twice
+two
+type
+typed
+typical
+typically
+unable
+under
+underlying
+understanding
+undoes
+unique
+united
+unlike
+unpack
+unsigned
+until
+untouched
+up
+update
+updated
+updates
+upload
+uploading
+uploads
+us
+use
+used
+useful
+user
+users
+uses
+using
+usual
+usually
+valid
+value
+values
+variable
+variation
+variety
+various
+vector
+venturing
+verifying
+versa
+version
+versions
+vertical
+very
+via
+vice
+virtual
+visual
+void
+VP
+waiting
+Wales
+want
+wants
+was
+way
+ways
+we
+web
+website
+well
+were
+what
+when
+whenever
+where
+whether
+which
+while
+whistle
+white
+who
+whole
+why
+widget
+widgets
+width
+widths
+will
+window
+windows
+wish
+with
+without
+word
+words
+work
+working
+works
+would
+wrap
+wrapper
+write
+writes
+writing
+writings
+written
+X
+X11
+XOR
+year
+years
+yes
+you
+your
+zero
diff --git a/examples/tools/customcompleter/textedit.cpp b/examples/tools/customcompleter/textedit.cpp
new file mode 100644
index 0000000000..ecafa8fa22
--- /dev/null
+++ b/examples/tools/customcompleter/textedit.cpp
@@ -0,0 +1,174 @@
+/****************************************************************************
+**
+** 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 "textedit.h"
+#include <QCompleter>
+#include <QKeyEvent>
+#include <QAbstractItemView>
+#include <QtDebug>
+#include <QApplication>
+#include <QModelIndex>
+#include <QAbstractItemModel>
+#include <QScrollBar>
+
+//! [0]
+TextEdit::TextEdit(QWidget *parent)
+: QTextEdit(parent), c(0)
+{
+ setPlainText(tr("This TextEdit provides autocompletions for words that have more than"
+ " 3 characters. You can trigger autocompletion using ") +
+ QKeySequence("Ctrl+E").toString(QKeySequence::NativeText));
+}
+//! [0]
+
+//! [1]
+TextEdit::~TextEdit()
+{
+}
+//! [1]
+
+//! [2]
+void TextEdit::setCompleter(QCompleter *completer)
+{
+ if (c)
+ QObject::disconnect(c, 0, this, 0);
+
+ c = completer;
+
+ if (!c)
+ return;
+
+ c->setWidget(this);
+ c->setCompletionMode(QCompleter::PopupCompletion);
+ c->setCaseSensitivity(Qt::CaseInsensitive);
+ QObject::connect(c, SIGNAL(activated(const QString&)),
+ this, SLOT(insertCompletion(const QString&)));
+}
+//! [2]
+
+//! [3]
+QCompleter *TextEdit::completer() const
+{
+ return c;
+}
+//! [3]
+
+//! [4]
+void TextEdit::insertCompletion(const QString& completion)
+{
+ if (c->widget() != this)
+ return;
+ QTextCursor tc = textCursor();
+ int extra = completion.length() - c->completionPrefix().length();
+ tc.movePosition(QTextCursor::Left);
+ tc.movePosition(QTextCursor::EndOfWord);
+ tc.insertText(completion.right(extra));
+ setTextCursor(tc);
+}
+//! [4]
+
+//! [5]
+QString TextEdit::textUnderCursor() const
+{
+ QTextCursor tc = textCursor();
+ tc.select(QTextCursor::WordUnderCursor);
+ return tc.selectedText();
+}
+//! [5]
+
+//! [6]
+void TextEdit::focusInEvent(QFocusEvent *e)
+{
+ if (c)
+ c->setWidget(this);
+ QTextEdit::focusInEvent(e);
+}
+//! [6]
+
+//! [7]
+void TextEdit::keyPressEvent(QKeyEvent *e)
+{
+ if (c && c->popup()->isVisible()) {
+ // The following keys are forwarded by the completer to the widget
+ switch (e->key()) {
+ case Qt::Key_Enter:
+ case Qt::Key_Return:
+ case Qt::Key_Escape:
+ case Qt::Key_Tab:
+ case Qt::Key_Backtab:
+ e->ignore();
+ return; // let the completer do default behavior
+ default:
+ break;
+ }
+ }
+
+ bool isShortcut = ((e->modifiers() & Qt::ControlModifier) && e->key() == Qt::Key_E); // CTRL+E
+ if (!c || !isShortcut) // dont process the shortcut when we have a completer
+ QTextEdit::keyPressEvent(e);
+//! [7]
+
+//! [8]
+ const bool ctrlOrShift = e->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier);
+ if (!c || (ctrlOrShift && e->text().isEmpty()))
+ return;
+
+ static QString eow("~!@#$%^&*()_+{}|:\"<>?,./;'[]\\-="); // end of word
+ bool hasModifier = (e->modifiers() != Qt::NoModifier) && !ctrlOrShift;
+ QString completionPrefix = textUnderCursor();
+
+ if (!isShortcut && (hasModifier || e->text().isEmpty()|| completionPrefix.length() < 3
+ || eow.contains(e->text().right(1)))) {
+ c->popup()->hide();
+ return;
+ }
+
+ if (completionPrefix != c->completionPrefix()) {
+ c->setCompletionPrefix(completionPrefix);
+ c->popup()->setCurrentIndex(c->completionModel()->index(0, 0));
+ }
+ QRect cr = cursorRect();
+ cr.setWidth(c->popup()->sizeHintForColumn(0)
+ + c->popup()->verticalScrollBar()->sizeHint().width());
+ c->complete(cr); // popup it up!
+}
+//! [8]
+
diff --git a/examples/tools/customcompleter/textedit.h b/examples/tools/customcompleter/textedit.h
new file mode 100644
index 0000000000..d727228050
--- /dev/null
+++ b/examples/tools/customcompleter/textedit.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TEXTEDIT_H
+#define TEXTEDIT_H
+
+#include <QTextEdit>
+
+QT_BEGIN_NAMESPACE
+class QCompleter;
+QT_END_NAMESPACE
+
+//! [0]
+class TextEdit : public QTextEdit
+{
+ Q_OBJECT
+
+public:
+ TextEdit(QWidget *parent = 0);
+ ~TextEdit();
+
+ void setCompleter(QCompleter *c);
+ QCompleter *completer() const;
+
+protected:
+ void keyPressEvent(QKeyEvent *e);
+ void focusInEvent(QFocusEvent *e);
+
+private slots:
+ void insertCompletion(const QString &completion);
+
+private:
+ QString textUnderCursor() const;
+
+private:
+ QCompleter *c;
+};
+//! [0]
+
+#endif // TEXTEDIT_H
+
diff --git a/examples/tools/customtype/customtype.pro b/examples/tools/customtype/customtype.pro
new file mode 100644
index 0000000000..3079964946
--- /dev/null
+++ b/examples/tools/customtype/customtype.pro
@@ -0,0 +1,3 @@
+HEADERS = message.h
+SOURCES = main.cpp \
+ message.cpp
diff --git a/examples/tools/customtype/main.cpp b/examples/tools/customtype/main.cpp
new file mode 100644
index 0000000000..e8f4265e53
--- /dev/null
+++ b/examples/tools/customtype/main.cpp
@@ -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$
+**
+****************************************************************************/
+
+#include <QCoreApplication>
+#include <QVariant>
+#include "message.h"
+
+int main(int argc, char *argv[])
+{
+ QCoreApplication app(argc, argv);
+ QStringList headers;
+ headers << "Subject: Hello World"
+ << "From: qt-info@nokia.com";
+ QString body = "This is a test.\r\n";
+
+//! [printing a custom type]
+ Message message(body, headers);
+ qDebug() << "Original:" << message;
+//! [printing a custom type]
+
+//! [storing a custom value]
+ QVariant stored;
+ stored.setValue(message);
+//! [storing a custom value]
+
+ qDebug() << "Stored:" << stored;
+
+//! [retrieving a custom value]
+ Message retrieved = stored.value<Message>();
+ qDebug() << "Retrieved:" << retrieved;
+ retrieved = qVariantValue<Message>(stored);
+ qDebug() << "Retrieved:" << retrieved;
+//! [retrieving a custom value]
+
+ return 0;
+}
diff --git a/examples/tools/customtype/message.cpp b/examples/tools/customtype/message.cpp
new file mode 100644
index 0000000000..b6fd536dca
--- /dev/null
+++ b/examples/tools/customtype/message.cpp
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** 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 "message.h"
+
+//! [Message class implementation]
+Message::Message()
+{
+}
+
+Message::Message(const Message &other)
+{
+ m_body = other.m_body;
+ m_headers = other.m_headers;
+}
+
+Message::~Message()
+{
+}
+//! [Message class implementation]
+
+Message::Message(const QString &body, const QStringList &headers)
+{
+ m_body = body;
+ m_headers = headers;
+}
+
+//! [custom type streaming operator]
+QDebug &operator<<(QDebug &dbg, const Message &message)
+{
+ QStringList pieces = message.body().split("\r\n", QString::SkipEmptyParts);
+ if (pieces.isEmpty())
+ dbg.nospace() << "Message()";
+ else if (pieces.size() == 1)
+ dbg.nospace() << "Message(" << pieces.first() << ")";
+ else
+ dbg.nospace() << "Message(" << pieces.first() << " ...)";
+ return dbg.maybeSpace();
+}
+//! [custom type streaming operator]
+
+//! [getter functions]
+QString Message::body() const
+{
+ return m_body;
+}
+
+QStringList Message::headers() const
+{
+ return m_headers;
+}
+//! [getter functions]
diff --git a/examples/tools/customtype/message.h b/examples/tools/customtype/message.h
new file mode 100644
index 0000000000..26205572e4
--- /dev/null
+++ b/examples/tools/customtype/message.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MESSAGE_H
+#define MESSAGE_H
+
+#include <QDebug>
+#include <QMetaType>
+#include <QStringList>
+
+//! [custom type definition]
+class Message
+{
+public:
+ Message();
+ Message(const Message &other);
+ ~Message();
+
+ Message(const QString &body, const QStringList &headers);
+
+ QString body() const;
+ QStringList headers() const;
+
+private:
+ QString m_body;
+ QStringList m_headers;
+};
+//! [custom type definition]
+
+//! [custom type meta-type declaration]
+Q_DECLARE_METATYPE(Message);
+//! [custom type meta-type declaration]
+
+//! [custom type streaming operator]
+QDebug &operator<<(QDebug &dbg, const Message &message);
+//! [custom type streaming operator]
+
+#endif
diff --git a/examples/tools/customtypesending/customtypesending.pro b/examples/tools/customtypesending/customtypesending.pro
new file mode 100644
index 0000000000..b8b2aaf5fe
--- /dev/null
+++ b/examples/tools/customtypesending/customtypesending.pro
@@ -0,0 +1,5 @@
+HEADERS = message.h \
+ window.h
+SOURCES = main.cpp \
+ message.cpp \
+ window.cpp
diff --git a/examples/tools/customtypesending/main.cpp b/examples/tools/customtypesending/main.cpp
new file mode 100644
index 0000000000..336f3d8c38
--- /dev/null
+++ b/examples/tools/customtypesending/main.cpp
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "message.h"
+#include "window.h"
+
+//! [main function]
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ Window window1;
+ QStringList headers;
+ headers << "Subject: Hello World"
+ << "From: qt-info@nokia.com";
+ QString body = "This is a test.\r\n";
+ Message message(body, headers);
+ window1.setMessage(message);
+
+ Window window2;
+ QObject::connect(&window1, SIGNAL(messageSent(Message)),
+ &window2, SLOT(setMessage(Message)));
+ QObject::connect(&window2, SIGNAL(messageSent(Message)),
+ &window1, SLOT(setMessage(Message)));
+ window1.show();
+ window2.show();
+ return app.exec();
+}
+//! [main function]
diff --git a/examples/tools/customtypesending/message.cpp b/examples/tools/customtypesending/message.cpp
new file mode 100644
index 0000000000..69928048dd
--- /dev/null
+++ b/examples/tools/customtypesending/message.cpp
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** 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 "message.h"
+
+Message::Message()
+{
+}
+
+Message::Message(const Message &other)
+{
+ m_body = other.m_body;
+ m_headers = other.m_headers;
+}
+
+Message::~Message()
+{
+}
+
+Message::Message(const QString &body, const QStringList &headers)
+{
+ m_body = body;
+ m_headers = headers;
+}
+
+QString Message::body() const
+{
+ return m_body;
+}
+
+QStringList Message::headers() const
+{
+ return m_headers;
+}
diff --git a/examples/tools/customtypesending/message.h b/examples/tools/customtypesending/message.h
new file mode 100644
index 0000000000..55f9568cf8
--- /dev/null
+++ b/examples/tools/customtypesending/message.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** 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 MESSAGE_H
+#define MESSAGE_H
+
+#include <QDebug>
+#include <QMetaType>
+#include <QStringList>
+
+//! [custom type definition]
+class Message
+{
+public:
+ Message();
+ Message(const Message &other);
+ ~Message();
+
+ Message(const QString &body, const QStringList &headers);
+
+ QString body() const;
+ QStringList headers() const;
+
+private:
+ QString m_body;
+ QStringList m_headers;
+};
+//! [custom type definition]
+
+//! [custom type meta-type declaration]
+Q_DECLARE_METATYPE(Message);
+//! [custom type meta-type declaration]
+
+#endif
diff --git a/examples/tools/customtypesending/window.cpp b/examples/tools/customtypesending/window.cpp
new file mode 100644
index 0000000000..be79518362
--- /dev/null
+++ b/examples/tools/customtypesending/window.cpp
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "window.h"
+
+//! [Window constructor]
+Window::Window()
+{
+ editor = new QTextEdit();
+ QPushButton *sendButton = new QPushButton(tr("&Send message"));
+
+ connect(sendButton, SIGNAL(clicked()), this, SLOT(sendMessage()));
+
+ QHBoxLayout *buttonLayout = new QHBoxLayout();
+ buttonLayout->addStretch();
+ buttonLayout->addWidget(sendButton);
+ buttonLayout->addStretch();
+
+ QVBoxLayout *layout = new QVBoxLayout(this);
+ layout->addWidget(editor);
+ layout->addLayout(buttonLayout);
+
+ setWindowTitle(tr("Custom Type Sending"));
+}
+//! [Window constructor]
+
+//! [sending a message]
+void Window::sendMessage()
+{
+ thisMessage = Message(editor->toPlainText(), thisMessage.headers());
+ emit messageSent(thisMessage);
+}
+//! [sending a message]
+
+//! [receiving a message]
+void Window::setMessage(const Message &message)
+{
+ thisMessage = message;
+ editor->setPlainText(thisMessage.body());
+}
+//! [receiving a message]
diff --git a/examples/tools/customtypesending/window.h b/examples/tools/customtypesending/window.h
new file mode 100644
index 0000000000..cbe9775eb0
--- /dev/null
+++ b/examples/tools/customtypesending/window.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 WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+#include "message.h"
+
+class QTextEdit;
+
+//! [Window class definition]
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Window();
+
+signals:
+ void messageSent(const Message &message);
+
+public slots:
+ void setMessage(const Message &message);
+
+private slots:
+ void sendMessage();
+
+private:
+ Message thisMessage;
+ QTextEdit *editor;
+};
+//! [Window class definition]
+
+#endif
diff --git a/examples/tools/echoplugin/echoplugin.pro b/examples/tools/echoplugin/echoplugin.pro
new file mode 100644
index 0000000000..6146b4901f
--- /dev/null
+++ b/examples/tools/echoplugin/echoplugin.pro
@@ -0,0 +1,13 @@
+#! [0]
+TEMPLATE = subdirs
+SUBDIRS = echowindow \
+ plugin
+#! [0]
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/tools/echoplugin
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS echoplugin.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/echoplugin
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/tools/echoplugin/echowindow/echointerface.h b/examples/tools/echoplugin/echowindow/echointerface.h
new file mode 100644
index 0000000000..d4aecd2efa
--- /dev/null
+++ b/examples/tools/echoplugin/echowindow/echointerface.h
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** 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 ECHOINTERFACE_H
+#define ECHOINTERFACE_H
+
+#include <QString>
+
+//! [0]
+class EchoInterface
+{
+public:
+ virtual ~EchoInterface() {}
+ virtual QString echo(const QString &message) = 0;
+};
+
+
+QT_BEGIN_NAMESPACE
+Q_DECLARE_INTERFACE(EchoInterface,
+ "com.trolltech.Plugin.EchoInterface/1.0");
+QT_END_NAMESPACE
+
+//! [0]
+#endif
diff --git a/examples/tools/echoplugin/echowindow/echowindow.cpp b/examples/tools/echoplugin/echowindow/echowindow.cpp
new file mode 100644
index 0000000000..0de85ea333
--- /dev/null
+++ b/examples/tools/echoplugin/echowindow/echowindow.cpp
@@ -0,0 +1,119 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "echowindow.h"
+
+//! [0]
+EchoWindow::EchoWindow()
+{
+ createGUI();
+ setLayout(layout);
+ setWindowTitle("Echo Plugin Example");
+
+ if (!loadPlugin()) {
+ QMessageBox::information(this, "Error", "Could not load the plugin");
+ lineEdit->setEnabled(false);
+ button->setEnabled(false);
+ }
+}
+//! [0]
+
+//! [1]
+void EchoWindow::sendEcho()
+{
+ QString text = echoInterface->echo(lineEdit->text());
+ label->setText(text);
+}
+//! [1]
+
+//! [2]
+void EchoWindow::createGUI()
+{
+ lineEdit = new QLineEdit;
+ label = new QLabel;
+ label->setFrameStyle(QFrame::Box | QFrame::Plain);
+ button = new QPushButton(tr("Send Message"));
+
+ connect(lineEdit, SIGNAL(editingFinished()),
+ this, SLOT(sendEcho()));
+ connect(button, SIGNAL(clicked()),
+ this, SLOT(sendEcho()));
+
+ layout = new QGridLayout;
+ layout->addWidget(new QLabel(tr("Message:")), 0, 0);
+ layout->addWidget(lineEdit, 0, 1);
+ layout->addWidget(new QLabel(tr("Answer:")), 1, 0);
+ layout->addWidget(label, 1, 1);
+ layout->addWidget(button, 2, 1, Qt::AlignRight);
+ layout->setSizeConstraint(QLayout::SetFixedSize);
+}
+//! [2]
+
+//! [3]
+bool EchoWindow::loadPlugin()
+{
+ QDir pluginsDir(qApp->applicationDirPath());
+#if defined(Q_OS_WIN)
+ if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release")
+ pluginsDir.cdUp();
+#elif defined(Q_OS_MAC)
+ if (pluginsDir.dirName() == "MacOS") {
+ pluginsDir.cdUp();
+ pluginsDir.cdUp();
+ pluginsDir.cdUp();
+ }
+#endif
+ pluginsDir.cd("plugins");
+ foreach (QString fileName, pluginsDir.entryList(QDir::Files)) {
+ QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));
+ QObject *plugin = pluginLoader.instance();
+ if (plugin) {
+ echoInterface = qobject_cast<EchoInterface *>(plugin);
+ if (echoInterface)
+ return true;
+ }
+ }
+
+ return false;
+}
+//! [3]
diff --git a/examples/tools/echoplugin/echowindow/echowindow.h b/examples/tools/echoplugin/echowindow/echowindow.h
new file mode 100644
index 0000000000..7378e62ca2
--- /dev/null
+++ b/examples/tools/echoplugin/echowindow/echowindow.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** 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 ECHODIALOG_H
+#define ECHODIALOG_H
+
+#include <QWidget>
+
+#include "echointerface.h"
+
+QT_BEGIN_NAMESPACE
+class QString;
+class QLineEdit;
+class QLabel;
+class QPushButton;
+class QGridLayout;
+QT_END_NAMESPACE
+
+//! [0]
+class EchoWindow : public QWidget
+{
+ Q_OBJECT
+
+public:
+ EchoWindow();
+
+private slots:
+ void sendEcho();
+
+private:
+ void createGUI();
+ bool loadPlugin();
+
+ EchoInterface *echoInterface;
+ QLineEdit *lineEdit;
+ QLabel *label;
+ QPushButton *button;
+ QGridLayout *layout;
+};
+//! [0]
+
+#endif
diff --git a/examples/tools/echoplugin/echowindow/echowindow.pro b/examples/tools/echoplugin/echowindow/echowindow.pro
new file mode 100644
index 0000000000..142438bac0
--- /dev/null
+++ b/examples/tools/echoplugin/echowindow/echowindow.pro
@@ -0,0 +1,20 @@
+HEADERS = echowindow.h \
+ echointerface.h
+SOURCES = echowindow.cpp \
+ main.cpp
+
+TARGET = echoplugin
+win32 {
+ debug:DESTDIR = ../debug/
+ release:DESTDIR = ../release/
+} else {
+ DESTDIR = ../
+}
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/tools/echoplugin
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS echowindow.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/echoplugin/echowindow
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/tools/echoplugin/echowindow/main.cpp b/examples/tools/echoplugin/echowindow/main.cpp
new file mode 100644
index 0000000000..cc18f66e6b
--- /dev/null
+++ b/examples/tools/echoplugin/echowindow/main.cpp
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "echowindow.h"
+#include "echointerface.h"
+
+//! [0]
+int main(int argv, char *args[])
+{
+ QApplication app(argv, args);
+
+ EchoWindow window;
+ window.show();
+
+ return app.exec();
+}
+//! [0]
diff --git a/examples/tools/echoplugin/plugin/echoplugin.cpp b/examples/tools/echoplugin/plugin/echoplugin.cpp
new file mode 100644
index 0000000000..67126be5dc
--- /dev/null
+++ b/examples/tools/echoplugin/plugin/echoplugin.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "echoplugin.h"
+
+//! [0]
+QString EchoPlugin::echo(const QString &message)
+{
+ return message;
+}
+//! [0]
+
+//! [1]
+Q_EXPORT_PLUGIN2(echoplugin, EchoPlugin);
+//! [1]
diff --git a/examples/tools/echoplugin/plugin/echoplugin.h b/examples/tools/echoplugin/plugin/echoplugin.h
new file mode 100644
index 0000000000..7ea1d47674
--- /dev/null
+++ b/examples/tools/echoplugin/plugin/echoplugin.h
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ECHOPLUGIN_H
+#define ECHOPLUGIN_H
+
+#include <QObject>
+#include "echoplugin.h"
+#include "echointerface.h"
+
+//! [0]
+class EchoPlugin : public QObject, EchoInterface
+{
+ Q_OBJECT
+ Q_INTERFACES(EchoInterface)
+
+public:
+ QString echo(const QString &message);
+};
+//! [0]
+
+#endif
diff --git a/examples/tools/echoplugin/plugin/plugin.pro b/examples/tools/echoplugin/plugin/plugin.pro
new file mode 100644
index 0000000000..d943425f24
--- /dev/null
+++ b/examples/tools/echoplugin/plugin/plugin.pro
@@ -0,0 +1,19 @@
+#! [0]
+TEMPLATE = lib
+CONFIG += plugin
+INCLUDEPATH += ../echowindow
+HEADERS = echoplugin.h
+SOURCES = echoplugin.cpp
+TARGET = $$qtLibraryTarget(echoplugin)
+DESTDIR = ../plugins
+#! [0]
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/tools/echoplugin/plugin
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS plugin.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/echoplugin/plugin
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+symbian:TARGET.EPOCALLOWDLLDATA = 1
diff --git a/examples/tools/i18n/i18n.pro b/examples/tools/i18n/i18n.pro
new file mode 100644
index 0000000000..a065611c87
--- /dev/null
+++ b/examples/tools/i18n/i18n.pro
@@ -0,0 +1,28 @@
+HEADERS = languagechooser.h \
+ mainwindow.h
+SOURCES = languagechooser.cpp \
+ main.cpp \
+ mainwindow.cpp
+RESOURCES += i18n.qrc
+TRANSLATIONS += translations/i18n_ar.ts \
+ translations/i18n_cs.ts \
+ translations/i18n_de.ts \
+ translations/i18n_el.ts \
+ translations/i18n_en.ts \
+ translations/i18n_eo.ts \
+ translations/i18n_fr.ts \
+ translations/i18n_it.ts \
+ translations/i18n_jp.ts \
+ translations/i18n_ko.ts \
+ translations/i18n_no.ts \
+ translations/i18n_ru.ts \
+ translations/i18n_sv.ts \
+ translations/i18n_zh.ts
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/tools/i18n
+sources.files = $$SOURCES $$HEADERS $$RESOURCES translations i18n.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/i18n
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/tools/i18n/i18n.qrc b/examples/tools/i18n/i18n.qrc
new file mode 100644
index 0000000000..16a89f140b
--- /dev/null
+++ b/examples/tools/i18n/i18n.qrc
@@ -0,0 +1,18 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>translations/i18n_ar.qm</file>
+ <file>translations/i18n_cs.qm</file>
+ <file>translations/i18n_de.qm</file>
+ <file>translations/i18n_el.qm</file>
+ <file>translations/i18n_en.qm</file>
+ <file>translations/i18n_eo.qm</file>
+ <file>translations/i18n_fr.qm</file>
+ <file>translations/i18n_it.qm</file>
+ <file>translations/i18n_jp.qm</file>
+ <file>translations/i18n_ko.qm</file>
+ <file>translations/i18n_no.qm</file>
+ <file>translations/i18n_ru.qm</file>
+ <file>translations/i18n_sv.qm</file>
+ <file>translations/i18n_zh.qm</file>
+</qresource>
+</RCC>
diff --git a/examples/tools/i18n/languagechooser.cpp b/examples/tools/i18n/languagechooser.cpp
new file mode 100644
index 0000000000..a8e97791d4
--- /dev/null
+++ b/examples/tools/i18n/languagechooser.cpp
@@ -0,0 +1,167 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "languagechooser.h"
+#include "mainwindow.h"
+
+#ifdef Q_WS_MAC
+QT_BEGIN_NAMESPACE
+extern void qt_mac_set_menubar_merge(bool merge);
+QT_END_NAMESPACE
+#endif
+
+LanguageChooser::LanguageChooser(QWidget *parent)
+ : QDialog(parent, Qt::WindowStaysOnTopHint)
+{
+ groupBox = new QGroupBox("Languages");
+
+ QGridLayout *groupBoxLayout = new QGridLayout;
+
+ QStringList qmFiles = findQmFiles();
+ for (int i = 0; i < qmFiles.size(); ++i) {
+ QCheckBox *checkBox = new QCheckBox(languageName(qmFiles[i]));
+ qmFileForCheckBoxMap.insert(checkBox, qmFiles[i]);
+ connect(checkBox, SIGNAL(toggled(bool)), this, SLOT(checkBoxToggled()));
+ groupBoxLayout->addWidget(checkBox, i / 2, i % 2);
+ }
+ groupBox->setLayout(groupBoxLayout);
+
+ buttonBox = new QDialogButtonBox;
+
+ showAllButton = buttonBox->addButton("Show All",
+ QDialogButtonBox::ActionRole);
+ hideAllButton = buttonBox->addButton("Hide All",
+ QDialogButtonBox::ActionRole);
+
+ connect(showAllButton, SIGNAL(clicked()), this, SLOT(showAll()));
+ connect(hideAllButton, SIGNAL(clicked()), this, SLOT(hideAll()));
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(groupBox);
+ mainLayout->addWidget(buttonBox);
+ setLayout(mainLayout);
+
+#ifdef Q_WS_MAC
+ qt_mac_set_menubar_merge(false);
+#endif
+
+ setWindowTitle("I18N");
+}
+
+bool LanguageChooser::eventFilter(QObject *object, QEvent *event)
+{
+ if (event->type() == QEvent::Close) {
+ MainWindow *window = qobject_cast<MainWindow *>(object);
+ if (window) {
+ QCheckBox *checkBox = mainWindowForCheckBoxMap.key(window);
+ if (checkBox)
+ checkBox->setChecked(false);
+ }
+ }
+ return QWidget::eventFilter(object, event);
+}
+
+void LanguageChooser::closeEvent(QCloseEvent * /* event */)
+{
+ qApp->quit();
+}
+
+void LanguageChooser::checkBoxToggled()
+{
+ QCheckBox *checkBox = qobject_cast<QCheckBox *>(sender());
+ MainWindow *window = mainWindowForCheckBoxMap[checkBox];
+ if (!window) {
+ QTranslator translator;
+ translator.load(qmFileForCheckBoxMap[checkBox]);
+ qApp->installTranslator(&translator);
+
+ window = new MainWindow;
+ window->setPalette(colorForLanguage(checkBox->text()));
+
+ window->installEventFilter(this);
+ mainWindowForCheckBoxMap.insert(checkBox, window);
+ }
+ window->setVisible(checkBox->isChecked());
+}
+
+void LanguageChooser::showAll()
+{
+ foreach (QCheckBox *checkBox, qmFileForCheckBoxMap.keys())
+ checkBox->setChecked(true);
+}
+
+void LanguageChooser::hideAll()
+{
+ foreach (QCheckBox *checkBox, qmFileForCheckBoxMap.keys())
+ checkBox->setChecked(false);
+}
+
+QStringList LanguageChooser::findQmFiles()
+{
+ QDir dir(":/translations");
+ QStringList fileNames = dir.entryList(QStringList("*.qm"), QDir::Files,
+ QDir::Name);
+ QMutableStringListIterator i(fileNames);
+ while (i.hasNext()) {
+ i.next();
+ i.setValue(dir.filePath(i.value()));
+ }
+ return fileNames;
+}
+
+QString LanguageChooser::languageName(const QString &qmFile)
+{
+ QTranslator translator;
+ translator.load(qmFile);
+
+ return translator.translate("MainWindow", "English");
+}
+
+QColor LanguageChooser::colorForLanguage(const QString &language)
+{
+ uint hashValue = qHash(language);
+ int red = 156 + (hashValue & 0x3F);
+ int green = 156 + ((hashValue >> 6) & 0x3F);
+ int blue = 156 + ((hashValue >> 12) & 0x3F);
+ return QColor(red, green, blue);
+}
diff --git a/examples/tools/i18n/languagechooser.h b/examples/tools/i18n/languagechooser.h
new file mode 100644
index 0000000000..69914f708a
--- /dev/null
+++ b/examples/tools/i18n/languagechooser.h
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** 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 LANGUAGECHOOSER_H
+#define LANGUAGECHOOSER_H
+
+#include <QDialog>
+#include <QMap>
+#include <QStringList>
+
+QT_BEGIN_NAMESPACE
+class QAbstractButton;
+class QCheckBox;
+class QDialogButtonBox;
+class QGroupBox;
+QT_END_NAMESPACE
+class MainWindow;
+
+class LanguageChooser : public QDialog
+{
+ Q_OBJECT
+
+public:
+ LanguageChooser(QWidget *parent = 0);
+
+protected:
+ bool eventFilter(QObject *object, QEvent *event);
+ void closeEvent(QCloseEvent *event);
+
+private slots:
+ void checkBoxToggled();
+ void showAll();
+ void hideAll();
+
+private:
+ QStringList findQmFiles();
+ QString languageName(const QString &qmFile);
+ QColor colorForLanguage(const QString &language);
+
+ QGroupBox *groupBox;
+ QDialogButtonBox *buttonBox;
+ QAbstractButton *showAllButton;
+ QAbstractButton *hideAllButton;
+ QMap<QCheckBox *, QString> qmFileForCheckBoxMap;
+ QMap<QCheckBox *, MainWindow *> mainWindowForCheckBoxMap;
+};
+
+#endif
diff --git a/examples/tools/i18n/main.cpp b/examples/tools/i18n/main.cpp
new file mode 100644
index 0000000000..98d3da0e56
--- /dev/null
+++ b/examples/tools/i18n/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "languagechooser.h"
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(i18n);
+
+ QApplication app(argc, argv);
+ LanguageChooser chooser;
+ chooser.show();
+ return app.exec();
+}
diff --git a/examples/tools/i18n/mainwindow.cpp b/examples/tools/i18n/mainwindow.cpp
new file mode 100644
index 0000000000..33cd5f57e7
--- /dev/null
+++ b/examples/tools/i18n/mainwindow.cpp
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "mainwindow.h"
+
+static const char * const listEntries[] = {
+ QT_TRANSLATE_NOOP("MainWindow", "First"),
+ QT_TRANSLATE_NOOP("MainWindow", "Second"),
+ QT_TRANSLATE_NOOP("MainWindow", "Third"),
+ 0
+};
+
+MainWindow::MainWindow()
+{
+ centralWidget = new QWidget;
+ setCentralWidget(centralWidget);
+
+ createGroupBox();
+
+ listWidget = new QListWidget;
+ for (int i = 0; listEntries[i]; ++i)
+ listWidget->addItem(tr(listEntries[i]));
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(groupBox);
+ mainLayout->addWidget(listWidget);
+ centralWidget->setLayout(mainLayout);
+
+ exitAction = new QAction(tr("E&xit"), this);
+ connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
+
+ fileMenu = menuBar()->addMenu(tr("&File"));
+ fileMenu->setPalette(QPalette(Qt::red));
+ fileMenu->addAction(exitAction);
+
+ setWindowTitle(tr("Language: %1").arg(tr("English")));
+ statusBar()->showMessage(tr("Internationalization Example"));
+
+ if (tr("LTR") == "RTL")
+ setLayoutDirection(Qt::RightToLeft);
+}
+
+void MainWindow::createGroupBox()
+{
+ groupBox = new QGroupBox(tr("View"));
+ perspectiveRadioButton = new QRadioButton(tr("Perspective"));
+ isometricRadioButton = new QRadioButton(tr("Isometric"));
+ obliqueRadioButton = new QRadioButton(tr("Oblique"));
+ perspectiveRadioButton->setChecked(true);
+
+ QVBoxLayout *groupBoxLayout = new QVBoxLayout;
+ groupBoxLayout->addWidget(perspectiveRadioButton);
+ groupBoxLayout->addWidget(isometricRadioButton);
+ groupBoxLayout->addWidget(obliqueRadioButton);
+ groupBox->setLayout(groupBoxLayout);
+}
diff --git a/examples/tools/i18n/mainwindow.h b/examples/tools/i18n/mainwindow.h
new file mode 100644
index 0000000000..5928be2588
--- /dev/null
+++ b/examples/tools/i18n/mainwindow.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QGroupBox;
+class QLabel;
+class QListWidget;
+class QMenu;
+class QRadioButton;
+QT_END_NAMESPACE
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+private:
+ void createGroupBox();
+
+ QWidget *centralWidget;
+ QLabel *label;
+ QGroupBox *groupBox;
+ QListWidget *listWidget;
+ QRadioButton *perspectiveRadioButton;
+ QRadioButton *isometricRadioButton;
+ QRadioButton *obliqueRadioButton;
+ QMenu *fileMenu;
+ QAction *exitAction;
+};
+
+#endif
diff --git a/examples/tools/i18n/translations/i18n_ar.qm b/examples/tools/i18n/translations/i18n_ar.qm
new file mode 100644
index 0000000000..a134c468bb
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_ar.qm
Binary files differ
diff --git a/examples/tools/i18n/translations/i18n_ar.ts b/examples/tools/i18n/translations/i18n_ar.ts
new file mode 100644
index 0000000000..a7ec2c9404
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_ar.ts
@@ -0,0 +1,57 @@
+<!DOCTYPE TS><TS>
+<context>
+ <name>MainWindow</name>
+ <message>
+ <source>First</source>
+ <translation>أول</translation>
+ </message>
+ <message>
+ <source>Internationalization Example</source>
+ <translation>مثال التدويل</translation>
+ </message>
+ <message>
+ <source>Isometric</source>
+ <translation>متماثل</translation>
+ </message>
+ <message>
+ <source>Language: %1</source>
+ <translation>اللغة: %1</translation>
+ </message>
+ <message>
+ <source>English</source>
+ <translation>العربية</translation>
+ </message>
+ <message>
+ <source>Oblique</source>
+ <translation>مصمت</translation>
+ </message>
+ <message>
+ <source>Perspective</source>
+ <translation>منظور</translation>
+ </message>
+ <message>
+ <source>Second</source>
+ <translation>ثانى</translation>
+ </message>
+ <message>
+ <source>Third</source>
+ <translation>ثالث</translation>
+ </message>
+ <message>
+ <source>View</source>
+ <translation>مرئى</translation>
+ </message>
+ <message>
+ <source>E&amp;xit</source>
+ <translation>أخرج</translation>
+ </message>
+ <message>
+ <source>&amp;File</source>
+ <translation>الملÙ</translation>
+ </message>
+ <message>
+ <source>LTR</source>
+ <translation>RTL</translation>
+ </message>
+</context>
+</TS>
diff --git a/examples/tools/i18n/translations/i18n_cs.qm b/examples/tools/i18n/translations/i18n_cs.qm
new file mode 100644
index 0000000000..5b7ff95b05
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_cs.qm
Binary files differ
diff --git a/examples/tools/i18n/translations/i18n_cs.ts b/examples/tools/i18n/translations/i18n_cs.ts
new file mode 100644
index 0000000000..6c4dee9b2e
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_cs.ts
@@ -0,0 +1,57 @@
+<!DOCTYPE TS><TS>
+<context>
+ <name>MainWindow</name>
+ <message>
+ <source>View</source>
+ <translation>Pohled</translation>
+ </message>
+ <message>
+ <source>&amp;File</source>
+ <translation>&amp;Soubor</translation>
+ </message>
+ <message>
+ <source>E&amp;xit</source>
+ <translation>&amp;Konec</translation>
+ </message>
+ <message>
+ <source>First</source>
+ <translation>První</translation>
+ </message>
+ <message>
+ <source>Third</source>
+ <translation>Třetí</translation>
+ </message>
+ <message>
+ <source>Language: %1</source>
+ <translation>Jayzk: %1</translation>
+ </message>
+ <message>
+ <source>English</source>
+ <translation>Český</translation>
+ </message>
+ <message>
+ <source>Oblique</source>
+ <translation>Nakloněný</translation>
+ </message>
+ <message>
+ <source>Second</source>
+ <translation>Druhý</translation>
+ </message>
+ <message>
+ <source>Isometric</source>
+ <translation>Isometrický</translation>
+ </message>
+ <message>
+ <source>Perspective</source>
+ <translation>Perspektivní</translation>
+ </message>
+ <message>
+ <source>Internationalization Example</source>
+ <translation>Ukázka lokalizace</translation>
+ </message>
+ <message>
+ <source>LTR</source>
+ <translation>LTR</translation>
+ </message>
+</context>
+</TS>
diff --git a/examples/tools/i18n/translations/i18n_de.qm b/examples/tools/i18n/translations/i18n_de.qm
new file mode 100644
index 0000000000..177fc49b8b
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_de.qm
Binary files differ
diff --git a/examples/tools/i18n/translations/i18n_de.ts b/examples/tools/i18n/translations/i18n_de.ts
new file mode 100644
index 0000000000..249a61d020
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_de.ts
@@ -0,0 +1,57 @@
+<!DOCTYPE TS><TS>
+<context>
+ <name>MainWindow</name>
+ <message>
+ <source>View</source>
+ <translation>Ansicht</translation>
+ </message>
+ <message>
+ <source>&amp;File</source>
+ <translation>&amp;Datei</translation>
+ </message>
+ <message>
+ <source>E&amp;xit</source>
+ <translation>Be&amp;enden</translation>
+ </message>
+ <message>
+ <source>First</source>
+ <translation>Erstens</translation>
+ </message>
+ <message>
+ <source>Third</source>
+ <translation>Drittens</translation>
+ </message>
+ <message>
+ <source>English</source>
+ <translation>Deutsch</translation>
+ </message>
+ <message>
+ <source>Language: %1</source>
+ <translation>Sprache: %1</translation>
+ </message>
+ <message>
+ <source>Oblique</source>
+ <translation>Schief</translation>
+ </message>
+ <message>
+ <source>Second</source>
+ <translation>Zweitens</translation>
+ </message>
+ <message>
+ <source>Isometric</source>
+ <translation>Isometrisch</translation>
+ </message>
+ <message>
+ <source>Perspective</source>
+ <translation>Perspektivisch</translation>
+ </message>
+ <message>
+ <source>Internationalization Example</source>
+ <translation>Internationalisierungsbeispiel</translation>
+ </message>
+ <message>
+ <source>LTR</source>
+ <translation>LTR</translation>
+ </message>
+</context>
+</TS>
diff --git a/examples/tools/i18n/translations/i18n_el.qm b/examples/tools/i18n/translations/i18n_el.qm
new file mode 100644
index 0000000000..5483291bb0
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_el.qm
Binary files differ
diff --git a/examples/tools/i18n/translations/i18n_el.ts b/examples/tools/i18n/translations/i18n_el.ts
new file mode 100644
index 0000000000..d23a0aad3e
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_el.ts
@@ -0,0 +1,57 @@
+<!DOCTYPE TS><TS>
+<context>
+ <name>MainWindow</name>
+ <message>
+ <source>&amp;File</source>
+ <translation>&amp;ΑÏχείο</translation>
+ </message>
+ <message>
+ <source>E&amp;xit</source>
+ <translation>Έ&amp;ξοδος</translation>
+ </message>
+ <message>
+ <source>First</source>
+ <translation>ΠÏώτο</translation>
+ </message>
+ <message>
+ <source>Internationalization Example</source>
+ <translation>ΠαÏάδειγμα διεθνοποίησης</translation>
+ </message>
+ <message>
+ <source>Isometric</source>
+ <translation>ΙσομετÏική</translation>
+ </message>
+ <message>
+ <source>Language: %1</source>
+ <translation>Γλώσσα: %1</translation>
+ </message>
+ <message>
+ <source>English</source>
+ <translation>Ελληνικά</translation>
+ </message>
+ <message>
+ <source>Oblique</source>
+ <translation>Πλάγια</translation>
+ </message>
+ <message>
+ <source>Perspective</source>
+ <translation>ΠÏοοπτική</translation>
+ </message>
+ <message>
+ <source>Second</source>
+ <translation>ΔεÏτεÏο</translation>
+ </message>
+ <message>
+ <source>Third</source>
+ <translation>ΤÏίτο</translation>
+ </message>
+ <message>
+ <source>View</source>
+ <translation>Όψη</translation>
+ </message>
+ <message>
+ <source>LTR</source>
+ <translation>LTR</translation>
+ </message>
+</context>
+</TS>
diff --git a/examples/tools/i18n/translations/i18n_en.qm b/examples/tools/i18n/translations/i18n_en.qm
new file mode 100644
index 0000000000..9190ac7e6f
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_en.qm
Binary files differ
diff --git a/examples/tools/i18n/translations/i18n_en.ts b/examples/tools/i18n/translations/i18n_en.ts
new file mode 100644
index 0000000000..ca38e958c1
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_en.ts
@@ -0,0 +1,57 @@
+<!DOCTYPE TS><TS>
+<context>
+ <name>MainWindow</name>
+ <message>
+ <source>E&amp;xit</source>
+ <translation>E&amp;xit</translation>
+ </message>
+ <message>
+ <source>&amp;File</source>
+ <translation>&amp;File</translation>
+ </message>
+ <message>
+ <source>Internationalization Example</source>
+ <translation>Internationalization Example</translation>
+ </message>
+ <message>
+ <source>Language: %1</source>
+ <translation>Language: %1</translation>
+ </message>
+ <message>
+ <source>English</source>
+ <translation>English</translation>
+ </message>
+ <message>
+ <source>View</source>
+ <translation>View</translation>
+ </message>
+ <message>
+ <source>Perspective</source>
+ <translation>Perspective</translation>
+ </message>
+ <message>
+ <source>Isometric</source>
+ <translation>Isometric</translation>
+ </message>
+ <message>
+ <source>Oblique</source>
+ <translation>Oblique</translation>
+ </message>
+ <message>
+ <source>First</source>
+ <translation>First</translation>
+ </message>
+ <message>
+ <source>Second</source>
+ <translation>Second</translation>
+ </message>
+ <message>
+ <source>Third</source>
+ <translation>Third</translation>
+ </message>
+ <message>
+ <source>LTR</source>
+ <translation>LTR</translation>
+ </message>
+</context>
+</TS>
diff --git a/examples/tools/i18n/translations/i18n_eo.qm b/examples/tools/i18n/translations/i18n_eo.qm
new file mode 100644
index 0000000000..a8457bef06
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_eo.qm
Binary files differ
diff --git a/examples/tools/i18n/translations/i18n_eo.ts b/examples/tools/i18n/translations/i18n_eo.ts
new file mode 100644
index 0000000000..16a37becd9
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_eo.ts
@@ -0,0 +1,57 @@
+<!DOCTYPE TS><TS>
+<context>
+ <name>MainWindow</name>
+ <message>
+ <source>&amp;File</source>
+ <translation>&amp;Dosiero</translation>
+ </message>
+ <message>
+ <source>First</source>
+ <translation>Unue</translation>
+ </message>
+ <message>
+ <source>Internationalization Example</source>
+ <translation>Ekzemplo pri internaciigo</translation>
+ </message>
+ <message>
+ <source>Isometric</source>
+ <translation>Isometria</translation>
+ </message>
+ <message>
+ <source>Language: %1</source>
+ <translation>Lingvo: %1</translation>
+ </message>
+ <message>
+ <source>English</source>
+ <translation>Esperanto</translation>
+ </message>
+ <message>
+ <source>Oblique</source>
+ <translation>Oblikva</translation>
+ </message>
+ <message>
+ <source>Perspective</source>
+ <translation>Perspektiva</translation>
+ </message>
+ <message>
+ <source>Second</source>
+ <translation>Due</translation>
+ </message>
+ <message>
+ <source>Third</source>
+ <translation>Trie</translation>
+ </message>
+ <message>
+ <source>View</source>
+ <translation>Aspekto</translation>
+ </message>
+ <message>
+ <source>E&amp;xit</source>
+ <translation>&amp;Fini</translation>
+ </message>
+ <message>
+ <source>LTR</source>
+ <translation>LTR</translation>
+ </message>
+</context>
+</TS>
diff --git a/examples/tools/i18n/translations/i18n_fr.qm b/examples/tools/i18n/translations/i18n_fr.qm
new file mode 100644
index 0000000000..3e8a69b80d
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_fr.qm
Binary files differ
diff --git a/examples/tools/i18n/translations/i18n_fr.ts b/examples/tools/i18n/translations/i18n_fr.ts
new file mode 100644
index 0000000000..0012892ef2
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_fr.ts
@@ -0,0 +1,57 @@
+<!DOCTYPE TS><TS>
+<context>
+ <name>MainWindow</name>
+ <message>
+ <source>View</source>
+ <translation>Vue</translation>
+ </message>
+ <message>
+ <source>&amp;File</source>
+ <translation>&amp;Fichier</translation>
+ </message>
+ <message>
+ <source>E&amp;xit</source>
+ <translation>&amp;Quitter</translation>
+ </message>
+ <message>
+ <source>First</source>
+ <translation>Premier</translation>
+ </message>
+ <message>
+ <source>Third</source>
+ <translation>Troisième</translation>
+ </message>
+ <message>
+ <source>Language: %1</source>
+ <translation>Langue : %1</translation>
+ </message>
+ <message>
+ <source>English</source>
+ <translation>Français</translation>
+ </message>
+ <message>
+ <source>Oblique</source>
+ <translation>Oblique</translation>
+ </message>
+ <message>
+ <source>Second</source>
+ <translation>Deuxième</translation>
+ </message>
+ <message>
+ <source>Isometric</source>
+ <translation>Isométrique</translation>
+ </message>
+ <message>
+ <source>Perspective</source>
+ <translation>Perspective</translation>
+ </message>
+ <message>
+ <source>Internationalization Example</source>
+ <translation>Exemple d&apos;internationalisation</translation>
+ </message>
+ <message>
+ <source>LTR</source>
+ <translation>LTR</translation>
+ </message>
+</context>
+</TS>
diff --git a/examples/tools/i18n/translations/i18n_it.qm b/examples/tools/i18n/translations/i18n_it.qm
new file mode 100644
index 0000000000..3dffd30548
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_it.qm
Binary files differ
diff --git a/examples/tools/i18n/translations/i18n_it.ts b/examples/tools/i18n/translations/i18n_it.ts
new file mode 100644
index 0000000000..d516a277b6
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_it.ts
@@ -0,0 +1,57 @@
+<!DOCTYPE TS><TS>
+<context>
+ <name>MainWindow</name>
+ <message>
+ <source>First</source>
+ <translation>Primo</translation>
+ </message>
+ <message>
+ <source>Internationalization Example</source>
+ <translation>Esempio di localizzazione</translation>
+ </message>
+ <message>
+ <source>Isometric</source>
+ <translation>Isometrica</translation>
+ </message>
+ <message>
+ <source>Language: %1</source>
+ <translation>Lingua: %1</translation>
+ </message>
+ <message>
+ <source>English</source>
+ <translation>Italiano</translation>
+ </message>
+ <message>
+ <source>Oblique</source>
+ <translation>Obliqua</translation>
+ </message>
+ <message>
+ <source>Perspective</source>
+ <translation>Prospettica</translation>
+ </message>
+ <message>
+ <source>Second</source>
+ <translation>Secondo</translation>
+ </message>
+ <message>
+ <source>Third</source>
+ <translation>Terzo</translation>
+ </message>
+ <message>
+ <source>View</source>
+ <translation>Vista</translation>
+ </message>
+ <message>
+ <source>E&amp;xit</source>
+ <translation>&amp;Esci</translation>
+ </message>
+ <message>
+ <source>&amp;File</source>
+ <translation>&amp;File</translation>
+ </message>
+ <message>
+ <source>LTR</source>
+ <translation>LTR</translation>
+ </message>
+</context>
+</TS>
diff --git a/examples/tools/i18n/translations/i18n_jp.qm b/examples/tools/i18n/translations/i18n_jp.qm
new file mode 100644
index 0000000000..017bc96cfc
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_jp.qm
Binary files differ
diff --git a/examples/tools/i18n/translations/i18n_jp.ts b/examples/tools/i18n/translations/i18n_jp.ts
new file mode 100644
index 0000000000..067b5a8a0b
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_jp.ts
@@ -0,0 +1,57 @@
+<!DOCTYPE TS><TS>
+<context>
+ <name>MainWindow</name>
+ <message>
+ <source>&amp;File</source>
+ <translation>ファイル(&amp;F)</translation>
+ </message>
+ <message>
+ <source>E&amp;xit</source>
+ <translation>終了(&amp;X)</translation>
+ </message>
+ <message>
+ <source>First</source>
+ <translation>第一行</translation>
+ </message>
+ <message>
+ <source>Internationalization Example</source>
+ <translation>国際化(i18n)ã®ä¾‹</translation>
+ </message>
+ <message>
+ <source>Isometric</source>
+ <translation>等角投影法</translation>
+ </message>
+ <message>
+ <source>Language: %1</source>
+ <translation>言語: %1</translation>
+ </message>
+ <message>
+ <source>English</source>
+ <translation>日本語</translation>
+ </message>
+ <message>
+ <source>Oblique</source>
+ <translation>æ–œã‚投影法</translation>
+ </message>
+ <message>
+ <source>Perspective</source>
+ <translation>é è¿‘法</translation>
+ </message>
+ <message>
+ <source>Second</source>
+ <translation>第二行</translation>
+ </message>
+ <message>
+ <source>Third</source>
+ <translation>第三行</translation>
+ </message>
+ <message>
+ <source>View</source>
+ <translation>表示方å¼</translation>
+ </message>
+ <message>
+ <source>LTR</source>
+ <translation>LTR</translation>
+ </message>
+</context>
+</TS>
diff --git a/examples/tools/i18n/translations/i18n_ko.qm b/examples/tools/i18n/translations/i18n_ko.qm
new file mode 100644
index 0000000000..d61b93db39
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_ko.qm
Binary files differ
diff --git a/examples/tools/i18n/translations/i18n_ko.ts b/examples/tools/i18n/translations/i18n_ko.ts
new file mode 100644
index 0000000000..bfd5924518
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_ko.ts
@@ -0,0 +1,57 @@
+<!DOCTYPE TS><TS>
+<context>
+ <name>MainWindow</name>
+ <message>
+ <source>&amp;File</source>
+ <translation>파ì¼&amp;F</translation>
+ </message>
+ <message>
+ <source>E&amp;xit</source>
+ <translation>종료&amp;X</translation>
+ </message>
+ <message>
+ <source>First</source>
+ <translation>첫번째</translation>
+ </message>
+ <message>
+ <source>Internationalization Example</source>
+ <translation>국제화 예제</translation>
+ </message>
+ <message>
+ <source>Isometric</source>
+ <translation>등측ë„</translation>
+ </message>
+ <message>
+ <source>Language: %1</source>
+ <translation>언어 : %1</translation>
+ </message>
+ <message>
+ <source>English</source>
+ <translation>한국어</translation>
+ </message>
+ <message>
+ <source>Oblique</source>
+ <translation>ë¹—ê°</translation>
+ </message>
+ <message>
+ <source>Perspective</source>
+ <translation>ì›ê·¼í™”법</translation>
+ </message>
+ <message>
+ <source>Second</source>
+ <translation>ë‘번째</translation>
+ </message>
+ <message>
+ <source>Third</source>
+ <translation>세번째</translation>
+ </message>
+ <message>
+ <source>View</source>
+ <translation>보기</translation>
+ </message>
+ <message>
+ <source>LTR</source>
+ <translation>LTR</translation>
+ </message>
+</context>
+</TS>
diff --git a/examples/tools/i18n/translations/i18n_no.qm b/examples/tools/i18n/translations/i18n_no.qm
new file mode 100644
index 0000000000..c84b0d74ba
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_no.qm
Binary files differ
diff --git a/examples/tools/i18n/translations/i18n_no.ts b/examples/tools/i18n/translations/i18n_no.ts
new file mode 100644
index 0000000000..2e06974997
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_no.ts
@@ -0,0 +1,57 @@
+<!DOCTYPE TS><TS>
+<context>
+ <name>MainWindow</name>
+ <message>
+ <source>View</source>
+ <translation>Vis</translation>
+ </message>
+ <message>
+ <source>&amp;File</source>
+ <translation>&amp;Fil</translation>
+ </message>
+ <message>
+ <source>E&amp;xit</source>
+ <translation>&amp;Avslutt</translation>
+ </message>
+ <message>
+ <source>First</source>
+ <translation>Første</translation>
+ </message>
+ <message>
+ <source>Third</source>
+ <translation>Tredje</translation>
+ </message>
+ <message>
+ <source>Language: %1</source>
+ <translation>Språk: %1</translation>
+ </message>
+ <message>
+ <source>English</source>
+ <translation>Norsk</translation>
+ </message>
+ <message>
+ <source>Oblique</source>
+ <translation>Skjevt</translation>
+ </message>
+ <message>
+ <source>Second</source>
+ <translation>Andre</translation>
+ </message>
+ <message>
+ <source>Isometric</source>
+ <translation>Isometrisk</translation>
+ </message>
+ <message>
+ <source>Perspective</source>
+ <translation>Perspektiv</translation>
+ </message>
+ <message>
+ <source>Internationalization Example</source>
+ <translation>Internasjonaliseringseksempel</translation>
+ </message>
+ <message>
+ <source>LTR</source>
+ <translation>LTR</translation>
+ </message>
+</context>
+</TS>
diff --git a/examples/tools/i18n/translations/i18n_ru.qm b/examples/tools/i18n/translations/i18n_ru.qm
new file mode 100644
index 0000000000..a76e1b8703
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_ru.qm
Binary files differ
diff --git a/examples/tools/i18n/translations/i18n_ru.ts b/examples/tools/i18n/translations/i18n_ru.ts
new file mode 100644
index 0000000000..748cc12fd9
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_ru.ts
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE TS><TS version="1.1" language="ru">
+<defaultcodec></defaultcodec>
+<context>
+ <name>MainWindow</name>
+ <message>
+ <source>View</source>
+ <translation>Вид</translation>
+ </message>
+ <message>
+ <source>&amp;File</source>
+ <translation>Файл</translation>
+ </message>
+ <message>
+ <source>E&amp;xit</source>
+ <translation>Выход</translation>
+ </message>
+ <message>
+ <source>First</source>
+ <translation>Первый</translation>
+ </message>
+ <message>
+ <source>Third</source>
+ <translation>Третий</translation>
+ </message>
+ <message>
+ <source>Language: %1</source>
+ <translation>Язык: %1</translation>
+ </message>
+ <message>
+ <source>English</source>
+ <translation>РуÑÑкий</translation>
+ </message>
+ <message>
+ <source>Oblique</source>
+ <translation>КурÑив</translation>
+ </message>
+ <message>
+ <source>Second</source>
+ <translation>Второй</translation>
+ </message>
+ <message>
+ <source>Isometric</source>
+ <translation>ИзометричеÑкий</translation>
+ </message>
+ <message>
+ <source>Perspective</source>
+ <translation>ПерÑпектива</translation>
+ </message>
+ <message>
+ <source>Internationalization Example</source>
+ <translation>Пример интернационализации</translation>
+ </message>
+ <message>
+ <source>LTR</source>
+ <translation>LTR</translation>
+ </message>
+</context>
+</TS>
diff --git a/examples/tools/i18n/translations/i18n_sv.qm b/examples/tools/i18n/translations/i18n_sv.qm
new file mode 100644
index 0000000000..7204b308b1
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_sv.qm
Binary files differ
diff --git a/examples/tools/i18n/translations/i18n_sv.ts b/examples/tools/i18n/translations/i18n_sv.ts
new file mode 100644
index 0000000000..ac4ab98bd3
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_sv.ts
@@ -0,0 +1,57 @@
+<!DOCTYPE TS><TS>
+<context>
+ <name>MainWindow</name>
+ <message>
+ <source>View</source>
+ <translation>Visa</translation>
+ </message>
+ <message>
+ <source>&amp;File</source>
+ <translation>&amp;Arkiv</translation>
+ </message>
+ <message>
+ <source>E&amp;xit</source>
+ <translation>&amp;Avsluta</translation>
+ </message>
+ <message>
+ <source>First</source>
+ <translation>Första</translation>
+ </message>
+ <message>
+ <source>Third</source>
+ <translation>Tredje</translation>
+ </message>
+ <message>
+ <source>Language: %1</source>
+ <translation>Språk: %1</translation>
+ </message>
+ <message>
+ <source>English</source>
+ <translation>Svenska</translation>
+ </message>
+ <message>
+ <source>Oblique</source>
+ <translation>Skevt</translation>
+ </message>
+ <message>
+ <source>Second</source>
+ <translation>Andra</translation>
+ </message>
+ <message>
+ <source>Isometric</source>
+ <translation>Isometriskt</translation>
+ </message>
+ <message>
+ <source>Perspective</source>
+ <translation>Perspektivt</translation>
+ </message>
+ <message>
+ <source>Internationalization Example</source>
+ <translation>Internationaliseringsexempel</translation>
+ </message>
+ <message>
+ <source>LTR</source>
+ <translation>LTR</translation>
+ </message>
+</context>
+</TS>
diff --git a/examples/tools/i18n/translations/i18n_zh.qm b/examples/tools/i18n/translations/i18n_zh.qm
new file mode 100644
index 0000000000..32053f4633
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_zh.qm
Binary files differ
diff --git a/examples/tools/i18n/translations/i18n_zh.ts b/examples/tools/i18n/translations/i18n_zh.ts
new file mode 100644
index 0000000000..3b715470a8
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_zh.ts
@@ -0,0 +1,57 @@
+<!DOCTYPE TS><TS>
+<context>
+ <name>MainWindow</name>
+ <message>
+ <source>View</source>
+ <translation>视图</translation>
+ </message>
+ <message>
+ <source>&amp;File</source>
+ <translation>文件[&amp;F]</translation>
+ </message>
+ <message>
+ <source>E&amp;xit</source>
+ <translation>退出[&amp;x]</translation>
+ </message>
+ <message>
+ <source>First</source>
+ <translation>第一个</translation>
+ </message>
+ <message>
+ <source>Third</source>
+ <translation>第三个</translation>
+ </message>
+ <message>
+ <source>Language: %1</source>
+ <translation>语言: %1</translation>
+ </message>
+ <message>
+ <source>English</source>
+ <translation>简体中文</translation>
+ </message>
+ <message>
+ <source>Oblique</source>
+ <translation>斜投影</translation>
+ </message>
+ <message>
+ <source>Second</source>
+ <translation>第二个</translation>
+ </message>
+ <message>
+ <source>Isometric</source>
+ <translation>等角投影</translation>
+ </message>
+ <message>
+ <source>Perspective</source>
+ <translation>é€è§†æŠ•å½±</translation>
+ </message>
+ <message>
+ <source>Internationalization Example</source>
+ <translation>国际化范例</translation>
+ </message>
+ <message>
+ <source>LTR</source>
+ <translation>LTR</translation>
+ </message>
+</context>
+</TS>
diff --git a/examples/tools/plugandpaint/interfaces.h b/examples/tools/plugandpaint/interfaces.h
new file mode 100644
index 0000000000..87eb9d0f20
--- /dev/null
+++ b/examples/tools/plugandpaint/interfaces.h
@@ -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$
+**
+****************************************************************************/
+
+#ifndef INTERFACES_H
+#define INTERFACES_H
+
+#include <QtPlugin>
+
+QT_BEGIN_NAMESPACE
+class QImage;
+class QPainter;
+class QWidget;
+class QPainterPath;
+class QPoint;
+class QRect;
+class QString;
+class QStringList;
+QT_END_NAMESPACE
+
+//! [0]
+class BrushInterface
+{
+public:
+ virtual ~BrushInterface() {}
+
+ virtual QStringList brushes() const = 0;
+ virtual QRect mousePress(const QString &brush, QPainter &painter,
+ const QPoint &pos) = 0;
+ virtual QRect mouseMove(const QString &brush, QPainter &painter,
+ const QPoint &oldPos, const QPoint &newPos) = 0;
+ virtual QRect mouseRelease(const QString &brush, QPainter &painter,
+ const QPoint &pos) = 0;
+};
+//! [0]
+
+//! [1]
+class ShapeInterface
+{
+public:
+ virtual ~ShapeInterface() {}
+
+ virtual QStringList shapes() const = 0;
+ virtual QPainterPath generateShape(const QString &shape,
+ QWidget *parent) = 0;
+};
+//! [1]
+
+//! [2]
+class FilterInterface
+{
+public:
+ virtual ~FilterInterface() {}
+
+ virtual QStringList filters() const = 0;
+ virtual QImage filterImage(const QString &filter, const QImage &image,
+ QWidget *parent) = 0;
+};
+//! [2]
+
+QT_BEGIN_NAMESPACE
+//! [3] //! [4]
+Q_DECLARE_INTERFACE(BrushInterface,
+ "com.trolltech.PlugAndPaint.BrushInterface/1.0")
+//! [3]
+Q_DECLARE_INTERFACE(ShapeInterface,
+ "com.trolltech.PlugAndPaint.ShapeInterface/1.0")
+//! [5]
+Q_DECLARE_INTERFACE(FilterInterface,
+ "com.trolltech.PlugAndPaint.FilterInterface/1.0")
+//! [4] //! [5]
+QT_END_NAMESPACE
+
+#endif
diff --git a/examples/tools/plugandpaint/main.cpp b/examples/tools/plugandpaint/main.cpp
new file mode 100644
index 0000000000..7778cac419
--- /dev/null
+++ b/examples/tools/plugandpaint/main.cpp
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** 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 "mainwindow.h"
+#include <QtPlugin>
+#include <QApplication>
+
+QT_BEGIN_NAMESPACE
+Q_IMPORT_PLUGIN(pnp_basictools)
+QT_END_NAMESPACE
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow window;
+ window.show();
+ return app.exec();
+}
+//! [0]
diff --git a/examples/tools/plugandpaint/mainwindow.cpp b/examples/tools/plugandpaint/mainwindow.cpp
new file mode 100644
index 0000000000..224bc71e04
--- /dev/null
+++ b/examples/tools/plugandpaint/mainwindow.cpp
@@ -0,0 +1,310 @@
+/****************************************************************************
+**
+** 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 "interfaces.h"
+#include "mainwindow.h"
+#include "paintarea.h"
+#include "plugindialog.h"
+
+#include <QPluginLoader>
+#include <QTimer>
+
+#include <QScrollArea>
+#include <QMessageBox>
+#include <QActionGroup>
+#include <QAction>
+#include <QMenu>
+#include <QMenuBar>
+#include <QFileDialog>
+#include <QColorDialog>
+#include <QInputDialog>
+#include <QApplication>
+
+MainWindow::MainWindow() :
+ paintArea(new PaintArea),
+ scrollArea(new QScrollArea)
+{
+ scrollArea->setBackgroundRole(QPalette::Dark);
+ scrollArea->setWidget(paintArea);
+ setCentralWidget(scrollArea);
+
+ createActions();
+ createMenus();
+ loadPlugins();
+
+ setWindowTitle(tr("Plug & Paint"));
+
+ if (!brushActionGroup->actions().isEmpty())
+ brushActionGroup->actions().first()->trigger();
+
+ QTimer::singleShot(500, this, SLOT(aboutPlugins()));
+}
+
+void MainWindow::open()
+{
+ const QString fileName = QFileDialog::getOpenFileName(this,
+ tr("Open File"),
+ QDir::currentPath());
+ if (!fileName.isEmpty()) {
+ if (!paintArea->openImage(fileName)) {
+ QMessageBox::information(this, tr("Plug & Paint"),
+ tr("Cannot load %1.").arg(fileName));
+ return;
+ }
+ paintArea->adjustSize();
+ }
+}
+
+bool MainWindow::saveAs()
+{
+ const QString initialPath = QDir::currentPath() + "/untitled.png";
+
+ const QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"),
+ initialPath);
+ if (fileName.isEmpty()) {
+ return false;
+ } else {
+ return paintArea->saveImage(fileName, "png");
+ }
+}
+
+void MainWindow::brushColor()
+{
+ const QColor newColor = QColorDialog::getColor(paintArea->brushColor());
+ if (newColor.isValid())
+ paintArea->setBrushColor(newColor);
+}
+
+void MainWindow::brushWidth()
+{
+ bool ok;
+ const int newWidth = QInputDialog::getInteger(this, tr("Plug & Paint"),
+ tr("Select brush width:"),
+ paintArea->brushWidth(),
+ 1, 50, 1, &ok);
+ if (ok)
+ paintArea->setBrushWidth(newWidth);
+}
+
+//! [0]
+void MainWindow::changeBrush()
+{
+ QAction *action = qobject_cast<QAction *>(sender());
+ BrushInterface *iBrush = qobject_cast<BrushInterface *>(action->parent());
+ const QString brush = action->text();
+
+ paintArea->setBrush(iBrush, brush);
+}
+//! [0]
+
+//! [1]
+void MainWindow::insertShape()
+{
+ QAction *action = qobject_cast<QAction *>(sender());
+ ShapeInterface *iShape = qobject_cast<ShapeInterface *>(action->parent());
+
+ const QPainterPath path = iShape->generateShape(action->text(), this);
+ if (!path.isEmpty())
+ paintArea->insertShape(path);
+}
+//! [1]
+
+//! [2]
+void MainWindow::applyFilter()
+{
+ QAction *action = qobject_cast<QAction *>(sender());
+ FilterInterface *iFilter =
+ qobject_cast<FilterInterface *>(action->parent());
+
+ const QImage image = iFilter->filterImage(action->text(), paintArea->image(),
+ this);
+ paintArea->setImage(image);
+}
+//! [2]
+
+void MainWindow::about()
+{
+ QMessageBox::about(this, tr("About Plug & Paint"),
+ tr("The <b>Plug & Paint</b> example demonstrates how to write Qt "
+ "applications that can be extended through plugins."));
+}
+
+//! [3]
+void MainWindow::aboutPlugins()
+{
+ PluginDialog dialog(pluginsDir.path(), pluginFileNames, this);
+ dialog.exec();
+}
+//! [3]
+
+void MainWindow::createActions()
+{
+ openAct = new QAction(tr("&Open..."), this);
+ openAct->setShortcut(tr("Ctrl+O"));
+ connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
+
+ saveAsAct = new QAction(tr("&Save As..."), this);
+ saveAsAct->setShortcut(tr("Ctrl+S"));
+ connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs()));
+
+ exitAct = new QAction(tr("E&xit"), this);
+ exitAct->setShortcut(tr("Ctrl+Q"));
+ connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
+
+ brushColorAct = new QAction(tr("&Brush Color..."), this);
+ connect(brushColorAct, SIGNAL(triggered()), this, SLOT(brushColor()));
+
+ brushWidthAct = new QAction(tr("&Brush Width..."), this);
+ connect(brushWidthAct, SIGNAL(triggered()), this, SLOT(brushWidth()));
+
+ brushActionGroup = new QActionGroup(this);
+
+ aboutAct = new QAction(tr("&About"), this);
+ connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+
+ aboutQtAct = new QAction(tr("About &Qt"), this);
+ connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+
+ aboutPluginsAct = new QAction(tr("About &Plugins"), this);
+ connect(aboutPluginsAct, SIGNAL(triggered()), this, SLOT(aboutPlugins()));
+}
+
+void MainWindow::createMenus()
+{
+ fileMenu = menuBar()->addMenu(tr("&File"));
+ fileMenu->addAction(openAct);
+ fileMenu->addAction(saveAsAct);
+ fileMenu->addSeparator();
+ fileMenu->addAction(exitAct);
+
+ brushMenu = menuBar()->addMenu(tr("&Brush"));
+ brushMenu->addAction(brushColorAct);
+ brushMenu->addAction(brushWidthAct);
+ brushMenu->addSeparator();
+
+ shapesMenu = menuBar()->addMenu(tr("&Shapes"));
+
+ filterMenu = menuBar()->addMenu(tr("&Filter"));
+
+ menuBar()->addSeparator();
+
+ helpMenu = menuBar()->addMenu(tr("&Help"));
+ helpMenu->addAction(aboutAct);
+ helpMenu->addAction(aboutQtAct);
+ helpMenu->addAction(aboutPluginsAct);
+}
+
+//! [4]
+void MainWindow::loadPlugins()
+{
+ foreach (QObject *plugin, QPluginLoader::staticInstances())
+ populateMenus(plugin);
+//! [4] //! [5]
+
+ pluginsDir = QDir(qApp->applicationDirPath());
+
+#if defined(Q_OS_WIN)
+ if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release")
+ pluginsDir.cdUp();
+#elif defined(Q_OS_MAC)
+ if (pluginsDir.dirName() == "MacOS") {
+ pluginsDir.cdUp();
+ pluginsDir.cdUp();
+ pluginsDir.cdUp();
+ }
+#endif
+ pluginsDir.cd("plugins");
+//! [5]
+
+//! [6]
+ foreach (QString fileName, pluginsDir.entryList(QDir::Files)) {
+ QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
+ QObject *plugin = loader.instance();
+ if (plugin) {
+ populateMenus(plugin);
+ pluginFileNames += fileName;
+//! [6] //! [7]
+ }
+//! [7] //! [8]
+ }
+//! [8]
+
+//! [9]
+ brushMenu->setEnabled(!brushActionGroup->actions().isEmpty());
+ shapesMenu->setEnabled(!shapesMenu->actions().isEmpty());
+ filterMenu->setEnabled(!filterMenu->actions().isEmpty());
+}
+//! [9]
+
+//! [10]
+void MainWindow::populateMenus(QObject *plugin)
+{
+ BrushInterface *iBrush = qobject_cast<BrushInterface *>(plugin);
+ if (iBrush)
+ addToMenu(plugin, iBrush->brushes(), brushMenu, SLOT(changeBrush()),
+ brushActionGroup);
+
+ ShapeInterface *iShape = qobject_cast<ShapeInterface *>(plugin);
+ if (iShape)
+ addToMenu(plugin, iShape->shapes(), shapesMenu, SLOT(insertShape()));
+
+ FilterInterface *iFilter = qobject_cast<FilterInterface *>(plugin);
+ if (iFilter)
+ addToMenu(plugin, iFilter->filters(), filterMenu, SLOT(applyFilter()));
+}
+//! [10]
+
+void MainWindow::addToMenu(QObject *plugin, const QStringList &texts,
+ QMenu *menu, const char *member,
+ QActionGroup *actionGroup)
+{
+ foreach (QString text, texts) {
+ QAction *action = new QAction(text, plugin);
+ connect(action, SIGNAL(triggered()), this, member);
+ menu->addAction(action);
+
+ if (actionGroup) {
+ action->setCheckable(true);
+ actionGroup->addAction(action);
+ }
+ }
+}
diff --git a/examples/tools/plugandpaint/mainwindow.h b/examples/tools/plugandpaint/mainwindow.h
new file mode 100644
index 0000000000..47afb2d6c3
--- /dev/null
+++ b/examples/tools/plugandpaint/mainwindow.h
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QDir>
+#include <QMainWindow>
+#include <QStringList>
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QActionGroup;
+class QMenu;
+class QScrollArea;
+QT_END_NAMESPACE
+class PaintArea;
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+private slots:
+ void open();
+ bool saveAs();
+ void brushColor();
+ void brushWidth();
+ void changeBrush();
+ void insertShape();
+ void applyFilter();
+ void about();
+ void aboutPlugins();
+
+private:
+ void createActions();
+ void createMenus();
+ void loadPlugins();
+ void populateMenus(QObject *plugin);
+ void addToMenu(QObject *plugin, const QStringList &texts, QMenu *menu,
+ const char *member, QActionGroup *actionGroup = 0);
+
+ PaintArea *paintArea;
+ QScrollArea *scrollArea;
+ QDir pluginsDir;
+ QStringList pluginFileNames;
+
+ QMenu *fileMenu;
+ QMenu *brushMenu;
+ QMenu *shapesMenu;
+ QMenu *filterMenu;
+ QMenu *helpMenu;
+ QActionGroup *brushActionGroup;
+ QAction *openAct;
+ QAction *saveAsAct;
+ QAction *exitAct;
+ QAction *brushWidthAct;
+ QAction *brushColorAct;
+ QAction *aboutAct;
+ QAction *aboutQtAct;
+ QAction *aboutPluginsAct;
+};
+
+#endif
diff --git a/examples/tools/plugandpaint/paintarea.cpp b/examples/tools/plugandpaint/paintarea.cpp
new file mode 100644
index 0000000000..9d5b3c5f2a
--- /dev/null
+++ b/examples/tools/plugandpaint/paintarea.cpp
@@ -0,0 +1,196 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include "interfaces.h"
+#include "paintarea.h"
+
+#include <QPainter>
+#include <QMouseEvent>
+
+PaintArea::PaintArea(QWidget *parent) :
+ QWidget(parent),
+ theImage(500, 400, QImage::Format_RGB32),
+ color(Qt::blue),
+ thickness(3),
+ brushInterface(0),
+ lastPos(-1, -1)
+{
+ setAttribute(Qt::WA_StaticContents);
+ setAttribute(Qt::WA_NoBackground);
+
+ theImage.fill(qRgb(255, 255, 255));
+}
+
+bool PaintArea::openImage(const QString &fileName)
+{
+ QImage image;
+ if (!image.load(fileName))
+ return false;
+
+ setImage(image);
+ return true;
+}
+
+bool PaintArea::saveImage(const QString &fileName, const char *fileFormat)
+{
+ return theImage.save(fileName, fileFormat);
+}
+
+void PaintArea::setImage(const QImage &image)
+{
+ theImage = image.convertToFormat(QImage::Format_RGB32);
+ update();
+ updateGeometry();
+}
+
+void PaintArea::insertShape(const QPainterPath &path)
+{
+ pendingPath = path;
+#ifndef QT_NO_CURSOR
+ setCursor(Qt::CrossCursor);
+#endif
+}
+
+void PaintArea::setBrushColor(const QColor &color)
+{
+ this->color = color;
+}
+
+void PaintArea::setBrushWidth(int width)
+{
+ thickness = width;
+}
+
+//! [0]
+void PaintArea::setBrush(BrushInterface *brushInterface, const QString &brush)
+{
+ this->brushInterface = brushInterface;
+ this->brush = brush;
+}
+//! [0]
+
+QSize PaintArea::sizeHint() const
+{
+ return theImage.size();
+}
+
+void PaintArea::paintEvent(QPaintEvent * /* event */)
+{
+ QPainter painter(this);
+ painter.drawImage(QPoint(0, 0), theImage);
+}
+
+void PaintArea::mousePressEvent(QMouseEvent *event)
+{
+ if (event->button() == Qt::LeftButton) {
+ if (!pendingPath.isEmpty()) {
+ QPainter painter(&theImage);
+ setupPainter(painter);
+
+ const QRectF boundingRect = pendingPath.boundingRect();
+ QLinearGradient gradient(boundingRect.topRight(),
+ boundingRect.bottomLeft());
+ gradient.setColorAt(0.0, QColor(color.red(), color.green(),
+ color.blue(), 63));
+ gradient.setColorAt(1.0, QColor(color.red(), color.green(),
+ color.blue(), 191));
+ painter.setBrush(gradient);
+ painter.translate(event->pos() - boundingRect.center());
+ painter.drawPath(pendingPath);
+
+ pendingPath = QPainterPath();
+#ifndef QT_NO_CURSOR
+ unsetCursor();
+#endif
+ update();
+ } else {
+ if (brushInterface) {
+ QPainter painter(&theImage);
+ setupPainter(painter);
+ const QRect rect = brushInterface->mousePress(brush, painter,
+ event->pos());
+ update(rect);
+ }
+
+ lastPos = event->pos();
+ }
+ }
+}
+
+//! [1]
+void PaintArea::mouseMoveEvent(QMouseEvent *event)
+{
+ if ((event->buttons() & Qt::LeftButton) && lastPos != QPoint(-1, -1)) {
+ if (brushInterface) {
+ QPainter painter(&theImage);
+ setupPainter(painter);
+ const QRect rect = brushInterface->mouseMove(brush, painter, lastPos,
+ event->pos());
+ update(rect);
+ }
+
+ lastPos = event->pos();
+ }
+}
+//! [1]
+
+void PaintArea::mouseReleaseEvent(QMouseEvent *event)
+{
+ if (event->button() == Qt::LeftButton && lastPos != QPoint(-1, -1)) {
+ if (brushInterface) {
+ QPainter painter(&theImage);
+ setupPainter(painter);
+ QRect rect = brushInterface->mouseRelease(brush, painter,
+ event->pos());
+ update(rect);
+ }
+
+ lastPos = QPoint(-1, -1);
+ }
+}
+
+void PaintArea::setupPainter(QPainter &painter)
+{
+ painter.setRenderHint(QPainter::Antialiasing, true);
+ painter.setPen(QPen(color, thickness, Qt::SolidLine, Qt::RoundCap,
+ Qt::RoundJoin));
+}
diff --git a/examples/tools/plugandpaint/paintarea.h b/examples/tools/plugandpaint/paintarea.h
new file mode 100644
index 0000000000..e4215d5885
--- /dev/null
+++ b/examples/tools/plugandpaint/paintarea.h
@@ -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$
+**
+****************************************************************************/
+
+#ifndef PAINTAREA_H
+#define PAINTAREA_H
+
+#include <QColor>
+#include <QImage>
+#include <QPainterPath>
+#include <QWidget>
+
+class BrushInterface;
+
+class PaintArea : public QWidget
+{
+ Q_OBJECT
+
+public:
+ PaintArea(QWidget *parent = 0);
+
+ bool openImage(const QString &fileName);
+ bool saveImage(const QString &fileName, const char *fileFormat);
+ void setImage(const QImage &image);
+ void insertShape(const QPainterPath &path);
+ void setBrushColor(const QColor &color);
+ void setBrushWidth(int width);
+ void setBrush(BrushInterface *brushInterface, const QString &brush);
+
+ QImage image() const { return theImage; }
+ QColor brushColor() const { return color; }
+ int brushWidth() const { return thickness; }
+ QSize sizeHint() const;
+
+protected:
+ void paintEvent(QPaintEvent *event);
+ void mousePressEvent(QMouseEvent *event);
+ void mouseMoveEvent(QMouseEvent *event);
+ void mouseReleaseEvent(QMouseEvent *event);
+
+private:
+ void setupPainter(QPainter &painter);
+
+ QImage theImage;
+ QColor color;
+ int thickness;
+
+ BrushInterface *brushInterface;
+ QString brush;
+ QPoint lastPos;
+
+ QPainterPath pendingPath;
+};
+
+#endif
diff --git a/examples/tools/plugandpaint/plugandpaint.pro b/examples/tools/plugandpaint/plugandpaint.pro
new file mode 100644
index 0000000000..fef1b86f7c
--- /dev/null
+++ b/examples/tools/plugandpaint/plugandpaint.pro
@@ -0,0 +1,28 @@
+#! [0]
+HEADERS = interfaces.h \
+ mainwindow.h \
+ paintarea.h \
+ plugindialog.h
+SOURCES = main.cpp \
+ mainwindow.cpp \
+ paintarea.cpp \
+ plugindialog.cpp
+symbian {
+ LIBS = -lpnp_basictools.lib
+} else {
+ LIBS = -L$${QT_BUILD_TREE}/examples/tools/plugandpaint/plugins -lpnp_basictools
+}
+
+if(!debug_and_release|build_pass):CONFIG(debug, debug|release) {
+ mac:LIBS = $$member(LIBS, 0) $$member(LIBS, 1)_debug
+ win32:LIBS = $$member(LIBS, 0) $$member(LIBS, 1)d
+}
+#! [0]
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/tools/plugandpaint
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS plugandpaint.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/plugandpaint
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/tools/plugandpaint/plugindialog.cpp b/examples/tools/plugandpaint/plugindialog.cpp
new file mode 100644
index 0000000000..5e37a8b635
--- /dev/null
+++ b/examples/tools/plugandpaint/plugindialog.cpp
@@ -0,0 +1,157 @@
+/****************************************************************************
+**
+** 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 "interfaces.h"
+#include "plugindialog.h"
+
+#include <QPluginLoader>
+#include <QStringList>
+#include <QDir>
+
+#include <QLabel>
+#include <QGridLayout>
+#include <QPushButton>
+#include <QTreeWidget>
+#include <QTreeWidgetItem>
+#include <QHeaderView>
+
+PluginDialog::PluginDialog(const QString &path, const QStringList &fileNames,
+ QWidget *parent) :
+ QDialog(parent),
+ label(new QLabel),
+ treeWidget(new QTreeWidget),
+ okButton(new QPushButton(tr("OK")))
+{
+ treeWidget->setAlternatingRowColors(false);
+ treeWidget->setSelectionMode(QAbstractItemView::NoSelection);
+ treeWidget->setColumnCount(1);
+ treeWidget->header()->hide();
+
+ okButton->setDefault(true);
+
+ connect(okButton, SIGNAL(clicked()), this, SLOT(close()));
+
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->setColumnStretch(0, 1);
+ mainLayout->setColumnStretch(2, 1);
+ mainLayout->addWidget(label, 0, 0, 1, 3);
+ mainLayout->addWidget(treeWidget, 1, 0, 1, 3);
+ mainLayout->addWidget(okButton, 2, 1);
+ setLayout(mainLayout);
+
+ interfaceIcon.addPixmap(style()->standardPixmap(QStyle::SP_DirOpenIcon),
+ QIcon::Normal, QIcon::On);
+ interfaceIcon.addPixmap(style()->standardPixmap(QStyle::SP_DirClosedIcon),
+ QIcon::Normal, QIcon::Off);
+ featureIcon.addPixmap(style()->standardPixmap(QStyle::SP_FileIcon));
+
+ setWindowTitle(tr("Plugin Information"));
+ findPlugins(path, fileNames);
+}
+
+//! [0]
+void PluginDialog::findPlugins(const QString &path,
+ const QStringList &fileNames)
+{
+ label->setText(tr("Plug & Paint found the following plugins\n"
+ "(looked in %1):")
+ .arg(QDir::toNativeSeparators(path)));
+
+ const QDir dir(path);
+
+ foreach (QObject *plugin, QPluginLoader::staticInstances())
+ populateTreeWidget(plugin, tr("%1 (Static Plugin)")
+ .arg(plugin->metaObject()->className()));
+
+ foreach (QString fileName, fileNames) {
+ QPluginLoader loader(dir.absoluteFilePath(fileName));
+ QObject *plugin = loader.instance();
+ if (plugin)
+ populateTreeWidget(plugin, fileName);
+ }
+}
+//! [0]
+
+//! [1]
+void PluginDialog::populateTreeWidget(QObject *plugin, const QString &text)
+{
+ QTreeWidgetItem *pluginItem = new QTreeWidgetItem(treeWidget);
+ pluginItem->setText(0, text);
+ treeWidget->setItemExpanded(pluginItem, true);
+
+ QFont boldFont = pluginItem->font(0);
+ boldFont.setBold(true);
+ pluginItem->setFont(0, boldFont);
+
+ if (plugin) {
+ BrushInterface *iBrush = qobject_cast<BrushInterface *>(plugin);
+ if (iBrush)
+ addItems(pluginItem, "BrushInterface", iBrush->brushes());
+
+ ShapeInterface *iShape = qobject_cast<ShapeInterface *>(plugin);
+ if (iShape)
+ addItems(pluginItem, "ShapeInterface", iShape->shapes());
+
+ FilterInterface *iFilter =
+ qobject_cast<FilterInterface *>(plugin);
+ if (iFilter)
+ addItems(pluginItem, "FilterInterface", iFilter->filters());
+ }
+}
+//! [1]
+
+void PluginDialog::addItems(QTreeWidgetItem *pluginItem,
+ const char *interfaceName,
+ const QStringList &features)
+{
+ QTreeWidgetItem *interfaceItem = new QTreeWidgetItem(pluginItem);
+ interfaceItem->setText(0, interfaceName);
+ interfaceItem->setIcon(0, interfaceIcon);
+
+ foreach (QString feature, features) {
+ if (feature.endsWith("..."))
+ feature.chop(3);
+ QTreeWidgetItem *featureItem = new QTreeWidgetItem(interfaceItem);
+ featureItem->setText(0, feature);
+ featureItem->setIcon(0, featureIcon);
+ }
+}
diff --git a/examples/tools/plugandpaint/plugindialog.h b/examples/tools/plugandpaint/plugindialog.h
new file mode 100644
index 0000000000..73cb6e498f
--- /dev/null
+++ b/examples/tools/plugandpaint/plugindialog.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PLUGINDIALOG_H
+#define PLUGINDIALOG_H
+
+#include <QDialog>
+#include <QIcon>
+
+QT_BEGIN_NAMESPACE
+class QLabel;
+class QPushButton;
+class QStringList;
+class QTreeWidget;
+class QTreeWidgetItem;
+QT_END_NAMESPACE
+
+class PluginDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ PluginDialog(const QString &path, const QStringList &fileNames,
+ QWidget *parent = 0);
+
+private:
+ void findPlugins(const QString &path, const QStringList &fileNames);
+ void populateTreeWidget(QObject *plugin, const QString &text);
+ void addItems(QTreeWidgetItem *pluginItem, const char *interfaceName,
+ const QStringList &features);
+
+ QLabel *label;
+ QTreeWidget *treeWidget;
+ QPushButton *okButton;
+ QIcon interfaceIcon;
+ QIcon featureIcon;
+};
+
+#endif
diff --git a/examples/tools/plugandpaintplugins/basictools/basictools.pro b/examples/tools/plugandpaintplugins/basictools/basictools.pro
new file mode 100644
index 0000000000..f9cd4a6a85
--- /dev/null
+++ b/examples/tools/plugandpaintplugins/basictools/basictools.pro
@@ -0,0 +1,17 @@
+#! [0]
+TEMPLATE = lib
+CONFIG += plugin static
+INCLUDEPATH += ../..
+HEADERS = basictoolsplugin.h
+SOURCES = basictoolsplugin.cpp
+TARGET = $$qtLibraryTarget(pnp_basictools)
+DESTDIR = ../../plugandpaint/plugins
+#! [0]
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/tools/plugandpaint/plugins
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS basictools.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/plugandpaintplugins/basictools
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/tools/plugandpaintplugins/basictools/basictoolsplugin.cpp b/examples/tools/plugandpaintplugins/basictools/basictoolsplugin.cpp
new file mode 100644
index 0000000000..95b239f450
--- /dev/null
+++ b/examples/tools/plugandpaintplugins/basictools/basictoolsplugin.cpp
@@ -0,0 +1,198 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include <math.h>
+#include <stdlib.h>
+
+#include "basictoolsplugin.h"
+
+const float Pi = 3.14159f;
+
+//! [0]
+QStringList BasicToolsPlugin::brushes() const
+{
+ return QStringList() << tr("Pencil") << tr("Air Brush")
+ << tr("Random Letters");
+}
+//! [0]
+
+//! [1]
+QRect BasicToolsPlugin::mousePress(const QString &brush, QPainter &painter,
+ const QPoint &pos)
+{
+ return mouseMove(brush, painter, pos, pos);
+}
+//! [1]
+
+//! [2]
+QRect BasicToolsPlugin::mouseMove(const QString &brush, QPainter &painter,
+ const QPoint &oldPos, const QPoint &newPos)
+{
+ painter.save();
+
+ int rad = painter.pen().width() / 2;
+ QRect boundingRect = QRect(oldPos, newPos).normalized()
+ .adjusted(-rad, -rad, +rad, +rad);
+ QColor color = painter.pen().color();
+ int thickness = painter.pen().width();
+ QColor transparentColor(color.red(), color.green(), color.blue(), 0);
+//! [2] //! [3]
+
+ if (brush == tr("Pencil")) {
+ painter.drawLine(oldPos, newPos);
+ } else if (brush == tr("Air Brush")) {
+ int numSteps = 2 + (newPos - oldPos).manhattanLength() / 2;
+
+ painter.setBrush(QBrush(color, Qt::Dense6Pattern));
+ painter.setPen(Qt::NoPen);
+
+ for (int i = 0; i < numSteps; ++i) {
+ int x = oldPos.x() + i * (newPos.x() - oldPos.x()) / (numSteps - 1);
+ int y = oldPos.y() + i * (newPos.y() - oldPos.y()) / (numSteps - 1);
+
+ painter.drawEllipse(x - (thickness / 2), y - (thickness / 2),
+ thickness, thickness);
+ }
+ } else if (brush == tr("Random Letters")) {
+ QChar ch('A' + (qrand() % 26));
+
+ QFont biggerFont = painter.font();
+ biggerFont.setBold(true);
+ biggerFont.setPointSize(biggerFont.pointSize() + thickness);
+ painter.setFont(biggerFont);
+
+ painter.drawText(newPos, QString(ch));
+
+ QFontMetrics metrics(painter.font());
+ boundingRect = metrics.boundingRect(ch);
+ boundingRect.translate(newPos);
+ boundingRect.adjust(-10, -10, +10, +10);
+ }
+ painter.restore();
+ return boundingRect;
+}
+//! [3]
+
+//! [4]
+QRect BasicToolsPlugin::mouseRelease(const QString & /* brush */,
+ QPainter & /* painter */,
+ const QPoint & /* pos */)
+{
+ return QRect(0, 0, 0, 0);
+}
+//! [4]
+
+//! [5]
+QStringList BasicToolsPlugin::shapes() const
+{
+ return QStringList() << tr("Circle") << tr("Star") << tr("Text...");
+}
+//! [5]
+
+//! [6]
+QPainterPath BasicToolsPlugin::generateShape(const QString &shape,
+ QWidget *parent)
+{
+ QPainterPath path;
+
+ if (shape == tr("Circle")) {
+ path.addEllipse(0, 0, 50, 50);
+ } else if (shape == tr("Star")) {
+ path.moveTo(90, 50);
+ for (int i = 1; i < 5; ++i) {
+ path.lineTo(50 + 40 * cos(0.8 * i * Pi),
+ 50 + 40 * sin(0.8 * i * Pi));
+ }
+ path.closeSubpath();
+ } else if (shape == tr("Text...")) {
+ QString text = QInputDialog::getText(parent, tr("Text Shape"),
+ tr("Enter text:"),
+ QLineEdit::Normal, tr("Qt"));
+ if (!text.isEmpty()) {
+ QFont timesFont("Times", 50);
+ timesFont.setStyleStrategy(QFont::ForceOutline);
+ path.addText(0, 0, timesFont, text);
+ }
+ }
+
+ return path;
+}
+//! [6]
+
+//! [7]
+QStringList BasicToolsPlugin::filters() const
+{
+ return QStringList() << tr("Invert Pixels") << tr("Swap RGB")
+ << tr("Grayscale");
+}
+//! [7]
+
+//! [8]
+QImage BasicToolsPlugin::filterImage(const QString &filter, const QImage &image,
+ QWidget * /* parent */)
+{
+ QImage result = image.convertToFormat(QImage::Format_RGB32);
+
+ if (filter == tr("Invert Pixels")) {
+ result.invertPixels();
+ } else if (filter == tr("Swap RGB")) {
+ result = result.rgbSwapped();
+ } else if (filter == tr("Grayscale")) {
+ for (int y = 0; y < result.height(); ++y) {
+ for (int x = 0; x < result.width(); ++x) {
+ int pixel = result.pixel(x, y);
+ int gray = qGray(pixel);
+ int alpha = qAlpha(pixel);
+ result.setPixel(x, y, qRgba(gray, gray, gray, alpha));
+ }
+ }
+ }
+ return result;
+}
+//! [8]
+
+QT_BEGIN_NAMESPACE
+//! [9]
+Q_EXPORT_PLUGIN2(pnp_basictools, BasicToolsPlugin)
+//! [9]
+QT_END_NAMESPACE
diff --git a/examples/tools/plugandpaintplugins/basictools/basictoolsplugin.h b/examples/tools/plugandpaintplugins/basictools/basictoolsplugin.h
new file mode 100644
index 0000000000..98aed0ba8b
--- /dev/null
+++ b/examples/tools/plugandpaintplugins/basictools/basictoolsplugin.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 BASICTOOLSPLUGIN_H
+#define BASICTOOLSPLUGIN_H
+
+#include <QRect>
+#include <QObject>
+#include <QStringList>
+#include <QPainterPath>
+#include <QImage>
+
+//! [0]
+#include <plugandpaint/interfaces.h>
+
+//! [1]
+class BasicToolsPlugin : public QObject,
+ public BrushInterface,
+ public ShapeInterface,
+ public FilterInterface
+{
+ Q_OBJECT
+ Q_INTERFACES(BrushInterface ShapeInterface FilterInterface)
+//! [0]
+
+//! [2]
+public:
+//! [1]
+ // BrushInterface
+ QStringList brushes() const;
+ QRect mousePress(const QString &brush, QPainter &painter,
+ const QPoint &pos);
+ QRect mouseMove(const QString &brush, QPainter &painter,
+ const QPoint &oldPos, const QPoint &newPos);
+ QRect mouseRelease(const QString &brush, QPainter &painter,
+ const QPoint &pos);
+
+ // ShapeInterface
+ QStringList shapes() const;
+ QPainterPath generateShape(const QString &shape, QWidget *parent);
+
+ // FilterInterface
+ QStringList filters() const;
+ QImage filterImage(const QString &filter, const QImage &image,
+ QWidget *parent);
+//! [3]
+};
+//! [2] //! [3]
+
+#endif
diff --git a/examples/tools/plugandpaintplugins/extrafilters/extrafilters.pro b/examples/tools/plugandpaintplugins/extrafilters/extrafilters.pro
new file mode 100644
index 0000000000..7fbb6d1787
--- /dev/null
+++ b/examples/tools/plugandpaintplugins/extrafilters/extrafilters.pro
@@ -0,0 +1,19 @@
+#! [0]
+TEMPLATE = lib
+CONFIG += plugin
+INCLUDEPATH += ../..
+HEADERS = extrafiltersplugin.h
+SOURCES = extrafiltersplugin.cpp
+TARGET = $$qtLibraryTarget(pnp_extrafilters)
+DESTDIR = ../../plugandpaint/plugins
+
+#! [0]
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/tools/plugandpaint/plugins
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS extrafilters.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/plugandpaintplugins/extrafilters
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+symbian:TARGET.EPOCALLOWDLLDATA = 1
diff --git a/examples/tools/plugandpaintplugins/extrafilters/extrafiltersplugin.cpp b/examples/tools/plugandpaintplugins/extrafilters/extrafiltersplugin.cpp
new file mode 100644
index 0000000000..b54d8b6d78
--- /dev/null
+++ b/examples/tools/plugandpaintplugins/extrafilters/extrafiltersplugin.cpp
@@ -0,0 +1,125 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include <math.h>
+#include <stdlib.h>
+
+#include "extrafiltersplugin.h"
+
+QStringList ExtraFiltersPlugin::filters() const
+{
+ return QStringList() << tr("Flip Horizontally") << tr("Flip Vertically")
+ << tr("Smudge...") << tr("Threshold...");
+}
+
+QImage ExtraFiltersPlugin::filterImage(const QString &filter,
+ const QImage &image, QWidget *parent)
+{
+ QImage original = image.convertToFormat(QImage::Format_RGB32);
+ QImage result = original;
+
+ if (filter == tr("Flip Horizontally")) {
+ for (int y = 0; y < original.height(); ++y) {
+ for (int x = 0; x < original.width(); ++x) {
+ int pixel = original.pixel(original.width() - x - 1, y);
+ result.setPixel(x, y, pixel);
+ }
+ }
+ } else if (filter == tr("Flip Vertically")) {
+ for (int y = 0; y < original.height(); ++y) {
+ for (int x = 0; x < original.width(); ++x) {
+ int pixel = original.pixel(x, original.height() - y - 1);
+ result.setPixel(x, y, pixel);
+ }
+ }
+ } else if (filter == tr("Smudge...")) {
+ bool ok;
+ int numIters = QInputDialog::getInteger(parent, tr("Smudge Filter"),
+ tr("Enter number of iterations:"),
+ 5, 1, 20, 1, &ok);
+ if (ok) {
+ for (int i = 0; i < numIters; ++i) {
+ for (int y = 1; y < original.height() - 1; ++y) {
+ for (int x = 1; x < original.width() - 1; ++x) {
+ int p1 = original.pixel(x, y);
+ int p2 = original.pixel(x, y + 1);
+ int p3 = original.pixel(x, y - 1);
+ int p4 = original.pixel(x + 1, y);
+ int p5 = original.pixel(x - 1, y);
+
+ int red = (qRed(p1) + qRed(p2) + qRed(p3) + qRed(p4)
+ + qRed(p5)) / 5;
+ int green = (qGreen(p1) + qGreen(p2) + qGreen(p3)
+ + qGreen(p4) + qGreen(p5)) / 5;
+ int blue = (qBlue(p1) + qBlue(p2) + qBlue(p3)
+ + qBlue(p4) + qBlue(p5)) / 5;
+ int alpha = (qAlpha(p1) + qAlpha(p2) + qAlpha(p3)
+ + qAlpha(p4) + qAlpha(p5)) / 5;
+
+ result.setPixel(x, y, qRgba(red, green, blue, alpha));
+ }
+ }
+ }
+ }
+ } else if (filter == tr("Threshold...")) {
+ bool ok;
+ int threshold = QInputDialog::getInteger(parent, tr("Threshold Filter"),
+ tr("Enter threshold:"),
+ 10, 1, 256, 1, &ok);
+ if (ok) {
+ int factor = 256 / threshold;
+ for (int y = 0; y < original.height(); ++y) {
+ for (int x = 0; x < original.width(); ++x) {
+ int pixel = original.pixel(x, y);
+ result.setPixel(x, y, qRgba(qRed(pixel) / factor * factor,
+ qGreen(pixel) / factor * factor,
+ qBlue(pixel) / factor * factor,
+ qAlpha(pixel)));
+ }
+ }
+ }
+ }
+ return result;
+}
+
+Q_EXPORT_PLUGIN2(pnp_extrafilters, ExtraFiltersPlugin)
diff --git a/examples/tools/plugandpaintplugins/extrafilters/extrafiltersplugin.h b/examples/tools/plugandpaintplugins/extrafilters/extrafiltersplugin.h
new file mode 100644
index 0000000000..b1b497eaed
--- /dev/null
+++ b/examples/tools/plugandpaintplugins/extrafilters/extrafiltersplugin.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 EXTRAFILTERSPLUGIN_H
+#define EXTRAFILTERSPLUGIN_H
+
+//! [0]
+#include <QObject>
+#include <QStringList>
+#include <QImage>
+
+#include <plugandpaint/interfaces.h>
+
+class ExtraFiltersPlugin : public QObject, public FilterInterface
+{
+ Q_OBJECT
+ Q_INTERFACES(FilterInterface)
+
+public:
+ QStringList filters() const;
+ QImage filterImage(const QString &filter, const QImage &image,
+ QWidget *parent);
+};
+//! [0]
+
+#endif
diff --git a/examples/tools/plugandpaintplugins/plugandpaintplugins.pro b/examples/tools/plugandpaintplugins/plugandpaintplugins.pro
new file mode 100644
index 0000000000..ccc042c307
--- /dev/null
+++ b/examples/tools/plugandpaintplugins/plugandpaintplugins.pro
@@ -0,0 +1,11 @@
+TEMPLATE = subdirs
+SUBDIRS = basictools \
+ extrafilters
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/tools/plugandpaintplugins
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS plugandpaintplugins.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/plugandpaintplugins
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/tools/regexp/main.cpp b/examples/tools/regexp/main.cpp
new file mode 100644
index 0000000000..4fc8de8071
--- /dev/null
+++ b/examples/tools/regexp/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "regexpdialog.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ RegExpDialog dialog;
+ dialog.show();
+ return dialog.exec();
+}
diff --git a/examples/tools/regexp/regexp.pro b/examples/tools/regexp/regexp.pro
new file mode 100644
index 0000000000..bbb3fd390e
--- /dev/null
+++ b/examples/tools/regexp/regexp.pro
@@ -0,0 +1,11 @@
+HEADERS = regexpdialog.h
+SOURCES = regexpdialog.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/tools/regexp
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS regexp.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/regexp
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/tools/regexp/regexpdialog.cpp b/examples/tools/regexp/regexpdialog.cpp
new file mode 100644
index 0000000000..8fe7383444
--- /dev/null
+++ b/examples/tools/regexp/regexpdialog.cpp
@@ -0,0 +1,188 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "regexpdialog.h"
+
+RegExpDialog::RegExpDialog(QWidget *parent)
+ : QDialog(parent)
+{
+ patternComboBox = new QComboBox;
+ patternComboBox->setEditable(true);
+ patternComboBox->setSizePolicy(QSizePolicy::Expanding,
+ QSizePolicy::Preferred);
+
+ patternLabel = new QLabel(tr("&Pattern:"));
+ patternLabel->setBuddy(patternComboBox);
+
+ escapedPatternLineEdit = new QLineEdit;
+ escapedPatternLineEdit->setReadOnly(true);
+ QPalette palette = escapedPatternLineEdit->palette();
+ palette.setBrush(QPalette::Base,
+ palette.brush(QPalette::Disabled, QPalette::Base));
+ escapedPatternLineEdit->setPalette(palette);
+
+ escapedPatternLabel = new QLabel(tr("&Escaped Pattern:"));
+ escapedPatternLabel->setBuddy(escapedPatternLineEdit);
+
+ syntaxComboBox = new QComboBox;
+ syntaxComboBox->addItem(tr("Regular expression v1"), QRegExp::RegExp);
+ syntaxComboBox->addItem(tr("Regular expression v2"), QRegExp::RegExp2);
+ syntaxComboBox->addItem(tr("Wildcard"), QRegExp::Wildcard);
+ syntaxComboBox->addItem(tr("Fixed string"), QRegExp::FixedString);
+
+ syntaxLabel = new QLabel(tr("&Pattern Syntax:"));
+ syntaxLabel->setBuddy(syntaxComboBox);
+
+ textComboBox = new QComboBox;
+ textComboBox->setEditable(true);
+ textComboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
+
+ textLabel = new QLabel(tr("&Text:"));
+ textLabel->setBuddy(textComboBox);
+
+ caseSensitiveCheckBox = new QCheckBox(tr("Case &Sensitive"));
+ caseSensitiveCheckBox->setChecked(true);
+ minimalCheckBox = new QCheckBox(tr("&Minimal"));
+
+ indexLabel = new QLabel(tr("Index of Match:"));
+ indexEdit = new QLineEdit;
+ indexEdit->setReadOnly(true);
+
+ matchedLengthLabel = new QLabel(tr("Matched Length:"));
+ matchedLengthEdit = new QLineEdit;
+ matchedLengthEdit->setReadOnly(true);
+
+ for (int i = 0; i < MaxCaptures; ++i) {
+ captureLabels[i] = new QLabel(tr("Capture %1:").arg(i));
+ captureEdits[i] = new QLineEdit;
+ captureEdits[i]->setReadOnly(true);
+ }
+ captureLabels[0]->setText(tr("Match:"));
+
+ QHBoxLayout *checkBoxLayout = new QHBoxLayout;
+ checkBoxLayout->addWidget(caseSensitiveCheckBox);
+ checkBoxLayout->addWidget(minimalCheckBox);
+ checkBoxLayout->addStretch(1);
+
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->addWidget(patternLabel, 0, 0);
+ mainLayout->addWidget(patternComboBox, 0, 1);
+ mainLayout->addWidget(escapedPatternLabel, 1, 0);
+ mainLayout->addWidget(escapedPatternLineEdit, 1, 1);
+ mainLayout->addWidget(syntaxLabel, 2, 0);
+ mainLayout->addWidget(syntaxComboBox, 2, 1);
+ mainLayout->addLayout(checkBoxLayout, 3, 0, 1, 2);
+ mainLayout->addWidget(textLabel, 4, 0);
+ mainLayout->addWidget(textComboBox, 4, 1);
+ mainLayout->addWidget(indexLabel, 5, 0);
+ mainLayout->addWidget(indexEdit, 5, 1);
+ mainLayout->addWidget(matchedLengthLabel, 6, 0);
+ mainLayout->addWidget(matchedLengthEdit, 6, 1);
+
+ for (int j = 0; j < MaxCaptures; ++j) {
+ mainLayout->addWidget(captureLabels[j], 7 + j, 0);
+ mainLayout->addWidget(captureEdits[j], 7 + j, 1);
+ }
+ setLayout(mainLayout);
+
+ connect(patternComboBox, SIGNAL(editTextChanged(const QString &)),
+ this, SLOT(refresh()));
+ connect(textComboBox, SIGNAL(editTextChanged(const QString &)),
+ this, SLOT(refresh()));
+ connect(caseSensitiveCheckBox, SIGNAL(toggled(bool)),
+ this, SLOT(refresh()));
+ connect(minimalCheckBox, SIGNAL(toggled(bool)), this, SLOT(refresh()));
+ connect(syntaxComboBox, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(refresh()));
+
+ patternComboBox->addItem(tr("[A-Za-z_]+([A-Za-z_0-9]*)"));
+ textComboBox->addItem(tr("(10 + delta4) * 32"));
+
+ setWindowTitle(tr("RegExp"));
+ setFixedHeight(sizeHint().height());
+ refresh();
+}
+
+void RegExpDialog::refresh()
+{
+ setUpdatesEnabled(false);
+
+ QString pattern = patternComboBox->currentText();
+ QString text = textComboBox->currentText();
+
+ QString escaped = pattern;
+ escaped.replace("\\", "\\\\");
+ escaped.replace("\"", "\\\"");
+ escaped.prepend("\"");
+ escaped.append("\"");
+ escapedPatternLineEdit->setText(escaped);
+
+ QRegExp rx(pattern);
+ Qt::CaseSensitivity cs = Qt::CaseInsensitive;
+ if (caseSensitiveCheckBox->isChecked())
+ cs = Qt::CaseSensitive;
+ rx.setCaseSensitivity(cs);
+ rx.setMinimal(minimalCheckBox->isChecked());
+ QRegExp::PatternSyntax syntax = QRegExp::PatternSyntax(
+ syntaxComboBox->itemData(syntaxComboBox->currentIndex()).toInt());
+ rx.setPatternSyntax(syntax);
+
+ QPalette palette = patternComboBox->palette();
+ if (rx.isValid()) {
+ palette.setColor(QPalette::Text,
+ textComboBox->palette().color(QPalette::Text));
+ } else {
+ palette.setColor(QPalette::Text, Qt::red);
+ }
+ patternComboBox->setPalette(palette);
+
+ indexEdit->setText(QString::number(rx.indexIn(text)));
+ matchedLengthEdit->setText(QString::number(rx.matchedLength()));
+ for (int i = 0; i < MaxCaptures; ++i) {
+ captureLabels[i]->setEnabled(i <= rx.numCaptures());
+ captureEdits[i]->setEnabled(i <= rx.numCaptures());
+ captureEdits[i]->setText(rx.cap(i));
+ }
+
+ setUpdatesEnabled(true);
+}
diff --git a/examples/tools/regexp/regexpdialog.h b/examples/tools/regexp/regexpdialog.h
new file mode 100644
index 0000000000..d4dfb650e7
--- /dev/null
+++ b/examples/tools/regexp/regexpdialog.h
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** 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 REGEXPDIALOG_H
+#define REGEXPDIALOG_H
+
+#include <QDialog>
+
+QT_BEGIN_NAMESPACE
+class QCheckBox;
+class QComboBox;
+class QLabel;
+class QLineEdit;
+QT_END_NAMESPACE
+
+class RegExpDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ RegExpDialog(QWidget *parent = 0);
+
+private slots:
+ void refresh();
+
+private:
+ QLabel *patternLabel;
+ QLabel *escapedPatternLabel;
+ QLabel *syntaxLabel;
+ QLabel *textLabel;
+ QComboBox *patternComboBox;
+ QLineEdit *escapedPatternLineEdit;
+ QComboBox *textComboBox;
+ QCheckBox *caseSensitiveCheckBox;
+ QCheckBox *minimalCheckBox;
+ QComboBox *syntaxComboBox;
+
+ QLabel *indexLabel;
+ QLabel *matchedLengthLabel;
+ QLineEdit *indexEdit;
+ QLineEdit *matchedLengthEdit;
+
+ enum { MaxCaptures = 6 };
+ QLabel *captureLabels[MaxCaptures];
+ QLineEdit *captureEdits[MaxCaptures];
+};
+
+#endif
diff --git a/examples/tools/settingseditor/inifiles/licensepage.ini b/examples/tools/settingseditor/inifiles/licensepage.ini
new file mode 100644
index 0000000000..608d1b7885
--- /dev/null
+++ b/examples/tools/settingseditor/inifiles/licensepage.ini
@@ -0,0 +1,46 @@
+[Field%201]
+Bottom=89
+Flags=MULTILINE|VSCROLL|READONLY
+Left=4
+Right=296
+State=No license agreement file found. Please contact support.
+Top=14
+Type=Text
+
+[Field%202]
+Bottom=8
+Left=4
+Right=294
+Text=Press Page Down to see the rest of the agreement.
+Top=0
+Type=Label
+
+[Field%203]
+Bottom=111
+Left=4
+Right=297
+Text=If you accept the terms of the agreement, select the first option below. You must accept the agreement to install this software. Click Next to continue.
+Top=92
+Type=Label
+
+[Field%204]
+Bottom=129
+Flags=GROUP|NOTIFY
+Left=4
+Right=299
+Text=I &accept the terms in the License Agreement
+Top=120
+Type=RadioButton
+
+[Field%205]
+Bottom=140
+Flags=NOTIFY
+Left=4
+Right=300
+State=1
+Text=I &do not accept the terms in the License Agreement
+Top=129
+Type=RadioButton
+
+[Settings]
+NumFields=5
diff --git a/examples/tools/settingseditor/inifiles/qsa.ini b/examples/tools/settingseditor/inifiles/qsa.ini
new file mode 100644
index 0000000000..56a2964ee5
--- /dev/null
+++ b/examples/tools/settingseditor/inifiles/qsa.ini
@@ -0,0 +1,26 @@
+[Field%201]
+Bottom=65
+Left=0
+Right=299
+Text=QSA Build Options
+Top=9
+Type=Groupbox
+
+[Field%202]
+Bottom=37
+Left=20
+Right=284
+Text=Don't compile QSA Workbench into QSA.
+Top=27
+Type=Checkbox
+
+[Field%203]
+Bottom=56
+Left=20
+Right=247
+Text=Don't compile QSA Workbench nor QSA Editor into QSA.
+Top=45
+Type=Checkbox
+
+[Settings]
+NumFields=3
diff --git a/examples/tools/settingseditor/locationdialog.cpp b/examples/tools/settingseditor/locationdialog.cpp
new file mode 100644
index 0000000000..600038b228
--- /dev/null
+++ b/examples/tools/settingseditor/locationdialog.cpp
@@ -0,0 +1,217 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "locationdialog.h"
+
+LocationDialog::LocationDialog(QWidget *parent)
+ : QDialog(parent)
+{
+ formatComboBox = new QComboBox;
+ formatComboBox->addItem(tr("Native"));
+ formatComboBox->addItem(tr("INI"));
+
+ scopeComboBox = new QComboBox;
+ scopeComboBox->addItem(tr("User"));
+ scopeComboBox->addItem(tr("System"));
+
+ organizationComboBox = new QComboBox;
+ organizationComboBox->addItem(tr("Trolltech"));
+ organizationComboBox->setEditable(true);
+
+ applicationComboBox = new QComboBox;
+ applicationComboBox->addItem(tr("Any"));
+ applicationComboBox->addItem(tr("Application Example"));
+ applicationComboBox->addItem(tr("Assistant"));
+ applicationComboBox->addItem(tr("Designer"));
+ applicationComboBox->addItem(tr("Linguist"));
+ applicationComboBox->setEditable(true);
+ applicationComboBox->setCurrentIndex(3);
+
+ formatLabel = new QLabel(tr("&Format:"));
+ formatLabel->setBuddy(formatComboBox);
+
+ scopeLabel = new QLabel(tr("&Scope:"));
+ scopeLabel->setBuddy(scopeComboBox);
+
+ organizationLabel = new QLabel(tr("&Organization:"));
+ organizationLabel->setBuddy(organizationComboBox);
+
+ applicationLabel = new QLabel(tr("&Application:"));
+ applicationLabel->setBuddy(applicationComboBox);
+
+ locationsGroupBox = new QGroupBox(tr("Setting Locations"));
+
+ QStringList labels;
+ labels << tr("Location") << tr("Access");
+
+ locationsTable = new QTableWidget;
+ locationsTable->setSelectionMode(QAbstractItemView::SingleSelection);
+ locationsTable->setSelectionBehavior(QAbstractItemView::SelectRows);
+ locationsTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
+ locationsTable->setColumnCount(2);
+ locationsTable->setHorizontalHeaderLabels(labels);
+ locationsTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
+ locationsTable->horizontalHeader()->resizeSection(1, 180);
+
+ buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
+ | QDialogButtonBox::Cancel);
+
+ connect(formatComboBox, SIGNAL(activated(int)),
+ this, SLOT(updateLocationsTable()));
+ connect(scopeComboBox, SIGNAL(activated(int)),
+ this, SLOT(updateLocationsTable()));
+ connect(organizationComboBox->lineEdit(),
+ SIGNAL(editingFinished()),
+ this, SLOT(updateLocationsTable()));
+ connect(applicationComboBox->lineEdit(),
+ SIGNAL(editingFinished()),
+ this, SLOT(updateLocationsTable()));
+ connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
+ connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
+
+ QVBoxLayout *locationsLayout = new QVBoxLayout;
+ locationsLayout->addWidget(locationsTable);
+ locationsGroupBox->setLayout(locationsLayout);
+
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->addWidget(formatLabel, 0, 0);
+ mainLayout->addWidget(formatComboBox, 0, 1);
+ mainLayout->addWidget(scopeLabel, 1, 0);
+ mainLayout->addWidget(scopeComboBox, 1, 1);
+ mainLayout->addWidget(organizationLabel, 2, 0);
+ mainLayout->addWidget(organizationComboBox, 2, 1);
+ mainLayout->addWidget(applicationLabel, 3, 0);
+ mainLayout->addWidget(applicationComboBox, 3, 1);
+ mainLayout->addWidget(locationsGroupBox, 4, 0, 1, 2);
+ mainLayout->addWidget(buttonBox, 5, 0, 1, 2);
+ setLayout(mainLayout);
+
+ updateLocationsTable();
+
+ setWindowTitle(tr("Open Application Settings"));
+ resize(650, 400);
+}
+
+QSettings::Format LocationDialog::format() const
+{
+ if (formatComboBox->currentIndex() == 0)
+ return QSettings::NativeFormat;
+ else
+ return QSettings::IniFormat;
+}
+
+QSettings::Scope LocationDialog::scope() const
+{
+ if (scopeComboBox->currentIndex() == 0)
+ return QSettings::UserScope;
+ else
+ return QSettings::SystemScope;
+}
+
+QString LocationDialog::organization() const
+{
+ return organizationComboBox->currentText();
+}
+
+QString LocationDialog::application() const
+{
+ if (applicationComboBox->currentText() == tr("Any"))
+ return "";
+ else
+ return applicationComboBox->currentText();
+}
+
+void LocationDialog::updateLocationsTable()
+{
+ locationsTable->setUpdatesEnabled(false);
+ locationsTable->setRowCount(0);
+
+ for (int i = 0; i < 2; ++i) {
+ if (i == 0 && scope() == QSettings::SystemScope)
+ continue;
+
+ QSettings::Scope actualScope = (i == 0) ? QSettings::UserScope
+ : QSettings::SystemScope;
+ for (int j = 0; j < 2; ++j) {
+ if (j == 0 && application().isEmpty())
+ continue;
+
+ QString actualApplication;
+ if (j == 0)
+ actualApplication = application();
+ QSettings settings(format(), actualScope, organization(),
+ actualApplication);
+
+ int row = locationsTable->rowCount();
+ locationsTable->setRowCount(row + 1);
+
+ QTableWidgetItem *item0 = new QTableWidgetItem;
+ item0->setText(settings.fileName());
+
+ QTableWidgetItem *item1 = new QTableWidgetItem;
+ bool disable = (settings.childKeys().isEmpty()
+ && settings.childGroups().isEmpty());
+
+ if (row == 0) {
+ if (settings.isWritable()) {
+ item1->setText(tr("Read-write"));
+ disable = false;
+ } else {
+ item1->setText(tr("Read-only"));
+ }
+ buttonBox->button(QDialogButtonBox::Ok)->setDisabled(disable);
+ } else {
+ item1->setText(tr("Read-only fallback"));
+ }
+
+ if (disable) {
+ item0->setFlags(item0->flags() & ~Qt::ItemIsEnabled);
+ item1->setFlags(item1->flags() & ~Qt::ItemIsEnabled);
+ }
+
+ locationsTable->setItem(row, 0, item0);
+ locationsTable->setItem(row, 1, item1);
+ }
+ }
+ locationsTable->setUpdatesEnabled(true);
+}
diff --git a/examples/tools/settingseditor/locationdialog.h b/examples/tools/settingseditor/locationdialog.h
new file mode 100644
index 0000000000..3ea8359569
--- /dev/null
+++ b/examples/tools/settingseditor/locationdialog.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef LOCATIONDIALOG_H
+#define LOCATIONDIALOG_H
+
+#include <QDialog>
+#include <QSettings>
+
+QT_BEGIN_NAMESPACE
+class QComboBox;
+class QDialogButtonBox;
+class QGroupBox;
+class QLabel;
+class QTableWidget;
+QT_END_NAMESPACE
+
+class LocationDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ LocationDialog(QWidget *parent = 0);
+
+ QSettings::Format format() const;
+ QSettings::Scope scope() const;
+ QString organization() const;
+ QString application() const;
+
+private slots:
+ void updateLocationsTable();
+
+private:
+ QLabel *formatLabel;
+ QLabel *scopeLabel;
+ QLabel *organizationLabel;
+ QLabel *applicationLabel;
+ QComboBox *formatComboBox;
+ QComboBox *scopeComboBox;
+ QComboBox *organizationComboBox;
+ QComboBox *applicationComboBox;
+ QGroupBox *locationsGroupBox;
+ QTableWidget *locationsTable;
+ QDialogButtonBox *buttonBox;
+};
+
+#endif
diff --git a/examples/tools/settingseditor/main.cpp b/examples/tools/settingseditor/main.cpp
new file mode 100644
index 0000000000..4856752c8c
--- /dev/null
+++ b/examples/tools/settingseditor/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow mainWin;
+ mainWin.show();
+ return app.exec();
+}
diff --git a/examples/tools/settingseditor/mainwindow.cpp b/examples/tools/settingseditor/mainwindow.cpp
new file mode 100644
index 0000000000..0f48a5c390
--- /dev/null
+++ b/examples/tools/settingseditor/mainwindow.cpp
@@ -0,0 +1,223 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "locationdialog.h"
+#include "mainwindow.h"
+#include "settingstree.h"
+
+MainWindow::MainWindow()
+{
+ settingsTree = new SettingsTree;
+ setCentralWidget(settingsTree);
+
+ locationDialog = 0;
+
+ createActions();
+ createMenus();
+
+ autoRefreshAct->setChecked(true);
+ fallbacksAct->setChecked(true);
+
+ setWindowTitle(tr("Settings Editor"));
+ resize(500, 600);
+}
+
+void MainWindow::openSettings()
+{
+ if (!locationDialog)
+ locationDialog = new LocationDialog(this);
+
+ if (locationDialog->exec()) {
+ QSettings *settings = new QSettings(locationDialog->format(),
+ locationDialog->scope(),
+ locationDialog->organization(),
+ locationDialog->application());
+ setSettingsObject(settings);
+ fallbacksAct->setEnabled(true);
+ }
+}
+
+void MainWindow::openIniFile()
+{
+ QString fileName = QFileDialog::getOpenFileName(this, tr("Open INI File"),
+ "", tr("INI Files (*.ini *.conf)"));
+ if (!fileName.isEmpty()) {
+ QSettings *settings = new QSettings(fileName, QSettings::IniFormat);
+ setSettingsObject(settings);
+ fallbacksAct->setEnabled(false);
+ }
+}
+
+void MainWindow::openPropertyList()
+{
+ QString fileName = QFileDialog::getOpenFileName(this,
+ tr("Open Property List"),
+ "", tr("Property List Files (*.plist)"));
+ if (!fileName.isEmpty()) {
+ QSettings *settings = new QSettings(fileName, QSettings::NativeFormat);
+ setSettingsObject(settings);
+ fallbacksAct->setEnabled(false);
+ }
+}
+
+void MainWindow::openRegistryPath()
+{
+ QString path = QInputDialog::getText(this, tr("Open Registry Path"),
+ tr("Enter the path in the Windows registry:"),
+ QLineEdit::Normal, "HKEY_CURRENT_USER\\");
+ if (!path.isEmpty()) {
+ QSettings *settings = new QSettings(path, QSettings::NativeFormat);
+ setSettingsObject(settings);
+ fallbacksAct->setEnabled(false);
+ }
+}
+
+void MainWindow::about()
+{
+ QMessageBox::about(this, tr("About Settings Editor"),
+ tr("The <b>Settings Editor</b> example shows how to access "
+ "application settings using Qt."));
+}
+
+void MainWindow::createActions()
+{
+ openSettingsAct = new QAction(tr("&Open Application Settings..."), this);
+ openSettingsAct->setShortcut(tr("Ctrl+O"));
+ connect(openSettingsAct, SIGNAL(triggered()), this, SLOT(openSettings()));
+
+ openIniFileAct = new QAction(tr("Open I&NI File..."), this);
+ openIniFileAct->setShortcut(tr("Ctrl+N"));
+ connect(openIniFileAct, SIGNAL(triggered()), this, SLOT(openIniFile()));
+
+ openPropertyListAct = new QAction(tr("Open Mac &Property List..."), this);
+ openPropertyListAct->setShortcut(tr("Ctrl+P"));
+ connect(openPropertyListAct, SIGNAL(triggered()),
+ this, SLOT(openPropertyList()));
+
+ openRegistryPathAct = new QAction(tr("Open Windows &Registry Path..."),
+ this);
+ openRegistryPathAct->setShortcut(tr("Ctrl+G"));
+ connect(openRegistryPathAct, SIGNAL(triggered()),
+ this, SLOT(openRegistryPath()));
+
+ refreshAct = new QAction(tr("&Refresh"), this);
+ refreshAct->setShortcut(tr("Ctrl+R"));
+ refreshAct->setEnabled(false);
+ connect(refreshAct, SIGNAL(triggered()), settingsTree, SLOT(refresh()));
+
+ exitAct = new QAction(tr("E&xit"), this);
+ exitAct->setShortcut(tr("Ctrl+Q"));
+ connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
+
+ autoRefreshAct = new QAction(tr("&Auto-Refresh"), this);
+ autoRefreshAct->setShortcut(tr("Ctrl+A"));
+ autoRefreshAct->setCheckable(true);
+ autoRefreshAct->setEnabled(false);
+ connect(autoRefreshAct, SIGNAL(triggered(bool)),
+ settingsTree, SLOT(setAutoRefresh(bool)));
+ connect(autoRefreshAct, SIGNAL(triggered(bool)),
+ refreshAct, SLOT(setDisabled(bool)));
+
+ fallbacksAct = new QAction(tr("&Fallbacks"), this);
+ fallbacksAct->setShortcut(tr("Ctrl+F"));
+ fallbacksAct->setCheckable(true);
+ fallbacksAct->setEnabled(false);
+ connect(fallbacksAct, SIGNAL(triggered(bool)),
+ settingsTree, SLOT(setFallbacksEnabled(bool)));
+
+ aboutAct = new QAction(tr("&About"), this);
+ connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+
+ aboutQtAct = new QAction(tr("About &Qt"), this);
+ connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+
+#ifndef Q_WS_MAC
+ openPropertyListAct->setEnabled(false);
+#endif
+#ifndef Q_WS_WIN
+ openRegistryPathAct->setEnabled(false);
+#endif
+}
+
+void MainWindow::createMenus()
+{
+ fileMenu = menuBar()->addMenu(tr("&File"));
+ fileMenu->addAction(openSettingsAct);
+ fileMenu->addAction(openIniFileAct);
+ fileMenu->addAction(openPropertyListAct);
+ fileMenu->addAction(openRegistryPathAct);
+ fileMenu->addSeparator();
+ fileMenu->addAction(refreshAct);
+ fileMenu->addSeparator();
+ fileMenu->addAction(exitAct);
+
+ optionsMenu = menuBar()->addMenu(tr("&Options"));
+ optionsMenu->addAction(autoRefreshAct);
+ optionsMenu->addAction(fallbacksAct);
+
+ menuBar()->addSeparator();
+
+ helpMenu = menuBar()->addMenu(tr("&Help"));
+ helpMenu->addAction(aboutAct);
+ helpMenu->addAction(aboutQtAct);
+}
+
+void MainWindow::setSettingsObject(QSettings *settings)
+{
+ settings->setFallbacksEnabled(fallbacksAct->isChecked());
+ settingsTree->setSettingsObject(settings);
+
+ refreshAct->setEnabled(true);
+ autoRefreshAct->setEnabled(true);
+
+ QString niceName = settings->fileName();
+ niceName.replace("\\", "/");
+ int pos = niceName.lastIndexOf("/");
+ if (pos != -1)
+ niceName.remove(0, pos + 1);
+
+ if (!settings->isWritable())
+ niceName = tr("%1 (read only)").arg(niceName);
+
+ setWindowTitle(tr("%1 - %2").arg(niceName).arg(tr("Settings Editor")));
+}
diff --git a/examples/tools/settingseditor/mainwindow.h b/examples/tools/settingseditor/mainwindow.h
new file mode 100644
index 0000000000..749602d78b
--- /dev/null
+++ b/examples/tools/settingseditor/mainwindow.h
@@ -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$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QMenu;
+class QSettings;
+QT_END_NAMESPACE
+class LocationDialog;
+class SettingsTree;
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+private slots:
+ void openSettings();
+ void openIniFile();
+ void openPropertyList();
+ void openRegistryPath();
+ void about();
+
+private:
+ void createActions();
+ void createMenus();
+ void setSettingsObject(QSettings *settings);
+
+ SettingsTree *settingsTree;
+ LocationDialog *locationDialog;
+
+ QMenu *fileMenu;
+ QMenu *optionsMenu;
+ QMenu *helpMenu;
+ QAction *openSettingsAct;
+ QAction *openIniFileAct;
+ QAction *openPropertyListAct;
+ QAction *openRegistryPathAct;
+ QAction *refreshAct;
+ QAction *exitAct;
+ QAction *autoRefreshAct;
+ QAction *fallbacksAct;
+ QAction *aboutAct;
+ QAction *aboutQtAct;
+};
+
+#endif
diff --git a/examples/tools/settingseditor/settingseditor.pro b/examples/tools/settingseditor/settingseditor.pro
new file mode 100644
index 0000000000..c6838bc73f
--- /dev/null
+++ b/examples/tools/settingseditor/settingseditor.pro
@@ -0,0 +1,17 @@
+HEADERS = locationdialog.h \
+ mainwindow.h \
+ settingstree.h \
+ variantdelegate.h
+SOURCES = locationdialog.cpp \
+ main.cpp \
+ mainwindow.cpp \
+ settingstree.cpp \
+ variantdelegate.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/tools/settingseditor
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS settingseditor.pro inifiles
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/settingseditor
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/tools/settingseditor/settingstree.cpp b/examples/tools/settingseditor/settingstree.cpp
new file mode 100644
index 0000000000..82d32fdb0d
--- /dev/null
+++ b/examples/tools/settingseditor/settingstree.cpp
@@ -0,0 +1,263 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "settingstree.h"
+#include "variantdelegate.h"
+
+SettingsTree::SettingsTree(QWidget *parent)
+ : QTreeWidget(parent)
+{
+ setItemDelegate(new VariantDelegate(this));
+
+ QStringList labels;
+ labels << tr("Setting") << tr("Type") << tr("Value");
+ setHeaderLabels(labels);
+ header()->setResizeMode(0, QHeaderView::Stretch);
+ header()->setResizeMode(2, QHeaderView::Stretch);
+
+ settings = 0;
+ refreshTimer.setInterval(2000);
+ autoRefresh = false;
+
+ groupIcon.addPixmap(style()->standardPixmap(QStyle::SP_DirClosedIcon),
+ QIcon::Normal, QIcon::Off);
+ groupIcon.addPixmap(style()->standardPixmap(QStyle::SP_DirOpenIcon),
+ QIcon::Normal, QIcon::On);
+ keyIcon.addPixmap(style()->standardPixmap(QStyle::SP_FileIcon));
+
+ connect(&refreshTimer, SIGNAL(timeout()), this, SLOT(maybeRefresh()));
+}
+
+void SettingsTree::setSettingsObject(QSettings *settings)
+{
+ delete this->settings;
+ this->settings = settings;
+ clear();
+
+ if (settings) {
+ settings->setParent(this);
+ refresh();
+ if (autoRefresh)
+ refreshTimer.start();
+ } else {
+ refreshTimer.stop();
+ }
+}
+
+QSize SettingsTree::sizeHint() const
+{
+ return QSize(800, 600);
+}
+
+void SettingsTree::setAutoRefresh(bool autoRefresh)
+{
+ this->autoRefresh = autoRefresh;
+ if (settings) {
+ if (autoRefresh) {
+ maybeRefresh();
+ refreshTimer.start();
+ } else {
+ refreshTimer.stop();
+ }
+ }
+}
+
+void SettingsTree::setFallbacksEnabled(bool enabled)
+{
+ if (settings) {
+ settings->setFallbacksEnabled(enabled);
+ refresh();
+ }
+}
+
+void SettingsTree::maybeRefresh()
+{
+ if (state() != EditingState)
+ refresh();
+}
+
+void SettingsTree::refresh()
+{
+ if (!settings)
+ return;
+
+ disconnect(this, SIGNAL(itemChanged(QTreeWidgetItem *, int)),
+ this, SLOT(updateSetting(QTreeWidgetItem *)));
+
+ settings->sync();
+ updateChildItems(0);
+
+ connect(this, SIGNAL(itemChanged(QTreeWidgetItem *, int)),
+ this, SLOT(updateSetting(QTreeWidgetItem *)));
+}
+
+bool SettingsTree::event(QEvent *event)
+{
+ if (event->type() == QEvent::WindowActivate) {
+ if (isActiveWindow() && autoRefresh)
+ maybeRefresh();
+ }
+ return QTreeWidget::event(event);
+}
+
+void SettingsTree::updateSetting(QTreeWidgetItem *item)
+{
+ QString key = item->text(0);
+ QTreeWidgetItem *ancestor = item->parent();
+ while (ancestor) {
+ key.prepend(ancestor->text(0) + "/");
+ ancestor = ancestor->parent();
+ }
+
+ settings->setValue(key, item->data(2, Qt::UserRole));
+ if (autoRefresh)
+ refresh();
+}
+
+void SettingsTree::updateChildItems(QTreeWidgetItem *parent)
+{
+ int dividerIndex = 0;
+
+ foreach (QString group, settings->childGroups()) {
+ QTreeWidgetItem *child;
+ int childIndex = findChild(parent, group, dividerIndex);
+ if (childIndex != -1) {
+ child = childAt(parent, childIndex);
+ child->setText(1, "");
+ child->setText(2, "");
+ child->setData(2, Qt::UserRole, QVariant());
+ moveItemForward(parent, childIndex, dividerIndex);
+ } else {
+ child = createItem(group, parent, dividerIndex);
+ }
+ child->setIcon(0, groupIcon);
+ ++dividerIndex;
+
+ settings->beginGroup(group);
+ updateChildItems(child);
+ settings->endGroup();
+ }
+
+ foreach (QString key, settings->childKeys()) {
+ QTreeWidgetItem *child;
+ int childIndex = findChild(parent, key, 0);
+
+ if (childIndex == -1 || childIndex >= dividerIndex) {
+ if (childIndex != -1) {
+ child = childAt(parent, childIndex);
+ for (int i = 0; i < child->childCount(); ++i)
+ delete childAt(child, i);
+ moveItemForward(parent, childIndex, dividerIndex);
+ } else {
+ child = createItem(key, parent, dividerIndex);
+ }
+ child->setIcon(0, keyIcon);
+ ++dividerIndex;
+ } else {
+ child = childAt(parent, childIndex);
+ }
+
+ QVariant value = settings->value(key);
+ if (value.type() == QVariant::Invalid) {
+ child->setText(1, "Invalid");
+ } else {
+ child->setText(1, value.typeName());
+ }
+ child->setText(2, VariantDelegate::displayText(value));
+ child->setData(2, Qt::UserRole, value);
+ }
+
+ while (dividerIndex < childCount(parent))
+ delete childAt(parent, dividerIndex);
+}
+
+QTreeWidgetItem *SettingsTree::createItem(const QString &text,
+ QTreeWidgetItem *parent, int index)
+{
+ QTreeWidgetItem *after = 0;
+ if (index != 0)
+ after = childAt(parent, index - 1);
+
+ QTreeWidgetItem *item;
+ if (parent)
+ item = new QTreeWidgetItem(parent, after);
+ else
+ item = new QTreeWidgetItem(this, after);
+
+ item->setText(0, text);
+ item->setFlags(item->flags() | Qt::ItemIsEditable);
+ return item;
+}
+
+QTreeWidgetItem *SettingsTree::childAt(QTreeWidgetItem *parent, int index)
+{
+ if (parent)
+ return parent->child(index);
+ else
+ return topLevelItem(index);
+}
+
+int SettingsTree::childCount(QTreeWidgetItem *parent)
+{
+ if (parent)
+ return parent->childCount();
+ else
+ return topLevelItemCount();
+}
+
+int SettingsTree::findChild(QTreeWidgetItem *parent, const QString &text,
+ int startIndex)
+{
+ for (int i = startIndex; i < childCount(parent); ++i) {
+ if (childAt(parent, i)->text(0) == text)
+ return i;
+ }
+ return -1;
+}
+
+void SettingsTree::moveItemForward(QTreeWidgetItem *parent, int oldIndex,
+ int newIndex)
+{
+ for (int i = 0; i < oldIndex - newIndex; ++i)
+ delete childAt(parent, newIndex);
+}
diff --git a/examples/tools/settingseditor/settingstree.h b/examples/tools/settingseditor/settingstree.h
new file mode 100644
index 0000000000..f82034b710
--- /dev/null
+++ b/examples/tools/settingseditor/settingstree.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SETTINGSTREE_H
+#define SETTINGSTREE_H
+
+#include <QIcon>
+#include <QTimer>
+#include <QTreeWidget>
+
+QT_BEGIN_NAMESPACE
+class QSettings;
+QT_END_NAMESPACE
+
+class SettingsTree : public QTreeWidget
+{
+ Q_OBJECT
+
+public:
+ SettingsTree(QWidget *parent = 0);
+
+ void setSettingsObject(QSettings *settings);
+ QSize sizeHint() const;
+
+public slots:
+ void setAutoRefresh(bool autoRefresh);
+ void setFallbacksEnabled(bool enabled);
+ void maybeRefresh();
+ void refresh();
+
+protected:
+ bool event(QEvent *event);
+
+private slots:
+ void updateSetting(QTreeWidgetItem *item);
+
+private:
+ void updateChildItems(QTreeWidgetItem *parent);
+ QTreeWidgetItem *createItem(const QString &text, QTreeWidgetItem *parent,
+ int index);
+ QTreeWidgetItem *childAt(QTreeWidgetItem *parent, int index);
+ int childCount(QTreeWidgetItem *parent);
+ int findChild(QTreeWidgetItem *parent, const QString &text, int startIndex);
+ void moveItemForward(QTreeWidgetItem *parent, int oldIndex, int newIndex);
+
+ QSettings *settings;
+ QTimer refreshTimer;
+ bool autoRefresh;
+ QIcon groupIcon;
+ QIcon keyIcon;
+};
+
+#endif
diff --git a/examples/tools/settingseditor/variantdelegate.cpp b/examples/tools/settingseditor/variantdelegate.cpp
new file mode 100644
index 0000000000..937a0e14ab
--- /dev/null
+++ b/examples/tools/settingseditor/variantdelegate.cpp
@@ -0,0 +1,317 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "variantdelegate.h"
+
+VariantDelegate::VariantDelegate(QObject *parent)
+ : QItemDelegate(parent)
+{
+ boolExp.setPattern("true|false");
+ boolExp.setCaseSensitivity(Qt::CaseInsensitive);
+
+ byteArrayExp.setPattern("[\\x00-\\xff]*");
+ charExp.setPattern(".");
+ colorExp.setPattern("\\(([0-9]*),([0-9]*),([0-9]*),([0-9]*)\\)");
+ doubleExp.setPattern("");
+ pointExp.setPattern("\\((-?[0-9]*),(-?[0-9]*)\\)");
+ rectExp.setPattern("\\((-?[0-9]*),(-?[0-9]*),(-?[0-9]*),(-?[0-9]*)\\)");
+ signedIntegerExp.setPattern("-?[0-9]*");
+ sizeExp = pointExp;
+ unsignedIntegerExp.setPattern("[0-9]*");
+
+ dateExp.setPattern("([0-9]{,4})-([0-9]{,2})-([0-9]{,2})");
+ timeExp.setPattern("([0-9]{,2}):([0-9]{,2}):([0-9]{,2})");
+ dateTimeExp.setPattern(dateExp.pattern() + "T" + timeExp.pattern());
+}
+
+void VariantDelegate::paint(QPainter *painter,
+ const QStyleOptionViewItem &option,
+ const QModelIndex &index) const
+{
+ if (index.column() == 2) {
+ QVariant value = index.model()->data(index, Qt::UserRole);
+ if (!isSupportedType(value.type())) {
+ QStyleOptionViewItem myOption = option;
+ myOption.state &= ~QStyle::State_Enabled;
+ QItemDelegate::paint(painter, myOption, index);
+ return;
+ }
+ }
+
+ QItemDelegate::paint(painter, option, index);
+}
+
+QWidget *VariantDelegate::createEditor(QWidget *parent,
+ const QStyleOptionViewItem & /* option */,
+ const QModelIndex &index) const
+{
+ if (index.column() != 2)
+ return 0;
+
+ QVariant originalValue = index.model()->data(index, Qt::UserRole);
+ if (!isSupportedType(originalValue.type()))
+ return 0;
+
+ QLineEdit *lineEdit = new QLineEdit(parent);
+ lineEdit->setFrame(false);
+
+ QRegExp regExp;
+
+ switch (originalValue.type()) {
+ case QVariant::Bool:
+ regExp = boolExp;
+ break;
+ case QVariant::ByteArray:
+ regExp = byteArrayExp;
+ break;
+ case QVariant::Char:
+ regExp = charExp;
+ break;
+ case QVariant::Color:
+ regExp = colorExp;
+ break;
+ case QVariant::Date:
+ regExp = dateExp;
+ break;
+ case QVariant::DateTime:
+ regExp = dateTimeExp;
+ break;
+ case QVariant::Double:
+ regExp = doubleExp;
+ break;
+ case QVariant::Int:
+ case QVariant::LongLong:
+ regExp = signedIntegerExp;
+ break;
+ case QVariant::Point:
+ regExp = pointExp;
+ break;
+ case QVariant::Rect:
+ regExp = rectExp;
+ break;
+ case QVariant::Size:
+ regExp = sizeExp;
+ break;
+ case QVariant::Time:
+ regExp = timeExp;
+ break;
+ case QVariant::UInt:
+ case QVariant::ULongLong:
+ regExp = unsignedIntegerExp;
+ break;
+ default:
+ ;
+ }
+
+ if (!regExp.isEmpty()) {
+ QValidator *validator = new QRegExpValidator(regExp, lineEdit);
+ lineEdit->setValidator(validator);
+ }
+
+ return lineEdit;
+}
+
+void VariantDelegate::setEditorData(QWidget *editor,
+ const QModelIndex &index) const
+{
+ QVariant value = index.model()->data(index, Qt::UserRole);
+ if (QLineEdit *lineEdit = qobject_cast<QLineEdit *>(editor))
+ lineEdit->setText(displayText(value));
+}
+
+void VariantDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
+ const QModelIndex &index) const
+{
+ QLineEdit *lineEdit = qobject_cast<QLineEdit *>(editor);
+ if (!lineEdit->isModified())
+ return;
+
+ QString text = lineEdit->text();
+ const QValidator *validator = lineEdit->validator();
+ if (validator) {
+ int pos;
+ if (validator->validate(text, pos) != QValidator::Acceptable)
+ return;
+ }
+
+ QVariant originalValue = index.model()->data(index, Qt::UserRole);
+ QVariant value;
+
+ switch (originalValue.type()) {
+ case QVariant::Char:
+ value = text.at(0);
+ break;
+ case QVariant::Color:
+ colorExp.exactMatch(text);
+ value = QColor(qMin(colorExp.cap(1).toInt(), 255),
+ qMin(colorExp.cap(2).toInt(), 255),
+ qMin(colorExp.cap(3).toInt(), 255),
+ qMin(colorExp.cap(4).toInt(), 255));
+ break;
+ case QVariant::Date:
+ {
+ QDate date = QDate::fromString(text, Qt::ISODate);
+ if (!date.isValid())
+ return;
+ value = date;
+ }
+ break;
+ case QVariant::DateTime:
+ {
+ QDateTime dateTime = QDateTime::fromString(text, Qt::ISODate);
+ if (!dateTime.isValid())
+ return;
+ value = dateTime;
+ }
+ break;
+ case QVariant::Point:
+ pointExp.exactMatch(text);
+ value = QPoint(pointExp.cap(1).toInt(), pointExp.cap(2).toInt());
+ break;
+ case QVariant::Rect:
+ rectExp.exactMatch(text);
+ value = QRect(rectExp.cap(1).toInt(), rectExp.cap(2).toInt(),
+ rectExp.cap(3).toInt(), rectExp.cap(4).toInt());
+ break;
+ case QVariant::Size:
+ sizeExp.exactMatch(text);
+ value = QSize(sizeExp.cap(1).toInt(), sizeExp.cap(2).toInt());
+ break;
+ case QVariant::StringList:
+ value = text.split(",");
+ break;
+ case QVariant::Time:
+ {
+ QTime time = QTime::fromString(text, Qt::ISODate);
+ if (!time.isValid())
+ return;
+ value = time;
+ }
+ break;
+ default:
+ value = text;
+ value.convert(originalValue.type());
+ }
+
+ model->setData(index, displayText(value), Qt::DisplayRole);
+ model->setData(index, value, Qt::UserRole);
+}
+
+bool VariantDelegate::isSupportedType(QVariant::Type type)
+{
+ switch (type) {
+ case QVariant::Bool:
+ case QVariant::ByteArray:
+ case QVariant::Char:
+ case QVariant::Color:
+ case QVariant::Date:
+ case QVariant::DateTime:
+ case QVariant::Double:
+ case QVariant::Int:
+ case QVariant::LongLong:
+ case QVariant::Point:
+ case QVariant::Rect:
+ case QVariant::Size:
+ case QVariant::String:
+ case QVariant::StringList:
+ case QVariant::Time:
+ case QVariant::UInt:
+ case QVariant::ULongLong:
+ return true;
+ default:
+ return false;
+ }
+}
+
+QString VariantDelegate::displayText(const QVariant &value)
+{
+ switch (value.type()) {
+ case QVariant::Bool:
+ case QVariant::ByteArray:
+ case QVariant::Char:
+ case QVariant::Double:
+ case QVariant::Int:
+ case QVariant::LongLong:
+ case QVariant::String:
+ case QVariant::UInt:
+ case QVariant::ULongLong:
+ return value.toString();
+ case QVariant::Color:
+ {
+ QColor color = qvariant_cast<QColor>(value);
+ return QString("(%1,%2,%3,%4)")
+ .arg(color.red()).arg(color.green())
+ .arg(color.blue()).arg(color.alpha());
+ }
+ case QVariant::Date:
+ return value.toDate().toString(Qt::ISODate);
+ case QVariant::DateTime:
+ return value.toDateTime().toString(Qt::ISODate);
+ case QVariant::Invalid:
+ return "<Invalid>";
+ case QVariant::Point:
+ {
+ QPoint point = value.toPoint();
+ return QString("(%1,%2)").arg(point.x()).arg(point.y());
+ }
+ case QVariant::Rect:
+ {
+ QRect rect = value.toRect();
+ return QString("(%1,%2,%3,%4)")
+ .arg(rect.x()).arg(rect.y())
+ .arg(rect.width()).arg(rect.height());
+ }
+ case QVariant::Size:
+ {
+ QSize size = value.toSize();
+ return QString("(%1,%2)").arg(size.width()).arg(size.height());
+ }
+ case QVariant::StringList:
+ return value.toStringList().join(",");
+ case QVariant::Time:
+ return value.toTime().toString(Qt::ISODate);
+ default:
+ break;
+ }
+ return QString("<%1>").arg(value.typeName());
+}
diff --git a/examples/tools/settingseditor/variantdelegate.h b/examples/tools/settingseditor/variantdelegate.h
new file mode 100644
index 0000000000..60997f7bc2
--- /dev/null
+++ b/examples/tools/settingseditor/variantdelegate.h
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef VARIANTDELEGATE_H
+#define VARIANTDELEGATE_H
+
+#include <QItemDelegate>
+#include <QRegExp>
+
+class VariantDelegate : public QItemDelegate
+{
+ Q_OBJECT
+
+public:
+ VariantDelegate(QObject *parent = 0);
+
+ void paint(QPainter *painter, const QStyleOptionViewItem &option,
+ const QModelIndex &index) const;
+ QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
+ const QModelIndex &index) const;
+ void setEditorData(QWidget *editor, const QModelIndex &index) const;
+ void setModelData(QWidget *editor, QAbstractItemModel *model,
+ const QModelIndex &index) const;
+
+ static bool isSupportedType(QVariant::Type type);
+ static QString displayText(const QVariant &value);
+
+private:
+ mutable QRegExp boolExp;
+ mutable QRegExp byteArrayExp;
+ mutable QRegExp charExp;
+ mutable QRegExp colorExp;
+ mutable QRegExp dateExp;
+ mutable QRegExp dateTimeExp;
+ mutable QRegExp doubleExp;
+ mutable QRegExp pointExp;
+ mutable QRegExp rectExp;
+ mutable QRegExp signedIntegerExp;
+ mutable QRegExp sizeExp;
+ mutable QRegExp timeExp;
+ mutable QRegExp unsignedIntegerExp;
+};
+
+#endif
diff --git a/examples/tools/styleplugin/plugin/plugin.pro b/examples/tools/styleplugin/plugin/plugin.pro
new file mode 100644
index 0000000000..2a36d51b34
--- /dev/null
+++ b/examples/tools/styleplugin/plugin/plugin.pro
@@ -0,0 +1,25 @@
+#! [0]
+TEMPLATE = lib
+CONFIG += plugin
+HEADERS = simplestyle.h \
+ simplestyleplugin.h
+SOURCES = simplestyle.cpp \
+ simplestyleplugin.cpp
+TARGET = simplestyleplugin
+#! [0]
+win32 {
+ debug:DESTDIR = ../debug/styles/
+ release:DESTDIR = ../release/styles/
+} else {
+ DESTDIR = ../styles/
+}
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/tools/styleplugin/styles
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS plugin.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/styleplugin/plugin
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
+
+symbian:TARGET.EPOCALLOWDLLDATA = 1
diff --git a/examples/tools/styleplugin/plugin/simplestyle.cpp b/examples/tools/styleplugin/plugin/simplestyle.cpp
new file mode 100644
index 0000000000..900c772881
--- /dev/null
+++ b/examples/tools/styleplugin/plugin/simplestyle.cpp
@@ -0,0 +1,49 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "simplestyle.h"
+
+void SimpleStyle::polish(QPalette &palette)
+{
+ palette.setBrush(QPalette::Button, Qt::red);
+}
diff --git a/examples/tools/styleplugin/plugin/simplestyle.h b/examples/tools/styleplugin/plugin/simplestyle.h
new file mode 100644
index 0000000000..f4c499cfa9
--- /dev/null
+++ b/examples/tools/styleplugin/plugin/simplestyle.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SIMPLESTYLE_H
+#define SIMPLESTYLE_H
+
+#include <QWindowsStyle>
+
+QT_BEGIN_NAMESPACE
+class QPalette;
+QT_END_NAMESPACE
+
+class SimpleStyle : public QWindowsStyle
+{
+ Q_OBJECT
+
+public:
+ SimpleStyle() {};
+
+ void polish(QPalette &palette);
+};
+
+#endif
diff --git a/examples/tools/styleplugin/plugin/simplestyleplugin.cpp b/examples/tools/styleplugin/plugin/simplestyleplugin.cpp
new file mode 100644
index 0000000000..6845c814af
--- /dev/null
+++ b/examples/tools/styleplugin/plugin/simplestyleplugin.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 <QtGui>
+
+#include "simplestyleplugin.h"
+#include "simplestyle.h"
+
+//! [0]
+QStringList SimpleStylePlugin::keys() const
+{
+ return QStringList() << "SimpleStyle";
+}
+//! [0]
+
+//! [1]
+QStyle *SimpleStylePlugin::create(const QString &key)
+{
+ if (key.toLower() == "simplestyle")
+ return new SimpleStyle;
+ return 0;
+}
+//! [1]
+
+QT_BEGIN_NAMESPACE
+Q_EXPORT_PLUGIN2(simplestyleplugin, SimpleStylePlugin)
+QT_END_NAMESPACE
diff --git a/examples/tools/styleplugin/plugin/simplestyleplugin.h b/examples/tools/styleplugin/plugin/simplestyleplugin.h
new file mode 100644
index 0000000000..106c4a909c
--- /dev/null
+++ b/examples/tools/styleplugin/plugin/simplestyleplugin.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SIMPLESTYLEPLUGIN_H
+#define SIMPLESTYLEPLUGIN_H
+
+#include <QStylePlugin>
+
+QT_BEGIN_NAMESPACE
+class QStringList;
+class QStyle;
+QT_END_NAMESPACE
+
+//! [0]
+class SimpleStylePlugin : public QStylePlugin
+{
+ Q_OBJECT
+
+public:
+ SimpleStylePlugin() {};
+
+ QStringList keys() const;
+ QStyle *create(const QString &key);
+};
+//! [0]
+
+#endif
diff --git a/examples/tools/styleplugin/styleplugin.pro b/examples/tools/styleplugin/styleplugin.pro
new file mode 100644
index 0000000000..74f77b5883
--- /dev/null
+++ b/examples/tools/styleplugin/styleplugin.pro
@@ -0,0 +1,11 @@
+TEMPLATE = subdirs
+SUBDIRS = stylewindow \
+ plugin
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/tools/styleplugin
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS styleplugin.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/styleplugin
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/tools/styleplugin/stylewindow/main.cpp b/examples/tools/styleplugin/stylewindow/main.cpp
new file mode 100644
index 0000000000..b6e69efd01
--- /dev/null
+++ b/examples/tools/styleplugin/stylewindow/main.cpp
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "stylewindow.h"
+
+//! [0]
+int main(int argv, char *args[])
+{
+ QApplication app(argv, args);
+ QApplication::setStyle(QStyleFactory::create("simplestyle"));
+
+ StyleWindow window;
+ window.resize(200, 50);
+ window.show();
+
+ return app.exec();
+}
+//! [0]
diff --git a/examples/tools/styleplugin/stylewindow/stylewindow.cpp b/examples/tools/styleplugin/stylewindow/stylewindow.cpp
new file mode 100644
index 0000000000..8a813baee0
--- /dev/null
+++ b/examples/tools/styleplugin/stylewindow/stylewindow.cpp
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "stylewindow.h"
+
+StyleWindow::StyleWindow()
+{
+ QPushButton *styledButton = new QPushButton(tr("Big Red Button"));
+
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(styledButton);
+
+ QGroupBox *styleBox = new QGroupBox(tr("A simple style button"));
+ styleBox->setLayout(layout);
+
+ QGridLayout *outerLayout = new QGridLayout;
+ outerLayout->addWidget(styleBox, 0, 0);
+ setLayout(outerLayout);
+
+ setWindowTitle(tr("Style Plugin Example"));
+}
diff --git a/examples/tools/styleplugin/stylewindow/stylewindow.h b/examples/tools/styleplugin/stylewindow/stylewindow.h
new file mode 100644
index 0000000000..5eba7513f3
--- /dev/null
+++ b/examples/tools/styleplugin/stylewindow/stylewindow.h
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef STYLEWINDOW_H
+#define STYLEWINDOW_H
+
+#include <QWidget>
+
+class StyleWindow : public QWidget
+{
+ Q_OBJECT
+
+public:
+ StyleWindow();
+};
+
+#endif
diff --git a/examples/tools/styleplugin/stylewindow/stylewindow.pro b/examples/tools/styleplugin/stylewindow/stylewindow.pro
new file mode 100644
index 0000000000..df68168387
--- /dev/null
+++ b/examples/tools/styleplugin/stylewindow/stylewindow.pro
@@ -0,0 +1,19 @@
+HEADERS = stylewindow.h
+SOURCES = stylewindow.cpp \
+ main.cpp
+
+TARGET = styleplugin
+win32 {
+ debug:DESTDIR = ../debug/
+ release:DESTDIR = ../release/
+} else {
+ DESTDIR = ../
+}
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/tools/styleplugin
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS stylewindow.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/styleplugin/stylewindow
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/tools/tools.pro b/examples/tools/tools.pro
new file mode 100644
index 0000000000..17a3ea2fa4
--- /dev/null
+++ b/examples/tools/tools.pro
@@ -0,0 +1,24 @@
+TEMPLATE = subdirs
+CONFIG += ordered
+SUBDIRS = codecs \
+ completer \
+ customcompleter \
+ echoplugin \
+ i18n \
+ plugandpaintplugins \
+ plugandpaint \
+ regexp \
+ settingseditor \
+ styleplugin \
+ treemodelcompleter \
+ undoframework
+
+plugandpaint.depends = plugandpaintplugins
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/tools
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS tools.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/tools/treemodelcompleter/main.cpp b/examples/tools/treemodelcompleter/main.cpp
new file mode 100644
index 0000000000..982575e77a
--- /dev/null
+++ b/examples/tools/treemodelcompleter/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "mainwindow.h"
+
+//! [0]
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(treemodelcompleter);
+
+ QApplication app(argc, argv);
+ MainWindow window;
+ window.show();
+ return app.exec();
+}
+//! [0]
diff --git a/examples/tools/treemodelcompleter/mainwindow.cpp b/examples/tools/treemodelcompleter/mainwindow.cpp
new file mode 100644
index 0000000000..9f69e8017d
--- /dev/null
+++ b/examples/tools/treemodelcompleter/mainwindow.cpp
@@ -0,0 +1,247 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "treemodelcompleter.h"
+#include "mainwindow.h"
+
+//! [0]
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent), completer(0), lineEdit(0)
+{
+ createMenu();
+
+ completer = new TreeModelCompleter(this);
+ completer->setModel(modelFromFile(":/resources/treemodel.txt"));
+ completer->setSeparator(QLatin1String("."));
+ QObject::connect(completer, SIGNAL(highlighted(const QModelIndex&)),
+ this, SLOT(highlight(const QModelIndex&)));
+
+ QWidget *centralWidget = new QWidget;
+
+ QLabel *modelLabel = new QLabel;
+ modelLabel->setText(tr("Tree Model<br>(Double click items to edit)"));
+
+ QLabel *modeLabel = new QLabel;
+ modeLabel->setText(tr("Completion Mode"));
+ modeCombo = new QComboBox;
+ modeCombo->addItem(tr("Inline"));
+ modeCombo->addItem(tr("Filtered Popup"));
+ modeCombo->addItem(tr("Unfiltered Popup"));
+ modeCombo->setCurrentIndex(1);
+
+ QLabel *caseLabel = new QLabel;
+ caseLabel->setText(tr("Case Sensitivity"));
+ caseCombo = new QComboBox;
+ caseCombo->addItem(tr("Case Insensitive"));
+ caseCombo->addItem(tr("Case Sensitive"));
+ caseCombo->setCurrentIndex(0);
+//! [0]
+
+//! [1]
+ QLabel *separatorLabel = new QLabel;
+ separatorLabel->setText(tr("Tree Separator"));
+
+ QLineEdit *separatorLineEdit = new QLineEdit;
+ separatorLineEdit->setText(completer->separator());
+ connect(separatorLineEdit, SIGNAL(textChanged(const QString&)),
+ completer, SLOT(setSeparator(const QString&)));
+
+ QCheckBox *wrapCheckBox = new QCheckBox;
+ wrapCheckBox->setText(tr("Wrap around completions"));
+ wrapCheckBox->setChecked(completer->wrapAround());
+ connect(wrapCheckBox, SIGNAL(clicked(bool)), completer, SLOT(setWrapAround(bool)));
+
+ contentsLabel = new QLabel;
+ contentsLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+ connect(separatorLineEdit, SIGNAL(textChanged(const QString&)),
+ this, SLOT(updateContentsLabel(const QString&)));
+
+ treeView = new QTreeView;
+ treeView->setModel(completer->model());
+ treeView->header()->hide();
+ treeView->expandAll();
+//! [1]
+
+//! [2]
+ connect(modeCombo, SIGNAL(activated(int)), this, SLOT(changeMode(int)));
+ connect(caseCombo, SIGNAL(activated(int)), this, SLOT(changeCase(int)));
+
+ lineEdit = new QLineEdit;
+ lineEdit->setCompleter(completer);
+//! [2]
+
+//! [3]
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(modelLabel, 0, 0); layout->addWidget(treeView, 0, 1);
+ layout->addWidget(modeLabel, 1, 0); layout->addWidget(modeCombo, 1, 1);
+ layout->addWidget(caseLabel, 2, 0); layout->addWidget(caseCombo, 2, 1);
+ layout->addWidget(separatorLabel, 3, 0); layout->addWidget(separatorLineEdit, 3, 1);
+ layout->addWidget(wrapCheckBox, 4, 0);
+ layout->addWidget(contentsLabel, 5, 0, 1, 2);
+ layout->addWidget(lineEdit, 6, 0, 1, 2);
+ centralWidget->setLayout(layout);
+ setCentralWidget(centralWidget);
+
+ changeCase(caseCombo->currentIndex());
+ changeMode(modeCombo->currentIndex());
+
+ setWindowTitle(tr("Tree Model Completer"));
+ lineEdit->setFocus();
+}
+//! [3]
+
+//! [4]
+void MainWindow::createMenu()
+{
+ QAction *exitAction = new QAction(tr("Exit"), this);
+ QAction *aboutAct = new QAction(tr("About"), this);
+ QAction *aboutQtAct = new QAction(tr("About Qt"), this);
+
+ connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
+ connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+ connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+
+ QMenu* fileMenu = menuBar()->addMenu(tr("File"));
+ fileMenu->addAction(exitAction);
+
+ QMenu* helpMenu = menuBar()->addMenu(tr("About"));
+ helpMenu->addAction(aboutAct);
+ helpMenu->addAction(aboutQtAct);
+}
+//! [4]
+
+//! [5]
+void MainWindow::changeMode(int index)
+{
+ QCompleter::CompletionMode mode;
+ if (index == 0)
+ mode = QCompleter::InlineCompletion;
+ else if (index == 1)
+ mode = QCompleter::PopupCompletion;
+ else
+ mode = QCompleter::UnfilteredPopupCompletion;
+
+ completer->setCompletionMode(mode);
+}
+//! [5]
+
+QAbstractItemModel *MainWindow::modelFromFile(const QString& fileName)
+{
+ QFile file(fileName);
+ if (!file.open(QFile::ReadOnly))
+ return new QStringListModel(completer);
+
+#ifndef QT_NO_CURSOR
+ QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
+#endif
+ QStringList words;
+
+ QStandardItemModel *model = new QStandardItemModel(completer);
+ QVector<QStandardItem *> parents(10);
+ parents[0] = model->invisibleRootItem();
+
+ while (!file.atEnd()) {
+ QString line = file.readLine();
+ QString trimmedLine = line.trimmed();
+ if (line.isEmpty() || trimmedLine.isEmpty())
+ continue;
+
+ QRegExp re("^\\s+");
+ int nonws = re.indexIn(line);
+ int level = 0;
+ if (nonws == -1) {
+ level = 0;
+ } else {
+ if (line.startsWith("\t")) {
+ level = re.cap(0).length();
+ } else {
+ level = re.cap(0).length()/4;
+ }
+ }
+
+ if (level+1 >= parents.size())
+ parents.resize(parents.size()*2);
+
+ QStandardItem *item = new QStandardItem;
+ item->setText(trimmedLine);
+ parents[level]->appendRow(item);
+ parents[level+1] = item;
+ }
+
+#ifndef QT_NO_CURSOR
+ QApplication::restoreOverrideCursor();
+#endif
+
+ return model;
+}
+
+void MainWindow::highlight(const QModelIndex &index)
+{
+ QAbstractItemModel *completionModel = completer->completionModel();
+ QAbstractProxyModel *proxy = qobject_cast<QAbstractProxyModel *>(completionModel);
+ if (!proxy)
+ return;
+ QModelIndex sourceIndex = proxy->mapToSource(index);
+ treeView->selectionModel()->select(sourceIndex, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
+ treeView->scrollTo(index);
+}
+
+//! [6]
+void MainWindow::about()
+{
+ QMessageBox::about(this, tr("About"), tr("This example demonstrates how "
+ "to use a QCompleter with a custom tree model."));
+}
+//! [6]
+
+//! [7]
+void MainWindow::changeCase(int cs)
+{
+ completer->setCaseSensitivity(cs ? Qt::CaseSensitive : Qt::CaseInsensitive);
+}
+//! [7]
+
+void MainWindow::updateContentsLabel(const QString& sep)
+{
+ contentsLabel->setText(QString(tr("Type path from model above with items at each level separated by a '%1'")).arg(sep));
+}
+
diff --git a/examples/tools/treemodelcompleter/mainwindow.h b/examples/tools/treemodelcompleter/mainwindow.h
new file mode 100644
index 0000000000..be14c34247
--- /dev/null
+++ b/examples/tools/treemodelcompleter/mainwindow.h
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include <QModelIndex>
+
+class TreeModelCompleter;
+QT_BEGIN_NAMESPACE
+class QAbstractItemModel;
+class QComboBox;
+class QLabel;
+class QLineEdit;
+class QProgressBar;
+class QCheckBox;
+class QTreeView;
+QT_END_NAMESPACE
+
+//! [0]
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow(QWidget *parent = 0);
+
+private slots:
+ void about();
+ void changeCase(int);
+ void changeMode(int);
+ void highlight(const QModelIndex&);
+ void updateContentsLabel(const QString&);
+//! [0]
+
+//! [1]
+private:
+ void createMenu();
+ QAbstractItemModel *modelFromFile(const QString& fileName);
+
+ QTreeView *treeView;
+ QComboBox *caseCombo;
+ QComboBox *modeCombo;
+ QLabel *contentsLabel;
+ TreeModelCompleter *completer;
+ QLineEdit *lineEdit;
+};
+//! [1]
+
+#endif // MAINWINDOW_H
diff --git a/examples/tools/treemodelcompleter/resources/treemodel.txt b/examples/tools/treemodelcompleter/resources/treemodel.txt
new file mode 100644
index 0000000000..06c90077af
--- /dev/null
+++ b/examples/tools/treemodelcompleter/resources/treemodel.txt
@@ -0,0 +1,20 @@
+Parent1
+ Child1
+ GrandChild1
+ GrandChild2
+ GrandChild3
+ GrandGrandChild1
+ Child2
+ GrandChild1
+ GrandGrandChild1
+ GrandChild2
+ Child3
+
+Parent2
+ Child1
+ GrandChild1
+ Child2
+ Child3
+ GrandChild1
+ GrandChild2
+
diff --git a/examples/tools/treemodelcompleter/treemodelcompleter.cpp b/examples/tools/treemodelcompleter/treemodelcompleter.cpp
new file mode 100644
index 0000000000..c1464b004e
--- /dev/null
+++ b/examples/tools/treemodelcompleter/treemodelcompleter.cpp
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** 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 "treemodelcompleter.h"
+#include <QStringList>
+
+//! [0]
+TreeModelCompleter::TreeModelCompleter(QObject *parent)
+ : QCompleter(parent)
+{
+}
+//! [0]
+
+//! [1]
+TreeModelCompleter::TreeModelCompleter(QAbstractItemModel *model, QObject *parent)
+ : QCompleter(model, parent)
+{
+}
+//! [1]
+
+void TreeModelCompleter::setSeparator(const QString &separator)
+{
+ sep = separator;
+}
+
+//! [2]
+QString TreeModelCompleter::separator() const
+{
+ return sep;
+}
+//! [2]
+
+//! [3]
+QStringList TreeModelCompleter::splitPath(const QString &path) const
+{
+ if (sep.isNull()) {
+ return QCompleter::splitPath(path);
+ }
+
+ return path.split(sep);
+}
+//! [3]
+
+//! [4]
+QString TreeModelCompleter::pathFromIndex(const QModelIndex &index) const
+{
+ if (sep.isNull()) {
+ return QCompleter::pathFromIndex(index);
+ }
+
+ // navigate up and accumulate data
+ QStringList dataList;
+ for (QModelIndex i = index; i.isValid(); i = i.parent()) {
+ dataList.prepend(model()->data(i, completionRole()).toString());
+ }
+
+ return dataList.join(sep);
+}
+//! [4]
+
diff --git a/examples/tools/treemodelcompleter/treemodelcompleter.h b/examples/tools/treemodelcompleter/treemodelcompleter.h
new file mode 100644
index 0000000000..51a59028f0
--- /dev/null
+++ b/examples/tools/treemodelcompleter/treemodelcompleter.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 TREEMODELCOMPLETER_H
+#define TREEMODELCOMPLETER_H
+
+#include <QCompleter>
+
+//! [0]
+class TreeModelCompleter : public QCompleter
+{
+ Q_OBJECT
+ Q_PROPERTY(QString separator READ separator WRITE setSeparator)
+
+public:
+ TreeModelCompleter(QObject *parent = 0);
+ TreeModelCompleter(QAbstractItemModel *model, QObject *parent = 0);
+
+ QString separator() const;
+public slots:
+ void setSeparator(const QString &separator);
+
+protected:
+ QStringList splitPath(const QString &path) const;
+ QString pathFromIndex(const QModelIndex &index) const;
+
+private:
+ QString sep;
+};
+//! [0]
+
+#endif // TREEMODELCOMPLETER_H
+
diff --git a/examples/tools/treemodelcompleter/treemodelcompleter.pro b/examples/tools/treemodelcompleter/treemodelcompleter.pro
new file mode 100644
index 0000000000..ef5c0cb38b
--- /dev/null
+++ b/examples/tools/treemodelcompleter/treemodelcompleter.pro
@@ -0,0 +1,14 @@
+HEADERS = treemodelcompleter.h \
+ mainwindow.h
+SOURCES = treemodelcompleter.cpp \
+ main.cpp \
+ mainwindow.cpp
+RESOURCES = treemodelcompleter.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/tools/treemodelcompleter
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS treemodelcompleter.pro resources
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/treemodelcompleter
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/tools/treemodelcompleter/treemodelcompleter.qrc b/examples/tools/treemodelcompleter/treemodelcompleter.qrc
new file mode 100644
index 0000000000..1130fcd641
--- /dev/null
+++ b/examples/tools/treemodelcompleter/treemodelcompleter.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/">
+ <file>resources/treemodel.txt</file>
+</qresource>
+</RCC>
diff --git a/examples/tools/undoframework/commands.cpp b/examples/tools/undoframework/commands.cpp
new file mode 100644
index 0000000000..78f0c162a3
--- /dev/null
+++ b/examples/tools/undoframework/commands.cpp
@@ -0,0 +1,163 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "commands.h"
+#include "diagramitem.h"
+
+//! [0]
+MoveCommand::MoveCommand(DiagramItem *diagramItem, const QPointF &oldPos,
+ QUndoCommand *parent)
+ : QUndoCommand(parent)
+{
+ myDiagramItem = diagramItem;
+ newPos = diagramItem->pos();
+ myOldPos = oldPos;
+}
+//! [0]
+
+//! [1]
+bool MoveCommand::mergeWith(const QUndoCommand *command)
+{
+ const MoveCommand *moveCommand = static_cast<const MoveCommand *>(command);
+ DiagramItem *item = moveCommand->myDiagramItem;
+
+ if (myDiagramItem != item)
+ return false;
+
+ newPos = item->pos();
+ setText(QObject::tr("Move %1")
+ .arg(createCommandString(myDiagramItem, newPos)));
+
+ return true;
+}
+//! [1]
+
+//! [2]
+void MoveCommand::undo()
+{
+ myDiagramItem->setPos(myOldPos);
+ myDiagramItem->scene()->update();
+ setText(QObject::tr("Move %1")
+ .arg(createCommandString(myDiagramItem, newPos)));
+}
+//! [2]
+
+//! [3]
+void MoveCommand::redo()
+{
+ myDiagramItem->setPos(newPos);
+ setText(QObject::tr("Move %1")
+ .arg(createCommandString(myDiagramItem, newPos)));
+}
+//! [3]
+
+//! [4]
+DeleteCommand::DeleteCommand(QGraphicsScene *scene, QUndoCommand *parent)
+ : QUndoCommand(parent)
+{
+ myGraphicsScene = scene;
+ QList<QGraphicsItem *> list = myGraphicsScene->selectedItems();
+ list.first()->setSelected(false);
+ myDiagramItem = static_cast<DiagramItem *>(list.first());
+ setText(QObject::tr("Delete %1")
+ .arg(createCommandString(myDiagramItem, myDiagramItem->pos())));
+}
+//! [4]
+
+//! [5]
+void DeleteCommand::undo()
+{
+ myGraphicsScene->addItem(myDiagramItem);
+ myGraphicsScene->update();
+}
+//! [5]
+
+//! [6]
+void DeleteCommand::redo()
+{
+ myGraphicsScene->removeItem(myDiagramItem);
+}
+//! [6]
+
+//! [7]
+AddCommand::AddCommand(DiagramItem::DiagramType addType,
+ QGraphicsScene *scene, QUndoCommand *parent)
+ : QUndoCommand(parent)
+{
+ static int itemCount = 0;
+
+ myGraphicsScene = scene;
+ myDiagramItem = new DiagramItem(addType);
+ initialPosition = QPointF((itemCount * 15) % int(scene->width()),
+ (itemCount * 15) % int(scene->height()));
+ scene->update();
+ ++itemCount;
+ setText(QObject::tr("Add %1")
+ .arg(createCommandString(myDiagramItem, initialPosition)));
+}
+//! [7]
+
+//! [8]
+void AddCommand::undo()
+{
+ myGraphicsScene->removeItem(myDiagramItem);
+ myGraphicsScene->update();
+}
+//! [8]
+
+//! [9]
+void AddCommand::redo()
+{
+ myGraphicsScene->addItem(myDiagramItem);
+ myDiagramItem->setPos(initialPosition);
+ myGraphicsScene->clearSelection();
+ myGraphicsScene->update();
+}
+//! [9]
+
+QString createCommandString(DiagramItem *item, const QPointF &pos)
+{
+ return QObject::tr("%1 at (%2, %3)")
+ .arg(item->diagramType() == DiagramItem::Box ? "Box" : "Triangle")
+ .arg(pos.x()).arg(pos.y());
+}
diff --git a/examples/tools/undoframework/commands.h b/examples/tools/undoframework/commands.h
new file mode 100644
index 0000000000..17e4f3cb2b
--- /dev/null
+++ b/examples/tools/undoframework/commands.h
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef COMMANDS_H
+#define COMMANDS_H
+
+#include <QUndoCommand>
+
+#include "diagramitem.h"
+
+//! [0]
+class MoveCommand : public QUndoCommand
+{
+public:
+ enum { Id = 1234 };
+
+ MoveCommand(DiagramItem *diagramItem, const QPointF &oldPos,
+ QUndoCommand *parent = 0);
+
+ void undo();
+ void redo();
+ bool mergeWith(const QUndoCommand *command);
+ int id() const { return Id; }
+
+private:
+ DiagramItem *myDiagramItem;
+ QPointF myOldPos;
+ QPointF newPos;
+};
+//! [0]
+
+//! [1]
+class DeleteCommand : public QUndoCommand
+{
+public:
+ DeleteCommand(QGraphicsScene *graphicsScene, QUndoCommand *parent = 0);
+
+ void undo();
+ void redo();
+
+private:
+ DiagramItem *myDiagramItem;
+ QGraphicsScene *myGraphicsScene;
+};
+//! [1]
+
+//! [2]
+class AddCommand : public QUndoCommand
+{
+public:
+ AddCommand(DiagramItem::DiagramType addType, QGraphicsScene *graphicsScene,
+ QUndoCommand *parent = 0);
+
+ void undo();
+ void redo();
+
+private:
+ DiagramItem *myDiagramItem;
+ QGraphicsScene *myGraphicsScene;
+ QPointF initialPosition;
+};
+//! [2]
+
+QString createCommandString(DiagramItem *item, const QPointF &point);
+
+#endif
diff --git a/examples/tools/undoframework/diagramitem.cpp b/examples/tools/undoframework/diagramitem.cpp
new file mode 100644
index 0000000000..1b4301e356
--- /dev/null
+++ b/examples/tools/undoframework/diagramitem.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 <QtGui>
+
+#include "diagramitem.h"
+
+DiagramItem::DiagramItem(DiagramType diagramType, QGraphicsItem *item,
+ QGraphicsScene *scene)
+ : QGraphicsPolygonItem(item, scene)
+{
+ if (diagramType == Box) {
+ boxPolygon << QPointF(0, 0) << QPointF(0, 30) << QPointF(30, 30)
+ << QPointF(30, 0) << QPointF(0, 0);
+ setPolygon(boxPolygon);
+ } else {
+ trianglePolygon << QPointF(15, 0) << QPointF(30, 30) << QPointF(0, 30)
+ << QPointF(15, 0);
+ setPolygon(trianglePolygon);
+ }
+
+ QColor color(static_cast<int>(qrand()) % 256,
+ static_cast<int>(qrand()) % 256, static_cast<int>(qrand()) % 256);
+ QBrush brush(color);
+ setBrush(brush);
+ setFlag(QGraphicsItem::ItemIsSelectable);
+ setFlag(QGraphicsItem::ItemIsMovable);
+}
diff --git a/examples/tools/undoframework/diagramitem.h b/examples/tools/undoframework/diagramitem.h
new file mode 100644
index 0000000000..68da876bfe
--- /dev/null
+++ b/examples/tools/undoframework/diagramitem.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 DIAGRAMITEM_H
+#define DIAGRAMITEM_H
+
+#include <QGraphicsPolygonItem>
+
+QT_BEGIN_NAMESPACE
+class QGraphicsItem;
+class QGraphicsScene;
+class QGraphicsSceneMouseEvent;
+class QPointF;
+QT_END_NAMESPACE
+
+class DiagramItem : public QGraphicsPolygonItem
+{
+public:
+ enum { Type = UserType + 1 };
+ enum DiagramType { Box, Triangle };
+
+ DiagramItem(DiagramType diagramType, QGraphicsItem *item = 0,
+ QGraphicsScene *scene = 0);
+
+ DiagramType diagramType() const {
+ return polygon() == boxPolygon ? Box : Triangle;
+ }
+ int type() const { return Type; }
+
+private:
+ QPolygonF boxPolygon;
+ QPolygonF trianglePolygon;
+};
+
+#endif
diff --git a/examples/tools/undoframework/diagramscene.cpp b/examples/tools/undoframework/diagramscene.cpp
new file mode 100644
index 0000000000..fcc63c90f0
--- /dev/null
+++ b/examples/tools/undoframework/diagramscene.cpp
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "diagramscene.h"
+#include "diagramitem.h"
+
+DiagramScene::DiagramScene(QObject *parent)
+ : QGraphicsScene(parent)
+{
+ movingItem = 0;
+}
+
+void DiagramScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
+{
+ QPointF mousePos(event->buttonDownScenePos(Qt::LeftButton).x(),
+ event->buttonDownScenePos(Qt::LeftButton).y());
+ movingItem = itemAt(mousePos.x(), mousePos.y());
+
+ if (movingItem != 0 && event->button() == Qt::LeftButton) {
+ oldPos = movingItem->pos();
+ }
+
+ clearSelection();
+ QGraphicsScene::mousePressEvent(event);
+}
+
+void DiagramScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
+{
+ if (movingItem != 0 && event->button() == Qt::LeftButton) {
+ if (oldPos != movingItem->pos())
+ emit itemMoved(qgraphicsitem_cast<DiagramItem *>(movingItem),
+ oldPos);
+ movingItem = 0;
+ }
+ QGraphicsScene::mouseReleaseEvent(event);
+}
diff --git a/examples/tools/undoframework/diagramscene.h b/examples/tools/undoframework/diagramscene.h
new file mode 100644
index 0000000000..e1537cc353
--- /dev/null
+++ b/examples/tools/undoframework/diagramscene.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 DIAGRAMSCENE_H
+#define DIAGRAMSCENE_H
+
+#include <QObject>
+#include <QGraphicsScene>
+
+class DiagramItem;
+QT_BEGIN_NAMESPACE
+class QGraphicsSceneDragDropEvent;
+class QGraphicsViewItem;
+QT_END_NAMESPACE
+
+//! [0]
+class DiagramScene : public QGraphicsScene
+{
+ Q_OBJECT
+
+public:
+ DiagramScene(QObject *parent = 0);
+
+signals:
+ void itemMoved(DiagramItem *movedItem, const QPointF &movedFromPosition);
+
+protected:
+ void mousePressEvent(QGraphicsSceneMouseEvent *event);
+ void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
+
+private:
+ QGraphicsItem *movingItem;
+ QPointF oldPos;
+};
+//! [0]
+
+#endif
diff --git a/examples/tools/undoframework/images/cross.png b/examples/tools/undoframework/images/cross.png
new file mode 100644
index 0000000000..09e5e8c2ad
--- /dev/null
+++ b/examples/tools/undoframework/images/cross.png
Binary files differ
diff --git a/examples/tools/undoframework/main.cpp b/examples/tools/undoframework/main.cpp
new file mode 100644
index 0000000000..170d292b8a
--- /dev/null
+++ b/examples/tools/undoframework/main.cpp
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "mainwindow.h"
+
+//! [0]
+int main(int argv, char *args[])
+{
+ Q_INIT_RESOURCE(undoframework);
+
+ QApplication app(argv, args);
+
+ MainWindow mainWindow;
+ mainWindow.show();
+
+ return app.exec();
+}
+//! [0]
diff --git a/examples/tools/undoframework/mainwindow.cpp b/examples/tools/undoframework/mainwindow.cpp
new file mode 100644
index 0000000000..f912ff2bba
--- /dev/null
+++ b/examples/tools/undoframework/mainwindow.cpp
@@ -0,0 +1,209 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "mainwindow.h"
+#include "diagramscene.h"
+#include "diagramitem.h"
+#include "commands.h"
+
+//! [0]
+MainWindow::MainWindow()
+{
+ undoStack = new QUndoStack();
+
+ createActions();
+ createMenus();
+
+ createUndoView();
+
+ diagramScene = new DiagramScene();
+ QBrush pixmapBrush(QPixmap(":/images/cross.png").scaled(30, 30));
+ diagramScene->setBackgroundBrush(pixmapBrush);
+ diagramScene->setSceneRect(QRect(0, 0, 500, 500));
+
+ connect(diagramScene, SIGNAL(itemMoved(DiagramItem *, const QPointF &)),
+ this, SLOT(itemMoved(DiagramItem *, const QPointF &)));
+
+ setWindowTitle("Undo Framework");
+ QGraphicsView *view = new QGraphicsView(diagramScene);
+ setCentralWidget(view);
+ resize(700, 500);
+}
+//! [0]
+
+//! [1]
+void MainWindow::createUndoView()
+{
+ undoView = new QUndoView(undoStack);
+ undoView->setWindowTitle(tr("Command List"));
+ undoView->show();
+ undoView->setAttribute(Qt::WA_QuitOnClose, false);
+}
+//! [1]
+
+//! [2]
+void MainWindow::createActions()
+{
+ deleteAction = new QAction(tr("&Delete Item"), this);
+ deleteAction->setShortcut(tr("Del"));
+ connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItem()));
+//! [2] //! [3]
+
+//! [3] //! [4]
+ addBoxAction = new QAction(tr("Add &Box"), this);
+//! [4]
+ addBoxAction->setShortcut(tr("Ctrl+O"));
+ connect(addBoxAction, SIGNAL(triggered()), this, SLOT(addBox()));
+
+ addTriangleAction = new QAction(tr("Add &Triangle"), this);
+ addTriangleAction->setShortcut(tr("Ctrl+T"));
+ connect(addTriangleAction, SIGNAL(triggered()), this, SLOT(addTriangle()));
+
+//! [5]
+ undoAction = undoStack->createUndoAction(this, tr("&Undo"));
+ undoAction->setShortcut(tr("Ctrl+Z"));
+
+ redoAction = undoStack->createRedoAction(this, tr("&Redo"));
+ QList<QKeySequence> redoShortcuts;
+ redoShortcuts << tr("Ctrl+Y") << tr("Shift+Ctrl+Z");
+ redoAction->setShortcuts(redoShortcuts);
+//! [5]
+
+ exitAction = new QAction(tr("E&xit"), this);
+ exitAction->setShortcut(tr("Ctrl+Q"));
+ connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
+
+ aboutAction = new QAction(tr("&About"), this);
+ QList<QKeySequence> aboutShortcuts;
+ aboutShortcuts << tr("Ctrl+A") << tr("Ctrl+B");
+ aboutAction->setShortcuts(aboutShortcuts);
+ connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
+}
+
+//! [6]
+void MainWindow::createMenus()
+{
+//! [6]
+ fileMenu = menuBar()->addMenu(tr("&File"));
+ fileMenu->addAction(exitAction);
+
+//! [7]
+ editMenu = menuBar()->addMenu(tr("&Edit"));
+ editMenu->addAction(undoAction);
+ editMenu->addAction(redoAction);
+ editMenu->addSeparator();
+ editMenu->addAction(deleteAction);
+ connect(editMenu, SIGNAL(aboutToShow()),
+ this, SLOT(itemMenuAboutToShow()));
+ connect(editMenu, SIGNAL(aboutToHide()),
+ this, SLOT(itemMenuAboutToHide()));
+
+//! [7]
+ itemMenu = menuBar()->addMenu(tr("&Item"));
+ itemMenu->addAction(addBoxAction);
+ itemMenu->addAction(addTriangleAction);
+
+ helpMenu = menuBar()->addMenu(tr("&About"));
+ helpMenu->addAction(aboutAction);
+//! [8]
+}
+//! [8]
+
+//! [9]
+void MainWindow::itemMoved(DiagramItem *movedItem,
+ const QPointF &oldPosition)
+{
+ undoStack->push(new MoveCommand(movedItem, oldPosition));
+}
+//! [9]
+
+//! [10]
+void MainWindow::deleteItem()
+{
+ if (diagramScene->selectedItems().isEmpty())
+ return;
+
+ QUndoCommand *deleteCommand = new DeleteCommand(diagramScene);
+ undoStack->push(deleteCommand);
+}
+//! [10]
+
+//! [11]
+void MainWindow::itemMenuAboutToHide()
+{
+ deleteAction->setEnabled(true);
+}
+//! [11]
+
+//! [12]
+void MainWindow::itemMenuAboutToShow()
+{
+ deleteAction->setEnabled(!diagramScene->selectedItems().isEmpty());
+}
+//! [12]
+
+//! [13]
+void MainWindow::addBox()
+{
+ QUndoCommand *addCommand = new AddCommand(DiagramItem::Box, diagramScene);
+ undoStack->push(addCommand);
+}
+//! [13]
+
+//! [14]
+void MainWindow::addTriangle()
+{
+ QUndoCommand *addCommand = new AddCommand(DiagramItem::Triangle,
+ diagramScene);
+ undoStack->push(addCommand);
+}
+//! [14]
+
+//! [15]
+void MainWindow::about()
+{
+ QMessageBox::about(this, tr("About Undo"),
+ tr("The <b>Undo</b> example demonstrates how to "
+ "use Qt's undo framework."));
+}
+//! [15]
diff --git a/examples/tools/undoframework/mainwindow.h b/examples/tools/undoframework/mainwindow.h
new file mode 100644
index 0000000000..5f08ffc2fe
--- /dev/null
+++ b/examples/tools/undoframework/mainwindow.h
@@ -0,0 +1,100 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QToolBar;
+class QMenu;
+class QUndoStack;
+class QUndoView;
+QT_END_NAMESPACE
+class DiagramScene;
+class DiagramItem;
+
+//! [0]
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+public slots:
+ void itemMoved(DiagramItem *movedDiagram, const QPointF &moveStartPosition);
+
+private slots:
+ void deleteItem();
+ void addBox();
+ void addTriangle();
+ void about();
+ void itemMenuAboutToShow();
+ void itemMenuAboutToHide();
+
+private:
+ void createActions();
+ void createMenus();
+ void createUndoView();
+
+ QAction *deleteAction;
+ QAction *addBoxAction;
+ QAction *addTriangleAction;
+ QAction *undoAction;
+ QAction *redoAction;
+ QAction *exitAction;
+ QAction *aboutAction;
+
+ QMenu *fileMenu;
+ QMenu *editMenu;
+ QMenu *itemMenu;
+ QMenu *helpMenu;
+
+ DiagramScene *diagramScene;
+ QUndoStack *undoStack;
+ QUndoView *undoView;
+};
+//! [0]
+
+#endif
diff --git a/examples/tools/undoframework/undoframework.pro b/examples/tools/undoframework/undoframework.pro
new file mode 100644
index 0000000000..f797eb501c
--- /dev/null
+++ b/examples/tools/undoframework/undoframework.pro
@@ -0,0 +1,18 @@
+HEADERS = commands.h \
+ diagramitem.h \
+ diagramscene.h \
+ mainwindow.h
+SOURCES = commands.cpp \
+ diagramitem.cpp \
+ diagramscene.cpp \
+ main.cpp \
+ mainwindow.cpp
+RESOURCES = undoframework.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/tools/undoframework
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS undoframework.pro README images
+sources.path = $$[QT_INSTALL_EXAMPLES]/tools/undoframework
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/tools/undoframework/undoframework.qrc b/examples/tools/undoframework/undoframework.qrc
new file mode 100644
index 0000000000..6321d94d8d
--- /dev/null
+++ b/examples/tools/undoframework/undoframework.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+ <qresource>
+ <file>images/cross.png</file>
+ </qresource>
+ </RCC>
+