Browse Source

All core plugin to override palette

QGC4.4
DonLakeFlyer 8 years ago
parent
commit
130e7ff315
  1. 2
      src/PlanView/MissionItemEditor.qml
  2. 40
      src/QGCPalette.cc
  3. 55
      src/QGCPalette.h
  4. 6
      src/QmlControls/QGCToolBarButton.qml
  5. 6
      src/api/QGCCorePlugin.cc
  6. 4
      src/api/QGCCorePlugin.h

2
src/PlanView/MissionItemEditor.qml

@ -16,7 +16,7 @@ import QGroundControl.Palette 1.0 @@ -16,7 +16,7 @@ import QGroundControl.Palette 1.0
Rectangle {
id: _root
height: editorLoader.y + editorLoader.height + (_margin * 2)
color: _currentItem ? qgcPal.primaryButton : qgcPal.windowShade
color: _currentItem ? qgcPal.missionItemEditor : qgcPal.windowShade
radius: _radius
property var map ///< Map control

40
src/QGCPalette.cc

@ -12,6 +12,8 @@ @@ -12,6 +12,8 @@
/// @author Don Gagne <don@thegagnes.com>
#include "QGCPalette.h"
#include "QGCApplication.h"
#include "QGCCorePlugin.h"
#include <QApplication>
#include <QPalette>
@ -20,6 +22,29 @@ QList<QGCPalette*> QGCPalette::_paletteObjects; @@ -20,6 +22,29 @@ QList<QGCPalette*> QGCPalette::_paletteObjects;
QGCPalette::Theme QGCPalette::_theme = QGCPalette::Dark;
QMap<int, QMap<int, QMap<QString, QColor>>> QGCPalette::_colorInfoMap;
QGCPalette::QGCPalette(QObject* parent) :
QObject(parent),
_colorGroupEnabled(true)
{
if (_colorInfoMap.isEmpty()) {
_buildMap();
}
// We have to keep track of all QGCPalette objects in the system so we can signal theme change to all of them
_paletteObjects += this;
}
QGCPalette::~QGCPalette()
{
bool fSuccess = _paletteObjects.removeOne(this);
Q_ASSERT(fSuccess);
Q_UNUSED(fSuccess);
}
void QGCPalette::_buildMap(void)
{
// Light Dark
// Disabled Enabled Disabled Enabled
DECLARE_QGC_COLOR(window, "#ffffff", "#ffffff", "#222222", "#222222")
@ -45,26 +70,13 @@ DECLARE_QGC_COLOR(colorBlue, "#1a72ff", "#1a72ff", "#536dff", "#536df @@ -45,26 +70,13 @@ DECLARE_QGC_COLOR(colorBlue, "#1a72ff", "#1a72ff", "#536dff", "#536df
DECLARE_QGC_COLOR(alertBackground, "#eecc44", "#eecc44", "#eecc44", "#eecc44")
DECLARE_QGC_COLOR(alertBorder, "#808080", "#808080", "#808080", "#808080")
DECLARE_QGC_COLOR(alertText, "#000000", "#000000", "#000000", "#000000")
DECLARE_QGC_COLOR(missionItemEditor, "#585858", "#8cb3be", "#585858", "#8cb3be")
// Colors are not affecting by theming
DECLARE_QGC_COLOR(mapWidgetBorderLight, "#ffffff", "#ffffff", "#ffffff", "#ffffff")
DECLARE_QGC_COLOR(mapWidgetBorderDark, "#000000", "#000000", "#000000", "#000000")
DECLARE_QGC_COLOR(brandingPurple, "#4A2C6D", "#4A2C6D", "#4A2C6D", "#4A2C6D")
DECLARE_QGC_COLOR(brandingBlue, "#48D6FF", "#48D6FF", "#48D6FF", "#48D6FF")
QGCPalette::QGCPalette(QObject* parent) :
QObject(parent),
_colorGroupEnabled(true)
{
// We have to keep track of all QGCPalette objects in the system so we can signal theme change to all of them
_paletteObjects += this;
}
QGCPalette::~QGCPalette()
{
bool fSuccess = _paletteObjects.removeOne(this);
Q_ASSERT(fSuccess);
Q_UNUSED(fSuccess);
}
void QGCPalette::setColorGroupEnabled(bool enabled)

55
src/QGCPalette.h

@ -12,22 +12,25 @@ @@ -12,22 +12,25 @@
#include <QObject>
#include <QColor>
#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) }, \
};
#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]; \
}
#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];
QColor name() const { return _colorInfoMap[_theme][_colorGroupEnabled ? ColorGroupEnabled : ColorGroupDisabled][QStringLiteral(#name)]; } \
void setName(QColor& color) { _colorInfoMap[_theme][_colorGroupEnabled ? ColorGroupEnabled : ColorGroupDisabled][QStringLiteral(#name)] = color; _signalPaletteChangeToAll(); }
/*!
QGCPalette is used in QML ui to expose color properties for the QGC palette. There are two
@ -50,20 +53,24 @@ @@ -50,20 +53,24 @@
class QGCPalette : public QObject
{
Q_OBJECT
Q_ENUMS(Theme)
public:
enum ColorGroup {
Disabled = 0,
Enabled
ColorGroupDisabled = 0,
ColorGroupEnabled,
cMaxColorGroup
};
enum Theme {
Light = 0,
Dark
Dark,
cMaxTheme
};
typedef QColor PaletteColorInfo_t[cMaxTheme][cMaxColorGroup];
Q_PROPERTY(Theme globalTheme READ globalTheme WRITE setGlobalTheme NOTIFY paletteChanged)
Q_PROPERTY(bool colorGroupEnabled READ colorGroupEnabled WRITE setColorGroupEnabled NOTIFY paletteChanged)
@ -94,26 +101,30 @@ public: @@ -94,26 +101,30 @@ public:
DEFINE_QGC_COLOR(alertBackground, setAlertBackground)
DEFINE_QGC_COLOR(alertBorder, setAlertBorder)
DEFINE_QGC_COLOR(alertText, setAlertText)
DEFINE_QGC_COLOR(missionItemEditor, setMissionItemEditor)
QGCPalette(QObject* parent = NULL);
~QGCPalette();
bool colorGroupEnabled () const { return _colorGroupEnabled; }
bool colorGroupEnabled (void) const { return _colorGroupEnabled; }
void setColorGroupEnabled (bool enabled);
static Theme globalTheme () { return _theme; }
static Theme globalTheme (void) { return _theme; }
static void setGlobalTheme (Theme newTheme);
signals:
void paletteChanged ();
private:
static void _signalPaletteChangeToAll ();
void _signalPaletteChanged ();
void _themeChanged ();
static void _buildMap (void);
static void _signalPaletteChangeToAll (void);
void _signalPaletteChanged (void);
void _themeChanged (void);
static Theme _theme; ///< There is a single theme for all palettes
bool _colorGroupEnabled; ///< Currently selected ColorGroup. true: enabled, false: disabled
static QMap<int, QMap<int, QMap<QString, QColor>>> _colorInfoMap; // theme -> colorGroup -> color name -> color
static QList<QGCPalette*> _paletteObjects; ///< List of all active QGCPalette objects
};

6
src/QmlControls/QGCToolBarButton.qml

@ -26,10 +26,10 @@ Item { @@ -26,10 +26,10 @@ Item {
property bool logo: false
property ExclusiveGroup exclusiveGroup: null
readonly property real _topBottomMargins: ScreenTools.defaultFontPixelHeight / 2
signal clicked()
readonly property real _topBottomMargins: ScreenTools.defaultFontPixelHeight / 2
onExclusiveGroupChanged: {
if (exclusiveGroup) {
exclusiveGroup.bindCheckable(_root)
@ -41,7 +41,7 @@ Item { @@ -41,7 +41,7 @@ Item {
Rectangle {
anchors.fill: parent
visible: logo
color: "#4A2C6D"
color: qgcPal.brandingPurple
}
QGCColoredImage {

6
src/api/QGCCorePlugin.cc

@ -184,3 +184,9 @@ void QGCCorePlugin::setShowAdvancedUI(bool show) @@ -184,3 +184,9 @@ void QGCCorePlugin::setShowAdvancedUI(bool show)
emit showAdvancedUIChanged(show);
}
}
void QGCCorePlugin::paletteOverride(QString colorName, QGCPalette::PaletteColorInfo_t& colorInfo)
{
Q_UNUSED(colorName);
Q_UNUSED(colorInfo);
}

4
src/api/QGCCorePlugin.h

@ -10,6 +10,7 @@ @@ -10,6 +10,7 @@
#pragma once
#include "QGCToolbox.h"
#include "QGCPalette.h"
#include <QObject>
#include <QVariantList>
@ -80,6 +81,9 @@ public: @@ -80,6 +81,9 @@ public:
/// @return An instance of an alternate postion source (or NULL if not available)
virtual QGeoPositionInfoSource* createPositionSource(QObject* parent) { Q_UNUSED(parent); return NULL; }
/// Allows a plugin to override the specified color name from the palette
virtual void paletteOverride(QString colorName, QGCPalette::PaletteColorInfo_t& colorInfo);
bool showTouchAreas(void) const { return _showTouchAreas; }
bool showAdvancedUI(void) const { return _showAdvancedUI; }
void setShowTouchAreas(bool show);

Loading…
Cancel
Save