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

Multi-window: OS X window list, fix OS X translations

This commit is contained in:
TheSpiritXIII 2015-07-29 19:46:19 -04:00 committed by tux3
parent 23e7f9326e
commit 97bdaa5e5f
11 changed files with 386 additions and 89 deletions

View File

@ -497,7 +497,8 @@ SOURCES += \
src/widget/categorywidget.cpp \ src/widget/categorywidget.cpp \
src/widget/tool/removefrienddialog.cpp \ src/widget/tool/removefrienddialog.cpp \
src/widget/contentlayout.cpp \ src/widget/contentlayout.cpp \
src/widget/contentdialog.cpp src/widget/contentdialog.cpp \
src/widget/tool/activatedialog.cpp
HEADERS += \ HEADERS += \
src/audio/audio.h \ src/audio/audio.h \
@ -543,4 +544,5 @@ HEADERS += \
src/widget/categorywidget.h \ src/widget/categorywidget.h \
src/widget/contentlayout.h \ src/widget/contentlayout.h \
src/widget/contentdialog.h \ src/widget/contentdialog.h \
src/widget/tool/activatedialog.h \
src/widget/tool/removefrienddialog.h src/widget/tool/removefrienddialog.h

View File

@ -42,6 +42,8 @@
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
#include <QWindow> #include <QWindow>
#include <QMenuBar> #include <QMenuBar>
#include <QActionGroup>
#include <QSignalMapper>
#endif #endif
static Nexus* nexus{nullptr}; static Nexus* nexus{nullptr};
@ -89,26 +91,44 @@ void Nexus::start()
qRegisterMetaType<ToxFile::FileDirection>("ToxFile::FileDirection"); qRegisterMetaType<ToxFile::FileDirection>("ToxFile::FileDirection");
qRegisterMetaType<std::shared_ptr<VideoFrame>>("std::shared_ptr<VideoFrame>"); qRegisterMetaType<std::shared_ptr<VideoFrame>>("std::shared_ptr<VideoFrame>");
loginScreen = new LoginScreen();
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
globalMenuBar = new QMenuBar(0); globalMenuBar = new QMenuBar(0);
dockMenu = new QMenu(globalMenuBar);
windowMenu = globalMenuBar->addMenu(tr("Window")); viewMenu = globalMenuBar->addMenu(QString());
windowMenu = globalMenuBar->addMenu(QString());
globalMenuBar->addAction(windowMenu->menuAction()); globalMenuBar->addAction(windowMenu->menuAction());
QAction* minimizeAction = Nexus::getInstance().windowMenu->addAction(tr("Minimize")); fullscreenAction = viewMenu->addAction(QString());
fullscreenAction->setShortcut(QKeySequence::FullScreen);
connect(fullscreenAction, &QAction::triggered, this, &Nexus::toggleFullscreen);
minimizeAction = windowMenu->addAction(QString());
minimizeAction->setShortcut(Qt::CTRL + Qt::Key_M); minimizeAction->setShortcut(Qt::CTRL + Qt::Key_M);
connect(minimizeAction, &QAction::triggered, [minimizeAction]() connect(minimizeAction, &QAction::triggered, [this]()
{ {
minimizeAction->setEnabled(false);
QApplication::focusWindow()->showMinimized(); QApplication::focusWindow()->showMinimized();
}); });
Nexus::getInstance().windowMenu->addSeparator();
windowMenu->addSeparator();
frontAction = windowMenu->addAction(QString());
connect(frontAction, &QAction::triggered, this, &Nexus::bringAllToFront);
QAction* quitAction = new QAction(globalMenuBar); QAction* quitAction = new QAction(globalMenuBar);
quitAction->setMenuRole(QAction::QuitRole); quitAction->setMenuRole(QAction::QuitRole);
connect(quitAction, &QAction::triggered, qApp, &QApplication::quit); connect(quitAction, &QAction::triggered, qApp, &QApplication::quit);
#endif
loginScreen = new LoginScreen(); windowMapper = new QSignalMapper(this);
connect(windowMapper, SIGNAL(mapped(QObject*)), this, SLOT(onOpenWindow(QObject*)));
connect(loginScreen, &LoginScreen::windowStateChanged, this, &Nexus::onWindowStateChanged);
retranslateUi();
#endif
if (profile) if (profile)
showMainGUI(); showMainGUI();
@ -278,3 +298,131 @@ bool Nexus::tryRemoveFile(const QString& filepath)
tmp.remove(); tmp.remove();
return writable; return writable;
} }
#ifdef Q_OS_MAC
void Nexus::retranslateUi()
{
viewMenu->menuAction()->setText(tr("View", "OS X Menu bar"));
windowMenu->menuAction()->setText(tr("Window", "OS X Menu bar"));
minimizeAction->setText(tr("Minimize", "OS X Menu bar"));
frontAction->setText((tr("Bring All to Front", "OS X Menu bar")));
}
void Nexus::onWindowStateChanged(Qt::WindowStates state)
{
minimizeAction->setEnabled(QApplication::activeWindow() != nullptr);
if (QApplication::activeWindow() != nullptr && sender() == QApplication::activeWindow())
{
if (state & Qt::WindowFullScreen)
minimizeAction->setEnabled(false);
if (state & Qt::WindowFullScreen)
fullscreenAction->setText(tr("Exit Fullscreen"));
else
fullscreenAction->setText(tr("Enter Fullscreen"));
updateWindows();
}
updateWindowsStates();
}
void Nexus::updateWindows()
{
updateWindowsArg(nullptr);
}
void Nexus::updateWindowsArg(QWindow* closedWindow)
{
QWindowList windowList = QApplication::topLevelWindows();
delete windowActions;
windowActions = new QActionGroup(this);
windowMenu->addSeparator();
QAction* dockLast;
if (dockMenu->actions().count() != 0)
dockLast = dockMenu->actions().first();
else
dockLast = nullptr;
QWindow* activeWindow;
if (QApplication::activeWindow())
activeWindow = QApplication::activeWindow()->windowHandle();
else
activeWindow = nullptr;
for (int i = 0; i < windowList.size(); ++i)
{
if (closedWindow == windowList[i])
continue;
QAction* action = windowActions->addAction(windowList[i]->title());
action->setCheckable(true);
action->setChecked(windowList[i] == activeWindow);
connect(action, SIGNAL(triggered()), windowMapper, SLOT(map()));
windowMapper->setMapping(action, windowList[i]);
windowMenu->addAction(action);
dockMenu->insertAction(dockLast, action);
}
if (!dockLast->isSeparator())
dockMenu->insertSeparator(dockLast);
}
void Nexus::updateWindowsClosed()
{
updateWindowsArg(static_cast<QWidget*>(sender())->windowHandle());
}
void Nexus::updateWindowsStates()
{
bool exists = false;
QWindowList windowList = QApplication::topLevelWindows();
for (QWindow* window : windowList)
{
if (!(window->windowState() & Qt::WindowMinimized))
{
exists = true;
break;
}
}
frontAction->setEnabled(exists);
}
void Nexus::onOpenWindow(QObject* object)
{
QWindow* window = static_cast<QWindow*>(object);
if (window->windowState() & QWindow::Minimized)
window->showNormal();
window->raise();
window->requestActivate();
}
void Nexus::toggleFullscreen()
{
QWidget* window = QApplication::activeWindow();
if (window->isFullScreen())
window->showNormal();
else
window->showFullScreen();
}
void Nexus::bringAllToFront()
{
QWindowList windowList = QApplication::topLevelWindows();
QWindow* focused = QApplication::focusWindow();
for (QWindow* window : windowList)
window->raise();
focused->raise();
}
#endif

View File

@ -32,6 +32,10 @@ class Core;
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
class QMenuBar; class QMenuBar;
class QMenu; class QMenu;
class QAction;
class QWindow;
class QActionGroup;
class QSignalMapper;
#endif #endif
/// This class is in charge of connecting various systems together /// This class is in charge of connecting various systems together
@ -59,7 +63,28 @@ public:
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
QMenuBar* globalMenuBar; QMenuBar* globalMenuBar;
QMenu* viewMenu;
QMenu* windowMenu; QMenu* windowMenu;
QAction* minimizeAction;
QAction* fullscreenAction;
QAction* frontAction;
QMenu* dockMenu;
public slots:
void retranslateUi();
void onWindowStateChanged(Qt::WindowStates state);
void updateWindows();
void updateWindowsClosed();
void updateWindowsStates();
void onOpenWindow(QObject* object);
void toggleFullscreen();
void bringAllToFront();
private:
void updateWindowsArg(QWindow *closedWindow);
QSignalMapper* windowMapper;
QActionGroup* windowActions = nullptr;
#endif #endif
private: private:

View File

@ -46,7 +46,7 @@ QHash<int, std::tuple<ContentDialog*, GenericChatroomWidget*>> ContentDialog::fr
QHash<int, std::tuple<ContentDialog*, GenericChatroomWidget*>> ContentDialog::groupList; QHash<int, std::tuple<ContentDialog*, GenericChatroomWidget*>> ContentDialog::groupList;
ContentDialog::ContentDialog(SettingsWidget* settingsWidget, QWidget* parent) ContentDialog::ContentDialog(SettingsWidget* settingsWidget, QWidget* parent)
: QDialog(parent, Qt::Window) : ActivateDialog(parent, Qt::Window)
, activeChatroomWidget(nullptr) , activeChatroomWidget(nullptr)
, settingsWidget(settingsWidget) , settingsWidget(settingsWidget)
{ {
@ -476,11 +476,15 @@ bool ContentDialog::event(QEvent* event)
} }
currentDialog = this; currentDialog = this;
#ifdef Q_OS_MAC
emit activated();
#endif
default: default:
break; break;
} }
return QWidget::event(event); return ActivateDialog::event(event);
} }
void ContentDialog::dragEnterEvent(QDragEnterEvent *event) void ContentDialog::dragEnterEvent(QDragEnterEvent *event)

View File

@ -20,7 +20,7 @@
#ifndef CONTENTDIALOG_H #ifndef CONTENTDIALOG_H
#define CONTENTDIALOG_H #define CONTENTDIALOG_H
#include <QDialog> #include "src/widget/tool/activatedialog.h"
#include <tuple> #include <tuple>
#include "src/core/corestructs.h" #include "src/core/corestructs.h"
#include "src/widget/genericchatitemlayout.h" #include "src/widget/genericchatitemlayout.h"
@ -37,7 +37,7 @@ class GroupWidget;
class FriendListLayout; class FriendListLayout;
class SettingsWidget; class SettingsWidget;
class ContentDialog : public QDialog class ContentDialog : public ActivateDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
@ -66,6 +66,11 @@ public:
static ContentDialog* getFriendDialog(int friendId); static ContentDialog* getFriendDialog(int friendId);
static ContentDialog* getGroupDialog(int groupId); static ContentDialog* getGroupDialog(int groupId);
#ifdef Q_OS_MAC
signals:
void activated();
#endif
public slots: public slots:
void updateTitleUsername(const QString& username); void updateTitleUsername(const QString& username);
void updateTitle(GenericChatroomWidget* chatroomWidget); void updateTitle(GenericChatroomWidget* chatroomWidget);

View File

@ -97,6 +97,16 @@ void LoginScreen::reset()
ui->autoLoginCB->setChecked(Settings::getInstance().getAutoLogin()); ui->autoLoginCB->setChecked(Settings::getInstance().getAutoLogin());
} }
#ifdef Q_OS_MAC
bool LoginScreen::event(QEvent* event)
{
if (event->type() == QEvent::WindowActivate || event->type() == QEvent::WindowStateChange)
emit windowStateChanged(windowState());
return QWidget::event(event);
}
#endif
void LoginScreen::onNewProfilePageClicked() void LoginScreen::onNewProfilePageClicked()
{ {
ui->stackedWidget->setCurrentIndex(0); ui->stackedWidget->setCurrentIndex(0);

View File

@ -37,6 +37,13 @@ public:
~LoginScreen(); ~LoginScreen();
void reset(); ///< Resets the UI, clears all fields void reset(); ///< Resets the UI, clears all fields
#ifdef Q_OS_MAC
bool event(QEvent* event) final override;
signals:
void windowStateChanged(Qt::WindowStates states);
#endif
private slots: private slots:
void onAutoLoginToggled(int state); void onAutoLoginToggled(int state);
void onLoginUsernameSelected(const QString& name); void onLoginUsernameSelected(const QString& name);

View File

@ -0,0 +1,36 @@
/*
Copyright © 2015 by The qTox Project
This file is part of qTox, a Qt-based graphical interface for Tox.
qTox is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
qTox is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with qTox. If not, see <http://www.gnu.org/licenses/>.
*/
#include "activatedialog.h"
#include <QEvent>
ActivateDialog::ActivateDialog(QWidget *parent, Qt::WindowFlags f)
: QDialog(parent, f)
{
}
bool ActivateDialog::event(QEvent* event)
{
if (event->type() == QEvent::WindowActivate || event->type() == QEvent::WindowStateChange)
emit windowStateChanged(windowState());
return QDialog::event(event);
}

View File

@ -0,0 +1,36 @@
/*
Copyright © 2015 by The qTox Project
This file is part of qTox, a Qt-based graphical interface for Tox.
qTox is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
qTox is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with qTox. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ACTIVATEDIALOG_H
#define ACTIVATEDIALOG_H
#include <QDialog>
class ActivateDialog : public QDialog
{
Q_OBJECT
public:
ActivateDialog(QWidget* parent = 0, Qt::WindowFlags f = 0);
bool event(QEvent* event) override;
signals:
void windowStateChanged(Qt::WindowStates state);
};
#endif // ACTIVATEDIALOG_H

View File

@ -50,6 +50,7 @@
#include "src/widget/form/profileform.h" #include "src/widget/form/profileform.h"
#include "src/widget/form/settingswidget.h" #include "src/widget/form/settingswidget.h"
#include "tool/removefrienddialog.h" #include "tool/removefrienddialog.h"
#include "src/widget/tool/activatedialog.h"
#include <cassert> #include <cassert>
#include <QMessageBox> #include <QMessageBox>
#include <QDebug> #include <QDebug>
@ -76,6 +77,7 @@
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
#include <QMenuBar> #include <QMenuBar>
#include <QWindow> #include <QWindow>
#include <QSignalMapper>
#endif #endif
#ifdef Q_OS_ANDROID #ifdef Q_OS_ANDROID
@ -243,13 +245,17 @@ void Widget::init()
new QShortcut(Qt::CTRL + Qt::Key_PageDown, this, SLOT(nextContact())); new QShortcut(Qt::CTRL + Qt::Key_PageDown, this, SLOT(nextContact()));
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
QMenuBar* globalMenu = Nexus::getInstance().globalMenuBar;
QAction* windowMenu = Nexus::getInstance().windowMenu->menuAction(); QAction* windowMenu = Nexus::getInstance().windowMenu->menuAction();
QAction* fileMenu = Nexus::getInstance().globalMenuBar->insertMenu(windowMenu, new QMenu(tr("File"), this)); QAction* viewMenu = Nexus::getInstance().viewMenu->menuAction();
QAction* frontAction = Nexus::getInstance().frontAction;
QAction* editProfileAction = fileMenu->menu()->addAction(tr("Edit Profile")); fileMenu = globalMenu->insertMenu(viewMenu, new QMenu(this));
editProfileAction = fileMenu->menu()->addAction(QString());
connect(editProfileAction, &QAction::triggered, this, &Widget::showProfile); connect(editProfileAction, &QAction::triggered, this, &Widget::showProfile);
QMenu* changeStatusMenu = fileMenu->menu()->addMenu(tr("Change Status")); changeStatusMenu = fileMenu->menu()->addMenu(QString());
fileMenu->menu()->addAction(changeStatusMenu->menuAction()); fileMenu->menu()->addAction(changeStatusMenu->menuAction());
changeStatusMenu->addAction(statusOnline); changeStatusMenu->addAction(statusOnline);
changeStatusMenu->addSeparator(); changeStatusMenu->addSeparator();
@ -257,50 +263,47 @@ void Widget::init()
changeStatusMenu->addAction(statusBusy); changeStatusMenu->addAction(statusBusy);
fileMenu->menu()->addSeparator(); fileMenu->menu()->addSeparator();
QAction* logoutAction = fileMenu->menu()->addAction(tr("Log out")); logoutAction = fileMenu->menu()->addAction(QString());
connect(logoutAction, &QAction::triggered, [this]() connect(logoutAction, &QAction::triggered, [this]()
{ {
Nexus::getInstance().showLogin(); Nexus::getInstance().showLogin();
}); });
QAction* editMenu = Nexus::getInstance().globalMenuBar->insertMenu(windowMenu, new QMenu(tr("Edit"), this)); editMenu = globalMenu->insertMenu(viewMenu, new QMenu(this));
editMenu->menu()->addSeparator(); editMenu->menu()->addSeparator();
QAction* viewMenu = Nexus::getInstance().globalMenuBar->insertMenu(windowMenu, new QMenu(tr("View"), this)); viewMenu->menu()->insertMenu(Nexus::getInstance().fullscreenAction, filterMenu);
QMenu* filterMenu = viewMenu->menu()->addMenu(tr("Filter...")); viewMenu->menu()->insertSeparator(Nexus::getInstance().fullscreenAction);
filterMenu->addAction(filterDisplayName);
filterMenu->addAction(filterDisplayActivity);
filterMenu->addSeparator();
filterMenu->addAction(filterAllAction);
filterMenu->addAction(filterOnlineAction);
filterMenu->addAction(filterOfflineAction);
filterMenu->addAction(filterFriendsAction);
filterMenu->addAction(filterGroupsAction);
viewMenu->menu()->addSeparator(); contactMenu = globalMenu->insertMenu(windowMenu, new QMenu(this));
fullscreenAction = viewMenu->menu()->addAction(tr("Enter Fullscreen"));
fullscreenAction->setShortcut(QKeySequence::FullScreen);
connect(fullscreenAction, &QAction::triggered, this, &Widget::toggleFullscreen);
QAction* contactMenu = Nexus::getInstance().globalMenuBar->insertMenu(windowMenu, new QMenu(tr("Contacts"), this)); addContactAction = contactMenu->menu()->addAction(QString());
QAction* addContactAction = contactMenu->menu()->addAction(tr("Add Contact..."));
connect(addContactAction, &QAction::triggered, this, &Widget::onAddClicked); connect(addContactAction, &QAction::triggered, this, &Widget::onAddClicked);
QAction* nextConversationAction = new QAction(tr("Next Conversation"), this); nextConversationAction = new QAction(this);
Nexus::getInstance().windowMenu->addAction(nextConversationAction); Nexus::getInstance().windowMenu->insertAction(frontAction, nextConversationAction);
nextConversationAction->setShortcut(QKeySequence::SelectNextPage); nextConversationAction->setShortcut(QKeySequence::SelectNextPage);
connect(nextConversationAction, &QAction::triggered, this, &Widget::nextContact); connect(nextConversationAction, &QAction::triggered, [this]()
{
if (ContentDialog::current() == QApplication::activeWindow())
ContentDialog::current()->cycleContacts(true);
else if (QApplication::activeWindow() == this)
cycleContacts(true);
});
QAction* previousConversationAction = new QAction(tr("Previous Conversation"), this); previousConversationAction = new QAction(this);
Nexus::getInstance().windowMenu->addAction(previousConversationAction); Nexus::getInstance().windowMenu->insertAction(frontAction, previousConversationAction);
previousConversationAction->setShortcut(QKeySequence::SelectPreviousPage); previousConversationAction->setShortcut(QKeySequence::SelectPreviousPage);
connect(previousConversationAction, &QAction::triggered, this, &Widget::previousContact); connect(previousConversationAction, &QAction::triggered, [this]
{
if (ContentDialog::current() == QApplication::activeWindow())
ContentDialog::current()->cycleContacts(false);
else if (QApplication::activeWindow() == this)
cycleContacts(false);
});
Nexus::getInstance().windowMenu->addSeparator(); windowMenu->menu()->insertSeparator(frontAction);
QAction* frontAction = Nexus::getInstance().windowMenu->addAction(tr("Bring All to Front"));
connect(frontAction, &QAction::triggered, this, &Widget::bringAllToFront);
QAction* preferencesAction = viewMenu->menu()->addAction(QString()); QAction* preferencesAction = viewMenu->menu()->addAction(QString());
preferencesAction->setMenuRole(QAction::PreferencesRole); preferencesAction->setMenuRole(QAction::PreferencesRole);
@ -313,6 +316,16 @@ void Widget::init()
onSettingsClicked(); onSettingsClicked();
settingsWidget->showAbout(); settingsWidget->showAbout();
}); });
QMenu* dockChangeStatusMenu = new QMenu(tr("Status"), this);
dockChangeStatusMenu->addAction(statusOnline);
statusOnline->setIconVisibleInMenu(true);
dockChangeStatusMenu->addSeparator();
dockChangeStatusMenu->addAction(statusAway);
dockChangeStatusMenu->addAction(statusBusy);
Nexus::getInstance().dockMenu->addAction(dockChangeStatusMenu->menuAction());
connect(this, &Widget::windowStateChanged, &Nexus::getInstance(), &Nexus::onWindowStateChanged);
#endif #endif
contentLayout = nullptr; contentLayout = nullptr;
@ -343,6 +356,8 @@ void Widget::init()
if (!Settings::getInstance().getShowSystemTray()) if (!Settings::getInstance().getShowSystemTray())
show(); show();
Nexus::getInstance().updateWindows();
} }
bool Widget::eventFilter(QObject *obj, QEvent *event) bool Widget::eventFilter(QObject *obj, QEvent *event)
@ -357,6 +372,8 @@ bool Widget::eventFilter(QObject *obj, QEvent *event)
else else
wasMaximized = false; wasMaximized = false;
} }
emit windowStateChanged(windowState());
} }
return false; return false;
} }
@ -1295,16 +1312,24 @@ void Widget::clearContactsList()
ContentDialog* Widget::createContentDialog() const ContentDialog* Widget::createContentDialog() const
{ {
return new ContentDialog(settingsWidget); ContentDialog* contentDialog = new ContentDialog(settingsWidget);
contentDialog->show();
#ifdef Q_OS_MAC
connect(contentDialog, &ContentDialog::destroyed, &Nexus::getInstance(), &Nexus::updateWindowsClosed);
connect(contentDialog, &ContentDialog::windowStateChanged, &Nexus::getInstance(), &Nexus::onWindowStateChanged);
connect(contentDialog->windowHandle(), &QWindow::windowTitleChanged, &Nexus::getInstance(), &Nexus::updateWindows);
Nexus::getInstance().updateWindows();
#endif
return contentDialog;
} }
ContentLayout* Widget::createContentDialog(DialogType type) const ContentLayout* Widget::createContentDialog(DialogType type)
{ {
class Dialog : public QDialog class Dialog : public ActivateDialog
{ {
public: public:
Dialog(DialogType type) Dialog(DialogType type)
: QDialog() : ActivateDialog()
, type(type) , type(type)
{ {
restoreGeometry(Settings::getInstance().getDialogSettingsGeometry()); restoreGeometry(Settings::getInstance().getDialogSettingsGeometry());
@ -1343,7 +1368,7 @@ ContentLayout* Widget::createContentDialog(DialogType type) const
DialogType type; DialogType type;
}; };
QDialog* dialog = new Dialog(type); Dialog* dialog = new Dialog(type);
dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->setAttribute(Qt::WA_DeleteOnClose);
ContentLayout* contentLayoutDialog = new ContentLayout(dialog); ContentLayout* contentLayoutDialog = new ContentLayout(dialog);
@ -1355,6 +1380,13 @@ ContentLayout* Widget::createContentDialog(DialogType type) const
dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->show(); dialog->show();
#ifdef Q_OS_MAC
connect(dialog, &Dialog::destroyed, &Nexus::getInstance(), &Nexus::updateWindowsClosed);
connect(dialog, &ActivateDialog::windowStateChanged, &Nexus::getInstance(), &Nexus::updateWindowsStates);
connect(dialog->windowHandle(), &QWindow::windowTitleChanged, &Nexus::getInstance(), &Nexus::updateWindows);
Nexus::getInstance().updateWindows();
#endif
return contentLayoutDialog; return contentLayoutDialog;
} }
@ -1549,6 +1581,14 @@ bool Widget::event(QEvent * e)
eventIcon = false; eventIcon = false;
updateIcons(); updateIcons();
} }
#ifdef Q_OS_MAC
emit windowStateChanged(windowState());
case QEvent::WindowStateChange:
Nexus::getInstance().updateWindowsStates();
#endif
default: default:
break; break;
} }
@ -1630,16 +1670,7 @@ void Widget::onTryCreateTrayIcon()
} }
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
QMenu* changeStatusMenu = new QMenu(tr("Status"), this); qt_mac_set_dock_menu(Nexus::getInstance().dockMenu);
changeStatusMenu->addAction(statusOnline);
statusOnline->setIconVisibleInMenu(true);
changeStatusMenu->addSeparator();
changeStatusMenu->addAction(statusAway);
changeStatusMenu->addAction(statusBusy);
QMenu* dockMenu = new QMenu(this);
dockMenu->addAction(changeStatusMenu->menuAction());
qt_mac_set_dock_menu(dockMenu);
#endif #endif
} }
else if (!isVisible()) else if (!isVisible())
@ -2003,33 +2034,20 @@ void Widget::retranslateUi()
if (!Settings::getInstance().getSeparateWindow()) if (!Settings::getInstance().getSeparateWindow())
setWindowTitle(fromDialogType(SettingDialog)); setWindowTitle(fromDialogType(SettingDialog));
}
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
void Widget::bringAllToFront() Nexus::getInstance().retranslateUi();
{
QWindowList windowList = QApplication::topLevelWindows();
for (QWindow* window : windowList)
{
window->raise();
window->showNormal();
window->requestActivate();
}
}
void Widget::toggleFullscreen() filterMenu->menuAction()->setText(tr("Filter..."));
{
QWidget* window = QApplication::activeWindow();
if (window->isFullScreen()) fileMenu->setText(tr("File"));
{ editMenu->setText(tr("Edit"));
window->showNormal(); contactMenu->setText(tr("Contacts"));
fullscreenAction->setText(tr("Enter Fullscreen")); changeStatusMenu->menuAction()->setText(tr("Change Status"));
} editProfileAction->setText(tr("Edit Profile"));
else logoutAction->setText(tr("Log out"));
{ addContactAction->setText(tr("Add Contact..."));
window->showFullScreen(); nextConversationAction->setText(tr("Next Conversation"));
fullscreenAction->setText(tr("Exit Fullscreen")); previousConversationAction->setText(tr("Previous Conversation"));
}
}
#endif #endif
}

View File

@ -83,7 +83,7 @@ public:
static QString fromDialogType(DialogType type); static QString fromDialogType(DialogType type);
ContentDialog* createContentDialog() const; ContentDialog* createContentDialog() const;
ContentLayout* createContentDialog(DialogType type) const; ContentLayout* createContentDialog(DialogType type);
static void confirmExecutableOpen(const QFileInfo file); static void confirmExecutableOpen(const QFileInfo file);
@ -147,6 +147,9 @@ signals:
void usernameChanged(const QString& username); void usernameChanged(const QString& username);
void statusMessageChanged(const QString& statusMessage); void statusMessageChanged(const QString& statusMessage);
void resized(); void resized();
#ifdef Q_OS_MAC
void windowStateChanged(Qt::WindowStates states);
#endif
protected: protected:
virtual bool eventFilter(QObject *obj, QEvent *event) final override; virtual bool eventFilter(QObject *obj, QEvent *event) final override;
@ -178,11 +181,6 @@ private slots:
void processOfflineMsgs(); void processOfflineMsgs();
void friendListContextMenu(const QPoint &pos); void friendListContextMenu(const QPoint &pos);
#ifdef Q_OS_MAC
void bringAllToFront();
void toggleFullscreen();
#endif
private: private:
enum ActiveToolMenuButton { enum ActiveToolMenuButton {
AddButton, AddButton,
@ -263,7 +261,15 @@ private:
bool wasMaximized = false; bool wasMaximized = false;
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
QAction* fullscreenAction; QAction* fileMenu;
QAction* editMenu;
QAction* contactMenu;
QMenu* changeStatusMenu;
QAction* editProfileAction;
QAction* logoutAction;
QAction* addContactAction;
QAction* nextConversationAction;
QAction* previousConversationAction;
#endif #endif
}; };