Added support Mac OS Dock Menu.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2015-12-03 10:43:31 +02:00
parent 61eec32420
commit 33087b2fe8
4 changed files with 87 additions and 35 deletions

View File

@ -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<TMainWindow*> 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<TMainWindow*> 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()
{

View File

@ -193,6 +193,8 @@ private:
void UpdatePatternUnit();
bool LoadFromExistingFile(const QString &path);
void CreateWindowMenu(QMenu *menu);
};
#endif // TMAINWINDOW_H

View File

@ -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)
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -375,7 +375,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>117</width>
<width>130</width>
<height>58</height>
</rect>
</property>
@ -461,7 +461,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>117</width>
<width>130</width>
<height>156</height>
</rect>
</property>
@ -625,7 +625,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>117</width>
<width>130</width>
<height>196</height>
</rect>
</property>
@ -867,7 +867,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>117</width>
<width>130</width>
<height>58</height>
</rect>
</property>
@ -2118,8 +2118,8 @@
<tabstop>toolButtonSplinePath</tabstop>
</tabstops>
<resources>
<include location="../../libs/vmisc/share/resources/icon.qrc"/>
<include location="share/resources/toolicon.qrc"/>
<include location="../../libs/vmisc/share/resources/icon.qrc"/>
</resources>
<connections/>
</ui>