2022-05-10 10:06:48 +00:00
|
|
|
// Copyright (C) 2021 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2012-10-25 10:45:13 +00:00
|
|
|
|
|
|
|
#include "filedialogpanel.h"
|
2013-01-29 17:47:20 +00:00
|
|
|
#include "colordialogpanel.h"
|
2013-02-04 13:51:15 +00:00
|
|
|
#include "fontdialogpanel.h"
|
2013-11-01 11:46:42 +00:00
|
|
|
#include "printdialogpanel.h"
|
2013-03-05 13:45:51 +00:00
|
|
|
#include "wizardpanel.h"
|
2013-06-11 18:27:28 +00:00
|
|
|
#include "messageboxpanel.h"
|
2012-10-25 10:45:13 +00:00
|
|
|
|
2018-04-05 07:47:48 +00:00
|
|
|
#include <QLibraryInfo>
|
|
|
|
#include <QDialogButtonBox>
|
2012-10-25 10:45:13 +00:00
|
|
|
#include <QMainWindow>
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QMenuBar>
|
|
|
|
#include <QTabWidget>
|
2018-04-05 07:47:48 +00:00
|
|
|
#include <QFormLayout>
|
2012-10-25 10:45:13 +00:00
|
|
|
#include <QMenu>
|
|
|
|
#include <QAction>
|
|
|
|
#include <QKeySequence>
|
|
|
|
|
2018-11-09 11:59:38 +00:00
|
|
|
static bool optNoPrinter = false;
|
|
|
|
|
2012-10-25 10:45:13 +00:00
|
|
|
// Test for dialogs, allowing to play with all dialog options for implementing native dialogs.
|
|
|
|
// Compiles with Qt 4.8 and Qt 5.
|
|
|
|
|
2018-04-05 07:47:48 +00:00
|
|
|
class AboutDialog : public QDialog
|
|
|
|
{
|
|
|
|
public:
|
2020-10-07 11:05:48 +00:00
|
|
|
explicit AboutDialog(QWidget *parent = nullptr);
|
2018-04-05 07:47:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent)
|
|
|
|
{
|
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
|
|
|
QFormLayout *mainLayout = new QFormLayout(this);
|
|
|
|
mainLayout->addRow(new QLabel(QLibraryInfo::build()));
|
|
|
|
mainLayout->addRow("Style:", new QLabel(qApp->style()->objectName()));
|
|
|
|
mainLayout->addRow("DPR:", new QLabel(QString::number(qApp->devicePixelRatio())));
|
|
|
|
const QString resolution = QString::number(logicalDpiX()) + QLatin1Char(',')
|
|
|
|
+ QString::number(logicalDpiY()) + QLatin1String("dpi");
|
|
|
|
mainLayout->addRow("Resolution:", new QLabel(resolution));
|
|
|
|
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close, Qt::Horizontal);
|
|
|
|
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
|
|
|
mainLayout->addRow(buttonBox);
|
|
|
|
}
|
|
|
|
|
2012-10-25 10:45:13 +00:00
|
|
|
class MainWindow : public QMainWindow {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2020-10-07 11:05:48 +00:00
|
|
|
explicit MainWindow(QWidget *parent = nullptr);
|
2018-04-05 07:47:48 +00:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void aboutDialog();
|
2012-10-25 10:45:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
|
|
|
|
{
|
|
|
|
setWindowTitle(tr("Dialogs Qt %1").arg(QLatin1String(QT_VERSION_STR)));
|
|
|
|
QMenu *fileMenu = menuBar()->addMenu(tr("File"));
|
|
|
|
QAction *quitAction = fileMenu->addAction(tr("Quit"));
|
|
|
|
quitAction->setShortcut(QKeySequence(QKeySequence::Quit));
|
|
|
|
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
|
2014-03-31 12:17:29 +00:00
|
|
|
QMenu *editMenu = menuBar()->addMenu(tr("&Edit"));
|
|
|
|
QAction *action = editMenu->addAction(tr("Cut"));
|
2018-11-14 13:58:47 +00:00
|
|
|
action->setShortcut(QKeySequence(QKeySequence::Cut));
|
2014-03-31 12:17:29 +00:00
|
|
|
action = editMenu->addAction(tr("Copy"));
|
|
|
|
action->setShortcut(QKeySequence(QKeySequence::Copy));
|
|
|
|
action = editMenu->addAction(tr("Paste"));
|
|
|
|
action->setShortcut(QKeySequence(QKeySequence::Paste));
|
|
|
|
action = editMenu->addAction(tr("Select All"));
|
|
|
|
action->setShortcut(QKeySequence(QKeySequence::SelectAll));
|
2018-04-05 07:47:48 +00:00
|
|
|
QMenu *aboutMenu = menuBar()->addMenu(tr("&About"));
|
|
|
|
QAction *aboutAction = aboutMenu->addAction(tr("About..."), this, SLOT(aboutDialog()));
|
|
|
|
aboutAction->setShortcut(Qt::Key_F1);
|
2012-10-25 10:45:13 +00:00
|
|
|
QTabWidget *tabWidget = new QTabWidget;
|
|
|
|
tabWidget->addTab(new FileDialogPanel, tr("QFileDialog"));
|
2013-01-29 17:47:20 +00:00
|
|
|
tabWidget->addTab(new ColorDialogPanel, tr("QColorDialog"));
|
2013-02-04 13:51:15 +00:00
|
|
|
tabWidget->addTab(new FontDialogPanel, tr("QFontDialog"));
|
2013-03-05 13:45:51 +00:00
|
|
|
tabWidget->addTab(new WizardPanel, tr("QWizard"));
|
2013-06-11 18:27:28 +00:00
|
|
|
tabWidget->addTab(new MessageBoxPanel, tr("QMessageBox"));
|
2013-11-01 11:46:42 +00:00
|
|
|
#ifndef QT_NO_PRINTER
|
2018-11-09 11:59:38 +00:00
|
|
|
if (!optNoPrinter)
|
|
|
|
tabWidget->addTab(new PrintDialogPanel, tr("QPrintDialog"));
|
2013-11-01 11:46:42 +00:00
|
|
|
#endif
|
2012-10-25 10:45:13 +00:00
|
|
|
setCentralWidget(tabWidget);
|
|
|
|
}
|
|
|
|
|
2018-04-05 07:47:48 +00:00
|
|
|
void MainWindow::aboutDialog()
|
|
|
|
{
|
|
|
|
AboutDialog dialog(this);
|
|
|
|
dialog.setWindowTitle(tr("About Dialogs"));
|
|
|
|
dialog.exec();
|
|
|
|
}
|
|
|
|
|
2012-10-25 10:45:13 +00:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2016-08-15 14:02:39 +00:00
|
|
|
for (int a = 1; a < argc; ++a) {
|
|
|
|
if (!qstrcmp(argv[a], "-n")) {
|
|
|
|
qDebug("AA_DontUseNativeDialogs");
|
|
|
|
QCoreApplication::setAttribute(Qt::AA_DontUseNativeDialogs);
|
2018-11-09 11:59:38 +00:00
|
|
|
} else if (!qstrcmp(argv[a], "-p")) {
|
|
|
|
optNoPrinter = true; // Avoid startup slowdown by printer code
|
2016-08-15 14:02:39 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-15 16:26:53 +00:00
|
|
|
|
2012-10-25 10:45:13 +00:00
|
|
|
QApplication a(argc, argv);
|
|
|
|
MainWindow w;
|
|
|
|
w.move(500, 200);
|
|
|
|
w.show();
|
|
|
|
return a.exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "main.moc"
|