Merge pull request #2719 from csoler/v0.6-BugFixing_28

fixed layout update problem when switching channels
This commit is contained in:
csoler 2023-04-23 13:15:01 +02:00 committed by GitHub
commit e1e95a1562
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 38 deletions

View File

@ -63,7 +63,7 @@ void RsGxsChannelPostsModel::setMode(TreeMode mode)
if(mode == TREE_MODE_LIST) if(mode == TREE_MODE_LIST)
setNumColumns(2); setNumColumns(2);
triggerViewUpdate(); triggerViewUpdate(true,true);
} }
void RsGxsChannelPostsModel::computeCommentCounts( std::vector<RsGxsChannelPost>& posts, std::vector<RsGxsComment>& comments) void RsGxsChannelPostsModel::computeCommentCounts( std::vector<RsGxsChannelPost>& posts, std::vector<RsGxsComment>& comments)
@ -118,12 +118,15 @@ void RsGxsChannelPostsModel::preMods()
} }
void RsGxsChannelPostsModel::postMods() void RsGxsChannelPostsModel::postMods()
{ {
triggerViewUpdate();
emit layoutChanged(); emit layoutChanged();
} }
void RsGxsChannelPostsModel::triggerViewUpdate() void RsGxsChannelPostsModel::triggerViewUpdate(bool data_changed, bool layout_changed)
{ {
if(data_changed)
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(rowCount()-1,mColumns-1,(void*)NULL)); emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(rowCount()-1,mColumns-1,(void*)NULL));
if(layout_changed)
emit layoutChanged();
} }
void RsGxsChannelPostsModel::getFilesList(std::list<ChannelPostFileInfo>& files) void RsGxsChannelPostsModel::getFilesList(std::list<ChannelPostFileInfo>& files)
@ -316,17 +319,8 @@ bool RsGxsChannelPostsModel::setNumColumns(int n)
preMods(); preMods();
beginResetModel();
endResetModel();
mColumns = n; mColumns = n;
if (rowCount()>0)
{
beginInsertRows(QModelIndex(),0,rowCount()-1);
endInsertRows();
}
postMods(); postMods();
return true; return true;
@ -548,7 +542,7 @@ void RsGxsChannelPostsModel::updateSinglePost(const RsGxsChannelPost& post,std::
uint32_t count; uint32_t count;
updateFilter(count); updateFilter(count);
triggerViewUpdate(); triggerViewUpdate(true,false);
} }
void RsGxsChannelPostsModel::setPosts(const RsGxsChannelGroup& group, std::vector<RsGxsChannelPost>& posts) void RsGxsChannelPostsModel::setPosts(const RsGxsChannelGroup& group, std::vector<RsGxsChannelPost>& posts)

View File

@ -115,7 +115,7 @@ public:
void updateChannel(const RsGxsGroupId& channel_group_id); void updateChannel(const RsGxsGroupId& channel_group_id);
const RsGxsGroupId& currentGroupId() const; const RsGxsGroupId& currentGroupId() const;
void triggerViewUpdate(); void triggerViewUpdate(bool data_changed,bool layout_changed);
// sets the number of columns. Returns 0 if nothing changes. // sets the number of columns. Returns 0 if nothing changes.
bool setNumColumns(int n); bool setNumColumns(int n);

View File

@ -92,9 +92,9 @@ Q_DECLARE_METATYPE(ChannelPostFileInfo)
int ChannelPostDelegate::cellSize(int col,const QFont& font,uint32_t parent_width) const int ChannelPostDelegate::cellSize(int col,const QFont& font,uint32_t parent_width) const
{ {
if(mUseGrid || col==0) if(mUseGrid || col==0)
return mZoom*COLUMN_SIZE_FONT_FACTOR_W*QFontMetricsF(font).height(); return (int)floor(mZoom*COLUMN_SIZE_FONT_FACTOR_W*QFontMetricsF(font).height());
else else
return 0.8*parent_width - mZoom*COLUMN_SIZE_FONT_FACTOR_W*QFontMetricsF(font).height(); return (int)floor(0.8*parent_width - mZoom*COLUMN_SIZE_FONT_FACTOR_W*QFontMetricsF(font).height());
} }
void ChannelPostDelegate::zoom(bool zoom_or_unzoom) void ChannelPostDelegate::zoom(bool zoom_or_unzoom)
@ -392,7 +392,7 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI
mChannelPostsDelegate->setAspectRatio(ChannelPostThumbnailView::ASPECT_RATIO_16_9); mChannelPostsDelegate->setAspectRatio(ChannelPostThumbnailView::ASPECT_RATIO_16_9);
connect(ui->postsTree,SIGNAL(zoomRequested(bool)),this,SLOT(updateZoomFactor(bool))); connect(ui->postsTree,SIGNAL(zoomRequested(bool)),this,SLOT(onUpdateZoomFactor(bool)));
connect(ui->commentsDialog,SIGNAL(commentsLoaded(int)),this,SLOT(updateCommentsCount(int))); connect(ui->commentsDialog,SIGNAL(commentsLoaded(int)),this,SLOT(updateCommentsCount(int)));
ui->channelPostFiles_TV->setModel(mChannelPostFilesModel = new RsGxsChannelPostFilesModel(this)); ui->channelPostFiles_TV->setModel(mChannelPostFilesModel = new RsGxsChannelPostFilesModel(this));
@ -517,23 +517,33 @@ void GxsChannelPostsWidgetWithModel::currentTabChanged(int t)
case CHANNEL_TABS_POSTS: case CHANNEL_TABS_POSTS:
ui->showUnread_TB->setHidden(false); ui->showUnread_TB->setHidden(false);
ui->viewType_TB->setHidden(false); ui->viewType_TB->setHidden(false);
updateZoomFactor(0); // fixes a bug due to the widget now knowing its size when not displayed.
break; break;
} }
} }
void GxsChannelPostsWidgetWithModel::updateZoomFactor(bool zoom_or_unzoom) void GxsChannelPostsWidgetWithModel::onUpdateZoomFactor(bool zoom_or_unzoom)
{ {
mChannelPostsDelegate->zoom(zoom_or_unzoom); if(zoom_or_unzoom)
updateZoomFactor(1);
else
updateZoomFactor(-1);
}
void GxsChannelPostsWidgetWithModel::updateZoomFactor(int what_to_do)
{
if(what_to_do != 0)
mChannelPostsDelegate->zoom(what_to_do > 0);
QSize s = ui->postsTree->size();
int n_columns = std::max(1,(int)floor(s.width() / (float)(mChannelPostsDelegate->cellSize(0,font(),s.width()))));
mChannelPostsModel->setNumColumns(n_columns); // forces the update
for(int i=0;i<mChannelPostsModel->columnCount();++i) for(int i=0;i<mChannelPostsModel->columnCount();++i)
ui->postsTree->setColumnWidth(i,mChannelPostsDelegate->cellSize(i,font(),ui->postsTree->width())); ui->postsTree->setColumnWidth(i,mChannelPostsDelegate->cellSize(i,font(),ui->postsTree->width()));
QSize s = ui->postsTree->size(); if(what_to_do)
mChannelPostsModel->triggerViewUpdate(true,false);
int n_columns = std::max(1,(int)floor(s.width() / (mChannelPostsDelegate->cellSize(0,font(),s.width())))); else
mChannelPostsModel->triggerViewUpdate(false,true);
mChannelPostsModel->setNumColumns(n_columns); // forces the update
ui->postsTree->dataChanged(QModelIndex(),QModelIndex());
} }
void GxsChannelPostsWidgetWithModel::sortColumnPostFiles(int col,Qt::SortOrder so) void GxsChannelPostsWidgetWithModel::sortColumnPostFiles(int col,Qt::SortOrder so)
@ -639,7 +649,7 @@ void GxsChannelPostsWidgetWithModel::switchView()
selectItem(msg_id); selectItem(msg_id);
ui->postsTree->setFocus(); ui->postsTree->setFocus();
mChannelPostsModel->triggerViewUpdate(); // This is already called by setMode(), but the model cannot know how many mChannelPostsModel->triggerViewUpdate(false,true); // This is already called by setMode(), but the model cannot know how many
// columns is actually has until we call handlePostsTreeSizeChange(), so // columns is actually has until we call handlePostsTreeSizeChange(), so
// we have to call it again here. // we have to call it again here.
} }
@ -1067,8 +1077,9 @@ void GxsChannelPostsWidgetWithModel::postChannelPostLoad()
best = i; best = i;
mChannelPostsDelegate->setAspectRatio(static_cast<ChannelPostThumbnailView::AspectRatio>(best)); mChannelPostsDelegate->setAspectRatio(static_cast<ChannelPostThumbnailView::AspectRatio>(best));
mChannelPostsModel->triggerViewUpdate();
handlePostsTreeSizeChange(ui->postsTree->size(),true); // force the update handlePostsTreeSizeChange(ui->postsTree->size(),true); // force the update
updateZoomFactor(0);
} }
void GxsChannelPostsWidgetWithModel::updateDisplay(bool update_group_data,bool update_posts) void GxsChannelPostsWidgetWithModel::updateDisplay(bool update_group_data,bool update_posts)

View File

@ -154,7 +154,7 @@ private slots:
void editPost(); void editPost();
void postContextMenu(const QPoint&); void postContextMenu(const QPoint&);
void copyMessageLink(); void copyMessageLink();
void updateZoomFactor(bool zoom_or_unzoom); void onUpdateZoomFactor(bool zoom_or_unzoom);
void switchView(); void switchView();
void switchOnlyUnread(bool b); void switchOnlyUnread(bool b);
void markMessageUnread(); void markMessageUnread();
@ -168,6 +168,7 @@ public slots:
void copyChannelFilesLink(); void copyChannelFilesLink();
private: private:
void updateZoomFactor(int what_to_do); // -1=unzoom, 0=nothing, 1=zoom
void processSettings(bool load); void processSettings(bool load);
RsGxsMessageId getCurrentItemId() const; RsGxsMessageId getCurrentItemId() const;
void selectItem(const RsGxsMessageId& msg_id); void selectItem(const RsGxsMessageId& msg_id);