ChatWidgetView -> ChannelView, added Emote Picker
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#include "widgets/chatwidgetview.hpp"
|
||||
#include "widgets/channelview.hpp"
|
||||
#include "channelmanager.hpp"
|
||||
#include "colorscheme.hpp"
|
||||
#include "messages/limitedqueuesnapshot.hpp"
|
||||
@@ -20,14 +20,15 @@
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
using namespace chatterino::messages;
|
||||
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
ChatWidgetView::ChatWidgetView(ChatWidget *_chatWidget)
|
||||
: BaseWidget(_chatWidget)
|
||||
, chatWidget(_chatWidget)
|
||||
ChannelView::ChannelView(BaseWidget *parent)
|
||||
: BaseWidget(parent)
|
||||
, scrollBar(this)
|
||||
, userPopupWidget(_chatWidget->getChannelRef())
|
||||
, userPopupWidget(std::shared_ptr<Channel>())
|
||||
{
|
||||
#ifndef Q_OS_MAC
|
||||
// this->setAttribute(Qt::WA_OpaquePaintEvent);
|
||||
@@ -35,7 +36,7 @@ ChatWidgetView::ChatWidgetView(ChatWidget *_chatWidget)
|
||||
this->setMouseTracking(true);
|
||||
|
||||
QObject::connect(&SettingsManager::getInstance(), &SettingsManager::wordTypeMaskChanged, this,
|
||||
&ChatWidgetView::wordTypeMaskChanged);
|
||||
&ChannelView::wordTypeMaskChanged);
|
||||
|
||||
this->scrollBar.getCurrentValueChanged().connect([this] {
|
||||
// Whenever the scrollbar value has been changed, re-render the ChatWidgetView
|
||||
@@ -45,15 +46,15 @@ ChatWidgetView::ChatWidgetView(ChatWidget *_chatWidget)
|
||||
});
|
||||
}
|
||||
|
||||
ChatWidgetView::~ChatWidgetView()
|
||||
ChannelView::~ChannelView()
|
||||
{
|
||||
QObject::disconnect(&SettingsManager::getInstance(), &SettingsManager::wordTypeMaskChanged,
|
||||
this, &ChatWidgetView::wordTypeMaskChanged);
|
||||
this, &ChannelView::wordTypeMaskChanged);
|
||||
}
|
||||
|
||||
bool ChatWidgetView::layoutMessages()
|
||||
bool ChannelView::layoutMessages()
|
||||
{
|
||||
auto messages = this->chatWidget->getMessagesSnapshot();
|
||||
auto messages = this->getMessagesSnapshot();
|
||||
|
||||
if (messages.getLength() == 0) {
|
||||
this->scrollBar.setVisible(false);
|
||||
@@ -130,21 +131,30 @@ bool ChatWidgetView::layoutMessages()
|
||||
return redraw;
|
||||
}
|
||||
|
||||
void ChatWidgetView::updateGifEmotes()
|
||||
void ChannelView::clearMessages()
|
||||
{
|
||||
// Clear all stored messages in this chat widget
|
||||
this->messages.clear();
|
||||
|
||||
// Layout chat widget messages, and force an update regardless if there are no messages
|
||||
this->layoutMessages();
|
||||
this->update();
|
||||
}
|
||||
|
||||
void ChannelView::updateGifEmotes()
|
||||
{
|
||||
this->onlyUpdateEmotes = true;
|
||||
this->update();
|
||||
}
|
||||
|
||||
ScrollBar &ChatWidgetView::getScrollBar()
|
||||
ScrollBar &ChannelView::getScrollBar()
|
||||
{
|
||||
return this->scrollBar;
|
||||
}
|
||||
|
||||
QString ChatWidgetView::getSelectedText() const
|
||||
QString ChannelView::getSelectedText()
|
||||
{
|
||||
messages::LimitedQueueSnapshot<messages::SharedMessageRef> messages =
|
||||
this->chatWidget->getMessagesSnapshot();
|
||||
LimitedQueueSnapshot<SharedMessageRef> messages = this->getMessagesSnapshot();
|
||||
|
||||
QString text;
|
||||
bool isSingleMessage = this->selection.isSingleMessage();
|
||||
@@ -232,7 +242,72 @@ QString ChatWidgetView::getSelectedText() const
|
||||
return text;
|
||||
}
|
||||
|
||||
void ChatWidgetView::resizeEvent(QResizeEvent *)
|
||||
messages::LimitedQueueSnapshot<SharedMessageRef> ChannelView::getMessagesSnapshot()
|
||||
{
|
||||
return this->messages.getSnapshot();
|
||||
}
|
||||
|
||||
void ChannelView::setChannel(std::shared_ptr<Channel> channel)
|
||||
{
|
||||
if (this->channel) {
|
||||
this->detachChannel();
|
||||
}
|
||||
this->messages.clear();
|
||||
|
||||
// on new message
|
||||
this->messageAppendedConnection =
|
||||
channel->messageAppended.connect([this](SharedMessage &message) {
|
||||
SharedMessageRef deleted;
|
||||
|
||||
auto messageRef = new MessageRef(message);
|
||||
|
||||
if (this->messages.appendItem(SharedMessageRef(messageRef), deleted)) {
|
||||
qreal value = std::max(0.0, this->getScrollBar().getDesiredValue() - 1);
|
||||
|
||||
this->getScrollBar().setDesiredValue(value, false);
|
||||
}
|
||||
|
||||
layoutMessages();
|
||||
update();
|
||||
});
|
||||
|
||||
// on message removed
|
||||
this->messageRemovedConnection =
|
||||
channel->messageRemovedFromStart.connect([this](SharedMessage &) {
|
||||
this->selection.min.messageIndex--;
|
||||
this->selection.max.messageIndex--;
|
||||
this->selection.start.messageIndex--;
|
||||
this->selection.end.messageIndex--;
|
||||
|
||||
layoutMessages();
|
||||
update();
|
||||
});
|
||||
|
||||
auto snapshot = channel->getMessageSnapshot();
|
||||
|
||||
for (size_t i = 0; i < snapshot.getLength(); i++) {
|
||||
SharedMessageRef deleted;
|
||||
|
||||
auto messageRef = new MessageRef(snapshot[i]);
|
||||
|
||||
this->messages.appendItem(SharedMessageRef(messageRef), deleted);
|
||||
}
|
||||
|
||||
this->channel = channel;
|
||||
|
||||
this->userPopupWidget.setChannel(channel);
|
||||
}
|
||||
|
||||
void ChannelView::detachChannel()
|
||||
{
|
||||
// on message added
|
||||
this->messageAppendedConnection.disconnect();
|
||||
|
||||
// on message removed
|
||||
this->messageRemovedConnection.disconnect();
|
||||
}
|
||||
|
||||
void ChannelView::resizeEvent(QResizeEvent *)
|
||||
{
|
||||
this->scrollBar.resize(this->scrollBar.width(), height());
|
||||
this->scrollBar.move(width() - this->scrollBar.width(), 0);
|
||||
@@ -242,7 +317,7 @@ void ChatWidgetView::resizeEvent(QResizeEvent *)
|
||||
this->update();
|
||||
}
|
||||
|
||||
void ChatWidgetView::setSelection(const SelectionItem &start, const SelectionItem &end)
|
||||
void ChannelView::setSelection(const SelectionItem &start, const SelectionItem &end)
|
||||
{
|
||||
// selections
|
||||
this->selection = Selection(start, end);
|
||||
@@ -251,7 +326,7 @@ void ChatWidgetView::setSelection(const SelectionItem &start, const SelectionIte
|
||||
// << max.charIndex;
|
||||
}
|
||||
|
||||
void ChatWidgetView::paintEvent(QPaintEvent * /*event*/)
|
||||
void ChannelView::paintEvent(QPaintEvent * /*event*/)
|
||||
{
|
||||
QPainter painter(this);
|
||||
|
||||
@@ -288,9 +363,9 @@ void ChatWidgetView::paintEvent(QPaintEvent * /*event*/)
|
||||
}
|
||||
}
|
||||
|
||||
void ChatWidgetView::drawMessages(QPainter &painter)
|
||||
void ChannelView::drawMessages(QPainter &painter)
|
||||
{
|
||||
auto messages = this->chatWidget->getMessagesSnapshot();
|
||||
auto messages = this->getMessagesSnapshot();
|
||||
|
||||
size_t start = this->scrollBar.getCurrentValue();
|
||||
|
||||
@@ -341,7 +416,9 @@ void ChatWidgetView::drawMessages(QPainter &painter)
|
||||
|
||||
messageRef->buffer = bufferPtr;
|
||||
|
||||
// if (buffer != nullptr) {
|
||||
painter.drawPixmap(0, y, *buffer);
|
||||
// }
|
||||
|
||||
y += messageRef->getHeight();
|
||||
|
||||
@@ -351,8 +428,8 @@ void ChatWidgetView::drawMessages(QPainter &painter)
|
||||
}
|
||||
}
|
||||
|
||||
void ChatWidgetView::updateMessageBuffer(messages::MessageRef *messageRef, QPixmap *buffer,
|
||||
int messageIndex)
|
||||
void ChannelView::updateMessageBuffer(messages::MessageRef *messageRef, QPixmap *buffer,
|
||||
int messageIndex)
|
||||
{
|
||||
QPainter painter(buffer);
|
||||
|
||||
@@ -403,8 +480,8 @@ void ChatWidgetView::updateMessageBuffer(messages::MessageRef *messageRef, QPixm
|
||||
messageRef->updateBuffer = false;
|
||||
}
|
||||
|
||||
void ChatWidgetView::drawMessageSelection(QPainter &painter, messages::MessageRef *messageRef,
|
||||
int messageIndex, int bufferHeight)
|
||||
void ChannelView::drawMessageSelection(QPainter &painter, messages::MessageRef *messageRef,
|
||||
int messageIndex, int bufferHeight)
|
||||
{
|
||||
if (this->selection.min.messageIndex > messageIndex ||
|
||||
this->selection.max.messageIndex < messageIndex) {
|
||||
@@ -552,7 +629,7 @@ void ChatWidgetView::drawMessageSelection(QPainter &painter, messages::MessageRe
|
||||
painter.fillRect(rect, selectionColor);
|
||||
}
|
||||
|
||||
void ChatWidgetView::wheelEvent(QWheelEvent *event)
|
||||
void ChannelView::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
if (this->scrollBar.isVisible()) {
|
||||
auto mouseMultiplier = SettingsManager::getInstance().mouseScrollMultiplier.get();
|
||||
@@ -562,7 +639,7 @@ void ChatWidgetView::wheelEvent(QWheelEvent *event)
|
||||
}
|
||||
}
|
||||
|
||||
void ChatWidgetView::mouseMoveEvent(QMouseEvent *event)
|
||||
void ChannelView::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
std::shared_ptr<messages::MessageRef> message;
|
||||
QPoint relativePos;
|
||||
@@ -594,10 +671,8 @@ void ChatWidgetView::mouseMoveEvent(QMouseEvent *event)
|
||||
}
|
||||
}
|
||||
|
||||
void ChatWidgetView::mousePressEvent(QMouseEvent *event)
|
||||
void ChannelView::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
this->chatWidget->giveFocus(Qt::MouseFocusReason);
|
||||
|
||||
this->isMouseDown = true;
|
||||
|
||||
this->lastPressPosition = event->screenPos();
|
||||
@@ -621,7 +696,7 @@ void ChatWidgetView::mousePressEvent(QMouseEvent *event)
|
||||
this->repaint();
|
||||
}
|
||||
|
||||
void ChatWidgetView::mouseReleaseEvent(QMouseEvent *event)
|
||||
void ChannelView::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if (!this->isMouseDown) {
|
||||
// We didn't grab the mouse press, so we shouldn't be handling the mouse
|
||||
@@ -682,10 +757,10 @@ void ChatWidgetView::mouseReleaseEvent(QMouseEvent *event)
|
||||
}
|
||||
}
|
||||
|
||||
bool ChatWidgetView::tryGetMessageAt(QPoint p, std::shared_ptr<messages::MessageRef> &_message,
|
||||
QPoint &relativePos, int &index)
|
||||
bool ChannelView::tryGetMessageAt(QPoint p, std::shared_ptr<messages::MessageRef> &_message,
|
||||
QPoint &relativePos, int &index)
|
||||
{
|
||||
auto messages = this->chatWidget->getMessagesSnapshot();
|
||||
auto messages = this->getMessagesSnapshot();
|
||||
|
||||
size_t start = this->scrollBar.getCurrentValue();
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "channel.hpp"
|
||||
#include "messages/lazyloadedimage.hpp"
|
||||
#include "messages/limitedqueuesnapshot.hpp"
|
||||
#include "messages/messageref.hpp"
|
||||
#include "messages/word.hpp"
|
||||
#include "widgets/accountpopup.hpp"
|
||||
@@ -13,6 +14,8 @@
|
||||
#include <QWheelEvent>
|
||||
#include <QWidget>
|
||||
|
||||
#include <boost/signals2.hpp>
|
||||
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
@@ -75,21 +78,23 @@ struct Selection {
|
||||
}
|
||||
};
|
||||
|
||||
class ChatWidget;
|
||||
|
||||
class ChatWidgetView : public BaseWidget
|
||||
class ChannelView : public BaseWidget
|
||||
{
|
||||
friend class ChatWidget;
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ChatWidgetView(ChatWidget *_chatWidget);
|
||||
~ChatWidgetView();
|
||||
|
||||
bool layoutMessages();
|
||||
explicit ChannelView(BaseWidget *parent = 0);
|
||||
~ChannelView();
|
||||
|
||||
void updateGifEmotes();
|
||||
ScrollBar &getScrollBar();
|
||||
QString getSelectedText() const;
|
||||
QString getSelectedText();
|
||||
|
||||
void setChannel(std::shared_ptr<Channel> channel);
|
||||
messages::LimitedQueueSnapshot<messages::SharedMessageRef> getMessagesSnapshot();
|
||||
bool layoutMessages();
|
||||
|
||||
void clearMessages();
|
||||
|
||||
protected:
|
||||
virtual void resizeEvent(QResizeEvent *) override;
|
||||
@@ -110,15 +115,17 @@ private:
|
||||
QRect rect;
|
||||
};
|
||||
|
||||
void detachChannel();
|
||||
|
||||
void drawMessages(QPainter &painter);
|
||||
void updateMessageBuffer(messages::MessageRef *messageRef, QPixmap *buffer, int messageIndex);
|
||||
void drawMessageSelection(QPainter &painter, messages::MessageRef *messageRef, int messageIndex,
|
||||
int bufferHeight);
|
||||
void setSelection(const SelectionItem &start, const SelectionItem &end);
|
||||
|
||||
std::vector<GifEmoteData> gifEmotes;
|
||||
std::shared_ptr<Channel> channel;
|
||||
|
||||
ChatWidget *const chatWidget;
|
||||
std::vector<GifEmoteData> gifEmotes;
|
||||
|
||||
ScrollBar scrollBar;
|
||||
|
||||
@@ -136,6 +143,11 @@ private:
|
||||
Selection selection;
|
||||
bool selecting = false;
|
||||
|
||||
messages::LimitedQueue<messages::SharedMessageRef> messages;
|
||||
|
||||
boost::signals2::connection messageAppendedConnection;
|
||||
boost::signals2::connection messageRemovedConnection;
|
||||
|
||||
private slots:
|
||||
void wordTypeMaskChanged()
|
||||
{
|
||||
+23
-68
@@ -18,6 +18,7 @@
|
||||
#include <QPainter>
|
||||
#include <QProcess>
|
||||
#include <QShortcut>
|
||||
#include <QTimer>
|
||||
#include <QVBoxLayout>
|
||||
#include <boost/signals2.hpp>
|
||||
|
||||
@@ -52,7 +53,7 @@ ChatWidget::ChatWidget(ChannelManager &_channelManager, NotebookPage *parent)
|
||||
, vbox(this)
|
||||
, header(this)
|
||||
, view(this)
|
||||
, input(this)
|
||||
, input(this, _channelManager.getEmoteManager())
|
||||
{
|
||||
this->vbox.setSpacing(0);
|
||||
this->vbox.setMargin(1);
|
||||
@@ -80,11 +81,15 @@ ChatWidget::ChatWidget(ChannelManager &_channelManager, NotebookPage *parent)
|
||||
this->channelNameUpdated(this->channelName.getValue());
|
||||
|
||||
this->input.textInput.installEventFilter(parent);
|
||||
|
||||
connect(&view, &this->view.mousePressEvent, this, [&](QMouseEvent *) {
|
||||
QTimer::singleShot(10, [this] { this->giveFocus(Qt::MouseFocusReason); });
|
||||
});
|
||||
}
|
||||
|
||||
ChatWidget::~ChatWidget()
|
||||
{
|
||||
this->detachChannel();
|
||||
channelNameUpdated("");
|
||||
}
|
||||
|
||||
std::shared_ptr<Channel> ChatWidget::getChannel() const
|
||||
@@ -99,82 +104,33 @@ std::shared_ptr<Channel> &ChatWidget::getChannelRef()
|
||||
|
||||
void ChatWidget::setChannel(std::shared_ptr<Channel> _newChannel)
|
||||
{
|
||||
this->view.setChannel(_newChannel);
|
||||
|
||||
this->channel = _newChannel;
|
||||
this->channel->roomIDchanged.connect([this]() { this->header.checkLive(); });
|
||||
|
||||
this->view.userPopupWidget.setChannel(_newChannel);
|
||||
|
||||
// on new message
|
||||
this->messageAppendedConnection =
|
||||
this->channel->messageAppended.connect([this](SharedMessage &message) {
|
||||
SharedMessageRef deleted;
|
||||
|
||||
auto messageRef = new MessageRef(message);
|
||||
|
||||
if (this->messages.appendItem(SharedMessageRef(messageRef), deleted)) {
|
||||
qreal value = std::max(0.0, this->view.getScrollBar().getDesiredValue() - 1);
|
||||
|
||||
this->view.getScrollBar().setDesiredValue(value, false);
|
||||
}
|
||||
});
|
||||
|
||||
// on message removed
|
||||
this->messageRemovedConnection =
|
||||
this->channel->messageRemovedFromStart.connect([this](SharedMessage &) {
|
||||
this->view.selection.min.messageIndex--;
|
||||
this->view.selection.max.messageIndex--;
|
||||
this->view.selection.start.messageIndex--;
|
||||
this->view.selection.end.messageIndex--;
|
||||
});
|
||||
|
||||
auto snapshot = this->channel->getMessageSnapshot();
|
||||
|
||||
for (size_t i = 0; i < snapshot.getLength(); i++) {
|
||||
SharedMessageRef deleted;
|
||||
|
||||
auto messageRef = new MessageRef(snapshot[i]);
|
||||
|
||||
this->messages.appendItem(SharedMessageRef(messageRef), deleted);
|
||||
twitch::TwitchChannel *twitchChannel = dynamic_cast<twitch::TwitchChannel *>(_newChannel.get());
|
||||
if (twitchChannel != nullptr) {
|
||||
twitchChannel->roomIDchanged.connect([this]() { this->header.checkLive(); });
|
||||
}
|
||||
}
|
||||
|
||||
void ChatWidget::detachChannel()
|
||||
{
|
||||
// on message added
|
||||
this->messageAppendedConnection.disconnect();
|
||||
|
||||
// on message removed
|
||||
this->messageRemovedConnection.disconnect();
|
||||
}
|
||||
|
||||
void ChatWidget::channelNameUpdated(const std::string &newChannelName)
|
||||
{
|
||||
// remove current channel
|
||||
if (!this->channel->isEmpty()) {
|
||||
this->channelManager.removeChannel(this->channel->name);
|
||||
|
||||
this->detachChannel();
|
||||
this->channelManager.removeTwitchChannel(this->channel->name);
|
||||
}
|
||||
|
||||
// update messages
|
||||
this->messages.clear();
|
||||
|
||||
if (newChannelName.empty()) {
|
||||
this->channel = this->channelManager.emptyChannel;
|
||||
this->setChannel(this->channelManager.emptyChannel);
|
||||
} else {
|
||||
this->setChannel(this->channelManager.addChannel(QString::fromStdString(newChannelName)));
|
||||
this->setChannel(
|
||||
this->channelManager.addTwitchChannel(QString::fromStdString(newChannelName)));
|
||||
}
|
||||
|
||||
// update header
|
||||
this->header.updateChannelText();
|
||||
|
||||
// update view
|
||||
this->layoutMessages(true);
|
||||
}
|
||||
|
||||
LimitedQueueSnapshot<SharedMessageRef> ChatWidget::getMessagesSnapshot()
|
||||
{
|
||||
return this->messages.getSnapshot();
|
||||
}
|
||||
|
||||
bool ChatWidget::showChangeChannelPopup(const char *dialogTitle, bool empty)
|
||||
@@ -202,9 +158,12 @@ bool ChatWidget::showChangeChannelPopup(const char *dialogTitle, bool empty)
|
||||
|
||||
void ChatWidget::layoutMessages(bool forceUpdate)
|
||||
{
|
||||
if (this->view.layoutMessages() || forceUpdate) {
|
||||
this->view.update();
|
||||
}
|
||||
this->view.layoutMessages();
|
||||
this->view.update();
|
||||
|
||||
// if (this->view.layoutMessages() || forceUpdate) {
|
||||
// this->view.update();
|
||||
// }
|
||||
}
|
||||
|
||||
void ChatWidget::updateGifEmotes()
|
||||
@@ -285,11 +244,7 @@ void ChatWidget::doPopup()
|
||||
|
||||
void ChatWidget::doClearChat()
|
||||
{
|
||||
// Clear all stored messages in this chat widget
|
||||
this->messages.clear();
|
||||
|
||||
// Layout chat widget messages, and force an update regardless if there are no messages
|
||||
this->layoutMessages(true);
|
||||
view.clearMessages();
|
||||
}
|
||||
|
||||
void ChatWidget::doOpenChannel()
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
#include "messages/word.hpp"
|
||||
#include "messages/wordpart.hpp"
|
||||
#include "widgets/basewidget.hpp"
|
||||
#include "widgets/channelview.hpp"
|
||||
#include "widgets/chatwidgetheader.hpp"
|
||||
#include "widgets/chatwidgetinput.hpp"
|
||||
#include "widgets/chatwidgetview.hpp"
|
||||
|
||||
#include <QFont>
|
||||
#include <QShortcut>
|
||||
@@ -49,13 +49,13 @@ public:
|
||||
std::shared_ptr<Channel> &getChannelRef();
|
||||
|
||||
bool showChangeChannelPopup(const char *dialogTitle, bool empty = false);
|
||||
messages::LimitedQueueSnapshot<messages::SharedMessageRef> getMessagesSnapshot();
|
||||
void layoutMessages(bool forceUpdate = false);
|
||||
void updateGifEmotes();
|
||||
|
||||
void giveFocus(Qt::FocusReason reason);
|
||||
bool hasFocus() const;
|
||||
|
||||
void layoutMessages(bool forceUpdate = false);
|
||||
void updateGifEmotes();
|
||||
|
||||
protected:
|
||||
virtual void paintEvent(QPaintEvent *) override;
|
||||
|
||||
@@ -67,24 +67,20 @@ public:
|
||||
|
||||
private:
|
||||
void setChannel(std::shared_ptr<Channel> newChannel);
|
||||
void detachChannel();
|
||||
void doOpenAccountPopupWidget(AccountPopupWidget *widget, QString user);
|
||||
|
||||
void channelNameUpdated(const std::string &newChannelName);
|
||||
|
||||
NotebookPage &parentPage;
|
||||
|
||||
messages::LimitedQueue<messages::SharedMessageRef> messages;
|
||||
|
||||
std::shared_ptr<Channel> channel;
|
||||
|
||||
QVBoxLayout vbox;
|
||||
ChatWidgetHeader header;
|
||||
ChatWidgetView view;
|
||||
ChannelView view;
|
||||
ChatWidgetInput input;
|
||||
|
||||
boost::signals2::connection messageAppendedConnection;
|
||||
boost::signals2::connection messageRemovedConnection;
|
||||
boost::signals2::connection channelIDChangedConnection;
|
||||
|
||||
public:
|
||||
void load(const boost::property_tree::ptree &tree);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "widgets/chatwidgetheader.hpp"
|
||||
#include "colorscheme.hpp"
|
||||
#include "twitch/twitchchannel.hpp"
|
||||
#include "util/urlfetch.hpp"
|
||||
#include "widgets/chatwidget.hpp"
|
||||
#include "widgets/notebookpage.hpp"
|
||||
@@ -81,16 +82,22 @@ void ChatWidgetHeader::updateChannelText()
|
||||
if (channelName.empty()) {
|
||||
this->channelNameLabel.setText("<no channel>");
|
||||
} else {
|
||||
if (this->chatWidget->getChannelRef()->isLive) {
|
||||
auto channel = this->chatWidget->getChannelRef();
|
||||
auto channel = this->chatWidget->getChannel();
|
||||
|
||||
twitch::TwitchChannel *twitchChannel = dynamic_cast<twitch::TwitchChannel *>(channel.get());
|
||||
|
||||
if (channel->isEmpty()) {
|
||||
this->channelNameLabel.setText(QString::fromStdString(channelName) + " (live)");
|
||||
this->setToolTip(
|
||||
"<style>.center { text-align: center; }</style>"
|
||||
"<p class = \"center\">" +
|
||||
channel->streamStatus + "<br><br>" + channel->streamGame + "<br>"
|
||||
"Live for " +
|
||||
channel->streamUptime + " with " + channel->streamViewerCount + " viewers"
|
||||
"</p>");
|
||||
if (twitchChannel != nullptr) {
|
||||
this->setToolTip("<style>.center { text-align: center; }</style>"
|
||||
"<p class = \"center\">" +
|
||||
twitchChannel->streamStatus + "<br><br>" +
|
||||
twitchChannel->streamGame + "<br>"
|
||||
"Live for " +
|
||||
twitchChannel->streamUptime + " with " +
|
||||
twitchChannel->streamViewerCount + " viewers"
|
||||
"</p>");
|
||||
}
|
||||
} else {
|
||||
this->channelNameLabel.setText(QString::fromStdString(channelName));
|
||||
this->setToolTip("");
|
||||
@@ -157,7 +164,7 @@ void ChatWidgetHeader::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
|
||||
void ChatWidgetHeader::leftButtonClicked()
|
||||
{
|
||||
QTimer::singleShot(100, [&] {
|
||||
QTimer::singleShot(80, [&] {
|
||||
this->leftMenu.move(this->leftLabel.mapToGlobal(QPoint(0, this->leftLabel.height())));
|
||||
this->leftMenu.show();
|
||||
});
|
||||
@@ -193,10 +200,18 @@ void ChatWidgetHeader::menuShowChangelog()
|
||||
{
|
||||
}
|
||||
|
||||
// TODO: this needs to be moved out of here
|
||||
void ChatWidgetHeader::checkLive()
|
||||
{
|
||||
auto channel = this->chatWidget->getChannelRef();
|
||||
twitch::TwitchChannel *channel =
|
||||
dynamic_cast<twitch::TwitchChannel *>(this->chatWidget->getChannel().get());
|
||||
|
||||
if (channel == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto id = QString::fromStdString(channel->roomID);
|
||||
|
||||
util::twitch::get("https://api.twitch.tv/kraken/streams/" + id, [=](QJsonObject obj) {
|
||||
if (obj.value("stream").isNull()) {
|
||||
channel->isLive = false;
|
||||
|
||||
@@ -23,12 +23,12 @@ ChatWidgetHeaderButton::ChatWidgetHeaderButton(BaseWidget *parent, int spacing)
|
||||
this->setMouseEffectColor(QColor(255, 255, 255, 63));
|
||||
}
|
||||
|
||||
void ChatWidgetHeaderButton::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
// void ChatWidgetHeaderButton::paintEvent(QPaintEvent *)
|
||||
//{
|
||||
// QPainter painter(this);
|
||||
|
||||
this->fancyPaint(painter);
|
||||
}
|
||||
// this->fancyPaint(painter);
|
||||
//}
|
||||
|
||||
} // namespace widgets
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -28,7 +28,7 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void paintEvent(QPaintEvent *) override;
|
||||
// virtual void paintEvent(QPaintEvent *) override;
|
||||
|
||||
private:
|
||||
struct {
|
||||
|
||||
@@ -13,9 +13,10 @@
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
ChatWidgetInput::ChatWidgetInput(ChatWidget *_chatWidget)
|
||||
ChatWidgetInput::ChatWidgetInput(ChatWidget *_chatWidget, EmoteManager &emoteManager)
|
||||
: BaseWidget(_chatWidget)
|
||||
, chatWidget(_chatWidget)
|
||||
, emoteManager(emoteManager)
|
||||
, emotesLabel(this)
|
||||
{
|
||||
this->setMaximumHeight(150);
|
||||
@@ -46,10 +47,12 @@ ChatWidgetInput::ChatWidgetInput(ChatWidget *_chatWidget)
|
||||
|
||||
connect(&this->emotesLabel, &ChatWidgetHeaderButton::clicked, [this] {
|
||||
if (this->emotePopup == nullptr) {
|
||||
this->emotePopup = new EmotePopup();
|
||||
this->emotePopup = new EmotePopup(this->colorScheme, this->emoteManager);
|
||||
}
|
||||
|
||||
this->emotePopup->show(); //
|
||||
this->emotePopup->resize(300, 500);
|
||||
this->emotePopup->loadChannel(this->chatWidget->getChannel());
|
||||
this->emotePopup->show();
|
||||
});
|
||||
|
||||
connect(&textInput, &ResizingTextEdit::textChanged, this, &ChatWidgetInput::editTextChanged);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "emotemanager.hpp"
|
||||
#include "resizingtextedit.hpp"
|
||||
#include "widgets/basewidget.hpp"
|
||||
#include "widgets/chatwidgetheaderbutton.hpp"
|
||||
@@ -25,7 +26,7 @@ class ChatWidgetInput : public BaseWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ChatWidgetInput(ChatWidget *_chatWidget);
|
||||
ChatWidgetInput(ChatWidget *_chatWidget, EmoteManager &);
|
||||
~ChatWidgetInput();
|
||||
|
||||
protected:
|
||||
@@ -37,6 +38,7 @@ protected:
|
||||
private:
|
||||
ChatWidget *const chatWidget;
|
||||
EmotePopup *emotePopup = nullptr;
|
||||
EmoteManager &emoteManager;
|
||||
|
||||
boost::signals2::connection textLengthVisibleChangedConnection;
|
||||
QHBoxLayout hbox;
|
||||
|
||||
@@ -1,18 +1,70 @@
|
||||
#include "emotepopup.h"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
|
||||
#include "messages/messagebuilder.hpp"
|
||||
#include "twitch/twitchchannel.hpp"
|
||||
|
||||
using namespace chatterino::twitch;
|
||||
using namespace chatterino::messages;
|
||||
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
EmotePopup::EmotePopup(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
EmotePopup::EmotePopup(ColorScheme &colorScheme, EmoteManager &emoteManager)
|
||||
: BaseWidget(colorScheme, 0)
|
||||
, emoteManager(emoteManager)
|
||||
{
|
||||
QHBoxLayout *layout = new QHBoxLayout(this);
|
||||
this->setLayout(layout);
|
||||
layout->setMargin(0);
|
||||
|
||||
view = new ChannelView(this);
|
||||
layout->addWidget(view);
|
||||
}
|
||||
|
||||
void EmotePopup::loadChannel(std::shared_ptr<Channel> channel)
|
||||
void EmotePopup::loadChannel(std::shared_ptr<Channel> _channel)
|
||||
{
|
||||
// channel->bttvChannelEmotes.each([](const QString &key, const EmoteData &value) {
|
||||
TwitchChannel *channel = dynamic_cast<TwitchChannel *>(_channel.get());
|
||||
|
||||
// //
|
||||
// });
|
||||
if (channel == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<Channel> emoteChannel(new Channel);
|
||||
|
||||
auto addEmotes = [&](EmoteMap &map, const QString &title, const QString &emoteDesc) {
|
||||
// TITLE
|
||||
messages::MessageBuilder builder1;
|
||||
|
||||
builder1.appendWord(
|
||||
Word(title, Word::Type::Text, QColor(255, 255, 255), QString(), QString()));
|
||||
|
||||
builder1.getMessage()->centered = true;
|
||||
emoteChannel->addMessage(builder1.getMessage());
|
||||
|
||||
// EMOTES
|
||||
messages::MessageBuilder builder2;
|
||||
builder2.getMessage()->centered = true;
|
||||
|
||||
map.each([&](const QString &key, const EmoteData &value) {
|
||||
builder2.appendWord(Word(value.image, Word::Type::AlwaysShow, key, emoteDesc,
|
||||
Link(Link::Type::InsertText, key)));
|
||||
});
|
||||
|
||||
emoteChannel->addMessage(builder2.getMessage());
|
||||
};
|
||||
|
||||
addEmotes(this->emoteManager.bttvGlobalEmotes, "BetterTTV Global Emotes",
|
||||
"BetterTTV Global Emote");
|
||||
addEmotes(*channel->bttvChannelEmotes.get(), "BetterTTV Channel Emotes",
|
||||
"BetterTTV Channel Emote");
|
||||
addEmotes(this->emoteManager.ffzGlobalEmotes, "FrankerFaceZ Global Emotes",
|
||||
"FrankerFaceZ Global Emote");
|
||||
addEmotes(*channel->ffzChannelEmotes.get(), "FrankerFaceZ Channel Emotes",
|
||||
"FrankerFaceZ Channel Emote");
|
||||
|
||||
view->setChannel(emoteChannel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include "channel.hpp"
|
||||
#include "emotemanager.hpp"
|
||||
#include "widgets/basewidget.hpp"
|
||||
#include "widgets/channelview.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
class EmotePopup : public QWidget
|
||||
class EmotePopup : public BaseWidget
|
||||
{
|
||||
public:
|
||||
explicit EmotePopup(QWidget *parent = 0);
|
||||
explicit EmotePopup(ColorScheme &, EmoteManager &);
|
||||
|
||||
void loadChannel(std::shared_ptr<Channel> channel);
|
||||
|
||||
private:
|
||||
ChannelView *view;
|
||||
EmoteManager &emoteManager;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ void FancyButton::setMouseEffectColor(QColor color)
|
||||
|
||||
void FancyButton::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter;
|
||||
QPainter painter(this);
|
||||
|
||||
this->fancyPaint(painter);
|
||||
}
|
||||
|
||||
@@ -212,7 +212,7 @@ void Notebook::resizeEvent(QResizeEvent *)
|
||||
|
||||
void Notebook::settingsButtonClicked()
|
||||
{
|
||||
QTimer::singleShot(100, [this] { SettingsDialog::showDialog(); });
|
||||
QTimer::singleShot(80, [this] { SettingsDialog::showDialog(); });
|
||||
}
|
||||
|
||||
void Notebook::usersButtonClicked()
|
||||
@@ -221,7 +221,7 @@ void Notebook::usersButtonClicked()
|
||||
|
||||
void Notebook::addPageButtonClicked()
|
||||
{
|
||||
QTimer::singleShot(100, [this] { this->addPage(true); });
|
||||
QTimer::singleShot(80, [this] { this->addPage(true); });
|
||||
}
|
||||
|
||||
void Notebook::load(const boost::property_tree::ptree &tree)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "widgets/scrollbar.hpp"
|
||||
#include "colorscheme.hpp"
|
||||
#include "widgets/chatwidgetview.hpp"
|
||||
#include "widgets/channelview.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QMouseEvent>
|
||||
@@ -11,7 +11,7 @@
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
ScrollBar::ScrollBar(ChatWidgetView *parent)
|
||||
ScrollBar::ScrollBar(ChannelView *parent)
|
||||
: BaseWidget(parent)
|
||||
, _currentValueAnimation(this, "_currentValue")
|
||||
, _highlights(nullptr)
|
||||
|
||||
@@ -14,14 +14,14 @@ class ColorScheme;
|
||||
|
||||
namespace widgets {
|
||||
|
||||
class ChatWidgetView;
|
||||
class ChannelView;
|
||||
|
||||
class ScrollBar : public BaseWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ScrollBar(ChatWidgetView *parent = 0);
|
||||
ScrollBar(ChannelView *parent = 0);
|
||||
~ScrollBar();
|
||||
|
||||
void removeHighlightsWhere(std::function<bool(ScrollBarHighlight &)> func);
|
||||
|
||||
Reference in New Issue
Block a user