This commit is contained in:
Rasmus Karlsson 2018-04-01 16:43:30 +02:00 committed by fourtf
parent 13705f15ed
commit 4888178079
12 changed files with 62 additions and 67 deletions

View file

@ -244,6 +244,7 @@ void MessageLayout::addSelectionText(QString &str, int from, int to)
{ {
this->container.addSelectionText(str, from, to); this->container.addSelectionText(str, from, to);
} }
} // namespace layouts } // namespace layouts
} // namespace messages } // namespace messages
} // namespace chatterino } // namespace chatterino

View file

@ -15,6 +15,7 @@
namespace chatterino { namespace chatterino {
namespace messages { namespace messages {
namespace layouts { namespace layouts {
class MessageLayout : boost::noncopyable class MessageLayout : boost::noncopyable
{ {
public: public:
@ -73,7 +74,8 @@ private:
void updateBuffer(QPixmap *pixmap, int messageIndex, Selection &selection); void updateBuffer(QPixmap *pixmap, int messageIndex, Selection &selection);
}; };
typedef std::shared_ptr<MessageLayout> MessageLayoutPtr; using MessageLayoutPtr = std::shared_ptr<MessageLayout>;
} // namespace layouts } // namespace layouts
} // namespace messages } // namespace messages
} // namespace chatterino } // namespace chatterino

View file

@ -12,13 +12,6 @@
namespace chatterino { namespace chatterino {
namespace messages { namespace messages {
namespace layouts { namespace layouts {
MessageLayoutContainer::MessageLayoutContainer()
: scale(1)
, flags(Message::None)
, margin(4, 8, 4, 8)
{
this->clear();
}
int MessageLayoutContainer::getHeight() const int MessageLayoutContainer::getHeight() const
{ {
@ -36,11 +29,11 @@ float MessageLayoutContainer::getScale() const
} }
// methods // methods
void MessageLayoutContainer::begin(int width, float _scale, Message::MessageFlags _flags) void MessageLayoutContainer::begin(int _width, float _scale, Message::MessageFlags _flags)
{ {
this->clear(); this->clear();
this->width = width; this->width = _width;
this->scale = this->scale; this->scale = _scale;
this->flags = _flags; this->flags = _flags;
} }
@ -434,6 +427,7 @@ void MessageLayoutContainer::addSelectionText(QString &str, int from, int to)
index += c; index += c;
} }
} }
} // namespace layouts } // namespace layouts
} // namespace messages } // namespace messages
} // namespace chatterino } // namespace chatterino

View file

@ -43,12 +43,11 @@ struct Margin {
}; };
struct MessageLayoutContainer { struct MessageLayoutContainer {
public: MessageLayoutContainer() = default;
MessageLayoutContainer();
Margin margin; Margin margin = {4, 8, 4, 8};
bool centered; bool centered = false;
bool enableCompactEmotes; bool enableCompactEmotes = false;
int getHeight() const; int getHeight() const;
int getWidth() const; int getWidth() const;
@ -89,20 +88,22 @@ private:
void _addElement(MessageLayoutElement *element); void _addElement(MessageLayoutElement *element);
// variables // variables
float scale; float scale = 1.f;
int width; int width = 0;
Message::MessageFlags flags; Message::MessageFlags flags = Message::MessageFlags::None;
int line; int line = 0;
int height; int height = 0;
int currentX, currentY; int currentX = 0;
int currentY = 0;
int charIndex = 0; int charIndex = 0;
size_t lineStart = 0; size_t lineStart = 0;
int lineHeight = 0; int lineHeight = 0;
int spaceWidth = 4; int spaceWidth = 4;
std::vector<std::unique_ptr<MessageLayoutElement>> elements;
std::vector<std::unique_ptr<MessageLayoutElement>> elements;
std::vector<Line> lines; std::vector<Line> lines;
}; };
} // namespace layouts } // namespace layouts
} // namespace messages } // namespace messages
} // namespace chatterino } // namespace chatterino

View file

@ -272,6 +272,7 @@ int TextIconLayoutElement::getXFromIndex(int index)
return this->getRect().right(); return this->getRect().right();
} }
} }
} // namespace layouts } // namespace layouts
} // namespace messages } // namespace messages
} // namespace chatterino } // namespace chatterino

View file

@ -56,12 +56,12 @@ public:
ImageLayoutElement(MessageElement &creator, Image *image, const QSize &size); ImageLayoutElement(MessageElement &creator, Image *image, const QSize &size);
protected: protected:
virtual void addCopyTextToString(QString &str, int from = 0, int to = INT_MAX) const override; void addCopyTextToString(QString &str, int from = 0, int to = INT_MAX) const override;
virtual int getSelectionIndexCount() override; int getSelectionIndexCount() override;
virtual void paint(QPainter &painter) override; void paint(QPainter &painter) override;
virtual void paintAnimated(QPainter &painter, int yOffset) override; void paintAnimated(QPainter &painter, int yOffset) override;
virtual int getMouseOverIndex(const QPoint &abs) override; int getMouseOverIndex(const QPoint &abs) override;
virtual int getXFromIndex(int index) override; int getXFromIndex(int index) override;
private: private:
Image *image; Image *image;
@ -75,12 +75,12 @@ public:
FontStyle style, float scale); FontStyle style, float scale);
protected: protected:
virtual void addCopyTextToString(QString &str, int from = 0, int to = INT_MAX) const override; void addCopyTextToString(QString &str, int from = 0, int to = INT_MAX) const override;
virtual int getSelectionIndexCount() override; int getSelectionIndexCount() override;
virtual void paint(QPainter &painter) override; void paint(QPainter &painter) override;
virtual void paintAnimated(QPainter &painter, int yOffset) override; void paintAnimated(QPainter &painter, int yOffset) override;
virtual int getMouseOverIndex(const QPoint &abs) override; int getMouseOverIndex(const QPoint &abs) override;
virtual int getXFromIndex(int index) override; int getXFromIndex(int index) override;
private: private:
QString text; QString text;
@ -98,18 +98,19 @@ public:
float scale, const QSize &size); float scale, const QSize &size);
protected: protected:
virtual void addCopyTextToString(QString &str, int from = 0, int to = INT_MAX) const override; void addCopyTextToString(QString &str, int from = 0, int to = INT_MAX) const override;
virtual int getSelectionIndexCount() override; int getSelectionIndexCount() override;
virtual void paint(QPainter &painter) override; void paint(QPainter &painter) override;
virtual void paintAnimated(QPainter &painter, int yOffset) override; void paintAnimated(QPainter &painter, int yOffset) override;
virtual int getMouseOverIndex(const QPoint &abs) override; int getMouseOverIndex(const QPoint &abs) override;
virtual int getXFromIndex(int index) override; int getXFromIndex(int index) override;
private: private:
QString line1; QString line1;
QString line2; QString line2;
float scale; float scale;
}; };
} // namespace layouts } // namespace layouts
} // namespace messages } // namespace messages
} // namespace chatterino } // namespace chatterino

View file

@ -247,6 +247,7 @@ void AbstractIrcServer::forEachChannel(std::function<void(ChannelPtr)> func)
func(chan); func(chan);
} }
} }
} // namespace irc } // namespace irc
} // namespace providers } // namespace providers
} // namespace chatterino } // namespace chatterino

View file

@ -1,15 +1,16 @@
#pragma once #pragma once
#include "channel.hpp"
#include <IrcMessage> #include <IrcMessage>
#include <functional> #include <functional>
#include <mutex> #include <mutex>
#include <pajlada/signals/signal.hpp> #include <pajlada/signals/signal.hpp>
#include "channel.hpp"
namespace chatterino { namespace chatterino {
namespace providers { namespace providers {
namespace irc { namespace irc {
class AbstractIrcServer class AbstractIrcServer
{ {
public: public:
@ -64,6 +65,7 @@ private:
std::mutex connectionMutex; std::mutex connectionMutex;
}; };
} // namespace irc } // namespace irc
} // namespace providers } // namespace providers
} // namespace chatterino } // namespace chatterino

View file

@ -24,15 +24,15 @@ public:
const ChannelPtr mentionsChannel; const ChannelPtr mentionsChannel;
protected: protected:
virtual void initializeConnection(Communi::IrcConnection *connection, bool isRead, void initializeConnection(Communi::IrcConnection *connection, bool isRead,
bool isWrite) override; bool isWrite) override;
virtual std::shared_ptr<Channel> createChannel(const QString &channelName) override; std::shared_ptr<Channel> createChannel(const QString &channelName) override;
virtual void privateMessageReceived(Communi::IrcPrivateMessage *message) override; void privateMessageReceived(Communi::IrcPrivateMessage *message) override;
virtual void messageReceived(Communi::IrcMessage *message) override; void messageReceived(Communi::IrcMessage *message) override;
virtual void writeConnectionMessageReceived(Communi::IrcMessage *message) override; void writeConnectionMessageReceived(Communi::IrcMessage *message) override;
virtual std::shared_ptr<Channel> getCustomChannel(const QString &channelname) override; std::shared_ptr<Channel> getCustomChannel(const QString &channelname) override;
QString CleanChannelName(const QString &dirtyChannelName) override; QString CleanChannelName(const QString &dirtyChannelName) override;
}; };

View file

@ -75,10 +75,8 @@ void FillInFFZEmoteData(const QJsonObject &urls, const QString &code, util::Emot
} // namespace } // namespace
EmoteManager::EmoteManager(SettingManager &_settingsManager, WindowManager &_windowManager) EmoteManager::EmoteManager()
: settingsManager(_settingsManager) : findShortCodesRegex(":([-+\\w]+):")
, windowManager(_windowManager)
, findShortCodesRegex(":([-+\\w]+):")
{ {
auto &accountManager = AccountManager::getInstance(); auto &accountManager = AccountManager::getInstance();
@ -91,7 +89,7 @@ EmoteManager::EmoteManager(SettingManager &_settingsManager, WindowManager &_win
EmoteManager &EmoteManager::getInstance() EmoteManager &EmoteManager::getInstance()
{ {
static EmoteManager instance(SettingManager::getInstance(), WindowManager::getInstance()); static EmoteManager instance;
return instance; return instance;
} }
@ -562,7 +560,9 @@ boost::signals2::signal<void()> &EmoteManager::getGifUpdateSignal()
this->gifUpdateTimer.setInterval(30); this->gifUpdateTimer.setInterval(30);
this->gifUpdateTimer.start(); this->gifUpdateTimer.start();
this->settingsManager.enableGifAnimations.connect([this](bool enabled, auto) { auto &settingManager = singletons::SettingManager::getInstance();
settingManager.enableGifAnimations.connect([this](bool enabled, auto) {
if (enabled) { if (enabled) {
this->gifUpdateTimer.start(); this->gifUpdateTimer.start();
} else { } else {
@ -573,7 +573,8 @@ boost::signals2::signal<void()> &EmoteManager::getGifUpdateSignal()
QObject::connect(&this->gifUpdateTimer, &QTimer::timeout, [this] { QObject::connect(&this->gifUpdateTimer, &QTimer::timeout, [this] {
this->gifUpdateTimerSignal(); this->gifUpdateTimerSignal();
// fourtf: // fourtf:
this->windowManager.repaintGifEmotes(); auto &windowManager = singletons::WindowManager::getInstance();
windowManager.repaintGifEmotes();
}); });
} }

View file

@ -20,13 +20,9 @@
namespace chatterino { namespace chatterino {
namespace singletons { namespace singletons {
class SettingManager;
class WindowManager;
class EmoteManager class EmoteManager
{ {
explicit EmoteManager(singletons::SettingManager &manager, EmoteManager();
singletons::WindowManager &windowManager);
public: public:
static EmoteManager &getInstance(); static EmoteManager &getInstance();
@ -66,9 +62,6 @@ public:
util::ConcurrentMap<QString, messages::Image *> miscImageCache; util::ConcurrentMap<QString, messages::Image *> miscImageCache;
private: private:
SettingManager &settingsManager;
WindowManager &windowManager;
/// Emojis /// Emojis
QRegularExpression findShortCodesRegex; QRegularExpression findShortCodesRegex;

View file

@ -3,8 +3,6 @@
#include "messages/image.hpp" #include "messages/image.hpp"
#include "util/concurrentmap.hpp" #include "util/concurrentmap.hpp"
#include <cassert>
namespace chatterino { namespace chatterino {
namespace util { namespace util {