- 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
This commit is contained in:
royqh1979@gmail.com 2021-09-19 17:59:03 +08:00
parent ad5b3f5e28
commit 77356215aa
16 changed files with 294 additions and 23 deletions

View File

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

View File

@ -78,7 +78,7 @@ void ExecutableRunner::run()
break; break;
} }
if (errorOccurred) { if (errorOccurred) {
qDebug()<<"process error:"<<process.error(); //qDebug()<<"process error:"<<process.error();
switch (process.error()) { switch (process.error()) {
case QProcess::FailedToStart: case QProcess::FailedToStart:
emit runErrorOccurred(tr("The runner process '%1' failed to start.").arg(mFilename)); emit runErrorOccurred(tr("The runner process '%1' failed to start.").arg(mFilename));

View File

@ -2771,9 +2771,33 @@ void Editor::applySettings()
} }
} }
static PSynHighlighterAttribute createRainbowAttribute(const QString& attrName, const QString& schemeName, const QString& schemeItemName) {
PColorSchemeItem item = pColorManager->getItem(schemeName,schemeItemName);
if (item) {
PSynHighlighterAttribute attr = std::make_shared<SynHighlighterAttribute>(attrName);
attr->setForeground(item->foreground());
attr->setBackground(item->background());
return attr;
}
return PSynHighlighterAttribute();
}
void Editor::applyColorScheme(const QString& schemeName) void Editor::applyColorScheme(const QString& schemeName)
{ {
SynEditorOptions options = getOptions();
options.setFlag(SynEditorOption::eoShowRainbowColor, pSettings->editor().rainbowParenthesis());
setOptions(options);
highlighterManager.applyColorScheme(highlighter(),schemeName); 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); PColorSchemeItem item = pColorManager->getItem(schemeName,COLOR_SCHEME_ACTIVE_LINE);
if (item) { if (item) {
setActiveLineColor(item->background()); setActiveLineColor(item->background());

View File

@ -931,7 +931,11 @@ void MainWindow::runExecutable(const QString &exeName,const QString &filename)
showMinimized(); showMinimized();
} }
updateAppTitle(); updateAppTitle();
if (pSettings->executor().useParams()) {
mCompilerManager->run(exeName,pSettings->executor().params(),QFileInfo(exeName).absolutePath());
} else {
mCompilerManager->run(exeName,"",QFileInfo(exeName).absolutePath()); mCompilerManager->run(exeName,"",QFileInfo(exeName).absolutePath());
}
} }
void MainWindow::runExecutable() void MainWindow::runExecutable()
@ -2649,13 +2653,13 @@ void MainWindow::on_actionAdd_Watch_triggered()
{ {
QString s = ""; QString s = "";
Editor *e = mEditorList->getEditor(); Editor *e = mEditorList->getEditor();
if (e==nullptr) if (e!=nullptr) {
return;
if (e->selAvail()) { if (e->selAvail()) {
s = e->selText(); s = e->selText();
} else { } else {
s = e->WordAtCursor(); s = e->WordAtCursor();
} }
}
bool isOk; bool isOk;
s=QInputDialog::getText(this, s=QInputDialog::getText(this,
tr("New Watch Expression"), tr("New Watch Expression"),

View File

@ -1092,6 +1092,10 @@
</property> </property>
</action> </action>
<action name="actionOptions"> <action name="actionOptions">
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/images/newlook24/061-rebuild.png</normaloff>:/icons/images/newlook24/061-rebuild.png</iconset>
</property>
<property name="text"> <property name="text">
<string>Options</string> <string>Options</string>
</property> </property>

View File

@ -3292,6 +3292,26 @@ void SynEdit::onScrolled(int)
invalidate(); 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 bool SynEdit::caretUseTextColor() const
{ {
return mCaretUseTextColor; 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) void SynEdit::paintEvent(QPaintEvent *event)
{ {
if (mPainterLock>0) if (mPainterLock>0)

View File

@ -256,7 +256,10 @@ public:
bool PointToLine(const QPoint& point, int& line); bool PointToLine(const QPoint& point, int& line);
bool isIdentChar(const QChar& ch); bool isIdentChar(const QChar& ch);
void setRainbowAttrs(const PSynHighlighterAttribute &attr0,
const PSynHighlighterAttribute &attr1,
const PSynHighlighterAttribute &attr2,
const PSynHighlighterAttribute &attr3);
// setter && getters // setter && getters
int topLine() const; int topLine() const;
void setTopLine(int value); void setTopLine(int value);
@ -351,6 +354,14 @@ public:
bool caretUseTextColor() const; bool caretUseTextColor() const;
void setCaretUseTextColor(bool newCaretUseTextColor); void setCaretUseTextColor(bool newCaretUseTextColor);
const PSynHighlighterAttribute &rainbowAttr0() const;
const PSynHighlighterAttribute &rainbowAttr1() const;
const PSynHighlighterAttribute &rainbowAttr2() const;
const PSynHighlighterAttribute &rainbowAttr3() const;
signals: signals:
void linesDeleted(int FirstLine, int Count); void linesDeleted(int FirstLine, int Count);
void linesInserted(int FirstLine, int Count); void linesInserted(int FirstLine, int Count);
@ -576,6 +587,11 @@ private:
QColor mSelectedForeground; QColor mSelectedForeground;
QColor mSelectedBackground; QColor mSelectedBackground;
QColor mCaretColor; QColor mCaretColor;
PSynHighlighterAttribute mRainbowAttr0;
PSynHighlighterAttribute mRainbowAttr1;
PSynHighlighterAttribute mRainbowAttr2;
PSynHighlighterAttribute mRainbowAttr3;
bool mCaretUseTextColor; bool mCaretUseTextColor;
QColor mActiveLineColor; QColor mActiveLineColor;
PSynEditUndoList mUndoList; PSynEditUndoList mUndoList;

View File

@ -681,20 +681,23 @@ void SynEditTextPainter::GetBraceColorAttr(int level, PSynHighlighterAttribute &
return; return;
if (attr != edit->mHighlighter->symbolAttribute()) if (attr != edit->mHighlighter->symbolAttribute())
return; return;
PSynHighlighterAttribute oldAttr = attr;
switch(level % 4) { switch(level % 4) {
case 0: case 0:
attr = edit->mHighlighter->keywordAttribute(); attr = edit->mRainbowAttr0;
break; break;
case 1: case 1:
attr = edit->mHighlighter->symbolAttribute(); attr = edit->mRainbowAttr1;
break; break;
case 2: case 2:
attr = edit->mHighlighter->stringAttribute(); attr = edit->mRainbowAttr2;
break; break;
case 3: case 3:
attr = edit->mHighlighter->identifierAttribute(); attr = edit->mRainbowAttr3;
break; break;
} }
if (!attr)
attr = oldAttr;
} }
void SynEditTextPainter::PaintLines() void SynEditTextPainter::PaintLines()

View File

@ -460,6 +460,16 @@ void Settings::Editor::setCaretUseTextColor(bool newUseIdentifierColor)
mCaretUseTextColor = newUseIdentifierColor; mCaretUseTextColor = newUseIdentifierColor;
} }
bool Settings::Editor::rainbowParenthesis() const
{
return mRainbowParenthesis;
}
void Settings::Editor::setRainbowParenthesis(bool newRainbowParenthesis)
{
mRainbowParenthesis = newRainbowParenthesis;
}
int Settings::Editor::rightEdgeWidth() const int Settings::Editor::rightEdgeWidth() const
{ {
return mRightEdgeWidth; return mRightEdgeWidth;
@ -933,6 +943,7 @@ void Settings::Editor::doSave()
//color scheme //color scheme
saveValue("color_scheme", mColorScheme); saveValue("color_scheme", mColorScheme);
saveValue("rainbow_parenthesis",mRainbowParenthesis);
//Symbol Completion //Symbol Completion
saveValue("complete_symbols", mCompleteSymbols); saveValue("complete_symbols", mCompleteSymbols);
@ -1032,6 +1043,7 @@ void Settings::Editor::doLoad()
//color //color
mColorScheme = stringValue("color_scheme", "VS Code"); mColorScheme = stringValue("color_scheme", "VS Code");
mRainbowParenthesis = boolValue("rainbow_parenthesis", true);
//Symbol Completion //Symbol Completion
mCompleteSymbols = boolValue("complete_symbols",true); mCompleteSymbols = boolValue("complete_symbols",true);
@ -2521,10 +2533,54 @@ void Settings::Executor::setMinimizeOnRun(bool minimizeOnRun)
mMinimizeOnRun = 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() void Settings::Executor::doSave()
{ {
saveValue("pause_console", mPauseConsole); saveValue("pause_console", mPauseConsole);
saveValue("minimize_on_run", mMinimizeOnRun); 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 bool Settings::Executor::pauseConsole() const
@ -2541,6 +2597,11 @@ void Settings::Executor::doLoad()
{ {
mPauseConsole = boolValue("pause_console",true); mPauseConsole = boolValue("pause_console",true);
mMinimizeOnRun = boolValue("minimize_on_run",false); mMinimizeOnRun = boolValue("minimize_on_run",false);
mUseParams = boolValue("use_params",false);
mParams = stringValue("params", "");
mRedirectInput = boolValue("redirect_input",false);
mInputFilename = stringValue("input_filename","");
} }

View File

@ -302,6 +302,9 @@ public:
bool caretUseTextColor() const; bool caretUseTextColor() const;
void setCaretUseTextColor(bool newUseIdentifierColor); void setCaretUseTextColor(bool newUseIdentifierColor);
bool rainbowParenthesis() const;
void setRainbowParenthesis(bool newRainbowParenthesis);
private: private:
//General //General
// indents // indents
@ -366,6 +369,7 @@ public:
//Color //Color
QString mColorScheme; QString mColorScheme;
bool mRainbowParenthesis;
//Symbol Completion //Symbol Completion
bool mCompleteSymbols; bool mCompleteSymbols;
@ -705,10 +709,23 @@ public:
bool minimizeOnRun() const; bool minimizeOnRun() const;
void setMinimizeOnRun(bool minimizeOnRun); void setMinimizeOnRun(bool minimizeOnRun);
bool useParams() const;
void setUseParams(bool newUseParams);
const QString &params() const;
void setParams(const QString &newParams);
bool redirectInput() const;
void setRedirectInput(bool newRedirectInput);
const QString &inputFilename() const;
void setInputFilename(const QString &newInputFilename);
private: private:
// general // general
bool mPauseConsole; bool mPauseConsole;
bool mMinimizeOnRun; bool mMinimizeOnRun;
bool mUseParams;
QString mParams;
bool mRedirectInput;
QString mInputFilename;
protected: protected:
void doSave() override; void doSave() override;

View File

@ -281,6 +281,7 @@ void EditorColorSchemeWidget::changeSchemeComboFont()
void EditorColorSchemeWidget::doLoad() void EditorColorSchemeWidget::doLoad()
{ {
ui->cbScheme->setCurrentText(pSettings->editor().colorScheme()); ui->cbScheme->setCurrentText(pSettings->editor().colorScheme());
ui->chkRainborParenthesis->setChecked(pSettings->editor().rainbowParenthesis());
} }
void EditorColorSchemeWidget::doSave() void EditorColorSchemeWidget::doSave()
@ -290,6 +291,7 @@ void EditorColorSchemeWidget::doSave()
pColorManager->saveScheme(name); pColorManager->saveScheme(name);
} }
pSettings->editor().setColorScheme(ui->cbScheme->currentText()); pSettings->editor().setColorScheme(ui->cbScheme->currentText());
pSettings->editor().setRainbowParenthesis(ui->chkRainborParenthesis->isChecked());
pSettings->editor().save(); pSettings->editor().save();
pMainWindow->updateEditorColorSchemes(); pMainWindow->updateEditorColorSchemes();
} catch (FileError e) { } catch (FileError e) {

View File

@ -336,6 +336,20 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item>
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="chkRainborParenthesis">
<property name="text">
<string>Rainbow parenthesis</string>
</property>
</widget>
</item>
</layout> </layout>
<action name="actionCopy_Scheme"> <action name="actionCopy_Scheme">
<property name="text"> <property name="text">

View File

@ -2,6 +2,8 @@
#include "ui_executorgeneralwidget.h" #include "ui_executorgeneralwidget.h"
#include "../settings.h" #include "../settings.h"
#include <QFileDialog>
ExecutorGeneralWidget::ExecutorGeneralWidget(const QString& name, const QString& group, QWidget *parent): ExecutorGeneralWidget::ExecutorGeneralWidget(const QString& name, const QString& group, QWidget *parent):
SettingsWidget(name,group,parent), SettingsWidget(name,group,parent),
ui(new Ui::ExecutorGeneralWidget) ui(new Ui::ExecutorGeneralWidget)
@ -18,12 +20,33 @@ void ExecutorGeneralWidget::doLoad()
{ {
ui->chkPauseConsole->setChecked(pSettings->executor().pauseConsole()); ui->chkPauseConsole->setChecked(pSettings->executor().pauseConsole());
ui->chkMinimizeOnRun->setChecked(pSettings->executor().minimizeOnRun()); 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() void ExecutorGeneralWidget::doSave()
{ {
pSettings->executor().setPauseConsole(ui->chkPauseConsole->isChecked()); pSettings->executor().setPauseConsole(ui->chkPauseConsole->isChecked());
pSettings->executor().setMinimizeOnRun(ui->chkMinimizeOnRun->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(); 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);
}
}

View File

@ -23,6 +23,8 @@ private:
protected: protected:
void doLoad() override; void doLoad() override;
void doSave() override; void doSave() override;
private slots:
void on_btnBrowse_triggered(QAction *arg1);
}; };
#endif // EXECUTORGENERALWIDGET_H #endif // EXECUTORGENERALWIDGET_H

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>400</width> <width>617</width>
<height>300</height> <height>449</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -47,7 +47,22 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="1" column="0"> <item row="1" column="0" colspan="2">
<widget class="QGroupBox" name="grpExecuteParameters">
<property name="title">
<string>Parameters to pass to your program</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="txtExecuteParamaters"/>
</item>
</layout>
</widget>
</item>
<item row="3" column="0">
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
@ -60,8 +75,49 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="2" column="0" colspan="2">
<widget class="QGroupBox" name="grpRedirectInput">
<property name="title">
<string>Redirect input to the following file:</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="1">
<widget class="QLineEdit" name="txtRedirectInputFile"/>
</item>
<item row="0" column="2">
<widget class="QToolButton" name="btnBrowse">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/icons/images/newlook24/053-open.png</normaloff>:/icons/images/newlook24/053-open.png</iconset>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QLabel" name="label">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Note: Debugger doesn't support this feature.</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<resources/> </item>
</layout>
</widget>
<resources>
<include location="../icons.qrc"/>
</resources>
<connections/> <connections/>
</ui> </ui>

View File

@ -63,14 +63,26 @@ void ColorEdit::paintEvent(QPaintEvent *)
{ {
QPainter painter(this); QPainter painter(this);
QRect rect = QRect(lineWidth(),lineWidth(),width()-2*lineWidth(),height()-2*lineWidth()); QRect rect = QRect(lineWidth(),lineWidth(),width()-2*lineWidth(),height()-2*lineWidth());
if (mColor.isValid()) { if (mColor.isValid() ) {
//painter.fillRect(rect,mColor); //painter.fillRect(rect,mColor);
if (isEnabled()) {
painter.setPen(contrast()); painter.setPen(contrast());
painter.setBrush(mColor); painter.setBrush(mColor);
} else {
painter.setBrush(palette().color(QPalette::Disabled,QPalette::Text));
painter.setBrush(palette().color(QPalette::Disabled,QPalette::Base));
}
painter.drawRect(rect); painter.drawRect(rect);
painter.drawText(rect,Qt::AlignCenter, mColor.name()); painter.drawText(rect,Qt::AlignCenter, mColor.name());
} else { } else {
//painter.fillRect(rect,palette().color(QPalette::Base)); //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.setPen(contrast());
painter.setBrush(palette().color(QPalette::Base)); painter.setBrush(palette().color(QPalette::Base));
painter.drawRect(rect); painter.drawRect(rect);
@ -78,7 +90,7 @@ void ColorEdit::paintEvent(QPaintEvent *)
} }
} }
void ColorEdit::mouseReleaseEvent(QMouseEvent *event) void ColorEdit::mouseReleaseEvent(QMouseEvent *)
{ {
QColor c = QColorDialog::getColor(); QColor c = QColorDialog::getColor();
if (c.isValid()) { if (c.isValid()) {
@ -86,12 +98,12 @@ void ColorEdit::mouseReleaseEvent(QMouseEvent *event)
} }
} }
void ColorEdit::enterEvent(QEvent *event) void ColorEdit::enterEvent(QEvent *)
{ {
setCursor(Qt::PointingHandCursor); setCursor(Qt::PointingHandCursor);
} }
void ColorEdit::leaveEvent(QEvent *event) void ColorEdit::leaveEvent(QEvent *)
{ {
setCursor(Qt::ArrowCursor); setCursor(Qt::ArrowCursor);
} }