fixed a few UI bugs in channel posts

This commit is contained in:
csoler 2020-06-12 11:00:51 +02:00
parent 67e8b87750
commit f40d7a75b3
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
4 changed files with 35 additions and 12 deletions

View File

@ -401,6 +401,11 @@ void RsGxsChannelPostsModel::clear()
emit channelPostsLoaded(); 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<RsGxsChannelPost>& posts) void RsGxsChannelPostsModel::setPosts(const RsGxsChannelGroup& group, std::vector<RsGxsChannelPost>& posts)
{ {
preMods(); preMods();
@ -413,6 +418,8 @@ void RsGxsChannelPostsModel::setPosts(const RsGxsChannelGroup& group, std::vecto
createPostsArray(posts); createPostsArray(posts);
std::sort(mPosts.begin(),mPosts.end());
mFilteredPosts.clear(); mFilteredPosts.clear();
for(int i=0;i<mPosts.size();++i) for(int i=0;i<mPosts.size();++i)
mFilteredPosts.push_back(i); mFilteredPosts.push_back(i);

View File

@ -109,7 +109,7 @@ public:
GxsIdDetails::loadPixmapFromData(post.mThumbnail.mData, post.mThumbnail.mSize, thumbnail,GxsIdDetails::ORIGINAL); GxsIdDetails::loadPixmapFromData(post.mThumbnail.mData, post.mThumbnail.mSize, thumbnail,GxsIdDetails::ORIGINAL);
lb->setPixmap(thumbnail); lb->setPixmap(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); QPixmap thumbnail = FilesDefs::getPixmapFromQtResourcePath(CHAN_DEFAULT_IMAGE);
lb->setPixmap(thumbnail); lb->setPixmap(thumbnail);
@ -157,7 +157,7 @@ void ChannelPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem &
QPixmap pixmap(w.size()); 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. pixmap.fill(QRgb(0xff308dc7)); // I dont know how to grab the backgroud color for selected objects automatically.
else else
pixmap.fill(QRgb(0x00ffffff)); // choose a fully transparent background 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->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(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()); QFontMetricsF fm(font());
@ -430,12 +436,14 @@ void GxsChannelPostsWidgetWithModel::handleEvent_main_thread(std::shared_ptr<con
void GxsChannelPostsWidgetWithModel::showPostDetails() void GxsChannelPostsWidgetWithModel::showPostDetails()
{ {
QModelIndex index = ui->postsTree->selectionModel()->currentIndex(); QModelIndex index = ui->postsTree->selectionModel()->currentIndex();
RsGxsChannelPost post = index.data(Qt::UserRole).value<RsGxsChannelPost>() ;
if(!index.isValid()) if(post.mMeta.mPublishTs == 0)
{ {
ui->postDetails_TE->clear(); ui->postDetails_TE->clear();
ui->postLogo_LB->hide(); ui->postLogo_LB->hide();
ui->postName_LB->hide(); ui->postName_LB->hide();
ui->postTime_LB->hide();
mChannelPostFilesModel->clear(); mChannelPostFilesModel->clear();
mSelectedGroup.clear(); mSelectedGroup.clear();
mSelectedPost.clear(); mSelectedPost.clear();
@ -444,12 +452,11 @@ void GxsChannelPostsWidgetWithModel::showPostDetails()
ui->postLogo_LB->show(); ui->postLogo_LB->show();
ui->postName_LB->show(); ui->postName_LB->show();
ui->postTime_LB->show();
if(index.row()==0 && index.column()==0) if(index.row()==0 && index.column()==0)
std::cerr << "here" << std::endl; std::cerr << "here" << std::endl;
RsGxsChannelPost post = index.data(Qt::UserRole).value<RsGxsChannelPost>() ;
mSelectedGroup = mGroup.mMeta.mGroupId; mSelectedGroup = mGroup.mMeta.mGroupId;
mSelectedPost = post.mMeta.mMsgId; 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. // Using fixed width so that the post will not displace the text when we browse.
ui->postLogo_LB->setPixmap(postImage); 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->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->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_FILE);
ui->channelPostFiles_TV->resizeColumnToContents(RsGxsChannelPostFilesModel::COLUMN_FILES_SIZE); 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; std::cerr << "Post channel load..." << std::endl;

View File

@ -138,7 +138,7 @@ private slots:
void setViewMode(int viewMode); void setViewMode(int viewMode);
void settingsChanged(); void settingsChanged();
void handlePostsTreeSizeChange(QSize s); void handlePostsTreeSizeChange(QSize s);
void postChannelLoad(); void postChannelPostLoad();
public slots: public slots:
void sortColumnFiles(int col,Qt::SortOrder so); void sortColumnFiles(int col,Qt::SortOrder so);

View File

@ -161,7 +161,7 @@
<item> <item>
<widget class="QTabWidget" name="channel_TW"> <widget class="QTabWidget" name="channel_TW">
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>1</number>
</property> </property>
<widget class="QWidget" name="tab_3"> <widget class="QWidget" name="tab_3">
<attribute name="title"> <attribute name="title">
@ -399,7 +399,7 @@ p, li { white-space: pre-wrap; }
</font> </font>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>2</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="tab"> <widget class="QWidget" name="tab">
<attribute name="title"> <attribute name="title">
@ -434,6 +434,13 @@ p, li { white-space: pre-wrap; }
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QLabel" name="postTime_LB">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item> <item>
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">