-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
98 lines (93 loc) · 3.58 KB
/
Copy pathmain.cpp
File metadata and controls
98 lines (93 loc) · 3.58 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <QGuiApplication>
#include "editorfont.h"
#include <cstdio>
#ifdef Q_OS_WIN
#include <QFileDialog>
#else
#include <KFileCustomDialog>
#include <KFileFilter>
#include <KFileWidget>
#endif
#include <QDialog>
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QQuickStyle>
#include <QTimer>
#include <QImage>
#include "scripteditor.h"
class KdeFileDialogController : public QObject
{
Q_OBJECT
public:
using QObject::QObject;
Q_INVOKABLE void open()
{
#ifdef Q_OS_WIN
const QUrl url = QFileDialog::getOpenFileUrl(
nullptr,
tr("Open TPL"),
QUrl(),
tr("TPL files (*.tpl);;All files (*)"));
if (url.isValid())
emit fileSelected(url);
#else
KFileCustomDialog dialog;
dialog.setWindowTitle(tr("Open TPL"));
dialog.setOperationMode(KFileWidget::Opening);
dialog.fileWidget()->setFilters({
KFileFilter(tr("TPL files (*.tpl)"), {QStringLiteral("*.tpl")}, {}),
KFileFilter(tr("All files (*)"), {QStringLiteral("*")}, {})
});
connect(dialog.fileWidget(), &KFileWidget::accepted, &dialog, &QDialog::accept);
dialog.resize(900, 600);
if (dialog.exec() == QDialog::Accepted)
emit fileSelected(dialog.fileWidget()->selectedUrl());
#endif
}
signals:
void fileSelected(const QUrl &url);
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
app.setApplicationName(QStringLiteral("MMZScriptEditor"));
app.setOrganizationName(QStringLiteral("MMZScriptEditor"));
#ifdef Q_OS_WIN
// The native Vista-based styles keep a light palette on Windows 10.
// Configure both layers: QApplication also supplies the palette used by
// Kirigami. With Qt >= 6.5, Fusion follows the system color scheme.
QApplication::setStyle(QStringLiteral("Fusion"));
QQuickStyle::setStyle(QStringLiteral("Fusion"));
#else
QQuickStyle::setStyle(QStringLiteral("org.kde.desktop"));
QQuickStyle::setFallbackStyle(QStringLiteral("Fusion"));
#endif
ScriptEditor editor;
KdeFileDialogController fileDialogController;
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty(QStringLiteral("editorFontFamily"),
editorFontFamily());
engine.rootContext()->setContextProperty(QStringLiteral("editorBackend"), &editor);
engine.rootContext()->setContextProperty(QStringLiteral("fileDialogController"), &fileDialogController);
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed, &app,
[] { QCoreApplication::exit(1); }, Qt::QueuedConnection);
QObject::connect(&engine, &QQmlEngine::warnings, &app, [](const QList<QQmlError> &warnings) {
for (const auto &warning : warnings) fprintf(stderr, "%s\n", qPrintable(warning.toString()));
});
engine.loadFromModule(QStringLiteral("MMZ.Editor"), QStringLiteral("Main"));
if (app.arguments().contains(QStringLiteral("--smoke-test"))) {
if (engine.rootObjects().isEmpty()) return 1;
for (const auto *name : {"document-open", "document-save", "document-save-all", "edit-find"}) {
const QString path = QStringLiteral(":/icons/%1.svg").arg(QString::fromLatin1(name));
if (QImage(path).isNull()) {
fprintf(stderr, "Cannot load action icon: %s\n", qPrintable(path));
return 1;
}
}
// Exercise initial QML creation and the event loop in packaging CI.
QTimer::singleShot(1000, &app, &QCoreApplication::quit);
}
return app.exec();
}
#include "main.moc"