switched to using tabs for comments in order to have more room. Layout still not working

This commit is contained in:
csoler 2020-09-19 22:32:19 +02:00
parent c7bc7e814b
commit f64482e3dd
5 changed files with 110 additions and 28 deletions

View file

@ -55,11 +55,16 @@ BoardPostDisplayWidget::BoardPostDisplayWidget(const RsPostedPost& post, Display
ui->setupUi(this); ui->setupUi(this);
setup(); setup();
if(mode != DISPLAY_MODE_COMMENTS)
ui->verticalLayout->addStretch(); ui->verticalLayout->addStretch();
else
ui->commentsWidget->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::MinimumExpanding);
ui->verticalLayout->setAlignment(Qt::AlignTop); ui->verticalLayout->setAlignment(Qt::AlignTop);
ui->topLayout->setAlignment(Qt::AlignTop); ui->topLayout->setAlignment(Qt::AlignTop);
ui->arrowsLayout->addStretch(); ui->arrowsLayout->addStretch();
ui->arrowsLayout->setAlignment(Qt::AlignTop); ui->arrowsLayout->setAlignment(Qt::AlignTop);
ui->verticalLayout_2->addStretch();
if(display_flags & SHOW_COMMENTS) if(display_flags & SHOW_COMMENTS)
{ {
@ -165,7 +170,10 @@ void BoardPostDisplayWidget::setup()
{ {
// show/hide things based on the view type // show/hide things based on the view type
if(dmode == DISPLAY_MODE_COMPACT) switch(dmode)
{
default:
case DISPLAY_MODE_COMPACT:
{ {
ui->pictureLabel_compact->show(); ui->pictureLabel_compact->show();
ui->expandButton->hide(); ui->expandButton->hide();
@ -175,12 +183,34 @@ void BoardPostDisplayWidget::setup()
ui->notes->hide(); ui->notes->hide();
ui->siteLabel->hide(); ui->siteLabel->hide();
} }
else break;
case DISPLAY_MODE_COMMENTS:
{
ui->pictureLabel_compact->show();
ui->expandButton->hide();
ui->pictureLabel->hide();
ui->notes->hide();
ui->scoreLabel->hide();
ui->voteDownButton->hide();
ui->voteUpButton->hide();
ui->siteLabel->hide();
ui->newLabel->hide();
ui->commentButton->hide();
ui->expandButton->hide();
ui->shareButton->hide();
ui->readButton->hide();
ui->newLabel->hide();
}
break;
case DISPLAY_MODE_CARD_VIEW:
{ {
ui->frame_picture->hide(); ui->frame_picture->hide();
ui->pictureLabel_compact->hide(); ui->pictureLabel_compact->hide();
ui->expandButton->hide(); ui->expandButton->hide();
} }
break;
}
if(mDisplayFlags & SHOW_NOTES) if(mDisplayFlags & SHOW_NOTES)
{ {
@ -311,7 +341,7 @@ void BoardPostDisplayWidget::setup()
ui->siteLabel->setText(sitestr); ui->siteLabel->setText(sitestr);
if(dmode == DISPLAY_MODE_COMPACT) if(dmode == DISPLAY_MODE_COMPACT || dmode == DISPLAY_MODE_COMMENTS)
{ {
if(mPost.mImage.mData != NULL) if(mPost.mImage.mData != NULL)
{ {
@ -373,6 +403,7 @@ void BoardPostDisplayWidget::setup()
// feed. // feed.
//frame_comment->show(); //frame_comment->show();
if(dmode != DISPLAY_MODE_COMMENTS)
ui->commentButton->show(); ui->commentButton->show();
if (mPost.mComments) if (mPost.mComments)

View file

@ -39,7 +39,8 @@ public:
enum DisplayMode { enum DisplayMode {
DISPLAY_MODE_UNKNOWN = 0x00, DISPLAY_MODE_UNKNOWN = 0x00,
DISPLAY_MODE_CARD_VIEW = 0x01, DISPLAY_MODE_CARD_VIEW = 0x01,
DISPLAY_MODE_COMPACT = 0x02 DISPLAY_MODE_COMPACT = 0x02,
DISPLAY_MODE_COMMENTS = 0x03,
}; };
enum DisplayFlags: uint8_t { enum DisplayFlags: uint8_t {
@ -76,7 +77,7 @@ protected slots:
signals: signals:
void vote(const RsGxsGrpMsgIdPair& msgId, bool up_or_down); void vote(const RsGxsGrpMsgIdPair& msgId, bool up_or_down);
void expand(RsGxsMessageId,bool); void expand(RsGxsMessageId,bool);
void commentsRequested(RsGxsMessageId,bool); void commentsRequested(const RsGxsMessageId&,bool);
protected: protected:
RsPostedPost mPost; RsPostedPost mPost;

View file

@ -32,6 +32,7 @@
#include "util/misc.h" #include "util/misc.h"
#include "gui/Posted/PostedCreatePostDialog.h" #include "gui/Posted/PostedCreatePostDialog.h"
#include "gui/common/UIStateHelper.h" #include "gui/common/UIStateHelper.h"
#include "gui/common/RSTabWidget.h"
#include "gui/settings/rsharesettings.h" #include "gui/settings/rsharesettings.h"
#include "gui/feeds/SubFileItem.h" #include "gui/feeds/SubFileItem.h"
#include "gui/notifyqt.h" #include "gui/notifyqt.h"
@ -91,8 +92,8 @@ void PostedPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem &
BoardPostDisplayWidget w(post,mDisplayMode,displayFlags(post.mMeta.mMsgId)); BoardPostDisplayWidget w(post,mDisplayMode,displayFlags(post.mMeta.mMsgId));
w.adjustSize();
w.setFixedSize(option.rect.size()); w.setFixedSize(option.rect.size());
w.adjustSize();
QPixmap pixmap(option.rect.size()); QPixmap pixmap(option.rect.size());
@ -145,16 +146,16 @@ void PostedPostDelegate::expandItem(RsGxsMessageId msgId,bool expanded)
mPostListWidget->forceRedraw(); mPostListWidget->forceRedraw();
} }
void PostedPostDelegate::commentItem(RsGxsMessageId msgId,bool comment) // void PostedPostDelegate::commentItem(RsGxsMessageId msgId,bool comment)
{ // {
std::cerr << __PRETTY_FUNCTION__ << ": received commentItem signal. b=" << comment << std::endl; // std::cerr << __PRETTY_FUNCTION__ << ": received commentItem signal. b=" << comment << std::endl;
if(comment) // if(comment)
mShowCommentItems.insert(msgId); // mShowCommentItems.insert(msgId);
else // else
mShowCommentItems.erase(msgId); // mShowCommentItems.erase(msgId);
//
mPostListWidget->forceRedraw(); // mPostListWidget->forceRedraw();
} // }
uint8_t PostedPostDelegate::displayFlags(const RsGxsMessageId &id) const uint8_t PostedPostDelegate::displayFlags(const RsGxsMessageId &id) const
{ {
uint8_t flags=0; uint8_t flags=0;
@ -178,10 +179,10 @@ QWidget *PostedPostDelegate::createEditor(QWidget *parent, const QStyleOptionVie
QObject::connect(w,SIGNAL(vote(RsGxsGrpMsgIdPair,bool)),mPostListWidget,SLOT(voteMsg(RsGxsGrpMsgIdPair,bool))); QObject::connect(w,SIGNAL(vote(RsGxsGrpMsgIdPair,bool)),mPostListWidget,SLOT(voteMsg(RsGxsGrpMsgIdPair,bool)));
QObject::connect(w,SIGNAL(expand(RsGxsMessageId,bool)),this,SLOT(expandItem(RsGxsMessageId,bool))); QObject::connect(w,SIGNAL(expand(RsGxsMessageId,bool)),this,SLOT(expandItem(RsGxsMessageId,bool)));
QObject::connect(w,SIGNAL(commentsRequested(RsGxsMessageId,bool)),this,SLOT(commentItem(RsGxsMessageId,bool))); QObject::connect(w,SIGNAL(commentsRequested(const RsGxsMessageId&,bool)),mPostListWidget,SLOT(openComments(const RsGxsMessageId&)));
w->adjustSize();
w->setFixedSize(option.rect.size()); w->setFixedSize(option.rect.size());
w->adjustSize();
return w; return w;
} }
@ -217,6 +218,10 @@ PostedListWidgetWithModel::PostedListWidgetWithModel(const RsGxsGroupId& postedI
ui->idChooser->setFlags(IDCHOOSER_ID_REQUIRED); ui->idChooser->setFlags(IDCHOOSER_ID_REQUIRED);
connect(ui->tabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(tabCloseRequested(int)));
ui->tabWidget->hideCloseButton(0);
ui->tabWidget->hideCloseButton(1);
connect(ui->sortStrategy_CB,SIGNAL(currentIndexChanged(int)),this,SLOT(updateSorting(int))); connect(ui->sortStrategy_CB,SIGNAL(currentIndexChanged(int)),this,SLOT(updateSorting(int)));
connect(ui->nextButton,SIGNAL(clicked()),this,SLOT(next10Posts())); connect(ui->nextButton,SIGNAL(clicked()),this,SLOT(next10Posts()));
connect(ui->prevButton,SIGNAL(clicked()),this,SLOT(prev10Posts())); connect(ui->prevButton,SIGNAL(clicked()),this,SLOT(prev10Posts()));
@ -522,6 +527,9 @@ void PostedListWidgetWithModel::updateGroupData()
insertBoardDetails(mGroup); insertBoardDetails(mGroup);
while(ui->tabWidget->widget(2) != nullptr)
tabCloseRequested(2);
emit groupDataLoaded(); emit groupDataLoaded();
emit groupChanged(this); // signals the parent widget to e.g. update the group tab name emit groupChanged(this); // signals the parent widget to e.g. update the group tab name
} ); } );
@ -637,9 +645,40 @@ void PostedListWidgetWithModel::setAllMessagesReadDo(bool read, uint32_t &token)
std::cerr << __PRETTY_FUNCTION__ << ": not implemented" << std::endl; std::cerr << __PRETTY_FUNCTION__ << ": not implemented" << std::endl;
} }
void PostedListWidgetWithModel::openComments(uint32_t /*type*/, const RsGxsGroupId &groupId, const QVector<RsGxsMessageId>& msg_versions,const RsGxsMessageId &msgId, const QString &title) void PostedListWidgetWithModel::openComments(const RsGxsMessageId& msgId)
{ {
emit loadComment(groupId, msg_versions,msgId, title); QModelIndex index = mPostedPostsModel->getIndexOfMessage(msgId);
if(!index.isValid())
return;
RsPostedPost post = index.data(Qt::UserRole).value<RsPostedPost>() ;
BoardPostDisplayWidget *w = new BoardPostDisplayWidget(post,BoardPostDisplayWidget::DISPLAY_MODE_COMMENTS,BoardPostDisplayWidget::SHOW_COMMENTS);
QString title = QString::fromUtf8(post.mMeta.mMsgName.c_str());
if(title.length() > 30)
title = title.left(27) + "...";
ui->tabWidget->addTab(w,title);
ui->tabWidget->layout();
}
void PostedListWidgetWithModel::tabCloseRequested(int index)
{
std::cerr << "GxsCommentContainer::tabCloseRequested(" << index << ")";
std::cerr << std::endl;
if (index != 0)
{
QWidget *comments = ui->tabWidget->widget(index);
ui->tabWidget->removeTab(index);
delete comments;
}
else
{
std::cerr << "GxsCommentContainer::tabCloseRequested() Not closing First Tab";
std::cerr << std::endl;
}
} }
void PostedListWidgetWithModel::createMsg() void PostedListWidgetWithModel::createMsg()

View file

@ -59,7 +59,7 @@ public:
public slots: public slots:
void expandItem(RsGxsMessageId msgId,bool expanded); void expandItem(RsGxsMessageId msgId,bool expanded);
void commentItem(RsGxsMessageId msgId,bool comment); //void commentItem(RsGxsMessageId msgId,bool comment);
private: private:
// The class keeps a list of expanded items. Because items are constantly re-created, it is not possible // The class keeps a list of expanded items. Because items are constantly re-created, it is not possible
@ -107,7 +107,8 @@ public:
virtual void deleteFeedItem(FeedItem *feedItem, uint32_t type); virtual void deleteFeedItem(FeedItem *feedItem, uint32_t type);
virtual void openChat(const RsPeerId& peerId); virtual void openChat(const RsPeerId& peerId);
#endif #endif
virtual void openComments(uint32_t type, const RsGxsGroupId &groupId, const QVector<RsGxsMessageId> &msg_versions, const RsGxsMessageId &msgId, const QString &title); public slots:
virtual void openComments(const RsGxsMessageId &msgId);
protected: protected:
/* GxsMessageFramePostWidget */ /* GxsMessageFramePostWidget */
@ -130,6 +131,7 @@ protected:
virtual void setAllMessagesReadDo(bool read, uint32_t &token) override; virtual void setAllMessagesReadDo(bool read, uint32_t &token) override;
private slots: private slots:
void tabCloseRequested(int index);
void updateSorting(int); void updateSorting(int);
void switchDisplayMode(); void switchDisplayMode();
void updateGroupData(); void updateGroupData();

View file

@ -15,10 +15,13 @@
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<widget class="QTabWidget" name="tabWidget"> <widget class="RSTabWidget" name="tabWidget">
<property name="currentIndex"> <property name="currentIndex">
<number>1</number> <number>1</number>
</property> </property>
<property name="tabsClosable">
<bool>true</bool>
</property>
<widget class="QWidget" name="tab"> <widget class="QWidget" name="tab">
<attribute name="title"> <attribute name="title">
<string>Details</string> <string>Details</string>
@ -539,6 +542,12 @@ p, li { white-space: pre-wrap; }
<extends>QComboBox</extends> <extends>QComboBox</extends>
<header>gui/gxs/GxsIdChooser.h</header> <header>gui/gxs/GxsIdChooser.h</header>
</customwidget> </customwidget>
<customwidget>
<class>RSTabWidget</class>
<extends>QTabWidget</extends>
<header>gui/common/RSTabWidget.h</header>
<container>1</container>
</customwidget>
</customwidgets> </customwidgets>
<resources> <resources>
<include location="Posted_images.qrc"/> <include location="Posted_images.qrc"/>