1
0
forked from blue/squawk

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

View File

@ -31,11 +31,27 @@ MessageLine::MessageLine(bool p_room, QWidget* parent):
myName(), myName(),
palNames(), palNames(),
views(), views(),
room(p_room) room(p_room),
busyLabel(),
busyLayout(),
busyShown(false),
rotation()
{ {
setLayout(layout); setLayout(layout);
setBackgroundRole(QPalette::Base); setBackgroundRole(QPalette::Base);
layout->addStretch(); 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() MessageLine::~MessageLine()
@ -72,6 +88,10 @@ MessageLine::Position MessageLine::message(const Shared::Message& msg)
res = middle; res = middle;
} }
if (busyShown) {
index += 1;
}
QVBoxLayout* vBox = new QVBoxLayout(); QVBoxLayout* vBox = new QVBoxLayout();
QHBoxLayout* hBox = new QHBoxLayout(); QHBoxLayout* hBox = new QHBoxLayout();
QWidget* message = new QWidget(); QWidget* message = new QWidget();
@ -184,3 +204,34 @@ QString MessageLine::firstMessageId() const
return messageOrder.begin()->second->getId(); 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 <QHBoxLayout>
#include <QLabel> #include <QLabel>
#include <QResizeEvent> #include <QResizeEvent>
#include <QIcon>
#include <QVariantAnimation>
#include "../global.h" #include "../global.h"
class MessageLine : public QWidget class MessageLine : public QWidget
@ -71,6 +73,13 @@ 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;
QHBoxLayout busyLayout;
bool busyShown;
QVariantAnimation rotation;
private slots:
void onAnimationValueChanged(const QVariant& value);
}; };
#endif // MESSAGELINE_H #endif // MESSAGELINE_H