From 8a20ab33b4d5a4390d6a358331ba1f6b5a2f974c Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 4 Sep 2023 21:58:45 +0200 Subject: [PATCH] fixed bug in ModelIndex creation in channel post view, and implemented arrow key navigation --- .../src/gui/gxs/GxsCommentDialog.cpp | 2 ++ .../gui/gxschannels/GxsChannelPostsModel.cpp | 21 +++++++++++++++- .../gui/gxschannels/GxsChannelPostsModel.h | 1 + .../GxsChannelPostsWidgetWithModel.cpp | 24 +++++++++++++++++++ .../GxsChannelPostsWidgetWithModel.h | 1 + 5 files changed, 48 insertions(+), 1 deletion(-) diff --git a/retroshare-gui/src/gui/gxs/GxsCommentDialog.cpp b/retroshare-gui/src/gui/gxs/GxsCommentDialog.cpp index 7b9e28131..4757b036e 100644 --- a/retroshare-gui/src/gui/gxs/GxsCommentDialog.cpp +++ b/retroshare-gui/src/gui/gxs/GxsCommentDialog.cpp @@ -95,8 +95,10 @@ void GxsCommentDialog::commentClear() } void GxsCommentDialog::commentLoad(const RsGxsGroupId &grpId, const std::set& msg_versions,const RsGxsMessageId& most_recent_msgId,bool use_cache) { +#ifdef DEBUG_COMMENT_DIALOG std::cerr << "GxsCommentDialog::commentLoad(" << grpId << ", most recent msg version: " << most_recent_msgId << ")"; std::cerr << std::endl; +#endif mGrpId = grpId; mMostRecentMsgId = most_recent_msgId; diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp index e9be3e6ed..a42587d85 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp @@ -176,6 +176,25 @@ int RsGxsChannelPostsModel::rowCount(const QModelIndex& parent) const return 0; } +int RsGxsChannelPostsModel::columnCount(int row) const +{ + if(mTreeMode == TREE_MODE_GRID) + { + if(row+1 == rowCount()) + { + int r = ((int)mFilteredPosts.size() % (int)mColumns); + + if(r > 0) + return r; + else + return columnCount(); + } + else + return columnCount(); + } + else + return 2; +} int RsGxsChannelPostsModel::columnCount(const QModelIndex &/*parent*/) const { if(mTreeMode == TREE_MODE_GRID) @@ -245,7 +264,7 @@ bool RsGxsChannelPostsModel::convertRefPointerToTabEntry(quintptr ref, uint32_t& QModelIndex RsGxsChannelPostsModel::index(int row, int column, const QModelIndex & parent) const { - if(row < 0 || column < 0 || column >= (int)mColumns) + if(row < 0 || column < 0 || row >= rowCount() || column >= columnCount(row)) return QModelIndex(); quintptr ref = getChildRef(parent.internalId(),(mTreeMode == TREE_MODE_GRID)?(column + row*mColumns):row); diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.h b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.h index 42dcbb9f7..c447f11a3 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.h +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.h @@ -105,6 +105,7 @@ public: QModelIndex root() const{ return createIndex(0,0,(void*)NULL) ;} QModelIndex getIndexOfMessage(const RsGxsMessageId& mid) const; + int columnCount(int row) const; // columns in the row of this particular index. std::vector > getPostVersions(const RsGxsMessageId& mid) const; diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp index a6ce946f5..ea27be6f9 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp @@ -504,6 +504,30 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI }, mEventHandlerId, RsEventType::GXS_CHANNELS ); } +void GxsChannelPostsWidgetWithModel::keyPressEvent(QKeyEvent *e) +{ + QModelIndex index = ui->postsTree->selectionModel()->currentIndex(); + + if(index.isValid() && mChannelPostsModel->getMode() == RsGxsChannelPostsModel::TREE_MODE_GRID) + { + int n = mChannelPostsModel->columnCount(index.row())-1; + + if(e->key() == Qt::Key_Left && index.column()==0) + { + ui->postsTree->setCurrentIndex(index.siblingAtColumn(n)); + e->accept(); + return; + } + if(e->key() == Qt::Key_Right && index.column()==n) + { + ui->postsTree->setCurrentIndex(index.siblingAtColumn(0)); + e->accept(); + return; + } + } + + GxsMessageFrameWidget::keyPressEvent(e); +} void GxsChannelPostsWidgetWithModel::resizeEvent(QResizeEvent *e) { GxsMessageFrameWidget::resizeEvent(e); diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h index 9cfcaae21..8891b57dd 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h @@ -139,6 +139,7 @@ protected: /* GxsMessageFrameWidget */ virtual void setAllMessagesReadDo(bool read) override; virtual void resizeEvent(QResizeEvent *e) override; + virtual void keyPressEvent(QKeyEvent *e) override; private slots: void showPostDetails();