1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
/*
This file is part of the KDE libraries
SPDX-FileCopyrightText: 2020 Ahmad Samir <a.samirh78@gmail.com>
SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include "kmessagedialog.h"
#include <KGuiItem>
#include <KStandardGuiItem>
#include <QApplication>
#include <QDebug>
#include <QDialogButtonBox>
#include <QMessageBox>
#include <QPushButton>
#include <memory>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
app.setAttribute(Qt::AA_UseHighDpiPixmaps, true);
app.setApplicationName(QStringLiteral("kmessagedialogtest"));
const auto types = {
KMessageDialog::QuestionTwoActions,
KMessageDialog::QuestionTwoActionsCancel,
KMessageDialog::WarningTwoActions,
KMessageDialog::WarningTwoActionsCancel,
KMessageDialog::WarningContinueCancel,
KMessageDialog::Information,
#if KWIDGETSADDONS_BUILD_DEPRECATED_SINCE(5, 97)
KMessageDialog::Sorry,
#endif
KMessageDialog::Error
};
for (auto type : types) {
auto dlg = std::unique_ptr<KMessageDialog>(new KMessageDialog(type, QStringLiteral("Message in a box."), nullptr));
dlg->setCaption(QString{});
dlg->setIcon(QIcon{});
if ((type != KMessageDialog::Information) &&
#if KWIDGETSADDONS_BUILD_DEPRECATED_SINCE(5, 97)
(type != KMessageDialog::Sorry) &&
#endif
(type != KMessageDialog::Error)) {
dlg->setButtons(KGuiItem(QStringLiteral("Primary Action")), KGuiItem(QStringLiteral("Secondary Action")), KStandardGuiItem::cancel());
}
auto getResult = [&]() {
const auto result = static_cast<KMessageDialog::ButtonType>(dlg->exec());
switch (result) {
case KMessageDialog::Ok:
case KMessageDialog::PrimaryAction:
qDebug() << "Button OK/Primary clicked."
<< "Don't ask again status:" << (dlg->isDontAskAgainChecked() ? "Checked" : "Unchecked");
break;
case KMessageDialog::SecondaryAction:
qDebug() << "Button Secondary clicked"
<< "Don't ask again status:" << (dlg->isDontAskAgainChecked() ? "Checked" : "Unchecked");
break;
case KMessageDialog::Cancel:
qDebug() << "Button Cancel clicked";
break;
default:
break;
}
};
getResult();
dlg->setDontAskAgainText(QStringLiteral("Do not show this again"));
dlg->setDontAskAgainChecked(false);
getResult();
dlg->setListWidgetItems(QStringList{QStringLiteral("file1"), QStringLiteral("file2")});
getResult();
dlg->setDetails(QStringLiteral("Some more details."));
getResult();
}
}
|