Merge branch 'master' of github.com:royqh1979/RedPanda-CPP

This commit is contained in:
royqh1979@gmail.com 2022-09-29 22:28:04 +08:00
commit e22f3f0684
307 changed files with 3871 additions and 3545 deletions

Binary file not shown.

19
NEWS.md
View File

@ -1,3 +1,22 @@
Red Panda C++ Version 1.4
- fix: "Encode in UTF-8" is not correctly checked, when the editor is openned using UTF-8 encoding.
- fix: crash when create non C/C++ source file in project
- fix: can't open text project file in the editor
- change: when create non-text project file, don't auto open it
- fix: the project compiler options is not correctly read when open old dev-c++ project
- fix: astyle.exe can't correctly format files that using non-ascii identifier
- fix: when "cleary symbol table of hidden editors" is turned on, content in the editor reshown is not correctly parsed
Red Panda C++ Version 1.3
- enhancement: don't parse all openned files when start up
- enhancement: don't parse files when close all and exit
- change: reduce time intervals for selection by mouse
- enhancement: change orders of the problems in the problem set panel by drag&drop
- enhancement: change orders of the problem cases in the problem panel by drag&drop
- fix: the size of horizontal caret is wrong
Red Panda C++ Version 1.2
- enhancement: Portuguese Translation ( Thanks for crcpucmg@github)

View File

@ -30,7 +30,7 @@ HighlighterManager::HighlighterManager()
}
PSynHighlighter HighlighterManager::getHighlighter(const QString &filename)
QSynedit::PHighlighter HighlighterManager::getHighlighter(const QString &filename)
{
QFileInfo info(filename);
QString suffix = info.suffix();
@ -43,26 +43,30 @@ PSynHighlighter HighlighterManager::getHighlighter(const QString &filename)
} else if (suffix == "vs" || suffix == "fs" || suffix == "frag") {
return getGLSLHighlighter();
}
return PSynHighlighter();
return QSynedit::PHighlighter();
}
PSynHighlighter HighlighterManager::copyHighlighter(PSynHighlighter highlighter)
QSynedit::PHighlighter HighlighterManager::copyHighlighter(QSynedit::PHighlighter highlighter)
{
if (!highlighter)
return PSynHighlighter();
return QSynedit::PHighlighter();
if (highlighter->getName() == SYN_HIGHLIGHTER_CPP)
return getCppHighlighter();
else if (highlighter->getName() == SYN_HIGHLIGHTER_ASM)
return getAsmHighlighter();
else if (highlighter->getName() == SYN_HIGHLIGHTER_GLSL)
return getGLSLHighlighter();
//todo
return PSynHighlighter();
return QSynedit::PHighlighter();
}
PSynHighlighter HighlighterManager::getCppHighlighter()
QSynedit::PHighlighter HighlighterManager::getCppHighlighter()
{
SynEditCppHighlighter* highlighter = new SynEditCppHighlighter();
QSynedit::CppHighlighter* highlighter = new QSynedit::CppHighlighter();
highlighter->asmAttribute()->setForeground(Qt::blue);
highlighter->charAttribute()->setForeground(Qt::black);
highlighter->commentAttribute()->setForeground(0x8C8C8C);
highlighter->commentAttribute()->setStyles(SynFontStyle::fsItalic);
highlighter->commentAttribute()->setStyles(QSynedit::FontStyle::fsItalic);
highlighter->classAttribute()->setForeground(0x008080);
highlighter->floatAttribute()->setForeground(Qt::darkMagenta);
highlighter->functionAttribute()->setForeground(0x00627A);
@ -80,16 +84,16 @@ PSynHighlighter HighlighterManager::getCppHighlighter()
highlighter->stringEscapeSequenceAttribute()->setForeground(Qt::red);
highlighter->symbolAttribute()->setForeground(0xc10000);
highlighter->variableAttribute()->setForeground(0x400080);
PSynHighlighter pHighlighter=std::make_shared<SynEditCppHighlighter>();
QSynedit::PHighlighter pHighlighter=std::make_shared<QSynedit::CppHighlighter>();
return pHighlighter;
}
PSynHighlighter HighlighterManager::getAsmHighlighter()
QSynedit::PHighlighter HighlighterManager::getAsmHighlighter()
{
SynEditASMHighlighter* highlighter = new SynEditASMHighlighter();
PSynHighlighter pHighlighter(highlighter);
QSynedit::ASMHighlighter* highlighter = new QSynedit::ASMHighlighter();
QSynedit::PHighlighter pHighlighter(highlighter);
highlighter->commentAttribute()->setForeground(0x8C8C8C);
highlighter->commentAttribute()->setStyles(SynFontStyle::fsItalic);
highlighter->commentAttribute()->setStyles(QSynedit::FontStyle::fsItalic);
highlighter->identifierAttribute()->setForeground(0x080808);
highlighter->keywordAttribute()->setForeground(0x0033b3);
highlighter->numberAttribute()->setForeground(0x1750EB);
@ -99,14 +103,14 @@ PSynHighlighter HighlighterManager::getAsmHighlighter()
return pHighlighter;
}
PSynHighlighter HighlighterManager::getGLSLHighlighter()
QSynedit::PHighlighter HighlighterManager::getGLSLHighlighter()
{
SynEditGLSLHighlighter* highlighter = new SynEditGLSLHighlighter();
PSynHighlighter pHighlighter(highlighter);
QSynedit::GLSLHighlighter* highlighter = new QSynedit::GLSLHighlighter();
QSynedit::PHighlighter pHighlighter(highlighter);
highlighter->asmAttribute()->setForeground(Qt::blue);
highlighter->charAttribute()->setForeground(Qt::black);
highlighter->commentAttribute()->setForeground(0x8C8C8C);
highlighter->commentAttribute()->setStyles(SynFontStyle::fsItalic);
highlighter->commentAttribute()->setStyles(QSynedit::FontStyle::fsItalic);
highlighter->classAttribute()->setForeground(0x008080);
highlighter->floatAttribute()->setForeground(Qt::darkMagenta);
highlighter->functionAttribute()->setForeground(0x00627A);
@ -127,7 +131,7 @@ PSynHighlighter HighlighterManager::getGLSLHighlighter()
return pHighlighter;
}
void HighlighterManager::applyColorScheme(PSynHighlighter highlighter, const QString &schemeName)
void HighlighterManager::applyColorScheme(QSynedit::PHighlighter highlighter, const QString &schemeName)
{
if (!highlighter)
return;
@ -137,14 +141,14 @@ void HighlighterManager::applyColorScheme(PSynHighlighter highlighter, const QSt
for (QString name: highlighter->attributes().keys()) {
PColorSchemeItem item = pColorManager->getItem(schemeName,name);
if (item) {
PSynHighlighterAttribute attr = highlighter->attributes()[name];
QSynedit::PHighlighterAttribute attr = highlighter->attributes()[name];
attr->setBackground(item->background());
attr->setForeground(item->foreground());
SynFontStyles styles = SynFontStyle::fsNone;
styles.setFlag(SynFontStyle::fsBold, item->bold());
styles.setFlag(SynFontStyle::fsItalic, item->italic());
styles.setFlag(SynFontStyle::fsUnderline, item->underlined());
styles.setFlag(SynFontStyle::fsStrikeOut, item->strikeout());
QSynedit::FontStyles styles = QSynedit::FontStyle::fsNone;
styles.setFlag(QSynedit::FontStyle::fsBold, item->bold());
styles.setFlag(QSynedit::FontStyle::fsItalic, item->italic());
styles.setFlag(QSynedit::FontStyle::fsUnderline, item->underlined());
styles.setFlag(QSynedit::FontStyle::fsStrikeOut, item->strikeout());
attr->setStyles(styles);
}
}

View File

@ -23,12 +23,12 @@ class HighlighterManager
public:
HighlighterManager();
PSynHighlighter getHighlighter(const QString& filename);
PSynHighlighter copyHighlighter(PSynHighlighter highlighter);
PSynHighlighter getCppHighlighter();
PSynHighlighter getAsmHighlighter();
PSynHighlighter getGLSLHighlighter();
void applyColorScheme(PSynHighlighter highlighter, const QString& schemeName);
QSynedit::PHighlighter getHighlighter(const QString& filename);
QSynedit::PHighlighter copyHighlighter(QSynedit::PHighlighter highlighter);
QSynedit::PHighlighter getCppHighlighter();
QSynedit::PHighlighter getAsmHighlighter();
QSynedit::PHighlighter getGLSLHighlighter();
void applyColorScheme(QSynedit::PHighlighter highlighter, const QString& schemeName);
};
extern HighlighterManager highlighterManager;

View File

@ -10,7 +10,7 @@ isEmpty(APP_NAME) {
}
isEmpty(APP_VERSION) {
APP_VERSION=1.2
APP_VERSION=1.4
}
macos: {
@ -52,6 +52,21 @@ 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, debug|release) {
OBJ_OUT_PWD = debug
}
CONFIG(release, debug|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 \
autolinkmanager.cpp \
@ -65,7 +80,6 @@ SOURCES += \
compiler/runner.cpp \
customfileiconprovider.cpp \
gdbmiresultparser.cpp \
platform.cpp \
compiler/compiler.cpp \
compiler/compilermanager.cpp \
compiler/executablerunner.cpp \
@ -82,10 +96,6 @@ SOURCES += \
project.cpp \
projectoptions.cpp \
projecttemplate.cpp \
qsynedit/Search.cpp \
qsynedit/SearchBase.cpp \
qsynedit/SearchRegex.cpp \
qsynedit/Types.cpp \
settingsdialog/compilerautolinkwidget.cpp \
settingsdialog/debuggeneralwidget.cpp \
settingsdialog/editorautosavewidget.cpp \
@ -139,22 +149,6 @@ SOURCES += \
iconsmanager.cpp \
main.cpp \
mainwindow.cpp \
qsynedit/CodeFolding.cpp \
qsynedit/Constants.cpp \
qsynedit/KeyStrokes.cpp \
qsynedit/MiscClasses.cpp \
qsynedit/MiscProcs.cpp \
qsynedit/SynEdit.cpp \
qsynedit/TextBuffer.cpp \
qsynedit/TextPainter.cpp \
qsynedit/exporter/synexporter.cpp \
qsynedit/exporter/synhtmlexporter.cpp \
qsynedit/exporter/synrtfexporter.cpp \
qsynedit/highlighter/asm.cpp \
qsynedit/highlighter/base.cpp \
qsynedit/highlighter/composition.cpp \
qsynedit/highlighter/cpp.cpp \
qsynedit/highlighter/glsl.cpp \
settingsdialog/compilersetdirectorieswidget.cpp \
settingsdialog/compilersetoptionwidget.cpp \
settings.cpp \
@ -227,15 +221,11 @@ HEADERS += \
parser/cpptokenizer.h \
parser/parserutils.h \
parser/statementmodel.h \
platform.h \
problems/ojproblemset.h \
problems/problemcasevalidator.h \
project.h \
projectoptions.h \
projecttemplate.h \
qsynedit/Search.h \
qsynedit/SearchBase.h \
qsynedit/SearchRegex.h \
settingsdialog/compilerautolinkwidget.h \
settingsdialog/debuggeneralwidget.h \
settingsdialog/editorautosavewidget.h \
@ -288,23 +278,6 @@ HEADERS += \
editorlist.h \
iconsmanager.h \
mainwindow.h \
qsynedit/CodeFolding.h \
qsynedit/Constants.h \
qsynedit/KeyStrokes.h \
qsynedit/MiscClasses.h \
qsynedit/MiscProcs.h \
qsynedit/SynEdit.h \
qsynedit/TextBuffer.h \
qsynedit/TextPainter.h \
qsynedit/Types.h \
qsynedit/exporter/synexporter.h \
qsynedit/exporter/synhtmlexporter.h \
qsynedit/exporter/synrtfexporter.h \
qsynedit/highlighter/asm.h \
qsynedit/highlighter/base.h \
qsynedit/highlighter/composition.h \
qsynedit/highlighter/cpp.h \
qsynedit/highlighter/glsl.h \
settingsdialog/compilersetdirectorieswidget.h \
settingsdialog/compilersetoptionwidget.h \
settings.h \
@ -515,9 +488,9 @@ RESOURCES += colorscheme_files
macos: {
# Add needed executables into the main app bundle
bundled_executable.files = \
$$OUT_PWD/../astyle/astyle \
$$OUT_PWD/../consolepauser/consolepauser \
$$OUT_PWD/../redpanda-git-askpass/redpanda-git-askpass.app/Contents/MacOS/redpanda-git-askpass
$$OUT_PWD/../tools/astyle/astyle \
$$OUT_PWD/../tools/consolepauser/consolepauser \
$$OUT_PWD/../tools/redpanda-git-askpass/redpanda-git-askpass.app/Contents/MacOS/redpanda-git-askpass
bundled_executable.path = Contents/MacOS
# Also bundled templates

View File

@ -30,7 +30,7 @@
#include "../editorlist.h"
#include "../parser/cppparser.h"
#include "../autolinkmanager.h"
#include "../platform.h"
#include "qt_utils/charsetinfo.h"
#include "../project.h"
#define COMPILE_PROCESS_END "---//END//----"
@ -352,6 +352,7 @@ QString Compiler::getCharsetArgument(const QByteArray& encoding,FileType fileTyp
} else {
execEncodingName = compilerSetExecCharset;
}
qDebug()<<encodingName<<execEncodingName;
if (checkSyntax) {
result += QString(" -finput-charset=%1")
.arg(encodingName);

View File

@ -25,7 +25,7 @@
#include <QMessageBox>
#include <QUuid>
#include "projectcompiler.h"
#include "../platform.h"
#include "qt_utils/charsetinfo.h"
enum RunProgramFlag {
RPF_PAUSE_CONSOLE = 0x0001,

View File

@ -18,7 +18,7 @@
#include "../project.h"
#include "compilermanager.h"
#include "../systemconsts.h"
#include "../platform.h"
#include "qt_utils/charsetinfo.h"
#include "../editor.h"
#include <QDir>

View File

@ -19,6 +19,7 @@
#include "compiler.h"
#include <QObject>
#include <QFile>
class Project;
class ProjectCompiler : public Compiler

View File

@ -19,7 +19,7 @@
#include <QFile>
#include <QFileInfo>
#include <QTextCodec>
#include "../platform.h"
#include "qt_utils/charsetinfo.h"
StdinCompiler::StdinCompiler(const QString &filename,const QByteArray& encoding, const QString& content,bool silent, bool onlyCheckSyntax):
Compiler(filename,silent, onlyCheckSyntax),

View File

@ -30,7 +30,7 @@ CppRefacter::CppRefacter(QObject *parent) : QObject(parent)
}
bool CppRefacter::findOccurence(Editor *editor, const BufferCoord &pos)
bool CppRefacter::findOccurence(Editor *editor, const QSynedit::BufferCoord &pos)
{
if (!editor->parser())
return false;
@ -106,7 +106,7 @@ static QString fullParentName(PStatement statement) {
return "";
}
}
void CppRefacter::renameSymbol(Editor *editor, const BufferCoord &pos, const QString &newWord)
void CppRefacter::renameSymbol(Editor *editor, const QSynedit::BufferCoord &pos, const QString &newWord)
{
if (!editor->parser()->freeze())
return;
@ -117,7 +117,7 @@ void CppRefacter::renameSymbol(Editor *editor, const BufferCoord &pos, const QSt
QStringList expression;
QChar s=editor->charAt(pos);
if (!editor->isIdentChar(s)) {
expression = editor->getExpressionAtPosition(BufferCoord{pos.ch-1,pos.line});
expression = editor->getExpressionAtPosition(QSynedit::BufferCoord{pos.ch-1,pos.line});
} else {
expression = editor->getExpressionAtPosition(pos);
}
@ -226,11 +226,11 @@ PSearchResultTreeItem CppRefacter::findOccurenceInFile(
while (!editor.highlighter()->eol()) {
int start = editor.highlighter()->getTokenPos() + 1;
QString token = editor.highlighter()->getToken();
PSynHighlighterAttribute attr = editor.highlighter()->getTokenAttribute();
QSynedit::PHighlighterAttribute attr = editor.highlighter()->getTokenAttribute();
if (!attr || attr!=editor.highlighter()->commentAttribute()) {
if (token == statement->command) {
//same name symbol , test if the same statement;
BufferCoord p;
QSynedit::BufferCoord p;
p.line = posY+1;
p.ch = start+1;
@ -290,7 +290,7 @@ void CppRefacter::renameSymbolInFile(const QString &filename, const PStatement &
QString token = editor.highlighter()->getToken();
if (token == statement->command) {
//same name symbol , test if the same statement;
BufferCoord p;
QSynedit::BufferCoord p;
p.line = posY+1;
p.ch = start;
@ -313,7 +313,7 @@ void CppRefacter::renameSymbolInFile(const QString &filename, const PStatement &
Editor * oldEditor = pMainWindow->editorList()->getOpenedEditorByFilename(filename);
if (oldEditor) {
BufferCoord oldXY=oldEditor->caretXY();
QSynedit::BufferCoord oldXY=oldEditor->caretXY();
int topLine = oldEditor->topLine();
int leftChar = oldEditor->leftChar();
oldEditor->beginUndoBlock();

View File

@ -23,7 +23,9 @@
#include "parser/cppparser.h"
class Editor;
struct BufferCoord;
namespace QSynedit {
struct BufferCoord;
}
class Project;
class CppRefacter : public QObject
{
@ -31,10 +33,10 @@ class CppRefacter : public QObject
public:
explicit CppRefacter(QObject *parent = nullptr);
bool findOccurence(Editor * editor, const BufferCoord& pos);
bool findOccurence(Editor * editor, const QSynedit::BufferCoord& pos);
bool findOccurence(const QString& statementFullname, SearchFileScope scope);
void renameSymbol(Editor* editor, const BufferCoord& pos, const QString& newWord);
void renameSymbol(Editor* editor, const QSynedit::BufferCoord& pos, const QString& newWord);
private:
void doFindOccurenceInEditor(PStatement statement, Editor* editor, const PCppParser& parser);
void doFindOccurenceInProject(PStatement statement, std::shared_ptr<Project> project, const PCppParser& parser);

File diff suppressed because it is too large Load Diff

View File

@ -53,7 +53,7 @@ private:
QByteArray mReasonBuffer;
};
class Editor : public SynEdit
class Editor : public QSynedit::SynEdit
{
Q_OBJECT
public:
@ -180,7 +180,7 @@ public:
bool hasPrevSyntaxIssue() const;
bool hasNextSyntaxIssue() const;
PSyntaxIssueList getSyntaxIssuesAtLine(int line);
PSyntaxIssue getSyntaxIssueAtPosition(const BufferCoord& pos);
PSyntaxIssue getSyntaxIssueAtPosition(const QSynedit::BufferCoord& pos);
int gutterClickedLine() const;
void toggleBreakpoint(int line);
void clearBreakpoints();
@ -192,11 +192,11 @@ public:
void removeBreakpointFocus();
void modifyBreakpointProperty(int line);
void setActiveBreakpointFocus(int Line, bool setFocus=true);
QString getPreviousWordAtPositionForSuggestion(const BufferCoord& p);
QString getPreviousWordAtPositionForSuggestion(const QSynedit::BufferCoord& p);
void reformat();
void checkSyntaxInBack();
void gotoDeclaration(const BufferCoord& pos);
void gotoDefinition(const BufferCoord& pos);
void gotoDeclaration(const QSynedit::BufferCoord& pos);
void gotoDefinition(const QSynedit::BufferCoord& pos);
void reparse();
void reparseTodo();
void insertString(const QString& value, bool moveCursor);
@ -216,12 +216,12 @@ public:
void deleteToBOL();
QStringList getOwnerExpressionAndMemberAtPositionForCompletion(
const BufferCoord& pos,
const QSynedit::BufferCoord& pos,
QString& memberOperator,
QStringList& memberExpression);
QString getWordForCompletionSearch(const BufferCoord& pos,bool permitTilde);
QString getWordForCompletionSearch(const QSynedit::BufferCoord& pos,bool permitTilde);
QStringList getExpressionAtPosition(
const BufferCoord& pos);
const QSynedit::BufferCoord& pos);
const PCppParser &parser();
@ -230,7 +230,7 @@ signals:
void renamed(const QString& oldName, const QString& newName, bool firstSave);
void fileSaved(const QString& filename, bool inProject);
private slots:
void onStatusChanged(SynStatusChanges changes);
void onStatusChanged(QSynedit::StatusChanges changes);
void onGutterClicked(Qt::MouseButton button, int x, int y, int line);
void onTipEvalValueReady(const QString& value);
void onLinesDeleted(int first,int count);
@ -272,7 +272,7 @@ private:
bool onHeaderCompletionKeyPressed(QKeyEvent* event);
bool onCompletionInputMethod(QInputMethodEvent *event);
TipType getTipType(QPoint point, BufferCoord& pos);
TipType getTipType(QPoint point, QSynedit::BufferCoord& pos);
void cancelHint();
QString getFileHint(const QString& s);
QString getParserHint(const QStringList& expression,const QString& s, int line);
@ -284,8 +284,8 @@ private:
void updateFunctionTip(bool showTip);
void clearUserCodeInTabStops();
void popUserCodeInTabStops();
void onExportedFormatToken(PSynHighlighter syntaxHighlighter, int Line, int column, const QString& token,
PSynHighlighterAttribute &attr);
void onExportedFormatToken(QSynedit::PHighlighter syntaxHighlighter, int Line, int column, const QString& token,
QSynedit::PHighlighterAttribute &attr);
void onScrollBarValueChanged();
private:
QByteArray mEncodingOption; // the encoding type set by the user
@ -331,8 +331,8 @@ private:
QString mLineBeforeTabStop;
QString mLineAfterTabStop;
QList<PTabStop> mUserCodeInTabStops;
BufferCoord mHighlightCharPos1;
BufferCoord mHighlightCharPos2;
QSynedit::BufferCoord mHighlightCharPos1;
QSynedit::BufferCoord mHighlightCharPos2;
std::shared_ptr<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > > mStatementColors;
QTimer mFunctionTipTimer;
int mHoverModifiedLine;
@ -347,7 +347,7 @@ protected:
// SynEdit interface
protected:
void onGutterPaint(QPainter &painter, int aLine, int X, int Y) override;
void onGetEditingAreas(int Line, SynEditingAreaList &areaList) override;
void onGetEditingAreas(int Line, QSynedit::EditingAreaList &areaList) override;
// SynEdit interface
protected:
@ -355,7 +355,7 @@ protected:
// SynEdit interface
protected:
void onPreparePaintHighlightToken(int line, int aChar, const QString &token, PSynHighlighterAttribute attr, SynFontStyles &style, QColor &foreground, QColor &background) override;
void onPreparePaintHighlightToken(int line, int aChar, const QString &token, QSynedit::PHighlighterAttribute attr, QSynedit::FontStyles &style, QColor &foreground, QColor &background) override;
// QObject interface
public:
@ -391,10 +391,10 @@ protected:
void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
};
QString getWordAtPosition(SynEdit* editor,
const BufferCoord& p,
BufferCoord& pWordBegin,
BufferCoord& pWordEnd,
QString getWordAtPosition(QSynedit::SynEdit* editor,
const QSynedit::BufferCoord& p,
QSynedit::BufferCoord& pWordBegin,
QSynedit::BufferCoord& pWordEnd,
Editor::WordPurpose purpose);

View File

@ -164,10 +164,6 @@ bool EditorList::closeEditor(Editor* editor, bool transferFocus, bool force) {
}
beginUpdate();
auto end = finally([this] {
this->endUpdate();
});
// if (transferFocus && (editor->pageControl()->currentWidget()==editor)) {
// //todo: activate & focus the previous editor
// }
@ -184,14 +180,17 @@ bool EditorList::closeEditor(Editor* editor, bool transferFocus, bool force) {
delete editor;
}
updateLayout();
if (!force) {
if (!force && transferFocus) {
editor = getEditor();
if (transferFocus && editor)
if (editor) {
editor->activate();
else
pMainWindow->updateClassBrowserForEditor(editor);
} else {
pMainWindow->updateClassBrowserForEditor(nullptr);
}
}
emit editorClosed();
endUpdate();
return true;
}

View File

@ -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"

View File

@ -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"
@ -110,6 +110,7 @@ MainWindow::MainWindow(QWidget *parent)
mCheckSyntaxInBack(false),
mShouldRemoveAllSettings(false),
mClosing(false),
mClosingAll(false),
mOpenningFiles(false),
mSystemTurnedOff(false)
{
@ -394,7 +395,7 @@ void MainWindow::updateForEncodingInfo(bool clear) {
ui->actionAuto_Detect->setChecked(editor->encodingOption() == ENCODING_AUTO_DETECT);
ui->actionEncode_in_ANSI->setChecked(editor->encodingOption() == ENCODING_SYSTEM_DEFAULT);
ui->actionEncode_in_UTF_8->setChecked(editor->encodingOption() == ENCODING_UTF8);
ui->actionEncode_in_UTF_8->setChecked(editor->encodingOption() == ENCODING_UTF8_BOM);
ui->actionEncode_in_UTF_8_BOM->setChecked(editor->encodingOption() == ENCODING_UTF8_BOM);
} else {
mFileEncodingStatus->setText("");
ui->actionAuto_Detect->setChecked(false);
@ -877,7 +878,7 @@ void MainWindow::onFileSaved(const QString &path, bool inProject)
ui->treeFiles->update(index);
}
}
pMainWindow->updateForEncodingInfo();
//updateForEncodingInfo();
}
void MainWindow::updateAppTitle()
@ -1160,17 +1161,25 @@ void MainWindow::openFiles(const QStringList &files)
}
}
//Didn't find a project? Open all files
for (const QString& file:files) {
openFile(file);
for (int i=0;i<files.length()-1;i++) {
openFile(files[i],false);
}
if (files.length()>0) {
openFile(files.last(),true);
}
mEditorList->endUpdate();
Editor* e=mEditorList->getEditor();
if (e)
e->activate();
}
void MainWindow::openFile(const QString &filename, QTabWidget* page)
void MainWindow::openFile(const QString &filename, bool activate, QTabWidget* page)
{
Editor* editor = mEditorList->getOpenedEditorByFilename(filename);
if (editor!=nullptr) {
editor->activate();
if (activate) {
editor->activate();
}
return;
}
try {
@ -1187,8 +1196,10 @@ void MainWindow::openFile(const QString &filename, QTabWidget* page)
// if (mProject) {
// mProject->associateEditorToUnit(editor,unit);
// }
editor->activate();
this->updateForEncodingInfo();
if (activate) {
editor->activate();
}
// editor->activate();
} catch (FileError e) {
QMessageBox::critical(this,tr("Error"),e.reason());
}
@ -1263,7 +1274,7 @@ void MainWindow::openProject(const QString &filename, bool openFiles)
updateCompilerSet();
updateClassBrowserForEditor(e);
}
updateForEncodingInfo();
//updateForEncodingInfo();
}
void MainWindow::changeOptions(const QString &widgetName, const QString &groupName)
@ -2214,7 +2225,7 @@ void MainWindow::loadLastOpens()
// }
if (!editor)
continue;
BufferCoord pos;
QSynedit::BufferCoord pos;
pos.ch = lastOpenIni.GetLongValue(sectionName,"CursorCol", 1);
pos.line = lastOpenIni.GetLongValue(sectionName,"CursorRow", 1);
editor->setCaretXY(pos);
@ -2230,7 +2241,7 @@ void MainWindow::loadLastOpens()
}
if (count>0) {
updateEditorActions();
updateForEncodingInfo();
//updateForEncodingInfo();
}
if (focusedEditor)
focusedEditor->activate();
@ -2298,7 +2309,7 @@ void MainWindow::newEditor()
pSettings->editor().defaultEncoding(),
false,true);
editor->activate();
updateForEncodingInfo();
//updateForEncodingInfo();
} catch (FileError e) {
QMessageBox::critical(this,tr("Error"),e.reason());
}
@ -4016,7 +4027,7 @@ void MainWindow::onEditorContextMenu(const QPoint& pos)
if (!editor)
return;
QMenu menu(this);
BufferCoord p;
QSynedit::BufferCoord p;
mEditorContextMenuPos = pos;
int line;
if (editor->getPositionOfMouse(p)) {
@ -4510,11 +4521,14 @@ void MainWindow::closeEvent(QCloseEvent *event) {
}
}
mClosingAll=true;
if (!mEditorList->closeAll(false)) {
mClosingAll=false;
mQuitting = false;
event->ignore();
return ;
}
mClosingAll=false;
if (!mShouldRemoveAllSettings && pSettings->editor().autoLoadLastFiles()) {
if (mProject) {
@ -5542,9 +5556,11 @@ void MainWindow::on_actionClose_triggered()
void MainWindow::on_actionClose_All_triggered()
{
mClosingAll=true;
mClosing = true;
mEditorList->closeAll(mSystemTurnedOff);
mClosing = false;
mClosingAll=false;
}
@ -5622,7 +5638,7 @@ void MainWindow::on_actionGoto_Definition_triggered()
void MainWindow::on_actionFind_references_triggered()
{
Editor * editor = mEditorList->getEditor();
BufferCoord pos;
QSynedit::BufferCoord pos;
if (editor && editor->pointToCharLine(mEditorContextMenuPos,pos)) {
CppRefacter refactor;
refactor.findOccurence(editor,pos);
@ -6163,7 +6179,7 @@ void MainWindow::newProjectUnitFile()
newProjectUnitDialog.setSuffix("c");
break;
default:
newProjectUnitDialog.setSuffix("");
newProjectUnitDialog.setSuffix("txt");
}
}
QString folder = mProject->fileSystemNodeFolderPath(pNode);
@ -6205,10 +6221,11 @@ void MainWindow::newProjectUnitFile()
mProject->saveAll();
updateProjectView();
idx = mProject->units().count()-1;
Editor * editor = mProject->openUnit(idx);
Editor * editor = mProject->openUnit(idx, false);
//editor->setUseCppSyntax(mProject->options().useGPP);
//editor->setModified(true);
editor->activate();
if (editor)
editor->activate();
QString branch;
if (pSettings->vcs().gitOk() && mProject->model()->iconProvider()->VCSRepository()->hasRepository(branch)) {
QString output;
@ -6472,7 +6489,7 @@ void MainWindow::on_actionRename_Symbol_triggered()
if (!editor->parser())
return;
editor->beginUpdate();
BufferCoord oldCaretXY = editor->caretXY();
QSynedit::BufferCoord oldCaretXY = editor->caretXY();
// mClassBrowserModel.beginUpdate();
QCursor oldCursor = editor->cursor();
editor->setCursor(Qt::CursorShape::WaitCursor);
@ -6484,7 +6501,7 @@ void MainWindow::on_actionRename_Symbol_triggered()
QStringList expression = editor->getExpressionAtPosition(oldCaretXY);
if (expression.isEmpty() && oldCaretXY.ch>1) {
BufferCoord coord=oldCaretXY;
QSynedit::BufferCoord coord=oldCaretXY;
coord.ch--;
expression = editor->getExpressionAtPosition(coord);
}
@ -6706,7 +6723,7 @@ void MainWindow::on_btnReplace_clicked()
line.insert(item->start-1, newWord);
contents[item->line-1] = line;
}
BufferCoord coord=editor->caretXY();
QSynedit::BufferCoord coord=editor->caretXY();
int topLine = editor->topLine();
int leftChar = editor->leftChar();
editor->replaceAll(contents.join(editor->lineBreak()));
@ -8089,3 +8106,13 @@ void MainWindow::on_actionNew_Template_triggered()
}
}
bool MainWindow::isQuitting() const
{
return mQuitting;
}
bool MainWindow::isClosingAll() const
{
return mClosingAll;
}

View File

@ -190,7 +190,7 @@ public:
const PBookmarkModel &bookmarkModel() const;
void openFile(const QString& filename, QTabWidget* page=nullptr);
void openFile(const QString& filename, bool activate=true, QTabWidget* page=nullptr);
void openProject(const QString& filename, bool openFiles = true);
void changeOptions(const QString& widgetName=QString(), const QString& groupName=QString());
@ -759,6 +759,7 @@ private:
CaretList mCaretList;
bool mClosing;
bool mClosingAll;
bool mOpenningFiles;
bool mSystemTurnedOff;
QPoint mEditorContextMenuPos;
@ -844,6 +845,8 @@ protected:
// QObject interface
public:
bool event(QEvent *event) override;
bool isClosingAll() const;
bool isQuitting() const;
};
extern MainWindow* pMainWindow;

View File

@ -473,7 +473,7 @@
<enum>QTabWidget::West</enum>
</property>
<property name="currentIndex">
<number>0</number>
<number>4</number>
</property>
<property name="usesScrollButtons">
<bool>true</bool>
@ -835,6 +835,15 @@
</item>
<item>
<widget class="QListView" name="lstProblemSet">
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::InternalMove</enum>
</property>
<property name="defaultDropAction">
<enum>Qt::MoveAction</enum>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
@ -1704,6 +1713,18 @@
</item>
<item>
<widget class="QTableView" name="tblProblemCases">
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="dragDropOverwriteMode">
<bool>false</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::InternalMove</enum>
</property>
<property name="defaultDropAction">
<enum>Qt::MoveAction</enum>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>

View File

@ -17,7 +17,7 @@
#include "cppparser.h"
#include "parserutils.h"
#include "../utils.h"
#include "../qsynedit/highlighter/cpp.h"
#include "qsynedit/highlighter/cpp.h"
#include <QApplication>
#include <QDate>
@ -959,6 +959,11 @@ QSet<QString> CppParser::scannedFiles()
return mPreprocessor.scannedFiles();
}
bool CppParser::isFileParsed(const QString &filename)
{
return mPreprocessor.scannedFiles().contains(filename);
}
QString CppParser::getScopePrefix(const PStatement& statement){
switch (statement->classScope) {
case StatementClassScope::scsPublic:
@ -4133,7 +4138,7 @@ PStatement CppParser::doParseEvalTypeInfo(
QString s = type;
// qDebug()<<"eval type info"<<type;
int position = s.length()-1;
SynEditCppHighlighter highlighter;
QSynedit::CppHighlighter highlighter;
highlighter.resetState();
highlighter.setLine(type,0);
int bracketLevel = 0;

View File

@ -112,6 +112,8 @@ public:
void unFreeze(); // UnFree/UnLock (reparse while searching)
QSet<QString> scannedFiles();
bool isFileParsed(const QString& filename);
QString prettyPrintStatement(const PStatement& statement, const QString& filename, int line = -1);
bool enabled() const;

View File

@ -166,6 +166,7 @@ struct Statement {
QString fullName; // fullname(including class and namespace), ClassA::foo
QSet<QString> usingList; // using namespaces
QString noNameArgs;// Args without name
// fields for code completion
int usageCount; //Usage Count
int matchPosTotal; // total of matched positions

View File

@ -21,7 +21,7 @@
#include "editorlist.h"
#include <parser/cppparser.h>
#include "utils.h"
#include "platform.h"
#include "qt_utils/charsetinfo.h"
#include "projecttemplate.h"
#include "systemconsts.h"
#include "iconsmanager.h"
@ -309,7 +309,7 @@ PProjectUnit Project::newUnit(PProjectModelNode parentNode, const QString& custo
return newUnit;
}
Editor *Project::openUnit(int index)
Editor *Project::openUnit(int index, bool forceOpen)
{
if ((index < 0) || (index >= mUnits.count()))
return nullptr;
@ -318,11 +318,8 @@ Editor *Project::openUnit(int index)
if (!unit->fileName().isEmpty() && fileExists(unit->fileName())) {
if (getFileType(unit->fileName())==FileType::Other) {
QMimeDatabase db;
QMimeType mimeType=db.mimeTypeForFile(unit->fileName());
if (!mimeType.isValid() || !mimeType.name().startsWith("text/")) {
if (forceOpen)
QDesktopServices::openUrl(QUrl::fromLocalFile(unit->fileName()));
}
return nullptr;
}
@ -1772,6 +1769,28 @@ void Project::loadOptions(SimpleIni& ini)
QByteArray oldCompilerOptions = ini.GetValue("Project", "CompilerSettings", "");
if (!oldCompilerOptions.isEmpty()) {
//version 2 compatibility
// test if it is created by old dev-c++
SimpleIni::TNamesDepend oKeys;
ini.GetAllKeys("Project", oKeys);
bool isNewDev=false;
for(const SimpleIni::Entry& entry:oKeys) {
QString key(entry.pItem);
if (key=="UsePrecompiledHeader"
|| key == "CompilerSetType"
|| key == "StaticLink"
|| key == "AddCharset"
|| key == "ExecEncoding"
|| key == "Encoding"
|| key == "UseUTF8") {
isNewDev = true;
break;
}
}
if (!isNewDev && oldCompilerOptions.length()>=25) {
char t = oldCompilerOptions[18];
oldCompilerOptions[18]=oldCompilerOptions[21];
oldCompilerOptions[21]=t;
}
for (int i=0;i<oldCompilerOptions.length();i++) {
QString key = pSettings->compilerSets().getKeyFromCompilerCompatibleIndex(i);
PCompilerOption pOption = CompilerInfoManager::getCompilerOption(

View File

@ -186,7 +186,7 @@ public:
int indexInUnits(const Editor* editor) const;
PProjectUnit newUnit(PProjectModelNode parentNode,
const QString& customFileName="");
Editor* openUnit(int index);
Editor* openUnit(int index, bool forceOpen=true);
Editor* unitEditor(const PProjectUnit& unit) const;
Editor* unitEditor(const ProjectUnit* unit) const;
Editor* unitEditor(int index) const {

View File

@ -1255,8 +1255,8 @@ void Settings::Editor::doLoad()
mEnhanceHomeKey = boolValue("enhance_home_key", true);
mEnhanceEndKey = boolValue("enhance_end_key",true);
mKeepCaretX = boolValue("keep_caret_x",true);
mCaretForInsert = static_cast<SynEditCaretType>( intValue("caret_for_insert",static_cast<int>(SynEditCaretType::ctVerticalLine)));
mCaretForOverwrite = static_cast<SynEditCaretType>( intValue("caret_for_overwrite",static_cast<int>(SynEditCaretType::ctBlock)));
mCaretForInsert = static_cast<QSynedit::EditCaretType>( intValue("caret_for_insert",static_cast<int>(QSynedit::EditCaretType::ctVerticalLine)));
mCaretForOverwrite = static_cast<QSynedit::EditCaretType>( intValue("caret_for_overwrite",static_cast<int>(QSynedit::EditCaretType::ctBlock)));
mCaretUseTextColor = boolValue("caret_use_text_color",true);
mCaretColor = colorValue("caret_color",Qt::yellow);
@ -1382,22 +1382,22 @@ void Settings::Editor::doLoad()
mShowFunctionTips = boolValue("show_function_tips",true);
}
SynEditCaretType Settings::Editor::caretForOverwrite() const
QSynedit::EditCaretType Settings::Editor::caretForOverwrite() const
{
return mCaretForOverwrite;
}
void Settings::Editor::setCaretForOverwrite(const SynEditCaretType &caretForOverwrite)
void Settings::Editor::setCaretForOverwrite(const QSynedit::EditCaretType &caretForOverwrite)
{
mCaretForOverwrite = caretForOverwrite;
}
SynEditCaretType Settings::Editor::caretForInsert() const
QSynedit::EditCaretType Settings::Editor::caretForInsert() const
{
return mCaretForInsert;
}
void Settings::Editor::setCaretForInsert(const SynEditCaretType &caretForInsert)
void Settings::Editor::setCaretForInsert(const QSynedit::EditCaretType &caretForInsert)
{
mCaretForInsert = caretForInsert;
}
@ -2893,7 +2893,7 @@ void Settings::CompilerSets::prepareCompatibleIndex()
//old settings compatibility, don't reorder, add or remove items
mCompilerCompatibleIndex.append(CC_CMD_OPT_ANSI);
mCompilerCompatibleIndex.append(CC_CMD_OPT_NO_ASM "gcc_cmd_opt_no_asm");
mCompilerCompatibleIndex.append(CC_CMD_OPT_NO_ASM);
mCompilerCompatibleIndex.append(CC_CMD_OPT_TRADITIONAL_CPP);
mCompilerCompatibleIndex.append(CC_CMD_OPT_ARCH);
@ -3886,7 +3886,7 @@ void Settings::CodeCompletion::doLoad()
statex.dwLength = sizeof (statex);
GlobalMemoryStatusEx (&statex);
if (statex.ullAvailPhys > (long long int)3*1024*1024*1024) {
if (statex.ullAvailPhys > (long long int)10*1024*1024*1024) {
doClear = false;
}
#endif

View File

@ -25,6 +25,7 @@
#include <QPair>
#include "qsynedit/SynEdit.h"
#include "compiler/compilerinfo.h"
#include "utils.h"
/**
* use the following command to get gcc's default bin/library folders:
@ -142,11 +143,11 @@ public:
bool enhanceEndKey() const;
void setEnhanceEndKey(bool enhanceEndKey);
SynEditCaretType caretForInsert() const;
void setCaretForInsert(const SynEditCaretType &caretForInsert);
QSynedit::EditCaretType caretForInsert() const;
void setCaretForInsert(const QSynedit::EditCaretType &caretForInsert);
SynEditCaretType caretForOverwrite() const;
void setCaretForOverwrite(const SynEditCaretType &caretForOverwrite);
QSynedit::EditCaretType caretForOverwrite() const;
void setCaretForOverwrite(const QSynedit::EditCaretType &caretForOverwrite);
QColor caretColor() const;
void setCaretColor(const QColor &caretColor);
@ -379,8 +380,8 @@ public:
bool mEnhanceHomeKey;
bool mEnhanceEndKey;
bool mKeepCaretX;
SynEditCaretType mCaretForInsert;
SynEditCaretType mCaretForOverwrite;
QSynedit::EditCaretType mCaretForInsert;
QSynedit::EditCaretType mCaretForOverwrite;
bool mCaretUseTextColor;
QColor mCaretColor;

View File

@ -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>

View File

@ -40,15 +40,15 @@ EditorGeneralWidget::~EditorGeneralWidget()
delete ui;
}
static void setCaretTypeIndex(QComboBox* combo, SynEditCaretType caretType) {
static void setCaretTypeIndex(QComboBox* combo, QSynedit::EditCaretType caretType) {
int t = static_cast<int>(caretType);
combo->setCurrentIndex(t);
}
static SynEditCaretType getCaretTypeIndex(QComboBox* combo) {
static QSynedit::EditCaretType getCaretTypeIndex(QComboBox* combo) {
if (combo->currentIndex()<0)
return SynEditCaretType::ctVerticalLine;
return static_cast<SynEditCaretType>(combo->currentIndex());
return QSynedit::EditCaretType::ctVerticalLine;
return static_cast<QSynedit::EditCaretType>(combo->currentIndex());
}
void EditorGeneralWidget::doLoad()
{

View File

@ -17,7 +17,7 @@
#include "editormiscwidget.h"
#include "ui_editormiscwidget.h"
#include "../settings.h"
#include "../platform.h"
#include "qt_utils/charsetinfo.h"
#include "../mainwindow.h"
EditorMiscWidget::EditorMiscWidget(const QString& name, const QString& group,

View File

@ -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),

View File

@ -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),

View File

@ -63,7 +63,7 @@ TodoThread::TodoThread(const QString& filename, QObject *parent): QThread(parent
void TodoThread::run()
{
PSynHighlighter highlighter = highlighterManager.getCppHighlighter();
QSynedit::PHighlighter highlighter = highlighterManager.getCppHighlighter();
emit parseStarted(mFilename);
auto action = finally([this]{
emit parseFinished();
@ -72,13 +72,13 @@ void TodoThread::run()
if (!pMainWindow->editorList()->getContentFromOpenedEditor(mFilename,lines)) {
return;
}
PSynHighlighterAttribute commentAttr = highlighter->getAttribute(SYNS_AttrComment);
QSynedit::PHighlighterAttribute commentAttr = highlighter->getAttribute(SYNS_AttrComment);
highlighter->resetState();
for (int i =0;i<lines.count();i++) {
highlighter->setLine(lines[i],i);
while (!highlighter->eol()) {
PSynHighlighterAttribute attr;
QSynedit::PHighlighterAttribute attr;
attr = highlighter->getTokenAttribute();
if (attr == commentAttr) {
QString token = highlighter->getToken();

File diff suppressed because it is too large Load Diff

View File

@ -26,20 +26,11 @@
#include <QThread>
#include <QProcessEnvironment>
#include "SimpleIni.h"
#include "qt_utils/utils.h"
using SimpleIni = CSimpleIniA;
using PSimpleIni = std::shared_ptr<SimpleIni>;
class QByteArray;
class QTextStream;
class QTextCodec;
#define ENCODING_AUTO_DETECT "AUTO"
#define ENCODING_UTF8 "UTF-8"
#define ENCODING_UTF8_BOM "UTF-8 BOM"
#define ENCODING_SYSTEM_DEFAULT "SYSTEM"
#define ENCODING_ASCII "ASCII"
enum class FileType{
CSource, // c source file (.c)
CppSource, // c++ source file (.cpp)
@ -51,12 +42,6 @@ enum class FileType{
Other // any others
};
enum class FileEndingType {
Windows,
Linux,
Mac
};// Windows: CRLF, UNIX: LF, Mac: CR
enum class SearchFileScope {
currentFile,
wholeProject,
@ -107,33 +92,27 @@ enum FormatterIndentType {
fitTab
};
class BaseError{
public:
explicit BaseError(const QString& reason);
QString reason() const;
protected:
QString mReason;
enum class SplitProcessCommandQuoteType {
None,
Single,
Double
};
class IndexOutOfRange:public BaseError {
public:
explicit IndexOutOfRange(int Index);
};
FileType getFileType(const QString& filename);
QStringList splitProcessCommand(const QString& cmd);
class FileError: public BaseError {
public:
explicit FileError(const QString& reason);
};
QString genMakePath(const QString& fileName,bool escapeSpaces, bool encloseInQuotes);
QString genMakePath1(const QString& fileName);
QString genMakePath2(const QString& fileName);
QString getCompiledExecutableName(const QString& filename);
bool programHasConsole(const QString& filename);
typedef void (*LineOutputFunc) (const QString& line);
typedef bool (*CheckAbortFunc) ();
bool isGreenEdition();
QString parseMacros(const QString& s);
const QByteArray GuessTextEncoding(const QByteArray& text);
class CppParser;
void resetCppParser(std::shared_ptr<CppParser> parser, int compilerSetIndex=-1);
bool isTextAllAscii(const QByteArray& text);
bool isTextAllAscii(const QString& text);
int getNewFileNumber();
QByteArray runAndGetOutput(const QString& cmd, const QString& workingDir, const QStringList& arguments,
const QByteArray& inputContent = QByteArray(),
@ -145,146 +124,24 @@ void executeFile(const QString& fileName,
const QString& workingDir,
const QString& tempFile);
bool isNonPrintableAsciiChar(char ch);
bool isGreenEdition();
bool fileExists(const QString& file);
bool fileExists(const QString& dir, const QString& fileName);
bool directoryExists(const QString& file);
bool removeFile(const QString& filename);
QString includeTrailingPathDelimiter(const QString& path);
QString excludeTrailingPathDelimiter(const QString& path);
FileType getFileType(const QString& filename);
QString changeFileExt(const QString& filename, QString ext);
QString extractRelativePath(const QString& base, const QString& dest);
QString genMakePath(const QString& fileName,bool escapeSpaces, bool encloseInQuotes);
QString genMakePath1(const QString& fileName);
QString genMakePath2(const QString& fileName);
QString getCompiledExecutableName(const QString& filename);
void splitStringArguments(const QString& arguments, QStringList& argumentList);
bool programHasConsole(const QString& filename);
using LineProcessFunc = std::function<void(const QString&)>;
#ifdef Q_OS_WIN
bool readRegistry(HKEY key,const QByteArray& subKey, const QByteArray& name, QString& value);
#endif
QStringList readStreamToLines(QTextStream* stream);
void readStreamToLines(QTextStream* stream, LineProcessFunc lineFunc);
QStringList textToLines(const QString& text);
void textToLines(const QString& text, LineProcessFunc lineFunc);
QString linesToText(const QStringList& lines);
QList<QByteArray> splitByteArrayToLines(const QByteArray& content);
QString parseMacros(const QString& s);
/**
* @brief readFileToLines
* @param fileName
* @param codec
* @return
*/
QStringList readFileToLines(const QString& fileName, QTextCodec* codec);
QStringList readFileToLines(const QString& fileName);
QByteArray readFileToByteArray(const QString& fileName);
void readFileToLines(const QString& fileName, QTextCodec* codec, LineProcessFunc lineFunc);
void stringsToFile(const QStringList& list, const QString& fileName);
void stringToFile(const QString& str, const QString& fileName);
int countLeadingWhitespaceChars(const QString& line);
void decodeKey(int combinedKey, int& key, Qt::KeyboardModifiers& modifiers);
void inflateRect(QRect& rect, int delta);
void inflateRect(QRect& rect, int dx, int dy);
QString trimRight(const QString& s);
QString trimLeft(const QString& s);
bool stringIsBlank(const QString& s);
int compareFileModifiedTime(const QString& filename1, const QString& filename2);
QByteArray getHTTPBody(const QByteArray& content);
bool haveGoodContrast(const QColor& c1, const QColor &c2);
qulonglong stringToHex(const QString& str, bool &isOk);
//void changeTheme(const QString& themeName);
bool findComplement(const QString& s,
const QChar& fromToken,
const QChar& toToken,
int& curPos,
int increment);
void logToFile(const QString& s, const QString& filename, bool append=true);
QString localizePath(const QString& path);
QString extractFileName(const QString& fileName);
QString extractFileDir(const QString& fileName);
QString extractFilePath(const QString& filePath);
QString extractAbsoluteFilePath(const QString& filePath);
bool haveGoodContrast(const QColor& c1, const QColor &c2);
QByteArray getHTTPBody(const QByteArray& content);
QString getSizeString(int size);
bool isReadOnly(const QString& filename);
QByteArray toByteArray(const QString& s);
QString fromByteArray(const QByteArray& s);
int getNewFileNumber();
enum class SplitProcessCommandQuoteType {
None,
Single,
Double
};
QStringList splitProcessCommand(const QString& cmd);
#ifdef Q_OS_WIN
bool readRegistry(HKEY key,const QByteArray& subKey, const QByteArray& name, QString& value);
#endif
class CppParser;
void resetCppParser(std::shared_ptr<CppParser> parser, int compilerSetIndex=-1);
int screenDPI();
void setScreenDPI(int dpi);
float pointToPixel(float point);
float pointToPixel(float point, float dpi);
float pixelToPoint(float pixel);
void copyFolder(const QString &fromDir, const QString& toDir);
bool copyFile(const QString &fromFile, const QString& toFile, bool overwrite);
/**
* from https://github.com/Microsoft/GSL
**/
template <class F>
class final_action
{
public:
static_assert(!std::is_reference<F>::value && !std::is_const<F>::value &&
!std::is_volatile<F>::value,
"Final_action should store its callable by value");
explicit final_action(F f) noexcept : f_(std::move(f)) {}
final_action(final_action&& other) noexcept
: f_(std::move(other.f_)), invoke_(std::exchange(other.invoke_, false))
{}
final_action(const final_action&) = delete;
final_action& operator=(const final_action&) = delete;
final_action& operator=(final_action&&) = delete;
~final_action() noexcept
{
if (invoke_) f_();
}
private:
F f_;
bool invoke_{true};
};
template <class F> final_action<typename std::remove_cv<typename std::remove_reference<F>::type>::type>
finally(F&& f) noexcept
{
return final_action<typename std::remove_cv<typename std::remove_reference<F>::type>::type>(
std::forward<F>(f));
}
#endif // UTILS_H

View File

@ -123,7 +123,7 @@ void CPUDialog::setDisassembly(const QString& file, const QString& funcName,cons
ui->txtCode->document()->add(line);
}
if (activeLine!=-1)
ui->txtCode->setCaretXYEx(true,BufferCoord{1,activeLine+1});
ui->txtCode->setCaretXYEx(true,QSynedit::BufferCoord{1,activeLine+1});
}
void CPUDialog::resetEditorFont(float dpi)

View File

@ -80,7 +80,7 @@
</widget>
</item>
<item>
<widget class="SynEdit" name="txtCode">
<widget class="QSynedit::SynEdit" name="txtCode">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
@ -224,7 +224,7 @@
</widget>
<customwidgets>
<customwidget>
<class>SynEdit</class>
<class>QSynedit::SynEdit</class>
<extends>QFrame</extends>
<header location="global">qsynedit/SynEdit.h</header>
<container>1</container>

View File

@ -31,21 +31,14 @@ EditorsTabWidget::EditorsTabWidget(QWidget* parent):QTabWidget(parent)
void EditorsTabWidget::dropEvent(QDropEvent *event)
{
if (event->mimeData()->hasUrls()) {
QStringList files;
foreach(const QUrl& url, event->mimeData()->urls()){
if (!url.isLocalFile())
continue;
QString file = url.toLocalFile();
if (getFileType(file)==FileType::Project) {
pMainWindow->openProject(file);
return;
}
}
foreach(const QUrl& url, event->mimeData()->urls()){
if (!url.isLocalFile())
continue;
QString file = url.toLocalFile();
pMainWindow->openFile(file,this);
files.append(file);
}
pMainWindow->openFiles(files);
}
}

View File

@ -19,7 +19,7 @@
#include "../mainwindow.h"
#include "../editorlist.h"
#include "../editor.h"
#include "../qsynedit/Constants.h"
#include <qsynedit/Constants.h>
#include <QFileInfo>
@ -56,8 +56,8 @@ void FilePropertiesDialog::calcFile(Editor *editor,
while (j<line.length() && (line[j]=='\t' || line[j]==' '))
j++;
QString token;
PSynHighlighterAttribute attr;
if (editor->getHighlighterAttriAtRowCol(BufferCoord{j+1,i+1},
QSynedit::PHighlighterAttribute attr;
if (editor->getHighlighterAttriAtRowCol(QSynedit::BufferCoord{j+1,i+1},
token,attr)) {
// if it is preprocessor...
if (attr->name() == SYNS_AttrPreprocessor) {

View File

@ -21,6 +21,7 @@
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QMimeData>
#include "../utils.h"
#include "../iconsmanager.h"
#include "../systemconsts.h"
@ -241,9 +242,45 @@ bool OJProblemSetModel::setData(const QModelIndex &index, const QVariant &value,
return false;
}
Qt::ItemFlags OJProblemSetModel::flags(const QModelIndex &) const
Qt::ItemFlags OJProblemSetModel::flags(const QModelIndex &index) const
{
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
Qt::ItemFlags flags = Qt::NoItemFlags;
if (index.isValid()) {
flags = Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled;
} else if (index.row() == -1) {
// -1 means it's a drop target?
flags = Qt::ItemIsDropEnabled;
}
return flags ;
}
Qt::DropActions OJProblemSetModel::supportedDropActions() const
{
return Qt::DropAction::MoveAction;
}
bool OJProblemSetModel::moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild)
{
if (sourceRow < 0
|| sourceRow + count - 1 >= mProblemSet.problems.count()
|| destinationChild < 0
|| destinationChild > mProblemSet.problems.count()
|| sourceRow == destinationChild
|| count <= 0) {
return false;
}
if (!beginMoveRows(QModelIndex(), sourceRow, sourceRow + count - 1, QModelIndex(), destinationChild))
return false;
int fromRow = sourceRow;
if (destinationChild < sourceRow)
fromRow += count - 1;
else
destinationChild--;
while (count--)
mProblemSet.problems.move(fromRow, destinationChild);
endMoveRows();
return true;
}
OJProblemModel::OJProblemModel(QObject *parent): QAbstractTableModel(parent)
@ -441,6 +478,9 @@ Qt::ItemFlags OJProblemModel::flags(const QModelIndex &idx) const
Qt::ItemFlags flags=Qt::ItemIsEnabled | Qt::ItemIsSelectable;
if (idx.column()==0)
flags |= Qt::ItemIsEditable ;
if (idx.isValid())
flags |= Qt::ItemIsDragEnabled;
flags |= Qt::ItemIsDropEnabled;
return flags;
}
@ -461,3 +501,49 @@ QVariant OJProblemModel::headerData(int section, Qt::Orientation orientation, in
}
return QVariant();
}
Qt::DropActions OJProblemModel::supportedDropActions() const
{
return Qt::DropAction::MoveAction;
}
bool OJProblemModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
{
mMoveTargetRow=row;
if (mMoveTargetRow==-1)
mMoveTargetRow=mProblem->cases.length();
return QAbstractTableModel::dropMimeData(data,action,row,0,parent);
}
bool OJProblemModel::insertRows(int row, int count, const QModelIndex &parent)
{
return true;
}
bool OJProblemModel::removeRows(int row, int count, const QModelIndex &parent)
{
int sourceRow = row;
int destinationChild = mMoveTargetRow;
mMoveTargetRow=-1;
if (sourceRow < 0
|| sourceRow + count - 1 >= mProblem->cases.count()
|| destinationChild < 0
|| destinationChild > mProblem->cases.count()
|| sourceRow == destinationChild
|| count <= 0) {
return false;
}
if (!beginMoveRows(QModelIndex(), sourceRow, sourceRow + count - 1, QModelIndex(), destinationChild))
return false;
int fromRow = sourceRow;
if (destinationChild < sourceRow)
fromRow += count - 1;
else
destinationChild--;
while (count--)
mProblem->cases.move(fromRow, destinationChild);
endMoveRows();
return true;
}

View File

@ -41,6 +41,7 @@ public:
private:
POJProblem mProblem;
int mMoveTargetRow;
// QAbstractItemModel interface
public:
@ -53,6 +54,19 @@ public:
public:
int columnCount(const QModelIndex &parent) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
// QAbstractItemModel interface
public:
Qt::DropActions supportedDropActions() const override;
// QAbstractItemModel interface
public:
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
// QAbstractItemModel interface
public:
bool insertRows(int row, int count, const QModelIndex &parent) override;
bool removeRows(int row, int count, const QModelIndex &parent) override;
};
class OJProblemSetModel : public QAbstractListModel
@ -87,6 +101,11 @@ public:
QVariant data(const QModelIndex &index, int role) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
// QAbstractItemModel interface
public:
Qt::DropActions supportedDropActions() const override;
bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild) override;
};
#endif // OJPROBLEMSETMODEL_H

View File

@ -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>
@ -44,8 +44,8 @@ SearchDialog::SearchDialog(QWidget *parent) :
ui->dialogLayout->insertWidget(0,mTabBar);
connect(mTabBar,&QTabBar::currentChanged,this, &SearchDialog::onTabChanged);
mSearchOptions&=0;
mBasicSearchEngine= PSynSearchBase(new SynSearch());
mRegexSearchEngine= PSynSearchBase(new SynSearchRegex());
mBasicSearchEngine= QSynedit::PSynSearchBase(new QSynedit::BasicSearcher());
mRegexSearchEngine= QSynedit::PSynSearchBase(new QSynedit::RegexSearcher());
}
SearchDialog::~SearchDialog()
@ -87,7 +87,7 @@ void SearchDialog::findInFiles(const QString &text)
show();
}
void SearchDialog::findInFiles(const QString &keyword, SearchFileScope scope, SynSearchOptions options)
void SearchDialog::findInFiles(const QString &keyword, SearchFileScope scope, QSynedit::SearchOptions options)
{
mTabBar->setCurrentIndex(2);
@ -106,10 +106,10 @@ void SearchDialog::findInFiles(const QString &keyword, SearchFileScope scope, Sy
break;
}
// Apply options
ui->chkRegExp->setChecked(options.testFlag(ssoRegExp));
ui->chkCaseSensetive->setChecked(options.testFlag(ssoMatchCase));
ui->chkWholeWord->setChecked(options.testFlag(ssoWholeWord));
ui->chkWrapAround->setChecked(options.testFlag(ssoWholeWord));
ui->chkRegExp->setChecked(options.testFlag(QSynedit::ssoRegExp));
ui->chkCaseSensetive->setChecked(options.testFlag(QSynedit::ssoMatchCase));
ui->chkWholeWord->setChecked(options.testFlag(QSynedit::ssoWholeWord));
ui->chkWrapAround->setChecked(options.testFlag(QSynedit::ssoWholeWord));
show();
}
@ -215,42 +215,42 @@ void SearchDialog::on_btnExecute_clicked()
// Apply options
if (ui->chkRegExp->isChecked()) {
mSearchOptions.setFlag(ssoRegExp);
mSearchOptions.setFlag(QSynedit::ssoRegExp);
}
if (ui->chkCaseSensetive->isChecked()) {
mSearchOptions.setFlag(ssoMatchCase);
mSearchOptions.setFlag(QSynedit::ssoMatchCase);
}
if (ui->chkWholeWord->isChecked()) {
mSearchOptions.setFlag(ssoWholeWord);
mSearchOptions.setFlag(QSynedit::ssoWholeWord);
}
if (ui->chkWrapAround->isChecked()) {
mSearchOptions.setFlag(ssoWrapAround);
mSearchOptions.setFlag(QSynedit::ssoWrapAround);
}
// Apply scope, when enabled
if (ui->grpScope->isEnabled()) {
if (ui->rbSelection->isChecked()) {
mSearchOptions.setFlag(ssoSelectedOnly);
mSearchOptions.setFlag(QSynedit::ssoSelectedOnly);
}
}
// Apply direction, when enabled
if (ui->grpDirection->isEnabled()) {
if (ui->rbBackward->isChecked()) {
mSearchOptions.setFlag(ssoBackwards);
mSearchOptions.setFlag(QSynedit::ssoBackwards);
}
}
// Apply origin, when enabled
if (ui->grpOrigin->isEnabled()) {
if (ui->rbEntireScope->isChecked()) {
mSearchOptions.setFlag(ssoEntireScope);
mSearchOptions.setFlag(QSynedit::ssoEntireScope);
}
}
// Use entire scope for file finding/replacing
if (actionType == SearchAction::FindFiles || actionType == SearchAction::ReplaceFiles) {
mSearchOptions.setFlag(ssoEntireScope);
mSearchOptions.setFlag(QSynedit::ssoEntireScope);
}
this->close();
@ -283,18 +283,18 @@ void SearchDialog::on_btnExecute_clicked()
QMessageBox::Yes|QMessageBox::YesAll|QMessageBox::No|QMessageBox::Cancel,
QMessageBox::Yes)) {
case QMessageBox::Yes:
return SynSearchAction::Replace;
return QSynedit::SearchAction::Replace;
case QMessageBox::YesAll:
return SynSearchAction::ReplaceAll;
return QSynedit::SearchAction::ReplaceAll;
case QMessageBox::No:
return SynSearchAction::Skip;
return QSynedit::SearchAction::Skip;
case QMessageBox::Cancel:
return SynSearchAction::Exit;
return QSynedit::SearchAction::Exit;
default:
return SynSearchAction::Exit;
return QSynedit::SearchAction::Exit;
}
} else {
return SynSearchAction::ReplaceAll;
return QSynedit::SearchAction::ReplaceAll;
}
},
[](){
@ -378,7 +378,7 @@ void SearchDialog::on_btnExecute_clicked()
results->results.append(parentItem);
}
} else if (fileExists(curFilename)) {
SynEdit editor;
QSynedit::SynEdit editor;
QByteArray realEncoding;
editor.document()->loadFromFile(curFilename,ENCODING_AUTO_DETECT, realEncoding);
fileSearched++;
@ -401,24 +401,24 @@ void SearchDialog::on_btnExecute_clicked()
}
}
int SearchDialog::execute(SynEdit *editor, const QString &sSearch, const QString &sReplace,
SynSearchMathedProc matchCallback,
SynSearchConfirmAroundProc confirmAroundCallback)
int SearchDialog::execute(QSynedit::SynEdit *editor, const QString &sSearch, const QString &sReplace,
QSynedit::SearchMathedProc matchCallback,
QSynedit::SearchConfirmAroundProc confirmAroundCallback)
{
if (editor==nullptr)
return 0;
// Modify the caret when using 'from cursor' and when the selection is ignored
if (!mSearchOptions.testFlag(ssoEntireScope) && !mSearchOptions.testFlag(ssoSelectedOnly)
if (!mSearchOptions.testFlag(QSynedit::ssoEntireScope) && !mSearchOptions.testFlag(QSynedit::ssoSelectedOnly)
&& editor->selAvail()) {
// start at end of selection
if (mSearchOptions.testFlag(ssoBackwards)) {
if (mSearchOptions.testFlag(QSynedit::ssoBackwards)) {
editor->setCaretXY(editor->blockBegin());
} else {
editor->setCaretXY(editor->blockEnd());
}
}
if (mSearchOptions.testFlag(ssoRegExp)) {
if (mSearchOptions.testFlag(QSynedit::ssoRegExp)) {
mSearchEngine = mRegexSearchEngine;
} else {
mSearchEngine = mBasicSearchEngine;
@ -428,12 +428,12 @@ int SearchDialog::execute(SynEdit *editor, const QString &sSearch, const QString
mSearchEngine, matchCallback, confirmAroundCallback);
}
std::shared_ptr<SearchResultTreeItem> SearchDialog::batchFindInEditor(SynEdit *e, const QString& filename,const QString &keyword)
std::shared_ptr<SearchResultTreeItem> SearchDialog::batchFindInEditor(QSynedit::SynEdit *e, const QString& filename,const QString &keyword)
{
//backup
BufferCoord caretBackup = e->caretXY();
BufferCoord blockBeginBackup = e->blockBegin();
BufferCoord blockEndBackup = e->blockEnd();
QSynedit::BufferCoord caretBackup = e->caretXY();
QSynedit::BufferCoord blockBeginBackup = e->blockBegin();
QSynedit::BufferCoord blockEndBackup = e->blockEnd();
int toplineBackup = e->topLine();
int leftCharBackup = e->leftChar();
@ -452,7 +452,7 @@ std::shared_ptr<SearchResultTreeItem> SearchDialog::batchFindInEditor(SynEdit *e
item->text = e->document()->getString(Line-1);
item->text.replace('\t',' ');
parentItem->results.append(item);
return SynSearchAction::Skip;
return QSynedit::SearchAction::Skip;
});
// restore
@ -486,7 +486,7 @@ QTabBar *SearchDialog::tabBar() const
return mTabBar;
}
PSynSearchBase SearchDialog::searchEngine() const
QSynedit::PSynSearchBase SearchDialog::searchEngine() const
{
return mSearchEngine;
}

View File

@ -18,7 +18,7 @@
#define SEARCHDIALOG_H
#include <QDialog>
#include "../qsynedit/SynEdit.h"
#include <qsynedit/SynEdit.h>
#include "../utils.h"
namespace Ui {
@ -46,9 +46,9 @@ public:
void findNext();
void findPrevious();
void findInFiles(const QString& text);
void findInFiles(const QString& keyword, SearchFileScope scope, SynSearchOptions options);
void findInFiles(const QString& keyword, SearchFileScope scope, QSynedit::SearchOptions options);
void replace(const QString& sFind, const QString& sReplace);
PSynSearchBase searchEngine() const;
QSynedit::PSynSearchBase searchEngine() const;
QTabBar *tabBar() const;
@ -60,18 +60,18 @@ private slots:
void on_btnExecute_clicked();
private:
int execute(SynEdit* editor, const QString& sSearch,
int execute(QSynedit::SynEdit* editor, const QString& sSearch,
const QString& sReplace,
SynSearchMathedProc matchCallback = nullptr,
SynSearchConfirmAroundProc confirmAroundCallback = nullptr);
std::shared_ptr<SearchResultTreeItem> batchFindInEditor(SynEdit * editor,const QString& filename, const QString& keyword);
QSynedit::SearchMathedProc matchCallback = nullptr,
QSynedit::SearchConfirmAroundProc confirmAroundCallback = nullptr);
std::shared_ptr<SearchResultTreeItem> batchFindInEditor(QSynedit::SynEdit * editor,const QString& filename, const QString& keyword);
private:
Ui::SearchDialog *ui;
QTabBar *mTabBar;
SynSearchOptions mSearchOptions;
PSynSearchBase mSearchEngine;
PSynSearchBase mBasicSearchEngine;
PSynSearchBase mRegexSearchEngine;
QSynedit::SearchOptions mSearchOptions;
QSynedit::PSynSearchBase mSearchEngine;
QSynedit::PSynSearchBase mBasicSearchEngine;
QSynedit::PSynSearchBase mRegexSearchEngine;
// QWidget interface
protected:

View File

@ -20,7 +20,7 @@
#include <QStyledItemDelegate>
#include "mainwindow.h"
PSearchResults SearchResultModel::addSearchResults(const QString &keyword, SynSearchOptions options, SearchFileScope scope)
PSearchResults SearchResultModel::addSearchResults(const QString &keyword, QSynedit::SearchOptions options, SearchFileScope scope)
{
int index=-1;
for (int i=0;i<mSearchResults.size();i++) {

View File

@ -20,7 +20,7 @@
#include <QTreeView>
#include <QMap>
#include <QStyledItemDelegate>
#include "../qsynedit/SearchBase.h"
#include "qsynedit/SearchBase.h"
#include "utils.h"
#define MAX_SEARCH_RESULTS 20
@ -46,7 +46,7 @@ struct SearchResultTreeItem {
};
struct SearchResults{
SynSearchOptions options;
QSynedit::SearchOptions options;
QString keyword;
QString statementFullname;
SearchFileScope scope;
@ -61,7 +61,7 @@ class SearchResultModel : public QObject {
Q_OBJECT
public:
explicit SearchResultModel(QObject* parent=nullptr);
PSearchResults addSearchResults(const QString& keyword,SynSearchOptions options,
PSearchResults addSearchResults(const QString& keyword,QSynedit::SearchOptions options,
SearchFileScope scope);
PSearchResults addSearchResults(
const QString& keyword,

View File

@ -3,37 +3,47 @@ TEMPLATE = subdirs
SUBDIRS += \
RedPandaIDE \
astyle \
consolepauser
consolepauser \
redpanda_qt_utils \
qsynedit
astyle.subdir = tools/astyle
consolepauser.subdir = tools/consolepauser
redpanda_qt_utils.subdir = libs/redpanda_qt_utils
qsynedit.subdir = libs/qsynedit
# Add the dependencies so that the RedPandaIDE project can add the depended programs
# into the main app bundle
RedPandaIDE.depends = astyle consolepauser
RedPandaIDE.depends = astyle consolepauser qsynedit
qsynedit.depends = redpanda_qt_utils
win32: {
SUBDIRS += \
redpanda-win-git-askpass
RedPandaIDE.depends += redpanda-win-git-askpass
redpanda-win-git-askpass
redpanda-win-git-askpass.subdir = tools/redpanda-win-git-askpass
RedPandaIDE.depends += redpanda-win-git-askpass
}
unix: {
SUBDIRS += \
redpanda-git-askpass
RedPandaIDE.depends += redpanda-git-askpass
redpanda-git-askpass.subdir = tools/redpanda-git-askpass
RedPandaIDE.depends += redpanda-git-askpass
}
APP_NAME = RedPandaCPP
APP_VERSION = 1.2
APP_VERSION = 1.4
linux: {
isEmpty(PREFIX) {
PREFIX = /usr/local
}
QMAKE_SUBSTITUTES += linux/redpandaide.desktop.in
QMAKE_SUBSTITUTES += platform/linux/redpandaide.desktop.in
resources.path = $${PREFIX}/share/$${APP_NAME}
resources.files += linux/templates
resources.files += platform/linux/templates
INSTALLS += resources
docs.path = $${PREFIX}/share/doc/$${APP_NAME}
@ -43,26 +53,26 @@ linux: {
INSTALLS += docs
pixmaps.path = $${PREFIX}/share/pixmaps
pixmaps.files += linux/redpandaide.png
pixmaps.files += platform/linux/redpandaide.png
INSTALLS += pixmaps
desktop.path = $${PREFIX}/share/applications
desktop.files += linux/redpandaide.desktop
desktop.files += platform/linux/redpandaide.desktop
INSTALLS += desktop
}
win32: {
!isEmpty(PREFIX) {
target.path = $${PREFIX}
QMAKE_SUBSTITUTES += windows/installer-scripts/config.nsh.in
QMAKE_SUBSTITUTES += windows/installer-scripts/config32.nsh.in
QMAKE_SUBSTITUTES += windows/installer-scripts/config-clang.nsh.in
QMAKE_SUBSTITUTES += platform/windows/installer-scripts/config.nsh.in
QMAKE_SUBSTITUTES += platform/windows/installer-scripts/config32.nsh.in
QMAKE_SUBSTITUTES += platform/windows/installer-scripts/config-clang.nsh.in
resources.path = $${PREFIX}
resources.files += windows/templates
resources.files += windows/installer-scripts/config.nsh
resources.files += windows/installer-scripts/config32.nsh
resources.files += windows/installer-scripts/config-clang.nsh
resources.files += platform/windows/templates
resources.files += platform/windows/installer-scripts/config.nsh
resources.files += platform/windows/installer-scripts/config32.nsh
resources.files += platform/windows/installer-scripts/config-clang.nsh
resources.files += README.md
resources.files += NEWS.md
resources.files += LICENSE

View File

@ -0,0 +1,64 @@
TEMPLATE = lib
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++17
CONFIG += nokey
CONFIG += staticlib
win32: {
DEFINES += _WIN32_WINNT=0x0601
}
gcc {
QMAKE_CXXFLAGS_RELEASE += -Werror=return-type
QMAKE_CXXFLAGS_DEBUG += -Werror=return-type
}
msvc {
DEFINES += NOMINMAX
}
SOURCES += qsynedit/CodeFolding.cpp \
qsynedit/Constants.cpp \
qsynedit/KeyStrokes.cpp \
qsynedit/MiscClasses.cpp \
qsynedit/MiscProcs.cpp \
qsynedit/SynEdit.cpp \
qsynedit/TextBuffer.cpp \
qsynedit/TextPainter.cpp \
qsynedit/exporter/synexporter.cpp \
qsynedit/exporter/synhtmlexporter.cpp \
qsynedit/exporter/synrtfexporter.cpp \
qsynedit/highlighter/asm.cpp \
qsynedit/highlighter/base.cpp \
qsynedit/highlighter/composition.cpp \
qsynedit/highlighter/cpp.cpp \
qsynedit/highlighter/glsl.cpp \
qsynedit/Search.cpp \
qsynedit/SearchBase.cpp \
qsynedit/SearchRegex.cpp \
qsynedit/Types.cpp
HEADERS += qsynedit/Search.h \
qsynedit/SearchBase.h \
qsynedit/SearchRegex.h \
qsynedit/CodeFolding.h \
qsynedit/Constants.h \
qsynedit/KeyStrokes.h \
qsynedit/MiscClasses.h \
qsynedit/MiscProcs.h \
qsynedit/SynEdit.h \
qsynedit/TextBuffer.h \
qsynedit/TextPainter.h \
qsynedit/Types.h \
qsynedit/exporter/synexporter.h \
qsynedit/exporter/synhtmlexporter.h \
qsynedit/exporter/synrtfexporter.h \
qsynedit/highlighter/asm.h \
qsynedit/highlighter/base.h \
qsynedit/highlighter/composition.h \
qsynedit/highlighter/cpp.h \
qsynedit/highlighter/glsl.h \
INCLUDEPATH += ../redpanda_qt_utils

View File

@ -17,14 +17,17 @@
#include "CodeFolding.h"
#include "Constants.h"
int SynEditFoldRegions::count()
namespace QSynedit {
int CodeFoldingDefines::count()
{
return fRegions.size();
}
PSynEditFoldRegion SynEditFoldRegions::add(bool addEnding, const QChar &openSymbol, const QChar &closeSymbol, const QString &highlight)
PCodeFoldingDefine CodeFoldingDefines::add(bool addEnding, const QChar &openSymbol, const QChar &closeSymbol, const QString &highlight)
{
PSynEditFoldRegion region = std::make_shared<SynEditFoldRegion>();
PCodeFoldingDefine region = std::make_shared<CodeFoldingDefine>();
region->addEnding = addEnding;
region->openSymbol = openSymbol;
region->closeSymbol = closeSymbol;
@ -33,12 +36,12 @@ PSynEditFoldRegion SynEditFoldRegions::add(bool addEnding, const QChar &openSymb
return region;
}
PSynEditFoldRegion SynEditFoldRegions::get(int index)
PCodeFoldingDefine CodeFoldingDefines::get(int index)
{
return fRegions.at(index);
}
SynEditCodeFolding::SynEditCodeFolding():
CodeFoldingOptions::CodeFoldingOptions():
indentGuides(true),
fillIndents(false),
showCollapsedLine(true),
@ -50,9 +53,9 @@ SynEditCodeFolding::SynEditCodeFolding():
}
bool SynEditFoldRange::parentCollapsed()
bool CodeFoldingRange::parentCollapsed()
{
PSynEditFoldRange parentFold = parent;
PCodeFoldingRange parentFold = parent;
// Find first parent that is collapsed
while (parentFold) {
if (parentFold->collapsed) {
@ -63,13 +66,16 @@ bool SynEditFoldRange::parentCollapsed()
return false;
}
void SynEditFoldRange::move(int count)
void CodeFoldingRange::move(int count)
{
fromLine += count;
toLine += count;
}
SynEditFoldRange::SynEditFoldRange(PSynEditFoldRange aParent, PSynEditFoldRanges aAllFold, int aFromLine, PSynEditFoldRegion aFoldRegion, int aToLine):
CodeFoldingRange::CodeFoldingRange(PCodeFoldingRange aParent,
PCodeFoldingRanges aAllFold,
int aFromLine,
PCodeFoldingDefine aFoldRegion, int aToLine):
fromLine(aFromLine),
toLine(aToLine),
linesCollapsed(0),
@ -79,37 +85,37 @@ SynEditFoldRange::SynEditFoldRange(PSynEditFoldRange aParent, PSynEditFoldRanges
hintMarkLeft(0),
parent(aParent)
{
subFoldRanges = std::make_shared<SynEditFoldRanges>();
subFoldRanges = std::make_shared<CodeFoldingRanges>();
}
PSynEditFoldRange SynEditFoldRanges::range(int index)
PCodeFoldingRange CodeFoldingRanges::range(int index)
{
return mRanges[index];
}
void SynEditFoldRanges::clear()
void CodeFoldingRanges::clear()
{
mRanges.clear();
}
int SynEditFoldRanges::count() const
int CodeFoldingRanges::count() const
{
return mRanges.size();
}
SynEditFoldRanges::SynEditFoldRanges()
CodeFoldingRanges::CodeFoldingRanges()
{
}
PSynEditFoldRange SynEditFoldRanges::addByParts(PSynEditFoldRange aParent,
PSynEditFoldRanges aAllFold,
PCodeFoldingRange CodeFoldingRanges::addByParts(PCodeFoldingRange aParent,
PCodeFoldingRanges aAllFold,
int aFromLine,
PSynEditFoldRegion aFoldRegion,
PCodeFoldingDefine aFoldRegion,
int aToLine)
{
PSynEditFoldRange range=std::make_shared<SynEditFoldRange>(aParent,aAllFold, aFromLine,aFoldRegion,aToLine);
PCodeFoldingRange range=std::make_shared<CodeFoldingRange>(aParent,aAllFold, aFromLine,aFoldRegion,aToLine);
mRanges.append(range);
if (aAllFold && aAllFold.get()!=this) {
aAllFold->add(range);
@ -117,22 +123,24 @@ PSynEditFoldRange SynEditFoldRanges::addByParts(PSynEditFoldRange aParent,
return range;
}
void SynEditFoldRanges::insert(int index, PSynEditFoldRange range)
void CodeFoldingRanges::insert(int index, PCodeFoldingRange range)
{
mRanges.insert(index,range);
}
void SynEditFoldRanges::remove(int index)
void CodeFoldingRanges::remove(int index)
{
mRanges.remove(index);
}
void SynEditFoldRanges::add(PSynEditFoldRange foldRange)
void CodeFoldingRanges::add(PCodeFoldingRange foldRange)
{
mRanges.push_back(foldRange);
}
PSynEditFoldRange SynEditFoldRanges::operator[](int index) const
PCodeFoldingRange CodeFoldingRanges::operator[](int index) const
{
return mRanges[index];
}
}

View File

@ -21,77 +21,79 @@
#include <memory>
#include <QVector>
struct SynEditFoldRegion;
typedef std::shared_ptr<SynEditFoldRegion> PSynEditFoldRegion;
namespace QSynedit {
struct CodeFoldingDefine;
using PCodeFoldingDefine = std::shared_ptr<CodeFoldingDefine> ;
class SynEditFoldRegions {
class CodeFoldingDefines {
private:
std::vector<PSynEditFoldRegion> fRegions;
std::vector<PCodeFoldingDefine> fRegions;
public:
int count();
PSynEditFoldRegion add(bool addEnding, const QChar& openSymbol, const QChar& closeSymbol, const QString& highlight);
PSynEditFoldRegion get(int index);
PCodeFoldingDefine add(bool addEnding, const QChar& openSymbol, const QChar& closeSymbol, const QString& highlight);
PCodeFoldingDefine get(int index);
};
typedef std::shared_ptr<SynEditFoldRegions> PSynFoldRegions;
typedef std::shared_ptr<CodeFoldingDefines> PSynFoldRegions;
struct SynEditFoldRegion {
struct CodeFoldingDefine {
bool addEnding;
SynEditFoldRegions subFoldRegions;
CodeFoldingDefines subFoldRegions;
QChar openSymbol;
QChar closeSymbol;
QString highlight;
};
struct SynEditCodeFolding {
struct CodeFoldingOptions {
bool indentGuides;
bool fillIndents;
bool showCollapsedLine;
QColor collapsedLineColor;
QColor folderBarLinesColor;
QColor indentGuidesColor;
SynEditFoldRegions foldRegions;
SynEditCodeFolding();
CodeFoldingDefines foldRegions;
CodeFoldingOptions();
};
class SynEditFoldRange;
typedef std::shared_ptr<SynEditFoldRange> PSynEditFoldRange;
class SynEditFoldRanges;
typedef std::shared_ptr<SynEditFoldRanges> PSynEditFoldRanges;
class CodeFoldingRange;
typedef std::shared_ptr<CodeFoldingRange> PCodeFoldingRange;
class CodeFoldingRanges;
typedef std::shared_ptr<CodeFoldingRanges> PCodeFoldingRanges;
class SynEditFoldRanges{
class CodeFoldingRanges{
private:
QVector<PSynEditFoldRange> mRanges;
QVector<PCodeFoldingRange> mRanges;
public:
PSynEditFoldRange range(int index);
PCodeFoldingRange range(int index);
void clear();
int count() const;
SynEditFoldRanges();
PSynEditFoldRange addByParts(PSynEditFoldRange aParent, PSynEditFoldRanges aAllFold,
int aFromLine, PSynEditFoldRegion aFoldRegion, int aToLine);
CodeFoldingRanges();
PCodeFoldingRange addByParts(PCodeFoldingRange aParent, PCodeFoldingRanges aAllFold,
int aFromLine, PCodeFoldingDefine aFoldRegion, int aToLine);
void insert(int index, PSynEditFoldRange range);
void insert(int index, PCodeFoldingRange range);
void remove(int index);
void add(PSynEditFoldRange foldRange);
PSynEditFoldRange operator[](int index) const;
void add(PCodeFoldingRange foldRange);
PCodeFoldingRange operator[](int index) const;
};
// A single fold
class SynEditFoldRange {
class CodeFoldingRange {
public:
int fromLine; // Beginning line
int toLine; // End line
int linesCollapsed; // Number of collapsed lines
PSynEditFoldRanges subFoldRanges; // Sub fold ranges
PCodeFoldingRanges subFoldRanges; // Sub fold ranges
bool collapsed; // Is collapsed?
PSynEditFoldRanges allFoldRanges;// TAllFoldRanges pointer
PSynEditFoldRegion foldRegion; // FoldRegion
PCodeFoldingRanges allFoldRanges;// TAllFoldRanges pointer
PCodeFoldingDefine foldRegion; // FoldRegion
int hintMarkLeft;
PSynEditFoldRange parent;
PCodeFoldingRange parent;
bool parentCollapsed();
void move(int count);
explicit SynEditFoldRange(PSynEditFoldRange aParent, PSynEditFoldRanges aAllFold,
int aFromLine, PSynEditFoldRegion aFoldRegion, int aToLine);
explicit CodeFoldingRange(PCodeFoldingRange aParent, PCodeFoldingRanges aAllFold,
int aFromLine, PCodeFoldingDefine aFoldRegion, int aToLine);
};
}
#endif // CODEFOLDING_H

View File

@ -15,11 +15,13 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "Constants.h"
const QSet<QChar> SynWordBreakChars{'.', ',', ';', ':',
namespace QSynedit {
const QSet<QChar> WordBreakChars{'.', ',', ';', ':',
'"', '\'', '!', '?', '[', ']', '(', ')', '{', '}', '^', '-', '=', '+',
'-', '*', '/', '\\', '|'};
const QChar SynTabChar('\t');
const QChar SynTabGlyph(0x2192);
const QChar SynSpaceGlyph('.');
const QChar SynLineBreakGlyph(0x2193);
const QChar SynSoftBreakGlyph(0x2193);
const QChar TabGlyph(0x2192);
const QChar SpaceGlyph('.');
const QChar LineBreakGlyph(0x2193);
const QChar SoftBreakGlyph(0x2193);
}

View File

@ -19,12 +19,13 @@
#include <QSet>
#include <QChar>
extern const QSet<QChar> SynWordBreakChars;
extern const QChar SynTabChar;
extern const QChar SynSpaceGlyph;
extern const QChar SynTabGlyph;
extern const QChar SynLineBreakGlyph;
extern const QChar SynSoftBreakGlyph;
namespace QSynedit {
extern const QSet<QChar> WordBreakChars;
extern const QChar SpaceGlyph;
extern const QChar TabGlyph;
extern const QChar LineBreakGlyph;
extern const QChar SoftBreakGlyph;
#define MAX_SCROLL 65535
@ -183,4 +184,8 @@ extern const QChar SynSoftBreakGlyph;
#define SYN_HIGHLIGHTER_CPP "SynCppHighlighter"
#define SYN_HIGHLIGHTER_ASM "SynASMHighlighter"
#define SYN_HIGHLIGHTER_GLSL "SynGLSLHighlighter"
}
#endif // CONSTANTS_H

View File

@ -15,17 +15,19 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "KeyStrokes.h"
#include "MiscProcs.h"
SynEditKeyStroke::SynEditKeyStroke()
namespace QSynedit {
EditKeyStroke::EditKeyStroke()
{
mKey = 0;
mKeyModifiers = Qt::NoModifier;
mKey2 = 0;
mKeyModifiers2 = Qt::NoModifier;
mCommand = SynEditorCommand::ecNone;
mCommand = EditCommand::ecNone;
}
QKeySequence SynEditKeyStroke::keySequence() const
QKeySequence EditKeyStroke::keySequence() const
{
if (mKey2 == 0) {
return QKeySequence(mKey + mKeyModifiers);
@ -34,7 +36,7 @@ QKeySequence SynEditKeyStroke::keySequence() const
}
}
void SynEditKeyStroke::setKeySequence(QKeySequence &keySequence)
void EditKeyStroke::setKeySequence(QKeySequence &keySequence)
{
if (keySequence.isEmpty())
return;
@ -47,64 +49,64 @@ void SynEditKeyStroke::setKeySequence(QKeySequence &keySequence)
}
}
int SynEditKeyStroke::key() const
int EditKeyStroke::key() const
{
return mKey;
}
void SynEditKeyStroke::setKey(int key)
void EditKeyStroke::setKey(int key)
{
mKey = key;
}
Qt::KeyboardModifiers SynEditKeyStroke::keyModifiers() const
Qt::KeyboardModifiers EditKeyStroke::keyModifiers() const
{
return mKeyModifiers;
}
void SynEditKeyStroke::setKeyModifiers(const Qt::KeyboardModifiers &keyModifiers)
void EditKeyStroke::setKeyModifiers(const Qt::KeyboardModifiers &keyModifiers)
{
mKeyModifiers = keyModifiers;
}
int SynEditKeyStroke::key2() const
int EditKeyStroke::key2() const
{
return mKey2;
}
void SynEditKeyStroke::setKey2(int key2)
void EditKeyStroke::setKey2(int key2)
{
mKey2 = key2;
}
Qt::KeyboardModifiers SynEditKeyStroke::keyModifiers2() const
Qt::KeyboardModifiers EditKeyStroke::keyModifiers2() const
{
return mKeyModifiers2;
}
void SynEditKeyStroke::setKeyModifiers2(const Qt::KeyboardModifiers &keyModifiers2)
void EditKeyStroke::setKeyModifiers2(const Qt::KeyboardModifiers &keyModifiers2)
{
mKeyModifiers2 = keyModifiers2;
}
SynEditorCommand SynEditKeyStroke::command() const
EditCommand EditKeyStroke::command() const
{
return mCommand;
}
void SynEditKeyStroke::setCommand(const SynEditorCommand &command)
void EditKeyStroke::setCommand(const EditCommand &command)
{
mCommand = command;
}
SynKeyError::SynKeyError(const QString &reason):BaseError(reason)
KeyError::KeyError(const QString &reason):BaseError(reason)
{
}
PSynEditKeyStroke SynEditKeyStrokes::add(SynEditorCommand command, int key, Qt::KeyboardModifiers modifiers)
PEditKeyStroke EditKeyStrokes::add(EditCommand command, int key, Qt::KeyboardModifiers modifiers)
{
PSynEditKeyStroke keyStroke = std::make_shared<SynEditKeyStroke>();
PEditKeyStroke keyStroke = std::make_shared<EditKeyStroke>();
keyStroke->setKey(key);
keyStroke->setKeyModifiers(modifiers);
keyStroke->setCommand(command);
@ -112,40 +114,40 @@ PSynEditKeyStroke SynEditKeyStrokes::add(SynEditorCommand command, int key, Qt::
return keyStroke;
}
PSynEditKeyStroke SynEditKeyStrokes::findCommand(SynEditorCommand command)
PEditKeyStroke EditKeyStrokes::findCommand(EditCommand command)
{
for (PSynEditKeyStroke& keyStroke:mList) {
for (PEditKeyStroke& keyStroke:mList) {
if (keyStroke->command() == command)
return keyStroke;
}
return PSynEditKeyStroke();
return PEditKeyStroke();
}
PSynEditKeyStroke SynEditKeyStrokes::findKeycode(int key, Qt::KeyboardModifiers modifiers)
PEditKeyStroke EditKeyStrokes::findKeycode(int key, Qt::KeyboardModifiers modifiers)
{
for (PSynEditKeyStroke& keyStroke:mList) {
for (PEditKeyStroke& keyStroke:mList) {
if (keyStroke->key() == key
&& keyStroke->keyModifiers() == (modifiers & ~ Qt::KeypadModifier)
&& keyStroke->key2()==0)
return keyStroke;
}
return PSynEditKeyStroke();
return PEditKeyStroke();
}
PSynEditKeyStroke SynEditKeyStrokes::findKeycode2(int key, Qt::KeyboardModifiers modifiers,
PEditKeyStroke EditKeyStrokes::findKeycode2(int key, Qt::KeyboardModifiers modifiers,
int key2, Qt::KeyboardModifiers modifiers2)
{
for (PSynEditKeyStroke& keyStroke:mList) {
for (PEditKeyStroke& keyStroke:mList) {
if (keyStroke->key() == key
&& keyStroke->keyModifiers()==(modifiers & ~ Qt::KeypadModifier)
&& keyStroke->key2()==key2
&& keyStroke->keyModifiers2()== (modifiers2 & ~ Qt::KeypadModifier))
return keyStroke;
}
return PSynEditKeyStroke();
return PEditKeyStroke();
}
PSynEditKeyStroke SynEditKeyStrokes::findKeySequence(const QKeySequence &keySeq)
PEditKeyStroke EditKeyStrokes::findKeySequence(const QKeySequence &keySeq)
{
switch (keySeq.count()) {
case 1: {
@ -167,75 +169,75 @@ PSynEditKeyStroke SynEditKeyStrokes::findKeySequence(const QKeySequence &keySeq)
return findKeycode2(key,modifiers,key2,modifiers2);
}
default:
return PSynEditKeyStroke();
return PEditKeyStroke();
}
}
void SynEditKeyStrokes::clear()
void EditKeyStrokes::clear()
{
return mList.clear();
}
void SynEditKeyStrokes::resetDefaults()
void EditKeyStrokes::resetDefaults()
{
clear();
add(SynEditorCommand::ecUp, Qt::Key_Up, Qt::NoModifier);
add(SynEditorCommand::ecSelUp, Qt::Key_Up, Qt::ShiftModifier);
add(SynEditorCommand::ecSelUp, Qt::Key_Up, Qt::ShiftModifier | Qt::AltModifier);
add(SynEditorCommand::ecScrollUp, Qt::Key_Up, Qt::ControlModifier);
add(SynEditorCommand::ecDown, Qt::Key_Down, Qt::NoModifier);
add(SynEditorCommand::ecSelDown, Qt::Key_Down, Qt::ShiftModifier);
add(SynEditorCommand::ecSelDown, Qt::Key_Down, Qt::ShiftModifier | Qt::AltModifier);
add(SynEditorCommand::ecScrollDown, Qt::Key_Down, Qt::ControlModifier);
add(SynEditorCommand::ecLeft, Qt::Key_Left, Qt::NoModifier);
add(SynEditorCommand::ecSelLeft, Qt::Key_Left, Qt::ShiftModifier);
add(SynEditorCommand::ecWordLeft, Qt::Key_Left, Qt::ControlModifier);
add(SynEditorCommand::ecSelWordLeft, Qt::Key_Left, Qt::ShiftModifier|Qt::ControlModifier);
add(SynEditorCommand::ecRight, Qt::Key_Right, Qt::NoModifier);
add(SynEditorCommand::ecSelRight, Qt::Key_Right, Qt::ShiftModifier);
add(SynEditorCommand::ecWordRight, Qt::Key_Right, Qt::ControlModifier);
add(SynEditorCommand::ecSelWordRight, Qt::Key_Right, Qt::ShiftModifier|Qt::ControlModifier);
add(EditCommand::ecUp, Qt::Key_Up, Qt::NoModifier);
add(EditCommand::ecSelUp, Qt::Key_Up, Qt::ShiftModifier);
add(EditCommand::ecSelUp, Qt::Key_Up, Qt::ShiftModifier | Qt::AltModifier);
add(EditCommand::ecScrollUp, Qt::Key_Up, Qt::ControlModifier);
add(EditCommand::ecDown, Qt::Key_Down, Qt::NoModifier);
add(EditCommand::ecSelDown, Qt::Key_Down, Qt::ShiftModifier);
add(EditCommand::ecSelDown, Qt::Key_Down, Qt::ShiftModifier | Qt::AltModifier);
add(EditCommand::ecScrollDown, Qt::Key_Down, Qt::ControlModifier);
add(EditCommand::ecLeft, Qt::Key_Left, Qt::NoModifier);
add(EditCommand::ecSelLeft, Qt::Key_Left, Qt::ShiftModifier);
add(EditCommand::ecWordLeft, Qt::Key_Left, Qt::ControlModifier);
add(EditCommand::ecSelWordLeft, Qt::Key_Left, Qt::ShiftModifier|Qt::ControlModifier);
add(EditCommand::ecRight, Qt::Key_Right, Qt::NoModifier);
add(EditCommand::ecSelRight, Qt::Key_Right, Qt::ShiftModifier);
add(EditCommand::ecWordRight, Qt::Key_Right, Qt::ControlModifier);
add(EditCommand::ecSelWordRight, Qt::Key_Right, Qt::ShiftModifier|Qt::ControlModifier);
// add(SynEditorCommand::ecExpandSelection, Qt::Key_Right, Qt::ShiftModifier|Qt::AltModifier);
// add(SynEditorCommand::ecShrinkSelection, Qt::Key_Left, Qt::ShiftModifier | Qt::AltModifier);
add(SynEditorCommand::ecPageDown, Qt::Key_PageDown, Qt::NoModifier);
add(SynEditorCommand::ecSelPageDown, Qt::Key_PageDown, Qt::ShiftModifier);
add(SynEditorCommand::ecPageBottom, Qt::Key_PageDown, Qt::ControlModifier);
add(SynEditorCommand::ecSelPageBottom, Qt::Key_PageDown, Qt::ShiftModifier|Qt::ControlModifier);
add(SynEditorCommand::ecPageUp, Qt::Key_PageUp, Qt::NoModifier);
add(SynEditorCommand::ecSelPageUp, Qt::Key_PageUp, Qt::ShiftModifier);
add(SynEditorCommand::ecPageTop, Qt::Key_PageUp, Qt::ControlModifier);
add(SynEditorCommand::ecSelPageTop, Qt::Key_PageUp, Qt::ShiftModifier|Qt::ControlModifier);
add(SynEditorCommand::ecLineStart, Qt::Key_Home, Qt::NoModifier);
add(SynEditorCommand::ecSelLineStart, Qt::Key_Home, Qt::ShiftModifier);
add(SynEditorCommand::ecEditorStart, Qt::Key_Home, Qt::ControlModifier);
add(SynEditorCommand::ecSelEditorStart, Qt::Key_Home, Qt::ShiftModifier|Qt::ControlModifier);
add(SynEditorCommand::ecLineEnd, Qt::Key_End, Qt::NoModifier);
add(SynEditorCommand::ecSelLineEnd, Qt::Key_End, Qt::ShiftModifier);
add(SynEditorCommand::ecEditorEnd, Qt::Key_End, Qt::ControlModifier);
add(SynEditorCommand::ecSelEditorEnd, Qt::Key_End, Qt::ShiftModifier|Qt::ControlModifier);
add(SynEditorCommand::ecToggleMode, Qt::Key_Insert, Qt::NoModifier);
add(EditCommand::ecPageDown, Qt::Key_PageDown, Qt::NoModifier);
add(EditCommand::ecSelPageDown, Qt::Key_PageDown, Qt::ShiftModifier);
add(EditCommand::ecPageBottom, Qt::Key_PageDown, Qt::ControlModifier);
add(EditCommand::ecSelPageBottom, Qt::Key_PageDown, Qt::ShiftModifier|Qt::ControlModifier);
add(EditCommand::ecPageUp, Qt::Key_PageUp, Qt::NoModifier);
add(EditCommand::ecSelPageUp, Qt::Key_PageUp, Qt::ShiftModifier);
add(EditCommand::ecPageTop, Qt::Key_PageUp, Qt::ControlModifier);
add(EditCommand::ecSelPageTop, Qt::Key_PageUp, Qt::ShiftModifier|Qt::ControlModifier);
add(EditCommand::ecLineStart, Qt::Key_Home, Qt::NoModifier);
add(EditCommand::ecSelLineStart, Qt::Key_Home, Qt::ShiftModifier);
add(EditCommand::ecEditorStart, Qt::Key_Home, Qt::ControlModifier);
add(EditCommand::ecSelEditorStart, Qt::Key_Home, Qt::ShiftModifier|Qt::ControlModifier);
add(EditCommand::ecLineEnd, Qt::Key_End, Qt::NoModifier);
add(EditCommand::ecSelLineEnd, Qt::Key_End, Qt::ShiftModifier);
add(EditCommand::ecEditorEnd, Qt::Key_End, Qt::ControlModifier);
add(EditCommand::ecSelEditorEnd, Qt::Key_End, Qt::ShiftModifier|Qt::ControlModifier);
add(EditCommand::ecToggleMode, Qt::Key_Insert, Qt::NoModifier);
// add(SynEditorCommand::ecCopy, Qt::Key_Insert, Qt::ControlModifier);
// add(SynEditorCommand::ecCut, Qt::Key_Delete, Qt::ShiftModifier);
// add(SynEditorCommand::ecPaste, Qt::Key_Insert, Qt::ShiftModifier);
add(SynEditorCommand::ecDeleteChar, Qt::Key_Delete, Qt::NoModifier);
add(SynEditorCommand::ecDeleteLastChar, Qt::Key_Backspace, Qt::NoModifier);
add(EditCommand::ecDeleteChar, Qt::Key_Delete, Qt::NoModifier);
add(EditCommand::ecDeleteLastChar, Qt::Key_Backspace, Qt::NoModifier);
// add(SynEditorCommand::ecDeleteLastChar, Qt::Key_Backspace, Qt::ShiftModifier);
// add(SynEditorCommand::ecDeleteWordStart, Qt::Key_Backspace, Qt::ControlModifier);
// add(SynEditorCommand::ecDeleteWordEnd, Qt::Key_Delete, Qt::ControlModifier);
// add(SynEditorCommand::ecUndo, Qt::Key_Backspace, Qt::AltModifier);
// add(SynEditorCommand::ecRedo, Qt::Key_Backspace, Qt::AltModifier|Qt::ShiftModifier);
add(SynEditorCommand::ecLineBreak, Qt::Key_Return, Qt::NoModifier);
add(SynEditorCommand::ecLineBreak, Qt::Key_Return, Qt::ShiftModifier);
add(SynEditorCommand::ecLineBreakAtEnd, Qt::Key_Return, Qt::ControlModifier);
add(SynEditorCommand::ecLineBreak, Qt::Key_Enter, Qt::NoModifier);
add(SynEditorCommand::ecLineBreak, Qt::Key_Enter, Qt::ShiftModifier);
add(SynEditorCommand::ecLineBreakAtEnd, Qt::Key_Enter, Qt::ControlModifier);
add(EditCommand::ecLineBreak, Qt::Key_Return, Qt::NoModifier);
add(EditCommand::ecLineBreak, Qt::Key_Return, Qt::ShiftModifier);
add(EditCommand::ecLineBreakAtEnd, Qt::Key_Return, Qt::ControlModifier);
add(EditCommand::ecLineBreak, Qt::Key_Enter, Qt::NoModifier);
add(EditCommand::ecLineBreak, Qt::Key_Enter, Qt::ShiftModifier);
add(EditCommand::ecLineBreakAtEnd, Qt::Key_Enter, Qt::ControlModifier);
// add(SynEditorCommand::ecTab, Qt::Key_Tab, Qt::NoModifier);
// add(SynEditorCommand::ecShiftTab, Qt::Key_Backtab, Qt::ShiftModifier);
// add(SynEditorCommand::ecShiftTab, Qt::Key_Tab, Qt::ShiftModifier);
add(SynEditorCommand::ecContextHelp, Qt::Key_F1, Qt::NoModifier);
add(EditCommand::ecContextHelp, Qt::Key_F1, Qt::NoModifier);
// add(SynEditorCommand::ecSelectAll, Qt::Key_A, Qt::ControlModifier);
// add(SynEditorCommand::ecCopy, Qt::Key_C, Qt::ControlModifier);
@ -258,19 +260,21 @@ void SynEditKeyStrokes::resetDefaults()
// add(SynEditorCommand::ecMatchBracket, Qt::Key_B, Qt::ControlModifier | Qt::ShiftModifier);
}
void SynEditKeyStrokes::setExtraKeyStrokes()
void EditKeyStrokes::setExtraKeyStrokes()
{
add(SynEditorCommand::ecDeleteWordStart, Qt::Key_Backspace, Qt::ControlModifier);
add(SynEditorCommand::ecDeleteWordEnd, Qt::Key_Delete, Qt::ControlModifier);
add(EditCommand::ecDeleteWordStart, Qt::Key_Backspace, Qt::ControlModifier);
add(EditCommand::ecDeleteWordEnd, Qt::Key_Delete, Qt::ControlModifier);
add(SynEditorCommand::ecDuplicateLine, Qt::Key_D, Qt::ControlModifier);
add(SynEditorCommand::ecDeleteLine, Qt::Key_E, Qt::ControlModifier);
add(EditCommand::ecDuplicateLine, Qt::Key_D, Qt::ControlModifier);
add(EditCommand::ecDeleteLine, Qt::Key_E, Qt::ControlModifier);
add(SynEditorCommand::ecSelectAll, Qt::Key_A, Qt::ControlModifier);
add(SynEditorCommand::ecCopy, Qt::Key_C, Qt::ControlModifier);
add(SynEditorCommand::ecPaste, Qt::Key_V, Qt::ControlModifier);
add(SynEditorCommand::ecCut, Qt::Key_X, Qt::ControlModifier);
add(EditCommand::ecSelectAll, Qt::Key_A, Qt::ControlModifier);
add(EditCommand::ecCopy, Qt::Key_C, Qt::ControlModifier);
add(EditCommand::ecPaste, Qt::Key_V, Qt::ControlModifier);
add(EditCommand::ecCut, Qt::Key_X, Qt::ControlModifier);
add(EditCommand::ecUndo, Qt::Key_Z, Qt::ControlModifier);
add(EditCommand::ecRedo, Qt::Key_Y, Qt::ControlModifier);
}
add(SynEditorCommand::ecUndo, Qt::Key_Z, Qt::ControlModifier);
add(SynEditorCommand::ecRedo, Qt::Key_Y, Qt::ControlModifier);
}

View File

@ -17,10 +17,13 @@
#ifndef SYNEDITKEYSTROKE_H
#define SYNEDITKEYSTROKE_H
#include "../utils.h"
#include <QKeySequence>
#include <QList>
#include <memory>
#include "MiscClasses.h"
#include "qt_utils/utils.h"
namespace QSynedit {
//****************************************************************************
// NOTE! If you add an editor command, you must also update the
// EditorCommandStrs constant array in implementation section below, or the
@ -35,7 +38,7 @@
// valid, while the ecEditXXX commands are ignored when the editor is in
// read-only mode
enum class SynEditorCommand {
enum class EditCommand {
ecNone = 0, // Nothing. Useful for user event to handle command
ecViewCommandFirst = 0,
ecViewCommandLast = 500,
@ -172,15 +175,15 @@ enum class SynEditorCommand {
};
class SynKeyError: public BaseError {
class KeyError: public BaseError {
public:
explicit SynKeyError(const QString& reason);
explicit KeyError(const QString& reason);
};
class SynEditKeyStroke
class EditKeyStroke
{
public:
explicit SynEditKeyStroke();
explicit EditKeyStroke();
QKeySequence keySequence() const;
void setKeySequence(QKeySequence& keySequence);
int key() const;
@ -195,34 +198,36 @@ public:
Qt::KeyboardModifiers keyModifiers2() const;
void setKeyModifiers2(const Qt::KeyboardModifiers &keyModifiers2);
SynEditorCommand command() const;
void setCommand(const SynEditorCommand &command);
EditCommand command() const;
void setCommand(const EditCommand &command);
private:
int mKey; // Virtual keycode, i.e. VK_xxx
Qt::KeyboardModifiers mKeyModifiers;
int mKey2;
Qt::KeyboardModifiers mKeyModifiers2;
SynEditorCommand mCommand;
EditCommand mCommand;
};
using PSynEditKeyStroke = std::shared_ptr<SynEditKeyStroke>;
using SynEditKeyStrokeList = QList<PSynEditKeyStroke>;
using PEditKeyStroke = std::shared_ptr<EditKeyStroke>;
using EditKeyStrokeList = QList<PEditKeyStroke>;
class SynEditKeyStrokes {
class EditKeyStrokes {
public:
PSynEditKeyStroke add(SynEditorCommand command, int key, Qt::KeyboardModifiers modifiers);
PSynEditKeyStroke findCommand(SynEditorCommand command);
PSynEditKeyStroke findKeycode(int key, Qt::KeyboardModifiers modifiers);
PSynEditKeyStroke findKeycode2(int key, Qt::KeyboardModifiers modifiers,
PEditKeyStroke add(EditCommand command, int key, Qt::KeyboardModifiers modifiers);
PEditKeyStroke findCommand(EditCommand command);
PEditKeyStroke findKeycode(int key, Qt::KeyboardModifiers modifiers);
PEditKeyStroke findKeycode2(int key, Qt::KeyboardModifiers modifiers,
int key2, Qt::KeyboardModifiers modifiers2);
PSynEditKeyStroke findKeySequence(const QKeySequence& keySeq);
PEditKeyStroke findKeySequence(const QKeySequence& keySeq);
void clear();
void resetDefaults();
void setExtraKeyStrokes();
private:
SynEditKeyStrokeList mList;
EditKeyStrokeList mList;
};
}
#endif // SYNEDITKEYSTROKE_H

View File

@ -17,7 +17,9 @@
#include "MiscClasses.h"
#include "algorithm"
SynGutter::SynGutter(QObject *parent):
namespace QSynedit {
Gutter::Gutter(QObject *parent):
QObject(parent)
{
mFont = QFont("Courier New",10);
@ -33,7 +35,7 @@ SynGutter::SynGutter(QObject *parent):
mUseFontStyle = true;
mAutoSize = true;
mAutoSizeDigitCount = mDigitCount;
mBorderStyle = SynGutterBorderStyle::Middle;
mBorderStyle = GutterBorderStyle::Middle;
mLineNumberStart = 1;
mGradient = false;
mGradientStartColor = Qt::transparent;
@ -41,12 +43,12 @@ SynGutter::SynGutter(QObject *parent):
mGradientSteps = 48;
}
QFont SynGutter::font() const
QFont Gutter::font() const
{
return mFont;
}
void SynGutter::setFont(const QFont &font)
void Gutter::setFont(const QFont &font)
{
if (mFont != font) {
mFont = font;
@ -54,12 +56,12 @@ void SynGutter::setFont(const QFont &font)
}
}
bool SynGutter::autoSize() const
bool Gutter::autoSize() const
{
return mAutoSize;
}
void SynGutter::setAutoSize(bool value)
void Gutter::setAutoSize(bool value)
{
if (mAutoSize != value) {
mAutoSize = value;
@ -67,27 +69,27 @@ void SynGutter::setAutoSize(bool value)
}
}
void SynGutter::setChanged()
void Gutter::setChanged()
{
emit changed();
}
const QColor &SynGutter::activeLineTextColor() const
const QColor &Gutter::activeLineTextColor() const
{
return mActiveLineTextColor;
}
void SynGutter::setActiveLineTextColor(const QColor &newActiveLineTextColor)
void Gutter::setActiveLineTextColor(const QColor &newActiveLineTextColor)
{
mActiveLineTextColor = newActiveLineTextColor;
}
QColor SynGutter::textColor() const
QColor Gutter::textColor() const
{
return mTextColor;
}
void SynGutter::setTextColor(const QColor &value)
void Gutter::setTextColor(const QColor &value)
{
if (mTextColor!=value) {
mTextColor = value;
@ -95,7 +97,7 @@ void SynGutter::setTextColor(const QColor &value)
}
}
void SynGutter::autoSizeDigitCount(int linesCount)
void Gutter::autoSizeDigitCount(int linesCount)
{
if (mVisible && mAutoSize && mShowLineNumbers) {
linesCount += (mLineNumberStart - 1);
@ -107,7 +109,7 @@ void SynGutter::autoSizeDigitCount(int linesCount)
}
}
QString SynGutter::formatLineNumber(int line)
QString Gutter::formatLineNumber(int line)
{
line += (mLineNumberStart - 1);
QString result = QString::number(line);
@ -118,7 +120,7 @@ QString SynGutter::formatLineNumber(int line)
}
}
int SynGutter::realGutterWidth(int charWidth)
int Gutter::realGutterWidth(int charWidth)
{
if (!mVisible) {
return 0;
@ -129,12 +131,12 @@ int SynGutter::realGutterWidth(int charWidth)
return mLeftOffset + mRightOffset;
}
bool SynGutter::visible() const
bool Gutter::visible() const
{
return mVisible;
}
void SynGutter::setVisible(bool visible)
void Gutter::setVisible(bool visible)
{
if (mVisible!=visible) {
mVisible = visible;
@ -142,12 +144,12 @@ void SynGutter::setVisible(bool visible)
}
}
bool SynGutter::useFontStyle() const
bool Gutter::useFontStyle() const
{
return mUseFontStyle;
}
void SynGutter::setUseFontStyle(bool useFontStyle)
void Gutter::setUseFontStyle(bool useFontStyle)
{
if (mUseFontStyle!=useFontStyle) {
mUseFontStyle = useFontStyle;
@ -155,12 +157,12 @@ void SynGutter::setUseFontStyle(bool useFontStyle)
}
}
bool SynGutter::showLineNumbers() const
bool Gutter::showLineNumbers() const
{
return mShowLineNumbers;
}
void SynGutter::setShowLineNumbers(bool showLineNumbers)
void Gutter::setShowLineNumbers(bool showLineNumbers)
{
if (mShowLineNumbers!=showLineNumbers) {
mShowLineNumbers = showLineNumbers;
@ -168,12 +170,12 @@ void SynGutter::setShowLineNumbers(bool showLineNumbers)
}
}
int SynGutter::rightOffset() const
int Gutter::rightOffset() const
{
return mRightOffset;
}
void SynGutter::setRightOffset(int rightOffset)
void Gutter::setRightOffset(int rightOffset)
{
int value = std::max(0, rightOffset);
if (mRightOffset != value) {
@ -182,12 +184,12 @@ void SynGutter::setRightOffset(int rightOffset)
}
}
int SynGutter::lineNumberStart() const
int Gutter::lineNumberStart() const
{
return mLineNumberStart;
}
void SynGutter::setLineNumberStart(int lineNumberStart)
void Gutter::setLineNumberStart(int lineNumberStart)
{
int value = std::max(0,lineNumberStart);
if (mLineNumberStart!=value) {
@ -196,17 +198,17 @@ void SynGutter::setLineNumberStart(int lineNumberStart)
}
}
bool SynGutter::zeroStart()
bool Gutter::zeroStart()
{
return mLineNumberStart == 0;
}
int SynGutter::leftOffset() const
int Gutter::leftOffset() const
{
return mLeftOffset;
}
void SynGutter::setLeftOffset(int leftOffset)
void Gutter::setLeftOffset(int leftOffset)
{
int value = std::max(0,leftOffset);
if (mLeftOffset != value) {
@ -215,12 +217,12 @@ void SynGutter::setLeftOffset(int leftOffset)
}
}
bool SynGutter::leadingZeros() const
bool Gutter::leadingZeros() const
{
return mLeadingZeros;
}
void SynGutter::setLeadingZeros(bool value)
void Gutter::setLeadingZeros(bool value)
{
if (mLeadingZeros!=value) {
mLeadingZeros = value;
@ -228,12 +230,12 @@ void SynGutter::setLeadingZeros(bool value)
}
}
int SynGutter::gradientSteps() const
int Gutter::gradientSteps() const
{
return mGradientSteps;
}
void SynGutter::setGradientSteps(int value)
void Gutter::setGradientSteps(int value)
{
if (mGradientSteps!=value) {
mGradientSteps = value;
@ -243,12 +245,12 @@ void SynGutter::setGradientSteps(int value)
}
}
QColor SynGutter::gradientEndColor() const
QColor Gutter::gradientEndColor() const
{
return mGradientEndColor;
}
void SynGutter::setGradientEndColor(const QColor &value)
void Gutter::setGradientEndColor(const QColor &value)
{
if (mGradientEndColor!=value) {
mGradientEndColor = value;
@ -256,12 +258,12 @@ void SynGutter::setGradientEndColor(const QColor &value)
}
}
QColor SynGutter::gradientStartColor() const
QColor Gutter::gradientStartColor() const
{
return mGradientStartColor;
}
void SynGutter::setGradientStartColor(const QColor &value)
void Gutter::setGradientStartColor(const QColor &value)
{
if (mGradientStartColor!=value) {
mGradientStartColor = value;
@ -269,12 +271,12 @@ void SynGutter::setGradientStartColor(const QColor &value)
}
}
bool SynGutter::gradient() const
bool Gutter::gradient() const
{
return mGradient;
}
void SynGutter::setGradient(bool value)
void Gutter::setGradient(bool value)
{
if (mGradient!=value){
mGradient = value;
@ -282,12 +284,12 @@ void SynGutter::setGradient(bool value)
}
}
SynGutterBorderStyle SynGutter::borderStyle() const
GutterBorderStyle Gutter::borderStyle() const
{
return mBorderStyle;
}
void SynGutter::setBorderStyle(const SynGutterBorderStyle &value)
void Gutter::setBorderStyle(const GutterBorderStyle &value)
{
if (mBorderStyle!=value) {
mBorderStyle = value;
@ -295,12 +297,12 @@ void SynGutter::setBorderStyle(const SynGutterBorderStyle &value)
}
}
int SynGutter::digitCount() const
int Gutter::digitCount() const
{
return mDigitCount;
}
void SynGutter::setDigitCount(int value)
void Gutter::setDigitCount(int value)
{
if (mDigitCount != value ) {
mDigitCount = value;
@ -308,12 +310,12 @@ void SynGutter::setDigitCount(int value)
}
}
QColor SynGutter::color() const
QColor Gutter::color() const
{
return mColor;
}
void SynGutter::setColor(const QColor &value)
void Gutter::setColor(const QColor &value)
{
if (mColor!=value) {
mColor = value;
@ -321,15 +323,17 @@ void SynGutter::setColor(const QColor &value)
}
}
QColor SynGutter::borderColor() const
QColor Gutter::borderColor() const
{
return mBorderColor;
}
void SynGutter::setBorderColor(const QColor &value)
void Gutter::setBorderColor(const QColor &value)
{
if (mBorderColor!=value) {
mBorderColor = value;
setChanged();
}
}
}

View File

@ -22,16 +22,18 @@
#include <QObject>
#include "Types.h"
enum class SynGutterBorderStyle {
namespace QSynedit {
enum class GutterBorderStyle {
None,
Middle,
Right
};
class SynGutter : public QObject {
class Gutter : public QObject {
Q_OBJECT
public:
explicit SynGutter(QObject* parent = nullptr);
explicit Gutter(QObject* parent = nullptr);
QFont font() const;
void setFont(const QFont &value);
@ -47,8 +49,8 @@ public:
int digitCount() const;
void setDigitCount(int value);
SynGutterBorderStyle borderStyle() const;
void setBorderStyle(const SynGutterBorderStyle &value);
GutterBorderStyle borderStyle() const;
void setBorderStyle(const GutterBorderStyle &value);
bool gradient() const;
void setGradient(bool value);
@ -116,12 +118,14 @@ private:
int mLineNumberStart;
int mRightOffset;
bool mShowLineNumbers;
SynGutterBorderStyle mBorderStyle;
GutterBorderStyle mBorderStyle;
bool mUseFontStyle;
bool mVisible;
int mAutoSizeDigitCount;
};
using PSynGutter = std::shared_ptr<SynGutter>;
using PSynGutter = std::shared_ptr<Gutter>;
}
#endif // MISCCLASSES_H

View File

@ -19,42 +19,16 @@
#include <QPainter>
#include <QTextStream>
#include <algorithm>
#include <QApplication>
#include <QScreen>
namespace QSynedit {
int minMax(int x, int mi, int ma)
{
x = std::min(x, ma );
return std::max( x, mi );
}
bool IsPowerOfTwo(int TabWidth) {
if (TabWidth<2)
return false;
int nW = 2;
do {
if (nW >= TabWidth)
break;
nW <<= 1;
} while (nW<0x10000);
return (nW == TabWidth);
}
bool GetHasTabs(const QString &line, int &CharsBefore)
{
bool result = false;
CharsBefore = 0;
if (!line.isEmpty()) {
for (const QChar& ch:line) {
if (ch == '\t') {
result = true;
break;
}
CharsBefore ++;
}
}
return result;
}
int getEOL(const QString &Line, int start)
{
if (start<0 || start>=Line.size()) {
@ -68,11 +42,11 @@ int getEOL(const QString &Line, int start)
return Line.size();
}
bool InternalEnumHighlighterAttris(PSynHighlighter Highlighter,
bool internalEnumHighlighterAttris(PHighlighter Highlighter,
bool SkipDuplicates,
HighlighterAttriProc highlighterAttriProc,
std::initializer_list<void *>& Params,
SynHighlighterList& HighlighterList) {
HighlighterList& HighlighterList) {
bool Result = true;
if (HighlighterList.indexOf(Highlighter)>0) {
if (SkipDuplicates)
@ -80,10 +54,10 @@ bool InternalEnumHighlighterAttris(PSynHighlighter Highlighter,
} else {
HighlighterList.append(Highlighter);
}
if (Highlighter->getClass() == SynHighlighterClass::Composition) {
if (Highlighter->getClass() == HighlighterClass::Composition) {
//todo: handle composition highlighter
} else if (Highlighter) {
for (PSynHighlighterAttribute pAttr: Highlighter->attributes()){
for (PHighlighterAttribute pAttr: Highlighter->attributes()){
QString UniqueAttriName = Highlighter->getName()
+ QString("%1").arg(HighlighterList.indexOf(Highlighter)) + '.'
+ pAttr->name();
@ -96,7 +70,7 @@ bool InternalEnumHighlighterAttris(PSynHighlighter Highlighter,
return Result;
}
bool enumHighlighterAttributes(PSynHighlighter Highlighter, bool SkipDuplicates,
bool enumHighlighterAttributes(PHighlighter Highlighter, bool SkipDuplicates,
HighlighterAttriProc highlighterAttriProc,
std::initializer_list<void *> Params)
{
@ -104,8 +78,8 @@ bool enumHighlighterAttributes(PSynHighlighter Highlighter, bool SkipDuplicates,
return false;
}
SynHighlighterList HighlighterList;
return InternalEnumHighlighterAttris(Highlighter, SkipDuplicates,
HighlighterList HighlighterList;
return internalEnumHighlighterAttris(Highlighter, SkipDuplicates,
highlighterAttriProc, Params, HighlighterList);
}
@ -115,13 +89,13 @@ int mulDiv(int a, int b, int c)
return a*b/c;
}
SynFontStyles getFontStyles(const QFont &font)
FontStyles getFontStyles(const QFont &font)
{
SynFontStyles styles;
styles.setFlag(SynFontStyle::fsBold, font.bold());
styles.setFlag(SynFontStyle::fsItalic, font.italic());
styles.setFlag(SynFontStyle::fsUnderline, font.underline());
styles.setFlag(SynFontStyle::fsStrikeOut, font.strikeOut());
FontStyles styles;
styles.setFlag(FontStyle::fsBold, font.bold());
styles.setFlag(FontStyle::fsItalic, font.italic());
styles.setFlag(FontStyle::fsUnderline, font.underline());
styles.setFlag(FontStyle::fsStrikeOut, font.strikeOut());
return styles;
}
@ -226,3 +200,5 @@ int calSpanLines(const BufferCoord &startPos, const BufferCoord &endPos)
{
return std::abs(endPos.line - startPos.line+1);
}
}

View File

@ -33,6 +33,8 @@ class QPainter;
class QRect;
class QColor;
namespace QSynedit {
int minMax(int x, int mi, int ma);
int mulDiv(int a, int b, int c);
BufferCoord maxBufferCoord(const BufferCoord& P1, const BufferCoord& P2);
@ -44,18 +46,18 @@ QStringList splitStrings(const QString& text);
int calSpanLines(const BufferCoord& startPos, const BufferCoord& endPos);
using HighlighterAttriProc = std::function<bool(PSynHighlighter Highlighter,
PSynHighlighterAttribute Attri, const QString& UniqueAttriName,
using HighlighterAttriProc = std::function<bool(PHighlighter Highlighter,
PHighlighterAttribute Attri, const QString& UniqueAttriName,
QList<void *> Params)>;
// Enums all child highlighters and their attributes of a TSynMultiSyn through a
// callback function.
// This function also handles nested TSynMultiSyns including their MarkerAttri.
bool enumHighlighterAttributes(PSynHighlighter Highlighter,
bool enumHighlighterAttributes(PHighlighter Highlighter,
bool SkipDuplicates, HighlighterAttriProc highlighterAttriProc,
std::initializer_list<void *> Params);
SynFontStyles getFontStyles(const QFont& font);
FontStyles getFontStyles(const QFont& font);
/**
* Find the first occurency of word char in s, starting from startPos
@ -88,5 +90,5 @@ int findLastNonWordChar(const QString& s, int startPos);
void ensureNotAfter(BufferCoord& cord1, BufferCoord& cord2);
bool isWordChar(const QChar& ch);
}
#endif // MISCPROCS_H

View File

@ -16,31 +16,33 @@
*/
#include "Search.h"
SynSearch::SynSearch(QObject *parent):SynSearchBase(parent)
namespace QSynedit {
BasicSearcher::BasicSearcher(QObject *parent):BaseSearcher(parent)
{
}
int SynSearch::length(int aIndex)
int BasicSearcher::length(int aIndex)
{
if (aIndex<0 || aIndex >= mResults.length())
return 0;
return pattern().length();
}
int SynSearch::result(int aIndex)
int BasicSearcher::result(int aIndex)
{
if (aIndex<0 || aIndex >= mResults.length())
return -1;
return mResults[aIndex];
}
int SynSearch::resultCount()
int BasicSearcher::resultCount()
{
return mResults.count();
}
int SynSearch::findAll(const QString &text)
int BasicSearcher::findAll(const QString &text)
{
mResults.clear();
if (pattern().isEmpty())
@ -72,12 +74,13 @@ int SynSearch::findAll(const QString &text)
return mResults.size();
}
QString SynSearch::replace(const QString &, const QString &aReplacement)
QString BasicSearcher::replace(const QString &, const QString &aReplacement)
{
return aReplacement;
}
bool SynSearch::isDelimitChar(QChar ch)
bool BasicSearcher::isDelimitChar(QChar ch)
{
return !(ch == '_' || ch.isLetterOrNumber());
}
}

View File

@ -18,12 +18,13 @@
#define SYNSEARCH_H
#include "SearchBase.h"
namespace QSynedit {
class SynSearch : public SynSearchBase
class BasicSearcher : public BaseSearcher
{
Q_OBJECT
public:
explicit SynSearch(QObject* parent = nullptr);
explicit BasicSearcher(QObject* parent = nullptr);
// SynSearchBase interface
public:
@ -37,5 +38,6 @@ private:
private:
QList<int> mResults;
};
}
#endif // SYNSEARCH_H

View File

@ -16,27 +16,29 @@
*/
#include "SearchBase.h"
SynSearchBase::SynSearchBase(QObject *parent) : QObject(parent)
namespace QSynedit {
BaseSearcher::BaseSearcher(QObject *parent) : QObject(parent)
{
}
QString SynSearchBase::pattern()
QString BaseSearcher::pattern()
{
return mPattern;
}
void SynSearchBase::setPattern(const QString &value)
void BaseSearcher::setPattern(const QString &value)
{
mPattern = value;
}
SynSearchOptions SynSearchBase::options() const
SearchOptions BaseSearcher::options() const
{
return mOptions;
}
void SynSearchBase::setOptions(const SynSearchOptions &options)
void BaseSearcher::setOptions(const SearchOptions &options)
{
mOptions = options;
}
}

View File

@ -20,7 +20,9 @@
#include <QObject>
#include <memory>
enum SynSearchOption {
namespace QSynedit {
enum SearchOption {
ssoMatchCase = 0x0001,
ssoWholeWord = 0x0002,
ssoBackwards = 0x0004,
@ -30,14 +32,14 @@ enum SynSearchOption {
ssoRegExp = 0x0080
};
Q_DECLARE_FLAGS(SynSearchOptions, SynSearchOption)
Q_DECLARE_OPERATORS_FOR_FLAGS(SynSearchOptions)
Q_DECLARE_FLAGS(SearchOptions, SearchOption)
Q_DECLARE_OPERATORS_FOR_FLAGS(SearchOptions)
class SynSearchBase : public QObject
class BaseSearcher : public QObject
{
Q_OBJECT
public:
explicit SynSearchBase(QObject *parent = nullptr);
explicit BaseSearcher(QObject *parent = nullptr);
QString pattern();
virtual void setPattern(const QString& value);
virtual int length(int aIndex) = 0;
@ -45,14 +47,16 @@ public:
virtual int resultCount() = 0;
virtual int findAll(const QString& text) = 0;
virtual QString replace(const QString& aOccurrence, const QString& aReplacement) = 0;
SynSearchOptions options() const;
virtual void setOptions(const SynSearchOptions &options);
SearchOptions options() const;
virtual void setOptions(const SearchOptions &options);
private:
QString mPattern;
SynSearchOptions mOptions;
SearchOptions mOptions;
};
using PSynSearchBase = std::shared_ptr<SynSearchBase>;
using PSynSearchBase = std::shared_ptr<BaseSearcher>;
}
#endif // SYNSEARCHBASE_H

View File

@ -18,31 +18,33 @@
#include <QRegExp>
SynSearchRegex::SynSearchRegex(QObject* parent):SynSearchBase(parent)
namespace QSynedit {
RegexSearcher::RegexSearcher(QObject* parent):BaseSearcher(parent)
{
}
int SynSearchRegex::length(int aIndex)
int RegexSearcher::length(int aIndex)
{
if (aIndex<0 || aIndex >= mResults.length())
return -1;
return mLengths[aIndex];
}
int SynSearchRegex::result(int aIndex)
int RegexSearcher::result(int aIndex)
{
if (aIndex<0 || aIndex >= mResults.length())
return -1;
return mResults[aIndex];
}
int SynSearchRegex::resultCount()
int RegexSearcher::resultCount()
{
return mResults.size();
}
int SynSearchRegex::findAll(const QString &text)
int RegexSearcher::findAll(const QString &text)
{
if (pattern().isEmpty())
return 0;
@ -57,28 +59,28 @@ int SynSearchRegex::findAll(const QString &text)
return mResults.size();
}
QString SynSearchRegex::replace(const QString &aOccurrence, const QString &aReplacement)
QString RegexSearcher::replace(const QString &aOccurrence, const QString &aReplacement)
{
QString s=aOccurrence;
return s.replace(mRegex,aReplacement);
}
void SynSearchRegex::setPattern(const QString &value)
void RegexSearcher::setPattern(const QString &value)
{
SynSearchBase::setPattern(value);
BaseSearcher::setPattern(value);
mRegex.setPattern(value);
updateRegexOptions();
}
void SynSearchRegex::setOptions(const SynSearchOptions &options)
void RegexSearcher::setOptions(const SearchOptions &options)
{
SynSearchBase::setOptions(options);
BaseSearcher::setOptions(options);
updateRegexOptions();
}
void SynSearchRegex::updateRegexOptions()
void RegexSearcher::updateRegexOptions()
{
if (options().testFlag(SynSearchOption::ssoMatchCase)) {
if (options().testFlag(SearchOption::ssoMatchCase)) {
mRegex.setPatternOptions(
mRegex.patternOptions() &
~QRegularExpression::CaseInsensitiveOption);
@ -88,3 +90,5 @@ void SynSearchRegex::updateRegexOptions()
QRegularExpression::CaseInsensitiveOption);
}
}
}

View File

@ -20,11 +20,12 @@
#include <QRegularExpression>
class SynSearchRegex : public SynSearchBase
namespace QSynedit {
class RegexSearcher : public BaseSearcher
{
Q_OBJECT
public:
explicit SynSearchRegex(QObject* parent=nullptr);
explicit RegexSearcher(QObject* parent=nullptr);
// SynSearchBase interface
public:
@ -34,7 +35,7 @@ public:
int findAll(const QString &text) override;
QString replace(const QString &aOccurrence, const QString &aReplacement) override;
void setPattern(const QString &value) override;
void setOptions(const SynSearchOptions &options) override;
void setOptions(const SearchOptions &options) override;
private:
void updateRegexOptions();
private:
@ -43,4 +44,6 @@ private:
QList<int> mResults;
};
}
#endif // SYNSEARCHREGEX_H

View File

@ -31,24 +31,17 @@
#include "KeyStrokes.h"
#include "SearchBase.h"
enum class SynFontSmoothMethod {
None, AntiAlias, ClearType
};
namespace QSynedit {
enum class SynScrollHintFormat {
shfTopLineOnly, shfTopToBottom
};
enum class SynScrollStyle {
enum class ScrollStyle {
ssNone, ssHorizontal, ssVertical, ssBoth
};
enum class SynEditCaretType {
enum class EditCaretType {
ctVerticalLine=0, ctHorizontalLine=1, ctHalfBlock=2, ctBlock=3
};
enum SynStatusChange {
enum StatusChange {
scNone = 0,
scAll = 0x0001,
scCaretX = 0x0002,
@ -63,10 +56,10 @@ enum SynStatusChange {
scModified = 0x0400
};
Q_DECLARE_FLAGS(SynStatusChanges, SynStatusChange)
Q_DECLARE_OPERATORS_FOR_FLAGS(SynStatusChanges)
Q_DECLARE_FLAGS(StatusChanges, StatusChange)
Q_DECLARE_OPERATORS_FOR_FLAGS(StatusChanges)
enum class SynStateFlag {
enum class StateFlag {
sfCaretChanged = 0x0001,
sfScrollbarChanged = 0x0002,
sfLinesChanging = 0x0004,
@ -76,11 +69,11 @@ enum class SynStateFlag {
sfWaitForDragging = 0x0040
};
Q_DECLARE_FLAGS(SynStateFlags,SynStateFlag)
Q_DECLARE_FLAGS(StateFlags,StateFlag)
Q_DECLARE_OPERATORS_FOR_FLAGS(SynStateFlags)
Q_DECLARE_OPERATORS_FOR_FLAGS(StateFlags)
enum SynEditorOption {
enum EditorOption {
eoAltSetsColumnMode = 0x00000001, //Holding down the Alt Key will put the selection mode into columnar format
eoAutoIndent = 0x00000002, //Will auto calculate the indent when input
eoLigatureSupport = 0x00000004, //Support ligaures in fonts like fira code
@ -113,11 +106,11 @@ enum SynEditorOption {
// eoNoCaret = 0x00000800, //Makes it so the caret is never visible
};
Q_DECLARE_FLAGS(SynEditorOptions, SynEditorOption)
Q_DECLARE_FLAGS(EditorOptions, EditorOption)
Q_DECLARE_OPERATORS_FOR_FLAGS(SynEditorOptions)
Q_DECLARE_OPERATORS_FOR_FLAGS(EditorOptions)
enum class SynSearchAction {
enum class SearchAction {
Replace,
ReplaceAll,
Skip,
@ -126,27 +119,23 @@ enum class SynSearchAction {
enum class SynTransientType {
enum class TransientType {
ttBefore, ttAfter
};
enum class SynScrollBarKind {
sbHorizontal, sbVertical
};
/*
using SynPaintTransientProc = std::function<void(const QPaintDevice& paintDevice,
SynTransientType transientType)>;
*/
using SynProcessCommandProc = std::function<void(SynEditorCommand& command, QChar& AChar, void* data)>;
using SynMouseCursorProc = std::function<void(const BufferCoord& aLineCharPos, QCursor & aCursor)>;
using SynPaintProc = std::function<void(const QPaintDevice& paintDevice )>;
using ProcessCommandProc = std::function<void(EditCommand& command, QChar& AChar, void* data)>;
using MouseCursorProc = std::function<void(const BufferCoord& aLineCharPos, QCursor & aCursor)>;
using PaintProc = std::function<void(const QPaintDevice& paintDevice )>;
//using SynPreparePaintHighlightTokenProc = std::function<void(int row,
// int column, const QString& token, PSynHighlighterAttribute attr,
// SynFontStyles& style, QColor& foreground, QColor& background)>;
using SynSearchMathedProc = std::function<SynSearchAction(const QString& sSearch,
// FontStyles& style, QColor& foreground, QColor& background)>;
using SearchMathedProc = std::function<SearchAction(const QString& sSearch,
const QString& sReplace, int Line, int ch, int wordLen)>;
using SynSearchConfirmAroundProc = std::function<bool ()>;
using SearchConfirmAroundProc = std::function<bool ()>;
class SynEdit;
using PSynEdit = std::shared_ptr<SynEdit>;
@ -228,7 +217,7 @@ public:
BufferCoord prevWordPos();
BufferCoord prevWordPosEx(const BufferCoord& XY);
void commandProcessor(SynEditorCommand Command, QChar AChar = QChar(), void * pData = nullptr);
void commandProcessor(EditCommand Command, QChar AChar = QChar(), void * pData = nullptr);
//Caret
void showCaret();
void hideCaret();
@ -246,25 +235,25 @@ public:
void collapseAll();
void unCollpaseAll();
void uncollapseAroundLine(int line);
PSynEditFoldRange foldHidesLine(int line);
PCodeFoldingRange foldHidesLine(int line);
void setSelLength(int Value);
void setSelText(const QString& text);
int searchReplace(const QString& sSearch, const QString& sReplace, SynSearchOptions options,
PSynSearchBase searchEngine, SynSearchMathedProc matchedCallback = nullptr,
SynSearchConfirmAroundProc confirmAroundCallback = nullptr);
int searchReplace(const QString& sSearch, const QString& sReplace, SearchOptions options,
PSynSearchBase searchEngine, SearchMathedProc matchedCallback = nullptr,
SearchConfirmAroundProc confirmAroundCallback = nullptr);
int maxScrollWidth() const;
int maxScrollHeight() const;
bool getHighlighterAttriAtRowCol(const BufferCoord& pos, QString& token,
PSynHighlighterAttribute& attri);
PHighlighterAttribute& attri);
bool getHighlighterAttriAtRowCol(const BufferCoord& pos, QString& token,
bool& tokenFinished, SynHighlighterTokenType& tokenType,
PSynHighlighterAttribute& attri);
bool& tokenFinished, TokenType& tokenType,
PHighlighterAttribute& attri);
bool getHighlighterAttriAtRowColEx(const BufferCoord& pos, QString& token,
SynHighlighterTokenType& tokenType, SynTokenKind &tokenKind, int &start,
PSynHighlighterAttribute& attri);
TokenType& tokenType, TokenKind &tokenKind, int &start,
PHighlighterAttribute& attri);
void beginUndoBlock();
void endUndoBlock();
@ -278,26 +267,26 @@ public:
}
//Commands
virtual void cutToClipboard() { commandProcessor(SynEditorCommand::ecCut);}
virtual void copyToClipboard() { commandProcessor(SynEditorCommand::ecCopy);}
virtual void pasteFromClipboard() { commandProcessor(SynEditorCommand::ecPaste);}
virtual void undo() { commandProcessor(SynEditorCommand::ecUndo);}
virtual void redo() { commandProcessor(SynEditorCommand::ecRedo);}
virtual void zoomIn() { commandProcessor(SynEditorCommand::ecZoomIn);}
virtual void zoomOut() { commandProcessor(SynEditorCommand::ecZoomOut);}
virtual void cutToClipboard() { commandProcessor(EditCommand::ecCut);}
virtual void copyToClipboard() { commandProcessor(EditCommand::ecCopy);}
virtual void pasteFromClipboard() { commandProcessor(EditCommand::ecPaste);}
virtual void undo() { commandProcessor(EditCommand::ecUndo);}
virtual void redo() { commandProcessor(EditCommand::ecRedo);}
virtual void zoomIn() { commandProcessor(EditCommand::ecZoomIn);}
virtual void zoomOut() { commandProcessor(EditCommand::ecZoomOut);}
virtual void selectAll() {
commandProcessor(SynEditorCommand::ecSelectAll);
commandProcessor(EditCommand::ecSelectAll);
}
virtual void selectWord() {
commandProcessor(SynEditorCommand::ecSelWord);
commandProcessor(EditCommand::ecSelWord);
}
virtual void tab() { commandProcessor(SynEditorCommand::ecTab);}
virtual void shifttab() { commandProcessor(SynEditorCommand::ecShiftTab);}
virtual void toggleComment() { commandProcessor(SynEditorCommand::ecToggleComment);}
virtual void toggleBlockComment() { commandProcessor(SynEditorCommand::ecToggleBlockComment);}
virtual void matchBracket() { commandProcessor(SynEditorCommand::ecMatchBracket);}
virtual void moveSelUp(){ commandProcessor(SynEditorCommand::ecMoveSelUp);}
virtual void moveSelDown(){ commandProcessor(SynEditorCommand::ecMoveSelDown);}
virtual void tab() { commandProcessor(EditCommand::ecTab);}
virtual void shifttab() { commandProcessor(EditCommand::ecShiftTab);}
virtual void toggleComment() { commandProcessor(EditCommand::ecToggleComment);}
virtual void toggleBlockComment() { commandProcessor(EditCommand::ecToggleBlockComment);}
virtual void matchBracket() { commandProcessor(EditCommand::ecMatchBracket);}
virtual void moveSelUp(){ commandProcessor(EditCommand::ecMoveSelUp);}
virtual void moveSelDown(){ commandProcessor(EditCommand::ecMoveSelDown);}
virtual void beginUpdate();
virtual void endUpdate();
@ -313,10 +302,10 @@ public:
bool pointToLine(const QPoint& point, int& line);
bool isIdentChar(const QChar& ch);
void setRainbowAttrs(const PSynHighlighterAttribute &attr0,
const PSynHighlighterAttribute &attr1,
const PSynHighlighterAttribute &attr2,
const PSynHighlighterAttribute &attr3);
void setRainbowAttrs(const PHighlighterAttribute &attr0,
const PHighlighterAttribute &attr1,
const PHighlighterAttribute &attr2,
const PHighlighterAttribute &attr3);
void updateMouseCursor();
@ -337,8 +326,8 @@ public:
void setBlockBegin(BufferCoord value);
void setBlockEnd(BufferCoord Value);
SynSelectionMode activeSelectionMode() const;
void setActiveSelectionMode(const SynSelectionMode &Value);
SelectionMode activeSelectionMode() const;
void setActiveSelectionMode(const SelectionMode &Value);
int charsInWindow() const;
@ -352,13 +341,13 @@ public:
bool modified() const;
void setModified(bool Value);
PSynHighlighter highlighter() const;
void setHighlighter(const PSynHighlighter &highlighter);
PHighlighter highlighter() const;
void setHighlighter(const PHighlighter &highlighter);
bool useCodeFolding() const;
void setUseCodeFolding(bool value);
SynEditCodeFolding & codeFolding();
CodeFoldingOptions & codeFolding();
QString displayLineText();
QString lineText() const;
@ -367,17 +356,17 @@ public:
const PSynDocument& document() const;
bool empty();
SynSelectionMode selectionMode() const;
void setSelectionMode(SynSelectionMode value);
SelectionMode selectionMode() const;
void setSelectionMode(SelectionMode value);
QString selText();
QStringList getContent(BufferCoord startPos, BufferCoord endPos, SynSelectionMode mode) const;
QStringList getContent(BufferCoord startPos, BufferCoord endPos, SelectionMode mode) const;
QString lineBreak();
SynEditorOptions getOptions() const;
void setOptions(const SynEditorOptions &Value);
EditorOptions getOptions() const;
void setOptions(const EditorOptions &Value);
int tabWidth() const { return mDocument->tabWidth(); }
void setTabWidth(int tabWidth);
@ -388,13 +377,13 @@ public:
QColor activeLineColor() const;
void setActiveLineColor(const QColor &activeLineColor);
SynEditCaretType overwriteCaret() const;
void setOverwriteCaret(const SynEditCaretType &overwriteCaret);
EditCaretType overwriteCaret() const;
void setOverwriteCaret(const EditCaretType &overwriteCaret);
SynEditCaretType insertCaret() const;
void setInsertCaret(const SynEditCaretType &insertCaret);
EditCaretType insertCaret() const;
void setInsertCaret(const EditCaretType &insertCaret);
SynGutter& gutter();
Gutter& gutter();
bool readOnly() const;
void setReadOnly(bool readOnly);
@ -422,13 +411,13 @@ public:
bool caretUseTextColor() const;
void setCaretUseTextColor(bool newCaretUseTextColor);
const PSynHighlighterAttribute &rainbowAttr0() const;
const PHighlighterAttribute &rainbowAttr0() const;
const PSynHighlighterAttribute &rainbowAttr1() const;
const PHighlighterAttribute &rainbowAttr1() const;
const PSynHighlighterAttribute &rainbowAttr2() const;
const PHighlighterAttribute &rainbowAttr2() const;
const PSynHighlighterAttribute &rainbowAttr3() const;
const PHighlighterAttribute &rainbowAttr3() const;
int mouseWheelScrollSpeed() const;
void setMouseWheelScrollSpeed(int newMouseWheelScrollSpeed);
@ -461,8 +450,7 @@ signals:
// void contextHelp(const QString& word);
// void scrolled(SynScrollBarKind ScrollBar);
void statusChanged(SynStatusChanges changes);
void statusChanged(StatusChanges changes);
void fontChanged();
void tabSizeChanged();
@ -470,21 +458,21 @@ signals:
protected:
virtual bool onGetSpecialLineColors(int Line,
QColor& foreground, QColor& backgroundColor) ;
virtual void onGetEditingAreas(int Line, SynEditingAreaList& areaList);
virtual void onGetEditingAreas(int Line, EditingAreaList& areaList);
virtual void onGutterGetText(int aLine, QString& aText);
virtual void onGutterPaint(QPainter& painter, int aLine, int X, int Y);
virtual void onPaint(QPainter& painter);
virtual void onPreparePaintHighlightToken(int line,
int aChar, const QString& token, PSynHighlighterAttribute attr,
SynFontStyles& style, QColor& foreground, QColor& background);
virtual void onProcessCommand(SynEditorCommand Command, QChar AChar, void * pData);
virtual void onCommandProcessed(SynEditorCommand Command, QChar AChar, void * pData);
virtual void ExecuteCommand(SynEditorCommand Command, QChar AChar, void * pData);
int aChar, const QString& token, PHighlighterAttribute attr,
FontStyles& style, QColor& foreground, QColor& background);
virtual void onProcessCommand(EditCommand Command, QChar AChar, void * pData);
virtual void onCommandProcessed(EditCommand Command, QChar AChar, void * pData);
virtual void ExecuteCommand(EditCommand Command, QChar AChar, void * pData);
virtual void onEndFirstPaintLock();
virtual void onBeginFirstPaintLock();
private:
void clearAreaList(SynEditingAreaList areaList);
void clearAreaList(EditingAreaList areaList);
void computeCaret();
void computeScroll(bool isDragging);
@ -496,7 +484,7 @@ private:
int clientLeft();
QRect clientRect();
void synFontChanged();
void doOnPaintTransient(SynTransientType TransientType);
void doSetSelText(const QString& value);
void updateLastCaretX();
@ -507,8 +495,8 @@ private:
void internalSetCaretXY(const BufferCoord& Value);
void internalSetCaretX(int Value);
void internalSetCaretY(int Value);
void setStatusChanged(SynStatusChanges changes);
void doOnStatusChange(SynStatusChanges changes);
void setStatusChanged(StatusChanges changes);
void doOnStatusChange(StatusChanges changes);
void updateScrollbars();
void updateCaret();
void recalcCharExtent();
@ -517,30 +505,29 @@ private:
int scanFrom(int Index, int canStopIndex);
void rescanRange(int line);
void rescanRanges();
void uncollapse(PSynEditFoldRange FoldRange);
void collapse(PSynEditFoldRange FoldRange);
void uncollapse(PCodeFoldingRange FoldRange);
void collapse(PCodeFoldingRange FoldRange);
void foldOnListInserted(int Line, int Count);
void foldOnListDeleted(int Line, int Count);
void foldOnListCleared();
void rescanFolds(); // rescan for folds
void rescanForFoldRanges();
void scanForFoldRanges(PSynEditFoldRanges TopFoldRanges);
void scanForFoldRanges(PCodeFoldingRanges TopFoldRanges);
int lineHasChar(int Line, int startChar, QChar character, const QString& highlighterAttrName);
void findSubFoldRange(PSynEditFoldRanges TopFoldRanges,int FoldIndex,PSynEditFoldRanges& parentFoldRanges, PSynEditFoldRange Parent);
PSynEditFoldRange collapsedFoldStartAtLine(int Line);
void doOnPaintTransientEx(SynTransientType TransientType, bool Lock);
void findSubFoldRange(PCodeFoldingRanges TopFoldRanges,int FoldIndex,PCodeFoldingRanges& parentFoldRanges, PCodeFoldingRange Parent);
PCodeFoldingRange collapsedFoldStartAtLine(int Line);
void initializeCaret();
PSynEditFoldRange foldStartAtLine(int Line) const;
PCodeFoldingRange foldStartAtLine(int Line) const;
bool foldCollapsedBetween(int startLine, int endLine) const;
QString substringByColumns(const QString& s, int startColumn, int& colLen);
PSynEditFoldRange foldAroundLine(int Line);
PSynEditFoldRange foldAroundLineEx(int Line, bool WantCollapsed, bool AcceptFromLine, bool AcceptToLine);
PSynEditFoldRange checkFoldRange(SynEditFoldRanges* FoldRangeToCheck,int Line, bool WantCollapsed, bool AcceptFromLine, bool AcceptToLine);
PSynEditFoldRange foldEndAtLine(int Line);
PCodeFoldingRange foldAroundLine(int Line);
PCodeFoldingRange foldAroundLineEx(int Line, bool WantCollapsed, bool AcceptFromLine, bool AcceptToLine);
PCodeFoldingRange checkFoldRange(CodeFoldingRanges* FoldRangeToCheck,int Line, bool WantCollapsed, bool AcceptFromLine, bool AcceptToLine);
PCodeFoldingRange foldEndAtLine(int Line);
void paintCaret(QPainter& painter, const QRect rcClip);
int textOffset() const;
SynEditorCommand TranslateKeyCode(int key, Qt::KeyboardModifiers modifiers);
EditCommand TranslateKeyCode(int key, Qt::KeyboardModifiers modifiers);
/**
* Move the caret to right DX columns
* @param DX
@ -554,15 +541,15 @@ private:
void moveCaretToLineEnd(bool isSelection);
void setSelectedTextEmpty();
void setSelTextPrimitive(const QStringList& text);
void setSelTextPrimitiveEx(SynSelectionMode PasteMode,
void setSelTextPrimitiveEx(SelectionMode PasteMode,
const QStringList& text);
void doLinesDeleted(int FirstLine, int Count);
void doLinesInserted(int FirstLine, int Count);
void properSetLine(int ALine, const QString& ALineText, bool notify = true);
//primitive edit operations
void doDeleteText(BufferCoord startPos, BufferCoord endPos, SynSelectionMode mode);
void doInsertText(const BufferCoord& pos, const QStringList& text, SynSelectionMode mode, int startLine, int endLine);
void doDeleteText(BufferCoord startPos, BufferCoord endPos, SelectionMode mode);
void doInsertText(const BufferCoord& pos, const QStringList& text, SelectionMode mode, int startLine, int endLine);
int doInsertTextByNormalMode(const BufferCoord& pos, const QStringList& text, BufferCoord &newPos);
int doInsertTextByColumnMode(const BufferCoord& pos, const QStringList& text, BufferCoord &newPos, int startLine, int endLine);
int doInsertTextByLineMode(const BufferCoord& pos, const QStringList& text, BufferCoord &newPos);
@ -649,8 +636,8 @@ private slots:
private:
std::shared_ptr<QImage> mContentImage;
SynEditFoldRanges mAllFoldRanges;
SynEditCodeFolding mCodeFolding;
CodeFoldingRanges mAllFoldRanges;
CodeFoldingOptions mCodeFolding;
bool mUseCodeFolding;
bool mAlwaysShowCaret;
BufferCoord mBlockBegin;
@ -662,7 +649,6 @@ private:
int mCharWidth;
QFont mFontDummy;
QFont mFontForNonAscii;
SynFontSmoothMethod mFontSmoothing;
bool mMouseMoved;
bool mInserting;
@ -674,21 +660,19 @@ private:
bool mReadOnly;
int mRightEdge;
QColor mRightEdgeColor;
QColor mScrollHintColor;
SynScrollHintFormat mScrollHintFormat;
SynScrollStyle mScrollBars;
ScrollStyle mScrollBars;
int mTextHeight;
int mTopLine;
PSynHighlighter mHighlighter;
PHighlighter mHighlighter;
QColor mSelectedForeground;
QColor mSelectedBackground;
QColor mForegroundColor;
QColor mBackgroundColor;
QColor mCaretColor;
PSynHighlighterAttribute mRainbowAttr0;
PSynHighlighterAttribute mRainbowAttr1;
PSynHighlighterAttribute mRainbowAttr2;
PSynHighlighterAttribute mRainbowAttr3;
PHighlighterAttribute mRainbowAttr0;
PHighlighterAttribute mRainbowAttr1;
PHighlighterAttribute mRainbowAttr2;
PHighlighterAttribute mRainbowAttr3;
bool mCaretUseTextColor;
QColor mActiveLineColor;
@ -697,22 +681,22 @@ private:
QPoint mMouseDownPos;
bool mHideSelection;
int mMouseWheelAccumulator;
SynEditCaretType mOverwriteCaret;
SynEditCaretType mInsertCaret;
EditCaretType mOverwriteCaret;
EditCaretType mInsertCaret;
QPoint mCaretOffset;
SynEditKeyStrokes mKeyStrokes;
EditKeyStrokes mKeyStrokes;
bool mModified;
QDateTime mLastModifyTime;
int mExtraLineSpacing;
SynSelectionMode mSelectionMode;
SynSelectionMode mActiveSelectionMode; //mode of the active selection
SelectionMode mSelectionMode;
SelectionMode mActiveSelectionMode; //mode of the active selection
bool mWantReturns;
bool mWantTabs;
SynGutter mGutter;
Gutter mGutter;
QRect mInvalidateRect;
SynStateFlags mStateFlags;
SynEditorOptions mOptions;
SynStatusChanges mStatusChanges;
StateFlags mStateFlags;
EditorOptions mOptions;
StatusChanges mStatusChanges;
int mLastKey;
Qt::KeyboardModifiers mLastKeyModifiers;
//fSearchEngine: TSynEditSearchCustom;
@ -731,12 +715,12 @@ private:
int mPainterLock; // lock counter to prevent repaint while painting
bool mUndoing;
// event handlers
SynProcessCommandProc mOnCommandProcessed;
SynMouseCursorProc mOnMouseCursor;
SynPaintProc mOnPaint;
ProcessCommandProc mOnCommandProcessed;
MouseCursorProc mOnMouseCursor;
PaintProc mOnPaint;
// SynPreparePaintHighlightTokenProc mOnPaintHighlightToken;
SynProcessCommandProc mOnProcessingCommand;
SynProcessCommandProc mOnProcessingUserCommand;
ProcessCommandProc mOnProcessingCommand;
ProcessCommandProc mOnProcessingUserCommand;
// SynSpecialLineColorsProc mOnSpecialLineColors;
// SynEditingAreasProc mOnEditingAreas;
@ -794,6 +778,9 @@ protected:
int mouseSelectionScrollSpeed() const;
void setMouseSelectionScrollSpeed(int newMouseSelectionScrollSpeed);
ScrollStyle scrollBars() const;
void setScrollBars(ScrollStyle newScrollBars);
protected:
void dragEnterEvent(QDragEnterEvent *event) override;
void dropEvent(QDropEvent *event) override;
@ -801,4 +788,5 @@ protected:
void dragLeaveEvent(QDragLeaveEvent *event) override;
};
}
#endif // SYNEDIT_H

View File

@ -15,6 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "TextBuffer.h"
#include "qt_utils/utils.h"
#include <QDataStream>
#include <QFile>
#include <QTextCodec>
@ -22,10 +23,12 @@
#include <QMutexLocker>
#include <stdexcept>
#include "SynEdit.h"
#include "../utils.h"
#include "../platform.h"
#include <QMessageBox>
#include <cmath>
#include "qt_utils/charsetinfo.h"
#include <QDebug>
namespace QSynedit {
SynDocument::SynDocument(const QFont& font, const QFont& nonAsciiFont, QObject *parent):
QObject(parent),
@ -150,7 +153,7 @@ QString SynDocument::lineBreak() const
return "\n";
}
SynRangeState SynDocument::ranges(int Index)
HighlighterState SynDocument::ranges(int Index)
{
QMutexLocker locker(&mMutex);
if (Index>=0 && Index < mLines.size()) {
@ -158,7 +161,7 @@ SynRangeState SynDocument::ranges(int Index)
} else {
ListIndexOutOfBounds(Index);
}
return SynRangeState();
return HighlighterState();
}
void SynDocument::insertItem(int Index, const QString &s)
@ -193,7 +196,7 @@ void SynDocument::setAppendNewLineAtEOF(bool appendNewLineAtEOF)
mAppendNewLineAtEOF = appendNewLineAtEOF;
}
void SynDocument::setRange(int Index, const SynRangeState& ARange)
void SynDocument::setRange(int Index, const HighlighterState& ARange)
{
QMutexLocker locker(&mMutex);
if (Index<0 || Index>=mLines.count()) {
@ -603,7 +606,7 @@ void SynDocument::loadFromFile(const QString& filename, const QByteArray& encodi
realEncoding = ENCODING_ASCII;
return;
}
realEncoding = pCharsetInfoManager->getDefaultSystemEncoding();
realEncoding = pCharsetInfoManager->getDefaultSystemEncoding();
QList<PCharsetInfo> charsets = pCharsetInfoManager->findCharsetByLocale(pCharsetInfoManager->localeName());
if (!charsets.isEmpty()) {
if (tryLoadFileByEncoding(realEncoding,file)) {
@ -836,7 +839,7 @@ SynEditUndoList::SynEditUndoList():QObject()
void SynEditUndoList::addChange(SynChangeReason reason, const BufferCoord &startPos,
const BufferCoord &endPos, const QStringList& changeText,
SynSelectionMode selMode)
SelectionMode selMode)
{
int changeNumber;
if (inBlock()) {
@ -858,7 +861,7 @@ void SynEditUndoList::addChange(SynChangeReason reason, const BufferCoord &start
}
}
void SynEditUndoList::restoreChange(SynChangeReason AReason, const BufferCoord &AStart, const BufferCoord &AEnd, const QStringList &ChangeText, SynSelectionMode SelMode, size_t changeNumber)
void SynEditUndoList::restoreChange(SynChangeReason AReason, const BufferCoord &AStart, const BufferCoord &AEnd, const QStringList &ChangeText, SelectionMode SelMode, size_t changeNumber)
{
PSynEditUndoItem newItem = std::make_shared<SynEditUndoItem>(AReason,
SelMode,AStart,AEnd,ChangeText,
@ -887,7 +890,7 @@ void SynEditUndoList::addGroupBreak()
return;
if (lastChangeReason() != SynChangeReason::GroupBreak) {
addChange(SynChangeReason::GroupBreak, {0,0}, {0,0}, QStringList(), SynSelectionMode::Normal);
addChange(SynChangeReason::GroupBreak, {0,0}, {0,0}, QStringList(), SelectionMode::Normal);
}
}
@ -1051,7 +1054,7 @@ void SynEditUndoList::ensureMaxEntries()
}
}
SynSelectionMode SynEditUndoItem::changeSelMode() const
SelectionMode SynEditUndoItem::changeSelMode() const
{
return mChangeSelMode;
}
@ -1076,7 +1079,7 @@ size_t SynEditUndoItem::changeNumber() const
return mChangeNumber;
}
SynEditUndoItem::SynEditUndoItem(SynChangeReason reason, SynSelectionMode selMode,
SynEditUndoItem::SynEditUndoItem(SynChangeReason reason, SelectionMode selMode,
BufferCoord startPos, BufferCoord endPos,
const QStringList& text, int number)
{
@ -1098,7 +1101,7 @@ SynEditRedoList::SynEditRedoList()
}
void SynEditRedoList::addRedo(SynChangeReason AReason, const BufferCoord &AStart, const BufferCoord &AEnd, const QStringList &ChangeText, SynSelectionMode SelMode, size_t changeNumber)
void SynEditRedoList::addRedo(SynChangeReason AReason, const BufferCoord &AStart, const BufferCoord &AEnd, const QStringList &ChangeText, SelectionMode SelMode, size_t changeNumber)
{
PSynEditUndoItem newItem = std::make_shared<SynEditUndoItem>(
AReason,
@ -1158,3 +1161,5 @@ int SynEditRedoList::itemCount()
{
return mItems.count();
}
}

View File

@ -23,10 +23,12 @@
#include <QMutex>
#include <QVector>
#include <memory>
#include <QFile>
#include "MiscProcs.h"
#include "../utils.h"
#include "Types.h"
#include "qt_utils/utils.h"
namespace QSynedit {
enum SynEditStringFlag {
sfHasTabs = 0x0001,
sfHasNoTabs = 0x0002,
@ -37,7 +39,7 @@ typedef int SynEditStringFlags;
struct SynDocumentLine {
QString fString;
SynRangeState fRange;
HighlighterState fRange;
int fColumns; //
public:
@ -54,8 +56,6 @@ class SynDocument;
typedef std::shared_ptr<SynDocument> PSynDocument;
class QFile;
class SynDocument : public QObject
{
Q_OBJECT
@ -70,8 +70,8 @@ public:
int rightBraces(int Index);
int lengthOfLongestLine();
QString lineBreak() const;
SynRangeState ranges(int Index);
void setRange(int Index, const SynRangeState& ARange);
HighlighterState ranges(int Index);
void setRange(int Index, const HighlighterState& ARange);
QString getString(int Index);
int count();
QString text();
@ -174,21 +174,21 @@ enum class SynChangeReason {
class SynEditUndoItem {
private:
SynChangeReason mChangeReason;
SynSelectionMode mChangeSelMode;
SelectionMode mChangeSelMode;
BufferCoord mChangeStartPos;
BufferCoord mChangeEndPos;
QStringList mChangeText;
size_t mChangeNumber;
public:
SynEditUndoItem(SynChangeReason reason,
SynSelectionMode selMode,
SelectionMode selMode,
BufferCoord startPos,
BufferCoord endPos,
const QStringList& text,
int number);
SynChangeReason changeReason() const;
SynSelectionMode changeSelMode() const;
SelectionMode changeSelMode() const;
BufferCoord changeStartPos() const;
BufferCoord changeEndPos() const;
QStringList changeText() const;
@ -203,10 +203,10 @@ public:
explicit SynEditUndoList();
void addChange(SynChangeReason AReason, const BufferCoord& AStart, const BufferCoord& AEnd,
const QStringList& ChangeText, SynSelectionMode SelMode);
const QStringList& ChangeText, SelectionMode SelMode);
void restoreChange(SynChangeReason AReason, const BufferCoord& AStart, const BufferCoord& AEnd,
const QStringList& ChangeText, SynSelectionMode SelMode, size_t changeNumber);
const QStringList& ChangeText, SelectionMode SelMode, size_t changeNumber);
void restoreChange(PSynEditUndoItem item);
@ -259,7 +259,7 @@ public:
explicit SynEditRedoList();
void addRedo(SynChangeReason AReason, const BufferCoord& AStart, const BufferCoord& AEnd,
const QStringList& ChangeText, SynSelectionMode SelMode, size_t changeNumber);
const QStringList& ChangeText, SelectionMode SelMode, size_t changeNumber);
void addRedo(PSynEditUndoItem item);
void clear();
@ -279,4 +279,6 @@ protected:
using PSynEditUndoList = std::shared_ptr<SynEditUndoList>;
using PSynEditRedoList = std::shared_ptr<SynEditRedoList>;
}
#endif // SYNEDITSTRINGLIST_H

View File

@ -20,6 +20,8 @@
#include <cmath>
#include <QDebug>
namespace QSynedit {
SynEditTextPainter::SynEditTextPainter(SynEdit *edit, QPainter *painter, int FirstRow, int LastRow, int FirstCol, int LastCol)
{
this->edit = edit;
@ -133,7 +135,7 @@ void SynEditTextPainter::paintGutter(const QRect& clip)
if (edit->mGutter.activeLineTextColor().isValid()) {
if (
(edit->mCaretY==vLine) ||
(edit->mActiveSelectionMode == SynSelectionMode::Column && vLine >= selectionStart.line && vLine <= selectionEnd.line)
(edit->mActiveSelectionMode == SelectionMode::Column && vLine >= selectionStart.line && vLine <= selectionEnd.line)
)
painter->setPen(edit->mGutter.activeLineTextColor());
else
@ -193,7 +195,7 @@ void SynEditTextPainter::paintGutter(const QRect& clip)
rcFold.top() + rcFold.height() / 2);
}
// Any fold ranges beginning on this line?
PSynEditFoldRange FoldRange = edit->foldStartAtLine(vLine);
PCodeFoldingRange FoldRange = edit->foldStartAtLine(vLine);
if (FoldRange) {
// Draw the bottom part of a line
if (!FoldRange->collapsed) {
@ -305,7 +307,7 @@ void SynEditTextPainter::computeSelectionInfo()
}
// In the column selection mode sort the begin and end of the selection,
// this makes the painting code simpler.
if (edit->mActiveSelectionMode == SynSelectionMode::Column && vSelStart.Column > vSelEnd.Column)
if (edit->mActiveSelectionMode == SelectionMode::Column && vSelStart.Column > vSelEnd.Column)
std::swap(vSelStart.Column, vSelEnd.Column);
}
}
@ -358,7 +360,7 @@ void SynEditTextPainter::paintToken(const QString &token, int tokenCols, int col
for (int i=0;i<token.length();i++) {
int charCols=0;
QString textToPaint = token[i];
if (token[i] == SynTabChar) {
if (token[i] == '\t') {
charCols = edit->tabWidth() - ((columnsBefore+tokenColLen) % edit->tabWidth());
} else {
charCols = edit->charColumns(token[i]);
@ -409,7 +411,7 @@ void SynEditTextPainter::paintToken(const QString &token, int tokenCols, int col
}
}
void SynEditTextPainter::paintEditAreas(const SynEditingAreaList &areaList)
void SynEditTextPainter::paintEditAreas(const EditingAreaList &areaList)
{
QRect rc;
int x1,x2;
@ -418,7 +420,7 @@ void SynEditTextPainter::paintEditAreas(const SynEditingAreaList &areaList)
rc=rcLine;
rc.setBottom(rc.bottom()-1);
setDrawingColors(false);
for (const PSynEditingArea& p:areaList) {
for (const PEditingArea& p:areaList) {
if (p->beginX > LastCol)
continue;
if (p->endX < FirstCol)
@ -436,13 +438,13 @@ void SynEditTextPainter::paintEditAreas(const SynEditingAreaList &areaList)
painter->setPen(p->color);
painter->setBrush(Qt::NoBrush);
switch(p->type) {
case SynEditingAreaType::eatRectangleBorder:
case EditingAreaType::eatRectangleBorder:
painter->drawRect(rc);
break;
case SynEditingAreaType::eatUnderLine:
case EditingAreaType::eatUnderLine:
painter->drawLine(rc.left(),rc.bottom(),rc.right(),rc.bottom());
break;
case SynEditingAreaType::eatWaveUnderLine:
case EditingAreaType::eatWaveUnderLine:
offset=3;
int lastX=rc.left();
int lastY=rc.bottom()-offset;
@ -496,16 +498,16 @@ void SynEditTextPainter::paintHighlightToken(bool bFillToEOL)
// if (bSpecialLine && edit->mOptions.testFlag(eoSpecialLineDefaultFg))
// colFG = TokenAccu.FG;
QFont font = edit->font();
font.setBold(TokenAccu.Style & SynFontStyle::fsBold);
font.setItalic(TokenAccu.Style & SynFontStyle::fsItalic);
font.setStrikeOut(TokenAccu.Style & SynFontStyle::fsStrikeOut);
font.setUnderline(TokenAccu.Style & SynFontStyle::fsUnderline);
font.setBold(TokenAccu.Style & FontStyle::fsBold);
font.setItalic(TokenAccu.Style & FontStyle::fsItalic);
font.setStrikeOut(TokenAccu.Style & FontStyle::fsStrikeOut);
font.setUnderline(TokenAccu.Style & FontStyle::fsUnderline);
painter->setFont(font);
QFont nonAsciiFont = edit->fontForNonAscii();
nonAsciiFont.setBold(TokenAccu.Style & SynFontStyle::fsBold);
nonAsciiFont.setItalic(TokenAccu.Style & SynFontStyle::fsItalic);
nonAsciiFont.setStrikeOut(TokenAccu.Style & SynFontStyle::fsStrikeOut);
nonAsciiFont.setUnderline(TokenAccu.Style & SynFontStyle::fsUnderline);
nonAsciiFont.setBold(TokenAccu.Style & FontStyle::fsBold);
nonAsciiFont.setItalic(TokenAccu.Style & FontStyle::fsItalic);
nonAsciiFont.setStrikeOut(TokenAccu.Style & FontStyle::fsStrikeOut);
nonAsciiFont.setUnderline(TokenAccu.Style & FontStyle::fsUnderline);
// Paint the chars
if (bComplexToken) {
@ -546,7 +548,7 @@ void SynEditTextPainter::paintHighlightToken(bool bFillToEOL)
if (rcToken.left() < nX1) {
setDrawingColors(false);
rcToken.setRight(nX1);
// if (TokenAccu.Len != 0 && TokenAccu.Style != SynFontStyle::fsNone)
// if (TokenAccu.Len != 0 && TokenAccu.Style != FontStyle::fsNone)
// AdjustEndRect();
painter->fillRect(rcToken,painter->brush());
rcToken.setLeft(nX1);
@ -565,7 +567,7 @@ void SynEditTextPainter::paintHighlightToken(bool bFillToEOL)
} else {
setDrawingColors(bLineSelected);
rcToken.setRight(rcLine.right());
// if (TokenAccu.Len != 0 && TokenAccu.Style != SynFontStyle::fsNone)
// if (TokenAccu.Len != 0 && TokenAccu.Style != FontStyle::fsNone)
// AdjustEndRect();
painter->fillRect(rcToken,painter->brush());
}
@ -592,11 +594,11 @@ bool SynEditTextPainter::tokenIsSpaces(bool &bSpacesTest, const QString& token,
// record. This will paint any chars already stored if there is
// a (visible) change in the attributes.
void SynEditTextPainter::addHighlightToken(const QString &Token, int columnsBefore,
int tokenColumns, int cLine, PSynHighlighterAttribute p_Attri)
int tokenColumns, int cLine, PHighlighterAttribute p_Attri)
{
bool bCanAppend;
QColor foreground, background;
SynFontStyles style;
FontStyles style;
bool bSpacesTest,bIsSpaces;
if (p_Attri) {
@ -627,7 +629,7 @@ void SynEditTextPainter::addHighlightToken(const QString &Token, int columnsBefo
bSpacesTest = false;
if (TokenAccu.Columns > 0) {
// font style must be the same or token is only spaces
if (TokenAccu.Style == style || ( (style & SynFontStyle::fsUnderline) == (TokenAccu.Style & fsUnderline)
if (TokenAccu.Style == style || ( (style & FontStyle::fsUnderline) == (TokenAccu.Style & fsUnderline)
&& tokenIsSpaces(bSpacesTest,Token,bIsSpaces)) ) {
if (
// background color must be the same and
@ -704,12 +706,12 @@ void SynEditTextPainter::paintFoldAttributes()
indentLevel++ ;
if (edit->mHighlighter) {
if (edit->mCodeFolding.indentGuides) {
PSynHighlighterAttribute attr = edit->mHighlighter->symbolAttribute();
PHighlighterAttribute attr = edit->mHighlighter->symbolAttribute();
getBraceColorAttr(indentLevel,attr);
paintColor = attr->foreground();
}
if (edit->mCodeFolding.fillIndents) {
PSynHighlighterAttribute attr = edit->mHighlighter->symbolAttribute();
PHighlighterAttribute attr = edit->mHighlighter->symbolAttribute();
getBraceColorAttr(indentLevel,attr);
gradientStart=attr->foreground();
attr = edit->mHighlighter->symbolAttribute();
@ -750,7 +752,7 @@ void SynEditTextPainter::paintFoldAttributes()
if (edit->mCodeFolding.showCollapsedLine) {
painter->setPen(edit->mCodeFolding.collapsedLineColor);
for (int i=0; i< edit->mAllFoldRanges.count();i++) {
PSynEditFoldRange range = edit->mAllFoldRanges[i];
PCodeFoldingRange range = edit->mAllFoldRanges[i];
if (range->collapsed && !range->parentCollapsed() &&
(range->fromLine <= vLastLine) && (range->fromLine >= vFirstLine) ) {
// Get starting and end points
@ -762,13 +764,13 @@ void SynEditTextPainter::paintFoldAttributes()
}
void SynEditTextPainter::getBraceColorAttr(int level, PSynHighlighterAttribute &attr)
void SynEditTextPainter::getBraceColorAttr(int level, PHighlighterAttribute &attr)
{
if (!edit->mOptions.testFlag(SynEditorOption::eoShowRainbowColor))
if (!edit->mOptions.testFlag(EditorOption::eoShowRainbowColor))
return;
if (attr != edit->mHighlighter->symbolAttribute())
return;
PSynHighlighterAttribute oldAttr = attr;
PHighlighterAttribute oldAttr = attr;
switch(level % 4) {
case 0:
attr = edit->mRainbowAttr0;
@ -794,12 +796,12 @@ void SynEditTextPainter::paintLines()
QString sLine; // the current line
QString sToken; // highlighter token info
int nTokenColumnsBefore, nTokenColumnLen;
PSynHighlighterAttribute attr;
PHighlighterAttribute attr;
int vFirstChar;
int vLastChar;
SynEditingAreaList areaList;
PSynEditFoldRange foldRange;
PSynHighlighterAttribute preeditAttr;
EditingAreaList areaList;
PCodeFoldingRange foldRange;
PHighlighterAttribute preeditAttr;
int nFold;
QString sFold;
@ -820,7 +822,7 @@ void SynEditTextPainter::paintLines()
// Get the line.
sLine = edit->mDocument->getString(vLine - 1);
// determine whether will be painted with ActiveLineColor
if (edit->mActiveSelectionMode == SynSelectionMode::Column) {
if (edit->mActiveSelectionMode == SelectionMode::Column) {
bCurrentLine = (vLine >= selectionBegin.line && vLine <= selectionEnd.line);
} else {
bCurrentLine = (edit->mCaretY == vLine);
@ -858,8 +860,8 @@ void SynEditTextPainter::paintLines()
// selection mode and a good start for the smNormal mode.
nLineSelStart = FirstCol;
nLineSelEnd = LastCol + 1;
if ((edit->mActiveSelectionMode == SynSelectionMode::Column) ||
((edit->mActiveSelectionMode == SynSelectionMode::Normal) && (cRow == vSelStart.Row)) ) {
if ((edit->mActiveSelectionMode == SelectionMode::Column) ||
((edit->mActiveSelectionMode == SelectionMode::Normal) && (cRow == vSelStart.Row)) ) {
int ch = edit->columnToChar(vLine,vSelStart.Column);
ch = edit->charToColumn(vLine,ch);
if (ch > LastCol) {
@ -870,8 +872,8 @@ void SynEditTextPainter::paintLines()
bComplexLine = true;
}
}
if ( (edit->mActiveSelectionMode == SynSelectionMode::Column) ||
((edit->mActiveSelectionMode == SynSelectionMode::Normal) && (cRow == vSelEnd.Row)) ) {
if ( (edit->mActiveSelectionMode == SelectionMode::Column) ||
((edit->mActiveSelectionMode == SelectionMode::Normal) && (cRow == vSelEnd.Row)) ) {
int ch = edit->columnToChar(vLine,vSelEnd.Column);
int col = edit->charToColumn(vLine,ch);
if (col<vSelEnd.Column)
@ -902,8 +904,8 @@ void SynEditTextPainter::paintLines()
nTokenColumnLen = edit->mDocument->lineColumns(vLine-1);
}
if (edit->mOptions.testFlag(eoShowSpecialChars) && (!bLineSelected) && (!bSpecialLine) && (nTokenColumnLen < vLastChar)) {
sToken = sToken + SynLineBreakGlyph;
nTokenColumnLen += edit->charColumns(SynLineBreakGlyph);
sToken = sToken + LineBreakGlyph;
nTokenColumnLen += edit->charColumns(LineBreakGlyph);
}
if (bComplexLine) {
setDrawingColors(true);
@ -923,12 +925,12 @@ void SynEditTextPainter::paintLines()
}
//Paint editingAreaBorders
if (bCurrentLine && edit->mInputPreeditString.length()>0) {
PSynEditingArea area = std::make_shared<SynEditingArea>();
PEditingArea area = std::make_shared<EditingArea>();
int col = edit->charToColumn(edit->mCaretY,edit->mCaretX);
int ch = edit->columnToChar(vLine,col);
area->beginX = edit->charToColumn(sLine,ch);
area->endX = edit->charToColumn(sLine,ch + edit->mInputPreeditString.length());
area->type = SynEditingAreaType::eatUnderLine;
area->type = EditingAreaType::eatUnderLine;
area->color = colFG;
areaList.append(area);
paintEditAreas(areaList);
@ -979,7 +981,7 @@ void SynEditTextPainter::paintLines()
|| sToken == "("
|| sToken == "{"
) {
SynRangeState rangeState = edit->mHighlighter->getRangeState();
HighlighterState rangeState = edit->mHighlighter->getState();
getBraceColorAttr(rangeState.bracketLevel
+rangeState.braceLevel
+rangeState.parenthesisLevel
@ -988,7 +990,7 @@ void SynEditTextPainter::paintLines()
|| sToken == ")"
|| sToken == "}"
){
SynRangeState rangeState = edit->mHighlighter->getRangeState();
HighlighterState rangeState = edit->mHighlighter->getState();
getBraceColorAttr(rangeState.bracketLevel
+rangeState.braceLevel
+rangeState.parenthesisLevel+1,
@ -1026,15 +1028,15 @@ void SynEditTextPainter::paintLines()
if (nTokenColumnLen > 0) {
sToken = edit->substringByColumns(sLine,nTokenColumnsBefore+1,nTokenColumnLen);
addHighlightToken(sToken, nTokenColumnsBefore - (vFirstChar - FirstCol),
nTokenColumnLen, vLine, PSynHighlighterAttribute());
nTokenColumnLen, vLine, PHighlighterAttribute());
}
}
// Draw LineBreak glyph.
if (edit->mOptions.testFlag(eoShowSpecialChars) && (!bLineSelected) &&
(!bSpecialLine) && (edit->mDocument->lineColumns(vLine-1) < vLastChar)) {
addHighlightToken(SynLineBreakGlyph,
addHighlightToken(LineBreakGlyph,
edit->mDocument->lineColumns(vLine-1) - (vFirstChar - FirstCol),
edit->charColumns(SynLineBreakGlyph),vLine, edit->mHighlighter->whitespaceAttribute());
edit->charColumns(LineBreakGlyph),vLine, edit->mHighlighter->whitespaceAttribute());
}
}
@ -1044,7 +1046,7 @@ void SynEditTextPainter::paintLines()
sFold = edit->highlighter()->foldString();
nFold = edit->stringColumns(sFold,edit->mDocument->lineColumns(vLine-1));
attr = edit->mHighlighter->symbolAttribute();
getBraceColorAttr(edit->mHighlighter->getRangeState().braceLevel,attr);
getBraceColorAttr(edit->mHighlighter->getState().braceLevel,attr);
addHighlightToken(sFold,edit->mDocument->lineColumns(vLine-1) - (vFirstChar - FirstCol)
, nFold, vLine, attr);
}
@ -1054,7 +1056,7 @@ void SynEditTextPainter::paintLines()
paintHighlightToken(true);
//Paint editingAreaBorders
foreach (const PSynEditingArea& area, areaList) {
foreach (const PEditingArea& area, areaList) {
if (bCurrentLine && edit->mInputPreeditString.length()>0) {
if (area->beginX > edit->mCaretX) {
area->beginX+=edit->mInputPreeditString.length();
@ -1067,12 +1069,12 @@ void SynEditTextPainter::paintLines()
area->endX = edit->charToColumn(sLine,area->endX);
}
if (bCurrentLine && edit->mInputPreeditString.length()>0) {
PSynEditingArea area = std::make_shared<SynEditingArea>();
PEditingArea area = std::make_shared<EditingArea>();
int col = edit->charToColumn(edit->mCaretY,edit->mCaretX);
int ch = edit->columnToChar(vLine,col);
area->beginX = edit->charToColumn(sLine,ch);
area->endX = edit->charToColumn(sLine,ch + edit->mInputPreeditString.length());
area->type = SynEditingAreaType::eatUnderLine;
area->type = EditingAreaType::eatUnderLine;
if (preeditAttr) {
area->color = preeditAttr->foreground();
} else {
@ -1093,3 +1095,4 @@ void SynEditTextPainter::paintLines()
bCurrentLine = false;
}
}
}

View File

@ -22,9 +22,9 @@
#include <QString>
#include "Types.h"
#include "highlighter/base.h"
#include "../utils.h"
#include "MiscClasses.h"
namespace QSynedit {
class SynEdit;
class SynEditTextPainter
{
@ -34,7 +34,7 @@ class SynEditTextPainter
QString s;
QColor FG;
QColor BG;
SynFontStyles Style;
FontStyles Style;
};
public:
@ -51,14 +51,14 @@ private:
void paintToken(const QString& token, int tokenLen, int columnsBefore,
int first, int last, bool isSelection, const QFont& font,
const QFont& fontForNonAscii);
void paintEditAreas(const SynEditingAreaList& areaList);
void paintEditAreas(const EditingAreaList& areaList);
void paintHighlightToken(bool bFillToEOL);
bool tokenIsSpaces(bool& bSpacesTest, const QString& token, bool& bIsSpaces);
void addHighlightToken(const QString& token, int columnsBefore, int tokenColumns,
int cLine, PSynHighlighterAttribute p_Attri);
int cLine, PHighlighterAttribute p_Attri);
void paintFoldAttributes();
void getBraceColorAttr(int level, PSynHighlighterAttribute &attr);
void getBraceColorAttr(int level, PHighlighterAttribute &attr);
void paintLines();
private:
@ -87,4 +87,6 @@ private:
SynTokenAccu TokenAccu;
};
}
#endif // TEXTPAINTER_H

View File

@ -18,6 +18,8 @@
#include "SynEdit.h"
#include <QDebug>
namespace QSynedit {
bool BufferCoord::operator==(const BufferCoord &coord)
{
return coord.ch == ch && coord.line == line;
@ -51,3 +53,5 @@ bool BufferCoord::operator!=(const BufferCoord &coord)
{
return coord.ch != ch || coord.line != line;
}
}

View File

@ -22,7 +22,9 @@
#include <QFlags>
#include <memory>
enum class SynSelectionMode {Normal, Line, Column};
namespace QSynedit {
enum class SelectionMode {Normal, Line, Column};
struct BufferCoord {
int ch;
@ -40,7 +42,7 @@ struct DisplayCoord {
int Row;
};
enum SynFontStyle {
enum FontStyle {
fsNone = 0,
fsBold = 0x0001,
fsItalic = 0x0002,
@ -48,27 +50,28 @@ enum SynFontStyle {
fsStrikeOut = 0x0008
};
Q_DECLARE_FLAGS(SynFontStyles,SynFontStyle)
Q_DECLARE_FLAGS(FontStyles,FontStyle)
Q_DECLARE_OPERATORS_FOR_FLAGS(SynFontStyles)
Q_DECLARE_OPERATORS_FOR_FLAGS(FontStyles)
enum class SynEditingAreaType {
enum class EditingAreaType {
eatRectangleBorder,
eatWaveUnderLine,
eatUnderLine
};
struct SynEditingArea {
struct EditingArea {
int beginX;
int endX;
QColor color;
SynEditingAreaType type;
EditingAreaType type;
};
using PSynEditingArea = std::shared_ptr<SynEditingArea>;
using SynEditingAreaList = QList<PSynEditingArea>;
using PSynEditingAreaList = std::shared_ptr<SynEditingAreaList>;
using PEditingArea = std::shared_ptr<EditingArea>;
using EditingAreaList = QList<PEditingArea>;
using PEditingAreaList = std::shared_ptr<EditingAreaList>;
}
#endif // TYPES_H

View File

@ -21,9 +21,10 @@
#include <QGuiApplication>
#include <QMimeData>
#include <QTextCodec>
#include "../../platform.h"
SynExporter::SynExporter()
namespace QSynedit {
SynExporter::SynExporter(const QByteArray charset):mCharset(charset)
{
mClipboardFormat = "text/plain";
mFont = QGuiApplication::font();
@ -31,7 +32,6 @@ SynExporter::SynExporter()
mForegroundColor = QGuiApplication::palette().color(QPalette::Text);
mUseBackground = false;
mExportAsText = false;
mCharset = pCharsetInfoManager->getDefaultSystemEncoding();
mFileEndingType = FileEndingType::Windows;
clear();
setTitle("");
@ -40,7 +40,7 @@ SynExporter::SynExporter()
void SynExporter::clear()
{
mBuffer.clear();
mLastStyle = SynFontStyle::fsNone;
mLastStyle = FontStyle::fsNone;
mLastBG = QGuiApplication::palette().color(QPalette::Base);
mLastFG = QGuiApplication::palette().color(QPalette::Text);
}
@ -90,7 +90,7 @@ void SynExporter::ExportRange(PSynDocument ALines, BufferCoord Start, BufferCoor
// export the line
mHighlighter->setLine(Line, i);
while (!mHighlighter->eol()) {
PSynHighlighterAttribute attri = mHighlighter->getTokenAttribute();
PHighlighterAttribute attri = mHighlighter->getTokenAttribute();
int startPos = mHighlighter->getTokenPos();
QString token = mHighlighter->getToken();
if (i==Start.line && (startPos+token.length() < Start.ch)) {
@ -166,12 +166,12 @@ void SynExporter::setFont(const QFont &font)
mFont = font;
}
PSynHighlighter SynExporter::highlighter() const
PHighlighter SynExporter::highlighter() const
{
return mHighlighter;
}
void SynExporter::setHighlighter(PSynHighlighter Value)
void SynExporter::setHighlighter(PHighlighter Value)
{
if (mHighlighter != Value) {
mHighlighter = Value;
@ -338,7 +338,7 @@ static QColor ValidatedColor(const QColor& color, const QColor& defaultColor) {
else
return defaultColor;
}
void SynExporter::SetTokenAttribute(PSynHighlighterAttribute Attri)
void SynExporter::SetTokenAttribute(PHighlighterAttribute Attri)
{
if (mFirstAttribute) {
mFirstAttribute = false;
@ -354,7 +354,7 @@ void SynExporter::SetTokenAttribute(PSynHighlighterAttribute Attri)
bool ChangedFG = (mLastFG != ValidatedColor(Attri->foreground(), mForegroundColor));
if (ChangedBG || ChangedFG || (mLastStyle != Attri->styles())) {
// which font style bits are to reset?
SynFontStyles ChangedStyles = mLastStyle & ~(Attri->styles());
FontStyles ChangedStyles = mLastStyle & ~(Attri->styles());
FormatAttributeDone(ChangedBG, ChangedFG, ChangedStyles);
// which font style bits are to set?
ChangedStyles = Attri->styles() & ~(mLastStyle);
@ -398,3 +398,5 @@ QString SynExporter::lineBreak()
}
return "\n";
}
}

View File

@ -20,15 +20,14 @@
#include <QString>
#include "../SynEdit.h"
using FormatTokenHandler = std::function<void(PSynHighlighter syntaxHighlighter, int Line, int column, const QString& token,
PSynHighlighterAttribute& attr)>;
namespace QSynedit {
using FormatTokenHandler = std::function<void(PHighlighter syntaxHighlighter, int Line, int column, const QString& token,
PHighlighterAttribute& attr)>;
class SynExporter
{
public:
explicit SynExporter();
explicit SynExporter(const QByteArray charset);
/**
* @brief Clears the output buffer and any internal data that relates to the last
@ -70,8 +69,8 @@ public:
QFont font() const;
void setFont(const QFont &font);
PSynHighlighter highlighter() const;
void setHighlighter(PSynHighlighter Value);
PHighlighter highlighter() const;
void setHighlighter(PHighlighter Value);
QString title() const;
void setTitle(const QString &Value);
@ -113,10 +112,10 @@ protected:
QString mDefaultFilter;
bool mExportAsText;
QFont mFont;
PSynHighlighter mHighlighter;
PHighlighter mHighlighter;
QColor mLastBG;
QColor mLastFG;
SynFontStyles mLastStyle;
FontStyles mLastStyle;
QMap<QChar,QString> mReplaceReserved;
QString mTitle;
bool mUseBackground;
@ -157,7 +156,7 @@ protected:
* @param FontStylesChanged
*/
virtual void FormatAttributeDone(bool BackgroundChanged, bool ForegroundChanged,
SynFontStyles FontStylesChanged) = 0;
FontStyles FontStylesChanged) = 0;
/**
* @brief Has to be overridden in descendant classes to add the opening format
@ -168,7 +167,7 @@ protected:
* @param FontStylesChanged
*/
virtual void FormatAttributeInit(bool BackgroundChanged, bool ForegroundChanged,
SynFontStyles FontStylesChanged) = 0;
FontStyles FontStylesChanged) = 0;
/**
* @brief Has to be overridden in descendant classes to add the closing format
* strings to the output buffer after the last token has been written.
@ -183,7 +182,7 @@ protected:
* @param FontStylesChanged
*/
virtual void FormatBeforeFirstAttribute(bool BackgroundChanged, bool ForegroundChanged,
SynFontStyles FontStylesChanged) = 0;
FontStyles FontStylesChanged) = 0;
/**
* @brief Can be overridden in descendant classes to add the formatted text of
* the actual token text to the output buffer.
@ -237,7 +236,7 @@ protected:
* added to the output buffer.
* @param Attri
*/
virtual void SetTokenAttribute(PSynHighlighterAttribute Attri);
virtual void SetTokenAttribute(PHighlighterAttribute Attri);
QTextCodec *getCodec();
private:
@ -246,5 +245,6 @@ private:
FormatTokenHandler mOnFormatToken;
};
}
#endif // SYNEXPORTER_H

View File

@ -18,7 +18,10 @@
#include "../MiscProcs.h"
#include <functional>
SynHTMLExporter::SynHTMLExporter(int tabSize)
namespace QSynedit {
SynHTMLExporter::SynHTMLExporter(int tabSize,const QByteArray charset):
SynExporter(charset)
{
mClipboardFormat = "text/html";
mDefaultFilter = "HTML Documents (*.htm;*.html)|*.htm;*.html";
@ -42,7 +45,7 @@ void SynHTMLExporter::setCreateHTMLFragment(bool createHTMLFragment)
mCreateHTMLFragment = createHTMLFragment;
}
QString SynHTMLExporter::AttriToCSS(PSynHighlighterAttribute Attri, const QString &UniqueAttriName)
QString SynHTMLExporter::AttriToCSS(PHighlighterAttribute Attri, const QString &UniqueAttriName)
{
QString StyleName = MakeValidName(UniqueAttriName);
@ -52,19 +55,19 @@ QString SynHTMLExporter::AttriToCSS(PSynHighlighterAttribute Attri, const QStrin
if (Attri->foreground().isValid())
Result += "color: " + ColorToHTML(Attri->foreground()) + "; ";
if (Attri->styles().testFlag(SynFontStyle::fsBold))
if (Attri->styles().testFlag(FontStyle::fsBold))
Result += "font-weight: bold; ";
if (Attri->styles().testFlag(SynFontStyle::fsItalic))
if (Attri->styles().testFlag(FontStyle::fsItalic))
Result += "font-style: italic; ";
if (Attri->styles().testFlag(SynFontStyle::fsUnderline))
if (Attri->styles().testFlag(FontStyle::fsUnderline))
Result += "text-decoration: underline; ";
if (Attri->styles().testFlag(SynFontStyle::fsStrikeOut))
if (Attri->styles().testFlag(FontStyle::fsStrikeOut))
Result += "text-decoration: line-through; ";
Result += "}";
return Result;
}
bool SynHTMLExporter::AttriToCSSCallback(PSynHighlighter , PSynHighlighterAttribute Attri, const QString& UniqueAttriName, QList<void *> params)
bool SynHTMLExporter::AttriToCSSCallback(PHighlighter , PHighlighterAttribute Attri, const QString& UniqueAttriName, QList<void *> params)
{
QString& styles = *static_cast<QString *>(params[0]);
styles.append(AttriToCSS(Attri,UniqueAttriName) + lineBreak());
@ -76,7 +79,7 @@ QString SynHTMLExporter::ColorToHTML(const QColor &AColor)
return AColor.name();
}
QString SynHTMLExporter::GetStyleName(PSynHighlighter Highlighter, PSynHighlighterAttribute Attri)
QString SynHTMLExporter::GetStyleName(PHighlighter Highlighter, PHighlighterAttribute Attri)
{
QString result;
enumHighlighterAttributes(Highlighter,false,
@ -101,9 +104,9 @@ QString SynHTMLExporter::MakeValidName(const QString &Name)
return Result;
}
bool SynHTMLExporter::StyleNameCallback(PSynHighlighter /*Highlighter*/, PSynHighlighterAttribute Attri, const QString& UniqueAttriName, QList<void *> params)
bool SynHTMLExporter::StyleNameCallback(PHighlighter /*Highlighter*/, PHighlighterAttribute Attri, const QString& UniqueAttriName, QList<void *> params)
{
PSynHighlighterAttribute& AttriToFind = *static_cast<PSynHighlighterAttribute*>(params[0]);
PHighlighterAttribute& AttriToFind = *static_cast<PHighlighterAttribute*>(params[0]);
QString& StyleName = *static_cast<QString *>(params[1]);
if (Attri == AttriToFind) {
@ -114,12 +117,12 @@ bool SynHTMLExporter::StyleNameCallback(PSynHighlighter /*Highlighter*/, PSynHig
return true;
}
void SynHTMLExporter::FormatAttributeDone(bool , bool , SynFontStyles )
void SynHTMLExporter::FormatAttributeDone(bool , bool , FontStyles )
{
AddData("</span>");
}
void SynHTMLExporter::FormatAttributeInit(bool , bool , SynFontStyles )
void SynHTMLExporter::FormatAttributeInit(bool , bool , FontStyles )
{
QString StyleName = GetStyleName(mHighlighter, mLastAttri);
AddData(QString("<span class=\"%1\">").arg(StyleName));
@ -130,7 +133,7 @@ void SynHTMLExporter::FormatAfterLastAttribute()
AddData("</span>");
}
void SynHTMLExporter::FormatBeforeFirstAttribute(bool, bool, SynFontStyles)
void SynHTMLExporter::FormatBeforeFirstAttribute(bool, bool, FontStyles)
{
QString StyleName = GetStyleName(mHighlighter, mLastAttri);
AddData(QString("<span class=\"%1\">").arg(StyleName));
@ -219,8 +222,9 @@ QString SynHTMLExporter::GetHeader()
return Result;
}
void SynHTMLExporter::SetTokenAttribute(PSynHighlighterAttribute Attri)
void SynHTMLExporter::SetTokenAttribute(PHighlighterAttribute Attri)
{
mLastAttri = Attri;
SynExporter::SetTokenAttribute(Attri);
}
}

View File

@ -19,38 +19,39 @@
#include "synexporter.h"
namespace QSynedit {
class SynHTMLExporter : public SynExporter
{
public:
SynHTMLExporter(int tabSize);
SynHTMLExporter(int tabSize,const QByteArray charset);
bool createHTMLFragment() const;
void setCreateHTMLFragment(bool createHTMLFragment);
protected:
bool mCreateHTMLFragment;
private:
PSynHighlighterAttribute mLastAttri;
QString AttriToCSS(PSynHighlighterAttribute Attri, const QString& UniqueAttriName);
bool AttriToCSSCallback(PSynHighlighter Highlighter, PSynHighlighterAttribute Attri,
PHighlighterAttribute mLastAttri;
QString AttriToCSS(PHighlighterAttribute Attri, const QString& UniqueAttriName);
bool AttriToCSSCallback(PHighlighter Highlighter, PHighlighterAttribute Attri,
const QString& UniqueAttriName, QList<void *> params);
QString ColorToHTML(const QColor &AColor);
QString GetStyleName(PSynHighlighter Highlighter,
PSynHighlighterAttribute Attri);
QString GetStyleName(PHighlighter Highlighter,
PHighlighterAttribute Attri);
QString MakeValidName(const QString &Name);
bool StyleNameCallback(PSynHighlighter Highlighter, PSynHighlighterAttribute Attri,
bool StyleNameCallback(PHighlighter Highlighter, PHighlighterAttribute Attri,
const QString& UniqueAttriName, QList<void *> params);
// SynExporter interface
protected:
void FormatAttributeDone(bool BackgroundChanged, bool ForegroundChanged, SynFontStyles FontStylesChanged);
void FormatAttributeInit(bool BackgroundChanged, bool ForegroundChanged, SynFontStyles FontStylesChanged);
void FormatAttributeDone(bool BackgroundChanged, bool ForegroundChanged, FontStyles FontStylesChanged);
void FormatAttributeInit(bool BackgroundChanged, bool ForegroundChanged, FontStyles FontStylesChanged);
void FormatAfterLastAttribute();
void FormatBeforeFirstAttribute(bool BackgroundChanged, bool ForegroundChanged, SynFontStyles FontStylesChanged);
void FormatBeforeFirstAttribute(bool BackgroundChanged, bool ForegroundChanged, FontStyles FontStylesChanged);
void FormatNewLine();
QString GetFooter();
QString GetFormatName();
QString GetHeader();
void SetTokenAttribute(PSynHighlighterAttribute Attri);
void SetTokenAttribute(PHighlighterAttribute Attri);
};
}
#endif // SYNHTMLEXPORTER_H

View File

@ -15,8 +15,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "synrtfexporter.h"
namespace QSynedit {
SynRTFExporter::SynRTFExporter():SynExporter()
SynRTFExporter::SynRTFExporter(const QByteArray charset):SynExporter(charset)
{
mDefaultFilter = "Rich Text Format Documents (*.rtf)|*.rtf";
mClipboardFormat = "application/x-qt-windows-mime;value=\"Rich Format Text\"";
@ -54,28 +55,28 @@ QString SynRTFExporter::GetFontTable()
return Result;
}
void SynRTFExporter::FormatAttributeDone(bool , bool , SynFontStyles FontStylesChanged)
void SynRTFExporter::FormatAttributeDone(bool , bool , FontStyles FontStylesChanged)
{
// nothing to do about the color, but reset the font style
if (FontStylesChanged.testFlag(SynFontStyle::fsBold)) {
if (FontStylesChanged.testFlag(FontStyle::fsBold)) {
mAttributesChanged = true;
AddData("\\b0");
}
if (FontStylesChanged.testFlag(SynFontStyle::fsItalic)) {
if (FontStylesChanged.testFlag(FontStyle::fsItalic)) {
mAttributesChanged = true;
AddData("\\i0");
}
if (FontStylesChanged.testFlag(SynFontStyle::fsUnderline)) {
if (FontStylesChanged.testFlag(FontStyle::fsUnderline)) {
mAttributesChanged = true;
AddData("\\ul0");
}
if (FontStylesChanged.testFlag(SynFontStyle::fsStrikeOut)) {
if (FontStylesChanged.testFlag(FontStyle::fsStrikeOut)) {
mAttributesChanged = true;
AddData("\\strike0");
}
}
void SynRTFExporter::FormatAttributeInit(bool BackgroundChanged, bool ForegroundChanged, SynFontStyles FontStylesChanged)
void SynRTFExporter::FormatAttributeInit(bool BackgroundChanged, bool ForegroundChanged, FontStyles FontStylesChanged)
{
// background color
if (BackgroundChanged) {
@ -92,19 +93,19 @@ void SynRTFExporter::FormatAttributeInit(bool BackgroundChanged, bool Foreground
}
// font styles
// nothing to do about the color, but reset the font style
if (FontStylesChanged.testFlag(SynFontStyle::fsBold)) {
if (FontStylesChanged.testFlag(FontStyle::fsBold)) {
mAttributesChanged = true;
AddData("\\b0");
}
if (FontStylesChanged.testFlag(SynFontStyle::fsItalic)) {
if (FontStylesChanged.testFlag(FontStyle::fsItalic)) {
mAttributesChanged = true;
AddData("\\i0");
}
if (FontStylesChanged.testFlag(SynFontStyle::fsUnderline)) {
if (FontStylesChanged.testFlag(FontStyle::fsUnderline)) {
mAttributesChanged = true;
AddData("\\ul0");
}
if (FontStylesChanged.testFlag(SynFontStyle::fsStrikeOut)) {
if (FontStylesChanged.testFlag(FontStyle::fsStrikeOut)) {
mAttributesChanged = true;
AddData("\\strike0");
}
@ -119,7 +120,7 @@ void SynRTFExporter::FormatAfterLastAttribute()
// no need to reset the font style here...
}
void SynRTFExporter::FormatBeforeFirstAttribute(bool BackgroundChanged, bool ForegroundChanged, SynFontStyles FontStylesChanged)
void SynRTFExporter::FormatBeforeFirstAttribute(bool BackgroundChanged, bool ForegroundChanged, FontStyles FontStylesChanged)
{
FormatAttributeInit(BackgroundChanged, ForegroundChanged, FontStylesChanged);
}
@ -164,3 +165,4 @@ QString SynRTFExporter::GetHeader()
.arg(GetColorIndex(mBackgroundColor));
return Result;
}
}

View File

@ -19,10 +19,12 @@
#include "synexporter.h"
namespace QSynedit {
class SynRTFExporter : public SynExporter
{
public:
explicit SynRTFExporter();
explicit SynRTFExporter(const QByteArray charset);
private:
bool mAttributesChanged;
QList<QColor> mListColors;
@ -32,14 +34,15 @@ private:
// SynExporter interface
protected:
void FormatAttributeDone(bool BackgroundChanged, bool ForegroundChanged, SynFontStyles FontStylesChanged) override;
void FormatAttributeInit(bool BackgroundChanged, bool ForegroundChanged, SynFontStyles FontStylesChanged) override;
void FormatAttributeDone(bool BackgroundChanged, bool ForegroundChanged, FontStyles FontStylesChanged) override;
void FormatAttributeInit(bool BackgroundChanged, bool ForegroundChanged, FontStyles FontStylesChanged) override;
void FormatAfterLastAttribute() override;
void FormatBeforeFirstAttribute(bool BackgroundChanged, bool ForegroundChanged, SynFontStyles FontStylesChanged) override;
void FormatBeforeFirstAttribute(bool BackgroundChanged, bool ForegroundChanged, FontStyles FontStylesChanged) override;
void FormatNewLine() override;
QString GetFooter() override;
QString GetFormatName() override;
QString GetHeader() override;
};
}
#endif // SYNRTFEXPORTER_H

View File

@ -17,7 +17,9 @@
#include "asm.h"
#include "../Constants.h"
const QSet<QString> SynEditASMHighlighter::Keywords {
namespace QSynedit {
const QSet<QString> ASMHighlighter::Keywords {
"aaa","aad","aam","adc","add","and","arpl","bound","bsf","bsr","bswap","bt","btc","btr","bts",
"call","cbw","cdq","clc","cld","cli","clts","cmc","cmp","cmps","cmpsb","cmpsd","cmpsw",
"cmpxchg","cwd","cwde","daa","das","dec","div","emms","enter","f2xm1","fabs","fadd","faddp","fbld",
@ -53,56 +55,56 @@ const QSet<QString> SynEditASMHighlighter::Keywords {
SynEditASMHighlighter::SynEditASMHighlighter()
ASMHighlighter::ASMHighlighter()
{
mCommentAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrComment);
mCommentAttribute->setStyles(SynFontStyle::fsItalic);
mCommentAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrComment);
mCommentAttribute->setStyles(FontStyle::fsItalic);
addAttribute(mCommentAttribute);
mIdentifierAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrIdentifier);
mIdentifierAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrIdentifier);
addAttribute(mIdentifierAttribute);
mKeywordAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrReservedWord);
mKeywordAttribute->setStyles(SynFontStyle::fsBold);
mKeywordAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrReservedWord);
mKeywordAttribute->setStyles(FontStyle::fsBold);
addAttribute(mKeywordAttribute);
mNumberAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrNumber);
mNumberAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrNumber);
addAttribute(mNumberAttribute);
mWhitespaceAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrSpace);
mWhitespaceAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrSpace);
addAttribute(mWhitespaceAttribute);
mStringAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrString);
mStringAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrString);
addAttribute(mStringAttribute);
mSymbolAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrSymbol);
mSymbolAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrSymbol);
addAttribute(mSymbolAttribute);
}
PSynHighlighterAttribute SynEditASMHighlighter::numberAttribute()
PHighlighterAttribute ASMHighlighter::numberAttribute()
{
return mNumberAttribute;
}
void SynEditASMHighlighter::CommentProc()
void ASMHighlighter::CommentProc()
{
mTokenID = TokenKind::Comment;
mTokenID = TokenId::Comment;
do {
mRun++;
} while (! (mLine[mRun]==0 || mLine[mRun] == '\r' || mLine[mRun]=='\n'));
}
void SynEditASMHighlighter::CRProc()
void ASMHighlighter::CRProc()
{
mTokenID = TokenKind::Space;
mTokenID = TokenId::Space;
mRun++;
if (mLine[mRun] == '\n')
mRun++;
}
void SynEditASMHighlighter::GreaterProc()
void ASMHighlighter::GreaterProc()
{
mRun++;
mTokenID = TokenKind::Symbol;
mTokenID = TokenId::Symbol;
if (mLine[mRun] == '=')
mRun++;
}
void SynEditASMHighlighter::IdentProc()
void ASMHighlighter::IdentProc()
{
int start = mRun;
while (isIdentChar(mLine[mRun])) {
@ -110,35 +112,35 @@ void SynEditASMHighlighter::IdentProc()
}
QString s = mLineString.mid(start,mRun-start);
if (Keywords.contains(s)) {
mTokenID = TokenKind::Key;
mTokenID = TokenId::Key;
} else {
mTokenID = TokenKind::Identifier;
mTokenID = TokenId::Identifier;
}
}
void SynEditASMHighlighter::LFProc()
void ASMHighlighter::LFProc()
{
mTokenID = TokenKind::Space;
mTokenID = TokenId::Space;
mRun++;
}
void SynEditASMHighlighter::LowerProc()
void ASMHighlighter::LowerProc()
{
mRun++;
mTokenID = TokenKind::Symbol;
mTokenID = TokenId::Symbol;
if (mLine[mRun]=='=' || mLine[mRun]== '>')
mRun++;
}
void SynEditASMHighlighter::NullProc()
void ASMHighlighter::NullProc()
{
mTokenID = TokenKind::Null;
mTokenID = TokenId::Null;
}
void SynEditASMHighlighter::NumberProc()
void ASMHighlighter::NumberProc()
{
mRun++;
mTokenID = TokenKind::Number;
mTokenID = TokenId::Number;
while (true) {
QChar ch = mLine[mRun];
if (!((ch>='0' && ch<='9') || (ch=='.') || (ch >= 'a' && ch<='f')
@ -148,9 +150,9 @@ void SynEditASMHighlighter::NumberProc()
}
}
void SynEditASMHighlighter::SingleQuoteStringProc()
void ASMHighlighter::SingleQuoteStringProc()
{
mTokenID = TokenKind::String;
mTokenID = TokenId::String;
if ((mRun+2 < mLineString.size()) && (mLine[mRun + 1] == '\'') && (mLine[mRun + 2] == '\''))
mRun += 2;
while (true) {
@ -162,23 +164,23 @@ void SynEditASMHighlighter::SingleQuoteStringProc()
mRun++;
}
void SynEditASMHighlighter::SlashProc()
void ASMHighlighter::SlashProc()
{
mRun++;
if (mLine[mRun] == '/') {
mTokenID = TokenKind::Comment;
mTokenID = TokenId::Comment;
while (true) {
mRun++;
if (mLine[mRun] == 0 || mLine[mRun] == '\r' || mLine[mRun] == '\n')
break;
}
} else
mTokenID = TokenKind::Symbol;
mTokenID = TokenId::Symbol;
}
void SynEditASMHighlighter::SpaceProc()
void ASMHighlighter::SpaceProc()
{
mTokenID = TokenKind::Space;
mTokenID = TokenId::Space;
while (true) {
mRun++;
if (mLine[mRun] == 0 || mLine[mRun] == '\r' || mLine[mRun] == '\n')
@ -188,9 +190,9 @@ void SynEditASMHighlighter::SpaceProc()
}
}
void SynEditASMHighlighter::StringProc()
void ASMHighlighter::StringProc()
{
mTokenID = TokenKind::String;
mTokenID = TokenId::String;
if ((mRun+2 < mLineString.size()) && (mLine[mRun + 1] == '\"') && (mLine[mRun + 2] == '\"'))
mRun += 2;
while (true) {
@ -204,95 +206,95 @@ void SynEditASMHighlighter::StringProc()
mRun++;
}
void SynEditASMHighlighter::SymbolProc()
void ASMHighlighter::SymbolProc()
{
mRun++;
mTokenID = TokenKind::Symbol;
mTokenID = TokenId::Symbol;
}
void SynEditASMHighlighter::UnknownProc()
void ASMHighlighter::UnknownProc()
{
mRun++;
mTokenID = TokenKind::Unknown;
mTokenID = TokenId::Unknown;
}
bool SynEditASMHighlighter::eol() const
bool ASMHighlighter::eol() const
{
return mTokenID == TokenKind::Null;
return mTokenID == TokenId::Null;
}
QString SynEditASMHighlighter::languageName()
QString ASMHighlighter::languageName()
{
return "asm";
}
SynHighlighterLanguage SynEditASMHighlighter::language()
HighlighterLanguage ASMHighlighter::language()
{
return SynHighlighterLanguage::Asssembly;
return HighlighterLanguage::Asssembly;
}
QString SynEditASMHighlighter::getToken() const
QString ASMHighlighter::getToken() const
{
return mLineString.mid(mTokenPos,mRun-mTokenPos);
}
PSynHighlighterAttribute SynEditASMHighlighter::getTokenAttribute() const
PHighlighterAttribute ASMHighlighter::getTokenAttribute() const
{
switch(mTokenID) {
case TokenKind::Comment:
case TokenId::Comment:
return mCommentAttribute;
case TokenKind::Identifier:
case TokenId::Identifier:
return mIdentifierAttribute;
case TokenKind::Key:
case TokenId::Key:
return mKeywordAttribute;
case TokenKind::Number:
case TokenId::Number:
return mNumberAttribute;
case TokenKind::Space:
case TokenId::Space:
return mWhitespaceAttribute;
case TokenKind::String:
case TokenId::String:
return mStringAttribute;
case TokenKind::Symbol:
case TokenId::Symbol:
return mSymbolAttribute;
case TokenKind::Unknown:
case TokenId::Unknown:
return mIdentifierAttribute;
}
return PSynHighlighterAttribute();
return PHighlighterAttribute();
}
SynTokenKind SynEditASMHighlighter::getTokenKind()
TokenKind ASMHighlighter::getTokenKind()
{
return mTokenID;
}
SynHighlighterTokenType SynEditASMHighlighter::getTokenType()
TokenType ASMHighlighter::getTokenType()
{
switch(mTokenID) {
case TokenKind::Comment:
return SynHighlighterTokenType::Comment;
case TokenKind::Identifier:
return SynHighlighterTokenType::Identifier;
case TokenKind::Key:
return SynHighlighterTokenType::Keyword;
case TokenKind::Number:
return SynHighlighterTokenType::Number;
case TokenKind::Space:
return SynHighlighterTokenType::Space;
case TokenKind::String:
return SynHighlighterTokenType::String;
case TokenKind::Symbol:
return SynHighlighterTokenType::Symbol;
case TokenKind::Unknown:
return SynHighlighterTokenType::Default;
case TokenId::Comment:
return TokenType::Comment;
case TokenId::Identifier:
return TokenType::Identifier;
case TokenId::Key:
return TokenType::Keyword;
case TokenId::Number:
return TokenType::Number;
case TokenId::Space:
return TokenType::Space;
case TokenId::String:
return TokenType::String;
case TokenId::Symbol:
return TokenType::Symbol;
case TokenId::Unknown:
return TokenType::Default;
}
return SynHighlighterTokenType::Default;
return TokenType::Default;
}
int SynEditASMHighlighter::getTokenPos()
int ASMHighlighter::getTokenPos()
{
return mTokenPos;
}
void SynEditASMHighlighter::next()
void ASMHighlighter::next()
{
mTokenPos = mRun;
switch(mLine[mRun].unicode()) {
@ -353,7 +355,7 @@ void SynEditASMHighlighter::next()
}
}
void SynEditASMHighlighter::setLine(const QString &newLine, int lineNumber)
void ASMHighlighter::setLine(const QString &newLine, int lineNumber)
{
mLineString = newLine;
mLine = mLineString.data();
@ -362,47 +364,48 @@ void SynEditASMHighlighter::setLine(const QString &newLine, int lineNumber)
next();
}
SynHighlighterClass SynEditASMHighlighter::getClass() const
HighlighterClass ASMHighlighter::getClass() const
{
return SynHighlighterClass::CppHighlighter;
return HighlighterClass::CppHighlighter;
}
QString SynEditASMHighlighter::getName() const
QString ASMHighlighter::getName() const
{
return SYN_HIGHLIGHTER_CPP;
}
bool SynEditASMHighlighter::getTokenFinished() const
bool ASMHighlighter::getTokenFinished() const
{
return true;
}
bool SynEditASMHighlighter::isLastLineCommentNotFinished(int /*state*/) const
bool ASMHighlighter::isLastLineCommentNotFinished(int /*state*/) const
{
return true;
}
bool SynEditASMHighlighter::isLastLineStringNotFinished(int /*state*/) const
bool ASMHighlighter::isLastLineStringNotFinished(int /*state*/) const
{
return true;
}
SynRangeState SynEditASMHighlighter::getRangeState() const
HighlighterState ASMHighlighter::getState() const
{
return SynRangeState();
return HighlighterState();
}
void SynEditASMHighlighter::setState(const SynRangeState&)
void ASMHighlighter::setState(const HighlighterState&)
{
}
void SynEditASMHighlighter::resetState()
void ASMHighlighter::resetState()
{
}
QSet<QString> SynEditASMHighlighter::keywords() const
QSet<QString> ASMHighlighter::keywords() const
{
return Keywords;
}
}

View File

@ -19,10 +19,11 @@
#include "base.h"
namespace QSynedit {
class SynEditASMHighlighter : public SynHighlighter
class ASMHighlighter : public Highlighter
{
enum TokenKind {
enum TokenId {
Comment,
Identifier,
Key,
@ -34,8 +35,8 @@ class SynEditASMHighlighter : public SynHighlighter
Unknown
};
public:
explicit SynEditASMHighlighter();
PSynHighlighterAttribute numberAttribute();
explicit ASMHighlighter();
PHighlighterAttribute numberAttribute();
static const QSet<QString> Keywords;
private:
@ -46,8 +47,8 @@ private:
int mStringLen;
QChar mToIdent;
int mTokenPos;
SynTokenKind mTokenID;
PSynHighlighterAttribute mNumberAttribute;
TokenKind mTokenID;
PHighlighterAttribute mNumberAttribute;
private:
void CommentProc();
@ -71,18 +72,18 @@ public:
bool eol() const override;
QString languageName() override;
SynHighlighterLanguage language() override;
HighlighterLanguage language() override;
QString getToken() const override;
PSynHighlighterAttribute getTokenAttribute() const override;
SynTokenKind getTokenKind() override;
SynHighlighterTokenType getTokenType() override;
PHighlighterAttribute getTokenAttribute() const override;
TokenKind getTokenKind() override;
TokenType getTokenType() override;
int getTokenPos() override;
void next() override;
void setLine(const QString &newLine, int lineNumber) override;
// SynHighlighter interface
public:
SynHighlighterClass getClass() const override;
HighlighterClass getClass() const override;
QString getName() const override;
// SynHighlighter interface
@ -90,8 +91,8 @@ public:
bool getTokenFinished() const override;
bool isLastLineCommentNotFinished(int state) const override;
bool isLastLineStringNotFinished(int state) const override;
SynRangeState getRangeState() const override;
void setState(const SynRangeState& rangeState) override;
HighlighterState getState() const override;
void setState(const HighlighterState& rangeState) override;
void resetState() override;
// SynHighlighter interface
@ -99,4 +100,6 @@ public:
QSet<QString> keywords() const override;
};
}
#endif // SYNEDITASMHIGHLIGHTER_H

View File

@ -17,85 +17,86 @@
#include "base.h"
#include "../Constants.h"
SynHighlighter::SynHighlighter() :
namespace QSynedit {
Highlighter::Highlighter() :
mEnabled(true),
mWordBreakChars{ SynWordBreakChars }
mWordBreakChars{ WordBreakChars }
{
}
const QMap<QString, PSynHighlighterAttribute>& SynHighlighter::attributes() const
const QMap<QString, PHighlighterAttribute>& Highlighter::attributes() const
{
return mAttributes;
}
const QSet<QChar>& SynHighlighter::wordBreakChars() const
const QSet<QChar>& Highlighter::wordBreakChars() const
{
return mWordBreakChars;
}
PSynHighlighterAttribute SynHighlighter::commentAttribute() const
PHighlighterAttribute Highlighter::commentAttribute() const
{
return mCommentAttribute;
}
PSynHighlighterAttribute SynHighlighter::identifierAttribute() const
PHighlighterAttribute Highlighter::identifierAttribute() const
{
return mIdentifierAttribute;
}
PSynHighlighterAttribute SynHighlighter::keywordAttribute() const
PHighlighterAttribute Highlighter::keywordAttribute() const
{
return mKeywordAttribute;
}
PSynHighlighterAttribute SynHighlighter::stringAttribute() const
PHighlighterAttribute Highlighter::stringAttribute() const
{
return mStringAttribute;
}
PSynHighlighterAttribute SynHighlighter::whitespaceAttribute() const
PHighlighterAttribute Highlighter::whitespaceAttribute() const
{
return mWhitespaceAttribute;
}
PSynHighlighterAttribute SynHighlighter::symbolAttribute() const
PHighlighterAttribute Highlighter::symbolAttribute() const
{
return mSymbolAttribute;
}
SynHighlighterTokenType SynHighlighter::getTokenType()
TokenType Highlighter::getTokenType()
{
return SynHighlighterTokenType::Default;
return TokenType::Default;
}
bool SynHighlighter::isKeyword(const QString &)
bool Highlighter::isKeyword(const QString &)
{
return false;
}
void SynHighlighter::nextToEol()
void Highlighter::nextToEol()
{
while (!eol())
next();
}
QSet<QString> SynHighlighter::keywords() const
QSet<QString> Highlighter::keywords() const
{
return QSet<QString>();
}
QString SynHighlighter::foldString()
QString Highlighter::foldString()
{
return " ... }";
}
bool SynHighlighter::isSpaceChar(const QChar &ch)
bool Highlighter::isSpaceChar(const QChar &ch)
{
return ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n';
}
bool SynHighlighter::isWordBreakChar(const QChar &ch)
bool Highlighter::isWordBreakChar(const QChar &ch)
{
switch (ch.unicode()) {
case '.':
@ -129,7 +130,7 @@ bool SynHighlighter::isWordBreakChar(const QChar &ch)
}
}
bool SynHighlighter::isIdentChar(const QChar &ch) const
bool Highlighter::isIdentChar(const QChar &ch) const
{
if (ch == '_') {
return true;
@ -146,96 +147,96 @@ bool SynHighlighter::isIdentChar(const QChar &ch) const
return false;
}
void SynHighlighter::addAttribute(PSynHighlighterAttribute attribute)
void Highlighter::addAttribute(PHighlighterAttribute attribute)
{
mAttributes[attribute->name()]=attribute;
}
void SynHighlighter::clearAttributes()
void Highlighter::clearAttributes()
{
mAttributes.clear();
}
int SynHighlighter::attributesCount() const
int Highlighter::attributesCount() const
{
return mAttributes.size();
}
PSynHighlighterAttribute SynHighlighter::getAttribute(const QString &name) const
PHighlighterAttribute Highlighter::getAttribute(const QString &name) const
{
auto search = mAttributes.find(name);
if (search!=mAttributes.end()) {
return search.value();
}
return PSynHighlighterAttribute();
return PHighlighterAttribute();
}
bool SynHighlighter::enabled() const
bool Highlighter::enabled() const
{
return mEnabled;
}
void SynHighlighter::setEnabled(bool value)
void Highlighter::setEnabled(bool value)
{
if (value != mEnabled) {
mEnabled = value;
}
}
SynFontStyles SynHighlighterAttribute::styles() const
FontStyles HighlighterAttribute::styles() const
{
return mStyles;
}
void SynHighlighterAttribute::setStyles(const SynFontStyles &styles)
void HighlighterAttribute::setStyles(const FontStyles &styles)
{
if (mStyles!=styles) {
mStyles = styles;
}
}
QColor SynHighlighterAttribute::foreground() const
QColor HighlighterAttribute::foreground() const
{
return mForeground;
}
void SynHighlighterAttribute::setForeground(const QColor &color)
void HighlighterAttribute::setForeground(const QColor &color)
{
mForeground = color;
}
QColor SynHighlighterAttribute::background() const
QColor HighlighterAttribute::background() const
{
return mBackground;
}
void SynHighlighterAttribute::setBackground(const QColor &background)
void HighlighterAttribute::setBackground(const QColor &background)
{
mBackground = background;
}
QString SynHighlighterAttribute::name() const
QString HighlighterAttribute::name() const
{
return mName;
}
void SynHighlighterAttribute::setName(const QString &name)
void HighlighterAttribute::setName(const QString &name)
{
if (mName!=name) {
mName = name;
}
}
SynHighlighterAttribute::SynHighlighterAttribute(const QString &name):
HighlighterAttribute::HighlighterAttribute(const QString &name):
mForeground(QColor()),
mBackground(QColor()),
mName(name),
mStyles(SynFontStyle::fsNone)
mStyles(FontStyle::fsNone)
{
}
bool SynRangeState::operator==(const SynRangeState &s2)
bool HighlighterState::operator==(const HighlighterState &s2)
{
// indents contains the information of brace/parenthesis/brackets embedded levels
return (state == s2.state)
@ -243,14 +244,14 @@ bool SynRangeState::operator==(const SynRangeState &s2)
;
}
int SynRangeState::getLastIndent()
int HighlighterState::getLastIndent()
{
if (indents.isEmpty())
return -1;
return indents.back();
}
SynRangeState::SynRangeState():
HighlighterState::HighlighterState():
state(0),
braceLevel(0),
bracketLevel(0),
@ -260,3 +261,4 @@ SynRangeState::SynRangeState():
firstIndentThisLine(0)
{
}
}

View File

@ -26,6 +26,7 @@
#include <QVector>
#include "../Types.h"
namespace QSynedit {
enum SynIndentType {
sitBrace = 0,
sitParenthesis = 1,
@ -33,7 +34,7 @@ enum SynIndentType {
sitStatement = 3,
};
struct SynRangeState {
struct HighlighterState {
int state; // current syntax parsing state
int braceLevel; // current braces embedding level (needed by rainbow color)
int bracketLevel; // current brackets embedding level (needed by rainbow color)
@ -46,41 +47,41 @@ struct SynRangeState {
QVector<int> matchingIndents; /* the indent matched ( and removed )
but not started at this line
(need by auto indent) */
bool operator==(const SynRangeState& s2);
bool operator==(const HighlighterState& s2);
int getLastIndent();
SynRangeState();
HighlighterState();
};
typedef int SynTokenKind;
typedef int TokenKind;
enum class SynHighlighterTokenType {
enum class TokenType {
Default, Space, Comment,
PreprocessDirective, String, StringEscapeSequence,
Identifier, Symbol,
Character, Keyword, Number};
enum class SynHighlighterClass {
enum class HighlighterClass {
Composition,
CppHighlighter,
AsmHighlighter,
GLSLHighlighter
};
enum class SynHighlighterLanguage {
enum class HighlighterLanguage {
Asssembly,
Cpp,
GLSL
};
class SynHighlighterAttribute {
class HighlighterAttribute {
public:
explicit SynHighlighterAttribute(const QString& name);
explicit HighlighterAttribute(const QString& name);
QString name() const;
void setName(const QString &name);
SynFontStyles styles() const;
void setStyles(const SynFontStyles &styles);
FontStyles styles() const;
void setStyles(const FontStyles &styles);
QColor foreground() const;
void setForeground(const QColor &color);
@ -92,58 +93,58 @@ private:
QColor mForeground;
QColor mBackground;
QString mName;
SynFontStyles mStyles;
FontStyles mStyles;
};
typedef std::shared_ptr<SynHighlighterAttribute> PSynHighlighterAttribute;
using SynHighlighterAttributeList = QVector<PSynHighlighterAttribute>;
typedef std::shared_ptr<HighlighterAttribute> PHighlighterAttribute;
using HighlighterAttributeList = QVector<PHighlighterAttribute>;
class SynHighlighter {
class Highlighter {
public:
explicit SynHighlighter();
explicit Highlighter();
const QMap<QString, PSynHighlighterAttribute>& attributes() const;
const QMap<QString, PHighlighterAttribute>& attributes() const;
const QSet<QChar>& wordBreakChars() const;
PSynHighlighterAttribute commentAttribute() const;
PHighlighterAttribute commentAttribute() const;
PSynHighlighterAttribute identifierAttribute() const;
PHighlighterAttribute identifierAttribute() const;
PSynHighlighterAttribute keywordAttribute() const;
PHighlighterAttribute keywordAttribute() const;
PSynHighlighterAttribute stringAttribute() const;
PHighlighterAttribute stringAttribute() const;
PSynHighlighterAttribute whitespaceAttribute() const;
PHighlighterAttribute whitespaceAttribute() const;
PSynHighlighterAttribute symbolAttribute() const;
PHighlighterAttribute symbolAttribute() const;
virtual bool isIdentChar(const QChar& ch) const;
virtual SynHighlighterClass getClass() const = 0;
virtual HighlighterClass getClass() const = 0;
virtual QString getName() const = 0;
virtual bool getTokenFinished() const = 0;
virtual bool isLastLineCommentNotFinished(int state) const = 0;
virtual bool isLastLineStringNotFinished(int state) const = 0;
virtual bool eol() const = 0;
virtual SynRangeState getRangeState() const = 0;
virtual HighlighterState getState() const = 0;
virtual QString getToken() const=0;
virtual PSynHighlighterAttribute getTokenAttribute() const=0;
virtual SynHighlighterTokenType getTokenType();
virtual SynTokenKind getTokenKind() = 0;
virtual PHighlighterAttribute getTokenAttribute() const=0;
virtual TokenType getTokenType();
virtual TokenKind getTokenKind() = 0;
virtual int getTokenPos() = 0;
virtual bool isKeyword(const QString& word);
virtual void next() = 0;
virtual void nextToEol();
virtual void setState(const SynRangeState& rangeState) = 0;
virtual void setState(const HighlighterState& rangeState) = 0;
virtual void setLine(const QString& newLine, int lineNumber) = 0;
virtual void resetState() = 0;
virtual QSet<QString> keywords() const;
virtual QString languageName() = 0;
virtual SynHighlighterLanguage language() = 0;
virtual HighlighterLanguage language() = 0;
virtual QString foldString();
@ -151,27 +152,28 @@ public:
virtual bool isWordBreakChar(const QChar& ch);
bool enabled() const;
void setEnabled(bool value);
virtual PSynHighlighterAttribute getAttribute(const QString& name) const;
virtual PHighlighterAttribute getAttribute(const QString& name) const;
protected:
PSynHighlighterAttribute mCommentAttribute;
PSynHighlighterAttribute mIdentifierAttribute;
PSynHighlighterAttribute mKeywordAttribute;
PSynHighlighterAttribute mStringAttribute;
PSynHighlighterAttribute mWhitespaceAttribute;
PSynHighlighterAttribute mSymbolAttribute;
PHighlighterAttribute mCommentAttribute;
PHighlighterAttribute mIdentifierAttribute;
PHighlighterAttribute mKeywordAttribute;
PHighlighterAttribute mStringAttribute;
PHighlighterAttribute mWhitespaceAttribute;
PHighlighterAttribute mSymbolAttribute;
void addAttribute(PSynHighlighterAttribute attribute);
void addAttribute(PHighlighterAttribute attribute);
void clearAttributes();
virtual int attributesCount() const;
private:
QMap<QString,PSynHighlighterAttribute> mAttributes;
QMap<QString,PHighlighterAttribute> mAttributes;
bool mEnabled;
QSet<QChar> mWordBreakChars;
};
using PSynHighlighter = std::shared_ptr<SynHighlighter>;
using SynHighlighterList = QVector<PSynHighlighter>;
using PHighlighter = std::shared_ptr<Highlighter>;
using HighlighterList = QVector<PHighlighter>;
}
#endif // SYNHIGHLIGTERBASE_H

View File

@ -17,86 +17,88 @@
#include "composition.h"
#include "../Constants.h"
SynHighlightComposition::SynHighlightComposition()
namespace QSynedit {
CompositedHighlighter::CompositedHighlighter()
{
}
SynHighlighterClass SynHighlightComposition::getClass() const
HighlighterClass CompositedHighlighter::getClass() const
{
return SynHighlighterClass::Composition;
return HighlighterClass::Composition;
}
QString SynHighlightComposition::getName() const
QString CompositedHighlighter::getName() const
{
return "SynHighlightComposition";
}
SynScheme::SynScheme(QObject *parent):
HighlighterSchema::HighlighterSchema(QObject *parent):
QObject(parent),
mCaseSensitive(true)
{
mMarkerAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrMarker);
mMarkerAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrMarker);
mMarkerAttribute->setForeground(Qt::yellow);
mMarkerAttribute->setStyles(SynFontStyle::fsBold);
mMarkerAttribute->setStyles(FontStyle::fsBold);
}
QString SynScheme::endExpr() const
QString HighlighterSchema::endExpr() const
{
return mEndExpr;
}
void SynScheme::setEndExpr(const QString &endExpr)
void HighlighterSchema::setEndExpr(const QString &endExpr)
{
mEndExpr = endExpr;
}
QString SynScheme::getStartExpr() const
QString HighlighterSchema::getStartExpr() const
{
return StartExpr;
}
void SynScheme::setStartExpr(const QString &value)
void HighlighterSchema::setStartExpr(const QString &value)
{
StartExpr = value;
}
PSynHighlighter SynScheme::getHighlighter() const
PHighlighter HighlighterSchema::getHighlighter() const
{
return mHighlighter;
}
void SynScheme::setHighlighter(const PSynHighlighter &highlighter)
void HighlighterSchema::setHighlighter(const PHighlighter &highlighter)
{
mHighlighter = highlighter;
}
PSynHighlighterAttribute SynScheme::getMarkerAttribute() const
PHighlighterAttribute HighlighterSchema::getMarkerAttribute() const
{
return mMarkerAttribute;
}
QString SynScheme::getSchemeName() const
QString HighlighterSchema::getSchemeName() const
{
return mSchemeName;
}
void SynScheme::setSchemeName(const QString &schemeName)
void HighlighterSchema::setSchemeName(const QString &schemeName)
{
mSchemeName = schemeName;
}
int SynScheme::getCaseSensitive() const
int HighlighterSchema::getCaseSensitive() const
{
return mCaseSensitive;
}
void SynScheme::setCaseSensitive(int caseSensitive)
void HighlighterSchema::setCaseSensitive(int caseSensitive)
{
mCaseSensitive = caseSensitive;
}
QString SynScheme::ConvertExpression(const QString &Value)
QString HighlighterSchema::ConvertExpression(const QString &Value)
{
if (!mCaseSensitive) {
return Value.toUpper();
@ -105,5 +107,7 @@ QString SynScheme::ConvertExpression(const QString &Value)
}
}
void SynScheme::MarkerAttriChanged() {
void HighlighterSchema::MarkerAttriChanged() {
}
}

View File

@ -20,26 +20,27 @@
#include <memory>
#include <QObject>
class SynSchema;
using PSynSchema = std::shared_ptr<SynSchema>;
namespace QSynedit {
class HighlighterSchema;
using PHighlighterSchema = std::shared_ptr<HighlighterSchema>;
using OnCheckMarker = std::function<void(PSynSchema Sender,int &StartPos, int &MarkerLen,
std::shared_ptr<QString>& MarkerText , int Line)>;
//using OnCheckMarker = std::function<void(PHighlighterSchema Sender,int &StartPos, int &MarkerLen,
// std::shared_ptr<QString>& MarkerText , int Line)>;
class SynScheme : public QObject {
class HighlighterSchema : public QObject {
Q_OBJECT
public:
explicit SynScheme(QObject* parent=nullptr);
explicit HighlighterSchema(QObject* parent=nullptr);
QString endExpr() const;
void setEndExpr(const QString &endExpr);
QString getStartExpr() const;
void setStartExpr(const QString &value);
PSynHighlighter getHighlighter() const;
void setHighlighter(const PSynHighlighter &highlighter);
PHighlighter getHighlighter() const;
void setHighlighter(const PHighlighter &highlighter);
PSynHighlighterAttribute getMarkerAttribute() const;
PHighlighterAttribute getMarkerAttribute() const;
QString getSchemeName() const;
void setSchemeName(const QString &schemeName);
@ -50,12 +51,12 @@ public:
private:
QString mEndExpr;
QString StartExpr;
PSynHighlighter mHighlighter;
PSynHighlighterAttribute mMarkerAttribute;
PHighlighter mHighlighter;
PHighlighterAttribute mMarkerAttribute;
QString mSchemeName;
int mCaseSensitive;
OnCheckMarker mOnCheckStartMarker;
OnCheckMarker mOnCheckEndMarker;
// OnCheckMarker mOnCheckStartMarker;
// OnCheckMarker mOnCheckEndMarker;
QString ConvertExpression(const QString& Value);
private slots:
void MarkerAttriChanged();
@ -63,15 +64,16 @@ private slots:
class SynHighlightComposition : public SynHighlighter
class CompositedHighlighter : public Highlighter
{
public:
explicit SynHighlightComposition();
explicit CompositedHighlighter();
// SynHighligterBase interface
public:
SynHighlighterClass getClass() const override;
HighlighterClass getClass() const override;
QString getName() const override;
};
}
#endif // SYNHIGHLIGHTCOMPOSITION_H

View File

@ -19,9 +19,11 @@
#include "base.h"
#include <QSet>
class SynEditCppHighlighter: public SynHighlighter
namespace QSynedit {
class CppHighlighter: public Highlighter
{
enum TokenKind {
enum TokenId {
Asm = 1,
Comment,
Directive,
@ -42,7 +44,7 @@ class SynEditCppHighlighter: public SynHighlighter
RawString
};
enum class ExtTokenKind {
enum class ExtTokenId {
Add, AddAssign, And, AndAssign, Arrow, Assign,
BitComplement, BraceClose, BraceOpen, Colon, Comma,
Decrement, Divide, DivideAssign, Ellipse, GreaterThan,
@ -66,40 +68,40 @@ class SynEditCppHighlighter: public SynHighlighter
};
public:
explicit SynEditCppHighlighter();
explicit CppHighlighter();
PSynHighlighterAttribute asmAttribute() const;
PHighlighterAttribute asmAttribute() const;
PSynHighlighterAttribute preprocessorAttribute() const;
PHighlighterAttribute preprocessorAttribute() const;
PSynHighlighterAttribute invalidAttribute() const;
PHighlighterAttribute invalidAttribute() const;
PSynHighlighterAttribute numberAttribute() const;
PHighlighterAttribute numberAttribute() const;
PSynHighlighterAttribute floatAttribute() const;
PHighlighterAttribute floatAttribute() const;
PSynHighlighterAttribute hexAttribute() const;
PHighlighterAttribute hexAttribute() const;
PSynHighlighterAttribute octAttribute() const;
PHighlighterAttribute octAttribute() const;
PSynHighlighterAttribute stringEscapeSequenceAttribute() const;
PHighlighterAttribute stringEscapeSequenceAttribute() const;
PSynHighlighterAttribute charAttribute() const;
PHighlighterAttribute charAttribute() const;
PSynHighlighterAttribute variableAttribute() const;
PHighlighterAttribute variableAttribute() const;
PSynHighlighterAttribute functionAttribute() const;
PHighlighterAttribute functionAttribute() const;
PSynHighlighterAttribute classAttribute() const;
PHighlighterAttribute classAttribute() const;
PSynHighlighterAttribute globalVarAttribute() const;
PHighlighterAttribute globalVarAttribute() const;
PSynHighlighterAttribute localVarAttribute() const;
PHighlighterAttribute localVarAttribute() const;
static const QSet<QString> Keywords;
ExtTokenKind getExtTokenId();
SynTokenKind getTokenId();
ExtTokenId getExtTokenId();
TokenKind getTokenId();
private:
void andSymbolProc();
void ansiCppProc();
@ -150,7 +152,7 @@ private:
private:
bool mAsmStart;
SynRangeState mRange;
HighlighterState mRange;
// SynRangeState mSpaceRange;
QString mLineString;
QChar* mLine;
@ -160,25 +162,25 @@ private:
int mToIdent;
int mTokenPos;
int mTokenId;
ExtTokenKind mExtTokenId;
ExtTokenId mExtTokenId;
int mLineNumber;
int mLeftBraces;
int mRightBraces;
PSynHighlighterAttribute mAsmAttribute;
PSynHighlighterAttribute mPreprocessorAttribute;
PSynHighlighterAttribute mInvalidAttribute;
PSynHighlighterAttribute mNumberAttribute;
PSynHighlighterAttribute mFloatAttribute;
PSynHighlighterAttribute mHexAttribute;
PSynHighlighterAttribute mOctAttribute;
PSynHighlighterAttribute mStringEscapeSequenceAttribute;
PSynHighlighterAttribute mCharAttribute;
PSynHighlighterAttribute mVariableAttribute;
PSynHighlighterAttribute mFunctionAttribute;
PSynHighlighterAttribute mClassAttribute;
PSynHighlighterAttribute mGlobalVarAttribute;
PSynHighlighterAttribute mLocalVarAttribute;
PHighlighterAttribute mAsmAttribute;
PHighlighterAttribute mPreprocessorAttribute;
PHighlighterAttribute mInvalidAttribute;
PHighlighterAttribute mNumberAttribute;
PHighlighterAttribute mFloatAttribute;
PHighlighterAttribute mHexAttribute;
PHighlighterAttribute mOctAttribute;
PHighlighterAttribute mStringEscapeSequenceAttribute;
PHighlighterAttribute mCharAttribute;
PHighlighterAttribute mVariableAttribute;
PHighlighterAttribute mFunctionAttribute;
PHighlighterAttribute mClassAttribute;
PHighlighterAttribute mGlobalVarAttribute;
PHighlighterAttribute mLocalVarAttribute;
// SynHighligterBase interface
public:
@ -187,24 +189,24 @@ public:
bool isLastLineStringNotFinished(int state) const override;
bool eol() const override;
QString getToken() const override;
PSynHighlighterAttribute getTokenAttribute() const override;
SynTokenKind getTokenKind() override;
PHighlighterAttribute getTokenAttribute() const override;
TokenKind getTokenKind() override;
int getTokenPos() override;
void next() override;
void setLine(const QString &newLine, int lineNumber) override;
bool isKeyword(const QString &word) override;
SynHighlighterTokenType getTokenType() override;
void setState(const SynRangeState& rangeState) override;
TokenType getTokenType() override;
void setState(const HighlighterState& rangeState) override;
void resetState() override;
SynHighlighterClass getClass() const override;
HighlighterClass getClass() const override;
QString getName() const override;
QString languageName() override;
SynHighlighterLanguage language() override;
HighlighterLanguage language() override;
// SynHighlighter interface
public:
SynRangeState getRangeState() const override;
HighlighterState getState() const override;
// SynHighlighter interface
public:
@ -219,4 +221,6 @@ public:
QString foldString() override;
};
}
#endif // SYNEDITCPPHIGHLIGHTER_H

View File

@ -19,9 +19,11 @@
#include "base.h"
#include <QSet>
class SynEditGLSLHighlighter: public SynHighlighter
namespace QSynedit {
class GLSLHighlighter: public Highlighter
{
enum TokenKind {
enum TokenId {
Asm = 1,
Comment,
Directive,
@ -42,7 +44,7 @@ class SynEditGLSLHighlighter: public SynHighlighter
RawString
};
enum class ExtTokenKind {
enum class ExtTokenId {
Add, AddAssign, And, AndAssign, Arrow, Assign,
BitComplement, BraceClose, BraceOpen, Colon, Comma,
Decrement, Divide, DivideAssign, Ellipse, GreaterThan,
@ -66,40 +68,40 @@ class SynEditGLSLHighlighter: public SynHighlighter
};
public:
explicit SynEditGLSLHighlighter();
explicit GLSLHighlighter();
PSynHighlighterAttribute asmAttribute() const;
PHighlighterAttribute asmAttribute() const;
PSynHighlighterAttribute preprocessorAttribute() const;
PHighlighterAttribute preprocessorAttribute() const;
PSynHighlighterAttribute invalidAttribute() const;
PHighlighterAttribute invalidAttribute() const;
PSynHighlighterAttribute numberAttribute() const;
PHighlighterAttribute numberAttribute() const;
PSynHighlighterAttribute floatAttribute() const;
PHighlighterAttribute floatAttribute() const;
PSynHighlighterAttribute hexAttribute() const;
PHighlighterAttribute hexAttribute() const;
PSynHighlighterAttribute octAttribute() const;
PHighlighterAttribute octAttribute() const;
PSynHighlighterAttribute stringEscapeSequenceAttribute() const;
PHighlighterAttribute stringEscapeSequenceAttribute() const;
PSynHighlighterAttribute charAttribute() const;
PHighlighterAttribute charAttribute() const;
PSynHighlighterAttribute variableAttribute() const;
PHighlighterAttribute variableAttribute() const;
PSynHighlighterAttribute functionAttribute() const;
PHighlighterAttribute functionAttribute() const;
PSynHighlighterAttribute classAttribute() const;
PHighlighterAttribute classAttribute() const;
PSynHighlighterAttribute globalVarAttribute() const;
PHighlighterAttribute globalVarAttribute() const;
PSynHighlighterAttribute localVarAttribute() const;
PHighlighterAttribute localVarAttribute() const;
static const QSet<QString> Keywords;
ExtTokenKind getExtTokenId();
SynTokenKind getTokenId();
ExtTokenId getExtTokenId();
TokenKind getTokenId();
private:
void andSymbolProc();
void ansiCppProc();
@ -147,7 +149,7 @@ private:
private:
bool mAsmStart;
SynRangeState mRange;
HighlighterState mRange;
// SynRangeState mSpaceRange;
QString mLineString;
QChar* mLine;
@ -157,25 +159,25 @@ private:
int mToIdent;
int mTokenPos;
int mTokenId;
ExtTokenKind mExtTokenId;
ExtTokenId mExtTokenId;
int mLineNumber;
int mLeftBraces;
int mRightBraces;
PSynHighlighterAttribute mAsmAttribute;
PSynHighlighterAttribute mPreprocessorAttribute;
PSynHighlighterAttribute mInvalidAttribute;
PSynHighlighterAttribute mNumberAttribute;
PSynHighlighterAttribute mFloatAttribute;
PSynHighlighterAttribute mHexAttribute;
PSynHighlighterAttribute mOctAttribute;
PSynHighlighterAttribute mStringEscapeSequenceAttribute;
PSynHighlighterAttribute mCharAttribute;
PSynHighlighterAttribute mVariableAttribute;
PSynHighlighterAttribute mFunctionAttribute;
PSynHighlighterAttribute mClassAttribute;
PSynHighlighterAttribute mGlobalVarAttribute;
PSynHighlighterAttribute mLocalVarAttribute;
PHighlighterAttribute mAsmAttribute;
PHighlighterAttribute mPreprocessorAttribute;
PHighlighterAttribute mInvalidAttribute;
PHighlighterAttribute mNumberAttribute;
PHighlighterAttribute mFloatAttribute;
PHighlighterAttribute mHexAttribute;
PHighlighterAttribute mOctAttribute;
PHighlighterAttribute mStringEscapeSequenceAttribute;
PHighlighterAttribute mCharAttribute;
PHighlighterAttribute mVariableAttribute;
PHighlighterAttribute mFunctionAttribute;
PHighlighterAttribute mClassAttribute;
PHighlighterAttribute mGlobalVarAttribute;
PHighlighterAttribute mLocalVarAttribute;
// SynHighligterBase interface
public:
@ -184,24 +186,24 @@ public:
bool isLastLineStringNotFinished(int state) const override;
bool eol() const override;
QString getToken() const override;
PSynHighlighterAttribute getTokenAttribute() const override;
SynTokenKind getTokenKind() override;
PHighlighterAttribute getTokenAttribute() const override;
TokenKind getTokenKind() override;
int getTokenPos() override;
void next() override;
void setLine(const QString &newLine, int lineNumber) override;
bool isKeyword(const QString &word) override;
SynHighlighterTokenType getTokenType() override;
void setState(const SynRangeState& rangeState) override;
TokenType getTokenType() override;
void setState(const HighlighterState& rangeState) override;
void resetState() override;
SynHighlighterClass getClass() const override;
HighlighterClass getClass() const override;
QString getName() const override;
QString languageName() override;
SynHighlighterLanguage language() override;
HighlighterLanguage language() override;
// SynHighlighter interface
public:
SynRangeState getRangeState() const override;
HighlighterState getState() const override;
// SynHighlighter interface
public:
@ -212,4 +214,5 @@ public:
QSet<QString> keywords() const override;
};
}
#endif // SYNEDITGLSLHIGHLIGHTER_H

View File

@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "platform.h"
#include "charsetinfo.h"
#include <QObject>
#include <memory>
#include <QMap>

View File

@ -14,8 +14,8 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef PLATFORM_H
#define PLATFORM_H
#ifndef QT_UTILS_CHARSETINFO_H
#define QT_UTILS_CHARSETINFO_H
#include <QByteArray>
#include <QString>
#include <memory>

View File

@ -0,0 +1,651 @@
/*
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "qt_utils/utils.h"
#include <QApplication>
#include <QByteArray>
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QProcess>
#include <QProcessEnvironment>
#include <QString>
#include <QTextCodec>
#include <QtGlobal>
#include <QDebug>
#include <QStyleFactory>
#include <QDateTime>
#include <QColor>
#include <QWindow>
#include <QScreen>
#include <QDirIterator>
#ifdef Q_OS_WIN
#include <QDirIterator>
#include <QMimeDatabase>
#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;
int size;
const QByteArray& s=text;
size = s.length();
if ( (size >= 3) && ((unsigned char)s[0]==0xEF) && ((unsigned char)s[1]==0xBB) && ((unsigned char)s[2]==0xBF)) {
return ENCODING_UTF8_BOM;
}
allAscii = true;
ii = 0;
while (ii < size) {
unsigned char ch = s[ii];
if (ch < 0x80 ) {
ii++; // is an ascii char
} else if (ch < 0xC0) { // value between 0x80 and 0xC0 is an invalid UTF-8 char
return ENCODING_SYSTEM_DEFAULT;
} else if (ch < 0xE0) { // should be an 2-byte UTF-8 char
if (ii>=size-1) {
return ENCODING_SYSTEM_DEFAULT;
}
unsigned char ch2=s[ii+1];
if ((ch2 & 0xC0) !=0x80) {
return ENCODING_SYSTEM_DEFAULT;
}
allAscii = false;
ii+=2;
} else if (ch < 0xF0) { // should be an 3-byte UTF-8 char
if (ii>=size-2) {
return ENCODING_SYSTEM_DEFAULT;
}
unsigned char ch2=s[ii+1];
unsigned char ch3=s[ii+2];
if (((ch2 & 0xC0)!=0x80) || ((ch3 & 0xC0)!=0x80)) {
return ENCODING_SYSTEM_DEFAULT;
}
allAscii = false;
ii+=3;
} else { // invalid UTF-8 char
return ENCODING_SYSTEM_DEFAULT;
}
}
if (allAscii)
return ENCODING_ASCII;
return ENCODING_UTF8;
}
bool isTextAllAscii(const QByteArray& text) {
for (char c:text) {
if (c<0) {
return false;
}
}
return true;
}
bool isTextAllAscii(const QString& text) {
for (QChar c:text) {
if (c.unicode()>127) {
return false;
}
}
return true;
}
bool isNonPrintableAsciiChar(char ch)
{
return (ch<=32) && (ch>=0);
}
QStringList textToLines(const QString &text)
{
QTextStream stream(&((QString&)text),QIODevice::ReadOnly);
return readStreamToLines(&stream);
}
void textToLines(const QString &text, LineProcessFunc lineFunc)
{
QTextStream stream(&((QString&)text),QIODevice::ReadOnly);
readStreamToLines(&stream,lineFunc);
}
QString linesToText(const QStringList &lines, const QString& lineBreak)
{
return lines.join(lineBreak);
}
QList<QByteArray> splitByteArrayToLines(const QByteArray &content)
{
QList<QByteArray> lines;
const char* p =content.constData();
const char* end = p+content.length();
const char* lineStart = p;
QByteArray line;
while (p<=end) {
char ch=*p;
switch(ch) {
case '\r':
line = QByteArray(lineStart, p-lineStart);
lines.append(line);
p++;
if (*p=='\n')
p++;
lineStart = p;
break;
case '\n':
line = QByteArray(lineStart, p-lineStart);
lines.append(line);
p++;
lineStart = p;
break;
default:
p++;
}
}
if (lineStart>end) {
lines.append("");
} else {
line = QByteArray(lineStart, end-lineStart+1);
lines.append(line);
}
return lines;
}
QString trimRight(const QString &s)
{
if (s.isEmpty())
return s;
int i = s.length()-1;
// while ((i>=0) && ((s[i] == '\r') || (s[i]=='\n') || (s[i] == '\t') || (s[i]==' '))) {
while ((i>=0) && (s[i]<=32)) {
i--;
};
if (i>=0) {
return s.left(i+1);
} else {
return QString();
}
}
QString trimLeft(const QString &s)
{
if (s.isEmpty())
return s;
int i=0;
// while ((i<s.length()) && ((s[i] == '\r') || (s[i]=='\n') || (s[i] == '\t') || (s[i]==' '))) {
// i++;
// };
while ((i<s.length()) && (s[i]<=32)) {
i++;
};
if (i<s.length()) {
return s.mid(i);
} else {
return QString();
}
}
int countLeadingWhitespaceChars(const QString &line)
{
int n=0;
while (n<line.length()) {
if (line[n].unicode()>32)
break;
n++;
}
return n;
}
bool stringIsBlank(const QString &s)
{
for (QChar ch:s) {
if (ch != ' ' && ch != '\t')
return false;
}
return true;
}
QByteArray toByteArray(const QString &s)
{
//return s.toLocal8Bit();
return s.toUtf8();
}
QString fromByteArray(const QByteArray &s)
{
QTextCodec* codec = QTextCodec::codecForName(ENCODING_UTF8);
QTextCodec::ConverterState state;
if (!codec)
return QString(s);
QString tmp = codec->toUnicode(s,s.length(),&state);
if (state.invalidChars>0)
tmp = QString::fromLocal8Bit(s);
return tmp;
}
QStringList readStreamToLines(QTextStream *stream)
{
QStringList list;
QString s;
while (stream->readLineInto(&s)) {
list.append(s);
}
return list;
}
void readStreamToLines(QTextStream *stream,
LineProcessFunc lineFunc)
{
QString s;
while (stream->readLineInto(&s)) {
lineFunc(s);
}
}
QStringList readFileToLines(const QString& fileName, QTextCodec* codec)
{
QFile file(fileName);
if (file.open(QFile::ReadOnly)) {
QTextStream stream(&file);
stream.setCodec(codec);
stream.setAutoDetectUnicode(false);
return readStreamToLines(&stream);
}
return QStringList();
}
void readFileToLines(const QString &fileName, QTextCodec *codec, LineProcessFunc lineFunc)
{
QFile file(fileName);
if (file.open(QFile::ReadOnly)) {
QTextStream stream(&file);
stream.setCodec(codec);
stream.setAutoDetectUnicode(false);
readStreamToLines(&stream, lineFunc);
}
}
QStringList readFileToLines(const QString &fileName)
{
QFile file(fileName);
if (file.size()<=0)
return QStringList();
QTextCodec* codec = QTextCodec::codecForLocale();
QStringList result;
QTextCodec::ConverterState state;
bool ok = true;
if (file.open(QFile::ReadOnly)) {
while (!file.atEnd()) {
QByteArray array = file.readLine();
QString s = codec->toUnicode(array,array.length(),&state);
if (state.invalidChars>0) {
ok=false;
break;
}
if (s.endsWith("\r\n")) {
s.remove(s.length()-2,2);
} else if (s.endsWith("\r")) {
s.remove(s.length()-1,1);
} else if (s.endsWith("\n")){
s.remove(s.length()-1,1);
}
result.append(s);
}
if (!ok) {
file.seek(0);
result.clear();
codec = QTextCodec::codecForName("UTF-8");
while (!file.atEnd()) {
QByteArray array = file.readLine();
QString s = codec->toUnicode(array,array.length(),&state);
if (state.invalidChars>0) {
result.clear();
break;
}
if (s.endsWith("\r\n")) {
s.remove(s.length()-2,2);
} else if (s.endsWith("\r")) {
s.remove(s.length()-1,1);
} else if (s.endsWith("\n")){
s.remove(s.length()-1,1);
}
result.append(s);
}
}
}
return result;
}
QByteArray readFileToByteArray(const QString &fileName)
{
QFile file(fileName);
if (file.open(QFile::ReadOnly)) {
return file.readAll();
}
return QByteArray();
}
void stringToFile(const QString &str, const QString &fileName)
{
QFile file(fileName);
if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
QTextStream stream(&file);
stream<<str;
}
}
void stringsToFile(const QStringList &list, const QString &fileName)
{
QFile file(fileName);
if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
QTextStream stream(&file);
for (const QString& s:list) {
stream<<s
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
<<Qt::endl;
#else
<<endl;
#endif
}
}
}
bool fileExists(const QString &file)
{
if (file.isEmpty())
return false;
return QFile(file).exists();
}
bool fileExists(const QString &dir, const QString &fileName)
{
if (dir.isEmpty() || fileName.isEmpty())
return false;
QDir dirInfo(dir);
return dirInfo.exists(fileName);
}
bool directoryExists(const QString &file)
{
if (file.isEmpty())
return false;
QFileInfo dir(file);
return dir.exists() && dir.isDir();
}
bool removeFile(const QString &filename)
{
QFile file(filename);
return file.remove();
}
bool copyFile(const QString &fromPath, const QString &toPath, bool overwrite)
{
QFile fromFile(fromPath);
QFile toFile(toPath);
if (!fromFile.exists())
return false;
if (toFile.exists()) {
if (!overwrite)
return false;
if (!toFile.remove())
return false;
}
if (!fromFile.open(QFile::ReadOnly))
return false;
if (!toFile.open(QFile::WriteOnly | QFile::Truncate))
return false;
int bufferSize=64*1024;
char buffer[bufferSize];
while (!fromFile.atEnd()) {
int readed = fromFile.read(buffer,bufferSize);
toFile.write(buffer,readed);
}
toFile.close();
fromFile.close();
return true;
}
void copyFolder(const QString &fromDir, const QString &toDir)
{
QDirIterator it(fromDir);
QDir dir(fromDir);
QDir targetDir(toDir);
const int absSourcePathLength = dir.absolutePath().length();
if (targetDir.exists())
return;
targetDir.mkpath(targetDir.absolutePath());
while (it.hasNext()){
it.next();
const auto fileInfo = it.fileInfo();
if(!fileInfo.isHidden() && !fileInfo.fileName().startsWith('.')) { //filters dot and dotdot
const QString subPathStructure = fileInfo.absoluteFilePath().mid(absSourcePathLength);
const QString constructedAbsolutePath = targetDir.absolutePath() + subPathStructure;
if(fileInfo.isDir()){
//Create directory in target folder
dir.mkpath(constructedAbsolutePath);
copyFolder(fileInfo.absoluteFilePath(), constructedAbsolutePath);
} else if(fileInfo.isFile()) {
//Copy File to target directory
//Remove file at target location, if it exists, or QFile::copy will fail
QFile::remove(constructedAbsolutePath);
QFile::copy(fileInfo.absoluteFilePath(), constructedAbsolutePath);
QFile newFile(constructedAbsolutePath);
QFile::Permissions permissions = newFile.permissions();
permissions |= (QFile::Permission::WriteOwner
| QFile::Permission::WriteUser
| QFile::Permission::WriteGroup
| QFile::Permission::WriteOther);
newFile.setPermissions(permissions);
}
}
}
}
QString includeTrailingPathDelimiter(const QString &path)
{
if (path.endsWith('/') || path.endsWith(QDir::separator())) {
return path;
} else {
return path + "/";
}
}
QString excludeTrailingPathDelimiter(const QString &path)
{
int pos = path.length()-1;
while (pos>=0 && (path[pos]=='/' || path[pos]==QDir::separator()))
pos--;
return path.mid(0,pos+1);
}
QString changeFileExt(const QString& filename, QString ext)
{
QFileInfo fileInfo(filename);
QString suffix = fileInfo.suffix();
QString name = fileInfo.fileName();
QString path;
if (!ext.isEmpty() && !ext.startsWith(".")) {
ext = "."+ext;
}
if (fileInfo.path() != ".") {
path = includeTrailingPathDelimiter(fileInfo.path());
}
if (suffix.isEmpty()) {
return path+filename+ext;
} else {
return path+fileInfo.completeBaseName()+ext;
}
}
QString extractRelativePath(const QString &base, const QString &dest)
{
QFileInfo baseInfo(base);
QDir baseDir;
if (baseInfo.isDir()) {
baseDir = QDir(baseInfo.absoluteFilePath());
} else {
baseDir = baseInfo.absoluteDir();
}
return baseDir.relativeFilePath(dest);
}
QString localizePath(const QString &path)
{
QString result = path;
result.replace("/",QDir::separator());
return result;
}
QString extractFileName(const QString &fileName)
{
QFileInfo fileInfo(fileName);
return fileInfo.fileName();
}
QString extractFileDir(const QString &fileName)
{
return extractFilePath(fileName);
}
QString extractFilePath(const QString &filePath)
{
QFileInfo info(filePath);
return info.path();
}
QString extractAbsoluteFilePath(const QString &filePath)
{
QFileInfo info(filePath);
return info.absoluteFilePath();
}
bool isReadOnly(const QString &filename)
{
return QFile(filename).isWritable();
}
int compareFileModifiedTime(const QString &filename1, const QString &filename2)
{
QFileInfo fileInfo1(filename1);
QFileInfo fileInfo2(filename2);
qint64 time1=fileInfo1.lastModified().toMSecsSinceEpoch();
qint64 time2=fileInfo2.lastModified().toMSecsSinceEpoch();
if (time1 > time2)
return 1;
if (time1 < time2)
return -1;
return 0;
}
void inflateRect(QRect &rect, int delta)
{
inflateRect(rect,delta,delta);
}
void inflateRect(QRect &rect, int dx, int dy)
{
rect.setLeft(rect.left()-dx);
rect.setRight(rect.right()+dx);
rect.setTop(rect.top()-dy);
rect.setBottom(rect.bottom()+dy);
}
static int defaultScreenDPI = -1;
int screenDPI()
{
if (defaultScreenDPI<1) {
defaultScreenDPI = qApp->primaryScreen()->logicalDotsPerInch();
}
return defaultScreenDPI;
}
void setScreenDPI(int dpi)
{
defaultScreenDPI = dpi;
}
float pointToPixel(float point, float dpi)
{
return point * dpi / 72;
}
float pointToPixel(float point)
{
return pointToPixel(point,screenDPI());
}
float pixelToPoint(float pixel)
{
return pixel * 72 / screenDPI();
}
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);
}

View File

@ -0,0 +1,185 @@
/*
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef REDPANDA_QT_UTILS_H
#define REDPANDA_QT_UTILS_H
#include <type_traits>
#include <utility>
#include <functional>
#include <QString>
#include <QRect>
#include <QStringList>
#include <memory>
#include <QThread>
#include <QProcessEnvironment>
class QByteArray;
class QTextStream;
class QTextCodec;
#define ENCODING_AUTO_DETECT "AUTO"
#define ENCODING_UTF8 "UTF-8"
#define ENCODING_UTF8_BOM "UTF-8 BOM"
#define ENCODING_SYSTEM_DEFAULT "SYSTEM"
#define ENCODING_ASCII "ASCII"
enum class FileEndingType {
Windows,
Linux,
Mac
};// Windows: CRLF, UNIX: LF, Mac: CR
class BaseError{
public:
explicit BaseError(const QString& reason);
QString reason() const;
protected:
QString mReason;
};
class IndexOutOfRange:public BaseError {
public:
explicit IndexOutOfRange(int Index);
};
class FileError: public BaseError {
public:
explicit FileError(const QString& reason);
};
/* text processing utils */
const QByteArray guessTextEncoding(const QByteArray& text);
bool isTextAllAscii(const QByteArray& text);
bool isTextAllAscii(const QString& text);
bool isNonPrintableAsciiChar(char ch);
using LineProcessFunc = std::function<void(const QString&)>;
QStringList textToLines(const QString& text);
void textToLines(const QString& text, LineProcessFunc lineFunc);
QString linesToText(const QStringList& lines, const QString& lineBreak="\n");
QList<QByteArray> splitByteArrayToLines(const QByteArray& content);
QString trimRight(const QString& s);
QString trimLeft(const QString& s);
int countLeadingWhitespaceChars(const QString& line);
bool stringIsBlank(const QString& s);
QByteArray toByteArray(const QString& s);
QString fromByteArray(const QByteArray& s);
/* text I/O utils */
QStringList readStreamToLines(QTextStream* stream);
void readStreamToLines(QTextStream* stream, LineProcessFunc lineFunc);
/**
* @brief readFileToLines
* @param fileName
* @param codec
* @return
*/
QStringList readFileToLines(const QString& fileName, QTextCodec* codec);
QStringList readFileToLines(const QString& fileName);
void readFileToLines(const QString& fileName, QTextCodec* codec, LineProcessFunc lineFunc);
QByteArray readFileToByteArray(const QString& fileName);
void stringsToFile(const QStringList& list, const QString& fileName);
void stringToFile(const QString& str, const QString& fileName);
/* File I/O utils */
bool fileExists(const QString& file);
bool fileExists(const QString& dir, const QString& fileName);
bool directoryExists(const QString& file);
bool removeFile(const QString& filename);
void copyFolder(const QString &fromDir, const QString& toDir);
bool copyFile(const QString &fromFile, const QString& toFile, bool overwrite);
QString includeTrailingPathDelimiter(const QString& path);
QString excludeTrailingPathDelimiter(const QString& path);
QString changeFileExt(const QString& filename, QString ext);
QString localizePath(const QString& path);
QString extractRelativePath(const QString& base, const QString& dest);
QString extractFileName(const QString& fileName);
QString extractFileDir(const QString& fileName);
QString extractFilePath(const QString& filePath);
QString extractAbsoluteFilePath(const QString& filePath);
bool isReadOnly(const QString& filename);
int compareFileModifiedTime(const QString& filename1, const QString& filename2);
/* UI utils */
void inflateRect(QRect& rect, int delta);
void inflateRect(QRect& rect, int dx, int dy);
int screenDPI();
void setScreenDPI(int dpi);
float pointToPixel(float point);
float pointToPixel(float point, float dpi);
float pixelToPoint(float pixel);
void decodeKey(int combinedKey, int& key, Qt::KeyboardModifiers& modifiers);
/**
* from https://github.com/Microsoft/GSL
**/
template <class F>
class final_action
{
public:
static_assert(!std::is_reference<F>::value && !std::is_const<F>::value &&
!std::is_volatile<F>::value,
"Final_action should store its callable by value");
explicit final_action(F f) noexcept : f_(std::move(f)) {}
final_action(final_action&& other) noexcept
: f_(std::move(other.f_)), invoke_(std::exchange(other.invoke_, false))
{}
final_action(const final_action&) = delete;
final_action& operator=(const final_action&) = delete;
final_action& operator=(final_action&&) = delete;
~final_action() noexcept
{
if (invoke_) f_();
}
private:
F f_;
bool invoke_{true};
};
template <class F> final_action<typename std::remove_cv<typename std::remove_reference<F>::type>::type>
finally(F&& f) noexcept
{
return final_action<typename std::remove_cv<typename std::remove_reference<F>::type>::type>(
std::forward<F>(f));
}
#endif // UTILS_H

View File

@ -0,0 +1,27 @@
TEMPLATE = lib
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++17
CONFIG += nokey
CONFIG += staticlib
win32: {
DEFINES += _WIN32_WINNT=0x0601
}
gcc {
QMAKE_CXXFLAGS_RELEASE += -Werror=return-type
QMAKE_CXXFLAGS_DEBUG += -Werror=return-type
}
msvc {
DEFINES += NOMINMAX
}
SOURCES += qt_utils/utils.cpp \
qt_utils/charsetinfo.cpp
HEADERS += qt_utils/utils.h \
qt_utils/charsetinfo.h

View File

@ -8,16 +8,14 @@ test -z $TMP_FOLDER | mkdir $TMP_FOLDER
cp -r packages/debian $TMP_FOLDER
cp -r astyle $TMP_FOLDER
cp -r redpanda-git-askpass $TMP_FOLDER
cp -r consolepauser $TMP_FOLDER
cp -r tools $TMP_FOLDER
cp -r libs $TMP_FOLDER
cp -r RedPandaIDE $TMP_FOLDER
cp README.md $TMP_FOLDER
cp LICENSE $TMP_FOLDER
cp NEWS.md $TMP_FOLDER
cp -r linux $TMP_FOLDER
cp -r platform $TMP_FOLDER
cp Red_Panda_CPP.pro $TMP_FOLDER
cp -r linux $TMP_FOLDER
cd $TMP_FOLDER
dpkg-buildpackage -us -uc

View File

@ -29,8 +29,8 @@ echo "Making no-compiler installer ..."
pushd .
cd "${PACKAGE_DIR}"
cp "${SOURCE_DIR}/windows/installer-scripts/lang.nsh" .
cp "${SOURCE_DIR}/windows/installer-scripts/redpanda-i686-nocompiler.nsi" .
cp "${SOURCE_DIR}/platform/windows/installer-scripts/lang.nsh" .
cp "${SOURCE_DIR}/platform/windows/installer-scripts/redpanda-i686-nocompiler.nsi" .
"${NSIS}" redpanda-i686-nocompiler.nsi
rm -f lang.nsh
@ -61,8 +61,8 @@ pushd .
cd "${PACKAGE_DIR}"
ln -s "${MINGW}" $MinGW_NAME
cp "${SOURCE_DIR}/windows/installer-scripts/lang.nsh" .
cp "${SOURCE_DIR}/windows/installer-scripts/redpanda-i686.nsi" .
cp "${SOURCE_DIR}/platform/windows/installer-scripts/lang.nsh" .
cp "${SOURCE_DIR}/platform/windows/installer-scripts/redpanda-i686.nsi" .
"${NSIS}" redpanda-i686.nsi
rm -f lang.nsh

View File

@ -29,8 +29,8 @@ echo "Making no-compiler installer ..."
pushd .
cd "${PACKAGE_DIR}"
cp "${SOURCE_DIR}/windows/installer-scripts/lang.nsh" .
cp "${SOURCE_DIR}/windows/installer-scripts/redpanda-nocompiler.nsi" .
cp "${SOURCE_DIR}/platform/windows/installer-scripts/lang.nsh" .
cp "${SOURCE_DIR}/platform/windows/installer-scripts/redpanda-nocompiler.nsi" .
"${NSIS}" redpanda-nocompiler.nsi
rm -f lang.nsh
@ -61,8 +61,8 @@ pushd .
cd "${PACKAGE_DIR}"
ln -s "${MINGW}" $MinGW_NAME
cp "${SOURCE_DIR}/windows/installer-scripts/lang.nsh" .
cp "${SOURCE_DIR}/windows/installer-scripts/redpanda-x64.nsi" .
cp "${SOURCE_DIR}/platform/windows/installer-scripts/lang.nsh" .
cp "${SOURCE_DIR}/platform/windows/installer-scripts/redpanda-x64.nsi" .
"${NSIS}" redpanda-x64.nsi
rm -f lang.nsh

View File

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View File

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

Some files were not shown because too many files have changed in this diff Show More