QGCPalette.h 4.5 KB
Newer Older
1 2 3 4 5 6 7 8 9
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * 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 15
#ifndef QGCPalette_h
#define QGCPalette_h

#include <QObject>
#include <QColor>

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#define QGCColorThemes  2
#define QGCColorGroups  2


#define DECLARE_QGC_COLOR(name, lightEnabled, lightDisabled, darkEnabled, darkDisabled) \
    QColor QGCPalette::_##name[QGCColorThemes][QGCColorGroups] = { \
        { QColor(lightEnabled), QColor(lightDisabled) }, \
        { QColor(darkEnabled),  QColor(darkDisabled) }, \
    };

#define DEFINE_QGC_COLOR(name, setName) \
    Q_PROPERTY(QColor name READ name WRITE setName NOTIFY paletteChanged) \
    QColor name() const { return _##name[_theme][_colorGroupEnabled  ? 1 : 0]; } \
    void setName(QColor& color) { _##name[_theme][_colorGroupEnabled ? 1 : 0] = color; _signalPaletteChangeToAll(); } \
    static QColor _##name[QGCColorThemes][QGCColorGroups];

Don Gagne's avatar
Don Gagne committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
/*!
 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 }
        }
*/
49

50 51 52
class QGCPalette : public QObject
{
    Q_OBJECT
53
    Q_ENUMS(Theme)
Gus Grubba's avatar
Gus Grubba committed
54

55
public:
56

57
    enum ColorGroup {
Don Gagne's avatar
Don Gagne committed
58
        Disabled = 0,
59
        Enabled
60
    };
61

62 63 64 65
    enum Theme {
        Light = 0,
        Dark
    };
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

    Q_PROPERTY(Theme    globalTheme         READ globalTheme        WRITE setGlobalTheme        NOTIFY paletteChanged)
    Q_PROPERTY(bool     colorGroupEnabled   READ colorGroupEnabled  WRITE setColorGroupEnabled  NOTIFY paletteChanged)

    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)
    DEFINE_QGC_COLOR(mapWidgetBorderLight,  setMapWidgetBorderLight)
    DEFINE_QGC_COLOR(mapWidgetBorderDark,   setMapWidgetBorderDark)
    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)

     QGCPalette(QObject* parent = NULL);
99 100
    ~QGCPalette();
    
101 102
    bool colorGroupEnabled      () const { return _colorGroupEnabled; }
    void setColorGroupEnabled   (bool enabled);
103
    
104 105
    static Theme    globalTheme     () { return _theme; }
    static void     setGlobalTheme  (Theme newTheme);
106

107
signals:
108
    void paletteChanged ();
109 110
    
private:
111 112 113
    static void _signalPaletteChangeToAll   ();
    void        _signalPaletteChanged       ();
    void        _themeChanged               ();
114
    
115 116
    static Theme                _theme;             ///< There is a single theme for all palettes
    bool                        _colorGroupEnabled; ///< Currently selected ColorGroup. true: enabled, false: disabled
117
    static QList<QGCPalette*>   _paletteObjects;    ///< List of all active QGCPalette objects
118 119 120
};

#endif