2222#include < QSystemTrayIcon>
2323#include < QLocale>
2424#include < QMessageBox>
25+ #include < qstylehints.h>
2526#include " aformsettings.h"
2627#include " soundplayer.h"
2728#include " chathelper.h"
@@ -64,7 +65,6 @@ lmFormSettings::lmFormSettings(QWidget *parent, Qt::WindowFlags flags) : QDialog
6465 connect (ui.btnPlaySound , SIGNAL (clicked ()), this , SLOT (btnPlaySound_clicked ()));
6566 connect (ui.btnSoundPath , SIGNAL (clicked ()), this , SLOT (btnSoundPath_clicked ()));
6667 connect (ui.btnResetSounds , SIGNAL (clicked ()), this , SLOT (btnResetSounds_clicked ()));
67- connect (ui.btnRefresfTheme , SIGNAL (clicked ()), this , SLOT (btnRefreshTheme_clicked ()));
6868}
6969
7070lmFormSettings::~lmFormSettings (void ) {
@@ -111,16 +111,12 @@ void lmFormSettings::init(void) {
111111 }
112112// =========================================================
113113
114- Themes themes = lmTheme::availableThemes ();
115- for (int index = 0 ; index < themes.count (); index++)
116- ui.cboTheme ->addItem (themes.at (index).name , themes.at (index).path );
117-
118114 for (int index = 0 ; index < ULV_Max; index++)
119115 ui.cboUserListView ->addItem (lmStrings::userListView ()[index], index);
120116
121- fontSize = 0 ;
122- font = QApplication::font ();
123- color = QApplication::palette ().text ().color ();
117+ fontSize = 0 ;
118+ font = QApplication::font ();
119+ color = QApplication::palette ().text ().color ();
124120 ui.lvCategories ->setCurrentRow (0 );
125121
126122 setWindowIcon (QIcon (IDR_APPICON));
@@ -298,13 +294,14 @@ void lmFormSettings::btnReset_clicked(void) {
298294}
299295
300296void lmFormSettings::cboTheme_currentIndexChanged (int index) {
301- QString themePath = ui.cboTheme ->itemData (index, Qt::UserRole).toString ();
297+ int colorSchemeIndex = ui.cboTheme ->currentIndex ();
298+ changeColorScheme (colorSchemeIndex);
302299
303300 pMessageLog->fontSizeVal = FS_SMALL;
304301 pMessageLog->localId = " Myself" ;
305302 pMessageLog->peerId = " Jack" ;
306303 pMessageLog->messageTime = true ;
307- pMessageLog->initMessageLog (themePath);
304+ pMessageLog->initMessageLog (" " ); // initializing empty theme path, so it retargets to default. remove later. NEED2TEST
308305
309306 MessageXml msg;
310307 msg.addData (XN_TIME, QString::number (QDateTime::currentMSecsSinceEpoch ()));
@@ -442,12 +439,6 @@ void lmFormSettings::btnResetSounds_clicked(void) {
442439 lvSounds_currentRowChanged (ui.lvSounds ->currentRow ());
443440}
444441
445- void lmFormSettings::btnRefreshTheme_clicked ()
446- {
447- pMessageLog->reloadTheme ();
448- cboTheme_currentIndexChanged (ui.cboTheme ->currentIndex ());
449- }
450-
451442void lmFormSettings::setPageHeaderStyle (QLabel* pLabel) {
452443 QFont font = pLabel->font ();
453444 int fontSize = pLabel->fontInfo ().pixelSize ();
@@ -599,14 +590,9 @@ void lmFormSettings::loadSettings(void) {
599590 ui.rdbFileBottom ->setChecked (!pSettings->value (IDS_FILETOP, IDS_FILETOP_VAL).toBool ());
600591 ui.txtFilePath ->setText (DefinitionsDir::fileStorageDir ());
601592
602- QString themePath = pSettings->value (IDS_THEME, IDS_THEME_VAL).toString ();
603- for (int index = 0 ; index < ui.cboTheme ->count (); index ++) {
604- QString theme = ui.cboTheme ->itemData (index, Qt::UserRole).toString ();
605- if (themePath.compare (theme) == 0 ) {
606- ui.cboTheme ->setCurrentIndex (index);
607- break ;
608- }
609- }
593+ int colorSchemeIndex = pSettings->value (IDS_COLORSCHEME, IDS_COLORSCHEME_VAL).toInt ();
594+ ui.cboTheme ->setCurrentIndex (colorSchemeIndex);
595+
610596 int userListView = pSettings->value (IDS_USERLISTVIEW, IDS_USERLISTVIEW_VAL).toInt ();
611597 ui.cboUserListView ->setCurrentIndex (userListView);
612598 ui.chkUserListToolTip ->setChecked (pSettings->value (IDS_STATUSTOOLTIP, IDS_STATUSTOOLTIP_VAL).toBool ());
@@ -615,6 +601,24 @@ void lmFormSettings::loadSettings(void) {
615601 ui.rdbCmdEnter ->setChecked (pSettings->value (IDS_SENDKEYMOD, IDS_SENDKEYMOD_VAL).toBool ());
616602}
617603
604+ void lmFormSettings::changeColorScheme (int index){
605+ switch (index) {
606+ case 0 :
607+ qApp->styleHints ()->setColorScheme (Qt::ColorScheme::Unknown);
608+ break ;
609+ case 1 :
610+ qApp->styleHints ()->setColorScheme (Qt::ColorScheme::Light);
611+ break ;
612+ case 2 :
613+ qApp->styleHints ()->setColorScheme (Qt::ColorScheme::Dark);
614+ break ;
615+ default :
616+ break ;
617+ }
618+ QEvent event (QEvent::ThemeChange);
619+ QCoreApplication::sendEvent (qApp, &event);
620+ }
621+
618622void lmFormSettings::saveSettings (void ) {
619623 pSettings->setValue (IDS_VERSION, IDA_VERSION);
620624
@@ -717,8 +721,8 @@ void lmFormSettings::saveSettings(void) {
717721 pSettings->setValue (IDS_FILETOP, ui.rdbFileTop ->isChecked (), IDS_FILETOP_VAL);
718722 pSettings->setValue (IDS_FILESTORAGEPATH, ui.txtFilePath ->text (), IDS_FILESTORAGEPATH_VAL);
719723
720- QString themePath = ui.cboTheme ->itemData (ui. cboTheme -> currentIndex (), Qt::UserRole). toString ();
721- pSettings->setValue (IDS_THEME, themePath, IDS_THEME_VAL );
724+ int colorSchemeIndex = ui.cboTheme ->currentIndex ();
725+ pSettings->setValue (IDS_COLORSCHEME, colorSchemeIndex, IDS_COLORSCHEME_VAL );
722726 pSettings->setValue (IDS_USERLISTVIEW, ui.cboUserListView ->currentIndex (), IDS_USERLISTVIEW_VAL);
723727 pSettings->setValue (IDS_STATUSTOOLTIP, ui.chkUserListToolTip ->isChecked (), IDS_STATUSTOOLTIP_VAL);
724728
0 commit comments