Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/LogParam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1129,10 +1129,10 @@ void LogParam::setMainWindowAlertBeep(bool state)

bool LogParam::getMainWindowDarkMode()
{
return getParam("mainwindow/darkmode", false).toBool();
return getParam("mainwindow/darkmode", 0).toInt();
}

void LogParam::setMainWindowDarkMode(bool state)
void LogParam::setMainWindowDarkMode(int state)
{
setParam("mainwindow/darkmode", state);
}
Expand Down
2 changes: 1 addition & 1 deletion core/LogParam.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ class LogParam : public QObject
static bool getMainWindowAlertBeep();
static void setMainWindowAlertBeep(bool state);
static bool getMainWindowDarkMode();
static void setMainWindowDarkMode(bool state);
static void setMainWindowDarkMode(int state);
static QByteArray getMainWindowGeometry();
static void setMainWindowGeometry(const QByteArray &state);
static QByteArray getMainWindowState();
Expand Down
2 changes: 1 addition & 1 deletion data/MainLayoutProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ MainLayoutProfilesManager::MainLayoutProfilesManager() :
profileDB.detailColC = toIntList(profileQuery.value(5).toString());
profileDB.mainGeometry = QByteArray::fromBase64(profileQuery.value(6).toString().toUtf8());
profileDB.mainState = QByteArray::fromBase64(profileQuery.value(7).toString().toUtf8());
profileDB.darkMode = profileQuery.value(8).toBool();
profileDB.darkMode = profileQuery.value(8).toInt();
profileDB.tabsexpanded = profileQuery.value(9).toBool();
profileDB.addlBandmaps = toPairStringList(profileQuery.value(10).toString());
addProfile(profileDB.profileName, profileDB);
Expand Down
8 changes: 6 additions & 2 deletions data/MainLayoutProfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ class MainLayoutProfile
{

public:
MainLayoutProfile(){darkMode = false; tabsexpanded = true;};
MainLayoutProfile()
{
darkMode = 0;
tabsexpanded = true;
};

QString profileName;
QList<int> rowA;
Expand All @@ -21,7 +25,7 @@ class MainLayoutProfile
QList<int> detailColC;
QByteArray mainGeometry;
QByteArray mainState;
bool darkMode;
int darkMode;
bool tabsexpanded;
QList<QPair<QString, QString>> addlBandmaps;

Expand Down
1 change: 1 addition & 0 deletions res/icons/color-palette-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions res/icons/color-palette-light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion res/icons/icons.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<file>cancel-24px.svg</file>
<file>info-24px.svg</file>
<file>close-24px.svg</file>
<file>light-dark-24px.svg</file>
<file>alert.svg</file>
<file>connect.svg</file>
<file>disconnect.svg</file>
Expand All @@ -35,5 +34,7 @@
<file>delete-button.svg</file>
<file>new-window.svg</file>
<file>clear-button.svg</file>
<file>color-palette-light.svg</file>
<file>color-palette-dark.svg</file>
</qresource>
</RCC>
1 change: 0 additions & 1 deletion res/icons/light-dark-24px.svg

This file was deleted.

209 changes: 147 additions & 62 deletions ui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,24 @@ MainWindow::MainWindow(QWidget* parent) :
restoreContestMenuDupeType();
restoreContestMenuLinkExchange();

darkLightModeSwith = new SwitchButton("", ui->statusBar);
darkIconLabel = new QLabel("<html><img src=':/icons/light-dark-24px.svg'></html>",ui->statusBar);
themeButton = new QPushButton(this);
themeButton->setToolTip(tr("Color Theme"));
themeButton->setIcon(QIcon(QPixmap(":/icons/color-palette-dark.svg")));
themeButton->setFlat(true);

QMenu *themeMenu = new QMenu(this);
themeMenu->addAction(ui->actionThemeNative);
themeMenu->addAction(ui->actionThemeLight);
themeMenu->addAction(ui->actionThemeDark);
themeButton->setMenu(themeMenu);

/* Dark Mode is supported only in case of Fusion Style */
if ( QApplication::style()->objectName().compare("fusion",
Qt::CaseSensitivity::CaseInsensitive) != 0)
{
isFusionStyle = false;
darkLightModeSwith->setEnabled(false);
darkIconLabel->setEnabled(false);
darkLightModeSwith->setToolTip(tr("Not enabled for non-Fusion style"));
darkModeToggle(Qt::Unchecked);

themeButton->setEnabled(false);
themeButton->setToolTip(tr("Not enabled for non-Fusion style"));
}
else
{
Expand Down Expand Up @@ -136,8 +141,7 @@ MainWindow::MainWindow(QWidget* parent) :

ui->statusBar->addPermanentWidget(alertTextButton);
ui->statusBar->addPermanentWidget(alertButton);
ui->statusBar->addPermanentWidget(darkLightModeSwith);
ui->statusBar->addPermanentWidget(darkIconLabel);
ui->statusBar->addPermanentWidget(themeButton);

setContestMode(LogParam::getContestID());

Expand Down Expand Up @@ -187,8 +191,15 @@ MainWindow::MainWindow(QWidget* parent) :
connect(this, &MainWindow::themeChanged, ui->rotatorWidget, &RotatorWidget::redrawMap);
connect(this, &MainWindow::themeChanged, stats, &StatisticsWidget::changeTheme);

connect(darkLightModeSwith, &SwitchButton::stateChanged, this, &MainWindow::darkModeToggle);
darkLightModeSwith->setChecked(LogParam::getMainWindowDarkMode());
connect(ui->actionThemeNative, &QAction::triggered, this, [this](bool checked) {
this->themeInit(0);
});
connect(ui->actionThemeDark, &QAction::triggered, this, [this](bool checked) {
this->themeInit(1);
});
connect(ui->actionThemeLight, &QAction::triggered, this, [this](bool checked) {
this->themeInit(2);
});

connect(Rig::instance(), &Rig::rigErrorPresent, this, &MainWindow::rigErrorHandler);
connect(Rig::instance(), &Rig::rigCWKeyOpenRequest, this, &MainWindow::cwKeyerConnectProfile);
Expand Down Expand Up @@ -536,7 +547,8 @@ QStringList MainWindow::getBuiltInStaticShortcutList() const
const QList<QShortcut*> allShortcuts = findChildren<QShortcut*>();
for ( QShortcut* shortcut : allShortcuts)
{
if ( !shortcut->key().toString().isEmpty() )
if (!shortcut->key().toString().isEmpty())

{
qCDebug(runtime) << "Built-In nonchangeble shortcut"
<< shortcut->key().toString(QKeySequence::NativeText);
Expand Down Expand Up @@ -815,26 +827,125 @@ void MainWindow::showUpdateDialog(const QString &newVersion, const QString &repo
settings.setValue("seenversion", newVersion); // platform-depend parameter
}

void MainWindow::darkModeToggle(int mode)
void MainWindow::setDarkTheme()
{
FCT_IDENTIFICATION;

qCDebug(function_parameters) << mode;
QPalette darkPalette;
QColor darkColor = QColor(45, 45, 45);
QColor disabledColor = QColor(127, 127, 127);
darkPalette.setColor(QPalette::Window, darkColor);
darkPalette.setColor(QPalette::WindowText, Qt::white);
darkPalette.setColor(QPalette::Base, QColor(18, 18, 18));
darkPalette.setColor(QPalette::AlternateBase, darkColor);
darkPalette.setColor(QPalette::Text, Qt::white);
darkPalette.setColor(QPalette::Disabled, QPalette::Text, disabledColor);
darkPalette.setColor(QPalette::Button, darkColor);
darkPalette.setColor(QPalette::ButtonText, Qt::white);
darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, disabledColor);
darkPalette.setColor(QPalette::BrightText, Qt::red);
darkPalette.setColor(QPalette::Link, QColor(42, 130, 218));
darkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218));
darkPalette.setColor(QPalette::HighlightedText, Qt::black);
darkPalette.setColor(QPalette::Disabled, QPalette::HighlightedText, disabledColor);

bool darkMode = (mode == Qt::Checked) ? true: false;
LogParam::setMainWindowDarkMode(darkMode);
qApp->setPalette(darkPalette);
}

if ( mode == Qt::Checked)
setDarkMode();
else
setLightMode();
void MainWindow::setLightTheme()
{
FCT_IDENTIFICATION;

QPalette lightPalette;
QColor lightColor = QColor(239, 239, 239);
QColor disabledColor = QColor(190, 190, 190);
lightPalette.setColor(QPalette::Window, lightColor);
lightPalette.setColor(QPalette::WindowText, Qt::black);
lightPalette.setColor(QPalette::Base, Qt::white);
lightPalette.setColor(QPalette::AlternateBase, lightColor);
lightPalette.setColor(QPalette::Text, Qt::black);
lightPalette.setColor(QPalette::Disabled, QPalette::Text, disabledColor);
lightPalette.setColor(QPalette::Button, lightColor);
lightPalette.setColor(QPalette::ButtonText, Qt::black);
lightPalette.setColor(QPalette::Disabled, QPalette::ButtonText, disabledColor);
lightPalette.setColor(QPalette::BrightText, Qt::white);
lightPalette.setColor(QPalette::Link, QColor(0, 0, 255));
lightPalette.setColor(QPalette::Highlight, QColor(48, 140, 198));
lightPalette.setColor(QPalette::HighlightedText, Qt::white);
lightPalette.setColor(QPalette::Disabled, QPalette::HighlightedText, Qt::white);

qApp->setPalette(lightPalette);

}

bool MainWindow::setNativeTheme()
{
FCT_IDENTIFICATION;

qApp->setPalette(this->style()->standardPalette());
bool isDark = false;

#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
const auto scheme = QGuiApplication::styleHints()->colorScheme();
isDark = scheme == Qt::ColorScheme::Dark;
#else
const QPalette defaultPalette = this->style()->standardPalette();
const auto text = defaultPalette.color(QPalette::WindowText);
const auto window = defaultPalette.color(QPalette::Window);
isDark = text.lightness() > window.lightness();
#endif // QT_VERSION

return isDark;
}

void MainWindow::themeInit(int mode)
{
FCT_IDENTIFICATION;

LogParam::setMainWindowDarkMode(mode);

ui->actionThemeNative->setChecked(false);
ui->actionThemeLight->setChecked(false);
ui->actionThemeDark->setChecked(false);
bool isDark = false;
switch (mode) {
case 0:
ui->actionThemeNative->setChecked(true);
isDark = this->setNativeTheme();
break;
case 1:
ui->actionThemeDark->setChecked(true);
this->setDarkTheme();
isDark = true;
break;
case 2:
ui->actionThemeLight->setChecked(true);
this->setLightTheme();
break;
}

QFile style(":/res/stylesheet.css");
style.open(QFile::ReadOnly | QIODevice::Text);
qApp->setStyleSheet(style.readAll());
style.close();

emit themeChanged(darkMode);
if (isDark) {
themeButton->setIcon(QIcon(QPixmap(":/icons/color-palette-dark.svg")));
} else {
themeButton->setIcon(QIcon(QPixmap(":/icons/color-palette-light.svg")));
}

emit themeChanged(mode, isDark);
}

void MainWindow::changeEvent(QEvent *event)
{
if (event->type() == QEvent::ThemeChange) {
if (ui->actionThemeNative->isChecked()) {
this->themeInit(0);
}
}
QMainWindow::changeEvent(event);
}

void MainWindow::processSpotAlert(SpotAlert alert)
Expand Down Expand Up @@ -935,9 +1046,12 @@ void MainWindow::setLayoutGeometry()

QByteArray newGeometry;
QByteArray newState;
bool darkMode = false;
const QList<QPair<QString, QString>> bandmapWidgets = (layoutProfile.profileName.isEmpty()) ? MainLayoutProfilesManager::toPairStringList(LogParam::getMainWindowBandmapWidgets())
: layoutProfile.addlBandmaps;
int darkMode = 0;
const QList<QPair<QString, QString>> bandmapWidgets
= (layoutProfile.profileName.isEmpty())
? MainLayoutProfilesManager::toPairStringList(LogParam::getMainWindowBandmapWidgets())
: layoutProfile.addlBandmaps;

if ( layoutProfile.mainGeometry != QByteArray()
|| layoutProfile.mainState != QByteArray() )
{
Expand Down Expand Up @@ -970,7 +1084,7 @@ void MainWindow::setLayoutGeometry()
connect(nt, &QTimer::timeout, this, [this, darkMode, newState]()
{
restoreState(newState);
darkLightModeSwith->setChecked(isFusionStyle && darkMode);
this->themeInit(isFusionStyle ? darkMode : 0);
connect(MainLayoutProfilesManager::instance(), &MainLayoutProfilesManager::profileChanged,
this, &MainWindow::setSimplyLayoutGeometry);
});
Expand Down Expand Up @@ -1011,7 +1125,7 @@ void MainWindow::setSimplyLayoutGeometry()
connect(nt, &QTimer::timeout, this, [this, layoutProfile]()
{
restoreState(layoutProfile.mainState);
darkLightModeSwith->setChecked(isFusionStyle && layoutProfile.darkMode);
this->themeInit(isFusionStyle ? layoutProfile.darkMode : 0);
});
nt->connect(nt, &QTimer::timeout, nt, &QTimer::deleteLater);
nt->start();
Expand All @@ -1029,8 +1143,13 @@ void MainWindow::saveProfileLayoutGeometry()
layoutProfile.addlBandmaps = getNonVfoBandmapsParams();
layoutProfile.mainGeometry = saveGeometry();
layoutProfile.mainState = saveState();
layoutProfile.darkMode = darkLightModeSwith->isChecked();
layoutProfile.tabsexpanded = ui->newContactWidget->getTabCollapseState();
layoutProfile.darkMode = 0;
if (ui->actionThemeDark->isChecked()) {
layoutProfile.darkMode = 1;
} else if (ui->actionThemeLight->isChecked()) {
layoutProfile.darkMode = 2;
}
layoutProfile.tabsexpanded = ui->newContactWidget->getTabCollapseState();
MainLayoutProfilesManager::instance()->addProfile(layoutProfile.profileName, layoutProfile);
MainLayoutProfilesManager::instance()->blockSignals(true); // prevent screen flashing
MainLayoutProfilesManager::instance()->save();
Expand All @@ -1047,40 +1166,6 @@ void MainWindow::setEquipmentKeepOptions(bool)
//saveEquipmentConnOptions();
}



void MainWindow::setDarkMode()
{
FCT_IDENTIFICATION;

QPalette darkPalette;
QColor darkColor = QColor(45,45,45);
QColor disabledColor = QColor(127,127,127);
darkPalette.setColor(QPalette::Window, darkColor);
darkPalette.setColor(QPalette::WindowText, Qt::white);
darkPalette.setColor(QPalette::Base, QColor(18,18,18));
darkPalette.setColor(QPalette::AlternateBase, darkColor);
darkPalette.setColor(QPalette::Text, Qt::white);
darkPalette.setColor(QPalette::Disabled, QPalette::Text, disabledColor);
darkPalette.setColor(QPalette::Button, darkColor);
darkPalette.setColor(QPalette::ButtonText, Qt::white);
darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, disabledColor);
darkPalette.setColor(QPalette::BrightText, Qt::red);
darkPalette.setColor(QPalette::Link, QColor(42, 130, 218));
darkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218));
darkPalette.setColor(QPalette::HighlightedText, Qt::black);
darkPalette.setColor(QPalette::Disabled, QPalette::HighlightedText, disabledColor);

qApp->setPalette(darkPalette);
}

void MainWindow::setLightMode()
{
FCT_IDENTIFICATION;

qApp->setPalette(this->style()->standardPalette());
}

void MainWindow::setupActivitiesMenu()
{
FCT_IDENTIFICATION;
Expand Down
Loading
Loading