From 77356215aa10e0522ad33562ace27b3d21404f11 Mon Sep 17 00:00:00 2001 From: "royqh1979@gmail.com" Date: Sun, 19 Sep 2021 17:59:03 +0800 Subject: [PATCH] - enhancement: paint color editor use system palette's disabled group color - fix: add watch not work when there's no editor openned; - enhancement: rainbow parenthesis - enhancement: run executable with parameters --- NEWS.md | 5 ++ RedPandaIDE/compiler/executablerunner.cpp | 2 +- RedPandaIDE/editor.cpp | 24 +++++++ RedPandaIDE/mainwindow.cpp | 18 ++++-- RedPandaIDE/mainwindow.ui | 4 ++ RedPandaIDE/qsynedit/SynEdit.cpp | 28 ++++++++ RedPandaIDE/qsynedit/SynEdit.h | 18 +++++- RedPandaIDE/qsynedit/TextPainter.cpp | 11 ++-- RedPandaIDE/settings.cpp | 61 ++++++++++++++++++ RedPandaIDE/settings.h | 17 +++++ .../editorcolorschemewidget.cpp | 2 + .../settingsdialog/editorcolorschemewidget.ui | 14 ++++ .../settingsdialog/executorgeneralwidget.cpp | 23 +++++++ .../settingsdialog/executorgeneralwidget.h | 2 + .../settingsdialog/executorgeneralwidget.ui | 64 +++++++++++++++++-- RedPandaIDE/widgets/coloredit.cpp | 24 +++++-- 16 files changed, 294 insertions(+), 23 deletions(-) diff --git a/NEWS.md b/NEWS.md index e69de29b..ca0ed84f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -0,0 +1,5 @@ +Version 0.2 + - enhancement: paint color editor use system palette's disabled group color + - fix: add watch not work when there's no editor openned; + - enhancement: rainbow parenthesis + - enhancement: run executable with parameters \ No newline at end of file diff --git a/RedPandaIDE/compiler/executablerunner.cpp b/RedPandaIDE/compiler/executablerunner.cpp index f20c70e8..94363b2e 100644 --- a/RedPandaIDE/compiler/executablerunner.cpp +++ b/RedPandaIDE/compiler/executablerunner.cpp @@ -78,7 +78,7 @@ void ExecutableRunner::run() break; } if (errorOccurred) { - qDebug()<<"process error:"<getItem(schemeName,schemeItemName); + if (item) { + PSynHighlighterAttribute attr = std::make_shared(attrName); + attr->setForeground(item->foreground()); + attr->setBackground(item->background()); + return attr; + } + return PSynHighlighterAttribute(); +} void Editor::applyColorScheme(const QString& schemeName) { + SynEditorOptions options = getOptions(); + options.setFlag(SynEditorOption::eoShowRainbowColor, pSettings->editor().rainbowParenthesis()); + setOptions(options); highlighterManager.applyColorScheme(highlighter(),schemeName); + if (pSettings->editor().rainbowParenthesis()) { + PSynHighlighterAttribute attr0 =createRainbowAttribute(COLOR_SCHEME_BRACE_1, + schemeName,COLOR_SCHEME_BRACE_1); + PSynHighlighterAttribute attr1 =createRainbowAttribute(COLOR_SCHEME_BRACE_2, + schemeName,COLOR_SCHEME_BRACE_2); + PSynHighlighterAttribute attr2 =createRainbowAttribute(COLOR_SCHEME_BRACE_3, + schemeName,COLOR_SCHEME_BRACE_3); + PSynHighlighterAttribute attr3 =createRainbowAttribute(COLOR_SCHEME_BRACE_4, + schemeName,COLOR_SCHEME_BRACE_4); + setRainbowAttrs(attr0,attr1,attr2,attr3); + } PColorSchemeItem item = pColorManager->getItem(schemeName,COLOR_SCHEME_ACTIVE_LINE); if (item) { setActiveLineColor(item->background()); diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index b71211e9..6927347c 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -931,7 +931,11 @@ void MainWindow::runExecutable(const QString &exeName,const QString &filename) showMinimized(); } updateAppTitle(); - mCompilerManager->run(exeName,"",QFileInfo(exeName).absolutePath()); + if (pSettings->executor().useParams()) { + mCompilerManager->run(exeName,pSettings->executor().params(),QFileInfo(exeName).absolutePath()); + } else { + mCompilerManager->run(exeName,"",QFileInfo(exeName).absolutePath()); + } } void MainWindow::runExecutable() @@ -2649,12 +2653,12 @@ void MainWindow::on_actionAdd_Watch_triggered() { QString s = ""; Editor *e = mEditorList->getEditor(); - if (e==nullptr) - return; - if (e->selAvail()) { - s = e->selText(); - } else { - s = e->WordAtCursor(); + if (e!=nullptr) { + if (e->selAvail()) { + s = e->selText(); + } else { + s = e->WordAtCursor(); + } } bool isOk; s=QInputDialog::getText(this, diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui index de40a9eb..48ae4bcc 100644 --- a/RedPandaIDE/mainwindow.ui +++ b/RedPandaIDE/mainwindow.ui @@ -1092,6 +1092,10 @@ + + + :/icons/images/newlook24/061-rebuild.png:/icons/images/newlook24/061-rebuild.png + Options diff --git a/RedPandaIDE/qsynedit/SynEdit.cpp b/RedPandaIDE/qsynedit/SynEdit.cpp index d38bac55..ed7de843 100644 --- a/RedPandaIDE/qsynedit/SynEdit.cpp +++ b/RedPandaIDE/qsynedit/SynEdit.cpp @@ -3292,6 +3292,26 @@ void SynEdit::onScrolled(int) invalidate(); } +const PSynHighlighterAttribute &SynEdit::rainbowAttr3() const +{ + return mRainbowAttr3; +} + +const PSynHighlighterAttribute &SynEdit::rainbowAttr2() const +{ + return mRainbowAttr2; +} + +const PSynHighlighterAttribute &SynEdit::rainbowAttr1() const +{ + return mRainbowAttr1; +} + +const PSynHighlighterAttribute &SynEdit::rainbowAttr0() const +{ + return mRainbowAttr0; +} + bool SynEdit::caretUseTextColor() const { return mCaretUseTextColor; @@ -5238,6 +5258,14 @@ bool SynEdit::isIdentChar(const QChar &ch) } } +void SynEdit::setRainbowAttrs(const PSynHighlighterAttribute &attr0, const PSynHighlighterAttribute &attr1, const PSynHighlighterAttribute &attr2, const PSynHighlighterAttribute &attr3) +{ + mRainbowAttr0 = attr0; + mRainbowAttr1 = attr1; + mRainbowAttr2 = attr2; + mRainbowAttr3 = attr3; +} + void SynEdit::paintEvent(QPaintEvent *event) { if (mPainterLock>0) diff --git a/RedPandaIDE/qsynedit/SynEdit.h b/RedPandaIDE/qsynedit/SynEdit.h index 347c737b..583ccbaf 100644 --- a/RedPandaIDE/qsynedit/SynEdit.h +++ b/RedPandaIDE/qsynedit/SynEdit.h @@ -256,7 +256,10 @@ public: bool PointToLine(const QPoint& point, int& line); bool isIdentChar(const QChar& ch); - + void setRainbowAttrs(const PSynHighlighterAttribute &attr0, + const PSynHighlighterAttribute &attr1, + const PSynHighlighterAttribute &attr2, + const PSynHighlighterAttribute &attr3); // setter && getters int topLine() const; void setTopLine(int value); @@ -351,6 +354,14 @@ public: bool caretUseTextColor() const; void setCaretUseTextColor(bool newCaretUseTextColor); + const PSynHighlighterAttribute &rainbowAttr0() const; + + const PSynHighlighterAttribute &rainbowAttr1() const; + + const PSynHighlighterAttribute &rainbowAttr2() const; + + const PSynHighlighterAttribute &rainbowAttr3() const; + signals: void linesDeleted(int FirstLine, int Count); void linesInserted(int FirstLine, int Count); @@ -576,6 +587,11 @@ private: QColor mSelectedForeground; QColor mSelectedBackground; QColor mCaretColor; + PSynHighlighterAttribute mRainbowAttr0; + PSynHighlighterAttribute mRainbowAttr1; + PSynHighlighterAttribute mRainbowAttr2; + PSynHighlighterAttribute mRainbowAttr3; + bool mCaretUseTextColor; QColor mActiveLineColor; PSynEditUndoList mUndoList; diff --git a/RedPandaIDE/qsynedit/TextPainter.cpp b/RedPandaIDE/qsynedit/TextPainter.cpp index e23770d9..ad8bb45f 100644 --- a/RedPandaIDE/qsynedit/TextPainter.cpp +++ b/RedPandaIDE/qsynedit/TextPainter.cpp @@ -681,20 +681,23 @@ void SynEditTextPainter::GetBraceColorAttr(int level, PSynHighlighterAttribute & return; if (attr != edit->mHighlighter->symbolAttribute()) return; + PSynHighlighterAttribute oldAttr = attr; switch(level % 4) { case 0: - attr = edit->mHighlighter->keywordAttribute(); + attr = edit->mRainbowAttr0; break; case 1: - attr = edit->mHighlighter->symbolAttribute(); + attr = edit->mRainbowAttr1; break; case 2: - attr = edit->mHighlighter->stringAttribute(); + attr = edit->mRainbowAttr2; break; case 3: - attr = edit->mHighlighter->identifierAttribute(); + attr = edit->mRainbowAttr3; break; } + if (!attr) + attr = oldAttr; } void SynEditTextPainter::PaintLines() diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index f0e79d0e..fd36b7a6 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -460,6 +460,16 @@ void Settings::Editor::setCaretUseTextColor(bool newUseIdentifierColor) mCaretUseTextColor = newUseIdentifierColor; } +bool Settings::Editor::rainbowParenthesis() const +{ + return mRainbowParenthesis; +} + +void Settings::Editor::setRainbowParenthesis(bool newRainbowParenthesis) +{ + mRainbowParenthesis = newRainbowParenthesis; +} + int Settings::Editor::rightEdgeWidth() const { return mRightEdgeWidth; @@ -933,6 +943,7 @@ void Settings::Editor::doSave() //color scheme saveValue("color_scheme", mColorScheme); + saveValue("rainbow_parenthesis",mRainbowParenthesis); //Symbol Completion saveValue("complete_symbols", mCompleteSymbols); @@ -1032,6 +1043,7 @@ void Settings::Editor::doLoad() //color mColorScheme = stringValue("color_scheme", "VS Code"); + mRainbowParenthesis = boolValue("rainbow_parenthesis", true); //Symbol Completion mCompleteSymbols = boolValue("complete_symbols",true); @@ -2521,10 +2533,54 @@ void Settings::Executor::setMinimizeOnRun(bool minimizeOnRun) mMinimizeOnRun = minimizeOnRun; } +bool Settings::Executor::useParams() const +{ + return mUseParams; +} + +void Settings::Executor::setUseParams(bool newUseParams) +{ + mUseParams = newUseParams; +} + +const QString &Settings::Executor::params() const +{ + return mParams; +} + +void Settings::Executor::setParams(const QString &newParams) +{ + mParams = newParams; +} + +bool Settings::Executor::redirectInput() const +{ + return mRedirectInput; +} + +void Settings::Executor::setRedirectInput(bool newRedirectInput) +{ + mRedirectInput = newRedirectInput; +} + +const QString &Settings::Executor::inputFilename() const +{ + return mInputFilename; +} + +void Settings::Executor::setInputFilename(const QString &newInputFilename) +{ + mInputFilename = newInputFilename; +} + void Settings::Executor::doSave() { saveValue("pause_console", mPauseConsole); saveValue("minimize_on_run", mMinimizeOnRun); + saveValue("use_params",mUseParams); + saveValue("params",mParams); + saveValue("redirect_input",mRedirectInput); + saveValue("input_filename",mInputFilename); } bool Settings::Executor::pauseConsole() const @@ -2541,6 +2597,11 @@ void Settings::Executor::doLoad() { mPauseConsole = boolValue("pause_console",true); mMinimizeOnRun = boolValue("minimize_on_run",false); + mUseParams = boolValue("use_params",false); + mParams = stringValue("params", ""); + mRedirectInput = boolValue("redirect_input",false); + mInputFilename = stringValue("input_filename",""); + } diff --git a/RedPandaIDE/settings.h b/RedPandaIDE/settings.h index 7f079072..2b35db67 100644 --- a/RedPandaIDE/settings.h +++ b/RedPandaIDE/settings.h @@ -302,6 +302,9 @@ public: bool caretUseTextColor() const; void setCaretUseTextColor(bool newUseIdentifierColor); + bool rainbowParenthesis() const; + void setRainbowParenthesis(bool newRainbowParenthesis); + private: //General // indents @@ -366,6 +369,7 @@ public: //Color QString mColorScheme; + bool mRainbowParenthesis; //Symbol Completion bool mCompleteSymbols; @@ -705,10 +709,23 @@ public: bool minimizeOnRun() const; void setMinimizeOnRun(bool minimizeOnRun); + bool useParams() const; + void setUseParams(bool newUseParams); + const QString ¶ms() const; + void setParams(const QString &newParams); + bool redirectInput() const; + void setRedirectInput(bool newRedirectInput); + const QString &inputFilename() const; + void setInputFilename(const QString &newInputFilename); + private: // general bool mPauseConsole; bool mMinimizeOnRun; + bool mUseParams; + QString mParams; + bool mRedirectInput; + QString mInputFilename; protected: void doSave() override; diff --git a/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp b/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp index 0b6028fb..55dfee99 100644 --- a/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp +++ b/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp @@ -281,6 +281,7 @@ void EditorColorSchemeWidget::changeSchemeComboFont() void EditorColorSchemeWidget::doLoad() { ui->cbScheme->setCurrentText(pSettings->editor().colorScheme()); + ui->chkRainborParenthesis->setChecked(pSettings->editor().rainbowParenthesis()); } void EditorColorSchemeWidget::doSave() @@ -290,6 +291,7 @@ void EditorColorSchemeWidget::doSave() pColorManager->saveScheme(name); } pSettings->editor().setColorScheme(ui->cbScheme->currentText()); + pSettings->editor().setRainbowParenthesis(ui->chkRainborParenthesis->isChecked()); pSettings->editor().save(); pMainWindow->updateEditorColorSchemes(); } catch (FileError e) { diff --git a/RedPandaIDE/settingsdialog/editorcolorschemewidget.ui b/RedPandaIDE/settingsdialog/editorcolorschemewidget.ui index 5b87fb3f..2de98e3f 100644 --- a/RedPandaIDE/settingsdialog/editorcolorschemewidget.ui +++ b/RedPandaIDE/settingsdialog/editorcolorschemewidget.ui @@ -336,6 +336,20 @@ + + + + Qt::Horizontal + + + + + + + Rainbow parenthesis + + + diff --git a/RedPandaIDE/settingsdialog/executorgeneralwidget.cpp b/RedPandaIDE/settingsdialog/executorgeneralwidget.cpp index 07d671c2..326e58e8 100644 --- a/RedPandaIDE/settingsdialog/executorgeneralwidget.cpp +++ b/RedPandaIDE/settingsdialog/executorgeneralwidget.cpp @@ -2,6 +2,8 @@ #include "ui_executorgeneralwidget.h" #include "../settings.h" +#include + ExecutorGeneralWidget::ExecutorGeneralWidget(const QString& name, const QString& group, QWidget *parent): SettingsWidget(name,group,parent), ui(new Ui::ExecutorGeneralWidget) @@ -18,12 +20,33 @@ void ExecutorGeneralWidget::doLoad() { ui->chkPauseConsole->setChecked(pSettings->executor().pauseConsole()); ui->chkMinimizeOnRun->setChecked(pSettings->executor().minimizeOnRun()); + ui->grpExecuteParameters->setChecked(pSettings->executor().useParams()); + ui->txtExecuteParamaters->setText(pSettings->executor().params()); + ui->grpRedirectInput->setChecked(pSettings->executor().redirectInput()); + ui->txtRedirectInputFile->setText(pSettings->executor().inputFilename()); } void ExecutorGeneralWidget::doSave() { pSettings->executor().setPauseConsole(ui->chkPauseConsole->isChecked()); pSettings->executor().setMinimizeOnRun(ui->chkMinimizeOnRun->isChecked()); + pSettings->executor().setUseParams(ui->grpExecuteParameters->isChecked()); + pSettings->executor().setParams(ui->txtExecuteParamaters->text()); + pSettings->executor().setRedirectInput(ui->grpRedirectInput->isChecked()); + pSettings->executor().setInputFilename(ui->txtRedirectInputFile->text()); pSettings->executor().save(); } + +void ExecutorGeneralWidget::on_btnBrowse_triggered(QAction *arg1) +{ + QString filename = QFileDialog::getOpenFileName( + this, + tr("Choose input file"), + QString(), + tr("All files (*.*)")); + if (!filename.isEmpty() && fileExists(filename)) { + ui->txtRedirectInputFile->setText(filename); + } +} + diff --git a/RedPandaIDE/settingsdialog/executorgeneralwidget.h b/RedPandaIDE/settingsdialog/executorgeneralwidget.h index bedc9cb6..25ccba8e 100644 --- a/RedPandaIDE/settingsdialog/executorgeneralwidget.h +++ b/RedPandaIDE/settingsdialog/executorgeneralwidget.h @@ -23,6 +23,8 @@ private: protected: void doLoad() override; void doSave() override; +private slots: + void on_btnBrowse_triggered(QAction *arg1); }; #endif // EXECUTORGENERALWIDGET_H diff --git a/RedPandaIDE/settingsdialog/executorgeneralwidget.ui b/RedPandaIDE/settingsdialog/executorgeneralwidget.ui index 1db4fb82..c9f8fccc 100644 --- a/RedPandaIDE/settingsdialog/executorgeneralwidget.ui +++ b/RedPandaIDE/settingsdialog/executorgeneralwidget.ui @@ -6,8 +6,8 @@ 0 0 - 400 - 300 + 617 + 449 @@ -47,7 +47,22 @@ - + + + + Parameters to pass to your program + + + true + + + + + + + + + Qt::Vertical @@ -60,8 +75,49 @@ + + + + Redirect input to the following file: + + + true + + + + + + + + + + + + + :/icons/images/newlook24/053-open.png:/icons/images/newlook24/053-open.png + + + + + + + + 75 + true + + + + Note: Debugger doesn't support this feature. + + + + + + - + + + diff --git a/RedPandaIDE/widgets/coloredit.cpp b/RedPandaIDE/widgets/coloredit.cpp index 520aa043..815ef458 100644 --- a/RedPandaIDE/widgets/coloredit.cpp +++ b/RedPandaIDE/widgets/coloredit.cpp @@ -63,14 +63,26 @@ void ColorEdit::paintEvent(QPaintEvent *) { QPainter painter(this); QRect rect = QRect(lineWidth(),lineWidth(),width()-2*lineWidth(),height()-2*lineWidth()); - if (mColor.isValid()) { + if (mColor.isValid() ) { //painter.fillRect(rect,mColor); - painter.setPen(contrast()); - painter.setBrush(mColor); + if (isEnabled()) { + painter.setPen(contrast()); + painter.setBrush(mColor); + } else { + painter.setBrush(palette().color(QPalette::Disabled,QPalette::Text)); + painter.setBrush(palette().color(QPalette::Disabled,QPalette::Base)); + } painter.drawRect(rect); painter.drawText(rect,Qt::AlignCenter, mColor.name()); } else { //painter.fillRect(rect,palette().color(QPalette::Base)); + if (isEnabled()) { + painter.setBrush(palette().color(QPalette::Text)); + painter.setBrush(palette().color(QPalette::Base)); + } else { + painter.setBrush(palette().color(QPalette::Disabled,QPalette::Text)); + painter.setBrush(palette().color(QPalette::Disabled,QPalette::Base)); + } painter.setPen(contrast()); painter.setBrush(palette().color(QPalette::Base)); painter.drawRect(rect); @@ -78,7 +90,7 @@ void ColorEdit::paintEvent(QPaintEvent *) } } -void ColorEdit::mouseReleaseEvent(QMouseEvent *event) +void ColorEdit::mouseReleaseEvent(QMouseEvent *) { QColor c = QColorDialog::getColor(); if (c.isValid()) { @@ -86,12 +98,12 @@ void ColorEdit::mouseReleaseEvent(QMouseEvent *event) } } -void ColorEdit::enterEvent(QEvent *event) +void ColorEdit::enterEvent(QEvent *) { setCursor(Qt::PointingHandCursor); } -void ColorEdit::leaveEvent(QEvent *event) +void ColorEdit::leaveEvent(QEvent *) { setCursor(Qt::ArrowCursor); }