tried to improve the logic in tab system. Not finished yet

This commit is contained in:
csoler 2020-06-23 21:37:36 +02:00
parent d39b09c5bc
commit b21193e460
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
3 changed files with 56 additions and 58 deletions

View File

@ -89,7 +89,6 @@ GxsGroupFrameDialog::GxsGroupFrameDialog(RsGxsIfaceHelper *ifaceImpl, QWidget *p
mSubscribedGroups = NULL; mSubscribedGroups = NULL;
mPopularGroups = NULL; mPopularGroups = NULL;
mOtherGroups = NULL; mOtherGroups = NULL;
mMessageWidget = NULL;
/* Setup Queue */ /* Setup Queue */
mInterface = ifaceImpl; mInterface = ifaceImpl;
@ -251,6 +250,13 @@ void GxsGroupFrameDialog::processSettings(bool load)
Settings->endGroup(); Settings->endGroup();
} }
bool GxsGroupFrameDialog::useTabs()
{
GroupFrameSettings groupFrameSettings;
return Settings->getGroupFrameSettings(groupFrameSettingsType(), groupFrameSettings) && groupFrameSettings.mOpenAllInNewTab;
}
void GxsGroupFrameDialog::settingsChanged() void GxsGroupFrameDialog::settingsChanged()
{ {
GroupFrameSettings groupFrameSettings; GroupFrameSettings groupFrameSettings;
@ -262,17 +268,15 @@ void GxsGroupFrameDialog::settingsChanged()
void GxsGroupFrameDialog::setSingleTab(bool singleTab) void GxsGroupFrameDialog::setSingleTab(bool singleTab)
{ {
if (singleTab) { if (singleTab)
if (!mMessageWidget) { {
mMessageWidget = createMessageWidget(RsGxsGroupId()); while(ui->messageTabWidget->count() > 1)
// remove close button of the the first tab {
ui->messageTabWidget->hideCloseButton(ui->messageTabWidget->indexOf(mMessageWidget)); auto w = ui->messageTabWidget->widget(0) ;
} ui->messageTabWidget->removeTab(0);
} else { delete w;
if (mMessageWidget) {
delete(mMessageWidget);
mMessageWidget = NULL;
} }
ui->messageTabWidget->hideCloseButton(0);
} }
} }
@ -433,15 +437,10 @@ void GxsGroupFrameDialog::groupTreeCustomPopupMenu(QPoint point)
QMenu contextMnu(this); QMenu contextMnu(this);
QAction *action; QAction *action;
#ifdef TODO action = contextMnu.addAction(QIcon(IMAGE_TABNEW), tr("Open in new tab"), this, SLOT(openInNewTab()));
if (mMessageWidget)
{
action = contextMnu.addAction(QIcon(IMAGE_TABNEW), tr("Open new tab"), this, SLOT(openInNewTab()));
if (mGroupId.isNull() || messageWidget(mGroupId, true)) // dont enable the open in tab if a tab is already here if(mGroupId.isNull()) // dont enable the open in tab if a tab is already here
action->setEnabled(false); action->setEnabled(false);
}
#endif
if (isSubscribed) { if (isSubscribed) {
action = contextMnu.addAction(QIcon(IMAGE_UNSUBSCRIBE), tr("Unsubscribe"), this, SLOT(unsubscribeGroup())); action = contextMnu.addAction(QIcon(IMAGE_UNSUBSCRIBE), tr("Unsubscribe"), this, SLOT(unsubscribeGroup()));
@ -677,7 +676,7 @@ bool GxsGroupFrameDialog::getCurrentGroupName(QString& name)
void GxsGroupFrameDialog::markMsgAsRead() void GxsGroupFrameDialog::markMsgAsRead()
{ {
GxsMessageFrameWidget *msgWidget = messageWidget(mGroupId, false); GxsMessageFrameWidget *msgWidget = messageWidget(mGroupId);
if (msgWidget) { if (msgWidget) {
msgWidget->setAllMessagesRead(true); msgWidget->setAllMessagesRead(true);
} }
@ -685,7 +684,7 @@ void GxsGroupFrameDialog::markMsgAsRead()
void GxsGroupFrameDialog::markMsgAsUnread() void GxsGroupFrameDialog::markMsgAsUnread()
{ {
GxsMessageFrameWidget *msgWidget = messageWidget(mGroupId, false); GxsMessageFrameWidget *msgWidget = messageWidget(mGroupId);
if (msgWidget) { if (msgWidget) {
msgWidget->setAllMessagesRead(false); msgWidget->setAllMessagesRead(false);
} }
@ -763,7 +762,7 @@ bool GxsGroupFrameDialog::navigate(const RsGxsGroupId &groupId, const RsGxsMessa
changedCurrentGroup(groupIdString); changedCurrentGroup(groupIdString);
/* search exisiting tab */ /* search exisiting tab */
GxsMessageFrameWidget *msgWidget = messageWidget(mGroupId, false); GxsMessageFrameWidget *msgWidget = messageWidget(mGroupId);
if (!msgWidget) { if (!msgWidget) {
return false; return false;
} }
@ -775,18 +774,17 @@ bool GxsGroupFrameDialog::navigate(const RsGxsGroupId &groupId, const RsGxsMessa
return msgWidget->navigate(msgId); return msgWidget->navigate(msgId);
} }
GxsMessageFrameWidget *GxsGroupFrameDialog::messageWidget(const RsGxsGroupId &groupId, bool ownTab) GxsMessageFrameWidget *GxsGroupFrameDialog::messageWidget(const RsGxsGroupId &groupId)
{ {
int tabCount = ui->messageTabWidget->count(); int tabCount = ui->messageTabWidget->count();
for (int index = 0; index < tabCount; ++index) {
for (int index = 0; index < tabCount; ++index)
{
GxsMessageFrameWidget *childWidget = dynamic_cast<GxsMessageFrameWidget*>(ui->messageTabWidget->widget(index)); GxsMessageFrameWidget *childWidget = dynamic_cast<GxsMessageFrameWidget*>(ui->messageTabWidget->widget(index));
if (ownTab && mMessageWidget && childWidget == mMessageWidget) {
continue; if (childWidget && childWidget->groupId() == groupId)
}
if (childWidget && childWidget->groupId() == groupId) {
return childWidget; return childWidget;
} }
}
return NULL; return NULL;
} }
@ -794,9 +792,9 @@ GxsMessageFrameWidget *GxsGroupFrameDialog::messageWidget(const RsGxsGroupId &gr
GxsMessageFrameWidget *GxsGroupFrameDialog::createMessageWidget(const RsGxsGroupId &groupId) GxsMessageFrameWidget *GxsGroupFrameDialog::createMessageWidget(const RsGxsGroupId &groupId)
{ {
GxsMessageFrameWidget *msgWidget = createMessageFrameWidget(groupId); GxsMessageFrameWidget *msgWidget = createMessageFrameWidget(groupId);
if (!msgWidget) {
if (!msgWidget)
return NULL; return NULL;
}
int index = ui->messageTabWidget->addTab(msgWidget, msgWidget->groupName(true)); int index = ui->messageTabWidget->addTab(msgWidget, msgWidget->groupName(true));
ui->messageTabWidget->setTabIcon(index, msgWidget->groupIcon()); ui->messageTabWidget->setTabIcon(index, msgWidget->groupIcon());
@ -827,35 +825,38 @@ void GxsGroupFrameDialog::changedCurrentGroup(const QString& groupId)
return; return;
} }
if (groupId.isEmpty()) { if (groupId.isEmpty())
if (mMessageWidget) { {
mMessageWidget->setGroupId(RsGxsGroupId()); auto w = currentWidget();
ui->messageTabWidget->setCurrentWidget(mMessageWidget);
} if(w)
w->setGroupId(RsGxsGroupId());
return; return;
} }
mGroupId = RsGxsGroupId(groupId.toStdString()); mGroupId = RsGxsGroupId(groupId.toStdString());
if (mGroupId.isNull()) {
if (mGroupId.isNull())
return; return;
}
/* search exisiting tab */ /* search exisiting tab */
GxsMessageFrameWidget *msgWidget = messageWidget(mGroupId, true); GxsMessageFrameWidget *msgWidget = messageWidget(mGroupId);
// check that we have at least one tab // check that we have at least one tab
if(!currentWidget())
msgWidget = createMessageWidget(RsGxsGroupId(groupId.toStdString()));
if(msgWidget) if(msgWidget)
ui->messageTabWidget->setCurrentWidget(msgWidget); ui->messageTabWidget->setCurrentWidget(msgWidget);
else else
{ {
msgWidget = currentWidget(); if(useTabs() || ui->messageTabWidget->count()==0)
msgWidget->setGroupId(mGroupId); {
msgWidget = createMessageWidget(RsGxsGroupId(groupId.toStdString()));
ui->messageTabWidget->setCurrentWidget(msgWidget);
}
else
currentWidget()->setGroupId(mGroupId);
} }
mMessageWidget = msgWidget;
} }
void GxsGroupFrameDialog::groupTreeMiddleButtonClicked(QTreeWidgetItem *item) void GxsGroupFrameDialog::groupTreeMiddleButtonClicked(QTreeWidgetItem *item)
@ -875,11 +876,10 @@ void GxsGroupFrameDialog::openGroupInNewTab(const RsGxsGroupId &groupId)
} }
/* search exisiting tab */ /* search exisiting tab */
GxsMessageFrameWidget *msgWidget = messageWidget(groupId, true); GxsMessageFrameWidget *msgWidget = messageWidget(groupId);
if (!msgWidget) {
/* not found, create new tab */ if (!msgWidget) /* not found, create new tab */
msgWidget = createMessageWidget(groupId); msgWidget = createMessageWidget(groupId);
}
ui->messageTabWidget->setCurrentWidget(msgWidget); ui->messageTabWidget->setCurrentWidget(msgWidget);
} }
@ -891,8 +891,6 @@ void GxsGroupFrameDialog::messageTabCloseRequested(int index)
GxsMessageFrameWidget *msgWidget = dynamic_cast<GxsMessageFrameWidget*>(ui->messageTabWidget->widget(index)); GxsMessageFrameWidget *msgWidget = dynamic_cast<GxsMessageFrameWidget*>(ui->messageTabWidget->widget(index));
delete msgWidget ; delete msgWidget ;
mMessageWidget = currentWidget();
} }
GxsMessageFrameWidget *GxsGroupFrameDialog::currentWidget() const GxsMessageFrameWidget *GxsGroupFrameDialog::currentWidget() const
@ -903,9 +901,9 @@ GxsMessageFrameWidget *GxsGroupFrameDialog::currentWidget() const
void GxsGroupFrameDialog::messageTabChanged(int index) void GxsGroupFrameDialog::messageTabChanged(int index)
{ {
GxsMessageFrameWidget *msgWidget = dynamic_cast<GxsMessageFrameWidget*>(ui->messageTabWidget->widget(index)); GxsMessageFrameWidget *msgWidget = dynamic_cast<GxsMessageFrameWidget*>(ui->messageTabWidget->widget(index));
if (!msgWidget) {
if (!msgWidget)
return; return;
}
ui->groupTreeWidget->activateId(QString::fromStdString(msgWidget->groupId().toStdString()), false); ui->groupTreeWidget->activateId(QString::fromStdString(msgWidget->groupId().toStdString()), false);
} }

View File

@ -181,7 +181,7 @@ private:
// subscribe/unsubscribe ack. // subscribe/unsubscribe ack.
GxsMessageFrameWidget *messageWidget(const RsGxsGroupId &groupId, bool ownTab); GxsMessageFrameWidget *messageWidget(const RsGxsGroupId &groupId);
GxsMessageFrameWidget *createMessageWidget(const RsGxsGroupId &groupId); GxsMessageFrameWidget *createMessageWidget(const RsGxsGroupId &groupId);
GxsCommentDialog *commentWidget(const RsGxsMessageId &msgId); GxsCommentDialog *commentWidget(const RsGxsMessageId &msgId);
@ -193,6 +193,7 @@ protected:
private: private:
GxsMessageFrameWidget *currentWidget() const; GxsMessageFrameWidget *currentWidget() const;
bool useTabs();
bool mInitialized; bool mInitialized;
bool mInFill; bool mInFill;
@ -201,8 +202,6 @@ private:
RsGxsGroupId mGroupId; RsGxsGroupId mGroupId;
RsGxsIfaceHelper *mInterface; RsGxsIfaceHelper *mInterface;
GxsMessageFrameWidget *mMessageWidget; // current widget
QTreeWidgetItem *mYourGroups; QTreeWidgetItem *mYourGroups;
QTreeWidgetItem *mSubscribedGroups; QTreeWidgetItem *mSubscribedGroups;
QTreeWidgetItem *mPopularGroups; QTreeWidgetItem *mPopularGroups;

View File

@ -558,6 +558,7 @@ void GxsChannelPostsWidgetWithModel::updateGroupData()
insertChannelDetails(mGroup); insertChannelDetails(mGroup);
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
} ); } );
}); });