fixed project code style in some files

This commit is contained in:
fourtf
2017-09-21 12:15:01 +02:00
parent 8eaca85402
commit 3e24752477
23 changed files with 395 additions and 294 deletions
+1 -1
View File
@@ -163,7 +163,7 @@ HEADERS += \
src/widgets/rippleeffectlabel.hpp \ src/widgets/rippleeffectlabel.hpp \
src/widgets/qualitypopup.hpp \ src/widgets/qualitypopup.hpp \
src/widgets/emotepopup.hpp \ src/widgets/emotepopup.hpp \
src/messages/messagecolor.h src/messages/messagecolor.hpp
PRECOMPILED_HEADER = PRECOMPILED_HEADER =
+3 -3
View File
@@ -19,7 +19,7 @@ using namespace chatterino::messages;
namespace chatterino { namespace chatterino {
Channel::Channel() Channel::Channel()
// , _loggingChannel(logging::get(_name)) // , loggingChannel(logging::get(name))
{ {
} }
@@ -30,7 +30,7 @@ bool Channel::isEmpty() const
messages::LimitedQueueSnapshot<messages::SharedMessage> Channel::getMessageSnapshot() messages::LimitedQueueSnapshot<messages::SharedMessage> Channel::getMessageSnapshot()
{ {
return _messages.getSnapshot(); return this->messages.getSnapshot();
} }
void Channel::addMessage(std::shared_ptr<Message> message) void Channel::addMessage(std::shared_ptr<Message> message)
@@ -41,7 +41,7 @@ void Channel::addMessage(std::shared_ptr<Message> message)
// _loggingChannel->append(message); // _loggingChannel->append(message);
// } // }
if (_messages.appendItem(message, deleted)) { if (this->messages.appendItem(message, deleted)) {
messageRemovedFromStart(deleted); messageRemovedFromStart(deleted);
} }
+2 -2
View File
@@ -41,9 +41,9 @@ public:
private: private:
// variables // variables
messages::LimitedQueue<messages::SharedMessage> _messages; messages::LimitedQueue<messages::SharedMessage> messages;
// std::shared_ptr<logging::Channel> _loggingChannel; // std::shared_ptr<logging::Channel> loggingChannel;
}; };
} // namespace chatterino } // namespace chatterino
+10 -10
View File
@@ -2,33 +2,33 @@
namespace chatterino { namespace chatterino {
IrcUser2::IrcUser2(const QString &userName, const QString &nickName, const QString &realName, IrcUser2::IrcUser2(const QString &_userName, const QString &_nickName, const QString &_realName,
const QString &password) const QString &_password)
: _userName(userName) : userName(_userName)
, _nickName(nickName) , nickName(_nickName)
, _realName(realName) , realName(_realName)
, _password(password) , password(_password)
{ {
} }
const QString &IrcUser2::getUserName() const const QString &IrcUser2::getUserName() const
{ {
return _userName; return this->userName;
} }
const QString &IrcUser2::getNickName() const const QString &IrcUser2::getNickName() const
{ {
return _nickName; return this->nickName;
} }
const QString &IrcUser2::getRealName() const const QString &IrcUser2::getRealName() const
{ {
return _realName; return this->realName;
} }
const QString &IrcUser2::getPassword() const const QString &IrcUser2::getPassword() const
{ {
return _password; return this->password;
} }
} // namespace chatterino } // namespace chatterino
+4 -4
View File
@@ -16,10 +16,10 @@ public:
const QString &getPassword() const; const QString &getPassword() const;
private: private:
QString _userName; QString userName;
QString _nickName; QString nickName;
QString _realName; QString realName;
QString _password; QString password;
}; };
} // namespace chatterino } // namespace chatterino
+30 -30
View File
@@ -31,7 +31,7 @@ IrcManager::IrcManager(ChannelManager &_channelManager, Resources &_resources,
, resources(_resources) , resources(_resources)
, emoteManager(_emoteManager) , emoteManager(_emoteManager)
, windowManager(_windowManager) , windowManager(_windowManager)
, _account(AccountManager::getInstance().getTwitchAnon()) , account(AccountManager::getInstance().getTwitchAnon())
, currentUser("/accounts/current") , currentUser("/accounts/current")
{ {
this->currentUser.getValueChangedSignal().connect([](const auto &newUsername) { this->currentUser.getValueChangedSignal().connect([](const auto &newUsername) {
@@ -42,12 +42,12 @@ IrcManager::IrcManager(ChannelManager &_channelManager, Resources &_resources,
const twitch::TwitchUser &IrcManager::getUser() const const twitch::TwitchUser &IrcManager::getUser() const
{ {
return _account; return this->account;
} }
void IrcManager::setUser(const twitch::TwitchUser &account) void IrcManager::setUser(const twitch::TwitchUser &account)
{ {
_account = account; this->account = account;
} }
void IrcManager::connect() void IrcManager::connect()
@@ -68,9 +68,9 @@ Communi::IrcConnection *IrcManager::createConnection(bool doRead)
&IrcManager::privateMessageReceived); &IrcManager::privateMessageReceived);
} }
QString username = _account.getUserName(); QString username = this->account.getUserName();
QString oauthClient = _account.getOAuthClient(); QString oauthClient = this->account.getOAuthClient();
QString oauthToken = _account.getOAuthToken(); QString oauthToken = this->account.getOAuthToken();
if (!oauthToken.startsWith("oauth:")) { if (!oauthToken.startsWith("oauth:")) {
oauthToken.prepend("oauth:"); oauthToken.prepend("oauth:");
} }
@@ -79,7 +79,7 @@ Communi::IrcConnection *IrcManager::createConnection(bool doRead)
connection->setNickName(username); connection->setNickName(username);
connection->setRealName(username); connection->setRealName(username);
if (!_account.isAnon()) { if (!this->account.isAnon()) {
connection->setPassword(oauthToken); connection->setPassword(oauthToken);
this->refreshIgnoredUsers(username, oauthClient, oauthToken); this->refreshIgnoredUsers(username, oauthClient, oauthToken);
@@ -109,26 +109,26 @@ void IrcManager::refreshIgnoredUsers(const QString &username, const QString &oau
QNetworkReply *reply = manager->get(req); QNetworkReply *reply = manager->get(req);
QObject::connect(reply, &QNetworkReply::finished, [=] { QObject::connect(reply, &QNetworkReply::finished, [=] {
_twitchBlockedUsersMutex.lock(); this->twitchBlockedUsersMutex.lock();
_twitchBlockedUsers.clear(); this->twitchBlockedUsers.clear();
_twitchBlockedUsersMutex.unlock(); this->twitchBlockedUsersMutex.unlock();
QByteArray data = reply->readAll(); QByteArray data = reply->readAll();
QJsonDocument jsonDoc(QJsonDocument::fromJson(data)); QJsonDocument jsonDoc(QJsonDocument::fromJson(data));
QJsonObject root = jsonDoc.object(); QJsonObject root = jsonDoc.object();
// nextLink = // nextLink =
// root.value("_links").toObject().value("next").toString(); // root.value("this->links").toObject().value("next").toString();
auto blocks = root.value("blocks").toArray(); auto blocks = root.value("blocks").toArray();
_twitchBlockedUsersMutex.lock(); this->twitchBlockedUsersMutex.lock();
for (QJsonValue block : blocks) { for (QJsonValue block : blocks) {
QJsonObject user = block.toObject().value("user").toObject(); QJsonObject user = block.toObject().value("user").toObject();
// display_name // displaythis->name
_twitchBlockedUsers.insert(user.value("name").toString().toLower(), true); this->twitchBlockedUsers.insert(user.value("name").toString().toLower(), true);
} }
_twitchBlockedUsersMutex.unlock(); this->twitchBlockedUsersMutex.unlock();
manager->deleteLater(); manager->deleteLater();
}); });
@@ -311,27 +311,27 @@ void IrcManager::handleUserNoticeMessage(Communi::IrcMessage *message)
bool IrcManager::isTwitchBlockedUser(QString const &username) bool IrcManager::isTwitchBlockedUser(QString const &username)
{ {
QMutexLocker locker(&_twitchBlockedUsersMutex); QMutexLocker locker(&this->twitchBlockedUsersMutex);
auto iterator = _twitchBlockedUsers.find(username); auto iterator = this->twitchBlockedUsers.find(username);
return iterator != _twitchBlockedUsers.end(); return iterator != this->twitchBlockedUsers.end();
} }
bool IrcManager::tryAddIgnoredUser(QString const &username, QString &errorMessage) bool IrcManager::tryAddIgnoredUser(QString const &username, QString &errorMessage)
{ {
QUrl url("https://api.twitch.tv/kraken/users/" + _account.getUserName() + "/blocks/" + QUrl url("https://api.twitch.tv/kraken/users/" + this->account.getUserName() + "/blocks/" +
username + "?oauth_token=" + _account.getOAuthToken() + username + "?oauth_token=" + this->account.getOAuthToken() +
"&client_id=" + _account.getOAuthClient()); "&client_id=" + this->account.getOAuthClient());
QNetworkRequest request(url); QNetworkRequest request(url);
auto reply = this->networkAccessManager.put(request, QByteArray()); auto reply = this->networkAccessManager.put(request, QByteArray());
reply->waitForReadyRead(10000); reply->waitForReadyRead(10000);
if (reply->error() == QNetworkReply::NoError) { if (reply->error() == QNetworkReply::NoError) {
_twitchBlockedUsersMutex.lock(); this->twitchBlockedUsersMutex.lock();
_twitchBlockedUsers.insert(username, true); this->twitchBlockedUsers.insert(username, true);
_twitchBlockedUsersMutex.unlock(); this->twitchBlockedUsersMutex.unlock();
return true; return true;
} }
@@ -352,18 +352,18 @@ void IrcManager::addIgnoredUser(QString const &username)
bool IrcManager::tryRemoveIgnoredUser(QString const &username, QString &errorMessage) bool IrcManager::tryRemoveIgnoredUser(QString const &username, QString &errorMessage)
{ {
QUrl url("https://api.twitch.tv/kraken/users/" + _account.getUserName() + "/blocks/" + QUrl url("https://api.twitch.tv/kraken/users/" + this->account.getUserName() + "/blocks/" +
username + "?oauth_token=" + _account.getOAuthToken() + username + "?oauth_token=" + this->account.getOAuthToken() +
"&client_id=" + _account.getOAuthClient()); "&client_id=" + this->account.getOAuthClient());
QNetworkRequest request(url); QNetworkRequest request(url);
auto reply = this->networkAccessManager.deleteResource(request); auto reply = this->networkAccessManager.deleteResource(request);
reply->waitForReadyRead(10000); reply->waitForReadyRead(10000);
if (reply->error() == QNetworkReply::NoError) { if (reply->error() == QNetworkReply::NoError) {
_twitchBlockedUsersMutex.lock(); this->twitchBlockedUsersMutex.lock();
_twitchBlockedUsers.remove(username); this->twitchBlockedUsers.remove(username);
_twitchBlockedUsersMutex.unlock(); this->twitchBlockedUsersMutex.unlock();
return true; return true;
} }
+5 -5
View File
@@ -27,8 +27,8 @@ class IrcManager : public QObject
Q_OBJECT Q_OBJECT
public: public:
IrcManager(ChannelManager &_channelManager, Resources &_resources, EmoteManager &_emoteManager, IrcManager(ChannelManager &channelManager, Resources &resources, EmoteManager &emoteManager,
WindowManager &_windowManager); WindowManager &windowManager);
void connect(); void connect();
void disconnect(); void disconnect();
@@ -56,7 +56,7 @@ public:
private: private:
// variables // variables
twitch::TwitchUser _account; twitch::TwitchUser account;
pajlada::Settings::Setting<std::string> currentUser; pajlada::Settings::Setting<std::string> currentUser;
@@ -69,8 +69,8 @@ private:
std::mutex connectionMutex; std::mutex connectionMutex;
uint32_t connectionGeneration = 0; uint32_t connectionGeneration = 0;
QMap<QString, bool> _twitchBlockedUsers; QMap<QString, bool> twitchBlockedUsers;
QMutex _twitchBlockedUsersMutex; QMutex twitchBlockedUsersMutex;
QNetworkAccessManager networkAccessManager; QNetworkAccessManager networkAccessManager;
+32 -32
View File
@@ -13,61 +13,61 @@ template <typename T>
class LimitedQueue class LimitedQueue
{ {
public: public:
LimitedQueue(int limit = 1000, int buffer = 250) LimitedQueue(int _limit = 1000, int _buffer = 250)
: _offset(0) : offset(0)
, _limit(limit) , limit(_limit)
, _buffer(buffer) , buffer(_buffer)
{ {
_vector = std::make_shared<std::vector<T>>(); this->vector = std::make_shared<std::vector<T>>();
_vector->reserve(_limit + _buffer); this->vector->reserve(this->limit + this->buffer);
} }
void clear() void clear()
{ {
std::lock_guard<std::mutex> lock(_mutex); std::lock_guard<std::mutex> lock(this->mutex);
_vector = std::make_shared<std::vector<T>>(); this->vector = std::make_shared<std::vector<T>>();
_vector->reserve(_limit + _buffer); this->vector->reserve(this->limit + this->buffer);
_offset = 0; this->offset = 0;
} }
// return true if an item was deleted // return true if an item was deleted
// deleted will be set if the item was deleted // deleted will be set if the item was deleted
bool appendItem(const T &item, T &deleted) bool appendItem(const T &item, T &deleted)
{ {
std::lock_guard<std::mutex> lock(_mutex); std::lock_guard<std::mutex> lock(this->mutex);
if (_vector->size() >= _limit) { if (this->vector->size() >= this->limit) {
// vector is full // vector is full
if (_offset == _buffer) { if (this->offset == this->buffer) {
deleted = _vector->at(_offset); deleted = this->vector->at(this->offset);
// create new vector // create new vector
auto newVector = std::make_shared<std::vector<T>>(); auto newVector = std::make_shared<std::vector<T>>();
newVector->reserve(_limit + _buffer); newVector->reserve(this->limit + this->buffer);
for (unsigned int i = 0; i < _limit; ++i) { for (unsigned int i = 0; i < this->limit; ++i) {
newVector->push_back(_vector->at(i + _offset)); newVector->push_back(this->vector->at(i + this->offset));
} }
newVector->push_back(item); newVector->push_back(item);
_offset = 0; this->offset = 0;
_vector = newVector; this->vector = newVector;
return true; return true;
} else { } else {
deleted = _vector->at(_offset); deleted = this->vector->at(this->offset);
// append item and increment offset("deleting" first element) // append item and increment offset("deleting" first element)
_vector->push_back(item); this->vector->push_back(item);
_offset++; this->offset++;
return true; return true;
} }
} else { } else {
// append item // append item
_vector->push_back(item); this->vector->push_back(item);
return false; return false;
} }
@@ -75,22 +75,22 @@ public:
messages::LimitedQueueSnapshot<T> getSnapshot() messages::LimitedQueueSnapshot<T> getSnapshot()
{ {
std::lock_guard<std::mutex> lock(_mutex); std::lock_guard<std::mutex> lock(this->mutex);
if (_vector->size() < _limit) { if (this->vector->size() < this->limit) {
return LimitedQueueSnapshot<T>(_vector, _offset, _vector->size()); return LimitedQueueSnapshot<T>(this->vector, this->offset, this->vector->size());
} else { } else {
return LimitedQueueSnapshot<T>(_vector, _offset, _limit); return LimitedQueueSnapshot<T>(this->vector, this->offset, this->limit);
} }
} }
private: private:
std::shared_ptr<std::vector<T>> _vector; std::shared_ptr<std::vector<T>> vector;
std::mutex _mutex; std::mutex mutex;
unsigned int _offset; unsigned int offset;
unsigned int _limit; unsigned int limit;
unsigned int _buffer; unsigned int buffer;
}; };
} // namespace messages } // namespace messages
+97
View File
@@ -0,0 +1,97 @@
#pragma once
#include "messages/limitedqueuesnapshot.hpp"
#include <memory>
#include <mutex>
#include <vector>
namespace chatterino {
namespace messages {
template <typename T>
class LimitedQueue
{
public:
LimitedQueue(int _limit = 1000, int _buffer = 250)
: offset(0)
, limit(_limit)
, buffer(_buffer)
{
this->vector = std::make_shared<std::vector<T>>();
this->vector->reserve(this->limit + this->buffer);
}
void clear()
{
std::lockthis->guard<std::mutex> lock(this->mutex);
this->vector = std::make_shared<std::vector<T>>();
this->vector->reserve(this->limit + this->buffer);
this->offset = 0;
}
// return true if an item was deleted
// deleted will be set if the item was deleted
bool appendItem(const T &item, T &deleted)
{
std::lock_guard<std::mutex> lock(this->mutex);
if (this->vector->size() >= this->limit) {
// vector is full
if (this->offset == this->buffer) {
deleted = this->vector->at(this->offset);
// create new vector
auto newVector = std::make_shared<std::vector<T>>();
newVector->reserve(this->limit + this->buffer);
for (unsigned int i = 0; i < this->limit; ++i) {
newVector->pushthis->back(this->vector->at(i + this->offset));
}
newVector->push_back(item);
this->offset = 0;
this->vector = newVector;
return true;
} else {
deleted = this->vector->at(this->offset);
// append item and increment offset("deleting" first element)
this->vector->push_back(item);
this->offset++;
return true;
}
} else {
// append item
this->vector->pushthis->back(item);
return false;
}
}
messages::LimitedQueueSnapshot<T> getSnapshot()
{
std::lockthis->guard<std::mutex> lock(this->mutex);
if (this->vector->size() < this->limit) {
return LimitedQueueSnapshot<T>(this->vector, this->offset, this->vector->size());
} else {
return LimitedQueueSnapshot<T>(this->vector, this->offset, this->limit);
}
}
private:
std::shared_ptr<std::vector<T>> vector;
std::mutex mutex;
unsigned int offset;
unsigned int limit;
unsigned int buffer;
};
} // namespace messages
} // namespace chatterino
+18 -3
View File
@@ -9,11 +9,26 @@ Link::Link()
{ {
} }
Link::Link(Type type, const QString &value) Link::Link(Type _type, const QString &_value)
: type(type) : type(_type)
, value(value) , value(_value)
{ {
} }
bool Link::isValid() const
{
return this->type != None;
}
Link::Type Link::getType() const
{
return this->type;
}
const QString &Link::getValue() const
{
return this->value;
}
} // namespace messages } // namespace messages
} // namespace chatterino } // namespace chatterino
+3 -14
View File
@@ -22,20 +22,9 @@ public:
Link(); Link();
Link(Type getType, const QString &getValue); Link(Type getType, const QString &getValue);
bool isValid() const bool isValid() const;
{ Type getType() const;
return type != None; const QString &getValue() const;
}
Type getType() const
{
return type;
}
const QString &getValue() const
{
return value;
}
private: private:
Type type; Type type;
+5 -5
View File
@@ -1,15 +1,15 @@
#include "messagecolor.h" #include "messagecolor.hpp"
namespace chatterino { namespace chatterino {
namespace messages { namespace messages {
MessageColor::MessageColor(const QColor &color) MessageColor::MessageColor(const QColor &_color)
: type(Type::Custom) : type(Type::Custom)
, color(color) , color(_color)
{ {
} }
MessageColor::MessageColor(Type type) MessageColor::MessageColor(Type _type)
: type(type) : type(_type)
{ {
} }
+40 -39
View File
@@ -14,40 +14,40 @@ using namespace chatterino::messages;
namespace chatterino { namespace chatterino {
namespace messages { namespace messages {
MessageRef::MessageRef(SharedMessage message) MessageRef::MessageRef(SharedMessage _message)
: _message(message) : message(_message)
, _wordParts() , wordParts()
{ {
} }
Message *MessageRef::getMessage() Message *MessageRef::getMessage()
{ {
return _message.get(); return this->message.get();
} }
int MessageRef::getHeight() const int MessageRef::getHeight() const
{ {
return _height; return this->height;
} }
bool MessageRef::layout(int width, bool enableEmoteMargins) bool MessageRef::layout(int width, bool enableEmoteMargins)
{ {
auto &settings = SettingsManager::getInstance(); auto &settings = SettingsManager::getInstance();
bool sizeChanged = width != _currentLayoutWidth; bool sizeChanged = width != this->currentLayoutWidth;
bool redraw = width != _currentLayoutWidth; bool redraw = width != this->currentLayoutWidth;
int spaceWidth = 4; int spaceWidth = 4;
int mediumTextLineHeight = int mediumTextLineHeight =
FontManager::getInstance().getFontMetrics(FontManager::Medium).height(); FontManager::getInstance().getFontMetrics(FontManager::Medium).height();
/* TODO(pajlada): Re-implement /* TODO(pajlada): Re-implement
bool recalculateImages = _emoteGeneration != EmoteManager::getInstance().getGeneration(); bool recalculateImages = this->emoteGeneration != EmoteManager::getInstance().getGeneration();
*/ */
bool recalculateImages = true; bool recalculateImages = true;
bool recalculateText = _fontGeneration != FontManager::getInstance().getGeneration(); bool recalculateText = this->fontGeneration != FontManager::getInstance().getGeneration();
bool newWordTypes = _currentWordTypes != SettingsManager::getInstance().getWordTypeMask(); bool newWordTypes = this->currentWordTypes != SettingsManager::getInstance().getWordTypeMask();
qreal emoteScale = settings.emoteScale.get(); qreal emoteScale = settings.emoteScale.get();
bool scaleEmotesByLineHeight = settings.scaleEmotesByLineHeight.get(); bool scaleEmotesByLineHeight = settings.scaleEmotesByLineHeight.get();
@@ -57,10 +57,10 @@ bool MessageRef::layout(int width, bool enableEmoteMargins)
return false; return false;
} }
// _emoteGeneration = EmoteManager::getInstance().getGeneration(); // this->emoteGeneration = EmoteManager::getInstance().getGeneration();
_fontGeneration = FontManager::getInstance().getGeneration(); this->fontGeneration = FontManager::getInstance().getGeneration();
for (auto &word : _message->getWords()) { for (auto &word : this->message->getWords()) {
if (word.isImage()) { if (word.isImage()) {
if (!recalculateImages) { if (!recalculateImages) {
continue; continue;
@@ -88,11 +88,11 @@ bool MessageRef::layout(int width, bool enableEmoteMargins)
} }
if (newWordTypes) { if (newWordTypes) {
_currentWordTypes = settings.getWordTypeMask(); this->currentWordTypes = settings.getWordTypeMask();
} }
// layout // layout
_currentLayoutWidth = width; this->currentLayoutWidth = width;
int x = MARGIN_LEFT; int x = MARGIN_LEFT;
int y = MARGIN_TOP; int y = MARGIN_TOP;
@@ -104,11 +104,11 @@ bool MessageRef::layout(int width, bool enableEmoteMargins)
int lineHeight = 0; int lineHeight = 0;
bool first = true; bool first = true;
_wordParts.clear(); this->wordParts.clear();
uint32_t flags = settings.getWordTypeMask(); uint32_t flags = settings.getWordTypeMask();
for (auto it = _message->getWords().begin(); it != _message->getWords().end(); ++it) { for (auto it = this->message->getWords().begin(); it != this->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 // Check if given word is supposed to be rendered by comparing it to the current setting
@@ -147,8 +147,9 @@ bool MessageRef::layout(int width, bool enableEmoteMargins)
if ((width = width + charWidths[i - 1]) + MARGIN_LEFT > right) { if ((width = width + charWidths[i - 1]) + MARGIN_LEFT > right) {
QString mid = text.mid(start, i - start - 1); QString mid = text.mid(start, i - start - 1);
_wordParts.push_back(WordPart(word, MARGIN_LEFT, y, width, word.getHeight(), this->wordParts.push_back(WordPart(word, MARGIN_LEFT, y, width,
lineNumber, mid, mid, false, charOffset)); word.getHeight(), lineNumber, mid, mid,
false, charOffset));
charOffset = i; charOffset = i;
@@ -164,18 +165,18 @@ bool MessageRef::layout(int width, bool enableEmoteMargins)
QString mid(text.mid(start)); QString mid(text.mid(start));
width = metrics.width(mid); width = metrics.width(mid);
_wordParts.push_back(WordPart(word, MARGIN_LEFT, y - word.getHeight(), width, this->wordParts.push_back(WordPart(word, MARGIN_LEFT, y - word.getHeight(), width,
word.getHeight(), lineNumber, mid, mid, charOffset)); word.getHeight(), lineNumber, mid, mid, charOffset));
x = width + MARGIN_LEFT + spaceWidth; x = width + MARGIN_LEFT + spaceWidth;
lineHeight = word.getHeight(); lineHeight = word.getHeight();
lineStart = _wordParts.size() - 1; lineStart = this->wordParts.size() - 1;
first = false; first = false;
} else if (first || x + word.getWidth() + xOffset <= right) { } else if (first || x + word.getWidth() + xOffset <= right) {
// fits in the line // fits in the line
_wordParts.push_back( this->wordParts.push_back(
WordPart(word, x, y - word.getHeight(), lineNumber, word.getCopyText())); WordPart(word, x, y - word.getHeight(), lineNumber, word.getCopyText()));
x += word.getWidth() + xOffset; x += word.getWidth() + xOffset;
@@ -192,10 +193,10 @@ bool MessageRef::layout(int width, bool enableEmoteMargins)
lineNumber++; lineNumber++;
_wordParts.push_back( this->wordParts.push_back(
WordPart(word, MARGIN_LEFT, y - word.getHeight(), lineNumber, word.getCopyText())); WordPart(word, MARGIN_LEFT, y - word.getHeight(), lineNumber, word.getCopyText()));
lineStart = _wordParts.size() - 1; lineStart = this->wordParts.size() - 1;
lineHeight = word.getHeight(); lineHeight = word.getHeight();
@@ -206,12 +207,12 @@ bool MessageRef::layout(int width, bool enableEmoteMargins)
alignWordParts(lineStart, lineHeight, width); alignWordParts(lineStart, lineHeight, width);
if (_height != y + lineHeight) { if (this->height != y + lineHeight) {
sizeChanged = true; sizeChanged = true;
_height = y + lineHeight; this->height = y + lineHeight;
} }
_height += MARGIN_BOTTOM; this->height += MARGIN_BOTTOM;
if (sizeChanged) { if (sizeChanged) {
buffer = nullptr; buffer = nullptr;
@@ -224,19 +225,19 @@ bool MessageRef::layout(int width, bool enableEmoteMargins)
const std::vector<WordPart> &MessageRef::getWordParts() const const std::vector<WordPart> &MessageRef::getWordParts() const
{ {
return _wordParts; return this->wordParts;
} }
void MessageRef::alignWordParts(int lineStart, int lineHeight, int width) void MessageRef::alignWordParts(int lineStart, int lineHeight, int width)
{ {
int xOffset = 0; int xOffset = 0;
if (this->_message->centered && _wordParts.size() > 0) { if (this->message->centered && this->wordParts.size() > 0) {
xOffset = (width - this->_wordParts.at(_wordParts.size() - 1).getRight()) / 2; xOffset = (width - this->wordParts.at(this->wordParts.size() - 1).getRight()) / 2;
} }
for (size_t i = lineStart; i < this->_wordParts.size(); i++) { for (size_t i = lineStart; i < this->wordParts.size(); i++) {
WordPart &wordPart2 = this->_wordParts.at(i); WordPart &wordPart2 = this->wordParts.at(i);
wordPart2.setPosition(wordPart2.getX() + xOffset, wordPart2.getY() + lineHeight); wordPart2.setPosition(wordPart2.getX() + xOffset, wordPart2.getY() + lineHeight);
} }
@@ -245,7 +246,7 @@ void MessageRef::alignWordParts(int lineStart, int lineHeight, int width)
const Word *MessageRef::tryGetWordPart(QPoint point) const Word *MessageRef::tryGetWordPart(QPoint point)
{ {
// go through all words and return the first one that contains the point. // go through all words and return the first one that contains the point.
for (WordPart &wordPart : _wordParts) { for (WordPart &wordPart : this->wordParts) {
if (wordPart.getRect().contains(point)) { if (wordPart.getRect().contains(point)) {
return &wordPart.getWord(); return &wordPart.getWord();
} }
@@ -256,15 +257,15 @@ const Word *MessageRef::tryGetWordPart(QPoint point)
int MessageRef::getSelectionIndex(QPoint position) int MessageRef::getSelectionIndex(QPoint position)
{ {
if (_wordParts.size() == 0) { if (this->wordParts.size() == 0) {
return 0; return 0;
} }
// find out in which line the cursor is // find out in which line the cursor is
int lineNumber = 0, lineStart = 0, lineEnd = 0; int lineNumber = 0, lineStart = 0, lineEnd = 0;
for (size_t i = 0; i < _wordParts.size(); i++) { for (size_t i = 0; i < this->wordParts.size(); i++) {
WordPart &part = _wordParts[i]; WordPart &part = this->wordParts[i];
if (part.getLineNumber() != 0 && position.y() < part.getY()) { if (part.getLineNumber() != 0 && position.y() < part.getY()) {
break; break;
@@ -282,13 +283,13 @@ int MessageRef::getSelectionIndex(QPoint position)
int index = 0; int index = 0;
for (int i = 0; i < lineStart; i++) { for (int i = 0; i < lineStart; i++) {
WordPart &part = _wordParts[i]; WordPart &part = this->wordParts[i];
index += part.getWord().isImage() ? 2 : part.getText().length() + 1; index += part.getWord().isImage() ? 2 : part.getText().length() + 1;
} }
for (int i = lineStart; i < lineEnd; i++) { for (int i = lineStart; i < lineEnd; i++) {
WordPart &part = _wordParts[i]; WordPart &part = this->wordParts[i];
// curser is left of the word part // curser is left of the word part
if (position.x() < part.getX()) { if (position.x() < part.getX()) {
+7 -7
View File
@@ -34,17 +34,17 @@ public:
private: private:
// variables // variables
SharedMessage _message; SharedMessage message;
std::vector<messages::WordPart> _wordParts; std::vector<messages::WordPart> wordParts;
int _height = 0; int height = 0;
int _currentLayoutWidth = -1; int currentLayoutWidth = -1;
int _fontGeneration = -1; int fontGeneration = -1;
/* TODO(pajlada): Re-implement /* TODO(pajlada): Re-implement
int _emoteGeneration = -1; int emoteGeneration = -1;
*/ */
Word::Type _currentWordTypes = Word::None; Word::Type currentWordTypes = Word::None;
// methods // methods
void alignWordParts(int lineStart, int lineHeight, int width); void alignWordParts(int lineStart, int lineHeight, int width);
+1 -1
View File
@@ -3,7 +3,7 @@
#include "fontmanager.hpp" #include "fontmanager.hpp"
#include "messages/lazyloadedimage.hpp" #include "messages/lazyloadedimage.hpp"
#include "messages/link.hpp" #include "messages/link.hpp"
#include "messages/messagecolor.h" #include "messages/messagecolor.hpp"
#include <stdint.h> #include <stdint.h>
#include <QRect> #include <QRect>
+41 -39
View File
@@ -4,106 +4,108 @@
namespace chatterino { namespace chatterino {
namespace messages { namespace messages {
WordPart::WordPart(Word &word, int x, int y, int lineNumber, const QString &copyText, WordPart::WordPart(Word &_word, int _x, int _y, int _lineNumber, const QString &_copyText,
bool allowTrailingSpace) bool _allowTrailingSpace)
: _word(word) : word(_word)
, _copyText(copyText) , copyText(_copyText)
, _text(word.isText() ? _word.getText() : QString()) , text(_word.isText() ? _word.getText() : QString())
, _x(x) , x(_x)
, _y(y) , y(_y)
, _width(word.getWidth()) , width(_word.getWidth())
, _height(word.getHeight()) , height(_word.getHeight())
, _lineNumber(lineNumber) , lineNumber(_lineNumber)
, _trailingSpace(!word.getCopyText().isEmpty() && word.hasTrailingSpace() & allowTrailingSpace) , _trailingSpace(!_word.getCopyText().isEmpty() &&
_word.hasTrailingSpace() & _allowTrailingSpace)
, wordCharOffset(0) , wordCharOffset(0)
{ {
} }
WordPart::WordPart(Word &word, int x, int y, int width, int height, int lineNumber, WordPart::WordPart(Word &_word, int _x, int _y, int _width, int _height, int _lineNumber,
const QString &copyText, const QString &customText, bool allowTrailingSpace, const QString &_copyText, const QString &_customText, bool _allowTrailingSpace,
int wordCharOffset) int _wordCharOffset)
: _word(word) : word(_word)
, _copyText(copyText) , copyText(_copyText)
, _text(customText) , text(_customText)
, _x(x) , x(_x)
, _y(y) , y(_y)
, _width(width) , width(_width)
, _height(height) , height(_height)
, _lineNumber(lineNumber) , lineNumber(_lineNumber)
, _trailingSpace(!word.getCopyText().isEmpty() && word.hasTrailingSpace() & allowTrailingSpace) , _trailingSpace(!_word.getCopyText().isEmpty() &&
, wordCharOffset(wordCharOffset) _word.hasTrailingSpace() & _allowTrailingSpace)
, wordCharOffset(_wordCharOffset)
{ {
} }
const Word &WordPart::getWord() const const Word &WordPart::getWord() const
{ {
return _word; return this->word;
} }
int WordPart::getWidth() const int WordPart::getWidth() const
{ {
return _width; return this->width;
} }
int WordPart::getHeight() const int WordPart::getHeight() const
{ {
return _height; return this->height;
} }
int WordPart::getX() const int WordPart::getX() const
{ {
return _x; return this->x;
} }
int WordPart::getY() const int WordPart::getY() const
{ {
return _y; return this->y;
} }
void WordPart::setPosition(int x, int y) void WordPart::setPosition(int x, int y)
{ {
_x = x; this->x = x;
_y = y; this->y = y;
} }
void WordPart::setY(int y) void WordPart::setY(int y)
{ {
_y = y; this->y = y;
} }
int WordPart::getRight() const int WordPart::getRight() const
{ {
return _x + _width; return this->x + this->width;
} }
int WordPart::getBottom() const int WordPart::getBottom() const
{ {
return _y + _height; return this->y + this->height;
} }
QRect WordPart::getRect() const QRect WordPart::getRect() const
{ {
return QRect(_x, _y, _width, _height - 1); return QRect(this->x, this->y, this->width, this->height - 1);
} }
const QString WordPart::getCopyText() const const QString WordPart::getCopyText() const
{ {
return _copyText; return this->copyText;
} }
int WordPart::hasTrailingSpace() const int WordPart::hasTrailingSpace() const
{ {
return _trailingSpace; return this->_trailingSpace;
} }
const QString &WordPart::getText() const const QString &WordPart::getText() const
{ {
return _text; return this->text;
} }
int WordPart::getLineNumber() const int WordPart::getLineNumber() const
{ {
return _lineNumber; return this->lineNumber;
} }
int WordPart::getCharacterLength() const int WordPart::getCharacterLength() const
+8 -8
View File
@@ -36,17 +36,17 @@ public:
short getCharacterWidth(int index) const; short getCharacterWidth(int index) const;
private: private:
Word &_word; Word &word;
QString _copyText; QString copyText;
QString _text; QString text;
int _x; int x;
int _y; int y;
int _width; int width;
int _height; int height;
int _lineNumber; int lineNumber;
bool _trailingSpace; bool _trailingSpace;
int wordCharOffset; int wordCharOffset;
+11 -11
View File
@@ -10,7 +10,7 @@ class BaseSetting
{ {
public: public:
BaseSetting(const QString &_name) BaseSetting(const QString &_name)
: _name(_name) : name(_name)
{ {
} }
@@ -19,11 +19,11 @@ public:
const QString &getName() const const QString &getName() const
{ {
return _name; return this->name;
} }
private: private:
QString _name; QString name;
}; };
template <typename T> template <typename T>
@@ -33,25 +33,25 @@ public:
Setting(std::vector<std::reference_wrapper<BaseSetting>> &settingItems, const QString &_name, Setting(std::vector<std::reference_wrapper<BaseSetting>> &settingItems, const QString &_name,
const T &defaultValue) const T &defaultValue)
: BaseSetting(_name) : BaseSetting(_name)
, _value(defaultValue) , value(defaultValue)
{ {
settingItems.push_back(*this); settingItems.push_back(*this);
} }
const T &get() const const T &get() const
{ {
return _value; return this->value;
} }
T &getnonConst() T &getnonConst()
{ {
return _value; return this->value;
} }
void set(const T &newValue) void set(const T &newValue)
{ {
if (_value != newValue) { if (this->value != newValue) {
_value = newValue; this->value = newValue;
valueChanged(newValue); valueChanged(newValue);
} }
@@ -59,7 +59,7 @@ public:
virtual QVariant getVariant() final virtual QVariant getVariant() final
{ {
return QVariant::fromValue(_value); return QVariant::fromValue(this->value);
} }
virtual void setVariant(QVariant value) final virtual void setVariant(QVariant value) final
@@ -73,13 +73,13 @@ public:
void insertMap(QString id, bool sound, bool task) void insertMap(QString id, bool sound, bool task)
{ {
QPair<bool, bool> pair(sound, task); QPair<bool, bool> pair(sound, task);
_value.insert(id, pair); this->value.insert(id, pair);
} }
boost::signals2::signal<void(const T &newValue)> valueChanged; boost::signals2::signal<void(const T &newValue)> valueChanged;
private: private:
T _value; T value;
}; };
} // namespace chatterino } // namespace chatterino
+59 -55
View File
@@ -10,42 +10,43 @@ using namespace chatterino::messages;
namespace chatterino { namespace chatterino {
SettingsManager::SettingsManager() SettingsManager::SettingsManager()
: _settings(Path::getAppdataPath() + "settings.ini", QSettings::IniFormat) : settings(Path::getAppdataPath() + "settings.ini", QSettings::IniFormat)
, showTimestamps("/appearance/messages/showTimestamps", true) , showTimestamps("/appearance/messages/showTimestamps", true)
, showTimestampSeconds("/appearance/messages/showTimestampSeconds", true) , showTimestampSeconds("/appearance/messages/showTimestampSeconds", true)
, showBadges("/appearance/messages/showBadges", true) , showBadges("/appearance/messages/showBadges", true)
, streamlinkPath("/behaviour/streamlink/path", "") , streamlinkPath("/behaviour/streamlink/path", "")
, preferredQuality("/behaviour/streamlink/quality", "Choose") , preferredQuality("/behaviour/streamlink/quality", "Choose")
, emoteScale(_settingsItems, "emoteScale", 1.0) , emoteScale(this->settingsItems, "emoteScale", 1.0)
, mouseScrollMultiplier(_settingsItems, "mouseScrollMultiplier", 1.0) , mouseScrollMultiplier(this->settingsItems, "mouseScrollMultiplier", 1.0)
, scaleEmotesByLineHeight(_settingsItems, "scaleEmotesByLineHeight", false) , scaleEmotesByLineHeight(this->settingsItems, "scaleEmotesByLineHeight", false)
, showLastMessageIndicator(_settingsItems, "showLastMessageIndicator", false) , showLastMessageIndicator(this->settingsItems, "showLastMessageIndicator", false)
, allowDouplicateMessages(_settingsItems, "allowDouplicateMessages", true) , allowDouplicateMessages(this->settingsItems, "allowDouplicateMessages", true)
, linksDoubleClickOnly(_settingsItems, "linksDoubleClickOnly", false) , linksDoubleClickOnly(this->settingsItems, "linksDoubleClickOnly", false)
, hideEmptyInput(_settingsItems, "hideEmptyInput", false) , hideEmptyInput(this->settingsItems, "hideEmptyInput", false)
, showMessageLength(_settingsItems, "showMessageLength", false) , showMessageLength(this->settingsItems, "showMessageLength", false)
, seperateMessages(_settingsItems, "seperateMessages", false) , seperateMessages(this->settingsItems, "seperateMessages", false)
, mentionUsersWithAt(_settingsItems, "mentionUsersWithAt", false) , mentionUsersWithAt(this->settingsItems, "mentionUsersWithAt", false)
, allowCommandsAtEnd(_settingsItems, "allowCommandsAtEnd", false) , allowCommandsAtEnd(this->settingsItems, "allowCommandsAtEnd", false)
, enableHighlights(_settingsItems, "enableHighlights", true) , enableHighlights(this->settingsItems, "enableHighlights", true)
, enableHighlightsSelf(_settingsItems, "enableHighlightsSelf", true) , enableHighlightsSelf(this->settingsItems, "enableHighlightsSelf", true)
, enableHighlightSound(_settingsItems, "enableHighlightSound", true) , enableHighlightSound(this->settingsItems, "enableHighlightSound", true)
, enableHighlightTaskbar(_settingsItems, "enableHighlightTaskbar", true) , enableHighlightTaskbar(this->settingsItems, "enableHighlightTaskbar", true)
, customHighlightSound(_settingsItems, "customHighlightSound", false) , customHighlightSound(this->settingsItems, "customHighlightSound", false)
, pathHighlightSound(_settingsItems, "pathHighlightSound", "qrc:/sounds/ping2.wav") , pathHighlightSound(this->settingsItems, "pathHighlightSound", "qrc:/sounds/ping2.wav")
, highlightProperties(_settingsItems, "highlightProperties", QMap<QString, QPair<bool, bool>>()) , highlightProperties(this->settingsItems, "highlightProperties",
, enableTwitchEmotes(_settingsItems, "enableTwitchEmotes", true) QMap<QString, QPair<bool, bool>>())
, enableBttvEmotes(_settingsItems, "enableBttvEmotes", true) , enableTwitchEmotes(this->settingsItems, "enableTwitchEmotes", true)
, enableFfzEmotes(_settingsItems, "enableFfzEmotes", true) , enableBttvEmotes(this->settingsItems, "enableBttvEmotes", true)
, enableEmojis(_settingsItems, "enableEmojis", true) , enableFfzEmotes(this->settingsItems, "enableFfzEmotes", true)
, enableGifAnimations(_settingsItems, "enableGifAnimations", true) , enableEmojis(this->settingsItems, "enableEmojis", true)
, enableGifs(_settingsItems, "enableGifs", true) , enableGifAnimations(this->settingsItems, "enableGifAnimations", true)
, inlineWhispers(_settingsItems, "inlineWhispers", true) , enableGifs(this->settingsItems, "enableGifs", true)
, windowTopMost(_settingsItems, "windowTopMost", false) , inlineWhispers(this->settingsItems, "inlineWhispers", true)
, hideTabX(_settingsItems, "hideTabX", false) , windowTopMost(this->settingsItems, "windowTopMost", false)
, hidePreferencesButton(_settingsItems, "hidePreferencesButton", false) , hideTabX(this->settingsItems, "hideTabX", false)
, hideUserButton(_settingsItems, "hideUserButton", false) , hidePreferencesButton(this->settingsItems, "hidePreferencesButton", false)
, useCustomWindowFrame(_settingsItems, "useCustomWindowFrame", true) , hideUserButton(this->settingsItems, "hideUserButton", false)
, useCustomWindowFrame(this->settingsItems, "useCustomWindowFrame", true)
{ {
this->showTimestamps.getValueChangedSignal().connect( this->showTimestamps.getValueChangedSignal().connect(
[this](const auto &) { this->updateWordTypeMask(); }); [this](const auto &) { this->updateWordTypeMask(); });
@@ -64,48 +65,51 @@ SettingsManager::SettingsManager()
void SettingsManager::save() void SettingsManager::save()
{ {
for (auto &item : _settingsItems) { for (auto &item : this->settingsItems) {
if (item.get().getName() != "highlightProperties") { if (item.get().getName() != "highlightProperties") {
_settings.setValue(item.get().getName(), item.get().getVariant()); this->settings.setValue(item.get().getName(), item.get().getVariant());
} else { } else {
_settings.beginGroup("Highlights"); this->settings.beginGroup("Highlights");
QStringList list = highlightProperties.get().keys(); QStringList list = highlightProperties.get().keys();
list.removeAll(""); list.removeAll("");
_settings.remove(""); this->settings.remove("");
for (auto string : list) { for (auto string : list) {
_settings.beginGroup(string); this->settings.beginGroup(string);
_settings.setValue("highlightSound", highlightProperties.get().value(string).first); this->settings.setValue("highlightSound",
_settings.setValue("highlightTask", highlightProperties.get().value(string).second); highlightProperties.get().value(string).first);
_settings.endGroup(); this->settings.setValue("highlightTask",
highlightProperties.get().value(string).second);
this->settings.endGroup();
} }
_settings.endGroup(); this->settings.endGroup();
} }
} }
} }
void SettingsManager::load() void SettingsManager::load()
{ {
for (auto &item : _settingsItems) { for (auto &item : this->settingsItems) {
if (item.get().getName() != "highlightProperties") { if (item.get().getName() != "highlightProperties") {
item.get().setVariant(_settings.value(item.get().getName())); item.get().setVariant(this->settings.value(item.get().getName()));
} else { } else {
_settings.beginGroup("Highlights"); this->settings.beginGroup("Highlights");
QStringList list = _settings.childGroups(); QStringList list = this->settings.childGroups();
qDebug() << list.join(","); qDebug() << list.join(",");
for (auto string : list) { for (auto string : list) {
_settings.beginGroup(string); this->settings.beginGroup(string);
highlightProperties.insertMap(string, _settings.value("highlightSound").toBool(), highlightProperties.insertMap(string,
_settings.value("highlightTask").toBool()); this->settings.value("highlightSound").toBool(),
_settings.endGroup(); this->settings.value("highlightTask").toBool());
this->settings.endGroup();
} }
_settings.endGroup(); this->settings.endGroup();
} }
} }
} }
Word::Type SettingsManager::getWordTypeMask() Word::Type SettingsManager::getWordTypeMask()
{ {
return _wordTypeMask; return this->wordTypeMask;
} }
bool SettingsManager::isIgnoredEmote(const QString &) bool SettingsManager::isIgnoredEmote(const QString &)
@@ -115,7 +119,7 @@ bool SettingsManager::isIgnoredEmote(const QString &)
QSettings &SettingsManager::getQSettings() QSettings &SettingsManager::getQSettings()
{ {
return _settings; return this->settings;
} }
void SettingsManager::updateWordTypeMask() void SettingsManager::updateWordTypeMask()
@@ -150,8 +154,8 @@ void SettingsManager::updateWordTypeMask()
Word::Type newMask = static_cast<Word::Type>(newMaskUint); Word::Type newMask = static_cast<Word::Type>(newMaskUint);
if (newMask != _wordTypeMask) { if (newMask != this->wordTypeMask) {
_wordTypeMask = newMask; this->wordTypeMask = newMask;
emit wordTypeMaskChanged(); emit wordTypeMaskChanged();
} }
@@ -161,11 +165,11 @@ SettingsSnapshot SettingsManager::createSnapshot()
{ {
SettingsSnapshot snapshot; SettingsSnapshot snapshot;
for (auto &item : this->_settingsItems) { for (auto &item : this->settingsItems) {
if (item.get().getName() != "highlightProperties") { if (item.get().getName() != "highlightProperties") {
snapshot.addItem(item, item.get().getVariant()); snapshot.addItem(item, item.get().getVariant());
} else { } else {
snapshot._mapItems = highlightProperties.get(); snapshot.mapItems = highlightProperties.get();
} }
} }
+11 -17
View File
@@ -22,22 +22,6 @@ public:
QSettings &getQSettings(); QSettings &getQSettings();
SettingsSnapshot createSnapshot(); SettingsSnapshot createSnapshot();
signals:
void wordTypeMaskChanged();
private:
SettingsManager();
// variables
QSettings _settings;
std::vector<std::reference_wrapper<BaseSetting>> _settingsItems;
messages::Word::Type _wordTypeMask = messages::Word::Default;
// methods
public: // temporary
void updateWordTypeMask();
public:
// new pajlada settings BBaper // new pajlada settings BBaper
pajlada::Settings::Setting<bool> showTimestamps; pajlada::Settings::Setting<bool> showTimestamps;
pajlada::Settings::Setting<bool> showTimestampSeconds; pajlada::Settings::Setting<bool> showTimestampSeconds;
@@ -78,12 +62,22 @@ public:
Setting<bool> hideUserButton; Setting<bool> hideUserButton;
Setting<bool> useCustomWindowFrame; Setting<bool> useCustomWindowFrame;
public:
static SettingsManager &getInstance() static SettingsManager &getInstance()
{ {
static SettingsManager instance; static SettingsManager instance;
return instance; return instance;
} }
void updateWordTypeMask();
signals:
void wordTypeMaskChanged();
private:
SettingsManager();
QSettings settings;
std::vector<std::reference_wrapper<BaseSetting>> settingsItems;
messages::Word::Type wordTypeMask = messages::Word::Default;
}; };
} // namespace chatterino } // namespace chatterino
+5 -5
View File
@@ -12,27 +12,27 @@ public:
void addItem(std::reference_wrapper<BaseSetting> setting, const QVariant &value) void addItem(std::reference_wrapper<BaseSetting> setting, const QVariant &value)
{ {
_items.push_back( this->items.push_back(
std::pair<std::reference_wrapper<BaseSetting>, QVariant>(setting.get(), value)); std::pair<std::reference_wrapper<BaseSetting>, QVariant>(setting.get(), value));
} }
void addMapItem(QString string, QPair<bool, bool> pair) void addMapItem(QString string, QPair<bool, bool> pair)
{ {
QMap<QString, QPair<bool, bool>> map; QMap<QString, QPair<bool, bool>> map;
_mapItems.insert(string, pair); this->mapItems.insert(string, pair);
} }
void apply() void apply()
{ {
for (auto &item : _items) { for (auto &item : this->items) {
item.first.get().setVariant(item.second); item.first.get().setVariant(item.second);
} }
} }
QMap<QString, QPair<bool, bool>> _mapItems; QMap<QString, QPair<bool, bool>> mapItems;
private: private:
std::vector<std::pair<std::reference_wrapper<BaseSetting>, QVariant>> _items; std::vector<std::pair<std::reference_wrapper<BaseSetting>, QVariant>> items;
}; };
} // namespace chatterino } // namespace chatterino
+2 -3
View File
@@ -319,8 +319,7 @@ void SettingsDialog::addTabs()
{"Choose", "Source", "High", "Medium", "Low", "Audio only"}, {"Choose", "Source", "High", "Medium", "Low", "Audio only"},
[](const QString &newValue, pajlada::Settings::Setting<std::string> &setting) { [](const QString &newValue, pajlada::Settings::Setting<std::string> &setting) {
setting = newValue.toStdString(); setting = newValue.toStdString();
}) }));
);
// v->addWidget(scroll); // v->addWidget(scroll);
// v->addStretch(1); // v->addStretch(1);
@@ -635,7 +634,7 @@ void SettingsDialog::cancelButtonClicked()
auto &instance = SettingsManager::getInstance(); auto &instance = SettingsManager::getInstance();
this->snapshot.apply(); this->snapshot.apply();
instance.highlightProperties.set(this->snapshot._mapItems); instance.highlightProperties.set(this->snapshot.mapItems);
QStringList list = instance.highlightProperties.get().keys(); QStringList list = instance.highlightProperties.get().keys();
list.removeDuplicates(); list.removeDuplicates();