From 033596a080211f103c3f6817049de5e7a19ca95e Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 7 Aug 2020 17:22:55 +0200 Subject: [PATCH] added two-views system for boards. Widgets are not yet correct --- .../src/gui/Posted/BoardPostDisplayWidget.cpp | 456 +++++----- .../src/gui/Posted/BoardPostDisplayWidget.h | 30 +- .../src/gui/Posted/BoardPostDisplayWidget.ui | 829 ++++++++++-------- .../src/gui/Posted/PostedCardView.h | 4 +- .../gui/Posted/PostedListWidgetWithModel.cpp | 69 +- .../gui/Posted/PostedListWidgetWithModel.h | 9 +- .../src/gui/Posted/PostedPostsModel.cpp | 4 + .../src/gui/Posted/PostedPostsModel.h | 3 + 8 files changed, 780 insertions(+), 624 deletions(-) diff --git a/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.cpp b/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.cpp index ac512a57d..47d4e0421 100644 --- a/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.cpp +++ b/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.cpp @@ -43,13 +43,17 @@ const char *BoardPostDisplayWidget::DEFAULT_BOARD_IMAGE = ":/icons/png/newsfeed2.png"; -BoardPostDisplayWidget::BoardPostDisplayWidget(const RsPostedPost& post,QWidget *parent) - : QWidget(parent),ui(new Ui::BoardPostDisplayWidget()),mPost(post) +//=================================================================================================================================== +//== Base class BoardPostDisplayWidget == +//=================================================================================================================================== + +BoardPostDisplayWidget::BoardPostDisplayWidget(const RsPostedPost& post,DisplayMode mode,QWidget *parent) + : QWidget(parent),ui(new Ui::BoardPostDisplayWidget()),dmode(mode),mPost(post) { ui->setupUi(this); + mExpanded = false; setup(); - fill(); } void BoardPostDisplayWidget::setCommentsSize(int comNb) @@ -114,234 +118,284 @@ BoardPostDisplayWidget::~BoardPostDisplayWidget() delete(ui); } +void BoardPostDisplayWidget::toggleNotes() {} + void BoardPostDisplayWidget::setup() { - setAttribute(Qt::WA_DeleteOnClose, true); + // show/hide things based on the view type - /* clear ui */ - ui->titleLabel->setText(tr("Loading")); - ui->dateLabel->clear(); - ui->fromLabel->clear(); - ui->siteLabel->clear(); + if(dmode == DISPLAY_MODE_COMPACT) + { + ui->pictureLabel_compact->show(); + ui->expandButton->show(); - connect(ui->commentButton, SIGNAL( clicked()), this, SLOT(loadComments())); - connect(ui->voteUpButton, SIGNAL(clicked()), this, SLOT(makeUpVote())); - connect(ui->voteDownButton, SIGNAL(clicked()), this, SLOT( makeDownVote())); - connect(ui->readButton, SIGNAL(toggled(bool)), this, SLOT(readToggled(bool))); - - QAction *CopyLinkAction = new QAction(QIcon(""),tr("Copy RetroShare Link"), this); - connect(CopyLinkAction, SIGNAL(triggered()), this, SLOT(copyMessageLink())); - - QAction *showInPeopleAct = new QAction(QIcon(), tr("Show author in people tab"), this); - connect(showInPeopleAct, SIGNAL(triggered()), this, SLOT(showAuthorInPeople())); - - int S = QFontMetricsF(font()).height() ; - - ui->voteUpButton->setIconSize(QSize(S*1.5,S*1.5)); - ui->voteDownButton->setIconSize(QSize(S*1.5,S*1.5)); - ui->commentButton->setIconSize(QSize(S*1.5,S*1.5)); - ui->readButton->setIconSize(QSize(S*1.5,S*1.5)); - ui->shareButton->setIconSize(QSize(S*1.5,S*1.5)); - - QMenu *menu = new QMenu(); - menu->addAction(CopyLinkAction); - menu->addSeparator(); - menu->addAction(showInPeopleAct); - ui->shareButton->setMenu(menu); - - ui->clearButton->hide(); - ui->readAndClearButton->hide(); -} - -void BoardPostDisplayWidget::fill() -{ - RsReputationLevel overall_reputation = rsReputations->overallReputationLevel(mPost.mMeta.mAuthorId); - bool redacted = (overall_reputation == RsReputationLevel::LOCALLY_NEGATIVE); - - if(redacted) { - ui->commentButton->setDisabled(true); - ui->voteUpButton->setDisabled(true); - ui->voteDownButton->setDisabled(true); -// ui->picture_frame->hide(); - ui->fromLabel->setId(mPost.mMeta.mAuthorId); - ui->titleLabel->setText(tr( "

The author of this message (with ID %1) is banned.").arg(QString::fromStdString(mPost.mMeta.mAuthorId.toStdString()))) ; - QDateTime qtime; - qtime.setTime_t(mPost.mMeta.mPublishTs); - QString timestamp = qtime.toString("hh:mm dd-MMM-yyyy"); - ui->dateLabel->setText(timestamp); - } else { - - QPixmap sqpixmap2 = FilesDefs::getPixmapFromQtResourcePath(":/images/thumb-default.png"); - - int desired_height = 1.5*(ui->voteDownButton->height() + ui->voteUpButton->height() + ui->scoreLabel->height()); - int desired_width = sqpixmap2.width()*desired_height/(float)sqpixmap2.height(); - - QDateTime qtime; - qtime.setTime_t(mPost.mMeta.mPublishTs); - QString timestamp = qtime.toString("hh:mm dd-MMM-yyyy"); - QString timestamp2 = misc::timeRelativeToNow(mPost.mMeta.mPublishTs); - ui->dateLabel->setText(timestamp2); - ui->dateLabel->setToolTip(timestamp); - - ui->fromLabel->setId(mPost.mMeta.mAuthorId); - - // Use QUrl to check/parse our URL - // The only combination that seems to work: load as EncodedUrl, extract toEncoded(). - QByteArray urlarray(mPost.mLink.c_str()); - QUrl url = QUrl::fromEncoded(urlarray.trimmed()); - QString urlstr = "Invalid Link"; - QString sitestr = "Invalid Link"; - - bool urlOkay = url.isValid(); - if (urlOkay) - { - QString scheme = url.scheme(); - if ((scheme != "https") - && (scheme != "http") - && (scheme != "ftp") - && (scheme != "retroshare")) - { - urlOkay = false; - sitestr = "Invalid Link Scheme"; - } - } - - if (urlOkay) - { - urlstr = QString(" "); - urlstr += QString::fromUtf8(mPost.mMeta.mMsgName.c_str()); - urlstr += QString(" "); - - QString siteurl = url.toEncoded(); - sitestr = QString(" %2 ").arg(siteurl).arg(siteurl); - - ui->titleLabel->setText(urlstr); - } + if(mExpanded) + { + ui->frame_picture->show(); + ui->expandButton->setIcon(FilesDefs::getIconFromQtResourcePath(QString(":/images/decrease.png"))); + ui->expandButton->setToolTip(tr("Hide")); + } else - ui->titleLabel->setText( QString::fromUtf8(mPost.mMeta.mMsgName.c_str()) ); - - if (urlarray.isEmpty()) - { - ui->siteLabel->hide(); - } + { + ui->frame_picture->hide(); + ui->expandButton->setIcon(FilesDefs::getIconFromQtResourcePath(QString(":/images/expand.png"))); + ui->expandButton->setToolTip(tr("Expand")); + } + } + else + { + ui->frame_picture->hide(); + ui->pictureLabel_compact->hide(); + ui->expandButton->hide(); + } - ui->siteLabel->setText(sitestr); - - if(mPost.mImage.mData != NULL) - { - QPixmap pixmap; - GxsIdDetails::loadPixmapFromData(mPost.mImage.mData, mPost.mImage.mSize, pixmap,GxsIdDetails::ORIGINAL); - // Wiping data - as its been passed to thumbnail. - - QPixmap scaledpixmap; - if(pixmap.width() > 800){ - QPixmap scaledpixmap = pixmap.scaledToWidth(800, Qt::SmoothTransformation); - ui->pictureLabel->setPixmap(scaledpixmap); - }else{ - ui->pictureLabel->setPixmap(pixmap); - } - } - else if (mPost.mImage.mData == NULL) - ui->pictureLabel->hide(); - else - ui->pictureLabel->show(); - } + setAttribute(Qt::WA_DeleteOnClose, true); - //QString score = "Hot" + QString::number(post.mHotScore); - //score += " Top" + QString::number(post.mTopScore); - //score += " New" + QString::number(post.mNewScore); + /* clear ui */ + ui->titleLabel->setText(tr("Loading")); + ui->dateLabel->clear(); + ui->fromLabel->clear(); + ui->siteLabel->clear(); - QString score = QString::number(mPost.mTopScore); + connect(ui->commentButton, SIGNAL( clicked()), this, SLOT(loadComments())); + connect(ui->voteUpButton, SIGNAL(clicked()), this, SLOT(makeUpVote())); + connect(ui->voteDownButton, SIGNAL(clicked()), this, SLOT( makeDownVote())); + connect(ui->readButton, SIGNAL(toggled(bool)), this, SLOT(readToggled(bool))); - ui->scoreLabel->setText(score); + QAction *CopyLinkAction = new QAction(QIcon(""),tr("Copy RetroShare Link"), this); + connect(CopyLinkAction, SIGNAL(triggered()), this, SLOT(copyMessageLink())); - // FIX THIS UP LATER. - ui->notes->setText(RsHtml().formatText(NULL, QString::fromUtf8(mPost.mNotes.c_str()), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS)); + QAction *showInPeopleAct = new QAction(QIcon(), tr("Show author in people tab"), this); + connect(showInPeopleAct, SIGNAL(triggered()), this, SLOT(showAuthorInPeople())); - QTextDocument doc; - doc.setHtml(ui->notes->text()); + int S = QFontMetricsF(font()).height() ; - if(doc.toPlainText().trimmed().isEmpty()) - ui->notes->hide(); + ui->voteUpButton->setIconSize(QSize(S*1.5,S*1.5)); + ui->voteDownButton->setIconSize(QSize(S*1.5,S*1.5)); + ui->commentButton->setIconSize(QSize(S*1.5,S*1.5)); + ui->readButton->setIconSize(QSize(S*1.5,S*1.5)); + ui->shareButton->setIconSize(QSize(S*1.5,S*1.5)); + + QMenu *menu = new QMenu(); + menu->addAction(CopyLinkAction); + menu->addSeparator(); + menu->addAction(showInPeopleAct); + ui->shareButton->setMenu(menu); + + ui->clearButton->hide(); + ui->readAndClearButton->hide(); + + RsReputationLevel overall_reputation = rsReputations->overallReputationLevel(mPost.mMeta.mAuthorId); + bool redacted = (overall_reputation == RsReputationLevel::LOCALLY_NEGATIVE); + + if(redacted) + { + ui->commentButton->setDisabled(true); + ui->voteUpButton->setDisabled(true); + ui->voteDownButton->setDisabled(true); + ui->fromLabel->setId(mPost.mMeta.mAuthorId); + ui->titleLabel->setText(tr( "

The author of this message (with ID %1) is banned.").arg(QString::fromStdString(mPost.mMeta.mAuthorId.toStdString()))) ; + QDateTime qtime; + qtime.setTime_t(mPost.mMeta.mPublishTs); + QString timestamp = qtime.toString("hh:mm dd-MMM-yyyy"); + ui->dateLabel->setText(timestamp); + } + else + { + QPixmap sqpixmap2 = FilesDefs::getPixmapFromQtResourcePath(":/images/thumb-default.png"); + + QDateTime qtime; + qtime.setTime_t(mPost.mMeta.mPublishTs); + QString timestamp = qtime.toString("hh:mm dd-MMM-yyyy"); + QString timestamp2 = misc::timeRelativeToNow(mPost.mMeta.mPublishTs); + ui->dateLabel->setText(timestamp2); + ui->dateLabel->setToolTip(timestamp); + + ui->fromLabel->setId(mPost.mMeta.mAuthorId); + + // Use QUrl to check/parse our URL + // The only combination that seems to work: load as EncodedUrl, extract toEncoded(). + QByteArray urlarray(mPost.mLink.c_str()); + QUrl url = QUrl::fromEncoded(urlarray.trimmed()); + QString urlstr = "Invalid Link"; + QString sitestr = "Invalid Link"; + + bool urlOkay = url.isValid(); + if (urlOkay) + { + QString scheme = url.scheme(); + if ((scheme != "https") + && (scheme != "http") + && (scheme != "ftp") + && (scheme != "retroshare")) + { + urlOkay = false; + sitestr = "Invalid Link Scheme"; + } + } + + if (urlOkay) + { + urlstr = QString(" "); + urlstr += QString::fromUtf8(mPost.mMeta.mMsgName.c_str()); + urlstr += QString(" "); + + QString siteurl = url.toEncoded(); + sitestr = QString(" %2 ").arg(siteurl).arg(siteurl); + + ui->titleLabel->setText(urlstr); + } + else + ui->titleLabel->setText( QString::fromUtf8(mPost.mMeta.mMsgName.c_str()) ); + + if (urlarray.isEmpty()) + { + ui->siteLabel->hide(); + } + + ui->siteLabel->setText(sitestr); + + if(dmode == DISPLAY_MODE_COMPACT) + { + if(mPost.mImage.mData != NULL) + { + QPixmap pixmap; + GxsIdDetails::loadPixmapFromData(mPost.mImage.mData, mPost.mImage.mSize, pixmap,GxsIdDetails::ORIGINAL); + // Wiping data - as its been passed to thumbnail. + + + QPixmap scaledpixmap; + if(pixmap.width() > 800){ + QPixmap scaledpixmap = pixmap.scaledToWidth(800, Qt::SmoothTransformation); + ui->pictureLabel_compact->setPixmap(scaledpixmap); + }else{ + ui->pictureLabel_compact->setPixmap(pixmap); + } + } + else if (mPost.mImage.mData == NULL) + ui->pictureLabel_compact->hide(); + else + ui->pictureLabel_compact->show(); + } + else + { + if(mPost.mImage.mData != NULL) + { + QPixmap pixmap; + GxsIdDetails::loadPixmapFromData(mPost.mImage.mData, mPost.mImage.mSize, pixmap,GxsIdDetails::ORIGINAL); + // Wiping data - as its been passed to thumbnail. + + + QPixmap scaledpixmap; + if(pixmap.width() > 800){ + QPixmap scaledpixmap = pixmap.scaledToWidth(800, Qt::SmoothTransformation); + ui->pictureLabel->setPixmap(scaledpixmap); + }else{ + ui->pictureLabel->setPixmap(pixmap); + } + } + else if (mPost.mImage.mData == NULL) + ui->pictureLabel->hide(); + else + ui->pictureLabel->show(); + } + } + + //QString score = "Hot" + QString::number(post.mHotScore); + //score += " Top" + QString::number(post.mTopScore); + //score += " New" + QString::number(post.mNewScore); + + QString score = QString::number(mPost.mTopScore); + + ui->scoreLabel->setText(score); + + // FIX THIS UP LATER. + ui->notes->setText(RsHtml().formatText(NULL, QString::fromUtf8(mPost.mNotes.c_str()), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS)); + + QTextDocument doc; + doc.setHtml(ui->notes->text()); + + if(doc.toPlainText().trimmed().isEmpty()) + ui->notes->hide(); #ifdef TO_REMOVE - // differences between Feed or Top of Comment. - if (mFeedHolder) - { - // feed. - //frame_comment->show(); - ui->commentButton->show(); + // differences between Feed or Top of Comment. + if (mFeedHolder) + { + // feed. + //frame_comment->show(); + ui->commentButton->show(); - if (mPost.mComments) - { - QString commentText = QString::number(mPost.mComments); - commentText += " "; - commentText += tr("Comments"); - ui->commentButton->setText(commentText); - } - else - { - ui->commentButton->setText(tr("Comment")); - } + if (mPost.mComments) + { + QString commentText = QString::number(mPost.mComments); + commentText += " "; + commentText += tr("Comments"); + ui->commentButton->setText(commentText); + } + else + { + ui->commentButton->setText(tr("Comment")); + } - setReadStatus(IS_MSG_NEW(mPost.mMeta.mMsgStatus), IS_MSG_UNREAD(mPost.mMeta.mMsgStatus) || IS_MSG_NEW(mPost.mMeta.mMsgStatus)); - } - else + setReadStatus(IS_MSG_NEW(mPost.mMeta.mMsgStatus), IS_MSG_UNREAD(mPost.mMeta.mMsgStatus) || IS_MSG_NEW(mPost.mMeta.mMsgStatus)); + } + else #endif - { - // no feed. - //frame_comment->hide(); - ui->commentButton->hide(); + { + // no feed. + //frame_comment->hide(); + ui->commentButton->hide(); - ui->readButton->hide(); - ui->newLabel->hide(); - } + ui->readButton->hide(); + ui->newLabel->hide(); + } #ifdef TO_REMOVE - if (mIsHome) - { - ui->clearButton->hide(); - ui->readAndClearButton->hide(); - } - else + if (mIsHome) + { + ui->clearButton->hide(); + ui->readAndClearButton->hide(); + } + else #endif - { - ui->clearButton->show(); - ui->readAndClearButton->show(); - } + { + ui->clearButton->show(); + ui->readAndClearButton->show(); + } - // disable voting buttons - if they have already voted. - if (mPost.mMeta.mMsgStatus & GXS_SERV::GXS_MSG_STATUS_VOTE_MASK) - { - ui->voteUpButton->setEnabled(false); - ui->voteDownButton->setEnabled(false); - } + // disable voting buttons - if they have already voted. + if (mPost.mMeta.mMsgStatus & GXS_SERV::GXS_MSG_STATUS_VOTE_MASK) + { + ui->voteUpButton->setEnabled(false); + ui->voteDownButton->setEnabled(false); + } #if 0 - uint32_t up, down, nComments; - - bool ok = rsPosted->retrieveScores(mPost.mMeta.mServiceString, up, down, nComments); + uint32_t up, down, nComments; - if(ok) - { - int32_t vote = up - down; - scoreLabel->setText(QString::number(vote)); + bool ok = rsPosted->retrieveScores(mPost.mMeta.mServiceString, up, down, nComments); - numCommentsLabel->setText("

# Comments: " - + QString::number(nComments) + "

"); - } + if(ok) + { + int32_t vote = up - down; + scoreLabel->setText(QString::number(vote)); - mInFill = false; + numCommentsLabel->setText("

# Comments: " + + QString::number(nComments) + "

"); + } + + mInFill = false; #endif #ifdef TODO - emit sizeChanged(this); + emit sizeChanged(this); #endif } -void BoardPostDisplayWidget::toggleNotes() {} + diff --git a/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.h b/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.h index 8a165dc76..d3acbc701 100644 --- a/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.h +++ b/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.h @@ -29,25 +29,32 @@ namespace Ui { class BoardPostDisplayWidget; } -class RsPostedPost; +struct RsPostedPost; class BoardPostDisplayWidget : public QWidget { Q_OBJECT public: - BoardPostDisplayWidget(const RsPostedPost& post,QWidget *parent=nullptr); + enum DisplayMode { + DISPLAY_MODE_UNKNOWN = 0x00, + DISPLAY_MODE_CARD_VIEW = 0x01, + DISPLAY_MODE_COMPACT = 0x02 + }; + + BoardPostDisplayWidget(const RsPostedPost& post,DisplayMode display_mode,QWidget *parent=nullptr); virtual ~BoardPostDisplayWidget(); static const char *DEFAULT_BOARD_IMAGE; protected: /* GxsGroupFeedItem */ - void setup() ; - void fill() ; - void doExpand(bool open) {} + virtual void setup(); // to be overloaded by the different views + + void doExpand(bool) {} void setComment(const RsGxsComment&) ; void setReadStatus(bool isNew, bool isUnread) ; + void toggle() {} void setCommentsSize(int comNb) ; void makeUpVote() ; @@ -57,9 +64,14 @@ protected: signals: void vote(const RsGxsGrpMsgIdPair& msgId, bool up_or_down); -private: - /** Qt Designer generated object */ - Ui::BoardPostDisplayWidget *ui; - +protected: RsPostedPost mPost; + + DisplayMode dmode; + bool mExpanded; + +private: + /** Qt Designer generated object */ + Ui::BoardPostDisplayWidget *ui; }; + diff --git a/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.ui b/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.ui index 900877531..473ccbf4e 100644 --- a/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.ui +++ b/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.ui @@ -7,7 +7,7 @@ 0 0 747 - 199 + 221 @@ -22,394 +22,479 @@ - + - + - + - - - - 0 - 0 - - - - Vote up - - - - - - - :/images/up-arrow.png:/images/up-arrow.png - - - true - - + + + + + + 0 + 0 + + + + Vote up + + + + + + + :/images/up-arrow.png:/images/up-arrow.png + + + true + + + + + + + + 9 + + + + 0 + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + Vote down + + + + + + \/ + + + + :/images/down-arrow.png:/images/down-arrow.png + + + true + + + + - - - - 9 - + + + Qt::Vertical - - 0 - - - Qt::AlignCenter - - - - - - - - 0 - 0 - - - + - 0 - 0 + 20 + 40 - - Vote down - - - - - - \/ - - - - :/images/down-arrow.png:/images/down-arrow.png - - - true - - + - - - Qt::Vertical + + + PictureLabel_compact - - - 20 - 40 - - - + + + + + + + + 5 + + + 0 + + + 6 + + + + + + 0 + 0 + + + + + 50 + false + + + + Posted by + + + + + + + + 0 + 0 + + + + Signed by + + + true + + + + + + + + 0 + 0 + + + + You eyes only + + + true + + + + + + + + 24 + 16777215 + + + + Qt::NoFocus + + + Toggle Message Read Status + + + + :/images/message-state-unread.png:/images/message-state-unread.png + + + true + + + false + + + true + + + + + + + New + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 70 + 20 + + + + + + + + + + + 0 + 0 + + + + + Arial + 10 + 75 + true + + + + This is a very very very very loooooooooooooooonnnnnnnnnnnnnnnnng title don't you think? Yes it is and should wrap around I hope + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + true + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + + + + + + + TextLabel + + + true + + + true + + + + + + + + 0 + 0 + + + + site + + + true + + + + + + + + + PictureLabel + + + true + + + + + + + Qt::Horizontal + + + + 268 + 17 + + + + + + + + + + + + Expand + + + + + + + :/images/expand.png:/images/expand.png + + + true + + + + + + + Comments + + + + :/images/comments.png:/images/comments.png + + + Qt::ToolButtonTextBesideIcon + + + true + + + + + + + Share + + + + :/images/share.png:/images/share.png + + + true + + + + + + + Qt::Horizontal + + + + 308 + 20 + + + + + + + + + 24 + 16777215 + + + + Qt::NoFocus + + + Set as read and remove item + + + + :/icons/png/correct.png:/icons/png/correct.png + + + + + + + + 24 + 16777215 + + + + Qt::NoFocus + + + Remove Item + + + + :/icons/png/exit2.png:/icons/png/exit2.png + + + + + + - - - - - 5 - - - 0 - - - 6 - - - - - - 0 - 0 - - - - - 50 - false - - - - Posted by - - - - - - - - 0 - 0 - - - - Signed by - - - true - - - - - - - - 0 - 0 - - - - You eyes only - - - true - - - - - - - - 24 - 16777215 - - - - Qt::NoFocus - - - Toggle Message Read Status - - - - :/images/message-state-unread.png:/images/message-state-unread.png - - - true - - - false - - - true - - - - - - - New - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 70 - 20 - - - - - - - - - - - 0 - 0 - - - - - Arial - 10 - 75 - true - - - - This is a very very very very loooooooooooooooonnnnnnnnnnnnnnnnng title don't you think? Yes it is and should wrap around I hope - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - true - - - true - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse - - - - - - - TextLabel - - - true - - - true - - - - - - - - 0 - 0 - - - - site - - - true - - - - - - - - - PictureLabel - - - true - - - - - - - Qt::Horizontal - - - - 268 - 17 - - - - - - - - - - - - Comments - - - - :/images/comments.png:/images/comments.png - - - Qt::ToolButtonTextBesideIcon - - - true - - - - - - - Share - - - - :/images/share.png:/images/share.png - - - true - - - - - - - Qt::Horizontal - - - - 308 - 20 - - - - - - - - - 24 - 16777215 - - - - Qt::NoFocus - - - Set as read and remove item - - - - :/icons/png/correct.png:/icons/png/correct.png - - - - - - - - 24 - 16777215 - - - - Qt::NoFocus - - - Remove Item - - - - :/icons/png/exit2.png:/icons/png/exit2.png - - - - - - + + + + 800 + 600 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + Qt::Horizontal + + + + 257 + 20 + + + + + + + + TextLabel + + + true + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + + + + + + + Qt::Horizontal + + + + 257 + 20 + + + + + + @@ -426,9 +511,9 @@ + - diff --git a/retroshare-gui/src/gui/Posted/PostedCardView.h b/retroshare-gui/src/gui/Posted/PostedCardView.h index 79c9c3fdb..0f4f5f2ab 100644 --- a/retroshare-gui/src/gui/Posted/PostedCardView.h +++ b/retroshare-gui/src/gui/Posted/PostedCardView.h @@ -31,7 +31,7 @@ class PostedCardView; } class FeedHolder; -class RsPostedPost; +struct RsPostedPost; class PostedCardView : public BasePostedItem { @@ -47,7 +47,7 @@ protected: void setup() override; void fill() override; - void doExpand(bool open) override {} + void doExpand(bool) override {} void setComment(const RsGxsComment&) override; void setReadStatus(bool isNew, bool isUnread) override; void toggle() override {} diff --git a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp index 3df9a3d76..608aff438 100644 --- a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp +++ b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp @@ -43,7 +43,6 @@ #include "PostedListWidgetWithModel.h" #include "PostedPostsModel.h" -#include "PostedCardView.h" #include "BoardPostDisplayWidget.h" #include @@ -64,6 +63,8 @@ // #define IMAGE_COPYLINK ":/images/copyrslink.png" +Q_DECLARE_METATYPE(RsPostedPost); + // Delegate used to paint into the table of thumbnails void PostedPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const @@ -82,7 +83,8 @@ void PostedPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem & painter->fillRect( option.rect, option.backgroundBrush); painter->restore(); - BoardPostDisplayWidget w(post); + BoardPostDisplayWidget w(post,mDisplayMode); + w.setMaximumWidth(mCellWidthPix); w.setMinimumWidth(mCellWidthPix); w.adjustSize(); @@ -155,7 +157,7 @@ QSize PostedPostDelegate::sizeHint(const QStyleOptionViewItem& option, const QMo RsPostedPost post = index.data(Qt::UserRole).value() ; - BoardPostDisplayWidget w(post); + BoardPostDisplayWidget w(post,mDisplayMode); w.setMinimumWidth(mCellWidthPix); w.setMaximumWidth(mCellWidthPix); w.adjustSize(); @@ -169,15 +171,15 @@ QSize PostedPostDelegate::sizeHint(const QStyleOptionViewItem& option, const QMo QWidget *PostedPostDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex& index) const { - RsPostedPost post = index.data(Qt::UserRole).value() ; + RsPostedPost post = index.data(Qt::UserRole).value() ; if(index.column() == RsPostedPostsModel::COLUMN_POSTS) { - QWidget *w = new BoardPostDisplayWidget(post,parent); - w->setMinimumWidth(mCellWidthPix); - w->setMaximumWidth(mCellWidthPix); - w->adjustSize(); - return w; + QWidget *w = new BoardPostDisplayWidget(post,mDisplayMode,parent); + w->setMinimumWidth(mCellWidthPix); + w->setMaximumWidth(mCellWidthPix); + w->adjustSize(); + return w; } else return NULL; @@ -213,6 +215,8 @@ PostedListWidgetWithModel::PostedListWidgetWithModel(const RsGxsGroupId& postedI //connect(ui->channelFiles_TV->header(),SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), this, SLOT(sortColumnFiles(int,Qt::SortOrder))); connect(ui->postsTree,SIGNAL(customContextMenuRequested(const QPoint&)),this,SLOT(postContextMenu(const QPoint&))); + connect(ui->cardViewButton,SIGNAL(clicked()),this,SLOT(switchDisplayMode())); + connect(ui->classicViewButton,SIGNAL(clicked()),this,SLOT(switchDisplayMode())); connect(mPostedPostsModel,SIGNAL(boardPostsLoaded()),this,SLOT(postPostLoad())); @@ -248,7 +252,9 @@ PostedListWidgetWithModel::PostedListWidgetWithModel(const RsGxsGroupId& postedI settingsChanged(); setGroupId(postedId); - mPostedPostsModel->updateBoard(postedId); + ui->classicViewButton->setChecked(true); // inits both button checking consistency and delegate display mode variables. + + mPostedPostsModel->updateBoard(postedId); mEventHandlerId = 0; // Needs to be asynced because this function is called by another thread! @@ -258,6 +264,22 @@ PostedListWidgetWithModel::PostedListWidgetWithModel(const RsGxsGroupId& postedI }, mEventHandlerId, RsEventType::GXS_POSTED ); } +void PostedListWidgetWithModel::switchDisplayMode() +{ + if(sender() == ui->classicViewButton) + { + whileBlocking(ui->cardViewButton)->setChecked(false); + mPostedPostsDelegate->setDisplayMode(BoardPostDisplayWidget::DISPLAY_MODE_COMPACT); + } + else + { + whileBlocking(ui->classicViewButton)->setChecked(false); + mPostedPostsDelegate->setDisplayMode(BoardPostDisplayWidget::DISPLAY_MODE_CARD_VIEW); + } + + mPostedPostsModel->update(); +} + void PostedListWidgetWithModel::updateSorting(int s) { switch(s) @@ -724,33 +746,6 @@ int PostedListWidgetWithModel::viewMode() } #endif -void PostedListWidgetWithModel::setViewMode(int viewMode) -{ -#ifdef TODO - switch (viewMode) { - case VIEW_MODE_FEEDS: - ui->feedWidget->show(); - ui->fileWidget->hide(); - - ui->feedToolButton->setChecked(true); - ui->fileToolButton->setChecked(false); - - break; - case VIEW_MODE_FILES: - ui->feedWidget->hide(); - ui->fileWidget->show(); - - ui->feedToolButton->setChecked(false); - ui->fileToolButton->setChecked(true); - - break; - default: - setViewMode(VIEW_MODE_FEEDS); - return; - } -#endif -} - #ifdef TODO /*static*/ bool PostedListWidgetWithModel::filterItem(FeedItem *feedItem, const QString &text, int filter) { diff --git a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.h b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.h index 365504b30..8ba9c77fe 100644 --- a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.h +++ b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.h @@ -29,6 +29,7 @@ #include "gui/gxs/GxsMessageFramePostWidget.h" #include "gui/feeds/FeedHolder.h" +#include "gui/Posted/BoardPostDisplayWidget.h" namespace Ui { class PostedListWidgetWithModel; @@ -43,7 +44,7 @@ class PostedPostDelegate: public QAbstractItemDelegate Q_OBJECT public: - PostedPostDelegate(QObject *parent=0) : QAbstractItemDelegate(parent),mCellWidthPix(100){} + PostedPostDelegate(QObject *parent=0) : QAbstractItemDelegate(parent),mCellWidthPix(100),mDisplayMode(BoardPostDisplayWidget::DISPLAY_MODE_COMPACT){} virtual ~PostedPostDelegate(){} void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const override; @@ -54,11 +55,13 @@ class PostedPostDelegate: public QAbstractItemDelegate int cellSize(const QFont& font) const; void setCellWidth(int pix) { mCellWidthPix = pix; } + void setDisplayMode(BoardPostDisplayWidget::DisplayMode dm) { mDisplayMode = dm; } private: QSize cellSize(const QSize& w) const; int mCellWidthPix; + BoardPostDisplayWidget::DisplayMode mDisplayMode; }; class PostedListWidgetWithModel: public GxsMessageFrameWidget @@ -117,10 +120,10 @@ protected: private slots: void updateSorting(int); - void updateGroupData(); + void switchDisplayMode(); + void updateGroupData(); void createMsg(); void subscribeGroup(bool subscribe); - void setViewMode(int viewMode); void settingsChanged(); void postPostLoad(); void postContextMenu(const QPoint&); diff --git a/retroshare-gui/src/gui/Posted/PostedPostsModel.cpp b/retroshare-gui/src/gui/Posted/PostedPostsModel.cpp index 5ca140091..0720b01d0 100644 --- a/retroshare-gui/src/gui/Posted/PostedPostsModel.cpp +++ b/retroshare-gui/src/gui/Posted/PostedPostsModel.cpp @@ -139,6 +139,10 @@ void RsPostedPostsModel::postMods() emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mDisplayedNbPosts,0,(void*)NULL)); } +void RsPostedPostsModel::update() +{ + emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mDisplayedNbPosts,0,(void*)NULL)); +} void RsPostedPostsModel::setFilter(const QStringList& strings, uint32_t& count) { diff --git a/retroshare-gui/src/gui/Posted/PostedPostsModel.h b/retroshare-gui/src/gui/Posted/PostedPostsModel.h index 0aab99b01..ac36e96c4 100644 --- a/retroshare-gui/src/gui/Posted/PostedPostsModel.h +++ b/retroshare-gui/src/gui/Posted/PostedPostsModel.h @@ -135,6 +135,9 @@ public: void updateBoard(const RsGxsGroupId& posted_group_id); const RsGxsGroupId& currentGroupId() const; + // Triggers a data change for all items. This can be used to redraw the view without re-loading the data. + void update(); + #ifdef TODO void setSortMode(SortMode mode) ;