Move more settings over to pajlada settings system

This commit is contained in:
Rasmus Karlsson 2017-12-17 01:19:56 +01:00
parent 8687d01cea
commit eb8e14b8fe
10 changed files with 104 additions and 105 deletions

View file

@ -233,8 +233,7 @@ void MessageRef::updateImageSizes()
const int mediumTextLineHeight =
FontManager::getInstance().getFontMetrics(FontManager::Medium).height();
const qreal emoteScale = SettingsManager::getInstance().emoteScale.get() * this->dpiMultiplyer;
const bool scaleEmotesByLineHeight =
SettingsManager::getInstance().scaleEmotesByLineHeight.get();
const bool scaleEmotesByLineHeight = SettingsManager::getInstance().scaleEmotesByLineHeight;
for (auto &word : this->message->getWords()) {
if (!word.isImage())

View file

@ -11,58 +11,42 @@ namespace chatterino {
SettingsManager::SettingsManager()
: settings(Path::getAppdataPath() + "settings.ini", QSettings::IniFormat)
, showTimestamps("/appearance/messages/showTimestamps", true)
, showTimestampSeconds("/appearance/messages/showTimestampSeconds", true)
, showBadges("/appearance/messages/showBadges", true)
, streamlinkPath("/behaviour/streamlink/path", "")
, preferredQuality("/behaviour/streamlink/quality", "Choose")
, emoteScale(this->settingsItems, "emoteScale", 1.0)
, mouseScrollMultiplier(this->settingsItems, "mouseScrollMultiplier", 1.0)
, scaleEmotesByLineHeight(this->settingsItems, "scaleEmotesByLineHeight", false)
, showLastMessageIndicator(this->settingsItems, "showLastMessageIndicator", false)
, allowDouplicateMessages(this->settingsItems, "allowDouplicateMessages", true)
, linksDoubleClickOnly(this->settingsItems, "linksDoubleClickOnly", false)
, hideEmptyInput(this->settingsItems, "hideEmptyInput", false)
, showMessageLength(this->settingsItems, "showMessageLength", false)
, seperateMessages(this->settingsItems, "seperateMessages", false)
, mentionUsersWithAt(this->settingsItems, "mentionUsersWithAt", false)
, allowCommandsAtEnd(this->settingsItems, "allowCommandsAtEnd", false)
, enableHighlights(this->settingsItems, "enableHighlights", true)
, enableHighlightsSelf(this->settingsItems, "enableHighlightsSelf", true)
, enableHighlightSound(this->settingsItems, "enableHighlightSound", true)
, enableHighlightTaskbar(this->settingsItems, "enableHighlightTaskbar", true)
, customHighlightSound(this->settingsItems, "customHighlightSound", false)
, pathHighlightSound(this->settingsItems, "pathHighlightSound", "qrc:/sounds/ping2.wav")
, highlightProperties(this->settingsItems, "highlightProperties",
QMap<QString, QPair<bool, bool>>())
, highlightUserBlacklist(this->settingsItems, "highlightUserBlacklist", "")
, highlightAlwaysPlaySound("/highlighting/alwaysPlaySound", false)
, enableTwitchEmotes(this->settingsItems, "enableTwitchEmotes", true)
, enableBttvEmotes(this->settingsItems, "enableBttvEmotes", true)
, enableFfzEmotes(this->settingsItems, "enableFfzEmotes", true)
, enableEmojis(this->settingsItems, "enableEmojis", true)
, enableGifAnimations(this->settingsItems, "enableGifAnimations", true)
, enableGifs(this->settingsItems, "enableGifs", true)
, inlineWhispers(this->settingsItems, "inlineWhispers", true)
, windowTopMost(this->settingsItems, "windowTopMost", false)
, hideTabX(this->settingsItems, "hideTabX", false)
, hidePreferencesButton(this->settingsItems, "hidePreferencesButton", false)
, hideUserButton(this->settingsItems, "hideUserButton", false)
, useCustomWindowFrame(this->settingsItems, "useCustomWindowFrame", true)
{
this->showTimestamps.getValueChangedSignal().connect(
[this](const auto &) { this->updateWordTypeMask(); });
this->showTimestampSeconds.getValueChangedSignal().connect(
[this](const auto &) { this->updateWordTypeMask(); });
this->showBadges.getValueChangedSignal().connect(
[this](const auto &) { this->updateWordTypeMask(); });
this->enableBttvEmotes.valueChanged.connect(
[this](const auto &) { this->updateWordTypeMask(); });
this->enableEmojis.valueChanged.connect([this](const auto &) { this->updateWordTypeMask(); });
this->enableFfzEmotes.valueChanged.connect(
[this](const auto &) { this->updateWordTypeMask(); });
this->enableTwitchEmotes.valueChanged.connect(
[this](const auto &) { this->updateWordTypeMask(); });
this->showTimestamps.getValueChangedSignal().connect([this](const auto &) {
this->updateWordTypeMask(); //
});
this->showTimestampSeconds.getValueChangedSignal().connect([this](const auto &) {
this->updateWordTypeMask(); //
});
this->showBadges.getValueChangedSignal().connect([this](const auto &) {
this->updateWordTypeMask(); //
});
this->enableBttvEmotes.getValueChangedSignal().connect([this](const auto &) {
this->updateWordTypeMask(); //
});
this->enableEmojis.getValueChangedSignal().connect([this](const auto &) {
this->updateWordTypeMask(); //
});
this->enableFfzEmotes.getValueChangedSignal().connect([this](const auto &) {
this->updateWordTypeMask(); //
});
this->enableTwitchEmotes.getValueChangedSignal().connect([this](const auto &) {
this->updateWordTypeMask(); //
});
}
void SettingsManager::save()
@ -136,15 +120,15 @@ void SettingsManager::updateWordTypeMask()
}
}
newMaskUint |= enableTwitchEmotes.get() ? Word::TwitchEmoteImage : Word::TwitchEmoteText;
newMaskUint |= enableFfzEmotes.get() ? Word::FfzEmoteImage : Word::FfzEmoteText;
newMaskUint |= enableBttvEmotes.get() ? Word::BttvEmoteImage : Word::BttvEmoteText;
newMaskUint |= enableTwitchEmotes ? Word::TwitchEmoteImage : Word::TwitchEmoteText;
newMaskUint |= enableFfzEmotes ? Word::FfzEmoteImage : Word::FfzEmoteText;
newMaskUint |= enableBttvEmotes ? Word::BttvEmoteImage : Word::BttvEmoteText;
newMaskUint |=
(enableBttvEmotes.get() && enableGifs.get()) ? Word::BttvEmoteImage : Word::BttvEmoteText;
newMaskUint |= enableEmojis.get() ? Word::EmojiImage : Word::EmojiText;
(enableBttvEmotes && enableGifAnimations) ? Word::BttvEmoteImage : Word::BttvEmoteText;
newMaskUint |= enableEmojis ? Word::EmojiImage : Word::EmojiText;
newMaskUint |= Word::BitsAmount;
newMaskUint |= enableGifs.get() ? Word::BitsAnimated : Word::BitsStatic;
newMaskUint |= enableGifAnimations ? Word::BitsAnimated : Word::BitsStatic;
if (this->showBadges) {
newMaskUint |= Word::Badges;

View file

@ -13,6 +13,8 @@ class SettingsManager : public QObject
{
Q_OBJECT
using BoolSetting = pajlada::Settings::Setting<bool>;
public:
void load();
void save();
@ -22,47 +24,58 @@ public:
QSettings &getQSettings();
SettingsSnapshot createSnapshot();
// new pajlada settings BBaper
pajlada::Settings::Setting<bool> showTimestamps;
pajlada::Settings::Setting<bool> showTimestampSeconds;
pajlada::Settings::Setting<bool> showBadges;
/// Appearance
BoolSetting showTimestamps = {"/appearance/messages/showTimestamps", true};
BoolSetting showTimestampSeconds = {"/appearance/messages/showTimestampSeconds", true};
BoolSetting showBadges = {"/appearance/messages/showBadges", true};
BoolSetting showLastMessageIndicator = {"/appearance/messages/showLastMessageIndicator", false};
BoolSetting hideEmptyInput = {"/appearance/hideEmptyInputBox", false};
BoolSetting showMessageLength = {"/appearance/messages/showMessageLength", false};
BoolSetting seperateMessages = {"/appearance/messages/separateMessages", false};
BoolSetting windowTopMost = {"/appearance/windowAlwaysOnTop", false};
BoolSetting hideTabX = {"/appearance/hideTabX", false};
BoolSetting hidePreferencesButton = {"/appearance/hidePreferencesButton", false};
BoolSetting hideUserButton = {"/appearance/hideUserButton", false};
// BoolSetting useCustomWindowFrame = {"/appearance/useCustomWindowFrame", false};
/// Behaviour
BoolSetting allowDouplicateMessages = {"/behaviour/allowDuplicateMessages", true};
BoolSetting mentionUsersWithAt = {"/behaviour/mentionUsersWithAt", false};
/// Commands
BoolSetting allowCommandsAtEnd = {"/commands/allowCommandsAtEnd", false};
/// Emotes
BoolSetting scaleEmotesByLineHeight = {"/emotes/scaleEmotesByLineHeight", false};
BoolSetting enableTwitchEmotes = {"/emotes/enableTwitchEmotes", true};
BoolSetting enableBttvEmotes = {"/emotes/enableBTTVEmotes", true};
BoolSetting enableFfzEmotes = {"/emotes/enableFFZEmotes", true};
BoolSetting enableEmojis = {"/emotes/enableEmojis", true};
BoolSetting enableGifAnimations = {"/emotes/enableGifAnimations", true};
/// Links
BoolSetting linksDoubleClickOnly = {"/links/doubleClickToOpen", false};
/// Highlighting
BoolSetting enableHighlights = {"/highlighting/enabled", true};
BoolSetting enableHighlightsSelf = {"/highlighting/nameIsHighlightKeyword", true};
BoolSetting enableHighlightSound = {"/highlighting/enableSound", true};
BoolSetting enableHighlightTaskbar = {"/highlighting/enableTaskbarFlashing", true};
BoolSetting customHighlightSound = {"/highlighting/useCustomSound", false};
pajlada::Settings::Setting<std::string> streamlinkPath;
pajlada::Settings::Setting<std::string> preferredQuality;
// Settings
Setting<float> emoteScale;
Setting<float> mouseScrollMultiplier;
Setting<bool> scaleEmotesByLineHeight;
Setting<bool> showLastMessageIndicator;
Setting<bool> allowDouplicateMessages;
Setting<bool> linksDoubleClickOnly;
Setting<bool> hideEmptyInput;
Setting<bool> showMessageLength;
Setting<bool> seperateMessages;
Setting<bool> mentionUsersWithAt;
Setting<bool> allowCommandsAtEnd;
Setting<bool> enableHighlights;
Setting<bool> enableHighlightsSelf;
Setting<bool> enableHighlightSound;
Setting<bool> enableHighlightTaskbar;
Setting<bool> customHighlightSound;
Setting<QString> pathHighlightSound;
Setting<QMap<QString, QPair<bool, bool>>> highlightProperties;
Setting<QString> highlightUserBlacklist;
pajlada::Settings::Setting<bool> highlightAlwaysPlaySound;
Setting<bool> enableTwitchEmotes;
Setting<bool> enableBttvEmotes;
Setting<bool> enableFfzEmotes;
Setting<bool> enableEmojis;
Setting<bool> enableGifAnimations;
Setting<bool> enableGifs;
Setting<bool> inlineWhispers;
Setting<bool> windowTopMost;
Setting<bool> hideTabX;
Setting<bool> hidePreferencesButton;
Setting<bool> hideUserButton;
Setting<bool> useCustomWindowFrame;
BoolSetting highlightAlwaysPlaySound = {"/highlighting/alwaysPlaySound", false};
BoolSetting inlineWhispers = {"/whispers/enableInlineWhispers", true};
static SettingsManager &getInstance()
{

View file

@ -63,7 +63,7 @@ SharedMessage TwitchMessageBuilder::parse()
this->appendUsername();
// highlights
if (settings.enableHighlights.get()) {
if (settings.enableHighlights) {
this->parseHighlights();
}
@ -372,7 +372,7 @@ void TwitchMessageBuilder::parseHighlights()
return;
}
if (settings.customHighlightSound.get()) {
if (settings.customHighlightSound) {
player->setMedia(QUrl(settings.pathHighlightSound.get()));
} else {
player->setMedia(QUrl("qrc:/sounds/ping2.wav"));
@ -397,9 +397,9 @@ void TwitchMessageBuilder::parseHighlights()
// TODO: This vector should only be rebuilt upon highlights being changed
std::vector<Highlight> activeHighlights;
if (settings.enableHighlightsSelf.get() && currentUsername.size() > 0) {
activeHighlights.emplace_back(currentUsername, settings.enableHighlightSound.get(),
settings.enableHighlightTaskbar.get());
if (settings.enableHighlightsSelf && currentUsername.size() > 0) {
activeHighlights.emplace_back(currentUsername, settings.enableHighlightSound,
settings.enableHighlightTaskbar);
}
const auto &highlightProperties = settings.highlightProperties.get();

View file

@ -22,7 +22,7 @@ NotebookTab::NotebookTab(Notebook *_notebook)
this->positionChangedAnimation.setEasingCurve(QEasingCurve(QEasingCurve::InCubic));
this->hideXConnection = SettingsManager::getInstance().hideTabX.valueChanged.connect(
this->hideXConnection = SettingsManager::getInstance().hideTabX.getValueChangedSignal().connect(
boost::bind(&NotebookTab::hideTabXChanged, this, _1));
this->setMouseTracking(true);
@ -62,14 +62,15 @@ NotebookTab::NotebookTab(Notebook *_notebook)
NotebookTab::~NotebookTab()
{
this->hideXConnection.disconnect();
SettingsManager::getInstance().hideTabX.getValueChangedSignal().disconnect(
this->hideXConnection);
}
void NotebookTab::calcSize()
{
float scale = getDpiMultiplier();
if (SettingsManager::getInstance().hideTabX.get()) {
if (SettingsManager::getInstance().hideTabX) {
this->resize(static_cast<int>((fontMetrics().width(title) + 16) * scale),
static_cast<int>(24 * scale));
} else {
@ -184,12 +185,12 @@ void NotebookTab::paintEvent(QPaintEvent *)
painter.setPen(fg);
float scale = this->getDpiMultiplier();
int rectW = (SettingsManager::getInstance().hideTabX.get() ? 0 : static_cast<int>(16) * scale);
int rectW = (SettingsManager::getInstance().hideTabX ? 0 : static_cast<int>(16) * scale);
QRect rect(0, 0, this->width() - rectW, this->height());
painter.drawText(rect, title, QTextOption(Qt::AlignCenter));
if (!SettingsManager::getInstance().hideTabX.get() && (mouseOver || selected)) {
if (!SettingsManager::getInstance().hideTabX && (mouseOver || selected)) {
QRect xRect = this->getXRect();
if (mouseOverX) {
painter.fillRect(xRect, QColor(0, 0, 0, 64));
@ -231,7 +232,7 @@ void NotebookTab::mouseReleaseEvent(QMouseEvent *event)
this->notebook->removePage(this->page);
}
} else {
if (!SettingsManager::getInstance().hideTabX.get() && this->mouseDownX &&
if (!SettingsManager::getInstance().hideTabX && this->mouseDownX &&
this->getXRect().contains(event->pos())) {
this->mouseDownX = false;
@ -264,7 +265,7 @@ void NotebookTab::dragEnterEvent(QDragEnterEvent *)
void NotebookTab::mouseMoveEvent(QMouseEvent *event)
{
if (!SettingsManager::getInstance().hideTabX.get()) {
if (!SettingsManager::getInstance().hideTabX) {
bool overX = this->getXRect().contains(event->pos());
if (overX != this->mouseOverX) {

View file

@ -7,6 +7,7 @@
#include <boost/property_tree/ptree.hpp>
#include <boost/signals2.hpp>
#include <boost/signals2/connection.hpp>
#include <pajlada/signals/signal.hpp>
namespace chatterino {
@ -57,7 +58,7 @@ protected:
void mouseMoveEvent(QMouseEvent *event) override;
private:
boost::signals2::connection hideXConnection;
pajlada::Signals::Signal<const bool &>::Connection hideXConnection;
QPropertyAnimation positionChangedAnimation;
bool positionChangedAnimationRunning = false;

View file

@ -67,7 +67,7 @@ SplitInput::SplitInput(Split *_chatWidget, EmoteManager &emoteManager, WindowMan
connect(&textInput, &ResizingTextEdit::textChanged, this, &SplitInput::editTextChanged);
this->refreshTheme();
textLengthLabel.setHidden(!SettingsManager::getInstance().showMessageLength.get());
textLengthLabel.setHidden(!SettingsManager::getInstance().showMessageLength);
auto completer = new QCompleter(
this->chatWidget->completionManager.createModel(this->chatWidget->channelName));
@ -181,7 +181,7 @@ SplitInput::SplitInput(Split *_chatWidget, EmoteManager &emoteManager, WindowMan
});
this->textLengthVisibleChangedConnection =
SettingsManager::getInstance().showMessageLength.valueChanged.connect(
SettingsManager::getInstance().showMessageLength.getValueChangedSignal().connect(
[this](const bool &value) { this->textLengthLabel.setHidden(!value); });
QObject::connect(&this->textInput, &QTextEdit::copyAvailable, [this](bool available) {
@ -193,7 +193,8 @@ SplitInput::SplitInput(Split *_chatWidget, EmoteManager &emoteManager, WindowMan
SplitInput::~SplitInput()
{
this->textLengthVisibleChangedConnection.disconnect();
SettingsManager::getInstance().showMessageLength.getValueChangedSignal().disconnect(
this->textLengthVisibleChangedConnection);
}
void SplitInput::clearSelection()

View file

@ -43,7 +43,7 @@ private:
EmoteManager &emoteManager;
WindowManager &windowManager;
boost::signals2::connection textLengthVisibleChangedConnection;
pajlada::Signals::Signal<const bool &>::Connection textLengthVisibleChangedConnection;
QHBoxLayout hbox;
QVBoxLayout vbox;
QHBoxLayout editContainer;

View file

@ -37,9 +37,9 @@ Notebook::Notebook(ChannelManager &_channelManager, Window *parent, bool _showBu
this->userButton.move(24, 0);
this->userButton.icon = NotebookButton::IconUser;
SettingsManager::getInstance().hidePreferencesButton.valueChanged.connect(
SettingsManager::getInstance().hidePreferencesButton.getValueChangedSignal().connect(
[this](const bool &) { this->performLayout(); });
SettingsManager::getInstance().hideUserButton.valueChanged.connect(
SettingsManager::getInstance().hideUserButton.getValueChangedSignal().connect(
[this](const bool &) { this->performLayout(); });
}
@ -167,13 +167,13 @@ void Notebook::performLayout(bool animated)
int x = 0, y = 0;
float scale = this->getDpiMultiplier();
if (!showButtons || SettingsManager::getInstance().hidePreferencesButton.get()) {
if (!showButtons || SettingsManager::getInstance().hidePreferencesButton) {
this->settingsButton.hide();
} else {
this->settingsButton.show();
x += settingsButton.width();
}
if (!showButtons || SettingsManager::getInstance().hideUserButton.get()) {
if (!showButtons || SettingsManager::getInstance().hideUserButton) {
this->userButton.hide();
} else {
this->userButton.move(x, 0);

View file

@ -371,7 +371,7 @@ QVBoxLayout *SettingsDialog::createEmotesTab()
layout->addWidget(createCheckbox("Enable Twitch Emotes", settings.enableTwitchEmotes));
layout->addWidget(createCheckbox("Enable BetterTTV Emotes", settings.enableBttvEmotes));
layout->addWidget(createCheckbox("Enable FrankerFaceZ Emotes", settings.enableFfzEmotes));
layout->addWidget(createCheckbox("Enable Gif Emotes", settings.enableGifs));
layout->addWidget(createCheckbox("Enable Gif Emotes", settings.enableGifAnimations));
layout->addWidget(createCheckbox("Enable Emojis", settings.enableEmojis));
layout->addWidget(createCheckbox("Enable Twitch Emotes", settings.enableTwitchEmotes));