mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-12-18 10:02:41 -05:00
keep focus on current item when changing view mode
This commit is contained in:
parent
f17fae4519
commit
11ecd6fbd1
2 changed files with 26 additions and 0 deletions
|
|
@ -460,8 +460,29 @@ void GxsChannelPostsWidgetWithModel::postContextMenu(const QPoint&)
|
||||||
menu.exec(QCursor::pos());
|
menu.exec(QCursor::pos());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RsGxsMessageId GxsChannelPostsWidgetWithModel::getCurrentItemId() const
|
||||||
|
{
|
||||||
|
RsGxsMessageId selected_msg_id ;
|
||||||
|
QModelIndex index = ui->postsTree->selectionModel()->currentIndex();
|
||||||
|
|
||||||
|
if(index.isValid())
|
||||||
|
selected_msg_id = index.data(Qt::UserRole).value<RsGxsChannelPost>().mMeta.mMsgId ;
|
||||||
|
|
||||||
|
return selected_msg_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GxsChannelPostsWidgetWithModel::selectItem(const RsGxsMessageId& msg_id)
|
||||||
|
{
|
||||||
|
auto index = mChannelPostsModel->getIndexOfMessage(msg_id);
|
||||||
|
|
||||||
|
ui->postsTree->selectionModel()->setCurrentIndex(index,QItemSelectionModel::ClearAndSelect);
|
||||||
|
ui->postsTree->scrollTo(index);//May change if model reloaded
|
||||||
|
}
|
||||||
|
|
||||||
void GxsChannelPostsWidgetWithModel::switchView()
|
void GxsChannelPostsWidgetWithModel::switchView()
|
||||||
{
|
{
|
||||||
|
auto msg_id = getCurrentItemId();
|
||||||
|
|
||||||
if(mChannelPostsModel->getMode() == RsGxsChannelPostsModel::TREE_MODE_GRID)
|
if(mChannelPostsModel->getMode() == RsGxsChannelPostsModel::TREE_MODE_GRID)
|
||||||
{
|
{
|
||||||
whileBlocking(ui->list_TB)->setChecked(true);
|
whileBlocking(ui->list_TB)->setChecked(true);
|
||||||
|
|
@ -484,6 +505,9 @@ void GxsChannelPostsWidgetWithModel::switchView()
|
||||||
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()));
|
||||||
|
|
||||||
|
selectItem(msg_id);
|
||||||
|
ui->postsTree->setFocus();
|
||||||
|
|
||||||
ui->postsTree->dataChanged(QModelIndex(),QModelIndex()); // forces update of the whole tree
|
ui->postsTree->dataChanged(QModelIndex(),QModelIndex()); // forces update of the whole tree
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -159,6 +159,8 @@ public slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void processSettings(bool load);
|
void processSettings(bool load);
|
||||||
|
RsGxsMessageId getCurrentItemId() const;
|
||||||
|
void selectItem(const RsGxsMessageId& msg_id);
|
||||||
|
|
||||||
void setAutoDownload(bool autoDl);
|
void setAutoDownload(bool autoDl);
|
||||||
static bool filterItem(FeedItem *feedItem, const QString &text, int filter);
|
static bool filterItem(FeedItem *feedItem, const QString &text, int filter);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue