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
8 changes: 8 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ if(APPLE)
psicons.icns

)
elseif(WIN32)
add_executable(
${PROJECT_NAME} WIN32
${PACKETSENDER_SRCS}
${PACKETSENDER_UI_HEADERS}
${PACKETSENDER_UIS}
${PACKETSENDER_QRC}
)
else()
add_executable(
${PROJECT_NAME}
Expand Down
22 changes: 22 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
#include "globals.h"
#ifndef CONSOLE_BUILD
#include <QtWidgets/QApplication>
#include <QColor>
#include <QDesktopServices>
#include <QPalette>
#include <QTranslator>
#include <QLibraryInfo>
#if QT_VERSION > QT_VERSION_CHECK(6, 0, 0)
Expand Down Expand Up @@ -138,6 +140,26 @@ void debugThemeFiles(bool debugMode) {
}

void applyTheme(bool isDark, bool debugMode, QApplication *app, MainWindow *mainWin = nullptr) {
if(isDark) {
app->setPalette(app->style()->standardPalette());
} else {
QPalette lightPalette;
lightPalette.setColor(QPalette::Window, QColor(250, 250, 250));
lightPalette.setColor(QPalette::WindowText, Qt::black);
lightPalette.setColor(QPalette::Base, Qt::white);
lightPalette.setColor(QPalette::AlternateBase, QColor(245, 245, 245));
lightPalette.setColor(QPalette::ToolTipBase, Qt::white);
lightPalette.setColor(QPalette::ToolTipText, Qt::black);
lightPalette.setColor(QPalette::Text, Qt::black);
lightPalette.setColor(QPalette::Button, QColor(245, 245, 245));
lightPalette.setColor(QPalette::ButtonText, Qt::black);
lightPalette.setColor(QPalette::BrightText, Qt::red);
lightPalette.setColor(QPalette::Link, QColor(0, 80, 160));
lightPalette.setColor(QPalette::Highlight, QColor(255, 249, 196));
lightPalette.setColor(QPalette::HighlightedText, Qt::black);
app->setPalette(lightPalette);
}

debugThemeFiles(debugMode);

QFile file(isDark ? Settings::DARK_STYLE_SHEET_NAME : Settings::LIGHT_STYLE_SHEET_NAME);
Expand Down
54 changes: 49 additions & 5 deletions src/packetsender.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,52 @@ QTableWidget::item:hover {
background-color: #fffbda;
}

QLineEdit {
border: 1px solid grey;
border-radius: 4px;
padding: 4px;
}
QLineEdit {
border: 1px solid grey;
border-radius: 4px;
padding: 4px;
}

QMenuBar {
background-color: #fafafa;
color: #111111;
}

QMenuBar::item {
background: transparent;
color: #111111;
padding: 4px 8px;
}

QMenuBar::item:selected {
background-color: #ececec;
border-radius: 4px;
}

QMenuBar::item:pressed {
background-color: #e0e0e0;
border-radius: 4px;
}

QMenu {
background-color: #fafafa;
color: #111111;
border: 1px solid #cfcfcf;
}

QMenu::item {
background-color: transparent;
color: #111111;
padding: 6px 24px 6px 28px;
}

QMenu::item:selected {
background-color: #fff9c4;
color: #111111;
}

QMenu::separator {
height: 1px;
background-color: #d8d8d8;
margin: 4px 8px;
}
53 changes: 41 additions & 12 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

#include <QDesktopServices>
#include <QFileDialog>
#include <QGuiApplication>
#include <QMessageBox>
#include <QPalette>
#include <QStyleHints>

#endif
Expand All @@ -42,6 +44,9 @@ const QString Settings::ERROR_STR = "Error";
#ifndef CONSOLE_BUILD
const QString Settings::LIGHT_STYLE_SHEET_NAME = ":/packetsender.css";
const QString Settings::DARK_STYLE_SHEET_NAME = ":/qdarkstyle/style.qss";
const QString Settings::THEME_MODE_SYSTEM = "system";
const QString Settings::THEME_MODE_LIGHT = "light";
const QString Settings::THEME_MODE_DARK = "dark";
#endif

QString Settings::logHeaderTranslate(QString txt)
Expand Down Expand Up @@ -187,15 +192,13 @@ Settings::Settings(QWidget *parent, MainWindow* mw) :
ui->autolaunchStarterPanelButton->setChecked(settings.value("autolaunchStarterPanelButton", false).toBool());


#if QT_VERSION > QT_VERSION_CHECK(6, 5, 0)
QString currentThemeMode = Settings::themeMode();
ui->themeModeCombo->setItemData(0, Settings::THEME_MODE_SYSTEM);
ui->themeModeCombo->setItemData(1, Settings::THEME_MODE_LIGHT);
ui->themeModeCombo->setItemData(2, Settings::THEME_MODE_DARK);
int themeIndex = ui->themeModeCombo->findData(currentThemeMode);
ui->themeModeCombo->setCurrentIndex(themeIndex < 0 ? 0 : themeIndex);

//This is now automatic in Qt6.5
ui->darkModeCheck->hide();

#endif


ui->darkModeCheck->setChecked(settings.value("darkModeCheck", true).toBool());
ui->httpAdjustContentTypeCheck->setChecked(settings.value("httpAdjustContentTypeCheck", true).toBool());

ui->translateMacroSendCheck->setChecked(settings.value("translateMacroSendCheck", true).toBool());
Expand Down Expand Up @@ -398,21 +401,46 @@ QString Settings::language()



QString Settings::themeMode() {
QSettings settings(SETTINGSFILE, QSettings::IniFormat);
QString mode = settings.value("themeMode", "").toString().toLower();

if(mode == THEME_MODE_SYSTEM || mode == THEME_MODE_LIGHT || mode == THEME_MODE_DARK) {
return mode;
}

if(settings.contains("darkModeCheck")) {
return settings.value("darkModeCheck", true).toBool() ? THEME_MODE_DARK : THEME_MODE_LIGHT;
}

return THEME_MODE_SYSTEM;
}


bool Settings::useDark() {


#ifndef CONSOLE_BUILD

#if QT_VERSION > QT_VERSION_CHECK(6, 5, 0)
QString mode = Settings::themeMode();

if(mode == THEME_MODE_DARK) {
return true;
}

if(mode == THEME_MODE_LIGHT) {
return false;
}

#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)

QStyleHints * styleHints = QGuiApplication::styleHints();
auto colorScheme = styleHints->colorScheme();
return colorScheme == Qt::ColorScheme::Dark;

#endif

QSettings settings(SETTINGSFILE, QSettings::IniFormat);
return settings.value("darkModeCheck", true).toBool();
return QGuiApplication::palette().color(QPalette::Window).lightness() < 128;

#else
return true;
Expand Down Expand Up @@ -529,7 +557,8 @@ void Settings::on_buttonBox_accepted()
settings.setValue("translateMacroSendCheck", ui->translateMacroSendCheck->isChecked());

settings.setValue("autolaunchStarterPanelButton", ui->autolaunchStarterPanelButton->isChecked());
settings.setValue("darkModeCheck", ui->darkModeCheck->isChecked());
QString themeMode = ui->themeModeCombo->currentData().toString();
settings.setValue("themeMode", themeMode.isEmpty() ? Settings::THEME_MODE_SYSTEM : themeMode);
settings.setValue("httpAdjustContentTypeCheck", ui->httpAdjustContentTypeCheck->isChecked());

settings.setValue("cancelResendNum", ui->cancelResendNumEdit->text().toUInt());
Expand Down
4 changes: 4 additions & 0 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ class Settings : public QDialog

static const QString LIGHT_STYLE_SHEET_NAME;
static const QString DARK_STYLE_SHEET_NAME;
static const QString THEME_MODE_SYSTEM;
static const QString THEME_MODE_LIGHT;
static const QString THEME_MODE_DARK;

static QList<int> portsToIntList(QString ports);
static QString intListToPorts(QList<int> portList);
Expand All @@ -115,6 +118,7 @@ class Settings : public QDialog
static bool needLanguage();
static QString logHeaderTranslate(QString txt);

static QString themeMode();
static bool useDark();
private slots:

Expand Down
34 changes: 29 additions & 5 deletions src/settings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -655,11 +655,34 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_18">
<item>
<widget class="QCheckBox" name="darkModeCheck">
<property name="text">
<string>Use Dark Theme (requires restart)</string>
</property>
</widget>
<layout class="QHBoxLayout" name="themeModeLayout">
<item>
<widget class="QLabel" name="themeModeLabel">
<property name="text">
<string>Theme</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="themeModeCombo">
<item>
<property name="text">
<string>System</string>
</property>
</item>
<item>
<property name="text">
<string>Light</string>
</property>
</item>
<item>
<property name="text">
<string>Dark</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="LanguageHolderLayout">
Expand Down Expand Up @@ -1296,6 +1319,7 @@
<tabstop>displayOrderList</tabstop>
<tabstop>displayOrderListTraffic</tabstop>
<tabstop>defaultDisplayButton</tabstop>
<tabstop>themeModeCombo</tabstop>
<tabstop>copyUnformattedCheck</tabstop>
<tabstop>rolling500entryCheck</tabstop>
<tabstop>restoreSessionCheck</tabstop>
Expand Down
Loading