fixed update of sizes in channel list view

This commit is contained in:
csoler 2020-08-28 14:07:32 +02:00
parent 81e08d0004
commit 03ac2eb53c
3 changed files with 15 additions and 16 deletions

View File

@ -69,8 +69,9 @@ void RsGxsChannelPostsModel::setMode(TreeMode mode)
if(mode == TREE_MODE_LIST)
setNumColumns(2);
// needs some update here
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(rowCount()-1,mColumns-1,(void*)NULL));
}
void RsGxsChannelPostsModel::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
{
const RsGxsChannelEvent *e = dynamic_cast<const RsGxsChannelEvent*>(event.get());
@ -115,7 +116,7 @@ void RsGxsChannelPostsModel::handleEvent_main_thread(std::shared_ptr<const RsEve
{
mPosts[j] = posts[i];
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mFilteredPosts.size(),mColumns-1,(void*)NULL));
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(rowCount()-1,mColumns-1,(void*)NULL));
}
}
},this);
@ -145,7 +146,7 @@ void RsGxsChannelPostsModel::postMods()
{
endResetModel();
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mFilteredPosts.size(),mColumns-1,(void*)NULL));
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(rowCount()-1,mColumns-1,(void*)NULL));
}
void RsGxsChannelPostsModel::getFilesList(std::list<ChannelPostFileInfo>& files)

View File

@ -89,7 +89,7 @@ int ChannelPostDelegate::cellSize(int col,const QFont& font,uint32_t parent_widt
if(mUseGrid || col==0)
return mZoom*COLUMN_SIZE_FONT_FACTOR_W*QFontMetricsF(font).height();
else
return parent_width - mZoom*COLUMN_SIZE_FONT_FACTOR_W*QFontMetricsF(font).height();
return 0.8*parent_width - mZoom*COLUMN_SIZE_FONT_FACTOR_W*QFontMetricsF(font).height();
}
void ChannelPostDelegate::zoom(bool zoom_or_unzoom)
@ -432,23 +432,21 @@ void GxsChannelPostsWidgetWithModel::switchView()
{
mChannelPostsDelegate->setWidgetGrid(false);
mChannelPostsModel->setMode(RsGxsChannelPostsModel::TREE_MODE_LIST);
ui->postsTree->setColumnWidth(0,ui->postsTree->width());
//ui->postsTree->setUniformRowHeights(true);
}
else
{
mChannelPostsDelegate->setWidgetGrid(true);
mChannelPostsModel->setMode(RsGxsChannelPostsModel::TREE_MODE_GRID);
for(int i=0;i<mChannelPostsModel->columnCount();++i)
ui->postsTree->setColumnWidth(i,mChannelPostsDelegate->cellSize(i,font(),ui->postsTree->width()));
//ui->postsTree->setUniformRowHeights(false);
handlePostsTreeSizeChange(ui->postsTree->size());
handlePostsTreeSizeChange(ui->postsTree->size(),true);
}
for(int i=0;i<mChannelPostsModel->columnCount();++i)
ui->postsTree->setColumnWidth(i,mChannelPostsDelegate->cellSize(i,font(),ui->postsTree->width()));
ui->postsTree->dataChanged(QModelIndex(),QModelIndex()); // forces update of the whole tree
}
void GxsChannelPostsWidgetWithModel::copyMessageLink()
{
try
@ -490,10 +488,10 @@ void GxsChannelPostsWidgetWithModel::editPost()
msgDialog->show();
}
void GxsChannelPostsWidgetWithModel::handlePostsTreeSizeChange(QSize s)
void GxsChannelPostsWidgetWithModel::handlePostsTreeSizeChange(QSize s,bool force)
{
int n_columns = std::max(1,(int)floor(s.width() / (mChannelPostsDelegate->cellSize(0,font(),ui->postsTree->width()))));
std::cerr << "nb columns: " << n_columns << std::endl;
std::cerr << "nb columns: " << n_columns << " current count=" << mChannelPostsModel->columnCount() << std::endl;
if(n_columns != mChannelPostsModel->columnCount())
mChannelPostsModel->setNumColumns(n_columns);

View File

@ -144,7 +144,7 @@ private slots:
void filterChanged(QString);
void setViewMode(int viewMode);
void settingsChanged();
void handlePostsTreeSizeChange(QSize s);
void handlePostsTreeSizeChange(QSize s, bool force=false);
void postChannelPostLoad();
void editPost();
void postContextMenu(const QPoint&);