qt 6.5.1 original
13
examples/widgets/dialogs/CMakeLists.txt
Normal file
@ -0,0 +1,13 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
if(QT_FEATURE_wizard)
|
||||
qt_internal_add_example(classwizard)
|
||||
qt_internal_add_example(trivialwizard)
|
||||
endif()
|
||||
qt_internal_add_example(extension)
|
||||
qt_internal_add_example(standarddialogs)
|
||||
qt_internal_add_example(tabdialog)
|
||||
if(QT_FEATURE_wizard AND TARGET Qt6::PrintSupport)
|
||||
qt_internal_add_example(licensewizard)
|
||||
endif()
|
9
examples/widgets/dialogs/README
Normal file
@ -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.
|
55
examples/widgets/dialogs/classwizard/CMakeLists.txt
Normal file
@ -0,0 +1,55 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(classwizard LANGUAGES CXX)
|
||||
|
||||
if(NOT DEFINED INSTALL_EXAMPLESDIR)
|
||||
set(INSTALL_EXAMPLESDIR "examples")
|
||||
endif()
|
||||
|
||||
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/dialogs/classwizard")
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
|
||||
|
||||
qt_standard_project_setup()
|
||||
|
||||
qt_add_executable(classwizard
|
||||
classwizard.cpp classwizard.h
|
||||
main.cpp
|
||||
)
|
||||
|
||||
set_target_properties(classwizard PROPERTIES
|
||||
WIN32_EXECUTABLE TRUE
|
||||
MACOSX_BUNDLE TRUE
|
||||
)
|
||||
|
||||
target_link_libraries(classwizard PRIVATE
|
||||
Qt6::Core
|
||||
Qt6::Gui
|
||||
Qt6::Widgets
|
||||
)
|
||||
|
||||
# Resources:
|
||||
set(classwizard_resource_files
|
||||
"images/background.png"
|
||||
"images/banner.png"
|
||||
"images/logo1.png"
|
||||
"images/logo2.png"
|
||||
"images/logo3.png"
|
||||
"images/watermark1.png"
|
||||
"images/watermark2.png"
|
||||
)
|
||||
|
||||
qt_add_resources(classwizard "classwizard"
|
||||
PREFIX
|
||||
"/"
|
||||
FILES
|
||||
${classwizard_resource_files}
|
||||
)
|
||||
|
||||
install(TARGETS classwizard
|
||||
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
)
|
394
examples/widgets/dialogs/classwizard/classwizard.cpp
Normal file
@ -0,0 +1,394 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#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 = nullptr);\n";
|
||||
} else if (field("qwidgetCtor").toBool()) {
|
||||
block += " " + className + "(QWidget *parent = nullptr);\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(nullptr, 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(nullptr, 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, &QAbstractButton::toggled,
|
||||
copyCtorCheckBox, &QWidget::setEnabled);
|
||||
|
||||
//! [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, &QAbstractButton::toggled,
|
||||
macroNameLabel, &QWidget::setEnabled);
|
||||
connect(protectCheckBox, &QAbstractButton::toggled,
|
||||
macroNameLineEdit, &QWidget::setEnabled);
|
||||
connect(includeBaseCheckBox, &QAbstractButton::toggled,
|
||||
baseIncludeLabel, &QWidget::setEnabled);
|
||||
connect(includeBaseCheckBox, &QAbstractButton::toggled,
|
||||
baseIncludeLineEdit, &QWidget::setEnabled);
|
||||
|
||||
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());
|
||||
|
||||
QRegularExpression rx("Q[A-Z].*");
|
||||
if (baseClass.isEmpty()) {
|
||||
baseIncludeLineEdit->clear();
|
||||
} else if (rx.match(baseClass).hasMatch()) {
|
||||
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));
|
||||
}
|
119
examples/widgets/dialogs/classwizard/classwizard.h
Normal file
@ -0,0 +1,119 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#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 = nullptr);
|
||||
|
||||
void accept() override;
|
||||
};
|
||||
//! [0]
|
||||
|
||||
//! [1]
|
||||
class IntroPage : public QWizardPage
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
IntroPage(QWidget *parent = nullptr);
|
||||
|
||||
private:
|
||||
QLabel *label;
|
||||
};
|
||||
//! [1]
|
||||
|
||||
//! [2]
|
||||
class ClassInfoPage : public QWizardPage
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ClassInfoPage(QWidget *parent = nullptr);
|
||||
|
||||
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 = nullptr);
|
||||
|
||||
protected:
|
||||
void initializePage() override;
|
||||
|
||||
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 = nullptr);
|
||||
|
||||
protected:
|
||||
void initializePage() override;
|
||||
|
||||
private:
|
||||
QLabel *outputDirLabel;
|
||||
QLabel *headerLabel;
|
||||
QLabel *implementationLabel;
|
||||
QLineEdit *outputDirLineEdit;
|
||||
QLineEdit *headerLineEdit;
|
||||
QLineEdit *implementationLineEdit;
|
||||
};
|
||||
|
||||
class ConclusionPage : public QWizardPage
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ConclusionPage(QWidget *parent = nullptr);
|
||||
|
||||
protected:
|
||||
void initializePage() override;
|
||||
|
||||
private:
|
||||
QLabel *label;
|
||||
};
|
||||
|
||||
#endif
|
10
examples/widgets/dialogs/classwizard/classwizard.pro
Normal file
@ -0,0 +1,10 @@
|
||||
QT += widgets
|
||||
|
||||
HEADERS = classwizard.h
|
||||
SOURCES = classwizard.cpp \
|
||||
main.cpp
|
||||
RESOURCES = classwizard.qrc
|
||||
|
||||
# install
|
||||
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/dialogs/classwizard
|
||||
INSTALLS += target
|
11
examples/widgets/dialogs/classwizard/classwizard.qrc
Normal file
@ -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>
|
BIN
examples/widgets/dialogs/classwizard/images/background.png
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
examples/widgets/dialogs/classwizard/images/banner.png
Normal file
After Width: | Height: | Size: 3.9 KiB |
BIN
examples/widgets/dialogs/classwizard/images/logo1.png
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
examples/widgets/dialogs/classwizard/images/logo2.png
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
examples/widgets/dialogs/classwizard/images/logo3.png
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
examples/widgets/dialogs/classwizard/images/watermark1.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
examples/widgets/dialogs/classwizard/images/watermark2.png
Normal file
After Width: | Height: | Size: 15 KiB |
28
examples/widgets/dialogs/classwizard/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 "classwizard.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
Q_INIT_RESOURCE(classwizard);
|
||||
|
||||
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
|
||||
|
||||
ClassWizard wizard;
|
||||
wizard.show();
|
||||
return app.exec();
|
||||
}
|
14
examples/widgets/dialogs/dialogs.pro
Normal file
@ -0,0 +1,14 @@
|
||||
QT_FOR_CONFIG += widgets
|
||||
|
||||
TEMPLATE = subdirs
|
||||
SUBDIRS = classwizard \
|
||||
extension \
|
||||
licensewizard \
|
||||
standarddialogs \
|
||||
tabdialog \
|
||||
trivialwizard
|
||||
|
||||
!qtHaveModule(printsupport): SUBDIRS -= licensewizard
|
||||
!qtConfig(wizard) {
|
||||
SUBDIRS -= trivialwizard licensewizard classwizard
|
||||
}
|
37
examples/widgets/dialogs/extension/CMakeLists.txt
Normal file
@ -0,0 +1,37 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(extension LANGUAGES CXX)
|
||||
|
||||
if(NOT DEFINED INSTALL_EXAMPLESDIR)
|
||||
set(INSTALL_EXAMPLESDIR "examples")
|
||||
endif()
|
||||
|
||||
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/dialogs/extension")
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
|
||||
|
||||
qt_standard_project_setup()
|
||||
|
||||
qt_add_executable(extension
|
||||
finddialog.cpp finddialog.h
|
||||
main.cpp
|
||||
)
|
||||
|
||||
set_target_properties(extension PROPERTIES
|
||||
WIN32_EXECUTABLE TRUE
|
||||
MACOSX_BUNDLE TRUE
|
||||
)
|
||||
|
||||
target_link_libraries(extension PRIVATE
|
||||
Qt6::Core
|
||||
Qt6::Gui
|
||||
Qt6::Widgets
|
||||
)
|
||||
|
||||
install(TARGETS extension
|
||||
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
)
|
9
examples/widgets/dialogs/extension/extension.pro
Normal file
@ -0,0 +1,9 @@
|
||||
QT += widgets
|
||||
|
||||
HEADERS = finddialog.h
|
||||
SOURCES = finddialog.cpp \
|
||||
main.cpp
|
||||
|
||||
# install
|
||||
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/dialogs/extension
|
||||
INSTALLS += target
|
77
examples/widgets/dialogs/extension/finddialog.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#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, &QAbstractButton::toggled, extension, &QWidget::setVisible);
|
||||
|
||||
QVBoxLayout *extensionLayout = new QVBoxLayout;
|
||||
extensionLayout->setContentsMargins(QMargins());
|
||||
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]
|
41
examples/widgets/dialogs/extension/finddialog.h
Normal file
@ -0,0 +1,41 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#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 = nullptr);
|
||||
|
||||
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
|
16
examples/widgets/dialogs/extension/main.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
#include "finddialog.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
FindDialog dialog;
|
||||
|
||||
dialog.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
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
After Width: | Height: | Size: 1.8 KiB |
BIN
examples/widgets/dialogs/licensewizard/images/watermark.png
Normal file
After Width: | Height: | Size: 34 KiB |
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
@ -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
@ -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
@ -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
@ -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();
|
||||
}
|
37
examples/widgets/dialogs/standarddialogs/CMakeLists.txt
Normal file
@ -0,0 +1,37 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(standarddialogs LANGUAGES CXX)
|
||||
|
||||
if(NOT DEFINED INSTALL_EXAMPLESDIR)
|
||||
set(INSTALL_EXAMPLESDIR "examples")
|
||||
endif()
|
||||
|
||||
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/dialogs/standarddialogs")
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
|
||||
|
||||
qt_standard_project_setup()
|
||||
|
||||
qt_add_executable(standarddialogs
|
||||
dialog.cpp dialog.h
|
||||
main.cpp
|
||||
)
|
||||
|
||||
set_target_properties(standarddialogs PROPERTIES
|
||||
WIN32_EXECUTABLE TRUE
|
||||
MACOSX_BUNDLE TRUE
|
||||
)
|
||||
|
||||
target_link_libraries(standarddialogs PRIVATE
|
||||
Qt6::Core
|
||||
Qt6::Gui
|
||||
Qt6::Widgets
|
||||
)
|
||||
|
||||
install(TARGETS standarddialogs
|
||||
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
)
|
479
examples/widgets/dialogs/standarddialogs/dialog.cpp
Normal file
@ -0,0 +1,479 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include <QtWidgets>
|
||||
|
||||
#include "dialog.h"
|
||||
|
||||
class DialogOptionsWidget : public QGroupBox
|
||||
{
|
||||
public:
|
||||
explicit DialogOptionsWidget(QWidget *parent = nullptr);
|
||||
|
||||
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;
|
||||
for (const CheckBoxEntry &checkboxEntry : std::as_const(checkBoxEntries)) {
|
||||
if (checkboxEntry.first->isChecked())
|
||||
result |= checkboxEntry.second;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Dialog::Dialog(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
QVBoxLayout *verticalLayout;
|
||||
if (QGuiApplication::styleHints()->showIsFullScreen() || QGuiApplication::styleHints()->showIsMaximized()) {
|
||||
QHBoxLayout *horizontalLayout = new QHBoxLayout(this);
|
||||
QGroupBox *groupBox = new QGroupBox(QGuiApplication::applicationDisplayName(), this);
|
||||
horizontalLayout->addWidget(groupBox);
|
||||
verticalLayout = new QVBoxLayout(groupBox);
|
||||
} else {
|
||||
verticalLayout = new QVBoxLayout(this);
|
||||
}
|
||||
|
||||
QToolBox *toolbox = new QToolBox;
|
||||
verticalLayout->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()"));
|
||||
|
||||
multiLineTextLabel = new QLabel;
|
||||
multiLineTextLabel->setFrameStyle(frameStyle);
|
||||
QPushButton *multiLineTextButton = new QPushButton(tr("QInputDialog::get&MultiLineText()"));
|
||||
|
||||
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()"));
|
||||
|
||||
QPushButton *errorButton =
|
||||
new QPushButton(tr("QErrorMessage::showM&essage()"));
|
||||
|
||||
connect(integerButton, &QAbstractButton::clicked, this, &Dialog::setInteger);
|
||||
connect(doubleButton, &QAbstractButton::clicked, this, &Dialog::setDouble);
|
||||
connect(itemButton, &QAbstractButton::clicked, this, &Dialog::setItem);
|
||||
connect(textButton, &QAbstractButton::clicked, this, &Dialog::setText);
|
||||
connect(multiLineTextButton, &QAbstractButton::clicked, this, &Dialog::setMultiLineText);
|
||||
connect(colorButton, &QAbstractButton::clicked, this, &Dialog::setColor);
|
||||
connect(fontButton, &QAbstractButton::clicked, this, &Dialog::setFont);
|
||||
connect(directoryButton, &QAbstractButton::clicked,
|
||||
this, &Dialog::setExistingDirectory);
|
||||
connect(openFileNameButton, &QAbstractButton::clicked,
|
||||
this, &Dialog::setOpenFileName);
|
||||
connect(openFileNamesButton, &QAbstractButton::clicked,
|
||||
this, &Dialog::setOpenFileNames);
|
||||
connect(saveFileNameButton, &QAbstractButton::clicked,
|
||||
this, &Dialog::setSaveFileName);
|
||||
connect(criticalButton, &QAbstractButton::clicked, this, &Dialog::criticalMessage);
|
||||
connect(informationButton, &QAbstractButton::clicked,
|
||||
this, &Dialog::informationMessage);
|
||||
connect(questionButton, &QAbstractButton::clicked, this, &Dialog::questionMessage);
|
||||
connect(warningButton, &QAbstractButton::clicked, this, &Dialog::warningMessage);
|
||||
connect(errorButton, &QAbstractButton::clicked, this, &Dialog::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->addWidget(multiLineTextButton, 4, 0);
|
||||
layout->addWidget(multiLineTextLabel, 4, 1);
|
||||
layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding), 5, 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("Show scalable fonts"), QFontDialog::ScalableFonts);
|
||||
fontDialogOptionsWidget->addCheckBox(tr("Show non scalable fonts"), QFontDialog::NonScalableFonts);
|
||||
fontDialogOptionsWidget->addCheckBox(tr("Show monospaced fonts"), QFontDialog::MonospacedFonts);
|
||||
fontDialogOptionsWidget->addCheckBox(tr("Show proportional fonts"), QFontDialog::ProportionalFonts);
|
||||
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("Readonly"), QFileDialog::ReadOnly);
|
||||
fileDialogOptionsWidget->addCheckBox(tr("Hide name filter details"), QFileDialog::HideNameFilterDetails);
|
||||
fileDialogOptionsWidget->addCheckBox(tr("Do not use custom directory icons (Windows)"), QFileDialog::DontUseCustomDirectoryIcons);
|
||||
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->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding), 5, 0);
|
||||
toolbox->addItem(page, tr("Message Boxes"));
|
||||
|
||||
setWindowTitle(QGuiApplication::applicationDisplayName());
|
||||
}
|
||||
|
||||
void Dialog::setInteger()
|
||||
{
|
||||
//! [0]
|
||||
bool ok;
|
||||
int i = QInputDialog::getInt(this, tr("QInputDialog::getInt()"),
|
||||
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,
|
||||
Qt::WindowFlags(), 1);
|
||||
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::setMultiLineText()
|
||||
{
|
||||
//! [4]
|
||||
bool ok;
|
||||
QString text = QInputDialog::getMultiLineText(this, tr("QInputDialog::getMultiLineText()"),
|
||||
tr("Address:"), "John Doe\nFreedom Street", &ok);
|
||||
if (ok && !text.isEmpty())
|
||||
multiLineTextLabel->setText(text);
|
||||
//! [4]
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
const QString &description = fontLabel->text();
|
||||
QFont defaultFont;
|
||||
if (!description.isEmpty())
|
||||
defaultFont.fromString(description);
|
||||
|
||||
bool ok;
|
||||
QFont font = QFontDialog::getFont(&ok, defaultFont, 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 msgBox(QMessageBox::Critical, tr("QMessageBox::critical()"),
|
||||
tr("Houston, we have a problem"), { }, this);
|
||||
msgBox.setInformativeText(tr("Activating the liquid oxygen stirring fans caused an explosion in one of the tanks. " \
|
||||
"Liquid oxygen levels are getting low. This may jeopardize the moon landing mission."));
|
||||
msgBox.addButton(QMessageBox::Abort);
|
||||
msgBox.addButton(QMessageBox::Retry);
|
||||
msgBox.addButton(QMessageBox::Ignore);
|
||||
int reply = msgBox.exec();
|
||||
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 msgBox(QMessageBox::Information, tr("QMessageBox::information()"),
|
||||
tr("Elvis has left the building."), { }, this);
|
||||
msgBox.setInformativeText(tr("This phrase was often used by public address announcers at the conclusion " \
|
||||
"of Elvis Presley concerts in order to disperse audiences who lingered in " \
|
||||
"hopes of an encore. It has since become a catchphrase and punchline."));
|
||||
if (msgBox.exec() == QMessageBox::Ok)
|
||||
informationLabel->setText(tr("OK"));
|
||||
else
|
||||
informationLabel->setText(tr("Escape"));
|
||||
}
|
||||
|
||||
void Dialog::questionMessage()
|
||||
{
|
||||
QMessageBox msgBox(QMessageBox::Question, tr("QMessageBox::question()"),
|
||||
tr("Would you like cheese with that?"), { }, this);
|
||||
msgBox.setInformativeText(tr("A cheeseburger is a hamburger topped with cheese. Traditionally, the slice of " \
|
||||
"cheese is placed on top of the meat patty. The cheese is usually added to the " \
|
||||
"cooking hamburger patty shortly before serving, which allows the cheese to melt."));
|
||||
msgBox.addButton(QMessageBox::Yes);
|
||||
msgBox.addButton(QMessageBox::No);
|
||||
msgBox.addButton(QMessageBox::Cancel);
|
||||
int reply = msgBox.exec();
|
||||
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()"),
|
||||
tr("Delete the only copy of your movie manuscript?"), { }, this);
|
||||
msgBox.setInformativeText(tr("You've been working on this manuscript for 738 days now. Hang in there!"));
|
||||
msgBox.setDetailedText("\"A long time ago in a galaxy far, far away....\"");
|
||||
msgBox.addButton(tr("&Keep"), QMessageBox::AcceptRole);
|
||||
msgBox.addButton(tr("Delete"), QMessageBox::DestructiveRole);
|
||||
if (msgBox.exec() == QMessageBox::AcceptRole)
|
||||
warningLabel->setText(tr("Keep"));
|
||||
else
|
||||
warningLabel->setText(tr("Delete"));
|
||||
|
||||
}
|
||||
|
||||
void Dialog::errorMessage()
|
||||
{
|
||||
errorMessageDialog->showMessage(
|
||||
tr("This dialog shows and remembers error messages. "
|
||||
"If the user chooses to not show the dialog again, the dialog "
|
||||
"will not appear again if QErrorMessage::showMessage() "
|
||||
"is called with the same message."));
|
||||
errorMessageDialog->showMessage(
|
||||
tr("You can queue up error messages, and they will be "
|
||||
"shown one after each other. Each message maintains "
|
||||
"its own state for whether it will be shown again "
|
||||
"the next time QErrorMessage::showMessage() is called "
|
||||
"with the same message."));
|
||||
}
|
65
examples/widgets/dialogs/standarddialogs/dialog.h
Normal file
@ -0,0 +1,65 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#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 = nullptr);
|
||||
|
||||
private slots:
|
||||
void setInteger();
|
||||
void setDouble();
|
||||
void setItem();
|
||||
void setText();
|
||||
void setMultiLineText();
|
||||
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 *multiLineTextLabel;
|
||||
QLabel *colorLabel;
|
||||
QLabel *fontLabel;
|
||||
QLabel *directoryLabel;
|
||||
QLabel *openFileNameLabel;
|
||||
QLabel *openFileNamesLabel;
|
||||
QLabel *saveFileNameLabel;
|
||||
QLabel *criticalLabel;
|
||||
QLabel *informationLabel;
|
||||
QLabel *questionLabel;
|
||||
QLabel *warningLabel;
|
||||
QErrorMessage *errorMessageDialog;
|
||||
DialogOptionsWidget *fileDialogOptionsWidget;
|
||||
DialogOptionsWidget *colorDialogOptionsWidget;
|
||||
DialogOptionsWidget *fontDialogOptionsWidget;
|
||||
QString openFilesPath;
|
||||
};
|
||||
|
||||
#endif
|
39
examples/widgets/dialogs/standarddialogs/main.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include <QApplication>
|
||||
#include <QScreen>
|
||||
#include <QStyleHints>
|
||||
#include <QTranslator>
|
||||
#include <QLocale>
|
||||
#include <QLibraryInfo>
|
||||
|
||||
#include "dialog.h"
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
#if QT_CONFIG(translation)
|
||||
QTranslator translator;
|
||||
if (translator.load(QLocale::system(), u"qtbase"_s, u"_"_s,
|
||||
QLibraryInfo::path(QLibraryInfo::TranslationsPath))) {
|
||||
app.installTranslator(&translator);
|
||||
}
|
||||
#endif
|
||||
|
||||
QGuiApplication::setApplicationDisplayName(Dialog::tr("Standard Dialogs"));
|
||||
|
||||
Dialog dialog;
|
||||
if (!QGuiApplication::styleHints()->showIsFullScreen() && !QGuiApplication::styleHints()->showIsMaximized()) {
|
||||
const QRect availableGeometry = dialog.screen()->availableGeometry();
|
||||
dialog.resize(availableGeometry.width() / 3, availableGeometry.height() * 2 / 3);
|
||||
dialog.move((availableGeometry.width() - dialog.width()) / 2,
|
||||
(availableGeometry.height() - dialog.height()) / 2);
|
||||
}
|
||||
dialog.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
47
examples/widgets/dialogs/standarddialogs/main.mm
Normal file
@ -0,0 +1,47 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include <QApplication>
|
||||
#include <QScreen>
|
||||
#include <QStyleHints>
|
||||
#include <QTranslator>
|
||||
#include <QLocale>
|
||||
#include <QLibraryInfo>
|
||||
|
||||
#include "dialog.h"
|
||||
|
||||
#include <AppKit/AppKit.h>
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
[NSApplication sharedApplication];
|
||||
NSApplicationLoad();
|
||||
NSApplicationLoad();
|
||||
[NSApp run];
|
||||
|
||||
QApplication app(argc, argv);
|
||||
//app.setAttribute(Qt::AA_DontUseNativeDialogs);
|
||||
|
||||
#if QT_CONFIG(translation)
|
||||
QTranslator translator;
|
||||
if (translator.load(QLocale::system(), u"qtbase"_s, u"_"_s,
|
||||
QLibraryInfo::path(QLibraryInfo::TranslationsPath))) {
|
||||
app.installTranslator(&translator);
|
||||
}
|
||||
#endif
|
||||
|
||||
QGuiApplication::setApplicationDisplayName(Dialog::tr("Standard Dialogs"));
|
||||
|
||||
Dialog dialog;
|
||||
if (!QGuiApplication::styleHints()->showIsFullScreen() && !QGuiApplication::styleHints()->showIsMaximized()) {
|
||||
const QRect availableGeometry = dialog.screen()->availableGeometry();
|
||||
dialog.resize(availableGeometry.width() / 3, availableGeometry.height() * 2 / 3);
|
||||
dialog.move((availableGeometry.width() - dialog.width()) / 2,
|
||||
(availableGeometry.height() - dialog.height()) / 2);
|
||||
}
|
||||
dialog.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
10
examples/widgets/dialogs/standarddialogs/standarddialogs.pro
Normal file
@ -0,0 +1,10 @@
|
||||
QT += widgets
|
||||
requires(qtConfig(filedialog))
|
||||
|
||||
HEADERS = dialog.h
|
||||
SOURCES = dialog.cpp \
|
||||
main.cpp
|
||||
|
||||
# install
|
||||
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/dialogs/standarddialogs
|
||||
INSTALLS += target
|
37
examples/widgets/dialogs/tabdialog/CMakeLists.txt
Normal file
@ -0,0 +1,37 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(tabdialog LANGUAGES CXX)
|
||||
|
||||
if(NOT DEFINED INSTALL_EXAMPLESDIR)
|
||||
set(INSTALL_EXAMPLESDIR "examples")
|
||||
endif()
|
||||
|
||||
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/dialogs/tabdialog")
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
|
||||
|
||||
qt_standard_project_setup()
|
||||
|
||||
qt_add_executable(tabdialog
|
||||
main.cpp
|
||||
tabdialog.cpp tabdialog.h
|
||||
)
|
||||
|
||||
set_target_properties(tabdialog PROPERTIES
|
||||
WIN32_EXECUTABLE TRUE
|
||||
MACOSX_BUNDLE TRUE
|
||||
)
|
||||
|
||||
target_link_libraries(tabdialog PRIVATE
|
||||
Qt6::Core
|
||||
Qt6::Gui
|
||||
Qt6::Widgets
|
||||
)
|
||||
|
||||
install(TARGETS tabdialog
|
||||
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
)
|
22
examples/widgets/dialogs/tabdialog/main.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#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();
|
||||
}
|
158
examples/widgets/dialogs/tabdialog/tabdialog.cpp
Normal file
@ -0,0 +1,158 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#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, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||||
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||
//! [2] //! [3]
|
||||
|
||||
//! [4]
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||
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]
|
62
examples/widgets/dialogs/tabdialog/tabdialog.h
Normal file
@ -0,0 +1,62 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#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:
|
||||
explicit GeneralTab(const QFileInfo &fileInfo, QWidget *parent = nullptr);
|
||||
};
|
||||
//! [0]
|
||||
|
||||
|
||||
//! [1]
|
||||
class PermissionsTab : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PermissionsTab(const QFileInfo &fileInfo, QWidget *parent = nullptr);
|
||||
};
|
||||
//! [1]
|
||||
|
||||
|
||||
//! [2]
|
||||
class ApplicationsTab : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ApplicationsTab(const QFileInfo &fileInfo, QWidget *parent = nullptr);
|
||||
};
|
||||
//! [2]
|
||||
|
||||
|
||||
//! [3]
|
||||
class TabDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TabDialog(const QString &fileName, QWidget *parent = nullptr);
|
||||
|
||||
private:
|
||||
QTabWidget *tabWidget;
|
||||
QDialogButtonBox *buttonBox;
|
||||
};
|
||||
//! [3]
|
||||
|
||||
#endif
|
10
examples/widgets/dialogs/tabdialog/tabdialog.pro
Normal file
@ -0,0 +1,10 @@
|
||||
QT += widgets
|
||||
requires(qtConfig(listwidget))
|
||||
|
||||
HEADERS = tabdialog.h
|
||||
SOURCES = main.cpp \
|
||||
tabdialog.cpp
|
||||
|
||||
# install
|
||||
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/dialogs/tabdialog
|
||||
INSTALLS += target
|
36
examples/widgets/dialogs/trivialwizard/CMakeLists.txt
Normal file
@ -0,0 +1,36 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(trivialwizard LANGUAGES CXX)
|
||||
|
||||
if(NOT DEFINED INSTALL_EXAMPLESDIR)
|
||||
set(INSTALL_EXAMPLESDIR "examples")
|
||||
endif()
|
||||
|
||||
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/dialogs/trivialwizard")
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
|
||||
|
||||
qt_standard_project_setup()
|
||||
|
||||
qt_add_executable(trivialwizard
|
||||
trivialwizard.cpp
|
||||
)
|
||||
|
||||
set_target_properties(trivialwizard PROPERTIES
|
||||
WIN32_EXECUTABLE TRUE
|
||||
MACOSX_BUNDLE TRUE
|
||||
)
|
||||
|
||||
target_link_libraries(trivialwizard PRIVATE
|
||||
Qt6::Core
|
||||
Qt6::Gui
|
||||
Qt6::Widgets
|
||||
)
|
||||
|
||||
install(TARGETS trivialwizard
|
||||
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
)
|
99
examples/widgets/dialogs/trivialwizard/trivialwizard.cpp
Normal file
@ -0,0 +1,99 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#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);
|
||||
|
||||
#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
|
||||
|
||||
QWizard wizard;
|
||||
wizard.addPage(createIntroPage());
|
||||
wizard.addPage(createRegistrationPage());
|
||||
wizard.addPage(createConclusionPage());
|
||||
|
||||
wizard.setWindowTitle("Trivial Wizard");
|
||||
wizard.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
//! [10] //! [11]
|
7
examples/widgets/dialogs/trivialwizard/trivialwizard.pro
Normal file
@ -0,0 +1,7 @@
|
||||
QT += widgets
|
||||
|
||||
SOURCES = trivialwizard.cpp
|
||||
|
||||
# install
|
||||
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/dialogs/trivialwizard
|
||||
INSTALLS += target
|