mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-02 02:24:58 -05:00
Merge pull request #2719 from csoler/v0.6-BugFixing_28
fixed layout update problem when switching channels
This commit is contained in:
commit
e1e95a1562
@ -63,7 +63,7 @@ void RsGxsChannelPostsModel::setMode(TreeMode mode)
|
||||
if(mode == TREE_MODE_LIST)
|
||||
setNumColumns(2);
|
||||
|
||||
triggerViewUpdate();
|
||||
triggerViewUpdate(true,true);
|
||||
}
|
||||
|
||||
void RsGxsChannelPostsModel::computeCommentCounts( std::vector<RsGxsChannelPost>& posts, std::vector<RsGxsComment>& comments)
|
||||
@ -118,12 +118,15 @@ void RsGxsChannelPostsModel::preMods()
|
||||
}
|
||||
void RsGxsChannelPostsModel::postMods()
|
||||
{
|
||||
triggerViewUpdate();
|
||||
emit layoutChanged();
|
||||
}
|
||||
void RsGxsChannelPostsModel::triggerViewUpdate()
|
||||
void RsGxsChannelPostsModel::triggerViewUpdate(bool data_changed, bool layout_changed)
|
||||
{
|
||||
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(rowCount()-1,mColumns-1,(void*)NULL));
|
||||
if(data_changed)
|
||||
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)
|
||||
@ -316,17 +319,8 @@ bool RsGxsChannelPostsModel::setNumColumns(int n)
|
||||
|
||||
preMods();
|
||||
|
||||
beginResetModel();
|
||||
endResetModel();
|
||||
|
||||
mColumns = n;
|
||||
|
||||
if (rowCount()>0)
|
||||
{
|
||||
beginInsertRows(QModelIndex(),0,rowCount()-1);
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
postMods();
|
||||
|
||||
return true;
|
||||
@ -548,7 +542,7 @@ void RsGxsChannelPostsModel::updateSinglePost(const RsGxsChannelPost& post,std::
|
||||
uint32_t count;
|
||||
updateFilter(count);
|
||||
|
||||
triggerViewUpdate();
|
||||
triggerViewUpdate(true,false);
|
||||
}
|
||||
|
||||
void RsGxsChannelPostsModel::setPosts(const RsGxsChannelGroup& group, std::vector<RsGxsChannelPost>& posts)
|
||||
|
@ -115,7 +115,7 @@ public:
|
||||
void updateChannel(const RsGxsGroupId& channel_group_id);
|
||||
const RsGxsGroupId& currentGroupId() const;
|
||||
|
||||
void triggerViewUpdate();
|
||||
void triggerViewUpdate(bool data_changed,bool layout_changed);
|
||||
|
||||
// sets the number of columns. Returns 0 if nothing changes.
|
||||
bool setNumColumns(int n);
|
||||
|
@ -92,9 +92,9 @@ Q_DECLARE_METATYPE(ChannelPostFileInfo)
|
||||
int ChannelPostDelegate::cellSize(int col,const QFont& font,uint32_t parent_width) const
|
||||
{
|
||||
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
|
||||
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)
|
||||
@ -279,18 +279,18 @@ void ChannelPostDelegate::setWidgetGrid(bool use_grid)
|
||||
|
||||
QWidget *ChannelPostFilesDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/*option*/, const QModelIndex& index) const
|
||||
{
|
||||
ChannelPostFileInfo file = index.data(Qt::UserRole).value<ChannelPostFileInfo>() ;
|
||||
ChannelPostFileInfo file = index.data(Qt::UserRole).value<ChannelPostFileInfo>() ;
|
||||
|
||||
if(index.column() == RsGxsChannelPostFilesModel::COLUMN_FILES_FILE)
|
||||
{
|
||||
if(index.column() == RsGxsChannelPostFilesModel::COLUMN_FILES_FILE)
|
||||
{
|
||||
GxsChannelFilesStatusWidget* w = new GxsChannelFilesStatusWidget(file,parent,true);
|
||||
w->setFocusPolicy(Qt::StrongFocus);
|
||||
connect(w,SIGNAL(onButtonClick()),this->parent(),SLOT(updateDAll_PB()));
|
||||
|
||||
return w;
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
return w;
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
void ChannelPostFilesDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
|
||||
{
|
||||
@ -392,7 +392,7 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI
|
||||
|
||||
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)));
|
||||
|
||||
ui->channelPostFiles_TV->setModel(mChannelPostFilesModel = new RsGxsChannelPostFilesModel(this));
|
||||
@ -517,23 +517,33 @@ void GxsChannelPostsWidgetWithModel::currentTabChanged(int t)
|
||||
case CHANNEL_TABS_POSTS:
|
||||
ui->showUnread_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;
|
||||
}
|
||||
}
|
||||
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)
|
||||
ui->postsTree->setColumnWidth(i,mChannelPostsDelegate->cellSize(i,font(),ui->postsTree->width()));
|
||||
|
||||
QSize s = ui->postsTree->size();
|
||||
|
||||
int n_columns = std::max(1,(int)floor(s.width() / (mChannelPostsDelegate->cellSize(0,font(),s.width()))));
|
||||
|
||||
mChannelPostsModel->setNumColumns(n_columns); // forces the update
|
||||
|
||||
ui->postsTree->dataChanged(QModelIndex(),QModelIndex());
|
||||
if(what_to_do)
|
||||
mChannelPostsModel->triggerViewUpdate(true,false);
|
||||
else
|
||||
mChannelPostsModel->triggerViewUpdate(false,true);
|
||||
}
|
||||
|
||||
void GxsChannelPostsWidgetWithModel::sortColumnPostFiles(int col,Qt::SortOrder so)
|
||||
@ -639,7 +649,7 @@ void GxsChannelPostsWidgetWithModel::switchView()
|
||||
selectItem(msg_id);
|
||||
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
|
||||
// we have to call it again here.
|
||||
}
|
||||
@ -1067,8 +1077,9 @@ void GxsChannelPostsWidgetWithModel::postChannelPostLoad()
|
||||
best = i;
|
||||
|
||||
mChannelPostsDelegate->setAspectRatio(static_cast<ChannelPostThumbnailView::AspectRatio>(best));
|
||||
mChannelPostsModel->triggerViewUpdate();
|
||||
handlePostsTreeSizeChange(ui->postsTree->size(),true); // force the update
|
||||
|
||||
updateZoomFactor(0);
|
||||
}
|
||||
|
||||
void GxsChannelPostsWidgetWithModel::updateDisplay(bool update_group_data,bool update_posts)
|
||||
|
@ -154,7 +154,7 @@ private slots:
|
||||
void editPost();
|
||||
void postContextMenu(const QPoint&);
|
||||
void copyMessageLink();
|
||||
void updateZoomFactor(bool zoom_or_unzoom);
|
||||
void onUpdateZoomFactor(bool zoom_or_unzoom);
|
||||
void switchView();
|
||||
void switchOnlyUnread(bool b);
|
||||
void markMessageUnread();
|
||||
@ -168,7 +168,8 @@ public slots:
|
||||
void copyChannelFilesLink();
|
||||
|
||||
private:
|
||||
void processSettings(bool load);
|
||||
void updateZoomFactor(int what_to_do); // -1=unzoom, 0=nothing, 1=zoom
|
||||
void processSettings(bool load);
|
||||
RsGxsMessageId getCurrentItemId() const;
|
||||
void selectItem(const RsGxsMessageId& msg_id);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user