diff --git a/RedPandaIDE/RedPandaIDE.pro b/RedPandaIDE/RedPandaIDE.pro index 1c717ce9..d9be5851 100644 --- a/RedPandaIDE/RedPandaIDE.pro +++ b/RedPandaIDE/RedPandaIDE.pro @@ -32,6 +32,7 @@ SOURCES += \ settingsdialog/compilersetdirectorieswidget.cpp \ settingsdialog/compilersetoptionwidget.cpp \ settings.cpp \ + settingsdialog/editorfontwidget.cpp \ settingsdialog/editorgeneralwidget.cpp \ settingsdialog/settingsdialog.cpp \ settingsdialog/settingswidget.cpp \ @@ -64,6 +65,7 @@ HEADERS += \ settingsdialog/compilersetdirectorieswidget.h \ settingsdialog/compilersetoptionwidget.h \ settings.h \ + settingsdialog/editorfontwidget.h \ settingsdialog/editorgeneralwidget.h \ settingsdialog/settingsdialog.h \ settingsdialog/settingswidget.h \ @@ -77,6 +79,7 @@ FORMS += \ mainwindow.ui \ settingsdialog/compilersetdirectorieswidget.ui \ settingsdialog/compilersetoptionwidget.ui \ + settingsdialog/editorfontwidget.ui \ settingsdialog/editorgeneralwidget.ui \ settingsdialog/settingsdialog.ui diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 77c2556d..d78e42c2 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -267,10 +267,14 @@ void Editor::applySettings() options.setFlag(eoEnhanceHomeKey,pSettings->editor().enhanceHomeKey()); options.setFlag(eoEnhanceEndKey,pSettings->editor().enhanceEndKey()); + options.setFlag(eoHideShowScrollbars,pSettings->editor().autoHideScrollbar()); + options.setFlag(eoScrollPastEol,pSettings->editor().scrollPastEol()); + options.setFlag(eoScrollPastEof,pSettings->editor().scrollPastEof()); + options.setFlag(eoScrollByOneLess,pSettings->editor().scrollByOneLess()); + options.setFlag(eoHalfPageScroll,pSettings->editor().halfPageScroll()); setOptions(options); setTabWidth(pSettings->editor().tabWidth()); - setInsertCaret(pSettings->editor().caretForInsert()); setOverwriteCaret(pSettings->editor().caretForOverwrite()); setCaretColor(pSettings->editor().caretColor()); diff --git a/RedPandaIDE/qsynedit/CodeFolding.cpp b/RedPandaIDE/qsynedit/CodeFolding.cpp index e74d03e5..ef3a1111 100644 --- a/RedPandaIDE/qsynedit/CodeFolding.cpp +++ b/RedPandaIDE/qsynedit/CodeFolding.cpp @@ -75,7 +75,7 @@ void SynEditFoldRanges::clear() mRanges.clear(); } -int SynEditFoldRanges::count() +int SynEditFoldRanges::count() const { return mRanges.size(); } @@ -114,7 +114,7 @@ void SynEditFoldRanges::add(PSynEditFoldRange foldRange) mRanges.push_back(foldRange); } -PSynEditFoldRange SynEditFoldRanges::operator[](int index) +PSynEditFoldRange SynEditFoldRanges::operator[](int index) const { return mRanges[index]; } diff --git a/RedPandaIDE/qsynedit/CodeFolding.h b/RedPandaIDE/qsynedit/CodeFolding.h index f96d1508..f2604b97 100644 --- a/RedPandaIDE/qsynedit/CodeFolding.h +++ b/RedPandaIDE/qsynedit/CodeFolding.h @@ -48,7 +48,7 @@ private: public: PSynEditFoldRange range(int index); void clear(); - int count(); + int count() const; SynEditFoldRanges(); PSynEditFoldRange addByParts(PSynEditFoldRange aParent, PSynEditFoldRanges aAllFold, int aFromLine, PSynEditFoldRegion aFoldRegion, int aToLine); @@ -56,7 +56,7 @@ public: void insert(int index, PSynEditFoldRange range); int remove(int index); void add(PSynEditFoldRange foldRange); - PSynEditFoldRange operator[](int index); + PSynEditFoldRange operator[](int index) const; }; // A single fold diff --git a/RedPandaIDE/qsynedit/SynEdit.cpp b/RedPandaIDE/qsynedit/SynEdit.cpp index ec734f5e..c65c1e70 100644 --- a/RedPandaIDE/qsynedit/SynEdit.cpp +++ b/RedPandaIDE/qsynedit/SynEdit.cpp @@ -75,7 +75,6 @@ SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent) this->setCursor(Qt::CursorShape::IBeamCursor); //TabStop := True; mInserting = true; - mMaxScrollWidth = 1024; mScrollBars = SynScrollStyle::ssBoth; mExtraLineSpacing = 0; qDebug()<<"init SynEdit: 6"; @@ -150,7 +149,7 @@ SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent) setMouseTracking(true); } -int SynEdit::displayLineCount() +int SynEdit::displayLineCount() const { if (mLines->empty()) { return 0; @@ -158,22 +157,22 @@ int SynEdit::displayLineCount() return lineToRow(mLines->count()); } -DisplayCoord SynEdit::displayXY() +DisplayCoord SynEdit::displayXY() const { return bufferToDisplayPos(caretXY()); } -int SynEdit::displayX() +int SynEdit::displayX() const { return displayXY().Column; } -int SynEdit::displayY() +int SynEdit::displayY() const { return displayXY().Row; } -BufferCoord SynEdit::caretXY() +BufferCoord SynEdit::caretXY() const { BufferCoord result; result.Char = caretX(); @@ -181,12 +180,12 @@ BufferCoord SynEdit::caretXY() return result; } -int SynEdit::caretX() +int SynEdit::caretX() const { return mCaretX; } -int SynEdit::caretY() +int SynEdit::caretY() const { return mCaretY; } @@ -213,7 +212,7 @@ void SynEdit::setCaretXYEx(bool CallEnsureCursorPos, BufferCoord value) if (vTriggerPaint) doOnPaintTransient(SynTransientType::ttBefore); - int nMaxX = mMaxScrollWidth + 1; + int nMaxX; if (value.Line > mLines->count()) value.Line = mLines->count(); if (value.Line < 1) { @@ -223,13 +222,14 @@ void SynEdit::setCaretXYEx(bool CallEnsureCursorPos, BufferCoord value) nMaxX = 1; } } else { - if (!mOptions.testFlag(SynEditorOption::eoScrollPastEol)) - nMaxX = mLines->getString(value.Line-1).length()+1; + nMaxX = mLines->getString(value.Line-1).length()+1; } - if ((value.Char > nMaxX) && (! (mOptions.testFlag(SynEditorOption::eoScrollPastEol)) ) ) - value.Char = nMaxX; - if (value.Char < 1) - value.Char = 1; + value.Char = std::min(value.Char,nMaxX); + value.Char = std::max(value.Char,1); +// if ((value.Char > nMaxX) && (! (mOptions.testFlag(SynEditorOption::eoScrollPastEol)) ) ) +// value.Char = nMaxX; +// if (value.Char < 1) +// value.Char = 1; if ((value.Char != mCaretX) || (value.Line != mCaretY)) { incPaintLock(); auto action = finally([this]{ @@ -291,6 +291,14 @@ void SynEdit::setCaretXYCentered(bool ForceToMiddle, const BufferCoord &value) } +int SynEdit::maxScrollWidth() const +{ + if (mOptions.testFlag(eoScrollPastEol)) + return mLines->lengthOfLongestLine(); + else + return std::max(mLines->lengthOfLongestLine()-mCharsInWindow+1, 1); +} + bool SynEdit::GetHighlighterAttriAtRowCol(const BufferCoord &XY, QString &Token, PSynHighlighterAttribute &Attri) { SynHighlighterTokenType TmpType; @@ -434,7 +442,7 @@ void SynEdit::invalidateGutterLines(int FirstLine, int LastLine) * @param aY * @return */ -DisplayCoord SynEdit::pixelsToNearestRowColumn(int aX, int aY) +DisplayCoord SynEdit::pixelsToNearestRowColumn(int aX, int aY) const { // Result is in display coordinates float f; @@ -451,7 +459,7 @@ DisplayCoord SynEdit::pixelsToNearestRowColumn(int aX, int aY) }; } -DisplayCoord SynEdit::pixelsToRowColumn(int aX, int aY) +DisplayCoord SynEdit::pixelsToRowColumn(int aX, int aY) const { return { .Column = std::max(1, mLeftChar + ((aX - mGutterWidth - 2) / mCharWidth)), @@ -459,7 +467,7 @@ DisplayCoord SynEdit::pixelsToRowColumn(int aX, int aY) }; } -QPoint SynEdit::RowColumnToPixels(const DisplayCoord &coord) +QPoint SynEdit::RowColumnToPixels(const DisplayCoord &coord) const { QPoint result; result.setX((coord.Column - 1) * mCharWidth + textOffset()); @@ -473,7 +481,7 @@ QPoint SynEdit::RowColumnToPixels(const DisplayCoord &coord) * @param p * @return */ -DisplayCoord SynEdit::bufferToDisplayPos(const BufferCoord &p) +DisplayCoord SynEdit::bufferToDisplayPos(const BufferCoord &p) const { DisplayCoord result {p.Char,p.Line}; // Account for tabs and charColumns @@ -490,7 +498,7 @@ DisplayCoord SynEdit::bufferToDisplayPos(const BufferCoord &p) * @param p * @return */ -BufferCoord SynEdit::displayToBufferPos(const DisplayCoord &p) +BufferCoord SynEdit::displayToBufferPos(const DisplayCoord &p) const { BufferCoord Result{p.Column,p.Row}; // Account for code folding @@ -503,7 +511,7 @@ BufferCoord SynEdit::displayToBufferPos(const DisplayCoord &p) return Result; } -int SynEdit::leftSpaces(const QString &line) +int SynEdit::leftSpaces(const QString &line) const { int result = 0; if (mOptions.testFlag(eoAutoIndent)) { @@ -520,7 +528,7 @@ int SynEdit::leftSpaces(const QString &line) return result; } -QString SynEdit::GetLeftSpacing(int charCount, bool wantTabs) +QString SynEdit::GetLeftSpacing(int charCount, bool wantTabs) const { if (wantTabs && !mOptions.testFlag(eoTabsToSpaces)) { return QString(charCount / mTabWidth,'\t') + QString(charCount % mTabWidth,' '); @@ -529,7 +537,7 @@ QString SynEdit::GetLeftSpacing(int charCount, bool wantTabs) } } -int SynEdit::charToColumn(int aLine, int aChar) +int SynEdit::charToColumn(int aLine, int aChar) const { Q_ASSERT( (aLine <= mLines->count()) && (aLine >= 1)); if (aLine <= mLines->count()) { @@ -538,7 +546,7 @@ int SynEdit::charToColumn(int aLine, int aChar) } } -int SynEdit::charToColumn(const QString &s, int aChar) +int SynEdit::charToColumn(const QString &s, int aChar) const { int x = 0; int len = std::min(aChar-1,s.length()); @@ -551,7 +559,7 @@ int SynEdit::charToColumn(const QString &s, int aChar) return x+1; } -int SynEdit::columnToChar(int aLine, int aColumn) +int SynEdit::columnToChar(int aLine, int aColumn) const { Q_ASSERT( (aLine <= mLines->count()) && (aLine >= 1)); if (aLine <= mLines->count()) { @@ -572,7 +580,7 @@ int SynEdit::columnToChar(int aLine, int aColumn) } } -int SynEdit::stringColumns(const QString &line, int colsBefore) +int SynEdit::stringColumns(const QString &line, int colsBefore) const { int columns = colsBefore; int charCols; @@ -588,7 +596,7 @@ int SynEdit::stringColumns(const QString &line, int colsBefore) return columns-colsBefore; } -int SynEdit::getLineIndent(const QString &line) +int SynEdit::getLineIndent(const QString &line) const { int indents = 0; for (QChar ch:line) { @@ -606,7 +614,7 @@ int SynEdit::getLineIndent(const QString &line) return indents; } -int SynEdit::rowToLine(int aRow) +int SynEdit::rowToLine(int aRow) const { if (mUseCodeFolding) return foldRowToLine(aRow); @@ -615,12 +623,12 @@ int SynEdit::rowToLine(int aRow) //return displayToBufferPos({1, aRow}).Line; } -int SynEdit::lineToRow(int aLine) +int SynEdit::lineToRow(int aLine) const { return bufferToDisplayPos({1, aLine}).Row; } -int SynEdit::foldRowToLine(int Row) +int SynEdit::foldRowToLine(int Row) const { int result = Row; for (int i=0;i=0;i--) { @@ -762,7 +770,7 @@ void SynEdit::unlockPainter() mPainterLock--; } -bool SynEdit::selAvail() +bool SynEdit::selAvail() const { return (mBlockBegin.Char != mBlockEnd.Char) || ((mBlockBegin.Line != mBlockEnd.Line) && (mActiveSelectionMode != SynSelectionMode::smColumn)); @@ -845,7 +853,7 @@ BufferCoord SynEdit::GetPreviousLeftBracket(int x, int y) } } -int SynEdit::charColumns(QChar ch) +int SynEdit::charColumns(QChar ch) const { if (ch == ' ') return 1; @@ -853,7 +861,7 @@ int SynEdit::charColumns(QChar ch) return std::ceil((int)(fontMetrics().horizontalAdvance(ch)) / (double)mCharWidth); } -double SynEdit::dpiFactor() +double SynEdit::dpiFactor() const { return fontMetrics().fontDpi() / 96.0; } @@ -874,7 +882,7 @@ void SynEdit::hideCaret() } } -bool SynEdit::IsPointInSelection(const BufferCoord &Value) +bool SynEdit::IsPointInSelection(const BufferCoord &Value) const { BufferCoord ptBegin = blockBegin(); BufferCoord ptEnd = blockEnd(); @@ -1037,11 +1045,12 @@ void SynEdit::SetSelWord() void SynEdit::SetWordBlock(BufferCoord Value) { - if (mOptions.testFlag(eoScrollPastEol)) - Value.Char = MinMax(Value.Char, 1, mMaxScrollWidth + 1); - else - Value.Char = std::max(Value.Char, 1); +// if (mOptions.testFlag(eoScrollPastEol)) +// Value.Char = +// else +// Value.Char = std::max(Value.Char, 1); Value.Line = MinMax(Value.Line, 1, mLines->count()); + Value.Char = std::max(Value.Char, 1); QString TempString = mLines->getString(Value.Line - 1); //needed for CaretX = LineLength +1 if (Value.Char > TempString.length()) { internalSetCaretXY(BufferCoord{TempString.length()+1, Value.Line}); @@ -2198,10 +2207,7 @@ void SynEdit::updateScrollbars() setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOn); } if (mScrollBars == SynScrollStyle::ssBoth || mScrollBars == SynScrollStyle::ssHorizontal) { - if (mOptions.testFlag(eoScrollPastEol)) - nMaxScroll = mLines->lengthOfLongestLine(); - else - nMaxScroll = std::max(mLines->lengthOfLongestLine()-mCharsInWindow+1, 1); + nMaxScroll = maxScrollWidth(); if (nMaxScroll <= MAX_SCROLL) { nMin = 1; nMax = nMaxScroll; @@ -2222,11 +2228,7 @@ void SynEdit::updateScrollbars() setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOn); if (mScrollBars == SynScrollStyle::ssBoth || mScrollBars == SynScrollStyle::ssVertical) { - if (mOptions.testFlag(eoScrollPastEof)) - nMaxScroll = std::max(displayLineCount(),1); - else - nMaxScroll = std::max(displayLineCount()-mLinesInWindow+1, 1); - + nMaxScroll = maxScrollHeight(); if (nMaxScroll <= MAX_SCROLL) { nMin = 1; nMax = std::max(1, nMaxScroll); @@ -2767,7 +2769,7 @@ void SynEdit::paintCaret(QPainter &painter, const QRect rcClip) } } -int SynEdit::textOffset() +int SynEdit::textOffset() const { return mGutterWidth + 2 - (mLeftChar-1)*mCharWidth; } @@ -2810,10 +2812,10 @@ void SynEdit::sizeOrFontChanged(bool bFont) } else updateScrollbars(); mStateFlags.setFlag(SynStateFlag::sfScrollbarChanged,false); - if (!mOptions.testFlag(SynEditorOption::eoScrollPastEol)) - setLeftChar(mLeftChar); - if (!mOptions.testFlag(SynEditorOption::eoScrollPastEof)) - setTopLine(mTopLine); + //if (!mOptions.testFlag(SynEditorOption::eoScrollPastEol)) + setLeftChar(mLeftChar); + //if (!mOptions.testFlag(SynEditorOption::eoScrollPastEof)) + setTopLine(mTopLine); } } @@ -2895,10 +2897,10 @@ void SynEdit::setOptions(const SynEditorOptions &Value) { if (Value != mOptions) { bool bSetDrag = mOptions.testFlag(eoDropFiles) != Value.testFlag(eoDropFiles); - if (!mOptions.testFlag(eoScrollPastEol)) - setLeftChar(mLeftChar); - if (!mOptions.testFlag(eoScrollPastEof)) - setTopLine(mTopLine); + //if (!mOptions.testFlag(eoScrollPastEol)) + setLeftChar(mLeftChar); + //if (!mOptions.testFlag(eoScrollPastEof)) + setTopLine(mTopLine); bool bUpdateAll = Value.testFlag(eoShowSpecialChars) != mOptions.testFlag(eoShowSpecialChars); if (!bUpdateAll) @@ -3572,7 +3574,8 @@ void SynEdit::MoveCaretHorz(int DX, bool isSelection) QString s = lineText(); int nLineLen = s.length(); // only moving or selecting one char can change the line - bool bChangeY = !mOptions.testFlag(SynEditorOption::eoScrollPastEol); + //bool bChangeY = !mOptions.testFlag(SynEditorOption::eoScrollPastEol); + bool bChangeY=true; if (bChangeY && (DX == -1) && (ptO.Char == 1) && (ptO.Line > 1)) { // end of previous line ptDst.Line--; @@ -4824,19 +4827,12 @@ bool SynEdit::viewportEvent(QEvent * event) return QAbstractScrollArea::viewportEvent(event); } -int SynEdit::maxScrollWidth() const +int SynEdit::maxScrollHeight() const { - return mMaxScrollWidth; -} - -void SynEdit::setMaxScrollWidth(int Value) -{ - Value = MinMax(Value, 1, INT_MAX - 1); - if (mMaxScrollWidth != Value) { - mMaxScrollWidth = Value; - if (mOptions.testFlag(SynEditorOption::eoScrollPastEol)) - updateScrollbars(); - } + if (mOptions.testFlag(eoScrollPastEof)) + return std::max(displayLineCount(),1); + else + return std::max(displayLineCount()-mLinesInWindow+1, 1); } bool SynEdit::modified() const @@ -4903,8 +4899,8 @@ void SynEdit::linesChanged() if (mGutter.showLineNumbers() && (mGutter.autoSize())) mGutter.autoSizeDigitCount(mLines->count()); - if (!mOptions.testFlag(SynEditorOption::eoScrollPastEof)) - setTopLine(mTopLine); + //if (!mOptions.testFlag(SynEditorOption::eoScrollPastEof)) + setTopLine(mTopLine); } void SynEdit::linesChanging() @@ -5010,11 +5006,8 @@ void SynEdit::setBlockEnd(BufferCoord Value) { setActiveSelectionMode(mSelectionMode); if (!mOptions.testFlag(eoNoSelection)) { - if (mOptions.testFlag(eoScrollPastEol)) - Value.Char = MinMax(Value.Char, 1, mMaxScrollWidth + 1); - else - Value.Char = std::max(Value.Char, 1); Value.Line = MinMax(Value.Line, 1, mLines->count()); + Value.Char = MinMax(Value.Char, 1, mLines->lengthOfLongestLine()+1); if (mActiveSelectionMode == SynSelectionMode::smNormal) { if (Value.Line >= 1 && Value.Line <= mLines->count()) Value.Char = std::min(Value.Char, mLines->getString(Value.Line - 1).length() + 1); @@ -5102,10 +5095,7 @@ void SynEdit::setBlockBegin(BufferCoord value) int nInval1, nInval2; bool SelChanged; setActiveSelectionMode(mSelectionMode); - if (mOptions.testFlag(SynEditorOption::eoScrollPastEol)) - value.Char = MinMax(value.Char, 1, mMaxScrollWidth + 1); - else - value.Char = std::max(value.Char, 1); + value.Char = MinMax(value.Char, 1, mLines->lengthOfLongestLine()+1); value.Line = MinMax(value.Line, 1, mLines->count()); if (mActiveSelectionMode == SynSelectionMode::smNormal) { if (value.Line >= 1 && value.Line <= mLines->count()) @@ -5143,14 +5133,9 @@ int SynEdit::leftChar() const void SynEdit::setLeftChar(int Value) { - int MaxVal; + //int MaxVal; //QRect iTextArea; - MaxVal = mLines->lengthOfLongestLine(); - if (mOptions.testFlag(SynEditorOption::eoScrollPastEol)) { - Value = std::min(Value,MaxVal); - } else { - Value = std::min(Value,MaxVal-mCharsInWindow+1); - } + Value = std::min(Value,maxScrollWidth()); if (Value != mLeftChar) { horizontalScrollBar()->setValue(Value); setStatusChanged(SynStatusChange::scLeftChar); @@ -5169,10 +5154,11 @@ int SynEdit::topLine() const void SynEdit::setTopLine(int Value) { - if (mOptions.testFlag(SynEditorOption::eoScrollPastEof)) - Value = std::min(Value, displayLineCount()); - else - Value = std::min(Value, displayLineCount() - mLinesInWindow + 1); + Value = std::min(Value,maxScrollHeight()); +// if (mOptions.testFlag(SynEditorOption::eoScrollPastEof)) +// Value = std::min(Value, displayLineCount()); +// else +// Value = std::min(Value, displayLineCount() - mLinesInWindow + 1); Value = std::max(Value, 1); if (Value != mTopLine) { verticalScrollBar()->setValue(Value); diff --git a/RedPandaIDE/qsynedit/SynEdit.h b/RedPandaIDE/qsynedit/SynEdit.h index d53ac773..5333bd2e 100644 --- a/RedPandaIDE/qsynedit/SynEdit.h +++ b/RedPandaIDE/qsynedit/SynEdit.h @@ -64,35 +64,35 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(SynStateFlags) enum SynEditorOption { eoAltSetsColumnMode = 0x00000001, //Holding down the Alt Key will put the selection mode into columnar format - eoAutoIndent = 0x00000002, //Will indent the caret on new lines with the same amount of leading white space as the preceding line - eoAddIndent = 0x00000004, //Will add one tab width of indent when typing { and :, and remove the same amount when typing } - //eoAutoSizeMaxScrollWidth = 0x00000008, //Automatically resizes the MaxScrollWidth property when inserting text - //eoDisableScrollArrows = 0x00000010 , //Disables the scroll bar arrow buttons when you can't scroll in that direction any more - eoDragDropEditing = 0x00000020, //Allows you to select a block of text and drag it within the document to another location - eoDropFiles = 0x00000040, //Allows the editor accept OLE file drops - eoEnhanceHomeKey = 0x00000080, //enhances home key positioning, similar to visual studio - eoEnhanceEndKey = 0x00000100, //enhances End key positioning, similar to JDeveloper - eoGroupUndo = 0x00000200, //When undoing/redoing actions, handle all continous changes of the same kind in one call instead undoing/redoing each command separately - eoHalfPageScroll = 0x00000400, //When scrolling with page-up and page-down commands, only scroll a half page at a time - eoHideShowScrollbars = 0x00000800, //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 = 0x00001000 , //When moving through lines w/o Cursor Past EOL, keeps the X position of the cursor - eoNoCaret = 0x00002000, //Makes it so the caret is never visible - eoNoSelection = 0x00004000, //Disables selecting text - eoRightMouseMovesCursor = 0x00008000, //When clicking with the right mouse for a popup menu, move the cursor to that location - eoScrollByOneLess = 0x00010000, //Forces scrolling to be one less -// eoScrollHintFollows = 0x00020000, //The scroll hint follows the mouse when scrolling vertically - eoScrollPastEof = 0x00040000, //Allows the cursor to go past the end of file marker - eoScrollPastEol = 0x00080000, //Allows the cursor to go past the last character into the white space at the end of a line -// eoShowScrollHint = 0x00100000, //Shows a hint of the visible line numbers when scrolling vertically - eoShowSpecialChars = 0x00200000, //Shows the special Characters -// eoSmartTabDelete = 0x00400000, //similar to Smart Tabs, but when you delete characters -// eoSmartTabs = 0x00800000, //When tabbing, the cursor will go to the next non-white space character of the previous line - eoSpecialLineDefaultFg = 0x01000000, //disables the foreground text color override when using the OnSpecialLineColor event - eoTabIndent = 0x02000000, //When active and act as block indent, unindent when text is selected - eoTabsToSpaces = 0x04000000, //Converts a tab character to a specified number of space characters - eoShowRainbowColor = 0x08000000, - eoTrimTrailingSpaces = 0x10000000, //Spaces at the end of lines will be trimmed and not saved - eoSelectWordByDblClick = 0x20000000 + eoAutoIndent = 0x00000002, //Will indent the caret on new lines with the same amount of leading white space as the preceding line + eoAddIndent = 0x00000004, //Will add one tab width of indent when typing { and :, and remove the same amount when typing } + eoDragDropEditing = 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 + eoEnhanceHomeKey = 0x00000020, //enhances home key positioning, similar to visual studio + eoEnhanceEndKey = 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 + eoHalfPageScroll = 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) + eoKeepCaretX = 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 + eoScrollByOneLess = 0x00001000, //Forces scrolling to be one less + eoScrollPastEof = 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 + eoShowSpecialChars = 0x00008000, //Shows the special Characters + eoSpecialLineDefaultFg = 0x00010000, //disables the foreground text color override when using the OnSpecialLineColor event + eoTabIndent = 0x00020000, //When active and act as block indent, unindent when text is selected + eoTabsToSpaces = 0x00040000, //Converts a tab character to a specified number of space characters + eoShowRainbowColor = 0x00080000, + eoTrimTrailingSpaces =0x00100000, //Spaces at the end of lines will be trimmed and not saved + eoSelectWordByDblClick=0x00200000, + eoNoSelection = 0x00400000, //Disables selecting text + //eoAutoSizeMaxScrollWidth = 0x00000008, //Automatically resizes the MaxScrollWidth property when inserting text + //eoDisableScrollArrows = 0x00000010 , //Disables the scroll bar arrow buttons when you can't scroll in that direction any more + // eoScrollHintFollows = 0x00020000, //The scroll hint follows the mouse when scrolling vertically + // eoShowScrollHint = 0x00100000, //Shows a hint of the visible line numbers when scrolling vertically + // eoSmartTabDelete = 0x00400000, //similar to Smart Tabs, but when you delete characters + // eoSmartTabs = 0x00800000, //When tabbing, the cursor will go to the next non-white space character of the previous line + // eoNoCaret = 0x00000800, //Makes it so the caret is never visible }; Q_DECLARE_FLAGS(SynEditorOptions, SynEditorOption) @@ -146,38 +146,38 @@ public: * Returns how many rows are there in the editor * @return */ - int displayLineCount(); + int displayLineCount() const; /** * @brief displayX * @return */ - DisplayCoord displayXY(); - int displayX(); - int displayY(); - BufferCoord caretXY(); - int caretX(); - int caretY(); + DisplayCoord displayXY() const; + int displayX() const; + int displayY() const; + BufferCoord caretXY() const; + int caretX() const; + int caretY() const; void invalidateGutter(); void invalidateGutterLine(int aLine); void invalidateGutterLines(int FirstLine, int LastLine); - DisplayCoord pixelsToNearestRowColumn(int aX, int aY); - DisplayCoord pixelsToRowColumn(int aX, int aY); - QPoint RowColumnToPixels(const DisplayCoord& coord); - DisplayCoord bufferToDisplayPos(const BufferCoord& p); - BufferCoord displayToBufferPos(const DisplayCoord& p); - int leftSpaces(const QString& line); - QString GetLeftSpacing(int charCount,bool wantTabs); - int charToColumn(int aLine, int aChar); - int charToColumn(const QString& s, int aChar); - int columnToChar(int aLine, int aColumn); - int stringColumns(const QString& line, int colsBefore); - int getLineIndent(const QString& line); - int rowToLine(int aRow); - int lineToRow(int aLine); - int foldRowToLine(int Row); - int foldLineToRow(int Line); + DisplayCoord pixelsToNearestRowColumn(int aX, int aY) const; + DisplayCoord pixelsToRowColumn(int aX, int aY) const; + QPoint RowColumnToPixels(const DisplayCoord& coord) const; + DisplayCoord bufferToDisplayPos(const BufferCoord& p) const; + BufferCoord displayToBufferPos(const DisplayCoord& p) const; + int leftSpaces(const QString& line) const; + QString GetLeftSpacing(int charCount,bool wantTabs) const; + int charToColumn(int aLine, int aChar) const; + int charToColumn(const QString& s, int aChar) const; + int columnToChar(int aLine, int aColumn) const; + int stringColumns(const QString& line, int colsBefore) const; + int getLineIndent(const QString& line) const; + int rowToLine(int aRow) const; + int lineToRow(int aLine) const; + int foldRowToLine(int Row) const; + int foldLineToRow(int Line) const; void setDefaultKeystrokes(); void invalidateLine(int Line); void invalidateLines(int FirstLine, int LastLine); @@ -186,11 +186,11 @@ public: void invalidate(); void lockPainter(); void unlockPainter(); - bool selAvail(); + bool selAvail() const; - int charColumns(QChar ch); - double dpiFactor(); - bool IsPointInSelection(const BufferCoord& Value); + int charColumns(QChar ch) const; + double dpiFactor() const; + bool IsPointInSelection(const BufferCoord& Value) const; BufferCoord NextWordPos(); BufferCoord NextWordPosEx(const BufferCoord& XY); BufferCoord WordStart(); @@ -209,6 +209,9 @@ public: void setCaretXYEx(bool CallEnsureCursorPos, BufferCoord value); void setCaretXYCentered(bool ForceToMiddle, const BufferCoord& value); + int maxScrollWidth() const; + int maxScrollHeight() const; + bool GetHighlighterAttriAtRowCol(const BufferCoord& XY, QString& Token, PSynHighlighterAttribute& Attri); bool GetHighlighterAttriAtRowCol(const BufferCoord& XY, QString& Token, @@ -217,6 +220,7 @@ public: bool GetHighlighterAttriAtRowColEx(const BufferCoord& XY, QString& Token, SynHighlighterTokenType& TokenType, SynTokenKind &TokenKind, int &Start, PSynHighlighterAttribute& Attri); + //Commands void cutToClipboard() { CommandProcessor(SynEditorCommand::ecCut);} void copyToClipboard() { CommandProcessor(SynEditorCommand::ecCopy);} @@ -255,9 +259,6 @@ public: bool modified() const; void setModified(bool Value); - int maxScrollWidth() const; - void setMaxScrollWidth(int Value); - int tabWidth() const; PSynHighlighter highlighter() const; @@ -388,7 +389,7 @@ private: PSynEditFoldRange checkFoldRange(SynEditFoldRanges* FoldRangeToCheck,int Line, bool WantCollapsed, bool AcceptFromLine, bool AcceptToLine); PSynEditFoldRange foldEndAtLine(int Line); void paintCaret(QPainter& painter, const QRect rcClip); - int textOffset(); + int textOffset() const; SynEditorCommand TranslateKeyCode(int key, Qt::KeyboardModifiers modifiers); /** * Move the caret to right DX columns @@ -505,7 +506,6 @@ private: PSynEditUndoList mOrigRedoList; int mLinesInWindow; int mLeftChar; - int mMaxScrollWidth; int mPaintLock; // lock counter for internal calculations bool mReadOnly; int mRightEdge; diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index c45e1de9..0ca4bee7 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -11,7 +11,6 @@ const char ValueToChar[28] = {'0', '1', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; - Settings* pSettings; Settings::Settings(const QString &filename): @@ -190,16 +189,66 @@ void Settings::Editor::setCaretColor(const QColor &caretColor) mCaretColor = caretColor; } -bool Settings::Editor::Editor::keepCaretX() const +bool Settings::Editor::keepCaretX() const { return mKeepCaretX; } -void Settings::Editor::Editor::setKeepCaretX(bool keepCaretX) +void Settings::Editor::setKeepCaretX(bool keepCaretX) { mKeepCaretX = keepCaretX; } +bool Settings::Editor::halfPageScroll() const +{ + return mHalfPageScroll; +} + +void Settings::Editor::setHalfPageScroll(bool halfPageScroll) +{ + mHalfPageScroll = halfPageScroll; +} + +bool Settings::Editor::scrollByOneLess() const +{ + return mScrollByOneLess; +} + +void Settings::Editor::setScrollByOneLess(bool scrollByOneLess) +{ + mScrollByOneLess = scrollByOneLess; +} + +bool Settings::Editor::scrollPastEol() const +{ + return mScrollPastEol; +} + +void Settings::Editor::setScrollPastEol(bool scrollPastEol) +{ + mScrollPastEol = scrollPastEol; +} + +bool Settings::Editor::scrollPastEof() const +{ + return mScrollPastEof; +} + +void Settings::Editor::setScrollPastEof(bool scrollPastEof) +{ + mScrollPastEof = scrollPastEof; +} + +bool Settings::Editor::autoHideScrollbar() const +{ + return mAutoHideScrollbar; +} + +void Settings::Editor::setAutoHideScrollbar(bool autoHideScrollbar) +{ + mAutoHideScrollbar = autoHideScrollbar; +} + void Settings::Editor::doSave() { saveValue("default_encoding",mDefaultEncoding); @@ -217,6 +266,13 @@ void Settings::Editor::doSave() saveValue("caret_for_insert",static_cast(mCaretForInsert)); saveValue("caret_for_overwrite",static_cast(mCaretForOverwrite)); saveValue("caret_color",mCaretColor); + + //scroll + saveValue("auto_hide_scroll_bar", mAutoHideScrollbar); + saveValue("scroll_past_eof", mScrollPastEof); + saveValue("scroll_past_eol", mScrollPastEol); + saveValue("scroll_by_one_less", mScrollByOneLess); + saveValue("half_page_scroll", mHalfPageScroll); } void Settings::Editor::doLoad() @@ -236,6 +292,13 @@ void Settings::Editor::doLoad() mCaretForInsert = static_cast( intValue("caret_for_insert",static_cast(SynEditCaretType::ctVerticalLine))); mCaretForOverwrite = static_cast( intValue("caret_for_overwrite",static_cast(SynEditCaretType::ctBlock))); mCaretColor = colorValue("caret_color",QColorConstants::Svg::black); + + //scroll + mAutoHideScrollbar = boolValue("auto_hide_scroll_bar", false); + mScrollPastEof = boolValue("scroll_past_eof", true); + mScrollPastEol = boolValue("scroll_past_eol", true); + mScrollByOneLess = boolValue("scroll_by_one_less", false); + mHalfPageScroll = boolValue("half_page_scroll",false); } SynEditCaretType Settings::Editor::caretForOverwrite() const diff --git a/RedPandaIDE/settings.h b/RedPandaIDE/settings.h index 0078be51..a0349e6d 100644 --- a/RedPandaIDE/settings.h +++ b/RedPandaIDE/settings.h @@ -118,6 +118,21 @@ public: bool keepCaretX() const; void setKeepCaretX(bool keepCaretX); + bool autoHideScrollbar() const; + void setAutoHideScrollbar(bool autoHideScrollbar); + + bool scrollPastEof() const; + void setScrollPastEof(bool scrollPastEof); + + bool scrollPastEol() const; + void setScrollPastEol(bool scrollPastEol); + + bool scrollByOneLess() const; + void setScrollByOneLess(bool scrollByOneLess); + + bool halfPageScroll() const; + void setHalfPageScroll(bool halfPageScroll); + private: QByteArray mDefaultEncoding; // indents @@ -134,6 +149,12 @@ public: SynEditCaretType mCaretForInsert; SynEditCaretType mCaretForOverwrite; QColor mCaretColor; + //scroll + bool mAutoHideScrollbar; + bool mScrollPastEof; + bool mScrollPastEol; + bool mScrollByOneLess; + bool mHalfPageScroll; // _Base interface protected: diff --git a/RedPandaIDE/settingsdialog/editorfontwidget.cpp b/RedPandaIDE/settingsdialog/editorfontwidget.cpp new file mode 100644 index 00000000..317a73fd --- /dev/null +++ b/RedPandaIDE/settingsdialog/editorfontwidget.cpp @@ -0,0 +1,43 @@ +#include "editorfontwidget.h" +#include "ui_editorfontwidget.h" + +EditorFontWidget::EditorFontWidget(const QString& name, const QString& group, QWidget *parent) : + SettingsWidget(name,group,parent), + ui(new Ui::EditorFontWidget) +{ + ui->setupUi(this); +} + +EditorFontWidget::~EditorFontWidget() +{ + delete ui; +} + + +void EditorFontWidget::on_chkOnlyMonospacedFonts_stateChanged(int) +{ + if (ui->chkOnlyMonospacedFonts->isChecked()) { + ui->cbFont->setFontFilters(QFontComboBox::FontFilter::MonospacedFonts); + } else { + ui->cbFont->setFontFilters(QFontComboBox::FontFilter::AllFonts); + } +} + +void EditorFontWidget::on_chkGutterOnlyMonospacedFonts_stateChanged(int) +{ + if (ui->chkGutterOnlyMonospacedFonts->isChecked()) { + ui->cbGutterFont->setFontFilters(QFontComboBox::FontFilter::MonospacedFonts); + } else { + ui->cbGutterFont->setFontFilters(QFontComboBox::FontFilter::AllFonts); + } +} + +void EditorFontWidget::doLoad() +{ + +} + +void EditorFontWidget::doSave() +{ + +} diff --git a/RedPandaIDE/settingsdialog/editorfontwidget.h b/RedPandaIDE/settingsdialog/editorfontwidget.h new file mode 100644 index 00000000..bb71a2ea --- /dev/null +++ b/RedPandaIDE/settingsdialog/editorfontwidget.h @@ -0,0 +1,33 @@ +#ifndef EDITORFONTWIDGET_H +#define EDITORFONTWIDGET_H + +#include +#include "settingswidget.h" + +namespace Ui { +class EditorFontWidget; +} + +class EditorFontWidget : public SettingsWidget +{ + Q_OBJECT + +public: + explicit EditorFontWidget(const QString& name, const QString& group, QWidget *parent = nullptr); + ~EditorFontWidget(); + + +private slots: + void on_chkOnlyMonospacedFonts_stateChanged(int arg1); + void on_chkGutterOnlyMonospacedFonts_stateChanged(int arg1); + +private: + Ui::EditorFontWidget *ui; + + // SettingsWidget interface +protected: + void doLoad() override; + void doSave() override; +}; + +#endif // EDITORFONTWIDGET_H diff --git a/RedPandaIDE/settingsdialog/editorfontwidget.ui b/RedPandaIDE/settingsdialog/editorfontwidget.ui new file mode 100644 index 00000000..e5c2f938 --- /dev/null +++ b/RedPandaIDE/settingsdialog/editorfontwidget.ui @@ -0,0 +1,379 @@ + + + EditorFontWidget + + + + 0 + 0 + 737 + 569 + + + + Form + + + + + + + 11 + + + 11 + + + + + Size: + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 2 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + Font: + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + false + + + QComboBox::AdjustToContentsOnFirstShow + + + QFontComboBox::AllFonts + + + + + + + Show only monospaced fonts + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + Gutter + + + + + + Gutter is visible + + + + + + + Auto size the gutter + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + base width + + + + + + + 1 + + + 999 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + Show Line Numbers + + + true + + + + + + Add leading zeros to line numbers + + + + + + + Line numbers starts at zero + + + + + + + + + + Use Custom Font + + + true + + + + + + Font: + + + + + + + Size: + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 2 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + false + + + QComboBox::AdjustToContentsOnFirstShow + + + QFontComboBox::AllFonts + + + + + + + Show only monospaced fonts + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/RedPandaIDE/settingsdialog/editorgeneralwidget.cpp b/RedPandaIDE/settingsdialog/editorgeneralwidget.cpp index bcfb0ea1..7e069559 100644 --- a/RedPandaIDE/settingsdialog/editorgeneralwidget.cpp +++ b/RedPandaIDE/settingsdialog/editorgeneralwidget.cpp @@ -51,6 +51,12 @@ void EditorGeneralWidget::doLoad() setCaretTypeIndex(ui->cbCaretForInsert,pSettings->editor().caretForInsert()); setCaretTypeIndex(ui->cbCaretForOverwrite,pSettings->editor().caretForOverwrite()); ui->colorCaret->setColor(pSettings->editor().caretColor()); + //scrolls; + ui->chkAutoHideScrollBars->setChecked(pSettings->editor().autoHideScrollbar()); + ui->chkScrollPastEOF->setChecked(pSettings->editor().scrollPastEof()); + ui->chkScrollPastEOL->setChecked(pSettings->editor().scrollPastEol()); + ui->chkScrollHalfPage->setChecked(pSettings->editor().halfPageScroll()); + ui->chkScrollByOneLess->setChecked(pSettings->editor().scrollByOneLess()); } void EditorGeneralWidget::doSave() @@ -69,6 +75,12 @@ void EditorGeneralWidget::doSave() pSettings->editor().setCaretForInsert(getCaretTypeIndex(ui->cbCaretForInsert)); pSettings->editor().setCaretForOverwrite(getCaretTypeIndex(ui->cbCaretForOverwrite)); pSettings->editor().setCaretColor(ui->colorCaret->color()); + //scrolls; + pSettings->editor().setAutoHideScrollbar(ui->chkAutoHideScrollBars->isChecked()); + pSettings->editor().setScrollPastEof(ui->chkScrollPastEOF->isChecked()); + pSettings->editor().setScrollPastEol(ui->chkScrollPastEOL->isChecked()); + pSettings->editor().setScrollByOneLess(ui->chkScrollByOneLess->isChecked()); + pSettings->editor().setHalfPageScroll(ui->chkScrollHalfPage->isChecked()); pSettings->editor().save(); pMainWindow->updateEditorSettings(); diff --git a/RedPandaIDE/settingsdialog/editorgeneralwidget.ui b/RedPandaIDE/settingsdialog/editorgeneralwidget.ui index 087c3354..4623fa1b 100644 --- a/RedPandaIDE/settingsdialog/editorgeneralwidget.ui +++ b/RedPandaIDE/settingsdialog/editorgeneralwidget.ui @@ -7,7 +7,7 @@ 0 0 721 - 636 + 691 @@ -165,7 +165,24 @@ 7 - + + + + Caret for overwriting mode + + + + + + + + + + Caret for inserting mode + + + + Qt::Horizontal @@ -178,7 +195,14 @@ - + + + + Caret Color + + + + QFrame::StyledPanel @@ -188,47 +212,9 @@ - - - - Caret can be positioned past end of line - - - - + - - - - Caret for inserting mode - - - - - - - - - - Caret for overwriting mode - - - - - - - Caret Color - - - - - - - Caret can be positioned past end of file - - - @@ -240,6 +226,43 @@ Scroll + + + + + Auto hide scroll bars + + + + + + + Can scroll the last char to the left edge of the editor + + + + + + + Can scroll the last line to the top edge of the editor + + + + + + + Page Up/Down scrolls half a page + + + + + + + Forces page scroll to be one line less + + + + diff --git a/RedPandaIDE/settingsdialog/settingsdialog.cpp b/RedPandaIDE/settingsdialog/settingsdialog.cpp index 1b032fb5..baaf3b52 100644 --- a/RedPandaIDE/settingsdialog/settingsdialog.cpp +++ b/RedPandaIDE/settingsdialog/settingsdialog.cpp @@ -3,6 +3,7 @@ #include "settingswidget.h" #include "compilersetoptionwidget.h" #include "editorgeneralwidget.h" +#include "editorfontwidget.h" #include #include @@ -25,6 +26,10 @@ SettingsDialog::SettingsDialog(QWidget *parent) : pEditorGeneralWidget = new EditorGeneralWidget(tr("General"),tr("Editor")); pEditorGeneralWidget->init(); addWidget(pEditorGeneralWidget); + + pEditorFontWidget = new EditorFontWidget(tr("Font"),tr("Editor")); + pEditorFontWidget->init(); + addWidget(pEditorFontWidget); } SettingsDialog::~SettingsDialog() diff --git a/RedPandaIDE/settingsdialog/settingsdialog.h b/RedPandaIDE/settingsdialog/settingsdialog.h index b6360c94..6ba9d4b0 100644 --- a/RedPandaIDE/settingsdialog/settingsdialog.h +++ b/RedPandaIDE/settingsdialog/settingsdialog.h @@ -12,6 +12,7 @@ class SettingsDialog; class CompilerSetOptionWidget; class EditorGeneralWidget; +class EditorFontWidget; class PCompilerSet; class SettingsWidget; class SettingsDialog : public QDialog @@ -44,6 +45,7 @@ private: CompilerSetOptionWidget* pCompilerSetOptionWidget; EditorGeneralWidget* pEditorGeneralWidget; + EditorFontWidget* pEditorFontWidget; }; #endif // SETTINGSDIALOG_H