Commit 364495b1 authored by Calvin Buckley's avatar Calvin Buckley 🤔
Browse files

Window menu on macOS

It could be enabled on other platforms; there's nothing Mac specific
about it.
parent ca3d7a96
......@@ -42,6 +42,7 @@
#include <QMessageBox>
#include <QStatusBar>
#include <QWhatsThis>
#include <QWindow>
#ifdef QT_DBUS_SUPPORT
#include <QDBusConnection>
......@@ -635,9 +636,12 @@ void QCGTopLevel::createMenu()
fileMenu->addAction(_exitAction);
#ifdef Q_OS_MAC
QMenu* windowMenu = mBar->addMenu(tr("&Window"));
windowMenu->addAction(_minimizeAction);
windowMenu->addAction(_zoomAction);
// class level for ease of manipulation
this->windowMenu = mBar->addMenu(tr("&Window"));
this->windowMenu->addAction(_minimizeAction);
this->windowMenu->addAction(_zoomAction);
connect(this->windowMenu, &QMenu::aboutToShow, this, &QCGTopLevel::windowListAboutToShow);
connect(this->windowMenu, &QMenu::triggered, this, &QCGTopLevel::windowListTriggered);
#endif
QMenu* helpMenu = mBar->addMenu(tr("&Help"));
......@@ -1843,6 +1847,30 @@ void QCGTopLevel::partsUnhideAllSlot()
#endif
}
void QCGTopLevel::windowListAboutToShow()
{
windowMenu->clear();
windowMenu->addAction(_minimizeAction);
windowMenu->addAction(_zoomAction);
windowMenu->addSeparator();
auto windowList = QApplication::topLevelWidgets();
for (int i = 0; i < windowList.size(); i++) {
QWidget *topLevelRaw = windowList[i];
if (QCGTopLevel *topLevel = qobject_cast<QCGTopLevel*>(topLevelRaw)) {
QString windowTitle = topLevel->windowTitle();
QAction *windowItem = windowMenu->addAction(windowTitle);
windowItem->setData(QVariant::fromValue(topLevel));
if (topLevel == this) {
qDebug() << "checked\n";
windowItem->setCheckable(true);
windowItem->setChecked(true);
}
}
}
}
void QCGTopLevel::forwardAboutToShow()
{
QMenu *popup = _forwardAction->menu();
......@@ -1949,6 +1977,20 @@ void QCGTopLevel::upAboutToShow()
}
}
void QCGTopLevel::windowListTriggered(QAction* action)
{
if (action == _minimizeAction || action == _zoomAction) {
// these are always in the menu for macOS
return;
}
QVariant data = action->data();
if (QCGTopLevel* tl = qvariant_cast<QCGTopLevel*>(data)) {
tl->activateWindow();
tl->raise();
}
}
void QCGTopLevel::forwardTriggered(QAction* action)
{
int count = action->data().toInt(nullptr);
......
......@@ -137,6 +137,8 @@ public Q_SLOTS:
void primaryAboutToShow();
void secondaryAboutToShow();
void groupingAboutToShow();
void windowListTriggered(QAction*);
void windowListAboutToShow();
bool setEventType(EventType*);
bool setEventType2(EventType*);
......@@ -231,6 +233,7 @@ private:
QAction *_upAction, *_forwardAction, *_backAction;
QAction *_configureAction, *_aboutAction, *_aboutQtAction;
QAction *_minimizeAction, *_zoomAction;
QMenu *windowMenu;
QComboBox* _eventTypeBox;
TraceFunction* _function;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment