Fixed dock menu on Mac OS.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2015-12-05 11:50:32 +02:00
parent e781b8252d
commit 7054714114
3 changed files with 31 additions and 15 deletions

View file

@ -120,18 +120,8 @@ TMainWindow::TMainWindow(QWidget *parent)
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 2) #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 2)
// Mac OS Dock Menu // Mac OS Dock Menu
QMenu *menu = new QMenu(this); QMenu *menu = new QMenu(this);
connect(menu, &QMenu::aboutToShow, this, &TMainWindow::AboutToShowDockMenu);
CreateWindowMenu(ui->menuWindow); AboutToShowDockMenu();
menu->addSeparator();
menu->addAction(ui->actionOpenIndividual);
menu->addAction(ui->actionOpenStandard);
menu->addAction(ui->actionOpenTemplate);
menu->addSeparator();
menu->addAction(ui->actionPreferences);
extern void qt_mac_set_dock_menu(QMenu *); extern void qt_mac_set_dock_menu(QMenu *);
qt_mac_set_dock_menu(menu); qt_mac_set_dock_menu(menu);
@ -765,6 +755,7 @@ void TMainWindow::ShowWindow()
{ {
const int offset = qvariant_cast<int>(v); const int offset = qvariant_cast<int>(v);
QList<TMainWindow*> windows = qApp->MainWindows(); QList<TMainWindow*> windows = qApp->MainWindows();
windows.at(offset)->raise();
windows.at(offset)->activateWindow(); windows.at(offset)->activateWindow();
} }
} }
@ -786,6 +777,28 @@ void TMainWindow::AboutQt()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
#if defined(Q_OS_MAC) #if defined(Q_OS_MAC)
void TMainWindow::AboutToShowDockMenu()
{
if (QMenu *menu = qobject_cast<QMenu *>(sender()))
{
menu->clear();
CreateWindowMenu(menu);
menu->addSeparator();
menu->addAction(ui->actionOpenIndividual);
menu->addAction(ui->actionOpenStandard);
menu->addAction(ui->actionOpenTemplate);
menu->addSeparator();
QAction *actionPreferences = menu->addAction(tr("Preferences"));
actionPreferences->setMenuRole(QAction::NoRole);
connect(actionPreferences, &QAction::triggered, this, &TMainWindow::Preferences);
}
}
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::OpenAt(QAction *where) void TMainWindow::OpenAt(QAction *where)
{ {
const QString path = curFile.left(curFile.indexOf(where->text())) + where->text(); const QString path = curFile.left(curFile.indexOf(where->text())) + where->text();
@ -2758,7 +2771,7 @@ void TMainWindow::CreateWindowMenu(QMenu *menu)
{ {
TMainWindow *window = windows.at(i); TMainWindow *window = windows.at(i);
QString title = window->windowTitle(); QString title = QString("%1. %2").arg(i+1).arg(window->windowTitle());
const int index = title.lastIndexOf("[*]"); const int index = title.lastIndexOf("[*]");
if (index != -1) if (index != -1)
{ {
@ -2769,7 +2782,7 @@ void TMainWindow::CreateWindowMenu(QMenu *menu)
action->setData(i); action->setData(i);
action->setCheckable(true); action->setCheckable(true);
action->setMenuRole(QAction::NoRole); action->setMenuRole(QAction::NoRole);
if (window == this) if (window->isActiveWindow())
{ {
action->setChecked(true); action->setChecked(true);
} }

View file

@ -87,6 +87,7 @@ private slots:
void AboutQt(); void AboutQt();
#if defined(Q_OS_MAC) #if defined(Q_OS_MAC)
void AboutToShowDockMenu();
void OpenAt(QAction *where); void OpenAt(QAction *where);
#endif //defined(Q_OS_MAC) #endif //defined(Q_OS_MAC)

View file

@ -172,7 +172,9 @@ MainWindow::MainWindow(QWidget *parent)
actionOpenTape->setMenuRole(QAction::NoRole); actionOpenTape->setMenuRole(QAction::NoRole);
connect(actionOpenTape, &QAction::triggered, this, &MainWindow::CreateMeasurements); connect(actionOpenTape, &QAction::triggered, this, &MainWindow::CreateMeasurements);
menu->addAction(ui->actionPreferences); QAction *actionPreferences = menu->addAction(tr("Preferences"));
actionPreferences->setMenuRole(QAction::NoRole);
connect(actionPreferences, &QAction::triggered, this, &MainWindow::Preferences);
extern void qt_mac_set_dock_menu(QMenu *); extern void qt_mac_set_dock_menu(QMenu *);
qt_mac_set_dock_menu(menu); qt_mac_set_dock_menu(menu);