rookie shaky messages history request in progress animation

This commit is contained in:
Blue 2019-09-05 18:25:31 +03:00
parent c295fa1c1d
commit e32c1177c3
3 changed files with 68 additions and 5 deletions

View File

@ -202,21 +202,23 @@ void Conversation::onSliderValueChanged(int value)
scroll = down;
} else {
if (!requestingHistory && value == 0) {
m_ui->historyStatus->setPixmap(Shared::icon("view-refresh", true).pixmap(25));
requestingHistory = true;
line->showBusyIndicator();
emit requestArchive(line->firstMessageId());
}
scroll = keep;
} else {
scroll = nothing;
}
}
}
}
void Conversation::responseArchive(const std::list<Shared::Message> list)
{
requestingHistory = false;
scroll = keep;
m_ui->historyStatus->clear();
line->hideBusyIndicator();
for (std::list<Shared::Message>::const_iterator itr = list.begin(), end = list.end(); itr != end; ++itr) {
addMessage(*itr);
}
@ -226,8 +228,9 @@ void Conversation::showEvent(QShowEvent* event)
{
if (!everShown) {
everShown = true;
m_ui->historyStatus->setPixmap(Shared::icon("view-refresh", true).pixmap(25));
line->showBusyIndicator();
requestingHistory = true;
scroll = keep;
emit requestArchive(line->firstMessageId());
}
emit shown();

View File

@ -31,11 +31,27 @@ MessageLine::MessageLine(bool p_room, QWidget* parent):
myName(),
palNames(),
views(),
room(p_room)
room(p_room),
busyLabel(),
busyLayout(),
busyShown(false),
rotation()
{
setLayout(layout);
setBackgroundRole(QPalette::Base);
layout->addStretch();
busyLabel.setPixmap(Shared::icon("view-refresh", true).pixmap(50));
busyLayout.addStretch();
busyLayout.addWidget(&busyLabel);
busyLayout.addStretch();
busyLabel.hide();
rotation.setDuration(500);
rotation.setStartValue(0.0f);
rotation.setEndValue(180.0f);
rotation.setLoopCount(-1);
connect(&rotation, SIGNAL(valueChanged(const QVariant&)), this, SLOT(onAnimationValueChanged(const QVariant&)));
}
MessageLine::~MessageLine()
@ -72,6 +88,10 @@ MessageLine::Position MessageLine::message(const Shared::Message& msg)
res = middle;
}
if (busyShown) {
index += 1;
}
QVBoxLayout* vBox = new QVBoxLayout();
QHBoxLayout* hBox = new QHBoxLayout();
QWidget* message = new QWidget();
@ -184,3 +204,34 @@ QString MessageLine::firstMessageId() const
return messageOrder.begin()->second->getId();
}
}
void MessageLine::showBusyIndicator()
{
if (!busyShown) {
layout->insertLayout(0, &busyLayout);
busyShown = true;
rotation.start();
busyLabel.show();
}
}
void MessageLine::hideBusyIndicator()
{
if (busyShown) {
busyLabel.hide();
rotation.stop();
layout->removeItem(&busyLayout);
busyShown = false;
}
}
void MessageLine::onAnimationValueChanged(const QVariant& value)
{
QTransform r;
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

@ -24,6 +24,8 @@
#include <QHBoxLayout>
#include <QLabel>
#include <QResizeEvent>
#include <QIcon>
#include <QVariantAnimation>
#include "../global.h"
class MessageLine : public QWidget
@ -71,6 +73,13 @@ private:
std::map<QString, QString> palNames;
std::deque<QHBoxLayout*> views;
bool room;
QLabel busyLabel;
QHBoxLayout busyLayout;
bool busyShown;
QVariantAnimation rotation;
private slots:
void onAnimationValueChanged(const QVariant& value);
};
#endif // MESSAGELINE_H