From 02bc955deca3918f75533cb78e1dc2095b06c5c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=AE=E7=94=9F=E8=8B=A5=E6=A2=A6?= <1070753498@qq.com> Date: Wed, 20 Sep 2023 18:52:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/player/main.cpp | 3 ++- examples/transcoder/main.cc | 5 +++-- utils/hostosinfo.h | 36 +++++++++++++++++++----------------- utils/osspecificaspects.h | 4 ++-- utils/utils.cpp | 24 +++++++++--------------- 5 files changed, 35 insertions(+), 37 deletions(-) diff --git a/examples/player/main.cpp b/examples/player/main.cpp index 12c5cc0..8d34b3b 100644 --- a/examples/player/main.cpp +++ b/examples/player/main.cpp @@ -27,8 +27,9 @@ void setAppInfo() auto main(int argc, char *argv[]) -> int { #if defined(Q_OS_WIN) && QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - if (!qEnvironmentVariableIsSet("QT_OPENGL")) + if (!qEnvironmentVariableIsSet("QT_OPENGL")) { QCoreApplication::setAttribute(Qt::AA_UseOpenGLES); + } #else qputenv("QSG_RHI_BACKEND", "opengl"); #endif diff --git a/examples/transcoder/main.cc b/examples/transcoder/main.cc index 5d9e93b..fe92f34 100644 --- a/examples/transcoder/main.cc +++ b/examples/transcoder/main.cc @@ -23,11 +23,12 @@ void setAppInfo() qApp->setWindowIcon(qApp->style()->standardIcon(QStyle::SP_DriveDVDIcon)); } -int main(int argc, char *argv[]) +auto main(int argc, char *argv[]) -> int { #if defined(Q_OS_WIN) && QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - if (!qEnvironmentVariableIsSet("QT_OPENGL")) + if (!qEnvironmentVariableIsSet("QT_OPENGL")) { QCoreApplication::setAttribute(Qt::AA_UseOpenGLES); + } #else qputenv("QSG_RHI_BACKEND", "opengl"); #endif diff --git a/utils/hostosinfo.h b/utils/hostosinfo.h index 9d02249..0340984 100644 --- a/utils/hostosinfo.h +++ b/utils/hostosinfo.h @@ -42,7 +42,7 @@ namespace Utils { class UTILS_EXPORT HostOsInfo { public: - static constexpr OsType hostOs() + static constexpr auto hostOs() -> OsType { #if defined(Q_OS_WIN) return OsTypeWindows; @@ -57,14 +57,19 @@ class UTILS_EXPORT HostOsInfo #endif } - enum HostArchitecture { HostArchitectureX86, HostArchitectureAMD64, HostArchitectureItanium, - HostArchitectureArm, HostArchitectureUnknown }; - static HostArchitecture hostArchitecture(); - - static constexpr bool isWindowsHost() { return hostOs() == OsTypeWindows; } - static constexpr bool isLinuxHost() { return hostOs() == OsTypeLinux; } - static constexpr bool isMacHost() { return hostOs() == OsTypeMac; } - static constexpr bool isAnyUnixHost() + enum HostArchitecture { + HostArchitectureX86, + HostArchitectureAMD64, + HostArchitectureItanium, + HostArchitectureArm, + HostArchitectureUnknown + }; + static auto hostArchitecture() -> HostArchitecture; + + static constexpr auto isWindowsHost() -> bool { return hostOs() == OsTypeWindows; } + static constexpr auto isLinuxHost() -> bool { return hostOs() == OsTypeLinux; } + static constexpr auto isMacHost() -> bool { return hostOs() == OsTypeMac; } + static constexpr auto isAnyUnixHost() -> bool { #ifdef Q_OS_UNIX return true; @@ -73,7 +78,7 @@ class UTILS_EXPORT HostOsInfo #endif } - static QString withExecutableSuffix(const QString &executable) + static auto withExecutableSuffix(const QString &executable) -> QString { return OsSpecificAspects::withExecutableSuffix(hostOs(), executable); } @@ -84,21 +89,18 @@ class UTILS_EXPORT HostOsInfo static Qt::CaseSensitivity fileNameCaseSensitivity() { return m_useOverrideFileNameCaseSensitivity - ? m_overrideFileNameCaseSensitivity - : OsSpecificAspects::fileNameCaseSensitivity(hostOs()); + ? m_overrideFileNameCaseSensitivity + : OsSpecificAspects::fileNameCaseSensitivity(hostOs()); } - static QChar pathListSeparator() - { - return OsSpecificAspects::pathListSeparator(hostOs()); - } + static QChar pathListSeparator() { return OsSpecificAspects::pathListSeparator(hostOs()); } static Qt::KeyboardModifier controlModifier() { return OsSpecificAspects::controlModifier(hostOs()); } - static bool canCreateOpenGLContext(QString *errorMessage); + static auto canCreateOpenGLContext(QString *errorMessage) -> bool; private: static Qt::CaseSensitivity m_overrideFileNameCaseSensitivity; diff --git a/utils/osspecificaspects.h b/utils/osspecificaspects.h index 1a5bec0..d60a584 100644 --- a/utils/osspecificaspects.h +++ b/utils/osspecificaspects.h @@ -38,7 +38,7 @@ enum OsType { OsTypeWindows, OsTypeLinux, OsTypeMac, OsTypeOtherUnix, OsTypeOthe namespace OsSpecificAspects { -inline QString withExecutableSuffix(OsType osType, const QString &executable) +inline auto withExecutableSuffix(OsType osType, const QString &executable) -> QString { QString finalName = executable; if (osType == OsTypeWindows) @@ -66,7 +66,7 @@ inline Qt::KeyboardModifier controlModifier(OsType osType) return osType == OsTypeMac ? Qt::MetaModifier : Qt::ControlModifier; } -inline QString pathWithNativeSeparators(OsType osType, const QString &pathName) +inline auto pathWithNativeSeparators(OsType osType, const QString &pathName) -> QString { if (osType == OsTypeWindows) { const int pos = pathName.indexOf('/'); diff --git a/utils/utils.cpp b/utils/utils.cpp index 0856423..5da4c15 100644 --- a/utils/utils.cpp +++ b/utils/utils.cpp @@ -58,7 +58,7 @@ void Utils::windowCenter(QWidget *window) window->move(x, y); } -QString compilerString() +auto compilerString() -> QString { #if defined(__apple_build_version__) // Apple clang has other version numbers QString isAppleString = QLatin1String(" (Apple)"); @@ -83,23 +83,17 @@ void Utils::printBuildInfo() void Utils::setHighDpiEnvironmentVariable() { - if (Utils::HostOsInfo().isMacHost()) { + if (Utils::HostOsInfo::isMacHost()) { return; } - if (Utils::HostOsInfo().isWindowsHost() && !qEnvironmentVariableIsSet("QT_OPENGL")) { -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - QCoreApplication::setAttribute(Qt::AA_UseOpenGLES); -#endif - } - if (Utils::HostOsInfo().isWindowsHost() + if (Utils::HostOsInfo::isWindowsHost() && !qEnvironmentVariableIsSet("QT_DEVICE_PIXEL_RATIO") // legacy in 5.6, but still functional && !qEnvironmentVariableIsSet("QT_AUTO_SCREEN_SCALE_FACTOR") && !qEnvironmentVariableIsSet("QT_SCALE_FACTOR") && !qEnvironmentVariableIsSet("QT_SCREEN_SCALE_FACTORS")) { #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); - QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); #endif } @@ -117,7 +111,7 @@ void Utils::reboot() QApplication::exit(); } -qint64 calculateDir(const QString &localPath) +auto calculateDir(const QString &localPath) -> qint64 { qint64 size = 0; QDir dir(localPath); @@ -136,7 +130,7 @@ qint64 calculateDir(const QString &localPath) return size; } -qint64 Utils::fileSize(const QString &localPath) +auto Utils::fileSize(const QString &localPath) -> qint64 { QFileInfo info(localPath); if (info.isDir()) { @@ -146,7 +140,7 @@ qint64 Utils::fileSize(const QString &localPath) } } -bool Utils::generateDirectorys(const QString &directory) +auto Utils::generateDirectorys(const QString &directory) -> bool { QDir sourceDir(directory); if (sourceDir.exists()) { @@ -188,7 +182,7 @@ void removeFiles(const QString &path) } } -static QString errnoToQString(int error) +static auto errnoToQString(int error) -> QString { #if defined(Q_OS_WIN) && !defined(Q_CC_MINGW) char msg[128]; @@ -229,7 +223,7 @@ void Utils::removeDirectory(const QString &path) } } -QString Utils::convertBytesToString(qint64 bytes) +auto Utils::convertBytesToString(qint64 bytes) -> QString { const QStringList list = {"B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"}; const int unit = 1024; @@ -276,7 +270,7 @@ void Utils::setGlobalThreadPoolMaxSize(int maxSize) instance->setMaxThreadCount(qMax(4, 2 * instance->maxThreadCount())); } -QString Utils::getConfigPath() +auto Utils::getConfigPath() -> QString { static QString path; if (path.isEmpty()) {