From 2faaccbb7a4963f6d8288282b50c7e99914c02f9 Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 11 Jun 2020 21:55:52 +0200 Subject: [PATCH] fixed a few cosmetic details in channels model and UI --- .../gui/gxschannels/GxsChannelPostsModel.cpp | 8 +-- .../GxsChannelPostsWidgetWithModel.cpp | 71 +++++++++++++++---- .../GxsChannelPostsWidgetWithModel.h | 3 + .../GxsChannelPostsWidgetWithModel.ui | 16 ++++- 4 files changed, 80 insertions(+), 18 deletions(-) diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp index 94d6f6406..caca20f93 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp @@ -145,7 +145,7 @@ int RsGxsChannelPostsModel::rowCount(const QModelIndex& parent) const int RsGxsChannelPostsModel::columnCount(const QModelIndex &/*parent*/) const { - return mColumns ; + return std::min((int)mFilteredPosts.size(),(int)mColumns) ; } bool RsGxsChannelPostsModel::getPostData(const QModelIndex& i,RsGxsChannelPost& fmpe) const @@ -635,7 +635,7 @@ QModelIndex RsGxsChannelPostsModel::getIndexOfMessage(const RsGxsMessageId& mid) RsGxsMessageId postId = mid; - for(uint32_t i=1;i -#define CHAN_DEFAULT_IMAGE ":/icons/png/channels.png" +#define CHAN_DEFAULT_IMAGE ":images/thumb-default-video.png" #define ROLE_PUBLISH FEED_TREEWIDGET_SORTROLE @@ -102,10 +103,17 @@ public: // now fill the data - QPixmap thumbnail; - GxsIdDetails::loadPixmapFromData(post.mThumbnail.mData, post.mThumbnail.mSize, thumbnail,GxsIdDetails::ORIGINAL); - - lb->setPixmap(thumbnail); + if(post.mThumbnail.mSize > 0) + { + QPixmap thumbnail; + GxsIdDetails::loadPixmapFromData(post.mThumbnail.mData, post.mThumbnail.mSize, thumbnail,GxsIdDetails::ORIGINAL); + lb->setPixmap(thumbnail); + } + else + { + QPixmap thumbnail = FilesDefs::getPixmapFromQtResourcePath(CHAN_DEFAULT_IMAGE); + lb->setPixmap(thumbnail); + } QFontMetricsF fm(font()); int W = THUMBNAIL_OVERSAMPLE_FACTOR * THUMBNAIL_W * fm.height() ; @@ -114,6 +122,15 @@ public: lb->setFixedSize(W,H); lt->setText(QString::fromUtf8(post.mMeta.mMsgName.c_str())); + + QFont font = lt->font(); + + if(IS_MSG_UNREAD(post.mMeta.mMsgStatus) || IS_MSG_NEW(post.mMeta.mMsgStatus)) + { + font.setBold(true); + lt->setFont(font); + } + lt->setMaximumWidth(W); lt->setWordWrap(true); @@ -401,15 +418,10 @@ void GxsChannelPostsWidgetWithModel::handleEvent_main_thread(std::shared_ptrmChannelGroupId == groupId()) updateDisplay(true); break; -// case RsChannelEventCode::READ_STATUS_CHANGED: -// if (FeedItem *feedItem = ui->feedWidget->findFeedItem(GxsChannelPostItem::computeIdentifier(e->mChannelMsgId))) -// if (GxsChannelPostItem *channelPostItem = dynamic_cast(feedItem)) -// channelPostItem->setReadStatus(false,!channelPostItem->isUnread()); -// //channelPostItem->setReadStatus(false,e->Don't get read status. Will be more easier and accurate); -// break; default: break; } @@ -419,18 +431,34 @@ void GxsChannelPostsWidgetWithModel::showPostDetails() { QModelIndex index = ui->postsTree->selectionModel()->currentIndex(); + if(!index.isValid() && !mSelectedPost.isNull() && mGroup.mMeta.mGroupId == mSelectedGroup) + { + index = mChannelPostsModel->getIndexOfMessage(mSelectedPost); + whileBlocking(ui->postsTree)->setCurrentIndex(index); + } + if(!index.isValid()) { ui->postDetails_TE->clear(); - ui->postLogo_LB->clear(); + ui->postLogo_LB->hide(); + ui->postName_LB->hide(); mChannelPostFilesModel->clear(); + mSelectedGroup.clear(); + mSelectedPost.clear(); return; } + + ui->postLogo_LB->show(); + ui->postName_LB->show(); + if(index.row()==0 && index.column()==0) std::cerr << "here" << std::endl; RsGxsChannelPost post = index.data(Qt::UserRole).value() ; + mSelectedGroup = mGroup.mMeta.mGroupId; + mSelectedPost = post.mMeta.mMsgId; + mChannelPostFilesModel->setFiles(post.mFiles); auto all_msgs_versions(post.mOlderVersions); @@ -447,7 +475,7 @@ void GxsChannelPostsWidgetWithModel::showPostDetails() if (post.mThumbnail.mData != NULL) GxsIdDetails::loadPixmapFromData(post.mThumbnail.mData, post.mThumbnail.mSize, postImage,GxsIdDetails::ORIGINAL); else - postImage = QPixmap(CHAN_DEFAULT_IMAGE); + postImage = FilesDefs::getPixmapFromQtResourcePath(CHAN_DEFAULT_IMAGE); int W = QFontMetricsF(font()).height() * 8; @@ -463,6 +491,16 @@ void GxsChannelPostsWidgetWithModel::showPostDetails() ui->channelPostFiles_TV->resizeColumnToContents(RsGxsChannelPostFilesModel::COLUMN_FILES_SIZE); ui->channelPostFiles_TV->setAutoSelect(true); + // Now also set the post as read + + if(IS_MSG_UNREAD(post.mMeta.mMsgStatus) || IS_MSG_NEW(post.mMeta.mMsgStatus)) + { + RsGxsGrpMsgIdPair postId; + postId.second = post.mMeta.mMsgId; + postId.first = post.mMeta.mGroupId; + + RsThread::async([postId]() { rsGxsChannels->markRead(postId, true) ; } ); + } } void GxsChannelPostsWidgetWithModel::updateChannelFiles() @@ -645,6 +683,8 @@ void GxsChannelPostsWidgetWithModel::createMsg() void GxsChannelPostsWidgetWithModel::insertChannelDetails(const RsGxsChannelGroup &group) { + // save selection if needed + /* IMAGE */ QPixmap chanImage; if (group.mImage.mData != NULL) { @@ -652,6 +692,11 @@ void GxsChannelPostsWidgetWithModel::insertChannelDetails(const RsGxsChannelGrou } else { chanImage = QPixmap(CHAN_DEFAULT_IMAGE); } + if(group.mMeta.mGroupName.empty()) + ui->channelName_LB->setText(tr("[No name]")); + else + ui->channelName_LB->setText(QString::fromUtf8(group.mMeta.mGroupName.c_str())); + ui->logoLabel->setPixmap(chanImage); ui->logoLabel->setFixedSize(QSize(ui->logoLabel->height()*chanImage.width()/(float)chanImage.height(),ui->logoLabel->height())); // make the logo have the same aspect ratio than the original image diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h index 90c1f76ad..49e5dc21e 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h @@ -166,6 +166,9 @@ private: RsGxsChannelPostFilesModel *mChannelPostFilesModel; RsGxsChannelPostFilesModel *mChannelFilesModel; + RsGxsMessageId mSelectedPost; + RsGxsGroupId mSelectedGroup; + /* UI - from Designer */ Ui::GxsChannelPostsWidgetWithModel *ui; }; diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.ui b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.ui index cfa36e40d..f44372c3a 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.ui +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.ui @@ -161,13 +161,27 @@ - 2 + 0 Channel details + + + + + 75 + true + false + + + + Channel title + + +