diff options
Diffstat (limited to 'examples/widgets/dialogs')
62 files changed, 3950 insertions, 0 deletions
diff --git a/examples/widgets/dialogs/README b/examples/widgets/dialogs/README new file mode 100644 index 0000000000..090b011061 --- /dev/null +++ b/examples/widgets/dialogs/README @@ -0,0 +1,9 @@ +Qt includes standard dialogs for many common operations, such as file +selection, printing, and color selection. + +Custom dialogs can also be created for specialized modal or modeless +interactions with users. + + +Documentation for these examples can be found via the Examples +link in the main Qt documentation. diff --git a/examples/widgets/dialogs/classwizard/classwizard.cpp b/examples/widgets/dialogs/classwizard/classwizard.cpp new file mode 100644 index 0000000000..eeb1fab55b --- /dev/null +++ b/examples/widgets/dialogs/classwizard/classwizard.cpp @@ -0,0 +1,430 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtWidgets> + +#include "classwizard.h" + +//! [0] //! [1] +ClassWizard::ClassWizard(QWidget *parent) + : QWizard(parent) +{ + addPage(new IntroPage); + addPage(new ClassInfoPage); + addPage(new CodeStylePage); + addPage(new OutputFilesPage); + addPage(new ConclusionPage); +//! [0] + + setPixmap(QWizard::BannerPixmap, QPixmap(":/images/banner.png")); + setPixmap(QWizard::BackgroundPixmap, QPixmap(":/images/background.png")); + + setWindowTitle(tr("Class Wizard")); +//! [2] +} +//! [1] //! [2] + +//! [3] +void ClassWizard::accept() +//! [3] //! [4] +{ + QByteArray className = field("className").toByteArray(); + QByteArray baseClass = field("baseClass").toByteArray(); + QByteArray macroName = field("macroName").toByteArray(); + QByteArray baseInclude = field("baseInclude").toByteArray(); + + QString outputDir = field("outputDir").toString(); + QString header = field("header").toString(); + QString implementation = field("implementation").toString(); +//! [4] + + QByteArray block; + + if (field("comment").toBool()) { + block += "/*\n"; + block += " " + header.toLatin1() + "\n"; + block += "*/\n"; + block += "\n"; + } + if (field("protect").toBool()) { + block += "#ifndef " + macroName + "\n"; + block += "#define " + macroName + "\n"; + block += "\n"; + } + if (field("includeBase").toBool()) { + block += "#include " + baseInclude + "\n"; + block += "\n"; + } + + block += "class " + className; + if (!baseClass.isEmpty()) + block += " : public " + baseClass; + block += "\n"; + block += "{\n"; + + /* qmake ignore Q_OBJECT */ + + if (field("qobjectMacro").toBool()) { + block += " Q_OBJECT\n"; + block += "\n"; + } + block += "public:\n"; + + if (field("qobjectCtor").toBool()) { + block += " " + className + "(QObject *parent = 0);\n"; + } else if (field("qwidgetCtor").toBool()) { + block += " " + className + "(QWidget *parent = 0);\n"; + } else if (field("defaultCtor").toBool()) { + block += " " + className + "();\n"; + if (field("copyCtor").toBool()) { + block += " " + className + "(const " + className + " &other);\n"; + block += "\n"; + block += " " + className + " &operator=" + "(const " + className + + " &other);\n"; + } + } + block += "};\n"; + + if (field("protect").toBool()) { + block += "\n"; + block += "#endif\n"; + } + + QFile headerFile(outputDir + "/" + header); + if (!headerFile.open(QFile::WriteOnly | QFile::Text)) { + QMessageBox::warning(0, QObject::tr("Simple Wizard"), + QObject::tr("Cannot write file %1:\n%2") + .arg(headerFile.fileName()) + .arg(headerFile.errorString())); + return; + } + headerFile.write(block); + + block.clear(); + + if (field("comment").toBool()) { + block += "/*\n"; + block += " " + implementation.toLatin1() + "\n"; + block += "*/\n"; + block += "\n"; + } + block += "#include \"" + header.toLatin1() + "\"\n"; + block += "\n"; + + if (field("qobjectCtor").toBool()) { + block += className + "::" + className + "(QObject *parent)\n"; + block += " : " + baseClass + "(parent)\n"; + block += "{\n"; + block += "}\n"; + } else if (field("qwidgetCtor").toBool()) { + block += className + "::" + className + "(QWidget *parent)\n"; + block += " : " + baseClass + "(parent)\n"; + block += "{\n"; + block += "}\n"; + } else if (field("defaultCtor").toBool()) { + block += className + "::" + className + "()\n"; + block += "{\n"; + block += " // missing code\n"; + block += "}\n"; + + if (field("copyCtor").toBool()) { + block += "\n"; + block += className + "::" + className + "(const " + className + + " &other)\n"; + block += "{\n"; + block += " *this = other;\n"; + block += "}\n"; + block += "\n"; + block += className + " &" + className + "::operator=(const " + + className + " &other)\n"; + block += "{\n"; + if (!baseClass.isEmpty()) + block += " " + baseClass + "::operator=(other);\n"; + block += " // missing code\n"; + block += " return *this;\n"; + block += "}\n"; + } + } + + QFile implementationFile(outputDir + "/" + implementation); + if (!implementationFile.open(QFile::WriteOnly | QFile::Text)) { + QMessageBox::warning(0, QObject::tr("Simple Wizard"), + QObject::tr("Cannot write file %1:\n%2") + .arg(implementationFile.fileName()) + .arg(implementationFile.errorString())); + return; + } + implementationFile.write(block); + +//! [5] + QDialog::accept(); +//! [5] //! [6] +} +//! [6] + +//! [7] +IntroPage::IntroPage(QWidget *parent) + : QWizardPage(parent) +{ + setTitle(tr("Introduction")); + setPixmap(QWizard::WatermarkPixmap, QPixmap(":/images/watermark1.png")); + + label = new QLabel(tr("This wizard will generate a skeleton C++ class " + "definition, including a few functions. You simply " + "need to specify the class name and set a few " + "options to produce a header file and an " + "implementation file for your new C++ class.")); + label->setWordWrap(true); + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(label); + setLayout(layout); +} +//! [7] + +//! [8] //! [9] +ClassInfoPage::ClassInfoPage(QWidget *parent) + : QWizardPage(parent) +{ +//! [8] + setTitle(tr("Class Information")); + setSubTitle(tr("Specify basic information about the class for which you " + "want to generate skeleton source code files.")); + setPixmap(QWizard::LogoPixmap, QPixmap(":/images/logo1.png")); + +//! [10] + classNameLabel = new QLabel(tr("&Class name:")); + classNameLineEdit = new QLineEdit; + classNameLabel->setBuddy(classNameLineEdit); + + baseClassLabel = new QLabel(tr("B&ase class:")); + baseClassLineEdit = new QLineEdit; + baseClassLabel->setBuddy(baseClassLineEdit); + + qobjectMacroCheckBox = new QCheckBox(tr("Generate Q_OBJECT ¯o")); + +//! [10] + groupBox = new QGroupBox(tr("C&onstructor")); +//! [9] + + qobjectCtorRadioButton = new QRadioButton(tr("&QObject-style constructor")); + qwidgetCtorRadioButton = new QRadioButton(tr("Q&Widget-style constructor")); + defaultCtorRadioButton = new QRadioButton(tr("&Default constructor")); + copyCtorCheckBox = new QCheckBox(tr("&Generate copy constructor and " + "operator=")); + + defaultCtorRadioButton->setChecked(true); + + connect(defaultCtorRadioButton, SIGNAL(toggled(bool)), + copyCtorCheckBox, SLOT(setEnabled(bool))); + +//! [11] //! [12] + registerField("className*", classNameLineEdit); + registerField("baseClass", baseClassLineEdit); + registerField("qobjectMacro", qobjectMacroCheckBox); +//! [11] + registerField("qobjectCtor", qobjectCtorRadioButton); + registerField("qwidgetCtor", qwidgetCtorRadioButton); + registerField("defaultCtor", defaultCtorRadioButton); + registerField("copyCtor", copyCtorCheckBox); + + QVBoxLayout *groupBoxLayout = new QVBoxLayout; +//! [12] + groupBoxLayout->addWidget(qobjectCtorRadioButton); + groupBoxLayout->addWidget(qwidgetCtorRadioButton); + groupBoxLayout->addWidget(defaultCtorRadioButton); + groupBoxLayout->addWidget(copyCtorCheckBox); + groupBox->setLayout(groupBoxLayout); + + QGridLayout *layout = new QGridLayout; + layout->addWidget(classNameLabel, 0, 0); + layout->addWidget(classNameLineEdit, 0, 1); + layout->addWidget(baseClassLabel, 1, 0); + layout->addWidget(baseClassLineEdit, 1, 1); + layout->addWidget(qobjectMacroCheckBox, 2, 0, 1, 2); + layout->addWidget(groupBox, 3, 0, 1, 2); + setLayout(layout); +//! [13] +} +//! [13] + +//! [14] +CodeStylePage::CodeStylePage(QWidget *parent) + : QWizardPage(parent) +{ + setTitle(tr("Code Style Options")); + setSubTitle(tr("Choose the formatting of the generated code.")); + setPixmap(QWizard::LogoPixmap, QPixmap(":/images/logo2.png")); + + commentCheckBox = new QCheckBox(tr("&Start generated files with a " +//! [14] + "comment")); + commentCheckBox->setChecked(true); + + protectCheckBox = new QCheckBox(tr("&Protect header file against multiple " + "inclusions")); + protectCheckBox->setChecked(true); + + macroNameLabel = new QLabel(tr("&Macro name:")); + macroNameLineEdit = new QLineEdit; + macroNameLabel->setBuddy(macroNameLineEdit); + + includeBaseCheckBox = new QCheckBox(tr("&Include base class definition")); + baseIncludeLabel = new QLabel(tr("Base class include:")); + baseIncludeLineEdit = new QLineEdit; + baseIncludeLabel->setBuddy(baseIncludeLineEdit); + + connect(protectCheckBox, SIGNAL(toggled(bool)), + macroNameLabel, SLOT(setEnabled(bool))); + connect(protectCheckBox, SIGNAL(toggled(bool)), + macroNameLineEdit, SLOT(setEnabled(bool))); + connect(includeBaseCheckBox, SIGNAL(toggled(bool)), + baseIncludeLabel, SLOT(setEnabled(bool))); + connect(includeBaseCheckBox, SIGNAL(toggled(bool)), + baseIncludeLineEdit, SLOT(setEnabled(bool))); + + registerField("comment", commentCheckBox); + registerField("protect", protectCheckBox); + registerField("macroName", macroNameLineEdit); + registerField("includeBase", includeBaseCheckBox); + registerField("baseInclude", baseIncludeLineEdit); + + QGridLayout *layout = new QGridLayout; + layout->setColumnMinimumWidth(0, 20); + layout->addWidget(commentCheckBox, 0, 0, 1, 3); + layout->addWidget(protectCheckBox, 1, 0, 1, 3); + layout->addWidget(macroNameLabel, 2, 1); + layout->addWidget(macroNameLineEdit, 2, 2); + layout->addWidget(includeBaseCheckBox, 3, 0, 1, 3); + layout->addWidget(baseIncludeLabel, 4, 1); + layout->addWidget(baseIncludeLineEdit, 4, 2); +//! [15] + setLayout(layout); +} +//! [15] + +//! [16] +void CodeStylePage::initializePage() +{ + QString className = field("className").toString(); + macroNameLineEdit->setText(className.toUpper() + "_H"); + + QString baseClass = field("baseClass").toString(); + + includeBaseCheckBox->setChecked(!baseClass.isEmpty()); + includeBaseCheckBox->setEnabled(!baseClass.isEmpty()); + baseIncludeLabel->setEnabled(!baseClass.isEmpty()); + baseIncludeLineEdit->setEnabled(!baseClass.isEmpty()); + + if (baseClass.isEmpty()) { + baseIncludeLineEdit->clear(); + } else if (QRegExp("Q[A-Z].*").exactMatch(baseClass)) { + baseIncludeLineEdit->setText("<" + baseClass + ">"); + } else { + baseIncludeLineEdit->setText("\"" + baseClass.toLower() + ".h\""); + } +} +//! [16] + +OutputFilesPage::OutputFilesPage(QWidget *parent) + : QWizardPage(parent) +{ + setTitle(tr("Output Files")); + setSubTitle(tr("Specify where you want the wizard to put the generated " + "skeleton code.")); + setPixmap(QWizard::LogoPixmap, QPixmap(":/images/logo3.png")); + + outputDirLabel = new QLabel(tr("&Output directory:")); + outputDirLineEdit = new QLineEdit; + outputDirLabel->setBuddy(outputDirLineEdit); + + headerLabel = new QLabel(tr("&Header file name:")); + headerLineEdit = new QLineEdit; + headerLabel->setBuddy(headerLineEdit); + + implementationLabel = new QLabel(tr("&Implementation file name:")); + implementationLineEdit = new QLineEdit; + implementationLabel->setBuddy(implementationLineEdit); + + registerField("outputDir*", outputDirLineEdit); + registerField("header*", headerLineEdit); + registerField("implementation*", implementationLineEdit); + + QGridLayout *layout = new QGridLayout; + layout->addWidget(outputDirLabel, 0, 0); + layout->addWidget(outputDirLineEdit, 0, 1); + layout->addWidget(headerLabel, 1, 0); + layout->addWidget(headerLineEdit, 1, 1); + layout->addWidget(implementationLabel, 2, 0); + layout->addWidget(implementationLineEdit, 2, 1); + setLayout(layout); +} + +//! [17] +void OutputFilesPage::initializePage() +{ + QString className = field("className").toString(); + headerLineEdit->setText(className.toLower() + ".h"); + implementationLineEdit->setText(className.toLower() + ".cpp"); + outputDirLineEdit->setText(QDir::toNativeSeparators(QDir::tempPath())); +} +//! [17] + +ConclusionPage::ConclusionPage(QWidget *parent) + : QWizardPage(parent) +{ + setTitle(tr("Conclusion")); + setPixmap(QWizard::WatermarkPixmap, QPixmap(":/images/watermark2.png")); + + label = new QLabel; + label->setWordWrap(true); + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(label); + setLayout(layout); +} + +void ConclusionPage::initializePage() +{ + QString finishText = wizard()->buttonText(QWizard::FinishButton); + finishText.remove('&'); + label->setText(tr("Click %1 to generate the class skeleton.") + .arg(finishText)); +} diff --git a/examples/widgets/dialogs/classwizard/classwizard.desktop b/examples/widgets/dialogs/classwizard/classwizard.desktop new file mode 100644 index 0000000000..7f7d232092 --- /dev/null +++ b/examples/widgets/dialogs/classwizard/classwizard.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Encoding=UTF-8 +Version=1.0 +Type=Application +Terminal=false +Name=Class Wizard +Exec=/opt/usr/bin/classwizard +Icon=classwizard +X-Window-Icon= +X-HildonDesk-ShowInToolbar=true +X-Osso-Type=application/x-executable diff --git a/examples/widgets/dialogs/classwizard/classwizard.h b/examples/widgets/dialogs/classwizard/classwizard.h new file mode 100644 index 0000000000..332025f207 --- /dev/null +++ b/examples/widgets/dialogs/classwizard/classwizard.h @@ -0,0 +1,156 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef CLASSWIZARD_H +#define CLASSWIZARD_H + +#include <QWizard> + +QT_BEGIN_NAMESPACE +class QCheckBox; +class QGroupBox; +class QLabel; +class QLineEdit; +class QRadioButton; +QT_END_NAMESPACE + +//! [0] +class ClassWizard : public QWizard +{ + Q_OBJECT + +public: + ClassWizard(QWidget *parent = 0); + + void accept(); +}; +//! [0] + +//! [1] +class IntroPage : public QWizardPage +{ + Q_OBJECT + +public: + IntroPage(QWidget *parent = 0); + +private: + QLabel *label; +}; +//! [1] + +//! [2] +class ClassInfoPage : public QWizardPage +{ + Q_OBJECT + +public: + ClassInfoPage(QWidget *parent = 0); + +private: + QLabel *classNameLabel; + QLabel *baseClassLabel; + QLineEdit *classNameLineEdit; + QLineEdit *baseClassLineEdit; + QCheckBox *qobjectMacroCheckBox; + QGroupBox *groupBox; + QRadioButton *qobjectCtorRadioButton; + QRadioButton *qwidgetCtorRadioButton; + QRadioButton *defaultCtorRadioButton; + QCheckBox *copyCtorCheckBox; +}; +//! [2] + +//! [3] +class CodeStylePage : public QWizardPage +{ + Q_OBJECT + +public: + CodeStylePage(QWidget *parent = 0); + +protected: + void initializePage(); + +private: + QCheckBox *commentCheckBox; + QCheckBox *protectCheckBox; + QCheckBox *includeBaseCheckBox; + QLabel *macroNameLabel; + QLabel *baseIncludeLabel; + QLineEdit *macroNameLineEdit; + QLineEdit *baseIncludeLineEdit; +}; +//! [3] + +class OutputFilesPage : public QWizardPage +{ + Q_OBJECT + +public: + OutputFilesPage(QWidget *parent = 0); + +protected: + void initializePage(); + +private: + QLabel *outputDirLabel; + QLabel *headerLabel; + QLabel *implementationLabel; + QLineEdit *outputDirLineEdit; + QLineEdit *headerLineEdit; + QLineEdit *implementationLineEdit; +}; + +class ConclusionPage : public QWizardPage +{ + Q_OBJECT + +public: + ConclusionPage(QWidget *parent = 0); + +protected: + void initializePage(); + +private: + QLabel *label; +}; + +#endif diff --git a/examples/widgets/dialogs/classwizard/classwizard.pro b/examples/widgets/dialogs/classwizard/classwizard.pro new file mode 100644 index 0000000000..d50ba675af --- /dev/null +++ b/examples/widgets/dialogs/classwizard/classwizard.pro @@ -0,0 +1,13 @@ +HEADERS = classwizard.h +SOURCES = classwizard.cpp \ + main.cpp +RESOURCES = classwizard.qrc + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/classwizard +sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro images +sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/classwizard +INSTALLS += target sources + +QT += widgets +simulator: warning(This example might not fully work on Simulator platform) diff --git a/examples/widgets/dialogs/classwizard/classwizard.qrc b/examples/widgets/dialogs/classwizard/classwizard.qrc new file mode 100644 index 0000000000..41a5ddc7d1 --- /dev/null +++ b/examples/widgets/dialogs/classwizard/classwizard.qrc @@ -0,0 +1,11 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>images/background.png</file> + <file>images/banner.png</file> + <file>images/logo1.png</file> + <file>images/logo2.png</file> + <file>images/logo3.png</file> + <file>images/watermark1.png</file> + <file>images/watermark2.png</file> +</qresource> +</RCC> diff --git a/examples/widgets/dialogs/classwizard/images/background.png b/examples/widgets/dialogs/classwizard/images/background.png Binary files differnew file mode 100644 index 0000000000..44c7badb85 --- /dev/null +++ b/examples/widgets/dialogs/classwizard/images/background.png diff --git a/examples/widgets/dialogs/classwizard/images/banner.png b/examples/widgets/dialogs/classwizard/images/banner.png Binary files differnew file mode 100644 index 0000000000..3169152b8e --- /dev/null +++ b/examples/widgets/dialogs/classwizard/images/banner.png diff --git a/examples/widgets/dialogs/classwizard/images/logo1.png b/examples/widgets/dialogs/classwizard/images/logo1.png Binary files differnew file mode 100644 index 0000000000..f9b594aafc --- /dev/null +++ b/examples/widgets/dialogs/classwizard/images/logo1.png diff --git a/examples/widgets/dialogs/classwizard/images/logo2.png b/examples/widgets/dialogs/classwizard/images/logo2.png Binary files differnew file mode 100644 index 0000000000..5dcbd4669d --- /dev/null +++ b/examples/widgets/dialogs/classwizard/images/logo2.png diff --git a/examples/widgets/dialogs/classwizard/images/logo3.png b/examples/widgets/dialogs/classwizard/images/logo3.png Binary files differnew file mode 100644 index 0000000000..9fd3ea2358 --- /dev/null +++ b/examples/widgets/dialogs/classwizard/images/logo3.png diff --git a/examples/widgets/dialogs/classwizard/images/watermark1.png b/examples/widgets/dialogs/classwizard/images/watermark1.png Binary files differnew file mode 100644 index 0000000000..0091f5c17a --- /dev/null +++ b/examples/widgets/dialogs/classwizard/images/watermark1.png diff --git a/examples/widgets/dialogs/classwizard/images/watermark2.png b/examples/widgets/dialogs/classwizard/images/watermark2.png Binary files differnew file mode 100644 index 0000000000..3b88f2e360 --- /dev/null +++ b/examples/widgets/dialogs/classwizard/images/watermark2.png diff --git a/examples/widgets/dialogs/classwizard/main.cpp b/examples/widgets/dialogs/classwizard/main.cpp new file mode 100644 index 0000000000..03dd625ae4 --- /dev/null +++ b/examples/widgets/dialogs/classwizard/main.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> +#include <QTranslator> +#include <QLocale> +#include <QLibraryInfo> + +#include "classwizard.h" + +int main(int argc, char *argv[]) +{ + Q_INIT_RESOURCE(classwizard); + + QApplication app(argc, argv); + + QString translatorFileName = QLatin1String("qt_"); + translatorFileName += QLocale::system().name(); + QTranslator *translator = new QTranslator(&app); + if (translator->load(translatorFileName, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) + app.installTranslator(translator); + + ClassWizard wizard; + wizard.show(); + return app.exec(); +} diff --git a/examples/widgets/dialogs/configdialog/configdialog.cpp b/examples/widgets/dialogs/configdialog/configdialog.cpp new file mode 100644 index 0000000000..2f70c816c4 --- /dev/null +++ b/examples/widgets/dialogs/configdialog/configdialog.cpp @@ -0,0 +1,116 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtWidgets> + +#include "configdialog.h" +#include "pages.h" + +ConfigDialog::ConfigDialog() +{ + contentsWidget = new QListWidget; + contentsWidget->setViewMode(QListView::IconMode); + contentsWidget->setIconSize(QSize(96, 84)); + contentsWidget->setMovement(QListView::Static); + contentsWidget->setMaximumWidth(128); + contentsWidget->setSpacing(12); + + pagesWidget = new QStackedWidget; + pagesWidget->addWidget(new ConfigurationPage); + pagesWidget->addWidget(new UpdatePage); + pagesWidget->addWidget(new QueryPage); + + QPushButton *closeButton = new QPushButton(tr("Close")); + + createIcons(); + contentsWidget->setCurrentRow(0); + + connect(closeButton, SIGNAL(clicked()), this, SLOT(close())); + + QHBoxLayout *horizontalLayout = new QHBoxLayout; + horizontalLayout->addWidget(contentsWidget); + horizontalLayout->addWidget(pagesWidget, 1); + + QHBoxLayout *buttonsLayout = new QHBoxLayout; + buttonsLayout->addStretch(1); + buttonsLayout->addWidget(closeButton); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addLayout(horizontalLayout); + mainLayout->addStretch(1); + mainLayout->addSpacing(12); + mainLayout->addLayout(buttonsLayout); + setLayout(mainLayout); + + setWindowTitle(tr("Config Dialog")); +} + +void ConfigDialog::createIcons() +{ + QListWidgetItem *configButton = new QListWidgetItem(contentsWidget); + configButton->setIcon(QIcon(":/images/config.png")); + configButton->setText(tr("Configuration")); + configButton->setTextAlignment(Qt::AlignHCenter); + configButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + + QListWidgetItem *updateButton = new QListWidgetItem(contentsWidget); + updateButton->setIcon(QIcon(":/images/update.png")); + updateButton->setText(tr("Update")); + updateButton->setTextAlignment(Qt::AlignHCenter); + updateButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + + QListWidgetItem *queryButton = new QListWidgetItem(contentsWidget); + queryButton->setIcon(QIcon(":/images/query.png")); + queryButton->setText(tr("Query")); + queryButton->setTextAlignment(Qt::AlignHCenter); + queryButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + + connect(contentsWidget, + SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), + this, SLOT(changePage(QListWidgetItem*,QListWidgetItem*))); +} + +void ConfigDialog::changePage(QListWidgetItem *current, QListWidgetItem *previous) +{ + if (!current) + current = previous; + + pagesWidget->setCurrentIndex(contentsWidget->row(current)); +} diff --git a/examples/widgets/dialogs/configdialog/configdialog.desktop b/examples/widgets/dialogs/configdialog/configdialog.desktop new file mode 100644 index 0000000000..11a326813a --- /dev/null +++ b/examples/widgets/dialogs/configdialog/configdialog.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Encoding=UTF-8 +Version=1.0 +Type=Application +Terminal=false +Name=Config Dialog +Exec=/opt/usr/bin/configdialog +Icon=configdialog +X-Window-Icon= +X-HildonDesk-ShowInToolbar=true +X-Osso-Type=application/x-executable diff --git a/examples/widgets/dialogs/configdialog/configdialog.h b/examples/widgets/dialogs/configdialog/configdialog.h new file mode 100644 index 0000000000..5b79e416ab --- /dev/null +++ b/examples/widgets/dialogs/configdialog/configdialog.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef CONFIGDIALOG_H +#define CONFIGDIALOG_H + +#include <QDialog> + +QT_BEGIN_NAMESPACE +class QListWidget; +class QListWidgetItem; +class QStackedWidget; +QT_END_NAMESPACE + +class ConfigDialog : public QDialog +{ + Q_OBJECT + +public: + ConfigDialog(); + +public slots: + void changePage(QListWidgetItem *current, QListWidgetItem *previous); + +private: + void createIcons(); + + QListWidget *contentsWidget; + QStackedWidget *pagesWidget; +}; + +#endif diff --git a/examples/widgets/dialogs/configdialog/configdialog.pro b/examples/widgets/dialogs/configdialog/configdialog.pro new file mode 100644 index 0000000000..643c2a238f --- /dev/null +++ b/examples/widgets/dialogs/configdialog/configdialog.pro @@ -0,0 +1,17 @@ +HEADERS = configdialog.h \ + pages.h +SOURCES = configdialog.cpp \ + main.cpp \ + pages.cpp +RESOURCES += configdialog.qrc + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/configdialog +sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro images +sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/configdialog +INSTALLS += target sources + +wince50standard-x86-msvc2005: LIBS += libcmt.lib corelibc.lib ole32.lib oleaut32.lib uuid.lib commctrl.lib coredll.lib winsock.lib ws2.lib + +QT += widgets +simulator: warning(This example might not fully work on Simulator platform) diff --git a/examples/widgets/dialogs/configdialog/configdialog.qrc b/examples/widgets/dialogs/configdialog/configdialog.qrc new file mode 100644 index 0000000000..31d0d49666 --- /dev/null +++ b/examples/widgets/dialogs/configdialog/configdialog.qrc @@ -0,0 +1,7 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>images/config.png</file> + <file>images/query.png</file> + <file>images/update.png</file> +</qresource> +</RCC> diff --git a/examples/widgets/dialogs/configdialog/images/config.png b/examples/widgets/dialogs/configdialog/images/config.png Binary files differnew file mode 100644 index 0000000000..5c14d5f470 --- /dev/null +++ b/examples/widgets/dialogs/configdialog/images/config.png diff --git a/examples/widgets/dialogs/configdialog/images/query.png b/examples/widgets/dialogs/configdialog/images/query.png Binary files differnew file mode 100644 index 0000000000..ea9e291eeb --- /dev/null +++ b/examples/widgets/dialogs/configdialog/images/query.png diff --git a/examples/widgets/dialogs/configdialog/images/update.png b/examples/widgets/dialogs/configdialog/images/update.png Binary files differnew file mode 100644 index 0000000000..3cb8ba6c77 --- /dev/null +++ b/examples/widgets/dialogs/configdialog/images/update.png diff --git a/examples/widgets/dialogs/configdialog/main.cpp b/examples/widgets/dialogs/configdialog/main.cpp new file mode 100644 index 0000000000..42f3cf2f43 --- /dev/null +++ b/examples/widgets/dialogs/configdialog/main.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> + +#include "configdialog.h" + +int main(int argc, char *argv[]) +{ + Q_INIT_RESOURCE(configdialog); + + QApplication app(argc, argv); + ConfigDialog dialog; + return dialog.exec(); +} diff --git a/examples/widgets/dialogs/configdialog/pages.cpp b/examples/widgets/dialogs/configdialog/pages.cpp new file mode 100644 index 0000000000..c89bc3c7c8 --- /dev/null +++ b/examples/widgets/dialogs/configdialog/pages.cpp @@ -0,0 +1,151 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtWidgets> + +#include "pages.h" + +ConfigurationPage::ConfigurationPage(QWidget *parent) + : QWidget(parent) +{ + QGroupBox *configGroup = new QGroupBox(tr("Server configuration")); + + QLabel *serverLabel = new QLabel(tr("Server:")); + QComboBox *serverCombo = new QComboBox; + serverCombo->addItem(tr("Qt (Australia)")); + serverCombo->addItem(tr("Qt (Germany)")); + serverCombo->addItem(tr("Qt (Norway)")); + serverCombo->addItem(tr("Qt (People's Republic of China)")); + serverCombo->addItem(tr("Qt (USA)")); + + QHBoxLayout *serverLayout = new QHBoxLayout; + serverLayout->addWidget(serverLabel); + serverLayout->addWidget(serverCombo); + + QVBoxLayout *configLayout = new QVBoxLayout; + configLayout->addLayout(serverLayout); + configGroup->setLayout(configLayout); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addWidget(configGroup); + mainLayout->addStretch(1); + setLayout(mainLayout); +} + +UpdatePage::UpdatePage(QWidget *parent) + : QWidget(parent) +{ + QGroupBox *updateGroup = new QGroupBox(tr("Package selection")); + QCheckBox *systemCheckBox = new QCheckBox(tr("Update system")); + QCheckBox *appsCheckBox = new QCheckBox(tr("Update applications")); + QCheckBox *docsCheckBox = new QCheckBox(tr("Update documentation")); + + QGroupBox *packageGroup = new QGroupBox(tr("Existing packages")); + + QListWidget *packageList = new QListWidget; + QListWidgetItem *qtItem = new QListWidgetItem(packageList); + qtItem->setText(tr("Qt")); + QListWidgetItem *qsaItem = new QListWidgetItem(packageList); + qsaItem->setText(tr("QSA")); + QListWidgetItem *teamBuilderItem = new QListWidgetItem(packageList); + teamBuilderItem->setText(tr("Teambuilder")); + + QPushButton *startUpdateButton = new QPushButton(tr("Start update")); + + QVBoxLayout *updateLayout = new QVBoxLayout; + updateLayout->addWidget(systemCheckBox); + updateLayout->addWidget(appsCheckBox); + updateLayout->addWidget(docsCheckBox); + updateGroup->setLayout(updateLayout); + + QVBoxLayout *packageLayout = new QVBoxLayout; + packageLayout->addWidget(packageList); + packageGroup->setLayout(packageLayout); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addWidget(updateGroup); + mainLayout->addWidget(packageGroup); + mainLayout->addSpacing(12); + mainLayout->addWidget(startUpdateButton); + mainLayout->addStretch(1); + setLayout(mainLayout); +} + +QueryPage::QueryPage(QWidget *parent) + : QWidget(parent) +{ + QGroupBox *packagesGroup = new QGroupBox(tr("Look for packages")); + + QLabel *nameLabel = new QLabel(tr("Name:")); + QLineEdit *nameEdit = new QLineEdit; + + QLabel *dateLabel = new QLabel(tr("Released after:")); + QDateTimeEdit *dateEdit = new QDateTimeEdit(QDate::currentDate()); + + QCheckBox *releasesCheckBox = new QCheckBox(tr("Releases")); + QCheckBox *upgradesCheckBox = new QCheckBox(tr("Upgrades")); + + QSpinBox *hitsSpinBox = new QSpinBox; + hitsSpinBox->setPrefix(tr("Return up to ")); + hitsSpinBox->setSuffix(tr(" results")); + hitsSpinBox->setSpecialValueText(tr("Return only the first result")); + hitsSpinBox->setMinimum(1); + hitsSpinBox->setMaximum(100); + hitsSpinBox->setSingleStep(10); + + QPushButton *startQueryButton = new QPushButton(tr("Start query")); + + QGridLayout *packagesLayout = new QGridLayout; + packagesLayout->addWidget(nameLabel, 0, 0); + packagesLayout->addWidget(nameEdit, 0, 1); + packagesLayout->addWidget(dateLabel, 1, 0); + packagesLayout->addWidget(dateEdit, 1, 1); + packagesLayout->addWidget(releasesCheckBox, 2, 0); + packagesLayout->addWidget(upgradesCheckBox, 3, 0); + packagesLayout->addWidget(hitsSpinBox, 4, 0, 1, 2); + packagesGroup->setLayout(packagesLayout); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addWidget(packagesGroup); + mainLayout->addSpacing(12); + mainLayout->addWidget(startQueryButton); + mainLayout->addStretch(1); + setLayout(mainLayout); +} diff --git a/examples/widgets/dialogs/configdialog/pages.h b/examples/widgets/dialogs/configdialog/pages.h new file mode 100644 index 0000000000..938a2a74f7 --- /dev/null +++ b/examples/widgets/dialogs/configdialog/pages.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PAGES_H +#define PAGES_H + +#include <QWidget> + +class ConfigurationPage : public QWidget +{ +public: + ConfigurationPage(QWidget *parent = 0); +}; + +class QueryPage : public QWidget +{ +public: + QueryPage(QWidget *parent = 0); +}; + +class UpdatePage : public QWidget +{ +public: + UpdatePage(QWidget *parent = 0); +}; + +#endif diff --git a/examples/widgets/dialogs/dialogs.pro b/examples/widgets/dialogs/dialogs.pro new file mode 100644 index 0000000000..a59e480efa --- /dev/null +++ b/examples/widgets/dialogs/dialogs.pro @@ -0,0 +1,19 @@ +TEMPLATE = subdirs +SUBDIRS = classwizard \ + configdialog \ + standarddialogs \ + tabdialog \ + trivialwizard + +!wince*: SUBDIRS += licensewizard \ + extension \ + findfiles + +wince*: SUBDIRS += sipdialog + +# install +sources.files = README *.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs +INSTALLS += sources + +QT += widgets diff --git a/examples/widgets/dialogs/extension/extension.desktop b/examples/widgets/dialogs/extension/extension.desktop new file mode 100644 index 0000000000..374b1c8340 --- /dev/null +++ b/examples/widgets/dialogs/extension/extension.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Encoding=UTF-8 +Version=1.0 +Type=Application +Terminal=false +Name=Extension +Exec=/opt/usr/bin/extension +Icon=extension +X-Window-Icon= +X-HildonDesk-ShowInToolbar=true +X-Osso-Type=application/x-executable diff --git a/examples/widgets/dialogs/extension/extension.pro b/examples/widgets/dialogs/extension/extension.pro new file mode 100644 index 0000000000..7e11dda4ab --- /dev/null +++ b/examples/widgets/dialogs/extension/extension.pro @@ -0,0 +1,12 @@ +HEADERS = finddialog.h +SOURCES = finddialog.cpp \ + main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/extension +sources.files = $$SOURCES $$HEADERS *.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/extension +INSTALLS += target sources + +QT += widgets +simulator: warning(This example might not fully work on Simulator platform) diff --git a/examples/widgets/dialogs/extension/finddialog.cpp b/examples/widgets/dialogs/extension/finddialog.cpp new file mode 100644 index 0000000000..c21ebf67c5 --- /dev/null +++ b/examples/widgets/dialogs/extension/finddialog.cpp @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtWidgets> + +#include "finddialog.h" + +//! [0] +FindDialog::FindDialog(QWidget *parent) + : QDialog(parent) +{ + label = new QLabel(tr("Find &what:")); + lineEdit = new QLineEdit; + label->setBuddy(lineEdit); + + caseCheckBox = new QCheckBox(tr("Match &case")); + fromStartCheckBox = new QCheckBox(tr("Search from &start")); + fromStartCheckBox->setChecked(true); + +//! [1] + findButton = new QPushButton(tr("&Find")); + findButton->setDefault(true); + + moreButton = new QPushButton(tr("&More")); + moreButton->setCheckable(true); +//! [0] + moreButton->setAutoDefault(false); + +//! [1] + +//! [2] + extension = new QWidget; + + wholeWordsCheckBox = new QCheckBox(tr("&Whole words")); + backwardCheckBox = new QCheckBox(tr("Search &backward")); + searchSelectionCheckBox = new QCheckBox(tr("Search se&lection")); +//! [2] + +//! [3] + buttonBox = new QDialogButtonBox(Qt::Vertical); + buttonBox->addButton(findButton, QDialogButtonBox::ActionRole); + buttonBox->addButton(moreButton, QDialogButtonBox::ActionRole); + + connect(moreButton, SIGNAL(toggled(bool)), extension, SLOT(setVisible(bool))); + + QVBoxLayout *extensionLayout = new QVBoxLayout; + extensionLayout->setMargin(0); + extensionLayout->addWidget(wholeWordsCheckBox); + extensionLayout->addWidget(backwardCheckBox); + extensionLayout->addWidget(searchSelectionCheckBox); + extension->setLayout(extensionLayout); +//! [3] + +//! [4] + QHBoxLayout *topLeftLayout = new QHBoxLayout; + topLeftLayout->addWidget(label); + topLeftLayout->addWidget(lineEdit); + + QVBoxLayout *leftLayout = new QVBoxLayout; + leftLayout->addLayout(topLeftLayout); + leftLayout->addWidget(caseCheckBox); + leftLayout->addWidget(fromStartCheckBox); + + QGridLayout *mainLayout = new QGridLayout; + mainLayout->setSizeConstraint(QLayout::SetFixedSize); + mainLayout->addLayout(leftLayout, 0, 0); + mainLayout->addWidget(buttonBox, 0, 1); + mainLayout->addWidget(extension, 1, 0, 1, 2); + mainLayout->setRowStretch(2, 1); + + setLayout(mainLayout); + + setWindowTitle(tr("Extension")); +//! [4] //! [5] + extension->hide(); +} +//! [5] diff --git a/examples/widgets/dialogs/extension/finddialog.h b/examples/widgets/dialogs/extension/finddialog.h new file mode 100644 index 0000000000..5599ac2c09 --- /dev/null +++ b/examples/widgets/dialogs/extension/finddialog.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef FINDDIALOG_H +#define FINDDIALOG_H + +#include <QDialog> + +QT_BEGIN_NAMESPACE +class QCheckBox; +class QDialogButtonBox; +class QGroupBox; +class QLabel; +class QLineEdit; +class QPushButton; +QT_END_NAMESPACE + +//! [0] +class FindDialog : public QDialog +{ + Q_OBJECT + +public: + FindDialog(QWidget *parent = 0); + +private: + QLabel *label; + QLineEdit *lineEdit; + QCheckBox *caseCheckBox; + QCheckBox *fromStartCheckBox; + QCheckBox *wholeWordsCheckBox; + QCheckBox *searchSelectionCheckBox; + QCheckBox *backwardCheckBox; + QDialogButtonBox *buttonBox; + QPushButton *findButton; + QPushButton *moreButton; + QWidget *extension; +}; +//! [0] + +#endif diff --git a/examples/widgets/dialogs/extension/main.cpp b/examples/widgets/dialogs/extension/main.cpp new file mode 100644 index 0000000000..f0eff079ed --- /dev/null +++ b/examples/widgets/dialogs/extension/main.cpp @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> + +#include "finddialog.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + FindDialog dialog; + + dialog.show(); + + return app.exec(); +} diff --git a/examples/widgets/dialogs/findfiles/findfiles.desktop b/examples/widgets/dialogs/findfiles/findfiles.desktop new file mode 100644 index 0000000000..04c91cd76d --- /dev/null +++ b/examples/widgets/dialogs/findfiles/findfiles.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Encoding=UTF-8 +Version=1.0 +Type=Application +Terminal=false +Name=Find Files +Exec=/opt/usr/bin/findfiles +Icon=findfiles +X-Window-Icon= +X-HildonDesk-ShowInToolbar=true +X-Osso-Type=application/x-executable diff --git a/examples/widgets/dialogs/findfiles/findfiles.pro b/examples/widgets/dialogs/findfiles/findfiles.pro new file mode 100644 index 0000000000..51d1c0eed1 --- /dev/null +++ b/examples/widgets/dialogs/findfiles/findfiles.pro @@ -0,0 +1,11 @@ +HEADERS = window.h +SOURCES = main.cpp \ + window.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/findfiles +sources.files = $$SOURCES $$HEADERS *.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/findfiles +INSTALLS += target sources + +QT += widgets diff --git a/examples/widgets/dialogs/findfiles/main.cpp b/examples/widgets/dialogs/findfiles/main.cpp new file mode 100644 index 0000000000..dcbf1c0449 --- /dev/null +++ b/examples/widgets/dialogs/findfiles/main.cpp @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> + +#include "window.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + Window window; + window.show(); + return app.exec(); +} diff --git a/examples/widgets/dialogs/findfiles/window.cpp b/examples/widgets/dialogs/findfiles/window.cpp new file mode 100644 index 0000000000..6b89436dc8 --- /dev/null +++ b/examples/widgets/dialogs/findfiles/window.cpp @@ -0,0 +1,247 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtWidgets> + +#include "window.h" + +//! [0] +Window::Window(QWidget *parent) + : QWidget(parent) +{ + browseButton = createButton(tr("&Browse..."), SLOT(browse())); + findButton = createButton(tr("&Find"), SLOT(find())); + + fileComboBox = createComboBox(tr("*")); + textComboBox = createComboBox(); + directoryComboBox = createComboBox(QDir::currentPath()); + + fileLabel = new QLabel(tr("Named:")); + textLabel = new QLabel(tr("Containing text:")); + directoryLabel = new QLabel(tr("In directory:")); + filesFoundLabel = new QLabel; + + createFilesTable(); +//! [0] + +//! [1] + QGridLayout *mainLayout = new QGridLayout; + mainLayout->setSizeConstraint(QLayout::SetNoConstraint); + mainLayout->addWidget(fileLabel, 0, 0); + mainLayout->addWidget(fileComboBox, 0, 1, 1, 2); + mainLayout->addWidget(textLabel, 1, 0); + mainLayout->addWidget(textComboBox, 1, 1, 1, 2); + mainLayout->addWidget(directoryLabel, 2, 0); + mainLayout->addWidget(directoryComboBox, 2, 1); + mainLayout->addWidget(browseButton, 2, 2); + mainLayout->addWidget(filesTable, 3, 0, 1, 3); + mainLayout->addWidget(filesFoundLabel, 4, 0, 1, 2); + mainLayout->addWidget(findButton, 4, 2); + setLayout(mainLayout); + + setWindowTitle(tr("Find Files")); + resize(700, 300); +} +//! [1] + +//! [2] +void Window::browse() +{ + QString directory = QFileDialog::getExistingDirectory(this, + tr("Find Files"), QDir::currentPath()); + + if (!directory.isEmpty()) { + if (directoryComboBox->findText(directory) == -1) + directoryComboBox->addItem(directory); + directoryComboBox->setCurrentIndex(directoryComboBox->findText(directory)); + } +} +//! [2] + +static void updateComboBox(QComboBox *comboBox) +{ + if (comboBox->findText(comboBox->currentText()) == -1) + comboBox->addItem(comboBox->currentText()); +} + +//! [3] +void Window::find() +{ + filesTable->setRowCount(0); + + QString fileName = fileComboBox->currentText(); + QString text = textComboBox->currentText(); + QString path = directoryComboBox->currentText(); +//! [3] + + updateComboBox(fileComboBox); + updateComboBox(textComboBox); + updateComboBox(directoryComboBox); + +//! [4] + currentDir = QDir(path); + QStringList files; + if (fileName.isEmpty()) + fileName = "*"; + files = currentDir.entryList(QStringList(fileName), + QDir::Files | QDir::NoSymLinks); + + if (!text.isEmpty()) + files = findFiles(files, text); + showFiles(files); +} +//! [4] + +//! [5] +QStringList Window::findFiles(const QStringList &files, const QString &text) +{ + QProgressDialog progressDialog(this); + progressDialog.setCancelButtonText(tr("&Cancel")); + progressDialog.setRange(0, files.size()); + progressDialog.setWindowTitle(tr("Find Files")); + +//! [5] //! [6] + QStringList foundFiles; + + for (int i = 0; i < files.size(); ++i) { + progressDialog.setValue(i); + progressDialog.setLabelText(tr("Searching file number %1 of %2...") + .arg(i).arg(files.size())); + qApp->processEvents(); +//! [6] + + if (progressDialog.wasCanceled()) + break; + +//! [7] + QFile file(currentDir.absoluteFilePath(files[i])); + + if (file.open(QIODevice::ReadOnly)) { + QString line; + QTextStream in(&file); + while (!in.atEnd()) { + if (progressDialog.wasCanceled()) + break; + line = in.readLine(); + if (line.contains(text)) { + foundFiles << files[i]; + break; + } + } + } + } + return foundFiles; +} +//! [7] + +//! [8] +void Window::showFiles(const QStringList &files) +{ + for (int i = 0; i < files.size(); ++i) { + QFile file(currentDir.absoluteFilePath(files[i])); + qint64 size = QFileInfo(file).size(); + + QTableWidgetItem *fileNameItem = new QTableWidgetItem(files[i]); + fileNameItem->setFlags(fileNameItem->flags() ^ Qt::ItemIsEditable); + QTableWidgetItem *sizeItem = new QTableWidgetItem(tr("%1 KB") + .arg(int((size + 1023) / 1024))); + sizeItem->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); + sizeItem->setFlags(sizeItem->flags() ^ Qt::ItemIsEditable); + + int row = filesTable->rowCount(); + filesTable->insertRow(row); + filesTable->setItem(row, 0, fileNameItem); + filesTable->setItem(row, 1, sizeItem); + } + filesFoundLabel->setText(tr("%1 file(s) found").arg(files.size()) + + (" (Double click on a file to open it)")); + filesFoundLabel->setWordWrap(true); +} +//! [8] + +//! [9] +QPushButton *Window::createButton(const QString &text, const char *member) +{ + QPushButton *button = new QPushButton(text); + connect(button, SIGNAL(clicked()), this, member); + return button; +} +//! [9] + +//! [10] +QComboBox *Window::createComboBox(const QString &text) +{ + QComboBox *comboBox = new QComboBox; + comboBox->setEditable(true); + comboBox->addItem(text); + comboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + return comboBox; +} +//! [10] + +//! [11] +void Window::createFilesTable() +{ + filesTable = new QTableWidget(0, 2); + filesTable->setSelectionBehavior(QAbstractItemView::SelectRows); + + QStringList labels; + labels << tr("Filename") << tr("Size"); + filesTable->setHorizontalHeaderLabels(labels); + filesTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); + filesTable->verticalHeader()->hide(); + filesTable->setShowGrid(false); + + connect(filesTable, SIGNAL(cellActivated(int,int)), + this, SLOT(openFileOfItem(int,int))); +} +//! [11] + +//! [12] + +void Window::openFileOfItem(int row, int /* column */) +{ + QTableWidgetItem *item = filesTable->item(row, 0); + + QDesktopServices::openUrl(QUrl::fromLocalFile(currentDir.absoluteFilePath(item->text()))); +} + +//! [12] + diff --git a/examples/widgets/dialogs/findfiles/window.h b/examples/widgets/dialogs/findfiles/window.h new file mode 100644 index 0000000000..0203de8a17 --- /dev/null +++ b/examples/widgets/dialogs/findfiles/window.h @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include <QWidget> +#include <QDir> + +QT_BEGIN_NAMESPACE +class QComboBox; +class QLabel; +class QPushButton; +class QTableWidget; +class QTableWidgetItem; +QT_END_NAMESPACE + +//! [0] +class Window : public QWidget +{ + Q_OBJECT + +public: + Window(QWidget *parent = 0); + +private slots: + void browse(); + void find(); + void openFileOfItem(int row, int column); + +private: + QStringList findFiles(const QStringList &files, const QString &text); + void showFiles(const QStringList &files); + QPushButton *createButton(const QString &text, const char *member); + QComboBox *createComboBox(const QString &text = QString()); + void createFilesTable(); + + QComboBox *fileComboBox; + QComboBox *textComboBox; + QComboBox *directoryComboBox; + QLabel *fileLabel; + QLabel *textLabel; + QLabel *directoryLabel; + QLabel *filesFoundLabel; + QPushButton *browseButton; + QPushButton *findButton; + QTableWidget *filesTable; + + QDir currentDir; +}; +//! [0] + +#endif diff --git a/examples/widgets/dialogs/licensewizard/images/logo.png b/examples/widgets/dialogs/licensewizard/images/logo.png Binary files differnew file mode 100644 index 0000000000..56f17a3e5a --- /dev/null +++ b/examples/widgets/dialogs/licensewizard/images/logo.png diff --git a/examples/widgets/dialogs/licensewizard/images/watermark.png b/examples/widgets/dialogs/licensewizard/images/watermark.png Binary files differnew file mode 100644 index 0000000000..124a05068b --- /dev/null +++ b/examples/widgets/dialogs/licensewizard/images/watermark.png diff --git a/examples/widgets/dialogs/licensewizard/licensewizard.cpp b/examples/widgets/dialogs/licensewizard/licensewizard.cpp new file mode 100644 index 0000000000..501f8e310c --- /dev/null +++ b/examples/widgets/dialogs/licensewizard/licensewizard.cpp @@ -0,0 +1,363 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtWidgets> +#include <QPrinter> +#include <QPrintDialog> + +#include "licensewizard.h" + +//! [0] //! [1] //! [2] +LicenseWizard::LicenseWizard(QWidget *parent) + : QWizard(parent) +{ +//! [0] + setPage(Page_Intro, new IntroPage); + setPage(Page_Evaluate, new EvaluatePage); + setPage(Page_Register, new RegisterPage); + setPage(Page_Details, new DetailsPage); + setPage(Page_Conclusion, new ConclusionPage); +//! [1] + + setStartId(Page_Intro); +//! [2] + +//! [3] +#ifndef Q_OS_MAC +//! [3] //! [4] + setWizardStyle(ModernStyle); +#endif +//! [4] //! [5] + setOption(HaveHelpButton, true); +//! [5] //! [6] + setPixmap(QWizard::LogoPixmap, QPixmap(":/images/logo.png")); + +//! [7] + connect(this, SIGNAL(helpRequested()), this, SLOT(showHelp())); +//! [7] + + setWindowTitle(tr("License Wizard")); +//! [8] +} +//! [6] //! [8] + +//! [9] //! [10] +void LicenseWizard::showHelp() +//! [9] //! [11] +{ + static QString lastHelpMessage; + + QString message; + + switch (currentId()) { + case Page_Intro: + message = tr("The decision you make here will affect which page you " + "get to see next."); + break; +//! [10] //! [11] + case Page_Evaluate: + message = tr("Make sure to provide a valid email address, such as " + "toni.buddenbrook@example.de."); + break; + case Page_Register: + message = tr("If you don't provide an upgrade key, you will be " + "asked to fill in your details."); + break; + case Page_Details: + message = tr("Make sure to provide a valid email address, such as " + "thomas.gradgrind@example.co.uk."); + break; + case Page_Conclusion: + message = tr("You must accept the terms and conditions of the " + "license to proceed."); + break; +//! [12] //! [13] + default: + message = tr("This help is likely not to be of any help."); + } +//! [12] + + if (lastHelpMessage == message) + message = tr("Sorry, I already gave what help I could. " + "Maybe you should try asking a human?"); + +//! [14] + QMessageBox::information(this, tr("License Wizard Help"), message); +//! [14] + + lastHelpMessage = message; +//! [15] +} +//! [13] //! [15] + +//! [16] +IntroPage::IntroPage(QWidget *parent) + : QWizardPage(parent) +{ + setTitle(tr("Introduction")); + setPixmap(QWizard::WatermarkPixmap, QPixmap(":/images/watermark.png")); + + topLabel = new QLabel(tr("This wizard will help you register your copy of " + "<i>Super Product One</i>™ or start " + "evaluating the product.")); + topLabel->setWordWrap(true); + + registerRadioButton = new QRadioButton(tr("&Register your copy")); + evaluateRadioButton = new QRadioButton(tr("&Evaluate the product for 30 " + "days")); + registerRadioButton->setChecked(true); + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(topLabel); + layout->addWidget(registerRadioButton); + layout->addWidget(evaluateRadioButton); + setLayout(layout); +} +//! [16] //! [17] + +//! [18] +int IntroPage::nextId() const +//! [17] //! [19] +{ + if (evaluateRadioButton->isChecked()) { + return LicenseWizard::Page_Evaluate; + } else { + return LicenseWizard::Page_Register; + } +} +//! [18] //! [19] + +//! [20] +EvaluatePage::EvaluatePage(QWidget *parent) + : QWizardPage(parent) +{ + setTitle(tr("Evaluate <i>Super Product One</i>™")); + setSubTitle(tr("Please fill both fields. Make sure to provide a valid " + "email address (e.g., john.smith@example.com).")); + + nameLabel = new QLabel(tr("N&ame:")); + nameLineEdit = new QLineEdit; +//! [20] + nameLabel->setBuddy(nameLineEdit); + + emailLabel = new QLabel(tr("&Email address:")); + emailLineEdit = new QLineEdit; + emailLineEdit->setValidator(new QRegExpValidator(QRegExp(".*@.*"), this)); + emailLabel->setBuddy(emailLineEdit); + +//! [21] + registerField("evaluate.name*", nameLineEdit); + registerField("evaluate.email*", emailLineEdit); +//! [21] + + QGridLayout *layout = new QGridLayout; + layout->addWidget(nameLabel, 0, 0); + layout->addWidget(nameLineEdit, 0, 1); + layout->addWidget(emailLabel, 1, 0); + layout->addWidget(emailLineEdit, 1, 1); + setLayout(layout); +//! [22] +} +//! [22] + +//! [23] +int EvaluatePage::nextId() const +{ + return LicenseWizard::Page_Conclusion; +} +//! [23] + +RegisterPage::RegisterPage(QWidget *parent) + : QWizardPage(parent) +{ + setTitle(tr("Register Your Copy of <i>Super Product One</i>™")); + setSubTitle(tr("If you have an upgrade key, please fill in " + "the appropriate field.")); + + nameLabel = new QLabel(tr("N&ame:")); + nameLineEdit = new QLineEdit; + nameLabel->setBuddy(nameLineEdit); + + upgradeKeyLabel = new QLabel(tr("&Upgrade key:")); + upgradeKeyLineEdit = new QLineEdit; + upgradeKeyLabel->setBuddy(upgradeKeyLineEdit); + + registerField("register.name*", nameLineEdit); + registerField("register.upgradeKey", upgradeKeyLineEdit); + + QGridLayout *layout = new QGridLayout; + layout->addWidget(nameLabel, 0, 0); + layout->addWidget(nameLineEdit, 0, 1); + layout->addWidget(upgradeKeyLabel, 1, 0); + layout->addWidget(upgradeKeyLineEdit, 1, 1); + setLayout(layout); +} + +//! [24] +int RegisterPage::nextId() const +{ + if (upgradeKeyLineEdit->text().isEmpty()) { + return LicenseWizard::Page_Details; + } else { + return LicenseWizard::Page_Conclusion; + } +} +//! [24] + +DetailsPage::DetailsPage(QWidget *parent) + : QWizardPage(parent) +{ + setTitle(tr("Fill In Your Details")); + setSubTitle(tr("Please fill all three fields. Make sure to provide a valid " + "email address (e.g., tanaka.aya@example.co.jp).")); + + companyLabel = new QLabel(tr("&Company name:")); + companyLineEdit = new QLineEdit; + companyLabel->setBuddy(companyLineEdit); + + emailLabel = new QLabel(tr("&Email address:")); + emailLineEdit = new QLineEdit; + emailLineEdit->setValidator(new QRegExpValidator(QRegExp(".*@.*"), this)); + emailLabel->setBuddy(emailLineEdit); + + postalLabel = new QLabel(tr("&Postal address:")); + postalLineEdit = new QLineEdit; + postalLabel->setBuddy(postalLineEdit); + + registerField("details.company*", companyLineEdit); + registerField("details.email*", emailLineEdit); + registerField("details.postal*", postalLineEdit); + + QGridLayout *layout = new QGridLayout; + layout->addWidget(companyLabel, 0, 0); + layout->addWidget(companyLineEdit, 0, 1); + layout->addWidget(emailLabel, 1, 0); + layout->addWidget(emailLineEdit, 1, 1); + layout->addWidget(postalLabel, 2, 0); + layout->addWidget(postalLineEdit, 2, 1); + setLayout(layout); +} + +//! [25] +int DetailsPage::nextId() const +{ + return LicenseWizard::Page_Conclusion; +} +//! [25] + +ConclusionPage::ConclusionPage(QWidget *parent) + : QWizardPage(parent) +{ + setTitle(tr("Complete Your Registration")); + setPixmap(QWizard::WatermarkPixmap, QPixmap(":/images/watermark.png")); + + bottomLabel = new QLabel; + bottomLabel->setWordWrap(true); + + agreeCheckBox = new QCheckBox(tr("I agree to the terms of the license")); + + registerField("conclusion.agree*", agreeCheckBox); + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(bottomLabel); + layout->addWidget(agreeCheckBox); + setLayout(layout); +} + +//! [26] +int ConclusionPage::nextId() const +{ + return -1; +} +//! [26] + +//! [27] +void ConclusionPage::initializePage() +{ + QString licenseText; + + if (wizard()->hasVisitedPage(LicenseWizard::Page_Evaluate)) { + licenseText = tr("<u>Evaluation License Agreement:</u> " + "You can use this software for 30 days and make one " + "backup, but you are not allowed to distribute it."); + } else if (wizard()->hasVisitedPage(LicenseWizard::Page_Details)) { + licenseText = tr("<u>First-Time License Agreement:</u> " + "You can use this software subject to the license " + "you will receive by email."); + } else { + licenseText = tr("<u>Upgrade License Agreement:</u> " + "This software is licensed under the terms of your " + "current license."); + } + bottomLabel->setText(licenseText); +} +//! [27] + +//! [28] +void ConclusionPage::setVisible(bool visible) +{ + QWizardPage::setVisible(visible); + + if (visible) { +//! [29] + wizard()->setButtonText(QWizard::CustomButton1, tr("&Print")); + wizard()->setOption(QWizard::HaveCustomButton1, true); + connect(wizard(), SIGNAL(customButtonClicked(int)), + this, SLOT(printButtonClicked())); +//! [29] + } else { + wizard()->setOption(QWizard::HaveCustomButton1, false); + disconnect(wizard(), SIGNAL(customButtonClicked(int)), + this, SLOT(printButtonClicked())); + } +} +//! [28] + +void ConclusionPage::printButtonClicked() +{ +#ifndef QT_NO_PRINTER + QPrinter printer; + QPrintDialog dialog(&printer, this); + if (dialog.exec()) + QMessageBox::warning(this, tr("Print License"), + tr("As an environmentally friendly measure, the " + "license text will not actually be printed.")); +#endif +} diff --git a/examples/widgets/dialogs/licensewizard/licensewizard.desktop b/examples/widgets/dialogs/licensewizard/licensewizard.desktop new file mode 100644 index 0000000000..423d81e9b3 --- /dev/null +++ b/examples/widgets/dialogs/licensewizard/licensewizard.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Encoding=UTF-8 +Version=1.0 +Type=Application +Terminal=false +Name=License Wizard +Exec=/opt/usr/bin/licensewizard +Icon=licensewizard +X-Window-Icon= +X-HildonDesk-ShowInToolbar=true +X-Osso-Type=application/x-executable diff --git a/examples/widgets/dialogs/licensewizard/licensewizard.h b/examples/widgets/dialogs/licensewizard/licensewizard.h new file mode 100644 index 0000000000..24ee45d6dd --- /dev/null +++ b/examples/widgets/dialogs/licensewizard/licensewizard.h @@ -0,0 +1,163 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef LICENSEWIZARD_H +#define LICENSEWIZARD_H + +#include <QWizard> + +QT_BEGIN_NAMESPACE +class QCheckBox; +class QLabel; +class QLineEdit; +class QRadioButton; +QT_END_NAMESPACE + +//! [0] //! [1] +class LicenseWizard : public QWizard +{ +//! [0] + Q_OBJECT + +public: +//! [2] + enum { Page_Intro, Page_Evaluate, Page_Register, Page_Details, + Page_Conclusion }; +//! [2] + + LicenseWizard(QWidget *parent = 0); + +private slots: + void showHelp(); +//! [3] +}; +//! [1] //! [3] + +//! [4] +class IntroPage : public QWizardPage +{ + Q_OBJECT + +public: + IntroPage(QWidget *parent = 0); + + int nextId() const; + +private: + QLabel *topLabel; + QRadioButton *registerRadioButton; + QRadioButton *evaluateRadioButton; +}; +//! [4] + +//! [5] +class EvaluatePage : public QWizardPage +{ + Q_OBJECT + +public: + EvaluatePage(QWidget *parent = 0); + + int nextId() const; + +private: + QLabel *nameLabel; + QLabel *emailLabel; + QLineEdit *nameLineEdit; + QLineEdit *emailLineEdit; +}; +//! [5] + +class RegisterPage : public QWizardPage +{ + Q_OBJECT + +public: + RegisterPage(QWidget *parent = 0); + + int nextId() const; + +private: + QLabel *nameLabel; + QLabel *upgradeKeyLabel; + QLineEdit *nameLineEdit; + QLineEdit *upgradeKeyLineEdit; +}; + +class DetailsPage : public QWizardPage +{ + Q_OBJECT + +public: + DetailsPage(QWidget *parent = 0); + + int nextId() const; + +private: + QLabel *companyLabel; + QLabel *emailLabel; + QLabel *postalLabel; + QLineEdit *companyLineEdit; + QLineEdit *emailLineEdit; + QLineEdit *postalLineEdit; +}; + +//! [6] +class ConclusionPage : public QWizardPage +{ + Q_OBJECT + +public: + ConclusionPage(QWidget *parent = 0); + + void initializePage(); + int nextId() const; + void setVisible(bool visible); + +private slots: + void printButtonClicked(); + +private: + QLabel *bottomLabel; + QCheckBox *agreeCheckBox; +}; +//! [6] + +#endif diff --git a/examples/widgets/dialogs/licensewizard/licensewizard.pro b/examples/widgets/dialogs/licensewizard/licensewizard.pro new file mode 100644 index 0000000000..c61325772e --- /dev/null +++ b/examples/widgets/dialogs/licensewizard/licensewizard.pro @@ -0,0 +1,13 @@ +HEADERS = licensewizard.h +SOURCES = licensewizard.cpp \ + main.cpp +RESOURCES = licensewizard.qrc + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/licensewizard +sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro images +sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/licensewizard +INSTALLS += target sources + +QT += widgets printsupport +simulator: warning(This example might not fully work on Simulator platform) diff --git a/examples/widgets/dialogs/licensewizard/licensewizard.qrc b/examples/widgets/dialogs/licensewizard/licensewizard.qrc new file mode 100644 index 0000000000..b069938515 --- /dev/null +++ b/examples/widgets/dialogs/licensewizard/licensewizard.qrc @@ -0,0 +1,6 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>images/logo.png</file> + <file>images/watermark.png</file> +</qresource> +</RCC> diff --git a/examples/widgets/dialogs/licensewizard/main.cpp b/examples/widgets/dialogs/licensewizard/main.cpp new file mode 100644 index 0000000000..c7771d7676 --- /dev/null +++ b/examples/widgets/dialogs/licensewizard/main.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> +#include <QTranslator> +#include <QLocale> +#include <QLibraryInfo> + +#include "licensewizard.h" + +int main(int argc, char *argv[]) +{ + Q_INIT_RESOURCE(licensewizard); + + QApplication app(argc, argv); + + QString translatorFileName = QLatin1String("qt_"); + translatorFileName += QLocale::system().name(); + QTranslator *translator = new QTranslator(&app); + if (translator->load(translatorFileName, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) + app.installTranslator(translator); + + LicenseWizard wizard; + wizard.show(); + return app.exec(); +} diff --git a/examples/widgets/dialogs/sipdialog/dialog.cpp b/examples/widgets/dialogs/sipdialog/dialog.cpp new file mode 100644 index 0000000000..fdfbc94ca4 --- /dev/null +++ b/examples/widgets/dialogs/sipdialog/dialog.cpp @@ -0,0 +1,122 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtWidgets> + +#include "dialog.h" + +//! [Dialog constructor part1] +Dialog::Dialog() +{ + desktopGeometry = QApplication::desktop()->availableGeometry(0); + + setWindowTitle(tr("SIP Dialog Example")); + QScrollArea *scrollArea = new QScrollArea(this); + QGroupBox *groupBox = new QGroupBox(scrollArea); + groupBox->setTitle(tr("SIP Dialog Example")); + QGridLayout *gridLayout = new QGridLayout(groupBox); + groupBox->setLayout(gridLayout); +//! [Dialog constructor part1] + +//! [Dialog constructor part2] + QLineEdit* lineEdit = new QLineEdit(groupBox); + lineEdit->setText(tr("Open and close the SIP")); + lineEdit->setMinimumWidth(220); + + QLabel* label = new QLabel(groupBox); + label->setText(tr("This dialog resizes if the SIP is opened")); + label->setMinimumWidth(220); + + QPushButton* button = new QPushButton(groupBox); + button->setText(tr("Close Dialog")); + button->setMinimumWidth(220); +//! [Dialog constructor part2] + +//! [Dialog constructor part3] + if (desktopGeometry.height() < 400) + gridLayout->setVerticalSpacing(80); + else + gridLayout->setVerticalSpacing(150); + + gridLayout->addWidget(label); + gridLayout->addWidget(lineEdit); + gridLayout->addWidget(button); +//! [Dialog constructor part3] + +//! [Dialog constructor part4] + scrollArea->setWidget(groupBox); + QHBoxLayout* layout = new QHBoxLayout(); + layout->addWidget(scrollArea); + setLayout(layout); + scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); +//! [Dialog constructor part4] + +//! [Dialog constructor part5] + connect(button, SIGNAL(clicked()), + qApp, SLOT(closeAllWindows())); + connect(QApplication::desktop(), SIGNAL(workAreaResized(int)), + this, SLOT(desktopResized(int))); +} +//! [Dialog constructor part5] + +//! [desktopResized() function] +void Dialog::desktopResized(int screen) +{ + if (screen != 0) + return; + reactToSIP(); +} +//! [desktopResized() function] + +//! [reactToSIP() function] +void Dialog::reactToSIP() +{ + QRect availableGeometry = QApplication::desktop()->availableGeometry(0); + + if (desktopGeometry != availableGeometry) { + if (windowState() | Qt::WindowMaximized) + setWindowState(windowState() & ~Qt::WindowMaximized); + + setGeometry(availableGeometry); + } + + desktopGeometry = availableGeometry; +} +//! [reactToSIP() function] diff --git a/examples/widgets/dialogs/sipdialog/dialog.h b/examples/widgets/dialogs/sipdialog/dialog.h new file mode 100644 index 0000000000..18eb92d857 --- /dev/null +++ b/examples/widgets/dialogs/sipdialog/dialog.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef DIALOG_H +#define DIALOG_H + +#include <QDialog> + +//! [Dialog header] +class Dialog : public QDialog +{ + Q_OBJECT + +public: + Dialog(); + void reactToSIP(); + +private: + QRect desktopGeometry; + +public slots: + void desktopResized(int screen); +}; +//! [Dialog header] + +#endif diff --git a/examples/widgets/dialogs/sipdialog/main.cpp b/examples/widgets/dialogs/sipdialog/main.cpp new file mode 100644 index 0000000000..79fd956fb9 --- /dev/null +++ b/examples/widgets/dialogs/sipdialog/main.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtWidgets> + +#include "dialog.h" + +//! [main() function] +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + Dialog dialog; + return dialog.exec(); +} +//! [main() function] diff --git a/examples/widgets/dialogs/sipdialog/sipdialog.desktop b/examples/widgets/dialogs/sipdialog/sipdialog.desktop new file mode 100644 index 0000000000..b9c9955339 --- /dev/null +++ b/examples/widgets/dialogs/sipdialog/sipdialog.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Encoding=UTF-8 +Version=1.0 +Type=Application +Terminal=false +Name=SIP Dialog +Exec=/opt/usr/bin/sipdialog +Icon=sipdialog +X-Window-Icon= +X-HildonDesk-ShowInToolbar=true +X-Osso-Type=application/x-executable diff --git a/examples/widgets/dialogs/sipdialog/sipdialog.pro b/examples/widgets/dialogs/sipdialog/sipdialog.pro new file mode 100644 index 0000000000..72db93f646 --- /dev/null +++ b/examples/widgets/dialogs/sipdialog/sipdialog.pro @@ -0,0 +1,15 @@ +HEADERS = dialog.h +SOURCES = main.cpp \ + dialog.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/sipdialog +sources.files = $$SOURCES $$HEADERS *.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/sipdialog +INSTALLS += target sources + +wince50standard-x86-msvc2005: LIBS += libcmt.lib corelibc.lib ole32.lib oleaut32.lib uuid.lib commctrl.lib coredll.lib winsock.lib ws2.lib + +QT += widgets + +simulator: warning(This example might not fully work on Simulator platform) diff --git a/examples/widgets/dialogs/standarddialogs/dialog.cpp b/examples/widgets/dialogs/standarddialogs/dialog.cpp new file mode 100644 index 0000000000..bde96c516b --- /dev/null +++ b/examples/widgets/dialogs/standarddialogs/dialog.cpp @@ -0,0 +1,471 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtWidgets> + +#include "dialog.h" + +#define MESSAGE \ + Dialog::tr("<p>Message boxes have a caption, a text, " \ + "and any number of buttons, each with standard or custom texts." \ + "<p>Click a button to close the message box. Pressing the Esc button " \ + "will activate the detected escape button (if any).") + + +class DialogOptionsWidget : public QGroupBox +{ +public: + explicit DialogOptionsWidget(QWidget *parent = 0); + + void addCheckBox(const QString &text, int value); + void addSpacer(); + int value() const; + +private: + typedef QPair<QCheckBox *, int> CheckBoxEntry; + QVBoxLayout *layout; + QList<CheckBoxEntry> checkBoxEntries; +}; + +DialogOptionsWidget::DialogOptionsWidget(QWidget *parent) : + QGroupBox(parent) , layout(new QVBoxLayout) +{ + setTitle(Dialog::tr("Options")); + setLayout(layout); +} + +void DialogOptionsWidget::addCheckBox(const QString &text, int value) +{ + QCheckBox *checkBox = new QCheckBox(text); + layout->addWidget(checkBox); + checkBoxEntries.append(CheckBoxEntry(checkBox, value)); +} + +void DialogOptionsWidget::addSpacer() +{ + layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding)); +} + +int DialogOptionsWidget::value() const +{ + int result = 0; + foreach (const CheckBoxEntry &checkboxEntry, checkBoxEntries) + if (checkboxEntry.first->isChecked()) + result |= checkboxEntry.second; + return result; +} + +Dialog::Dialog(QWidget *parent) + : QWidget(parent) +{ + QVBoxLayout *mainLayout = new QVBoxLayout(this); + QToolBox *toolbox = new QToolBox; + mainLayout->addWidget(toolbox); + + errorMessageDialog = new QErrorMessage(this); + + int frameStyle = QFrame::Sunken | QFrame::Panel; + + integerLabel = new QLabel; + integerLabel->setFrameStyle(frameStyle); + QPushButton *integerButton = + new QPushButton(tr("QInputDialog::get&Int()")); + + doubleLabel = new QLabel; + doubleLabel->setFrameStyle(frameStyle); + QPushButton *doubleButton = + new QPushButton(tr("QInputDialog::get&Double()")); + + itemLabel = new QLabel; + itemLabel->setFrameStyle(frameStyle); + QPushButton *itemButton = new QPushButton(tr("QInputDialog::getIte&m()")); + + textLabel = new QLabel; + textLabel->setFrameStyle(frameStyle); + QPushButton *textButton = new QPushButton(tr("QInputDialog::get&Text()")); + + colorLabel = new QLabel; + colorLabel->setFrameStyle(frameStyle); + QPushButton *colorButton = new QPushButton(tr("QColorDialog::get&Color()")); + + fontLabel = new QLabel; + fontLabel->setFrameStyle(frameStyle); + QPushButton *fontButton = new QPushButton(tr("QFontDialog::get&Font()")); + + directoryLabel = new QLabel; + directoryLabel->setFrameStyle(frameStyle); + QPushButton *directoryButton = + new QPushButton(tr("QFileDialog::getE&xistingDirectory()")); + + openFileNameLabel = new QLabel; + openFileNameLabel->setFrameStyle(frameStyle); + QPushButton *openFileNameButton = + new QPushButton(tr("QFileDialog::get&OpenFileName()")); + + openFileNamesLabel = new QLabel; + openFileNamesLabel->setFrameStyle(frameStyle); + QPushButton *openFileNamesButton = + new QPushButton(tr("QFileDialog::&getOpenFileNames()")); + + saveFileNameLabel = new QLabel; + saveFileNameLabel->setFrameStyle(frameStyle); + QPushButton *saveFileNameButton = + new QPushButton(tr("QFileDialog::get&SaveFileName()")); + + criticalLabel = new QLabel; + criticalLabel->setFrameStyle(frameStyle); + QPushButton *criticalButton = + new QPushButton(tr("QMessageBox::critica&l()")); + + informationLabel = new QLabel; + informationLabel->setFrameStyle(frameStyle); + QPushButton *informationButton = + new QPushButton(tr("QMessageBox::i&nformation()")); + + questionLabel = new QLabel; + questionLabel->setFrameStyle(frameStyle); + QPushButton *questionButton = + new QPushButton(tr("QMessageBox::&question()")); + + warningLabel = new QLabel; + warningLabel->setFrameStyle(frameStyle); + QPushButton *warningButton = new QPushButton(tr("QMessageBox::&warning()")); + + errorLabel = new QLabel; + errorLabel->setFrameStyle(frameStyle); + QPushButton *errorButton = + new QPushButton(tr("QErrorMessage::showM&essage()")); + + connect(integerButton, SIGNAL(clicked()), this, SLOT(setInteger())); + connect(doubleButton, SIGNAL(clicked()), this, SLOT(setDouble())); + connect(itemButton, SIGNAL(clicked()), this, SLOT(setItem())); + connect(textButton, SIGNAL(clicked()), this, SLOT(setText())); + connect(colorButton, SIGNAL(clicked()), this, SLOT(setColor())); + connect(fontButton, SIGNAL(clicked()), this, SLOT(setFont())); + connect(directoryButton, SIGNAL(clicked()), + this, SLOT(setExistingDirectory())); + connect(openFileNameButton, SIGNAL(clicked()), + this, SLOT(setOpenFileName())); + connect(openFileNamesButton, SIGNAL(clicked()), + this, SLOT(setOpenFileNames())); + connect(saveFileNameButton, SIGNAL(clicked()), + this, SLOT(setSaveFileName())); + connect(criticalButton, SIGNAL(clicked()), this, SLOT(criticalMessage())); + connect(informationButton, SIGNAL(clicked()), + this, SLOT(informationMessage())); + connect(questionButton, SIGNAL(clicked()), this, SLOT(questionMessage())); + connect(warningButton, SIGNAL(clicked()), this, SLOT(warningMessage())); + connect(errorButton, SIGNAL(clicked()), this, SLOT(errorMessage())); + + QWidget *page = new QWidget; + QGridLayout *layout = new QGridLayout(page); + layout->setColumnStretch(1, 1); + layout->setColumnMinimumWidth(1, 250); + layout->addWidget(integerButton, 0, 0); + layout->addWidget(integerLabel, 0, 1); + layout->addWidget(doubleButton, 1, 0); + layout->addWidget(doubleLabel, 1, 1); + layout->addWidget(itemButton, 2, 0); + layout->addWidget(itemLabel, 2, 1); + layout->addWidget(textButton, 3, 0); + layout->addWidget(textLabel, 3, 1); + layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding), 4, 0); + toolbox->addItem(page, tr("Input Dialogs")); + + const QString doNotUseNativeDialog = tr("Do not use native dialog"); + + page = new QWidget; + layout = new QGridLayout(page); + layout->setColumnStretch(1, 1); + layout->addWidget(colorButton, 0, 0); + layout->addWidget(colorLabel, 0, 1); + colorDialogOptionsWidget = new DialogOptionsWidget; + colorDialogOptionsWidget->addCheckBox(doNotUseNativeDialog, QColorDialog::DontUseNativeDialog); + colorDialogOptionsWidget->addCheckBox(tr("Show alpha channel") , QColorDialog::ShowAlphaChannel); + colorDialogOptionsWidget->addCheckBox(tr("No buttons") , QColorDialog::NoButtons); + layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding), 1, 0); + layout->addWidget(colorDialogOptionsWidget, 2, 0, 1 ,2); + + toolbox->addItem(page, tr("Color Dialog")); + + page = new QWidget; + layout = new QGridLayout(page); + layout->setColumnStretch(1, 1); + layout->addWidget(fontButton, 0, 0); + layout->addWidget(fontLabel, 0, 1); + fontDialogOptionsWidget = new DialogOptionsWidget; + fontDialogOptionsWidget->addCheckBox(doNotUseNativeDialog, QFontDialog::DontUseNativeDialog); + fontDialogOptionsWidget->addCheckBox(tr("No buttons") , QFontDialog::NoButtons); + layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding), 1, 0); + layout->addWidget(fontDialogOptionsWidget, 2, 0, 1 ,2); + toolbox->addItem(page, tr("Font Dialog")); + + page = new QWidget; + layout = new QGridLayout(page); + layout->setColumnStretch(1, 1); + layout->addWidget(directoryButton, 0, 0); + layout->addWidget(directoryLabel, 0, 1); + layout->addWidget(openFileNameButton, 1, 0); + layout->addWidget(openFileNameLabel, 1, 1); + layout->addWidget(openFileNamesButton, 2, 0); + layout->addWidget(openFileNamesLabel, 2, 1); + layout->addWidget(saveFileNameButton, 3, 0); + layout->addWidget(saveFileNameLabel, 3, 1); + fileDialogOptionsWidget = new DialogOptionsWidget; + fileDialogOptionsWidget->addCheckBox(doNotUseNativeDialog, QFileDialog::DontUseNativeDialog); + fileDialogOptionsWidget->addCheckBox(tr("Show directories only"), QFileDialog::ShowDirsOnly); + fileDialogOptionsWidget->addCheckBox(tr("Do not resolve symlinks"), QFileDialog::DontResolveSymlinks); + fileDialogOptionsWidget->addCheckBox(tr("Do not confirm overwrite"), QFileDialog::DontConfirmOverwrite); + fileDialogOptionsWidget->addCheckBox(tr("Do not use sheet"), QFileDialog::DontUseSheet); + fileDialogOptionsWidget->addCheckBox(tr("Readonly"), QFileDialog::ReadOnly); + fileDialogOptionsWidget->addCheckBox(tr("Hide name filter details"), QFileDialog::HideNameFilterDetails); + layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding), 4, 0); + layout->addWidget(fileDialogOptionsWidget, 5, 0, 1 ,2); + toolbox->addItem(page, tr("File Dialogs")); + + page = new QWidget; + layout = new QGridLayout(page); + layout->setColumnStretch(1, 1); + layout->addWidget(criticalButton, 0, 0); + layout->addWidget(criticalLabel, 0, 1); + layout->addWidget(informationButton, 1, 0); + layout->addWidget(informationLabel, 1, 1); + layout->addWidget(questionButton, 2, 0); + layout->addWidget(questionLabel, 2, 1); + layout->addWidget(warningButton, 3, 0); + layout->addWidget(warningLabel, 3, 1); + layout->addWidget(errorButton, 4, 0); + layout->addWidget(errorLabel, 4, 1); + layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding), 5, 0); + toolbox->addItem(page, tr("Message Boxes")); + + setWindowTitle(tr("Standard Dialogs")); +} + +void Dialog::setInteger() +{ +//! [0] + bool ok; + int i = QInputDialog::getInt(this, tr("QInputDialog::getInteger()"), + tr("Percentage:"), 25, 0, 100, 1, &ok); + if (ok) + integerLabel->setText(tr("%1%").arg(i)); +//! [0] +} + +void Dialog::setDouble() +{ +//! [1] + bool ok; + double d = QInputDialog::getDouble(this, tr("QInputDialog::getDouble()"), + tr("Amount:"), 37.56, -10000, 10000, 2, &ok); + if (ok) + doubleLabel->setText(QString("$%1").arg(d)); +//! [1] +} + +void Dialog::setItem() +{ +//! [2] + QStringList items; + items << tr("Spring") << tr("Summer") << tr("Fall") << tr("Winter"); + + bool ok; + QString item = QInputDialog::getItem(this, tr("QInputDialog::getItem()"), + tr("Season:"), items, 0, false, &ok); + if (ok && !item.isEmpty()) + itemLabel->setText(item); +//! [2] +} + +void Dialog::setText() +{ +//! [3] + bool ok; + QString text = QInputDialog::getText(this, tr("QInputDialog::getText()"), + tr("User name:"), QLineEdit::Normal, + QDir::home().dirName(), &ok); + if (ok && !text.isEmpty()) + textLabel->setText(text); +//! [3] +} + +void Dialog::setColor() +{ + const QColorDialog::ColorDialogOptions options = QFlag(colorDialogOptionsWidget->value()); + const QColor color = QColorDialog::getColor(Qt::green, this, "Select Color", options); + + if (color.isValid()) { + colorLabel->setText(color.name()); + colorLabel->setPalette(QPalette(color)); + colorLabel->setAutoFillBackground(true); + } +} + +void Dialog::setFont() +{ + const QFontDialog::FontDialogOptions options = QFlag(fontDialogOptionsWidget->value()); + bool ok; + QFont font = QFontDialog::getFont(&ok, QFont(fontLabel->text()), this, "Select Font", options); + if (ok) { + fontLabel->setText(font.key()); + fontLabel->setFont(font); + } +} + +void Dialog::setExistingDirectory() +{ + QFileDialog::Options options = QFlag(fileDialogOptionsWidget->value()); + options |= QFileDialog::DontResolveSymlinks | QFileDialog::ShowDirsOnly; + QString directory = QFileDialog::getExistingDirectory(this, + tr("QFileDialog::getExistingDirectory()"), + directoryLabel->text(), + options); + if (!directory.isEmpty()) + directoryLabel->setText(directory); +} + +void Dialog::setOpenFileName() +{ + const QFileDialog::Options options = QFlag(fileDialogOptionsWidget->value()); + QString selectedFilter; + QString fileName = QFileDialog::getOpenFileName(this, + tr("QFileDialog::getOpenFileName()"), + openFileNameLabel->text(), + tr("All Files (*);;Text Files (*.txt)"), + &selectedFilter, + options); + if (!fileName.isEmpty()) + openFileNameLabel->setText(fileName); +} + +void Dialog::setOpenFileNames() +{ + const QFileDialog::Options options = QFlag(fileDialogOptionsWidget->value()); + QString selectedFilter; + QStringList files = QFileDialog::getOpenFileNames( + this, tr("QFileDialog::getOpenFileNames()"), + openFilesPath, + tr("All Files (*);;Text Files (*.txt)"), + &selectedFilter, + options); + if (files.count()) { + openFilesPath = files[0]; + openFileNamesLabel->setText(QString("[%1]").arg(files.join(", "))); + } +} + +void Dialog::setSaveFileName() +{ + const QFileDialog::Options options = QFlag(fileDialogOptionsWidget->value()); + QString selectedFilter; + QString fileName = QFileDialog::getSaveFileName(this, + tr("QFileDialog::getSaveFileName()"), + saveFileNameLabel->text(), + tr("All Files (*);;Text Files (*.txt)"), + &selectedFilter, + options); + if (!fileName.isEmpty()) + saveFileNameLabel->setText(fileName); +} + +void Dialog::criticalMessage() +{ + QMessageBox::StandardButton reply; + reply = QMessageBox::critical(this, tr("QMessageBox::critical()"), + MESSAGE, + QMessageBox::Abort | QMessageBox::Retry | QMessageBox::Ignore); + if (reply == QMessageBox::Abort) + criticalLabel->setText(tr("Abort")); + else if (reply == QMessageBox::Retry) + criticalLabel->setText(tr("Retry")); + else + criticalLabel->setText(tr("Ignore")); +} + +void Dialog::informationMessage() +{ + QMessageBox::StandardButton reply; + reply = QMessageBox::information(this, tr("QMessageBox::information()"), MESSAGE); + if (reply == QMessageBox::Ok) + informationLabel->setText(tr("OK")); + else + informationLabel->setText(tr("Escape")); +} + +void Dialog::questionMessage() +{ + QMessageBox::StandardButton reply; + reply = QMessageBox::question(this, tr("QMessageBox::question()"), + MESSAGE, + QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel); + if (reply == QMessageBox::Yes) + questionLabel->setText(tr("Yes")); + else if (reply == QMessageBox::No) + questionLabel->setText(tr("No")); + else + questionLabel->setText(tr("Cancel")); +} + +void Dialog::warningMessage() +{ + QMessageBox msgBox(QMessageBox::Warning, tr("QMessageBox::warning()"), + MESSAGE, 0, this); + msgBox.addButton(tr("Save &Again"), QMessageBox::AcceptRole); + msgBox.addButton(tr("&Continue"), QMessageBox::RejectRole); + if (msgBox.exec() == QMessageBox::AcceptRole) + warningLabel->setText(tr("Save Again")); + else + warningLabel->setText(tr("Continue")); + +} + +void Dialog::errorMessage() +{ + errorMessageDialog->showMessage( + tr("This dialog shows and remembers error messages. " + "If the checkbox is checked (as it is by default), " + "the shown message will be shown again, " + "but if the user unchecks the box the message " + "will not appear again if QErrorMessage::showMessage() " + "is called with the same message.")); + errorLabel->setText(tr("If the box is unchecked, the message " + "won't appear again.")); +} diff --git a/examples/widgets/dialogs/standarddialogs/dialog.h b/examples/widgets/dialogs/standarddialogs/dialog.h new file mode 100644 index 0000000000..2b14d793d6 --- /dev/null +++ b/examples/widgets/dialogs/standarddialogs/dialog.h @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef DIALOG_H +#define DIALOG_H + +#include <QWidget> + +QT_BEGIN_NAMESPACE +class QCheckBox; +class QLabel; +class QErrorMessage; +QT_END_NAMESPACE + +class DialogOptionsWidget; + +class Dialog : public QWidget +{ + Q_OBJECT + +public: + Dialog(QWidget *parent = 0); + +private slots: + void setInteger(); + void setDouble(); + void setItem(); + void setText(); + void setColor(); + void setFont(); + void setExistingDirectory(); + void setOpenFileName(); + void setOpenFileNames(); + void setSaveFileName(); + void criticalMessage(); + void informationMessage(); + void questionMessage(); + void warningMessage(); + void errorMessage(); + +private: + QLabel *integerLabel; + QLabel *doubleLabel; + QLabel *itemLabel; + QLabel *textLabel; + QLabel *colorLabel; + QLabel *fontLabel; + QLabel *directoryLabel; + QLabel *openFileNameLabel; + QLabel *openFileNamesLabel; + QLabel *saveFileNameLabel; + QLabel *criticalLabel; + QLabel *informationLabel; + QLabel *questionLabel; + QLabel *warningLabel; + QLabel *errorLabel; + QErrorMessage *errorMessageDialog; + DialogOptionsWidget *fileDialogOptionsWidget; + DialogOptionsWidget *colorDialogOptionsWidget; + DialogOptionsWidget *fontDialogOptionsWidget; + QString openFilesPath; +}; + +#endif diff --git a/examples/widgets/dialogs/standarddialogs/main.cpp b/examples/widgets/dialogs/standarddialogs/main.cpp new file mode 100644 index 0000000000..001239929e --- /dev/null +++ b/examples/widgets/dialogs/standarddialogs/main.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> +#include <QTranslator> +#include <QLocale> +#include <QLibraryInfo> + +#include "dialog.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + QString translatorFileName = QLatin1String("qt_"); + translatorFileName += QLocale::system().name(); + QTranslator *translator = new QTranslator(&app); + if (translator->load(translatorFileName, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) + app.installTranslator(translator); + + Dialog dialog; + dialog.show(); + + return app.exec(); +} diff --git a/examples/widgets/dialogs/standarddialogs/standarddialogs.desktop b/examples/widgets/dialogs/standarddialogs/standarddialogs.desktop new file mode 100644 index 0000000000..f74830317a --- /dev/null +++ b/examples/widgets/dialogs/standarddialogs/standarddialogs.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Encoding=UTF-8 +Version=1.0 +Type=Application +Terminal=false +Name=Standard Dialogs +Exec=/opt/usr/bin/standarddialogs +Icon=standarddialogs +X-Window-Icon= +X-HildonDesk-ShowInToolbar=true +X-Osso-Type=application/x-executable diff --git a/examples/widgets/dialogs/standarddialogs/standarddialogs.pro b/examples/widgets/dialogs/standarddialogs/standarddialogs.pro new file mode 100644 index 0000000000..cbcb4d7302 --- /dev/null +++ b/examples/widgets/dialogs/standarddialogs/standarddialogs.pro @@ -0,0 +1,13 @@ +HEADERS = dialog.h +SOURCES = dialog.cpp \ + main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/standarddialogs +sources.files = $$SOURCES $$HEADERS *.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/standarddialogs +INSTALLS += target sources + +wince50standard-x86-msvc2005: LIBS += libcmt.lib corelibc.lib ole32.lib oleaut32.lib uuid.lib commctrl.lib coredll.lib winsock.lib ws2.lib + +QT += widgets diff --git a/examples/widgets/dialogs/tabdialog/main.cpp b/examples/widgets/dialogs/tabdialog/main.cpp new file mode 100644 index 0000000000..119a4c272c --- /dev/null +++ b/examples/widgets/dialogs/tabdialog/main.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> + +#include "tabdialog.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + QString fileName; + + if (argc >= 2) + fileName = argv[1]; + else + fileName = "."; + + TabDialog tabdialog(fileName); + tabdialog.show(); + + return app.exec(); +} diff --git a/examples/widgets/dialogs/tabdialog/tabdialog.cpp b/examples/widgets/dialogs/tabdialog/tabdialog.cpp new file mode 100644 index 0000000000..00e3706c5c --- /dev/null +++ b/examples/widgets/dialogs/tabdialog/tabdialog.cpp @@ -0,0 +1,196 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtWidgets> + +#include "tabdialog.h" + +//! [0] +TabDialog::TabDialog(const QString &fileName, QWidget *parent) + : QDialog(parent) +{ + QFileInfo fileInfo(fileName); + + tabWidget = new QTabWidget; + tabWidget->addTab(new GeneralTab(fileInfo), tr("General")); + tabWidget->addTab(new PermissionsTab(fileInfo), tr("Permissions")); + tabWidget->addTab(new ApplicationsTab(fileInfo), tr("Applications")); +//! [0] + +//! [1] //! [2] + buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok +//! [1] //! [3] + | QDialogButtonBox::Cancel); + + connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); + connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); +//! [2] //! [3] + +//! [4] + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->setSizeConstraint(QLayout::SetNoConstraint); + mainLayout->addWidget(tabWidget); + mainLayout->addWidget(buttonBox); + setLayout(mainLayout); +//! [4] + +//! [5] + setWindowTitle(tr("Tab Dialog")); +} +//! [5] + +//! [6] +GeneralTab::GeneralTab(const QFileInfo &fileInfo, QWidget *parent) + : QWidget(parent) +{ + QLabel *fileNameLabel = new QLabel(tr("File Name:")); + QLineEdit *fileNameEdit = new QLineEdit(fileInfo.fileName()); + + QLabel *pathLabel = new QLabel(tr("Path:")); + QLabel *pathValueLabel = new QLabel(fileInfo.absoluteFilePath()); + pathValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken); + + QLabel *sizeLabel = new QLabel(tr("Size:")); + qlonglong size = fileInfo.size()/1024; + QLabel *sizeValueLabel = new QLabel(tr("%1 K").arg(size)); + sizeValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken); + + QLabel *lastReadLabel = new QLabel(tr("Last Read:")); + QLabel *lastReadValueLabel = new QLabel(fileInfo.lastRead().toString()); + lastReadValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken); + + QLabel *lastModLabel = new QLabel(tr("Last Modified:")); + QLabel *lastModValueLabel = new QLabel(fileInfo.lastModified().toString()); + lastModValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addWidget(fileNameLabel); + mainLayout->addWidget(fileNameEdit); + mainLayout->addWidget(pathLabel); + mainLayout->addWidget(pathValueLabel); + mainLayout->addWidget(sizeLabel); + mainLayout->addWidget(sizeValueLabel); + mainLayout->addWidget(lastReadLabel); + mainLayout->addWidget(lastReadValueLabel); + mainLayout->addWidget(lastModLabel); + mainLayout->addWidget(lastModValueLabel); + mainLayout->addStretch(1); + setLayout(mainLayout); +} +//! [6] + +//! [7] +PermissionsTab::PermissionsTab(const QFileInfo &fileInfo, QWidget *parent) + : QWidget(parent) +{ + QGroupBox *permissionsGroup = new QGroupBox(tr("Permissions")); + + QCheckBox *readable = new QCheckBox(tr("Readable")); + if (fileInfo.isReadable()) + readable->setChecked(true); + + QCheckBox *writable = new QCheckBox(tr("Writable")); + if ( fileInfo.isWritable() ) + writable->setChecked(true); + + QCheckBox *executable = new QCheckBox(tr("Executable")); + if ( fileInfo.isExecutable() ) + executable->setChecked(true); + + QGroupBox *ownerGroup = new QGroupBox(tr("Ownership")); + + QLabel *ownerLabel = new QLabel(tr("Owner")); + QLabel *ownerValueLabel = new QLabel(fileInfo.owner()); + ownerValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken); + + QLabel *groupLabel = new QLabel(tr("Group")); + QLabel *groupValueLabel = new QLabel(fileInfo.group()); + groupValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken); + + QVBoxLayout *permissionsLayout = new QVBoxLayout; + permissionsLayout->addWidget(readable); + permissionsLayout->addWidget(writable); + permissionsLayout->addWidget(executable); + permissionsGroup->setLayout(permissionsLayout); + + QVBoxLayout *ownerLayout = new QVBoxLayout; + ownerLayout->addWidget(ownerLabel); + ownerLayout->addWidget(ownerValueLabel); + ownerLayout->addWidget(groupLabel); + ownerLayout->addWidget(groupValueLabel); + ownerGroup->setLayout(ownerLayout); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addWidget(permissionsGroup); + mainLayout->addWidget(ownerGroup); + mainLayout->addStretch(1); + setLayout(mainLayout); +} +//! [7] + +//! [8] +ApplicationsTab::ApplicationsTab(const QFileInfo &fileInfo, QWidget *parent) + : QWidget(parent) +{ + QLabel *topLabel = new QLabel(tr("Open with:")); + + QListWidget *applicationsListBox = new QListWidget; + QStringList applications; + + for (int i = 1; i <= 30; ++i) + applications.append(tr("Application %1").arg(i)); + applicationsListBox->insertItems(0, applications); + + QCheckBox *alwaysCheckBox; + + if (fileInfo.suffix().isEmpty()) + alwaysCheckBox = new QCheckBox(tr("Always use this application to " + "open this type of file")); + else + alwaysCheckBox = new QCheckBox(tr("Always use this application to " + "open files with the extension '%1'").arg(fileInfo.suffix())); + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(topLabel); + layout->addWidget(applicationsListBox); + layout->addWidget(alwaysCheckBox); + setLayout(layout); +} +//! [8] diff --git a/examples/widgets/dialogs/tabdialog/tabdialog.desktop b/examples/widgets/dialogs/tabdialog/tabdialog.desktop new file mode 100644 index 0000000000..651f7d4068 --- /dev/null +++ b/examples/widgets/dialogs/tabdialog/tabdialog.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Encoding=UTF-8 +Version=1.0 +Type=Application +Terminal=false +Name=Tab Dialog +Exec=/opt/usr/bin/tabdialog +Icon=tabdialog +X-Window-Icon= +X-HildonDesk-ShowInToolbar=true +X-Osso-Type=application/x-executable diff --git a/examples/widgets/dialogs/tabdialog/tabdialog.h b/examples/widgets/dialogs/tabdialog/tabdialog.h new file mode 100644 index 0000000000..c2b46f0e92 --- /dev/null +++ b/examples/widgets/dialogs/tabdialog/tabdialog.h @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TABDIALOG_H +#define TABDIALOG_H + +#include <QDialog> + +QT_BEGIN_NAMESPACE +class QDialogButtonBox; +class QFileInfo; +class QTabWidget; +QT_END_NAMESPACE + +//! [0] +class GeneralTab : public QWidget +{ + Q_OBJECT + +public: + GeneralTab(const QFileInfo &fileInfo, QWidget *parent = 0); +}; +//! [0] + + +//! [1] +class PermissionsTab : public QWidget +{ + Q_OBJECT + +public: + PermissionsTab(const QFileInfo &fileInfo, QWidget *parent = 0); +}; +//! [1] + + +//! [2] +class ApplicationsTab : public QWidget +{ + Q_OBJECT + +public: + ApplicationsTab(const QFileInfo &fileInfo, QWidget *parent = 0); +}; +//! [2] + + +//! [3] +class TabDialog : public QDialog +{ + Q_OBJECT + +public: + TabDialog(const QString &fileName, QWidget *parent = 0); + +private: + QTabWidget *tabWidget; + QDialogButtonBox *buttonBox; +}; +//! [3] + +#endif diff --git a/examples/widgets/dialogs/tabdialog/tabdialog.pro b/examples/widgets/dialogs/tabdialog/tabdialog.pro new file mode 100644 index 0000000000..66ac14daf2 --- /dev/null +++ b/examples/widgets/dialogs/tabdialog/tabdialog.pro @@ -0,0 +1,12 @@ +HEADERS = tabdialog.h +SOURCES = main.cpp \ + tabdialog.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/tabdialog +sources.files = $$SOURCES $$HEADERS *.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/tabdialog +INSTALLS += target sources + +wince50standard-x86-msvc2005: LIBS += libcmt.lib corelibc.lib ole32.lib oleaut32.lib uuid.lib commctrl.lib coredll.lib winsock.lib ws2.lib +QT += widgets diff --git a/examples/widgets/dialogs/trivialwizard/trivialwizard.cpp b/examples/widgets/dialogs/trivialwizard/trivialwizard.cpp new file mode 100644 index 0000000000..f8209405d9 --- /dev/null +++ b/examples/widgets/dialogs/trivialwizard/trivialwizard.cpp @@ -0,0 +1,135 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtWidgets> +#include <QTranslator> +#include <QLocale> +#include <QLibraryInfo> + +//! [0] //! [1] +QWizardPage *createIntroPage() +{ + QWizardPage *page = new QWizardPage; + page->setTitle("Introduction"); + + QLabel *label = new QLabel("This wizard will help you register your copy " + "of Super Product Two."); + label->setWordWrap(true); + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(label); + page->setLayout(layout); + + return page; +} +//! [0] + +//! [2] +QWizardPage *createRegistrationPage() +//! [1] //! [3] +{ +//! [3] + QWizardPage *page = new QWizardPage; + page->setTitle("Registration"); + page->setSubTitle("Please fill both fields."); + + QLabel *nameLabel = new QLabel("Name:"); + QLineEdit *nameLineEdit = new QLineEdit; + + QLabel *emailLabel = new QLabel("Email address:"); + QLineEdit *emailLineEdit = new QLineEdit; + + QGridLayout *layout = new QGridLayout; + layout->addWidget(nameLabel, 0, 0); + layout->addWidget(nameLineEdit, 0, 1); + layout->addWidget(emailLabel, 1, 0); + layout->addWidget(emailLineEdit, 1, 1); + page->setLayout(layout); + + return page; +//! [4] +} +//! [2] //! [4] + +//! [5] //! [6] +QWizardPage *createConclusionPage() +//! [5] //! [7] +{ +//! [7] + QWizardPage *page = new QWizardPage; + page->setTitle("Conclusion"); + + QLabel *label = new QLabel("You are now successfully registered. Have a " + "nice day!"); + label->setWordWrap(true); + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(label); + page->setLayout(layout); + + return page; +//! [8] +} +//! [6] //! [8] + +//! [9] //! [10] +int main(int argc, char *argv[]) +//! [9] //! [11] +{ + QApplication app(argc, argv); + + QString translatorFileName = QLatin1String("qt_"); + translatorFileName += QLocale::system().name(); + QTranslator *translator = new QTranslator(&app); + if (translator->load(translatorFileName, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) + app.installTranslator(translator); + + + QWizard wizard; + wizard.addPage(createIntroPage()); + wizard.addPage(createRegistrationPage()); + wizard.addPage(createConclusionPage()); + + wizard.setWindowTitle("Trivial Wizard"); + wizard.show(); + + return app.exec(); +} +//! [10] //! [11] diff --git a/examples/widgets/dialogs/trivialwizard/trivialwizard.desktop b/examples/widgets/dialogs/trivialwizard/trivialwizard.desktop new file mode 100644 index 0000000000..fad568ecc8 --- /dev/null +++ b/examples/widgets/dialogs/trivialwizard/trivialwizard.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Encoding=UTF-8 +Version=1.0 +Type=Application +Terminal=false +Name=Trivial Wizard +Exec=/opt/usr/bin/trivialwizard +Icon=trivialwizard +X-Window-Icon= +X-HildonDesk-ShowInToolbar=true +X-Osso-Type=application/x-executable diff --git a/examples/widgets/dialogs/trivialwizard/trivialwizard.pro b/examples/widgets/dialogs/trivialwizard/trivialwizard.pro new file mode 100644 index 0000000000..26d488d99d --- /dev/null +++ b/examples/widgets/dialogs/trivialwizard/trivialwizard.pro @@ -0,0 +1,10 @@ +SOURCES = trivialwizard.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/trivialwizard +sources.files = $$SOURCES $$HEADERS *.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/trivialwizard +INSTALLS += target sources + +QT += widgets +simulator: warning(This example might not fully work on Simulator platform) |