@@ -47,19 +47,24 @@ MainWindow::MainWindow(QWidget* parent) :
47
47
restoreContestMenuDupeType ();
48
48
restoreContestMenuLinkExchange ();
49
49
50
- darkLightModeSwith = new SwitchButton (" " , ui->statusBar );
51
- darkIconLabel = new QLabel (" <html><img src=':/icons/light-dark-24px.svg'></html>" ,ui->statusBar );
50
+ themeButton = new QPushButton (this );
51
+ themeButton->setToolTip (tr (" Color Theme" ));
52
+ themeButton->setIcon (QIcon (QPixmap (" :/icons/color-palette-dark.svg" )));
53
+ themeButton->setFlat (true );
54
+
55
+ QMenu *themeMenu = new QMenu (this );
56
+ themeMenu->addAction (ui->actionThemeNative );
57
+ themeMenu->addAction (ui->actionThemeLight );
58
+ themeMenu->addAction (ui->actionThemeDark );
59
+ themeButton->setMenu (themeMenu);
52
60
53
61
/* Dark Mode is supported only in case of Fusion Style */
54
62
if ( QApplication::style ()->objectName ().compare (" fusion" ,
55
63
Qt::CaseSensitivity::CaseInsensitive) != 0 )
56
64
{
57
65
isFusionStyle = false ;
58
- darkLightModeSwith->setEnabled (false );
59
- darkIconLabel->setEnabled (false );
60
- darkLightModeSwith->setToolTip (tr (" Not enabled for non-Fusion style" ));
61
- darkModeToggle (Qt::Unchecked);
62
-
66
+ themeButton->setEnabled (false );
67
+ themeButton->setToolTip (tr (" Not enabled for non-Fusion style" ));
63
68
}
64
69
else
65
70
{
@@ -136,8 +141,7 @@ MainWindow::MainWindow(QWidget* parent) :
136
141
137
142
ui->statusBar ->addPermanentWidget (alertTextButton);
138
143
ui->statusBar ->addPermanentWidget (alertButton);
139
- ui->statusBar ->addPermanentWidget (darkLightModeSwith);
140
- ui->statusBar ->addPermanentWidget (darkIconLabel);
144
+ ui->statusBar ->addPermanentWidget (themeButton);
141
145
142
146
setContestMode (LogParam::getContestID ());
143
147
@@ -187,8 +191,15 @@ MainWindow::MainWindow(QWidget* parent) :
187
191
connect (this , &MainWindow::themeChanged, ui->rotatorWidget , &RotatorWidget::redrawMap);
188
192
connect (this , &MainWindow::themeChanged, stats, &StatisticsWidget::changeTheme);
189
193
190
- connect (darkLightModeSwith, &SwitchButton::stateChanged, this , &MainWindow::darkModeToggle);
191
- darkLightModeSwith->setChecked (LogParam::getMainWindowDarkMode ());
194
+ connect (ui->actionThemeNative , &QAction::triggered, this , [this ](bool checked) {
195
+ this ->themeInit (0 );
196
+ });
197
+ connect (ui->actionThemeDark , &QAction::triggered, this , [this ](bool checked) {
198
+ this ->themeInit (1 );
199
+ });
200
+ connect (ui->actionThemeLight , &QAction::triggered, this , [this ](bool checked) {
201
+ this ->themeInit (2 );
202
+ });
192
203
193
204
connect (Rig::instance (), &Rig::rigErrorPresent, this , &MainWindow::rigErrorHandler);
194
205
connect (Rig::instance (), &Rig::rigCWKeyOpenRequest, this , &MainWindow::cwKeyerConnectProfile);
@@ -536,7 +547,8 @@ QStringList MainWindow::getBuiltInStaticShortcutList() const
536
547
const QList<QShortcut*> allShortcuts = findChildren<QShortcut*>();
537
548
for ( QShortcut* shortcut : allShortcuts)
538
549
{
539
- if ( !shortcut->key ().toString ().isEmpty () )
550
+ if (!shortcut->key ().toString ().isEmpty ())
551
+
540
552
{
541
553
qCDebug (runtime) << " Built-In nonchangeble shortcut"
542
554
<< shortcut->key ().toString (QKeySequence::NativeText);
@@ -815,26 +827,125 @@ void MainWindow::showUpdateDialog(const QString &newVersion, const QString &repo
815
827
settings.setValue (" seenversion" , newVersion); // platform-depend parameter
816
828
}
817
829
818
- void MainWindow::darkModeToggle ( int mode )
830
+ void MainWindow::setDarkTheme ( )
819
831
{
820
832
FCT_IDENTIFICATION;
821
833
822
- qCDebug (function_parameters) << mode;
834
+ QPalette darkPalette;
835
+ QColor darkColor = QColor (45 , 45 , 45 );
836
+ QColor disabledColor = QColor (127 , 127 , 127 );
837
+ darkPalette.setColor (QPalette::Window, darkColor);
838
+ darkPalette.setColor (QPalette::WindowText, Qt::white);
839
+ darkPalette.setColor (QPalette::Base, QColor (18 , 18 , 18 ));
840
+ darkPalette.setColor (QPalette::AlternateBase, darkColor);
841
+ darkPalette.setColor (QPalette::Text, Qt::white);
842
+ darkPalette.setColor (QPalette::Disabled, QPalette::Text, disabledColor);
843
+ darkPalette.setColor (QPalette::Button, darkColor);
844
+ darkPalette.setColor (QPalette::ButtonText, Qt::white);
845
+ darkPalette.setColor (QPalette::Disabled, QPalette::ButtonText, disabledColor);
846
+ darkPalette.setColor (QPalette::BrightText, Qt::red);
847
+ darkPalette.setColor (QPalette::Link, QColor (42 , 130 , 218 ));
848
+ darkPalette.setColor (QPalette::Highlight, QColor (42 , 130 , 218 ));
849
+ darkPalette.setColor (QPalette::HighlightedText, Qt::black);
850
+ darkPalette.setColor (QPalette::Disabled, QPalette::HighlightedText, disabledColor);
823
851
824
- bool darkMode = (mode == Qt::Checked) ? true : false ;
825
- LogParam::setMainWindowDarkMode (darkMode);
852
+ qApp-> setPalette (darkPalette) ;
853
+ }
826
854
827
- if ( mode == Qt::Checked)
828
- setDarkMode ();
829
- else
830
- setLightMode ();
855
+ void MainWindow::setLightTheme ()
856
+ {
857
+ FCT_IDENTIFICATION;
858
+
859
+ QPalette lightPalette;
860
+ QColor lightColor = QColor (239 , 239 , 239 );
861
+ QColor disabledColor = QColor (190 , 190 , 190 );
862
+ lightPalette.setColor (QPalette::Window, lightColor);
863
+ lightPalette.setColor (QPalette::WindowText, Qt::black);
864
+ lightPalette.setColor (QPalette::Base, Qt::white);
865
+ lightPalette.setColor (QPalette::AlternateBase, lightColor);
866
+ lightPalette.setColor (QPalette::Text, Qt::black);
867
+ lightPalette.setColor (QPalette::Disabled, QPalette::Text, disabledColor);
868
+ lightPalette.setColor (QPalette::Button, lightColor);
869
+ lightPalette.setColor (QPalette::ButtonText, Qt::black);
870
+ lightPalette.setColor (QPalette::Disabled, QPalette::ButtonText, disabledColor);
871
+ lightPalette.setColor (QPalette::BrightText, Qt::white);
872
+ lightPalette.setColor (QPalette::Link, QColor (0 , 0 , 255 ));
873
+ lightPalette.setColor (QPalette::Highlight, QColor (48 , 140 , 198 ));
874
+ lightPalette.setColor (QPalette::HighlightedText, Qt::white);
875
+ lightPalette.setColor (QPalette::Disabled, QPalette::HighlightedText, Qt::white);
876
+
877
+ qApp->setPalette (lightPalette);
878
+
879
+ }
880
+
881
+ bool MainWindow::setNativeTheme ()
882
+ {
883
+ FCT_IDENTIFICATION;
884
+
885
+ qApp->setPalette (this ->style ()->standardPalette ());
886
+ bool isDark = false ;
887
+
888
+ #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
889
+ const auto scheme = QGuiApplication::styleHints ()->colorScheme ();
890
+ isDark = scheme == Qt::ColorScheme::Dark;
891
+ #else
892
+ const QPalette defaultPalette = this ->style ()->standardPalette ();
893
+ const auto text = defaultPalette.color (QPalette::WindowText);
894
+ const auto window = defaultPalette.color (QPalette::Window);
895
+ isDark = return text.lightness () > window.lightness ();
896
+ #endif // QT_VERSION
897
+
898
+ return isDark;
899
+ }
900
+
901
+ void MainWindow::themeInit (int mode)
902
+ {
903
+ FCT_IDENTIFICATION;
904
+
905
+ LogParam::setMainWindowDarkMode (mode);
906
+
907
+ ui->actionThemeNative ->setChecked (false );
908
+ ui->actionThemeLight ->setChecked (false );
909
+ ui->actionThemeDark ->setChecked (false );
910
+ bool isDark = false ;
911
+ switch (mode) {
912
+ case 0 :
913
+ ui->actionThemeNative ->setChecked (true );
914
+ isDark = this ->setNativeTheme ();
915
+ break ;
916
+ case 1 :
917
+ ui->actionThemeDark ->setChecked (true );
918
+ this ->setDarkTheme ();
919
+ isDark = true ;
920
+ break ;
921
+ case 2 :
922
+ ui->actionThemeLight ->setChecked (true );
923
+ this ->setLightTheme ();
924
+ break ;
925
+ }
831
926
832
927
QFile style (" :/res/stylesheet.css" );
833
928
style.open (QFile::ReadOnly | QIODevice::Text);
834
929
qApp->setStyleSheet (style.readAll ());
835
930
style.close ();
836
931
837
- emit themeChanged (darkMode);
932
+ if (isDark) {
933
+ themeButton->setIcon (QIcon (QPixmap (" :/icons/color-palette-dark.svg" )));
934
+ } else {
935
+ themeButton->setIcon (QIcon (QPixmap (" :/icons/color-palette-light.svg" )));
936
+ }
937
+
938
+ emit themeChanged (mode, isDark);
939
+ }
940
+
941
+ void MainWindow::changeEvent (QEvent *event)
942
+ {
943
+ if (event->type () == QEvent::ThemeChange) {
944
+ if (ui->actionThemeNative ->isChecked ()) {
945
+ this ->themeInit (0 );
946
+ }
947
+ }
948
+ QMainWindow::changeEvent (event);
838
949
}
839
950
840
951
void MainWindow::processSpotAlert (SpotAlert alert)
@@ -935,9 +1046,12 @@ void MainWindow::setLayoutGeometry()
935
1046
936
1047
QByteArray newGeometry;
937
1048
QByteArray newState;
938
- bool darkMode = false ;
939
- const QList<QPair<QString, QString>> bandmapWidgets = (layoutProfile.profileName .isEmpty ()) ? MainLayoutProfilesManager::toPairStringList (LogParam::getMainWindowBandmapWidgets ())
940
- : layoutProfile.addlBandmaps ;
1049
+ int darkMode = 0 ;
1050
+ const QList<QPair<QString, QString>> bandmapWidgets
1051
+ = (layoutProfile.profileName .isEmpty ())
1052
+ ? MainLayoutProfilesManager::toPairStringList (LogParam::getMainWindowBandmapWidgets ())
1053
+ : layoutProfile.addlBandmaps ;
1054
+
941
1055
if ( layoutProfile.mainGeometry != QByteArray ()
942
1056
|| layoutProfile.mainState != QByteArray () )
943
1057
{
@@ -970,7 +1084,7 @@ void MainWindow::setLayoutGeometry()
970
1084
connect (nt, &QTimer::timeout, this , [this , darkMode, newState]()
971
1085
{
972
1086
restoreState (newState);
973
- darkLightModeSwith-> setChecked (isFusionStyle && darkMode);
1087
+ this -> themeInit (isFusionStyle ? darkMode : 0 );
974
1088
connect (MainLayoutProfilesManager::instance (), &MainLayoutProfilesManager::profileChanged,
975
1089
this , &MainWindow::setSimplyLayoutGeometry);
976
1090
});
@@ -1011,7 +1125,7 @@ void MainWindow::setSimplyLayoutGeometry()
1011
1125
connect (nt, &QTimer::timeout, this , [this , layoutProfile]()
1012
1126
{
1013
1127
restoreState (layoutProfile.mainState );
1014
- darkLightModeSwith-> setChecked (isFusionStyle && layoutProfile.darkMode );
1128
+ this -> themeInit (isFusionStyle ? layoutProfile.darkMode : 0 );
1015
1129
});
1016
1130
nt->connect (nt, &QTimer::timeout, nt, &QTimer::deleteLater);
1017
1131
nt->start ();
@@ -1029,8 +1143,13 @@ void MainWindow::saveProfileLayoutGeometry()
1029
1143
layoutProfile.addlBandmaps = getNonVfoBandmapsParams ();
1030
1144
layoutProfile.mainGeometry = saveGeometry ();
1031
1145
layoutProfile.mainState = saveState ();
1032
- layoutProfile.darkMode = darkLightModeSwith->isChecked ();
1033
- layoutProfile.tabsexpanded = ui->newContactWidget ->getTabCollapseState ();
1146
+ layoutProfile.darkMode = 0 ;
1147
+ if (ui->actionThemeDark ->isChecked ()) {
1148
+ layoutProfile.darkMode = 1 ;
1149
+ } else if (ui->actionThemeLight ->isChecked ()) {
1150
+ layoutProfile.darkMode = 2 ;
1151
+ }
1152
+ layoutProfile.tabsexpanded = ui->newContactWidget ->getTabCollapseState ();
1034
1153
MainLayoutProfilesManager::instance ()->addProfile (layoutProfile.profileName , layoutProfile);
1035
1154
MainLayoutProfilesManager::instance ()->blockSignals (true ); // prevent screen flashing
1036
1155
MainLayoutProfilesManager::instance ()->save ();
@@ -1047,40 +1166,6 @@ void MainWindow::setEquipmentKeepOptions(bool)
1047
1166
// saveEquipmentConnOptions();
1048
1167
}
1049
1168
1050
-
1051
-
1052
- void MainWindow::setDarkMode ()
1053
- {
1054
- FCT_IDENTIFICATION;
1055
-
1056
- QPalette darkPalette;
1057
- QColor darkColor = QColor (45 ,45 ,45 );
1058
- QColor disabledColor = QColor (127 ,127 ,127 );
1059
- darkPalette.setColor (QPalette::Window, darkColor);
1060
- darkPalette.setColor (QPalette::WindowText, Qt::white);
1061
- darkPalette.setColor (QPalette::Base, QColor (18 ,18 ,18 ));
1062
- darkPalette.setColor (QPalette::AlternateBase, darkColor);
1063
- darkPalette.setColor (QPalette::Text, Qt::white);
1064
- darkPalette.setColor (QPalette::Disabled, QPalette::Text, disabledColor);
1065
- darkPalette.setColor (QPalette::Button, darkColor);
1066
- darkPalette.setColor (QPalette::ButtonText, Qt::white);
1067
- darkPalette.setColor (QPalette::Disabled, QPalette::ButtonText, disabledColor);
1068
- darkPalette.setColor (QPalette::BrightText, Qt::red);
1069
- darkPalette.setColor (QPalette::Link, QColor (42 , 130 , 218 ));
1070
- darkPalette.setColor (QPalette::Highlight, QColor (42 , 130 , 218 ));
1071
- darkPalette.setColor (QPalette::HighlightedText, Qt::black);
1072
- darkPalette.setColor (QPalette::Disabled, QPalette::HighlightedText, disabledColor);
1073
-
1074
- qApp->setPalette (darkPalette);
1075
- }
1076
-
1077
- void MainWindow::setLightMode ()
1078
- {
1079
- FCT_IDENTIFICATION;
1080
-
1081
- qApp->setPalette (this ->style ()->standardPalette ());
1082
- }
1083
-
1084
1169
void MainWindow::setupActivitiesMenu ()
1085
1170
{
1086
1171
FCT_IDENTIFICATION;
0 commit comments