Go to the documentation of this file.00001
00008
00009
00010
00011
00012 #include <QtGui>
00013 #include <QMessageBox>
00014 #include <iostream>
00015 #include "main_window.hpp"
00016
00017 using namespace Qt;
00018
00019
00020
00021
00022
00023 MainWindow::MainWindow(QNode *node, QWidget *parent) :
00024 QMainWindow(parent),
00025 qnode(node)
00026 {
00027 ui.setupUi(this);
00028 QObject::connect(ui.actionAbout_Qt, SIGNAL(triggered(bool)), qApp, SLOT(aboutQt()));
00029
00030 ReadSettings();
00031 setWindowIcon(QIcon(":/images/icon.png"));
00032 ui.tab_manager->setCurrentIndex(0);
00033
00034 setWindowTitle(QApplication::translate("MainWindowDesign", qnode->nodeName().c_str(), 0, QApplication::UnicodeUTF8));
00035
00036
00037
00038
00039 ui.view_logging->setModel(qnode->loggingModel());
00040 QObject::connect(qnode, SIGNAL(loggingUpdated()), this, SLOT(updateLoggingView()));
00041 QObject::connect(qnode, SIGNAL(rosShutdown()), this, SLOT(close()));
00042
00043
00044
00045
00046 if ( ui.checkbox_remember_settings->isChecked() ) {
00047 on_button_connect_clicked(true);
00048 }
00049 }
00050
00051 MainWindow::~MainWindow() {}
00052
00053
00054
00055
00056
00057 void MainWindow::showNoMasterMessage() {
00058 QMessageBox msgBox;
00059 msgBox.setText("Couldn't find the ros master.");
00060 msgBox.exec();
00061 close();
00062 }
00063
00064
00065
00066
00067
00068
00069 void MainWindow::on_button_connect_clicked(bool check ) {
00070 if ( ui.checkbox_use_environment->isChecked() ) {
00071 if ( !qnode->on_init() ) {
00072 showNoMasterMessage();
00073 } else {
00074 ui.button_connect->setEnabled(false);
00075 }
00076 } else {
00077 if ( ! qnode->on_init(
00078 ui.line_edit_master->text().toStdString(),
00079 ui.line_edit_host->text().toStdString() )
00080 ) {
00081 showNoMasterMessage();
00082 } else {
00083 ui.button_connect->setEnabled(false);
00084 ui.line_edit_master->setReadOnly(true);
00085 ui.line_edit_host->setReadOnly(true);
00086 }
00087 }
00088 }
00089
00090 void MainWindow::on_checkbox_use_environment_stateChanged(int state) {
00091 bool enabled;
00092 if ( state == 0 ) {
00093 enabled = true;
00094 } else {
00095 enabled = false;
00096 }
00097 ui.line_edit_master->setEnabled(enabled);
00098 ui.line_edit_host->setEnabled(enabled);
00099 }
00100
00101
00102
00103
00104
00110 void MainWindow::updateLoggingView() {
00111 ui.view_logging->scrollToBottom();
00112 }
00113
00114
00115
00116
00117
00118 void MainWindow::on_actionAbout_triggered() {
00119 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>"));
00120 }
00121
00122
00123
00124
00125
00126 void MainWindow::ReadSettings() {
00127 QSettings settings("Qt-Ros Package", qnode->nodeName().c_str());
00128 restoreGeometry(settings.value("geometry").toByteArray());
00129 restoreState(settings.value("windowState").toByteArray());
00130 QString master_url = settings.value("master_url",QString("http://192.168.1.2:11311/")).toString();
00131 QString host_url = settings.value("host_url", QString("192.168.1.3")).toString();
00132 QString topic_name = settings.value("topic_name", QString("/chatter")).toString();
00133 ui.line_edit_master->setText(master_url);
00134 ui.line_edit_host->setText(host_url);
00135 bool remember = settings.value("remember_settings", false).toBool();
00136 ui.checkbox_remember_settings->setChecked(remember);
00137 bool checked = settings.value("use_environment_variables", false).toBool();
00138 ui.checkbox_use_environment->setChecked(checked);
00139 if ( checked ) {
00140 ui.line_edit_master->setEnabled(false);
00141 ui.line_edit_host->setEnabled(false);
00142 }
00143 }
00144
00145 void MainWindow::WriteSettings() {
00146 QSettings settings("Qt-Ros Package", qnode->nodeName().c_str());
00147 settings.setValue("geometry", geometry());
00148 settings.setValue("master_url",ui.line_edit_master->text());
00149 settings.setValue("host_url",ui.line_edit_host->text());
00150 settings.setValue("use_environment_variables",QVariant(ui.checkbox_use_environment->isChecked()));
00151 settings.setValue("windowState", saveState());
00152 settings.setValue("remember_settings",QVariant(ui.checkbox_remember_settings->isChecked()));
00153 }
00154
00155 void MainWindow::closeEvent(QCloseEvent *event)
00156 {
00157 qnode->shutdown();
00158 WriteSettings();
00159 QMainWindow::closeEvent(event);
00160 }