Cppcheck
codeeditorstyle.h
Go to the documentation of this file.
1 /*
2  * Cppcheck - A tool for static C/C++ code analysis
3  * Copyright (C) 2007-2023 Cppcheck team.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef CODEEDITORSTYLE_H
20 #define CODEEDITORSTYLE_H
21 
22 #include <QColor>
23 #include <QFont>
24 #include <QString>
25 #include <Qt>
26 
27 const QString SETTINGS_STYLE_GROUP("EditorStyle");
28 const QString SETTINGS_STYLE_TYPE("StyleType");
29 const QString SETTINGS_STYLE_TYPE_LIGHT("DefaultLight");
30 const QString SETTINGS_STYLE_TYPE_DARK("DefaultDark");
31 const QString SETTINGS_STYLE_TYPE_CUSTOM("Custom");
32 const QString SETTINGS_STYLE_WIDGETFG("StyleWidgetFG");
33 const QString SETTINGS_STYLE_WIDGETBG("StyleWidgetBG");
34 const QString SETTINGS_STYLE_HILIFG("StyleHighlightFG");
35 const QString SETTINGS_STYLE_LINENUMFG("StyleLineNumFG");
36 const QString SETTINGS_STYLE_LINENUMBG("StyleLineNumBG");
37 const QString SETTINGS_STYLE_KEYWORDFG("StyleKeywordFG");
38 const QString SETTINGS_STYLE_KEYWORDWT("StyleKeywordWeight");
39 const QString SETTINGS_STYLE_CLASSFG("StyleClassFG");
40 const QString SETTINGS_STYLE_CLASSWT("StyleClassWeight");
41 const QString SETTINGS_STYLE_QUOTEFG("StyleQuoteFG");
42 const QString SETTINGS_STYLE_QUOTEWT("StyleQuoteWeight");
43 const QString SETTINGS_STYLE_COMMENTFG("StyleCommentFG");
44 const QString SETTINGS_STYLE_COMMENTWT("StyleCommentWeight");
45 const QString SETTINGS_STYLE_SYMBOLFG("StyleSymbolFG");
46 const QString SETTINGS_STYLE_SYMBOLBG("StyleSymbolBG");
47 const QString SETTINGS_STYLE_SYMBOLWT("StyleSymbolWeight");
48 
49 class QSettings;
50 
52 public:
53  explicit CodeEditorStyle(
54  // cppcheck-suppress naming-varname - TODO: fix this
55  QColor CtrlFGColor, QColor CtrlBGColor,
56  // cppcheck-suppress naming-varname - TODO: fix this
57  QColor HiLiBGColor,
58  // cppcheck-suppress naming-varname - TODO: fix this
59  QColor LnNumFGColor, QColor LnNumBGColor,
60  // cppcheck-suppress naming-varname - TODO: fix this
61  QColor KeyWdFGColor, QFont::Weight KeyWdWeight,
62  // cppcheck-suppress naming-varname - TODO: fix this
63  QColor ClsFGColor, QFont::Weight ClsWeight,
64  // cppcheck-suppress naming-varname - TODO: fix this
65  QColor QteFGColor, QFont::Weight QteWeight,
66  // cppcheck-suppress naming-varname - TODO: fix this
67  QColor CmtFGColor, QFont::Weight CmtWeight,
68  // cppcheck-suppress naming-varname - TODO: fix this
69  QColor SymbFGColor, QColor SymbBGColor,
70  // cppcheck-suppress naming-varname - TODO: fix this
71  QFont::Weight SymbWeight);
72 
73  bool operator==(const CodeEditorStyle& rhs) const;
74  bool operator!=(const CodeEditorStyle& rhs) const;
75 
76  bool isSystemTheme() const {
77  return mSystemTheme;
78  }
79 
81  static CodeEditorStyle loadSettings(QSettings *settings);
82  static void saveSettings(QSettings *settings, const CodeEditorStyle& theStyle);
83 
84 public:
85  bool mSystemTheme{};
86  QColor widgetFGColor;
87  QColor widgetBGColor;
91  QColor keywordColor;
92  QFont::Weight keywordWeight;
93  QColor classColor;
94  QFont::Weight classWeight;
95  QColor quoteColor;
96  QFont::Weight quoteWeight;
97  QColor commentColor;
98  QFont::Weight commentWeight;
99  QColor symbolFGColor;
101  QFont::Weight symbolWeight;
102 };
103 
105  /* editor FG/BG */ Qt::black, QColor(240, 240, 240),
106  /* highlight BG */ QColor(255, 220, 220),
107  /* line number FG/BG */ Qt::black, QColor(240, 240, 240),
108  /* keyword FG/Weight */ Qt::darkBlue, QFont::Bold,
109  /* class FG/Weight */ Qt::darkMagenta, QFont::Bold,
110  /* quote FG/Weight */ Qt::darkGreen, QFont::Normal,
111  /* comment FG/Weight */ Qt::gray, QFont::Normal,
112  /* Symbol FG/BG/Weight */ Qt::red, QColor(220, 220, 255), QFont::Normal
113  );
114 
115 // Styling derived from Eclipse Color Theme - 'RecognEyes'
116 // http://www.eclipsecolorthemes.org/?view=theme&id=30
118  /* editor FG/BG */ QColor(218, 218, 218), QColor(16, 16, 32),
119  /* highlight BG */ QColor(64, 64, 64),
120  /* line number FG/BG */ QColor(43, 145, 175), QColor(16, 16, 32),
121  /* keyword FG/Weight */ QColor(0, 204, 204), QFont::Bold,
122  /* class FG/Weight */ QColor(218, 0, 218), QFont::Bold,
123  /* quote FG/Weight */ QColor(0, 204, 0), QFont::Normal,
124  /* comment FG/Weight */ QColor(180, 180, 180), QFont::Normal,
125  /* Symbol FG/BG/Weight */ QColor(218, 32, 32), QColor(32, 32, 108), QFont::Normal
126  );
127 
128 #endif /* CODEEDITORSTYLE_H */
static void saveSettings(QSettings *settings, const CodeEditorStyle &theStyle)
QFont::Weight classWeight
QFont::Weight commentWeight
static CodeEditorStyle getSystemTheme()
QFont::Weight quoteWeight
static CodeEditorStyle loadSettings(QSettings *settings)
QFont::Weight symbolWeight
bool isSystemTheme() const
bool operator==(const CodeEditorStyle &rhs) const
bool operator!=(const CodeEditorStyle &rhs) const
CodeEditorStyle(QColor CtrlFGColor, QColor CtrlBGColor, QColor HiLiBGColor, QColor LnNumFGColor, QColor LnNumBGColor, QColor KeyWdFGColor, QFont::Weight KeyWdWeight, QColor ClsFGColor, QFont::Weight ClsWeight, QColor QteFGColor, QFont::Weight QteWeight, QColor CmtFGColor, QFont::Weight CmtWeight, QColor SymbFGColor, QColor SymbBGColor, QFont::Weight SymbWeight)
QFont::Weight keywordWeight
const QString SETTINGS_STYLE_SYMBOLFG("StyleSymbolFG")
const QString SETTINGS_STYLE_GROUP("EditorStyle")
const QString SETTINGS_STYLE_QUOTEFG("StyleQuoteFG")
const QString SETTINGS_STYLE_KEYWORDFG("StyleKeywordFG")
const QString SETTINGS_STYLE_TYPE_CUSTOM("Custom")
const QString SETTINGS_STYLE_LINENUMFG("StyleLineNumFG")
const QString SETTINGS_STYLE_QUOTEWT("StyleQuoteWeight")
const QString SETTINGS_STYLE_KEYWORDWT("StyleKeywordWeight")
const QString SETTINGS_STYLE_TYPE("StyleType")
const QString SETTINGS_STYLE_TYPE_DARK("DefaultDark")
const QString SETTINGS_STYLE_SYMBOLWT("StyleSymbolWeight")
const QString SETTINGS_STYLE_HILIFG("StyleHighlightFG")
const QString SETTINGS_STYLE_LINENUMBG("StyleLineNumBG")
const QString SETTINGS_STYLE_TYPE_LIGHT("DefaultLight")
const QString SETTINGS_STYLE_SYMBOLBG("StyleSymbolBG")
static const CodeEditorStyle defaultStyleLight(Qt::black, QColor(240, 240, 240), QColor(255, 220, 220), Qt::black, QColor(240, 240, 240), Qt::darkBlue, QFont::Bold, Qt::darkMagenta, QFont::Bold, Qt::darkGreen, QFont::Normal, Qt::gray, QFont::Normal, Qt::red, QColor(220, 220, 255), QFont::Normal)
const QString SETTINGS_STYLE_WIDGETBG("StyleWidgetBG")
const QString SETTINGS_STYLE_CLASSWT("StyleClassWeight")
const QString SETTINGS_STYLE_CLASSFG("StyleClassFG")
const QString SETTINGS_STYLE_COMMENTFG("StyleCommentFG")
const QString SETTINGS_STYLE_WIDGETFG("StyleWidgetFG")
const QString SETTINGS_STYLE_COMMENTWT("StyleCommentWeight")
static const CodeEditorStyle defaultStyleDark(QColor(218, 218, 218), QColor(16, 16, 32), QColor(64, 64, 64), QColor(43, 145, 175), QColor(16, 16, 32), QColor(0, 204, 204), QFont::Bold, QColor(218, 0, 218), QFont::Bold, QColor(0, 204, 0), QFont::Normal, QColor(180, 180, 180), QFont::Normal, QColor(218, 32, 32), QColor(32, 32, 108), QFont::Normal)