QGCPalette.h 8.28 KB
Newer Older
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8 9
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

10 11 12 13 14
#ifndef QGCPalette_h
#define QGCPalette_h

#include <QObject>
#include <QColor>
15 16 17 18 19 20 21 22 23 24 25 26 27
#include <QMap>

#define DECLARE_QGC_COLOR(name, lightDisabled, lightEnabled, darkDisabled, darkEnabled) \
    { \
        PaletteColorInfo_t colorInfo = { \
            { QColor(lightDisabled), QColor(lightEnabled) }, \
            { QColor(darkDisabled), QColor(darkEnabled) } \
        }; \
        qgcApp()->toolbox()->corePlugin()->paletteOverride(#name, colorInfo); \
        _colorInfoMap[Light][ColorGroupEnabled][QStringLiteral(#name)] = colorInfo[Light][ColorGroupEnabled]; \
        _colorInfoMap[Light][ColorGroupDisabled][QStringLiteral(#name)] = colorInfo[Light][ColorGroupDisabled]; \
        _colorInfoMap[Dark][ColorGroupEnabled][QStringLiteral(#name)] = colorInfo[Dark][ColorGroupEnabled]; \
        _colorInfoMap[Dark][ColorGroupDisabled][QStringLiteral(#name)] = colorInfo[Dark][ColorGroupDisabled]; \
28
        _colors << #name; \
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
#define DECLARE_QGC_NONTHEMED_COLOR(name, disabledColor, enabledColor) \
    { \
        PaletteColorInfo_t colorInfo = { \
            { QColor(disabledColor), QColor(enabledColor) }, \
            { QColor(disabledColor), QColor(enabledColor) } \
        }; \
        qgcApp()->toolbox()->corePlugin()->paletteOverride(#name, colorInfo); \
        _colorInfoMap[Light][ColorGroupEnabled][QStringLiteral(#name)] = colorInfo[Light][ColorGroupEnabled]; \
        _colorInfoMap[Light][ColorGroupDisabled][QStringLiteral(#name)] = colorInfo[Light][ColorGroupDisabled]; \
        _colorInfoMap[Dark][ColorGroupEnabled][QStringLiteral(#name)] = colorInfo[Dark][ColorGroupEnabled]; \
        _colorInfoMap[Dark][ColorGroupDisabled][QStringLiteral(#name)] = colorInfo[Dark][ColorGroupDisabled]; \
        _colors << #name; \
    }

#define DECLARE_QGC_SINGLE_COLOR(name, color) \
    { \
        PaletteColorInfo_t colorInfo = { \
            { QColor(color), QColor(color) }, \
            { QColor(color), QColor(color) } \
        }; \
        qgcApp()->toolbox()->corePlugin()->paletteOverride(#name, colorInfo); \
        _colorInfoMap[Light][ColorGroupEnabled][QStringLiteral(#name)] = colorInfo[Light][ColorGroupEnabled]; \
        _colorInfoMap[Light][ColorGroupDisabled][QStringLiteral(#name)] = colorInfo[Light][ColorGroupDisabled]; \
        _colorInfoMap[Dark][ColorGroupEnabled][QStringLiteral(#name)] = colorInfo[Dark][ColorGroupEnabled]; \
        _colorInfoMap[Dark][ColorGroupDisabled][QStringLiteral(#name)] = colorInfo[Dark][ColorGroupDisabled]; \
        _colors << #name; \
    }

59 60 61 62 63 64 65 66 67 68 69 70
#define DEFINE_QGC_COLOR(NAME, SETNAME) \
    Q_PROPERTY(QColor NAME READ NAME WRITE SETNAME NOTIFY paletteChanged) \
    Q_PROPERTY(QStringList NAME ## Colors READ NAME ## Colors NOTIFY paletteChanged) \
    QColor NAME() const { return _colorInfoMap[_theme][_colorGroupEnabled  ? ColorGroupEnabled : ColorGroupDisabled][QStringLiteral(#NAME)]; } \
    QStringList NAME ## Colors() const { \
        QStringList c; \
        c << _colorInfoMap[Light][ColorGroupEnabled][QStringLiteral(#NAME)].name(QColor::HexRgb); \
        c << _colorInfoMap[Light][ColorGroupDisabled][QStringLiteral(#NAME)].name(QColor::HexRgb); \
        c << _colorInfoMap[Dark][ColorGroupEnabled][QStringLiteral(#NAME)].name(QColor::HexRgb); \
        c << _colorInfoMap[Dark][ColorGroupDisabled][QStringLiteral(#NAME)].name(QColor::HexRgb); \
        return c; \
    } \
71
    void SETNAME(const QColor& color) { _colorInfoMap[_theme][_colorGroupEnabled  ? ColorGroupEnabled : ColorGroupDisabled][QStringLiteral(#NAME)] = color; _signalPaletteChangeToAll(); }
72

Don Gagne's avatar
Don Gagne committed
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
/*!
 QGCPalette is used in QML ui to expose color properties for the QGC palette. There are two
 separate palettes in QGC, light and dark. The light palette is for outdoor use and the dark
 palette is for indoor use. Each palette also has a set of different colors for enabled and
 disabled states.

 Usage:

        import QGroundControl.Palette 1.0

        Rectangle {
            anchors.fill:   parent
            color:          qgcPal.window

            QGCPalette { id: qgcPal: colorGroupEnabled: enabled }
        }
*/
90

91 92 93
class QGCPalette : public QObject
{
    Q_OBJECT
94

95 96
public:
    enum ColorGroup {
97 98 99
        ColorGroupDisabled = 0,
        ColorGroupEnabled,
        cMaxColorGroup
100
    };
101

102 103
    enum Theme {
        Light = 0,
104 105
        Dark,
        cMaxTheme
106
    };
107
    Q_ENUM(Theme)
108

109 110
    typedef QColor PaletteColorInfo_t[cMaxTheme][cMaxColorGroup];

111 112 113
    Q_PROPERTY(Theme        globalTheme         READ globalTheme        WRITE setGlobalTheme        NOTIFY paletteChanged)
    Q_PROPERTY(bool         colorGroupEnabled   READ colorGroupEnabled  WRITE setColorGroupEnabled  NOTIFY paletteChanged)
    Q_PROPERTY(QStringList  colors              READ colors             CONSTANT)
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129

    DEFINE_QGC_COLOR(window,                setWindow)
    DEFINE_QGC_COLOR(windowShade,           setWindowShade)
    DEFINE_QGC_COLOR(windowShadeDark,       setWindowShadeDark)
    DEFINE_QGC_COLOR(text,                  setText)
    DEFINE_QGC_COLOR(warningText,           setWarningText)
    DEFINE_QGC_COLOR(button,                setButton)
    DEFINE_QGC_COLOR(buttonText,            setButtonText)
    DEFINE_QGC_COLOR(buttonHighlight,       setButtonHighlight)
    DEFINE_QGC_COLOR(buttonHighlightText,   setButtonHighlightText)
    DEFINE_QGC_COLOR(primaryButton,         setPrimaryButton)
    DEFINE_QGC_COLOR(primaryButtonText,     setPrimaryButtonText)
    DEFINE_QGC_COLOR(textField,             setTextField)
    DEFINE_QGC_COLOR(textFieldText,         setTextFieldText)
    DEFINE_QGC_COLOR(mapButton,             setMapButton)
    DEFINE_QGC_COLOR(mapButtonHighlight,    setMapButtonHighlight)
130 131
    DEFINE_QGC_COLOR(mapIndicator,          setMapIndicator)
    DEFINE_QGC_COLOR(mapIndicatorChild,     setMapIndicatorChild)
132 133
    DEFINE_QGC_COLOR(mapWidgetBorderLight,  setMapWidgetBorderLight)
    DEFINE_QGC_COLOR(mapWidgetBorderDark,   setMapWidgetBorderDark)
134
    DEFINE_QGC_COLOR(mapMissionTrajectory,  setMapMissionTrajectory)
135 136 137 138 139 140 141 142 143 144
    DEFINE_QGC_COLOR(brandingPurple,        setBrandingPurple)
    DEFINE_QGC_COLOR(brandingBlue,          setBrandingBlue)
    DEFINE_QGC_COLOR(colorGreen,            setColorGreen)
    DEFINE_QGC_COLOR(colorOrange,           setColorOrange)
    DEFINE_QGC_COLOR(colorRed,              setColorRed)
    DEFINE_QGC_COLOR(colorGrey,             setColorGrey)
    DEFINE_QGC_COLOR(colorBlue,             setColorBlue)
    DEFINE_QGC_COLOR(alertBackground,       setAlertBackground)
    DEFINE_QGC_COLOR(alertBorder,           setAlertBorder)
    DEFINE_QGC_COLOR(alertText,             setAlertText)
145
    DEFINE_QGC_COLOR(missionItemEditor,     setMissionItemEditor)
Gus Grubba's avatar
Gus Grubba committed
146
    DEFINE_QGC_COLOR(hoverColor,            setHoverColor)
147 148 149
    DEFINE_QGC_COLOR(statusFailedText,      setstatusFailedText)
    DEFINE_QGC_COLOR(statusPassedText,      setstatusPassedText)
    DEFINE_QGC_COLOR(statusPendingText,     setstatusPendingText)
150
    DEFINE_QGC_COLOR(surveyPolygonInterior, setSurveyPolygonInterior)
151

152
     QGCPalette(QObject* parent = nullptr);
153
    ~QGCPalette();
154

155 156 157
    QStringList colors                      () const { return _colors; }
    bool        colorGroupEnabled           () const { return _colorGroupEnabled; }
    void        setColorGroupEnabled        (bool enabled);
158

159 160
    static Theme    globalTheme             () { return _theme; }
    static void     setGlobalTheme          (Theme newTheme);
161

162
signals:
163
    void paletteChanged ();
164

165
private:
166 167 168 169
    static void _buildMap                   ();
    static void _signalPaletteChangeToAll   ();
    void        _signalPaletteChanged       ();
    void        _themeChanged               ();
170

171 172
    static Theme                _theme;             ///< There is a single theme for all palettes
    bool                        _colorGroupEnabled; ///< Currently selected ColorGroup. true: enabled, false: disabled
173
    static QStringList          _colors;
174 175 176

    static QMap<int, QMap<int, QMap<QString, QColor>>> _colorInfoMap;   // theme -> colorGroup -> color name -> color
    static QList<QGCPalette*> _paletteObjects;    ///< List of all active QGCPalette objects
177 178 179
};

#endif