2017-06-06 17:18:23 +02:00
|
|
|
#pragma once
|
2017-01-01 02:30:42 +01:00
|
|
|
|
2017-06-11 09:31:45 +02:00
|
|
|
#include "channel.hpp"
|
2018-01-11 20:16:25 +01:00
|
|
|
#include "messages/image.hpp"
|
|
|
|
#include "messages/layouts/messagelayout.hpp"
|
2017-09-16 00:05:06 +02:00
|
|
|
#include "messages/limitedqueuesnapshot.hpp"
|
2018-01-11 20:16:25 +01:00
|
|
|
#include "messages/messageelement.hpp"
|
2018-01-04 23:50:30 +01:00
|
|
|
#include "messages/selection.hpp"
|
2017-06-11 09:31:45 +02:00
|
|
|
#include "widgets/accountpopup.hpp"
|
2017-06-26 16:41:20 +02:00
|
|
|
#include "widgets/basewidget.hpp"
|
2017-11-12 17:21:50 +01:00
|
|
|
#include "widgets/helper/rippleeffectlabel.hpp"
|
2017-06-11 09:31:45 +02:00
|
|
|
#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-09-16 00:05:06 +02:00
|
|
|
#include <boost/signals2.hpp>
|
2017-12-26 12:32:24 +01:00
|
|
|
#include <pajlada/signals/signal.hpp>
|
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:
|
2017-12-17 02:18:13 +01:00
|
|
|
explicit ChannelView(BaseWidget *parent = 0);
|
2017-09-16 00:05:06 +02:00
|
|
|
~ChannelView();
|
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-05 11:22:51 +01:00
|
|
|
void pause(int msecTimeout);
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
void setChannel(SharedChannel channel);
|
|
|
|
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
|
|
|
|
2017-09-16 16:49:52 +02:00
|
|
|
boost::signals2::signal<void(QMouseEvent *)> mouseDown;
|
2017-09-21 02:20:02 +02:00
|
|
|
boost::signals2::signal<void()> selectionChanged;
|
2017-12-26 12:32:24 +01:00
|
|
|
pajlada::Signals::NoArgSignal highlightedMessageReceived;
|
2017-09-16 16:49:52 +02:00
|
|
|
|
2017-01-03 21:19:33 +01:00
|
|
|
protected:
|
2017-06-11 11:36:42 +02:00
|
|
|
virtual void resizeEvent(QResizeEvent *) override;
|
2017-01-03 21:19:33 +01:00
|
|
|
|
2017-06-11 11:36:42 +02:00
|
|
|
virtual void paintEvent(QPaintEvent *) override;
|
|
|
|
virtual void wheelEvent(QWheelEvent *event) override;
|
2017-01-26 04:26:40 +01:00
|
|
|
|
2018-01-05 11:22:51 +01:00
|
|
|
virtual void enterEvent(QEvent *) override;
|
|
|
|
virtual void leaveEvent(QEvent *) override;
|
|
|
|
|
2017-07-02 14:28:37 +02:00
|
|
|
virtual void mouseMoveEvent(QMouseEvent *event) override;
|
|
|
|
virtual void mousePressEvent(QMouseEvent *event) override;
|
|
|
|
virtual void mouseReleaseEvent(QMouseEvent *event) override;
|
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:
|
2017-10-11 10:34:04 +02:00
|
|
|
QTimer updateTimer;
|
|
|
|
bool updateQueued = false;
|
2018-01-05 03:14:46 +01:00
|
|
|
bool messageWasAdded = false;
|
2018-01-05 11:22:51 +01:00
|
|
|
bool paused = false;
|
|
|
|
QTimer pauseTimeout;
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
messages::LimitedQueueSnapshot<messages::MessageLayoutPtr> snapshot;
|
2017-09-17 02:13:57 +02:00
|
|
|
|
2017-09-16 00:05:06 +02:00
|
|
|
void detachChannel();
|
2017-10-11 10:34:04 +02:00
|
|
|
void actuallyLayoutMessages();
|
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);
|
2017-08-18 15:12:07 +02:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
SharedChannel channel;
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-01-06 03:48:56 +01:00
|
|
|
Scrollbar scrollBar;
|
2017-09-21 17:34:41 +02:00
|
|
|
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
|
|
|
|
bool showingLatestMessages = true;
|
2017-12-28 00:48:21 +01:00
|
|
|
bool enableScrollingToBottom = true;
|
2017-06-06 17:22:16 +02:00
|
|
|
|
2017-06-11 11:36:42 +02:00
|
|
|
AccountPopupWidget userPopupWidget;
|
|
|
|
bool onlyUpdateEmotes = false;
|
2017-01-05 16:07:20 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
// Mouse event variables
|
2017-06-11 11:36:42 +02:00
|
|
|
bool isMouseDown = false;
|
|
|
|
QPointF lastPressPosition;
|
2017-01-22 12:46:35 +01:00
|
|
|
|
2018-01-04 23:50:30 +01:00
|
|
|
messages::Selection selection;
|
2017-08-18 15:12:07 +02:00
|
|
|
bool selecting = false;
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
messages::LimitedQueue<messages::MessageLayoutPtr> messages;
|
2017-09-16 00:05:06 +02:00
|
|
|
|
|
|
|
boost::signals2::connection messageAppendedConnection;
|
2018-01-01 22:29:21 +01:00
|
|
|
boost::signals2::connection messageAddedAtStartConnection;
|
2017-09-16 00:05:06 +02:00
|
|
|
boost::signals2::connection messageRemovedConnection;
|
2018-01-05 23:14:55 +01:00
|
|
|
boost::signals2::connection messageReplacedConnection;
|
2017-09-17 02:13:57 +02:00
|
|
|
boost::signals2::connection repaintGifsConnection;
|
2017-09-21 17:34:41 +02:00
|
|
|
boost::signals2::connection layoutConnection;
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2017-12-17 03:37:46 +01:00
|
|
|
std::vector<pajlada::Signals::ScopedConnection> managedConnections;
|
2017-12-26 18:24:02 +01:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
std::unordered_set<std::shared_ptr<messages::MessageLayout>> messagesOnScreen;
|
2017-12-26 18:24:02 +01:00
|
|
|
|
2017-01-22 12:46:35 +01:00
|
|
|
private slots:
|
2017-04-12 17:46:44 +02:00
|
|
|
void wordTypeMaskChanged()
|
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
|