| 1974 | |
| 1975 | |
| 1976 | void WizMainWindow::initToolBarPluginButtons() |
| 1977 | { |
| 1978 | JSPluginManager &jsPluginMgr = JSPluginManager::instance(); |
| 1979 | |
| 1980 | auto menus = jsPluginMgr.modulesByModuleType("Menu"); |
| 1981 | foreach (auto menuData, menus) { |
| 1982 | if (menuData->spec()->buttonLocation() != "Main") |
| 1983 | continue; |
| 1984 | auto btn = new QToolButton(this); |
| 1985 | btn->setPopupMode(QToolButton::MenuButtonPopup); |
| 1986 | QMenu *m = new QMenu(btn); |
| 1987 | foreach (int i, menuData->spec()->actionIndexes()) { |
| 1988 | auto parent = menuData->parentPlugin(); |
| 1989 | auto acm = parent->module(i); |
| 1990 | QAction *ac = jsPluginMgr.createPluginAction(btn, acm); |
| 1991 | m->addAction(ac); |
| 1992 | connect(ac, &QAction::triggered, this, |
| 1993 | [this, btn, ac] (bool checked) { |
| 1994 | QRect rc = btn->rect(); |
| 1995 | QPoint pt = btn->mapToGlobal(QPoint(rc.width()/2, rc.height())); |
| 1996 | Q_EMIT pluginPopupRequest(ac, pt); |
| 1997 | } |
| 1998 | ); |
| 1999 | } |
| 2000 | |
| 2001 | btn->setMenu(m); |
| 2002 | auto acs = m->actions(); |
| 2003 | if (!acs.isEmpty()) { |
| 2004 | btn->setDefaultAction(acs.first()); |
| 2005 | m_toolBar->addWidget(btn); |
| 2006 | setHitTestVisible(btn); |
| 2007 | } |
| 2008 | } |
| 2009 | |
| 2010 | QList<JSPluginModule *> modules = jsPluginMgr.modulesByKeyValue("ModuleType", "Action"); |
| 2011 | for (auto moduleData : modules) { |
| 2012 | if (moduleData->spec()->buttonLocation() != "Main") |
| 2013 | continue; |
| 2014 | QAction *ac = jsPluginMgr.createPluginAction(m_toolBar, moduleData); |
| 2015 | connect(ac, &QAction::triggered, |
| 2016 | &jsPluginMgr, &JSPluginManager::handlePluginActionTriggered); |
| 2017 | |
| 2018 | m_toolBar->addAction(ac); |
| 2019 | |
| 2020 | setHitTestVisible(m_toolBar->widgetForAction(ac)); |
| 2021 | } |
| 2022 | |
| 2023 | connect(this, &WizMainWindow::pluginPopupRequest, |
| 2024 | &jsPluginMgr, &JSPluginManager::handlePluginPopupRequest); |
| 2025 | } |
| 2026 | |
| 2027 | /** |
| 2028 | * @brief 初始化客户端主体区域<目录树, 笔记列表, 文档页面> |
nothing calls this directly
no test coverage detected