fixed notebookpagedroppreview animation

This commit is contained in:
fourtf 2017-01-26 09:26:18 +01:00
parent d012aa922d
commit a5e7ef9980
5 changed files with 54 additions and 30 deletions

View file

@ -4,6 +4,7 @@
#include <QMap> #include <QMap>
#include <QMutex> #include <QMutex>
#include <functional> #include <functional>
#include <unordered_map>
namespace chatterino { namespace chatterino {
@ -12,22 +13,21 @@ class ConcurrentMap
{ {
public: public:
ConcurrentMap() ConcurrentMap()
: map()
{ {
mutex = new QMutex(); this->mutex = new QMutex();
map = new QMap<TKey, TValue>();
} }
bool bool
tryGet(const TKey &name, TValue &value) const tryGet(const TKey &name, TValue &value) const
{ {
mutex->lock(); this->mutex->lock();
auto a = map->find(name); auto a = map.find(name);
if (a == map->end()) { if (a == map.end()) {
mutex->unlock(); this->mutex->unlock();
value = NULL;
return false; return false;
} }
mutex->unlock(); this->mutex->unlock();
value = a.value(); value = a.value();
return true; return true;
} }
@ -35,37 +35,39 @@ public:
TValue TValue
getOrAdd(const TKey &name, std::function<TValue()> addLambda) getOrAdd(const TKey &name, std::function<TValue()> addLambda)
{ {
mutex->lock(); this->mutex->lock();
auto a = map->find(name); auto a = map.find(name);
if (a == map->end()) {
if (a == map.end()) {
TValue value = addLambda(); TValue value = addLambda();
map->insert(name, value); map.insert(name, value);
mutex->unlock(); this->mutex->unlock();
return value; return value;
} }
mutex->unlock();
this->mutex->unlock();
return a.value(); return a.value();
} }
void void
clear() clear()
{ {
mutex->lock(); this->mutex->lock();
map->clear(); map.clear();
mutex->unlock(); this->mutex->unlock();
} }
void void
insert(const TKey &name, const TValue &value) insert(const TKey &name, const TValue &value)
{ {
mutex->lock(); this->mutex->lock();
map->insert(name, value); map.insert(name, value);
mutex->unlock(); this->mutex->unlock();
} }
private: private:
QMutex *mutex; QMutex *mutex;
QMap<TKey, TValue> *map; QMap<TKey, TValue> map;
}; };
} }

View file

@ -47,10 +47,12 @@ void
LazyLoadedImage::loadImage() LazyLoadedImage::loadImage()
{ {
// QThreadPool::globalInstance()->start(new LambdaQRunnable([=] { // QThreadPool::globalInstance()->start(new LambdaQRunnable([=] {
QNetworkAccessManager *manager = new QNetworkAccessManager();
QUrl url(this->url); QUrl url(this->url);
QNetworkRequest request(url); QNetworkRequest request(url);
QNetworkReply *reply = IrcManager::getAccessManager().get(request); QNetworkReply *reply = manager->get(request);
QObject::connect(reply, &QNetworkReply::finished, [=] { QObject::connect(reply, &QNetworkReply::finished, [=] {
QPixmap *pixmap = new QPixmap(); QPixmap *pixmap = new QPixmap();
@ -63,6 +65,8 @@ LazyLoadedImage::loadImage()
this->pixmap = pixmap; this->pixmap = pixmap;
Emotes::incGeneration(); Emotes::incGeneration();
Windows::layoutVisibleChatWidgets(); Windows::layoutVisibleChatWidgets();
delete manager;
}); });
// })); // }));
} }

View file

@ -54,7 +54,7 @@ ChatWidgetView::layoutMessages()
redraw |= message.get()->layout(this->width(), true); 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--) { for (int i = messages.size() - 1; i >= 0; i--) {
auto *message = messages[i].get(); auto *message = messages[i].get();

View file

@ -1,6 +1,7 @@
#include "widgets/notebookpagedroppreview.h" #include "widgets/notebookpagedroppreview.h"
#include "colorscheme.h" #include "colorscheme.h"
#include <QDebug>
#include <QPainter> #include <QPainter>
namespace chatterino { namespace chatterino {
@ -10,8 +11,10 @@ NotebookPageDropPreview::NotebookPageDropPreview(QWidget *parent)
: QWidget(parent) : QWidget(parent)
, positionAnimation(this, "geometry") , positionAnimation(this, "geometry")
, desiredGeometry() , desiredGeometry()
, animate(false)
{ {
setHidden(true); this->positionAnimation.setEasingCurve(QEasingCurve(QEasingCurve::InCubic));
this->setHidden(true);
} }
void void
@ -23,6 +26,12 @@ NotebookPageDropPreview::paintEvent(QPaintEvent *)
ColorScheme::getInstance().DropPreviewBackground); ColorScheme::getInstance().DropPreviewBackground);
} }
void
NotebookPageDropPreview::hideEvent(QHideEvent *)
{
animate = false;
}
void void
NotebookPageDropPreview::setBounds(const QRect &rect) NotebookPageDropPreview::setBounds(const QRect &rect)
{ {
@ -30,13 +39,19 @@ NotebookPageDropPreview::setBounds(const QRect &rect)
return; return;
} }
if (animate) {
this->positionAnimation.stop(); this->positionAnimation.stop();
this->positionAnimation.setDuration(50); this->positionAnimation.setDuration(50);
this->positionAnimation.setStartValue(geometry()); this->positionAnimation.setStartValue(this->geometry());
this->positionAnimation.setEndValue(rect); this->positionAnimation.setEndValue(rect);
this->positionAnimation.start(); this->positionAnimation.start();
} else {
this->setGeometry(rect);
}
this->desiredGeometry = rect; this->desiredGeometry = rect;
animate = true;
} }
} }
} }

View file

@ -17,8 +17,11 @@ public:
protected: protected:
void paintEvent(QPaintEvent *); void paintEvent(QPaintEvent *);
void hideEvent(QHideEvent *);
QPropertyAnimation positionAnimation; QPropertyAnimation positionAnimation;
QRect desiredGeometry; QRect desiredGeometry;
bool animate;
}; };
} }
} }