From bdb36f7528da2f3a70304dcdf931634a9588e421 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 9 Aug 2020 14:09:50 +0200 Subject: [PATCH] fixed sizes and switching between modes --- .../src/gui/Posted/BoardPostDisplayWidget.cpp | 36 +- .../src/gui/Posted/BoardPostDisplayWidget.ui | 331 ++++++++---------- .../gui/Posted/PostedListWidgetWithModel.cpp | 55 +-- .../gui/Posted/PostedListWidgetWithModel.h | 7 +- .../src/gui/Posted/PostedPostsModel.cpp | 6 + .../src/gui/Posted/PostedPostsModel.h | 3 + 6 files changed, 196 insertions(+), 242 deletions(-) diff --git a/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.cpp b/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.cpp index 47d4e0421..df79d374b 100644 --- a/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.cpp +++ b/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.cpp @@ -48,11 +48,9 @@ const char *BoardPostDisplayWidget::DEFAULT_BOARD_IMAGE = ":/icons/png/newsfeed2 //=================================================================================================================================== BoardPostDisplayWidget::BoardPostDisplayWidget(const RsPostedPost& post,DisplayMode mode,QWidget *parent) - : QWidget(parent),ui(new Ui::BoardPostDisplayWidget()),dmode(mode),mPost(post) + : QWidget(parent),mPost(post),dmode(mode),mExpanded(false),ui(new Ui::BoardPostDisplayWidget()) { ui->setupUi(this); - mExpanded = false; - setup(); } @@ -127,6 +125,10 @@ void BoardPostDisplayWidget::setup() if(dmode == DISPLAY_MODE_COMPACT) { ui->pictureLabel_compact->show(); + ui->pictureLabel->hide(); + ui->notes->hide(); + ui->siteLabel->hide(); + ui->expandButton->show(); if(mExpanded) @@ -182,9 +184,6 @@ void BoardPostDisplayWidget::setup() 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); @@ -265,14 +264,10 @@ void BoardPostDisplayWidget::setup() GxsIdDetails::loadPixmapFromData(mPost.mImage.mData, mPost.mImage.mSize, pixmap,GxsIdDetails::ORIGINAL); // Wiping data - as its been passed to thumbnail. + int desired_height = QFontMetricsF(font()).height() * 5; - QPixmap scaledpixmap; - if(pixmap.width() > 800){ - QPixmap scaledpixmap = pixmap.scaledToWidth(800, Qt::SmoothTransformation); - ui->pictureLabel_compact->setPixmap(scaledpixmap); - }else{ - ui->pictureLabel_compact->setPixmap(pixmap); - } + QPixmap scaledpixmap = pixmap.scaledToHeight(desired_height, Qt::SmoothTransformation); + ui->pictureLabel_compact->setPixmap(scaledpixmap); } else if (mPost.mImage.mData == NULL) ui->pictureLabel_compact->hide(); @@ -353,19 +348,6 @@ void BoardPostDisplayWidget::setup() ui->newLabel->hide(); } -#ifdef TO_REMOVE - if (mIsHome) - { - ui->clearButton->hide(); - ui->readAndClearButton->hide(); - } - else -#endif - { - 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) { @@ -393,6 +375,8 @@ void BoardPostDisplayWidget::setup() mInFill = false; #endif + updateGeometry(); + #ifdef TODO emit sizeChanged(this); #endif diff --git a/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.ui b/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.ui index 473ccbf4e..273eeebd0 100644 --- a/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.ui +++ b/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.ui @@ -6,12 +6,12 @@ 0 0 - 747 - 221 + 816 + 203 - + 0 0 @@ -22,87 +22,104 @@ - + - + + + QLayout::SetMinimumSize + - + + + QLayout::SetMinimumSize + - + - - - - 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 - - + - 0 - - - Qt::AlignCenter - - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - Vote down - - - - - - \/ - - - - :/images/down-arrow.png:/images/down-arrow.png - - - true + PictureLabel_compact - + Qt::Vertical @@ -116,15 +133,11 @@ - - - - PictureLabel_compact - - - + + QLayout::SetMinimumSize + @@ -239,6 +252,54 @@ + + + + Comments + + + + :/images/comments.png:/images/comments.png + + + Qt::ToolButtonTextBesideIcon + + + true + + + + + + + Share + + + + :/images/share.png:/images/share.png + + + true + + + + + + + Expand + + + + + + + :/images/expand.png:/images/expand.png + + + true + + + @@ -330,123 +391,12 @@ - - - - - - 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 - - - - - - - - 800 - 600 - - QFrame::StyledPanel @@ -511,9 +461,8 @@ - - + diff --git a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp index 608aff438..3ae793b54 100644 --- a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp +++ b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp @@ -67,6 +67,8 @@ Q_DECLARE_METATYPE(RsPostedPost); // Delegate used to paint into the table of thumbnails +std::ostream& operator<<(std::ostream& o,const QSize& s) { return o << s.width() << " x " << s.height() ; } + void PostedPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const { if((option.state & QStyle::State_Selected)) // Avoids double display. The selected widget is never exactly the size of the rendered one, @@ -85,13 +87,13 @@ void PostedPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem & BoardPostDisplayWidget w(post,mDisplayMode); - w.setMaximumWidth(mCellWidthPix); - w.setMinimumWidth(mCellWidthPix); + //w.setMaximumWidth(mCellWidthPix); + //w.setMinimumWidth(mCellWidthPix); w.adjustSize(); - QPixmap pixmap(option.rect.size()); + w.setFixedSize(cellSize(w.size())); - std::cerr << "pixmap.depth=" << pixmap.depth() << std::endl; + QPixmap pixmap(option.rect.size()); #ifdef SUSPENDED_CODE if((option.state & QStyle::State_Selected) && post.mMeta.mPublishTs > 0) // check if post is selected and is not empty (end of last row) @@ -114,6 +116,7 @@ void PostedPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem & w.render(&pixmap,QPoint(0,0),QRegion(),QWidget::DrawChildren );// draw the widgets, not the background + std::cerr << "PostedPostDelegate::paint(): w.size() = " << w.size() << std::endl; #ifdef TODO if(IS_MSG_UNREAD(post.mMeta.mMsgStatus) || IS_MSG_NEW(post.mMeta.mMsgStatus)) { @@ -123,15 +126,15 @@ void PostedPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem & } #endif - // debug - if(index.row()==0 && index.column()==0) - { - QFile file("yourFile.png"); - file.open(QIODevice::WriteOnly); - pixmap.save(&file, "PNG"); - std::cerr << "Saved pxmap to png" << std::endl; - } - //std::cerr << "option.rect = " << option.rect.width() << "x" << option.rect.height() << ". fm.height()=" << QFontMetricsF(option.font).height() << std::endl; + // debug + if(index.row()==0 && index.column()==0) + { + QFile file("yourFile.png"); + file.open(QIODevice::WriteOnly); + pixmap.save(&file, "PNG"); + std::cerr << "Saved pxmap to png" << std::endl; + } + //std::cerr << "option.rect = " << option.rect.width() << "x" << option.rect.height() << ". fm.height()=" << QFontMetricsF(option.font).height() << std::endl; painter->save(); @@ -148,7 +151,7 @@ void PostedPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem & QSize PostedPostDelegate::cellSize(const QSize& w) const { - return QSize(mCellWidthPix,0 + w.height() * mCellWidthPix/(float)w.width()); + return QSize(mCellWidthPix,mCellWidthPix * w.height()/(float)w.width()); } QSize PostedPostDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const @@ -158,15 +161,19 @@ QSize PostedPostDelegate::sizeHint(const QStyleOptionViewItem& option, const QMo RsPostedPost post = index.data(Qt::UserRole).value() ; BoardPostDisplayWidget w(post,mDisplayMode); - w.setMinimumWidth(mCellWidthPix); - w.setMaximumWidth(mCellWidthPix); + + //w.setMinimumWidth(mCellWidthPix); + //w.setMaximumWidth(mCellWidthPix); + w.adjustSize(); - QSize ss = cellSize(w.size()) + QSize(0,5); + QSize ss = cellSize(w.size()); - std::cerr << "w =" << w.width() << " x " << w.height() << " new size = " << ss.width() << " x " << ss.height() << std::endl; + std::cerr << "PostedPostDelegate::sizeHint(): w =" << w.width() << " x " << w.height() << " new size = " << ss.width() << " x " << ss.height() ; + w.setFixedSize(ss); - return ss; + std::cerr << " Final size:" << w.size() << std::endl; + return w.size(); } QWidget *PostedPostDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex& index) const @@ -176,9 +183,13 @@ QWidget *PostedPostDelegate::createEditor(QWidget *parent, const QStyleOptionVie if(index.column() == RsPostedPostsModel::COLUMN_POSTS) { QWidget *w = new BoardPostDisplayWidget(post,mDisplayMode,parent); - w->setMinimumWidth(mCellWidthPix); - w->setMaximumWidth(mCellWidthPix); + + //w->setMinimumWidth(mCellWidthPix); + //w->setMaximumWidth(mCellWidthPix); w->adjustSize(); + w->setFixedSize(cellSize(w->size())); + + std::cerr << "PostedPostDelegate::createEditor(): size = " << w->size() << std::endl; return w; } else @@ -277,7 +288,7 @@ void PostedListWidgetWithModel::switchDisplayMode() mPostedPostsDelegate->setDisplayMode(BoardPostDisplayWidget::DISPLAY_MODE_CARD_VIEW); } - mPostedPostsModel->update(); + mPostedPostsModel->deepUpdate(); } void PostedListWidgetWithModel::updateSorting(int s) diff --git a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.h b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.h index 8ba9c77fe..eef377233 100644 --- a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.h +++ b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.h @@ -52,13 +52,14 @@ class PostedPostDelegate: public QAbstractItemDelegate void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const override; QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; - int cellSize(const QFont& font) const; + //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; + QSize cellSize(const QSize& w) const; // Converts the supplied size to the cell size for the current container. + // The client should then scale its widget to fit the given size. int mCellWidthPix; BoardPostDisplayWidget::DisplayMode mDisplayMode; @@ -105,7 +106,7 @@ protected: #ifdef TODO virtual bool insertGroupData(const RsGxsGenericGroupData *data) override; #endif - virtual void blank() ; + virtual void blank() override; #ifdef TODO virtual bool getGroupData(RsGxsGenericGroupData *& data) override; diff --git a/retroshare-gui/src/gui/Posted/PostedPostsModel.cpp b/retroshare-gui/src/gui/Posted/PostedPostsModel.cpp index 0720b01d0..e05e52b70 100644 --- a/retroshare-gui/src/gui/Posted/PostedPostsModel.cpp +++ b/retroshare-gui/src/gui/Posted/PostedPostsModel.cpp @@ -489,6 +489,12 @@ void RsPostedPostsModel::setPostsInterval(int start,int nb_posts) postMods(); } +void RsPostedPostsModel::deepUpdate() +{ + auto posts(mPosts); + setPosts(mPostedGroup,posts); +} + void RsPostedPostsModel::setPosts(const RsPostedGroup& group, std::vector& posts) { preMods(); diff --git a/retroshare-gui/src/gui/Posted/PostedPostsModel.h b/retroshare-gui/src/gui/Posted/PostedPostsModel.h index ac36e96c4..948d892f4 100644 --- a/retroshare-gui/src/gui/Posted/PostedPostsModel.h +++ b/retroshare-gui/src/gui/Posted/PostedPostsModel.h @@ -138,6 +138,9 @@ public: // Triggers a data change for all items. This can be used to redraw the view without re-loading the data. void update(); + // Triggers a preMod, begin/end remove rows and data update. Could be useful if update is not enough to reset cell sizes. + void deepUpdate(); + #ifdef TODO void setSortMode(SortMode mode) ;