From 94813fe3dfa1f2f73c7aa410b339ea197b706d2a Mon Sep 17 00:00:00 2001 From: fourtf Date: Wed, 8 Aug 2018 20:06:20 +0200 Subject: [PATCH] added subfunctions for ChannelView() --- src/widgets/helper/ChannelView.cpp | 140 ++++++++++++----------------- src/widgets/helper/ChannelView.hpp | 9 +- 2 files changed, 67 insertions(+), 82 deletions(-) diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index ca490dbaa..1615d15ba 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -95,70 +95,11 @@ ChannelView::ChannelView(BaseWidget *parent) : BaseWidget(parent) , scrollBar_(this) { - auto app = getApp(); - this->setMouseTracking(true); - this->connections_.push_back(app->windows->wordFlagsChanged.connect([this] { - this->layoutMessages(); - this->update(); - })); - - this->scrollBar_.getCurrentValueChanged().connect([this] { - // Whenever the scrollbar value has been changed, re-render the - // ChatWidgetView - this->actuallyLayoutMessages(true); - - // if (!this->isPaused()) { - this->goToBottom_->setVisible(this->enableScrollingToBottom_ && - this->scrollBar_.isVisible() && - !this->scrollBar_.isAtBottom()); - // } - - this->queueUpdate(); - }); - - this->scrollBar_.getDesiredValueChanged().connect([this] { - this->pausedByScrollingUp_ = !this->scrollBar_.isAtBottom(); - }); - - this->connections_.push_back(app->windows->repaintGifs.connect([&] { - this->queueUpdate(); // - })); - - this->connections_.push_back( - app->windows->layout.connect([&](Channel *channel) { - if (channel == nullptr || this->channel_.get() == channel) { - this->layoutMessages(); - } - })); - - this->goToBottom_ = new EffectLabel(this, 0); - this->goToBottom_->setStyleSheet( - "background-color: rgba(0,0,0,0.66); color: #FFF;"); - this->goToBottom_->getLabel().setText("More messages below"); - this->goToBottom_->setVisible(false); - - this->connections_.emplace_back(app->fonts->fontChanged.connect([this] { - this->layoutMessages(); // - })); - - QObject::connect(this->goToBottom_, &EffectLabel::clicked, this, [=] { - QTimer::singleShot(180, [=] { - this->scrollBar_.scrollToBottom( - app->settings->enableSmoothScrollingNewMessages.getValue()); - }); - }); - - // this->updateTimer.setInterval(1000 / 60); - // this->updateTimer.setSingleShot(true); - // connect(&this->updateTimer, &QTimer::timeout, this, [this] { - // if (this->updateQueued) { - // this->updateQueued = false; - // this->repaint(); - // this->updateTimer.start(); - // } - // }); + this->initializeLayout(); + this->initializeScrollbar(); + this->initializeSignals(); this->pauseTimeout_.setSingleShot(true); QObject::connect(&this->pauseTimeout_, &QTimer::timeout, [this] { @@ -167,31 +108,68 @@ ChannelView::ChannelView(BaseWidget *parent) this->layoutMessages(); }); - app->settings->showLastMessageIndicator.connect( - [this](auto, auto) { - this->update(); // - }, - this->connections_); - - this->layoutCooldown_ = new QTimer(this); - this->layoutCooldown_->setSingleShot(true); - this->layoutCooldown_->setInterval(66); - - QObject::connect(this->layoutCooldown_, &QTimer::timeout, [this] { - if (this->layoutQueued_) { - this->layoutMessages(); - this->layoutQueued_ = false; - } - }); - - QShortcut *shortcut = new QShortcut(QKeySequence("Ctrl+C"), this); + auto shortcut = new QShortcut(QKeySequence("Ctrl+C"), this); QObject::connect(shortcut, &QShortcut::activated, [this] { QGuiApplication::clipboard()->setText(this->getSelectedText()); }); } -ChannelView::~ChannelView() +void ChannelView::initializeLayout() { + this->goToBottom_ = new EffectLabel(this, 0); + this->goToBottom_->setStyleSheet( + "background-color: rgba(0,0,0,0.66); color: #FFF;"); + this->goToBottom_->getLabel().setText("More messages below"); + this->goToBottom_->setVisible(false); + + QObject::connect(this->goToBottom_, &EffectLabel::clicked, this, [=] { + QTimer::singleShot(180, [=] { + this->scrollBar_.scrollToBottom( + getApp() + ->settings->enableSmoothScrollingNewMessages.getValue()); + }); + }); +} + +void ChannelView::initializeScrollbar() +{ + this->scrollBar_.getCurrentValueChanged().connect([this] { + this->actuallyLayoutMessages(true); + + this->goToBottom_->setVisible(this->enableScrollingToBottom_ && + this->scrollBar_.isVisible() && + !this->scrollBar_.isAtBottom()); + + this->queueUpdate(); + }); + + this->scrollBar_.getDesiredValueChanged().connect([this] { + this->pausedByScrollingUp_ = !this->scrollBar_.isAtBottom(); + }); +} + +void ChannelView::initializeSignals() +{ + this->connections_.push_back( + getApp()->windows->wordFlagsChanged.connect([this] { + this->layoutMessages(); + this->update(); + })); + + getApp()->settings->showLastMessageIndicator.connect( + [this](auto, auto) { this->update(); }, this->connections_); + + connections_.push_back( + getApp()->windows->repaintGifs.connect([&] { this->queueUpdate(); })); + + connections_.push_back( + getApp()->windows->layout.connect([&](Channel *channel) { + if (channel == nullptr || this->channel_.get() == channel) + this->layoutMessages(); + })); + + connections_.push_back(getApp()->fonts->fontChanged.connect( + [this] { this->layoutMessages(); })); } void ChannelView::themeChangedEvent() diff --git a/src/widgets/helper/ChannelView.hpp b/src/widgets/helper/ChannelView.hpp index 5072befd8..cb8ad990f 100644 --- a/src/widgets/helper/ChannelView.hpp +++ b/src/widgets/helper/ChannelView.hpp @@ -27,7 +27,6 @@ class ChannelView : public BaseWidget public: explicit ChannelView(BaseWidget *parent = nullptr); - virtual ~ChannelView() override; void queueUpdate(); Scrollbar &getScrollBar(); @@ -77,6 +76,14 @@ protected: QPoint &relativePos, int &index); private: + void initializeLayout(); + void initializeScrollbar(); + void initializeSignals(); + + // void messageAppended(MessagePtr &message); + // void messageAddedAtStart(std::vector &messages); + // void messageRemoveFromStart(MessagePtr &message); + void updatePauseStatus(); void detachChannel(); void actuallyLayoutMessages(bool causedByScollbar = false);