astyle formatting

[ci skip]
This commit is contained in:
versat 2019-06-25 15:29:15 +02:00
parent b0e56f873f
commit b1e2b9d61b
12 changed files with 471 additions and 476 deletions

View File

@ -106,27 +106,27 @@ void Highlighter::setSymbols(const QStringList &symbols)
} }
} }
void Highlighter::setStyle( const CodeEditorStyle &newStyle ) void Highlighter::setStyle(const CodeEditorStyle &newStyle)
{ {
mKeywordFormat.setForeground( newStyle.keywordColor ); mKeywordFormat.setForeground(newStyle.keywordColor);
mKeywordFormat.setFontWeight( newStyle.keywordWeight ); mKeywordFormat.setFontWeight(newStyle.keywordWeight);
mClassFormat.setForeground( newStyle.classColor ); mClassFormat.setForeground(newStyle.classColor);
mClassFormat.setFontWeight( newStyle.classWeight ); mClassFormat.setFontWeight(newStyle.classWeight);
mSingleLineCommentFormat.setForeground( newStyle.commentColor ); mSingleLineCommentFormat.setForeground(newStyle.commentColor);
mSingleLineCommentFormat.setFontWeight( newStyle.commentWeight ); mSingleLineCommentFormat.setFontWeight(newStyle.commentWeight);
mMultiLineCommentFormat.setForeground( newStyle.commentColor ); mMultiLineCommentFormat.setForeground(newStyle.commentColor);
mMultiLineCommentFormat.setFontWeight( newStyle.commentWeight ); mMultiLineCommentFormat.setFontWeight(newStyle.commentWeight);
mQuotationFormat.setForeground( newStyle.quoteColor ); mQuotationFormat.setForeground(newStyle.quoteColor);
mQuotationFormat.setFontWeight( newStyle.quoteWeight ); mQuotationFormat.setFontWeight(newStyle.quoteWeight);
mSymbolFormat.setForeground( newStyle.symbolFGColor ); mSymbolFormat.setForeground(newStyle.symbolFGColor);
mSymbolFormat.setBackground( newStyle.symbolBGColor ); mSymbolFormat.setBackground(newStyle.symbolBGColor);
mSymbolFormat.setFontWeight( newStyle.symbolWeight ); mSymbolFormat.setFontWeight(newStyle.symbolWeight);
for( HighlightingRule& rule : mHighlightingRules ) { for (HighlightingRule& rule : mHighlightingRules) {
applyFormat( rule ); applyFormat(rule);
} }
for( HighlightingRule& rule : mHighlightingRulesWithSymbols ) { for (HighlightingRule& rule : mHighlightingRulesWithSymbols) {
applyFormat( rule ); applyFormat(rule);
} }
} }
@ -162,43 +162,42 @@ void Highlighter::highlightBlock(const QString &text)
} }
} }
void Highlighter::applyFormat( HighlightingRule &rule ) void Highlighter::applyFormat(HighlightingRule &rule)
{ {
switch( rule.ruleRole ) switch (rule.ruleRole) {
{ case RuleRole::Keyword:
case RuleRole::Keyword: rule.format = mKeywordFormat;
rule.format = mKeywordFormat; break;
break; case RuleRole::Class:
case RuleRole::Class: rule.format = mClassFormat;
rule.format = mClassFormat; break;
break; case RuleRole::Comment:
case RuleRole::Comment: rule.format = mSingleLineCommentFormat;
rule.format = mSingleLineCommentFormat; break;
break; case RuleRole::Quote:
case RuleRole::Quote: rule.format = mQuotationFormat;
rule.format = mQuotationFormat; break;
break; case RuleRole::Symbol:
case RuleRole::Symbol: rule.format = mSymbolFormat;
rule.format = mSymbolFormat; break;
break;
} }
} }
CodeEditor::CodeEditor(QWidget *parent) : CodeEditor::CodeEditor(QWidget *parent) :
QPlainTextEdit(parent), QPlainTextEdit(parent),
mWidgetStyle( new CodeEditorStyle( defaultStyleLight )) mWidgetStyle(new CodeEditorStyle(defaultStyleLight))
{ {
mLineNumberArea = new LineNumberArea(this); mLineNumberArea = new LineNumberArea(this);
mHighlighter = new Highlighter( document(), mWidgetStyle ); mHighlighter = new Highlighter(document(), mWidgetStyle);
mErrorPosition = -1; mErrorPosition = -1;
QFont font( "Monospace" ); QFont font("Monospace");
font.setStyleHint( QFont::TypeWriter ); font.setStyleHint(QFont::TypeWriter);
setFont( font ); setFont(font);
// set widget coloring by overriding widget style sheet // set widget coloring by overriding widget style sheet
setObjectName("CodeEditor"); setObjectName("CodeEditor");
setStyleSheet( generateStyleString() ); setStyleSheet(generateStyleString());
connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int))); connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int)));
connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int))); connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int)));
@ -230,8 +229,8 @@ void CodeEditor::setStyle(const CodeEditorStyle& newStyle)
{ {
*mWidgetStyle = newStyle; *mWidgetStyle = newStyle;
// apply new styling // apply new styling
setStyleSheet( generateStyleString() ); setStyleSheet(generateStyleString());
mHighlighter->setStyle( newStyle ); mHighlighter->setStyle(newStyle);
mHighlighter->rehighlight(); mHighlighter->rehighlight();
highlightErrorLine(); highlightErrorLine();
} }
@ -296,7 +295,7 @@ void CodeEditor::highlightErrorLine()
selection.format.setBackground(mWidgetStyle->highlightBGColor); selection.format.setBackground(mWidgetStyle->highlightBGColor);
selection.format.setProperty(QTextFormat::FullWidthSelection, true); selection.format.setProperty(QTextFormat::FullWidthSelection, true);
selection.cursor = QTextCursor(document()); selection.cursor = QTextCursor(document());
if( mErrorPosition >= 0 ) { if (mErrorPosition >= 0) {
selection.cursor.setPosition(mErrorPosition); selection.cursor.setPosition(mErrorPosition);
} else { } else {
selection.cursor.setPosition(0); selection.cursor.setPosition(0);

View File

@ -24,7 +24,7 @@ public:
void setSymbols(const QStringList &symbols); void setSymbols(const QStringList &symbols);
void setStyle( const CodeEditorStyle &newStyle ); void setStyle(const CodeEditorStyle &newStyle);
protected: protected:
void highlightBlock(const QString &text) override; void highlightBlock(const QString &text) override;
@ -43,7 +43,7 @@ private:
RuleRole ruleRole; RuleRole ruleRole;
}; };
void applyFormat( HighlightingRule &rule ); void applyFormat(HighlightingRule &rule);
QVector<HighlightingRule> mHighlightingRules; QVector<HighlightingRule> mHighlightingRules;
QVector<HighlightingRule> mHighlightingRulesWithSymbols; QVector<HighlightingRule> mHighlightingRulesWithSymbols;

View File

@ -20,15 +20,15 @@
#include <QSettings> #include <QSettings>
CodeEditorStyle::CodeEditorStyle( CodeEditorStyle::CodeEditorStyle(
const QColor& CtrlFGColor, const QColor& CtrlBGColor, const QColor& CtrlFGColor, const QColor& CtrlBGColor,
const QColor& HiLiBGColor, const QColor& HiLiBGColor,
const QColor& LnNumFGColor, const QColor& LnNumBGColor, const QColor& LnNumFGColor, const QColor& LnNumBGColor,
const QColor& KeyWdFGColor, const QFont::Weight& KeyWdWeight, const QColor& KeyWdFGColor, const QFont::Weight& KeyWdWeight,
const QColor& ClsFGColor, const QFont::Weight& ClsWeight, const QColor& ClsFGColor, const QFont::Weight& ClsWeight,
const QColor& QteFGColor, const QFont::Weight& QteWeight, const QColor& QteFGColor, const QFont::Weight& QteWeight,
const QColor& CmtFGColor, const QFont::Weight& CmtWeight, const QColor& CmtFGColor, const QFont::Weight& CmtWeight,
const QColor& SymbFGColor, const QColor& SymbBGColor, const QColor& SymbFGColor, const QColor& SymbBGColor,
const QFont::Weight& SymbWeight) : const QFont::Weight& SymbWeight) :
widgetFGColor(CtrlFGColor), widgetFGColor(CtrlFGColor),
widgetBGColor(CtrlBGColor), widgetBGColor(CtrlBGColor),
highlightBGColor(HiLiBGColor), highlightBGColor(HiLiBGColor),
@ -47,168 +47,162 @@ CodeEditorStyle::CodeEditorStyle(
symbolWeight(SymbWeight) symbolWeight(SymbWeight)
{} {}
bool CodeEditorStyle::operator==( const CodeEditorStyle& rhs ) const bool CodeEditorStyle::operator==(const CodeEditorStyle& rhs) const
{ {
if( widgetFGColor != rhs.widgetFGColor ) return false; if (widgetFGColor != rhs.widgetFGColor) return false;
if( widgetBGColor != rhs.widgetBGColor ) return false; if (widgetBGColor != rhs.widgetBGColor) return false;
if( highlightBGColor != rhs.highlightBGColor ) return false; if (highlightBGColor != rhs.highlightBGColor) return false;
if( lineNumFGColor != rhs.lineNumFGColor ) return false; if (lineNumFGColor != rhs.lineNumFGColor) return false;
if( lineNumBGColor != rhs.lineNumBGColor ) return false; if (lineNumBGColor != rhs.lineNumBGColor) return false;
if( keywordColor != rhs.keywordColor ) return false; if (keywordColor != rhs.keywordColor) return false;
if( keywordWeight != rhs.keywordWeight ) return false; if (keywordWeight != rhs.keywordWeight) return false;
if( classColor != rhs.classColor ) return false; if (classColor != rhs.classColor) return false;
if( classWeight != rhs.classWeight ) return false; if (classWeight != rhs.classWeight) return false;
if( quoteColor != rhs.quoteColor ) return false; if (quoteColor != rhs.quoteColor) return false;
if( quoteWeight != rhs.quoteWeight ) return false; if (quoteWeight != rhs.quoteWeight) return false;
if( commentColor != rhs.commentColor ) return false; if (commentColor != rhs.commentColor) return false;
if( commentWeight != rhs.commentWeight ) return false; if (commentWeight != rhs.commentWeight) return false;
if( symbolFGColor != rhs.symbolFGColor ) return false; if (symbolFGColor != rhs.symbolFGColor) return false;
if( symbolBGColor != rhs.symbolBGColor ) return false; if (symbolBGColor != rhs.symbolBGColor) return false;
if( symbolWeight != rhs.symbolWeight ) return false; if (symbolWeight != rhs.symbolWeight) return false;
return true; return true;
} }
bool CodeEditorStyle::operator!=( const CodeEditorStyle& rhs ) const bool CodeEditorStyle::operator!=(const CodeEditorStyle& rhs) const
{ {
return !(*this == rhs); return !(*this == rhs);
} }
CodeEditorStyle CodeEditorStyle::loadSettings( QSettings *settings ) CodeEditorStyle CodeEditorStyle::loadSettings(QSettings *settings)
{ {
CodeEditorStyle theStyle( defaultStyleLight ); CodeEditorStyle theStyle(defaultStyleLight);
if( !settings) return theStyle; if (!settings) return theStyle;
if( !settings->childGroups().contains( SETTINGS_STYLE_GROUP )) if (!settings->childGroups().contains(SETTINGS_STYLE_GROUP))
return theStyle; return theStyle;
// style section exists - load values // style section exists - load values
settings->beginGroup( SETTINGS_STYLE_GROUP ); settings->beginGroup(SETTINGS_STYLE_GROUP);
QString type = settings->value( QString type = settings->value(
SETTINGS_STYLE_TYPE, SETTINGS_STYLE_TYPE,
QVariant( SETTINGS_STYLE_TYPE_LIGHT ) QVariant(SETTINGS_STYLE_TYPE_LIGHT)
).toString(); ).toString();
if( type == SETTINGS_STYLE_TYPE_LIGHT ) if (type == SETTINGS_STYLE_TYPE_LIGHT) {
{
settings->endGroup(); settings->endGroup();
return theStyle; return theStyle;
} }
if( type == SETTINGS_STYLE_TYPE_DARK ) if (type == SETTINGS_STYLE_TYPE_DARK) {
{
theStyle = defaultStyleDark; theStyle = defaultStyleDark;
settings->endGroup(); settings->endGroup();
return theStyle; return theStyle;
} }
if( type == SETTINGS_STYLE_TYPE_CUSTOM ) if (type == SETTINGS_STYLE_TYPE_CUSTOM) {
{
theStyle.widgetFGColor = settings->value( theStyle.widgetFGColor = settings->value(
SETTINGS_STYLE_WIDGETFG, SETTINGS_STYLE_WIDGETFG,
QVariant(defaultStyleLight.widgetFGColor)).value<QColor>(); QVariant(defaultStyleLight.widgetFGColor)).value<QColor>();
theStyle.widgetBGColor = settings->value( theStyle.widgetBGColor = settings->value(
SETTINGS_STYLE_WIDGETBG, SETTINGS_STYLE_WIDGETBG,
QVariant(defaultStyleLight.widgetBGColor)).value<QColor>(); QVariant(defaultStyleLight.widgetBGColor)).value<QColor>();
theStyle.highlightBGColor = settings->value( theStyle.highlightBGColor = settings->value(
SETTINGS_STYLE_HILIFG, SETTINGS_STYLE_HILIFG,
QVariant(defaultStyleLight.highlightBGColor)).value<QColor>(); QVariant(defaultStyleLight.highlightBGColor)).value<QColor>();
theStyle.lineNumFGColor = settings->value( theStyle.lineNumFGColor = settings->value(
SETTINGS_STYLE_LINENUMFG, SETTINGS_STYLE_LINENUMFG,
QVariant(defaultStyleLight.lineNumFGColor)).value<QColor>(); QVariant(defaultStyleLight.lineNumFGColor)).value<QColor>();
theStyle.lineNumBGColor = settings->value( theStyle.lineNumBGColor = settings->value(
SETTINGS_STYLE_LINENUMBG, SETTINGS_STYLE_LINENUMBG,
QVariant(defaultStyleLight.lineNumBGColor)).value<QColor>(); QVariant(defaultStyleLight.lineNumBGColor)).value<QColor>();
theStyle.keywordColor = settings->value( theStyle.keywordColor = settings->value(
SETTINGS_STYLE_KEYWORDFG, SETTINGS_STYLE_KEYWORDFG,
QVariant(defaultStyleLight.keywordColor)).value<QColor>(); QVariant(defaultStyleLight.keywordColor)).value<QColor>();
QVariant defKeyWWt(static_cast<int>(defaultStyleLight.keywordWeight)); QVariant defKeyWWt(static_cast<int>(defaultStyleLight.keywordWeight));
theStyle.keywordWeight = static_cast<QFont::Weight>( theStyle.keywordWeight = static_cast<QFont::Weight>(
settings->value( SETTINGS_STYLE_KEYWORDWT, defKeyWWt).toInt()); settings->value(SETTINGS_STYLE_KEYWORDWT, defKeyWWt).toInt());
theStyle.classColor = settings->value( theStyle.classColor = settings->value(
SETTINGS_STYLE_CLASSFG, SETTINGS_STYLE_CLASSFG,
QVariant(defaultStyleLight.classColor)).value<QColor>(); QVariant(defaultStyleLight.classColor)).value<QColor>();
QVariant defClsWt(static_cast<int>(defaultStyleLight.classWeight)); QVariant defClsWt(static_cast<int>(defaultStyleLight.classWeight));
theStyle.classWeight = static_cast<QFont::Weight>( theStyle.classWeight = static_cast<QFont::Weight>(
settings->value( SETTINGS_STYLE_CLASSWT, defClsWt).toInt()); settings->value(SETTINGS_STYLE_CLASSWT, defClsWt).toInt());
theStyle.quoteColor = settings->value( theStyle.quoteColor = settings->value(
SETTINGS_STYLE_QUOTEFG, SETTINGS_STYLE_QUOTEFG,
QVariant(defaultStyleLight.quoteColor)).value<QColor>(); QVariant(defaultStyleLight.quoteColor)).value<QColor>();
QVariant defQteWt(static_cast<int>(defaultStyleLight.quoteWeight)); QVariant defQteWt(static_cast<int>(defaultStyleLight.quoteWeight));
theStyle.quoteWeight = static_cast<QFont::Weight>( theStyle.quoteWeight = static_cast<QFont::Weight>(
settings->value( SETTINGS_STYLE_QUOTEWT, defQteWt).toInt()); settings->value(SETTINGS_STYLE_QUOTEWT, defQteWt).toInt());
theStyle.commentColor = settings->value( theStyle.commentColor = settings->value(
SETTINGS_STYLE_COMMENTFG, SETTINGS_STYLE_COMMENTFG,
QVariant(defaultStyleLight.commentColor)).value<QColor>(); QVariant(defaultStyleLight.commentColor)).value<QColor>();
QVariant defCmtWt(static_cast<int>(defaultStyleLight.commentWeight)); QVariant defCmtWt(static_cast<int>(defaultStyleLight.commentWeight));
theStyle.commentWeight = static_cast<QFont::Weight>( theStyle.commentWeight = static_cast<QFont::Weight>(
settings->value( SETTINGS_STYLE_COMMENTWT, defCmtWt).toInt()); settings->value(SETTINGS_STYLE_COMMENTWT, defCmtWt).toInt());
theStyle.symbolFGColor = settings->value( theStyle.symbolFGColor = settings->value(
SETTINGS_STYLE_SYMBOLFG, SETTINGS_STYLE_SYMBOLFG,
QVariant(defaultStyleLight.symbolFGColor)).value<QColor>(); QVariant(defaultStyleLight.symbolFGColor)).value<QColor>();
theStyle.symbolBGColor = settings->value( theStyle.symbolBGColor = settings->value(
SETTINGS_STYLE_SYMBOLBG, SETTINGS_STYLE_SYMBOLBG,
QVariant(defaultStyleLight.symbolBGColor)).value<QColor>(); QVariant(defaultStyleLight.symbolBGColor)).value<QColor>();
QVariant defSymWt(static_cast<int>(defaultStyleLight.symbolWeight)); QVariant defSymWt(static_cast<int>(defaultStyleLight.symbolWeight));
theStyle.symbolWeight = static_cast<QFont::Weight>( theStyle.symbolWeight = static_cast<QFont::Weight>(
settings->value( SETTINGS_STYLE_SYMBOLWT, defSymWt).toInt()); settings->value(SETTINGS_STYLE_SYMBOLWT, defSymWt).toInt());
} }
settings->endGroup(); settings->endGroup();
return theStyle; return theStyle;
} }
void CodeEditorStyle::saveSettings( QSettings *settings, void CodeEditorStyle::saveSettings(QSettings *settings,
const CodeEditorStyle& theStyle ) const CodeEditorStyle& theStyle)
{ {
if( !settings ) return; if (!settings) return;
if( settings->childGroups().contains( SETTINGS_STYLE_GROUP )) if (settings->childGroups().contains(SETTINGS_STYLE_GROUP)) {
{ settings->remove(SETTINGS_STYLE_GROUP);
settings->remove( SETTINGS_STYLE_GROUP );
} }
settings->beginGroup( SETTINGS_STYLE_GROUP ); settings->beginGroup(SETTINGS_STYLE_GROUP);
bool isDefaultLight = ( defaultStyleLight == theStyle ); bool isDefaultLight = (defaultStyleLight == theStyle);
bool isDefaultDark = ( defaultStyleDark == theStyle ); bool isDefaultDark = (defaultStyleDark == theStyle);
if( isDefaultLight && !isDefaultDark ) { if (isDefaultLight && !isDefaultDark) {
settings->setValue( SETTINGS_STYLE_TYPE, settings->setValue(SETTINGS_STYLE_TYPE,
SETTINGS_STYLE_TYPE_LIGHT ); SETTINGS_STYLE_TYPE_LIGHT);
} } else if (!isDefaultLight && isDefaultDark) {
else if( !isDefaultLight && isDefaultDark ) { settings->setValue(SETTINGS_STYLE_TYPE,
settings->setValue( SETTINGS_STYLE_TYPE, SETTINGS_STYLE_TYPE_DARK);
SETTINGS_STYLE_TYPE_DARK ); } else {
} settings->setValue(SETTINGS_STYLE_TYPE,
else { SETTINGS_STYLE_TYPE_CUSTOM);
settings->setValue( SETTINGS_STYLE_TYPE, settings->setValue(SETTINGS_STYLE_WIDGETFG,
SETTINGS_STYLE_TYPE_CUSTOM ); QVariant(theStyle.widgetFGColor));
settings->setValue( SETTINGS_STYLE_WIDGETFG, settings->setValue(SETTINGS_STYLE_WIDGETBG,
QVariant( theStyle.widgetFGColor )); QVariant(theStyle.widgetBGColor));
settings->setValue( SETTINGS_STYLE_WIDGETBG, settings->setValue(SETTINGS_STYLE_HILIFG,
QVariant( theStyle.widgetBGColor )); QVariant(theStyle.highlightBGColor));
settings->setValue( SETTINGS_STYLE_HILIFG, settings->setValue(SETTINGS_STYLE_LINENUMFG,
QVariant( theStyle.highlightBGColor )); QVariant(theStyle.lineNumFGColor));
settings->setValue( SETTINGS_STYLE_LINENUMFG, settings->setValue(SETTINGS_STYLE_LINENUMBG,
QVariant( theStyle.lineNumFGColor )); QVariant(theStyle.lineNumBGColor));
settings->setValue( SETTINGS_STYLE_LINENUMBG, settings->setValue(SETTINGS_STYLE_KEYWORDFG,
QVariant( theStyle.lineNumBGColor )); QVariant(theStyle.keywordColor));
settings->setValue( SETTINGS_STYLE_KEYWORDFG, settings->setValue(SETTINGS_STYLE_KEYWORDWT,
QVariant( theStyle.keywordColor )); QVariant(static_cast<int>(theStyle.keywordWeight)));
settings->setValue( SETTINGS_STYLE_KEYWORDWT, settings->setValue(SETTINGS_STYLE_CLASSFG,
QVariant( static_cast<int>( theStyle.keywordWeight ))); QVariant(theStyle.classColor));
settings->setValue( SETTINGS_STYLE_CLASSFG, settings->setValue(SETTINGS_STYLE_CLASSWT,
QVariant( theStyle.classColor )); QVariant(static_cast<int>(theStyle.classWeight)));
settings->setValue( SETTINGS_STYLE_CLASSWT, settings->setValue(SETTINGS_STYLE_QUOTEFG,
QVariant( static_cast<int>( theStyle.classWeight ))); QVariant(theStyle.quoteColor));
settings->setValue( SETTINGS_STYLE_QUOTEFG, settings->setValue(SETTINGS_STYLE_QUOTEWT,
QVariant( theStyle.quoteColor )); QVariant(static_cast<int>(theStyle.quoteWeight)));
settings->setValue( SETTINGS_STYLE_QUOTEWT, settings->setValue(SETTINGS_STYLE_COMMENTFG,
QVariant( static_cast<int>( theStyle.quoteWeight ))); QVariant(theStyle.commentColor));
settings->setValue( SETTINGS_STYLE_COMMENTFG, settings->setValue(SETTINGS_STYLE_COMMENTWT,
QVariant( theStyle.commentColor )); QVariant(static_cast<int>(theStyle.commentWeight)));
settings->setValue( SETTINGS_STYLE_COMMENTWT, settings->setValue(SETTINGS_STYLE_SYMBOLFG,
QVariant( static_cast<int>( theStyle.commentWeight ))); QVariant(theStyle.symbolFGColor));
settings->setValue( SETTINGS_STYLE_SYMBOLFG, settings->setValue(SETTINGS_STYLE_SYMBOLBG,
QVariant( theStyle.symbolFGColor )); QVariant(theStyle.symbolBGColor));
settings->setValue( SETTINGS_STYLE_SYMBOLBG, settings->setValue(SETTINGS_STYLE_SYMBOLWT,
QVariant( theStyle.symbolBGColor )); QVariant(static_cast<int>(theStyle.symbolWeight)));
settings->setValue( SETTINGS_STYLE_SYMBOLWT,
QVariant( static_cast<int>( theStyle.symbolWeight )));
} }
settings->endGroup(); settings->endGroup();
} }

View File

@ -23,27 +23,27 @@
#include <QColor> #include <QColor>
#include <QFont> #include <QFont>
const QString SETTINGS_STYLE_GROUP( "EditorStyle" ); const QString SETTINGS_STYLE_GROUP("EditorStyle");
const QString SETTINGS_STYLE_TYPE( "StyleType"); const QString SETTINGS_STYLE_TYPE("StyleType");
const QString SETTINGS_STYLE_TYPE_LIGHT( "DefaultLight" ); const QString SETTINGS_STYLE_TYPE_LIGHT("DefaultLight");
const QString SETTINGS_STYLE_TYPE_DARK( "DefaultDark" ); const QString SETTINGS_STYLE_TYPE_DARK("DefaultDark");
const QString SETTINGS_STYLE_TYPE_CUSTOM( "Custom" ); const QString SETTINGS_STYLE_TYPE_CUSTOM("Custom");
const QString SETTINGS_STYLE_WIDGETFG( "StyleWidgetFG" ); const QString SETTINGS_STYLE_WIDGETFG("StyleWidgetFG");
const QString SETTINGS_STYLE_WIDGETBG( "StyleWidgetBG" ); const QString SETTINGS_STYLE_WIDGETBG("StyleWidgetBG");
const QString SETTINGS_STYLE_HILIFG( "StyleHighlightFG" ); const QString SETTINGS_STYLE_HILIFG("StyleHighlightFG");
const QString SETTINGS_STYLE_LINENUMFG( "StyleLineNumFG" ); const QString SETTINGS_STYLE_LINENUMFG("StyleLineNumFG");
const QString SETTINGS_STYLE_LINENUMBG( "StyleLineNumBG" ); const QString SETTINGS_STYLE_LINENUMBG("StyleLineNumBG");
const QString SETTINGS_STYLE_KEYWORDFG( "StyleKeywordFG" ); const QString SETTINGS_STYLE_KEYWORDFG("StyleKeywordFG");
const QString SETTINGS_STYLE_KEYWORDWT( "StyleKeywordWeight" ); const QString SETTINGS_STYLE_KEYWORDWT("StyleKeywordWeight");
const QString SETTINGS_STYLE_CLASSFG( "StyleClassFG" ); const QString SETTINGS_STYLE_CLASSFG("StyleClassFG");
const QString SETTINGS_STYLE_CLASSWT( "StyleClassWeight" ); const QString SETTINGS_STYLE_CLASSWT("StyleClassWeight");
const QString SETTINGS_STYLE_QUOTEFG( "StyleQuoteFG" ); const QString SETTINGS_STYLE_QUOTEFG("StyleQuoteFG");
const QString SETTINGS_STYLE_QUOTEWT( "StyleQuoteWeight" ); const QString SETTINGS_STYLE_QUOTEWT("StyleQuoteWeight");
const QString SETTINGS_STYLE_COMMENTFG( "StyleCommentFG" ); const QString SETTINGS_STYLE_COMMENTFG("StyleCommentFG");
const QString SETTINGS_STYLE_COMMENTWT( "StyleCommentWeight" ); const QString SETTINGS_STYLE_COMMENTWT("StyleCommentWeight");
const QString SETTINGS_STYLE_SYMBOLFG( "StyleSymbolFG" ); const QString SETTINGS_STYLE_SYMBOLFG("StyleSymbolFG");
const QString SETTINGS_STYLE_SYMBOLBG( "StyleSymbolBG" ); const QString SETTINGS_STYLE_SYMBOLBG("StyleSymbolBG");
const QString SETTINGS_STYLE_SYMBOLWT( "StyleSymbolWeight" ); const QString SETTINGS_STYLE_SYMBOLWT("StyleSymbolWeight");
class QSettings; class QSettings;
@ -61,11 +61,11 @@ public:
const QFont::Weight& SymbWeight); const QFont::Weight& SymbWeight);
~CodeEditorStyle() {}; ~CodeEditorStyle() {};
bool operator==( const CodeEditorStyle& rhs ) const; bool operator==(const CodeEditorStyle& rhs) const;
bool operator!=( const CodeEditorStyle& rhs ) const; bool operator!=(const CodeEditorStyle& rhs) const;
static CodeEditorStyle loadSettings( QSettings *settings ); static CodeEditorStyle loadSettings(QSettings *settings);
static void saveSettings( QSettings *settings, const CodeEditorStyle& theStyle ); static void saveSettings(QSettings *settings, const CodeEditorStyle& theStyle);
public: public:
QColor widgetFGColor; QColor widgetFGColor;

View File

@ -19,96 +19,102 @@
#include "codeeditstylecontrols.h" #include "codeeditstylecontrols.h"
#include <QColorDialog> #include <QColorDialog>
SelectColorButton::SelectColorButton( QWidget* parent ) : SelectColorButton::SelectColorButton(QWidget* parent) :
QPushButton( parent ), QPushButton(parent),
mColor( QColor( 255, 255, 255 )) mColor(QColor(255, 255, 255))
{ {
updateColor(); updateColor();
connect( this, SIGNAL( clicked() ), this, SLOT( changeColor() )); connect(this, SIGNAL(clicked()), this, SLOT(changeColor()));
} }
void SelectColorButton::updateColor() { void SelectColorButton::updateColor()
{
QString btnColorStyle = QString( QString btnColorStyle = QString(
"background-color:rgb(%1,%2,%3);" "background-color:rgb(%1,%2,%3);"
"border-style:outset;" "border-style:outset;"
"border-width: 1px;") "border-width: 1px;")
.arg( mColor.red() ) .arg(mColor.red())
.arg( mColor.green() ) .arg(mColor.green())
.arg( mColor.blue() ); .arg(mColor.blue());
setObjectName("SelectColorButton"); setObjectName("SelectColorButton");
setStyleSheet( btnColorStyle ); setStyleSheet(btnColorStyle);
} }
void SelectColorButton::changeColor() { void SelectColorButton::changeColor()
QColorDialog pDlg( mColor ); {
pDlg.setModal( true ); QColorDialog pDlg(mColor);
pDlg.setModal(true);
int nResult = pDlg.exec(); int nResult = pDlg.exec();
if (nResult == QDialog::Accepted ) if (nResult == QDialog::Accepted) {
{ setColor(pDlg.selectedColor());
setColor( pDlg.selectedColor() ); emit colorChanged(mColor);
emit colorChanged( mColor );
} }
} }
void SelectColorButton::setColor( const QColor& color ) { void SelectColorButton::setColor(const QColor& color)
{
mColor = color; mColor = color;
updateColor(); updateColor();
} }
const QColor& SelectColorButton::getColor() { const QColor& SelectColorButton::getColor()
{
return mColor; return mColor;
} }
SelectFontWeightCombo::SelectFontWeightCombo( QWidget* parent ) : SelectFontWeightCombo::SelectFontWeightCombo(QWidget* parent) :
QComboBox( parent ), QComboBox(parent),
mWeight( QFont::Normal ) mWeight(QFont::Normal)
{ {
addItem( QObject::tr( "Thin" ), addItem(QObject::tr("Thin"),
QVariant( static_cast<int>( QFont::Thin ))); QVariant(static_cast<int>(QFont::Thin)));
addItem( QObject::tr( "ExtraLight" ), addItem(QObject::tr("ExtraLight"),
QVariant( static_cast<int>( QFont::ExtraLight ))); QVariant(static_cast<int>(QFont::ExtraLight)));
addItem( QObject::tr( "Light" ), addItem(QObject::tr("Light"),
QVariant( static_cast<int>( QFont::Light ))); QVariant(static_cast<int>(QFont::Light)));
addItem( QObject::tr( "Normal" ), addItem(QObject::tr("Normal"),
QVariant( static_cast<int>( QFont::Normal ))); QVariant(static_cast<int>(QFont::Normal)));
addItem( QObject::tr( "Medium" ), addItem(QObject::tr("Medium"),
QVariant( static_cast<int>( QFont::Medium ))); QVariant(static_cast<int>(QFont::Medium)));
addItem( QObject::tr( "DemiBold" ), addItem(QObject::tr("DemiBold"),
QVariant( static_cast<int>( QFont::DemiBold ))); QVariant(static_cast<int>(QFont::DemiBold)));
addItem( QObject::tr( "Bold" ), addItem(QObject::tr("Bold"),
QVariant( static_cast<int>( QFont::Bold ))); QVariant(static_cast<int>(QFont::Bold)));
addItem( QObject::tr( "ExtraBold" ), addItem(QObject::tr("ExtraBold"),
QVariant( static_cast<int>( QFont::ExtraBold ))); QVariant(static_cast<int>(QFont::ExtraBold)));
addItem( QObject::tr( "Black" ), addItem(QObject::tr("Black"),
QVariant( static_cast<int>( QFont::Black ))); QVariant(static_cast<int>(QFont::Black)));
updateWeight(); updateWeight();
connect( this, SIGNAL( currentIndexChanged( int )), connect(this, SIGNAL(currentIndexChanged(int)),
this, SLOT( changeWeight( int ))); this, SLOT(changeWeight(int)));
} }
void SelectFontWeightCombo::updateWeight() { void SelectFontWeightCombo::updateWeight()
int nResult = findData( QVariant( static_cast<int>( mWeight ))); {
int nResult = findData(QVariant(static_cast<int>(mWeight)));
if( nResult != -1 ) { if (nResult != -1) {
setCurrentIndex( nResult ); setCurrentIndex(nResult);
} } else {
else { setCurrentIndex(findData(static_cast<int>(QFont::Normal)));
setCurrentIndex( findData( static_cast<int>( QFont::Normal )));
} }
} }
void SelectFontWeightCombo::changeWeight( int index ) { void SelectFontWeightCombo::changeWeight(int index)
if( index != -1 ) { {
setWeight( static_cast<QFont::Weight>( itemData( index ).toInt() )); if (index != -1) {
emit weightChanged( mWeight ); setWeight(static_cast<QFont::Weight>(itemData(index).toInt()));
emit weightChanged(mWeight);
} }
} }
void SelectFontWeightCombo::setWeight( const QFont::Weight& weight ) { void SelectFontWeightCombo::setWeight(const QFont::Weight& weight)
{
mWeight = weight; mWeight = weight;
updateWeight(); updateWeight();
} }
const QFont::Weight& SelectFontWeightCombo::getWeight() { const QFont::Weight& SelectFontWeightCombo::getWeight()
{
return mWeight; return mWeight;
} }

View File

@ -27,18 +27,17 @@
#include <QColor> #include <QColor>
#include <QFont> #include <QFont>
class SelectColorButton : public QPushButton class SelectColorButton : public QPushButton {
{
Q_OBJECT Q_OBJECT
public: public:
explicit SelectColorButton( QWidget* parent ); explicit SelectColorButton(QWidget* parent);
virtual ~SelectColorButton(){}; virtual ~SelectColorButton() {};
void setColor( const QColor& color ); void setColor(const QColor& color);
const QColor& getColor(); const QColor& getColor();
signals: signals:
void colorChanged( QColor& newColor ); void colorChanged(QColor& newColor);
public slots: public slots:
void updateColor(); void updateColor();
@ -49,22 +48,21 @@ private:
}; };
class SelectFontWeightCombo : public QComboBox class SelectFontWeightCombo : public QComboBox {
{
Q_OBJECT Q_OBJECT
public: public:
explicit SelectFontWeightCombo( QWidget* parent ); explicit SelectFontWeightCombo(QWidget* parent);
virtual ~SelectFontWeightCombo() {} virtual ~SelectFontWeightCombo() {}
void setWeight( const QFont::Weight& weight ); void setWeight(const QFont::Weight& weight);
const QFont::Weight& getWeight(); const QFont::Weight& getWeight();
signals: signals:
void weightChanged( QFont::Weight& newWeight ); void weightChanged(QFont::Weight& newWeight);
public slots: public slots:
void updateWeight(); void updateWeight();
void changeWeight( int index ); void changeWeight(int index);
private: private:
QFont::Weight mWeight; QFont::Weight mWeight;

View File

@ -23,200 +23,200 @@
#include <QDialogButtonBox> #include <QDialogButtonBox>
const QString StyleEditDialog::mSampleDocument( const QString StyleEditDialog::mSampleDocument(
"/*****\n" "/*****\n"
"* Multiline Comment\n" "* Multiline Comment\n"
"*****/\n" "*****/\n"
"#include <QApplication>\n" "#include <QApplication>\n"
"#include <iostream>\n" "#include <iostream>\n"
"\n" "\n"
"class fwdClass;\n" "class fwdClass;\n"
"\n" "\n"
"int main(int argc, char *argv[])\n" "int main(int argc, char *argv[])\n"
"{\n" "{\n"
" QApplication a(argc, argv);\n" " QApplication a(argc, argv);\n"
" int nLife = 42;\n" " int nLife = 42;\n"
" w.show();\n" " w.show();\n"
" // single line comment\n" " // single line comment\n"
" // line below is highlighted\n" " // line below is highlighted\n"
" fwdClass( nLife );\n" " fwdClass( nLife );\n"
" return a.exec();\n" " return a.exec();\n"
"}\n" "}\n"
"\n" "\n"
"void class fwdClass( double dValue ) {\n" "void class fwdClass( double dValue ) {\n"
" std::cout << \"Ipsum Lorem: \"\n" " std::cout << \"Ipsum Lorem: \"\n"
" << nValue\n" " << nValue\n"
" << std::endl;\n" " << std::endl;\n"
"}\n"); "}\n");
const QStringList StyleEditDialog::mErrSymbolsList = ( const QStringList StyleEditDialog::mErrSymbolsList = (
QStringList( QStringList() QStringList(QStringList()
<< "nLife" << "nLife"
<< "dValue" << "dValue"
<< "nValue")); << "nValue"));
const int StyleEditDialog::mErrLineNum = 16; const int StyleEditDialog::mErrLineNum = 16;
StyleEditDialog::StyleEditDialog( const CodeEditorStyle& newStyle, StyleEditDialog::StyleEditDialog(const CodeEditorStyle& newStyle,
QWidget *parent /*= nullptr*/ ) : QWidget *parent /*= nullptr*/) :
QDialog( parent ), QDialog(parent),
mStyleIncoming( newStyle ), mStyleIncoming(newStyle),
mStyleOutgoing( newStyle ) mStyleOutgoing(newStyle)
{ {
QVBoxLayout *vboxMain = new QVBoxLayout(this); QVBoxLayout *vboxMain = new QVBoxLayout(this);
QHBoxLayout *hboxEdit = new QHBoxLayout(); QHBoxLayout *hboxEdit = new QHBoxLayout();
// Color/Weight controls // Color/Weight controls
QFormLayout *flEditControls = new QFormLayout(); QFormLayout *flEditControls = new QFormLayout();
mBtnWidgetColorFG = new SelectColorButton( this ); mBtnWidgetColorFG = new SelectColorButton(this);
flEditControls->addRow( QObject::tr("Editor Foreground Color"), flEditControls->addRow(QObject::tr("Editor Foreground Color"),
mBtnWidgetColorFG ); mBtnWidgetColorFG);
mBtnWidgetColorBG = new SelectColorButton( this ); mBtnWidgetColorBG = new SelectColorButton(this);
flEditControls->addRow( QObject::tr("Editor Background Color"), flEditControls->addRow(QObject::tr("Editor Background Color"),
mBtnWidgetColorBG ); mBtnWidgetColorBG);
mBtnHighlightBG = new SelectColorButton( this ); mBtnHighlightBG = new SelectColorButton(this);
flEditControls->addRow( QObject::tr("Highlight Background Color"), flEditControls->addRow(QObject::tr("Highlight Background Color"),
mBtnHighlightBG ); mBtnHighlightBG);
mBtnLineNumFG = new SelectColorButton( this ); mBtnLineNumFG = new SelectColorButton(this);
flEditControls->addRow( QObject::tr("Line Number Foreground Color"), flEditControls->addRow(QObject::tr("Line Number Foreground Color"),
mBtnLineNumFG ); mBtnLineNumFG);
mBtnLineNumBG = new SelectColorButton( this ); mBtnLineNumBG = new SelectColorButton(this);
flEditControls->addRow( QObject::tr("Line Number Background Color"), flEditControls->addRow(QObject::tr("Line Number Background Color"),
mBtnLineNumBG ); mBtnLineNumBG);
mBtnKeywordFG = new SelectColorButton( this ); mBtnKeywordFG = new SelectColorButton(this);
flEditControls->addRow( QObject::tr("Keyword Foreground Color"), flEditControls->addRow(QObject::tr("Keyword Foreground Color"),
mBtnKeywordFG ); mBtnKeywordFG);
mCBKeywordWeight = new SelectFontWeightCombo( this ); mCBKeywordWeight = new SelectFontWeightCombo(this);
flEditControls->addRow( QObject::tr("Keyword Font Weight"), flEditControls->addRow(QObject::tr("Keyword Font Weight"),
mCBKeywordWeight ); mCBKeywordWeight);
mBtnClassFG = new SelectColorButton( this ); mBtnClassFG = new SelectColorButton(this);
flEditControls->addRow( QObject::tr("Class ForegroundColor"), flEditControls->addRow(QObject::tr("Class ForegroundColor"),
mBtnClassFG ); mBtnClassFG);
mCBClassWeight = new SelectFontWeightCombo( this ); mCBClassWeight = new SelectFontWeightCombo(this);
flEditControls->addRow( QObject::tr("Class Font Weight"), flEditControls->addRow(QObject::tr("Class Font Weight"),
mCBClassWeight ); mCBClassWeight);
mBtnQuoteFG = new SelectColorButton( this ); mBtnQuoteFG = new SelectColorButton(this);
flEditControls->addRow( QObject::tr("Quote Foreground Color"), flEditControls->addRow(QObject::tr("Quote Foreground Color"),
mBtnQuoteFG ); mBtnQuoteFG);
mCBQuoteWeight = new SelectFontWeightCombo( this ); mCBQuoteWeight = new SelectFontWeightCombo(this);
flEditControls->addRow( QObject::tr("Quote Font Weight"), flEditControls->addRow(QObject::tr("Quote Font Weight"),
mCBQuoteWeight ); mCBQuoteWeight);
mBtnCommentFG = new SelectColorButton( this ); mBtnCommentFG = new SelectColorButton(this);
flEditControls->addRow( QObject::tr("Comment Foreground Color"), flEditControls->addRow(QObject::tr("Comment Foreground Color"),
mBtnCommentFG ); mBtnCommentFG);
mCBCommentWeight = new SelectFontWeightCombo( this ); mCBCommentWeight = new SelectFontWeightCombo(this);
flEditControls->addRow( QObject::tr("Comment Font Weight"), flEditControls->addRow(QObject::tr("Comment Font Weight"),
mCBCommentWeight ); mCBCommentWeight);
mBtnSymbolFG = new SelectColorButton( this ); mBtnSymbolFG = new SelectColorButton(this);
flEditControls->addRow( QObject::tr("Symbol Foreground Color"), flEditControls->addRow(QObject::tr("Symbol Foreground Color"),
mBtnSymbolFG ); mBtnSymbolFG);
mBtnSymbolBG = new SelectColorButton( this ); mBtnSymbolBG = new SelectColorButton(this);
flEditControls->addRow( QObject::tr("Symbol Background Color"), flEditControls->addRow(QObject::tr("Symbol Background Color"),
mBtnSymbolBG ); mBtnSymbolBG);
mCBSymbolWeight = new SelectFontWeightCombo( this ); mCBSymbolWeight = new SelectFontWeightCombo(this);
flEditControls->addRow( QObject::tr("Symbol Font Weight"), flEditControls->addRow(QObject::tr("Symbol Font Weight"),
mCBSymbolWeight ); mCBSymbolWeight);
hboxEdit->addLayout( flEditControls ); hboxEdit->addLayout(flEditControls);
// CodeEditor to display Style // CodeEditor to display Style
mSampleEditor = new CodeEditor( this ); mSampleEditor = new CodeEditor(this);
QFont sampleFont( "Monospace" ); QFont sampleFont("Monospace");
QFontMetrics fm(sampleFont); QFontMetrics fm(sampleFont);
mSampleEditor->setMinimumWidth( fm.width(QString( 40, 'W' ))); mSampleEditor->setMinimumWidth(fm.width(QString(40, 'W')));
// designate highlight, errors, and symbols // designate highlight, errors, and symbols
mSampleEditor->setError( mSampleDocument, mErrLineNum, mErrSymbolsList); mSampleEditor->setError(mSampleDocument, mErrLineNum, mErrSymbolsList);
// End Controls // End Controls
hboxEdit->addWidget( mSampleEditor ); hboxEdit->addWidget(mSampleEditor);
vboxMain->addLayout( hboxEdit ); vboxMain->addLayout(hboxEdit);
// Default Controls // Default Controls
QHBoxLayout *hboxDefaultControls = new QHBoxLayout(); QHBoxLayout *hboxDefaultControls = new QHBoxLayout();
mBtnDefaultLight = new QPushButton( QObject::tr("Set to Default Light"), mBtnDefaultLight = new QPushButton(QObject::tr("Set to Default Light"),
this ); this);
mBtnDefaultDark = new QPushButton( QObject::tr("Set to Default Dark"), mBtnDefaultDark = new QPushButton(QObject::tr("Set to Default Dark"),
this ); this);
hboxDefaultControls->addStretch( 1 ); hboxDefaultControls->addStretch(1);
hboxDefaultControls->addWidget( mBtnDefaultLight ); hboxDefaultControls->addWidget(mBtnDefaultLight);
hboxDefaultControls->addWidget( mBtnDefaultDark ); hboxDefaultControls->addWidget(mBtnDefaultDark);
hboxDefaultControls->addStretch( 1 ); hboxDefaultControls->addStretch(1);
vboxMain->addLayout( hboxDefaultControls ); vboxMain->addLayout(hboxDefaultControls);
vboxMain->addStretch( 2 ); vboxMain->addStretch(2);
// dialog controls // dialog controls
QDialogButtonBox *dBtnBox = new QDialogButtonBox( QDialogButtonBox *dBtnBox = new QDialogButtonBox(
QDialogButtonBox::Cancel | QDialogButtonBox::Cancel |
QDialogButtonBox::Ok | QDialogButtonBox::Ok |
QDialogButtonBox::Reset ); QDialogButtonBox::Reset);
vboxMain->addStretch( 1 ); vboxMain->addStretch(1);
vboxMain->addWidget( dBtnBox ); vboxMain->addWidget(dBtnBox);
// setup values for style controls // setup values for style controls
updateControls(); updateControls();
updateStyle(); updateStyle();
connect( dBtnBox, SIGNAL( accepted() ), this, SLOT( accept() )); connect(dBtnBox, SIGNAL(accepted()), this, SLOT(accept()));
connect( dBtnBox, SIGNAL( rejected() ), this, SLOT( reject() )); connect(dBtnBox, SIGNAL(rejected()), this, SLOT(reject()));
connect( dBtnBox->button( QDialogButtonBox::Reset ), SIGNAL(clicked()), connect(dBtnBox->button(QDialogButtonBox::Reset), SIGNAL(clicked()),
this, SLOT( resetStyle() )); this, SLOT(resetStyle()));
connect( mBtnDefaultLight, SIGNAL( clicked() ), connect(mBtnDefaultLight, SIGNAL(clicked()),
this, SLOT( setStyleDefaultLight() )); this, SLOT(setStyleDefaultLight()));
connect( mBtnDefaultDark, SIGNAL( clicked() ), connect(mBtnDefaultDark, SIGNAL(clicked()),
this, SLOT( setStyleDefaultDark() )); this, SLOT(setStyleDefaultDark()));
connect( mBtnWidgetColorFG, SIGNAL( colorChanged( QColor& )), connect(mBtnWidgetColorFG, SIGNAL(colorChanged(QColor&)),
this, SLOT( colorChangedWidgetFG( QColor& ))); this, SLOT(colorChangedWidgetFG(QColor&)));
connect( mBtnWidgetColorBG, SIGNAL( colorChanged( QColor& )), connect(mBtnWidgetColorBG, SIGNAL(colorChanged(QColor&)),
this, SLOT( colorChangedWidgetBG( QColor& ))); this, SLOT(colorChangedWidgetBG(QColor&)));
connect( mBtnHighlightBG, SIGNAL( colorChanged( QColor& )), connect(mBtnHighlightBG, SIGNAL(colorChanged(QColor&)),
this, SLOT( colorChangedHighlightBG( QColor& ))); this, SLOT(colorChangedHighlightBG(QColor&)));
connect( mBtnLineNumFG, SIGNAL( colorChanged( QColor& )), connect(mBtnLineNumFG, SIGNAL(colorChanged(QColor&)),
this, SLOT( colorChangedLineNumFG( QColor& ))); this, SLOT(colorChangedLineNumFG(QColor&)));
connect( mBtnLineNumBG, SIGNAL( colorChanged( QColor& )), connect(mBtnLineNumBG, SIGNAL(colorChanged(QColor&)),
this, SLOT( colorChangedLineNumBG( QColor& ))); this, SLOT(colorChangedLineNumBG(QColor&)));
connect( mBtnKeywordFG, SIGNAL( colorChanged( QColor& )), connect(mBtnKeywordFG, SIGNAL(colorChanged(QColor&)),
this, SLOT( colorChangedKeywordFG( QColor& ))); this, SLOT(colorChangedKeywordFG(QColor&)));
connect( mCBKeywordWeight, SIGNAL( weightChanged( QFont::Weight& )), connect(mCBKeywordWeight, SIGNAL(weightChanged(QFont::Weight&)),
this, SLOT( weightChangedKeyword( QFont::Weight& ))); this, SLOT(weightChangedKeyword(QFont::Weight&)));
connect( mBtnClassFG, SIGNAL( colorChanged( QColor& )), connect(mBtnClassFG, SIGNAL(colorChanged(QColor&)),
this, SLOT( colorChangedClassFG( QColor& ))); this, SLOT(colorChangedClassFG(QColor&)));
connect( mCBClassWeight, SIGNAL( weightChanged( QFont::Weight& )), connect(mCBClassWeight, SIGNAL(weightChanged(QFont::Weight&)),
this, SLOT( weightChangedClass( QFont::Weight& ))); this, SLOT(weightChangedClass(QFont::Weight&)));
connect( mBtnQuoteFG, SIGNAL( colorChanged( QColor& )), connect(mBtnQuoteFG, SIGNAL(colorChanged(QColor&)),
this, SLOT( colorChangedQuoteFG( QColor& ))); this, SLOT(colorChangedQuoteFG(QColor&)));
connect( mCBQuoteWeight, SIGNAL( weightChanged( QFont::Weight& )), connect(mCBQuoteWeight, SIGNAL(weightChanged(QFont::Weight&)),
this, SLOT( weightChangedQuote( QFont::Weight& ))); this, SLOT(weightChangedQuote(QFont::Weight&)));
connect( mBtnCommentFG, SIGNAL( colorChanged( QColor& )), connect(mBtnCommentFG, SIGNAL(colorChanged(QColor&)),
this, SLOT( colorChangedCommentFG( QColor& ))); this, SLOT(colorChangedCommentFG(QColor&)));
connect( mCBCommentWeight, SIGNAL( weightChanged( QFont::Weight& )), connect(mCBCommentWeight, SIGNAL(weightChanged(QFont::Weight&)),
this, SLOT( weightChangedComment( QFont::Weight& ))); this, SLOT(weightChangedComment(QFont::Weight&)));
connect( mBtnSymbolFG, SIGNAL( colorChanged( QColor& )), connect(mBtnSymbolFG, SIGNAL(colorChanged(QColor&)),
this, SLOT( colorChangedSymbolFG( QColor& ))); this, SLOT(colorChangedSymbolFG(QColor&)));
connect( mBtnSymbolBG, SIGNAL( colorChanged( QColor& )), connect(mBtnSymbolBG, SIGNAL(colorChanged(QColor&)),
this, SLOT( colorChangedSymbolBG( QColor& ))); this, SLOT(colorChangedSymbolBG(QColor&)));
connect( mCBSymbolWeight, SIGNAL( weightChanged( QFont::Weight& )), connect(mCBSymbolWeight, SIGNAL(weightChanged(QFont::Weight&)),
this, SLOT( weightChangedSymbol( QFont::Weight& ))); this, SLOT(weightChangedSymbol(QFont::Weight&)));
} }
void StyleEditDialog::updateControls() void StyleEditDialog::updateControls()
{ {
mBtnWidgetColorFG->setColor( mStyleOutgoing.widgetFGColor ); mBtnWidgetColorFG->setColor(mStyleOutgoing.widgetFGColor);
mBtnWidgetColorBG->setColor( mStyleOutgoing.widgetBGColor ); mBtnWidgetColorBG->setColor(mStyleOutgoing.widgetBGColor);
mBtnHighlightBG->setColor( mStyleOutgoing.highlightBGColor ); mBtnHighlightBG->setColor(mStyleOutgoing.highlightBGColor);
mBtnLineNumFG->setColor( mStyleOutgoing.lineNumFGColor ); mBtnLineNumFG->setColor(mStyleOutgoing.lineNumFGColor);
mBtnLineNumBG->setColor( mStyleOutgoing.lineNumBGColor ); mBtnLineNumBG->setColor(mStyleOutgoing.lineNumBGColor);
mBtnKeywordFG->setColor( mStyleOutgoing.keywordColor ); mBtnKeywordFG->setColor(mStyleOutgoing.keywordColor);
mCBKeywordWeight->setWeight( mStyleOutgoing.keywordWeight ); mCBKeywordWeight->setWeight(mStyleOutgoing.keywordWeight);
mBtnClassFG->setColor( mStyleOutgoing.classColor ); mBtnClassFG->setColor(mStyleOutgoing.classColor);
mCBClassWeight->setWeight( mStyleOutgoing.classWeight ); mCBClassWeight->setWeight(mStyleOutgoing.classWeight);
mBtnQuoteFG->setColor( mStyleOutgoing.quoteColor ); mBtnQuoteFG->setColor(mStyleOutgoing.quoteColor);
mCBQuoteWeight->setWeight( mStyleOutgoing.quoteWeight ); mCBQuoteWeight->setWeight(mStyleOutgoing.quoteWeight);
mBtnCommentFG->setColor( mStyleOutgoing.commentColor ); mBtnCommentFG->setColor(mStyleOutgoing.commentColor);
mCBCommentWeight->setWeight( mStyleOutgoing.commentWeight ); mCBCommentWeight->setWeight(mStyleOutgoing.commentWeight);
mBtnSymbolFG->setColor( mStyleOutgoing.symbolFGColor ); mBtnSymbolFG->setColor(mStyleOutgoing.symbolFGColor);
mBtnSymbolBG->setColor( mStyleOutgoing.symbolBGColor ); mBtnSymbolBG->setColor(mStyleOutgoing.symbolBGColor);
mCBSymbolWeight->setWeight( mStyleOutgoing.symbolWeight ); mCBSymbolWeight->setWeight(mStyleOutgoing.symbolWeight);
} }
void StyleEditDialog::updateStyle() void StyleEditDialog::updateStyle()
{ {
mBtnDefaultLight->setEnabled( mStyleOutgoing != defaultStyleLight ); mBtnDefaultLight->setEnabled(mStyleOutgoing != defaultStyleLight);
mBtnDefaultDark->setEnabled( mStyleOutgoing != defaultStyleDark ); mBtnDefaultDark->setEnabled(mStyleOutgoing != defaultStyleDark);
// set Editor Styling // set Editor Styling
mSampleEditor->setStyle( mStyleOutgoing ); mSampleEditor->setStyle(mStyleOutgoing);
} }
CodeEditorStyle StyleEditDialog::getStyle() CodeEditorStyle StyleEditDialog::getStyle()
@ -245,97 +245,97 @@ void StyleEditDialog::setStyleDefaultDark()
updateStyle(); updateStyle();
} }
void StyleEditDialog::colorChangedWidgetFG( QColor& newColor ) void StyleEditDialog::colorChangedWidgetFG(QColor& newColor)
{ {
mStyleOutgoing.widgetFGColor = newColor; mStyleOutgoing.widgetFGColor = newColor;
updateStyle(); updateStyle();
} }
void StyleEditDialog::colorChangedWidgetBG( QColor& newColor ) void StyleEditDialog::colorChangedWidgetBG(QColor& newColor)
{ {
mStyleOutgoing.widgetBGColor = newColor; mStyleOutgoing.widgetBGColor = newColor;
updateStyle(); updateStyle();
} }
void StyleEditDialog::colorChangedHighlightBG( QColor& newColor ) void StyleEditDialog::colorChangedHighlightBG(QColor& newColor)
{ {
mStyleOutgoing.highlightBGColor = newColor; mStyleOutgoing.highlightBGColor = newColor;
updateStyle(); updateStyle();
} }
void StyleEditDialog::colorChangedLineNumFG( QColor& newColor ) void StyleEditDialog::colorChangedLineNumFG(QColor& newColor)
{ {
mStyleOutgoing.lineNumFGColor = newColor; mStyleOutgoing.lineNumFGColor = newColor;
updateStyle(); updateStyle();
} }
void StyleEditDialog::colorChangedLineNumBG( QColor& newColor ) void StyleEditDialog::colorChangedLineNumBG(QColor& newColor)
{ {
mStyleOutgoing.lineNumBGColor = newColor; mStyleOutgoing.lineNumBGColor = newColor;
updateStyle(); updateStyle();
} }
void StyleEditDialog::colorChangedKeywordFG( QColor& newColor ) void StyleEditDialog::colorChangedKeywordFG(QColor& newColor)
{ {
mStyleOutgoing.keywordColor = newColor; mStyleOutgoing.keywordColor = newColor;
updateStyle(); updateStyle();
} }
void StyleEditDialog::weightChangedKeyword( QFont::Weight& newWeight ) void StyleEditDialog::weightChangedKeyword(QFont::Weight& newWeight)
{ {
mStyleOutgoing.keywordWeight = newWeight; mStyleOutgoing.keywordWeight = newWeight;
updateStyle(); updateStyle();
} }
void StyleEditDialog::colorChangedClassFG( QColor& newColor ) void StyleEditDialog::colorChangedClassFG(QColor& newColor)
{ {
mStyleOutgoing.classColor = newColor; mStyleOutgoing.classColor = newColor;
updateStyle(); updateStyle();
} }
void StyleEditDialog::weightChangedClass( QFont::Weight& newWeight ) void StyleEditDialog::weightChangedClass(QFont::Weight& newWeight)
{ {
mStyleOutgoing.classWeight = newWeight; mStyleOutgoing.classWeight = newWeight;
updateStyle(); updateStyle();
} }
void StyleEditDialog::colorChangedQuoteFG( QColor& newColor ) void StyleEditDialog::colorChangedQuoteFG(QColor& newColor)
{ {
mStyleOutgoing.quoteColor = newColor; mStyleOutgoing.quoteColor = newColor;
updateStyle(); updateStyle();
} }
void StyleEditDialog::weightChangedQuote( QFont::Weight& newWeight ) void StyleEditDialog::weightChangedQuote(QFont::Weight& newWeight)
{ {
mStyleOutgoing.quoteWeight = newWeight; mStyleOutgoing.quoteWeight = newWeight;
updateStyle(); updateStyle();
} }
void StyleEditDialog::colorChangedCommentFG( QColor& newColor ) void StyleEditDialog::colorChangedCommentFG(QColor& newColor)
{ {
mStyleOutgoing.commentColor = newColor; mStyleOutgoing.commentColor = newColor;
updateStyle(); updateStyle();
} }
void StyleEditDialog::weightChangedComment( QFont::Weight& newWeight ) void StyleEditDialog::weightChangedComment(QFont::Weight& newWeight)
{ {
mStyleOutgoing.commentWeight = newWeight; mStyleOutgoing.commentWeight = newWeight;
updateStyle(); updateStyle();
} }
void StyleEditDialog::colorChangedSymbolFG( QColor& newColor ) void StyleEditDialog::colorChangedSymbolFG(QColor& newColor)
{ {
mStyleOutgoing.symbolFGColor = newColor; mStyleOutgoing.symbolFGColor = newColor;
updateStyle(); updateStyle();
} }
void StyleEditDialog::colorChangedSymbolBG( QColor& newColor ) void StyleEditDialog::colorChangedSymbolBG(QColor& newColor)
{ {
mStyleOutgoing.symbolBGColor = newColor; mStyleOutgoing.symbolBGColor = newColor;
updateStyle(); updateStyle();
} }
void StyleEditDialog::weightChangedSymbol( QFont::Weight& newWeight ) void StyleEditDialog::weightChangedSymbol(QFont::Weight& newWeight)
{ {
mStyleOutgoing.symbolWeight = newWeight; mStyleOutgoing.symbolWeight = newWeight;
updateStyle(); updateStyle();

View File

@ -25,12 +25,11 @@
#include "codeeditor.h" #include "codeeditor.h"
#include "codeeditorstyle.h" #include "codeeditorstyle.h"
class StyleEditDialog : public QDialog class StyleEditDialog : public QDialog {
{
Q_OBJECT Q_OBJECT
public: public:
explicit StyleEditDialog( const CodeEditorStyle& newStyle, explicit StyleEditDialog(const CodeEditorStyle& newStyle,
QWidget *parent = nullptr); QWidget *parent = nullptr);
virtual ~StyleEditDialog() {}; virtual ~StyleEditDialog() {};
CodeEditorStyle getStyle(); CodeEditorStyle getStyle();
@ -43,22 +42,22 @@ public slots:
void resetStyle(); void resetStyle();
void setStyleDefaultLight(); void setStyleDefaultLight();
void setStyleDefaultDark(); void setStyleDefaultDark();
void colorChangedWidgetFG( QColor& newColor ); void colorChangedWidgetFG(QColor& newColor);
void colorChangedWidgetBG( QColor& newColor ); void colorChangedWidgetBG(QColor& newColor);
void colorChangedHighlightBG( QColor& newColor ); void colorChangedHighlightBG(QColor& newColor);
void colorChangedLineNumFG( QColor& newColor ); void colorChangedLineNumFG(QColor& newColor);
void colorChangedLineNumBG( QColor& newColor ); void colorChangedLineNumBG(QColor& newColor);
void colorChangedKeywordFG( QColor& newColor ); void colorChangedKeywordFG(QColor& newColor);
void weightChangedKeyword( QFont::Weight& newWeight ); void weightChangedKeyword(QFont::Weight& newWeight);
void colorChangedClassFG( QColor& newColor ); void colorChangedClassFG(QColor& newColor);
void weightChangedClass( QFont::Weight& newWeight ); void weightChangedClass(QFont::Weight& newWeight);
void colorChangedQuoteFG( QColor& newColor ); void colorChangedQuoteFG(QColor& newColor);
void weightChangedQuote( QFont::Weight& newWeight ); void weightChangedQuote(QFont::Weight& newWeight);
void colorChangedCommentFG( QColor& newColor ); void colorChangedCommentFG(QColor& newColor);
void weightChangedComment( QFont::Weight& newWeight ); void weightChangedComment(QFont::Weight& newWeight);
void colorChangedSymbolFG( QColor& newColor ); void colorChangedSymbolFG(QColor& newColor);
void colorChangedSymbolBG( QColor& newColor ); void colorChangedSymbolBG(QColor& newColor);
void weightChangedSymbol( QFont::Weight& newWeight ); void weightChangedSymbol(QFont::Weight& newWeight);
private: private:
CodeEditorStyle mStyleIncoming; CodeEditorStyle mStyleIncoming;

View File

@ -1007,7 +1007,7 @@ void MainWindow::programSettings()
dialog.showNoErrorsMessage(), dialog.showNoErrorsMessage(),
dialog.showErrorId(), dialog.showErrorId(),
dialog.showInconclusive()); dialog.showInconclusive());
mUI.mResults->updateStyleSetting( mSettings ); mUI.mResults->updateStyleSetting(mSettings);
const QString newLang = mSettings->value(SETTINGS_LANGUAGE, "en").toString(); const QString newLang = mSettings->value(SETTINGS_LANGUAGE, "en").toString();
setLanguage(newLang); setLanguage(newLang);
} }

View File

@ -70,8 +70,8 @@ void ResultsView::initialize(QSettings *settings, ApplicationList *list, ThreadH
mUI.mProgress->setMinimum(0); mUI.mProgress->setMinimum(0);
mUI.mProgress->setVisible(false); mUI.mProgress->setVisible(false);
CodeEditorStyle theStyle( CodeEditorStyle::loadSettings( settings )); CodeEditorStyle theStyle(CodeEditorStyle::loadSettings(settings));
mUI.mCode->setStyle( theStyle ); mUI.mCode->setStyle(theStyle);
QByteArray state = settings->value(SETTINGS_MAINWND_SPLITTER_STATE).toByteArray(); QByteArray state = settings->value(SETTINGS_MAINWND_SPLITTER_STATE).toByteArray();
mUI.mVerticalSplitter->restoreState(state); mUI.mVerticalSplitter->restoreState(state);
@ -240,10 +240,10 @@ void ResultsView::updateSettings(bool showFullPath,
mShowNoErrorsMessage = showNoErrorsMessage; mShowNoErrorsMessage = showNoErrorsMessage;
} }
void ResultsView::updateStyleSetting( QSettings *settings ) void ResultsView::updateStyleSetting(QSettings *settings)
{ {
CodeEditorStyle theStyle( CodeEditorStyle::loadSettings( settings )); CodeEditorStyle theStyle(CodeEditorStyle::loadSettings(settings));
mUI.mCode->setStyle( theStyle ); mUI.mCode->setStyle(theStyle);
} }
void ResultsView::setCheckDirectory(const QString &dir) void ResultsView::setCheckDirectory(const QString &dir)

View File

@ -115,7 +115,7 @@ public:
* *
* @param settings Pointer to QSettings Object * @param settings Pointer to QSettings Object
*/ */
void updateStyleSetting( QSettings *settings ); void updateStyleSetting(QSettings *settings);
/** /**
* @brief Set the directory we are checking * @brief Set the directory we are checking

View File

@ -66,7 +66,7 @@ SettingsDialog::SettingsDialog(ApplicationList *list,
#else #else
mUI.mTabClang->setVisible(false); mUI.mTabClang->setVisible(false);
#endif #endif
mCurrentStyle = new CodeEditorStyle( CodeEditorStyle::loadSettings( &settings )); mCurrentStyle = new CodeEditorStyle(CodeEditorStyle::loadSettings(&settings));
manageStyleControls(); manageStyleControls();
connect(mUI.mButtons, &QDialogButtonBox::accepted, this, &SettingsDialog::ok); connect(mUI.mButtons, &QDialogButtonBox::accepted, this, &SettingsDialog::ok);
@ -84,10 +84,10 @@ SettingsDialog::SettingsDialog(ApplicationList *list,
connect(mUI.mBtnBrowsePythonPath, &QPushButton::clicked, this, &SettingsDialog::browsePythonPath); connect(mUI.mBtnBrowsePythonPath, &QPushButton::clicked, this, &SettingsDialog::browsePythonPath);
connect(mUI.mBtnBrowseMisraFile, &QPushButton::clicked, this, &SettingsDialog::browseMisraFile); connect(mUI.mBtnBrowseMisraFile, &QPushButton::clicked, this, &SettingsDialog::browseMisraFile);
connect(mUI.btnEditCustom, SIGNAL( clicked() ), this, SLOT( editCodeEditorStyle() )); connect(mUI.btnEditCustom, SIGNAL(clicked()), this, SLOT(editCodeEditorStyle()));
connect(mUI.choiceLight, SIGNAL( released() ), this, SLOT( setCodeEditorStyleDefault() )); connect(mUI.choiceLight, SIGNAL(released()), this, SLOT(setCodeEditorStyleDefault()));
connect(mUI.choiceDark, SIGNAL( released() ), this, SLOT( setCodeEditorStyleDefault() )); connect(mUI.choiceDark, SIGNAL(released()), this, SLOT(setCodeEditorStyleDefault()));
connect(mUI.choiceCustom, SIGNAL( toggled( bool )), mUI.btnEditCustom, SLOT( setEnabled( bool ))); connect(mUI.choiceCustom, SIGNAL(toggled(bool)), mUI.btnEditCustom, SLOT(setEnabled(bool)));
mUI.mListWidget->setSortingEnabled(false); mUI.mListWidget->setSortingEnabled(false);
populateApplicationList(); populateApplicationList();
@ -184,7 +184,7 @@ void SettingsDialog::saveSettingValues() const
const QString langcode = currentLang->data(mLangCodeRole).toString(); const QString langcode = currentLang->data(mLangCodeRole).toString();
settings.setValue(SETTINGS_LANGUAGE, langcode); settings.setValue(SETTINGS_LANGUAGE, langcode);
} }
CodeEditorStyle::saveSettings(&settings, *mCurrentStyle ); CodeEditorStyle::saveSettings(&settings, *mCurrentStyle);
} }
@ -330,18 +330,17 @@ void SettingsDialog::browseMisraFile()
// Slot to set default light style // Slot to set default light style
void SettingsDialog::setCodeEditorStyleDefault() void SettingsDialog::setCodeEditorStyleDefault()
{ {
if( mUI.choiceLight->isChecked() ) *mCurrentStyle = defaultStyleLight; if (mUI.choiceLight->isChecked()) *mCurrentStyle = defaultStyleLight;
if( mUI.choiceDark->isChecked() ) *mCurrentStyle = defaultStyleDark; if (mUI.choiceDark->isChecked()) *mCurrentStyle = defaultStyleDark;
manageStyleControls(); manageStyleControls();
} }
// Slot to edit custom style // Slot to edit custom style
void SettingsDialog::editCodeEditorStyle() void SettingsDialog::editCodeEditorStyle()
{ {
StyleEditDialog pDlg( *mCurrentStyle, this ); StyleEditDialog pDlg(*mCurrentStyle, this);
int nResult = pDlg.exec(); int nResult = pDlg.exec();
if( nResult == QDialog::Accepted ) if (nResult == QDialog::Accepted) {
{
*mCurrentStyle = pDlg.getStyle(); *mCurrentStyle = pDlg.getStyle();
manageStyleControls(); manageStyleControls();
} }
@ -362,8 +361,8 @@ void SettingsDialog::manageStyleControls()
{ {
bool isDefaultLight = *mCurrentStyle == defaultStyleLight; bool isDefaultLight = *mCurrentStyle == defaultStyleLight;
bool isDefaultDark = *mCurrentStyle == defaultStyleDark; bool isDefaultDark = *mCurrentStyle == defaultStyleDark;
mUI.choiceLight->setChecked( isDefaultLight && !isDefaultDark ); mUI.choiceLight->setChecked(isDefaultLight && !isDefaultDark);
mUI.choiceDark->setChecked( !isDefaultLight && isDefaultDark ); mUI.choiceDark->setChecked(!isDefaultLight && isDefaultDark);
mUI.choiceCustom->setChecked( !isDefaultLight && !isDefaultDark ); mUI.choiceCustom->setChecked(!isDefaultLight && !isDefaultDark);
mUI.btnEditCustom->setEnabled( !isDefaultLight && !isDefaultDark ); mUI.btnEditCustom->setEnabled(!isDefaultLight && !isDefaultDark);
} }