Automatically select dark colors for BootGuard markings in dark mode

This commit is contained in:
Nikolaj Schlej 2023-02-11 21:05:18 -08:00
parent ef7ceefa41
commit 944133caa7
3 changed files with 23 additions and 12 deletions

View file

@ -168,10 +168,14 @@ void UEFITool::init()
ui->builderMessagesListWidget->installEventFilter(this); ui->builderMessagesListWidget->installEventFilter(this);
// Switch default window style to Fusion on Qt6 Windows builds // Switch default window style to Fusion on Qt6 Windows builds
// TOOD: remove this one default style gains dark theme support // TODO: remove this once default style gains dark theme support
#if defined Q_OS_WIN and QT_VERSION_MAJOR >= 6 #if defined Q_OS_WIN and QT_VERSION_MAJOR >= 6
QApplication::setStyle(QStyleFactory::create("Fusion")); QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", QSettings::NativeFormat);
QApplication::setPalette(QApplication::style()->standardPalette()); if (settings.value("AppsUseLightTheme", 1).toInt() == 0) {
QApplication::setStyle(QStyleFactory::create("Fusion"));
QApplication::setPalette(QApplication::style()->standardPalette());
model->setMarkingDarkMode(true);
}
#endif #endif
} }

View file

@ -29,15 +29,10 @@ QVariant TreeModel::data(const UModelIndex &index, int role) const
#if defined (QT_GUI_LIB) #if defined (QT_GUI_LIB)
else if (role == Qt::BackgroundRole) { else if (role == Qt::BackgroundRole) {
if (markingEnabledFlag && marking(index) != BootGuardMarking::None) { if (markingEnabledFlag && marking(index) != BootGuardMarking::None) {
// Use light colors by default
uint8_t bgFullyInRange = Qt::red;
uint8_t vendorFullyInRange = Qt::cyan;
uint8_t partiallyInRange = Qt::yellow;
switch (marking(index)) { switch (marking(index)) {
case BootGuardMarking::BootGuardFullyInRange: return QBrush((Qt::GlobalColor)bgFullyInRange); break; case BootGuardMarking::BootGuardFullyInRange: return QBrush((Qt::GlobalColor)(markingDarkModeFlag ? Qt::darkRed : Qt::red )); break;
case BootGuardMarking::VendorFullyInRange: return QBrush((Qt::GlobalColor)vendorFullyInRange); break; case BootGuardMarking::VendorFullyInRange: return QBrush((Qt::GlobalColor)(markingDarkModeFlag ? Qt::darkCyan : Qt::cyan )); break;
case BootGuardMarking::PartiallyInRange: return QBrush((Qt::GlobalColor)partiallyInRange); break; case BootGuardMarking::PartiallyInRange: return QBrush((Qt::GlobalColor)(markingDarkModeFlag ? Qt::darkYellow : Qt::yellow)); break;
} }
} }
} }
@ -350,6 +345,13 @@ void TreeModel::TreeModel::setMarkingEnabled(const bool enabled)
emit dataChanged(UModelIndex(), UModelIndex()); emit dataChanged(UModelIndex(), UModelIndex());
} }
void TreeModel::TreeModel::setMarkingDarkMode(const bool enabled)
{
markingDarkModeFlag = enabled;
emit dataChanged(UModelIndex(), UModelIndex());
}
void TreeModel::setMarking(const UModelIndex &index, const UINT8 marking) void TreeModel::setMarking(const UModelIndex &index, const UINT8 marking)
{ {
if (!index.isValid()) if (!index.isValid())

View file

@ -96,13 +96,14 @@ class TreeModel : public QAbstractItemModel
private: private:
TreeItem *rootItem; TreeItem *rootItem;
bool markingEnabledFlag; bool markingEnabledFlag;
bool markingDarkModeFlag;
public: public:
QVariant data(const UModelIndex &index, int role) const; QVariant data(const UModelIndex &index, int role) const;
Qt::ItemFlags flags(const UModelIndex &index) const; Qt::ItemFlags flags(const UModelIndex &index) const;
QVariant headerData(int section, Qt::Orientation orientation, QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const; int role = Qt::DisplayRole) const;
TreeModel(QObject *parent = 0) : QAbstractItemModel(parent), markingEnabledFlag(true) { TreeModel(QObject *parent = 0) : QAbstractItemModel(parent), markingEnabledFlag(true), markingDarkModeFlag(false) {
rootItem = new TreeItem(0, Types::Root, 0, UString(), UString(), UString(), UByteArray(), UByteArray(), UByteArray(), true, false); rootItem = new TreeItem(0, Types::Root, 0, UString(), UString(), UString(), UByteArray(), UByteArray(), UByteArray(), true, false);
} }
@ -114,6 +115,7 @@ class TreeModel
private: private:
TreeItem *rootItem; TreeItem *rootItem;
bool markingEnabledFlag; bool markingEnabledFlag;
bool markingDarkModeFlag;
void dataChanged(const UModelIndex &, const UModelIndex &) {} void dataChanged(const UModelIndex &, const UModelIndex &) {}
void layoutAboutToBeChanged() {} void layoutAboutToBeChanged() {}
@ -143,6 +145,9 @@ public:
bool markingEnabled() { return markingEnabledFlag; } bool markingEnabled() { return markingEnabledFlag; }
void setMarkingEnabled(const bool enabled); void setMarkingEnabled(const bool enabled);
bool markingDarkMode() { return markingDarkModeFlag; }
void setMarkingDarkMode(const bool enabled);
UModelIndex index(int row, int column, const UModelIndex &parent = UModelIndex()) const; UModelIndex index(int row, int column, const UModelIndex &parent = UModelIndex()) const;
UModelIndex parent(const UModelIndex &index) const; UModelIndex parent(const UModelIndex &index) const;
int rowCount(const UModelIndex &parent = UModelIndex()) const; int rowCount(const UModelIndex &parent = UModelIndex()) const;