-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathmain.cpp
More file actions
185 lines (162 loc) · 5.53 KB
/
Copy pathmain.cpp
File metadata and controls
185 lines (162 loc) · 5.53 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include "mainwindow.h"
#include <QApplication>
#include <QMessageBox>
#include <QAbstractNativeEventFilter>
#include "analyzer/customanalyzer.h"
#include "style.h"
bool g_developerMode = false;
bool g_usbOnly = false;
bool g_raspbian = false;
bool g_bAA55modeNewProtocol = false;
MainWindow* g_mainWindow;
#ifdef Q_OS_WIN
#include <windows.h>
#include <dbt.h>
//#ifndef _DEBUG
//#define LOG_TO_FILE
//#endif
#ifdef LOG_TO_FILE
QString logFilePath = "antscope2";
bool firstLog = true;
void customMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
if (type != QtInfoMsg)
return;
QHash<QtMsgType, QString> msgLevelHash({{QtDebugMsg, "Debug"}, {QtInfoMsg, "Info"}, {QtWarningMsg, "Warning"}, {QtCriticalMsg, "Critical"}, {QtFatalMsg, "Fatal"}});
QTime time = QTime::currentTime();
QString formattedTime = time.toString("hh:mm:ss.zzz");
QString sufix = QDateTime::currentDateTime().toString("-yyyyMMdd_hhmmss.log");
QString logLevelName = "";//msgLevelHash[type];
QString txt = QString("%1 %2: %3 (%4:%5, %6)")
.arg(formattedTime, logLevelName, msg, context.file)
.arg(context.line)
.arg(context.function);
if (firstLog) {
firstLog = false;
QDir dir = QDir::tempPath();
logFilePath = dir.absoluteFilePath(logFilePath + sufix);
}
QFile outFile(logFilePath);
outFile.open(QIODevice::WriteOnly | QIODevice::Append);
QTextStream ts(&outFile);
ts << txt << "\n";
ts.flush();
}
#endif
class MyNativeEventFilter : public QAbstractNativeEventFilter {
public :
virtual bool nativeEventFilter( const QByteArray &eventType, void *message, long * /*result*/ )
//Q_DECL_OVERRIDE
{
if (eventType == "windows_generic_MSG")
{
MSG *msg = static_cast<MSG *>(message);
static int i = 0;
msg = (MSG*)message;
//qDebug() << "message: " << msg->message << " wParam: " << msg->wParam
// << " lParam: " << msg->lParam;
if (msg->message == WM_DEVICECHANGE)
{
qDebug() << "WM_DEVICECHANGE: " <<
(msg->wParam==DBT_DEVICEARRIVAL?"DBT_DEVICEARRIVAL":
(msg->wParam==DBT_DEVICEREMOVECOMPLETE?"DBT_DEVICEREMOVECOMPLETE":QString::number(msg->wParam)));
}
}
return false;
}
};
#endif
void setAbsoluteFqMaximum()
{
int fqMax = 0;
if (CustomAnalyzer::customized() && CustomAnalyzer::getCurrent() != nullptr) {
fqMax = CustomAnalyzer::getCurrent()->maxFq().toInt();
} else {
#ifdef NEW_ANALYZER
foreach (AnalyzerParameters* param, AnalyzerParameters::analyzers()) {
QString str = param->maxFq();
int fq = str.toInt();
fqMax = qMax(fqMax, fq);
}
#else
for (int idx=1; idx<QUANTITY; idx++) {
QString str = maxFq[idx];
int fq = str.toInt();
fqMax = qMax(fqMax, fq);
}
#endif
}
ABSOLUTE_MAX_FQ = fqMax;
}
int g_showMessageBox(QWidget* parent, QMessageBox::Icon icon,
QString title, QString text,
QMessageBox::StandardButtons buttons = QMessageBox::Ok,
QMessageBox::StandardButton defaultButton = QMessageBox::NoButton)
{
QMessageBox msgBox;
msgBox.setIcon(icon);
msgBox.setWindowTitle(title);
msgBox.setText(text);
msgBox.setStandardButtons(buttons);
msgBox.setDefaultButton(defaultButton);
msgBox.setStyleSheet(Style::messageBox());
return msgBox.exec();
}
int main(int argc, char *argv[])
{
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
// Fix for 4K Display Issues Disabled
#ifdef DUMB_Q_OS_WIN
char** params;
params = new char*[argc+2];
int ip=0;
for (; ip<argc; ip++) {
params[ip] = argv[ip];
}
params[ip++] = (char*)"--platform";
params[ip] = (char*)"windows:dpiawareness=0";
int cntp = argc + 2;
QApplication a(cntp, params);
#else
QApplication a(argc, argv);
#endif
QStringList args = a.arguments();
#ifdef LOG_TO_FILE
qInstallMessageHandler(customMessageOutput);
qInfo() << " ";
qInfo() << "*********************************************************";
qInfo() << " AntScope2 " << QString(ANTSCOPE2VER) << " STARTED " << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
qInfo() << " ";
#endif
#ifdef Q_OS_WIN
// TODO DEBUG: catch attach/detach device event
//MyNativeEventFilter myEventfilter;
//a.eventDispatcher()->installNativeEventFilter(&myEventfilter);
#endif
if (args.contains("-developer")) {
g_developerMode = true;
MAX_DOTS = 1000000;
}
if (args.contains("-usb-only")) {
g_usbOnly = true;
}
g_raspbian = QSysInfo::productType().contains("raspbian", Qt::CaseInsensitive);
QString style;
style = Style::messageBox();
a.setStyleSheet(style);
style = Style::dialog();
style += Style::pushButton();
style += Style::label();
style += Style::lineEdit();
a.setStyleSheet(style);
MainWindow w;
g_mainWindow = w.m_mainWindow;
foreach (QString path, args) {
if (path.contains(".asd")) {
w.openFile(path);
break;
}
}
w.show();
return a.exec();
}