using orange color for unread comment bubble in channel post widget, and fixed the color update when new comment arrives

This commit is contained in:
csoler 2023-03-29 20:46:41 +02:00
parent 48c959c858
commit cc93a6da1a
3 changed files with 51 additions and 27 deletions

View File

@ -801,6 +801,16 @@ void RsGxsChannelPostsModel::setAllMsgReadStatus(bool read_status)
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(rowCount()-1,mColumns-1,(void*)NULL)); emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(rowCount()-1,mColumns-1,(void*)NULL));
} }
void RsGxsChannelPostsModel::updatePostWithNewComment(const RsGxsMessageId& msg_id)
{
for(uint32_t i=0;i<mPosts.size();++i)
if(mPosts[i].mMeta.mMsgId == msg_id)
{
++mPosts[i].mUnreadCommentCount;
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(rowCount()-1,mColumns-1,(void*)NULL)); // update everything because we don't know the index.
break;
}
}
void RsGxsChannelPostsModel::setMsgReadStatus(const QModelIndex& i,bool read_status) void RsGxsChannelPostsModel::setMsgReadStatus(const QModelIndex& i,bool read_status)
{ {
if(!i.isValid()) if(!i.isValid())
@ -824,6 +834,8 @@ void RsGxsChannelPostsModel::setMsgReadStatus(const QModelIndex& i,bool read_sta
else else
mPosts[mFilteredPosts[entry]].mMeta.mMsgStatus |= GXS_SERV::GXS_MSG_STATUS_GUI_UNREAD; mPosts[mFilteredPosts[entry]].mMeta.mMsgStatus |= GXS_SERV::GXS_MSG_STATUS_GUI_UNREAD;
mPosts[mFilteredPosts[entry]].mUnreadCommentCount = 0;
emit dataChanged(i,i); emit dataChanged(i,i);
} }

View File

@ -139,6 +139,7 @@ public:
void setMsgReadStatus(const QModelIndex &i, bool read_status); void setMsgReadStatus(const QModelIndex &i, bool read_status);
void setAllMsgReadStatus(bool read_status); void setAllMsgReadStatus(bool read_status);
void updatePostWithNewComment(const RsGxsMessageId& msg_id);
void setFilter(const QStringList &strings, bool only_unread,uint32_t &count) ; void setFilter(const QStringList &strings, bool only_unread,uint32_t &count) ;
bool postPassesFilter(const RsGxsChannelPost &post, const QStringList &strings, bool only_unread) const; bool postPassesFilter(const RsGxsChannelPost &post, const QStringList &strings, bool only_unread) const;

View File

@ -73,12 +73,13 @@ QColor SelectedColor = QRgb(0xff308dc7);
#define COLUMN_SIZE_FONT_FACTOR_W 6 #define COLUMN_SIZE_FONT_FACTOR_W 6
#define COLUMN_SIZE_FONT_FACTOR_H 10 #define COLUMN_SIZE_FONT_FACTOR_H 10
#define STAR_OVERLAY_IMAGE ":icons/star_overlay_128.png" #define STAR_OVERLAY_IMAGE ":icons/star_overlay_128.png"
#define COMMENT_OVERLAY_IMAGE ":images/white-bubble-64.png" #define COMMENT_OVERLAY_IMAGE ":images/white-bubble-64.png"
#define IMAGE_COPYLINK ":icons/png/copy.png" #define UNREAD_COMMENT_OVERLAY_IMAGE ":images/orange-bubble-64.png"
#define IMAGE_GRID_VIEW ":icons/png/menu.png" #define IMAGE_COPYLINK ":icons/png/copy.png"
#define IMAGE_DOWNLOAD ":icons/png/download.png" #define IMAGE_GRID_VIEW ":icons/png/menu.png"
#define IMAGE_UNREAD ":icons/png/message.png" #define IMAGE_DOWNLOAD ":icons/png/download.png"
#define IMAGE_UNREAD ":icons/png/message.png"
Q_DECLARE_METATYPE(ChannelPostFileInfo) Q_DECLARE_METATYPE(ChannelPostFileInfo)
@ -157,33 +158,39 @@ void ChannelPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem &
// file.close(); // file.close();
// } // }
if(mUseGrid || index.column()==0) if(mZoom != 1.0)
pixmap = pixmap.scaled(mZoom*pixmap.size(),Qt::KeepAspectRatio,Qt::SmoothTransformation);
if(IS_MSG_UNREAD(post.mMeta.mMsgStatus) || IS_MSG_NEW(post.mMeta.mMsgStatus))
{ {
if(mZoom != 1.0) QPainter p(&pixmap);
pixmap = pixmap.scaled(mZoom*pixmap.size(),Qt::KeepAspectRatio,Qt::SmoothTransformation); QFontMetricsF fm(option.font);
if(IS_MSG_UNREAD(post.mMeta.mMsgStatus) || IS_MSG_NEW(post.mMeta.mMsgStatus)) p.drawPixmap(mZoom*QPoint(0.1*fm.height(),-3.4*fm.height()),FilesDefs::getPixmapFromQtResourcePath(STAR_OVERLAY_IMAGE).scaled(mZoom*6*fm.height(),mZoom*6*fm.height(),Qt::KeepAspectRatio,Qt::SmoothTransformation));
{ }
QPainter p(&pixmap);
QFontMetricsF fm(option.font);
p.drawPixmap(mZoom*QPoint(0.1*fm.height(),-3.4*fm.height()),FilesDefs::getPixmapFromQtResourcePath(STAR_OVERLAY_IMAGE).scaled(mZoom*6*fm.height(),mZoom*6*fm.height(),Qt::KeepAspectRatio,Qt::SmoothTransformation)); if(post.mUnreadCommentCount > 0)
} {
QPainter p(&pixmap);
QFontMetricsF fm(option.font);
if(post.mUnreadCommentCount) p.drawPixmap(QPoint(pixmap.width(),0.0)+mZoom*QPoint(-2.9*fm.height(),0.4*fm.height()),
{ FilesDefs::getPixmapFromQtResourcePath(UNREAD_COMMENT_OVERLAY_IMAGE).scaled(mZoom*3*fm.height(),mZoom*3*fm.height(),
QPainter p(&pixmap); Qt::KeepAspectRatio,Qt::SmoothTransformation));
QFontMetricsF fm(option.font); }
else if(post.mCommentCount > 0)
p.drawPixmap(QPoint(pixmap.width(),0.0)+mZoom*QPoint(-2.9*fm.height(),0.4*fm.height()), {
FilesDefs::getPixmapFromQtResourcePath(COMMENT_OVERLAY_IMAGE).scaled(mZoom*3*fm.height(),mZoom*3*fm.height(), QPainter p(&pixmap);
Qt::KeepAspectRatio,Qt::SmoothTransformation)); QFontMetricsF fm(option.font);
}
p.drawPixmap(QPoint(pixmap.width(),0.0)+mZoom*QPoint(-2.9*fm.height(),0.4*fm.height()),
FilesDefs::getPixmapFromQtResourcePath(COMMENT_OVERLAY_IMAGE).scaled(mZoom*3*fm.height(),mZoom*3*fm.height(),
Qt::KeepAspectRatio,Qt::SmoothTransformation));
} }
painter->drawPixmap(option.rect.topLeft(), painter->drawPixmap(option.rect.topLeft(),
pixmap.scaled(option.rect.width(),option.rect.width()*pixmap.height()/(float)pixmap.width(),Qt::IgnoreAspectRatio,Qt::SmoothTransformation)); pixmap.scaled(option.rect.width(),option.rect.width()*pixmap.height()/(float)pixmap.width(),
Qt::IgnoreAspectRatio,Qt::SmoothTransformation));
} }
else else
{ {
@ -833,7 +840,11 @@ void GxsChannelPostsWidgetWithModel::handleEvent_main_thread(std::shared_ptr<con
} }
break; break;
case RsChannelEventCode::NEW_COMMENT: // [[fallthrough]]; case RsChannelEventCode::NEW_COMMENT:
if(e->mChannelGroupId == groupId() && e->mChannelThreadId != ui->commentsDialog->messageId())
mChannelPostsModel->updatePostWithNewComment(e->mChannelThreadId); [[fallthrough]];
case RsChannelEventCode::NEW_VOTE: case RsChannelEventCode::NEW_VOTE:
if(e->mChannelGroupId == groupId() && e->mChannelThreadId == ui->commentsDialog->messageId()) if(e->mChannelGroupId == groupId() && e->mChannelThreadId == ui->commentsDialog->messageId())
@ -922,7 +933,7 @@ void GxsChannelPostsWidgetWithModel::showPostDetails()
// Now also set the post as read // Now also set the post as read
if(IS_MSG_UNREAD(post.mMeta.mMsgStatus) || IS_MSG_NEW(post.mMeta.mMsgStatus)) if(IS_MSG_UNREAD(post.mMeta.mMsgStatus) || IS_MSG_NEW(post.mMeta.mMsgStatus) || post.mUnreadCommentCount > 0)
{ {
mChannelPostsModel->setMsgReadStatus(index,true); mChannelPostsModel->setMsgReadStatus(index,true);