From df7afb956a19fd7ba4d9265a9ececce58f95d7a6 Mon Sep 17 00:00:00 2001 From: leo Date: Sat, 31 Jan 2015 20:38:53 +0000 Subject: [PATCH] More Qt cleanup. --- common/lc_application.cpp | 26 +++++++++++++++++++++++ common/lc_application.h | 2 -- common/lc_file.h | 12 +++++------ common/lc_global.h | 33 ++++++++++++++++++++++++++++- common/lc_mainwindow.cpp | 4 ++-- common/project.cpp | 12 +++++------ leocad.pro | 2 -- qt/lc_config.h | 42 ------------------------------------- qt/lc_qapplication.cpp | 44 --------------------------------------- 9 files changed, 72 insertions(+), 105 deletions(-) delete mode 100644 qt/lc_config.h delete mode 100644 qt/lc_qapplication.cpp diff --git a/common/lc_application.cpp b/common/lc_application.cpp index bc4b0d35..9544fe90 100644 --- a/common/lc_application.cpp +++ b/common/lc_application.cpp @@ -79,6 +79,32 @@ void lcApplication::SetClipboard(const QByteArray& Clipboard) gMainWindow->UpdatePaste(!mClipboard.isEmpty()); } +void lcApplication::ExportClipboard(const QByteArray& Clipboard) +{ + QMimeData* MimeData = new QMimeData(); + + MimeData->setData("application/vnd.leocad-clipboard", Clipboard); + QApplication::clipboard()->setMimeData(MimeData); + + SetClipboard(Clipboard); +} + +void lcApplication::GetFileList(const char* Path, lcArray& FileList) +{ + QDir Dir(Path); + Dir.setFilter(QDir::Files | QDir::Hidden | QDir::Readable); + + FileList.RemoveAll(); + QStringList Files = Dir.entryList(); + + for (int FileIdx = 0; FileIdx < Files.size(); FileIdx++) + { + QString AbsolutePath = Dir.absoluteFilePath(Files[FileIdx]); + + FileList.Add(AbsolutePath.toLocal8Bit().data()); + } +} + bool lcApplication::LoadPiecesLibrary(const char* LibPath, const char* LibraryInstallPath, const char* LDrawPath, const char* LibraryCachePath) { if (mLibrary == NULL) diff --git a/common/lc_application.h b/common/lc_application.h index a7dd5892..de95eac3 100644 --- a/common/lc_application.h +++ b/common/lc_application.h @@ -48,8 +48,6 @@ public: bool LoadPiecesLibrary(const char* LibPath, const char* LibraryInstallPath, const char* LDrawPath, const char* LibraryCachePath); - void OpenURL(const char* URL); - void RunProcess(const char* ExecutablePath, const lcArray& Arguments); void GetFileList(const char* Path, lcArray& FileList); void SetClipboard(const QByteArray& Clipboard); void ExportClipboard(const QByteArray& Clipboard); diff --git a/common/lc_file.h b/common/lc_file.h index 4ef92d13..8c8a85c1 100644 --- a/common/lc_file.h +++ b/common/lc_file.h @@ -283,7 +283,7 @@ protected: NumRead = ReadBuffer(Buffer, Count * 2) / 2; -#ifdef LC_BIG_ENDIAN +#if Q_BYTE_ORDER == Q_BIG_ENDIAN lcuint8 Temp[2]; lcuint8* Bytes = (lcuint8*)Buffer; @@ -306,7 +306,7 @@ protected: NumRead = ReadBuffer(Buffer, Count * 4) / 4; -#ifdef LC_BIG_ENDIAN +#if Q_BYTE_ORDER == Q_BIG_ENDIAN lcuint8 Temp[4]; lcuint8* Bytes = (lcuint8*)Buffer; @@ -333,7 +333,7 @@ protected: NumRead = ReadBuffer(Buffer, Count * 8) / 8; -#ifdef LC_BIG_ENDIAN +#if Q_BYTE_ORDER == Q_BIG_ENDIAN lcuint8 Temp[8]; lcuint8* Bytes = (lcuint8*)Buffer; @@ -369,7 +369,7 @@ protected: size_t Write16(const void* Buffer, size_t Count) { -#ifdef LC_BIG_ENDIAN +#if Q_BYTE_ORDER == Q_BIG_ENDIAN size_t BytesWritten = 0; lcuint8 Temp[2]; lcuint8* Bytes = (lcuint8*)Buffer; @@ -390,7 +390,7 @@ protected: size_t Write32(const void* Buffer, size_t Count) { -#ifdef LC_BIG_ENDIAN +#if Q_BYTE_ORDER == Q_BIG_ENDIAN size_t BytesWritten = 0; lcuint8 Temp[4]; lcuint8* Bytes = (lcuint8*)Buffer; @@ -413,7 +413,7 @@ protected: size_t Write64(const void* Buffer, size_t Count) { -#ifdef LC_BIG_ENDIAN +#if Q_BYTE_ORDER == Q_BIG_ENDIAN size_t BytesWritten = 0; lcuint8 Temp[8]; lcuint8* Bytes = (lcuint8*)Buffer; diff --git a/common/lc_global.h b/common/lc_global.h index 7e154e38..2e15bf0a 100644 --- a/common/lc_global.h +++ b/common/lc_global.h @@ -1,7 +1,38 @@ #ifndef _LC_GLOBAL_H_ #define _LC_GLOBAL_H_ -#include "lc_config.h" +#include +#include +#include +#include +#include + +// Old defines and declarations. +#define LC_MAXPATH 1024 + +#define LC_POINTER_TO_INT(p) ((lcint32) (quintptr) (p)) + +typedef qint8 lcint8; +typedef quint8 lcuint8; +typedef qint16 lcint16; +typedef quint16 lcuint16; +typedef qint32 lcint32; +typedef quint32 lcuint32; +typedef qint64 lcint64; +typedef quint64 lcuint64; +typedef quintptr lcuintptr; + +#ifdef Q_OS_WIN +#define snprintf _snprintf +#define isnan _isnan +#define strcasecmp stricmp +#define strncasecmp strnicmp +char* strcasestr(const char *s, const char *find); +#else +char* strupr(char* string); +char* strlwr(char* string); +int stricmp(const char* str1, const char* str2); +#endif // Version number. #define LC_VERSION_MAJOR 0 diff --git a/common/lc_mainwindow.cpp b/common/lc_mainwindow.cpp index 9cbb8d39..1079c52a 100644 --- a/common/lc_mainwindow.cpp +++ b/common/lc_mainwindow.cpp @@ -2140,11 +2140,11 @@ void lcMainWindow::HandleCommand(lcCommandId CommandId) break; case LC_HELP_HOMEPAGE: - g_App->OpenURL("http://www.leocad.org/"); + QDesktopServices::openUrl(QUrl("http://www.leocad.org/")); break; case LC_HELP_EMAIL: - g_App->OpenURL("mailto:leozide@gmail.com?subject=LeoCAD"); + QDesktopServices::openUrl(QUrl("mailto:leozide@gmail.com?subject=LeoCAD")); break; case LC_HELP_UPDATES: diff --git a/common/project.cpp b/common/project.cpp index 223e0351..ac3d1d81 100644 --- a/common/project.cpp +++ b/common/project.cpp @@ -1521,18 +1521,18 @@ void Project::ExportPOVRay() if (Options.Render) { - lcArray Arguments; + QStringList Arguments; char Argument[LC_MAXPATH + 32]; sprintf(Argument, "+I%s", Options.FileName); - Arguments.Add(Argument); + Arguments.append(Argument); if (Options.LGEOPath[0]) { sprintf(Argument, "+L%slg/", Options.LGEOPath); - Arguments.Add(Argument); + Arguments.append(Argument); sprintf(Argument, "+L%sar/", Options.LGEOPath); - Arguments.Add(Argument); + Arguments.append(Argument); } sprintf(Argument, "+o%s", Options.FileName); @@ -1545,10 +1545,10 @@ void Project::ExportPOVRay() else *(Slash2 + 1) = 0; - Arguments.Add(Argument); + Arguments.append(Argument); } - g_App->RunProcess(Options.POVRayPath, Arguments); + QProcess::execute(Options.POVRayPath, Arguments); } } diff --git a/leocad.pro b/leocad.pro index c9abbeaf..553f0119 100644 --- a/leocad.pro +++ b/leocad.pro @@ -161,7 +161,6 @@ SOURCES += common/view.cpp \ qt/lc_qpreferencesdialog.cpp \ qt/lc_qcategorydialog.cpp \ qt/lc_qimagedialog.cpp \ - qt/lc_qapplication.cpp \ qt/lc_qupdatedialog.cpp \ qt/lc_qutils.cpp \ qt/lc_qpropertiestree.cpp \ @@ -207,7 +206,6 @@ HEADERS += \ common/group.h \ common/debug.h \ common/camera.h \ - qt/lc_config.h \ qt/lc_qpovraydialog.h \ qt/lc_qarraydialog.h \ qt/lc_qgroupdialog.h \ diff --git a/qt/lc_config.h b/qt/lc_config.h deleted file mode 100644 index 1f2ddecb..00000000 --- a/qt/lc_config.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef _LC_CONFIG_H_ -#define _LC_CONFIG_H_ - -#include -#include -#include -#include -#include - -#define LC_MAXPATH 1024 - -#define LC_POINTER_TO_INT(p) ((lcint32) (quintptr) (p)) - -typedef qint8 lcint8; -typedef quint8 lcuint8; -typedef qint16 lcint16; -typedef quint16 lcuint16; -typedef qint32 lcint32; -typedef quint32 lcuint32; -typedef qint64 lcint64; -typedef quint64 lcuint64; -typedef quintptr lcuintptr; - -#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN -#define LC_LITTLE_ENDIAN -#else -#define LC_BIG_ENDIAN -#endif - -#ifdef Q_OS_WIN -#define snprintf _snprintf -#define isnan _isnan -#define strcasecmp stricmp -#define strncasecmp strnicmp -char* strcasestr(const char *s, const char *find); -#else -char* strupr(char* string); -char* strlwr(char* string); -int stricmp(const char* str1, const char* str2); -#endif - -#endif // _LC_CONFIG_H_ diff --git a/qt/lc_qapplication.cpp b/qt/lc_qapplication.cpp deleted file mode 100644 index fba2de65..00000000 --- a/qt/lc_qapplication.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "lc_global.h" -#include "lc_application.h" -#include "lc_file.h" - -void lcApplication::OpenURL(const char* URL) -{ - QDesktopServices::openUrl(QUrl(URL)); -} - -void lcApplication::RunProcess(const char* ExecutablePath, const lcArray& Arguments) -{ - QStringList argumentList; - - for (int argIdx = 0; argIdx < Arguments.GetSize(); argIdx++) - argumentList << (const char*)Arguments[argIdx]; - - QProcess::execute(ExecutablePath, argumentList); -} - -void lcApplication::ExportClipboard(const QByteArray& Clipboard) -{ - QMimeData *mimeData = new QMimeData(); - - mimeData->setData("application/vnd.leocad-clipboard", Clipboard); - QApplication::clipboard()->setMimeData(mimeData); - - SetClipboard(Clipboard); -} - -void lcApplication::GetFileList(const char* Path, lcArray& FileList) -{ - QDir dir(Path); - dir.setFilter(QDir::Files | QDir::Hidden | QDir::Readable); - - FileList.RemoveAll(); - QStringList files = dir.entryList(); - - for (int fileIdx = 0; fileIdx < files.size(); fileIdx++) - { - QString absolutePath = dir.absoluteFilePath(files[fileIdx]); - - FileList.Add(absolutePath.toLocal8Bit().data()); - } -}