Temporary change UI style for Qt6-based Windows build of UEFITool to support dark mode

This commit is contained in:
Nikolaj Schlej 2023-02-11 20:19:32 -08:00
parent d48955d45a
commit ef7ceefa41
5 changed files with 31 additions and 18 deletions

View File

@ -148,7 +148,7 @@ void UEFITool::init()
model->setMarkingEnabled(markingEnabled); model->setMarkingEnabled(markingEnabled);
ui->actionToggleBootGuardMarking->setChecked(markingEnabled); ui->actionToggleBootGuardMarking->setChecked(markingEnabled);
// Connect // Connect signals to slots
connect(ui->structureTreeView->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), connect(ui->structureTreeView->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
this, SLOT(populateUi(const QModelIndex &))); this, SLOT(populateUi(const QModelIndex &)));
connect(ui->structureTreeView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), connect(ui->structureTreeView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
@ -162,10 +162,17 @@ void UEFITool::init()
connect(ui->fitTableWidget, SIGNAL(itemDoubleClicked(QTableWidgetItem*)), this, SLOT(scrollTreeView(QTableWidgetItem*))); connect(ui->fitTableWidget, SIGNAL(itemDoubleClicked(QTableWidgetItem*)), this, SLOT(scrollTreeView(QTableWidgetItem*)));
connect(ui->messagesTabWidget, SIGNAL(currentChanged(int)), this, SLOT(currentTabChanged(int))); connect(ui->messagesTabWidget, SIGNAL(currentChanged(int)), this, SLOT(currentTabChanged(int)));
// allow enter/return pressing to scroll tree view // Allow enter/return pressing to scroll tree view
ui->parserMessagesListWidget->installEventFilter(this); ui->parserMessagesListWidget->installEventFilter(this);
ui->finderMessagesListWidget->installEventFilter(this); ui->finderMessagesListWidget->installEventFilter(this);
ui->builderMessagesListWidget->installEventFilter(this); ui->builderMessagesListWidget->installEventFilter(this);
// Switch default window style to Fusion on Qt6 Windows builds
// TOOD: remove this one default style gains dark theme support
#if defined Q_OS_WIN and QT_VERSION_MAJOR >= 6
QApplication::setStyle(QStyleFactory::create("Fusion"));
QApplication::setPalette(QApplication::style()->standardPalette());
#endif
} }
void UEFITool::populateUi(const QItemSelection &selected) void UEFITool::populateUi(const QItemSelection &selected)

View File

@ -31,6 +31,7 @@
#include <QProcess> #include <QProcess>
#include <QSettings> #include <QSettings>
#include <QSplitter> #include <QSplitter>
#include <QStyleFactory>
#include <QString> #include <QString>
#include <QTableWidget> #include <QTableWidget>
#include <QTreeView> #include <QTreeView>

View File

@ -35,17 +35,6 @@
#include "digest/sha2.h" #include "digest/sha2.h"
#include "digest/sm3.h" #include "digest/sm3.h"
#ifndef QT_CORE_LIB
namespace Qt {
enum GlobalColor {
red = 7,
green = 8,
cyan = 10,
yellow = 12,
};
}
#endif
// Constructor // Constructor
FfsParser::FfsParser(TreeModel* treeModel) : model(treeModel), FfsParser::FfsParser(TreeModel* treeModel) : model(treeModel),
imageBase(0), addressDiff(0x100000000ULL), protectedRegionsBase(0) { imageBase(0), addressDiff(0x100000000ULL), protectedRegionsBase(0) {
@ -3778,14 +3767,14 @@ USTATUS FfsParser::markProtectedRangeRecursive(const UModelIndex & index, const
if (std::min(currentOffset + currentSize, range.Offset + range.Size) > std::max(currentOffset, range.Offset)) { if (std::min(currentOffset + currentSize, range.Offset + range.Size) > std::max(currentOffset, range.Offset)) {
if (range.Offset <= currentOffset && currentOffset + currentSize <= range.Offset + range.Size) { // Mark as fully in range if (range.Offset <= currentOffset && currentOffset + currentSize <= range.Offset + range.Size) { // Mark as fully in range
if (range.Type == PROTECTED_RANGE_INTEL_BOOT_GUARD_IBB) { if (range.Type == PROTECTED_RANGE_INTEL_BOOT_GUARD_IBB) {
model->setMarking(index, Qt::red); model->setMarking(index, BootGuardMarking::BootGuardFullyInRange);
} }
else { else {
model->setMarking(index, Qt::cyan); model->setMarking(index, BootGuardMarking::VendorFullyInRange);
} }
} }
else { // Mark as partially in range else { // Mark as partially in range
model->setMarking(index, Qt::yellow); model->setMarking(index, BootGuardMarking::PartiallyInRange);
} }
} }
} }

View File

@ -28,8 +28,17 @@ 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) > 0) { if (markingEnabledFlag && marking(index) != BootGuardMarking::None) {
return QBrush((Qt::GlobalColor)marking(index)); // Use light colors by default
uint8_t bgFullyInRange = Qt::red;
uint8_t vendorFullyInRange = Qt::cyan;
uint8_t partiallyInRange = Qt::yellow;
switch (marking(index)) {
case BootGuardMarking::BootGuardFullyInRange: return QBrush((Qt::GlobalColor)bgFullyInRange); break;
case BootGuardMarking::VendorFullyInRange: return QBrush((Qt::GlobalColor)vendorFullyInRange); break;
case BootGuardMarking::PartiallyInRange: return QBrush((Qt::GlobalColor)partiallyInRange); break;
}
} }
} }
#endif #endif

View File

@ -19,6 +19,13 @@ enum ItemFixedState {
Fixed Fixed
}; };
enum BootGuardMarking {
None = 0, // Needs to be zero
PartiallyInRange,
BootGuardFullyInRange,
VendorFullyInRange
};
#if defined(QT_CORE_LIB) #if defined(QT_CORE_LIB)
// Use Qt classes // Use Qt classes
#include <QAbstractItemModel> #include <QAbstractItemModel>