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
2 changes: 2 additions & 0 deletions files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ set(sources
src/SpeechBubble.h
src/TalkStateManager.cpp
src/TalkStateManager.h
src/Theme.cpp
src/Theme.h
src/ts3log.cpp
src/ts3log.h
src/UpdateChecker.cpp
Expand Down
13 changes: 13 additions & 0 deletions src/ConfigModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <QSettings>

#include "ConfigModel.h"
#include "Theme.h"
#include "main.h"
#include "buildinfo.h"
#include "plugin.h"
Expand All @@ -37,6 +38,7 @@ ConfigModel::ConfigModel()

m_activeConfig = 0;
m_nextUpdateCheck = 0;
m_themeMode = ThemeMode::System;
}


Expand Down Expand Up @@ -75,6 +77,7 @@ void ConfigModel::readConfig(const QString& file)
m_showHotkeysOnButtons = settings.value("show_hotkeys_on_buttons", false).toBool();
m_hotkeysEnabled = settings.value("hotkeys_enabled", true).toBool();
m_nextUpdateCheck = settings.value("next_update_check", 0).toUInt();
m_themeMode = themeModeFromString(settings.value("theme_mode", "system").toString().toUtf8().constData());

notifyAllEvents();
}
Expand Down Expand Up @@ -102,6 +105,7 @@ void ConfigModel::writeConfig(const QString& file)
settings.setValue("show_hotkeys_on_buttons", m_showHotkeysOnButtons);
settings.setValue("hotkeys_enabled", m_hotkeysEnabled);
settings.setValue("next_update_check", m_nextUpdateCheck);
settings.setValue("theme_mode", themeModeToString(m_themeMode));

for (int i = 0; i < NUM_CONFIGS; i++)
writeConfiguration(settings, i == 0 ? QString("files") : QString("files%1").arg(i + 1), m_sounds[i]);
Expand Down Expand Up @@ -378,6 +382,7 @@ void ConfigModel::notifyAllEvents()
notify(NOTIFY_SET_BUBBLE_COLS_BUILD, m_bubbleColsBuild);
notify(NOTIFY_SET_SHOW_HOTKEYS_ON_BUTTONS, m_showHotkeysOnButtons);
notify(NOTIFY_SET_HOTKEYS_ENABLED, m_hotkeysEnabled);
notify(NOTIFY_SET_THEME_MODE, static_cast<int>(m_themeMode));
}


Expand All @@ -387,3 +392,11 @@ void ConfigModel::setShowHotkeysOnButtons(bool show)
writeConfig();
notify(NOTIFY_SET_SHOW_HOTKEYS_ON_BUTTONS, show ? 1 : 0);
}


void ConfigModel::setThemeMode(ThemeMode mode)
{
m_themeMode = mode;
writeConfig();
notify(NOTIFY_SET_THEME_MODE, static_cast<int>(mode));
}
9 changes: 9 additions & 0 deletions src/ConfigModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <vector>
#include <array>
#include "SoundInfo.h"
#include "Theme.h"
#include <QString>
#include <memory>
#include <set>
Expand All @@ -36,6 +37,7 @@ class ConfigModel
NOTIFY_SET_SHOW_HOTKEYS_ON_BUTTONS,
NOTIFY_SET_HOTKEYS_ENABLED,
NOTIFY_SET_NEXT_UPDATE_CHECK,
NOTIFY_SET_THEME_MODE,
};

class Observer
Expand Down Expand Up @@ -152,6 +154,12 @@ class ConfigModel
}
void setNextUpdateCheck(uint time);

ThemeMode getThemeMode() const
{
return m_themeMode;
}
void setThemeMode(ThemeMode mode);

private:
std::vector<SoundInfo>& sounds()
{
Expand Down Expand Up @@ -183,4 +191,5 @@ class ConfigModel
bool m_hotkeysEnabled;

uint m_nextUpdateCheck;
ThemeMode m_themeMode;
};
51 changes: 30 additions & 21 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "MainWindow.h"
#include "ConfigModel.h"
#include "Theme.h"
#include "main.h"
#include "SoundSettings.h"
#include "ts3log.h"
Expand Down Expand Up @@ -59,6 +60,14 @@ MainWindow::MainWindow(ConfigModel* model, QWidget* parent /*= 0*/) :

createConfigButtons();

m_themeButton = new QPushButton(this);
m_themeButton->setFixedSize(28, 28);
m_themeButton->setFlat(true);
m_themeButton->setToolTip("Toggle dark/light mode");
connect(m_themeButton, &QPushButton::clicked, this, &MainWindow::onThemeButtonClicked);
if (auto* settingsLayout = qobject_cast<QHBoxLayout*>(ui->settingsWidget->layout()))
settingsLayout->addWidget(m_themeButton);

settingsSection = new ExpandableSection("Settings", 200, this);
settingsSection->setContentLayout(*ui->settingsWidget->layout());
layout()->addWidget(settingsSection);
Expand Down Expand Up @@ -160,27 +169,7 @@ MainWindow::MainWindow(ConfigModel* model, QWidget* parent /*= 0*/) :
/* Force configuration 0 */
setConfiguration(0);

ui->gridWidget->setStyleSheet(
"QPushButton {"
" padding: 4px;"
" border: 1px solid rgb(173, 173, 173);"
" color: black;"
" background-color: rgb(225, 225, 225);"
"}"
"QPushButton:disabled {"
" background-color: rgb(204, 204, 204);"
" border-color: rgb(191, 191, 191);"
" color: rgb(120, 120, 120);"
"}"
"QPushButton:hover {"
" background-color: rgb(228, 239, 249);"
" border-color: rgb(11, 123, 212);"
"}"
"QPushButton:pressed {"
" background-color: rgb(204, 228, 247);"
" border-color: rgb(0, 85, 155);"
"}"
);
applyTheme(m_model->getThemeMode());
}

void MainWindow::setConfiguration(int cfg)
Expand Down Expand Up @@ -888,6 +877,23 @@ void MainWindow::onVolumeSliderContextMenuRemote(const QPoint& point)
ts3Functions.requestHotkeyInputDialog(getPluginID(), HOTKEY_VOLUME_DECREASE, 0, this);
}

void MainWindow::applyTheme(ThemeMode mode)
{
bool dark = themeIsDark(mode);
setStyleSheet(dark ? darkThemeStylesheet() : lightThemeStylesheet());
ui->gridWidget->setStyleSheet(dark ? darkGridStylesheet() : lightGridStylesheet());
// Sun = click to switch to light; Moon = click to switch to dark
m_themeButton->setText(dark ? "\u2600" : "\U0001F319");
}


void MainWindow::onThemeButtonClicked()
{
bool currentlyDark = themeIsDark(m_model->getThemeMode());
m_model->setThemeMode(currentlyDark ? ThemeMode::Light : ThemeMode::Dark);
}


void MainWindow::ModelObserver::notify(ConfigModel& model, ConfigModel::notifications_e what, int data)
{
switch (what)
Expand Down Expand Up @@ -938,6 +944,9 @@ void MainWindow::ModelObserver::notify(ConfigModel& model, ConfigModel::notifica
if (p.ui->cb_disable_hotkeys->isChecked() == model.getHotkeysEnabled())
p.ui->cb_disable_hotkeys->setChecked(!model.getHotkeysEnabled());
break;
case ConfigModel::NOTIFY_SET_THEME_MODE:
p.applyTheme(static_cast<ThemeMode>(data));
break;
default:
break;
}
Expand Down
5 changes: 4 additions & 1 deletion src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "ui_MainWindow.h"
#include "ConfigModel.h"
#include "Theme.h"

class SpeechBubble;
class ExpandableSection;
Expand Down Expand Up @@ -89,9 +90,9 @@ class MainWindow : public QWidget
void onSetConfig();
void onConfigHotkey();


void onSaveModel();
void onLoadModel();
void onThemeButtonClicked();

signals:
void hotkeyRecordedEvent(QString keyword, QString key);
Expand All @@ -112,6 +113,7 @@ class MainWindow : public QWidget
void openHotkeySetDialog(size_t buttonId);
void openButtonColorDialog(size_t buttonId);
QString unescapeCustomText(const QString& text);
void applyTheme(ThemeMode mode);

class ModelObserver : public ConfigModel::Observer
{
Expand Down Expand Up @@ -142,4 +144,5 @@ class MainWindow : public QWidget
QIcon m_playIcon;
std::array<QRadioButton*, NUM_CONFIGS> m_configRadioButtons;
std::array<QPushButton*, NUM_CONFIGS> m_configHotkeyButtons;
QPushButton* m_themeButton;
};
Loading
Loading