forked from blue/squawk
first lousy attempt to make load indicator in feedView
This commit is contained in:
parent
50190f3eac
commit
0973cb2991
@ -346,6 +346,7 @@ void Models::MessageFeed::fetchMore(const QModelIndex& parent)
|
|||||||
{
|
{
|
||||||
if (syncState == incomplete) {
|
if (syncState == incomplete) {
|
||||||
syncState = syncing;
|
syncState = syncing;
|
||||||
|
emit syncStateChange(syncState);
|
||||||
emit requestStateChange(true);
|
emit requestStateChange(true);
|
||||||
|
|
||||||
if (storage.size() == 0) {
|
if (storage.size() == 0) {
|
||||||
@ -373,6 +374,7 @@ void Models::MessageFeed::responseArchive(const std::list<Shared::Message> list,
|
|||||||
} else {
|
} else {
|
||||||
syncState = incomplete;
|
syncState = incomplete;
|
||||||
}
|
}
|
||||||
|
emit syncStateChange(syncState);
|
||||||
emit requestStateChange(false);
|
emit requestStateChange(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -543,3 +545,8 @@ void Models::MessageFeed::reportLocalPathInvalid(const QString& messageId)
|
|||||||
|
|
||||||
emit dataChanged(index, index, {MessageRoles::Attach});
|
emit dataChanged(index, index, {MessageRoles::Attach});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Models::MessageFeed::SyncState Models::MessageFeed::getSyncState() const
|
||||||
|
{
|
||||||
|
return syncState;
|
||||||
|
}
|
||||||
|
@ -41,7 +41,13 @@ namespace Models {
|
|||||||
class MessageFeed : public QAbstractListModel
|
class MessageFeed : public QAbstractListModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
enum SyncState {
|
||||||
|
incomplete,
|
||||||
|
syncing,
|
||||||
|
complete
|
||||||
|
};
|
||||||
|
|
||||||
MessageFeed(const Element* rosterItem, QObject *parent = nullptr);
|
MessageFeed(const Element* rosterItem, QObject *parent = nullptr);
|
||||||
~MessageFeed();
|
~MessageFeed();
|
||||||
|
|
||||||
@ -69,6 +75,7 @@ public:
|
|||||||
|
|
||||||
void incrementObservers();
|
void incrementObservers();
|
||||||
void decrementObservers();
|
void decrementObservers();
|
||||||
|
SyncState getSyncState() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void requestArchive(const QString& before);
|
void requestArchive(const QString& before);
|
||||||
@ -78,6 +85,7 @@ signals:
|
|||||||
void newMessage(const Shared::Message& msg);
|
void newMessage(const Shared::Message& msg);
|
||||||
void unnoticedMessage(const Shared::Message& msg);
|
void unnoticedMessage(const Shared::Message& msg);
|
||||||
void localPathInvalid(const QString& path);
|
void localPathInvalid(const QString& path);
|
||||||
|
void syncStateChange(SyncState state);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum MessageRoles {
|
enum MessageRoles {
|
||||||
@ -102,12 +110,6 @@ protected:
|
|||||||
std::set<MessageRoles> detectChanges(const Shared::Message& msg, const QMap<QString, QVariant>& data) const;
|
std::set<MessageRoles> detectChanges(const Shared::Message& msg, const QMap<QString, QVariant>& data) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum SyncState {
|
|
||||||
incomplete,
|
|
||||||
syncing,
|
|
||||||
complete
|
|
||||||
};
|
|
||||||
|
|
||||||
//tags
|
//tags
|
||||||
struct id {};
|
struct id {};
|
||||||
struct time {};
|
struct time {};
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
constexpr int maxMessageHeight = 10000;
|
constexpr int maxMessageHeight = 10000;
|
||||||
constexpr int approximateSingleMessageHeight = 20;
|
constexpr int approximateSingleMessageHeight = 20;
|
||||||
|
constexpr int progressSize = 70;
|
||||||
|
|
||||||
const std::set<int> FeedView::geometryChangingRoles = {
|
const std::set<int> FeedView::geometryChangingRoles = {
|
||||||
Models::MessageFeed::Attach,
|
Models::MessageFeed::Attach,
|
||||||
@ -43,13 +44,18 @@ FeedView::FeedView(QWidget* parent):
|
|||||||
vo(0),
|
vo(0),
|
||||||
specialDelegate(false),
|
specialDelegate(false),
|
||||||
specialModel(false),
|
specialModel(false),
|
||||||
clearWidgetsMode(false)
|
clearWidgetsMode(false),
|
||||||
|
modelState(Models::MessageFeed::complete),
|
||||||
|
progress()
|
||||||
{
|
{
|
||||||
horizontalScrollBar()->setRange(0, 0);
|
horizontalScrollBar()->setRange(0, 0);
|
||||||
verticalScrollBar()->setSingleStep(approximateSingleMessageHeight);
|
verticalScrollBar()->setSingleStep(approximateSingleMessageHeight);
|
||||||
setMouseTracking(true);
|
setMouseTracking(true);
|
||||||
setSelectionBehavior(SelectItems);
|
setSelectionBehavior(SelectItems);
|
||||||
// viewport()->setAttribute(Qt::WA_Hover, true);
|
// viewport()->setAttribute(Qt::WA_Hover, true);
|
||||||
|
|
||||||
|
progress.setParent(viewport());
|
||||||
|
progress.resize(progressSize, progressSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
FeedView::~FeedView()
|
FeedView::~FeedView()
|
||||||
@ -293,6 +299,13 @@ void FeedView::mouseMoveEvent(QMouseEvent* event)
|
|||||||
QAbstractItemView::mouseMoveEvent(event);
|
QAbstractItemView::mouseMoveEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FeedView::resizeEvent(QResizeEvent* event)
|
||||||
|
{
|
||||||
|
progress.move((width() - progressSize) / 2, 0);
|
||||||
|
|
||||||
|
QAbstractItemView::resizeEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QFont FeedView::getFont() const
|
QFont FeedView::getFont() const
|
||||||
{
|
{
|
||||||
@ -319,14 +332,22 @@ void FeedView::setItemDelegate(QAbstractItemDelegate* delegate)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeedView::setModel(QAbstractItemModel* model)
|
void FeedView::setModel(QAbstractItemModel* p_model)
|
||||||
{
|
{
|
||||||
QAbstractItemView::setModel(model);
|
if (specialModel) {
|
||||||
|
Models::MessageFeed* feed = static_cast<Models::MessageFeed*>(model());
|
||||||
|
disconnect(feed, &Models::MessageFeed::syncStateChange, this, &FeedView::onModelSyncStateChange);
|
||||||
|
}
|
||||||
|
|
||||||
Models::MessageFeed* feed = dynamic_cast<Models::MessageFeed*>(model);
|
QAbstractItemView::setModel(p_model);
|
||||||
|
|
||||||
|
Models::MessageFeed* feed = dynamic_cast<Models::MessageFeed*>(p_model);
|
||||||
if (feed) {
|
if (feed) {
|
||||||
|
onModelSyncStateChange(feed->getSyncState());
|
||||||
specialModel = true;
|
specialModel = true;
|
||||||
|
connect(feed, &Models::MessageFeed::syncStateChange, this, &FeedView::onModelSyncStateChange);
|
||||||
} else {
|
} else {
|
||||||
|
onModelSyncStateChange(Models::MessageFeed::complete);
|
||||||
specialModel = false;
|
specialModel = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -352,3 +373,17 @@ void FeedView::onMessageInvalidPath(const QString& messageId)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FeedView::onModelSyncStateChange(Models::MessageFeed::SyncState state)
|
||||||
|
{
|
||||||
|
if (modelState != state) {
|
||||||
|
modelState = state;
|
||||||
|
|
||||||
|
if (state == Models::MessageFeed::syncing) {
|
||||||
|
progress.show();
|
||||||
|
progress.start();
|
||||||
|
} else {
|
||||||
|
progress.stop();
|
||||||
|
progress.hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
#include <ui/models/messagefeed.h>
|
#include <ui/models/messagefeed.h>
|
||||||
|
#include "progress.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @todo write docs
|
* @todo write docs
|
||||||
@ -56,6 +57,7 @@ protected slots:
|
|||||||
void dataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight, const QVector<int> & roles) override;
|
void dataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight, const QVector<int> & roles) override;
|
||||||
void onMessageButtonPushed(const QString& messageId, bool download);
|
void onMessageButtonPushed(const QString& messageId, bool download);
|
||||||
void onMessageInvalidPath(const QString& messageId);
|
void onMessageInvalidPath(const QString& messageId);
|
||||||
|
void onModelSyncStateChange(Models::MessageFeed::SyncState state);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int verticalOffset() const override;
|
int verticalOffset() const override;
|
||||||
@ -63,6 +65,7 @@ protected:
|
|||||||
void paintEvent(QPaintEvent * event) override;
|
void paintEvent(QPaintEvent * event) override;
|
||||||
void updateGeometries() override;
|
void updateGeometries() override;
|
||||||
void mouseMoveEvent(QMouseEvent * event) override;
|
void mouseMoveEvent(QMouseEvent * event) override;
|
||||||
|
void resizeEvent(QResizeEvent * event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool tryToCalculateGeometriesWithNoScrollbars(const QStyleOptionViewItem& option, const QAbstractItemModel* model, uint32_t totalHeight);
|
bool tryToCalculateGeometriesWithNoScrollbars(const QStyleOptionViewItem& option, const QAbstractItemModel* model, uint32_t totalHeight);
|
||||||
@ -78,6 +81,8 @@ private:
|
|||||||
bool specialDelegate;
|
bool specialDelegate;
|
||||||
bool specialModel;
|
bool specialModel;
|
||||||
bool clearWidgetsMode;
|
bool clearWidgetsMode;
|
||||||
|
Models::MessageFeed::SyncState modelState;
|
||||||
|
Progress progress;
|
||||||
|
|
||||||
static const std::set<int> geometryChangingRoles;
|
static const std::set<int> geometryChangingRoles;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user