beeter loading animation

This commit is contained in:
Blue 2019-09-06 02:44:20 +03:00
parent e32c1177c3
commit 139c0de0e3
2 changed files with 21 additions and 11 deletions

View File

@ -19,6 +19,7 @@
#include "messageline.h" #include "messageline.h"
#include <QDebug> #include <QDebug>
#include <QGraphicsDropShadowEffect> #include <QGraphicsDropShadowEffect>
#include <cmath>
const QRegExp urlReg("^(?!<img\\ssrc=\")((?:https?|ftp)://\\S+)"); const QRegExp urlReg("^(?!<img\\ssrc=\")((?:https?|ftp)://\\S+)");
const QRegExp imgReg("((?:https?|ftp)://\\S+\\.(?:jpg|jpeg|png|svg|gif))"); const QRegExp imgReg("((?:https?|ftp)://\\S+\\.(?:jpg|jpeg|png|svg|gif))");
@ -32,7 +33,9 @@ MessageLine::MessageLine(bool p_room, QWidget* parent):
palNames(), palNames(),
views(), views(),
room(p_room), room(p_room),
busyLabel(), busyPixmap(new QGraphicsPixmapItem(Shared::icon("view-refresh", true).pixmap(70))),
busyScene(),
busyLabel(&busyScene),
busyLayout(), busyLayout(),
busyShown(false), busyShown(false),
rotation() rotation()
@ -41,12 +44,20 @@ MessageLine::MessageLine(bool p_room, QWidget* parent):
setBackgroundRole(QPalette::Base); setBackgroundRole(QPalette::Base);
layout->addStretch(); layout->addStretch();
busyLabel.setPixmap(Shared::icon("view-refresh", true).pixmap(50)); busyScene.addItem(busyPixmap);
busyLayout.addStretch(); busyLayout.addStretch();
busyLayout.addWidget(&busyLabel); busyLayout.addWidget(&busyLabel);
busyLayout.addStretch(); busyLayout.addStretch();
busyLabel.setMaximumSize(70, 70);
busyLabel.setMinimumSize(70, 70);
busyLabel.setSceneRect(0, 0, 70, 70);
busyLabel.setFrameStyle(0);
busyLabel.setContentsMargins(0, 0, 0, 0);
busyLabel.setInteractive(false);
busyPixmap->setTransformOriginPoint(35, 35);
busyPixmap->setTransformationMode(Qt::SmoothTransformation);
busyPixmap->setOffset(0, 0);;
busyLabel.hide();
rotation.setDuration(500); rotation.setDuration(500);
rotation.setStartValue(0.0f); rotation.setStartValue(0.0f);
rotation.setEndValue(180.0f); rotation.setEndValue(180.0f);
@ -227,11 +238,5 @@ void MessageLine::hideBusyIndicator()
void MessageLine::onAnimationValueChanged(const QVariant& value) void MessageLine::onAnimationValueChanged(const QVariant& value)
{ {
QTransform r; busyPixmap->setRotation(value.toReal());
r.rotate(value.toReal());
QPixmap pxm = Shared::icon("view-refresh", true).pixmap(50).transformed(r, Qt::SmoothTransformation);
int dw = pxm.width() - 50;
int dh = pxm.height() - 50;
pxm = pxm.copy(dw/2, dh/2, 50, 50);
busyLabel.setPixmap(pxm);
} }

View File

@ -25,6 +25,9 @@
#include <QLabel> #include <QLabel>
#include <QResizeEvent> #include <QResizeEvent>
#include <QIcon> #include <QIcon>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsPixmapItem>
#include <QVariantAnimation> #include <QVariantAnimation>
#include "../global.h" #include "../global.h"
@ -73,7 +76,9 @@ private:
std::map<QString, QString> palNames; std::map<QString, QString> palNames;
std::deque<QHBoxLayout*> views; std::deque<QHBoxLayout*> views;
bool room; bool room;
QLabel busyLabel; QGraphicsPixmapItem* busyPixmap;
QGraphicsScene busyScene;
QGraphicsView busyLabel;
QHBoxLayout busyLayout; QHBoxLayout busyLayout;
bool busyShown; bool busyShown;
QVariantAnimation rotation; QVariantAnimation rotation;