2020-08-15 21:48:28 +00:00
|
|
|
/*
|
|
|
|
* Squawk messenger.
|
|
|
|
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "feedview.h"
|
|
|
|
|
|
|
|
#include <QPaintEvent>
|
|
|
|
#include <QPainter>
|
2020-08-17 10:27:14 +00:00
|
|
|
#include <QScrollBar>
|
2020-08-15 21:48:28 +00:00
|
|
|
#include <QDebug>
|
|
|
|
|
2021-02-01 22:55:15 +00:00
|
|
|
#include "messagedelegate.h"
|
2021-02-06 11:02:42 +00:00
|
|
|
#include "ui/models/messagefeed.h"
|
2021-05-03 00:35:43 +00:00
|
|
|
#include "eb.h"
|
2021-02-01 22:55:15 +00:00
|
|
|
|
2020-08-17 10:27:14 +00:00
|
|
|
constexpr int maxMessageHeight = 10000;
|
|
|
|
constexpr int approximateSingleMessageHeight = 20;
|
2021-04-30 20:07:00 +00:00
|
|
|
constexpr int progressSize = 70;
|
2020-08-17 10:27:14 +00:00
|
|
|
|
2021-04-22 22:41:32 +00:00
|
|
|
const std::set<int> FeedView::geometryChangingRoles = {
|
|
|
|
Models::MessageFeed::Attach,
|
|
|
|
Models::MessageFeed::Text,
|
|
|
|
Models::MessageFeed::Id,
|
|
|
|
Models::MessageFeed::Error
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2020-08-15 21:48:28 +00:00
|
|
|
FeedView::FeedView(QWidget* parent):
|
|
|
|
QAbstractItemView(parent),
|
2020-08-17 10:27:14 +00:00
|
|
|
hints(),
|
2021-02-01 22:55:15 +00:00
|
|
|
vo(0),
|
|
|
|
specialDelegate(false),
|
2021-02-06 11:02:42 +00:00
|
|
|
specialModel(false),
|
2021-04-30 20:07:00 +00:00
|
|
|
clearWidgetsMode(false),
|
|
|
|
modelState(Models::MessageFeed::complete),
|
|
|
|
progress()
|
2020-08-15 21:48:28 +00:00
|
|
|
{
|
2020-08-17 10:27:14 +00:00
|
|
|
horizontalScrollBar()->setRange(0, 0);
|
|
|
|
verticalScrollBar()->setSingleStep(approximateSingleMessageHeight);
|
2021-01-07 21:50:12 +00:00
|
|
|
setMouseTracking(true);
|
|
|
|
setSelectionBehavior(SelectItems);
|
|
|
|
// viewport()->setAttribute(Qt::WA_Hover, true);
|
2021-04-30 20:07:00 +00:00
|
|
|
|
|
|
|
progress.setParent(viewport());
|
|
|
|
progress.resize(progressSize, progressSize);
|
2020-08-15 21:48:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FeedView::~FeedView()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex FeedView::indexAt(const QPoint& point) const
|
|
|
|
{
|
2021-01-07 21:50:12 +00:00
|
|
|
int32_t vh = viewport()->height();
|
|
|
|
uint32_t y = vh - point.y() + vo;
|
|
|
|
|
|
|
|
for (std::deque<Hint>::size_type i = 0; i < hints.size(); ++i) {
|
2021-05-01 23:03:08 +00:00
|
|
|
if (hints[i].offset + hints[i].height >= y) {
|
|
|
|
return model()->index(i, 0, rootIndex());
|
2020-08-17 10:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-15 21:48:28 +00:00
|
|
|
return QModelIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FeedView::scrollTo(const QModelIndex& index, QAbstractItemView::ScrollHint hint)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect FeedView::visualRect(const QModelIndex& index) const
|
|
|
|
{
|
2021-05-01 23:03:08 +00:00
|
|
|
unsigned int row = index.row();
|
|
|
|
if (!index.isValid() || row >= hints.size()) {
|
|
|
|
qDebug() << "visualRect for" << row;
|
2020-08-15 21:48:28 +00:00
|
|
|
return QRect();
|
|
|
|
} else {
|
2021-05-01 23:03:08 +00:00
|
|
|
const Hint& hint = hints.at(row);
|
2020-08-15 21:48:28 +00:00
|
|
|
const QWidget* vp = viewport();
|
2020-08-17 10:27:14 +00:00
|
|
|
return QRect(0, vp->height() - hint.height - hint.offset + vo, vp->width(), hint.height);
|
2020-08-15 21:48:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int FeedView::horizontalOffset() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FeedView::isIndexHidden(const QModelIndex& index) const
|
|
|
|
{
|
2020-08-17 10:27:14 +00:00
|
|
|
return false;
|
2020-08-15 21:48:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex FeedView::moveCursor(QAbstractItemView::CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
|
|
|
|
{
|
|
|
|
return QModelIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FeedView::setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags command)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int FeedView::verticalOffset() const
|
|
|
|
{
|
2020-08-17 10:27:14 +00:00
|
|
|
return vo;
|
2020-08-15 21:48:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QRegion FeedView::visualRegionForSelection(const QItemSelection& selection) const
|
|
|
|
{
|
|
|
|
return QRegion();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FeedView::rowsInserted(const QModelIndex& parent, int start, int end)
|
|
|
|
{
|
|
|
|
QAbstractItemView::rowsInserted(parent, start, end);
|
2021-05-01 23:03:08 +00:00
|
|
|
|
|
|
|
scheduleDelayedItemsLayout();
|
2020-08-15 21:48:28 +00:00
|
|
|
}
|
|
|
|
|
2021-04-20 21:56:47 +00:00
|
|
|
void FeedView::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles)
|
|
|
|
{
|
2021-04-22 22:41:32 +00:00
|
|
|
if (specialDelegate) {
|
|
|
|
for (int role : roles) {
|
|
|
|
if (geometryChangingRoles.count(role) != 0) {
|
2021-05-01 23:03:08 +00:00
|
|
|
scheduleDelayedItemsLayout(); //to recalculate layout only if there are some geometry changing modifications
|
2021-04-22 22:41:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-04-20 21:56:47 +00:00
|
|
|
QAbstractItemView::dataChanged(topLeft, bottomRight, roles);
|
|
|
|
}
|
|
|
|
|
2020-08-15 21:48:28 +00:00
|
|
|
void FeedView::updateGeometries()
|
|
|
|
{
|
|
|
|
qDebug() << "updateGeometries";
|
2020-08-17 10:27:14 +00:00
|
|
|
QScrollBar* bar = verticalScrollBar();
|
|
|
|
|
|
|
|
const QStyle* st = style();
|
2020-08-15 21:48:28 +00:00
|
|
|
const QAbstractItemModel* m = model();
|
2021-05-01 23:03:08 +00:00
|
|
|
QSize layoutBounds = maximumViewportSize();
|
2020-08-15 21:48:28 +00:00
|
|
|
QStyleOptionViewItem option = viewOptions();
|
2020-08-17 10:27:14 +00:00
|
|
|
option.rect.setHeight(maxMessageHeight);
|
|
|
|
option.rect.setWidth(layoutBounds.width());
|
|
|
|
int frameAroundContents = 0;
|
|
|
|
int verticalScrollBarExtent = st->pixelMetric(QStyle::PM_ScrollBarExtent, 0, bar);
|
|
|
|
|
|
|
|
bool layedOut = false;
|
|
|
|
if (verticalScrollBarExtent != 0 && verticalScrollBarPolicy() == Qt::ScrollBarAsNeeded && m->rowCount() * approximateSingleMessageHeight < layoutBounds.height()) {
|
|
|
|
hints.clear();
|
|
|
|
layedOut = tryToCalculateGeometriesWithNoScrollbars(option, m, layoutBounds.height());
|
|
|
|
}
|
2020-08-15 21:48:28 +00:00
|
|
|
|
2020-08-17 10:27:14 +00:00
|
|
|
if (layedOut) {
|
|
|
|
bar->setRange(0, 0);
|
2021-05-01 23:03:08 +00:00
|
|
|
vo = 0;
|
2020-08-17 10:27:14 +00:00
|
|
|
} else {
|
|
|
|
int verticalMargin = 0;
|
|
|
|
if (st->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents)) {
|
|
|
|
frameAroundContents = st->pixelMetric(QStyle::PM_DefaultFrameWidth) * 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (verticalScrollBarPolicy() == Qt::ScrollBarAsNeeded) {
|
|
|
|
verticalMargin = verticalScrollBarExtent + frameAroundContents;
|
|
|
|
}
|
|
|
|
|
2021-05-01 23:03:08 +00:00
|
|
|
layoutBounds.rwidth() -= verticalMargin;
|
2020-08-17 10:27:14 +00:00
|
|
|
|
|
|
|
option.features |= QStyleOptionViewItem::WrapText;
|
|
|
|
option.rect.setWidth(layoutBounds.width());
|
|
|
|
|
|
|
|
hints.clear();
|
|
|
|
uint32_t previousOffset = 0;
|
|
|
|
for (int i = 0, size = m->rowCount(); i < size; ++i) {
|
|
|
|
QModelIndex index = m->index(i, 0, rootIndex());
|
|
|
|
int height = itemDelegate(index)->sizeHint(option, index).height();
|
|
|
|
hints.emplace_back(Hint({
|
|
|
|
false,
|
|
|
|
previousOffset,
|
|
|
|
static_cast<uint32_t>(height)
|
|
|
|
}));
|
|
|
|
previousOffset += height;
|
|
|
|
}
|
|
|
|
|
2021-05-01 23:03:08 +00:00
|
|
|
int totalHeight = previousOffset - layoutBounds.height();
|
|
|
|
if (modelState != Models::MessageFeed::complete) {
|
|
|
|
totalHeight += progressSize;
|
|
|
|
}
|
|
|
|
vo = qMax(qMin(vo, totalHeight), 0);
|
|
|
|
bar->setRange(0, totalHeight);
|
2020-08-17 10:27:14 +00:00
|
|
|
bar->setPageStep(layoutBounds.height());
|
2021-05-01 23:03:08 +00:00
|
|
|
bar->setValue(totalHeight - vo);
|
2020-08-17 10:27:14 +00:00
|
|
|
}
|
2021-02-01 22:55:15 +00:00
|
|
|
|
2021-05-01 23:03:08 +00:00
|
|
|
positionProgress();
|
|
|
|
|
2021-02-01 22:55:15 +00:00
|
|
|
if (specialDelegate) {
|
|
|
|
clearWidgetsMode = true;
|
|
|
|
}
|
2021-05-01 23:03:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
QAbstractItemView::updateGeometries();
|
2020-08-17 10:27:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool FeedView::tryToCalculateGeometriesWithNoScrollbars(const QStyleOptionViewItem& option, const QAbstractItemModel* m, uint32_t totalHeight)
|
|
|
|
{
|
|
|
|
uint32_t previousOffset = 0;
|
|
|
|
bool success = true;
|
2020-08-15 21:48:28 +00:00
|
|
|
for (int i = 0, size = m->rowCount(); i < size; ++i) {
|
2020-08-17 10:27:14 +00:00
|
|
|
QModelIndex index = m->index(i, 0, rootIndex());
|
2020-08-15 21:48:28 +00:00
|
|
|
int height = itemDelegate(index)->sizeHint(option, index).height();
|
2020-08-17 10:27:14 +00:00
|
|
|
|
|
|
|
if (previousOffset + height > totalHeight) {
|
|
|
|
success = false;
|
|
|
|
break;
|
|
|
|
}
|
2020-08-15 21:48:28 +00:00
|
|
|
hints.emplace_back(Hint({
|
|
|
|
false,
|
|
|
|
previousOffset,
|
|
|
|
static_cast<uint32_t>(height)
|
|
|
|
}));
|
|
|
|
previousOffset += height;
|
|
|
|
}
|
2020-08-17 10:27:14 +00:00
|
|
|
|
|
|
|
return success;
|
2020-08-15 21:48:28 +00:00
|
|
|
}
|
|
|
|
|
2020-08-17 10:27:14 +00:00
|
|
|
|
2020-08-15 21:48:28 +00:00
|
|
|
void FeedView::paintEvent(QPaintEvent* event)
|
|
|
|
{
|
2021-01-14 11:22:02 +00:00
|
|
|
//qDebug() << "paint" << event->rect();
|
2020-08-15 21:48:28 +00:00
|
|
|
const QAbstractItemModel* m = model();
|
2020-08-17 10:27:14 +00:00
|
|
|
QWidget* vp = viewport();
|
|
|
|
QRect zone = event->rect().translated(0, -vo);
|
|
|
|
uint32_t vph = vp->height();
|
|
|
|
int32_t y1 = zone.y();
|
|
|
|
int32_t y2 = y1 + zone.height();
|
|
|
|
|
|
|
|
bool inZone = false;
|
|
|
|
std::deque<QModelIndex> toRener;
|
|
|
|
for (std::deque<Hint>::size_type i = 0; i < hints.size(); ++i) {
|
|
|
|
const Hint& hint = hints[i];
|
|
|
|
int32_t relativeY1 = vph - hint.offset - hint.height;
|
|
|
|
if (!inZone) {
|
|
|
|
if (y2 > relativeY1) {
|
|
|
|
inZone = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (inZone) {
|
|
|
|
toRener.emplace_back(m->index(i, 0, rootIndex()));
|
|
|
|
}
|
|
|
|
if (y1 > relativeY1) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QPainter painter(vp);
|
2020-08-15 21:48:28 +00:00
|
|
|
QStyleOptionViewItem option = viewOptions();
|
2020-08-17 10:27:14 +00:00
|
|
|
option.features = QStyleOptionViewItem::WrapText;
|
2021-01-07 21:50:12 +00:00
|
|
|
QPoint cursor = vp->mapFromGlobal(QCursor::pos());
|
2020-08-15 21:48:28 +00:00
|
|
|
|
2021-04-26 16:37:36 +00:00
|
|
|
if (specialDelegate) {
|
2021-02-06 11:02:42 +00:00
|
|
|
MessageDelegate* del = static_cast<MessageDelegate*>(itemDelegate());
|
2021-04-26 16:37:36 +00:00
|
|
|
if (clearWidgetsMode) {
|
|
|
|
del->beginClearWidgets();
|
|
|
|
}
|
2021-02-01 22:55:15 +00:00
|
|
|
}
|
|
|
|
|
2020-08-17 10:27:14 +00:00
|
|
|
for (const QModelIndex& index : toRener) {
|
2020-08-15 21:48:28 +00:00
|
|
|
option.rect = visualRect(index);
|
2021-01-07 21:50:12 +00:00
|
|
|
option.state.setFlag(QStyle::State_MouseOver, option.rect.contains(cursor));
|
2020-08-15 21:48:28 +00:00
|
|
|
itemDelegate(index)->paint(&painter, option, index);
|
|
|
|
}
|
2021-02-01 22:55:15 +00:00
|
|
|
|
|
|
|
if (clearWidgetsMode && specialDelegate) {
|
2021-02-06 11:02:42 +00:00
|
|
|
MessageDelegate* del = static_cast<MessageDelegate*>(itemDelegate());
|
2021-02-01 22:55:15 +00:00
|
|
|
del->endClearWidgets();
|
|
|
|
clearWidgetsMode = false;
|
|
|
|
}
|
2021-05-03 00:35:43 +00:00
|
|
|
|
|
|
|
if (event->rect().height() == vp->height()) {
|
|
|
|
// draw the blurred drop shadow...
|
|
|
|
}
|
2020-08-15 21:48:28 +00:00
|
|
|
}
|
2020-08-17 10:27:14 +00:00
|
|
|
|
|
|
|
void FeedView::verticalScrollbarValueChanged(int value)
|
|
|
|
{
|
|
|
|
vo = verticalScrollBar()->maximum() - value;
|
|
|
|
|
2021-05-01 23:03:08 +00:00
|
|
|
positionProgress();
|
|
|
|
|
2021-02-01 22:55:15 +00:00
|
|
|
if (specialDelegate) {
|
|
|
|
clearWidgetsMode = true;
|
|
|
|
}
|
|
|
|
|
2021-05-03 00:35:43 +00:00
|
|
|
if (modelState == Models::MessageFeed::incomplete && value < progressSize) {
|
|
|
|
model()->fetchMore(rootIndex());
|
|
|
|
}
|
|
|
|
|
2020-08-17 10:27:14 +00:00
|
|
|
QAbstractItemView::verticalScrollbarValueChanged(vo);
|
|
|
|
}
|
2020-08-20 21:32:30 +00:00
|
|
|
|
2021-01-07 21:50:12 +00:00
|
|
|
void FeedView::mouseMoveEvent(QMouseEvent* event)
|
|
|
|
{
|
|
|
|
if (!isVisible()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QAbstractItemView::mouseMoveEvent(event);
|
|
|
|
}
|
|
|
|
|
2021-04-30 20:07:00 +00:00
|
|
|
void FeedView::resizeEvent(QResizeEvent* event)
|
|
|
|
{
|
|
|
|
QAbstractItemView::resizeEvent(event);
|
2021-05-01 23:03:08 +00:00
|
|
|
|
|
|
|
positionProgress();
|
2021-05-03 00:35:43 +00:00
|
|
|
emit resized();
|
2021-04-30 20:07:00 +00:00
|
|
|
}
|
|
|
|
|
2021-05-01 23:03:08 +00:00
|
|
|
void FeedView::positionProgress()
|
|
|
|
{
|
|
|
|
QSize layoutBounds = maximumViewportSize();
|
|
|
|
int progressPosition = layoutBounds.height() - progressSize;
|
|
|
|
std::deque<Hint>::size_type size = hints.size();
|
|
|
|
if (size > 0) {
|
|
|
|
const Hint& hint = hints[size - 1];
|
|
|
|
progressPosition -= hint.offset + hint.height;
|
|
|
|
}
|
|
|
|
progressPosition += vo;
|
|
|
|
|
|
|
|
progress.move((width() - progressSize) / 2, progressPosition);
|
|
|
|
}
|
2021-01-07 21:50:12 +00:00
|
|
|
|
2020-08-20 21:32:30 +00:00
|
|
|
QFont FeedView::getFont() const
|
|
|
|
{
|
|
|
|
return viewOptions().font;
|
|
|
|
}
|
2021-02-01 22:55:15 +00:00
|
|
|
|
|
|
|
void FeedView::setItemDelegate(QAbstractItemDelegate* delegate)
|
|
|
|
{
|
2021-02-06 11:02:42 +00:00
|
|
|
if (specialDelegate) {
|
|
|
|
MessageDelegate* del = static_cast<MessageDelegate*>(itemDelegate());
|
|
|
|
disconnect(del, &MessageDelegate::buttonPushed, this, &FeedView::onMessageButtonPushed);
|
2021-04-28 20:26:19 +00:00
|
|
|
disconnect(del, &MessageDelegate::invalidPath, this, &FeedView::onMessageInvalidPath);
|
2021-02-06 11:02:42 +00:00
|
|
|
}
|
|
|
|
|
2021-02-01 22:55:15 +00:00
|
|
|
QAbstractItemView::setItemDelegate(delegate);
|
|
|
|
|
|
|
|
MessageDelegate* del = dynamic_cast<MessageDelegate*>(delegate);
|
|
|
|
if (del) {
|
|
|
|
specialDelegate = true;
|
2021-02-06 11:02:42 +00:00
|
|
|
connect(del, &MessageDelegate::buttonPushed, this, &FeedView::onMessageButtonPushed);
|
2021-04-28 20:26:19 +00:00
|
|
|
connect(del, &MessageDelegate::invalidPath, this, &FeedView::onMessageInvalidPath);
|
2021-02-01 22:55:15 +00:00
|
|
|
} else {
|
|
|
|
specialDelegate = false;
|
|
|
|
}
|
|
|
|
}
|
2021-02-06 11:02:42 +00:00
|
|
|
|
2021-04-30 20:07:00 +00:00
|
|
|
void FeedView::setModel(QAbstractItemModel* p_model)
|
2021-02-06 11:02:42 +00:00
|
|
|
{
|
2021-04-30 20:07:00 +00:00
|
|
|
if (specialModel) {
|
|
|
|
Models::MessageFeed* feed = static_cast<Models::MessageFeed*>(model());
|
|
|
|
disconnect(feed, &Models::MessageFeed::syncStateChange, this, &FeedView::onModelSyncStateChange);
|
|
|
|
}
|
2021-02-06 11:02:42 +00:00
|
|
|
|
2021-04-30 20:07:00 +00:00
|
|
|
QAbstractItemView::setModel(p_model);
|
|
|
|
|
|
|
|
Models::MessageFeed* feed = dynamic_cast<Models::MessageFeed*>(p_model);
|
2021-02-06 11:02:42 +00:00
|
|
|
if (feed) {
|
2021-04-30 20:07:00 +00:00
|
|
|
onModelSyncStateChange(feed->getSyncState());
|
2021-02-06 11:02:42 +00:00
|
|
|
specialModel = true;
|
2021-04-30 20:07:00 +00:00
|
|
|
connect(feed, &Models::MessageFeed::syncStateChange, this, &FeedView::onModelSyncStateChange);
|
2021-02-06 11:02:42 +00:00
|
|
|
} else {
|
2021-04-30 20:07:00 +00:00
|
|
|
onModelSyncStateChange(Models::MessageFeed::complete);
|
2021-02-06 11:02:42 +00:00
|
|
|
specialModel = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FeedView::onMessageButtonPushed(const QString& messageId, bool download)
|
|
|
|
{
|
|
|
|
if (specialModel) {
|
|
|
|
Models::MessageFeed* feed = static_cast<Models::MessageFeed*>(model());
|
|
|
|
|
|
|
|
if (download) {
|
|
|
|
feed->downloadAttachment(messageId);
|
|
|
|
} else {
|
|
|
|
feed->uploadAttachment(messageId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-04-28 20:26:19 +00:00
|
|
|
|
|
|
|
void FeedView::onMessageInvalidPath(const QString& messageId)
|
|
|
|
{
|
|
|
|
if (specialModel) {
|
|
|
|
Models::MessageFeed* feed = static_cast<Models::MessageFeed*>(model());
|
|
|
|
feed->reportLocalPathInvalid(messageId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-30 20:07:00 +00:00
|
|
|
void FeedView::onModelSyncStateChange(Models::MessageFeed::SyncState state)
|
|
|
|
{
|
2021-05-01 23:03:08 +00:00
|
|
|
bool needToUpdateGeometry = false;
|
2021-04-30 20:07:00 +00:00
|
|
|
if (modelState != state) {
|
2021-05-01 23:03:08 +00:00
|
|
|
if (state == Models::MessageFeed::complete || modelState == Models::MessageFeed::complete) {
|
|
|
|
needToUpdateGeometry = true;
|
|
|
|
}
|
2021-04-30 20:07:00 +00:00
|
|
|
modelState = state;
|
|
|
|
|
|
|
|
if (state == Models::MessageFeed::syncing) {
|
|
|
|
progress.show();
|
|
|
|
progress.start();
|
|
|
|
} else {
|
|
|
|
progress.stop();
|
|
|
|
progress.hide();
|
|
|
|
}
|
|
|
|
}
|
2021-05-01 23:03:08 +00:00
|
|
|
|
|
|
|
if (needToUpdateGeometry) {
|
|
|
|
scheduleDelayedItemsLayout();
|
|
|
|
}
|
2021-04-30 20:07:00 +00:00
|
|
|
}
|