- enhancement: Unique look&feel for the underline shown while ctrl+mouse over #include line.

- enhancement: Better look&feel for the wave underline shown for syntax errors.
This commit is contained in:
Roy Qu 2024-03-03 18:42:45 +08:00
parent 64afb18dfd
commit 8561a035ae
3 changed files with 45 additions and 27 deletions

View File

@ -26,6 +26,8 @@ Red Panda C++ Version 2.27
- change: Force use utf8 as the exec encoding for fmtlib in the auto link options page. - change: Force use utf8 as the exec encoding for fmtlib in the auto link options page.
- fix: After spaces in comments and strings, symbol completion for '{' and '(' are wrong. - fix: After spaces in comments and strings, symbol completion for '{' and '(' are wrong.
- fix: Issue #230 Crash when input " in the txt files. - fix: Issue #230 Crash when input " in the txt files.
- enhancement: Unique look&feel for the underline shown while ctrl+mouse over #include line.
- enhancement: Better look&feel for the wave underline shown for syntax errors.
Red Panda C++ Version 2.26 Red Panda C++ Version 2.26
- enhancement: Code suggestion for embedded std::vectors. - enhancement: Code suggestion for embedded std::vectors.

View File

@ -1141,10 +1141,10 @@ void Editor::onGutterPaint(QPainter &painter, int aLine, int X, int Y)
} }
} }
void Editor::onGetEditingAreas(int Line, QSynedit::EditingAreaList &areaList) void Editor::onGetEditingAreas(int line, QSynedit::EditingAreaList &areaList)
{ {
areaList.clear(); areaList.clear();
if (mTabStopBegin>=0 && mTabStopY == Line) { if (mTabStopBegin>=0 && mTabStopY == line) {
QSynedit::PEditingArea p = std::make_shared<QSynedit::EditingArea>(); QSynedit::PEditingArea p = std::make_shared<QSynedit::EditingArea>();
p->type = QSynedit::EditingAreaType::eatRectangleBorder; p->type = QSynedit::EditingAreaType::eatRectangleBorder;
// int spaceCount = leftSpaces(mLineBeforeTabStop); // int spaceCount = leftSpaces(mLineBeforeTabStop);
@ -1154,7 +1154,7 @@ void Editor::onGetEditingAreas(int Line, QSynedit::EditingAreaList &areaList)
p->color = syntaxer()->stringAttribute()->foreground(); p->color = syntaxer()->stringAttribute()->foreground();
areaList.append(p); areaList.append(p);
} }
PSyntaxIssueList lst = getSyntaxIssuesAtLine(Line); PSyntaxIssueList lst = getSyntaxIssuesAtLine(line);
if (lst) { if (lst) {
for (const PSyntaxIssue& issue: *lst) { for (const PSyntaxIssue& issue: *lst) {
QSynedit::PEditingArea p=std::make_shared<QSynedit::EditingArea>(); QSynedit::PEditingArea p=std::make_shared<QSynedit::EditingArea>();
@ -1169,6 +1169,20 @@ void Editor::onGetEditingAreas(int Line, QSynedit::EditingAreaList &areaList)
areaList.append(p); areaList.append(p);
} }
} }
QString lineText = document()->getLine(line-1);
if (mParser && mParser->isIncludeLine(lineText)) {
if (line == mHoverModifiedLine) {
int pos1=std::max(lineText.indexOf("<"),lineText.indexOf("\""));
int pos2=std::max(lineText.lastIndexOf(">"),lineText.lastIndexOf("\""));
if (pos1>=0 && pos2>=0 && pos1 < pos2) {
QSynedit::PEditingArea p=std::make_shared<QSynedit::EditingArea>();
p->beginX = pos1+2;
p->endX = pos2+1;
p->type = QSynedit::EditingAreaType::eatUnderLine;
areaList.append(p);
}
}
}
} }
bool Editor::onGetSpecialLineColors(int Line, QColor &foreground, QColor &backgroundColor) bool Editor::onGetSpecialLineColors(int Line, QColor &foreground, QColor &backgroundColor)
@ -1210,15 +1224,6 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
} }
QString lineText = document()->getLine(line-1); QString lineText = document()->getLine(line-1);
if (mParser->isIncludeLine(lineText)) { if (mParser->isIncludeLine(lineText)) {
if (line == mHoverModifiedLine) {
int pos1=std::max(lineText.indexOf("<"),lineText.indexOf("\""));
int pos2=std::max(lineText.lastIndexOf(">"),lineText.lastIndexOf("\""));
pos1++;
pos2++;
if (pos1>0 && pos2>0 && pos1<aChar && aChar < pos2) {
style.setFlag(QSynedit::FontStyle::fsUnderline);
}
}
} else if (mParser->enabled() && attr->tokenType() == QSynedit::TokenType::Identifier) { } else if (mParser->enabled() && attr->tokenType() == QSynedit::TokenType::Identifier) {
QSynedit::BufferCoord p{aChar,line}; QSynedit::BufferCoord p{aChar,line};
// BufferCoord pBeginPos,pEndPos; // BufferCoord pBeginPos,pEndPos;

View File

@ -341,7 +341,6 @@ void QSynEditPainter::paintToken(
const QFont& font, bool showGlyphs) const QFont& font, bool showGlyphs)
{ {
bool startPaint; bool startPaint;
int nX;
bool fontInited = false; bool fontInited = false;
int tokenRight = tokenWidth+tokenLeft; int tokenRight = tokenWidth+tokenLeft;
@ -351,7 +350,8 @@ void QSynEditPainter::paintToken(
// qDebug()<<startGlyph<<endGlyph; // qDebug()<<startGlyph<<endGlyph;
if (last >= first && mRcToken.right() > mRcToken.left()) { if (last >= first && mRcToken.right() > mRcToken.left()) {
nX = fixXValue(first); int nX = fixXValue(first);
int nY = mRcToken.bottom()-mPainter->fontMetrics().descent();
first -= tokenLeft; first -= tokenLeft;
last -= tokenLeft; last -= tokenLeft;
QRect rcTokenBack = mRcToken; QRect rcTokenBack = mRcToken;
@ -413,7 +413,7 @@ void QSynEditPainter::paintToken(
mPainter->setFont(font); mPainter->setFont(font);
fontInited = true; fontInited = true;
} }
mPainter->drawText(nX,mRcToken.bottom()-mPainter->fontMetrics().descent() , textToPaint); mPainter->drawText(nX, nY, textToPaint);
drawed = true; drawed = true;
} }
} }
@ -440,7 +440,7 @@ void QSynEditPainter::paintToken(
fontInited = true; fontInited = true;
} }
//qDebug()<<"Drawing"<<textToPaint; //qDebug()<<"Drawing"<<textToPaint;
mPainter->drawText(nX+padding,mRcToken.bottom()-mPainter->fontMetrics().descent() , textToPaint); mPainter->drawText(nX+padding, nY, textToPaint);
} }
} }
drawed = true; drawed = true;
@ -461,12 +461,12 @@ void QSynEditPainter::paintEditAreas(const EditingAreaList &areaList)
{ {
QRect rc; QRect rc;
int x1,x2; int x1,x2;
int offset;
//painter->setClipRect(rcLine); //painter->setClipRect(rcLine);
rc=mRcLine; rc=mRcLine;
rc.setBottom(rc.bottom()-1); rc.setBottom(rc.bottom()-1);
setDrawingColors(false); setDrawingColors(false);
for (const PEditingArea& p:areaList) { for (const PEditingArea& p:areaList) {
int penWidth = std::max(1,mEdit->font().pixelSize() / 15);
if (p->beginX > mRight) if (p->beginX > mRight)
continue; continue;
if (p->endX < mLeft) if (p->endX < mLeft)
@ -481,30 +481,41 @@ void QSynEditPainter::paintEditAreas(const EditingAreaList &areaList)
x2 = p->endX; x2 = p->endX;
rc.setLeft(fixXValue(x1)); rc.setLeft(fixXValue(x1));
rc.setRight(fixXValue(x2)); rc.setRight(fixXValue(x2));
mPainter->setPen(p->color); QPen pen;
pen.setColor(p->color);
pen.setWidth(penWidth);
mPainter->setPen(pen);
mPainter->setBrush(Qt::NoBrush); mPainter->setBrush(Qt::NoBrush);
switch(p->type) { switch(p->type) {
case EditingAreaType::eatRectangleBorder: case EditingAreaType::eatRectangleBorder:
mPainter->drawRect(rc); mPainter->drawRect(rc);
break; break;
case EditingAreaType::eatUnderLine: case EditingAreaType::eatUnderLine: {
mPainter->drawLine(rc.left(),rc.bottom(),rc.right(),rc.bottom()); mPainter->drawLine(rc.left(),rc.bottom()-pen.width(),rc.right(),rc.bottom()-pen.width());
}
break; break;
case EditingAreaType::eatWaveUnderLine: case EditingAreaType::eatWaveUnderLine: {
offset=3; int maxOffset = 2*penWidth;
int offset = maxOffset;
int lastX=rc.left(); int lastX=rc.left();
int lastY=rc.bottom()-offset; int lastY=rc.bottom()-offset;
int t = rc.left(); int t = rc.left();
while (t<rc.right()) { while (t<rc.right()) {
t+=3; t+=maxOffset;
if (t>rc.right()) if (t>=rc.right()) {
int diff = t - rc.right();
offset = (offset==0)?(maxOffset-diff):diff;
t = rc.right(); t = rc.right();
offset = 3 - offset; mPainter->drawLine(lastX,lastY,t,rc.bottom()-offset);
mPainter->drawLine(lastX,lastY,t,rc.bottom()-offset); } else {
offset = maxOffset - offset;
mPainter->drawLine(lastX,lastY,t,rc.bottom()-offset);
}
lastX = t; lastX = t;
lastY = rc.bottom()-offset; lastY = rc.bottom()-offset;
} }
}
break;
} }
} }
} }