From f40d7a75b36f009f8d42af2984cb78aa64c5de4e Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 12 Jun 2020 11:00:51 +0200 Subject: [PATCH] fixed a few UI bugs in channel posts --- .../gui/gxschannels/GxsChannelPostsModel.cpp | 7 +++++ .../GxsChannelPostsWidgetWithModel.cpp | 27 ++++++++++++------- .../GxsChannelPostsWidgetWithModel.h | 2 +- .../GxsChannelPostsWidgetWithModel.ui | 11 ++++++-- 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp index f22e7ca58..ae2c3d119 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp @@ -401,6 +401,11 @@ void RsGxsChannelPostsModel::clear() emit channelPostsLoaded(); } +bool operator<(const RsGxsChannelPost& p1,const RsGxsChannelPost& p2) +{ + return p1.mMeta.mPublishTs > p2.mMeta.mPublishTs; +} + void RsGxsChannelPostsModel::setPosts(const RsGxsChannelGroup& group, std::vector& posts) { preMods(); @@ -413,6 +418,8 @@ void RsGxsChannelPostsModel::setPosts(const RsGxsChannelGroup& group, std::vecto createPostsArray(posts); + std::sort(mPosts.begin(),mPosts.end()); + mFilteredPosts.clear(); for(int i=0;isetPixmap(thumbnail); } - else + else if(post.mMeta.mPublishTs > 0) // this is for testing that the post is not an empty post (happens at the end of the last row) { QPixmap thumbnail = FilesDefs::getPixmapFromQtResourcePath(CHAN_DEFAULT_IMAGE); lb->setPixmap(thumbnail); @@ -157,7 +157,7 @@ void ChannelPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem & QPixmap pixmap(w.size()); - if(option.state & QStyle::State_Selected) + if((option.state & QStyle::State_Selected) && post.mMeta.mPublishTs > 0) // check if post is selected and is not empty (end of last row) pixmap.fill(QRgb(0xff308dc7)); // I dont know how to grab the backgroud color for selected objects automatically. else pixmap.fill(QRgb(0x00ffffff)); // choose a fully transparent background @@ -323,7 +323,13 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI connect(ui->channelFiles_TV->header(),SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), this, SLOT(sortColumnFiles(int,Qt::SortOrder))); connect(ui->postsTree->selectionModel(),SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)),this,SLOT(showPostDetails())); - connect(mChannelPostsModel,SIGNAL(channelPostsLoaded()),this,SLOT(postChannelLoad())); + connect(mChannelPostsModel,SIGNAL(channelPostsLoaded()),this,SLOT(postChannelPostLoad())); + + ui->postName_LB->hide(); + ui->postTime_LB->hide(); + ui->postLogo_LB->hide(); + + ui->postDetails_TE->setPlaceholderText(tr("No post selected")); QFontMetricsF fm(font()); @@ -430,12 +436,14 @@ void GxsChannelPostsWidgetWithModel::handleEvent_main_thread(std::shared_ptrpostsTree->selectionModel()->currentIndex(); + RsGxsChannelPost post = index.data(Qt::UserRole).value() ; - if(!index.isValid()) + if(post.mMeta.mPublishTs == 0) { ui->postDetails_TE->clear(); ui->postLogo_LB->hide(); ui->postName_LB->hide(); + ui->postTime_LB->hide(); mChannelPostFilesModel->clear(); mSelectedGroup.clear(); mSelectedPost.clear(); @@ -444,12 +452,11 @@ void GxsChannelPostsWidgetWithModel::showPostDetails() ui->postLogo_LB->show(); ui->postName_LB->show(); + ui->postTime_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; @@ -476,10 +483,12 @@ void GxsChannelPostsWidgetWithModel::showPostDetails() // Using fixed width so that the post will not displace the text when we browse. ui->postLogo_LB->setPixmap(postImage); - ui->postName_LB->setText(QString::fromUtf8(post.mMeta.mMsgName.c_str())); - ui->postLogo_LB->setFixedSize(W,postImage.height()/(float)postImage.width()*W); + + ui->postName_LB->setText(QString::fromUtf8(post.mMeta.mMsgName.c_str())); ui->postName_LB->setFixedWidth(W); + ui->postTime_LB->setText(QDateTime::fromMSecsSinceEpoch(post.mMeta.mPublishTs*1000).toString("MM/dd/yyyy, hh:mm")); + ui->postTime_LB->setFixedWidth(W); ui->channelPostFiles_TV->resizeColumnToContents(RsGxsChannelPostFilesModel::COLUMN_FILES_FILE); ui->channelPostFiles_TV->resizeColumnToContents(RsGxsChannelPostFilesModel::COLUMN_FILES_SIZE); @@ -528,7 +537,7 @@ void GxsChannelPostsWidgetWithModel::updateGroupData() }); } -void GxsChannelPostsWidgetWithModel::postChannelLoad() +void GxsChannelPostsWidgetWithModel::postChannelPostLoad() { std::cerr << "Post channel load..." << std::endl; diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h index 7d2b9038c..5f2f4adae 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h @@ -138,7 +138,7 @@ private slots: void setViewMode(int viewMode); void settingsChanged(); void handlePostsTreeSizeChange(QSize s); - void postChannelLoad(); + void postChannelPostLoad(); public slots: void sortColumnFiles(int col,Qt::SortOrder so); diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.ui b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.ui index f44372c3a..71412862e 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.ui +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.ui @@ -161,7 +161,7 @@ - 0 + 1 @@ -399,7 +399,7 @@ p, li { white-space: pre-wrap; } - 2 + 0 @@ -434,6 +434,13 @@ p, li { white-space: pre-wrap; } + + + + TextLabel + + +