From b957d6bc3a8c8484e6ead628996c00ff67a73307 Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Sat, 27 Apr 2024 17:19:34 -0700 Subject: [PATCH] Support compiling with Qt6. --- common/lc_application.cpp | 4 ++ common/lc_blenderpreferences.cpp | 30 +++++++++-- common/lc_glextensions.cpp | 4 ++ common/lc_global.h | 1 + common/lc_http.cpp | 1 + common/lc_objectproperty.cpp | 2 +- qt/lc_renderdialog.cpp | 87 ++++++++++++-------------------- qt/lc_renderdialog.h | 3 -- qt/qtmain.cpp | 5 +- qt/system.cpp | 54 ++++++++++++++++++++ 10 files changed, 125 insertions(+), 66 deletions(-) diff --git a/common/lc_application.cpp b/common/lc_application.cpp index f782654b..c429f7fe 100644 --- a/common/lc_application.cpp +++ b/common/lc_application.cpp @@ -13,8 +13,10 @@ #include "lc_previewwidget.h" #ifdef Q_OS_WIN +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) #include #endif +#endif lcApplication* gApplication; @@ -1239,7 +1241,9 @@ lcStartupMode lcApplication::Initialize(const QList>& Libra gMainWindow->show(); #ifdef Q_OS_WIN +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) QWindowsWindowFunctions::setHasBorderInFullScreen(gMainWindow->windowHandle(), true); +#endif #endif } diff --git a/common/lc_blenderpreferences.cpp b/common/lc_blenderpreferences.cpp index 56553dfb..6bac634f 100644 --- a/common/lc_blenderpreferences.cpp +++ b/common/lc_blenderpreferences.cpp @@ -1757,15 +1757,24 @@ void lcBlenderPreferences::GetStandardOutput() void lcBlenderPreferences::ReadStdOut(const QString& StdOutput, QString& Errors) { +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + QRegularExpression RxInfo("^INFO: "); + QRegularExpression RxData("^DATA: "); + QRegularExpression RxError("^(?:\\w)*ERROR: ", QRegularExpression::CaseInsensitiveOption); + QRegularExpression RxWarning("^(?:\\w)*WARNING: ", QRegularExpression::CaseInsensitiveOption); + QRegularExpression RxAddonVersion("^ADDON VERSION: ", QRegularExpression::CaseInsensitiveOption); + QStringList StdOutLines = StdOutput.split(QRegularExpression("\n|\r\n|\r")); +#else QRegExp RxInfo("^INFO: "); QRegExp RxData("^DATA: "); QRegExp RxError("^(?:\\w)*ERROR: ", Qt::CaseInsensitive); QRegExp RxWarning("^(?:\\w)*WARNING: ", Qt::CaseInsensitive); QRegExp RxAddonVersion("^ADDON VERSION: ", Qt::CaseInsensitive); + QStringList StdOutLines = StdOutput.split(QRegExp("\n|\r\n|\r")); +#endif bool ErrorEncountered = false; QStringList Items, ErrorList; - QStringList StdOutLines = StdOutput.split(QRegExp("\n|\r\n|\r")); const QString SaveAddonVersion = mAddonVersion; const QString SaveVersion = mBlenderVersion; @@ -1862,9 +1871,15 @@ void lcBlenderPreferences::ReadStdOut() mStdOutList.append(StdOut); +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + QRegularExpression RxInfo("^INFO: "); + QRegularExpression RxError("(?:\\w)*ERROR: ", QRegularExpression::CaseInsensitiveOption); + QRegularExpression RxWarning("(?:\\w)*WARNING: ", QRegularExpression::CaseInsensitiveOption); +#else QRegExp RxInfo("^INFO: "); QRegExp RxError("(?:\\w)*ERROR: ", Qt::CaseInsensitive); QRegExp RxWarning("(?:\\w)*WARNING: ", Qt::CaseInsensitive); +#endif bool const Error = StdOut.contains(RxError); bool const Warning = StdOut.contains(RxWarning); @@ -2382,7 +2397,7 @@ void lcBlenderPreferences::ResetSettings() void lcBlenderPreferences::LoadSettings() { - QStringList const& DataPathList = QStandardPaths::standardLocations(QStandardPaths::DataLocation); + QStringList const& DataPathList = QStandardPaths::standardLocations(QStandardPaths::AppLocalDataLocation); gAddonPreferences->mDataDir = DataPathList.first(); if (QFileInfo(lcGetProfileString(LC_PROFILE_BLENDER_PATH)).isReadable()) @@ -2759,7 +2774,12 @@ void lcBlenderPreferences::ColorButtonClicked(bool) connect(Popup, SIGNAL(selected(int)), SLOT(SetDefaultColor(int))); Popup->setMinimumSize(300, 200); +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + QScreen* Screen = screen(); + const QRect DesktopGeom = Screen ? Screen->geometry() : QRect(); +#else const QRect DesktopGeom = QApplication::desktop()->geometry(); +#endif QPoint Pos = Parent->mapToGlobal(Parent->rect().bottomLeft()); if (Pos.x() < DesktopGeom.left()) @@ -3478,7 +3498,7 @@ int lcBlenderPreferences::ShowMessage(const QString& Header, const QString& Tit if (FixedWidth == MinimumWidth) { int Index = (MinimumWidth / FontWidth) - 1; - if (!Body.midRef(Index,1).isEmpty()) + if (!Body.mid(Index,1).isEmpty()) FixedWidth = Body.indexOf(" ", Index); } else if (FixedWidth < MinimumWidth) @@ -3666,12 +3686,12 @@ bool lcBlenderPreferences::ExtractAddon(const QString FileName, QString& Result) // Check the file path - if broken, convert separators, eat leading and trailing ones FileInfo.filePath = QDir::fromNativeSeparators(FileInfo.ZipInfo.file_name); - QStringRef FilePathRef(&FileInfo.filePath); + QString FilePathRef(FileInfo.filePath); while (FilePathRef.startsWith(QLatin1Char('.')) || FilePathRef.startsWith(QLatin1Char('/'))) FilePathRef = FilePathRef.mid(1); while (FilePathRef.endsWith(QLatin1Char('/'))) FilePathRef.chop(1); - FileInfo.filePath = FilePathRef.toString(); + FileInfo.filePath = FilePathRef; const QString AbsPath = QDir::fromNativeSeparators(DestinationDir + QDir::separator() + FileInfo.filePath); diff --git a/common/lc_glextensions.cpp b/common/lc_glextensions.cpp index 2fcb0a8a..98cc0432 100644 --- a/common/lc_glextensions.cpp +++ b/common/lc_glextensions.cpp @@ -11,6 +11,10 @@ GLfloat gMaxAnisotropy; #if !defined(QT_NO_DEBUG) && defined(GL_ARB_debug_output) +#ifndef APIENTRY +#define APIENTRY +#endif + static void APIENTRY lcGLDebugCallback(GLenum Source, GLenum Type, GLuint Id, GLenum Severity, GLsizei Length, const GLchar* Message, GLvoid* UserParam) { Q_UNUSED(Source); diff --git a/common/lc_global.h b/common/lc_global.h index 33fbfa04..6cd3cc0b 100644 --- a/common/lc_global.h +++ b/common/lc_global.h @@ -58,6 +58,7 @@ typedef quint32 lcStep; #ifdef Q_OS_WIN char* strcasestr(const char *s, const char *find); +int lcTerminateChildProcess(QWidget* Parent, const qint64 Pid, const qint64 Ppid); #else char* strupr(char* string); #endif diff --git a/common/lc_http.cpp b/common/lc_http.cpp index 8863eb07..0cfca2c8 100644 --- a/common/lc_http.cpp +++ b/common/lc_http.cpp @@ -3,6 +3,7 @@ #ifdef Q_OS_WIN +#include #include lcHttpReply::lcHttpReply(QObject* Parent, const QString& URL) diff --git a/common/lc_objectproperty.cpp b/common/lc_objectproperty.cpp index 2aaf3711..91d23d7a 100644 --- a/common/lc_objectproperty.cpp +++ b/common/lc_objectproperty.cpp @@ -273,7 +273,7 @@ bool lcObjectProperty::Load(QTextStream& Stream, const QString& Token, const return true; } - if (Token.endsWith(QLatin1String("_KEY")) && Token.leftRef(Token.size() - 4) == VariableName) + if (Token.endsWith(QLatin1String("_KEY")) && Token.left(Token.size() - 4) == VariableName) { QString StepString; Stream >> StepString; diff --git a/qt/lc_renderdialog.cpp b/qt/lc_renderdialog.cpp index 144ba99f..bfc9b272 100644 --- a/qt/lc_renderdialog.cpp +++ b/qt/lc_renderdialog.cpp @@ -8,10 +8,6 @@ #include "lc_mainwindow.h" #include "lc_model.h" -#ifdef Q_OS_WIN -#include -#endif - #define LC_POVRAY_PREVIEW_WIDTH 768 #define LC_POVRAY_PREVIEW_HEIGHT 432 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS) @@ -109,7 +105,7 @@ lcRenderDialog::lcRenderDialog(QWidget* Parent, int Command) bool BlenderConfigured = !lcGetProfileString(LC_PROFILE_BLENDER_IMPORT_MODULE).isEmpty(); - QStringList const& DataPathList = QStandardPaths::standardLocations(QStandardPaths::DataLocation); + QStringList const& DataPathList = QStandardPaths::standardLocations(QStandardPaths::AppLocalDataLocation); if (!QDir(QString("%1/Blender/addons/%2").arg(DataPathList.first()).arg(LC_BLENDER_ADDON_FOLDER_STR)).isReadable()) { BlenderConfigured = false; @@ -239,8 +235,7 @@ bool lcRenderDialog::PromptCancel() else if (mCommand == BLENDER_RENDER) gMainWindow->mActions[LC_FILE_RENDER_BLENDER]->setEnabled(true); #ifdef Q_OS_WIN - TerminateChildProcess(mProcess->processId(), - QCoreApplication::applicationPid()); + lcTerminateChildProcess(this, mProcess->processId(), QCoreApplication::applicationPid()); #endif mProcess->kill(); CloseProcess(); @@ -430,7 +425,7 @@ void lcRenderDialog::on_RenderButton_clicked() mBlendProgValue = 0; mBlendProgMax = 0; - const QStringList DataPathList = QStandardPaths::standardLocations(QStandardPaths::DataLocation); + const QStringList DataPathList = QStandardPaths::standardLocations(QStandardPaths::AppLocalDataLocation); mDataPath = DataPathList.first(); const QString DefaultBlendFile = QString("%1/blender/config/%2").arg(mDataPath).arg(LC_BLENDER_ADDON_BLEND_FILE); @@ -562,8 +557,13 @@ void lcRenderDialog::on_RenderButton_clicked() if (Log.open(QFile::ReadOnly | QFile::Text)) { QByteArray Ba = Log.readAll(); +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + const bool Error = QString(Ba).contains(QRegularExpression("(?:\\w)*ERROR: ", QRegularExpression::CaseInsensitiveOption)); + const bool Warning = QString(Ba).contains(QRegularExpression("(?:\\w)*WARNING: ", QRegularExpression::CaseInsensitiveOption)); +#else const bool Error = QString(Ba).contains(QRegExp("(?:\\w)*ERROR: ", Qt::CaseInsensitive)); const bool Warning = QString(Ba).contains(QRegExp("(?:\\w)*WARNING: ", Qt::CaseInsensitive)); +#endif if (Error || Warning) { QMessageBox::Icon Icon = QMessageBox::Warning; @@ -606,53 +606,6 @@ void lcRenderDialog::on_RenderButton_clicked() #endif } -#ifdef Q_OS_WIN -int lcRenderDialog::TerminateChildProcess(const qint64 Pid, const qint64 Ppid) -{ - DWORD pID = DWORD(Pid); - DWORD ppID = DWORD(Ppid); - HANDLE hSnapshot = INVALID_HANDLE_VALUE, hProcess = INVALID_HANDLE_VALUE; - PROCESSENTRY32 pe32; - - if ((hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, ppID)) == INVALID_HANDLE_VALUE) - { - QMessageBox::warning(this, tr("Error"), QString("%1 failed: %1").arg("CreateToolhelp32Snapshot").arg(GetLastError())); - return -1; - } - pe32.dwSize = sizeof(PROCESSENTRY32); - if (Process32First(hSnapshot, &pe32) == FALSE) - { - QMessageBox::warning(this, tr("Error"), QString("%1 failed: %2").arg("Process32First").arg(GetLastError())); - CloseHandle(hSnapshot); - return -2; - } - do - { - if (QString::fromWCharArray(pe32.szExeFile).contains(QRegExp("^(?:cmd\\.exe|conhost\\.exe|blender\\.exe)$", Qt::CaseInsensitive))) - { - if ((pe32.th32ProcessID == pID && pe32.th32ParentProcessID == ppID) || pe32.th32ParentProcessID == pID) - { - if ((hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pe32.th32ProcessID)) == INVALID_HANDLE_VALUE) - { - QMessageBox::warning(this, tr("Error"), tr("%1 failed: %2").arg("OpenProcess").arg(GetLastError())); - return -3; - } - else - { - TerminateProcess(hProcess, 9); - CloseHandle(hProcess); - } - } - } - } - while (Process32Next(hSnapshot, &pe32)); - - CloseHandle(hSnapshot); - - return 0; -} -#endif - void lcRenderDialog::ReadStdOut() { if (mCommand == POVRAY_RENDER) @@ -660,13 +613,31 @@ void lcRenderDialog::ReadStdOut() QString StdOut = QString(mProcess->readAllStandardOutput()); mStdOutList.append(StdOut); + +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + QRegularExpression RxRenderProgress; + RxRenderProgress.setPatternOptions(QRegularExpression::CaseInsensitiveOption); +#else QRegExp RxRenderProgress; RxRenderProgress.setCaseSensitivity(Qt::CaseInsensitive); +#endif bool BlenderVersion3 = lcGetProfileString(LC_PROFILE_BLENDER_VERSION).startsWith("v3"); + if (BlenderVersion3) RxRenderProgress.setPattern("Sample (\\d+)\\/(\\d+)"); else RxRenderProgress.setPattern("(\\d+)\\/(\\d+) Tiles"); + +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + QRegularExpressionMatch Match = RxRenderProgress.match(StdOut); + if (Match.hasMatch()) + { + mBlendProgValue = Match.captured(1).toInt(); + mBlendProgMax = Match.captured(2).toInt(); + ui->RenderProgress->setMaximum(mBlendProgMax); + ui->RenderProgress->setValue(mBlendProgValue); + } +#else if (StdOut.contains(RxRenderProgress)) { mBlendProgValue = RxRenderProgress.cap(1).toInt(); @@ -674,6 +645,7 @@ void lcRenderDialog::ReadStdOut() ui->RenderProgress->setMaximum(mBlendProgMax); ui->RenderProgress->setValue(mBlendProgValue); } +#endif } QString lcRenderDialog::ReadStdErr(bool& HasError) const @@ -698,8 +670,13 @@ QString lcRenderDialog::ReadStdErr(bool& HasError) const returnLines << Line.trimmed() + "
"; if (mCommand == POVRAY_RENDER) { +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + if (Line.contains(QRegularExpression("^POV-Ray finished$", QRegularExpression::CaseInsensitiveOption))) + HasError = false; +#else if (Line.contains(QRegExp("^POV-Ray finished$", Qt::CaseSensitive))) HasError = false; +#endif } else if (mCommand == BLENDER_RENDER) { diff --git a/qt/lc_renderdialog.h b/qt/lc_renderdialog.h index 1c5be87c..03cf0701 100644 --- a/qt/lc_renderdialog.h +++ b/qt/lc_renderdialog.h @@ -72,9 +72,6 @@ protected: void CloseProcess(); bool PromptCancel(); void ShowResult(); -#ifdef Q_OS_WIN - int TerminateChildProcess(const qint64 Pid, const qint64 Ppid); -#endif #ifndef QT_NO_PROCESS lcRenderProcess* mProcess; #endif diff --git a/qt/qtmain.cpp b/qt/qtmain.cpp index 3663c7f9..df739ae2 100644 --- a/qt/qtmain.cpp +++ b/qt/qtmain.cpp @@ -10,6 +10,7 @@ #pragma warning(push) #pragma warning(disable : 4091) +#include #include #include #include @@ -176,11 +177,11 @@ int main(int argc, char *argv[]) qRegisterMetaType("PieceInfo*"); qRegisterMetaType >("QList"); + qRegisterMetaType("lcVector3"); #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) qRegisterMetaTypeStreamOperators >("QList"); -#endif - qRegisterMetaType("lcVector3"); QMetaType::registerComparators(); +#endif QList> LibraryPaths; diff --git a/qt/system.cpp b/qt/system.cpp index fb534c46..9cdbc6bf 100644 --- a/qt/system.cpp +++ b/qt/system.cpp @@ -2,6 +2,9 @@ #ifdef Q_OS_WIN +#include +#include + char* strcasestr(const char *s, const char *find) { char c, sc; @@ -23,6 +26,57 @@ char* strcasestr(const char *s, const char *find) return ((char *)s); } +int lcTerminateChildProcess(QWidget* Parent, const qint64 Pid, const qint64 Ppid) +{ + DWORD pID = DWORD(Pid); + DWORD ppID = DWORD(Ppid); + HANDLE hSnapshot = INVALID_HANDLE_VALUE, hProcess = INVALID_HANDLE_VALUE; + PROCESSENTRY32 pe32; + + if ((hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, ppID)) == INVALID_HANDLE_VALUE) + { + QMessageBox::warning(Parent, QObject::tr("Error"), QString("%1 failed: %1").arg("CreateToolhelp32Snapshot").arg(GetLastError())); + return -1; + } + pe32.dwSize = sizeof(PROCESSENTRY32); + if (Process32First(hSnapshot, &pe32) == FALSE) + { + QMessageBox::warning(Parent, QObject::tr("Error"), QString("%1 failed: %2").arg("Process32First").arg(GetLastError())); + CloseHandle(hSnapshot); + return -2; + } + do + { +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + QRegularExpression ExeExpression("^(?:cmd\\.exe|conhost\\.exe|blender\\.exe)$", QRegularExpression::CaseInsensitiveOption); +#else + QRegExp ExeExpression("^(?:cmd\\.exe|conhost\\.exe|blender\\.exe)$", Qt::CaseInsensitive); +#endif + + if (QString::fromWCharArray(pe32.szExeFile).contains(ExeExpression)) + { + if ((pe32.th32ProcessID == pID && pe32.th32ParentProcessID == ppID) || pe32.th32ParentProcessID == pID) + { + if ((hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pe32.th32ProcessID)) == INVALID_HANDLE_VALUE) + { + QMessageBox::warning(Parent, QObject::tr("Error"), QObject::tr("%1 failed: %2").arg("OpenProcess").arg(GetLastError())); + return -3; + } + else + { + TerminateProcess(hProcess, 9); + CloseHandle(hProcess); + } + } + } + } + while (Process32Next(hSnapshot, &pe32)); + + CloseHandle(hSnapshot); + + return 0; +} + #else char* strupr(char *string)