Go to the documentation of this file.00001
00008
00009
00010
00011
00012 #include <QtGui>
00013 #include <QMessageBox>
00014 #include <iostream>
00015 #include "../include/%(package)s/main_window.hpp"
00016
00017
00018
00019
00020
00021 namespace %(package)s {
00022
00023 using namespace Qt;
00024
00025
00026
00027
00028
00029 MainWindow::MainWindow(int argc, char** argv, QWidget *parent)
00030 : QMainWindow(parent)
00031 , qnode(argc,argv)
00032 {
00033 ui.setupUi(this);
00034 QObject::connect(ui.actionAbout_Qt, SIGNAL(triggered(bool)), qApp, SLOT(aboutQt()));
00035
00036 ReadSettings();
00037 setWindowIcon(QIcon(":/images/icon.png"));
00038 ui.tab_manager->setCurrentIndex(0);
00039 QObject::connect(&qnode, SIGNAL(rosShutdown()), this, SLOT(close()));
00040
00041
00042
00043
00044 ui.view_logging->setModel(qnode.loggingModel());
00045 QObject::connect(&qnode, SIGNAL(loggingUpdated()), this, SLOT(updateLoggingView()));
00046
00047
00048
00049
00050 if ( ui.checkbox_remember_settings->isChecked() ) {
00051 on_button_connect_clicked(true);
00052 }
00053 }
00054
00055 MainWindow::~MainWindow() {}
00056
00057
00058
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
00070
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
00104 }
00105
00106
00107
00108
00109
00115 void MainWindow::updateLoggingView() {
00116 ui.view_logging->scrollToBottom();
00117 }
00118
00119
00120
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
00129
00130
00131 void MainWindow::ReadSettings() {
00132 QSettings settings("Qt-Ros Package", "%(package)s");
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
00138 ui.line_edit_master->setText(master_url);
00139 ui.line_edit_host->setText(host_url);
00140
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
00149 }
00150 }
00151
00152 void MainWindow::WriteSettings() {
00153 QSettings settings("Qt-Ros Package", "%(package)s");
00154 settings.setValue("master_url",ui.line_edit_master->text());
00155 settings.setValue("host_url",ui.line_edit_host->text());
00156
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 }
00171