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 <QMutex>
|
||||
#include <functional>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
|
@ -12,22 +13,21 @@ class ConcurrentMap
|
|||
{
|
||||
public:
|
||||
ConcurrentMap()
|
||||
: map()
|
||||
{
|
||||
mutex = new QMutex();
|
||||
map = new QMap<TKey, TValue>();
|
||||
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<TValue()> 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<TKey, TValue> *map;
|
||||
QMap<TKey, TValue> map;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
//}));
|
||||
// }));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "widgets/notebookpagedroppreview.h"
|
||||
#include "colorscheme.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QPainter>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (animate) {
|
||||
this->positionAnimation.stop();
|
||||
this->positionAnimation.setDuration(50);
|
||||
this->positionAnimation.setStartValue(geometry());
|
||||
this->positionAnimation.setStartValue(this->geometry());
|
||||
this->positionAnimation.setEndValue(rect);
|
||||
this->positionAnimation.start();
|
||||
} else {
|
||||
this->setGeometry(rect);
|
||||
}
|
||||
|
||||
this->desiredGeometry = rect;
|
||||
|
||||
animate = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,11 @@ public:
|
|||
protected:
|
||||
void paintEvent(QPaintEvent *);
|
||||
|
||||
void hideEvent(QHideEvent *);
|
||||
|
||||
QPropertyAnimation positionAnimation;
|
||||
QRect desiredGeometry;
|
||||
bool animate;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue