summaryrefslogtreecommitdiffstats
path: root/examples/widgets/dialogs/standarddialogs/dialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/widgets/dialogs/standarddialogs/dialog.cpp')
-rw-r--r--examples/widgets/dialogs/standarddialogs/dialog.cpp132
1 files changed, 45 insertions, 87 deletions
diff --git a/examples/widgets/dialogs/standarddialogs/dialog.cpp b/examples/widgets/dialogs/standarddialogs/dialog.cpp
index 7df24e06f6..67fb615794 100644
--- a/examples/widgets/dialogs/standarddialogs/dialog.cpp
+++ b/examples/widgets/dialogs/standarddialogs/dialog.cpp
@@ -1,67 +1,10 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QtWidgets>
#include "dialog.h"
-#define MESSAGE \
- Dialog::tr("<p>Message boxes have a caption, a text, " \
- "and any number of buttons, each with standard or custom texts." \
- "<p>Click a button to close the message box. Pressing the Esc button " \
- "will activate the detected escape button (if any).")
-#define MESSAGE_DETAILS \
- Dialog::tr("If a message box has detailed text, the user can reveal it " \
- "by pressing the Show Details... button.")
-
-
class DialogOptionsWidget : public QGroupBox
{
public:
@@ -99,7 +42,7 @@ void DialogOptionsWidget::addSpacer()
int DialogOptionsWidget::value() const
{
int result = 0;
- for (const CheckBoxEntry &checkboxEntry : qAsConst(checkBoxEntries)) {
+ for (const CheckBoxEntry &checkboxEntry : std::as_const(checkBoxEntries)) {
if (checkboxEntry.first->isChecked())
result |= checkboxEntry.second;
}
@@ -195,8 +138,6 @@ Dialog::Dialog(QWidget *parent)
warningLabel->setFrameStyle(frameStyle);
QPushButton *warningButton = new QPushButton(tr("QMessageBox::&warning()"));
- errorLabel = new QLabel;
- errorLabel->setFrameStyle(frameStyle);
QPushButton *errorButton =
new QPushButton(tr("QErrorMessage::showM&essage()"));
@@ -250,6 +191,7 @@ Dialog::Dialog(QWidget *parent)
colorDialogOptionsWidget->addCheckBox(doNotUseNativeDialog, QColorDialog::DontUseNativeDialog);
colorDialogOptionsWidget->addCheckBox(tr("Show alpha channel") , QColorDialog::ShowAlphaChannel);
colorDialogOptionsWidget->addCheckBox(tr("No buttons") , QColorDialog::NoButtons);
+ colorDialogOptionsWidget->addCheckBox(tr("Hide Color Picker") , QColorDialog::NoEyeDropperButton);
layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding), 1, 0);
layout->addWidget(colorDialogOptionsWidget, 2, 0, 1 ,2);
@@ -306,7 +248,6 @@ Dialog::Dialog(QWidget *parent)
layout->addWidget(warningButton, 3, 0);
layout->addWidget(warningLabel, 3, 1);
layout->addWidget(errorButton, 4, 0);
- layout->addWidget(errorLabel, 4, 1);
layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding), 5, 0);
toolbox->addItem(page, tr("Message Boxes"));
@@ -460,10 +401,14 @@ void Dialog::setSaveFileName()
void Dialog::criticalMessage()
{
- QMessageBox::StandardButton reply;
- reply = QMessageBox::critical(this, tr("QMessageBox::critical()"),
- MESSAGE,
- QMessageBox::Abort | QMessageBox::Retry | QMessageBox::Ignore);
+ 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)
@@ -474,9 +419,12 @@ void Dialog::criticalMessage()
void Dialog::informationMessage()
{
- QMessageBox::StandardButton reply;
- reply = QMessageBox::information(this, tr("QMessageBox::information()"), MESSAGE);
- if (reply == QMessageBox::Ok)
+ 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"));
@@ -484,10 +432,15 @@ void Dialog::informationMessage()
void Dialog::questionMessage()
{
- QMessageBox::StandardButton reply;
- reply = QMessageBox::question(this, tr("QMessageBox::question()"),
- MESSAGE,
- QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
+ 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)
@@ -499,26 +452,31 @@ void Dialog::questionMessage()
void Dialog::warningMessage()
{
QMessageBox msgBox(QMessageBox::Warning, tr("QMessageBox::warning()"),
- MESSAGE, { }, this);
- msgBox.setDetailedText(MESSAGE_DETAILS);
- msgBox.addButton(tr("Save &Again"), QMessageBox::AcceptRole);
- msgBox.addButton(tr("&Continue"), QMessageBox::RejectRole);
- if (msgBox.exec() == QMessageBox::AcceptRole)
- warningLabel->setText(tr("Save Again"));
+ 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....\"");
+ auto *keepButton = msgBox.addButton(tr("&Keep"), QMessageBox::AcceptRole);
+ auto *deleteButton = msgBox.addButton(tr("Delete"), QMessageBox::DestructiveRole);
+ msgBox.exec();
+ if (msgBox.clickedButton() == keepButton)
+ warningLabel->setText(tr("Keep"));
+ else if (msgBox.clickedButton() == deleteButton)
+ warningLabel->setText(tr("Delete"));
else
- warningLabel->setText(tr("Continue"));
-
+ warningLabel->setText("");
}
void Dialog::errorMessage()
{
errorMessageDialog->showMessage(
tr("This dialog shows and remembers error messages. "
- "If the checkbox is checked (as it is by default), "
- "the shown message will be shown again, "
- "but if the user unchecks the box the message "
+ "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."));
- errorLabel->setText(tr("If the box is unchecked, the message "
- "won't appear again."));
+ 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."));
}