From 014ba45ebbcd19238ffaaf3a8f43777ab977bd0b Mon Sep 17 00:00:00 2001 From: TheSpiritXIII Date: Tue, 30 Jun 2015 12:29:09 -0400 Subject: [PATCH] Multi-window: Keep window size, fix segfault, circle integration, changed defaults --- src/persistence/settings.cpp | 2 +- src/widget/circlewidget.cpp | 37 ++++++++++++++++++++++++++++++-- src/widget/contentdialog.cpp | 38 +++++++++++++++++++++------------ src/widget/form/profileform.cpp | 10 +++++++++ src/widget/form/profileform.h | 1 + src/widget/widget.cpp | 33 ++++++++++++++++++++++------ src/widget/widget.h | 1 + 7 files changed, 99 insertions(+), 23 deletions(-) diff --git a/src/persistence/settings.cpp b/src/persistence/settings.cpp index 9b645bd91..1b4882231 100644 --- a/src/persistence/settings.cpp +++ b/src/persistence/settings.cpp @@ -175,7 +175,7 @@ void Settings::loadGlobal() QStandardPaths::locate(QStandardPaths::HomeLocation, QString(), QStandardPaths::LocateDirectory) ).toString(); separateWindow = s.value("separateWindow", false).toBool(); - dontGroupWindows = s.value("dontGroupWindows", false).toBool(); + dontGroupWindows = s.value("dontGroupWindows", true).toBool(); groupchatPosition = s.value("groupchatPosition", true).toBool(); s.endGroup(); diff --git a/src/widget/circlewidget.cpp b/src/widget/circlewidget.cpp index 90225a194..079682610 100644 --- a/src/widget/circlewidget.cpp +++ b/src/widget/circlewidget.cpp @@ -24,6 +24,7 @@ #include "src/persistence/settings.h" #include "src/friendlist.h" #include "src/friend.h" +#include "src/widget/contentdialog.h" #include "widget.h" #include #include @@ -84,8 +85,13 @@ void CircleWidget::contextMenuEvent(QContextMenuEvent* event) QMenu menu; QAction* renameAction = menu.addAction(tr("Rename circle", "Menu for renaming a circle")); QAction* removeAction = menu.addAction(tr("Remove circle", "Menu for removing a circle")); + QAction* openAction = nullptr; + + if (friendOfflineLayout()->count() + friendOnlineLayout()->count() > 0) + openAction = menu.addAction(tr("Open all in new window")); QAction* selectedItem = menu.exec(mapToGlobal(event->pos())); + if (selectedItem == renameAction) { editName(); @@ -107,6 +113,33 @@ void CircleWidget::contextMenuEvent(QContextMenuEvent* event) circleList.remove(replacedCircle); } + else if (selectedItem == openAction) + { + ContentDialog* dialog = Widget::getInstance()->createContentDialog(); + + for (int i = 0; i < friendOnlineLayout()->count(); ++i) + { + FriendWidget* friendWidget = dynamic_cast(friendOnlineLayout()->itemAt(i)->widget()); + + if (friendWidget != nullptr) + { + Friend* f = friendWidget->getFriend(); + dialog->addFriend(friendWidget->friendId, f->getDisplayedName()); + } + } + for (int i = 0; i < friendOfflineLayout()->count(); ++i) + { + FriendWidget* friendWidget = dynamic_cast(friendOfflineLayout()->itemAt(i)->widget()); + + if (friendWidget != nullptr) + { + Friend* f = friendWidget->getFriend(); + dialog->addFriend(friendWidget->friendId, f->getDisplayedName()); + } + } + dialog->show(); + } + setContainerAttribute(Qt::WA_UnderMouse, false); } @@ -181,14 +214,14 @@ void CircleWidget::updateID(int index) for (int i = 0; i < friendOnlineLayout()->count(); ++i) { - FriendWidget* friendWidget = dynamic_cast(friendOnlineLayout()->itemAt(i)); + FriendWidget* friendWidget = dynamic_cast(friendOnlineLayout()->itemAt(i)->widget()); if (friendWidget != nullptr) Settings::getInstance().setFriendCircleID(FriendList::findFriend(friendWidget->friendId)->getToxId(), id); } for (int i = 0; i < friendOfflineLayout()->count(); ++i) { - FriendWidget* friendWidget = dynamic_cast(friendOfflineLayout()->itemAt(i)); + FriendWidget* friendWidget = dynamic_cast(friendOfflineLayout()->itemAt(i)->widget()); if (friendWidget != nullptr) Settings::getInstance().setFriendCircleID(FriendList::findFriend(friendWidget->friendId)->getToxId(), id); diff --git a/src/widget/contentdialog.cpp b/src/widget/contentdialog.cpp index f986924b7..dce517f72 100644 --- a/src/widget/contentdialog.cpp +++ b/src/widget/contentdialog.cpp @@ -146,7 +146,6 @@ FriendWidget* ContentDialog::addFriend(int friendId, QString id) Friend* frnd = friendWidget->getFriend(); - onChatroomWidgetClicked(friendWidget, false); connect(frnd, &Friend::displayedNameChanged, this, &ContentDialog::updateFriendWidget); connect(settingsWidget, &SettingsWidget::compactToggled, friendWidget, &FriendWidget::compactChange); @@ -155,7 +154,13 @@ FriendWidget* ContentDialog::addFriend(int friendId, QString id) connect(Core::getInstance(), &Core::friendAvatarChanged, friendWidget, &FriendWidget::onAvatarChange); connect(Core::getInstance(), &Core::friendAvatarRemoved, friendWidget, &FriendWidget::onAvatarRemoved); + ContentDialog* lastDialog = getFriendDialog(friendId); + + if (lastDialog != nullptr) + lastDialog->removeFriend(friendId); + friendList.insert(friendId, std::make_tuple(this, friendWidget)); + onChatroomWidgetClicked(friendWidget, false); return friendWidget; } @@ -171,9 +176,13 @@ GroupWidget* ContentDialog::addGroup(int groupId, const QString& name) connect(settingsWidget, &SettingsWidget::compactToggled, groupWidget, &GroupWidget::compactChange); connect(groupWidget, &GroupWidget::chatroomWidgetClicked, this, &ContentDialog::onChatroomWidgetClicked); - onChatroomWidgetClicked(groupWidget, false); + ContentDialog* lastDialog = getGroupDialog(groupId); + + if (lastDialog != nullptr) + lastDialog->removeGroup(groupId); groupList.insert(groupId, std::make_tuple(this, groupWidget)); + onChatroomWidgetClicked(groupWidget, false); return groupWidget; } @@ -191,16 +200,7 @@ void ContentDialog::removeFriend(int friendId) if (activeChatroomWidget == chatroomWidget) { // Need to find replacement to show here instead. - if (chatroomWidgetCount() > 1) - { - cycleContacts(true, false); - } - else - { - contentLayout->clear(); - activeChatroomWidget = nullptr; - deleteLater(); - } + cycleContacts(true, false); } friendLayout->removeFriendWidget(chatroomWidget, Status::Offline); @@ -208,7 +208,17 @@ void ContentDialog::removeFriend(int friendId) chatroomWidget->deleteLater(); friendList.remove(friendId); - update(); + + if (chatroomWidgetCount() == 0) + { + contentLayout->clear(); + activeChatroomWidget = nullptr; + deleteLater(); + } + else + { + update(); + } } void ContentDialog::removeGroup(int groupId) @@ -287,7 +297,7 @@ void ContentDialog::cycleContacts(bool forward, bool loop) GenericChatroomWidget* chatWidget = dynamic_cast(currentLayout->itemAt(index)->widget()); if (chatWidget != nullptr) - emit chatWidget->chatroomWidgetClicked(chatWidget); + onChatroomWidgetClicked(chatWidget, false); return; } diff --git a/src/widget/form/profileform.cpp b/src/widget/form/profileform.cpp index ef8a7fa96..fb577f24f 100644 --- a/src/widget/form/profileform.cpp +++ b/src/widget/form/profileform.cpp @@ -134,6 +134,16 @@ ProfileForm::~ProfileForm() head->deleteLater(); } +bool ProfileForm::isShown() const +{ + if (head->isVisible()) + { + return true; + } + + return false; +} + void ProfileForm::show(ContentLayout* contentLayout) { contentLayout->mainHead->layout()->addWidget(head); diff --git a/src/widget/form/profileform.h b/src/widget/form/profileform.h index 2ef32429b..cc995e154 100644 --- a/src/widget/form/profileform.h +++ b/src/widget/form/profileform.h @@ -55,6 +55,7 @@ public: ~ProfileForm(); virtual void show() final{} void show(ContentLayout* contentLayout); + bool isShown() const; signals: void userNameChanged(QString); diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 79760b511..74aa3b268 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -550,6 +550,8 @@ void Widget::onSeparateWindowChanged(bool separate, bool clicked) } else { + int width = ui->friendList->size().width(); + if (contentLayout != nullptr) { contentLayout->clear(); @@ -563,7 +565,7 @@ void Widget::onSeparateWindowChanged(bool separate, bool clicked) setMinimumWidth(ui->tooliconsZone->sizeHint().width()); if (clicked) - resize(ui->statusPanel->width(), height()); + resize(width, height()); setWindowTitle(QString()); setActiveToolMenuButton(None); @@ -728,15 +730,29 @@ void Widget::onSettingsClicked() void Widget::showProfile() // onAvatarClicked, onUsernameClicked { - hideMainForms(nullptr); - profileForm->show(contentLayout); - setWindowTitle(tr("Profile")); + if (Settings::getInstance().getSeparateWindow()) + { + if (!profileForm->isShown()) + { + profileForm->show(createContentDialog(tr("Profile"))); + setActiveToolMenuButton(Widget::None); + } + } + else + { + hideMainForms(nullptr); + profileForm->show(contentLayout); + setWindowTitle(tr("Profile")); + setActiveToolMenuButton(Widget::None); + } } void Widget::hideMainForms(GenericChatroomWidget* chatroomWidget) { setActiveToolMenuButton(Widget::None); - contentLayout->clear(); + + if (contentLayout != nullptr) + contentLayout->clear(); if (activeChatroomWidget != nullptr) activeChatroomWidget->setAsInactiveChatroom(); @@ -967,7 +983,7 @@ void Widget::onChatroomWidgetClicked(GenericChatroomWidget *widget, bool group) dialog = ContentDialog::current(); if (dialog == nullptr) - dialog = new ContentDialog(settingsWidget); + dialog = createContentDialog(); dialog->show(); Friend* frnd = widget->getFriend(); @@ -1230,6 +1246,11 @@ void Widget::clearContactsList() removeGroup(g, true); } +ContentDialog* Widget::createContentDialog() const +{ + return new ContentDialog(settingsWidget); +} + ContentLayout* Widget::createContentDialog(const QString &title) const { QDialog* dialog = new QDialog(); diff --git a/src/widget/widget.h b/src/widget/widget.h index a8f537cdd..33deb23b4 100644 --- a/src/widget/widget.h +++ b/src/widget/widget.h @@ -72,6 +72,7 @@ public: bool getIsWindowMinimized(); void updateIcons(); void clearContactsList(); + ContentDialog* createContentDialog() const; ContentLayout* createContentDialog(const QString& title) const; static void confirmExecutableOpen(const QFileInfo file);