main_window.cpp
Go to the documentation of this file.
00001 
00008 /*****************************************************************************
00009 ** Includes
00010 *****************************************************************************/
00011 
00012 #include <QtGui>
00013 #include <QMessageBox>
00014 #include <iostream>
00015 #include "../include/segbot_controller/main_window.hpp"
00016 
00017 /*****************************************************************************
00018 ** Namespaces
00019 *****************************************************************************/
00020 
00021 namespace segbot_controller {
00022 
00023 using namespace Qt;
00024 
00025 /*****************************************************************************
00026 ** Implementation [MainWindow]
00027 *****************************************************************************/
00028 
00029 MainWindow::MainWindow(int argc, char** argv, QWidget *parent)
00030         : QMainWindow(parent)
00031         , qnode(argc,argv)
00032 {
00033         ui.setupUi(this); // Calling this incidentally connects all ui's triggers to on_...() callbacks in this class.
00034     QObject::connect(ui.actionAbout_Qt, SIGNAL(triggered(bool)), qApp, SLOT(aboutQt())); // qApp is a global variable for the application
00035 
00036     ReadSettings();
00037         setWindowIcon(QIcon(":/images/icon.png"));
00038         ui.tab_manager->setCurrentIndex(0); // ensure the first tab is showing - qt-designer should have this already hardwired, but often loses it (settings?).
00039     QObject::connect(&qnode, SIGNAL(rosShutdown()), this, SLOT(close()));
00040 
00041         /*********************
00042         ** Logging
00043         **********************/
00044         ui.view_logging->setModel(qnode.loggingModel());
00045     QObject::connect(&qnode, SIGNAL(loggingUpdated()), this, SLOT(updateLoggingView()));
00046 
00047     /*********************
00048     ** Auto Start
00049     **********************/
00050     if ( ui.checkbox_remember_settings->isChecked() ) {
00051         on_button_connect_clicked(true);
00052     }
00053 }
00054 
00055 MainWindow::~MainWindow() {}
00056 
00057 /*****************************************************************************
00058 ** Implementation [Slots]
00059 *****************************************************************************/
00060 
00061 void MainWindow::showNoMasterMessage() {
00062         QMessageBox msgBox;
00063         msgBox.setText("Couldn't find the ros master.");
00064         msgBox.exec();
00065     close();
00066 }
00067 
00068 /*
00069  * These triggers whenever the button is clicked, regardless of whether it
00070  * is already checked or not.
00071  */
00072 
00073 void MainWindow::on_button_connect_clicked(bool check ) {
00074         if ( ui.checkbox_use_environment->isChecked() ) {
00075                 if ( !qnode.init() ) {
00076                         showNoMasterMessage();
00077                 } else {
00078                         ui.button_connect->setEnabled(false);
00079                 }
00080         } else {
00081                 if ( ! qnode.init(ui.line_edit_master->text().toStdString(),
00082                                    ui.line_edit_host->text().toStdString()) ) {
00083                         showNoMasterMessage();
00084                 } else {
00085                         ui.button_connect->setEnabled(false);
00086                         ui.line_edit_master->setReadOnly(true);
00087                         ui.line_edit_host->setReadOnly(true);
00088                         ui.line_edit_topic->setReadOnly(true);
00089                 }
00090         }
00091 }
00092 
00093 
00094 void MainWindow::on_checkbox_use_environment_stateChanged(int state) {
00095         bool enabled;
00096         if ( state == 0 ) {
00097                 enabled = true;
00098         } else {
00099                 enabled = false;
00100         }
00101         ui.line_edit_master->setEnabled(enabled);
00102         ui.line_edit_host->setEnabled(enabled);
00103         //ui.line_edit_topic->setEnabled(enabled);
00104 }
00105 
00106 /*****************************************************************************
00107 ** Implemenation [Slots][manually connected]
00108 *****************************************************************************/
00109 
00115 void MainWindow::updateLoggingView() {
00116         ui.view_logging->scrollToBottom();
00117 }
00118 
00119 /*****************************************************************************
00120 ** Implementation [Menu]
00121 *****************************************************************************/
00122 
00123 void MainWindow::on_actionAbout_triggered() {
00124     QMessageBox::about(this, tr("About ..."),tr("<h2>PACKAGE_NAME Test Program 0.10</h2><p>Copyright Yujin Robot</p><p>This package needs an about description.</p>"));
00125 }
00126 
00127 /*****************************************************************************
00128 ** Implementation [Configuration]
00129 *****************************************************************************/
00130 
00131 void MainWindow::ReadSettings() {
00132     QSettings settings("Qt-Ros Package", "segbot_controller");
00133     restoreGeometry(settings.value("geometry").toByteArray());
00134     restoreState(settings.value("windowState").toByteArray());
00135     QString master_url = settings.value("master_url",QString("http://192.168.1.2:11311/")).toString();
00136     QString host_url = settings.value("host_url", QString("192.168.1.3")).toString();
00137     //QString topic_name = settings.value("topic_name", QString("/chatter")).toString();
00138     ui.line_edit_master->setText(master_url);
00139     ui.line_edit_host->setText(host_url);
00140     //ui.line_edit_topic->setText(topic_name);
00141     bool remember = settings.value("remember_settings", false).toBool();
00142     ui.checkbox_remember_settings->setChecked(remember);
00143     bool checked = settings.value("use_environment_variables", false).toBool();
00144     ui.checkbox_use_environment->setChecked(checked);
00145     if ( checked ) {
00146         ui.line_edit_master->setEnabled(false);
00147         ui.line_edit_host->setEnabled(false);
00148         //ui.line_edit_topic->setEnabled(false);
00149     }
00150 }
00151 
00152 void MainWindow::WriteSettings() {
00153     QSettings settings("Qt-Ros Package", "segbot_controller");
00154     settings.setValue("master_url",ui.line_edit_master->text());
00155     settings.setValue("host_url",ui.line_edit_host->text());
00156     //settings.setValue("topic_name",ui.line_edit_topic->text());
00157     settings.setValue("use_environment_variables",QVariant(ui.checkbox_use_environment->isChecked()));
00158     settings.setValue("geometry", saveGeometry());
00159     settings.setValue("windowState", saveState());
00160     settings.setValue("remember_settings",QVariant(ui.checkbox_remember_settings->isChecked()));
00161 
00162 }
00163 
00164 void MainWindow::closeEvent(QCloseEvent *event)
00165 {
00166         WriteSettings();
00167         QMainWindow::closeEvent(event);
00168 }
00169 
00170 }  // namespace segbot_controller
00171 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends


segbot_controller
Author(s): lab
autogenerated on Sun Mar 24 2013 17:17:27