void ConfigStabilizationWidget::setupStabBanksGUI() { StabilizationSettings *stabSettings = qobject_cast<StabilizationSettings *>(getObject("StabilizationSettings")); Q_ASSERT(stabSettings); m_stabSettingsBankCount = stabSettings->getField("FlightModeMap")->getOptions().count(); // Set up fake tab widget stuff for pid banks support m_stabTabBars.append(ui->basicPIDBankTabBar); m_stabTabBars.append(ui->advancedPIDBankTabBar); QAction *defaultStabMenuAction = new QAction(QIcon(":configgadget/images/gear.png"), QString(), this); QAction *restoreAllAction = new QAction(tr("all to saved"), this); connect(restoreAllAction, SIGNAL(triggered()), this, SLOT(restoreAllStabBanks())); QAction *resetAllAction = new QAction(tr("all to default"), this); connect(resetAllAction, SIGNAL(triggered()), this, SLOT(resetAllStabBanks())); QAction *restoreCurrentAction = new QAction(tr("to saved"), this); connect(restoreCurrentAction, SIGNAL(triggered()), this, SLOT(restoreCurrentAction())); QAction *resetCurrentAction = new QAction(tr("to default"), this); connect(resetCurrentAction, SIGNAL(triggered()), this, SLOT(resetCurrentStabBank())); QAction *copyCurrentAction = new QAction(tr("to others"), this); connect(copyCurrentAction, SIGNAL(triggered()), this, SLOT(copyCurrentStabBank())); connect(&m_stabSettingsCopyFromSignalMapper, SIGNAL(mapped(int)), this, SLOT(copyFromBankToCurrent(int))); connect(&m_stabSettingsCopyToSignalMapper, SIGNAL(mapped(int)), this, SLOT(copyToBankFromCurrent(int))); connect(&m_stabSettingsSwapSignalMapper, SIGNAL(mapped(int)), this, SLOT(swapBankAndCurrent(int))); foreach(QTabBar * tabBar, m_stabTabBars) { for (int i = 0; i < m_stabSettingsBankCount; i++) { tabBar->addTab(tr("Settings Bank %1").arg(i + 1)); tabBar->setTabData(i, QString("StabilizationSettingsBank%1").arg(i + 1)); QToolButton *tabButton = new QToolButton(); connect(this, SIGNAL(enableControlsChanged(bool)), tabButton, SLOT(setEnabled(bool))); tabButton->setDefaultAction(defaultStabMenuAction); tabButton->setAutoRaise(true); tabButton->setPopupMode(QToolButton::InstantPopup); tabButton->setToolTip(tr("The functions in this menu effect all fields in the settings banks,\n" "not only the ones visible on screen.")); QMenu *tabMenu = new QMenu(); QMenu *restoreMenu = new QMenu(tr("Restore")); QMenu *resetMenu = new QMenu(tr("Reset")); QMenu *copyMenu = new QMenu(tr("Copy")); QMenu *swapMenu = new QMenu(tr("Swap")); QAction *menuAction; for (int j = 0; j < m_stabSettingsBankCount; j++) { if (j == i) { restoreMenu->addAction(restoreCurrentAction); resetMenu->addAction(resetCurrentAction); copyMenu->addAction(copyCurrentAction); } else { menuAction = new QAction(tr("from %1").arg(j + 1), this); connect(menuAction, SIGNAL(triggered()), &m_stabSettingsCopyFromSignalMapper, SLOT(map())); m_stabSettingsCopyFromSignalMapper.setMapping(menuAction, j); copyMenu->addAction(menuAction); menuAction = new QAction(tr("to %1").arg(j + 1), this); connect(menuAction, SIGNAL(triggered()), &m_stabSettingsCopyToSignalMapper, SLOT(map())); m_stabSettingsCopyToSignalMapper.setMapping(menuAction, j); copyMenu->addAction(menuAction); menuAction = new QAction(tr("with %1").arg(j + 1), this); connect(menuAction, SIGNAL(triggered()), &m_stabSettingsSwapSignalMapper, SLOT(map())); m_stabSettingsSwapSignalMapper.setMapping(menuAction, j); swapMenu->addAction(menuAction); } } restoreMenu->addAction(restoreAllAction); resetMenu->addAction(resetAllAction); tabMenu->addMenu(copyMenu); tabMenu->addMenu(swapMenu); tabMenu->addMenu(resetMenu); tabMenu->addMenu(restoreMenu); tabButton->setMenu(tabMenu); tabBar->setTabButton(i, QTabBar::RightSide, tabButton); } tabBar->setExpanding(false); connect(tabBar, SIGNAL(currentChanged(int)), this, SLOT(stabBankChanged(int))); } for (int i = 0; i < m_stabSettingsBankCount; i++) { if (i > 0) { m_stabilizationObjectsString.append(","); } m_stabilizationObjectsString.append(m_stabTabBars.at(0)->tabData(i).toString()); } }