2017-06-06 17:18:23 +02:00
|
|
|
#pragma once
|
2017-01-01 02:30:42 +01:00
|
|
|
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "Channel.hpp"
|
|
|
|
#include "messages/Image.hpp"
|
|
|
|
#include "messages/layouts/MessageLayout.hpp"
|
|
|
|
#include "messages/LimitedQueueSnapshot.hpp"
|
|
|
|
#include "messages/MessageElement.hpp"
|
|
|
|
#include "messages/Selection.hpp"
|
|
|
|
#include "widgets/BaseWidget.hpp"
|
|
|
|
#include "widgets/helper/RippleEffectLabel.hpp"
|
|
|
|
#include "widgets/Scrollbar.hpp"
|
2017-01-01 02:30:42 +01:00
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
#include <QPaintEvent>
|
2017-01-26 04:26:40 +01:00
|
|
|
#include <QScroller>
|
2017-10-11 10:34:04 +02:00
|
|
|
#include <QTimer>
|
2017-01-26 04:26:40 +01:00
|
|
|
#include <QWheelEvent>
|
2017-01-18 04:33:30 +01:00
|
|
|
#include <QWidget>
|
2017-12-26 12:32:24 +01:00
|
|
|
#include <pajlada/signals/signal.hpp>
|
2018-04-03 02:55:32 +02:00
|
|
|
|
2017-12-26 18:24:02 +01:00
|
|
|
#include <unordered_set>
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2017-01-18 21:30:23 +01:00
|
|
|
namespace chatterino {
|
|
|
|
namespace widgets {
|
2017-06-11 11:36:42 +02:00
|
|
|
|
2017-09-16 00:05:06 +02:00
|
|
|
class ChannelView : public BaseWidget
|
2017-01-01 02:30:42 +01:00
|
|
|
{
|
2017-09-16 00:05:06 +02:00
|
|
|
Q_OBJECT
|
2017-09-12 19:06:16 +02:00
|
|
|
|
2017-01-01 02:30:42 +01:00
|
|
|
public:
|
2018-04-03 02:55:32 +02:00
|
|
|
explicit ChannelView(BaseWidget *parent = nullptr);
|
2018-06-13 13:27:10 +02:00
|
|
|
virtual ~ChannelView() override;
|
2017-01-16 03:15:07 +01:00
|
|
|
|
2017-10-11 10:34:04 +02:00
|
|
|
void queueUpdate();
|
2018-01-06 03:48:56 +01:00
|
|
|
Scrollbar &getScrollBar();
|
2017-09-16 00:05:06 +02:00
|
|
|
QString getSelectedText();
|
2017-09-21 02:20:02 +02:00
|
|
|
bool hasSelection();
|
|
|
|
void clearSelection();
|
2017-12-28 00:48:21 +01:00
|
|
|
void setEnableScrollingToBottom(bool);
|
|
|
|
bool getEnableScrollingToBottom() const;
|
2018-01-27 21:13:22 +01:00
|
|
|
void setOverrideFlags(boost::optional<messages::MessageElement::Flags> value);
|
|
|
|
const boost::optional<messages::MessageElement::Flags> &getOverrideFlags() const;
|
2018-01-05 11:22:51 +01:00
|
|
|
void pause(int msecTimeout);
|
2018-01-23 22:48:33 +01:00
|
|
|
void updateLastReadMessage();
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
void setChannel(ChannelPtr channel_);
|
2018-01-11 20:16:25 +01:00
|
|
|
messages::LimitedQueueSnapshot<messages::MessageLayoutPtr> getMessagesSnapshot();
|
2017-10-11 10:34:04 +02:00
|
|
|
void layoutMessages();
|
2017-09-16 00:05:06 +02:00
|
|
|
|
|
|
|
void clearMessages();
|
2017-02-07 00:03:15 +01:00
|
|
|
|
2018-04-03 02:55:32 +02:00
|
|
|
pajlada::Signals::Signal<QMouseEvent *> mouseDown;
|
|
|
|
pajlada::Signals::NoArgSignal selectionChanged;
|
2018-04-10 16:53:40 +02:00
|
|
|
pajlada::Signals::Signal<HighlightState> tabHighlightRequested;
|
2018-01-24 20:58:53 +01:00
|
|
|
pajlada::Signals::Signal<const messages::Link &> linkClicked;
|
2017-09-16 16:49:52 +02:00
|
|
|
|
2017-01-03 21:19:33 +01:00
|
|
|
protected:
|
2018-04-03 02:55:32 +02:00
|
|
|
void themeRefreshEvent() override;
|
2018-01-24 20:35:26 +01:00
|
|
|
|
2018-04-03 02:55:32 +02:00
|
|
|
void resizeEvent(QResizeEvent *) override;
|
2017-01-03 21:19:33 +01:00
|
|
|
|
2018-04-03 02:55:32 +02:00
|
|
|
void paintEvent(QPaintEvent *) override;
|
|
|
|
void wheelEvent(QWheelEvent *event) override;
|
2017-01-26 04:26:40 +01:00
|
|
|
|
2018-04-03 02:55:32 +02:00
|
|
|
void enterEvent(QEvent *) override;
|
|
|
|
void leaveEvent(QEvent *) override;
|
2018-01-05 11:22:51 +01:00
|
|
|
|
2018-04-03 02:55:32 +02:00
|
|
|
void mouseMoveEvent(QMouseEvent *event) override;
|
|
|
|
void mousePressEvent(QMouseEvent *event) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *event) override;
|
|
|
|
void mouseDoubleClickEvent(QMouseEvent *event) override;
|
2018-01-24 21:44:31 +01:00
|
|
|
|
2018-04-18 09:12:29 +02:00
|
|
|
void hideEvent(QHideEvent *) override;
|
|
|
|
|
2018-01-24 21:44:31 +01:00
|
|
|
void handleLinkClick(QMouseEvent *event, const messages::Link &link,
|
|
|
|
messages::MessageLayout *layout);
|
2017-02-17 23:51:35 +01:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
bool tryGetMessageAt(QPoint p, std::shared_ptr<messages::MessageLayout> &message,
|
2017-08-18 15:12:07 +02:00
|
|
|
QPoint &relativePos, int &index);
|
2017-02-17 23:51:35 +01:00
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
private:
|
2018-06-13 13:27:10 +02:00
|
|
|
QTimer *layoutCooldown_;
|
|
|
|
bool layoutQueued_;
|
2018-04-06 18:27:49 +02:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
QTimer updateTimer_;
|
|
|
|
bool updateQueued_ = false;
|
|
|
|
bool messageWasAdded_ = false;
|
|
|
|
bool lastMessageHasAlternateBackground_ = false;
|
2018-05-17 17:27:20 +02:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
bool pausedTemporarily_ = false;
|
|
|
|
bool pausedBySelection_ = false;
|
|
|
|
bool pausedByScrollingUp_ = false;
|
|
|
|
void updatePauseStatus();
|
|
|
|
int messagesAddedSinceSelectionPause_ = 0;
|
2018-05-17 17:27:20 +02:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
QTimer pauseTimeout_;
|
|
|
|
boost::optional<messages::MessageElement::Flags> overrideFlags_;
|
|
|
|
messages::MessageLayoutPtr lastReadMessage_;
|
2018-01-05 11:22:51 +01:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
messages::LimitedQueueSnapshot<messages::MessageLayoutPtr> snapshot_;
|
2017-09-17 02:13:57 +02:00
|
|
|
|
2017-09-16 00:05:06 +02:00
|
|
|
void detachChannel();
|
2018-05-06 16:12:21 +02:00
|
|
|
void actuallyLayoutMessages(bool causedByScollbar = false);
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
void drawMessages(QPainter &painter);
|
2018-01-04 23:50:30 +01:00
|
|
|
void setSelection(const messages::SelectionItem &start, const messages::SelectionItem &end);
|
2018-01-17 16:52:51 +01:00
|
|
|
messages::MessageElement::Flags getFlags() const;
|
2018-05-17 12:16:13 +02:00
|
|
|
bool isPaused();
|
|
|
|
|
2018-06-04 14:39:26 +02:00
|
|
|
void handleMouseClick(QMouseEvent *event,
|
|
|
|
const messages::MessageLayoutElement *hoverLayoutElement,
|
|
|
|
messages::MessageLayout *layout);
|
|
|
|
void addContextMenuItems(const messages::MessageLayoutElement *hoveredElement,
|
|
|
|
messages::MessageLayout *layout);
|
|
|
|
|
2018-05-17 17:27:20 +02:00
|
|
|
// void beginPause();
|
|
|
|
// void endPause();
|
2017-08-18 15:12:07 +02:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
ChannelPtr channel_;
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
Scrollbar scrollBar_;
|
|
|
|
RippleEffectLabel *goToBottom_;
|
2017-02-07 00:03:15 +01:00
|
|
|
|
2017-06-06 17:22:16 +02:00
|
|
|
// This variable can be used to decide whether or not we should render the "Show latest
|
|
|
|
// messages" button
|
2018-06-13 13:27:10 +02:00
|
|
|
bool showingLatestMessages_ = true;
|
|
|
|
bool enableScrollingToBottom_ = true;
|
2017-06-06 17:22:16 +02:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
bool onlyUpdateEmotes_ = false;
|
2017-01-05 16:07:20 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
// Mouse event variables
|
2018-06-13 13:27:10 +02:00
|
|
|
bool isMouseDown_ = false;
|
|
|
|
bool isRightMouseDown_ = false;
|
|
|
|
QPointF lastPressPosition_;
|
|
|
|
QPointF lastRightPressPosition_;
|
2017-01-22 12:46:35 +01:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
messages::Selection selection_;
|
|
|
|
bool selecting_ = false;
|
2017-08-18 15:12:07 +02:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
messages::LimitedQueue<messages::MessageLayoutPtr> messages;
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
pajlada::Signals::Connection messageAppendedConnection_;
|
|
|
|
pajlada::Signals::Connection messageAddedAtStartConnection_;
|
|
|
|
pajlada::Signals::Connection messageRemovedConnection_;
|
|
|
|
pajlada::Signals::Connection messageReplacedConnection_;
|
|
|
|
pajlada::Signals::Connection repaintGifsConnection_;
|
|
|
|
pajlada::Signals::Connection layoutConnection_;
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2018-06-13 03:58:52 +02:00
|
|
|
std::vector<pajlada::Signals::ScopedConnection> connections_;
|
|
|
|
std::vector<pajlada::Signals::ScopedConnection> channelConnections_;
|
2017-12-26 18:24:02 +01:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
std::unordered_set<std::shared_ptr<messages::MessageLayout>> messagesOnScreen_;
|
2017-12-26 18:24:02 +01:00
|
|
|
|
2018-06-13 03:58:52 +02:00
|
|
|
int getLayoutWidth() const;
|
|
|
|
|
2017-01-22 12:46:35 +01:00
|
|
|
private slots:
|
2018-01-17 17:02:34 +01:00
|
|
|
void wordFlagsChanged()
|
2017-01-22 12:46:35 +01:00
|
|
|
{
|
2017-02-17 23:51:35 +01:00
|
|
|
layoutMessages();
|
2017-02-07 00:03:15 +01:00
|
|
|
update();
|
2017-01-22 12:46:35 +01:00
|
|
|
}
|
2017-01-01 02:30:42 +01:00
|
|
|
};
|
2017-06-06 17:18:23 +02:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
} // namespace widgets
|
|
|
|
} // namespace chatterino
|