diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 9d44fce7..2727638a 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -5334,6 +5334,7 @@ void Editor::applySettings() codeFolding().fillIndents = pSettings->editor().fillIndents(); QFont f=QFont(); + f.setFamily(pSettings->editor().fontName()); f.setFamilies(pSettings->editor().fontFamilies()); f.setPixelSize(pointToPixel(pSettings->editor().fontSize())); f.setStyleStrategy(QFont::PreferAntialias); @@ -5418,6 +5419,7 @@ static QSynedit::PTokenAttribute createRainbowAttribute(const QString& attrName, } return QSynedit::PTokenAttribute(); } + void Editor::applyColorScheme(const QString& schemeName) { QSynedit::EditorOptions options = getOptions(); diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index d54b5a6c..5d69712d 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -718,6 +718,7 @@ void Settings::Editor::setUseFallbackFont3(bool useFont) { QStringList Settings::Editor::fontFamilies() const { QStringList result { + //QString("%1 [%2]").arg(mFontName,mFallbackFontName), mFontName, mFallbackFontName, }; diff --git a/RedPandaIDE/settingsdialog/editorfontwidget.cpp b/RedPandaIDE/settingsdialog/editorfontwidget.cpp index 889ae7ae..955d917b 100644 --- a/RedPandaIDE/settingsdialog/editorfontwidget.cpp +++ b/RedPandaIDE/settingsdialog/editorfontwidget.cpp @@ -125,6 +125,7 @@ void EditorFontWidget::doSave() pSettings->editor().setGutterFontSize(ui->spinGutterFontSize->value()); pSettings->editor().save(); + QFont::cleanup(); pMainWindow->updateEditorSettings(); } diff --git a/RedPandaIDE/settingsdialog/editorfontwidget.ui b/RedPandaIDE/settingsdialog/editorfontwidget.ui index 27c3685d..082b4ebc 100644 --- a/RedPandaIDE/settingsdialog/editorfontwidget.ui +++ b/RedPandaIDE/settingsdialog/editorfontwidget.ui @@ -52,13 +52,6 @@ - - - - *Needs restart - - - @@ -135,13 +128,6 @@ - - - - *Needs restart - - - @@ -269,13 +255,6 @@ - - - - *Needs restart - - - diff --git a/RedPandaIDE/widgets/cpudialog.cpp b/RedPandaIDE/widgets/cpudialog.cpp index a48aefed..14fb9a97 100644 --- a/RedPandaIDE/widgets/cpudialog.cpp +++ b/RedPandaIDE/widgets/cpudialog.cpp @@ -148,9 +148,10 @@ void CPUDialog::resetEditorFont(float dpi) pSettings->editor().forceFixedFontWidth()); ui->txtCode->setOptions(options); QFont f=QFont(); + f.setFamily(pSettings->editor().fontName()); f.setFamilies(pSettings->editor().fontFamilies()); f.setPixelSize(pointToPixel(pSettings->editor().fontSize(),dpi)); - f.setStyleStrategy(QFont::PreferAntialias); + f.setStyleStrategy(QFont::NoFontMerging); ui->txtCode->setFont(f); } diff --git a/libs/qsynedit/qsynedit/painter.cpp b/libs/qsynedit/qsynedit/painter.cpp index e9b50cb7..9dbaa9d7 100644 --- a/libs/qsynedit/qsynedit/painter.cpp +++ b/libs/qsynedit/qsynedit/painter.cpp @@ -32,7 +32,7 @@ QSynEditPainter::QSynEditPainter(QSynEdit *edit, QPainter *painter, int firstRow { } -void QSynEditPainter::paintTextLines(const QRect& clip) +void QSynEditPainter::paintEditingArea(const QRect& clip) { mPainter->fillRect(clip, mEdit->mBackgroundColor); mClip = clip; @@ -55,33 +55,33 @@ void QSynEditPainter::paintTextLines(const QRect& clip) // necessary information about the selected area: is there any visible // selected area, and what are its lines / columns? if (mLastLine >= mFirstLine) { - computeSelectionInfo(); - paintLines(); + computeSelectionInfo(); + paintLines(); } //painter->setClipping(false); // If anything of the two pixel space before the text area is visible, then // fill it with the component background color. if (mClip.left() mGutterWidth + 2) { - rcToken = mClip; - rcToken.setLeft( std::max(mClip.left(), mEdit->mGutterWidth)); - rcToken.setRight(mEdit->mGutterWidth + 2); + mRcToken = mClip; + mRcToken.setLeft( std::max(mClip.left(), mEdit->mGutterWidth)); + mRcToken.setRight(mEdit->mGutterWidth + 2); // Paint whole left edge of the text with same color. // (value of WhiteAttribute can vary in e.g. MultiSyn) - mPainter->fillRect(rcToken,colEditorBG()); + mPainter->fillRect(mRcToken,colEditorBG()); // Adjust the invalid area to not include this area. - mClip.setLeft(rcToken.right()); + mClip.setLeft(mRcToken.right()); } // If there is anything visible below the last line, then fill this as well. - rcToken = mClip; - rcToken.setTop((mLastRow - mEdit->mTopLine + 1) * mEdit->mTextHeight); - if (rcToken.top() < rcToken.bottom()) { - mPainter->fillRect(rcToken,colEditorBG()); + mRcToken = mClip; + mRcToken.setTop((mLastRow - mEdit->mTopLine + 1) * mEdit->mTextHeight); + if (mRcToken.top() < mRcToken.bottom()) { + mPainter->fillRect(mRcToken,colEditorBG()); // Draw the right edge if necessary. if (bDoRightEdge) { QPen pen(mEdit->mRightEdgeColor,1); mPainter->setPen(pen); - mPainter->drawLine(nRightEdge, rcToken.top(),nRightEdge, rcToken.bottom() + 1); + mPainter->drawLine(nRightEdge, mRcToken.top(),nRightEdge, mRcToken.bottom() + 1); } } @@ -350,11 +350,11 @@ void QSynEditPainter::paintToken( // qDebug()<= first && rcToken.right() > rcToken.left()) { + if (last >= first && mRcToken.right() > mRcToken.left()) { nX = fixXValue(first); first -= tokenLeft; last -= tokenLeft; - QRect rcTokenBack = rcToken; + QRect rcTokenBack = mRcToken; mPainter->fillRect(rcTokenBack,mPainter->brush()); if (first > tokenWidth) { } else { @@ -399,7 +399,7 @@ void QSynEditPainter::paintToken( break; int glyph2Width = calcSegmentInterval(glyphStartPositionList, tokenRight, i+1); if (mEdit->mOptions.testFlag(eoForceMonospace)) { - if (glyphWidth+glyph2Width != mPainter->fontMetrics().horizontalAdvance(textToPaint+glyph2)) { + if (glyph2Width != mPainter->fontMetrics().horizontalAdvance(glyph2)) { break; } } @@ -414,7 +414,7 @@ void QSynEditPainter::paintToken( fontInited = true; } //qDebug()<<"paint 1:"<drawText(nX,rcToken.bottom()-mPainter->fontMetrics().descent() , textToPaint); + mPainter->drawText(nX,mRcToken.bottom()-mPainter->fontMetrics().descent() , textToPaint); drawed = true; } } @@ -441,7 +441,7 @@ void QSynEditPainter::paintToken( fontInited = true; } //qDebug()<<"Drawing"<drawText(nX+padding,rcToken.bottom()-mPainter->fontMetrics().descent() , textToPaint); + mPainter->drawText(nX+padding,mRcToken.bottom()-mPainter->fontMetrics().descent() , textToPaint); } } drawed = true; @@ -454,7 +454,7 @@ void QSynEditPainter::paintToken( } } - rcToken.setLeft(rcToken.right()+1); + mRcToken.setLeft(mRcToken.right()+1); } } @@ -464,7 +464,7 @@ void QSynEditPainter::paintEditAreas(const EditingAreaList &areaList) int x1,x2; int offset; //painter->setClipRect(rcLine); - rc=rcLine; + rc=mRcLine; rc.setBottom(rc.bottom()-1); setDrawingColors(false); for (const PEditingArea& p:areaList) { @@ -512,7 +512,8 @@ void QSynEditPainter::paintEditAreas(const EditingAreaList &areaList) void QSynEditPainter::paintHighlightToken(const QString& lineText, const QList &glyphStartCharList, - const QList &glyphStartPositionsList) + const QList &glyphStartPositionsList, + bool bFillToEOL) { bool isComplexToken; int nC1, nC2, nC1Sel, nC2Sel; @@ -553,7 +554,7 @@ void QSynEditPainter::paintHighlightToken(const QString& lineText, // first unselected part of the token if (bU1) { setDrawingColors(false); - rcToken.setRight(fixXValue(mLineSelStart)); + mRcToken.setRight(fixXValue(mLineSelStart)); paintToken( lineText, glyphStartCharList, @@ -567,7 +568,7 @@ void QSynEditPainter::paintHighlightToken(const QString& lineText, setDrawingColors(true); nC1Sel = std::max(mLineSelStart, nC1); nC2Sel = std::min(mLineSelEnd, nC2); - rcToken.setRight(fixXValue(nC2Sel)); + mRcToken.setRight(fixXValue(nC2Sel)); paintToken( lineText, glyphStartCharList, @@ -579,7 +580,7 @@ void QSynEditPainter::paintHighlightToken(const QString& lineText, // second unselected part of the token if (bU2) { setDrawingColors(false); - rcToken.setRight(fixXValue(nC2)); + mRcToken.setRight(fixXValue(nC2)); paintToken( lineText, glyphStartCharList, @@ -591,7 +592,7 @@ void QSynEditPainter::paintHighlightToken(const QString& lineText, } } else { setDrawingColors(bSel); - rcToken.setRight(fixXValue(nC2)); + mRcToken.setRight(fixXValue(nC2)); paintToken( lineText, glyphStartCharList, @@ -602,6 +603,23 @@ void QSynEditPainter::paintHighlightToken(const QString& lineText, mTokenAccu.font, mTokenAccu.showSpecialGlyphs); } } + + // Fill the background to the end of this line if necessary. + if (bFillToEOL && mRcToken.left() < mRcLine.right()) { + if (mIsSpecialLine && colSpBG.isValid()) + colBG = colSpBG; + else + colBG = colEditorBG(); + if (mIsComplexLine) { + setDrawingColors(mRcToken.left() < mLineSelEnd); + mRcToken.setRight(mRcLine.right()); + mPainter->fillRect(mRcToken,mPainter->brush()); + } else { + setDrawingColors(mIsLineSelected); + mRcToken.setRight(mRcLine.right()); + mPainter->fillRect(mRcToken,mPainter->brush()); + } + } } // Store the token chars with the attributes in the TokenAccu @@ -663,7 +681,7 @@ void QSynEditPainter::addHighlightToken( } // If we can't append it, then we have to paint the old token chars first. if (!bCanAppend) - paintHighlightToken(lineText, glyphStartCharList, glyphStartPositionList); + paintHighlightToken(lineText, glyphStartCharList, glyphStartPositionList, false); } if (bInitFont) { mTokenAccu.style = style; @@ -708,7 +726,7 @@ void QSynEditPainter::addHighlightToken( void QSynEditPainter::paintFoldAttributes() { - int tabSteps, lineIndent, lastNonBlank, X, Y; + int tabSteps, lineIndent, lastNonBlank; // Paint indent guides. Use folds to determine indent value of these // Use a separate loop so we can use a custom pen // Paint indent guides using custom pen @@ -728,8 +746,9 @@ void QSynEditPainter::paintFoldAttributes() int vLine = mEdit->rowToLine(row); if (vLine > mEdit->mDocument->count() && mEdit->mDocument->count() > 0) break; + int X; // Set vertical coord - Y = (row - mEdit->mTopLine) * mEdit->mTextHeight; // limit inside clip rect + int Y = (row - mEdit->mTopLine) * mEdit->mTextHeight; // limit inside clip rect if (mEdit->mTextHeight % 2 == 1 && vLine % 2 == 0) { Y++; } @@ -742,15 +761,10 @@ void QSynEditPainter::paintFoldAttributes() lineIndent = mEdit->getLineIndent(mEdit->mDocument->getLine(lastNonBlank)); int braceLevel = mEdit->mDocument->getSyntaxState(lastNonBlank).braceLevel; int indentLevel = braceLevel ; - if (mEdit->tabSize()>0) - indentLevel = lineIndent / mEdit->tabSize(); - // Step horizontal coord - //TabSteps = edit->mTabWidth; tabSteps = 0; indentLevel = 0; - while (tabSteps < lineIndent) { - X = tabSteps * mEdit->mCharWidth + mEdit->textOffset() - 2; + X = tabSteps * mEdit->mCharWidth + mEdit->textOffset() - 1; tabSteps+=mEdit->tabSize(); indentLevel++ ; if (mEdit->mSyntaxer) { @@ -771,9 +785,9 @@ void QSynEditPainter::paintFoldAttributes() if (mEdit->mCodeFolding.fillIndents) { int X1; if (tabSteps>lineIndent) - X1 = lineIndent * mEdit->mCharWidth + mEdit->textOffset() - 2; + X1 = lineIndent * mEdit->mCharWidth + mEdit->textOffset() - 1; else - X1 = tabSteps * mEdit->mCharWidth + mEdit->textOffset() - 2; + X1 = tabSteps * mEdit->mCharWidth + mEdit->textOffset() - 1; gradientStart.setAlpha(20); gradientEnd.setAlpha(10); QLinearGradient gradient(X,Y,X1,Y); @@ -805,7 +819,7 @@ void QSynEditPainter::paintFoldAttributes() if (range->collapsed && !range->parentCollapsed() && (range->fromLine <= mLastLine) && (range->fromLine >= mFirstLine) ) { // Get starting and end points - Y = (mEdit->lineToRow(range->fromLine) - mEdit->mTopLine + 1) * mEdit->mTextHeight - 1; + int Y = (mEdit->lineToRow(range->fromLine) - mEdit->mTopLine + 1) * mEdit->mTextHeight - 1; mPainter->drawLine(mClip.left(),Y, mClip.right(),Y); } } @@ -850,8 +864,8 @@ void QSynEditPainter::paintLines() // Initialize rcLine for drawing. Note that Top and Bottom are updated // inside the loop. Get only the starting point for this. - rcLine = mClip; - rcLine.setBottom((mFirstRow - mEdit->mTopLine) * mEdit->mTextHeight); + mRcLine = mClip; + mRcLine.setBottom((mFirstRow - mEdit->mTopLine) * mEdit->mTextHeight); mTokenAccu.width = 0; mTokenAccu.left = 0; mTokenAccu.style = FontStyle::fsNone; @@ -904,7 +918,7 @@ void QSynEditPainter::paintLines() mLineSelEnd = mRight + 1; if ((mEdit->mActiveSelectionMode == SelectionMode::Column) || ((mEdit->mActiveSelectionMode == SelectionMode::Normal) && (row == mSelStart.row)) ) { - int xpos = mEdit->xposToGlyphLeft(vLine,mSelStart.x); + int xpos = mSelStart.x; if (xpos > mRight) { mLineSelStart = 0; mLineSelEnd = 0; @@ -915,7 +929,7 @@ void QSynEditPainter::paintLines() } if ( (mEdit->mActiveSelectionMode == SelectionMode::Column) || ((mEdit->mActiveSelectionMode == SelectionMode::Normal) && (row == mSelEnd.row)) ) { - int xpos = mEdit->xposToGlyphLeft(vLine,mSelEnd.x); + int xpos = mSelEnd.x; if (xpos < mLeft) { mLineSelStart = 0; mLineSelEnd = 0; @@ -931,19 +945,19 @@ void QSynEditPainter::paintLines() // Update the rcLine rect to this line. // rcLine.setTop(rcLine.bottom()); // rcLine.setBottom(rcLine.bottom()+edit->mTextHeight); - rcLine.setTop((row - mEdit->mTopLine) * mEdit->mTextHeight); - rcLine.setHeight(mEdit->mTextHeight); + mRcLine.setTop((row - mEdit->mTopLine) * mEdit->mTextHeight); + mRcLine.setHeight(mEdit->mTextHeight); mIsLineSelected = (!mIsComplexLine) && (mLineSelStart > 0); - if (mIsSpecialLine && colSpBG.isValid()) - colBG = colSpBG; - else - colBG = colEditorBG(); - setDrawingColors(selToEnd); - mPainter->fillRect(rcLine,mPainter->brush()); + // if (mIsSpecialLine && colSpBG.isValid()) + // colBG = colSpBG; + // else + // colBG = colEditorBG(); + // setDrawingColors(selToEnd); + // mPainter->fillRect(rcLine,mPainter->brush()); - rcToken = rcLine; + mRcToken = mRcLine; int lineWidth; QList glyphStartCharList = mEdit->mDocument->getGlyphStartCharList(vLine-1,sLine); @@ -961,8 +975,8 @@ void QSynEditPainter::paintLines() } if (mIsComplexLine) { setDrawingColors(true); - rcToken.setLeft(std::max(rcLine.left(), fixXValue(mLineSelStart))); - rcToken.setRight(std::min(rcLine.right(), fixXValue(mLineSelEnd))); + mRcToken.setLeft(std::max(mRcLine.left(), fixXValue(mLineSelStart))); + mRcToken.setRight(std::min(mRcLine.right(), fixXValue(mLineSelEnd))); paintToken( sLine, glyphStartCharList, @@ -972,8 +986,8 @@ void QSynEditPainter::paintLines() tokenWidth, 0, mLineSelStart, mLineSelEnd, mEdit->font(),false); setDrawingColors(false); - rcToken.setLeft(std::max(rcLine.left(), fixXValue(mLeft))); - rcToken.setRight(std::min(rcLine.right(), fixXValue(mLineSelStart))); + mRcToken.setLeft(std::max(mRcLine.left(), fixXValue(mLeft))); + mRcToken.setRight(std::min(mRcLine.right(), fixXValue(mLineSelStart))); paintToken( sLine, glyphStartCharList, @@ -982,8 +996,8 @@ void QSynEditPainter::paintLines() glyphStartCharList.length(), tokenWidth, 0, mLeft, mLineSelStart, mEdit->font(), false); - rcToken.setLeft(std::max(rcLine.left(), fixXValue(mLineSelEnd))); - rcToken.setRight(std::min(rcLine.right(), fixXValue(mRight))); + mRcToken.setLeft(std::max(mRcLine.left(), fixXValue(mLineSelEnd))); + mRcToken.setRight(std::min(mRcLine.right(), fixXValue(mRight))); paintToken( sLine, glyphStartCharList, @@ -1153,7 +1167,7 @@ void QSynEditPainter::paintLines() } // Draw anything that's left in the TokenAccu record. Fill to the end // of the invalid area with the correct colors. - paintHighlightToken(sLine, glyphStartCharList, glyphStartPositionsList); + paintHighlightToken(sLine, glyphStartCharList, glyphStartPositionsList, true); //Paint editingAreaBorders foreach (const PEditingArea& area, areaList) { @@ -1200,7 +1214,7 @@ void QSynEditPainter::paintLines() // calls to ExtTextOut. if (bDoRightEdge) { mPainter->setPen(mEdit->mRightEdgeColor); - mPainter->drawLine(nRightEdge, rcLine.top(),nRightEdge,rcLine.bottom()+1); + mPainter->drawLine(nRightEdge, mRcLine.top(),nRightEdge,mRcLine.bottom()+1); } mIsCurrentLine = false; } diff --git a/libs/qsynedit/qsynedit/painter.h b/libs/qsynedit/qsynedit/painter.h index 10637543..796a1e5d 100644 --- a/libs/qsynedit/qsynedit/painter.h +++ b/libs/qsynedit/qsynedit/painter.h @@ -49,7 +49,7 @@ public: QSynEditPainter(const QSynEditPainter&)=delete; QSynEditPainter& operator=(const QSynEditPainter&)=delete; - void paintTextLines(const QRect& clip); + void paintEditingArea(const QRect& clip); void paintGutter(const QRect& clip); private: @@ -69,7 +69,8 @@ private: void paintEditAreas(const EditingAreaList& areaList); void paintHighlightToken(const QString& lineText, const QList &glyphStartCharList, - const QList &glyphStartPositionsList); + const QList &glyphStartPositionsList, + bool bFillToEOL); void addHighlightToken( const QString& lineText, const QString& token, int tokenLeft, @@ -103,7 +104,7 @@ private: int mLineSelStart, mLineSelEnd; bool mIsComplexLine; // painting the background and the text - QRect rcLine, rcToken; + QRect mRcLine, mRcToken; int mFirstLine, mLastLine; QRect mClip; diff --git a/libs/qsynedit/qsynedit/qsynedit.cpp b/libs/qsynedit/qsynedit/qsynedit.cpp index e96b4fad..0f62bf0e 100644 --- a/libs/qsynedit/qsynedit/qsynedit.cpp +++ b/libs/qsynedit/qsynedit/qsynedit.cpp @@ -3761,7 +3761,7 @@ void QSynEdit::paintCaret(QPainter &painter, const QRect rcClip) int QSynEdit::textOffset() const { - return mGutterWidth + 2 - mLeftPos; + return mGutterWidth + 2 - mLeftPos ; } EditCommand QSynEdit::TranslateKeyCode(int key, Qt::KeyboardModifiers modifiers) @@ -6049,7 +6049,8 @@ void QSynEdit::paintEvent(QPaintEvent *event) nX1 = mLeftPos; if (rcClip.left() > mGutterWidth + 2 ) nX1 += (rcClip.left() - mGutterWidth - 2 ) ; - nX2 = mLeftPos + (rcClip.right() - mGutterWidth - 2); + // nX2 = mLeftPos + (rcClip.right() - mGutterWidth - 2); + nX2 = rcClip.right(); // lines nL1 = minMax(mTopLine + rcClip.top() / mTextHeight, mTopLine, displayLineCount()); nL2 = minMax(mTopLine + (rcClip.bottom() + mTextHeight - 1) / mTextHeight, 1, displayLineCount()); @@ -6064,7 +6065,7 @@ void QSynEdit::paintEvent(QPaintEvent *event) if (rcClip.right() > mGutterWidth ) { rcDraw = rcClip; rcDraw.setLeft( std::max(rcDraw.left(), mGutterWidth)); - textPainter.paintTextLines(rcDraw); + textPainter.paintEditingArea(rcDraw); } // Then the gutter area if it was (partly) invalidated.