QGCPalette.cc 6 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
    { QColor("#cc0808"), QColor("#cc0808") },
45
    { QColor("#f85761"), QColor("#f85761") }
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 60
    { QColor("#e4e4e4"), QColor("#946120") },
    { QColor(0x58, 0x58, 0x58), QColor("#fff291") },
61 62
};

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

68
QColor QGCPalette::_primaryButton[QGCPalette::_cThemes][QGCPalette::_cColorGroups] = {
69 70
    { QColor(0x58, 0x58, 0x58), QColor("#8cb3be") },
    { QColor(0x58, 0x58, 0x58), QColor("#8cb3be") },
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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
QColor QGCPalette::_colorGreen[QGCPalette::_cThemes][QGCPalette::_cColorGroups] = {
    { QColor("#009431"), QColor("#009431") },   //-- Light
    { QColor("#00e04b"), QColor("#00e04b") },   //-- Dark
};
QColor QGCPalette::_colorOrange[QGCPalette::_cThemes][QGCPalette::_cColorGroups] = {
    { QColor("#b95604"), QColor("#b95604") },
    { QColor("#de8500"), QColor("#de8500") },
};
QColor QGCPalette::_colorRed[QGCPalette::_cThemes][QGCPalette::_cColorGroups] = {
    { QColor("#ed3939"), QColor("#ed3939") },
    { QColor("#f32836"), QColor("#f32836") },
};
QColor QGCPalette::_colorGrey[QGCPalette::_cThemes][QGCPalette::_cColorGroups] = {
    { QColor("#808080"), QColor("#808080") },
    { QColor("#bfbfbf"), QColor("#bfbfbf") },
};
QColor QGCPalette::_colorBlue[QGCPalette::_cThemes][QGCPalette::_cColorGroups] = {
    { QColor("#1a72ff"), QColor("#1a72ff") },
    { QColor("#536dff"), QColor("#536dff") },
};

140
QGCPalette::QGCPalette(QObject* parent) :
Don Gagne's avatar
Don Gagne committed
141
    QObject(parent),
142
    _colorGroupEnabled(true)
143
{
144 145
    // We have to keep track of all QGCPalette objects in the system so we can signal theme change to all of them
    _paletteObjects += this;
146 147 148 149
}

QGCPalette::~QGCPalette()
{
150 151 152
    bool fSuccess = _paletteObjects.removeOne(this);
    Q_ASSERT(fSuccess);
    Q_UNUSED(fSuccess);
153 154
}

155
void QGCPalette::setColorGroupEnabled(bool enabled)
156
{
157
    _colorGroupEnabled = enabled;
158 159
    emit paletteChanged();
}
160 161 162

void QGCPalette::setGlobalTheme(Theme newTheme)
{
163
    // Mobile build does not have themes
164 165
    if (_theme != newTheme) {
        _theme = newTheme;
166
        _signalPaletteChangeToAll();
167 168 169
    }
}

170
void QGCPalette::_signalPaletteChangeToAll(void)
171
{
172 173 174 175
    // Notify all objects of the new theme
    foreach (QGCPalette* palette, _paletteObjects) {
        palette->_signalPaletteChanged();
    }
176
}
Don Gagne's avatar
Don Gagne committed
177

178 179 180 181 182

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