From e32c1177c3f548503c8a51961d1f250a6875274a Mon Sep 17 00:00:00 2001 From: blue Date: Thu, 5 Sep 2019 18:25:31 +0300 Subject: [PATCH] rookie shaky messages history request in progress animation --- ui/widgets/conversation.cpp | 11 +++++--- ui/widgets/messageline.cpp | 53 ++++++++++++++++++++++++++++++++++++- ui/widgets/messageline.h | 9 +++++++ 3 files changed, 68 insertions(+), 5 deletions(-) diff --git a/ui/widgets/conversation.cpp b/ui/widgets/conversation.cpp index 22cf909..9673983 100644 --- a/ui/widgets/conversation.cpp +++ b/ui/widgets/conversation.cpp @@ -202,11 +202,13 @@ 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; } - scroll = nothing; } } } @@ -216,7 +218,7 @@ void Conversation::responseArchive(const std::list list) requestingHistory = false; scroll = keep; - m_ui->historyStatus->clear(); + line->hideBusyIndicator(); for (std::list::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(); diff --git a/ui/widgets/messageline.cpp b/ui/widgets/messageline.cpp index f4ec827..ea07145 100644 --- a/ui/widgets/messageline.cpp +++ b/ui/widgets/messageline.cpp @@ -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); +} diff --git a/ui/widgets/messageline.h b/ui/widgets/messageline.h index 407120c..1cd294c 100644 --- a/ui/widgets/messageline.h +++ b/ui/widgets/messageline.h @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include "../global.h" class MessageLine : public QWidget @@ -71,6 +73,13 @@ private: std::map palNames; std::deque views; bool room; + QLabel busyLabel; + QHBoxLayout busyLayout; + bool busyShown; + QVariantAnimation rotation; + +private slots: + void onAnimationValueChanged(const QVariant& value); }; #endif // MESSAGELINE_H