make a few settings into pajlada::Settings::Settings

Add setting to hide badges

Give focus to text input if you click anywhere in a chat widget
This commit is contained in:
Rasmus Karlsson 2017-06-11 20:53:43 +02:00
parent 945ca5d17a
commit 7c3cd930f3
11 changed files with 71 additions and 27 deletions

View file

@ -50,5 +50,6 @@ QString MessageBuilder::matchLink(const QString &string)
// TODO: Implement this xD
return QString();
}
}
}
} // namespace messages
} // namespace chatterino

View file

@ -84,7 +84,7 @@ bool MessageRef::layout(int width, bool enableEmoteMargins)
}
if (newWordTypes) {
_currentWordTypes = SettingsManager::getInstance().getWordTypeMask();
_currentWordTypes = settings.getWordTypeMask();
}
// layout
@ -102,11 +102,12 @@ bool MessageRef::layout(int width, bool enableEmoteMargins)
_wordParts.clear();
uint32_t flags = SettingsManager::getInstance().getWordTypeMask();
uint32_t flags = settings.getWordTypeMask();
for (auto it = _message->getWords().begin(); it != _message->getWords().end(); ++it) {
Word &word = *it;
// Check if given word is supposed to be rendered by comparing it to the current setting
if ((word.getType() & flags) == Word::None) {
continue;
}

View file

@ -17,8 +17,9 @@ SettingsManager::SettingsManager()
, emoteScale(_settingsItems, "emoteScale", 1.0)
, mouseScrollMultiplier(_settingsItems, "mouseScrollMultiplier", 1.0)
, scaleEmotesByLineHeight(_settingsItems, "scaleEmotesByLineHeight", false)
, showTimestamps(_settingsItems, "showTimestamps", true)
, showTimestampSeconds(_settingsItems, "showTimestampSeconds", false)
, showTimestamps("/appearance/messages/showTimestamps", true)
, showTimestampSeconds("/appearance/messages/showTimestampSeconds", true)
, showBadges("/appearance/messages/showBadges", true)
, showLastMessageIndicator(_settingsItems, "showLastMessageIndicator", false)
, allowDouplicateMessages(_settingsItems, "allowDouplicateMessages", true)
, linksDoubleClickOnly(_settingsItems, "linksDoubleClickOnly", false)
@ -47,6 +48,7 @@ SettingsManager::SettingsManager()
this->showTimestamps.valueChanged.connect([this](const auto &) { this->updateWordTypeMask(); });
this->showTimestampSeconds.valueChanged.connect(
[this](const auto &) { this->updateWordTypeMask(); });
this->showBadges.valueChanged.connect([this](const auto &) { this->updateWordTypeMask(); });
this->enableBttvEmotes.valueChanged.connect(
[this](const auto &) { this->updateWordTypeMask(); });
this->enableEmojis.valueChanged.connect([this](const auto &) { this->updateWordTypeMask(); });
@ -87,29 +89,36 @@ QSettings &SettingsManager::getQSettings()
void SettingsManager::updateWordTypeMask()
{
uint32_t mask = Word::Text;
uint32_t newMaskUint = Word::Text;
if (showTimestamps.get()) {
mask |= showTimestampSeconds.get() ? Word::TimestampWithSeconds : Word::TimestampNoSeconds;
if (this->showTimestamps) {
if (this->showTimestampSeconds) {
newMaskUint |= Word::TimestampWithSeconds;
} else {
newMaskUint |= Word::TimestampNoSeconds;
}
}
mask |= enableTwitchEmotes.get() ? Word::TwitchEmoteImage : Word::TwitchEmoteText;
mask |= enableFfzEmotes.get() ? Word::FfzEmoteImage : Word::FfzEmoteText;
mask |= enableBttvEmotes.get() ? Word::BttvEmoteImage : Word::BttvEmoteText;
mask |=
newMaskUint |= enableTwitchEmotes.get() ? Word::TwitchEmoteImage : Word::TwitchEmoteText;
newMaskUint |= enableFfzEmotes.get() ? Word::FfzEmoteImage : Word::FfzEmoteText;
newMaskUint |= enableBttvEmotes.get() ? Word::BttvEmoteImage : Word::BttvEmoteText;
newMaskUint |=
(enableBttvEmotes.get() && enableGifs.get()) ? Word::BttvEmoteImage : Word::BttvEmoteText;
mask |= enableEmojis.get() ? Word::EmojiImage : Word::EmojiText;
newMaskUint |= enableEmojis.get() ? Word::EmojiImage : Word::EmojiText;
mask |= Word::BitsAmount;
mask |= enableGifs.get() ? Word::BitsAnimated : Word::BitsStatic;
newMaskUint |= Word::BitsAmount;
newMaskUint |= enableGifs.get() ? Word::BitsAnimated : Word::BitsStatic;
mask |= Word::Badges;
mask |= Word::Username;
if (this->showBadges) {
newMaskUint |= Word::Badges;
}
Word::Type _mask = (Word::Type)mask;
newMaskUint |= Word::Username;
if (mask != _mask) {
_wordTypeMask = _mask;
Word::Type newMask = static_cast<Word::Type>(newMaskUint);
if (newMask != _wordTypeMask) {
_wordTypeMask = newMask;
emit wordTypeMaskChanged();
}

View file

@ -5,6 +5,7 @@
#include "settingssnapshot.hpp"
#include <QSettings>
#include <pajlada/settings/setting.hpp>
namespace chatterino {
@ -36,6 +37,11 @@ private:
void updateWordTypeMask();
public:
// new pajlada settings BBaper
pajlada::Settings::Setting<bool> showTimestamps;
pajlada::Settings::Setting<bool> showTimestampSeconds;
pajlada::Settings::Setting<bool> showBadges;
// Settings
Setting<QString> theme;
Setting<float> themeHue;
@ -43,8 +49,6 @@ public:
Setting<float> emoteScale;
Setting<float> mouseScrollMultiplier;
Setting<bool> scaleEmotesByLineHeight;
Setting<bool> showTimestamps;
Setting<bool> showTimestampSeconds;
Setting<bool> showLastMessageIndicator;
Setting<bool> allowDouplicateMessages;
Setting<bool> linksDoubleClickOnly;
@ -76,8 +80,6 @@ public:
static SettingsManager instance;
return instance;
}
private:
};
} // namespace chatterino

View file

@ -188,6 +188,11 @@ void ChatWidget::updateGifEmotes()
this->view.updateGifEmotes();
}
void ChatWidget::giveFocus()
{
this->input.textInput.setFocus();
}
void ChatWidget::paintEvent(QPaintEvent *)
{
// color the background of the chat

View file

@ -47,6 +47,8 @@ public:
void layoutMessages();
void updateGifEmotes();
void giveFocus();
protected:
void paintEvent(QPaintEvent *) override;

View file

@ -29,7 +29,7 @@ protected:
virtual void resizeEvent(QResizeEvent *) override;
private:
ChatWidget *chatWidget;
ChatWidget *const chatWidget;
QHBoxLayout hbox;
QVBoxLayout vbox;
@ -46,6 +46,8 @@ private slots:
}
void editTextChanged();
// void editKeyPressed(QKeyEvent *event);
friend class ChatWidget;
};
} // namespace widgets

View file

@ -336,6 +336,8 @@ void ChatWidgetView::mousePressEvent(QMouseEvent *event)
{
this->isMouseDown = true;
this->lastPressPosition = event->screenPos();
this->chatWidget->giveFocus();
}
void ChatWidgetView::mouseReleaseEvent(QMouseEvent *event)

View file

@ -49,7 +49,7 @@ private:
std::vector<GifEmoteData> gifEmotes;
ChatWidget *chatWidget;
ChatWidget *const chatWidget;
ScrollBar scrollBar;

View file

@ -5,6 +5,7 @@
#include "windowmanager.hpp"
#include <QComboBox>
#include <QDebug>
#include <QFile>
#include <QFormLayout>
#include <QGroupBox>
@ -166,6 +167,7 @@ void SettingsDialog::addTabs()
auto v = new QVBoxLayout();
v->addWidget(createCheckbox("Show timestamp", settings.showTimestamps));
v->addWidget(createCheckbox("Show seconds in timestamp", settings.showTimestampSeconds));
v->addWidget(createCheckbox("Show badges", settings.showBadges));
v->addWidget(createCheckbox("Allow sending duplicate messages (add a space at the end)",
settings.allowDouplicateMessages));
v->addWidget(createCheckbox("Seperate messages", settings.seperateMessages));
@ -323,6 +325,22 @@ QCheckBox *SettingsDialog::createCheckbox(const QString &title, Setting<bool> &s
return checkbox;
}
QCheckBox *SettingsDialog::createCheckbox(const QString &title,
pajlada::Settings::Setting<bool> &setting)
{
auto checkbox = new QCheckBox(title);
// Set checkbox initial state
checkbox->setChecked(setting.getValue());
QObject::connect(checkbox, &QCheckBox::toggled, this, [&setting](bool state) {
qDebug() << "update checkbox value";
setting = state; //
});
return checkbox;
}
void SettingsDialog::okButtonClicked()
{
this->close();

View file

@ -14,6 +14,7 @@
#include <QStackedLayout>
#include <QVBoxLayout>
#include <QWidget>
#include <pajlada/settings/setting.hpp>
namespace chatterino {
namespace widgets {
@ -46,6 +47,7 @@ private:
/// Widget creation helpers
QCheckBox *createCheckbox(const QString &title, Setting<bool> &setting);
QCheckBox *createCheckbox(const QString &title, pajlada::Settings::Setting<bool> &setting);
void okButtonClicked();
void cancelButtonClicked();