mirror of
https://github.com/x-tools-author/x-tools.git
synced 2025-09-15 15:28:40 +08:00
chore: update the file
This commit is contained in:
parent
a9d3418626
commit
837b473636
@ -249,29 +249,6 @@ else()
|
||||
list(REMOVE_ITEM X_TOOLS_SOURCE ${TMP_DIR}/UI/DataVisualization/2D/ChartsUiSettings.ui)
|
||||
endif()
|
||||
|
||||
# --------------------------------------------------------------------------------------------------
|
||||
# Tools
|
||||
set(X_TOOLS_TOOLS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/Tools")
|
||||
macro(add_tool dir_name)
|
||||
file(GLOB TOOL_SOURCE "${X_TOOLS_TOOLS_DIR}/${dir_name}/*.*")
|
||||
include_directories(${X_TOOLS_TOOLS_DIR}/${dir_name})
|
||||
list(APPEND X_TOOLS_SOURCE ${TOOL_SOURCE})
|
||||
# away remove main.cpp
|
||||
list(REMOVE_ITEM X_TOOLS_SOURCE ${X_TOOLS_TOOLS_DIR}/${dir_name}/main.cpp)
|
||||
endmacro()
|
||||
# cmake-format: off
|
||||
file(GLOB ALL_TOOLS RELATIVE ${X_TOOLS_TOOLS_DIR} ${X_TOOLS_TOOLS_DIR}/*)
|
||||
list(REMOVE_ITEM ALL_TOOLS "AssistantFactory.h")
|
||||
list(REMOVE_ITEM ALL_TOOLS "AssistantFactory.cpp")
|
||||
# cmake-format: on
|
||||
if(NOT X_TOOLS_ENABLE_MODULE_SERIALBUS)
|
||||
list(REMOVE_ITEM ALL_TOOLS "CANBus" "Modbus")
|
||||
endif()
|
||||
|
||||
foreach(tool ${ALL_TOOLS})
|
||||
add_tool(${tool})
|
||||
endforeach()
|
||||
|
||||
set(X_TOOLS_TOOLS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/Tools)
|
||||
include_directories(${X_TOOLS_TOOLS_DIR})
|
||||
list(APPEND X_TOOLS_SOURCE ${X_TOOLS_TOOLS_DIR}/AssistantFactory.h)
|
||||
@ -305,10 +282,11 @@ set_target_properties(
|
||||
MACOSX_BUNDLE TRUE
|
||||
WIN32_EXECUTABLE TRUE
|
||||
QT_ANDROID_PACKAGE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/android)
|
||||
target_link_libraries(xTools PUBLIC Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui)
|
||||
target_link_libraries(xTools PUBLIC Qt${QT_VERSION_MAJOR}::Network)
|
||||
target_link_libraries(xTools PUBLIC Qt${QT_VERSION_MAJOR}::Svg Qt${QT_VERSION_MAJOR}::Widgets)
|
||||
target_link_libraries(xTools PUBLIC glog::glog qrencode qmdnsengine)
|
||||
target_link_libraries(
|
||||
xTools
|
||||
PUBLIC Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::Network
|
||||
Qt${QT_VERSION_MAJOR}::Svg Qt${QT_VERSION_MAJOR}::Widgets)
|
||||
target_link_libraries(xTools PUBLIC QssMgr glog::glog qrencode qmdnsengine)
|
||||
|
||||
if(X_TOOLS_ENABLE_MODULE_SERIAL_PORT)
|
||||
target_link_libraries(xTools PUBLIC Qt${QT_VERSION_MAJOR}::SerialPort)
|
||||
|
||||
@ -23,9 +23,9 @@ list(APPEND QSS_MGR_SOURCE ${CMAKE_SOURCE_DIR}/3rd/${package_name}/src/acss_glob
|
||||
list(APPEND QSS_MGR_SOURCE ${CMAKE_SOURCE_DIR}/3rd/${package_name}/src/QtAdvancedStylesheet.h)
|
||||
list(APPEND QSS_MGR_SOURCE ${CMAKE_SOURCE_DIR}/3rd/${package_name}/src/QtAdvancedStylesheet.cpp)
|
||||
list(APPEND QSS_MGR_SOURCE ${CMAKE_SOURCE_DIR}/3rd/${package_name}/src/QtAdvancedStylesheet.cpp)
|
||||
add_library(QSSMgr STATIC ${QSS_MGR_SOURCE})
|
||||
set_property(TARGET QSSMgr PROPERTY FOLDER "3rd")
|
||||
target_link_libraries(QSSMgr PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui
|
||||
add_library(QssMgr STATIC ${QSS_MGR_SOURCE})
|
||||
set_property(TARGET QssMgr PROPERTY FOLDER "3rd")
|
||||
target_link_libraries(QssMgr PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui
|
||||
Qt${QT_VERSION_MAJOR}::Svg Qt${QT_VERSION_MAJOR}::Widgets)
|
||||
|
||||
# --------------------------------------------------------------------------------------------------
|
||||
|
||||
@ -19,10 +19,12 @@
|
||||
#include <QLabel>
|
||||
#include <QLayout>
|
||||
#include <QMenuBar>
|
||||
#include <QMessageBox>
|
||||
#include <QNetworkProxyFactory>
|
||||
#include <QPainter>
|
||||
#include <QPixmap>
|
||||
#include <QScrollBar>
|
||||
#include <QSvgRenderer>
|
||||
#include <QTextBrowser>
|
||||
#include <QVariant>
|
||||
|
||||
@ -35,7 +37,7 @@
|
||||
#endif
|
||||
|
||||
MainWindow::MainWindow(QWidget* parent)
|
||||
: xTools::MainWindow(parent)
|
||||
: QMainWindow(parent)
|
||||
, m_toolMenu(nullptr)
|
||||
{
|
||||
m_appStyleActionGroup = new QActionGroup(this);
|
||||
@ -141,7 +143,7 @@ QIcon MainWindow::cookedIcon(const QIcon& icon)
|
||||
|
||||
void MainWindow::updateWindowTitle()
|
||||
{
|
||||
xTools& xTools = xTools::singleton();
|
||||
xTools::xTools& xTools = xTools::xTools::singleton();
|
||||
QString title = xTools.appFriendlyName();
|
||||
title += " v";
|
||||
title += QApplication::applicationVersion();
|
||||
@ -564,7 +566,7 @@ void MainWindow::initMenuLanguage()
|
||||
m_languageMenu = new QMenu(tr("&Languages"), this);
|
||||
menuBar()->addMenu(m_languageMenu);
|
||||
|
||||
xTools& xTools = xTools::singleton();
|
||||
xTools::xTools& xTools = xTools::xTools::singleton();
|
||||
QStringList languages = xTools.languageSupportedLanguages();
|
||||
QString settingLanguage = xTools.settingsLanguage();
|
||||
for (auto& language : languages) {
|
||||
@ -609,7 +611,7 @@ void MainWindow::initMenuHelp()
|
||||
|
||||
void MainWindow::initOptionMenuAppStyleMenu()
|
||||
{
|
||||
xTools& xTools = xTools::singleton();
|
||||
xTools::xTools& xTools = xTools::xTools::singleton();
|
||||
m_appStyleMenu = new QMenu(tr("Application Style"), this);
|
||||
m_optionMenu->addMenu(m_appStyleMenu);
|
||||
QStringList keys = QStyleFactory::keys();
|
||||
@ -645,7 +647,7 @@ void MainWindow::initOptionMenuSettingsMenu()
|
||||
auto clearAction = new QAction(tr("Clear Settings"), this);
|
||||
menu->addAction(clearAction);
|
||||
connect(clearAction, &QAction::triggered, this, [=]() {
|
||||
xTools& xTools = xTools::singleton();
|
||||
xTools::xTools& xTools = xTools::xTools::singleton();
|
||||
xTools.settingsSetClearSettings(true);
|
||||
tryToReboot();
|
||||
});
|
||||
@ -653,7 +655,7 @@ void MainWindow::initOptionMenuSettingsMenu()
|
||||
auto openAction = new QAction(tr("Open Settings Directory"), this);
|
||||
menu->addAction(openAction);
|
||||
connect(openAction, &QAction::triggered, this, [=]() {
|
||||
xTools& xTools = xTools::singleton();
|
||||
xTools::xTools& xTools = xTools::xTools::singleton();
|
||||
QDesktopServices::openUrl(xTools.settingsPath());
|
||||
});
|
||||
}
|
||||
@ -662,7 +664,7 @@ void MainWindow::initOptionMenuHdpiPolicy()
|
||||
{
|
||||
QMenu* menu = new QMenu(tr("HDPI Policy"));
|
||||
QActionGroup* actionGroup = new QActionGroup(this);
|
||||
xTools& xTools = xTools::singleton();
|
||||
xTools::xTools& xTools = xTools::xTools::singleton();
|
||||
int currentPolicy = xTools.settingsHdpiPolicy();
|
||||
auto supportedPolicies = xTools.hdpiSupportedPolicies();
|
||||
for (auto& policy : supportedPolicies) {
|
||||
@ -701,7 +703,7 @@ void MainWindow::initOptionMenuColorScheme()
|
||||
m_optionMenu->addMenu(m_colorSchemeMenu);
|
||||
|
||||
connect(&actionGroup, &QActionGroup::triggered, this, [=](QAction* action) {
|
||||
xTools& xTools = xTools::singleton();
|
||||
xTools::xTools& xTools = xTools::xTools::singleton();
|
||||
if (action == dark) {
|
||||
xTools.settingsSetColorScheme(static_cast<int>(Qt::ColorScheme::Dark));
|
||||
} else if (action == light) {
|
||||
@ -715,7 +717,7 @@ void MainWindow::initOptionMenuColorScheme()
|
||||
styleHints->setColorScheme(static_cast<Qt::ColorScheme>(currentScheme));
|
||||
});
|
||||
|
||||
xTools& xTools = xTools::singleton();
|
||||
xTools::xTools& xTools = xTools::xTools::singleton();
|
||||
auto currentScheme = xTools.settingsColorScheme();
|
||||
switch (currentScheme) {
|
||||
case static_cast<int>(Qt::ColorScheme::Dark):
|
||||
@ -736,14 +738,14 @@ void MainWindow::initOptionMenuColorScheme()
|
||||
|
||||
void MainWindow::onHdpiPolicyActionTriggered(int policy)
|
||||
{
|
||||
xTools& xTools = xTools::singleton();
|
||||
xTools::xTools& xTools = xTools::xTools::singleton();
|
||||
xTools.settingsSetHdpiPolicy(int(policy));
|
||||
tryToReboot();
|
||||
}
|
||||
|
||||
void MainWindow::onAboutActionTriggered()
|
||||
{
|
||||
xTools& xTools = xTools::singleton();
|
||||
xTools::xTools& xTools = xTools::xTools::singleton();
|
||||
QString buildDateTimeFormat = xTools.dtSystemDateFormat();
|
||||
buildDateTimeFormat += " ";
|
||||
buildDateTimeFormat += xTools.dtSystemTimeFormat();
|
||||
|
||||
@ -11,21 +11,21 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QWidget>
|
||||
|
||||
#include "AsciiAssistant.h"
|
||||
#include "Base64Assistant.h"
|
||||
#include "BroadcastAssistant.h"
|
||||
#include "CrcAssistant.h"
|
||||
#include "FileCheckAssistant.h"
|
||||
#include "FileMergeAssistant.h"
|
||||
#include "NumberAssistant.h"
|
||||
#include "PingAssistant.h"
|
||||
#include "StringAssistant.h"
|
||||
#include "MdnsAssistant.h"
|
||||
#include "QRCodeAssistant.h"
|
||||
#include "ASCII/AsciiAssistant.h"
|
||||
#include "Base64/Base64Assistant.h"
|
||||
#include "Broadcast/BroadcastAssistant.h"
|
||||
#include "CRC/CrcAssistant.h"
|
||||
#include "FileCheck/FileCheckAssistant.h"
|
||||
#include "FileMerge/FileMergeAssistant.h"
|
||||
#include "Number/NumberAssistant.h"
|
||||
#include "Ping/PingAssistant.h"
|
||||
#include "QRCode/QRCodeAssistant.h"
|
||||
#include "String/StringAssistant.h"
|
||||
#include "mDNS/MdnsAssistant.h"
|
||||
|
||||
#ifdef X_TOOLS_ENABLE_MODULE_SERIALBUS
|
||||
#include "CanBusAssistant.h"
|
||||
#include "ModbusAssistant.h"
|
||||
#include "CANBus/CanBusAssistant.h"
|
||||
#include "Modbus/ModbusAssistant.h"
|
||||
#endif
|
||||
|
||||
AssistantFactory::AssistantFactory(QObject* parent)
|
||||
|
||||
@ -119,8 +119,7 @@ ModbusAssistant::ModbusAssistant(QWidget *parent)
|
||||
, m_keyCtx(new ModbusSettingKeys)
|
||||
, m_textFormat(static_cast<int>(xTools::xIO::TextFormat::Dec))
|
||||
{
|
||||
xTools::xTools &xTools = xTools::xTools::singleton();
|
||||
m_settings = xTools.settings();
|
||||
m_settings = xTools::xTools::singleton().settings();
|
||||
|
||||
ui->setupUi(this);
|
||||
|
||||
|
||||
@ -7,10 +7,15 @@
|
||||
* code directory.
|
||||
**************************************************************************************************/
|
||||
#include "MainWindow.h"
|
||||
#include "application.h"
|
||||
#include "xtools.h"
|
||||
|
||||
int main(const int argc, char *argv[])
|
||||
{
|
||||
const QString version = xTools::xTools::xToolsVersion();
|
||||
return xTools::exec<MainWindow, MainWindow>(argc, argv, QString("xTools"), version);
|
||||
Application app(argc, argv);
|
||||
|
||||
MainWindow window;
|
||||
window.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
@ -15,8 +15,6 @@
|
||||
#include <QPainter>
|
||||
#include <QStandardPaths>
|
||||
|
||||
namespace xTools {
|
||||
|
||||
bool QssMgr::m_enableStylesheet = false;
|
||||
bool QssMgr::m_awaysEnableStylesheet = false;
|
||||
QssMgr::QssMgr(QObject* parent)
|
||||
@ -256,5 +254,3 @@ void QssMgr::setApplicationStylesheetEnabled(bool enable)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace xTools
|
||||
|
||||
@ -14,8 +14,6 @@
|
||||
#include <QSettings>
|
||||
#include <QtAdvancedStylesheet.h>
|
||||
|
||||
namespace xTools {
|
||||
|
||||
class QssMgr : public acss::QtAdvancedStylesheet
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -56,5 +54,3 @@ private:
|
||||
|
||||
void setApplicationStylesheetEnabled(bool enable);
|
||||
};
|
||||
|
||||
} // namespace xTools
|
||||
|
||||
91
src/xtools.h
91
src/xtools.h
@ -29,6 +29,7 @@
|
||||
static void (*gOutputLog2Ui)(QtMsgType, const QMessageLogContext &, const QString &);
|
||||
|
||||
namespace xTools {
|
||||
|
||||
class xToolsPrivate;
|
||||
class xTools : public QObject
|
||||
{
|
||||
@ -135,92 +136,4 @@ public:
|
||||
Q_INVOKABLE void tryToClearSettings();
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief exec: Using this function to start the application with a main window, you can specified
|
||||
* the central widget type of main window. If MainWindow is the same as CentralWidget, the
|
||||
* main window will not be created and the instance of CentralWidget will be the main window.
|
||||
* \param argc: The number of command line arguments.
|
||||
* \param argv: The command line arguments.
|
||||
* \param appName: The name of the application.
|
||||
* \param version: The version of the application.
|
||||
* \param doSomethingBeforAppExec: The function will be called before the application exec. The
|
||||
* parameter of the function is the instance of the main window and the instance of the application.
|
||||
* \return
|
||||
*/
|
||||
template<typename CentralWidgetT, typename MainWindowT>
|
||||
int exec(int argc,
|
||||
char *argv[],
|
||||
const QString &appName,
|
||||
const QString &appVersion = QString("0.0.0"),
|
||||
const std::function<void(void *, void *)> &doSomethingBeforAppExec = nullptr)
|
||||
{
|
||||
QCoreApplication::setApplicationVersion(appVersion);
|
||||
xTools::doSomethingBeforeAppCreated(argv, appName);
|
||||
|
||||
QApplication app(argc, argv);
|
||||
g_xTools.splashScreenShow();
|
||||
g_xTools.languageSetupAppLanguage();
|
||||
|
||||
QStyleHints *styleHints = QApplication::styleHints();
|
||||
styleHints->setColorScheme(static_cast<Qt::ColorScheme>(g_xTools.settingsColorScheme()));
|
||||
|
||||
const QString dtStr = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
|
||||
g_xTools.settingsSetValue("startUpTime", dtStr);
|
||||
|
||||
#ifdef X_TOOLS_ENABLE_QSS
|
||||
auto &styleSheetManager = QssMgr::singleton();
|
||||
const QString styleSheet = styleSheetManager.styleSheet();
|
||||
if (!styleSheet.isEmpty() && !styleSheetManager.currentTheme().isEmpty()) {
|
||||
app.setStyleSheet(styleSheet);
|
||||
}
|
||||
#endif
|
||||
|
||||
const QStringList keys = QStyleFactory::keys();
|
||||
qInfo() << "The supported application styles are:" << qPrintable(keys.join(QChar(',')));
|
||||
const QString style = g_xTools.settingsAppStyle();
|
||||
if (style.isEmpty()) {
|
||||
qWarning() << "The application style is not specified, the default style is:"
|
||||
<< qPrintable(QApplication::style()->objectName());
|
||||
} else if (keys.contains(style) || keys.contains(style.toLower())) {
|
||||
qInfo() << "The current style of application is:" << qPrintable(style);
|
||||
QApplication::setStyle(QStyleFactory::create(style));
|
||||
}
|
||||
|
||||
QWidget *ui;
|
||||
if (std::is_same<CentralWidgetT, MainWindowT>::value) {
|
||||
auto widget = new CentralWidgetT();
|
||||
ui = widget;
|
||||
} else {
|
||||
auto mainWindow = new MainWindowT();
|
||||
auto centralWidget = new CentralWidgetT(mainWindow);
|
||||
mainWindow->setWindowTitle(appName);
|
||||
mainWindow->setCentralWidget(centralWidget);
|
||||
ui = mainWindow;
|
||||
}
|
||||
|
||||
QSplashScreen *splashScreen = g_xTools.splashScreenGet();
|
||||
splashScreen->finish(ui);
|
||||
ui->show();
|
||||
ui->resize(static_cast<int>(static_cast<qreal>(ui->height()) * 1.732), ui->height());
|
||||
g_xTools.moveToScreenCenter(ui);
|
||||
|
||||
if (doSomethingBeforAppExec) {
|
||||
doSomethingBeforAppExec(ui, &app);
|
||||
}
|
||||
|
||||
const int ret = app.exec();
|
||||
xTools::doSomethingAfterAppExited();
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<typename CentralWidget>
|
||||
int execCentralWidget(int argc,
|
||||
char *argv[],
|
||||
const QString &appName,
|
||||
const QString &appVersion = QString("0.0.0"),
|
||||
const std::function<void(void *, void *)> &doSomethingBeforAppExec = nullptr)
|
||||
{
|
||||
return exec<CentralWidget, MainWindow>(argc, argv, appName, appVersion, doSomethingBeforAppExec);
|
||||
}
|
||||
|
||||
} // namespace xTools
|
||||
}
|
||||
@ -94,4 +94,4 @@ public:
|
||||
QStringList m_appSupportedLanguagePrefixes;
|
||||
};
|
||||
|
||||
} // namespace xTools
|
||||
} // namespace xTools
|
||||
Loading…
Reference in New Issue
Block a user