mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-09-29 05:44:14 +02:00
Merge branch 'master' into feature-3dmouse-spnav
This commit is contained in:
+94
-4
@@ -167,9 +167,7 @@ QETApp::QETApp() :
|
||||
if (m_splash_screen) {
|
||||
m_splash_screen -> hide();
|
||||
}
|
||||
|
||||
checkBackupFiles();
|
||||
|
||||
|
||||
#ifdef QET_SPACEMOUSE_SUPPORT
|
||||
//Always safe to construct: it silently does nothing when spacenavd
|
||||
//isn't running or no device is attached, which is the common case
|
||||
@@ -177,6 +175,17 @@ QETApp::QETApp() :
|
||||
//SpaceMouseListener's class comment.
|
||||
m_space_mouse_listener = new SpaceMouseListener(this);
|
||||
#endif
|
||||
|
||||
//Deferred so this constructor returns before the prompts appear.
|
||||
//checkBackupFiles() opens modal dialogs, and main() still has work to
|
||||
//do once we return -- in particular connecting
|
||||
//SingleApplication::receivedMessage to receiveMessage(). While those
|
||||
//prompts were up that connection did not exist yet, so a file handed
|
||||
//to the already-running instance during start-up was accepted by the
|
||||
//socket and then dropped on the floor.
|
||||
QMetaObject::invokeMethod(this, [this]() {
|
||||
checkBackupFiles();
|
||||
}, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1828,6 +1837,81 @@ void QETApp::useSystemPalette(bool use) {
|
||||
QET::Palette::refreshStyleSheets();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QETApp::useCustomPalette
|
||||
Apply a user-chosen color as the application-wide palette.
|
||||
Builds a full QPalette from \a color, keeping the system palette
|
||||
as a fallback for roles we don't touch.
|
||||
@param color the user-chosen base color
|
||||
*/
|
||||
void QETApp::useCustomPalette(const QColor &color) {
|
||||
if (!color.isValid())
|
||||
return;
|
||||
|
||||
// Derive readable text colors from the chosen color.
|
||||
const bool dark = color.lightness() < 128;
|
||||
const QColor text = dark ? QColor(220, 220, 220) : QColor(30, 30, 30);
|
||||
const QColor disabled_text = dark ? QColor(175, 175, 175) : QColor(128, 128, 128);
|
||||
|
||||
// Slightly lighter/darker for button and window shading.
|
||||
QColor button = color;
|
||||
button = QColor::fromHslF(color.hslHueF(),
|
||||
color.hslSaturationF(),
|
||||
dark ? qMin(color.lightnessF() + 0.08, 1.0)
|
||||
: qMax(color.lightnessF() - 0.08, 0.0));
|
||||
QColor light = QColor::fromHslF(color.hslHueF(),
|
||||
color.hslSaturationF(),
|
||||
dark ? qMin(color.lightnessF() + 0.15, 1.0)
|
||||
: qMax(color.lightnessF() - 0.15, 0.0));
|
||||
QColor mid = QColor::fromHslF(color.hslHueF(),
|
||||
color.hslSaturationF(),
|
||||
dark ? qMin(color.lightnessF() + 0.04, 1.0)
|
||||
: qMax(color.lightnessF() - 0.04, 0.0));
|
||||
QColor dark_c = QColor::fromHslF(color.hslHueF(),
|
||||
color.hslSaturationF(),
|
||||
dark ? qMin(color.lightnessF() - 0.04, 1.0)
|
||||
: qMax(color.lightnessF() - 0.12, 0.0));
|
||||
QColor shadow = QColor::fromHslF(color.hslHueF(),
|
||||
color.hslSaturationF(),
|
||||
dark ? qMin(color.lightnessF() - 0.10, 1.0)
|
||||
: qMax(color.lightnessF() - 0.20, 0.0));
|
||||
|
||||
QPalette p;
|
||||
// Active and Inactive get the same colors; only Disabled differs.
|
||||
for (auto group : {QPalette::Active, QPalette::Inactive}) {
|
||||
p.setColor(group, QPalette::Window, color);
|
||||
p.setColor(group, QPalette::WindowText, text);
|
||||
p.setColor(group, QPalette::Base, color);
|
||||
p.setColor(group, QPalette::AlternateBase, button);
|
||||
p.setColor(group, QPalette::Text, text);
|
||||
p.setColor(group, QPalette::Button, button);
|
||||
p.setColor(group, QPalette::ButtonText, text);
|
||||
p.setColor(group, QPalette::BrightText, dark ? QColor(255,90,90) : Qt::white);
|
||||
p.setColor(group, QPalette::Highlight, QColor(30, 96, 176));
|
||||
p.setColor(group, QPalette::HighlightedText, Qt::white);
|
||||
p.setColor(group, QPalette::ToolTipBase, button);
|
||||
p.setColor(group, QPalette::ToolTipText, text);
|
||||
p.setColor(group, QPalette::Light, light);
|
||||
p.setColor(group, QPalette::Midlight, mid);
|
||||
p.setColor(group, QPalette::Mid, mid);
|
||||
p.setColor(group, QPalette::Dark, dark_c);
|
||||
p.setColor(group, QPalette::Shadow, shadow);
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)
|
||||
p.setColor(group, QPalette::Accent, QColor(30, 96, 176));
|
||||
#endif
|
||||
}
|
||||
p.setColor(QPalette::Disabled, QPalette::WindowText, disabled_text);
|
||||
p.setColor(QPalette::Disabled, QPalette::Text, disabled_text);
|
||||
p.setColor(QPalette::Disabled, QPalette::ButtonText, disabled_text);
|
||||
|
||||
qApp->setPalette(p);
|
||||
qApp->setStyleSheet(QString());
|
||||
|
||||
// Switch icon theme to match light/dark.
|
||||
applyIconTheme(p);
|
||||
QET::Palette::refreshStyleSheets();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QETApp::quitQET
|
||||
Request the closing of all windows;
|
||||
@@ -2419,7 +2503,13 @@ void QETApp::initStyle()
|
||||
|
||||
//Apply or not the system style
|
||||
QSettings settings;
|
||||
useSystemPalette(settings.value("usesystemcolors", true).toBool());
|
||||
if (settings.value("usesystemcolors", true).toBool()) {
|
||||
useSystemPalette(true);
|
||||
} else if (settings.contains("customapplicationcolor")) {
|
||||
useCustomPalette(QColor(settings.value("customapplicationcolor").toString()));
|
||||
} else {
|
||||
useSystemPalette(false);
|
||||
}
|
||||
|
||||
#if defined(Q_OS_MACOS) && QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
|
||||
// Setting an application palette stops Qt from following the OS
|
||||
|
||||
Reference in New Issue
Block a user