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) {
|
||||
syncState = syncing;
|
||||
emit syncStateChange(syncState);
|
||||
emit requestStateChange(true);
|
||||
|
||||
if (storage.size() == 0) {
|
||||
@ -373,6 +374,7 @@ void Models::MessageFeed::responseArchive(const std::list<Shared::Message> list,
|
||||
} else {
|
||||
syncState = incomplete;
|
||||
}
|
||||
emit syncStateChange(syncState);
|
||||
emit requestStateChange(false);
|
||||
}
|
||||
}
|
||||
@ -543,3 +545,8 @@ void Models::MessageFeed::reportLocalPathInvalid(const QString& messageId)
|
||||
|
||||
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
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
public:
|
||||
enum SyncState {
|
||||
incomplete,
|
||||
syncing,
|
||||
complete
|
||||
};
|
||||
|
||||
MessageFeed(const Element* rosterItem, QObject *parent = nullptr);
|
||||
~MessageFeed();
|
||||
|
||||
@ -69,6 +75,7 @@ public:
|
||||
|
||||
void incrementObservers();
|
||||
void decrementObservers();
|
||||
SyncState getSyncState() const;
|
||||
|
||||
signals:
|
||||
void requestArchive(const QString& before);
|
||||
@ -78,6 +85,7 @@ signals:
|
||||
void newMessage(const Shared::Message& msg);
|
||||
void unnoticedMessage(const Shared::Message& msg);
|
||||
void localPathInvalid(const QString& path);
|
||||
void syncStateChange(SyncState state);
|
||||
|
||||
public:
|
||||
enum MessageRoles {
|
||||
@ -102,12 +110,6 @@ protected:
|
||||
std::set<MessageRoles> detectChanges(const Shared::Message& msg, const QMap<QString, QVariant>& data) const;
|
||||
|
||||
private:
|
||||
enum SyncState {
|
||||
incomplete,
|
||||
syncing,
|
||||
complete
|
||||
};
|
||||
|
||||
//tags
|
||||
struct id {};
|
||||
struct time {};
|
||||
|
@ -28,6 +28,7 @@
|
||||
|
||||
constexpr int maxMessageHeight = 10000;
|
||||
constexpr int approximateSingleMessageHeight = 20;
|
||||
constexpr int progressSize = 70;
|
||||
|
||||
const std::set<int> FeedView::geometryChangingRoles = {
|
||||
Models::MessageFeed::Attach,
|
||||
@ -43,13 +44,18 @@ FeedView::FeedView(QWidget* parent):
|
||||
vo(0),
|
||||
specialDelegate(false),
|
||||
specialModel(false),
|
||||
clearWidgetsMode(false)
|
||||
clearWidgetsMode(false),
|
||||
modelState(Models::MessageFeed::complete),
|
||||
progress()
|
||||
{
|
||||
horizontalScrollBar()->setRange(0, 0);
|
||||
verticalScrollBar()->setSingleStep(approximateSingleMessageHeight);
|
||||
setMouseTracking(true);
|
||||
setSelectionBehavior(SelectItems);
|
||||
// viewport()->setAttribute(Qt::WA_Hover, true);
|
||||
|
||||
progress.setParent(viewport());
|
||||
progress.resize(progressSize, progressSize);
|
||||
}
|
||||
|
||||
FeedView::~FeedView()
|
||||
@ -293,6 +299,13 @@ void FeedView::mouseMoveEvent(QMouseEvent* event)
|
||||
QAbstractItemView::mouseMoveEvent(event);
|
||||
}
|
||||
|
||||
void FeedView::resizeEvent(QResizeEvent* event)
|
||||
{
|
||||
progress.move((width() - progressSize) / 2, 0);
|
||||
|
||||
QAbstractItemView::resizeEvent(event);
|
||||
}
|
||||
|
||||
|
||||
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) {
|
||||
onModelSyncStateChange(feed->getSyncState());
|
||||
specialModel = true;
|
||||
connect(feed, &Models::MessageFeed::syncStateChange, this, &FeedView::onModelSyncStateChange);
|
||||
} else {
|
||||
onModelSyncStateChange(Models::MessageFeed::complete);
|
||||
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 <ui/models/messagefeed.h>
|
||||
#include "progress.h"
|
||||
|
||||
/**
|
||||
* @todo write docs
|
||||
@ -56,6 +57,7 @@ protected slots:
|
||||
void dataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight, const QVector<int> & roles) override;
|
||||
void onMessageButtonPushed(const QString& messageId, bool download);
|
||||
void onMessageInvalidPath(const QString& messageId);
|
||||
void onModelSyncStateChange(Models::MessageFeed::SyncState state);
|
||||
|
||||
protected:
|
||||
int verticalOffset() const override;
|
||||
@ -63,6 +65,7 @@ protected:
|
||||
void paintEvent(QPaintEvent * event) override;
|
||||
void updateGeometries() override;
|
||||
void mouseMoveEvent(QMouseEvent * event) override;
|
||||
void resizeEvent(QResizeEvent * event) override;
|
||||
|
||||
private:
|
||||
bool tryToCalculateGeometriesWithNoScrollbars(const QStyleOptionViewItem& option, const QAbstractItemModel* model, uint32_t totalHeight);
|
||||
@ -78,6 +81,8 @@ private:
|
||||
bool specialDelegate;
|
||||
bool specialModel;
|
||||
bool clearWidgetsMode;
|
||||
Models::MessageFeed::SyncState modelState;
|
||||
Progress progress;
|
||||
|
||||
static const std::set<int> geometryChangingRoles;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user