File: codeeditorstyle.h

package info (click to toggle)
cppcheck 2.17.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 25,384 kB
  • sloc: cpp: 263,341; python: 19,737; ansic: 7,953; sh: 1,018; makefile: 996; xml: 994; cs: 291
file content (128 lines) | stat: -rw-r--r-- 5,203 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* -*- C++ -*-
 * Cppcheck - A tool for static C/C++ code analysis
 * Copyright (C) 2007-2024 Cppcheck team.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef CODEEDITORSTYLE_H
#define CODEEDITORSTYLE_H

#include <QColor>
#include <QFont>
#include <QString>
#include <Qt>

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;

class CodeEditorStyle {
public:
    explicit CodeEditorStyle(
        // cppcheck-suppress naming-varname - TODO: fix this
        QColor CtrlFGColor, QColor CtrlBGColor,
        // cppcheck-suppress naming-varname - TODO: fix this
        QColor HiLiBGColor,
        // cppcheck-suppress naming-varname - TODO: fix this
        QColor LnNumFGColor, QColor LnNumBGColor,
        // cppcheck-suppress naming-varname - TODO: fix this
        QColor KeyWdFGColor, QFont::Weight KeyWdWeight,
        // cppcheck-suppress naming-varname - TODO: fix this
        QColor ClsFGColor, QFont::Weight ClsWeight,
        // cppcheck-suppress naming-varname - TODO: fix this
        QColor QteFGColor, QFont::Weight QteWeight,
        // cppcheck-suppress naming-varname - TODO: fix this
        QColor CmtFGColor, QFont::Weight CmtWeight,
        // cppcheck-suppress naming-varname - TODO: fix this
        QColor SymbFGColor, QColor SymbBGColor,
        // cppcheck-suppress naming-varname - TODO: fix this
        QFont::Weight SymbWeight);

    bool operator==(const CodeEditorStyle& rhs) const;
    bool operator!=(const CodeEditorStyle& rhs) const;

    bool isSystemTheme() const {
        return mSystemTheme;
    }

    static CodeEditorStyle getSystemTheme();
    static CodeEditorStyle loadSettings(QSettings *settings);
    static void saveSettings(QSettings *settings, const CodeEditorStyle& theStyle);

public:
    bool mSystemTheme{};
    QColor widgetFGColor;
    QColor widgetBGColor;
    QColor highlightBGColor;
    QColor lineNumFGColor;
    QColor lineNumBGColor;
    QColor keywordColor;
    QFont::Weight keywordWeight;
    QColor classColor;
    QFont::Weight classWeight;
    QColor quoteColor;
    QFont::Weight quoteWeight;
    QColor commentColor;
    QFont::Weight commentWeight;
    QColor symbolFGColor;
    QColor symbolBGColor;
    QFont::Weight symbolWeight;
};

static const CodeEditorStyle defaultStyleLight(
    /* editor FG/BG */ Qt::black, QColor(240, 240, 240),
    /* highlight BG */ QColor(255, 220, 220),
    /* line number FG/BG */ Qt::black, QColor(240, 240, 240),
    /* keyword FG/Weight */ Qt::darkBlue, QFont::Bold,
    /* class FG/Weight */ Qt::darkMagenta, QFont::Bold,
    /* quote FG/Weight */ Qt::darkGreen, QFont::Normal,
    /* comment FG/Weight */ Qt::gray, QFont::Normal,
    /* Symbol FG/BG/Weight */ Qt::red, QColor(220, 220, 255), QFont::Normal
    );

// Styling derived from Eclipse Color Theme - 'RecognEyes'
// http://www.eclipsecolorthemes.org/?view=theme&id=30
static const CodeEditorStyle defaultStyleDark(
    /* editor FG/BG */ QColor(218, 218, 218), QColor(16, 16, 32),
    /* highlight BG */ QColor(64, 64, 64),
    /* line number FG/BG */ QColor(43, 145, 175), QColor(16, 16, 32),
    /* keyword FG/Weight */ QColor(0, 204, 204), QFont::Bold,
    /* class FG/Weight */ QColor(218, 0, 218), QFont::Bold,
    /* quote FG/Weight */ QColor(0, 204, 0), QFont::Normal,
    /* comment FG/Weight */ QColor(180, 180, 180), QFont::Normal,
    /* Symbol FG/BG/Weight */ QColor(218, 32, 32), QColor(32, 32, 108), QFont::Normal
    );

#endif /* CODEEDITORSTYLE_H */