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 // TODO: Implement this xD
return QString(); return QString();
} }
}
} } // namespace messages
} // namespace chatterino

View file

@ -84,7 +84,7 @@ bool MessageRef::layout(int width, bool enableEmoteMargins)
} }
if (newWordTypes) { if (newWordTypes) {
_currentWordTypes = SettingsManager::getInstance().getWordTypeMask(); _currentWordTypes = settings.getWordTypeMask();
} }
// layout // layout
@ -102,11 +102,12 @@ bool MessageRef::layout(int width, bool enableEmoteMargins)
_wordParts.clear(); _wordParts.clear();
uint32_t flags = SettingsManager::getInstance().getWordTypeMask(); uint32_t flags = settings.getWordTypeMask();
for (auto it = _message->getWords().begin(); it != _message->getWords().end(); ++it) { for (auto it = _message->getWords().begin(); it != _message->getWords().end(); ++it) {
Word &word = *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) { if ((word.getType() & flags) == Word::None) {
continue; continue;
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -5,6 +5,7 @@
#include "windowmanager.hpp" #include "windowmanager.hpp"
#include <QComboBox> #include <QComboBox>
#include <QDebug>
#include <QFile> #include <QFile>
#include <QFormLayout> #include <QFormLayout>
#include <QGroupBox> #include <QGroupBox>
@ -166,6 +167,7 @@ void SettingsDialog::addTabs()
auto v = new QVBoxLayout(); auto v = new QVBoxLayout();
v->addWidget(createCheckbox("Show timestamp", settings.showTimestamps)); v->addWidget(createCheckbox("Show timestamp", settings.showTimestamps));
v->addWidget(createCheckbox("Show seconds in timestamp", settings.showTimestampSeconds)); 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)", v->addWidget(createCheckbox("Allow sending duplicate messages (add a space at the end)",
settings.allowDouplicateMessages)); settings.allowDouplicateMessages));
v->addWidget(createCheckbox("Seperate messages", settings.seperateMessages)); v->addWidget(createCheckbox("Seperate messages", settings.seperateMessages));
@ -323,6 +325,22 @@ QCheckBox *SettingsDialog::createCheckbox(const QString &title, Setting<bool> &s
return checkbox; 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() void SettingsDialog::okButtonClicked()
{ {
this->close(); this->close();

View file

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