Go to the documentation of this file.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 }
00056
00057 ConsoleMaster::~ConsoleMaster()
00058 {
00059 ros_thread_.shutdown();
00060 ros_thread_.wait();
00061 }
00062
00063 void ConsoleMaster::createNewWindow()
00064 {
00065 ConsoleWindow* win = new ConsoleWindow(&db_);
00066 windows_.append(win);
00067
00068 QSettings settings;
00069 window_font_ = settings.value(SettingsKeys::FONT, QFont("Ubuntu Mono", 9)).value<QFont>();
00070 win->setFont(window_font_);
00071 QObject::connect(win, SIGNAL(createNewWindow()),
00072 this, SLOT(createNewWindow()));
00073
00074 QObject::connect(&ros_thread_, SIGNAL(connected(bool)),
00075 win, SLOT(connected(bool)));
00076
00077 QObject::connect(this,
00078 SIGNAL(fontChanged(const QFont &)),
00079 win, SLOT(setFont(const QFont &)));
00080
00081 QObject::connect(win, SIGNAL(selectFont()),
00082 this, SLOT(selectFont()));
00083
00084 QObject::connect(win, SIGNAL(readBagFile()),
00085 &bag_reader_, SLOT(promptForBagFile()));
00086
00087
00088 if (!ros_thread_.isRunning())
00089 {
00090
00091
00092
00093 QObject::connect(&ros_thread_, SIGNAL(logReceived(const rosgraph_msgs::LogConstPtr& )),
00094 &db_, SLOT(queueMessage(const rosgraph_msgs::LogConstPtr&) ));
00095
00096 QObject::connect(&ros_thread_, SIGNAL(spun()),
00097 &db_, SLOT(processQueue()));
00098
00099 ros_thread_.start();
00100 }
00101
00102 win->show();
00103 }
00104
00105 void ConsoleMaster::fontSelectionChanged(const QFont &font)
00106 {
00107 window_font_ = font;
00108 QSettings settings;
00109 settings.setValue(SettingsKeys::FONT, font);
00110 Q_EMIT fontChanged(window_font_);
00111 }
00112
00113 void ConsoleMaster::selectFont()
00114 {
00115 QFont starting_font = window_font_;
00116
00117 QFontDialog dlg(window_font_);
00118
00119 QObject::connect(&dlg, SIGNAL(currentFontChanged(const QFont &)),
00120 this, SLOT(fontSelectionChanged(const QFont &)));
00121
00122 int ret = dlg.exec();
00123
00124 if (ret == QDialog::Accepted) {
00125 if (window_font_ != dlg.selectedFont()) {
00126 window_font_ = dlg.selectedFont();
00127 Q_EMIT fontChanged(window_font_);
00128 }
00129 } else {
00130 if (window_font_ != starting_font) {
00131 window_font_ = starting_font;
00132 Q_EMIT fontChanged(window_font_);
00133 }
00134 }
00135 }
00136 }