From 7160a6c111da64083066459fde6db4af8d925674 Mon Sep 17 00:00:00 2001 From: Mariano Lizarraga Date: Fri, 23 Jul 2010 19:22:29 -0500 Subject: [PATCH] Major cleanup of MainWindow constructor. All widgets have now the visible property set to false on its constructor --- src/main.cc | 2 +- src/ui/DebugConsole.cc | 2 + src/ui/HDDisplay.cc | 2 + src/ui/HSIDisplay.cc | 1 + src/ui/HUD.cc | 2 + src/ui/MainWindow.cc | 172 +++++++++++++++-------------- src/ui/MainWindow.h | 5 + src/ui/MapWidget.cc | 2 + src/ui/ObjectDetectionView.cc | 2 + src/ui/ParameterInterface.cc | 1 + src/ui/WaypointList.cc | 2 + src/ui/XMLCommProtocolWidget.cc | 2 + src/ui/linechart/Linecharts.cc | 1 + src/ui/uas/UASInfoWidget.cc | 2 + src/ui/uas/UASListWidget.cc | 2 + src/ui/watchdog/WatchdogControl.cc | 2 + 16 files changed, 118 insertions(+), 84 deletions(-) diff --git a/src/main.cc b/src/main.cc index dbb457cb0..7db249d83 100644 --- a/src/main.cc +++ b/src/main.cc @@ -36,7 +36,7 @@ This file is part of the PIXHAWK project /* SDL does ugly things to main() */ #ifdef main -# undef main + #undef main #endif /** diff --git a/src/ui/DebugConsole.cc b/src/ui/DebugConsole.cc index 598f7b63f..2a0199ced 100644 --- a/src/ui/DebugConsole.cc +++ b/src/ui/DebugConsole.cc @@ -101,6 +101,8 @@ DebugConsole::DebugConsole(QWidget *parent) : connect(m_ui->holdCheckBox, SIGNAL(clicked(bool)), this, SLOT(setAutoHold(bool))); // Connect hold button connect(m_ui->holdButton, SIGNAL(toggled(bool)), this, SLOT(hold(bool))); + + this->setVisible(false); } DebugConsole::~DebugConsole() diff --git a/src/ui/HDDisplay.cc b/src/ui/HDDisplay.cc index 0b7574fb9..dd996b640 100644 --- a/src/ui/HDDisplay.cc +++ b/src/ui/HDDisplay.cc @@ -100,6 +100,8 @@ HDDisplay::HDDisplay(QStringList* plotList, QWidget *parent) : // Connect with UAS connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), this, SLOT(setActiveUAS(UASInterface*))); //start(); + + this->setVisible(false); } HDDisplay::~HDDisplay() diff --git a/src/ui/HSIDisplay.cc b/src/ui/HSIDisplay.cc index b025febf3..9123aafc7 100644 --- a/src/ui/HSIDisplay.cc +++ b/src/ui/HSIDisplay.cc @@ -100,6 +100,7 @@ HSIDisplay::HSIDisplay(QWidget *parent) : xCenterPos = vwidth/2.0f; yCenterPos = vheight/2.0f + topMargin - bottomMargin; + this->setVisible(false); } void HSIDisplay::paintEvent(QPaintEvent * event) diff --git a/src/ui/HUD.cc b/src/ui/HUD.cc index 11ce1208d..dfd986470 100644 --- a/src/ui/HUD.cc +++ b/src/ui/HUD.cc @@ -153,6 +153,8 @@ HUD::HUD(int width, int height, QWidget* parent) // Connect with UAS UASManager* manager = UASManager::instance(); connect(manager, SIGNAL(activeUASSet(UASInterface*)), this, SLOT(setActiveUAS(UASInterface*))); + + this->setVisible(false); } HUD::~HUD() diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index e94b180a9..198c6e098 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -62,94 +62,23 @@ This file is part of the QGROUNDCONTROL project * * @see QMainWindow::show() **/ -MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), -settings() +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + settings() { this->hide(); this->setVisible(false); - mavlink = new MAVLinkProtocol(); - // Setup user interface ui.setupUi(this); - // Initialize views, NOT show them yet, only initialize model and controller - centerStack = new QStackedWidget(this); - linechart = new Linecharts(this); - linechart->setActive(false); - connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)), linechart, SLOT(addSystem(UASInterface*))); - connect(UASManager::instance(), SIGNAL(activeUASSet(int)), linechart, SLOT(selectSystem(int))); - centerStack->addWidget(linechart); - control = new UASControlWidget(this); - //controlDock = new QDockWidget(this); - //controlDock->setWidget(control); - list = new UASListWidget(this); - list->setVisible(false); - waypoints = new WaypointList(this, NULL); - waypoints->setVisible(false); - info = new UASInfoWidget(this); - info->setVisible(false); - detection = new ObjectDetectionView("patterns", this); - detection->setVisible(false); - hud = new HUD(640, 480, this); - hud->setVisible(false); - debugConsole = new DebugConsole(this); - debugConsole->setVisible(false); - map = new MapWidget(this); - map->setVisible(false); - protocol = new XMLCommProtocolWidget(this); - protocol->setVisible(false); - centerStack->addWidget(protocol); - parameters = new ParameterInterface(this); - parameters->setVisible(false); - watchdogControl = new WatchdogControl(this); - watchdogControl->setVisible(false); - hsi = new HSIDisplay(this); - hsi->setVisible(false); - - QStringList* acceptList = new QStringList(); - acceptList->append("roll IMU"); - acceptList->append("pitch IMU"); - acceptList->append("yaw IMU"); - acceptList->append("rollspeed IMU"); - acceptList->append("pitchspeed IMU"); - acceptList->append("yawspeed IMU"); - headDown1 = new HDDisplay(acceptList, this); - headDown1->setVisible(false); - - QStringList* acceptList2 = new QStringList(); - acceptList2->append("Battery"); - acceptList2->append("Pressure"); - headDown2 = new HDDisplay(acceptList2, this); - headDown2->setVisible(false); - centerStack->addWidget(map); - centerStack->addWidget(hud); - setCentralWidget(centerStack); - - // Get IPs - QList hostAddresses = QNetworkInterface::allAddresses(); - - QString windowname = qApp->applicationName() + " " + qApp->applicationVersion(); - - windowname.append(" (" + QHostInfo::localHostName() + ": "); - bool prevAddr = false; - for (int i = 0; i < hostAddresses.size(); i++) - { - // Exclude loopback IPv4 and all IPv6 addresses - if (hostAddresses.at(i) != QHostAddress("127.0.0.1") && !hostAddresses.at(i).toString().contains(":")) - { - if(prevAddr) windowname.append("/"); - windowname.append(hostAddresses.at(i).toString()); - prevAddr = true; - } - } + buildWidgets(); - windowname.append(")"); + connectWidgets(); - setWindowTitle(windowname); -#ifndef Q_WS_MAC - //qApp->setWindowIcon(QIcon(":/core/images/qtcreator_logo_128.png")); -#endif + arrangeCenterStack(); + + configureWindowName(); // Add status bar setStatusBar(createStatusBar()); @@ -157,10 +86,10 @@ settings() // Set the application style (not the same as a style sheet) // Set the style to Plastique qApp->setStyle("plastique"); + // Set style sheet as last step reloadStylesheet(); - joystick = new JoystickInput(); // Create actions connectActions(); @@ -170,9 +99,6 @@ settings() // Adjust the size adjustSize(); - - // - connect(mavlink, SIGNAL(receiveLossChanged(int, float)), info, SLOT(updateSendLoss(int, float))); } MainWindow::~MainWindow() @@ -181,6 +107,86 @@ MainWindow::~MainWindow() statusBar = NULL; } + +void MainWindow::buildWidgets() +{ + QStringList* acceptList = new QStringList(); + acceptList->append("roll IMU"); + acceptList->append("pitch IMU"); + acceptList->append("yaw IMU"); + acceptList->append("rollspeed IMU"); + acceptList->append("pitchspeed IMU"); + acceptList->append("yawspeed IMU"); + + QStringList* acceptList2 = new QStringList(); + acceptList2->append("Battery"); + acceptList2->append("Pressure"); + + + mavlink = new MAVLinkProtocol(); + linechart = new Linecharts(this); + control = new UASControlWidget(this); + list = new UASListWidget(this); + waypoints = new WaypointList(this, NULL); + info = new UASInfoWidget(this); + detection = new ObjectDetectionView("patterns", this); + hud = new HUD(640, 480, this); + debugConsole= new DebugConsole(this); + map = new MapWidget(this); + protocol = new XMLCommProtocolWidget(this); + parameters = new ParameterInterface(this); + watchdogControl = new WatchdogControl(this); + hsi = new HSIDisplay(this); + headDown1 = new HDDisplay(acceptList, this); + headDown2 = new HDDisplay(acceptList2, this); + joystick = new JoystickInput(); +} + +void MainWindow::connectWidgets(){ + connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)), linechart, SLOT(addSystem(UASInterface*))); + connect(UASManager::instance(), SIGNAL(activeUASSet(int)), linechart, SLOT(selectSystem(int))); + connect(mavlink, SIGNAL(receiveLossChanged(int, float)), info, SLOT(updateSendLoss(int, float))); +} + +void MainWindow::arrangeCenterStack(){ + + centerStack = new QStackedWidget(this); + + centerStack->addWidget(linechart); + centerStack->addWidget(protocol); + centerStack->addWidget(map); + centerStack->addWidget(hud); + + setCentralWidget(centerStack); +} + +void MainWindow::configureWindowName(){ + QList hostAddresses = QNetworkInterface::allAddresses(); + QString windowname = qApp->applicationName() + " " + qApp->applicationVersion(); + bool prevAddr = false; + + windowname.append(" (" + QHostInfo::localHostName() + ": "); + + for (int i = 0; i < hostAddresses.size(); i++) + { + // Exclude loopback IPv4 and all IPv6 addresses + if (hostAddresses.at(i) != QHostAddress("127.0.0.1") && !hostAddresses.at(i).toString().contains(":")) + { + if(prevAddr) windowname.append("/"); + windowname.append(hostAddresses.at(i).toString()); + prevAddr = true; + } + } + + windowname.append(")"); + + setWindowTitle(windowname); + +#ifndef Q_WS_MAC + //qApp->setWindowIcon(QIcon(":/core/images/qtcreator_logo_128.png")); +#endif +} + QStatusBar* MainWindow::createStatusBar() { QStatusBar* bar = new QStatusBar(); diff --git a/src/ui/MainWindow.h b/src/ui/MainWindow.h index 4576384f7..d611fe095 100644 --- a/src/ui/MainWindow.h +++ b/src/ui/MainWindow.h @@ -129,6 +129,10 @@ protected: void loadWidgets(); void connectActions(); void clearView(); + void buildWidgets(); + void connectWidgets(); + void arrangeCenterStack(); + void configureWindowName(); // TODO Should be moved elsewhere, as the protocol does not belong to the UI MAVLinkProtocol* mavlink; @@ -178,6 +182,7 @@ protected: private: Ui::MainWindow ui; + }; #endif /* _MAINWINDOW_H_ */ diff --git a/src/ui/MapWidget.cc b/src/ui/MapWidget.cc index d73b7b181..df6e8fd8b 100644 --- a/src/ui/MapWidget.cc +++ b/src/ui/MapWidget.cc @@ -107,6 +107,8 @@ MapWidget::MapWidget(QWidget *parent) : mc->setZoom(3); connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)), this, SLOT(addUAS(UASInterface*))); + + this->setVisible(false); } MapWidget::~MapWidget() diff --git a/src/ui/ObjectDetectionView.cc b/src/ui/ObjectDetectionView.cc index 68e9f3c2e..f5a80e804 100644 --- a/src/ui/ObjectDetectionView.cc +++ b/src/ui/ObjectDetectionView.cc @@ -57,6 +57,8 @@ ObjectDetectionView::ObjectDetectionView(QString folder, QWidget *parent) : letterTimer.start(1000); connect(&letterTimer, SIGNAL(timeout()), this, SLOT(decreaseLetterTime())); connect(m_ui->clearButton, SIGNAL(clicked()), this, SLOT(clearLists())); + + this->setVisible(false); } ObjectDetectionView::~ObjectDetectionView() diff --git a/src/ui/ParameterInterface.cc b/src/ui/ParameterInterface.cc index 777034f4d..33a63c740 100644 --- a/src/ui/ParameterInterface.cc +++ b/src/ui/ParameterInterface.cc @@ -23,6 +23,7 @@ ParameterInterface::ParameterInterface(QWidget *parent) : // Setup MAV connections connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)), this, SLOT(addUAS(UASInterface*))); + this->setVisible(false); } ParameterInterface::~ParameterInterface() diff --git a/src/ui/WaypointList.cc b/src/ui/WaypointList.cc index 6c3828f09..48297575e 100644 --- a/src/ui/WaypointList.cc +++ b/src/ui/WaypointList.cc @@ -84,6 +84,8 @@ WaypointList::WaypointList(QWidget *parent, UASInterface* uas) : // STATUS LABEL updateStatusLabel(""); + + this->setVisible(false); } WaypointList::~WaypointList() diff --git a/src/ui/XMLCommProtocolWidget.cc b/src/ui/XMLCommProtocolWidget.cc index 907cd0fd6..582c74ac6 100644 --- a/src/ui/XMLCommProtocolWidget.cc +++ b/src/ui/XMLCommProtocolWidget.cc @@ -24,6 +24,8 @@ XMLCommProtocolWidget::XMLCommProtocolWidget(QWidget *parent) : connect(m_ui->selectOutputButton, SIGNAL(clicked()), this, SLOT(selectOutputDirectory())); connect(m_ui->generateButton, SIGNAL(clicked()), this, SLOT(generate())); connect(m_ui->saveButton, SIGNAL(clicked()), this, SLOT(save())); + + this->setVisible(false); } void XMLCommProtocolWidget::selectXMLFile() diff --git a/src/ui/linechart/Linecharts.cc b/src/ui/linechart/Linecharts.cc index fa88d9d2f..d904a1973 100644 --- a/src/ui/linechart/Linecharts.cc +++ b/src/ui/linechart/Linecharts.cc @@ -5,6 +5,7 @@ Linecharts::Linecharts(QWidget *parent) : plots(), active(true) { + this->setVisible(false); } diff --git a/src/ui/uas/UASInfoWidget.cc b/src/ui/uas/UASInfoWidget.cc index c835c5f64..08f176cd4 100644 --- a/src/ui/uas/UASInfoWidget.cc +++ b/src/ui/uas/UASInfoWidget.cc @@ -75,6 +75,8 @@ UASInfoWidget::UASInfoWidget(QWidget *parent, QString name) : QWidget(parent) connect(updateTimer, SIGNAL(timeout()), this, SLOT(refresh())); updateTimer->start(50); + this->setVisible(false); + } UASInfoWidget::~UASInfoWidget() diff --git a/src/ui/uas/UASListWidget.cc b/src/ui/uas/UASListWidget.cc index 7369341e2..e4fb0026f 100644 --- a/src/ui/uas/UASListWidget.cc +++ b/src/ui/uas/UASListWidget.cc @@ -51,6 +51,8 @@ UASListWidget::UASListWidget(QWidget *parent) : QWidget(parent), m_ui(new Ui::UA this->setMinimumWidth(250); uasViews = QMap(); + + this->setVisible(false); } UASListWidget::~UASListWidget() diff --git a/src/ui/watchdog/WatchdogControl.cc b/src/ui/watchdog/WatchdogControl.cc index 572ecb8d8..50cde8fed 100644 --- a/src/ui/watchdog/WatchdogControl.cc +++ b/src/ui/watchdog/WatchdogControl.cc @@ -24,6 +24,8 @@ WatchdogControl::WatchdogControl(QWidget *parent) : ui->mainWidget->setLayout(listLayout); connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)), this, SLOT(setUAS(UASInterface*))); + + this->setVisible(false); } WatchdogControl::~WatchdogControl() -- 2.22.0