Skip to content

Commit

Permalink
Support compiling with Qt6.
Browse files Browse the repository at this point in the history
  • Loading branch information
leozide committed Apr 28, 2024
1 parent ad2f56e commit b957d6b
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 66 deletions.
4 changes: 4 additions & 0 deletions common/lc_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
#include "lc_previewwidget.h"

#ifdef Q_OS_WIN
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
#include <QtPlatformHeaders\QWindowsWindowFunctions>
#endif
#endif

lcApplication* gApplication;

Expand Down Expand Up @@ -1239,7 +1241,9 @@ lcStartupMode lcApplication::Initialize(const QList<QPair<QString, bool>>& Libra
gMainWindow->show();

#ifdef Q_OS_WIN
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QWindowsWindowFunctions::setHasBorderInFullScreen(gMainWindow->windowHandle(), true);
#endif
#endif
}

Expand Down
30 changes: 25 additions & 5 deletions common/lc_blenderpreferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);

Expand Down
4 changes: 4 additions & 0 deletions common/lc_glextensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions common/lc_global.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions common/lc_http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#ifdef Q_OS_WIN

#include <windows.h>
#include <wininet.h>

lcHttpReply::lcHttpReply(QObject* Parent, const QString& URL)
Expand Down
2 changes: 1 addition & 1 deletion common/lc_objectproperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ bool lcObjectProperty<T>::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;
Expand Down
87 changes: 32 additions & 55 deletions qt/lc_renderdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
#include "lc_mainwindow.h"
#include "lc_model.h"

#ifdef Q_OS_WIN
#include <TlHelp32.h>
#endif

#define LC_POVRAY_PREVIEW_WIDTH 768
#define LC_POVRAY_PREVIEW_HEIGHT 432
#if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -606,74 +606,46 @@ 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)
return;

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();
mBlendProgMax = RxRenderProgress.cap(2).toInt();
ui->RenderProgress->setMaximum(mBlendProgMax);
ui->RenderProgress->setValue(mBlendProgValue);
}
#endif
}

QString lcRenderDialog::ReadStdErr(bool& HasError) const
Expand All @@ -698,8 +670,13 @@ QString lcRenderDialog::ReadStdErr(bool& HasError) const
returnLines << Line.trimmed() + "<br>";
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)
{
Expand Down
3 changes: 0 additions & 3 deletions qt/lc_renderdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ protected slots:
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
Expand Down
5 changes: 3 additions & 2 deletions qt/qtmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#pragma warning(push)
#pragma warning(disable : 4091)
#include <windows.h>
#include <dbghelp.h>
#include <direct.h>
#include <shlobj.h>
Expand Down Expand Up @@ -176,11 +177,11 @@ int main(int argc, char *argv[])

qRegisterMetaType<PieceInfo*>("PieceInfo*");
qRegisterMetaType<QList<int> >("QList<int>");
qRegisterMetaType<lcVector3>("lcVector3");
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
qRegisterMetaTypeStreamOperators<QList<int> >("QList<int>");
#endif
qRegisterMetaType<lcVector3>("lcVector3");
QMetaType::registerComparators<lcVector3>();
#endif

QList<QPair<QString, bool>> LibraryPaths;

Expand Down
Loading

0 comments on commit b957d6b

Please sign in to comment.