From 6ad87990c76b8d34734d846345052a5c1a311e94 Mon Sep 17 00:00:00 2001 From: "royqh1979@gmail.com" Date: Wed, 3 Nov 2021 18:09:12 +0800 Subject: [PATCH] - fix: Custom editor colors shouldn't be tested for high contrast with the default background color - fix: Custom color settings not correctly displayed in the options widget - enhancement: add hit counts in the search result view - fix: editor actions' state not correctly updated after close editors. - fix: When replace in the editor, "Yes to All" and "No" button doesn't work correctly. - fix: crash when editing non-c/c++ files - enhancement: set the alpha value of scheme colors - enhancement: can use symbols' own scheme color to draw selection - enhancement: can use different colors to highlight the current word and the selections --- NEWS.md | 5 + RedPandaIDE/colorscheme.cpp | 27 +++- RedPandaIDE/colorscheme.h | 5 + RedPandaIDE/colorschemes/VS_Code.scheme | 14 +- RedPandaIDE/editor.cpp | 146 +++++++++++------- RedPandaIDE/editor.h | 6 +- RedPandaIDE/qsynedit/MiscClasses.cpp | 10 ++ RedPandaIDE/qsynedit/MiscClasses.h | 4 + RedPandaIDE/qsynedit/SynEdit.cpp | 31 +++- RedPandaIDE/qsynedit/SynEdit.h | 8 + RedPandaIDE/qsynedit/TextPainter.cpp | 67 ++++---- .../editorcolorschemewidget.cpp | 46 +++--- RedPandaIDE/widgets/coloredit.cpp | 5 +- 13 files changed, 246 insertions(+), 128 deletions(-) diff --git a/NEWS.md b/NEWS.md index c1be869a..f3d21be6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,6 +8,11 @@ Version 0.7.8 - fix: Custom color settings not correctly displayed in the options widget - enhancement: add hit counts in the search result view - fix: editor actions' state not correctly updated after close editors. + - fix: When replace in the editor, "Yes to All" and "No" button doesn't work correctly. + - fix: crash when editing non-c/c++ files + - enhancement: set the alpha value of scheme colors + - enhancement: can use symbols' own scheme color to draw selection + - enhancement: can use different colors to highlight the current word and the selections Version 0.7.7 - enhancement: Problem Set diff --git a/RedPandaIDE/colorscheme.cpp b/RedPandaIDE/colorscheme.cpp index e0938085..a40d7f55 100644 --- a/RedPandaIDE/colorscheme.cpp +++ b/RedPandaIDE/colorscheme.cpp @@ -60,6 +60,14 @@ PColorScheme ColorScheme::load(const QString &filename) return ColorScheme::fromJson(doc.object()); } +void ColorScheme::addItem(const QString& name) +{ + if (mItems.contains(name)) + return; + PColorSchemeItem item = std::make_shared(); + mItems[name]=item; +} + QMap ColorScheme::items() { return mItems; @@ -220,12 +228,12 @@ PColorSchemeItem ColorSchemeItem::fromJson(const QJsonObject &json) void ColorSchemeItem::toJson(QJsonObject &json) { if (mForeground.isValid()) { - json["foreground"] = mForeground.name(); + json["foreground"] = mForeground.name(QColor::HexArgb); } else if (json.contains("foreground")){ json.remove("foreground"); } if (mBackground.isValid()) { - json["background"] = mBackground.name(); + json["background"] = mBackground.name(QColor::HexArgb); } else if (json.contains("background")){ json.remove("background"); } @@ -503,6 +511,10 @@ void ColorManager::initItemDefines() QObject::tr("Gutter"), QObject::tr("Editor"), true,true,true); + addDefine(COLOR_SCHEME_GUTTER_ACTIVE_LINE, + QObject::tr("Gutter Active Line"), + QObject::tr("Editor"), + true,false,false); //Active Line addDefine(COLOR_SCHEME_ACTIVE_LINE, QObject::tr("Active Line"), @@ -528,6 +540,17 @@ void ColorManager::initItemDefines() QObject::tr("Selection"), QObject::tr("Editor"), true,true,false); + + addDefine(COLOR_SCHEME_TEXT, + QObject::tr("Editor Text"), + QObject::tr("Editor"), + true,true,false); + + addDefine(COLOR_SCHEME_CURRENT_HIGHLIGHTED_WORD, + QObject::tr("Current Highlighted Word"), + QObject::tr("Editor"), + true,true,false); + //Syntax Error addDefine(COLOR_SCHEME_ERROR, QObject::tr("Error"), diff --git a/RedPandaIDE/colorscheme.h b/RedPandaIDE/colorscheme.h index 18143341..fcf5b1ee 100644 --- a/RedPandaIDE/colorscheme.h +++ b/RedPandaIDE/colorscheme.h @@ -11,7 +11,10 @@ #define COLOR_SCHEME_ERROR "Error" #define COLOR_SCHEME_ACTIVE_BREAKPOINT "Active Breakpoint" #define COLOR_SCHEME_GUTTER "Gutter" +#define COLOR_SCHEME_GUTTER_ACTIVE_LINE "Gutter Active Line" #define COLOR_SCHEME_SELECTION "Selected text" +#define COLOR_SCHEME_TEXT "Editor Text" +#define COLOR_SCHEME_CURRENT_HIGHLIGHTED_WORD "Current Highlighted Word" #define COLOR_SCHEME_FOLD_LINE "Fold Line" #define COLOR_SCHEME_ACTIVE_LINE "Active Line" #define COLOR_SCHEME_WARNING "Warning" @@ -69,6 +72,8 @@ public: static PColorScheme load(const QString& filename); + void addItem(const QString& name); + QMap items(); static PColorScheme fromJson(const QJsonObject& json); diff --git a/RedPandaIDE/colorschemes/VS_Code.scheme b/RedPandaIDE/colorschemes/VS_Code.scheme index 07259191..ba6bf41d 100644 --- a/RedPandaIDE/colorschemes/VS_Code.scheme +++ b/RedPandaIDE/colorschemes/VS_Code.scheme @@ -113,7 +113,6 @@ }, "Space" : { "foreground" : "#505050", - "background" : "#1E1E1E", "bold" : false, "italic" : false, "underlined" : false, @@ -140,14 +139,23 @@ "underlined" : false, "strikeout" : false }, + "Editor Text": { + "foreground" : "#ffffff", + "background" : "#1E1E1E" + }, + "Current Highlighted Word": { + "background": "#50ffffff" + }, "Selected text" : { - "foreground" : "#000000", - "background" : "#808080" + "background" : "#3c55aaff" }, "Gutter" : { "foreground" : "#858585", "background" : "#1E1E1E" }, + "Gutter Active Line" : { + "foreground" : "#C0C0C0" + }, "Breakpoint" : { }, "Error" : { diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index cd619af7..0a48a97e 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -74,8 +74,8 @@ Editor::Editor(QWidget *parent, const QString& filename, mLastIdCharPressed(0), mCurrentWord(), mCurrentTipType(TipType::None), - mOldSelectionWord(), - mSelectionWord(), + mOldHighlightedWord(), + mCurrentHighlightedWord(), mSaving(false) { mUseCppSyntax = pSettings->editor().defaultFileCpp(); @@ -855,37 +855,6 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to { if (token.isEmpty()) return; - //selection - if (selAvail() && highlighter()) { - if (( - (attr == highlighter()->identifierAttribute()) - || (attr == highlighter()->keywordAttribute()) - || (attr->name() == SYNS_AttrPreprocessor) - ) - && (token == mSelectionWord)) { - foreground = selectedForeground(); - background = selectedBackground(); - return; - } - } - - if (!selAvail() && attr->name() == SYNS_AttrSymbol) { -// qDebug()<name()<<" - "<identifierAttribute())) { @@ -918,7 +887,43 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to } else { foreground = highlighter()->identifierAttribute()->foreground(); } - return; + } + + //selection + if (highlighter()) { + if (( + (attr == highlighter()->identifierAttribute()) + || (attr == highlighter()->keywordAttribute()) + || (attr->name() == SYNS_AttrPreprocessor) + ) + && (token == mCurrentHighlightedWord)) { + if (mCurrentHighlighWordForeground.isValid()) + foreground = mCurrentHighlighWordForeground; + if (mCurrentHighlighWordBackground.isValid()) + background = mCurrentHighlighWordBackground; + } + } else if (token == mCurrentHighlightedWord) { + if (mCurrentHighlighWordForeground.isValid()) + foreground = mCurrentHighlighWordForeground; + if (mCurrentHighlighWordBackground.isValid()) + background = mCurrentHighlighWordBackground; + } else if (!selAvail() && attr->name() == SYNS_AttrSymbol) { +// qDebug()<=1 && wordBegin.Line<=lines()->count()) { - QString line = lines()->getString(wordBegin.Line-1); - mSelectionWord = line.mid(wordBegin.Char-1,wordEnd.Char-wordBegin.Char); - } - } -// qDebug()<=1 && wordBegin.Line<=lines()->count()) { +// QString line = lines()->getString(wordBegin.Line-1); +// mSelectionWord = line.mid(wordBegin.Char-1,wordEnd.Char-wordBegin.Char); +// } +// } +//// qDebug()<updateStatusbarForLineCol(); @@ -3742,6 +3748,10 @@ void Editor::applyColorScheme(const QString& schemeName) gutter().setTextColor(item->foreground()); gutter().setColor(item->background()); } + item = pColorManager->getItem(schemeName,COLOR_SCHEME_GUTTER_ACTIVE_LINE); + if (item) { + gutter().setActiveLineTextColor(item->foreground()); + } item = pColorManager->getItem(schemeName,COLOR_SCHEME_FOLD_LINE); if (item) { codeFolding().folderBarLinesColor = item->foreground(); @@ -3762,6 +3772,9 @@ void Editor::applyColorScheme(const QString& schemeName) if (item) { setSelectedForeground(item->foreground()); setSelectedBackground(item->background()); + } else { + this->setForegroundColor(palette().color(QPalette::HighlightedText)); + this->setBackgroundColor(palette().color(QPalette::Highlight)); } item = pColorManager->getItem(schemeName,COLOR_SCHEME_ACTIVE_BREAKPOINT); if (item) { @@ -3773,6 +3786,23 @@ void Editor::applyColorScheme(const QString& schemeName) this->mBreakpointForegroundColor = item->foreground(); this->mBreakpointBackgroundColor = item->background(); } + item = pColorManager->getItem(schemeName,COLOR_SCHEME_TEXT); + if (item) { + this->setForegroundColor(item->foreground()); + this->setBackgroundColor(item->background()); + } else { + this->setForegroundColor(palette().color(QPalette::Text)); + this->setBackgroundColor(palette().color(QPalette::Base)); + } + item = pColorManager->getItem(schemeName,COLOR_SCHEME_CURRENT_HIGHLIGHTED_WORD); + if (item) { + mCurrentHighlighWordForeground = item->foreground(); + mCurrentHighlighWordBackground = item->background(); + } else { + mCurrentHighlighWordForeground = selectedForeground(); + mCurrentHighlighWordBackground = selectedBackground(); + } + this->invalidate(); } diff --git a/RedPandaIDE/editor.h b/RedPandaIDE/editor.h index e02583f3..14de640c 100644 --- a/RedPandaIDE/editor.h +++ b/RedPandaIDE/editor.h @@ -243,6 +243,8 @@ private: QColor mActiveBreakpointBackgroundColor; QColor mBreakpointForegroundColor; QColor mBreakpointBackgroundColor; + QColor mCurrentHighlighWordForeground; + QColor mCurrentHighlighWordBackground; int mSyntaxErrorLine; int mLineCount; int mGutterClickedLine; @@ -257,8 +259,8 @@ private: QString mCurrentWord; QString mCurrentDebugTipWord; TipType mCurrentTipType; - QString mOldSelectionWord; - QString mSelectionWord; + QString mOldHighlightedWord; + QString mCurrentHighlightedWord; bool mSaving; diff --git a/RedPandaIDE/qsynedit/MiscClasses.cpp b/RedPandaIDE/qsynedit/MiscClasses.cpp index c9a60fbd..823edcd7 100644 --- a/RedPandaIDE/qsynedit/MiscClasses.cpp +++ b/RedPandaIDE/qsynedit/MiscClasses.cpp @@ -56,6 +56,16 @@ void SynGutter::setChanged() emit changed(); } +const QColor &SynGutter::activeLineTextColor() const +{ + return mActiveLineTextColor; +} + +void SynGutter::setActiveLineTextColor(const QColor &newActiveLineTextColor) +{ + mActiveLineTextColor = newActiveLineTextColor; +} + QColor SynGutter::textColor() const { return mTextColor; diff --git a/RedPandaIDE/qsynedit/MiscClasses.h b/RedPandaIDE/qsynedit/MiscClasses.h index 4debbc9a..002d1483 100644 --- a/RedPandaIDE/qsynedit/MiscClasses.h +++ b/RedPandaIDE/qsynedit/MiscClasses.h @@ -76,6 +76,9 @@ public: QColor textColor() const; void setTextColor(const QColor &value); + const QColor &activeLineTextColor() const; + void setActiveLineTextColor(const QColor &newActiveLineTextColor); + signals: void changed(); private: @@ -84,6 +87,7 @@ private: bool mAutoSize; QColor mBorderColor; QColor mTextColor; + QColor mActiveLineTextColor; QColor mColor; int mDigitCount; QFont mFont; diff --git a/RedPandaIDE/qsynedit/SynEdit.cpp b/RedPandaIDE/qsynedit/SynEdit.cpp index 35eb2fb0..8c974771 100644 --- a/RedPandaIDE/qsynedit/SynEdit.cpp +++ b/RedPandaIDE/qsynedit/SynEdit.cpp @@ -1077,7 +1077,7 @@ void SynEdit::processGutterClick(QMouseEvent *event) rect.setLeft(mGutterWidth - mGutter.rightOffset()); rect.setRight(rect.left() + mGutter.rightOffset() - 4); rect.setTop((RowColumn.Row - mTopLine) * mTextHeight); - rect.setBottom(rect.top() + mTextHeight); + rect.setBottom(rect.top() + mTextHeight - 1); if (rect.contains(QPoint(X, Y))) { if (FoldRange->collapsed) uncollapse(FoldRange); @@ -3081,6 +3081,8 @@ int SynEdit::scanFrom(int Index, int canStopIndex) void SynEdit::rescanRange(int line) { + if (!mHighlighter) + return; line--; line = std::max(0,line); if (line >= mLines->count()) @@ -3507,7 +3509,7 @@ void SynEdit::paintCaret(QPainter &painter, const QRect rcClip) ct =mOverwriteCaret; } if (mCaretUseTextColor) { - painter.setPen(palette().color(QPalette::Text)); + painter.setPen(mForegroundColor); } else { painter.setPen(mCaretColor); } @@ -3592,6 +3594,26 @@ void SynEdit::onScrolled(int) invalidate(); } +const QColor &SynEdit::backgroundColor() const +{ + return mBackgroundColor; +} + +void SynEdit::setBackgroundColor(const QColor &newBackgroundColor) +{ + mBackgroundColor = newBackgroundColor; +} + +const QColor &SynEdit::foregroundColor() const +{ + return mForegroundColor; +} + +void SynEdit::setForegroundColor(const QColor &newForegroundColor) +{ + mForegroundColor = newForegroundColor; +} + int SynEdit::mouseWheelScrollSpeed() const { return mMouseWheelScrollSpeed; @@ -4698,6 +4720,8 @@ int SynEdit::searchReplace(const QString &sSearch, const QString &sReplace, SynS doOnPaintTransient(SynTransientType::ttAfter); }); int i; + // If it's a search only we can leave the procedure now. + SynSearchAction searchAction = SynSearchAction::Exit; while ((ptCurrent.Line >= ptStart.Line) && (ptCurrent.Line <= ptEnd.Line)) { int nInLine = searchEngine->findAll(mLines->getString(ptCurrent.Line - 1)); int iResultOffset = 0; @@ -4748,8 +4772,7 @@ int SynEdit::searchReplace(const QString &sSearch, const QString &sReplace, SynS internalSetCaretXY(blockBegin()); else internalSetCaretXY(ptCurrent); - // If it's a search only we can leave the procedure now. - SynSearchAction searchAction = SynSearchAction::Exit; + QString replaceText = searchEngine->replace(selText(), sReplace); if (matchedCallback && !dobatchReplace) { searchAction = matchedCallback(sSearch,replaceText,ptCurrent.Line, diff --git a/RedPandaIDE/qsynedit/SynEdit.h b/RedPandaIDE/qsynedit/SynEdit.h index f4301d05..51541591 100644 --- a/RedPandaIDE/qsynedit/SynEdit.h +++ b/RedPandaIDE/qsynedit/SynEdit.h @@ -376,6 +376,12 @@ public: int mouseWheelScrollSpeed() const; void setMouseWheelScrollSpeed(int newMouseWheelScrollSpeed); + const QColor &foregroundColor() const; + void setForegroundColor(const QColor &newForegroundColor); + + const QColor &backgroundColor() const; + void setBackgroundColor(const QColor &newBackgroundColor); + signals: void linesDeleted(int FirstLine, int Count); void linesInserted(int FirstLine, int Count); @@ -610,6 +616,8 @@ private: PSynHighlighter mHighlighter; QColor mSelectedForeground; QColor mSelectedBackground; + QColor mForegroundColor; + QColor mBackgroundColor; QColor mCaretColor; PSynHighlighterAttribute mRainbowAttr0; PSynHighlighterAttribute mRainbowAttr1; diff --git a/RedPandaIDE/qsynedit/TextPainter.cpp b/RedPandaIDE/qsynedit/TextPainter.cpp index 774a952e..fd573b84 100644 --- a/RedPandaIDE/qsynedit/TextPainter.cpp +++ b/RedPandaIDE/qsynedit/TextPainter.cpp @@ -16,6 +16,7 @@ SynEditTextPainter::SynEditTextPainter(SynEdit *edit, QPainter *painter, int Fir void SynEditTextPainter::paintTextLines(const QRect& clip) { + painter->fillRect(clip, edit->mBackgroundColor); AClip = clip; vFirstLine = edit->rowToLine(aFirstRow); vLastLine = edit->rowToLine(aLastRow); @@ -81,14 +82,6 @@ void SynEditTextPainter::paintGutter(const QRect& clip) AClip = clip; - //todo: Does the following comment still apply? - // Changed to use fTextDrawer.BeginDrawing and fTextDrawer.EndDrawing only - // when absolutely necessary. Note: Never change brush / pen / font of the - // canvas inside of this block (only through methods of fTextDrawer)! - // If we have to draw the line numbers then we don't want to erase - // 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->fillRect(AClip,edit->mGutter.color()); rcLine=AClip; @@ -108,16 +101,22 @@ void SynEditTextPainter::paintGutter(const QRect& clip) newFont.setUnderline(false); painter->setFont(newFont); } + QColor textColor; if (edit->mGutter.textColor().isValid()) { - painter->setPen(edit->mGutter.textColor()); + textColor = edit->mGutter.textColor(); } else { - painter->setPen(edit->palette().color(QPalette::Text)); + textColor = edit->mForegroundColor; } // draw each line if it is not hidden by a fold for (int cRow = aFirstRow; cRow <= aLastRow; cRow++) { vLine = edit->rowToLine(cRow); if ((vLine > edit->mLines->count()) && (edit->mLines->count() > 0 )) break; + if (edit->mCaretY==vLine && edit->mGutter.activeLineTextColor().isValid()) { + painter->setPen(edit->mGutter.activeLineTextColor()); + } else { + painter->setPen(textColor); + } vLineTop = (cRow - edit->mTopLine) * edit->mTextHeight; // next line rect @@ -270,14 +269,8 @@ QColor SynEditTextPainter::colEditorBG() if (edit->mActiveLineColor.isValid() && bCurrentLine) { return edit->mActiveLineColor; } else { - if (edit->mHighlighter) { - PSynHighlighterAttribute attr = edit->mHighlighter->whitespaceAttribute(); - if (attr && attr->background().isValid()) { - return attr->background(); - } - } + return edit->mBackgroundColor; } - return edit->palette().color(QPalette::Base); } void SynEditTextPainter::ComputeSelectionInfo() @@ -351,13 +344,19 @@ void SynEditTextPainter::ComputeSelectionInfo() void SynEditTextPainter::setDrawingColors(bool Selected) { if (Selected) { - painter->setPen(colSelFG); - painter->setBrush(colSelBG); - painter->setBackground(colSelBG); + if (colSelFG.isValid()) + painter->setPen(colSelFG); + else + painter->setPen(colFG); + if (colSelBG.isValid()) + painter->setBrush(colSelBG); + else + painter->setBrush(colBG); + painter->setBackground(edit->mBackgroundColor); } else { painter->setPen(colFG); painter->setBrush(colBG); - painter->setBackground(colBG); + painter->setBackground(edit->mBackgroundColor); } } @@ -376,7 +375,9 @@ void SynEditTextPainter::PaintToken(const QString &Token, int TokenCols, int Col nX = ColumnToXValue(First); First -= ColumnsBefore; Last -= ColumnsBefore; - painter->fillRect(rcToken,painter->brush()); + QRect rcTokenBack = rcToken; + rcTokenBack.setWidth(rcTokenBack.width()-1); + painter->fillRect(rcTokenBack,painter->brush()); if (First > TokenCols) { } else { int tokenColLen=0; @@ -588,8 +589,6 @@ void SynEditTextPainter::AddHighlightToken(const QString &Token, int ColumnsBefo SynFontStyles Style; bool bSpacesTest,bIsSpaces; -// qDebug()<<"Add highlight token"<foreground(); Background = p_Attri->background(); @@ -604,7 +603,7 @@ void SynEditTextPainter::AddHighlightToken(const QString &Token, int ColumnsBefo Background = colEditorBG(); } if (!Foreground.isValid()) { - Foreground = edit->palette().color(QPalette::Text); + Foreground = edit->mForegroundColor; } edit->onPreparePaintHighlightToken(cLine,edit->mHighlighter->getTokenPos()+1, @@ -618,7 +617,7 @@ void SynEditTextPainter::AddHighlightToken(const QString &Token, int ColumnsBefo if (TokenAccu.Style == Style || ( (Style & SynFontStyle::fsUnderline) == (TokenAccu.Style & fsUnderline) && TokenIsSpaces(bSpacesTest,Token,bIsSpaces)) ) { // either special colors or same colors - if ((bSpecialLine && !(edit->mOptions.testFlag(SynEditorOption::eoSpecialLineDefaultFg))) || bLineSelected || + if ((bSpecialLine && !(edit->mOptions.testFlag(SynEditorOption::eoSpecialLineDefaultFg))) || // background color must be the same and ((TokenAccu.BG == Background) && // foreground color must be the same or token is only spaces @@ -819,14 +818,8 @@ void SynEditTextPainter::PaintLines() colBG = colEditorBG(); bSpecialLine = edit->onGetSpecialLineColors(vLine, colFG, colBG); - if (bSpecialLine) { - // The selection colors are just swapped, like seen in Delphi. - colSelFG = colBG; - colSelBG = colFG; - } else { - colSelFG = edit->mSelectedForeground; - colSelBG = edit->mSelectedBackground; - } + colSelFG = edit->mSelectedForeground; + colSelBG = edit->mSelectedBackground; edit->onGetEditingAreas(vLine, areaList); // Removed word wrap support vFirstChar = FirstCol; @@ -867,8 +860,10 @@ void SynEditTextPainter::PaintLines() } //endif bAnySelection // Update the rcLine rect to this line. - rcLine.setTop(rcLine.bottom()); - rcLine.setBottom(rcLine.bottom()+edit->mTextHeight); +// rcLine.setTop(rcLine.bottom()); +// rcLine.setBottom(rcLine.bottom()+edit->mTextHeight); + rcLine.setTop((cRow - edit->mTopLine) * edit->mTextHeight); + rcLine.setHeight(edit->mTextHeight); bLineSelected = (!bComplexLine) && (nLineSelStart > 0); rcToken = rcLine; diff --git a/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp b/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp index 31811621..cde34118 100644 --- a/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp +++ b/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp @@ -189,29 +189,33 @@ void EditorColorSchemeWidget::onItemSelectionChanged() ui->colorForeground->setEnabled(define->hasForeground()); ui->grpFontStyles->setEnabled(define->hasFontStyle()); PColorSchemeItem item = pColorManager->getItem(ui->cbScheme->currentText(), name); - if (item) { - if (define->hasBackground()) { - setColorProp(ui->colorBackground, ui->cbBackground,item->background()); - } else { - setColorProp(ui->colorBackground, ui->cbBackground,QColor()); - } - if (define->hasForeground()) { - setColorProp(ui->colorForeground, ui->cbForeground,item->foreground()); - } else { - setColorProp(ui->colorForeground, ui->cbForeground,QColor()); - } - if (define->hasFontStyle()) { - ui->cbBold->setChecked(item->bold()); - ui->cbItalic->setChecked(item->italic()); - ui->cbUnderlined->setChecked(item->underlined()); - ui->cbStrikeout->setChecked(item->strikeout()); - } else { - ui->cbBold->setChecked(false); - ui->cbItalic->setChecked(false); - ui->cbUnderlined->setChecked(false); - ui->cbStrikeout->setChecked(false); + if (!item) { + PColorScheme scheme = pColorManager->get(ui->cbScheme->currentText()); + if (scheme) { + scheme->addItem(name); } } + if (define->hasBackground() && item) { + setColorProp(ui->colorBackground, ui->cbBackground,item->background()); + } else { + setColorProp(ui->colorBackground, ui->cbBackground,QColor()); + } + if (define->hasForeground() && item) { + setColorProp(ui->colorForeground, ui->cbForeground,item->foreground()); + } else { + setColorProp(ui->colorForeground, ui->cbForeground,QColor()); + } + if (define->hasFontStyle() && item) { + ui->cbBold->setChecked(item->bold()); + ui->cbItalic->setChecked(item->italic()); + ui->cbUnderlined->setChecked(item->underlined()); + ui->cbStrikeout->setChecked(item->strikeout()); + } else { + ui->cbBold->setChecked(false); + ui->cbItalic->setChecked(false); + ui->cbUnderlined->setChecked(false); + ui->cbStrikeout->setChecked(false); + } } } diff --git a/RedPandaIDE/widgets/coloredit.cpp b/RedPandaIDE/widgets/coloredit.cpp index 7def1e1e..24c8ece6 100644 --- a/RedPandaIDE/widgets/coloredit.cpp +++ b/RedPandaIDE/widgets/coloredit.cpp @@ -73,7 +73,7 @@ void ColorEdit::paintEvent(QPaintEvent *) painter.setBrush(palette().color(QPalette::Disabled,QPalette::Base)); } painter.drawRect(rect); - painter.drawText(rect,Qt::AlignCenter, mColor.name()); + painter.drawText(rect,Qt::AlignCenter, mColor.name(QColor::HexArgb)); } else { //painter.fillRect(rect,palette().color(QPalette::Base)); if (isEnabled()) { @@ -92,7 +92,8 @@ void ColorEdit::paintEvent(QPaintEvent *) void ColorEdit::mouseReleaseEvent(QMouseEvent *) { - QColor c = QColorDialog::getColor(); + QColor c = QColorDialog::getColor(mColor,nullptr,tr("Color"), + QColorDialog::ShowAlphaChannel | QColorDialog::DontUseNativeDialog); if (c.isValid()) { setColor(c); }