mirror-chatterino2/src/widgets/chatwidget.hpp
Rasmus Karlsson 59d383c161 Huge refactor
- Remove some underscore-prefixes
 - Start using this-> more
 - Remove a few of the singletons (We pass references to managers to
         things that need it now. Might not be much better, but for now
         it works. It also shows what places might be slightly wrong
         designed)
2017-06-13 21:27:26 +02:00

108 lines
2.9 KiB
C++

#pragma once
#include "channel.hpp"
#include "messages/limitedqueuesnapshot.hpp"
#include "messages/messageref.hpp"
#include "messages/word.hpp"
#include "messages/wordpart.hpp"
#include "widgets/chatwidgetheader.hpp"
#include "widgets/chatwidgetinput.hpp"
#include "widgets/chatwidgetview.hpp"
#include <QFont>
#include <QShortcut>
#include <QVBoxLayout>
#include <QWidget>
#include <boost/property_tree/ptree.hpp>
#include <boost/signals2/connection.hpp>
namespace chatterino {
class ChannelManager;
namespace widgets {
// Each ChatWidget consists of three sub-elements that handle their own part of the chat widget:
// ChatWidgetHeader
// - Responsible for rendering which channel the ChatWidget is in, and the menu in the top-left of
// the chat widget
// ChatWidgetView
// - Responsible for rendering all chat messages, and the scrollbar
// ChatWidgetInput
// - Responsible for rendering and handling user text input
//
// Each sub-element has a reference to the parent Chat Widget
class ChatWidget : public QWidget
{
Q_OBJECT
public:
ChatWidget(ChannelManager &_channelManager, QWidget *parent = nullptr);
~ChatWidget();
std::shared_ptr<Channel> getChannel() const;
std::shared_ptr<Channel> &getChannelRef();
const QString &getChannelName() const;
void setChannelName(const QString &name);
void showChangeChannelPopup();
messages::LimitedQueueSnapshot<messages::SharedMessageRef> getMessagesSnapshot();
void layoutMessages();
void updateGifEmotes();
void giveFocus();
protected:
void paintEvent(QPaintEvent *) override;
private:
ChannelManager &channelManager;
void setChannel(std::shared_ptr<Channel> newChannel);
void detachChannel();
messages::LimitedQueue<messages::SharedMessageRef> messages;
std::shared_ptr<Channel> channel;
QString channelName;
QVBoxLayout vbox;
ChatWidgetHeader header;
ChatWidgetView view;
ChatWidgetInput input;
boost::signals2::connection messageAppendedConnection;
boost::signals2::connection messageRemovedConnection;
public:
void load(const boost::property_tree::ptree &tree);
boost::property_tree::ptree save();
public slots:
// Add new split to the notebook page that this chat widget is in
// Maybe we should use this chat widget as a hint to where the new split should be created
void doAddSplit();
// Close current split (chat widget)
void doCloseSplit();
// Show a dialog for changing the current splits/chat widgets channel
void doChangeChannel();
// Open popup copy of this chat widget
// XXX: maybe make current chatwidget a popup instead?
void doPopup();
// Clear chat from all messages
void doClearChat();
// Open link to twitch channel in default browser
void doOpenChannel();
// Open popup player of twitch channel in default browser
void doOpenPopupPlayer();
};
} // namespace widgets
} // namespace chatterino