From 35cc460e719f600a5bad294dddec4a2a0d54cb7a Mon Sep 17 00:00:00 2001 From: thunder2 Date: Sun, 30 Dec 2012 02:41:53 +0000 Subject: [PATCH] Added a standard tab to GxsForums and FeedReader. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6055 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- plugins/FeedReader/gui/FeedReaderDialog.cpp | 106 +++++++++++++++--- plugins/FeedReader/gui/FeedReaderDialog.h | 13 ++- plugins/FeedReader/gui/FeedReaderDialog.ui | 8 +- .../gui/FeedReaderMessageWidget.cpp | 44 ++++++-- .../FeedReader/gui/FeedReaderMessageWidget.h | 1 + retroshare-gui/src/gui/GxsForumsDialog.cpp | 81 ++++++++++--- retroshare-gui/src/gui/GxsForumsDialog.h | 10 +- retroshare-gui/src/gui/GxsForumsDialog.ui | 8 +- .../src/gui/common/GroupTreeWidget.cpp | 10 +- .../src/gui/common/GroupTreeWidget.h | 4 +- .../gui/gxsforums/GxsForumThreadWidget.cpp | 24 +++- .../src/gui/gxsforums/GxsForumThreadWidget.h | 1 + 12 files changed, 252 insertions(+), 58 deletions(-) diff --git a/plugins/FeedReader/gui/FeedReaderDialog.cpp b/plugins/FeedReader/gui/FeedReaderDialog.cpp index 9cb5418b1..bff723fea 100644 --- a/plugins/FeedReader/gui/FeedReaderDialog.cpp +++ b/plugins/FeedReader/gui/FeedReaderDialog.cpp @@ -68,11 +68,16 @@ FeedReaderDialog::FeedReaderDialog(RsFeedReader *feedReader, QWidget *parent) connect(mNotify, SIGNAL(notifyMsgChanged(QString,QString,int)), this, SLOT(msgChanged(QString,QString,int))); /* connect signals */ - connect(ui->feedTreeWidget, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this, SLOT(feedItemChanged(QTreeWidgetItem*))); - connect(ui->messageTabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(messageTabCloseRequested(int))); - + connect(ui->feedTreeWidget, SIGNAL(itemActivated(QTreeWidgetItem*,int)), this, SLOT(feedTreeItemActivated(QTreeWidgetItem*))); + if (!style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, NULL, this)) { + // need signal itemClicked too + connect(ui->feedTreeWidget, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this, SLOT(feedTreeItemActivated(QTreeWidgetItem*))); + } connect(ui->feedTreeWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(feedTreeCustomPopupMenu(QPoint))); + connect(ui->messageTabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(messageTabCloseRequested(int))); + connect(ui->messageTabWidget, SIGNAL(currentChanged(int)), this, SLOT(messageTabChanged(int))); + connect(ui->feedAddButton, SIGNAL(clicked()), this, SLOT(newFeed())); connect(ui->feedProcessButton, SIGNAL(clicked()), this, SLOT(processFeed())); @@ -102,7 +107,11 @@ FeedReaderDialog::FeedReaderDialog(RsFeedReader *feedReader, QWidget *parent) ui->feedTreeWidget->installEventFilter(this); - feedItemChanged(NULL); + mMessageWidget = createMessageWidget(""); + // remove close button of the the first tab + ui->messageTabWidget->hideCloseButton(ui->messageTabWidget->indexOf(mMessageWidget)); + + feedTreeItemActivated(NULL); } FeedReaderDialog::~FeedReaderDialog() @@ -231,14 +240,33 @@ std::string FeedReaderDialog::currentFeedId() return item->data(COLUMN_FEED_DATA, ROLE_FEED_ID).toString().toStdString(); } +void FeedReaderDialog::setCurrentFeedId(const std::string &feedId) +{ + if (feedId.empty()) { + return; + } + + QTreeWidgetItemIterator it(ui->feedTreeWidget); + QTreeWidgetItem *item; + while ((item = *it) != NULL) { + if (item->data(COLUMN_FEED_DATA, ROLE_FEED_ID).toString().toStdString() == feedId) { + ui->feedTreeWidget->setCurrentItem(item); + break; + } + ++it; + } +} + void FeedReaderDialog::feedTreeCustomPopupMenu(QPoint /*point*/) { QMenu contextMnu(this); bool folder = false; + std::string feedId; QTreeWidgetItem *item = ui->feedTreeWidget->currentItem(); if (item) { folder = item->data(COLUMN_FEED_DATA, ROLE_FEED_FOLDER).toBool(); + feedId = item->data(COLUMN_FEED_DATA, ROLE_FEED_ID).toString().toStdString(); } QMenu *menu = contextMnu.addMenu(QIcon(""), tr("New")); @@ -253,6 +281,13 @@ void FeedReaderDialog::feedTreeCustomPopupMenu(QPoint /*point*/) contextMnu.addSeparator(); + action = contextMnu.addAction(QIcon(""), tr("Open in new tab"), this, SLOT(openInNewTab())); + if (!item || folder || feedMessageWidget(feedId)) { + action->setEnabled(false); + } + + contextMnu.addSeparator(); + action = contextMnu.addAction(QIcon(":/images/edit_16.png"), tr("Edit"), this, SLOT(editFeed())); if (!item || item == mRootItem) { action->setEnabled(false); @@ -530,6 +565,9 @@ FeedReaderMessageWidget *FeedReaderDialog::feedMessageWidget(const std::string & int tabCount = ui->messageTabWidget->count(); for (int index = 0; index < tabCount; ++index) { FeedReaderMessageWidget *childWidget = dynamic_cast(ui->messageTabWidget->widget(index)); + if (childWidget == mMessageWidget) { + continue; + } if (childWidget && childWidget->feedId() == id) { return childWidget; } @@ -538,7 +576,17 @@ FeedReaderMessageWidget *FeedReaderDialog::feedMessageWidget(const std::string & return NULL; } -void FeedReaderDialog::feedItemChanged(QTreeWidgetItem *item) +FeedReaderMessageWidget *FeedReaderDialog::createMessageWidget(const std::string &feedId) +{ + FeedReaderMessageWidget *messageWidget = new FeedReaderMessageWidget(feedId, mFeedReader, mNotify); + int index = ui->messageTabWidget->addTab(messageWidget, messageWidget->feedName(true)); + ui->messageTabWidget->setTabIcon(index, messageWidget->feedIcon()); + connect(messageWidget, SIGNAL(feedMessageChanged(QWidget*)), this, SLOT(messageTabInfoChanged(QWidget*))); + + return messageWidget; +} + +void FeedReaderDialog::feedTreeItemActivated(QTreeWidgetItem *item) { if (!item) { ui->feedAddButton->setEnabled(false); @@ -558,13 +606,27 @@ void FeedReaderDialog::feedItemChanged(QTreeWidgetItem *item) std::string feedId = item->data(COLUMN_FEED_DATA, ROLE_FEED_ID).toString().toStdString(); /* search exisiting tab */ FeedReaderMessageWidget *messageWidget = feedMessageWidget(feedId); - if (!messageWidget) { - /* create a message widget */ - messageWidget = new FeedReaderMessageWidget(feedId, mFeedReader, mNotify); - int index = ui->messageTabWidget->addTab(messageWidget, messageWidget->feedName(true)); - ui->messageTabWidget->setTabIcon(index, messageWidget->feedIcon()); - connect(messageWidget, SIGNAL(feedMessageChanged(QWidget*)), this, SLOT(messageTabChanged(QWidget*))); + /* not found, use standard tab */ + messageWidget = mMessageWidget; + messageWidget->setFeedId(feedId); + } + + ui->messageTabWidget->setCurrentWidget(messageWidget); +} + +void FeedReaderDialog::openInNewTab() +{ + std::string feedId = currentFeedId(); + if (feedId.empty()) { + return; + } + + /* search exisiting tab */ + FeedReaderMessageWidget *messageWidget = feedMessageWidget(feedId); + if (!messageWidget) { + /* not found, create new tab */ + messageWidget = createMessageWidget(feedId); } ui->messageTabWidget->setCurrentWidget(messageWidget); @@ -573,12 +635,28 @@ void FeedReaderDialog::feedItemChanged(QTreeWidgetItem *item) void FeedReaderDialog::messageTabCloseRequested(int index) { FeedReaderMessageWidget *messageWidget = dynamic_cast(ui->messageTabWidget->widget(index)); - if (messageWidget) { - delete(messageWidget); + if (!messageWidget) { + return; } + + if (messageWidget == mMessageWidget) { + return; + } + + delete(messageWidget); } -void FeedReaderDialog::messageTabChanged(QWidget *widget) +void FeedReaderDialog::messageTabChanged(int index) +{ + FeedReaderMessageWidget *messageWidget = dynamic_cast(ui->messageTabWidget->widget(index)); + if (!messageWidget) { + return; + } + + setCurrentFeedId(messageWidget->feedId()); +} + +void FeedReaderDialog::messageTabInfoChanged(QWidget *widget) { int index = ui->messageTabWidget->indexOf(widget); if (index < 0) { diff --git a/plugins/FeedReader/gui/FeedReaderDialog.h b/plugins/FeedReader/gui/FeedReaderDialog.h index 92858ee43..361a4d29f 100644 --- a/plugins/FeedReader/gui/FeedReaderDialog.h +++ b/plugins/FeedReader/gui/FeedReaderDialog.h @@ -46,12 +46,13 @@ public: virtual UserNotify *getUserNotify(QObject *parent); protected: - virtual void showEvent(QShowEvent *e); + virtual void showEvent(QShowEvent *event); bool eventFilter(QObject *obj, QEvent *ev); private slots: void feedTreeCustomPopupMenu(QPoint point); - void feedItemChanged(QTreeWidgetItem *item); + void feedTreeItemActivated(QTreeWidgetItem *item); + void openInNewTab(); void newFolder(); void newFeed(); void removeFeed(); @@ -60,13 +61,15 @@ private slots: void processFeed(); void messageTabCloseRequested(int index); - void messageTabChanged(QWidget *widget); + void messageTabChanged(int index); + void messageTabInfoChanged(QWidget *widget); /* FeedReaderNotify */ void feedChanged(const QString &feedId, int type); private: std::string currentFeedId(); + void setCurrentFeedId(const std::string &feedId); void processSettings(bool load); void addFeedToExpand(const std::string &feedId); void getExpandedFeedIds(QList &feedIds); @@ -76,12 +79,14 @@ private: void calculateFeedItems(); void calculateFeedItem(QTreeWidgetItem *item, uint32_t &unreadCount, bool &loading); - FeedReaderMessageWidget *feedMessageWidget(const std::string &id); + FeedReaderMessageWidget *feedMessageWidget(const std::string &feedId); + FeedReaderMessageWidget *createMessageWidget(const std::string &feedId); bool mProcessSettings; QList *mOpenFeedIds; QTreeWidgetItem *mRootItem; RSTreeWidgetItemCompareRole *mFeedCompareRole; + FeedReaderMessageWidget *mMessageWidget; // gui interface RsFeedReader *mFeedReader; diff --git a/plugins/FeedReader/gui/FeedReaderDialog.ui b/plugins/FeedReader/gui/FeedReaderDialog.ui index dc6e82777..6a4f0c696 100644 --- a/plugins/FeedReader/gui/FeedReaderDialog.ui +++ b/plugins/FeedReader/gui/FeedReaderDialog.ui @@ -141,7 +141,7 @@ - + true @@ -159,6 +159,12 @@ QTreeWidget
gui/common/RSTreeWidget.h
+ + RSTabWidget + QTabWidget +
gui/common/RSTabWidget.h
+ 1 +
diff --git a/plugins/FeedReader/gui/FeedReaderMessageWidget.cpp b/plugins/FeedReader/gui/FeedReaderMessageWidget.cpp index 4953a7863..b1c587eba 100644 --- a/plugins/FeedReader/gui/FeedReaderMessageWidget.cpp +++ b/plugins/FeedReader/gui/FeedReaderMessageWidget.cpp @@ -30,7 +30,7 @@ #define ROLE_MSG_LINK Qt::UserRole + 4 FeedReaderMessageWidget::FeedReaderMessageWidget(const std::string &feedId, RsFeedReader *feedReader, FeedReaderNotify *notify, QWidget *parent) : - QWidget(parent), mFeedId(feedId), mFeedReader(feedReader), mNotify(notify), ui(new Ui::FeedReaderMessageWidget) + QWidget(parent), mFeedReader(feedReader), mNotify(notify), ui(new Ui::FeedReaderMessageWidget) { ui->setupUi(this); @@ -111,17 +111,7 @@ FeedReaderMessageWidget::FeedReaderMessageWidget(const std::string &feedId, RsFe ui->msgTreeWidget->installEventFilter(this); - FeedInfo feedInfo; - if (mFeedReader->getFeedInfo(mFeedId, feedInfo)) { - mFeedName = QString::fromUtf8(feedInfo.name.c_str()); - - mFeedReader->getMessageCount(mFeedId, NULL, NULL, &mUnreadCount); - } else { - mFeedId.clear(); - } - - updateMsgs(); - updateCurrentMessage(); + setFeedId(feedId); } FeedReaderMessageWidget::~FeedReaderMessageWidget() @@ -203,6 +193,35 @@ bool FeedReaderMessageWidget::eventFilter(QObject *obj, QEvent *event) return QWidget::eventFilter(obj, event); } +void FeedReaderMessageWidget::setFeedId(const std::string &feedId) +{ + if (mFeedId == feedId) { + if (!feedId.empty()) { + return; + } + } + + mFeedId = feedId; + + ui->feedProcessButton->setEnabled(!mFeedId.empty()); + + if (!mFeedId.empty()) { + FeedInfo feedInfo; + if (mFeedReader->getFeedInfo(mFeedId, feedInfo)) { + mFeedName = QString::fromUtf8(feedInfo.name.c_str()); + + mFeedReader->getMessageCount(mFeedId, NULL, NULL, &mUnreadCount); + } else { + mFeedId.clear(); + } + } + + emit feedMessageChanged(this); + + updateMsgs(); + updateCurrentMessage(); +} + QString FeedReaderMessageWidget::feedName(bool withUnreadCount) { QString name = mFeedName.isEmpty() ? tr("No name") : mFeedName; @@ -250,6 +269,7 @@ void FeedReaderMessageWidget::msgTreeCustomPopupMenu(QPoint /*point*/) action->setEnabled(!selectedItems.empty()); action = contextMnu.addAction(QIcon(""), tr("Mark all as read"), this, SLOT(markAllAsReadMsg())); + action->setEnabled(!mFeedId.empty()); contextMnu.addSeparator(); diff --git a/plugins/FeedReader/gui/FeedReaderMessageWidget.h b/plugins/FeedReader/gui/FeedReaderMessageWidget.h index 4ff0dd124..55498b549 100644 --- a/plugins/FeedReader/gui/FeedReaderMessageWidget.h +++ b/plugins/FeedReader/gui/FeedReaderMessageWidget.h @@ -23,6 +23,7 @@ public: ~FeedReaderMessageWidget(); std::string feedId() { return mFeedId; } + void setFeedId(const std::string &feedId); QString feedName(bool withUnreadCount); QIcon feedIcon(); diff --git a/retroshare-gui/src/gui/GxsForumsDialog.cpp b/retroshare-gui/src/gui/GxsForumsDialog.cpp index be12e48cd..1e34607c8 100644 --- a/retroshare-gui/src/gui/GxsForumsDialog.cpp +++ b/retroshare-gui/src/gui/GxsForumsDialog.cpp @@ -72,8 +72,9 @@ GxsForumsDialog::GxsForumsDialog(QWidget *parent) connect(ui.forumTreeWidget, SIGNAL(treeCustomContextMenuRequested(QPoint)), this, SLOT(forumListCustomPopupMenu(QPoint))); connect(ui.newForumButton, SIGNAL(clicked()), this, SLOT(newforum())); - connect(ui.forumTreeWidget, SIGNAL(treeItemClicked(QString)), this, SLOT(changedForum(QString))); + connect(ui.forumTreeWidget, SIGNAL(treeItemActivated(QString)), this, SLOT(changedForum(QString))); connect(ui.threadTabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(threadTabCloseRequested(int))); + connect(ui.threadTabWidget, SIGNAL(currentChanged(int)), this, SLOT(threadTabChanged(int))); connect(NotifyQt::getInstance(), SIGNAL(forumMsgReadSatusChanged(QString,QString,int)), this, SLOT(forumMsgReadSatusChanged(QString,QString,int))); // HACK - TEMPORARY HIJACKING THIS BUTTON FOR REFRESH. @@ -96,6 +97,10 @@ GxsForumsDialog::GxsForumsDialog(QWidget *parent) // load settings processSettings(true); + mThreadWidget = createThreadWidget(""); + // remove close button of the the first tab + ui.threadTabWidget->hideCloseButton(ui.threadTabWidget->indexOf(mThreadWidget)); + /* Hide platform specific features */ #ifdef Q_WS_WIN @@ -148,6 +153,11 @@ void GxsForumsDialog::forumListCustomPopupMenu(QPoint /*point*/) action = contextMnu.addAction(QIcon(IMAGE_UNSUBSCRIBE), tr("Unsubscribe to Forum"), this, SLOT(unsubscribeToForum())); action->setEnabled (!mForumId.empty() && IS_GROUP_SUBSCRIBED(subscribeFlags)); + action = contextMnu.addAction(QIcon(""), tr("Open in new tab"), this, SLOT(openInNewTab())); + if (mForumId.empty() || forumThreadWidget(mForumId)) { + action->setEnabled(false); + } + contextMnu.addSeparator(); contextMnu.addAction(QIcon(IMAGE_NEWFORUM), tr("New Forum"), this, SLOT(newforum())); @@ -320,12 +330,15 @@ void GxsForumsDialog::insertForumsData(const std::list &forumLi updateMessageSummaryList(""); } -GxsForumThreadWidget *GxsForumsDialog::forumThreadWidget(const std::string &id) +GxsForumThreadWidget *GxsForumsDialog::forumThreadWidget(const std::string &forumId) { int tabCount = ui.threadTabWidget->count(); for (int index = 0; index < tabCount; ++index) { GxsForumThreadWidget *childWidget = dynamic_cast(ui.threadTabWidget->widget(index)); - if (childWidget && childWidget->forumId() == id) { + if (childWidget == mThreadWidget) { + continue; + } + if (childWidget && childWidget->forumId() == forumId) { return childWidget; break; } @@ -334,9 +347,19 @@ GxsForumThreadWidget *GxsForumsDialog::forumThreadWidget(const std::string &id) return NULL; } -void GxsForumsDialog::changedForum(const QString &id) +GxsForumThreadWidget *GxsForumsDialog::createThreadWidget(const std::string &forumId) { - mForumId = id.toStdString(); + GxsForumThreadWidget *threadWidget = new GxsForumThreadWidget(forumId); + int index = ui.threadTabWidget->addTab(threadWidget, threadWidget->forumName(true)); + ui.threadTabWidget->setTabIcon(index, threadWidget->forumIcon()); + connect(threadWidget, SIGNAL(forumChanged(QWidget*)), this, SLOT(threadTabInfoChanged(QWidget*))); + + return threadWidget; +} + +void GxsForumsDialog::changedForum(const QString &forumId) +{ + mForumId = forumId.toStdString(); if (mForumId.empty()) { return; } @@ -344,14 +367,28 @@ void GxsForumsDialog::changedForum(const QString &id) // requestGroupSummary_CurrentForum(mForumId); /* search exisiting tab */ - GxsForumThreadWidget *threadWidget = forumThreadWidget(id.toStdString()); + GxsForumThreadWidget *threadWidget = forumThreadWidget(mForumId); if (!threadWidget) { - /* create a thread widget */ - threadWidget = new GxsForumThreadWidget(id.toStdString()); - int index = ui.threadTabWidget->addTab(threadWidget, threadWidget->forumName(true)); - ui.threadTabWidget->setTabIcon(index, threadWidget->forumIcon()); - connect(threadWidget, SIGNAL(forumChanged(QWidget*)), this, SLOT(threadTabChanged(QWidget*))); + /* not found, use standard tab */ + threadWidget = mThreadWidget; + threadWidget->setForumId(mForumId); + } + + ui.threadTabWidget->setCurrentWidget(threadWidget); +} + +void GxsForumsDialog::openInNewTab() +{ + if (mForumId.empty()) { + return; + } + + /* search exisiting tab */ + GxsForumThreadWidget *threadWidget = forumThreadWidget(mForumId); + if (!threadWidget) { + /* not found, create new tab */ + threadWidget = createThreadWidget(mForumId); } ui.threadTabWidget->setCurrentWidget(threadWidget); @@ -360,12 +397,28 @@ void GxsForumsDialog::changedForum(const QString &id) void GxsForumsDialog::threadTabCloseRequested(int index) { GxsForumThreadWidget *threadWidget = dynamic_cast(ui.threadTabWidget->widget(index)); - if (threadWidget) { - delete(threadWidget); + if (!threadWidget) { + return; } + + if (threadWidget == mThreadWidget) { + return; + } + + delete(threadWidget); } -void GxsForumsDialog::threadTabChanged(QWidget *widget) +void GxsForumsDialog::threadTabChanged(int index) +{ + GxsForumThreadWidget *threadWidget = dynamic_cast(ui.threadTabWidget->widget(index)); + if (!threadWidget) { + return; + } + + ui.forumTreeWidget->activateId(QString::fromStdString(threadWidget->forumId()), false); +} + +void GxsForumsDialog::threadTabInfoChanged(QWidget *widget) { int index = ui.threadTabWidget->indexOf(widget); if (index < 0) { diff --git a/retroshare-gui/src/gui/GxsForumsDialog.h b/retroshare-gui/src/gui/GxsForumsDialog.h index 72ea8ecdb..fd501b162 100644 --- a/retroshare-gui/src/gui/GxsForumsDialog.h +++ b/retroshare-gui/src/gui/GxsForumsDialog.h @@ -65,9 +65,11 @@ private slots: void restoreForumKeys(); void newforum(); - void changedForum(const QString &id); + void changedForum(const QString &forumId); + void openInNewTab(); void threadTabCloseRequested(int index); - void threadTabChanged(QWidget *widget); + void threadTabChanged(int index); + void threadTabInfoChanged(QWidget *widget); void copyForumLink(); @@ -101,13 +103,15 @@ private: void requestGroupSummary(); void loadGroupSummary(const uint32_t &token); - GxsForumThreadWidget *forumThreadWidget(const std::string &id); + GxsForumThreadWidget *forumThreadWidget(const std::string &forumId); + GxsForumThreadWidget *createThreadWidget(const std::string &forumId); // void requestGroupSummary_CurrentForum(const std::string &forumId); // void loadGroupSummary_CurrentForum(const uint32_t &token); std::string mForumId; TokenQueue *mForumQueue; + GxsForumThreadWidget *mThreadWidget; QTreeWidgetItem *yourForums; QTreeWidgetItem *subscribedForums; diff --git a/retroshare-gui/src/gui/GxsForumsDialog.ui b/retroshare-gui/src/gui/GxsForumsDialog.ui index 9420b701e..077b96d7e 100644 --- a/retroshare-gui/src/gui/GxsForumsDialog.ui +++ b/retroshare-gui/src/gui/GxsForumsDialog.ui @@ -168,7 +168,7 @@
- + -1 @@ -194,6 +194,12 @@ + + RSTabWidget + QTabWidget +
gui/common/RSTabWidget.h
+ 1 +
GroupTreeWidget QWidget diff --git a/retroshare-gui/src/gui/common/GroupTreeWidget.cpp b/retroshare-gui/src/gui/common/GroupTreeWidget.cpp index a85a67dd5..b845e0133 100644 --- a/retroshare-gui/src/gui/common/GroupTreeWidget.cpp +++ b/retroshare-gui/src/gui/common/GroupTreeWidget.cpp @@ -70,7 +70,11 @@ GroupTreeWidget::GroupTreeWidget(QWidget *parent) : connect(ui->treeWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customContextMenuRequested(QPoint))); connect(ui->treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), this, SLOT(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*))); - connect(ui->treeWidget, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this, SLOT(itemClicked(QTreeWidgetItem*,int))); + connect(ui->treeWidget, SIGNAL(itemActivated(QTreeWidgetItem*,int)), this, SLOT(itemActivated(QTreeWidgetItem*,int))); + if (!style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, NULL, this)) { + // need signal itemClicked too + connect(ui->treeWidget, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this, SLOT(itemActivated(QTreeWidgetItem*,int))); + } /* Add own item delegate */ RSItemDelegate *itemDelegate = new RSItemDelegate(this); @@ -234,7 +238,7 @@ void GroupTreeWidget::currentItemChanged(QTreeWidgetItem *current, QTreeWidgetIt emit treeCurrentItemChanged(id); } -void GroupTreeWidget::itemClicked(QTreeWidgetItem *item, int column) +void GroupTreeWidget::itemActivated(QTreeWidgetItem *item, int column) { Q_UNUSED(column); @@ -244,7 +248,7 @@ void GroupTreeWidget::itemClicked(QTreeWidgetItem *item, int column) id = item->data(COLUMN_DATA, ROLE_ID).toString(); } - emit treeItemClicked(id); + emit treeItemActivated(id); } QTreeWidgetItem *GroupTreeWidget::addCategoryItem(const QString &name, const QIcon &icon, bool expand) diff --git a/retroshare-gui/src/gui/common/GroupTreeWidget.h b/retroshare-gui/src/gui/common/GroupTreeWidget.h index 1a7fecff7..3875e5f11 100644 --- a/retroshare-gui/src/gui/common/GroupTreeWidget.h +++ b/retroshare-gui/src/gui/common/GroupTreeWidget.h @@ -100,7 +100,7 @@ public: signals: void treeCustomContextMenuRequested(const QPoint &pos); void treeCurrentItemChanged(const QString &id); - void treeItemClicked(const QString &id); + void treeItemActivated(const QString &id); protected: void changeEvent(QEvent *e); @@ -108,7 +108,7 @@ protected: private slots: void customContextMenuRequested(const QPoint &pos); void currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous); - void itemClicked(QTreeWidgetItem *item, int column); + void itemActivated(QTreeWidgetItem *item, int column); void filterChanged(); void sort(); diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp index 1c73de909..b180fc1a6 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp @@ -90,7 +90,6 @@ GxsForumThreadWidget::GxsForumThreadWidget(const std::string &forumId, QWidget * { ui->setupUi(this); - mForumId = forumId; mSubscribeFlags = 0; mInProcessSettings = false; mUnreadCount = 0; @@ -172,8 +171,7 @@ GxsForumThreadWidget::GxsForumThreadWidget(const std::string &forumId, QWidget * mFillThread = NULL; - ui->forumName->setText(tr("Loading")); - insertThreads(); + setForumId(forumId); ui->threadTreeWidget->installEventFilter(this); } @@ -234,9 +232,27 @@ void GxsForumThreadWidget::processSettings(bool load) mInProcessSettings = false; } +void GxsForumThreadWidget::setForumId(const std::string &forumId) +{ + if (mForumId == forumId) { + if (!forumId.empty()) { + return; + } + } + + mForumId = forumId; + ui->forumName->setText(mForumId.empty () ? "" : tr("Loading")); + mNewCount = 0; + mUnreadCount = 0; + + emit forumChanged(this); + + insertThreads(); +} + QString GxsForumThreadWidget::forumName(bool withUnreadCount) { - QString name = ui->forumName->text(); + QString name = mForumId.empty () ? tr("No name") : ui->forumName->text(); if (withUnreadCount && mUnreadCount) { name += QString(" (%1)").arg(mUnreadCount); diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h index 7aefac457..4eebd53b5 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h @@ -41,6 +41,7 @@ public: void setTextColorMissing(QColor color) { mTextColorMissing = color; } std::string forumId() { return mForumId; } + void setForumId(const std::string &forumId); QString forumName(bool withUnreadCount); QIcon forumIcon(); unsigned int newCount() { return mNewCount; }