Fixed "jumping" of the items in channels and news feed when items are changed (load, toggle and remove).

Added workaround for QTBUG-3372.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5650 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2012-10-08 23:06:34 +00:00
parent 52c26dae30
commit 7502085b64
18 changed files with 195 additions and 16 deletions

View File

@ -225,6 +225,11 @@ void ChannelFeed::createChannel()
/*************************************************************************************/ /*************************************************************************************/
/*************************************************************************************/ /*************************************************************************************/
QScrollArea *ChannelFeed::getScrollArea()
{
return scrollArea;
}
void ChannelFeed::deleteFeedItem(QWidget */*item*/, uint32_t /*type*/) void ChannelFeed::deleteFeedItem(QWidget */*item*/, uint32_t /*type*/)
{ {
} }
@ -587,9 +592,14 @@ void ChannelFeed::fillThreadAddMsg(const QString &channelId, const QString &chan
progressBar->setValue(current * progressBar->maximum() / count); progressBar->setValue(current * progressBar->maximum() / count);
} }
lockLayout(NULL, true);
ChanMsgItem *cmi = new ChanMsgItem(this, 0, channelId.toStdString(), channelMsgId.toStdString(), true); ChanMsgItem *cmi = new ChanMsgItem(this, 0, channelId.toStdString(), channelMsgId.toStdString(), true);
mChanMsgItems.push_back(cmi); mChanMsgItems.push_back(cmi);
verticalLayout->addWidget(cmi); verticalLayout->addWidget(cmi);
cmi->show();
lockLayout(cmi, false);
} }
} }

View File

@ -50,6 +50,8 @@ public:
virtual UserNotify *getUserNotify(QObject *parent); virtual UserNotify *getUserNotify(QObject *parent);
/* FeedHolder */
virtual QScrollArea *getScrollArea();
virtual void deleteFeedItem(QWidget *item, uint32_t type); virtual void deleteFeedItem(QWidget *item, uint32_t type);
virtual void openChat(std::string peerId); virtual void openChat(std::string peerId);

View File

@ -229,14 +229,6 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
<widget class="QWidget" name="scrollAreaWidgetContents"> <widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>413</width>
<height>16</height>
</rect>
</property>
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>

View File

@ -400,11 +400,16 @@ void NewsFeed::addFeedItem(QWidget *item)
sendNewsFeedChanged(); sendNewsFeedChanged();
lockLayout(NULL, true);
if (Settings->getAddFeedsAtEnd()) { if (Settings->getAddFeedsAtEnd()) {
verticalLayout->addWidget(item); verticalLayout->addWidget(item);
} else { } else {
verticalLayout->insertWidget(0, item); verticalLayout->insertWidget(0, item);
} }
item->show();
lockLayout(item, false);
} }
void NewsFeed::addFeedItemIfUnique(QWidget *item, int itemType, const std::string &sslId, bool replace) void NewsFeed::addFeedItemIfUnique(QWidget *item, int itemType, const std::string &sslId, bool replace)
@ -742,6 +747,11 @@ void NewsFeed::addFeedItemFilesNew(RsFeedItem &/*fi*/)
} }
/* FeedHolder Functions (for FeedItem functionality) */ /* FeedHolder Functions (for FeedItem functionality) */
QScrollArea *NewsFeed::getScrollArea()
{
return scrollArea;
}
void NewsFeed::deleteFeedItem(QWidget *item, uint32_t /*type*/) void NewsFeed::deleteFeedItem(QWidget *item, uint32_t /*type*/)
{ {
#ifdef NEWS_DEBUG #ifdef NEWS_DEBUG

View File

@ -43,6 +43,7 @@ public:
virtual ~NewsFeed(); virtual ~NewsFeed();
/* FeedHolder Functions (for FeedItem functionality) */ /* FeedHolder Functions (for FeedItem functionality) */
virtual QScrollArea *getScrollArea();
virtual void deleteFeedItem(QWidget *item, uint32_t type); virtual void deleteFeedItem(QWidget *item, uint32_t type);
virtual void openChat(std::string peerId); virtual void openChat(std::string peerId);

View File

@ -129,6 +129,8 @@ void BlogMsgItem::small()
void BlogMsgItem::toggle() void BlogMsgItem::toggle()
{ {
mParent->lockLayout(this, true);
if (expandFrame->isHidden()) if (expandFrame->isHidden())
{ {
expandFrame->show(); expandFrame->show();
@ -141,6 +143,8 @@ void BlogMsgItem::toggle()
expandButton->setIcon(QIcon(QString(":/images/edit_add24.png"))); expandButton->setIcon(QIcon(QString(":/images/edit_add24.png")));
expandButton->setToolTip(tr("Expand")); expandButton->setToolTip(tr("Expand"));
} }
mParent->lockLayout(this, false);
} }
@ -150,7 +154,11 @@ void BlogMsgItem::removeItem()
std::cerr << "BlogMsgItem::removeItem()"; std::cerr << "BlogMsgItem::removeItem()";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
mParent->lockLayout(this, true);
hide(); hide();
mParent->lockLayout(this, false);
if (mParent) if (mParent)
{ {
mParent->deleteFeedItem(this, mFeedId); mParent->deleteFeedItem(this, mFeedId);

View File

@ -140,6 +140,8 @@ void BlogNewItem::small()
void BlogNewItem::toggle() void BlogNewItem::toggle()
{ {
mParent->lockLayout(this, true);
if (expandFrame->isHidden()) if (expandFrame->isHidden())
{ {
expandFrame->show(); expandFrame->show();
@ -152,6 +154,8 @@ void BlogNewItem::toggle()
expandButton->setIcon(QIcon(QString(":/images/edit_add24.png"))); expandButton->setIcon(QIcon(QString(":/images/edit_add24.png")));
expandButton->setToolTip(tr("Expand")); expandButton->setToolTip(tr("Expand"));
} }
mParent->lockLayout(this, false);
} }
@ -161,7 +165,11 @@ void BlogNewItem::removeItem()
std::cerr << "BlogNewItem::removeItem()"; std::cerr << "BlogNewItem::removeItem()";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
mParent->lockLayout(this, true);
hide(); hide();
mParent->lockLayout(this, false);
if (mParent) if (mParent)
{ {
mParent->deleteFeedItem(this, mFeedId); mParent->deleteFeedItem(this, mFeedId);

View File

@ -317,6 +317,8 @@ void ChanMsgItem::updateItem()
void ChanMsgItem::toggle() void ChanMsgItem::toggle()
{ {
mParent->lockLayout(this, true);
if (expandFrame->isHidden()) if (expandFrame->isHidden())
{ {
expandFrame->show(); expandFrame->show();
@ -331,6 +333,8 @@ void ChanMsgItem::toggle()
expandButton->setIcon(QIcon(QString(":/images/edit_add24.png"))); expandButton->setIcon(QIcon(QString(":/images/edit_add24.png")));
expandButton->setToolTip(tr("Expand")); expandButton->setToolTip(tr("Expand"));
} }
mParent->lockLayout(this, false);
} }
void ChanMsgItem::removeItem() void ChanMsgItem::removeItem()
@ -339,7 +343,11 @@ void ChanMsgItem::removeItem()
std::cerr << "ChanMsgItem::removeItem()"; std::cerr << "ChanMsgItem::removeItem()";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
mParent->lockLayout(this, true);
hide(); hide();
mParent->lockLayout(this, false);
if (mParent) if (mParent)
{ {
mParent->deleteFeedItem(this, mFeedId); mParent->deleteFeedItem(this, mFeedId);

View File

@ -140,6 +140,8 @@ void ChanNewItem::small()
void ChanNewItem::toggle() void ChanNewItem::toggle()
{ {
mParent->lockLayout(this, true);
if (expandFrame->isHidden()) if (expandFrame->isHidden())
{ {
expandFrame->show(); expandFrame->show();
@ -152,6 +154,8 @@ void ChanNewItem::toggle()
expandButton->setIcon(QIcon(QString(":/images/edit_add24.png"))); expandButton->setIcon(QIcon(QString(":/images/edit_add24.png")));
expandButton->setToolTip(tr("Expand")); expandButton->setToolTip(tr("Expand"));
} }
mParent->lockLayout(this, false);
} }
@ -161,7 +165,11 @@ void ChanNewItem::removeItem()
std::cerr << "ChanNewItem::removeItem()"; std::cerr << "ChanNewItem::removeItem()";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
mParent->lockLayout(this, true);
hide(); hide();
mParent->lockLayout(this, false);
if (mParent) if (mParent)
{ {
mParent->deleteFeedItem(this, mFeedId); mParent->deleteFeedItem(this, mFeedId);

View File

@ -160,7 +160,11 @@ void ChatMsgItem::removeItem()
std::cerr << "ChatMsgItem::removeItem()"; std::cerr << "ChatMsgItem::removeItem()";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
mParent->lockLayout(this, true);
hide(); hide();
mParent->lockLayout(this, false);
if (mParent) if (mParent)
{ {
mParent->deleteFeedItem(this, mFeedId); mParent->deleteFeedItem(this, mFeedId);
@ -216,6 +220,8 @@ void ChatMsgItem::openChat()
void ChatMsgItem::togglequickmessage() void ChatMsgItem::togglequickmessage()
{ {
mParent->lockLayout(this, true);
if (messageFrame->isHidden()) if (messageFrame->isHidden())
{ {
messageFrame->setVisible(true); messageFrame->setVisible(true);
@ -229,6 +235,7 @@ void ChatMsgItem::togglequickmessage()
cancelButton->hide(); cancelButton->hide();
} }
mParent->lockLayout(this, false);
} }
void ChatMsgItem::sendMessage() void ChatMsgItem::sendMessage()

View File

@ -0,0 +1,80 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2012 RetroShare Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include <QLayout>
#include <QApplication>
#include <QScrollArea>
#include "FeedHolder.h"
/** Constructor */
FeedHolder::FeedHolder()
{
mLockCount = 0;
}
// Workaround for QTBUG-3372
void FeedHolder::lockLayout(QWidget *feedItem, bool lock)
{
if (lock) {
if (mLockCount == 0) {
QScrollArea *scrollArea = getScrollArea();
if (scrollArea) {
// disable update
scrollArea->setUpdatesEnabled(false);
QWidget *widget = scrollArea->widget();
if (widget && widget->layout()) {
// disable layout
widget->layout()->setEnabled(false);
}
}
}
++mLockCount;
} else {
--mLockCount;
if (mLockCount == 0) {
QScrollArea *scrollArea = getScrollArea();
if (scrollArea) {
if (feedItem && !feedItem->isHidden()) {
// show window without hide it
// something in show causes a recalculation of the layout
feedItem->setAttribute(Qt::WA_WState_Hidden, true);
feedItem->show();
}
// enable update
scrollArea->setUpdatesEnabled(true);
// recalculate layout
QWidget *widget = scrollArea->widget();
if (widget && widget->layout()) {
// enable layout
widget->layout()->setEnabled(true);
}
// send layout request (without event queue) but with the newly calculated sizeHint from the call to :show
QApplication::sendEvent(scrollArea, new QEvent(QEvent::LayoutRequest));
}
}
mLockCount = qMax(mLockCount, 0);
}
}

View File

@ -25,16 +25,22 @@
#include <string> #include <string>
#include <stdint.h> #include <stdint.h>
const uint32_t FEEDHOLDER_MSG_MESSAGE = 0x0001; class QScrollArea;
const uint32_t FEEDHOLDER_MSG_FORUM = 0x0002;
const uint32_t FEEDHOLDER_MSG_CHANNEL = 0x0003;
const uint32_t FEEDHOLDER_MSG_BLOG = 0x0004;
class FeedHolder class FeedHolder
{ {
public: public:
FeedHolder();
virtual QScrollArea *getScrollArea() = 0;
virtual void deleteFeedItem(QWidget *item, uint32_t type) = 0; virtual void deleteFeedItem(QWidget *item, uint32_t type) = 0;
virtual void openChat(std::string peerId) = 0; virtual void openChat(std::string peerId) = 0;
// Workaround for QTBUG-3372
void lockLayout(QWidget *feedItem, bool lock);
protected:
int mLockCount;
}; };
#endif #endif

View File

@ -252,6 +252,8 @@ void ForumMsgItem::small()
void ForumMsgItem::toggle() void ForumMsgItem::toggle()
{ {
mParent->lockLayout(this, true);
if (prevFrame->isHidden()) if (prevFrame->isHidden())
{ {
prevFrame->show(); prevFrame->show();
@ -277,6 +279,8 @@ void ForumMsgItem::toggle()
expandButton->setIcon(QIcon(QString(":/images/edit_add24.png"))); expandButton->setIcon(QIcon(QString(":/images/edit_add24.png")));
expandButton->setToolTip(tr("Expand")); expandButton->setToolTip(tr("Expand"));
} }
mParent->lockLayout(this, false);
} }
void ForumMsgItem::removeItem() void ForumMsgItem::removeItem()
@ -285,7 +289,11 @@ void ForumMsgItem::removeItem()
std::cerr << "ForumMsgItem::removeItem()"; std::cerr << "ForumMsgItem::removeItem()";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
mParent->lockLayout(this, true);
hide(); hide();
mParent->lockLayout(this, false);
if (mParent) if (mParent)
{ {
mParent->deleteFeedItem(this, mFeedId); mParent->deleteFeedItem(this, mFeedId);

View File

@ -123,7 +123,6 @@ void ForumNewItem::updateItem()
} }
void ForumNewItem::small() void ForumNewItem::small()
{ {
expandFrame->hide(); expandFrame->hide();
@ -131,6 +130,8 @@ void ForumNewItem::small()
void ForumNewItem::toggle() void ForumNewItem::toggle()
{ {
mParent->lockLayout(this, true);
if (expandFrame->isHidden()) if (expandFrame->isHidden())
{ {
expandFrame->show(); expandFrame->show();
@ -143,8 +144,9 @@ void ForumNewItem::toggle()
expandButton->setIcon(QIcon(QString(":/images/edit_add24.png"))); expandButton->setIcon(QIcon(QString(":/images/edit_add24.png")));
expandButton->setToolTip(tr("Expand")); expandButton->setToolTip(tr("Expand"));
} }
}
mParent->lockLayout(this, false);
}
void ForumNewItem::removeItem() void ForumNewItem::removeItem()
{ {
@ -152,7 +154,11 @@ void ForumNewItem::removeItem()
std::cerr << "ForumNewItem::removeItem()"; std::cerr << "ForumNewItem::removeItem()";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
mParent->lockLayout(this, true);
hide(); hide();
mParent->lockLayout(this, false);
if (mParent) if (mParent)
{ {
mParent->deleteFeedItem(this, mFeedId); mParent->deleteFeedItem(this, mFeedId);

View File

@ -196,6 +196,8 @@ void MsgItem::small()
void MsgItem::toggle() void MsgItem::toggle()
{ {
mParent->lockLayout(this, true);
if (expandFrame->isHidden()) if (expandFrame->isHidden())
{ {
expandFrame->show(); expandFrame->show();
@ -208,6 +210,8 @@ void MsgItem::toggle()
expandButton->setIcon(QIcon(QString(":/images/edit_add24.png"))); expandButton->setIcon(QIcon(QString(":/images/edit_add24.png")));
expandButton->setToolTip(tr("Expand")); expandButton->setToolTip(tr("Expand"));
} }
mParent->lockLayout(this, false);
} }
@ -217,7 +221,11 @@ void MsgItem::removeItem()
std::cerr << "MsgItem::removeItem()"; std::cerr << "MsgItem::removeItem()";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
mParent->lockLayout(this, true);
hide(); hide();
mParent->lockLayout(this, false);
if (mParent) if (mParent)
{ {
mParent->deleteFeedItem(this, mFeedId); mParent->deleteFeedItem(this, mFeedId);

View File

@ -215,6 +215,8 @@ void PeerItem::small()
void PeerItem::toggle() void PeerItem::toggle()
{ {
mParent->lockLayout(this, true);
if (expandFrame->isHidden()) if (expandFrame->isHidden())
{ {
expandFrame->show(); expandFrame->show();
@ -227,6 +229,8 @@ void PeerItem::toggle()
expandButton->setIcon(QIcon(QString(":/images/edit_add24.png"))); expandButton->setIcon(QIcon(QString(":/images/edit_add24.png")));
expandButton->setToolTip(tr("Expand")); expandButton->setToolTip(tr("Expand"));
} }
mParent->lockLayout(this, false);
} }
@ -236,7 +240,11 @@ void PeerItem::removeItem()
std::cerr << "PeerItem::removeItem()"; std::cerr << "PeerItem::removeItem()";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
mParent->lockLayout(this, true);
hide(); hide();
mParent->lockLayout(this, false);
if (mParent) if (mParent)
{ {
mParent->deleteFeedItem(this, mFeedId); mParent->deleteFeedItem(this, mFeedId);

View File

@ -191,8 +191,8 @@ void SecurityItem::updateItem()
connLabel->setText(tr("Unknown Peer")); connLabel->setText(tr("Unknown Peer"));
chatButton->hide(); chatButton->hide();
quickmsgButton->hide(); quickmsgButton->hide();
requestLabel->hide(); requestLabel->hide();
removeFriendButton->setEnabled(false); removeFriendButton->setEnabled(false);
@ -281,6 +281,8 @@ void SecurityItem::small()
void SecurityItem::toggle() void SecurityItem::toggle()
{ {
mParent->lockLayout(this, true);
if (expandFrame->isHidden()) if (expandFrame->isHidden())
{ {
expandFrame->show(); expandFrame->show();
@ -293,6 +295,8 @@ void SecurityItem::toggle()
expandButton->setIcon(QIcon(QString(":/images/edit_add24.png"))); expandButton->setIcon(QIcon(QString(":/images/edit_add24.png")));
expandButton->setToolTip(tr("Expand")); expandButton->setToolTip(tr("Expand"));
} }
mParent->lockLayout(this, false);
} }
void SecurityItem::removeItem() void SecurityItem::removeItem()
@ -301,7 +305,11 @@ void SecurityItem::removeItem()
std::cerr << "SecurityItem::removeItem()"; std::cerr << "SecurityItem::removeItem()";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
mParent->lockLayout(this, true);
hide(); hide();
mParent->lockLayout(this, false);
if (mParent) if (mParent)
{ {
mParent->deleteFeedItem(this, mFeedId); mParent->deleteFeedItem(this, mFeedId);

View File

@ -688,6 +688,7 @@ SOURCES += main.cpp \
gui/elastic/node.cpp \ gui/elastic/node.cpp \
gui/NewsFeed.cpp \ gui/NewsFeed.cpp \
gui/ChannelFeed.cpp \ gui/ChannelFeed.cpp \
gui/feeds/FeedHolder.cpp \
gui/feeds/ForumNewItem.cpp \ gui/feeds/ForumNewItem.cpp \
gui/feeds/ForumMsgItem.cpp \ gui/feeds/ForumMsgItem.cpp \
gui/feeds/PeerItem.cpp \ gui/feeds/PeerItem.cpp \