1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

OP-1348 Congig gadget would briefly flash next widget when replacing the currently selected widget

This commit is contained in:
Philippe Renon 2014-05-13 22:04:01 +02:00
parent 6c65b13c2b
commit 513ba37746
3 changed files with 33 additions and 40 deletions

View File

@ -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;

View File

@ -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)
{

View File

@ -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<UAVObjectUtilManager>();
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);
}