From 33087b2fe8bb66d8e4c2b451646b89eb1f6fbcf5 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 3 Dec 2015 10:43:31 +0200 Subject: [PATCH] Added support Mac OS Dock Menu. --HG-- branch : develop --- src/app/tape/tmainwindow.cpp | 78 ++++++++++++++++++++++---------- src/app/tape/tmainwindow.h | 2 + src/app/valentina/mainwindow.cpp | 32 +++++++++++-- src/app/valentina/mainwindow.ui | 10 ++-- 4 files changed, 87 insertions(+), 35 deletions(-) diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 51803915a..4cf7a7f7c 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -111,7 +111,27 @@ TMainWindow::TMainWindow(QWidget *parent) #if defined(Q_OS_MAC) // On Mac deafault icon size is 32x32. ui->toolBarGradation->setIconSize(QSize(24, 24)); + +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 2) + // Mac OS Dock Menu + QMenu *menu = new QMenu(this); + + CreateWindowMenu(ui->menuWindow); + + 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 *); + qt_mac_set_dock_menu(menu); #endif +#endif //defined(Q_OS_MAC) } //--------------------------------------------------------------------------------------------------------------------- @@ -652,31 +672,7 @@ void TMainWindow::FileSaveAs() void TMainWindow::AboutToShowWindowMenu() { ui->menuWindow->clear(); - QAction *action = ui->menuWindow->addAction(tr("&New Window"), this, SLOT(NewWindow())); - action->setMenuRole(QAction::NoRole); - ui->menuWindow->addSeparator(); - - QList windows = qApp->MainWindows(); - for (int i = 0; i < windows.count(); ++i) - { - TMainWindow *window = windows.at(i); - - QString title = window->windowTitle(); - const int index = title.lastIndexOf("[*]"); - if (index != -1) - { - window->isWindowModified() ? title.replace(index, 3, "*") : title.replace(index, 3, ""); - } - - QAction *action = ui->menuWindow->addAction(title, this, SLOT(ShowWindow())); - action->setData(i); - action->setCheckable(true); - action->setMenuRole(QAction::NoRole); - if (window == this) - { - action->setChecked(true); - } - } + CreateWindowMenu(ui->menuWindow); } //--------------------------------------------------------------------------------------------------------------------- @@ -2629,6 +2625,38 @@ bool TMainWindow::LoadFromExistingFile(const QString &path) return true; } +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::CreateWindowMenu(QMenu *menu) +{ + SCASSERT(menu != nullptr); + + QAction *action = menu->addAction(tr("&New Window"), this, SLOT(NewWindow())); + action->setMenuRole(QAction::NoRole); + menu->addSeparator(); + + QList windows = qApp->MainWindows(); + for (int i = 0; i < windows.count(); ++i) + { + TMainWindow *window = windows.at(i); + + QString title = window->windowTitle(); + const int index = title.lastIndexOf("[*]"); + if (index != -1) + { + window->isWindowModified() ? title.replace(index, 3, "*") : title.replace(index, 3, ""); + } + + QAction *action = menu->addAction(title, this, SLOT(ShowWindow())); + action->setData(i); + action->setCheckable(true); + action->setMenuRole(QAction::NoRole); + if (window == this) + { + action->setChecked(true); + } + } +} + //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::SetDecimals() { diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index c7ce80b23..a9be0e379 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -193,6 +193,8 @@ private: void UpdatePatternUnit(); bool LoadFromExistingFile(const QString &path); + + void CreateWindowMenu(QMenu *menu); }; #endif // TMAINWINDOW_H diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 78a4b836c..470bff114 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -138,6 +138,11 @@ MainWindow::MainWindow(QWidget *parent) setCurrentFile(""); WindowsLocale(); + connect(ui->listWidget, &QListWidget::currentRowChanged, this, &MainWindow::ShowPaper); + ui->dockWidgetLayoutPages->setVisible(false); + + connect(watcher, &QFileSystemWatcher::fileChanged, this, &MainWindow::MeasurementsChanged); + #if defined(Q_OS_MAC) // On Mac deafault icon size is 32x32. ui->toolBarArrows->setIconSize(QSize(24, 24)); @@ -145,12 +150,29 @@ MainWindow::MainWindow(QWidget *parent) ui->toolBarOption->setIconSize(QSize(24, 24)); ui->toolBarStages->setIconSize(QSize(24, 24)); ui->toolBarTools->setIconSize(QSize(24, 24)); + +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 2) + // Mac OS Dock Menu + QMenu *menu = new QMenu(this); + + QAction *actionNewPattern = menu->addAction(tr("New pattern")); + actionNewPattern->setMenuRole(QAction::NoRole); + connect(actionNewPattern, &QAction::triggered, this, &MainWindow::New); + + QAction *actionOpenPattern = menu->addAction(tr("Open pattern")); + actionOpenPattern->setMenuRole(QAction::NoRole); + connect(actionOpenPattern, &QAction::triggered, this, &MainWindow::Open); + + QAction *actionOpenTape = menu->addAction(tr("Create/Edit measurements")); + actionOpenTape->setMenuRole(QAction::NoRole); + connect(actionOpenTape, &QAction::triggered, this, &MainWindow::CreateMeasurements); + + menu->addAction(ui->actionPreferences); + + extern void qt_mac_set_dock_menu(QMenu *); + qt_mac_set_dock_menu(menu); #endif - - connect(ui->listWidget, &QListWidget::currentRowChanged, this, &MainWindow::ShowPaper); - ui->dockWidgetLayoutPages->setVisible(false); - - connect(watcher, &QFileSystemWatcher::fileChanged, this, &MainWindow::MeasurementsChanged); +#endif //defined(Q_OS_MAC) } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/valentina/mainwindow.ui b/src/app/valentina/mainwindow.ui index e32e78f4c..2c5dd7692 100644 --- a/src/app/valentina/mainwindow.ui +++ b/src/app/valentina/mainwindow.ui @@ -375,7 +375,7 @@ 0 0 - 117 + 130 58 @@ -461,7 +461,7 @@ 0 0 - 117 + 130 156 @@ -625,7 +625,7 @@ 0 0 - 117 + 130 196 @@ -867,7 +867,7 @@ 0 0 - 117 + 130 58 @@ -2118,8 +2118,8 @@ toolButtonSplinePath - +