00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include <swri_console/console_master.h>
00032 #include <swri_console/console_window.h>
00033 #include <swri_console/settings_keys.h>
00034
00035 #include <QFontDialog>
00036 #include <QSettings>
00037
00038 namespace swri_console
00039 {
00040 ConsoleMaster::ConsoleMaster(int argc, char** argv):
00041 ros_thread_(argc, argv),
00042 connected_(false),
00043 window_font_(QFont("Ubuntu Mono", 9))
00044 {
00045
00046
00047
00048
00049 qRegisterMetaType<rosgraph_msgs::LogConstPtr>("rosgraph_msgs::LogConstPtr");
00050
00051 QObject::connect(&bag_reader_, SIGNAL(logReceived(const rosgraph_msgs::LogConstPtr& )),
00052 &db_, SLOT(queueMessage(const rosgraph_msgs::LogConstPtr&) ));
00053 QObject::connect(&bag_reader_, SIGNAL(finishedReading()),
00054 &db_, SLOT(processQueue()));
00055 QObject::connect(&log_reader_, SIGNAL(logReceived(const rosgraph_msgs::LogConstPtr& )),
00056 &db_, SLOT(queueMessage(const rosgraph_msgs::LogConstPtr&) ));
00057 QObject::connect(&log_reader_, SIGNAL(finishedReading()),
00058 &db_, SLOT(processQueue()));
00059 }
00060
00061 ConsoleMaster::~ConsoleMaster()
00062 {
00063 ros_thread_.shutdown();
00064 ros_thread_.wait();
00065 }
00066
00067 void ConsoleMaster::createNewWindow()
00068 {
00069 ConsoleWindow* win = new ConsoleWindow(&db_);
00070 windows_.append(win);
00071
00072 QSettings settings;
00073 window_font_ = settings.value(SettingsKeys::FONT, QFont("Ubuntu Mono", 9)).value<QFont>();
00074 win->setFont(window_font_);
00075 QObject::connect(win, SIGNAL(createNewWindow()),
00076 this, SLOT(createNewWindow()));
00077
00078 QObject::connect(&ros_thread_, SIGNAL(connected(bool)),
00079 win, SLOT(connected(bool)));
00080
00081 QObject::connect(this,
00082 SIGNAL(fontChanged(const QFont &)),
00083 win, SLOT(setFont(const QFont &)));
00084
00085 QObject::connect(win, SIGNAL(selectFont()),
00086 this, SLOT(selectFont()));
00087
00088 QObject::connect(win, SIGNAL(readBagFile()),
00089 &bag_reader_, SLOT(promptForBagFile()));
00090
00091 QObject::connect(win, SIGNAL(readLogFile()),
00092 &log_reader_, SLOT(promptForLogFile()));
00093
00094 QObject::connect(win, SIGNAL(readLogDirectory()),
00095 &log_reader_, SLOT(promptForLogDirectory()));
00096
00097
00098 if (!ros_thread_.isRunning())
00099 {
00100
00101
00102
00103 QObject::connect(&ros_thread_, SIGNAL(logReceived(const rosgraph_msgs::LogConstPtr& )),
00104 &db_, SLOT(queueMessage(const rosgraph_msgs::LogConstPtr&) ));
00105
00106 QObject::connect(&ros_thread_, SIGNAL(spun()),
00107 &db_, SLOT(processQueue()));
00108
00109 ros_thread_.start();
00110 }
00111
00112 win->show();
00113 }
00114
00115 void ConsoleMaster::fontSelectionChanged(const QFont &font)
00116 {
00117 window_font_ = font;
00118 QSettings settings;
00119 settings.setValue(SettingsKeys::FONT, font);
00120 Q_EMIT fontChanged(window_font_);
00121 }
00122
00123 void ConsoleMaster::selectFont()
00124 {
00125 QFont starting_font = window_font_;
00126
00127 QFontDialog dlg(window_font_);
00128
00129 QObject::connect(&dlg, SIGNAL(currentFontChanged(const QFont &)),
00130 this, SLOT(fontSelectionChanged(const QFont &)));
00131
00132 int ret = dlg.exec();
00133
00134 if (ret == QDialog::Accepted) {
00135 if (window_font_ != dlg.selectedFont()) {
00136 window_font_ = dlg.selectedFont();
00137 Q_EMIT fontChanged(window_font_);
00138 }
00139 } else {
00140 if (window_font_ != starting_font) {
00141 window_font_ = starting_font;
00142 Q_EMIT fontChanged(window_font_);
00143 }
00144 }
00145 }
00146 }