- enhancement: adjust the appearance of problem case's input/output/expected control

This commit is contained in:
Roy Qu 2022-06-14 09:09:35 +08:00
parent fb18a1f1a3
commit cfdbdca812
7 changed files with 115 additions and 21 deletions

View File

@ -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.

View File

@ -10,7 +10,7 @@ isEmpty(APP_NAME) {
}
isEmpty(APP_VERSION) {
APP_VERSION=1.1.0
APP_VERSION=1.1.1
}
macos: {

View File

@ -107,7 +107,7 @@
"Gutter": {
"background": "#fff0f0f0",
"bold": false,
"foreground": "#ff000000",
"foreground": "#ff004200",
"italic": false,
"strikeout": false,
"underlined": false

View File

@ -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));
}
}

View File

@ -18,15 +18,15 @@
#include <QPainter>
#include <QTextBlock>
#include <QDebug>
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<QTextEdit::ExtraSelection> extraSelections;
lineNumberArea->update();
// QList<QTextEdit::ExtraSelection> 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);
}

View File

@ -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

View File

@ -23,7 +23,7 @@ SUBDIRS += \
APP_NAME = RedPandaCPP
APP_VERSION = 1.1.0
APP_VERSION = 1.1.1
linux: {
isEmpty(PREFIX) {