diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp index dd2c8cccc..ad695136d 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp @@ -20,6 +20,7 @@ #include #include +#include #include "retroshare/rsgxscircles.h" @@ -52,6 +53,86 @@ #define VIEW_MODE_FEEDS 1 #define VIEW_MODE_FILES 2 +Q_DECLARE_METATYPE(RsGxsChannelPost*) + +void ChannelPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const +{ + QString byteUnits[4] = {tr("B"), tr("KB"), tr("MB"), tr("GB")}; + QStyleOptionViewItem opt = option; + QStyleOptionProgressBarV2 newopt; + QRect pixmapRect; + QPixmap pixmap; + qlonglong fileSize; + double dlspeed, multi; + int seconds,minutes, hours, days; + qlonglong remaining; + QString temp ; + qlonglong completed; + qlonglong downloadtime; + qint64 qi64Value; + + // prepare + painter->save(); + painter->setClipRect(opt.rect); + + RsGxsChannelPost post = index.data(Qt::UserRole).value() ; + //const RsGxsChannelPost& post(*pinfo); + + QVariant value = index.data(Qt::TextColorRole); + + 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; + + if(option.state & QStyle::State_Selected) + painter->setPen(opt.palette.color(cg, QPalette::HighlightedText)); + else + painter->setPen(opt.palette.color(cg, QPalette::Text)); + + //painter->drawText(option.rect, Qt::AlignRight, QString("TODO")); + + QPixmap thumbnail; + GxsIdDetails::loadPixmapFromData(post.mThumbnail.mData, post.mThumbnail.mSize, thumbnail,GxsIdDetails::ORIGINAL); + + QFontMetricsF fm(opt.font); + + int W = IMAGE_SIZE_FACTOR_W * fm.height() * IMAGE_ZOOM_FACTOR; + int H = IMAGE_SIZE_FACTOR_H * fm.height() * IMAGE_ZOOM_FACTOR; + + int w = fm.width("X") ; + int h = fm.height() ; + + float img_coord_x = IMAGE_MARGIN_FACTOR*0.5*w; + float img_coord_y = IMAGE_MARGIN_FACTOR*0.5*h; + + QPoint img_pos(img_coord_x,img_coord_y); + QPoint img_size(W,H); + + QPoint txt_pos(0,img_coord_y + H + h); + + painter->drawPixmap(QRect(opt.rect.topLeft() + img_pos,opt.rect.topLeft()+img_pos+img_size),thumbnail.scaled(W,H,Qt::KeepAspectRatio,Qt::SmoothTransformation)); + painter->drawText(QRect(option.rect.topLeft() + txt_pos,option.rect.bottomRight()),Qt::AlignCenter,QString::fromStdString(post.mMeta.mMsgName)); +} + +QSize ChannelPostDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const +{ + RsGxsChannelPost post = index.data(Qt::UserRole).value() ; + + //QPixmap thumbnail; + //GxsIdDetails::loadPixmapFromData(post.mThumbnail.mData, post.mThumbnail.mSize, thumbnail,GxsIdDetails::ORIGINAL); + + QFontMetricsF fm(option.font); + + int W = IMAGE_SIZE_FACTOR_W * fm.height() * IMAGE_ZOOM_FACTOR; + int H = IMAGE_SIZE_FACTOR_H * fm.height() * IMAGE_ZOOM_FACTOR; + + int h = fm.height() ; + int w = fm.width("X") ; + + return QSize(W+IMAGE_MARGIN_FACTOR*w,H + 2*h); +} + /** Constructor */ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupId &channelId, QWidget *parent) : GxsMessageFrameWidget(rsGxsChannels, parent), @@ -61,6 +142,9 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI ui->setupUi(this); ui->postsTree->setModel(mThreadModel = new RsGxsChannelPostsModel()); + ui->postsTree->setItemDelegate(new ChannelPostDelegate()); + + connect(ui->postsTree->selectionModel(),SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)),this,SLOT(showPostDetails())); /* Setup UI helper */ @@ -95,7 +179,7 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI /* Initialize view button */ //setViewMode(VIEW_MODE_FEEDS); see processSettings - ui->infoWidget->hide(); + //ui->infoWidget->hide(); QSignalMapper *signalMapper = new QSignalMapper(this); connect(ui->feedToolButton, SIGNAL(clicked()), signalMapper, SLOT(map())); @@ -109,7 +193,7 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI ui->loadingLabel->hide(); ui->progressBar->hide(); - ui->nameLabel->setMinimumWidth(20); + //ui->nameLabel->setMinimumWidth(20); /* Initialize feed widget */ //ui->feedWidget->setSortRole(ROLE_PUBLISH, Qt::DescendingOrder); @@ -169,6 +253,13 @@ void GxsChannelPostsWidgetWithModel::handleEvent_main_thread(std::shared_ptrpostsTree->selectionModel()->currentIndex(); + + std::cerr << "Showing details about selected index : "<< selected_index.row() << "," << selected_index.column() << std::endl; +} + void GxsChannelPostsWidgetWithModel::updateGroupData() { if(groupId().isNull()) @@ -280,12 +371,12 @@ QString GxsChannelPostsWidgetWithModel::groupName(bool) void GxsChannelPostsWidgetWithModel::groupNameChanged(const QString &name) { - if (groupId().isNull()) { - ui->nameLabel->setText(tr("No Channel Selected")); - ui->logoLabel->setPixmap(QPixmap(":/icons/png/channels.png")); - } else { - ui->nameLabel->setText(name); - } +// if (groupId().isNull()) { +// ui->nameLabel->setText(tr("No Channel Selected")); +// ui->logoLabel->setPixmap(QPixmap(":/icons/png/channels.png")); +// } else { +// ui->nameLabel->setText(name); +// } } QIcon GxsChannelPostsWidgetWithModel::groupIcon() @@ -336,7 +427,7 @@ void GxsChannelPostsWidgetWithModel::insertChannelDetails(const RsGxsChannelGrou } else { chanImage = QPixmap(CHAN_DEFAULT_IMAGE); } - ui->logoLabel->setPixmap(chanImage); + //ui->logoLabel->setPixmap(chanImage); if (group.mMeta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_PUBLISH) { @@ -361,7 +452,7 @@ void GxsChannelPostsWidgetWithModel::insertChannelDetails(const RsGxsChannelGrou ui->feedToolButton->setEnabled(true); ui->fileToolButton->setEnabled(true); - ui->infoWidget->hide(); + //ui->infoWidget->hide(); setViewMode(viewMode()); ui->subscribeToolButton->setText(tr("Subscribed") + " " + QString::number(group.mMeta.mPop) ); @@ -785,7 +876,7 @@ void GxsChannelPostsWidgetWithModel::blank() mThreadModel->clear(); groupNameChanged(QString()); - ui->infoWidget->hide(); + //ui->infoWidget->hide(); } bool GxsChannelPostsWidgetWithModel::navigate(const RsGxsMessageId &msgId) diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h index 64478a112..246be0715 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h @@ -23,8 +23,9 @@ #include -#include "gui/gxs/GxsMessageFramePostWidget.h" +#include +#include "gui/gxs/GxsMessageFramePostWidget.h" #include "gui/feeds/FeedHolder.h" namespace Ui { @@ -36,6 +37,24 @@ class QTreeWidgetItem; class FeedItem; class RsGxsChannelPostsModel; +class ChannelPostDelegate: public QAbstractItemDelegate +{ + Q_OBJECT + + public: + ChannelPostDelegate(QObject *parent=0) : QAbstractItemDelegate(parent){} + virtual ~ChannelPostDelegate(){} + + void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const override; + QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override; + + private: + static constexpr float IMAGE_MARGIN_FACTOR = 1.0; + static constexpr float IMAGE_SIZE_FACTOR_W = 4.0 ; + static constexpr float IMAGE_SIZE_FACTOR_H = 6.0 ; + static constexpr float IMAGE_ZOOM_FACTOR = 1.0; +}; + class GxsChannelPostsWidgetWithModel: public GxsMessageFrameWidget { Q_OBJECT @@ -91,6 +110,7 @@ protected: virtual void setAllMessagesReadDo(bool read, uint32_t &token); private slots: + void showPostDetails(); void updateGroupData(); void createMsg(); void toggleAutoDownload(); diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.ui b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.ui index c1bc74996..2ae7ecac8 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.ui +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.ui @@ -26,69 +26,6 @@ 0 - - - - QFrame::Box - - - QFrame::Sunken - - - - 4 - - - 4 - - - 4 - - - 4 - - - - - - 64 - 64 - - - - - 64 - 64 - - - - - - - :/images/channels.png - - - true - - - - - - - - - - - - - - Channel Name - - - - - - @@ -285,237 +222,226 @@ - - - + + + 0 - - - 3 - - - 0 - - - 3 - - - 3 - - - - - false - - - QFrame::NoFrame - - - QFrame::Plain - - - - 6 + + + Channel details + + + + + + Channel details - - 6 - - - 6 - - - 6 - - - - - Channel details - - - - 9 + + + 9 + + + 9 + + + 9 + + + 9 + + + + + + 0 + 0 + - - 9 + + + 75 + true + - - 9 + + Last Post: - - 9 - - - - - - 0 - 0 - - - - - 75 - true - - - - Last Post: - - - - - - - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> + + + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } </style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;"> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'MS Shell Dlg 2'; font-size:8pt;">Description</span></p></body></html> - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse - - - true - - - true - - - - - - - - 75 - true - - - - Description: - - - - - - - - 75 - true - - - - Created: - - - - - - - - 75 - true - - - - Administrator: - - - - - - - - 0 - 0 - - - - - 75 - true - - - - Posts: - - - - - - - - 75 - true - - - - Distribution: - - - - - - - unknown - - - - - - - unknown - - - - - - - unknown - - - true - - - - - - - unknown - - - - - - - 0 - - - - - - - - - - - - - Qt::Vertical - - - - 0 - 0 - - - - - + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + + + true + + + true + + + + + + + + 75 + true + + + + Description: + + + + + + + + 75 + true + + + + Created: + + + + + + + + 75 + true + + + + Administrator: + + + + + + + + 0 + 0 + + + + + 75 + true + + + + Posts: + + + + + + + + 75 + true + + + + Distribution: + + + + + + + unknown + + + + + + + unknown + + + + + + + unknown + + + true + + + + + + + unknown + + + + + + + 0 + + + + + + + + + + + Posts + + + + + + QAbstractItemView::SelectItems + + + false + + + + + - + + + 0 + + + + Details + + + + + + + + + + Comments + + + @@ -528,10 +454,6 @@ p, li { white-space: pre-wrap; } Files - toolBarFrame - headFrame - infoWidget - postsTree @@ -544,11 +466,6 @@ p, li { white-space: pre-wrap; } QToolButton
gui/common/SubscribeToolButton.h
- - StyledElidedLabel - QLabel -
gui/common/StyledElidedLabel.h
-
LineEditClear QLineEdit @@ -556,8 +473,8 @@ p, li { white-space: pre-wrap; }
- +