mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-29 14:52:12 +01:00
OP-1348 Congig gadget would briefly flash next widget when replacing the currently selected widget
This commit is contained in:
parent
6c65b13c2b
commit
513ba37746
@ -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)
|
void MyTabbedStackWidget::insertTab(const int index, QWidget *tab, const QIcon &icon, const QString &label)
|
||||||
{
|
{
|
||||||
tab->setContentsMargins(0, 0, 0, 0);
|
tab->setContentsMargins(0, 0, 0, 0);
|
||||||
m_stackWidget->insertWidget(index, tab);
|
|
||||||
|
// create and insert item
|
||||||
QListWidgetItem *item = new QListWidgetItem(icon, label);
|
QListWidgetItem *item = new QListWidgetItem(icon, label);
|
||||||
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
||||||
item->setTextAlignment(Qt::AlignHCenter | Qt::AlignBottom);
|
item->setTextAlignment(Qt::AlignHCenter | Qt::AlignBottom);
|
||||||
item->setToolTip(label);
|
item->setToolTip(label);
|
||||||
m_listWidget->insertItem(index, item);
|
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)
|
void MyTabbedStackWidget::removeTab(int index)
|
||||||
@ -97,6 +116,7 @@ void MyTabbedStackWidget::removeTab(int index)
|
|||||||
|
|
||||||
m_stackWidget->removeWidget(wid);
|
m_stackWidget->removeWidget(wid);
|
||||||
delete wid;
|
delete wid;
|
||||||
|
|
||||||
QListWidgetItem *item = m_listWidget->item(index);
|
QListWidgetItem *item = m_listWidget->item(index);
|
||||||
m_listWidget->removeItemWidget(item);
|
m_listWidget->removeItemWidget(item);
|
||||||
delete item;
|
delete item;
|
||||||
|
@ -40,6 +40,7 @@ public:
|
|||||||
MyTabbedStackWidget(QWidget *parent = 0, bool isVertical = false, bool iconAbove = true);
|
MyTabbedStackWidget(QWidget *parent = 0, bool isVertical = false, bool iconAbove = true);
|
||||||
|
|
||||||
void insertTab(int index, QWidget *tab, const QIcon &icon, const QString &label);
|
void insertTab(int index, QWidget *tab, const QIcon &icon, const QString &label);
|
||||||
|
void replaceTab(int index, QWidget *tab);
|
||||||
void removeTab(int index);
|
void removeTab(int index);
|
||||||
void setIconSize(int size)
|
void setIconSize(int size)
|
||||||
{
|
{
|
||||||
|
@ -166,24 +166,11 @@ void ConfigGadgetWidget::resizeEvent(QResizeEvent *event)
|
|||||||
|
|
||||||
void ConfigGadgetWidget::onAutopilotDisconnect()
|
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);
|
QWidget *qwd = new DefaultAttitudeWidget(this);
|
||||||
ftw->removeTab(ConfigGadgetWidget::sensors);
|
ftw->replaceTab(ConfigGadgetWidget::sensors, qwd);
|
||||||
ftw->insertTab(ConfigGadgetWidget::sensors, qwd, *icon, QString("Attitude"));
|
|
||||||
|
|
||||||
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);
|
qwd = new DefaultHwSettingsWidget(this);
|
||||||
ftw->removeTab(ConfigGadgetWidget::hardware);
|
ftw->replaceTab(ConfigGadgetWidget::hardware, qwd);
|
||||||
ftw->insertTab(ConfigGadgetWidget::hardware, qwd, *icon, QString("Hardware"));
|
|
||||||
|
|
||||||
ftw->setCurrentIndex(selectedIndex);
|
|
||||||
|
|
||||||
emit autopilotDisconnected();
|
emit autopilotDisconnected();
|
||||||
}
|
}
|
||||||
@ -196,45 +183,26 @@ void ConfigGadgetWidget::onAutopilotConnect()
|
|||||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||||
UAVObjectUtilManager *utilMngr = pm->getObject<UAVObjectUtilManager>();
|
UAVObjectUtilManager *utilMngr = pm->getObject<UAVObjectUtilManager>();
|
||||||
if (utilMngr) {
|
if (utilMngr) {
|
||||||
int selectedIndex = ftw->currentIndex();
|
|
||||||
int board = utilMngr->getBoardModel();
|
int board = utilMngr->getBoardModel();
|
||||||
if ((board & 0xff00) == 1024) {
|
if ((board & 0xff00) == 1024) {
|
||||||
// CopterControl family
|
// 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);
|
QWidget *qwd = new ConfigCCAttitudeWidget(this);
|
||||||
ftw->removeTab(ConfigGadgetWidget::sensors);
|
ftw->replaceTab(ConfigGadgetWidget::sensors, qwd);
|
||||||
ftw->insertTab(ConfigGadgetWidget::sensors, qwd, *icon, QString("Attitude"));
|
|
||||||
|
|
||||||
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);
|
qwd = new ConfigCCHWWidget(this);
|
||||||
ftw->removeTab(ConfigGadgetWidget::hardware);
|
ftw->replaceTab(ConfigGadgetWidget::hardware, qwd);
|
||||||
ftw->insertTab(ConfigGadgetWidget::hardware, qwd, *icon, QString("Hardware"));
|
|
||||||
} else if ((board & 0xff00) == 0x0900) {
|
} else if ((board & 0xff00) == 0x0900) {
|
||||||
// Revolution family
|
// 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);
|
QWidget *qwd = new ConfigRevoWidget(this);
|
||||||
ftw->removeTab(ConfigGadgetWidget::sensors);
|
ftw->replaceTab(ConfigGadgetWidget::sensors, qwd);
|
||||||
ftw->insertTab(ConfigGadgetWidget::sensors, qwd, *icon, QString("Attitude"));
|
|
||||||
|
|
||||||
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);
|
qwd = new ConfigRevoHWWidget(this);
|
||||||
ftw->removeTab(ConfigGadgetWidget::hardware);
|
ftw->replaceTab(ConfigGadgetWidget::hardware, qwd);
|
||||||
ftw->insertTab(ConfigGadgetWidget::hardware, qwd, *icon, QString("Hardware"));
|
|
||||||
} else {
|
} else {
|
||||||
// Unknown board
|
// Unknown board
|
||||||
qDebug() << "Unknown board " << board;
|
qDebug() << "Unknown board " << board;
|
||||||
}
|
}
|
||||||
ftw->setCurrentIndex(selectedIndex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
emit autopilotConnected();
|
emit autopilotConnected();
|
||||||
@ -284,6 +252,10 @@ void ConfigGadgetWidget::onOPLinkDisconnect()
|
|||||||
{
|
{
|
||||||
qDebug() << "ConfigGadgetWidget onOPLinkDisconnect";
|
qDebug() << "ConfigGadgetWidget onOPLinkDisconnect";
|
||||||
oplinkTimeout->stop();
|
oplinkTimeout->stop();
|
||||||
ftw->removeTab(ConfigGadgetWidget::oplink);
|
|
||||||
oplinkConnected = false;
|
oplinkConnected = false;
|
||||||
|
|
||||||
|
if (ftw->currentIndex() == ConfigGadgetWidget::oplink) {
|
||||||
|
ftw->setCurrentIndex(0);
|
||||||
|
}
|
||||||
|
ftw->removeTab(ConfigGadgetWidget::oplink);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user