From cfdbdca812b53510f991fafe4f49ffd2a1004da1 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Tue, 14 Jun 2022 09:09:35 +0800 Subject: [PATCH] - enhancement: adjust the appearance of problem case's input/output/expected control --- NEWS.md | 3 + RedPandaIDE/RedPandaIDE.pro | 2 +- .../colorschemes/Intellij_Classic.scheme | 2 +- RedPandaIDE/mainwindow.cpp | 34 ++++++++ RedPandaIDE/widgets/linenumbertexteditor.cpp | 78 ++++++++++++++----- RedPandaIDE/widgets/linenumbertexteditor.h | 15 ++++ Red_Panda_CPP.pro | 2 +- 7 files changed, 115 insertions(+), 21 deletions(-) diff --git a/NEWS.md b/NEWS.md index 2d23c21f..4f17a27d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,6 @@ +Red Panda C++ Version 1.1.1 + - enhancement: adjust the appearance of problem case's input/output/expected control + Red Panda C++ Version 1.1.0 - enhancement: when ctrl+mouse cursor hovered an identifier or header name, use underline to highlight it - enhancement: mark editor as modified, if the editing file is changed by other applications. diff --git a/RedPandaIDE/RedPandaIDE.pro b/RedPandaIDE/RedPandaIDE.pro index 1132ff3a..291036f7 100644 --- a/RedPandaIDE/RedPandaIDE.pro +++ b/RedPandaIDE/RedPandaIDE.pro @@ -10,7 +10,7 @@ isEmpty(APP_NAME) { } isEmpty(APP_VERSION) { - APP_VERSION=1.1.0 + APP_VERSION=1.1.1 } macos: { diff --git a/RedPandaIDE/colorschemes/Intellij_Classic.scheme b/RedPandaIDE/colorschemes/Intellij_Classic.scheme index d96065dc..3b2c6c8e 100644 --- a/RedPandaIDE/colorschemes/Intellij_Classic.scheme +++ b/RedPandaIDE/colorschemes/Intellij_Classic.scheme @@ -107,7 +107,7 @@ "Gutter": { "background": "#fff0f0f0", "bold": false, - "foreground": "#ff000000", + "foreground": "#ff004200", "italic": false, "strikeout": false, "underlined": false diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 582c4a74..28b97432 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -606,11 +606,45 @@ void MainWindow::updateEditorColorSchemes() mCompletionPopup->setPalette(pal); mHeaderCompletionPopup->setPalette(pal); ui->classBrowser->setPalette(pal); + ui->txtProblemCaseInput->setPalette(pal); + ui->txtProblemCaseExpected->setPalette(pal); + ui->txtProblemCaseOutput->setPalette(pal); } else { QPalette pal = palette(); mCompletionPopup->setPalette(pal); mHeaderCompletionPopup->setPalette(pal); ui->classBrowser->setPalette(pal); + ui->txtProblemCaseInput->setPalette(pal); + ui->txtProblemCaseExpected->setPalette(pal); + ui->txtProblemCaseOutput->setPalette(pal); + } + item = pColorManager->getItem(schemeName, COLOR_SCHEME_GUTTER); + if (item) { + ui->txtProblemCaseInput->setLineNumberAreaForeground(item->foreground()); + ui->txtProblemCaseInput->setLineNumberAreaBackground(item->background()); + ui->txtProblemCaseOutput->setLineNumberAreaForeground(item->foreground()); + ui->txtProblemCaseOutput->setLineNumberAreaBackground(item->background()); + ui->txtProblemCaseExpected->setLineNumberAreaForeground(item->foreground()); + ui->txtProblemCaseExpected->setLineNumberAreaBackground(item->background()); + } else { + QPalette pal = palette(); + ui->txtProblemCaseInput->setLineNumberAreaForeground(pal.color(QPalette::ButtonText)); + ui->txtProblemCaseInput->setLineNumberAreaBackground(pal.color(QPalette::Button)); + ui->txtProblemCaseOutput->setLineNumberAreaForeground(pal.color(QPalette::ButtonText)); + ui->txtProblemCaseOutput->setLineNumberAreaBackground(pal.color(QPalette::Button)); + ui->txtProblemCaseExpected->setLineNumberAreaForeground(pal.color(QPalette::ButtonText)); + ui->txtProblemCaseExpected->setLineNumberAreaBackground(pal.color(QPalette::Button)); + } + item = pColorManager->getItem(schemeName, COLOR_SCHEME_GUTTER_ACTIVE_LINE); + if (item) { + ui->txtProblemCaseInput->setLineNumberAreaCurrentLine(item->foreground()); + ui->txtProblemCaseOutput->setLineNumberAreaCurrentLine(item->foreground()); + ui->txtProblemCaseExpected->setLineNumberAreaCurrentLine(item->foreground()); + } else { + QPalette pal = palette(); + ui->txtProblemCaseInput->setLineNumberAreaCurrentLine(pal.color(QPalette::ButtonText)); + ui->txtProblemCaseOutput->setLineNumberAreaCurrentLine(pal.color(QPalette::ButtonText)); + ui->txtProblemCaseExpected->setLineNumberAreaCurrentLine(pal.color(QPalette::ButtonText)); } } diff --git a/RedPandaIDE/widgets/linenumbertexteditor.cpp b/RedPandaIDE/widgets/linenumbertexteditor.cpp index b0ae20f0..b47c21e9 100644 --- a/RedPandaIDE/widgets/linenumbertexteditor.cpp +++ b/RedPandaIDE/widgets/linenumbertexteditor.cpp @@ -18,15 +18,15 @@ #include #include +#include -LineNumberTextEditor::LineNumberTextEditor(QWidget *parent) +LineNumberTextEditor::LineNumberTextEditor(QWidget *parent):QPlainTextEdit(parent) { lineNumberArea = new LineNumberArea(this); connect(this, &LineNumberTextEditor::blockCountChanged, this, &LineNumberTextEditor::updateLineNumberAreaWidth); connect(this, &LineNumberTextEditor::updateRequest, this, &LineNumberTextEditor::updateLineNumberArea); - //connect(this, &LineNumberTextEditor::cursorPositionChanged, this, &LineNumberTextEditor::highlightCurrentLine); - + connect(this, &LineNumberTextEditor::cursorPositionChanged, this, &LineNumberTextEditor::highlightCurrentLine); updateLineNumberAreaWidth(0); //highlightCurrentLine(); } @@ -40,7 +40,7 @@ int LineNumberTextEditor::lineNumberAreaWidth() ++digits; } - int space = 3 + fontMetrics().horizontalAdvance(QLatin1Char('9')) * digits; + int space = 10 + fontMetrics().horizontalAdvance(QLatin1Char('9')) * digits; return space; } @@ -61,6 +61,39 @@ void LineNumberTextEditor::updateLineNumberArea(const QRect &rect, int dy) updateLineNumberAreaWidth(0); } +const QColor &LineNumberTextEditor::lineNumberAreaCurrentLine() const +{ + return mLineNumberAreaCurrentLine; +} + +void LineNumberTextEditor::setLineNumberAreaCurrentLine(const QColor &newLineNumberAreaCurrentLine) +{ + if (mLineNumberAreaCurrentLine == newLineNumberAreaCurrentLine) + return; + mLineNumberAreaCurrentLine = newLineNumberAreaCurrentLine; + emit lineNumberAreaCurrentLineChanged(); +} + +const QColor &LineNumberTextEditor::lineNumberAreaBackground() const +{ + return mLineNumberAreaBackground; +} + +void LineNumberTextEditor::setLineNumberAreaBackground(const QColor &newLineNumberAreaBackground) +{ + mLineNumberAreaBackground = newLineNumberAreaBackground; +} + +const QColor &LineNumberTextEditor::lineNumberAreaForeground() const +{ + return mLineNumberAreaForeground; +} + +void LineNumberTextEditor::setLineNumberAreaForeground(const QColor &newLineNumberAreaForeground) +{ + mLineNumberAreaForeground = newLineNumberAreaForeground; +} + void LineNumberTextEditor::resizeEvent(QResizeEvent *e) { QPlainTextEdit::resizeEvent(e); @@ -71,28 +104,32 @@ void LineNumberTextEditor::resizeEvent(QResizeEvent *e) void LineNumberTextEditor::highlightCurrentLine() { - QList extraSelections; + lineNumberArea->update(); +// QList extraSelections; - if (!isReadOnly()) { - QTextEdit::ExtraSelection selection; +// if (!isReadOnly()) { +// QTextEdit::ExtraSelection selection; - QColor lineColor = QColor(Qt::yellow).lighter(160); +// QColor lineColor = QColor(Qt::yellow).lighter(160); - selection.format.setBackground(lineColor); - selection.format.setProperty(QTextFormat::FullWidthSelection, true); - selection.cursor = textCursor(); - selection.cursor.clearSelection(); - extraSelections.append(selection); - } +// selection.format.setBackground(lineColor); +// selection.format.setProperty(QTextFormat::FullWidthSelection, true); +// selection.cursor = textCursor(); +// selection.cursor.clearSelection(); +// extraSelections.append(selection); +// } - setExtraSelections(extraSelections); +// setExtraSelections(extraSelections); } void LineNumberTextEditor::lineNumberAreaPaintEvent(QPaintEvent *event) { QPainter painter(lineNumberArea); painter.setFont(font()); - painter.fillRect(event->rect(), palette().color(QPalette::Button)); + if (isEnabled()) + painter.fillRect(event->rect(), mLineNumberAreaBackground); + else + painter.fillRect(event->rect(), palette().color(QPalette::Disabled, QPalette::Button)); QTextBlock block = firstVisibleBlock(); int blockNumber = block.blockNumber(); int top = qRound(blockBoundingGeometry(block).translated(contentOffset()).top()); @@ -100,8 +137,13 @@ void LineNumberTextEditor::lineNumberAreaPaintEvent(QPaintEvent *event) while (block.isValid() && top <= event->rect().bottom()) { if (block.isVisible() && bottom >= event->rect().top()) { QString number = QString::number(blockNumber + 1); - painter.setPen(palette().color(QPalette::ButtonText)); - painter.drawText(0, top, lineNumberArea->width(), fontMetrics().height(), + if (!isEnabled()) + painter.setPen(palette().color(QPalette::Disabled,QPalette::ButtonText)); + else if (textCursor().blockNumber()==blockNumber) + painter.setPen(mLineNumberAreaCurrentLine); + else + painter.setPen(mLineNumberAreaForeground); + painter.drawText(5, top, lineNumberArea->width()-10, fontMetrics().height(), Qt::AlignRight, number); } diff --git a/RedPandaIDE/widgets/linenumbertexteditor.h b/RedPandaIDE/widgets/linenumbertexteditor.h index ce949292..461136d2 100644 --- a/RedPandaIDE/widgets/linenumbertexteditor.h +++ b/RedPandaIDE/widgets/linenumbertexteditor.h @@ -28,6 +28,18 @@ public: void lineNumberAreaPaintEvent(QPaintEvent *event); int lineNumberAreaWidth(); + const QColor &lineNumberAreaForeground() const; + void setLineNumberAreaForeground(const QColor &newLineNumberAreaForeground); + + const QColor &lineNumberAreaBackground() const; + void setLineNumberAreaBackground(const QColor &newLineNumberAreaBackground); + + const QColor &lineNumberAreaCurrentLine() const; + void setLineNumberAreaCurrentLine(const QColor &newLineNumberAreaCurrentLine); + +signals: + void lineNumberAreaCurrentLineChanged(); + protected: void resizeEvent(QResizeEvent *event) override; @@ -38,6 +50,9 @@ private slots: private: QWidget *lineNumberArea; + QColor mLineNumberAreaForeground; + QColor mLineNumberAreaBackground; + QColor mLineNumberAreaCurrentLine; }; class LineNumberArea : public QWidget diff --git a/Red_Panda_CPP.pro b/Red_Panda_CPP.pro index a12b5844..80e52d2e 100644 --- a/Red_Panda_CPP.pro +++ b/Red_Panda_CPP.pro @@ -23,7 +23,7 @@ SUBDIRS += \ APP_NAME = RedPandaCPP -APP_VERSION = 1.1.0 +APP_VERSION = 1.1.1 linux: { isEmpty(PREFIX) {