Optimized fill of feed items by moving the fill of the hidden area to the first expand of the frame.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8514 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2015-06-17 18:59:12 +00:00
parent 4cb081f4ff
commit 846d5f4f50
27 changed files with 152 additions and 41 deletions

View File

@ -98,7 +98,7 @@ void FeedReaderFeedItem::toggle()
expand(ui->expandFrame->isHidden());
}
void FeedReaderFeedItem::expand(bool open)
void FeedReaderFeedItem::doExpand(bool open)
{
if (mParent) {
mParent->lockLayout(this, true);

View File

@ -42,8 +42,9 @@ public:
FeedReaderFeedItem(RsFeedReader *feedReader, FeedReaderNotify *notify, FeedHolder *parent, const FeedInfo &feedInfo, const FeedMsgInfo &msgInfo);
~FeedReaderFeedItem();
protected:
/* FeedItem */
virtual void expand(bool open);
virtual void doExpand(bool open);
private slots:
/* default stuff */

View File

@ -51,8 +51,9 @@ public:
const RsPostedPost &getPost() const;
RsPostedPost &post();
protected:
/* FeedItem */
virtual void expand(bool /*open*/) {}
virtual void doExpand(bool /*open*/) {}
private slots:
void loadComments();

View File

@ -38,8 +38,9 @@ public:
void updateItemStatic();
protected:
/* FeedItem */
virtual void expand(bool /*open*/) {}
virtual void doExpand(bool /*open*/) {}
private slots:
/* default stuff */

View File

@ -24,9 +24,23 @@
/** Constructor */
FeedItem::FeedItem(QWidget *parent) : QWidget(parent)
{
mWasExpanded = false;
}
FeedItem::~FeedItem()
{
emit feedItemDestroyed(this);
}
void FeedItem::expand(bool open)
{
if (open) {
expandFill(!mWasExpanded);
}
doExpand(open);
if (open) {
mWasExpanded = true;
}
}

View File

@ -34,11 +34,19 @@ public:
/** Default Destructor */
virtual ~FeedItem();
virtual void expand(bool open) = 0;
bool wasExpanded() { return mWasExpanded; }
void expand(bool open);
protected:
virtual void doExpand(bool open) = 0;
virtual void expandFill(bool /*first*/) {}
signals:
void sizeChanged(FeedItem *feedItem);
void feedItemDestroyed(FeedItem *feedItem);
private:
bool mWasExpanded;
};
#endif

View File

@ -166,7 +166,7 @@ void GxsChannelGroupItem::toggle()
expand(ui->expandFrame->isHidden());
}
void GxsChannelGroupItem::expand(bool open)
void GxsChannelGroupItem::doExpand(bool open)
{
if (mFeedHolder)
{

View File

@ -43,10 +43,10 @@ public:
bool setGroup(const RsGxsChannelGroup &group);
/* FeedItem */
virtual void expand(bool open);
protected:
/* FeedItem */
virtual void doExpand(bool open);
/* GxsGroupFeedItem */
virtual QString groupName();
virtual void loadGroup(const uint32_t &token);

View File

@ -34,6 +34,7 @@
#include "gui/RetroShareLink.h"
#include "util/HandleRichText.h"
#include "util/DateTime.h"
#include "util/stringutil.h"
#include <iostream>
@ -311,7 +312,9 @@ void GxsChannelPostItem::fill()
{
/* subject */
ui->titleLabel->setText(QString::fromUtf8(mPost.mMeta.mMsgName.c_str()));
ui->subjectLabel->setText(RsHtml().formatText(NULL, QString::fromUtf8(mPost.mMsg.c_str()), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
// fill first 4 lines of message
ui->subjectLabel->setText(RsHtml().formatText(NULL, RsStringUtil::CopyLines(QString::fromUtf8(mPost.mMsg.c_str()), 4), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
//QString score = QString::number(post.mTopScore);
// scoreLabel->setText(score);
@ -376,8 +379,10 @@ void GxsChannelPostItem::fill()
voteDownButton->setEnabled(false);
}*/
ui->msgLabel->setText(RsHtml().formatText(NULL, QString::fromUtf8(mPost.mMsg.c_str()), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
ui->msgFrame->setVisible(!mPost.mMsg.empty());
if (wasExpanded() || ui->expandFrame->isVisible()) {
fillExpandFrame();
}
ui->datetimelabel->setText(DateTime::formatLongDateTime(mPost.mMeta.mPublishTs));
@ -427,6 +432,11 @@ void GxsChannelPostItem::fill()
mInFill = false;
}
void GxsChannelPostItem::fillExpandFrame()
{
ui->msgLabel->setText(RsHtml().formatText(NULL, QString::fromUtf8(mPost.mMsg.c_str()), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
}
QString GxsChannelPostItem::messageName()
{
return QString::fromUtf8(mPost.mMeta.mMsgName.c_str());
@ -552,7 +562,7 @@ void GxsChannelPostItem::updateItem()
//downloadButton->setEnabled(true);
}
void GxsChannelPostItem::expand(bool open)
void GxsChannelPostItem::doExpand(bool open)
{
if (mFeedHolder)
{
@ -582,6 +592,15 @@ void GxsChannelPostItem::expand(bool open)
}
}
void GxsChannelPostItem::expandFill(bool first)
{
GxsFeedItem::expandFill(first);
if (first) {
fillExpandFrame();
}
}
void GxsChannelPostItem::toggle()
{
expand(ui->expandFrame->isHidden());

View File

@ -55,12 +55,13 @@ public:
QString getMsgLabel();
const std::list<SubFileItem *> &getFileItems() {return mFileItems; }
/* FeedItem */
virtual void expand(bool open);
bool isUnread() const ;
protected:
/* FeedItem */
virtual void doExpand(bool open);
virtual void expandFill(bool first);
/* GxsGroupFeedItem */
virtual QString groupName();
virtual void loadGroup(const uint32_t &token);
@ -92,6 +93,7 @@ signals:
private:
void setup();
void fill();
void fillExpandFrame();
void setReadStatus(bool isNew, bool isUnread);
private:

View File

@ -166,7 +166,7 @@ void GxsForumGroupItem::toggle()
expand(ui->expandFrame->isHidden());
}
void GxsForumGroupItem::expand(bool open)
void GxsForumGroupItem::doExpand(bool open)
{
if (mFeedHolder)
{

View File

@ -43,10 +43,10 @@ public:
bool setGroup(const RsGxsForumGroup &group);
/* FeedItem */
virtual void expand(bool open);
protected:
/* FeedItem */
virtual void doExpand(bool open);
/* GxsGroupFeedItem */
virtual QString groupName();
virtual void loadGroup(const uint32_t &token);

View File

@ -313,7 +313,9 @@ void GxsForumMsgItem::fill()
RetroShareLink msgLink;
msgLink.createGxsMessageLink(RetroShareLink::TYPE_FORUM, mMessage.mMeta.mGroupId, mMessage.mMeta.mMsgId, messageName());
ui->subLabel->setText(msgLink.toHtml());
ui->msgLabel->setText(RsHtml().formatText(NULL, QString::fromUtf8(mMessage.mMsg.c_str()), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
if (wasExpanded() || ui->expandFrame->isVisible()) {
fillExpandFrame();
}
ui->timestamplabel->setText(DateTime::formatLongDateTime(mMessage.mMeta.mPublishTs));
@ -355,12 +357,17 @@ void GxsForumMsgItem::fill()
mInFill = false;
}
void GxsForumMsgItem::fillExpandFrame()
{
ui->msgLabel->setText(RsHtml().formatText(NULL, QString::fromUtf8(mMessage.mMsg.c_str()), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
}
QString GxsForumMsgItem::messageName()
{
return QString::fromUtf8(mMessage.mMeta.mMsgName.c_str());
}
void GxsForumMsgItem::expand(bool open)
void GxsForumMsgItem::doExpand(bool open)
{
if (mFeedHolder)
{
@ -395,6 +402,15 @@ void GxsForumMsgItem::expand(bool open)
}
}
void GxsForumMsgItem::expandFill(bool first)
{
GxsFeedItem::expandFill(first);
if (first) {
fillExpandFrame();
}
}
void GxsForumMsgItem::toggle()
{
expand(ui->expandFrame->isHidden());

View File

@ -46,10 +46,11 @@ public:
bool setGroup(const RsGxsForumGroup &group, bool doFill = true);
bool setMessage(const RsGxsForumMsg &msg, bool doFill = true);
/* FeedItem */
virtual void expand(bool open);
protected:
/* FeedItem */
virtual void doExpand(bool open);
virtual void expandFill(bool first);
/* load message data */
void requestParentMessage(const RsGxsMessageId &msgId);
virtual void loadParentMessage(const uint32_t &token);
@ -78,6 +79,7 @@ signals:
private:
void setup();
void fill();
void fillExpandFrame();
void setReadStatus(bool isNew, bool isUnread);
void setAsRead();
bool isTop();

View File

@ -69,7 +69,6 @@ MsgItem::MsgItem(FeedHolder *parent, uint32_t feedId, const std::string &msgId,
updateItem();
}
void MsgItem::updateItemStatic()
{
/* fill in */
@ -148,8 +147,11 @@ void MsgItem::updateItemStatic()
titleLabel->setText(title);
subjectLabel->setText(QString::fromUtf8(mi.title.c_str()));
msgLabel->setText(RsHtml().formatText(NULL, QString::fromUtf8(mi.msg.c_str()), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
mMsg = QString::fromUtf8(mi.msg.c_str());
if (wasExpanded() || expandFrame->isVisible()) {
fillExpandFrame();
}
std::list<FileInfo>::iterator it;
for(it = mi.files.begin(); it != mi.files.end(); ++it)
@ -175,6 +177,10 @@ void MsgItem::updateItemStatic()
}
}
void MsgItem::fillExpandFrame()
{
msgLabel->setText(RsHtml().formatText(NULL, mMsg, RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
}
void MsgItem::updateItem()
{
@ -207,7 +213,7 @@ void MsgItem::toggle()
expand(expandFrame->isHidden());
}
void MsgItem::expand(bool open)
void MsgItem::doExpand(bool open)
{
if (mParent) {
mParent->lockLayout(this, true);
@ -237,6 +243,15 @@ void MsgItem::expand(bool open)
}
}
void MsgItem::expandFill(bool first)
{
FeedItem::expandFill(first);
if (first) {
fillExpandFrame();
}
}
void MsgItem::removeItem()
{
#ifdef DEBUG_ITEM

View File

@ -39,8 +39,13 @@ public:
void updateItemStatic();
protected:
/* FeedItem */
virtual void expand(bool open);
virtual void doExpand(bool open);
virtual void expandFill(bool first);
private:
void fillExpandFrame();
private slots:
/* default stuff */
@ -61,6 +66,7 @@ private:
ChatId mPeerId;
std::string mMsgId;
QString mMsg;
bool mIsHome;
bool mCloseOnRead;

View File

@ -201,7 +201,7 @@ void PeerItem::toggle()
expand(expandFrame->isHidden());
}
void PeerItem::expand(bool open)
void PeerItem::doExpand(bool open)
{
if (mParent) {
mParent->lockLayout(this, true);

View File

@ -43,8 +43,9 @@ public:
void updateItemStatic();
protected:
/* FeedItem */
virtual void expand(bool open);
virtual void doExpand(bool open);
private slots:
/* default stuff */

View File

@ -171,7 +171,7 @@ void PostedGroupItem::toggle()
expand(ui->expandFrame->isHidden());
}
void PostedGroupItem::expand(bool open)
void PostedGroupItem::doExpand(bool open)
{
if (mFeedHolder)
{

View File

@ -43,10 +43,10 @@ public:
bool setGroup(const RsPostedGroup &group);
/* FeedItem */
virtual void expand(bool open);
protected:
/* FeedItem */
virtual void doExpand(bool open);
/* GxsGroupFeedItem */
virtual QString groupName();
virtual void loadGroup(const uint32_t &token);

View File

@ -195,7 +195,7 @@ void SecurityIpItem::toggle()
expand(ui->expandFrame->isHidden());
}
void SecurityIpItem::expand(bool open)
void SecurityIpItem::doExpand(bool open)
{
if (mParent) {
mParent->lockLayout(this, true);

View File

@ -46,8 +46,9 @@ public:
bool isSame(const std::string& ipAddr, const std::string& ipAddrReported, uint32_t type);
protected:
/* FeedItem */
virtual void expand(bool open);
virtual void doExpand(bool open);
private:
void setup();

View File

@ -286,7 +286,7 @@ void SecurityItem::toggle()
expand(expandFrame->isHidden());
}
void SecurityItem::expand(bool open)
void SecurityItem::doExpand(bool open)
{
if (mParent) {
mParent->lockLayout(this, true);

View File

@ -45,8 +45,9 @@ public:
bool isSame(const RsPeerId &sslId, uint32_t type);
protected:
/* FeedItem */
virtual void expand(bool open);
virtual void doExpand(bool open);
private slots:
/* default stuff */

View File

@ -35,7 +35,7 @@
#include <iostream>
//#define ENABLE_GENERATE
#define ENABLE_GENERATE
#define CREATEMSG_CHANNELINFO 0x002

View File

@ -317,3 +317,23 @@ string_is_hex(const QString &str)
return true;
}
namespace RsStringUtil
{
QString CopyLines(const QString &s, quint16 lines)
{
int index = -1;
for (int i = 0; i < lines; ++i) {
index = s.indexOf("\n", index + 1);
if (index == -1) {
break;
}
}
if (index != -1) {
return s.left(index);
}
return s;
}
}

View File

@ -84,5 +84,8 @@ QString string_format_arguments(const QStringList &args);
* otherwise. */
bool string_is_hex(const QString &str);
namespace RsStringUtil
{
QString CopyLines(const QString &s, quint16 lines);
}
#endif