From a5e7ef99809e595551c4f38534f6d827ff905ffc Mon Sep 17 00:00:00 2001 From: fourtf Date: Thu, 26 Jan 2017 09:26:18 +0100 Subject: [PATCH] fixed notebookpagedroppreview animation --- concurrentmap.h | 44 +++++++++++++++-------------- messages/lazyloadedimage.cpp | 8 ++++-- widgets/chatwidgetview.cpp | 2 +- widgets/notebookpagedroppreview.cpp | 27 ++++++++++++++---- widgets/notebookpagedroppreview.h | 3 ++ 5 files changed, 54 insertions(+), 30 deletions(-) diff --git a/concurrentmap.h b/concurrentmap.h index e12015925..45cf3b626 100644 --- a/concurrentmap.h +++ b/concurrentmap.h @@ -4,6 +4,7 @@ #include #include #include +#include namespace chatterino { @@ -12,22 +13,21 @@ class ConcurrentMap { public: ConcurrentMap() + : map() { - mutex = new QMutex(); - map = new QMap(); + this->mutex = new QMutex(); } bool tryGet(const TKey &name, TValue &value) const { - mutex->lock(); - auto a = map->find(name); - if (a == map->end()) { - mutex->unlock(); - value = NULL; + this->mutex->lock(); + auto a = map.find(name); + if (a == map.end()) { + this->mutex->unlock(); return false; } - mutex->unlock(); + this->mutex->unlock(); value = a.value(); return true; } @@ -35,37 +35,39 @@ public: TValue getOrAdd(const TKey &name, std::function addLambda) { - mutex->lock(); - auto a = map->find(name); - if (a == map->end()) { + this->mutex->lock(); + auto a = map.find(name); + + if (a == map.end()) { TValue value = addLambda(); - map->insert(name, value); - mutex->unlock(); + map.insert(name, value); + this->mutex->unlock(); return value; } - mutex->unlock(); + + this->mutex->unlock(); return a.value(); } void clear() { - mutex->lock(); - map->clear(); - mutex->unlock(); + this->mutex->lock(); + map.clear(); + this->mutex->unlock(); } void insert(const TKey &name, const TValue &value) { - mutex->lock(); - map->insert(name, value); - mutex->unlock(); + this->mutex->lock(); + map.insert(name, value); + this->mutex->unlock(); } private: QMutex *mutex; - QMap *map; + QMap map; }; } diff --git a/messages/lazyloadedimage.cpp b/messages/lazyloadedimage.cpp index 468ec2b6c..15bfcdf26 100644 --- a/messages/lazyloadedimage.cpp +++ b/messages/lazyloadedimage.cpp @@ -47,10 +47,12 @@ void LazyLoadedImage::loadImage() { // QThreadPool::globalInstance()->start(new LambdaQRunnable([=] { + QNetworkAccessManager *manager = new QNetworkAccessManager(); + QUrl url(this->url); QNetworkRequest request(url); - QNetworkReply *reply = IrcManager::getAccessManager().get(request); + QNetworkReply *reply = manager->get(request); QObject::connect(reply, &QNetworkReply::finished, [=] { QPixmap *pixmap = new QPixmap(); @@ -63,8 +65,10 @@ LazyLoadedImage::loadImage() this->pixmap = pixmap; Emotes::incGeneration(); Windows::layoutVisibleChatWidgets(); + + delete manager; }); - //})); + // })); } } } diff --git a/widgets/chatwidgetview.cpp b/widgets/chatwidgetview.cpp index 59ab12b6c..762ab5372 100644 --- a/widgets/chatwidgetview.cpp +++ b/widgets/chatwidgetview.cpp @@ -54,7 +54,7 @@ ChatWidgetView::layoutMessages() redraw |= message.get()->layout(this->width(), true); } - int h = this->height(); + int h = this->height() - 8; for (int i = messages.size() - 1; i >= 0; i--) { auto *message = messages[i].get(); diff --git a/widgets/notebookpagedroppreview.cpp b/widgets/notebookpagedroppreview.cpp index 63db87d52..682e5a66c 100644 --- a/widgets/notebookpagedroppreview.cpp +++ b/widgets/notebookpagedroppreview.cpp @@ -1,6 +1,7 @@ #include "widgets/notebookpagedroppreview.h" #include "colorscheme.h" +#include #include namespace chatterino { @@ -10,8 +11,10 @@ NotebookPageDropPreview::NotebookPageDropPreview(QWidget *parent) : QWidget(parent) , positionAnimation(this, "geometry") , desiredGeometry() + , animate(false) { - setHidden(true); + this->positionAnimation.setEasingCurve(QEasingCurve(QEasingCurve::InCubic)); + this->setHidden(true); } void @@ -23,6 +26,12 @@ NotebookPageDropPreview::paintEvent(QPaintEvent *) ColorScheme::getInstance().DropPreviewBackground); } +void +NotebookPageDropPreview::hideEvent(QHideEvent *) +{ + animate = false; +} + void NotebookPageDropPreview::setBounds(const QRect &rect) { @@ -30,13 +39,19 @@ NotebookPageDropPreview::setBounds(const QRect &rect) return; } - this->positionAnimation.stop(); - this->positionAnimation.setDuration(50); - this->positionAnimation.setStartValue(geometry()); - this->positionAnimation.setEndValue(rect); - this->positionAnimation.start(); + if (animate) { + this->positionAnimation.stop(); + this->positionAnimation.setDuration(50); + this->positionAnimation.setStartValue(this->geometry()); + this->positionAnimation.setEndValue(rect); + this->positionAnimation.start(); + } else { + this->setGeometry(rect); + } this->desiredGeometry = rect; + + animate = true; } } } diff --git a/widgets/notebookpagedroppreview.h b/widgets/notebookpagedroppreview.h index db6d37720..39ade28b3 100644 --- a/widgets/notebookpagedroppreview.h +++ b/widgets/notebookpagedroppreview.h @@ -17,8 +17,11 @@ public: protected: void paintEvent(QPaintEvent *); + void hideEvent(QHideEvent *); + QPropertyAnimation positionAnimation; QRect desiredGeometry; + bool animate; }; } }