chore: update files of project

This commit is contained in:
x-tools-author 2024-03-28 22:43:20 +08:00
parent 303084a2ee
commit 4112701530
4 changed files with 55 additions and 66 deletions

View File

@ -14,6 +14,10 @@
#include <QMetaEnum>
#include <QStyleFactory>
#include "xToolsApplication.h"
#include "xToolsMainWindow.h"
#include "xToolsSettings.h"
#ifdef X_TOOLS_USING_GLOG
#include "glog/logging.h"
#endif
@ -21,7 +25,7 @@
#ifdef X_TOOLS_ENABLE_HIGH_DPI_POLICY
#include "xToolsDataStructure.h"
#endif
#include "xToolsSettings.h"
#ifdef X_TOOLS_USING_GLOG
@ -172,3 +176,50 @@ static void sakDoSomethingAfterAppExited()
xToolsShutdownGoogleLogging();
#endif
}
template<typename CentralWidgetT, typename MainWindowT, typename AppT>
int xToolsExec(int argc, char* argv[], const QString& appName, bool usingCommonMainWindow = true)
{
QString cookedAppName = appName;
#ifdef X_TOOLS_BUILD_FOR_STORE
cookedAppName += QObject::tr("(Store)");
#endif
sakDoSomethingBeforeAppCreated(argv, cookedAppName);
AppT app(argc, argv);
#ifdef X_TOOLS_VERSION
app.setApplicationVersion(X_TOOLS_VERSION);
#endif
QSplashScreen& splashScreen = qobject_cast<xToolsApplication*>(qApp)->splashScreen();
if (usingCommonMainWindow) {
MainWindowT* mainWindow = new MainWindowT();
splashScreen.finish(mainWindow);
CentralWidgetT* centralWidget = new CentralWidgetT(mainWindow);
mainWindow->setWindowTitle(cookedAppName);
mainWindow->setCentralWidget(centralWidget);
mainWindow->show();
mainWindow->resize(int(qreal(mainWindow->height()) * 1.732), mainWindow->height());
mainWindow->moveToCenter();
qInfo() << "The size of window is" << mainWindow->size();
} else {
CentralWidgetT* widget = new CentralWidgetT();
splashScreen.finish(widget);
widget->show();
widget->resize(int(qreal(widget->height()) * 1.732), widget->height());
qInfo() << "The size of window is" << widget->size();
}
int ret = app.exec();
sakDoSomethingAfterAppExited();
return ret;
}
template<typename T>
int xToolsExec(int argc, char* argv[], const QString& appName, bool usingCommonMainWindow = true)
{
return xToolsExec<T, xToolsMainWindow, xToolsApplication>(argc,
argv,
appName,
usingCommonMainWindow);
}

View File

@ -1,60 +0,0 @@
/***************************************************************************************************
* Copyright 2023-2024 x-tools-author(x-tools@outlook.com). All rights reserved.
*
* The file is encoded using "utf8 with bom", it is a part of xTools project.
*
* xTools is licensed according to the terms in the file LICENCE(GPL V3) in the root of the source
* code directory.
**************************************************************************************************/
#pragma once
#include "xTools.h"
#include "xToolsApplication.h"
#include "xToolsMainWindow.h"
template<typename UiT, typename MainWindowT, typename AppT>
int xToolsExec(int argc, char* argv[], const QString& appName, bool usingCommonMainWindow = true)
{
QString cookedAppName = appName;
#ifdef X_TOOLS_BUILD_FOR_STORE
cookedAppName += QObject::tr("(Store)");
#endif
sakDoSomethingBeforeAppCreated(argv, cookedAppName);
AppT app(argc, argv);
#ifdef X_TOOLS_VERSION
app.setApplicationVersion(X_TOOLS_VERSION);
#endif
QSplashScreen& splashScreen = qobject_cast<xToolsApplication*>(qApp)->splashScreen();
if (usingCommonMainWindow) {
MainWindowT* mainWindow = new MainWindowT();
splashScreen.finish(mainWindow);
UiT* centralWidget = new UiT(mainWindow);
mainWindow->setWindowTitle(cookedAppName);
mainWindow->setCentralWidget(centralWidget);
mainWindow->show();
mainWindow->resize(int(qreal(mainWindow->height()) * 1.732), mainWindow->height());
mainWindow->moveToCenter();
qInfo() << "The size of window is" << mainWindow->size();
} else {
UiT* widget = new UiT();
splashScreen.finish(widget);
widget->show();
widget->resize(int(qreal(widget->height()) * 1.732), widget->height());
qInfo() << "The size of window is" << widget->size();
}
int ret = app.exec();
sakDoSomethingAfterAppExited();
return ret;
}
template<typename T>
int xToolsExec(int argc, char* argv[], const QString& appName, bool usingCommonMainWindow = true)
{
return xToolsExec<T, xToolsMainWindow, xToolsApplication>(argc,
argv,
appName,
usingCommonMainWindow);
}

View File

@ -8,7 +8,7 @@
**************************************************************************************************/
#include "Application.h"
#include "MainWindow.h"
#include "xToolsUi.h"
#include "xTools.h"
int main(const int argc, char *argv[])
{

View File

@ -124,6 +124,7 @@ SOURCES += \
Source/Assistants/Ping/Source/xToolsPingAssistant.cpp \
Source/Assistants/String/Source/xToolsStringAssistant.cpp \
Source/Assistants/xToolsAssistantFactory.cpp \
Source/Common/Common/xToolsApplication.cpp \
Source/Common/Common/xToolsCrcInterface.cpp \
Source/Common/Common/xToolsDataStructure.cpp \
Source/Common/Common/xToolsNetworkInterfaceScanner.cpp \
@ -131,7 +132,6 @@ SOURCES += \
Source/Common/Common/xToolsSettings.cpp \
Source/Common/Common/xToolsTableModel.cpp \
Source/Common/CommonUI/xToolsAffixesComboBox.cpp \
Source/Common/CommonUI/xToolsApplication.cpp \
Source/Common/CommonUI/xToolsBaudRateComboBox.cpp \
Source/Common/CommonUI/xToolsCheckBox.cpp \
Source/Common/CommonUI/xToolsComboBox.cpp \
@ -150,7 +150,6 @@ SOURCES += \
Source/Common/CommonUI/xToolsSpinBox.cpp \
Source/Common/CommonUI/xToolsStopBitsComboBox.cpp \
Source/Common/CommonUI/xToolsTextFormatComboBox.cpp \
Source/Common/CommonUI/xToolsUiInterface.cpp \
Source/Common/CommonUI/xToolsWebSocketMessageTypeComboBox.cpp \
Source/SystemTrayIcon.cpp \
Source/ToolBox/ToolBox/xToolsToolBox.cpp \
@ -231,6 +230,7 @@ HEADERS += \
Source/Assistants/String/Source/xToolsStringAssistant.h \
Source/Assistants/xToolsAssistantFactory.h \
Source/Common/Common/xTools.h \
Source/Common/Common/xToolsApplication.h \
Source/Common/Common/xToolsCompatibility.h \
Source/Common/Common/xToolsCrcInterface.h \
Source/Common/Common/xToolsDataStructure.h \
@ -239,7 +239,6 @@ HEADERS += \
Source/Common/Common/xToolsSettings.h \
Source/Common/Common/xToolsTableModel.h \
Source/Common/CommonUI/xToolsAffixesComboBox.h \
Source/Common/CommonUI/xToolsApplication.h \
Source/Common/CommonUI/xToolsBaudRateComboBox.h \
Source/Common/CommonUI/xToolsCheckBox.h \
Source/Common/CommonUI/xToolsComboBox.h \
@ -259,7 +258,6 @@ HEADERS += \
Source/Common/CommonUI/xToolsStopBitsComboBox.h \
Source/Common/CommonUI/xToolsTextFormatComboBox.h \
Source/Common/CommonUI/xToolsUi.h \
Source/Common/CommonUI/xToolsUiInterface.h \
Source/Common/CommonUI/xToolsWebSocketMessageTypeComboBox.h \
Source/MainWindow.h \
Source/SystemTrayIcon.h \