bug fixing, better progres indicator positioning

This commit is contained in:
Blue 2021-05-02 02:03:08 +03:00
parent 0973cb2991
commit 216dcd29e9
3 changed files with 50 additions and 16 deletions

View File

@ -68,8 +68,8 @@ QModelIndex FeedView::indexAt(const QPoint& point) const
uint32_t y = vh - point.y() + vo; uint32_t y = vh - point.y() + vo;
for (std::deque<Hint>::size_type i = 0; i < hints.size(); ++i) { for (std::deque<Hint>::size_type i = 0; i < hints.size(); ++i) {
if (hints[i].offset >= y) { if (hints[i].offset + hints[i].height >= y) {
return model()->index(i - 1, 0, rootIndex()); return model()->index(i, 0, rootIndex());
} }
} }
@ -82,11 +82,12 @@ void FeedView::scrollTo(const QModelIndex& index, QAbstractItemView::ScrollHint
QRect FeedView::visualRect(const QModelIndex& index) const QRect FeedView::visualRect(const QModelIndex& index) const
{ {
if (!index.isValid() || index.row() >= hints.size()) { unsigned int row = index.row();
qDebug() << "visualRect for" << index.row(); if (!index.isValid() || row >= hints.size()) {
qDebug() << "visualRect for" << row;
return QRect(); return QRect();
} else { } else {
const Hint& hint = hints.at(index.row()); const Hint& hint = hints.at(row);
const QWidget* vp = viewport(); const QWidget* vp = viewport();
return QRect(0, vp->height() - hint.height - hint.offset + vo, vp->width(), hint.height); return QRect(0, vp->height() - hint.height - hint.offset + vo, vp->width(), hint.height);
} }
@ -123,8 +124,9 @@ QRegion FeedView::visualRegionForSelection(const QItemSelection& selection) cons
void FeedView::rowsInserted(const QModelIndex& parent, int start, int end) void FeedView::rowsInserted(const QModelIndex& parent, int start, int end)
{ {
updateGeometries();
QAbstractItemView::rowsInserted(parent, start, end); QAbstractItemView::rowsInserted(parent, start, end);
scheduleDelayedItemsLayout();
} }
void FeedView::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles) void FeedView::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles)
@ -132,7 +134,7 @@ void FeedView::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottom
if (specialDelegate) { if (specialDelegate) {
for (int role : roles) { for (int role : roles) {
if (geometryChangingRoles.count(role) != 0) { if (geometryChangingRoles.count(role) != 0) {
updateGeometries(); //to recalculate layout only if there are some geometry changing modifications scheduleDelayedItemsLayout(); //to recalculate layout only if there are some geometry changing modifications
break; break;
} }
} }
@ -145,11 +147,9 @@ void FeedView::updateGeometries()
qDebug() << "updateGeometries"; qDebug() << "updateGeometries";
QScrollBar* bar = verticalScrollBar(); QScrollBar* bar = verticalScrollBar();
QAbstractItemView::updateGeometries();
const QStyle* st = style(); const QStyle* st = style();
const QAbstractItemModel* m = model(); const QAbstractItemModel* m = model();
QRect layoutBounds = QRect(QPoint(), maximumViewportSize()); QSize layoutBounds = maximumViewportSize();
QStyleOptionViewItem option = viewOptions(); QStyleOptionViewItem option = viewOptions();
option.rect.setHeight(maxMessageHeight); option.rect.setHeight(maxMessageHeight);
option.rect.setWidth(layoutBounds.width()); option.rect.setWidth(layoutBounds.width());
@ -164,6 +164,7 @@ void FeedView::updateGeometries()
if (layedOut) { if (layedOut) {
bar->setRange(0, 0); bar->setRange(0, 0);
vo = 0;
} else { } else {
int verticalMargin = 0; int verticalMargin = 0;
if (st->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents)) { if (st->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents)) {
@ -174,7 +175,7 @@ void FeedView::updateGeometries()
verticalMargin = verticalScrollBarExtent + frameAroundContents; verticalMargin = verticalScrollBarExtent + frameAroundContents;
} }
layoutBounds.adjust(0, 0, -verticalMargin, 0); layoutBounds.rwidth() -= verticalMargin;
option.features |= QStyleOptionViewItem::WrapText; option.features |= QStyleOptionViewItem::WrapText;
option.rect.setWidth(layoutBounds.width()); option.rect.setWidth(layoutBounds.width());
@ -192,14 +193,24 @@ void FeedView::updateGeometries()
previousOffset += height; previousOffset += height;
} }
bar->setRange(0, previousOffset - layoutBounds.height()); int totalHeight = previousOffset - layoutBounds.height();
bar->setPageStep(layoutBounds.height()); if (modelState != Models::MessageFeed::complete) {
bar->setValue(previousOffset - layoutBounds.height() - vo); totalHeight += progressSize;
} }
vo = qMax(qMin(vo, totalHeight), 0);
bar->setRange(0, totalHeight);
bar->setPageStep(layoutBounds.height());
bar->setValue(totalHeight - vo);
}
positionProgress();
if (specialDelegate) { if (specialDelegate) {
clearWidgetsMode = true; clearWidgetsMode = true;
} }
QAbstractItemView::updateGeometries();
} }
bool FeedView::tryToCalculateGeometriesWithNoScrollbars(const QStyleOptionViewItem& option, const QAbstractItemModel* m, uint32_t totalHeight) bool FeedView::tryToCalculateGeometriesWithNoScrollbars(const QStyleOptionViewItem& option, const QAbstractItemModel* m, uint32_t totalHeight)
@ -283,6 +294,8 @@ void FeedView::verticalScrollbarValueChanged(int value)
{ {
vo = verticalScrollBar()->maximum() - value; vo = verticalScrollBar()->maximum() - value;
positionProgress();
if (specialDelegate) { if (specialDelegate) {
clearWidgetsMode = true; clearWidgetsMode = true;
} }
@ -301,11 +314,24 @@ void FeedView::mouseMoveEvent(QMouseEvent* event)
void FeedView::resizeEvent(QResizeEvent* event) void FeedView::resizeEvent(QResizeEvent* event)
{ {
progress.move((width() - progressSize) / 2, 0);
QAbstractItemView::resizeEvent(event); QAbstractItemView::resizeEvent(event);
positionProgress();
} }
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);
}
QFont FeedView::getFont() const QFont FeedView::getFont() const
{ {
@ -375,7 +401,11 @@ void FeedView::onMessageInvalidPath(const QString& messageId)
void FeedView::onModelSyncStateChange(Models::MessageFeed::SyncState state) void FeedView::onModelSyncStateChange(Models::MessageFeed::SyncState state)
{ {
bool needToUpdateGeometry = false;
if (modelState != state) { if (modelState != state) {
if (state == Models::MessageFeed::complete || modelState == Models::MessageFeed::complete) {
needToUpdateGeometry = true;
}
modelState = state; modelState = state;
if (state == Models::MessageFeed::syncing) { if (state == Models::MessageFeed::syncing) {
@ -386,4 +416,8 @@ void FeedView::onModelSyncStateChange(Models::MessageFeed::SyncState state)
progress.hide(); progress.hide();
} }
} }
if (needToUpdateGeometry) {
scheduleDelayedItemsLayout();
}
} }

View File

@ -69,6 +69,7 @@ protected:
private: private:
bool tryToCalculateGeometriesWithNoScrollbars(const QStyleOptionViewItem& option, const QAbstractItemModel* model, uint32_t totalHeight); bool tryToCalculateGeometriesWithNoScrollbars(const QStyleOptionViewItem& option, const QAbstractItemModel* model, uint32_t totalHeight);
void positionProgress();
private: private:
struct Hint { struct Hint {

View File

@ -392,7 +392,6 @@ void Conversation::onFeedMessage(const Shared::Message& msg)
void Conversation::onMessage(const Shared::Message& msg) void Conversation::onMessage(const Shared::Message& msg)
{ {
qDebug() << window()->windowState();
if (!msg.getForwarded()) { if (!msg.getForwarded()) {
QApplication::alert(this); QApplication::alert(this);
if (window()->windowState().testFlag(Qt::WindowMinimized)) { if (window()->windowState().testFlag(Qt::WindowMinimized)) {