1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Multi-window: Keep window size, fix segfault, circle integration, changed defaults

This commit is contained in:
TheSpiritXIII 2015-06-30 12:29:09 -04:00 committed by tux3
parent c181df6336
commit 014ba45ebb
7 changed files with 99 additions and 23 deletions

View File

@ -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();

View File

@ -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 <QVariant>
#include <QBoxLayout>
@ -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<FriendWidget*>(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<FriendWidget*>(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<FriendWidget*>(friendOnlineLayout()->itemAt(i));
FriendWidget* friendWidget = dynamic_cast<FriendWidget*>(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<FriendWidget*>(friendOfflineLayout()->itemAt(i));
FriendWidget* friendWidget = dynamic_cast<FriendWidget*>(friendOfflineLayout()->itemAt(i)->widget());
if (friendWidget != nullptr)
Settings::getInstance().setFriendCircleID(FriendList::findFriend(friendWidget->friendId)->getToxId(), id);

View File

@ -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<GenericChatroomWidget*>(currentLayout->itemAt(index)->widget());
if (chatWidget != nullptr)
emit chatWidget->chatroomWidgetClicked(chatWidget);
onChatroomWidgetClicked(chatWidget, false);
return;
}

View File

@ -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);

View File

@ -55,6 +55,7 @@ public:
~ProfileForm();
virtual void show() final{}
void show(ContentLayout* contentLayout);
bool isShown() const;
signals:
void userNameChanged(QString);

View File

@ -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();

View File

@ -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);