refactor: enum to enum class in qsynedit

This commit is contained in:
Roy Qu 2024-04-03 10:14:54 +08:00
parent 732e3f7c72
commit 494a5c61e4
5 changed files with 173 additions and 169 deletions

View File

@ -162,7 +162,7 @@ Editor::Editor(QWidget *parent, const QString& filename,
if (mParentPageControl) if (mParentPageControl)
connect(this,&QSynEdit::gutterClicked,this,&Editor::onGutterClicked); connect(this,&QSynEdit::gutterClicked,this,&Editor::onGutterClicked);
onStatusChanged(QSynedit::StatusChange::scOpenFile); onStatusChanged(QSynedit::StatusChange::OpenFile);
setAttribute(Qt::WA_Hover,true); setAttribute(Qt::WA_Hover,true);
@ -1853,16 +1853,16 @@ Editor::PSyntaxIssue Editor::getSyntaxIssueAtPosition(const QSynedit::BufferCoor
void Editor::onStatusChanged(QSynedit::StatusChanges changes) void Editor::onStatusChanged(QSynedit::StatusChanges changes)
{ {
if ((!changes.testFlag(QSynedit::StatusChange::scReadOnly) if ((!changes.testFlag(QSynedit::StatusChange::ReadOnly)
&& !changes.testFlag(QSynedit::StatusChange::scInsertMode) && !changes.testFlag(QSynedit::StatusChange::InsertMode)
&& (document()->count()!=mLineCount) && (document()->count()!=mLineCount)
&& (document()->count()!=0) && ((mLineCount>0) || (document()->count()>1))) && (document()->count()!=0) && ((mLineCount>0) || (document()->count()>1)))
|| ||
(mCurrentLineModified (mCurrentLineModified
&& !changes.testFlag(QSynedit::StatusChange::scReadOnly) && !changes.testFlag(QSynedit::StatusChange::ReadOnly)
&& changes.testFlag(QSynedit::StatusChange::scCaretY))) { && changes.testFlag(QSynedit::StatusChange::CaretY))) {
mCurrentLineModified = false; mCurrentLineModified = false;
if (!changes.testFlag(QSynedit::StatusChange::scOpenFile)) { if (!changes.testFlag(QSynedit::StatusChange::OpenFile)) {
reparse(false); reparse(false);
if (pSettings->editor().syntaxCheckWhenLineChanged()) if (pSettings->editor().syntaxCheckWhenLineChanged())
checkSyntaxInBack(); checkSyntaxInBack();
@ -1875,17 +1875,17 @@ void Editor::onStatusChanged(QSynedit::StatusChanges changes)
// } // }
} }
mLineCount = document()->count(); mLineCount = document()->count();
if (changes.testFlag(QSynedit::scModifyChanged)) { if (changes.testFlag(QSynedit::StatusChange::ModifyChanged)) {
updateCaption(); updateCaption();
} }
if (changes.testFlag(QSynedit::scModified)) { if (changes.testFlag(QSynedit::StatusChange::Modified)) {
mCurrentLineModified = true; mCurrentLineModified = true;
if (mParentPageControl) if (mParentPageControl)
mCanAutoSave = true; mCanAutoSave = true;
} }
if (changes.testFlag(QSynedit::StatusChange::scCaretX) if (changes.testFlag(QSynedit::StatusChange::CaretX)
|| changes.testFlag(QSynedit::StatusChange::scCaretY)) { || changes.testFlag(QSynedit::StatusChange::CaretY)) {
if (mTabStopBegin >=0) { if (mTabStopBegin >=0) {
if (mTabStopY==caretY()) { if (mTabStopY==caretY()) {
if (mLineAfterTabStop.isEmpty()) { if (mLineAfterTabStop.isEmpty()) {
@ -1947,7 +1947,7 @@ void Editor::onStatusChanged(QSynedit::StatusChanges changes)
} }
// scSelection includes anything caret related // scSelection includes anything caret related
if (changes.testFlag(QSynedit::StatusChange::scSelection)) { if (changes.testFlag(QSynedit::StatusChange::Selection)) {
if (!selAvail() && pSettings->editor().highlightCurrentWord()) { if (!selAvail() && pSettings->editor().highlightCurrentWord()) {
QString token; QString token;
QSynedit::PTokenAttribute attri; QSynedit::PTokenAttribute attri;
@ -1986,17 +1986,17 @@ void Editor::onStatusChanged(QSynedit::StatusChanges changes)
} }
} }
if (changes.testFlag(QSynedit::scInsertMode) || changes.testFlag(QSynedit::scReadOnly)) if (changes.testFlag(QSynedit::StatusChange::InsertMode) || changes.testFlag(QSynedit::StatusChange::ReadOnly))
pMainWindow->updateForStatusbarModeInfo(); pMainWindow->updateForStatusbarModeInfo();
pMainWindow->updateEditorActions(); pMainWindow->updateEditorActions();
if (changes.testFlag(QSynedit::StatusChange::scCaretY) && mParentPageControl) { if (changes.testFlag(QSynedit::StatusChange::CaretY) && mParentPageControl) {
pMainWindow->caretList().addCaret(this,caretY(),caretX()); pMainWindow->caretList().addCaret(this,caretY(),caretX());
pMainWindow->updateCaretActions(); pMainWindow->updateCaretActions();
} }
if (changes.testFlag(QSynedit::StatusChange::scReadOnly)) { if (changes.testFlag(QSynedit::StatusChange::ReadOnly)) {
if (!readOnly()) if (!readOnly())
initAutoBackup(); initAutoBackup();
} }
@ -5188,7 +5188,7 @@ void Editor::replaceContent(const QString &newContent, bool doReparse)
QSynedit::EditorOptions oldOptions = getOptions(); QSynedit::EditorOptions oldOptions = getOptions();
QSynedit::EditorOptions newOptions = oldOptions; QSynedit::EditorOptions newOptions = oldOptions;
newOptions.setFlag(QSynedit::EditorOption::eoAutoIndent,false); newOptions.setFlag(QSynedit::EditorOption::AutoIndent,false);
setOptions(newOptions); setOptions(newOptions);
replaceAll(newContent); replaceAll(newContent);
setCaretXY(mOldCaret); setCaretXY(mOldCaret);
@ -5347,36 +5347,38 @@ void Editor::setActiveBreakpointFocus(int Line, bool setFocus)
void Editor::applySettings() void Editor::applySettings()
{ {
incPaintLock(); incPaintLock();
QSynedit::EditorOptions options = QSynedit::eoAltSetsColumnMode | QSynedit::EditorOptions options = QSynedit::EditorOption::AltSetsColumnMode
QSynedit::eoDragDropEditing | QSynedit::eoDropFiles | QSynedit::eoKeepCaretX | QSynedit::eoTabsToSpaces | | QSynedit::EditorOption::DragDropEditing | QSynedit::EditorOption::DropFiles
QSynedit::eoRightMouseMovesCursor | QSynedit::eoTabIndent | QSynedit::eoHideShowScrollbars | QSynedit::eoGroupUndo | QSynedit::EditorOption::RightMouseMovesCursor
| QSynedit::eoSelectWordByDblClick; | QSynedit::EditorOption::TabIndent
| QSynedit::EditorOption::GroupUndo
options.setFlag(QSynedit::eoShowLeadingSpaces, pSettings->editor().showLeadingSpaces()); | QSynedit::EditorOption::SelectWordByDblClick;
options.setFlag(QSynedit::eoShowTrailingSpaces, pSettings->editor().showTrailingSpaces());
options.setFlag(QSynedit::eoShowInnerSpaces, pSettings->editor().showInnerSpaces());
options.setFlag(QSynedit::eoShowLineBreaks, pSettings->editor().showLineBreaks());
//options //options
options.setFlag(QSynedit::eoAutoIndent,pSettings->editor().autoIndent()); options.setFlag(QSynedit::EditorOption::ShowLeadingSpaces, pSettings->editor().showLeadingSpaces());
options.setFlag(QSynedit::eoTabsToSpaces,pSettings->editor().tabToSpaces()); options.setFlag(QSynedit::EditorOption::ShowTrailingSpaces, pSettings->editor().showTrailingSpaces());
options.setFlag(QSynedit::EditorOption::ShowInnerSpaces, pSettings->editor().showInnerSpaces());
options.setFlag(QSynedit::EditorOption::ShowLineBreaks, pSettings->editor().showLineBreaks());
options.setFlag(QSynedit::eoKeepCaretX,pSettings->editor().keepCaretX()); options.setFlag(QSynedit::EditorOption::AutoIndent,pSettings->editor().autoIndent());
options.setFlag(QSynedit::eoEnhanceHomeKey,pSettings->editor().enhanceHomeKey()); options.setFlag(QSynedit::EditorOption::TabsToSpaces,pSettings->editor().tabToSpaces());
options.setFlag(QSynedit::eoEnhanceEndKey,pSettings->editor().enhanceEndKey());
options.setFlag(QSynedit::eoHideShowScrollbars,pSettings->editor().autoHideScrollbar()); options.setFlag(QSynedit::EditorOption::KeepCaretX,pSettings->editor().keepCaretX());
options.setFlag(QSynedit::eoScrollPastEol,pSettings->editor().scrollPastEol()); options.setFlag(QSynedit::EditorOption::EnhanceHomeKey,pSettings->editor().enhanceHomeKey());
options.setFlag(QSynedit::eoScrollPastEof,pSettings->editor().scrollPastEof()); options.setFlag(QSynedit::EditorOption::EnhanceEndKey,pSettings->editor().enhanceEndKey());
options.setFlag(QSynedit::eoHalfPageScroll,pSettings->editor().halfPageScroll());
options.setFlag(QSynedit::eoInvertMouseScroll, false);
options.setFlag(QSynedit::eoShowRainbowColor, options.setFlag(QSynedit::EditorOption::AutoHideScrollbars,pSettings->editor().autoHideScrollbar());
options.setFlag(QSynedit::EditorOption::ScrollPastEol,pSettings->editor().scrollPastEol());
options.setFlag(QSynedit::EditorOption::ScrollPastEof,pSettings->editor().scrollPastEof());
options.setFlag(QSynedit::EditorOption::HalfPageScroll,pSettings->editor().halfPageScroll());
options.setFlag(QSynedit::EditorOption::InvertMouseScroll, false);
options.setFlag(QSynedit::EditorOption::ShowRainbowColor,
pSettings->editor().rainbowParenthesis() pSettings->editor().rainbowParenthesis()
&& syntaxer()->supportBraceLevel()); && syntaxer()->supportBraceLevel());
options.setFlag(QSynedit::eoForceMonospace, options.setFlag(QSynedit::EditorOption::ForceMonospace,
pSettings->editor().forceFixedFontWidth()); pSettings->editor().forceFixedFontWidth());
options.setFlag(QSynedit::eoLigatureSupport, options.setFlag(QSynedit::EditorOption::LigatureSupport,
pSettings->editor().enableLigaturesSupport()); pSettings->editor().enableLigaturesSupport());
setOptions(options); setOptions(options);
@ -5481,7 +5483,7 @@ static QSynedit::PTokenAttribute createRainbowAttribute(const QString& attrName,
void Editor::applyColorScheme(const QString& schemeName) void Editor::applyColorScheme(const QString& schemeName)
{ {
QSynedit::EditorOptions options = getOptions(); QSynedit::EditorOptions options = getOptions();
options.setFlag(QSynedit::EditorOption::eoShowRainbowColor, options.setFlag(QSynedit::EditorOption::ShowRainbowColor,
pSettings->editor().rainbowParenthesis() pSettings->editor().rainbowParenthesis()
&& syntaxer()->supportBraceLevel()); && syntaxer()->supportBraceLevel());
setOptions(options); setOptions(options);

View File

@ -44,9 +44,9 @@ CPUDialog::CPUDialog(QWidget *parent) :
ui->txtCode->setUseCodeFolding(false); ui->txtCode->setUseCodeFolding(false);
ui->txtCode->setRightEdge(0); ui->txtCode->setRightEdge(0);
QSynedit::EditorOptions options=ui->txtCode->getOptions(); QSynedit::EditorOptions options=ui->txtCode->getOptions();
options.setFlag(QSynedit::EditorOption::eoScrollPastEof,false); options.setFlag(QSynedit::EditorOption::ScrollPastEof,false);
options.setFlag(QSynedit::EditorOption::eoScrollPastEol,false); options.setFlag(QSynedit::EditorOption::ScrollPastEol,false);
options.setFlag(QSynedit::EditorOption::eoShowRainbowColor, false); options.setFlag(QSynedit::EditorOption::ShowRainbowColor, false);
ui->txtCode->setOptions(options); ui->txtCode->setOptions(options);
PColorSchemeItem item = pColorManager->getItem(pSettings->editor().colorScheme(),COLOR_SCHEME_ACTIVE_LINE); PColorSchemeItem item = pColorManager->getItem(pSettings->editor().colorScheme(),COLOR_SCHEME_ACTIVE_LINE);
if (item) { if (item) {
@ -141,8 +141,8 @@ void CPUDialog::setDisassembly(const QString& file, const QString& funcName,cons
void CPUDialog::resetEditorFont(float dpi) void CPUDialog::resetEditorFont(float dpi)
{ {
QSynedit::EditorOptions options=ui->txtCode->getOptions(); QSynedit::EditorOptions options=ui->txtCode->getOptions();
options.setFlag(QSynedit::eoLigatureSupport, pSettings->editor().enableLigaturesSupport()); options.setFlag(QSynedit::EditorOption::LigatureSupport, pSettings->editor().enableLigaturesSupport());
options.setFlag(QSynedit::eoForceMonospace, options.setFlag(QSynedit::EditorOption::ForceMonospace,
pSettings->editor().forceFixedFontWidth()); pSettings->editor().forceFixedFontWidth());
ui->txtCode->setOptions(options); ui->txtCode->setOptions(options);
QFont f=QFont(); QFont f=QFont();

View File

@ -404,11 +404,11 @@ void QSynEditPainter::paintToken(
} }
if (startPaint) { if (startPaint) {
bool drawed = false; bool drawed = false;
if (mEdit->mOptions.testFlag(eoLigatureSupport)) { if (mEdit->mOptions.testFlag(EditorOption::LigatureSupport)) {
bool tryLigature = false; bool tryLigature = false;
if (glyph.length()==0) { if (glyph.length()==0) {
} else if (glyph.length()==1 && glyph.front().unicode()<=32){ } else if (glyph.length()==1 && glyph.front().unicode()<=32){
} else if (mEdit->mOptions.testFlag(eoForceMonospace) } else if (mEdit->mOptions.testFlag(EditorOption::ForceMonospace)
&& glyphWidth != mPainter->fontMetrics().horizontalAdvance(glyph)) { && glyphWidth != mPainter->fontMetrics().horizontalAdvance(glyph)) {
} else { } else {
tryLigature = true; tryLigature = true;
@ -427,7 +427,7 @@ void QSynEditPainter::paintToken(
&& glyph2.front().unicode()<=32)) && glyph2.front().unicode()<=32))
break; break;
int glyph2Width = calcSegmentInterval(glyphStartPositionList, tokenRight, i+1); int glyph2Width = calcSegmentInterval(glyphStartPositionList, tokenRight, i+1);
if (mEdit->mOptions.testFlag(eoForceMonospace)) { if (mEdit->mOptions.testFlag(EditorOption::ForceMonospace)) {
if (glyph2Width != mPainter->fontMetrics().horizontalAdvance(glyph2)) { if (glyph2Width != mPainter->fontMetrics().horizontalAdvance(glyph2)) {
break; break;
} }
@ -902,7 +902,7 @@ void QSynEditPainter::paintFoldAttributes()
void QSynEditPainter::getBraceColorAttr(int level, PTokenAttribute &attr) void QSynEditPainter::getBraceColorAttr(int level, PTokenAttribute &attr)
{ {
if (!mEdit->mOptions.testFlag(EditorOption::eoShowRainbowColor)) if (!mEdit->mOptions.testFlag(EditorOption::ShowRainbowColor))
return; return;
if (attr->tokenType() != TokenType::Operator) if (attr->tokenType() != TokenType::Operator)
return; return;
@ -1115,11 +1115,11 @@ void QSynEditPainter::paintLines()
if (attr && attr->tokenType() == TokenType::Space) { if (attr && attr->tokenType() == TokenType::Space) {
int pos = mEdit->mSyntaxer->getTokenPos(); int pos = mEdit->mSyntaxer->getTokenPos();
if (pos==0) { if (pos==0) {
showGlyph = mEdit->mOptions.testFlag(eoShowLeadingSpaces); showGlyph = mEdit->mOptions.testFlag(EditorOption::ShowLeadingSpaces);
} else if (pos+sToken.length()==sLine.length()) { } else if (pos+sToken.length()==sLine.length()) {
showGlyph = mEdit->mOptions.testFlag(eoShowTrailingSpaces); showGlyph = mEdit->mOptions.testFlag(EditorOption::ShowTrailingSpaces);
} else { } else {
showGlyph = mEdit->mOptions.testFlag(eoShowInnerSpaces); showGlyph = mEdit->mOptions.testFlag(EditorOption::ShowInnerSpaces);
} }
} }
addHighlightToken( addHighlightToken(
@ -1148,7 +1148,7 @@ void QSynEditPainter::paintLines()
getBraceColorAttr(mEdit->mSyntaxer->getState().braceLevel,attr); getBraceColorAttr(mEdit->mSyntaxer->getState().braceLevel,attr);
} else { } else {
// Draw LineBreak glyph. // Draw LineBreak glyph.
if (mEdit->mOptions.testFlag(eoShowLineBreaks) if (mEdit->mOptions.testFlag(EditorOption::ShowLineBreaks)
&& (mEdit->mDocument->lineWidth(vLine-1) < mRight)) { && (mEdit->mDocument->lineWidth(vLine-1) < mRight)) {
addOnStr = LineBreakGlyph; addOnStr = LineBreakGlyph;
attr = mEdit->mSyntaxer->whitespaceAttribute(); attr = mEdit->mSyntaxer->whitespaceAttribute();

View File

@ -136,9 +136,11 @@ QSynEdit::QSynEdit(QWidget *parent) : QAbstractScrollArea(parent),
mBlockBegin.ch = 1; mBlockBegin.ch = 1;
mBlockBegin.line = 1; mBlockBegin.line = 1;
mBlockEnd = mBlockBegin; mBlockEnd = mBlockBegin;
mOptions = eoAutoIndent mOptions = EditorOption::AutoIndent
| eoDragDropEditing | eoEnhanceEndKey | eoTabIndent | | EditorOption::DragDropEditing | EditorOption::EnhanceEndKey
eoGroupUndo | eoKeepCaretX | eoSelectWordByDblClick; | EditorOption::TabIndent | EditorOption::GroupUndo
| EditorOption::KeepCaretX
| EditorOption::SelectWordByDblClick;
mScrollTimer = new QTimer(this); mScrollTimer = new QTimer(this);
//mScrollTimer->setInterval(100); //mScrollTimer->setInterval(100);
@ -266,7 +268,7 @@ void QSynEdit::setInsertMode(bool value)
if (mInserting != value) { if (mInserting != value) {
mInserting = value; mInserting = value;
updateCaret(); updateCaret();
emit statusChanged(scInsertMode); emit statusChanged(StatusChange::InsertMode);
} }
} }
@ -292,7 +294,7 @@ int QSynEdit::maxScrollWidth() const
return -1; return -1;
if (useCodeFolding()) if (useCodeFolding())
maxWidth += stringWidth(syntaxer()->foldString(""),maxWidth); maxWidth += stringWidth(syntaxer()->foldString(""),maxWidth);
if (mOptions.testFlag(eoScrollPastEol)) if (mOptions.testFlag(EditorOption::ScrollPastEol))
return std::max(maxWidth-2*mCharWidth, 0); return std::max(maxWidth-2*mCharWidth, 0);
else else
return std::max(maxWidth-viewWidth()+mCharWidth, 0); return std::max(maxWidth-viewWidth()+mCharWidth, 0);
@ -769,7 +771,7 @@ BufferCoord QSynEdit::displayToBufferPos(const DisplayCoord &p) const
int QSynEdit::leftSpaces(const QString &line) const int QSynEdit::leftSpaces(const QString &line) const
{ {
int result = 0; int result = 0;
if (mOptions.testFlag(eoAutoIndent)) { if (mOptions.testFlag(EditorOption::AutoIndent)) {
for (QChar ch:line) { for (QChar ch:line) {
if (ch == '\t') { if (ch == '\t') {
result += tabSize() - (result % tabSize()); result += tabSize() - (result % tabSize());
@ -785,7 +787,7 @@ int QSynEdit::leftSpaces(const QString &line) const
QString QSynEdit::GetLeftSpacing(int charCount, bool wantTabs) const QString QSynEdit::GetLeftSpacing(int charCount, bool wantTabs) const
{ {
if (wantTabs && !mOptions.testFlag(eoTabsToSpaces) && tabSize()>0) { if (wantTabs && !mOptions.testFlag(EditorOption::TabsToSpaces) && tabSize()>0) {
return QString(charCount / tabSize(),'\t') + QString(charCount % tabSize(),' '); return QString(charCount / tabSize(),'\t') + QString(charCount % tabSize(),' ');
} else { } else {
return QString(charCount,' '); return QString(charCount,' ');
@ -1488,7 +1490,7 @@ void QSynEdit::doSelectAll()
} }
setCaretAndSelection(caretXY(), BufferCoord{1, 1}, lastPt); setCaretAndSelection(caretXY(), BufferCoord{1, 1}, lastPt);
// Selection should have changed... // Selection should have changed...
emit statusChanged(StatusChange::scSelection); emit statusChanged(StatusChange::Selection);
} }
void QSynEdit::doComment() void QSynEdit::doComment()
@ -1709,7 +1711,7 @@ void QSynEdit::doMouseScroll(bool isDragging, int scrollX, int scrollY)
} else } else
setBlockEnd(caretXY()); setBlockEnd(caretXY());
if (mOptions.testFlag(EditorOption::eoGroupUndo)) if (mOptions.testFlag(EditorOption::GroupUndo))
mUndoList->addGroupBreak(); mUndoList->addGroupBreak();
} }
if (isDragging) { if (isDragging) {
@ -2025,7 +2027,7 @@ BufferCoord QSynEdit::ensureBufferCoordValid(const BufferCoord &coord)
if (value.line < 1) { if (value.line < 1) {
// this is just to make sure if Lines stringlist should be empty // this is just to make sure if Lines stringlist should be empty
value.line = 1; value.line = 1;
if (!mOptions.testFlag(EditorOption::eoScrollPastEol)) { if (!mOptions.testFlag(EditorOption::ScrollPastEol)) {
nMaxX = 1; nMaxX = 1;
} else { } else {
nMaxX = getDisplayStringAtLine(value.line).length()+1; nMaxX = getDisplayStringAtLine(value.line).length()+1;
@ -2232,10 +2234,10 @@ void QSynEdit::insertLine(bool moveCaret)
mSyntaxer->getState().state); mSyntaxer->getState().state);
int indentSpaces = 0; int indentSpaces = 0;
if (mOptions.testFlag(eoAutoIndent)) { if (mOptions.testFlag(EditorOption::AutoIndent)) {
rightLineText=trimLeft(rightLineText); rightLineText=trimLeft(rightLineText);
indentSpaces = calcIndentSpaces(mCaretY+1, indentSpaces = calcIndentSpaces(mCaretY+1,
rightLineText,mOptions.testFlag(eoAutoIndent) rightLineText,mOptions.testFlag(EditorOption::AutoIndent)
); );
} }
QString indentSpacesForRightLineText = GetLeftSpacing(indentSpaces,true); QString indentSpacesForRightLineText = GetLeftSpacing(indentSpaces,true);
@ -2247,7 +2249,7 @@ void QSynEdit::insertLine(bool moveCaret)
if (!notInComment && if (!notInComment &&
( leftLineText.endsWith("/*") && rightLineText.startsWith("*/") ( leftLineText.endsWith("/*") && rightLineText.startsWith("*/")
)) { )) {
indentSpaces = calcIndentSpaces(mCaretY+1, "" , mOptions.testFlag(eoAutoIndent)); indentSpaces = calcIndentSpaces(mCaretY+1, "" , mOptions.testFlag(EditorOption::AutoIndent));
indentSpacesForRightLineText = GetLeftSpacing(indentSpaces,true); indentSpacesForRightLineText = GetLeftSpacing(indentSpaces,true);
mDocument->insertLine(mCaretY, indentSpacesForRightLineText); mDocument->insertLine(mCaretY, indentSpacesForRightLineText);
nLinesInserted++; nLinesInserted++;
@ -2258,7 +2260,7 @@ void QSynEdit::insertLine(bool moveCaret)
if (notInComment && if (notInComment &&
( leftLineText.endsWith('{') && rightLineText.startsWith('}') ( leftLineText.endsWith('{') && rightLineText.startsWith('}')
)) { )) {
indentSpaces = calcIndentSpaces(mCaretY+1, "" , mOptions.testFlag(eoAutoIndent) indentSpaces = calcIndentSpaces(mCaretY+1, "" , mOptions.testFlag(EditorOption::AutoIndent)
&& notInComment); && notInComment);
indentSpacesForRightLineText = GetLeftSpacing(indentSpaces,true); indentSpacesForRightLineText = GetLeftSpacing(indentSpaces,true);
mDocument->insertLine(mCaretY, indentSpacesForRightLineText); mDocument->insertLine(mCaretY, indentSpacesForRightLineText);
@ -2284,7 +2286,7 @@ void QSynEdit::doTabKey()
return; return;
} }
// Provide Visual Studio like block indenting // Provide Visual Studio like block indenting
if (mOptions.testFlag(eoTabIndent) && canDoBlockIndent()) { if (mOptions.testFlag(EditorOption::TabIndent) && canDoBlockIndent()) {
doBlockIndent(); doBlockIndent();
return; return;
} }
@ -2293,7 +2295,7 @@ void QSynEdit::doTabKey()
setSelectedTextEmpty(); setSelectedTextEmpty();
} }
QString Spaces; QString Spaces;
if (mOptions.testFlag(eoTabsToSpaces)) { if (mOptions.testFlag(EditorOption::TabsToSpaces)) {
int left = charToGlyphLeft(mCaretY,mCaretX); int left = charToGlyphLeft(mCaretY,mCaretX);
int i = std::ceil( (tabWidth() - (left) % tabWidth() ) / (float) tabSize()); int i = std::ceil( (tabWidth() - (left) % tabWidth() ) / (float) tabSize());
Spaces = QString(i,' '); Spaces = QString(i,' ');
@ -2308,7 +2310,7 @@ void QSynEdit::doTabKey()
void QSynEdit::doShiftTabKey() void QSynEdit::doShiftTabKey()
{ {
// Provide Visual Studio like block indenting // Provide Visual Studio like block indenting
if (mOptions.testFlag(eoTabIndent) && canDoBlockIndent()) { if (mOptions.testFlag(EditorOption::TabIndent) && canDoBlockIndent()) {
doBlockUnindent(); doBlockUnindent();
return; return;
} }
@ -2522,12 +2524,12 @@ void QSynEdit::doBlockIndent()
x = 1; x = 1;
} else { } else {
e = BE.line; e = BE.line;
if (mOptions.testFlag(EditorOption::eoTabsToSpaces)) if (mOptions.testFlag(EditorOption::TabsToSpaces))
x = caretX() + tabSize(); x = caretX() + tabSize();
else else
x = caretX() + 1; x = caretX() + 1;
} }
if (mOptions.testFlag(eoTabsToSpaces)) { if (mOptions.testFlag(EditorOption::TabsToSpaces)) {
spaces = QString(tabSize(),' ') ; spaces = QString(tabSize(),' ') ;
} else { } else {
spaces = "\t"; spaces = "\t";
@ -2707,7 +2709,7 @@ void QSynEdit::doAddChar(const QChar& ch)
int oldCaretY=mCaretY; int oldCaretY=mCaretY;
// auto // auto
if (mActiveSelectionMode==SelectionMode::Normal if (mActiveSelectionMode==SelectionMode::Normal
&& mOptions.testFlag(eoAutoIndent) && mOptions.testFlag(EditorOption::AutoIndent)
&& mSyntaxer->language() == ProgrammingLanguage::CPP && mSyntaxer->language() == ProgrammingLanguage::CPP
&& (oldCaretY<=mDocument->count()) ) { && (oldCaretY<=mDocument->count()) ) {
@ -3038,7 +3040,7 @@ void QSynEdit::internalSetCaretXY(BufferCoord value, bool ensureVisible)
}); });
if (mCaretX != value.ch) { if (mCaretX != value.ch) {
mCaretX = value.ch; mCaretX = value.ch;
mStatusChanges.setFlag(StatusChange::scCaretX); mStatusChanges.setFlag(StatusChange::CaretX);
invalidateLine(mCaretY); invalidateLine(mCaretY);
} }
if (mCaretY != value.line) { if (mCaretY != value.line) {
@ -3048,7 +3050,7 @@ void QSynEdit::internalSetCaretXY(BufferCoord value, bool ensureVisible)
invalidateGutterLine(mCaretY); invalidateGutterLine(mCaretY);
invalidateLine(oldCaretY); invalidateLine(oldCaretY);
invalidateGutterLine(oldCaretY); invalidateGutterLine(oldCaretY);
mStatusChanges.setFlag(StatusChange::scCaretY); mStatusChanges.setFlag(StatusChange::CaretY);
} }
// Call UpdateLastCaretX before DecPaintLock because the event handler it // Call UpdateLastCaretX before DecPaintLock because the event handler it
// calls could raise an exception, and we don't want fLastCaretX to be // calls could raise an exception, and we don't want fLastCaretX to be
@ -3087,12 +3089,12 @@ void QSynEdit::setStatusChanged(StatusChanges changes)
void QSynEdit::doOnStatusChange(StatusChanges) void QSynEdit::doOnStatusChange(StatusChanges)
{ {
if (mStatusChanges.testFlag(StatusChange::scCaretX) if (mStatusChanges.testFlag(StatusChange::CaretX)
|| mStatusChanges.testFlag(StatusChange::scCaretY)) { || mStatusChanges.testFlag(StatusChange::CaretY)) {
qApp->inputMethod()->update(Qt::ImCursorPosition); qApp->inputMethod()->update(Qt::ImCursorPosition);
} }
emit statusChanged(mStatusChanges); emit statusChanged(mStatusChanges);
mStatusChanges = StatusChange::scNone; mStatusChanges = StatusChange::None;
} }
void QSynEdit::updateHScrollbar() void QSynEdit::updateHScrollbar()
@ -3270,7 +3272,7 @@ void QSynEdit::updateModifiedStatus()
setModified(mModified); setModified(mModified);
// qDebug()<<mModified<<oldModified; // qDebug()<<mModified<<oldModified;
if (oldModified!=mModified) if (oldModified!=mModified)
emit statusChanged(StatusChange::scModifyChanged); emit statusChanged(StatusChange::ModifyChanged);
} }
void QSynEdit::reparseLines(int startLine, int endLine) void QSynEdit::reparseLines(int startLine, int endLine)
@ -3800,7 +3802,7 @@ void QSynEdit::setScrollBars(ScrollStyle newScrollBars)
{ {
mScrollBars = newScrollBars; mScrollBars = newScrollBars;
if (mScrollBars == ScrollStyle::ssBoth || mScrollBars == ScrollStyle::ssHorizontal) { if (mScrollBars == ScrollStyle::ssBoth || mScrollBars == ScrollStyle::ssHorizontal) {
if (mOptions.testFlag(eoHideShowScrollbars)) { if (mOptions.testFlag(EditorOption::AutoHideScrollbars)) {
setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAsNeeded); setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAsNeeded);
} else { } else {
setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOn); setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOn);
@ -3810,7 +3812,7 @@ void QSynEdit::setScrollBars(ScrollStyle newScrollBars)
setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOff);
} }
if (mScrollBars == ScrollStyle::ssBoth || mScrollBars == ScrollStyle::ssVertical) { if (mScrollBars == ScrollStyle::ssBoth || mScrollBars == ScrollStyle::ssVertical) {
if (mOptions.testFlag(eoHideShowScrollbars)) { if (mOptions.testFlag(EditorOption::AutoHideScrollbars)) {
setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAsNeeded); setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAsNeeded);
} else { } else {
setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOn); setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOn);
@ -3961,7 +3963,7 @@ void QSynEdit::setReadOnly(bool readOnly)
{ {
if (mReadOnly != readOnly) { if (mReadOnly != readOnly) {
mReadOnly = readOnly; mReadOnly = readOnly;
emit statusChanged(scReadOnly); emit statusChanged(StatusChange::ReadOnly);
} }
} }
@ -4037,21 +4039,21 @@ void QSynEdit::setOptions(const EditorOptions &value)
if (value != mOptions) { if (value != mOptions) {
incPaintLock(); incPaintLock();
bool bUpdateAll = bool bUpdateAll =
!sameEditorOption(value,mOptions, eoShowLeadingSpaces) !sameEditorOption(value,mOptions, EditorOption::ShowLeadingSpaces)
|| !sameEditorOption(value,mOptions, eoLigatureSupport) || !sameEditorOption(value,mOptions, EditorOption::LigatureSupport)
|| !sameEditorOption(value,mOptions, eoForceMonospace) || !sameEditorOption(value,mOptions, EditorOption::ForceMonospace)
|| !sameEditorOption(value,mOptions, eoShowInnerSpaces) || !sameEditorOption(value,mOptions, EditorOption::ShowInnerSpaces)
|| !sameEditorOption(value,mOptions, eoShowTrailingSpaces) || !sameEditorOption(value,mOptions, EditorOption::ShowTrailingSpaces)
|| !sameEditorOption(value,mOptions, eoShowLineBreaks) || !sameEditorOption(value,mOptions, EditorOption::ShowLineBreaks)
|| !sameEditorOption(value,mOptions, eoShowRainbowColor); || !sameEditorOption(value,mOptions, EditorOption::ShowRainbowColor);
mOptions = value; mOptions = value;
setScrollBars(mScrollBars); setScrollBars(mScrollBars);
mDocument->setForceMonospace(mOptions.testFlag(eoForceMonospace) ); mDocument->setForceMonospace(mOptions.testFlag(EditorOption::ForceMonospace) );
// constrain caret position to MaxScrollWidth if eoScrollPastEol is enabled // constrain caret position to MaxScrollWidth if eoScrollPastEol is enabled
internalSetCaretXY(caretXY()); internalSetCaretXY(caretXY());
if (mOptions.testFlag(eoScrollPastEol)) { if (mOptions.testFlag(EditorOption::ScrollPastEol)) {
BufferCoord vTempBlockBegin = blockBegin(); BufferCoord vTempBlockBegin = blockBegin();
BufferCoord vTempBlockEnd = blockEnd(); BufferCoord vTempBlockEnd = blockEnd();
setBlockBegin(vTempBlockBegin); setBlockBegin(vTempBlockBegin);
@ -4113,7 +4115,7 @@ void QSynEdit::doUndo()
if (item->changeNumber() == oldChangeNumber) if (item->changeNumber() == oldChangeNumber)
keepGoing = true; keepGoing = true;
else { else {
keepGoing = (mOptions.testFlag(eoGroupUndo) && keepGoing = (mOptions.testFlag(EditorOption::GroupUndo) &&
(lastChange == item->changeReason()) ); (lastChange == item->changeReason()) );
} }
oldChangeNumber=item->changeNumber(); oldChangeNumber=item->changeNumber();
@ -4130,12 +4132,12 @@ void QSynEdit::doUndoItem()
{ {
mUndoing = true; mUndoing = true;
beginEditing(); beginEditing();
bool ChangeScrollPastEol = ! mOptions.testFlag(eoScrollPastEol); bool ChangeScrollPastEol = ! mOptions.testFlag(EditorOption::ScrollPastEol);
mOptions.setFlag(eoScrollPastEol); mOptions.setFlag(EditorOption::ScrollPastEol);
auto action = finally([&,this]{ auto action = finally([&,this]{
endEditing(); endEditing();
if (ChangeScrollPastEol) if (ChangeScrollPastEol)
mOptions.setFlag(eoScrollPastEol,false); mOptions.setFlag(EditorOption::ScrollPastEol,false);
mUndoing = false; mUndoing = false;
}); });
@ -4312,7 +4314,7 @@ void QSynEdit::doRedo()
if (item->changeNumber() == oldChangeNumber) if (item->changeNumber() == oldChangeNumber)
keepGoing = true; keepGoing = true;
else { else {
keepGoing = (mOptions.testFlag(eoGroupUndo) && keepGoing = (mOptions.testFlag(EditorOption::GroupUndo) &&
(lastChange == item->changeReason())); (lastChange == item->changeReason()));
} }
oldChangeNumber=item->changeNumber(); oldChangeNumber=item->changeNumber();
@ -4332,15 +4334,15 @@ void QSynEdit::doRedo()
void QSynEdit::doRedoItem() void QSynEdit::doRedoItem()
{ {
mUndoing = true; mUndoing = true;
bool ChangeScrollPastEol = ! mOptions.testFlag(eoScrollPastEol); bool ChangeScrollPastEol = ! mOptions.testFlag(EditorOption::ScrollPastEol);
mOptions.setFlag(eoScrollPastEol); mOptions.setFlag(EditorOption::ScrollPastEol);
mUndoList->setInsideRedo(true); mUndoList->setInsideRedo(true);
beginEditing(); beginEditing();
auto action = finally([&,this]{ auto action = finally([&,this]{
endEditing(); endEditing();
mUndoList->setInsideRedo(false); mUndoList->setInsideRedo(false);
if (ChangeScrollPastEol) if (ChangeScrollPastEol)
mOptions.setFlag(eoScrollPastEol,false); mOptions.setFlag(EditorOption::ScrollPastEol,false);
mUndoing = false; mUndoing = false;
}); });
PUndoItem item = mRedoList->popItem(); PUndoItem item = mRedoList->popItem();
@ -4715,7 +4717,7 @@ void QSynEdit::moveCaretHorz(int deltaX, bool isSelection)
else else
ptDst = blockEnd(); ptDst = blockEnd();
} else { } else {
if (mOptions.testFlag(eoAltSetsColumnMode)) { if (mOptions.testFlag(EditorOption::AltSetsColumnMode)) {
if (qApp->keyboardModifiers().testFlag(Qt::AltModifier) && !mReadOnly) { if (qApp->keyboardModifiers().testFlag(Qt::AltModifier) && !mReadOnly) {
setActiveSelectionMode(SelectionMode::Column); setActiveSelectionMode(SelectionMode::Column);
} else } else
@ -4787,10 +4789,10 @@ void QSynEdit::moveCaretVert(int deltaY, bool isSelection)
} }
if (ptO.row != ptDst.row) { if (ptO.row != ptDst.row) {
if (mOptions.testFlag(eoKeepCaretX)) if (mOptions.testFlag(EditorOption::KeepCaretX))
ptDst.x = mLastCaretColumn; ptDst.x = mLastCaretColumn;
} }
if (mOptions.testFlag(eoAltSetsColumnMode)) { if (mOptions.testFlag(EditorOption::AltSetsColumnMode)) {
if (qApp->keyboardModifiers().testFlag(Qt::AltModifier) && !mReadOnly) if (qApp->keyboardModifiers().testFlag(Qt::AltModifier) && !mReadOnly)
setActiveSelectionMode(SelectionMode::Column); setActiveSelectionMode(SelectionMode::Column);
else else
@ -4831,7 +4833,7 @@ void QSynEdit::moveCaretVert(int deltaY, bool isSelection)
void QSynEdit::moveCaretAndSelection(const BufferCoord &ptBefore, const BufferCoord &ptAfter, bool isSelection, bool ensureCaretVisible) void QSynEdit::moveCaretAndSelection(const BufferCoord &ptBefore, const BufferCoord &ptAfter, bool isSelection, bool ensureCaretVisible)
{ {
if (mOptions.testFlag(EditorOption::eoGroupUndo)) { if (mOptions.testFlag(EditorOption::GroupUndo)) {
mUndoList->addGroupBreak(); mUndoList->addGroupBreak();
} }
@ -4850,7 +4852,7 @@ void QSynEdit::moveCaretToLineStart(bool isSelection)
{ {
int newX; int newX;
// home key enhancement // home key enhancement
if (mOptions.testFlag(EditorOption::eoEnhanceHomeKey)) { if (mOptions.testFlag(EditorOption::EnhanceHomeKey)) {
QString s = mDocument->getLine(mCaretY - 1); QString s = mDocument->getLine(mCaretY - 1);
int first_nonblank = 0; int first_nonblank = 0;
@ -4873,7 +4875,7 @@ void QSynEdit::moveCaretToLineStart(bool isSelection)
void QSynEdit::moveCaretToLineEnd(bool isSelection, bool ensureCaretVisible) void QSynEdit::moveCaretToLineEnd(bool isSelection, bool ensureCaretVisible)
{ {
int vNewX; int vNewX;
if (mOptions.testFlag(EditorOption::eoEnhanceEndKey)) { if (mOptions.testFlag(EditorOption::EnhanceEndKey)) {
QString vText = displayLineText(); QString vText = displayLineText();
int vLastNonBlank = vText.length()-1; int vLastNonBlank = vText.length()-1;
int vMinX = 0; int vMinX = 0;
@ -5001,7 +5003,7 @@ void QSynEdit::setSelTextPrimitiveEx(SelectionMode mode, const QStringList &text
endEditing(); endEditing();
} }
decPaintLock(); decPaintLock();
setStatusChanged(StatusChange::scSelection); setStatusChanged(StatusChange::Selection);
} }
void QSynEdit::doSetSelText(const QString &value) void QSynEdit::doSetSelText(const QString &value)
@ -5167,8 +5169,8 @@ int QSynEdit::searchReplace(const QString &sSearch, const QString &sReplace, Sea
beginEditing(); beginEditing();
dobatchReplace = true; dobatchReplace = true;
} }
bool oldAutoIndent = mOptions.testFlag(EditorOption::eoAutoIndent); bool oldAutoIndent = mOptions.testFlag(EditorOption::AutoIndent);
mOptions.setFlag(EditorOption::eoAutoIndent,false); mOptions.setFlag(EditorOption::AutoIndent,false);
doSetSelText(replaceText); doSetSelText(replaceText);
nReplaceLen = caretX() - nFound; nReplaceLen = caretX() - nFound;
// fix the caret position and the remaining results // fix the caret position and the remaining results
@ -5182,7 +5184,7 @@ int QSynEdit::searchReplace(const QString &sSearch, const QString &sReplace, Sea
} }
} }
} }
mOptions.setFlag(EditorOption::eoAutoIndent,oldAutoIndent); mOptions.setFlag(EditorOption::AutoIndent,oldAutoIndent);
} }
} }
@ -5380,7 +5382,7 @@ int QSynEdit::doInsertTextByNormalMode(const BufferCoord& pos, const QStringList
int caretY=pos.line; int caretY=pos.line;
// step1: insert the first line of Value into current line // step1: insert the first line of Value into current line
if (text.length()>1) { if (text.length()>1) {
if (!mUndoing && mSyntaxer->language()==ProgrammingLanguage::CPP && mOptions.testFlag(eoAutoIndent)) { if (!mUndoing && mSyntaxer->language()==ProgrammingLanguage::CPP && mOptions.testFlag(EditorOption::AutoIndent)) {
QString s = trimLeft(text[0]); QString s = trimLeft(text[0]);
if (sLeftSide.isEmpty()) { if (sLeftSide.isEmpty()) {
sLeftSide = GetLeftSpacing(calcIndentSpaces(caretY,s,true),true); sLeftSide = GetLeftSpacing(calcIndentSpaces(caretY,s,true),true);
@ -5417,7 +5419,7 @@ int QSynEdit::doInsertTextByNormalMode(const BufferCoord& pos, const QStringList
if (i==text.length()-1) if (i==text.length()-1)
str += sRightSide; str += sRightSide;
} }
if (!mUndoing && mSyntaxer->language()==ProgrammingLanguage::CPP && mOptions.testFlag(eoAutoIndent) && notInComment) { if (!mUndoing && mSyntaxer->language()==ProgrammingLanguage::CPP && mOptions.testFlag(EditorOption::AutoIndent) && notInComment) {
int indentSpaces = calcIndentSpaces(caretY,str,true); int indentSpaces = calcIndentSpaces(caretY,str,true);
str = GetLeftSpacing(indentSpaces,true)+trimLeft(str); str = GetLeftSpacing(indentSpaces,true)+trimLeft(str);
} }
@ -5425,11 +5427,11 @@ int QSynEdit::doInsertTextByNormalMode(const BufferCoord& pos, const QStringList
reparseLines(caretY-1,caretY); reparseLines(caretY-1,caretY);
result++; result++;
} }
bChangeScroll = !mOptions.testFlag(eoScrollPastEol); bChangeScroll = !mOptions.testFlag(EditorOption::ScrollPastEol);
mOptions.setFlag(eoScrollPastEol); mOptions.setFlag(EditorOption::ScrollPastEol);
auto action = finally([&,this]{ auto action = finally([&,this]{
if (bChangeScroll) if (bChangeScroll)
mOptions.setFlag(eoScrollPastEol,false); mOptions.setFlag(EditorOption::ScrollPastEol,false);
}); });
newPos=BufferCoord{str.length() - sRightSide.length()+1,caretY}; newPos=BufferCoord{str.length() - sRightSide.length()+1,caretY};
//onLinesPutted(startLine-1,result+1); //onLinesPutted(startLine-1,result+1);
@ -5612,7 +5614,7 @@ void QSynEdit::executeCommand(EditCommand command, QChar ch, void *pData)
case EditCommand::SelPageDown: case EditCommand::SelPageDown:
{ {
int counter = mLinesInWindow; int counter = mLinesInWindow;
if (mOptions.testFlag(eoHalfPageScroll)) if (mOptions.testFlag(EditorOption::HalfPageScroll))
counter /= 2; counter /= 2;
if (counter<0) if (counter<0)
break; break;
@ -6059,7 +6061,7 @@ void QSynEdit::mousePressEvent(QMouseEvent *event)
BufferCoord oldCaret=caretXY(); BufferCoord oldCaret=caretXY();
if (button == Qt::RightButton) { if (button == Qt::RightButton) {
if (mOptions.testFlag(eoRightMouseMovesCursor) && if (mOptions.testFlag(EditorOption::RightMouseMovesCursor) &&
( (selAvail() && ! isPointInSelection(displayToBufferPos(pixelsToGlyphPos(X, Y)))) ( (selAvail() && ! isPointInSelection(displayToBufferPos(pixelsToGlyphPos(X, Y))))
|| ! selAvail())) { || ! selAvail())) {
invalidateSelection(); invalidateSelection();
@ -6076,7 +6078,7 @@ void QSynEdit::mousePressEvent(QMouseEvent *event)
} }
computeCaret(); computeCaret();
mStateFlags.setFlag(StateFlag::WaitForDragging,false); mStateFlags.setFlag(StateFlag::WaitForDragging,false);
if (bWasSel && mOptions.testFlag(eoDragDropEditing) && (X >= mGutterWidth + 2) if (bWasSel && mOptions.testFlag(EditorOption::DragDropEditing) && (X >= mGutterWidth + 2)
&& (mActiveSelectionMode == SelectionMode::Normal) && isPointInSelection(displayToBufferPos(pixelsToGlyphPos(X, Y))) ) { && (mActiveSelectionMode == SelectionMode::Normal) && isPointInSelection(displayToBufferPos(pixelsToGlyphPos(X, Y))) ) {
bStartDrag = true; bStartDrag = true;
} }
@ -6087,7 +6089,7 @@ void QSynEdit::mousePressEvent(QMouseEvent *event)
//BlockBegin and BlockEnd are restored to their original position in the //BlockBegin and BlockEnd are restored to their original position in the
//code from above and SetBlockEnd will take care of proper invalidation //code from above and SetBlockEnd will take care of proper invalidation
setBlockEnd(caretXY()); setBlockEnd(caretXY());
} else if (mOptions.testFlag(eoAltSetsColumnMode)) { } else if (mOptions.testFlag(EditorOption::AltSetsColumnMode)) {
if (event->modifiers() == Qt::AltModifier && !mReadOnly) if (event->modifiers() == Qt::AltModifier && !mReadOnly)
setActiveSelectionMode(SelectionMode::Column); setActiveSelectionMode(SelectionMode::Column);
else else
@ -6099,7 +6101,7 @@ void QSynEdit::mousePressEvent(QMouseEvent *event)
} }
} }
if (oldCaret!=caretXY()) { if (oldCaret!=caretXY()) {
if (mOptions.testFlag(EditorOption::eoGroupUndo)) if (mOptions.testFlag(EditorOption::GroupUndo))
mUndoList->addGroupBreak(); mUndoList->addGroupBreak();
} }
} }
@ -6131,7 +6133,7 @@ void QSynEdit::mouseReleaseEvent(QMouseEvent *event)
ensureLineAlignedWithTop(); ensureLineAlignedWithTop();
ensureCaretVisible(); ensureCaretVisible();
if (oldCaret!=caretXY()) { if (oldCaret!=caretXY()) {
if (mOptions.testFlag(EditorOption::eoGroupUndo)) if (mOptions.testFlag(EditorOption::GroupUndo))
mUndoList->addGroupBreak(); mUndoList->addGroupBreak();
} }
} }
@ -6156,7 +6158,7 @@ void QSynEdit::mouseMoveEvent(QMouseEvent *event)
drag->exec(Qt::DropActions(Qt::CopyAction | Qt::MoveAction)); drag->exec(Qt::DropActions(Qt::CopyAction | Qt::MoveAction));
} }
} else if (buttons == Qt::LeftButton) { } else if (buttons == Qt::LeftButton) {
if (mOptions.testFlag(eoAltSetsColumnMode)) { if (mOptions.testFlag(EditorOption::AltSetsColumnMode)) {
if (event->modifiers() == Qt::AltModifier && !mReadOnly) if (event->modifiers() == Qt::AltModifier && !mReadOnly)
setActiveSelectionMode(SelectionMode::Column); setActiveSelectionMode(SelectionMode::Column);
else else
@ -6172,7 +6174,7 @@ void QSynEdit::mouseDoubleClickEvent(QMouseEvent *event)
QAbstractScrollArea::mouseDoubleClickEvent(event); QAbstractScrollArea::mouseDoubleClickEvent(event);
QPoint ptMouse = event->pos(); QPoint ptMouse = event->pos();
if (ptMouse.x() >= mGutterWidth) { if (ptMouse.x() >= mGutterWidth) {
if (mOptions.testFlag(EditorOption::eoSelectWordByDblClick)) if (mOptions.testFlag(EditorOption::SelectWordByDblClick))
setSelWord(); setSelWord();
mStateFlags.setFlag(StateFlag::DblClicked); mStateFlags.setFlag(StateFlag::DblClicked);
} }
@ -6209,7 +6211,7 @@ void QSynEdit::leaveEvent(QEvent *)
void QSynEdit::wheelEvent(QWheelEvent *event) void QSynEdit::wheelEvent(QWheelEvent *event)
{ {
int sign = mOptions.testFlag(EditorOption::eoInvertMouseScroll)?+1:-1; int sign = mOptions.testFlag(EditorOption::InvertMouseScroll)?+1:-1;
if (event->modifiers() == Qt::ShiftModifier) { if (event->modifiers() == Qt::ShiftModifier) {
if ( (mWheelAccumulatedDeltaX>0 &&event->angleDelta().y()<0) if ( (mWheelAccumulatedDeltaX>0 &&event->angleDelta().y()<0)
|| (mWheelAccumulatedDeltaX<0 &&event->angleDelta().y()>0)) || (mWheelAccumulatedDeltaX<0 &&event->angleDelta().y()>0))
@ -6437,7 +6439,7 @@ void QSynEdit::dragLeaveEvent(QDragLeaveEvent *)
int QSynEdit::maxScrollHeight() const int QSynEdit::maxScrollHeight() const
{ {
if (mOptions.testFlag(eoScrollPastEof)) if (mOptions.testFlag(EditorOption::ScrollPastEof))
return (std::max(displayLineCount(),1) - 1) * mTextHeight; return (std::max(displayLineCount(),1) - 1) * mTextHeight;
else else
return std::max((displayLineCount()-mLinesInWindow+1) * mTextHeight, 0) ; return std::max((displayLineCount()-mLinesInWindow+1) * mTextHeight, 0) ;
@ -6452,7 +6454,7 @@ void QSynEdit::setModified(bool value)
{ {
if (value) { if (value) {
mLastModifyTime = QDateTime::currentDateTime(); mLastModifyTime = QDateTime::currentDateTime();
emit statusChanged(StatusChange::scModified); emit statusChanged(StatusChange::Modified);
} }
if (value != mModified) { if (value != mModified) {
mModified = value; mModified = value;
@ -6461,12 +6463,12 @@ void QSynEdit::setModified(bool value)
mUndoList->clear(); mUndoList->clear();
mRedoList->clear(); mRedoList->clear();
} else { } else {
if (mOptions.testFlag(EditorOption::eoGroupUndo)) { if (mOptions.testFlag(EditorOption::GroupUndo)) {
mUndoList->addGroupBreak(); mUndoList->addGroupBreak();
} }
mUndoList->setInitialState(); mUndoList->setInitialState();
} }
emit statusChanged(StatusChange::scModifyChanged); emit statusChanged(StatusChange::ModifyChanged);
} }
} }
@ -6541,7 +6543,7 @@ void QSynEdit::onLinesCleared()
// scroll to start of text // scroll to start of text
setTopPos(0); setTopPos(0);
setLeftPos(0); setLeftPos(0);
mStatusChanges.setFlag(StatusChange::scAll); mStatusChanges.setFlag(StatusChange::AllCleared);
} }
void QSynEdit::onLinesDeleted(int line, int count) void QSynEdit::onLinesDeleted(int line, int count)
@ -6604,7 +6606,7 @@ void QSynEdit::setActiveSelectionMode(const SelectionMode &Value)
mActiveSelectionMode = Value; mActiveSelectionMode = Value;
if (selAvail()) if (selAvail())
invalidateSelection(); invalidateSelection();
setStatusChanged(StatusChange::scSelection); setStatusChanged(StatusChange::Selection);
} }
} }
@ -6680,7 +6682,7 @@ void QSynEdit::setBlockEnd(BufferCoord value)
std::max(mBlockEnd.line, oldBlockEnd.line)); std::max(mBlockEnd.line, oldBlockEnd.line));
} }
} }
setStatusChanged(StatusChange::scSelection); setStatusChanged(StatusChange::Selection);
} }
} }
@ -6796,7 +6798,7 @@ void QSynEdit::setBlockBegin(BufferCoord value)
mBlockEnd = value; mBlockEnd = value;
} }
if (SelChanged) if (SelChanged)
setStatusChanged(StatusChange::scSelection); setStatusChanged(StatusChange::Selection);
} }
int QSynEdit::leftPos() const int QSynEdit::leftPos() const
@ -6813,7 +6815,7 @@ void QSynEdit::setLeftPos(int value)
if (value != mLeftPos) { if (value != mLeftPos) {
if (mDocument->maxLineWidth()<0) if (mDocument->maxLineWidth()<0)
mLeftPos = value; mLeftPos = value;
setStatusChanged(StatusChange::scLeftPos); setStatusChanged(StatusChange::LeftPos);
if (mScrollBars == ScrollStyle::ssBoth || mScrollBars == ScrollStyle::ssHorizontal) if (mScrollBars == ScrollStyle::ssBoth || mScrollBars == ScrollStyle::ssHorizontal)
horizontalScrollBar()->setValue(value); horizontalScrollBar()->setValue(value);
else { else {
@ -6841,7 +6843,7 @@ void QSynEdit::setTopPos(int value)
//value = std::min(value,maxScrollHeight()); //value = std::min(value,maxScrollHeight());
value = std::max(value, 0); value = std::max(value, 0);
if (value != mTopPos) { if (value != mTopPos) {
setStatusChanged(StatusChange::scTopPos); setStatusChanged(StatusChange::TopPos);
mTopPos = value; mTopPos = value;
if (mScrollBars == ScrollStyle::ssBoth || mScrollBars == ScrollStyle::ssVertical) { if (mScrollBars == ScrollStyle::ssBoth || mScrollBars == ScrollStyle::ssVertical) {
verticalScrollBar()->setValue(value); verticalScrollBar()->setValue(value);

View File

@ -42,19 +42,19 @@ enum class EditCaretType {
ctVerticalLine=0, ctHorizontalLine=1, ctHalfBlock=2, ctBlock=3 ctVerticalLine=0, ctHorizontalLine=1, ctHalfBlock=2, ctBlock=3
}; };
enum StatusChange { enum class StatusChange {
scNone = 0, None = 0,
scAll = 0x0001, AllCleared = 0x0001,
scCaretX = 0x0002, CaretX = 0x0002,
scCaretY = 0x0004, CaretY = 0x0004,
scLeftPos = 0x0008, LeftPos = 0x0008,
scTopPos = 0x0010, TopPos = 0x0010,
scInsertMode = 0x0020, InsertMode = 0x0020,
scModifyChanged = 0x0040, ModifyChanged = 0x0040,
scSelection = 0x0080, Selection = 0x0080,
scReadOnly = 0x0100, ReadOnly = 0x0100,
scOpenFile = 0x0200, OpenFile = 0x0200,
scModified = 0x0400 Modified = 0x0400
}; };
Q_DECLARE_FLAGS(StatusChanges, StatusChange) Q_DECLARE_FLAGS(StatusChanges, StatusChange)
@ -72,33 +72,33 @@ Q_DECLARE_FLAGS(StateFlags,StateFlag)
Q_DECLARE_OPERATORS_FOR_FLAGS(StateFlags) Q_DECLARE_OPERATORS_FOR_FLAGS(StateFlags)
enum EditorOption { enum class EditorOption {
eoAltSetsColumnMode = 0x00000001, //Holding down the Alt Key will put the selection mode into columnar format AltSetsColumnMode = 0x00000001, //Holding down the Alt Key will put the selection mode into columnar format
eoAutoIndent = 0x00000002, //Will auto calculate the indent when input AutoIndent = 0x00000002, //Will auto calculate the indent when input
eoLigatureSupport = 0x00000004, //Support ligaures in fonts like fira code LigatureSupport = 0x00000004, //Support ligaures in fonts like fira code
eoDragDropEditing = 0x00000008, //Allows you to select a block of text and drag it within the document to another location DragDropEditing = 0x00000008, //Allows you to select a block of text and drag it within the document to another location
eoDropFiles = 0x00000010, //Allows the editor accept OLE file drops DropFiles = 0x00000010, //Allows the editor accept OLE file drops
eoEnhanceHomeKey = 0x00000020, //enhances home key positioning, similar to visual studio EnhanceHomeKey = 0x00000020, //enhances home key positioning, similar to visual studio
eoEnhanceEndKey = 0x00000040, //enhances End key positioning, similar to JDeveloper EnhanceEndKey = 0x00000040, //enhances End key positioning, similar to JDeveloper
eoGroupUndo = 0x00000080, //When undoing/redoing actions, handle all continous changes of the same kind in one call instead undoing/redoing each command separately GroupUndo = 0x00000080, //When undoing/redoing actions, handle all continous changes of the same kind in one call instead undoing/redoing each command separately
eoHalfPageScroll = 0x00000100, //When scrolling with page-up and page-down commands, only scroll a half page at a time HalfPageScroll = 0x00000100, //When scrolling with page-up and page-down commands, only scroll a half page at a time
eoHideShowScrollbars = 0x00000200, //if enabled, then the scrollbars will only show when necessary. If you have ScrollPastEOL, then it the horizontal bar will always be there (it uses MaxLength instead) AutoHideScrollbars = 0x00000200, //if enabled, then the scrollbars will only show when necessary. If you have ScrollPastEOL, then it the horizontal bar will always be there (it uses MaxLength instead)
eoKeepCaretX = 0x00000400 , //When moving through lines w/o Cursor Past EOL, keeps the X position of the cursor KeepCaretX = 0x00000400 , //When moving through lines w/o Cursor Past EOL, keeps the X position of the cursor
eoRightMouseMovesCursor= 0x00000800, //When clicking with the right mouse for a popup menu, move the cursor to that location RightMouseMovesCursor= 0x00000800, //When clicking with the right mouse for a popup menu, move the cursor to that location
// eoScrollByOneLess = 0x00001000, //Forces scrolling to be one less // eoScrollByOneLess = 0x00001000, //Forces scrolling to be one less
eoScrollPastEof = 0x00002000, //Allows the cursor to go past the end of file marker ScrollPastEof = 0x00002000, //Allows the cursor to go past the end of file marker
eoScrollPastEol = 0x00004000, //Allows the cursor to go past the last character into the white space at the end of a line ScrollPastEol = 0x00004000, //Allows the cursor to go past the last character into the white space at the end of a line
eoInvertMouseScroll = 0x00008000, //Shows the special Characters InvertMouseScroll = 0x00008000, //Shows the special Characters
// eoSpecialLineDefaultFg = 0x00010000, //disables the foreground text color override when using the OnSpecialLineColor event // eoSpecialLineDefaultFg = 0x00010000, //disables the foreground text color override when using the OnSpecialLineColor event
eoTabIndent = 0x00020000, //When active <Tab> and <Shift><Tab> act as block indent, unindent when text is selected TabIndent = 0x00020000, //When active <Tab> and <Shift><Tab> act as block indent, unindent when text is selected
eoTabsToSpaces = 0x00040000, //Converts a tab character to a specified number of space characters TabsToSpaces = 0x00040000, //Converts a tab character to a specified number of space characters
eoShowRainbowColor = 0x00080000, ShowRainbowColor = 0x00080000,
eoSelectWordByDblClick = 0x00100000, SelectWordByDblClick = 0x00100000,
eoShowLeadingSpaces = 0x00200000, ShowLeadingSpaces = 0x00200000,
eoShowTrailingSpaces = 0x00400000, ShowTrailingSpaces = 0x00400000,
eoShowInnerSpaces = 0x00800000, ShowInnerSpaces = 0x00800000,
eoShowLineBreaks = 0x01000000, ShowLineBreaks = 0x01000000,
eoForceMonospace = 0x02000000, ForceMonospace = 0x02000000,
}; };
Q_DECLARE_FLAGS(EditorOptions, EditorOption) Q_DECLARE_FLAGS(EditorOptions, EditorOption)