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

View file

@ -163,7 +163,7 @@ HEADERS += \
src/widgets/rippleeffectlabel.hpp \
src/widgets/qualitypopup.hpp \
src/widgets/emotepopup.hpp \
src/messages/messagecolor.h
src/messages/messagecolor.hpp
PRECOMPILED_HEADER =

View file

@ -19,7 +19,7 @@ using namespace chatterino::messages;
namespace chatterino {
Channel::Channel()
// , _loggingChannel(logging::get(_name))
// , loggingChannel(logging::get(name))
{
}
@ -30,7 +30,7 @@ bool Channel::isEmpty() const
messages::LimitedQueueSnapshot<messages::SharedMessage> Channel::getMessageSnapshot()
{
return _messages.getSnapshot();
return this->messages.getSnapshot();
}
void Channel::addMessage(std::shared_ptr<Message> message)
@ -41,7 +41,7 @@ void Channel::addMessage(std::shared_ptr<Message> message)
// _loggingChannel->append(message);
// }
if (_messages.appendItem(message, deleted)) {
if (this->messages.appendItem(message, deleted)) {
messageRemovedFromStart(deleted);
}

View file

@ -41,9 +41,9 @@ public:
private:
// 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

View file

@ -2,33 +2,33 @@
namespace chatterino {
IrcUser2::IrcUser2(const QString &userName, const QString &nickName, const QString &realName,
const QString &password)
: _userName(userName)
, _nickName(nickName)
, _realName(realName)
, _password(password)
IrcUser2::IrcUser2(const QString &_userName, const QString &_nickName, const QString &_realName,
const QString &_password)
: userName(_userName)
, nickName(_nickName)
, realName(_realName)
, password(_password)
{
}
const QString &IrcUser2::getUserName() const
{
return _userName;
return this->userName;
}
const QString &IrcUser2::getNickName() const
{
return _nickName;
return this->nickName;
}
const QString &IrcUser2::getRealName() const
{
return _realName;
return this->realName;
}
const QString &IrcUser2::getPassword() const
{
return _password;
return this->password;
}
} // namespace chatterino

View file

@ -16,10 +16,10 @@ public:
const QString &getPassword() const;
private:
QString _userName;
QString _nickName;
QString _realName;
QString _password;
QString userName;
QString nickName;
QString realName;
QString password;
};
} // namespace chatterino

View file

@ -31,7 +31,7 @@ IrcManager::IrcManager(ChannelManager &_channelManager, Resources &_resources,
, resources(_resources)
, emoteManager(_emoteManager)
, windowManager(_windowManager)
, _account(AccountManager::getInstance().getTwitchAnon())
, account(AccountManager::getInstance().getTwitchAnon())
, currentUser("/accounts/current")
{
this->currentUser.getValueChangedSignal().connect([](const auto &newUsername) {
@ -42,12 +42,12 @@ IrcManager::IrcManager(ChannelManager &_channelManager, Resources &_resources,
const twitch::TwitchUser &IrcManager::getUser() const
{
return _account;
return this->account;
}
void IrcManager::setUser(const twitch::TwitchUser &account)
{
_account = account;
this->account = account;
}
void IrcManager::connect()
@ -68,9 +68,9 @@ Communi::IrcConnection *IrcManager::createConnection(bool doRead)
&IrcManager::privateMessageReceived);
}
QString username = _account.getUserName();
QString oauthClient = _account.getOAuthClient();
QString oauthToken = _account.getOAuthToken();
QString username = this->account.getUserName();
QString oauthClient = this->account.getOAuthClient();
QString oauthToken = this->account.getOAuthToken();
if (!oauthToken.startsWith("oauth:")) {
oauthToken.prepend("oauth:");
}
@ -79,7 +79,7 @@ Communi::IrcConnection *IrcManager::createConnection(bool doRead)
connection->setNickName(username);
connection->setRealName(username);
if (!_account.isAnon()) {
if (!this->account.isAnon()) {
connection->setPassword(oauthToken);
this->refreshIgnoredUsers(username, oauthClient, oauthToken);
@ -109,26 +109,26 @@ void IrcManager::refreshIgnoredUsers(const QString &username, const QString &oau
QNetworkReply *reply = manager->get(req);
QObject::connect(reply, &QNetworkReply::finished, [=] {
_twitchBlockedUsersMutex.lock();
_twitchBlockedUsers.clear();
_twitchBlockedUsersMutex.unlock();
this->twitchBlockedUsersMutex.lock();
this->twitchBlockedUsers.clear();
this->twitchBlockedUsersMutex.unlock();
QByteArray data = reply->readAll();
QJsonDocument jsonDoc(QJsonDocument::fromJson(data));
QJsonObject root = jsonDoc.object();
// nextLink =
// root.value("_links").toObject().value("next").toString();
// root.value("this->links").toObject().value("next").toString();
auto blocks = root.value("blocks").toArray();
_twitchBlockedUsersMutex.lock();
this->twitchBlockedUsersMutex.lock();
for (QJsonValue block : blocks) {
QJsonObject user = block.toObject().value("user").toObject();
// display_name
_twitchBlockedUsers.insert(user.value("name").toString().toLower(), true);
// displaythis->name
this->twitchBlockedUsers.insert(user.value("name").toString().toLower(), true);
}
_twitchBlockedUsersMutex.unlock();
this->twitchBlockedUsersMutex.unlock();
manager->deleteLater();
});
@ -311,27 +311,27 @@ void IrcManager::handleUserNoticeMessage(Communi::IrcMessage *message)
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)
{
QUrl url("https://api.twitch.tv/kraken/users/" + _account.getUserName() + "/blocks/" +
username + "?oauth_token=" + _account.getOAuthToken() +
"&client_id=" + _account.getOAuthClient());
QUrl url("https://api.twitch.tv/kraken/users/" + this->account.getUserName() + "/blocks/" +
username + "?oauth_token=" + this->account.getOAuthToken() +
"&client_id=" + this->account.getOAuthClient());
QNetworkRequest request(url);
auto reply = this->networkAccessManager.put(request, QByteArray());
reply->waitForReadyRead(10000);
if (reply->error() == QNetworkReply::NoError) {
_twitchBlockedUsersMutex.lock();
_twitchBlockedUsers.insert(username, true);
_twitchBlockedUsersMutex.unlock();
this->twitchBlockedUsersMutex.lock();
this->twitchBlockedUsers.insert(username, true);
this->twitchBlockedUsersMutex.unlock();
return true;
}
@ -352,18 +352,18 @@ void IrcManager::addIgnoredUser(QString const &username)
bool IrcManager::tryRemoveIgnoredUser(QString const &username, QString &errorMessage)
{
QUrl url("https://api.twitch.tv/kraken/users/" + _account.getUserName() + "/blocks/" +
username + "?oauth_token=" + _account.getOAuthToken() +
"&client_id=" + _account.getOAuthClient());
QUrl url("https://api.twitch.tv/kraken/users/" + this->account.getUserName() + "/blocks/" +
username + "?oauth_token=" + this->account.getOAuthToken() +
"&client_id=" + this->account.getOAuthClient());
QNetworkRequest request(url);
auto reply = this->networkAccessManager.deleteResource(request);
reply->waitForReadyRead(10000);
if (reply->error() == QNetworkReply::NoError) {
_twitchBlockedUsersMutex.lock();
_twitchBlockedUsers.remove(username);
_twitchBlockedUsersMutex.unlock();
this->twitchBlockedUsersMutex.lock();
this->twitchBlockedUsers.remove(username);
this->twitchBlockedUsersMutex.unlock();
return true;
}

View file

@ -27,8 +27,8 @@ class IrcManager : public QObject
Q_OBJECT
public:
IrcManager(ChannelManager &_channelManager, Resources &_resources, EmoteManager &_emoteManager,
WindowManager &_windowManager);
IrcManager(ChannelManager &channelManager, Resources &resources, EmoteManager &emoteManager,
WindowManager &windowManager);
void connect();
void disconnect();
@ -56,7 +56,7 @@ public:
private:
// variables
twitch::TwitchUser _account;
twitch::TwitchUser account;
pajlada::Settings::Setting<std::string> currentUser;
@ -69,8 +69,8 @@ private:
std::mutex connectionMutex;
uint32_t connectionGeneration = 0;
QMap<QString, bool> _twitchBlockedUsers;
QMutex _twitchBlockedUsersMutex;
QMap<QString, bool> twitchBlockedUsers;
QMutex twitchBlockedUsersMutex;
QNetworkAccessManager networkAccessManager;

View file

@ -13,61 +13,61 @@ template <typename T>
class LimitedQueue
{
public:
LimitedQueue(int limit = 1000, int buffer = 250)
: _offset(0)
, _limit(limit)
, _buffer(buffer)
LimitedQueue(int _limit = 1000, int _buffer = 250)
: offset(0)
, limit(_limit)
, buffer(_buffer)
{
_vector = std::make_shared<std::vector<T>>();
_vector->reserve(_limit + _buffer);
this->vector = std::make_shared<std::vector<T>>();
this->vector->reserve(this->limit + this->buffer);
}
void clear()
{
std::lock_guard<std::mutex> lock(_mutex);
std::lock_guard<std::mutex> lock(this->mutex);
_vector = std::make_shared<std::vector<T>>();
_vector->reserve(_limit + _buffer);
this->vector = std::make_shared<std::vector<T>>();
this->vector->reserve(this->limit + this->buffer);
_offset = 0;
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(_mutex);
std::lock_guard<std::mutex> lock(this->mutex);
if (_vector->size() >= _limit) {
if (this->vector->size() >= this->limit) {
// vector is full
if (_offset == _buffer) {
deleted = _vector->at(_offset);
if (this->offset == this->buffer) {
deleted = this->vector->at(this->offset);
// create new vector
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) {
newVector->push_back(_vector->at(i + _offset));
for (unsigned int i = 0; i < this->limit; ++i) {
newVector->push_back(this->vector->at(i + this->offset));
}
newVector->push_back(item);
_offset = 0;
_vector = newVector;
this->offset = 0;
this->vector = newVector;
return true;
} else {
deleted = _vector->at(_offset);
deleted = this->vector->at(this->offset);
// append item and increment offset("deleting" first element)
_vector->push_back(item);
_offset++;
this->vector->push_back(item);
this->offset++;
return true;
}
} else {
// append item
_vector->push_back(item);
this->vector->push_back(item);
return false;
}
@ -75,22 +75,22 @@ public:
messages::LimitedQueueSnapshot<T> getSnapshot()
{
std::lock_guard<std::mutex> lock(_mutex);
std::lock_guard<std::mutex> lock(this->mutex);
if (_vector->size() < _limit) {
return LimitedQueueSnapshot<T>(_vector, _offset, _vector->size());
if (this->vector->size() < this->limit) {
return LimitedQueueSnapshot<T>(this->vector, this->offset, this->vector->size());
} else {
return LimitedQueueSnapshot<T>(_vector, _offset, _limit);
return LimitedQueueSnapshot<T>(this->vector, this->offset, this->limit);
}
}
private:
std::shared_ptr<std::vector<T>> _vector;
std::mutex _mutex;
std::shared_ptr<std::vector<T>> vector;
std::mutex mutex;
unsigned int _offset;
unsigned int _limit;
unsigned int _buffer;
unsigned int offset;
unsigned int limit;
unsigned int buffer;
};
} // namespace messages

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

View file

@ -9,11 +9,26 @@ Link::Link()
{
}
Link::Link(Type type, const QString &value)
: type(type)
, value(value)
Link::Link(Type _type, const QString &_value)
: type(_type)
, 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 chatterino

View file

@ -22,20 +22,9 @@ public:
Link();
Link(Type getType, const QString &getValue);
bool isValid() const
{
return type != None;
}
Type getType() const
{
return type;
}
const QString &getValue() const
{
return value;
}
bool isValid() const;
Type getType() const;
const QString &getValue() const;
private:
Type type;

View file

@ -1,15 +1,15 @@
#include "messagecolor.h"
#include "messagecolor.hpp"
namespace chatterino {
namespace messages {
MessageColor::MessageColor(const QColor &color)
MessageColor::MessageColor(const QColor &_color)
: type(Type::Custom)
, color(color)
, color(_color)
{
}
MessageColor::MessageColor(Type type)
: type(type)
MessageColor::MessageColor(Type _type)
: type(_type)
{
}

View file

@ -14,40 +14,40 @@ using namespace chatterino::messages;
namespace chatterino {
namespace messages {
MessageRef::MessageRef(SharedMessage message)
: _message(message)
, _wordParts()
MessageRef::MessageRef(SharedMessage _message)
: message(_message)
, wordParts()
{
}
Message *MessageRef::getMessage()
{
return _message.get();
return this->message.get();
}
int MessageRef::getHeight() const
{
return _height;
return this->height;
}
bool MessageRef::layout(int width, bool enableEmoteMargins)
{
auto &settings = SettingsManager::getInstance();
bool sizeChanged = width != _currentLayoutWidth;
bool redraw = width != _currentLayoutWidth;
bool sizeChanged = width != this->currentLayoutWidth;
bool redraw = width != this->currentLayoutWidth;
int spaceWidth = 4;
int mediumTextLineHeight =
FontManager::getInstance().getFontMetrics(FontManager::Medium).height();
/* TODO(pajlada): Re-implement
bool recalculateImages = _emoteGeneration != EmoteManager::getInstance().getGeneration();
bool recalculateImages = this->emoteGeneration != EmoteManager::getInstance().getGeneration();
*/
bool recalculateImages = true;
bool recalculateText = _fontGeneration != FontManager::getInstance().getGeneration();
bool newWordTypes = _currentWordTypes != SettingsManager::getInstance().getWordTypeMask();
bool recalculateText = this->fontGeneration != FontManager::getInstance().getGeneration();
bool newWordTypes = this->currentWordTypes != SettingsManager::getInstance().getWordTypeMask();
qreal emoteScale = settings.emoteScale.get();
bool scaleEmotesByLineHeight = settings.scaleEmotesByLineHeight.get();
@ -57,10 +57,10 @@ bool MessageRef::layout(int width, bool enableEmoteMargins)
return false;
}
// _emoteGeneration = EmoteManager::getInstance().getGeneration();
_fontGeneration = FontManager::getInstance().getGeneration();
// this->emoteGeneration = EmoteManager::getInstance().getGeneration();
this->fontGeneration = FontManager::getInstance().getGeneration();
for (auto &word : _message->getWords()) {
for (auto &word : this->message->getWords()) {
if (word.isImage()) {
if (!recalculateImages) {
continue;
@ -88,11 +88,11 @@ bool MessageRef::layout(int width, bool enableEmoteMargins)
}
if (newWordTypes) {
_currentWordTypes = settings.getWordTypeMask();
this->currentWordTypes = settings.getWordTypeMask();
}
// layout
_currentLayoutWidth = width;
this->currentLayoutWidth = width;
int x = MARGIN_LEFT;
int y = MARGIN_TOP;
@ -104,11 +104,11 @@ bool MessageRef::layout(int width, bool enableEmoteMargins)
int lineHeight = 0;
bool first = true;
_wordParts.clear();
this->wordParts.clear();
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;
// 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) {
QString mid = text.mid(start, i - start - 1);
_wordParts.push_back(WordPart(word, MARGIN_LEFT, y, width, word.getHeight(),
lineNumber, mid, mid, false, charOffset));
this->wordParts.push_back(WordPart(word, MARGIN_LEFT, y, width,
word.getHeight(), lineNumber, mid, mid,
false, charOffset));
charOffset = i;
@ -164,18 +165,18 @@ bool MessageRef::layout(int width, bool enableEmoteMargins)
QString mid(text.mid(start));
width = metrics.width(mid);
_wordParts.push_back(WordPart(word, MARGIN_LEFT, y - word.getHeight(), width,
word.getHeight(), lineNumber, mid, mid, charOffset));
this->wordParts.push_back(WordPart(word, MARGIN_LEFT, y - word.getHeight(), width,
word.getHeight(), lineNumber, mid, mid, charOffset));
x = width + MARGIN_LEFT + spaceWidth;
lineHeight = word.getHeight();
lineStart = _wordParts.size() - 1;
lineStart = this->wordParts.size() - 1;
first = false;
} else if (first || x + word.getWidth() + xOffset <= right) {
// fits in the line
_wordParts.push_back(
this->wordParts.push_back(
WordPart(word, x, y - word.getHeight(), lineNumber, word.getCopyText()));
x += word.getWidth() + xOffset;
@ -192,10 +193,10 @@ bool MessageRef::layout(int width, bool enableEmoteMargins)
lineNumber++;
_wordParts.push_back(
this->wordParts.push_back(
WordPart(word, MARGIN_LEFT, y - word.getHeight(), lineNumber, word.getCopyText()));
lineStart = _wordParts.size() - 1;
lineStart = this->wordParts.size() - 1;
lineHeight = word.getHeight();
@ -206,12 +207,12 @@ bool MessageRef::layout(int width, bool enableEmoteMargins)
alignWordParts(lineStart, lineHeight, width);
if (_height != y + lineHeight) {
if (this->height != y + lineHeight) {
sizeChanged = true;
_height = y + lineHeight;
this->height = y + lineHeight;
}
_height += MARGIN_BOTTOM;
this->height += MARGIN_BOTTOM;
if (sizeChanged) {
buffer = nullptr;
@ -224,19 +225,19 @@ bool MessageRef::layout(int width, bool enableEmoteMargins)
const std::vector<WordPart> &MessageRef::getWordParts() const
{
return _wordParts;
return this->wordParts;
}
void MessageRef::alignWordParts(int lineStart, int lineHeight, int width)
{
int xOffset = 0;
if (this->_message->centered && _wordParts.size() > 0) {
xOffset = (width - this->_wordParts.at(_wordParts.size() - 1).getRight()) / 2;
if (this->message->centered && this->wordParts.size() > 0) {
xOffset = (width - this->wordParts.at(this->wordParts.size() - 1).getRight()) / 2;
}
for (size_t i = lineStart; i < this->_wordParts.size(); i++) {
WordPart &wordPart2 = this->_wordParts.at(i);
for (size_t i = lineStart; i < this->wordParts.size(); i++) {
WordPart &wordPart2 = this->wordParts.at(i);
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)
{
// 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)) {
return &wordPart.getWord();
}
@ -256,15 +257,15 @@ const Word *MessageRef::tryGetWordPart(QPoint point)
int MessageRef::getSelectionIndex(QPoint position)
{
if (_wordParts.size() == 0) {
if (this->wordParts.size() == 0) {
return 0;
}
// find out in which line the cursor is
int lineNumber = 0, lineStart = 0, lineEnd = 0;
for (size_t i = 0; i < _wordParts.size(); i++) {
WordPart &part = _wordParts[i];
for (size_t i = 0; i < this->wordParts.size(); i++) {
WordPart &part = this->wordParts[i];
if (part.getLineNumber() != 0 && position.y() < part.getY()) {
break;
@ -282,13 +283,13 @@ int MessageRef::getSelectionIndex(QPoint position)
int index = 0;
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;
}
for (int i = lineStart; i < lineEnd; i++) {
WordPart &part = _wordParts[i];
WordPart &part = this->wordParts[i];
// curser is left of the word part
if (position.x() < part.getX()) {

View file

@ -34,17 +34,17 @@ public:
private:
// variables
SharedMessage _message;
std::vector<messages::WordPart> _wordParts;
SharedMessage message;
std::vector<messages::WordPart> wordParts;
int _height = 0;
int height = 0;
int _currentLayoutWidth = -1;
int _fontGeneration = -1;
int currentLayoutWidth = -1;
int fontGeneration = -1;
/* TODO(pajlada): Re-implement
int _emoteGeneration = -1;
int emoteGeneration = -1;
*/
Word::Type _currentWordTypes = Word::None;
Word::Type currentWordTypes = Word::None;
// methods
void alignWordParts(int lineStart, int lineHeight, int width);

View file

@ -3,7 +3,7 @@
#include "fontmanager.hpp"
#include "messages/lazyloadedimage.hpp"
#include "messages/link.hpp"
#include "messages/messagecolor.h"
#include "messages/messagecolor.hpp"
#include <stdint.h>
#include <QRect>

View file

@ -4,106 +4,108 @@
namespace chatterino {
namespace messages {
WordPart::WordPart(Word &word, int x, int y, int lineNumber, const QString &copyText,
bool allowTrailingSpace)
: _word(word)
, _copyText(copyText)
, _text(word.isText() ? _word.getText() : QString())
, _x(x)
, _y(y)
, _width(word.getWidth())
, _height(word.getHeight())
, _lineNumber(lineNumber)
, _trailingSpace(!word.getCopyText().isEmpty() && word.hasTrailingSpace() & allowTrailingSpace)
WordPart::WordPart(Word &_word, int _x, int _y, int _lineNumber, const QString &_copyText,
bool _allowTrailingSpace)
: word(_word)
, copyText(_copyText)
, text(_word.isText() ? _word.getText() : QString())
, x(_x)
, y(_y)
, width(_word.getWidth())
, height(_word.getHeight())
, lineNumber(_lineNumber)
, _trailingSpace(!_word.getCopyText().isEmpty() &&
_word.hasTrailingSpace() & _allowTrailingSpace)
, wordCharOffset(0)
{
}
WordPart::WordPart(Word &word, int x, int y, int width, int height, int lineNumber,
const QString &copyText, const QString &customText, bool allowTrailingSpace,
int wordCharOffset)
: _word(word)
, _copyText(copyText)
, _text(customText)
, _x(x)
, _y(y)
, _width(width)
, _height(height)
, _lineNumber(lineNumber)
, _trailingSpace(!word.getCopyText().isEmpty() && word.hasTrailingSpace() & allowTrailingSpace)
, wordCharOffset(wordCharOffset)
WordPart::WordPart(Word &_word, int _x, int _y, int _width, int _height, int _lineNumber,
const QString &_copyText, const QString &_customText, bool _allowTrailingSpace,
int _wordCharOffset)
: word(_word)
, copyText(_copyText)
, text(_customText)
, x(_x)
, y(_y)
, width(_width)
, height(_height)
, lineNumber(_lineNumber)
, _trailingSpace(!_word.getCopyText().isEmpty() &&
_word.hasTrailingSpace() & _allowTrailingSpace)
, wordCharOffset(_wordCharOffset)
{
}
const Word &WordPart::getWord() const
{
return _word;
return this->word;
}
int WordPart::getWidth() const
{
return _width;
return this->width;
}
int WordPart::getHeight() const
{
return _height;
return this->height;
}
int WordPart::getX() const
{
return _x;
return this->x;
}
int WordPart::getY() const
{
return _y;
return this->y;
}
void WordPart::setPosition(int x, int y)
{
_x = x;
_y = y;
this->x = x;
this->y = y;
}
void WordPart::setY(int y)
{
_y = y;
this->y = y;
}
int WordPart::getRight() const
{
return _x + _width;
return this->x + this->width;
}
int WordPart::getBottom() const
{
return _y + _height;
return this->y + this->height;
}
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
{
return _copyText;
return this->copyText;
}
int WordPart::hasTrailingSpace() const
{
return _trailingSpace;
return this->_trailingSpace;
}
const QString &WordPart::getText() const
{
return _text;
return this->text;
}
int WordPart::getLineNumber() const
{
return _lineNumber;
return this->lineNumber;
}
int WordPart::getCharacterLength() const

View file

@ -36,17 +36,17 @@ public:
short getCharacterWidth(int index) const;
private:
Word &_word;
Word &word;
QString _copyText;
QString _text;
QString copyText;
QString text;
int _x;
int _y;
int _width;
int _height;
int x;
int y;
int width;
int height;
int _lineNumber;
int lineNumber;
bool _trailingSpace;
int wordCharOffset;

View file

@ -10,7 +10,7 @@ class BaseSetting
{
public:
BaseSetting(const QString &_name)
: _name(_name)
: name(_name)
{
}
@ -19,11 +19,11 @@ public:
const QString &getName() const
{
return _name;
return this->name;
}
private:
QString _name;
QString name;
};
template <typename T>
@ -33,25 +33,25 @@ public:
Setting(std::vector<std::reference_wrapper<BaseSetting>> &settingItems, const QString &_name,
const T &defaultValue)
: BaseSetting(_name)
, _value(defaultValue)
, value(defaultValue)
{
settingItems.push_back(*this);
}
const T &get() const
{
return _value;
return this->value;
}
T &getnonConst()
{
return _value;
return this->value;
}
void set(const T &newValue)
{
if (_value != newValue) {
_value = newValue;
if (this->value != newValue) {
this->value = newValue;
valueChanged(newValue);
}
@ -59,7 +59,7 @@ public:
virtual QVariant getVariant() final
{
return QVariant::fromValue(_value);
return QVariant::fromValue(this->value);
}
virtual void setVariant(QVariant value) final
@ -73,13 +73,13 @@ public:
void insertMap(QString id, bool sound, bool task)
{
QPair<bool, bool> pair(sound, task);
_value.insert(id, pair);
this->value.insert(id, pair);
}
boost::signals2::signal<void(const T &newValue)> valueChanged;
private:
T _value;
T value;
};
} // namespace chatterino

View file

@ -10,42 +10,43 @@ using namespace chatterino::messages;
namespace chatterino {
SettingsManager::SettingsManager()
: _settings(Path::getAppdataPath() + "settings.ini", QSettings::IniFormat)
: 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(_settingsItems, "emoteScale", 1.0)
, mouseScrollMultiplier(_settingsItems, "mouseScrollMultiplier", 1.0)
, scaleEmotesByLineHeight(_settingsItems, "scaleEmotesByLineHeight", false)
, showLastMessageIndicator(_settingsItems, "showLastMessageIndicator", false)
, allowDouplicateMessages(_settingsItems, "allowDouplicateMessages", true)
, linksDoubleClickOnly(_settingsItems, "linksDoubleClickOnly", false)
, hideEmptyInput(_settingsItems, "hideEmptyInput", false)
, showMessageLength(_settingsItems, "showMessageLength", false)
, seperateMessages(_settingsItems, "seperateMessages", false)
, mentionUsersWithAt(_settingsItems, "mentionUsersWithAt", false)
, allowCommandsAtEnd(_settingsItems, "allowCommandsAtEnd", false)
, enableHighlights(_settingsItems, "enableHighlights", true)
, enableHighlightsSelf(_settingsItems, "enableHighlightsSelf", true)
, enableHighlightSound(_settingsItems, "enableHighlightSound", true)
, enableHighlightTaskbar(_settingsItems, "enableHighlightTaskbar", true)
, customHighlightSound(_settingsItems, "customHighlightSound", false)
, pathHighlightSound(_settingsItems, "pathHighlightSound", "qrc:/sounds/ping2.wav")
, highlightProperties(_settingsItems, "highlightProperties", QMap<QString, QPair<bool, bool>>())
, enableTwitchEmotes(_settingsItems, "enableTwitchEmotes", true)
, enableBttvEmotes(_settingsItems, "enableBttvEmotes", true)
, enableFfzEmotes(_settingsItems, "enableFfzEmotes", true)
, enableEmojis(_settingsItems, "enableEmojis", true)
, enableGifAnimations(_settingsItems, "enableGifAnimations", true)
, enableGifs(_settingsItems, "enableGifs", true)
, inlineWhispers(_settingsItems, "inlineWhispers", true)
, windowTopMost(_settingsItems, "windowTopMost", false)
, hideTabX(_settingsItems, "hideTabX", false)
, hidePreferencesButton(_settingsItems, "hidePreferencesButton", false)
, hideUserButton(_settingsItems, "hideUserButton", false)
, useCustomWindowFrame(_settingsItems, "useCustomWindowFrame", true)
, 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>>())
, 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(); });
@ -64,48 +65,51 @@ SettingsManager::SettingsManager()
void SettingsManager::save()
{
for (auto &item : _settingsItems) {
for (auto &item : this->settingsItems) {
if (item.get().getName() != "highlightProperties") {
_settings.setValue(item.get().getName(), item.get().getVariant());
this->settings.setValue(item.get().getName(), item.get().getVariant());
} else {
_settings.beginGroup("Highlights");
this->settings.beginGroup("Highlights");
QStringList list = highlightProperties.get().keys();
list.removeAll("");
_settings.remove("");
this->settings.remove("");
for (auto string : list) {
_settings.beginGroup(string);
_settings.setValue("highlightSound", highlightProperties.get().value(string).first);
_settings.setValue("highlightTask", highlightProperties.get().value(string).second);
_settings.endGroup();
this->settings.beginGroup(string);
this->settings.setValue("highlightSound",
highlightProperties.get().value(string).first);
this->settings.setValue("highlightTask",
highlightProperties.get().value(string).second);
this->settings.endGroup();
}
_settings.endGroup();
this->settings.endGroup();
}
}
}
void SettingsManager::load()
{
for (auto &item : _settingsItems) {
for (auto &item : this->settingsItems) {
if (item.get().getName() != "highlightProperties") {
item.get().setVariant(_settings.value(item.get().getName()));
item.get().setVariant(this->settings.value(item.get().getName()));
} else {
_settings.beginGroup("Highlights");
QStringList list = _settings.childGroups();
this->settings.beginGroup("Highlights");
QStringList list = this->settings.childGroups();
qDebug() << list.join(",");
for (auto string : list) {
_settings.beginGroup(string);
highlightProperties.insertMap(string, _settings.value("highlightSound").toBool(),
_settings.value("highlightTask").toBool());
_settings.endGroup();
this->settings.beginGroup(string);
highlightProperties.insertMap(string,
this->settings.value("highlightSound").toBool(),
this->settings.value("highlightTask").toBool());
this->settings.endGroup();
}
_settings.endGroup();
this->settings.endGroup();
}
}
}
Word::Type SettingsManager::getWordTypeMask()
{
return _wordTypeMask;
return this->wordTypeMask;
}
bool SettingsManager::isIgnoredEmote(const QString &)
@ -115,7 +119,7 @@ bool SettingsManager::isIgnoredEmote(const QString &)
QSettings &SettingsManager::getQSettings()
{
return _settings;
return this->settings;
}
void SettingsManager::updateWordTypeMask()
@ -150,8 +154,8 @@ void SettingsManager::updateWordTypeMask()
Word::Type newMask = static_cast<Word::Type>(newMaskUint);
if (newMask != _wordTypeMask) {
_wordTypeMask = newMask;
if (newMask != this->wordTypeMask) {
this->wordTypeMask = newMask;
emit wordTypeMaskChanged();
}
@ -161,11 +165,11 @@ SettingsSnapshot SettingsManager::createSnapshot()
{
SettingsSnapshot snapshot;
for (auto &item : this->_settingsItems) {
for (auto &item : this->settingsItems) {
if (item.get().getName() != "highlightProperties") {
snapshot.addItem(item, item.get().getVariant());
} else {
snapshot._mapItems = highlightProperties.get();
snapshot.mapItems = highlightProperties.get();
}
}

View file

@ -22,22 +22,6 @@ public:
QSettings &getQSettings();
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
pajlada::Settings::Setting<bool> showTimestamps;
pajlada::Settings::Setting<bool> showTimestampSeconds;
@ -78,12 +62,22 @@ public:
Setting<bool> hideUserButton;
Setting<bool> useCustomWindowFrame;
public:
static SettingsManager &getInstance()
{
static SettingsManager 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

View file

@ -12,27 +12,27 @@ public:
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));
}
void addMapItem(QString string, QPair<bool, bool> pair)
{
QMap<QString, QPair<bool, bool>> map;
_mapItems.insert(string, pair);
this->mapItems.insert(string, pair);
}
void apply()
{
for (auto &item : _items) {
for (auto &item : this->items) {
item.first.get().setVariant(item.second);
}
}
QMap<QString, QPair<bool, bool>> _mapItems;
QMap<QString, QPair<bool, bool>> mapItems;
private:
std::vector<std::pair<std::reference_wrapper<BaseSetting>, QVariant>> _items;
std::vector<std::pair<std::reference_wrapper<BaseSetting>, QVariant>> items;
};
} // namespace chatterino

View file

@ -319,8 +319,7 @@ void SettingsDialog::addTabs()
{"Choose", "Source", "High", "Medium", "Low", "Audio only"},
[](const QString &newValue, pajlada::Settings::Setting<std::string> &setting) {
setting = newValue.toStdString();
})
);
}));
// v->addWidget(scroll);
// v->addStretch(1);
@ -635,7 +634,7 @@ void SettingsDialog::cancelButtonClicked()
auto &instance = SettingsManager::getInstance();
this->snapshot.apply();
instance.highlightProperties.set(this->snapshot._mapItems);
instance.highlightProperties.set(this->snapshot.mapItems);
QStringList list = instance.highlightProperties.get().keys();
list.removeDuplicates();