mirror of
https://github.com/leozide/leocad
synced 2025-01-17 18:11:42 +01:00
Support compiling with Qt6.
This commit is contained in:
parent
ad2f56ea86
commit
b957d6bc3a
10 changed files with 125 additions and 66 deletions
|
@ -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;
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#ifdef Q_OS_WIN
|
||||
|
||||
#include <windows.h>
|
||||
#include <wininet.h>
|
||||
|
||||
lcHttpReply::lcHttpReply(QObject* Parent, const QString& URL)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
@ -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() + "<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)
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4091)
|
||||
#include <windows.h>
|
||||
#include <dbghelp.h>
|
||||
#include <direct.h>
|
||||
#include <shlobj.h>
|
||||
|
@ -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;
|
||||
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
#ifdef Q_OS_WIN
|
||||
|
||||
#include <windows.h>
|
||||
#include <TlHelp32.h>
|
||||
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue