QGCPalette.cc 5.11 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (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.
 *
 ****************************************************************************/
dogmaphobic's avatar
dogmaphobic committed
9

10 11 12 13 14 15 16 17 18

/// @file
///     @author Don Gagne <don@thegagnes.com>

#include "QGCPalette.h"

#include <QApplication>
#include <QPalette>

19 20 21 22
QList<QGCPalette*>   QGCPalette::_paletteObjects;

QGCPalette::Theme QGCPalette::_theme = QGCPalette::Dark;

23
QColor QGCPalette::_window[QGCPalette::_cThemes][QGCPalette::_cColorGroups] = {
24
    { QColor("#ffffff"), QColor("#ffffff") },
25 26 27 28
    { QColor(0x22, 0x22, 0x22), QColor(0x22, 0x22, 0x22) }
};

QColor QGCPalette::_windowShade[QGCPalette::_cThemes][QGCPalette::_cColorGroups] = {
29
    { QColor("#d9d9d9"), QColor("#d9d9d9") },
30 31 32 33
    { QColor(51, 51, 51), QColor(51, 51, 51) }
};

QColor QGCPalette::_windowShadeDark[QGCPalette::_cThemes][QGCPalette::_cColorGroups] = {
34
    { QColor("#bdbdbd"), QColor("#bdbdbd") },
35
    { QColor(40, 40, 40), QColor(40, 40, 40) }
36 37
};

38
QColor QGCPalette::_text[QGCPalette::_cThemes][QGCPalette::_cColorGroups] = {
39
    { QColor("#9d9d9d"), QColor("#000000") },
40
    { QColor(0x58, 0x58, 0x58), QColor(0xFF, 0xFF, 0xFF) }
41 42
};

43
QColor QGCPalette::_warningText[QGCPalette::_cThemes][QGCPalette::_cColorGroups] = {
dogmaphobic's avatar
dogmaphobic committed
44 45
    { QColor("#cc0808"), QColor("#cc0808") },
    { QColor("#e4e428"), QColor("#e4e428") }
46 47
};

48
QColor QGCPalette::_button[QGCPalette::_cThemes][QGCPalette::_cColorGroups] = {
49
    { QColor("#ffffff"),  QColor("#ffffff") },
50
    { QColor(0x58, 0x58, 0x58), QColor(98, 98, 100) },
51 52 53
};

QColor QGCPalette::_buttonText[QGCPalette::_cThemes][QGCPalette::_cColorGroups] = {
54
    { QColor("#9d9d9d"), QColor("#000000") },
55
    { QColor(0x2c, 0x2c, 0x2c), QColor(0xFF, 0xFF, 0xFF) },
56 57
};

58
QColor QGCPalette::_buttonHighlight[QGCPalette::_cThemes][QGCPalette::_cColorGroups] = {
59
    { QColor("#e4e4e4"), QColor("#33b5e5") },
60
    { QColor(0x58, 0x58, 0x58), QColor(237, 235, 51) },
61 62
};

63 64 65
QColor QGCPalette::_buttonHighlightText[QGCPalette::_cThemes][QGCPalette::_cColorGroups] = {
    { QColor(0x2c, 0x2c, 0x2c), QColor(0, 0, 0) },
    { QColor(0x2c, 0x2c, 0x2c), QColor(0, 0, 0) },
66 67
};

68
QColor QGCPalette::_primaryButton[QGCPalette::_cThemes][QGCPalette::_cColorGroups] = {
dogmaphobic's avatar
dogmaphobic committed
69 70
    { QColor(0x58, 0x58, 0x58), QColor("#badec5") },
    { QColor(0x58, 0x58, 0x58), QColor("#badec5") },
71 72
};

73 74 75
QColor QGCPalette::_primaryButtonText[QGCPalette::_cThemes][QGCPalette::_cColorGroups] = {
    { QColor(0x2c, 0x2c, 0x2c), QColor(0, 0, 0) },
    { QColor(0x2c, 0x2c, 0x2c), QColor(0, 0, 0) },
76 77
};

78
QColor QGCPalette::_textField[QGCPalette::_cThemes][QGCPalette::_cColorGroups] = {
79
    { QColor("#ffffff"), QColor("#ffffff") },
80
    { QColor(0x58, 0x58, 0x58), QColor(255, 255, 255) },
Don Gagne's avatar
Don Gagne committed
81 82
};

83
QColor QGCPalette::_textFieldText[QGCPalette::_cThemes][QGCPalette::_cColorGroups] = {
84
    { QColor("#dedede"), QColor("#000000") },
85
    { QColor(0x2c, 0x2c, 0x2c), QColor(0, 0, 0) },
86
};
87

88 89 90 91 92 93 94 95 96 97
QColor QGCPalette::_mapButton[QGCPalette::_cThemes][QGCPalette::_cColorGroups] = {
    { QColor(0x58, 0x58, 0x58), QColor(0, 0, 0) },
    { QColor(0x58, 0x58, 0x58), QColor(0, 0, 0) },
};

QColor QGCPalette::_mapButtonHighlight[QGCPalette::_cThemes][QGCPalette::_cColorGroups] = {
    { QColor(0x58, 0x58, 0x58), QColor(190, 120, 28) },
    { QColor(0x58, 0x58, 0x58), QColor(190, 120, 28) },
};

98 99 100 101 102 103 104 105 106 107 108
// Map widget colors are not affecting by theming
QColor QGCPalette::_mapWidgetBorderLight[QGCPalette::_cThemes][QGCPalette::_cColorGroups] = {
    { QColor(255, 255, 255), QColor(255, 255, 255) },
    { QColor(255, 255, 255), QColor(255, 255, 255) },
};

QColor QGCPalette::_mapWidgetBorderDark[QGCPalette::_cThemes][QGCPalette::_cColorGroups] = {
    { QColor(0, 0, 0), QColor(0, 0, 0) },
    { QColor(0, 0, 0), QColor(0, 0, 0) },
};

Don Gagne's avatar
Don Gagne committed
109 110 111 112 113 114 115 116 117 118
QColor QGCPalette::_brandingPurple[QGCPalette::_cThemes][QGCPalette::_cColorGroups] = {
    { QColor("#4A2C6D"), QColor("#4A2C6D") },
    { QColor("#4A2C6D"), QColor("#4A2C6D") },
};

QColor QGCPalette::_brandingBlue[QGCPalette::_cThemes][QGCPalette::_cColorGroups] = {
    { QColor("#48D6FF"), QColor("#48D6FF") },
    { QColor("#48D6FF"), QColor("#48D6FF") },
};

119
QGCPalette::QGCPalette(QObject* parent) :
Don Gagne's avatar
Don Gagne committed
120
    QObject(parent),
121
    _colorGroupEnabled(true)
122
{
123 124
    // We have to keep track of all QGCPalette objects in the system so we can signal theme change to all of them
    _paletteObjects += this;
125 126 127 128
}

QGCPalette::~QGCPalette()
{
129 130 131
    bool fSuccess = _paletteObjects.removeOne(this);
    Q_ASSERT(fSuccess);
    Q_UNUSED(fSuccess);
132 133
}

134
void QGCPalette::setColorGroupEnabled(bool enabled)
135
{
136
    _colorGroupEnabled = enabled;
137 138
    emit paletteChanged();
}
139 140 141

void QGCPalette::setGlobalTheme(Theme newTheme)
{
142
    // Mobile build does not have themes
143 144
    if (_theme != newTheme) {
        _theme = newTheme;
145
        _signalPaletteChangeToAll();
146 147 148
    }
}

149
void QGCPalette::_signalPaletteChangeToAll(void)
150
{
151 152 153 154
    // Notify all objects of the new theme
    foreach (QGCPalette* palette, _paletteObjects) {
        palette->_signalPaletteChanged();
    }
155
}
Don Gagne's avatar
Don Gagne committed
156

157 158 159 160 161

void QGCPalette::_signalPaletteChanged(void)
{
    emit paletteChanged();
}