-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
164 lines (147 loc) · 5.06 KB
/
main.cpp
File metadata and controls
164 lines (147 loc) · 5.06 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// ********************************************************************
// Copyright © 2025 by EoF Software Labs
// Copyright © 2024 Apple Inc. (some copied parts)
// Copyright by libgaminggear Project (some copied parts)
// Copyright by roccat-tools Project (some copied parts)
// SPDX-License-Identifier: GPL-3.0
// ********************************************************************
#include "rtmainwindow.h"
#include <QApplication>
#include <QFile>
#include <QFileInfo>
#include <QFileOpenEvent>
#include <QLocale>
#include <QMessageBox>
#include <QProxyStyle>
#include <QStyleFactory>
#include <QTranslator>
#ifdef Q_OS_MACOS
extern const char *GetBundleVersion();
extern const char *GetBuildNumber();
#else
static const char *GetBundleVersion() { return "1.0.0"; }
static const char *GetBuildNumber() { return "1"; }
#endif
class RTApplication : public QApplication
{
public:
RTApplication(int &argc, char **argv)
: QApplication(argc, argv)
{}
int exec()
{
QTranslator translator;
const QStringList uiLanguages = QLocale::system().uiLanguages();
for (const QString &locale : uiLanguages) {
const QString baseName = "RoccatTyon_" + QLocale(locale).name();
if (translator.load(":/i18n/" + baseName)) {
installTranslator(&translator);
break;
}
}
QString projectFile;
const QStringList args = arguments();
if (args.size() > 1) {
projectFile = args.at(1);
}
/* Override commandline style with our fixed GUI style type */
/* macintosh, Windows, Fusion */
QString styleName;
// qDebug() << QStyleFactory::keys();
#if defined(Q_OS_MACOS)
styleName = "Fusion"; //"macOS";
#elif defined(Q_OS_LINUX)
styleName = "Fusion";
#else
styleName = "Windows";
#endif
/* configure custom GUI style hinter */
QStyle *style;
if ((style = QStyleFactory::create(styleName))) {
ApplicationStyle *myStyle = new ApplicationStyle();
myStyle->setBaseStyle(style);
setStyle(myStyle);
}
QFile r(":/styles/assets/appstyle.css");
if (r.open(QFile::ReadOnly)) {
setStyleSheet(r.readAll());
r.close();
}
m_window = new RTMainWindow(/*projectFile*/);
m_window->show();
int rc = QApplication::exec();
delete m_window;
return rc;
}
bool event(QEvent *event) override
{
if (event->type() == QEvent::FileOpen) {
QFileOpenEvent *openEvent = static_cast<QFileOpenEvent *>(event);
const QUrl url = openEvent->url();
if (url.isLocalFile()) {
QFileInfo fi(url.toLocalFile());
qDebug() << "QEvent::FileOpen ->" << fi.absoluteFilePath();
/*m_window->setProjectFileName(fi.absoluteFilePath());*/
} else if (url.isValid()) {
// process according to the URL's schema
qDebug() << "QEvent::FileOpen ->" << url;
} else {
qDebug() << "QEvent::FileOpen ->" << url;
}
}
return QApplication::event(event);
}
private:
class ApplicationStyle : public QProxyStyle
{
public:
int styleHint(StyleHint hint,
const QStyleOption *option = nullptr, //
const QWidget *widget = nullptr, //
QStyleHintReturn *returnData = nullptr) const override
{
switch (hint) {
case QStyle::SH_ComboBox_Popup: {
return 0;
}
case QStyle::SH_MessageBox_CenterButtons: {
return 0;
}
case QStyle::SH_FocusFrame_AboveWidget: {
return 1;
}
default: {
break;
}
}
return QProxyStyle::styleHint(hint, option, widget, returnData);
}
};
private:
RTMainWindow *m_window;
};
int main(int argc, char *argv[])
{
#ifdef Q_OS_LINUX
::setenv("QT_QPA_PLATFORM", "xcb", 0);
#endif
#ifdef Q_OS_MACOS
::setenv("QT_QPA_PLATFORM", "cocoa", 0);
#endif
/* Set specific QT debug message pattern
* %{type} %{threadid} %{function}
* [T:%{threadid}|F:%{function}]
*/
setenv("QT_MESSAGE_PATTERN", "[T:%{threadid}] %{message}", 0);
QApplication::setAttribute(Qt::AA_NativeWindows, true);
QApplication::setAttribute(Qt::AA_UseDesktopOpenGL, true);
QApplication::setAttribute(Qt::AA_Use96Dpi);
QApplication::setOrganizationName(QStringLiteral("EoF Software Labs"));
QApplication::setApplicationName(QStringLiteral("ROCCAT Tyon Control"));
QApplication::setApplicationDisplayName(QApplication::applicationName());
QApplication::setApplicationVersion(QStringLiteral("%1.%2").arg(GetBundleVersion(), GetBuildNumber()));
QApplication::setDesktopSettingsAware(true);
QApplication::setQuitOnLastWindowClosed(true);
RTApplication a(argc, argv);
return a.exec();
}