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

Multi-window: Dispaly own username on detached windows, fix log out while having detached windows

This commit is contained in:
TheSpiritXIII 2015-07-02 13:16:11 -04:00 committed by tux3
parent 29c72549a2
commit 6a5fb9f518
5 changed files with 110 additions and 34 deletions

View File

@ -220,6 +220,7 @@ void Settings::loadGlobal()
splitterState = s.value("splitterState", QByteArray()).toByteArray();
dialogGeometry = s.value("dialogGeometry", QByteArray()).toByteArray();
dialogSplitterState = s.value("dialogSplitterState", QByteArray()).toByteArray();
dialogSettingsGeometry = s.value("dialogSettingsGeometry", QByteArray()).toByteArray();
s.endGroup();
s.beginGroup("Audio");
@ -416,6 +417,9 @@ void Settings::saveGlobal()
s.setValue("windowGeometry", windowGeometry);
s.setValue("windowState", windowState);
s.setValue("splitterState", splitterState);
s.setValue("dialogGeometry", dialogGeometry);
s.setValue("dialogSplitterState", dialogSplitterState);
s.setValue("dialogSettingsGeometry", dialogSettingsGeometry);
s.endGroup();
s.beginGroup("Audio");
@ -1120,6 +1124,18 @@ void Settings::setDialogSplitterState(const QByteArray &value)
dialogSplitterState = value;
}
QByteArray Settings::getDialogSettingsGeometry() const
{
QMutexLocker locker{&bigLock};
return dialogSettingsGeometry;
}
void Settings::setDialogSettingsGeometry(const QByteArray &value)
{
QMutexLocker locker{&bigLock};
dialogSettingsGeometry = value;
}
bool Settings::isMinimizeOnCloseEnabled() const
{
QMutexLocker locker{&bigLock};

View File

@ -223,6 +223,9 @@ public:
QByteArray getDialogSplitterState() const;
void setDialogSplitterState(const QByteArray &value);
QByteArray getDialogSettingsGeometry() const;
void setDialogSettingsGeometry(const QByteArray& value);
QString getFriendAdress(const QString &publicKey) const;
void updateFriendAdress(const QString &newAddr);
@ -350,6 +353,7 @@ private:
QByteArray splitterState;
QByteArray dialogGeometry;
QByteArray dialogSplitterState;
QByteArray dialogSettingsGeometry;
QString style;
bool showSystemTray;

View File

@ -118,6 +118,8 @@ ContentDialog::ContentDialog(SettingsWidget* settingsWidget, QWidget* parent)
new QShortcut(Qt::CTRL + Qt::Key_Tab, this, SLOT(nextContact()));
new QShortcut(Qt::CTRL + Qt::Key_PageUp, this, SLOT(previousContact()));
new QShortcut(Qt::CTRL + Qt::Key_PageDown, this, SLOT(nextContact()));
connect(Core::getInstance(), &Core::usernameSet, this, &ContentDialog::updateTitleUsername);
}
ContentDialog::~ContentDialog()
@ -382,6 +384,20 @@ ContentDialog* ContentDialog::getGroupDialog(int groupId)
return getDialog(groupId, groupList);
}
void ContentDialog::updateTitleUsername(const QString& username)
{
if (displayWidget != nullptr)
setWindowTitle(username + QStringLiteral(" - ") + displayWidget->getTitle());
else
setWindowTitle(username);
}
void ContentDialog::updateTitle(GenericChatroomWidget* chatroomWidget)
{
displayWidget = chatroomWidget;
updateTitleUsername(Core::getInstance()->getUsername());
}
void ContentDialog::previousContact()
{
cycleContacts(false);
@ -401,10 +417,7 @@ bool ContentDialog::event(QEvent* event)
{
activeChatroomWidget->resetEventFlags();
activeChatroomWidget->updateStatusLight();
QString windowTitle = activeChatroomWidget->getName();
if (!activeChatroomWidget->getStatusString().isNull())
windowTitle += " (" + activeChatroomWidget->getStatusString() + ")";
setWindowTitle(windowTitle);
updateTitle(activeChatroomWidget);
Friend* frnd = activeChatroomWidget->getFriend();
@ -484,8 +497,14 @@ void ContentDialog::changeEvent(QEvent *event)
void ContentDialog::resizeEvent(QResizeEvent* event)
{
Q_UNUSED(event);
saveDialogGeometry();
QDialog::resizeEvent(event);
}
void ContentDialog::moveEvent(QMoveEvent* event)
{
saveDialogGeometry();
QDialog::moveEvent(event);
}
void ContentDialog::onChatroomWidgetClicked(GenericChatroomWidget *widget, bool group)
@ -523,7 +542,7 @@ void ContentDialog::onChatroomWidgetClicked(GenericChatroomWidget *widget, bool
widget->setAsActiveChatroom();
widget->resetEventFlags();
widget->updateStatusLight();
setWindowTitle(widget->getTitle());
updateTitle(widget);
if (widget->getFriend() != nullptr)
widget->getFriend()->getFriendWidget()->updateStatusLight();
@ -558,10 +577,9 @@ void ContentDialog::saveDialogGeometry()
{
Settings::getInstance().setDialogGeometry(saveGeometry());
}
#include <QDebug>
void ContentDialog::saveSplitterState()
{
qDebug() << splitter->saveState();
Settings::getInstance().setDialogSplitterState(splitter->saveState());
}
@ -639,7 +657,7 @@ void ContentDialog::updateStatus(int id, const QHash<int, std::tuple<ContentDial
chatroomWidget->updateStatusLight();
if (chatroomWidget->isActive())
std::get<0>(iter.value())->setWindowTitle(chatroomWidget->getTitle());
std::get<0>(iter.value())->updateTitle(chatroomWidget);
}
bool ContentDialog::isWidgetActive(int id, const QHash<int, std::tuple<ContentDialog *, GenericChatroomWidget *> > &list)

View File

@ -66,6 +66,8 @@ public:
static ContentDialog* getGroupDialog(int groupId);
public slots:
void updateTitleUsername(const QString& username);
void updateTitle(GenericChatroomWidget* chatroomWidget);
void previousContact();
void nextContact();
@ -75,6 +77,7 @@ protected:
void dropEvent(QDropEvent* event) final override;
void changeEvent(QEvent* event) override;
void resizeEvent(QResizeEvent* event) override;
void moveEvent(QMoveEvent* event) override;
private slots:
void onChatroomWidgetClicked(GenericChatroomWidget* widget, bool group);
@ -99,6 +102,7 @@ private:
GenericChatItemLayout groupLayout;
ContentLayout* contentLayout;
GenericChatroomWidget* activeChatroomWidget;
GenericChatroomWidget* displayWidget = nullptr;
SettingsWidget* settingsWidget;
static ContentDialog* currentDialog;
static QHash<int, std::tuple<ContentDialog*, GenericChatroomWidget*>> friendList;

View File

@ -406,6 +406,14 @@ void Widget::updateIcons()
Widget::~Widget()
{
QWidgetList windowList = QApplication::topLevelWidgets();
for (QWidget* window : windowList)
{
if (window != this)
window->close();
}
Translator::unregister(this);
AutoUpdater::abortUpdates();
if (icon)
@ -545,12 +553,21 @@ void Widget::onSeparateWindowChanged(bool separate, bool clicked)
contentLayout = new ContentLayout(contentWidget);
ui->mainSplitter->addWidget(contentWidget);
clicked = true;
setMinimumWidth(775);
onSettingsClicked();
}
else
{
int width = ui->friendList->size().width();
QSize size;
QPoint pos;
if (contentLayout)
{
pos = mapToGlobal(ui->mainSplitter->widget(1)->pos());
size = ui->mainSplitter->widget(1)->size();
}
if (contentLayout != nullptr)
{
@ -572,10 +589,16 @@ void Widget::onSeparateWindowChanged(bool separate, bool clicked)
setWindowTitle(QString());
setActiveToolMenuButton(None);
}
if (clicked)
onSettingsClicked();
if (clicked)
{
ContentLayout* contentLayout = createContentDialog(tr("Settings"));
contentLayout->parentWidget()->resize(size);
contentLayout->parentWidget()->move(pos);
settingsWidget->show(contentLayout);
setActiveToolMenuButton(Widget::None);
}
}
}
void Widget::setWindowTitle(const QString& title)
@ -894,12 +917,7 @@ void Widget::onFriendStatusChanged(int friendId, Status status)
f->setStatus(status);
f->getFriendWidget()->updateStatusLight();
if(f->getFriendWidget()->isActive())
{
QString windowTitle = f->getFriendWidget()->getName();
if (!f->getFriendWidget()->getStatusString().isNull())
windowTitle += " (" + f->getFriendWidget()->getStatusString() + ")";
setWindowTitle(windowTitle);
}
setWindowTitle(f->getFriendWidget()->getTitle());
ContentDialog::updateFriendStatus(friendId);
@ -1213,7 +1231,7 @@ void Widget::removeFriend(Friend* f, bool fake)
}
f->getFriendWidget()->setAsInactiveChatroom();
if (static_cast<GenericChatroomWidget*>(f->getFriendWidget()) == activeChatroomWidget)
if (f->getFriendWidget() == activeChatroomWidget)
{
activeChatroomWidget = nullptr;
onAddClicked();
@ -1261,11 +1279,35 @@ ContentDialog* Widget::createContentDialog() const
ContentLayout* Widget::createContentDialog(const QString &title) const
{
QDialog* dialog = new QDialog();
ContentLayout* contentLayout = new ContentLayout(dialog);
class Dialog : public QDialog
{
public:
Dialog()
: QDialog()
{
restoreGeometry(Settings::getInstance().getDialogSettingsGeometry());
}
protected:
void resizeEvent(QResizeEvent* event) override
{
Settings::getInstance().setDialogSettingsGeometry(saveGeometry());
QDialog::resizeEvent(event);
}
void moveEvent(QMoveEvent* event) override
{
Settings::getInstance().setDialogSettingsGeometry(saveGeometry());
QDialog::moveEvent(event);
}
};
QDialog* dialog = new Dialog();
dialog->setAttribute(Qt::WA_DeleteOnClose);
ContentLayout* contentLayoutDialog = new ContentLayout(dialog);
dialog->setObjectName("detached");
dialog->setLayout(contentLayout);
dialog->setLayout(contentLayoutDialog);
dialog->layout()->setMargin(0);
dialog->layout()->setSpacing(0);
dialog->setMinimumSize(720, 400);
@ -1273,7 +1315,7 @@ ContentLayout* Widget::createContentDialog(const QString &title) const
dialog->setWindowTitle(title);
dialog->show();
return contentLayout;
return contentLayoutDialog;
}
void Widget::copyFriendIdToClipboard(int friendId)
@ -1332,12 +1374,7 @@ void Widget::onGroupMessageReceived(int groupnumber, int peernumber, const QStri
ContentDialog::updateGroupStatus(g->getGroupId());
if (g->getGroupWidget()->isActive())
{
QString windowTitle = g->getGroupWidget()->getName();
if (!g->getGroupWidget()->getStatusString().isNull())
windowTitle += " (" + g->getGroupWidget()->getStatusString() + ")";
setWindowTitle(windowTitle);
}
setWindowTitle(g->getGroupWidget()->getTitle());
}
void Widget::onGroupNamelistChanged(int groupnumber, int peernumber, uint8_t Change)
@ -1475,10 +1512,7 @@ bool Widget::event(QEvent * e)
{
activeChatroomWidget->resetEventFlags();
activeChatroomWidget->updateStatusLight();
QString windowTitle = activeChatroomWidget->getName();
if (!activeChatroomWidget->getStatusString().isNull())
windowTitle += " (" + activeChatroomWidget->getStatusString() + ")";
setWindowTitle(windowTitle);
setWindowTitle(activeChatroomWidget->getTitle());
}
if (eventFlag)
{