mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
fixed notebookpagedroppreview animation
This commit is contained in:
parent
d012aa922d
commit
a5e7ef9980
5 changed files with 54 additions and 30 deletions
|
@ -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;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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,8 +65,10 @@ LazyLoadedImage::loadImage()
|
||||||
this->pixmap = pixmap;
|
this->pixmap = pixmap;
|
||||||
Emotes::incGeneration();
|
Emotes::incGeneration();
|
||||||
Windows::layoutVisibleChatWidgets();
|
Windows::layoutVisibleChatWidgets();
|
||||||
|
|
||||||
|
delete manager;
|
||||||
});
|
});
|
||||||
//}));
|
// }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->positionAnimation.stop();
|
if (animate) {
|
||||||
this->positionAnimation.setDuration(50);
|
this->positionAnimation.stop();
|
||||||
this->positionAnimation.setStartValue(geometry());
|
this->positionAnimation.setDuration(50);
|
||||||
this->positionAnimation.setEndValue(rect);
|
this->positionAnimation.setStartValue(this->geometry());
|
||||||
this->positionAnimation.start();
|
this->positionAnimation.setEndValue(rect);
|
||||||
|
this->positionAnimation.start();
|
||||||
|
} else {
|
||||||
|
this->setGeometry(rect);
|
||||||
|
}
|
||||||
|
|
||||||
this->desiredGeometry = rect;
|
this->desiredGeometry = rect;
|
||||||
|
|
||||||
|
animate = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue