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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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