diff --git a/RedPandaIDE/RedPandaIDE.pro b/RedPandaIDE/RedPandaIDE.pro index 06ad8177..8e6c38d1 100644 --- a/RedPandaIDE/RedPandaIDE.pro +++ b/RedPandaIDE/RedPandaIDE.pro @@ -52,7 +52,19 @@ msvc { # In order to do so, uncomment the following line. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +CONFIG(debug_and_release_target): { + CONFIG(debug): { + OBJ_OUT_PWD = debug + } + CONFIG(release): { + OBJ_OUT_PWD = release + } +} INCLUDEPATH += ../libs/qsynedit ../libs/redpanda_qt_utils +LIBS += -L$$OUT_PWD/../libs/redpanda_qt_utils/$$OBJ_OUT_PWD \ + -L$$OUT_PWD/../libs/qsynedit/$$OBJ_OUT_PWD \ + -lqsynedit -lredpanda_qt_utils SOURCES += \ HighlighterManager.cpp \ diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 6a4cb563..3f993f80 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -50,6 +50,7 @@ #include "editorlist.h" #include #include "project.h" +#include using namespace std; @@ -1372,7 +1373,7 @@ void Editor::copyAsHTML() { if (!selAvail()) return; - QSynedit::SynHTMLExporter exporter(tabWidth()); + QSynedit::SynHTMLExporter exporter(tabWidth(), pCharsetInfoManager->getDefaultSystemEncoding()); exporter.setTitle(QFileInfo(mFilename).fileName()); exporter.setExportAsText(false); @@ -2837,7 +2838,7 @@ void Editor::print() void Editor::exportAsRTF(const QString &rtfFilename) { - QSynedit::SynRTFExporter exporter; + QSynedit::SynRTFExporter exporter(pCharsetInfoManager->getDefaultSystemEncoding()); exporter.setTitle(extractFileName(rtfFilename)); exporter.setExportAsText(true); exporter.setUseBackground(pSettings->editor().copyRTFUseBackground()); @@ -2862,7 +2863,7 @@ void Editor::exportAsRTF(const QString &rtfFilename) void Editor::exportAsHTML(const QString &htmlFilename) { - QSynedit::SynHTMLExporter exporter(tabWidth()); + QSynedit::SynHTMLExporter exporter(tabWidth(), pCharsetInfoManager->getDefaultSystemEncoding()); exporter.setTitle(extractFileName(htmlFilename)); exporter.setExportAsText(false); exporter.setUseBackground(pSettings->editor().copyHTMLUseBackground()); diff --git a/RedPandaIDE/main.cpp b/RedPandaIDE/main.cpp index de3af472..1204a45e 100644 --- a/RedPandaIDE/main.cpp +++ b/RedPandaIDE/main.cpp @@ -32,7 +32,7 @@ #include "colorscheme.h" #include "iconsmanager.h" #include "autolinkmanager.h" -#include "platform.h" +#include #include "parser/parserutils.h" #include "editorlist.h" #include "widgets/choosethemedialog.h" diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 6cc4ceda..c26ed3ba 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -27,7 +27,7 @@ #include "project.h" #include "projecttemplate.h" #include "widgets/newprojectdialog.h" -#include "platform.h" +#include #include "widgets/aboutdialog.h" #include "shortcutmanager.h" #include "colorscheme.h" diff --git a/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp b/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp index db1fb1c3..05a380df 100644 --- a/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp +++ b/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp @@ -22,7 +22,7 @@ #include #include "../utils.h" #include "../iconsmanager.h" -#include "../platform.h" +#include #include #include #include diff --git a/RedPandaIDE/settingsdialog/projectcompilerwidget.cpp b/RedPandaIDE/settingsdialog/projectcompilerwidget.cpp index c0f7022b..12b57ed6 100644 --- a/RedPandaIDE/settingsdialog/projectcompilerwidget.cpp +++ b/RedPandaIDE/settingsdialog/projectcompilerwidget.cpp @@ -19,7 +19,7 @@ #include "../settings.h" #include "../project.h" #include "../mainwindow.h" -#include "../platform.h" +#include ProjectCompilerWidget::ProjectCompilerWidget(const QString &name, const QString &group, QWidget *parent) : SettingsWidget(name,group,parent), diff --git a/RedPandaIDE/settingsdialog/projectfileswidget.cpp b/RedPandaIDE/settingsdialog/projectfileswidget.cpp index 2eca269f..3039b698 100644 --- a/RedPandaIDE/settingsdialog/projectfileswidget.cpp +++ b/RedPandaIDE/settingsdialog/projectfileswidget.cpp @@ -18,7 +18,7 @@ #include "ui_projectfileswidget.h" #include "../mainwindow.h" #include "../systemconsts.h" -#include "../platform.h" +#include ProjectFilesWidget::ProjectFilesWidget(const QString &name, const QString &group, QWidget *parent) : SettingsWidget(name,group,parent), diff --git a/RedPandaIDE/utils.cpp b/RedPandaIDE/utils.cpp index 141987db..6688be85 100644 --- a/RedPandaIDE/utils.cpp +++ b/RedPandaIDE/utils.cpp @@ -2,12 +2,14 @@ #include "systemconsts.h" #include #include +#include #include "editor.h" #include "editorlist.h" #include "settings.h" #include "mainwindow.h" #include "project.h" #include "parser/cppparser.h" +#include "compiler/executablerunner.h" #ifdef Q_OS_WIN #include #include @@ -355,3 +357,167 @@ int getNewFileNumber() count++; return count; } + +#ifdef Q_OS_WIN +static bool gIsGreenEdition = true; +static bool gIsGreenEditionInited = false; +#endif +bool isGreenEdition() +{ +#ifdef Q_OS_WIN + if (!gIsGreenEditionInited) { + QString keyString = QString("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\RedPanda-C++"); + QString value; + if (!readRegistry(HKEY_LOCAL_MACHINE,keyString.toLocal8Bit(),"UninstallString",value)) { + keyString = "SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\RedPanda-C++"; + if (!readRegistry(HKEY_LOCAL_MACHINE,keyString.toLocal8Bit(),"UninstallString",value)) { + value=""; + } + } + if (!value.isEmpty()) { + QString regPath = extractFileDir(value); + + QString appPath = QApplication::instance()->applicationDirPath(); + gIsGreenEdition = excludeTrailingPathDelimiter(regPath).compare(excludeTrailingPathDelimiter(appPath), + Qt::CaseInsensitive)!=0; + } + gIsGreenEditionInited = true; + } + return gIsGreenEdition; +#else + return false; +#endif +} + +QByteArray runAndGetOutput(const QString &cmd, const QString& workingDir, const QStringList& arguments, + const QByteArray &inputContent, bool inheritEnvironment, + const QProcessEnvironment& env) +{ + QProcess process; + QByteArray result; + if (env.isEmpty()) { + if (inheritEnvironment) { + process.setProcessEnvironment(QProcessEnvironment::systemEnvironment()); + } else { + process.setProcessEnvironment(QProcessEnvironment()); + } + } else { + process.setProcessEnvironment(env); + } + process.setWorkingDirectory(workingDir); + process.connect(&process,&QProcess::readyReadStandardError, + [&](){ + result.append(process.readAllStandardError()); + }); + process.connect(&process,&QProcess::readyReadStandardOutput, + [&](){ + result.append(process.readAllStandardOutput()); + }); + process.start(cmd,arguments); + if (!inputContent.isEmpty()) { + process.write(inputContent); + } + process.closeWriteChannel(); + process.waitForFinished(); + return result; +} + +void executeFile(const QString &fileName, const QString ¶ms, const QString &workingDir, const QString &tempFile) +{ + ExecutableRunner* runner=new ExecutableRunner( + fileName, + params, + workingDir); + runner->connect(runner, &QThread::finished, + [runner,tempFile](){ + if (!tempFile.isEmpty()) { + QFile::remove(tempFile); + } + runner->deleteLater(); + }); + runner->connect(runner, &Runner::runErrorOccurred, + [](const QString&){ + //todo + }); + runner->setStartConsole(true); + runner->start(); +} + +#ifdef Q_OS_WIN +bool readRegistry(HKEY key,const QByteArray& subKey, const QByteArray& name, QString& value) { + DWORD dataSize; + LONG result; + result = RegGetValueA(key,subKey, + name, RRF_RT_REG_SZ | RRF_RT_REG_MULTI_SZ, + NULL, + NULL, + &dataSize); + if (result!=ERROR_SUCCESS) + return false; + char * buffer = new char[dataSize+10]; + result = RegGetValueA(key,subKey, + name, RRF_RT_REG_SZ | RRF_RT_REG_MULTI_SZ, + NULL, + buffer, + &dataSize); + if (result!=ERROR_SUCCESS) { + delete[] buffer; + return false; + } + value=QString::fromLocal8Bit(buffer); + delete [] buffer; + return true; +} +#endif + +qulonglong stringToHex(const QString &str, bool &isOk) +{ + qulonglong value = str.toULongLong(&isOk,16); + return value; +} + +bool findComplement(const QString &s, const QChar &fromToken, const QChar &toToken, int &curPos, int increment) +{ + int curPosBackup = curPos; + int level = 0; + //todo: skip comment, char and strings + while ((curPos < s.length()) && (curPos >= 0)) { + if (s[curPos] == fromToken) { + level++; + } else if (s[curPos] == toToken) { + level--; + if (level == 0) + return true; + } + curPos += increment; + } + curPos = curPosBackup; + return false; +} + +bool haveGoodContrast(const QColor& c1, const QColor &c2) { + int lightness1 = qGray(c1.rgb()); + int lightness2 = qGray(c2.rgb()); + return std::abs(lightness1 - lightness2)>=120; +} + +QByteArray getHTTPBody(const QByteArray& content) { + int i= content.indexOf("\r\n\r\n"); + if (i>=0) { + return content.mid(i+4); + } + return ""; +} + +QString getSizeString(int size) +{ + if (size < 1024) { + return QString("%1 ").arg(size)+QObject::tr("bytes"); + } else if (size < 1024 * 1024) { + return QString("%1 ").arg(size / 1024.0)+QObject::tr("KB"); + } else if (size < 1024 * 1024 * 1024) { + return QString("%1 ").arg(size / 1024.0 / 1024.0)+QObject::tr("MB"); + } else { + return QString("%1 ").arg(size / 1024.0 / 1024.0 / 1024.0)+QObject::tr("GB"); + } +} diff --git a/RedPandaIDE/utils.h b/RedPandaIDE/utils.h index a21f158a..023bda2b 100644 --- a/RedPandaIDE/utils.h +++ b/RedPandaIDE/utils.h @@ -114,4 +114,34 @@ void resetCppParser(std::shared_ptr parser, int compilerSetIndex=-1); int getNewFileNumber(); +QByteArray runAndGetOutput(const QString& cmd, const QString& workingDir, const QStringList& arguments, + const QByteArray& inputContent = QByteArray(), + bool inheritEnvironment = false, + const QProcessEnvironment& env = QProcessEnvironment() ); + +void executeFile(const QString& fileName, + const QString& params, + const QString& workingDir, + const QString& tempFile); + +bool isGreenEdition(); + +#ifdef Q_OS_WIN +bool readRegistry(HKEY key,const QByteArray& subKey, const QByteArray& name, QString& value); +#endif + +qulonglong stringToHex(const QString& str, bool &isOk); + +bool findComplement(const QString& s, + const QChar& fromToken, + const QChar& toToken, + int& curPos, + int increment); + +bool haveGoodContrast(const QColor& c1, const QColor &c2); + +QByteArray getHTTPBody(const QByteArray& content); + +QString getSizeString(int size); + #endif // UTILS_H diff --git a/RedPandaIDE/widgets/filepropertiesdialog.cpp b/RedPandaIDE/widgets/filepropertiesdialog.cpp index 92f58278..1f687452 100644 --- a/RedPandaIDE/widgets/filepropertiesdialog.cpp +++ b/RedPandaIDE/widgets/filepropertiesdialog.cpp @@ -19,7 +19,7 @@ #include "../mainwindow.h" #include "../editorlist.h" #include "../editor.h" -#include "../qsynedit/Constants.h" +#include #include diff --git a/RedPandaIDE/widgets/searchdialog.cpp b/RedPandaIDE/widgets/searchdialog.cpp index 9ed5fcc2..ab591336 100644 --- a/RedPandaIDE/widgets/searchdialog.cpp +++ b/RedPandaIDE/widgets/searchdialog.cpp @@ -20,8 +20,8 @@ #include "../editor.h" #include "../mainwindow.h" #include "../editorlist.h" -#include "../qsynedit/Search.h" -#include "../qsynedit/SearchRegex.h" +#include +#include #include "../project.h" #include "../settings.h" #include diff --git a/RedPandaIDE/widgets/searchdialog.h b/RedPandaIDE/widgets/searchdialog.h index 98e1a02c..e3200bc3 100644 --- a/RedPandaIDE/widgets/searchdialog.h +++ b/RedPandaIDE/widgets/searchdialog.h @@ -18,7 +18,7 @@ #define SEARCHDIALOG_H #include -#include "../qsynedit/SynEdit.h" +#include #include "../utils.h" namespace Ui { diff --git a/libs/redpanda_qt_utils/qt_utils/utils.cpp b/libs/redpanda_qt_utils/qt_utils/utils.cpp index f8c88ca0..3180b766 100644 --- a/libs/redpanda_qt_utils/qt_utils/utils.cpp +++ b/libs/redpanda_qt_utils/qt_utils/utils.cpp @@ -37,6 +37,28 @@ #include #endif +BaseError::BaseError(const QString &reason): +mReason(reason) +{ + +} + +QString BaseError::reason() const +{ + return mReason; +} + +IndexOutOfRange::IndexOutOfRange(int Index): +BaseError(QObject::tr("Index %1 out of range").arg(Index)) +{ + +} + +FileError::FileError(const QString &reason): BaseError(reason) +{ + +} + const QByteArray guessTextEncoding(const QByteArray& text){ bool allAscii; int ii; @@ -606,5 +628,23 @@ float pixelToPoint(float pixel) } - - +void decodeKey(const int combinedKey, int &key, Qt::KeyboardModifiers &modifiers) +{ + modifiers = Qt::NoModifier; + if (combinedKey & Qt::ShiftModifier) { + modifiers|=Qt::ShiftModifier; + } + if (combinedKey & Qt::ControlModifier) { + modifiers|=Qt::ControlModifier; + } + if (combinedKey & Qt::AltModifier) { + modifiers|=Qt::AltModifier; + } + if (combinedKey & Qt::MetaModifier) { + modifiers|=Qt::MetaModifier; + } + if (combinedKey & Qt::KeypadModifier) { + modifiers|= Qt::KeypadModifier; + } + key = combinedKey & ~(Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier | Qt::KeypadModifier); +}