From 513ba37746ee254920bd703b299f5aef36d352bc Mon Sep 17 00:00:00 2001 From: Philippe Renon Date: Tue, 13 May 2014 22:04:01 +0200 Subject: [PATCH] OP-1348 Congig gadget would briefly flash next widget when replacing the currently selected widget --- .../src/libs/utils/mytabbedstackwidget.cpp | 22 +++++++- .../src/libs/utils/mytabbedstackwidget.h | 1 + .../src/plugins/config/configgadgetwidget.cpp | 50 ++++--------------- 3 files changed, 33 insertions(+), 40 deletions(-) diff --git a/ground/openpilotgcs/src/libs/utils/mytabbedstackwidget.cpp b/ground/openpilotgcs/src/libs/utils/mytabbedstackwidget.cpp index 2626ca47b..ed1bd75ae 100644 --- a/ground/openpilotgcs/src/libs/utils/mytabbedstackwidget.cpp +++ b/ground/openpilotgcs/src/libs/utils/mytabbedstackwidget.cpp @@ -83,12 +83,31 @@ MyTabbedStackWidget::MyTabbedStackWidget(QWidget *parent, bool isVertical, bool void MyTabbedStackWidget::insertTab(const int index, QWidget *tab, const QIcon &icon, const QString &label) { tab->setContentsMargins(0, 0, 0, 0); - m_stackWidget->insertWidget(index, tab); + + // create and insert item QListWidgetItem *item = new QListWidgetItem(icon, label); item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); item->setTextAlignment(Qt::AlignHCenter | Qt::AlignBottom); item->setToolTip(label); m_listWidget->insertItem(index, item); + + // insert widget + m_stackWidget->insertWidget(index, tab); +} + +void MyTabbedStackWidget::replaceTab(int index, QWidget *tab) +{ + QWidget *wid = m_stackWidget->widget(index); + + // insert new widget + m_stackWidget->insertWidget(index, tab); + if (index == currentIndex()) { + // currently selected tab is being replaced so select the new tab before removing the old one + m_stackWidget->setCurrentWidget(tab); + } + // remove and delete old widget + m_stackWidget->removeWidget(wid); + delete wid; } void MyTabbedStackWidget::removeTab(int index) @@ -97,6 +116,7 @@ void MyTabbedStackWidget::removeTab(int index) m_stackWidget->removeWidget(wid); delete wid; + QListWidgetItem *item = m_listWidget->item(index); m_listWidget->removeItemWidget(item); delete item; diff --git a/ground/openpilotgcs/src/libs/utils/mytabbedstackwidget.h b/ground/openpilotgcs/src/libs/utils/mytabbedstackwidget.h index 661200383..169eca9ba 100644 --- a/ground/openpilotgcs/src/libs/utils/mytabbedstackwidget.h +++ b/ground/openpilotgcs/src/libs/utils/mytabbedstackwidget.h @@ -40,6 +40,7 @@ public: MyTabbedStackWidget(QWidget *parent = 0, bool isVertical = false, bool iconAbove = true); void insertTab(int index, QWidget *tab, const QIcon &icon, const QString &label); + void replaceTab(int index, QWidget *tab); void removeTab(int index); void setIconSize(int size) { diff --git a/ground/openpilotgcs/src/plugins/config/configgadgetwidget.cpp b/ground/openpilotgcs/src/plugins/config/configgadgetwidget.cpp index 4ae81eb08..368037842 100644 --- a/ground/openpilotgcs/src/plugins/config/configgadgetwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configgadgetwidget.cpp @@ -166,24 +166,11 @@ void ConfigGadgetWidget::resizeEvent(QResizeEvent *event) void ConfigGadgetWidget::onAutopilotDisconnect() { - int selectedIndex = ftw->currentIndex(); - - QIcon *icon = new QIcon(); - - icon->addFile(":/configgadget/images/ins_normal.png", QSize(), QIcon::Normal, QIcon::Off); - icon->addFile(":/configgadget/images/ins_selected.png", QSize(), QIcon::Selected, QIcon::Off); QWidget *qwd = new DefaultAttitudeWidget(this); - ftw->removeTab(ConfigGadgetWidget::sensors); - ftw->insertTab(ConfigGadgetWidget::sensors, qwd, *icon, QString("Attitude")); + ftw->replaceTab(ConfigGadgetWidget::sensors, qwd); - icon = new QIcon(); - icon->addFile(":/configgadget/images/hardware_normal.png", QSize(), QIcon::Normal, QIcon::Off); - icon->addFile(":/configgadget/images/hardware_selected.png", QSize(), QIcon::Selected, QIcon::Off); qwd = new DefaultHwSettingsWidget(this); - ftw->removeTab(ConfigGadgetWidget::hardware); - ftw->insertTab(ConfigGadgetWidget::hardware, qwd, *icon, QString("Hardware")); - - ftw->setCurrentIndex(selectedIndex); + ftw->replaceTab(ConfigGadgetWidget::hardware, qwd); emit autopilotDisconnected(); } @@ -196,45 +183,26 @@ void ConfigGadgetWidget::onAutopilotConnect() ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); UAVObjectUtilManager *utilMngr = pm->getObject(); if (utilMngr) { - int selectedIndex = ftw->currentIndex(); int board = utilMngr->getBoardModel(); if ((board & 0xff00) == 1024) { // CopterControl family - QIcon *icon = new QIcon(); - icon->addFile(":/configgadget/images/ins_normal.png", QSize(), QIcon::Normal, QIcon::Off); - icon->addFile(":/configgadget/images/ins_selected.png", QSize(), QIcon::Selected, QIcon::Off); QWidget *qwd = new ConfigCCAttitudeWidget(this); - ftw->removeTab(ConfigGadgetWidget::sensors); - ftw->insertTab(ConfigGadgetWidget::sensors, qwd, *icon, QString("Attitude")); + ftw->replaceTab(ConfigGadgetWidget::sensors, qwd); - icon = new QIcon(); - icon->addFile(":/configgadget/images/hardware_normal.png", QSize(), QIcon::Normal, QIcon::Off); - icon->addFile(":/configgadget/images/hardware_selected.png", QSize(), QIcon::Selected, QIcon::Off); qwd = new ConfigCCHWWidget(this); - ftw->removeTab(ConfigGadgetWidget::hardware); - ftw->insertTab(ConfigGadgetWidget::hardware, qwd, *icon, QString("Hardware")); + ftw->replaceTab(ConfigGadgetWidget::hardware, qwd); } else if ((board & 0xff00) == 0x0900) { // Revolution family - - QIcon *icon = new QIcon(); - icon->addFile(":/configgadget/images/ins_normal.png", QSize(), QIcon::Normal, QIcon::Off); - icon->addFile(":/configgadget/images/ins_selected.png", QSize(), QIcon::Selected, QIcon::Off); QWidget *qwd = new ConfigRevoWidget(this); - ftw->removeTab(ConfigGadgetWidget::sensors); - ftw->insertTab(ConfigGadgetWidget::sensors, qwd, *icon, QString("Attitude")); + ftw->replaceTab(ConfigGadgetWidget::sensors, qwd); - icon = new QIcon(); - icon->addFile(":/configgadget/images/hardware_normal.png", QSize(), QIcon::Normal, QIcon::Off); - icon->addFile(":/configgadget/images/hardware_selected.png", QSize(), QIcon::Selected, QIcon::Off); qwd = new ConfigRevoHWWidget(this); - ftw->removeTab(ConfigGadgetWidget::hardware); - ftw->insertTab(ConfigGadgetWidget::hardware, qwd, *icon, QString("Hardware")); + ftw->replaceTab(ConfigGadgetWidget::hardware, qwd); } else { // Unknown board qDebug() << "Unknown board " << board; } - ftw->setCurrentIndex(selectedIndex); } emit autopilotConnected(); @@ -284,6 +252,10 @@ void ConfigGadgetWidget::onOPLinkDisconnect() { qDebug() << "ConfigGadgetWidget onOPLinkDisconnect"; oplinkTimeout->stop(); - ftw->removeTab(ConfigGadgetWidget::oplink); oplinkConnected = false; + + if (ftw->currentIndex() == ConfigGadgetWidget::oplink) { + ftw->setCurrentIndex(0); + } + ftw->removeTab(ConfigGadgetWidget::oplink); }