mirror of
https://github.com/crystalidea/qt6windows7.git
synced 2025-07-03 07:45:30 +08:00
qt 6.5.1 original
This commit is contained in:
51
examples/widgets/dialogs/licensewizard/CMakeLists.txt
Normal file
51
examples/widgets/dialogs/licensewizard/CMakeLists.txt
Normal file
@ -0,0 +1,51 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(licensewizard LANGUAGES CXX)
|
||||
|
||||
if(NOT DEFINED INSTALL_EXAMPLESDIR)
|
||||
set(INSTALL_EXAMPLESDIR "examples")
|
||||
endif()
|
||||
|
||||
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/dialogs/licensewizard")
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core Gui PrintSupport Widgets)
|
||||
|
||||
qt_standard_project_setup()
|
||||
|
||||
qt_add_executable(licensewizard
|
||||
licensewizard.cpp licensewizard.h
|
||||
main.cpp
|
||||
)
|
||||
|
||||
set_target_properties(licensewizard PROPERTIES
|
||||
WIN32_EXECUTABLE TRUE
|
||||
MACOSX_BUNDLE TRUE
|
||||
)
|
||||
|
||||
target_link_libraries(licensewizard PRIVATE
|
||||
Qt6::Core
|
||||
Qt6::Gui
|
||||
Qt6::PrintSupport
|
||||
Qt6::Widgets
|
||||
)
|
||||
|
||||
# Resources:
|
||||
set(licensewizard_resource_files
|
||||
"images/logo.png"
|
||||
"images/watermark.png"
|
||||
)
|
||||
|
||||
qt_add_resources(licensewizard "licensewizard"
|
||||
PREFIX
|
||||
"/"
|
||||
FILES
|
||||
${licensewizard_resource_files}
|
||||
)
|
||||
|
||||
install(TARGETS licensewizard
|
||||
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
)
|
BIN
examples/widgets/dialogs/licensewizard/images/logo.png
Normal file
BIN
examples/widgets/dialogs/licensewizard/images/logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
BIN
examples/widgets/dialogs/licensewizard/images/watermark.png
Normal file
BIN
examples/widgets/dialogs/licensewizard/images/watermark.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 34 KiB |
333
examples/widgets/dialogs/licensewizard/licensewizard.cpp
Normal file
333
examples/widgets/dialogs/licensewizard/licensewizard.cpp
Normal file
@ -0,0 +1,333 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include <QtWidgets>
|
||||
#if defined(QT_PRINTSUPPORT_LIB)
|
||||
#include <QtPrintSupport/qtprintsupportglobal.h>
|
||||
#if QT_CONFIG(printdialog)
|
||||
#include <QPrinter>
|
||||
#include <QPrintDialog>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "licensewizard.h"
|
||||
|
||||
QString emailRegExp = QStringLiteral(".+@.+");
|
||||
|
||||
//! [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, &QWizard::helpRequested, this, &LicenseWizard::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 QRegularExpressionValidator(QRegularExpression(emailRegExp), 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 QRegularExpressionValidator(QRegularExpression(emailRegExp), 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(), &QWizard::customButtonClicked,
|
||||
this, &ConclusionPage::printButtonClicked);
|
||||
//! [29]
|
||||
} else {
|
||||
wizard()->setOption(QWizard::HaveCustomButton1, false);
|
||||
disconnect(wizard(), &QWizard::customButtonClicked,
|
||||
this, &ConclusionPage::printButtonClicked);
|
||||
}
|
||||
}
|
||||
//! [28]
|
||||
|
||||
void ConclusionPage::printButtonClicked()
|
||||
{
|
||||
#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printdialog)
|
||||
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
|
||||
}
|
126
examples/widgets/dialogs/licensewizard/licensewizard.h
Normal file
126
examples/widgets/dialogs/licensewizard/licensewizard.h
Normal file
@ -0,0 +1,126 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#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 = nullptr);
|
||||
|
||||
private slots:
|
||||
void showHelp();
|
||||
//! [3]
|
||||
};
|
||||
//! [1] //! [3]
|
||||
|
||||
//! [4]
|
||||
class IntroPage : public QWizardPage
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
IntroPage(QWidget *parent = nullptr);
|
||||
|
||||
int nextId() const override;
|
||||
|
||||
private:
|
||||
QLabel *topLabel;
|
||||
QRadioButton *registerRadioButton;
|
||||
QRadioButton *evaluateRadioButton;
|
||||
};
|
||||
//! [4]
|
||||
|
||||
//! [5]
|
||||
class EvaluatePage : public QWizardPage
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
EvaluatePage(QWidget *parent = nullptr);
|
||||
|
||||
int nextId() const override;
|
||||
|
||||
private:
|
||||
QLabel *nameLabel;
|
||||
QLabel *emailLabel;
|
||||
QLineEdit *nameLineEdit;
|
||||
QLineEdit *emailLineEdit;
|
||||
};
|
||||
//! [5]
|
||||
|
||||
class RegisterPage : public QWizardPage
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
RegisterPage(QWidget *parent = nullptr);
|
||||
|
||||
int nextId() const override;
|
||||
|
||||
private:
|
||||
QLabel *nameLabel;
|
||||
QLabel *upgradeKeyLabel;
|
||||
QLineEdit *nameLineEdit;
|
||||
QLineEdit *upgradeKeyLineEdit;
|
||||
};
|
||||
|
||||
class DetailsPage : public QWizardPage
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DetailsPage(QWidget *parent = nullptr);
|
||||
|
||||
int nextId() const override;
|
||||
|
||||
private:
|
||||
QLabel *companyLabel;
|
||||
QLabel *emailLabel;
|
||||
QLabel *postalLabel;
|
||||
QLineEdit *companyLineEdit;
|
||||
QLineEdit *emailLineEdit;
|
||||
QLineEdit *postalLineEdit;
|
||||
};
|
||||
|
||||
//! [6]
|
||||
class ConclusionPage : public QWizardPage
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ConclusionPage(QWidget *parent = nullptr);
|
||||
|
||||
void initializePage() override;
|
||||
int nextId() const override;
|
||||
void setVisible(bool visible) override;
|
||||
|
||||
private slots:
|
||||
void printButtonClicked();
|
||||
|
||||
private:
|
||||
QLabel *bottomLabel;
|
||||
QCheckBox *agreeCheckBox;
|
||||
};
|
||||
//! [6]
|
||||
|
||||
#endif
|
10
examples/widgets/dialogs/licensewizard/licensewizard.pro
Normal file
10
examples/widgets/dialogs/licensewizard/licensewizard.pro
Normal file
@ -0,0 +1,10 @@
|
||||
QT += widgets printsupport
|
||||
|
||||
HEADERS = licensewizard.h
|
||||
SOURCES = licensewizard.cpp \
|
||||
main.cpp
|
||||
RESOURCES = licensewizard.qrc
|
||||
|
||||
# install
|
||||
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/dialogs/licensewizard
|
||||
INSTALLS += target
|
6
examples/widgets/dialogs/licensewizard/licensewizard.qrc
Normal file
6
examples/widgets/dialogs/licensewizard/licensewizard.qrc
Normal file
@ -0,0 +1,6 @@
|
||||
<!DOCTYPE RCC><RCC version="1.0">
|
||||
<qresource>
|
||||
<file>images/logo.png</file>
|
||||
<file>images/watermark.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
28
examples/widgets/dialogs/licensewizard/main.cpp
Normal file
28
examples/widgets/dialogs/licensewizard/main.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#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);
|
||||
|
||||
#ifndef QT_NO_TRANSLATION
|
||||
QString translatorFileName = QLatin1String("qtbase_");
|
||||
translatorFileName += QLocale::system().name();
|
||||
QTranslator *translator = new QTranslator(&app);
|
||||
if (translator->load(translatorFileName, QLibraryInfo::path(QLibraryInfo::TranslationsPath)))
|
||||
app.installTranslator(translator);
|
||||
#endif
|
||||
|
||||
LicenseWizard wizard;
|
||||
wizard.show();
|
||||
return app.exec();
|
||||
}
|
Reference in New Issue
Block a user