More dark mode fixes for Windows

Also enforce modality for progress dialog if possible
This commit is contained in:
Cacodemon345
2025-05-31 17:42:46 +06:00
parent db8de7317d
commit 06e1d0a5eb
6 changed files with 23 additions and 11 deletions

View File

@@ -22,6 +22,10 @@
#include "qt_vmmanager_details.hpp"
#include "ui_qt_vmmanager_details.h"
#ifdef Q_OS_WINDOWS
extern bool windows_is_light_theme();
#endif
VMManagerDetails::VMManagerDetails(QWidget *parent) :
QWidget(parent), ui(new Ui::VMManagerDetails) {
ui->setupUi(this);
@@ -71,10 +75,10 @@ VMManagerDetails::VMManagerDetails(QWidget *parent) :
screenshotThumbnailSize = QSize(240, 160);
// Set the icons for the screenshot navigation buttons
ui->screenshotNext->setIcon(QApplication::style()->standardIcon(QStyle::SP_MediaSeekForward));
ui->screenshotPrevious->setIcon(QApplication::style()->standardIcon(QStyle::SP_MediaSeekBackward));
ui->screenshotNextTB->setIcon(QApplication::style()->standardIcon(QStyle::SP_MediaSeekForward));
ui->screenshotPreviousTB->setIcon(QApplication::style()->standardIcon(QStyle::SP_MediaSeekBackward));
ui->screenshotNext->setIcon(QApplication::style()->standardIcon(QStyle::SP_ArrowRight));
ui->screenshotPrevious->setIcon(QApplication::style()->standardIcon(QStyle::SP_ArrowLeft));
ui->screenshotNextTB->setIcon(QApplication::style()->standardIcon(QStyle::SP_ArrowRight));
ui->screenshotPreviousTB->setIcon(QApplication::style()->standardIcon(QStyle::SP_ArrowLeft));
// Disabled by default
ui->screenshotNext->setEnabled(false);
ui->screenshotPrevious->setEnabled(false);
@@ -90,11 +94,19 @@ VMManagerDetails::VMManagerDetails(QWidget *parent) :
ui->screenshotPrevious->setVisible(false);
QString toolButtonStyleSheet;
// Simple method to try and determine if light mode is enabled
#ifdef Q_OS_WINDOWS
const bool lightMode = windows_is_light_theme();
#else
const bool lightMode = QApplication::palette().window().color().value() > QApplication::palette().windowText().color().value();
#endif
if (lightMode) {
toolButtonStyleSheet = "QToolButton {background: transparent; border: none; padding: 5px} QToolButton:hover {background: palette(midlight)} QToolButton:pressed {background: palette(mid)}";
} else {
#ifndef Q_OS_WINDOWS
toolButtonStyleSheet = "QToolButton {background: transparent; border: none; padding: 5px} QToolButton:hover {background: palette(dark)} QToolButton:pressed {background: palette(mid)}";
#else
toolButtonStyleSheet = "QToolButton {padding: 5px}";
#endif
}
ui->ssNavTBHolder->setStyleSheet(toolButtonStyleSheet);

View File

@@ -390,7 +390,7 @@ VMManagerMain::addNewSystem(const QString &name, const QString &dir, const QStri
return;
}
const auto current_index = ui->listView->currentIndex();
vm_model->reload();
vm_model->reload(this);
const auto created_object = vm_model->getIndexForConfigFile(new_system->config_file);
if (created_object.row() < 0) {
// For some reason the index of the new object couldn't be determined. Fall back to the old index.

View File

@@ -95,10 +95,10 @@ VMManagerModel::getConfigObjectForIndex(const QModelIndex &index) const
return machines.at(index.row());
}
void
VMManagerModel::reload()
VMManagerModel::reload(QWidget* parent)
{
// Scan for configs
auto machines_vec = VMManagerSystem::scanForConfigs();
auto machines_vec = VMManagerSystem::scanForConfigs(parent);
for (const auto &scanned_config : machines_vec) {
int found = 0;
for (const auto &existing_config : machines) {

View File

@@ -54,7 +54,7 @@ public:
[[nodiscard]] VMManagerSystem * getConfigObjectForIndex(const QModelIndex &index) const;
QModelIndex getIndexForConfigFile(const QFileInfo& config_file);
void reload();
void reload(QWidget* parent = nullptr);
void updateDisplayName(const QModelIndex &index, const QString &newDisplayName);
QHash <QString, int> getProcessStats();
signals:

View File

@@ -107,9 +107,9 @@ VMManagerSystem::~VMManagerSystem() {
}
QVector<VMManagerSystem *>
VMManagerSystem::scanForConfigs(const QString &searchPath)
VMManagerSystem::scanForConfigs(QWidget* parent, const QString &searchPath)
{
QProgressDialog progDialog;
QProgressDialog progDialog(parent);
unsigned int found = 0;
progDialog.setCancelButton(nullptr);
progDialog.setWindowTitle(tr("Searching for VMs..."));

View File

@@ -84,7 +84,7 @@ public:
~VMManagerSystem() override;
static QVector<VMManagerSystem *> scanForConfigs(const QString &searchPath = {});
static QVector<VMManagerSystem *> scanForConfigs(QWidget* parent = nullptr, const QString &searchPath = {});
static QString generateTemporaryFilename();
QFileInfo config_file;