diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.cpp index 17554a632..ab20c2fd8 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.cpp @@ -43,6 +43,9 @@ RsGxsChannelPostFilesModel::RsGxsChannelPostFilesModel(QObject *parent) : QAbstractItemModel(parent) { initEmptyHierarchy(mFiles); + + mTimer = new QTimer; + connect(mTimer,SIGNAL(timeout()),this,SLOT(update())); } void RsGxsChannelPostFilesModel::initEmptyHierarchy(std::vector& files) @@ -68,6 +71,11 @@ void RsGxsChannelPostFilesModel::postMods() emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mFiles.size(),COLUMN_FILES_NB_COLUMNS-1,(void*)NULL)); } +void RsGxsChannelPostFilesModel::update() +{ + emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mFiles.size(),COLUMN_FILES_NB_COLUMNS-1,(void*)NULL)); +} + #ifdef TODO void RsGxsChannelPostsModel::setSortMode(SortMode mode) { @@ -694,34 +702,13 @@ void RsGxsChannelPostFilesModel::setFiles(const std::list& files) postMods(); emit channelLoaded(); + + if(!files.empty()) + mTimer->start(5000); + else + mTimer->stop(); } -//ChannelPostsModelIndex RsGxsChannelPostsModel::addEntry(std::vector& posts,const ChannelPostsModelPostEntry& entry) -//{ -// uint32_t N = posts.size(); -// posts.push_back(entry); -// -//#ifdef DEBUG_FORUMMODEL -// std::cerr << "Added new entry " << N << " children of " << parent << std::endl; -//#endif -// if(N == parent) -// std::cerr << "(EE) trying to add a post as its own parent!" << std::endl; -// -// return ChannelPostsModelIndex(N); -//} - -//void RsGxsChannelPostsModel::convertMsgToPostEntry(const RsGxsChannelGroup& mChannelGroup,const RsMsgMetaData& msg, bool /*useChildTS*/, ChannelPostsModelPostEntry& fentry) -//{ -// fentry.mTitle = msg.mMsgName; -// fentry.mMsgId = msg.mMsgId; -// fentry.mPublishTs = msg.mPublishTs; -// fentry.mPostFlags = 0; -// fentry.mMsgStatus = msg.mMsgStatus; -// -// // Early check for a message that should be hidden because its author -// // is flagged with a bad reputation -//} - QModelIndex RsGxsChannelPostFilesModel::getIndexOfFile(const RsFileHash& hash) const { // Brutal search. This is not so nice, so dont call that in a loop! If too costly, we'll use a map. diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.h b/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.h index 111906e64..873f179e8 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.h +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.h @@ -34,6 +34,8 @@ typedef uint32_t ChannelPostFilesModelIndex; +class QTimer; + // This class is the item model used by Qt to display the information class RsGxsChannelPostFilesModel : public QAbstractItemModel @@ -130,6 +132,9 @@ public: signals: void channelLoaded(); // emitted after the posts have been set. Can be used to updated the UI. +private slots: + void update(); + private: #ifdef TODO bool mUseChildTS; @@ -153,4 +158,6 @@ private: void initEmptyHierarchy(std::vector &files); std::vector mFiles ; // store the list of files for the post + + QTimer *mTimer; }; diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp index 4e5ea5077..d0dc70e96 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp @@ -156,11 +156,6 @@ void ChannelPostFilesDelegate::updateEditorGeometry(QWidget *editor, const QStyl editor->setGeometry(option.rect); } -void ChannelPostFilesDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const -{ - // nothing to do here. Is this override needed? -} - void ChannelPostFilesDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const { RsGxsFile file = index.data(Qt::UserRole).value() ; @@ -187,6 +182,12 @@ void ChannelPostFilesDelegate::paint(QPainter * painter, const QStyleOptionViewI painter->save(); painter->setClipRect(option.rect); + painter->save(); + + painter->fillRect( option.rect, option.backgroundBrush); + //optionFocusRect.backgroundColor = option.palette.color(colorgroup, (option.state & QStyle::State_Selected) ? QPalette::Highlight : QPalette::Background); + painter->restore(); + #ifdef TODO RsGxsFile file = index.data(Qt::UserRole).value() ; QVariant value = index.data(Qt::TextColorRole); @@ -194,25 +195,30 @@ void ChannelPostFilesDelegate::paint(QPainter * painter, const QStyleOptionViewI if(value.isValid() && qvariant_cast(value).isValid()) opt.palette.setColor(QPalette::Text, qvariant_cast(value)); - QPalette::ColorGroup cg = option.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled; + QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled) ? QPalette::Normal : QPalette::Disabled; if(option.state & QStyle::State_Selected) - painter->setPen(opt.palette.color(cg, QPalette::HighlightedText)); + painter->setPen(option.palette.color(cg, QPalette::HighlightedText)); else - painter->setPen(opt.palette.color(cg, QPalette::Text)); + painter->setPen(option.palette.color(cg, QPalette::Text)); #endif switch(index.column()) { - case RsGxsChannelPostFilesModel::COLUMN_FILES_NAME: painter->drawText(option.rect,Qt::AlignLeft | Qt::AlignVCenter,QString::fromUtf8(file.mName.c_str())); + case RsGxsChannelPostFilesModel::COLUMN_FILES_NAME: painter->drawText(option.rect,Qt::AlignLeft | Qt::AlignVCenter," " + QString::fromUtf8(file.mName.c_str())); break; case RsGxsChannelPostFilesModel::COLUMN_FILES_SIZE: painter->drawText(option.rect,Qt::AlignRight | Qt::AlignVCenter,misc::friendlyUnit(qulonglong(file.mSize))); break; case RsGxsChannelPostFilesModel::COLUMN_FILES_FILE: { - GxsChannelFilesStatusWidget w(file); - QPixmap pixmap(w.size()); - w.render(&pixmap); + GxsChannelFilesStatusWidget w(file); + + w.setFixedWidth(option.rect.width()); + + QPixmap pixmap(w.size()); + pixmap.fill(option.palette.color(QPalette::Background)); // choose the background + w.render(&pixmap,QPoint(),QRegion(),QWidget::DrawChildren );// draw the widgets, not the background + painter->drawPixmap(option.rect.topLeft(),pixmap); #ifdef TODO @@ -237,10 +243,10 @@ QSize ChannelPostFilesDelegate::sizeHint(const QStyleOptionViewItem& option, con switch(index.column()) { - case RsGxsChannelPostFilesModel::COLUMN_FILES_NAME: return QSize(fm.width(QString::fromUtf8(file.mName.c_str())),fm.height()); - case RsGxsChannelPostFilesModel::COLUMN_FILES_SIZE: return QSize(fm.width(misc::friendlyUnit(qulonglong(file.mSize))),fm.height()); + case RsGxsChannelPostFilesModel::COLUMN_FILES_NAME: return QSize(1.1*fm.width(QString::fromUtf8(file.mName.c_str())),fm.height()); + case RsGxsChannelPostFilesModel::COLUMN_FILES_SIZE: return QSize(1.1*fm.width(misc::friendlyUnit(qulonglong(file.mSize))),fm.height()); default: - case RsGxsChannelPostFilesModel::COLUMN_FILES_FILE: return GxsChannelFilesStatusWidget(file).size(); + case RsGxsChannelPostFilesModel::COLUMN_FILES_FILE: return QSize(option.rect.width(),GxsChannelFilesStatusWidget(file).height()); } } @@ -398,7 +404,14 @@ 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->setFixedWidth(W); + + ui->channelPostFiles_TV->resizeColumnToContents(RsGxsChannelPostFilesModel::COLUMN_FILES_FILE); + ui->channelPostFiles_TV->resizeColumnToContents(RsGxsChannelPostFilesModel::COLUMN_FILES_SIZE); + ui->channelPostFiles_TV->resizeColumnToContents(RsGxsChannelPostFilesModel::COLUMN_FILES_NAME); } void GxsChannelPostsWidgetWithModel::updateGroupData() diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h index aee073b09..1aa555caf 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h @@ -51,9 +51,6 @@ class ChannelPostFilesDelegate: public QStyledItemDelegate void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const override; QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; - void setEditorData(QWidget *editor, const QModelIndex &index) const override; - - private: }; class ChannelPostDelegate: public QAbstractItemDelegate diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.ui b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.ui index 18e59ff2e..0332379b0 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.ui +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.ui @@ -465,6 +465,19 @@ p, li { white-space: pre-wrap; } Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + true + + + + + + + TextLabel + + + true + @@ -500,6 +513,12 @@ p, li { white-space: pre-wrap; } true + + 5 + + + false +