File indexing completed on 2024-07-14 14:26:31

0001 /*
0002     KStyle for KF5
0003     SPDX-FileCopyrightText: 2013 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #include "kstyle.h"
0009 
0010 #include <QApplication>
0011 #include <QDialog>
0012 #include <QDialogButtonBox>
0013 #include <QLayout>
0014 #include <QPushButton>
0015 #include <QTextEdit>
0016 #include <QVBoxLayout>
0017 #include <QWidget>
0018 
0019 void showDialog()
0020 {
0021     QDialog dialog;
0022 
0023     auto *layout = new QVBoxLayout(&dialog);
0024 
0025     QDialogButtonBox *box = new QDialogButtonBox(QDialogButtonBox::Cancel | QDialogButtonBox::Ok, &dialog);
0026 
0027     // Useful to change the text because setting the text triggers setShortcut
0028     box->button(QDialogButtonBox::Ok)->setText(QStringLiteral("Send"));
0029     QObject::connect(box, &QDialogButtonBox::accepted, &dialog, &QDialog::accept);
0030     QObject::connect(box, &QDialogButtonBox::rejected, &dialog, &QDialog::reject);
0031 
0032     auto usefulWidget = new QTextEdit(&dialog);
0033     layout->addWidget(usefulWidget);
0034     layout->addWidget(box);
0035 
0036     // Make sure we test ctrl+return acceptance with the focus on the button
0037     usefulWidget->setFocus();
0038 
0039     dialog.resize(200, 200);
0040     dialog.exec();
0041 }
0042 
0043 int main(int argc, char **argv)
0044 {
0045     QApplication app(argc, argv);
0046     app.setStyle(new KStyle);
0047 
0048     QWidget w;
0049     auto *layout = new QVBoxLayout(&w);
0050 
0051     QPushButton *showDialogButton = new QPushButton(QStringLiteral("Dialog"), &w);
0052     QObject::connect(showDialogButton, &QPushButton::clicked, &showDialog);
0053     layout->addWidget(showDialogButton);
0054     w.resize(200, 200);
0055     w.show();
0056 
0057     return app.exec();
0058 }