* move cursor horizontally ok

This commit is contained in:
royqh1979@gmail.com 2021-05-27 20:33:25 +08:00
parent 7f0ab217e8
commit d4abd99a6c
3 changed files with 1216 additions and 54 deletions

File diff suppressed because it is too large Load Diff

View File

@ -142,10 +142,15 @@ public:
explicit SynEdit(QWidget *parent = nullptr);
/**
* @brief how many rows are there in the editor
* Returns how many rows are there in the editor
* @return
*/
int displayLineCount();
/**
* @brief displayX
* @return
*/
DisplayCoord displayXY();
int displayX();
int displayY();
@ -192,6 +197,7 @@ public:
void showCaret();
void hideCaret();
// setter && getters
int topLine() const;
void setTopLine(int value);
@ -224,6 +230,15 @@ public:
int tabWidth() const;
PSynHighlighter highlighter() const;
void setHighlighter(const PSynHighlighter &highlighter);
bool useCodeFolding() const;
void setUseCodeFolding(bool value);
QString lineText();
void setLineText(const QString s);
PSynEditStringList lines() const;
bool empty();
@ -252,6 +267,8 @@ signals:
void fontChanged();
void tabSizeChanged();
protected:
protected:
virtual bool onGetSpecialLineColors(int Line,
QColor& foreground, QColor& backgroundColor) ;
@ -259,6 +276,9 @@ protected:
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 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);
private:
void clearAreaList(SynEditingAreaList areaList);
@ -315,6 +335,18 @@ private:
PSynEditFoldRange foldEndAtLine(int Line);
void paintCaret(QPainter& painter, const QRect rcClip);
int textOffset();
SynEditorCommand TranslateKeyCode(int key, Qt::KeyboardModifiers modifiers);
void CommandProcessor(SynEditorCommand Command, QChar AChar, void * pData);
/**
* Move the caret to right DX columns
* @param DX
* @param SelectionCommand
*/
void MoveCaretHorz(int DX, bool isSelection);
void MoveCaretAndSelection(const BufferCoord& ptBefore, const BufferCoord& ptAfter,
bool isSelection);
void MoveCaretToLineStart(bool isSelection);
void MoveCaretToLineEnd(bool isSelection);
private slots:
void bookMarkOptionsChanged();
@ -440,34 +472,19 @@ private:
int m_blinkStatus;
// QWidget interface
protected:
void paintEvent(QPaintEvent *event) override;
friend class SynEditTextPainter;
// QWidget interface
protected:
void paintEvent(QPaintEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
// QObject interface
protected:
void timerEvent(QTimerEvent *event) override;
// QObject interface
public:
bool event(QEvent *event) override;
// QWidget interface
PSynHighlighter highlighter() const;
void setHighlighter(const PSynHighlighter &highlighter);
bool useCodeFolding() const;
void setUseCodeFolding(bool value);
protected:
void focusInEvent(QFocusEvent *event) override;
void focusOutEvent(QFocusEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
};
#endif // SYNEDIT_H

View File

@ -50,9 +50,7 @@ void SynEditTextPainter::paintTextLines(const QRect& clip)
rcToken.setRight(edit->mGutterWidth + 2);
// Paint whole left edge of the text with same color.
// (value of WhiteAttribute can vary in e.g. MultiSyn)
painter->setPen(colEditorBG());
painter->setBrush(colEditorBG());
painter->drawRect(rcToken);
painter->fillRect(rcToken,colEditorBG());
// Adjust the invalid area to not include this area.
AClip.setLeft(rcToken.right());
}
@ -60,9 +58,7 @@ void SynEditTextPainter::paintTextLines(const QRect& clip)
rcToken = AClip;
rcToken.setTop((aLastRow - edit->mTopLine + 1) * edit->mTextHeight);
if (rcToken.top() < rcToken.bottom()) {
painter->setPen(colEditorBG());
painter->setBrush(colEditorBG());
painter->drawRect(rcToken);
painter->fillRect(rcToken,colEditorBG());
// Draw the right edge if necessary.
if (bDoRightEdge) {
QPen pen(edit->mRightEdgeColor,1);
@ -95,12 +91,9 @@ void SynEditTextPainter::paintGutter(const QRect& clip)
// the background first. Do it line by line with TextRect instead
// and fill only the area after the last visible line.
//painter->setClipRect(AClip);
painter->setBrush(edit->mGutter.color());
painter->setPen(edit->mGutter.color());
painter->fillRect(AClip,edit->mGutter.color());
rcLine=AClip;
painter->drawRect(AClip);
if (edit->mGutter.showLineNumbers()) {
// prepare the rect initially
rcLine = AClip;
@ -355,11 +348,7 @@ void SynEditTextPainter::PaintToken(const QString &Token, int TokenCols, int Col
nX = ColumnToXValue(First);
First -= ColumnsBefore;
Last -= ColumnsBefore;
QPen oldPen = painter->pen();
QPen newPen(painter->brush().color());
painter->setPen(newPen);
painter->drawRect(rcToken);
painter->setPen(oldPen);
painter->fillRect(rcToken,painter->brush());
if (First > TokenCols) {
} else {
int tokenColLen=0;
@ -520,30 +509,26 @@ void SynEditTextPainter::PaintHighlightToken(bool bFillToEOL)
rcToken.setRight(nX1);
// if (TokenAccu.Len != 0 && TokenAccu.Style != SynFontStyle::fsNone)
// AdjustEndRect();
painter->setPen(Qt::NoPen);
painter->drawRect(rcToken);
painter->fillRect(rcToken,painter->brush());
rcToken.setLeft(nX1);
}
if (rcToken.left() < nX2) {
setDrawingColors(true);
rcToken.setRight(nX2);
painter->setPen(Qt::NoPen);
painter->drawRect(rcToken);
painter->fillRect(rcToken,painter->brush());
rcToken.setLeft(nX2);
}
if (rcToken.left() < rcLine.right()) {
setDrawingColors(false);
rcToken.setRight(rcLine.right());
painter->setPen(Qt::NoPen);
painter->drawRect(rcToken);
painter->fillRect(rcToken,painter->brush());
}
} else {
setDrawingColors(bLineSelected);
rcToken.setRight(rcLine.right());
// if (TokenAccu.Len != 0 && TokenAccu.Style != SynFontStyle::fsNone)
// AdjustEndRect();
painter->setPen(painter->brush().color());
painter->drawRect(rcToken);
painter->fillRect(rcToken,painter->brush());
}
}
}