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

Merge branch 'pr1953'

This commit is contained in:
tux3 2015-07-22 23:33:21 +02:00
commit 74b771373d
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
7 changed files with 174 additions and 18 deletions

View File

@ -1085,7 +1085,7 @@ QSplitter:handle{
<x>0</x>
<y>0</y>
<width>284</width>
<height>353</height>
<height>398</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5"/>
@ -1841,20 +1841,6 @@ QSplitter:handle{
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>775</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<action name="actionClose">
<property name="text">
<string>Close</string>

View File

@ -39,6 +39,11 @@
#include <QDesktopWidget>
#endif
#ifdef Q_OS_MAC
#include <QWindow>
#include <QMenuBar>
#endif
static Nexus* nexus{nullptr};
Nexus::Nexus(QObject *parent) :
@ -60,6 +65,9 @@ Nexus::~Nexus()
delete loginScreen;
delete profile;
Settings::getInstance().saveGlobal();
#ifdef Q_OS_MAC
delete globalMenuBar;
#endif
}
void Nexus::start()
@ -81,6 +89,25 @@ void Nexus::start()
qRegisterMetaType<ToxFile::FileDirection>("ToxFile::FileDirection");
qRegisterMetaType<std::shared_ptr<VideoFrame>>("std::shared_ptr<VideoFrame>");
#ifdef Q_OS_MAC
globalMenuBar = new QMenuBar(0);
windowMenu = globalMenuBar->addMenu(tr("Window"));
globalMenuBar->addAction(windowMenu->menuAction());
QAction* minimizeAction = Nexus::getInstance().windowMenu->addAction(tr("Minimize"));
minimizeAction->setShortcut(Qt::CTRL + Qt::Key_M);
connect(minimizeAction, &QAction::triggered, [minimizeAction]()
{
QApplication::focusWindow()->showMinimized();
});
Nexus::getInstance().windowMenu->addSeparator();
QAction* quitAction = new QAction(globalMenuBar);
quitAction->setMenuRole(QAction::QuitRole);
connect(quitAction, &QAction::triggered, qApp, &QApplication::quit);
#endif
loginScreen = new LoginScreen();
if (profile)

View File

@ -29,6 +29,11 @@ class Profile;
class LoginScreen;
class Core;
#ifdef Q_OS_MAC
class QMenuBar;
class QMenu;
#endif
/// This class is in charge of connecting various systems together
/// and forwarding signals appropriately to the right objects
/// It is in charge of starting the GUI and the Core
@ -52,6 +57,11 @@ public:
static QString getSupportedImageFilter();
static bool tryRemoveFile(const QString& filepath); ///< Dangerous way to find out if a path is writable
#ifdef Q_OS_MAC
QMenuBar* globalMenuBar;
QMenu* windowMenu;
#endif
private:
explicit Nexus(QObject *parent = 0);
~Nexus();

View File

@ -81,6 +81,11 @@ void SettingsWidget::setBodyHeadStyle(QString style)
body->setStyle(QStyleFactory::create(style));
}
void SettingsWidget::showAbout()
{
onTabChanged(settingsWidgets->count() - 1);
}
void SettingsWidget::show(Ui::MainWindow& ui)
{
ui.mainContent->layout()->addWidget(body);

View File

@ -45,6 +45,8 @@ public:
void show(Ui::MainWindow &ui);
void setBodyHeadStyle(QString style);
void showAbout();
signals:
void setShowSystemTray(bool newValue);
void compactToggled(bool compact);

View File

@ -69,6 +69,11 @@
#include <QProcess>
#include <tox/tox.h>
#ifdef Q_OS_MAC
#include <QMenuBar>
#include <QWindow>
#endif
#ifdef Q_OS_ANDROID
#define IS_ON_DESKTOP_GUI 0
#else
@ -122,9 +127,6 @@ void Widget::init()
statusBusy->setIcon(getStatusIcon(Status::Busy, 10, 10));
connect(statusBusy, SIGNAL(triggered()), this, SLOT(setStatusBusy()));
ui->statusbar->hide();
ui->menubar->hide();
layout()->setContentsMargins(0, 0, 0, 0);
ui->friendList->setStyleSheet(Style::resolve(Style::getStylesheet(":ui/friendList/friendList.css")));
@ -255,6 +257,79 @@ void Widget::init()
new QShortcut(Qt::CTRL + Qt::Key_PageUp, this, SLOT(previousContact()));
new QShortcut(Qt::CTRL + Qt::Key_PageDown, this, SLOT(nextContact()));
#ifdef Q_OS_MAC
QAction* windowMenu = Nexus::getInstance().windowMenu->menuAction();
QAction* fileMenu = Nexus::getInstance().globalMenuBar->insertMenu(windowMenu, new QMenu(tr("File"), this));
QAction* editProfileAction = fileMenu->menu()->addAction(tr("Edit Profile"));
connect(editProfileAction, &QAction::triggered, this, &Widget::showProfile);
QMenu* changeStatusMenu = fileMenu->menu()->addMenu(tr("Change Status"));
fileMenu->menu()->addAction(changeStatusMenu->menuAction());
changeStatusMenu->addAction(statusOnline);
changeStatusMenu->addSeparator();
changeStatusMenu->addAction(statusAway);
changeStatusMenu->addAction(statusBusy);
fileMenu->menu()->addSeparator();
QAction* logoutAction = fileMenu->menu()->addAction(tr("Log out"));
connect(logoutAction, &QAction::triggered, [this]()
{
Nexus::getInstance().showLogin();
});
QAction* editMenu = Nexus::getInstance().globalMenuBar->insertMenu(windowMenu, new QMenu(tr("Edit"), this));
editMenu->menu()->addSeparator();
QAction* viewMenu = Nexus::getInstance().globalMenuBar->insertMenu(windowMenu, new QMenu(tr("View"), this));
QMenu* filterMenu = viewMenu->menu()->addMenu(tr("Filter..."));
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();
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));
QAction* addContactAction = contactMenu->menu()->addAction(tr("Add Contact..."));
connect(addContactAction, &QAction::triggered, this, &Widget::onAddClicked);
QAction* nextConversationAction = new QAction(tr("Next Conversation"), this);
Nexus::getInstance().windowMenu->addAction(nextConversationAction);
nextConversationAction->setShortcut(QKeySequence::SelectNextPage);
connect(nextConversationAction, &QAction::triggered, this, &Widget::nextContact);
QAction* previousConversationAction = new QAction(tr("Previous Conversation"), this);
Nexus::getInstance().windowMenu->addAction(previousConversationAction);
previousConversationAction->setShortcut(QKeySequence::SelectPreviousPage);
connect(previousConversationAction, &QAction::triggered, this, &Widget::previousContact);
Nexus::getInstance().windowMenu->addSeparator();
QAction* frontAction = Nexus::getInstance().windowMenu->addAction(tr("Bring All to Front"));
connect(frontAction, &QAction::triggered, this, &Widget::bringAllToFront);
QAction* preferencesAction = viewMenu->menu()->addAction(QString());
preferencesAction->setMenuRole(QAction::PreferencesRole);
connect(preferencesAction, &QAction::triggered, this, &Widget::onSettingsClicked);
QAction* aboutAction = viewMenu->menu()->addAction(QString());
aboutAction->setMenuRole(QAction::AboutRole);
connect(aboutAction, &QAction::triggered, [this]()
{
onSettingsClicked();
settingsWidget->showAbout();
});
#endif
addFriendForm->show(*ui);
setWindowTitle(tr("Add friend"));
ui->addButton->setCheckable(true);
@ -1256,6 +1331,19 @@ void Widget::onTryCreateTrayIcon()
{
show();
}
#ifdef Q_OS_MAC
QMenu* changeStatusMenu = new QMenu(tr("Status"), this);
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
}
else if (!isVisible())
{
@ -1617,3 +1705,32 @@ void Widget::retranslateUi()
statusBusy->setText(tr("Busy", "Button to set your status to 'Busy'"));
setWindowTitle(tr("Settings"));
}
#ifdef Q_OS_MAC
void Widget::bringAllToFront()
{
QWindowList windowList = QApplication::topLevelWindows();
for (QWindow* window : windowList)
{
window->raise();
window->showNormal();
window->requestActivate();
}
}
void Widget::toggleFullscreen()
{
QWidget* window = QApplication::activeWindow();
if (window->isFullScreen())
{
window->showNormal();
fullscreenAction->setText(tr("Enter Fullscreen"));
}
else
{
window->showFullScreen();
fullscreenAction->setText(tr("Exit Fullscreen"));
}
}
#endif

View File

@ -160,6 +160,11 @@ private slots:
void processOfflineMsgs();
void friendListContextMenu(const QPoint &pos);
#ifdef Q_OS_MAC
void bringAllToFront();
void toggleFullscreen();
#endif
private:
enum ActiveToolMenuButton {
AddButton,
@ -236,6 +241,10 @@ private:
bool eventFlag;
bool eventIcon;
bool wasMaximized = false;
#ifdef Q_OS_MAC
QAction* fullscreenAction;
#endif
};
bool toxActivateEventHandler(const QByteArray& data);