work done: make qsynedit a standalone module
This commit is contained in:
parent
15bbf15d38
commit
ebf78dbecb
|
@ -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 \
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
#include "editorlist.h"
|
||||
#include <QDebug>
|
||||
#include "project.h"
|
||||
#include <qt_utils/charsetinfo.h>
|
||||
|
||||
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());
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#include "colorscheme.h"
|
||||
#include "iconsmanager.h"
|
||||
#include "autolinkmanager.h"
|
||||
#include "platform.h"
|
||||
#include <qt_utils/charsetinfo.h>
|
||||
#include "parser/parserutils.h"
|
||||
#include "editorlist.h"
|
||||
#include "widgets/choosethemedialog.h"
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include "project.h"
|
||||
#include "projecttemplate.h"
|
||||
#include "widgets/newprojectdialog.h"
|
||||
#include "platform.h"
|
||||
#include <qt_utils/charsetinfo.h>
|
||||
#include "widgets/aboutdialog.h"
|
||||
#include "shortcutmanager.h"
|
||||
#include "colorscheme.h"
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include <QMessageBox>
|
||||
#include "../utils.h"
|
||||
#include "../iconsmanager.h"
|
||||
#include "../platform.h"
|
||||
#include <qt_utils/charsetinfo.h>
|
||||
#include <QDebug>
|
||||
#include <QFileDialog>
|
||||
#include <QInputDialog>
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "../settings.h"
|
||||
#include "../project.h"
|
||||
#include "../mainwindow.h"
|
||||
#include "../platform.h"
|
||||
#include <qt_utils/charsetinfo.h>
|
||||
|
||||
ProjectCompilerWidget::ProjectCompilerWidget(const QString &name, const QString &group, QWidget *parent) :
|
||||
SettingsWidget(name,group,parent),
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include "ui_projectfileswidget.h"
|
||||
#include "../mainwindow.h"
|
||||
#include "../systemconsts.h"
|
||||
#include "../platform.h"
|
||||
#include <qt_utils/charsetinfo.h>
|
||||
|
||||
ProjectFilesWidget::ProjectFilesWidget(const QString &name, const QString &group, QWidget *parent) :
|
||||
SettingsWidget(name,group,parent),
|
||||
|
|
|
@ -2,12 +2,14 @@
|
|||
#include "systemconsts.h"
|
||||
#include <QDate>
|
||||
#include <QDateTime>
|
||||
#include <QApplication>
|
||||
#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 <QMimeDatabase>
|
||||
#include <windows.h>
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -114,4 +114,34 @@ void resetCppParser(std::shared_ptr<CppParser> 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
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "../mainwindow.h"
|
||||
#include "../editorlist.h"
|
||||
#include "../editor.h"
|
||||
#include "../qsynedit/Constants.h"
|
||||
#include <qsynedit/Constants.h>
|
||||
|
||||
#include <QFileInfo>
|
||||
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
#include "../editor.h"
|
||||
#include "../mainwindow.h"
|
||||
#include "../editorlist.h"
|
||||
#include "../qsynedit/Search.h"
|
||||
#include "../qsynedit/SearchRegex.h"
|
||||
#include <qsynedit/Search.h>
|
||||
#include <qsynedit/SearchRegex.h>
|
||||
#include "../project.h"
|
||||
#include "../settings.h"
|
||||
#include <QMessageBox>
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#define SEARCHDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include "../qsynedit/SynEdit.h"
|
||||
#include <qsynedit/SynEdit.h>
|
||||
#include "../utils.h"
|
||||
|
||||
namespace Ui {
|
||||
|
|
|
@ -37,6 +37,28 @@
|
|||
#include <windows.h>
|
||||
#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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue