Skip to content

Commit 998e773

Browse files
committed
Replaced theme selection with colorschemes
1 parent 9d76590 commit 998e773

File tree

6 files changed

+69
-38
lines changed

6 files changed

+69
-38
lines changed

CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ qt6_add_translations(LanMessenger
6464
#==========================================================================================================================================<< TO DO
6565
#Search for NEED2TEST within the project.
6666
#Remove themes.
67-
#qApp->styleHints()->setColorScheme(Qt::ColorScheme::Dark);
68-
#qApp->styleHints()->setColorScheme(Qt::ColorScheme::Light);
69-
#qApp->styleHints()->setColorScheme(Qt::ColorScheme::Unknown);
67+
#colorschemes are a complete mess. How do you even get these to behave?!
7068

7169
#File transfers dont have a timestamp parameter, but they generate their own for now. Should change this.
7270
#Crashing somewhere after "New connection received" and before "Accepted connection from user", (when a new peer joins network.)

sources/aformmain.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "messagelog.h"
2626
#include "history.h"
2727
#include <cstdlib>
28+
#include <qstylehints.h>
2829

2930
lmFormMain::lmFormMain(QWidget *parent, Qt::WindowFlags flags) : QWidget(parent, flags) {
3031
ui.setupUi(this);
@@ -136,6 +137,24 @@ void lmFormMain::start(void) {
136137
// and the program will connect to the network before start() is called.
137138
setAvatar();
138139
pTrayIcon->setVisible(showSysTray);
140+
141+
int colorSchemeIndex = pSettings->value(IDS_COLORSCHEME, IDS_COLORSCHEME_VAL).toInt(); //NEED2TEST Kinda had to, but its messy, i dont like this.
142+
switch (colorSchemeIndex) {
143+
case 0:
144+
qApp->styleHints()->setColorScheme(Qt::ColorScheme::Unknown);
145+
break;
146+
case 1:
147+
qApp->styleHints()->setColorScheme(Qt::ColorScheme::Light);
148+
break;
149+
case 2:
150+
qApp->styleHints()->setColorScheme(Qt::ColorScheme::Dark);
151+
break;
152+
default:
153+
break;
154+
}
155+
QEvent event(QEvent::ThemeChange);
156+
QCoreApplication::sendEvent(qApp, &event);
157+
139158
if(pSettings->value(IDS_AUTOSHOW, IDS_AUTOSHOW_VAL).toBool())
140159
show();
141160
}

sources/aformsettings.cpp

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
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

7070
lmFormSettings::~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

300296
void 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-
451442
void 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+
618622
void 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

sources/aformsettings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class lmFormSettings : public QDialog {
5353

5454
void init(void);
5555
void settingsChanged(void);
56+
void changeColorScheme(int index);
5657

5758
signals:
5859
void historyCleared(void);
@@ -87,7 +88,6 @@ private slots:
8788
void btnPlaySound_clicked(void);
8889
void btnSoundPath_clicked(void);
8990
void btnResetSounds_clicked(void);
90-
void btnRefreshTheme_clicked(void);
9191

9292

9393
private:

sources/aformsettings.ui

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
<enum>QFrame::Shadow::Plain</enum>
116116
</property>
117117
<property name="currentIndex">
118-
<number>3</number>
118+
<number>0</number>
119119
</property>
120120
<widget class="QWidget" name="pageGeneral">
121121
<layout class="QVBoxLayout" name="verticalLayout_5">
@@ -2161,6 +2161,21 @@
21612161
<verstretch>0</verstretch>
21622162
</sizepolicy>
21632163
</property>
2164+
<item>
2165+
<property name="text">
2166+
<string>System</string>
2167+
</property>
2168+
</item>
2169+
<item>
2170+
<property name="text">
2171+
<string>Light</string>
2172+
</property>
2173+
</item>
2174+
<item>
2175+
<property name="text">
2176+
<string>Dark</string>
2177+
</property>
2178+
</item>
21642179
</widget>
21652180
</item>
21662181
<item>
@@ -2176,13 +2191,6 @@
21762191
</property>
21772192
</spacer>
21782193
</item>
2179-
<item>
2180-
<widget class="QPushButton" name="btnRefresfTheme">
2181-
<property name="text">
2182-
<string>Refresh</string>
2183-
</property>
2184-
</widget>
2185-
</item>
21862194
</layout>
21872195
</item>
21882196
<item>

sources/settings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@
144144
#define IDS_THEME_OLD_VAL ":/themes/Classic"
145145
#define IDS_THEME "Appearance/Theme"
146146
#define IDS_THEME_VAL ":/themes/Classic"
147+
#define IDS_COLORSCHEME "Appearance/ColorScheme"
148+
#define IDS_COLORSCHEME_VAL "0"
147149
#define IDS_USERLISTVIEW "Appearance/UserListView"
148150
#define IDS_USERLISTVIEW_VAL ULV_Detailed
149151
#define IDS_STATUSTOOLTIP "Appearance/StatusToolTip"

0 commit comments

Comments
 (0)