36 #include <QFontDialog> 51 config_widget_(new QWidget()),
63 p.setColor(QPalette::Background, Qt::white);
67 QPalette p3(
ui_.status->palette());
68 p3.setColor(QPalette::Text, Qt::red);
69 ui_.status->setPalette(p3);
71 QObject::connect(
ui_.selecttopic, SIGNAL(clicked()),
this, SLOT(
SelectTopic()));
72 QObject::connect(
ui_.topic, SIGNAL(editingFinished()),
this, SLOT(
TopicEdited()));
73 QObject::connect(
ui_.anchor, SIGNAL(activated(QString)),
this, SLOT(
SetAnchor(QString)));
74 QObject::connect(
ui_.units, SIGNAL(activated(QString)),
this, SLOT(
SetUnits(QString)));
75 QObject::connect(
ui_.offsetx, SIGNAL(valueChanged(
int)),
this, SLOT(
SetOffsetX(
int)));
76 QObject::connect(
ui_.offsety, SIGNAL(valueChanged(
int)),
this, SLOT(
SetOffsetY(
int)));
77 QObject::connect(
ui_.font_button, SIGNAL(clicked()),
this, SLOT(
SelectFont()));
78 QObject::connect(
ui_.color, SIGNAL(colorEdited(
const QColor &)),
this, SLOT(
SelectColor()));
80 font_.setFamily(tr(
"Helvetica"));
82 ui_.font_button->setText(
font_.family());
107 painter->resetTransform();
108 painter->setFont(
font_);
119 QPen invisPen(QBrush(Qt::transparent), 1);
120 painter->setPen(invisPen);
124 QPen pen(QBrush(
color_), 1);
125 painter->setPen(pen);
145 y_offset =
static_cast<int>((float)(
offset_y_ *
canvas_->height()) / 100.0);
148 int right =
static_cast<int>((float)
canvas_->width() -
message_.size().width()) - x_offset;
149 int bottom =
static_cast<int>((float)
canvas_->height() -
message_.size().height()) - y_offset;
150 int yCenter =
static_cast<int>((float)
canvas_->height() / 2.0 -
message_.size().height()/2.0);
151 int xCenter =
static_cast<int>((float)
canvas_->width() / 2.0 -
message_.size().width()/2.0);
158 ulPoint.setX(x_offset);
159 ulPoint.setY(y_offset);
162 ulPoint.setX(xCenter);
163 ulPoint.setY(y_offset);
167 ulPoint.setY(y_offset);
170 ulPoint.setX(x_offset);
171 ulPoint.setY(yCenter);
174 ulPoint.setX(xCenter);
175 ulPoint.setY(yCenter);
179 ulPoint.setY(yCenter);
182 ulPoint.setX(x_offset);
183 ulPoint.setY(bottom);
186 ulPoint.setX(xCenter);
187 ulPoint.setY(bottom);
191 ulPoint.setY(bottom);
194 painter->drawStaticText(ulPoint,
message_);
201 ui_.topic->setText(QString(node[TOPIC_KEY].as<std::string>().c_str()));
207 font_.fromString(QString(node[FONT_KEY].as<std::string>().c_str()));
209 ui_.font_button->setText(
font_.family());
214 color_ = QColor(node[COLOR_KEY].as<std::string>().c_str());
215 ui_.color->setColor(QColor(
color_.name().toStdString().c_str()));
220 std::string anchor = node[
ANCHOR_KEY].as<std::string>();
221 ui_.anchor->setCurrentIndex(
ui_.anchor->findText(anchor.c_str()));
227 std::string units = node[
UNITS_KEY].as<std::string>();
228 ui_.units->setCurrentIndex(
ui_.units->findText(units.c_str()));
247 emitter << YAML::Key <<
FONT_KEY << YAML::Value <<
font_.toString().toStdString();
248 emitter << YAML::Key <<
COLOR_KEY << YAML::Value <<
color_.name().toStdString();
249 emitter << YAML::Key <<
TOPIC_KEY << YAML::Value <<
ui_.topic->text().toStdString();
291 ui_.font_button->setText(
font_.family());
298 "std_msgs/String",
"marti_common_msgs/StringStamped");
300 if (!topic.
name.empty())
302 ui_.topic->setText(QString::fromStdString(topic.
name));
309 std::string topic =
ui_.topic->text().trimmed().toStdString();
323 ROS_INFO(
"Subscribing to %s", topic_.c_str());
330 if (anchor ==
"top left")
334 else if (anchor ==
"top center")
338 else if (anchor ==
"top right")
342 else if (anchor ==
"center left")
346 else if (anchor ==
"center")
350 else if (anchor ==
"center right")
354 else if (anchor ==
"bottom left")
358 else if (anchor ==
"bottom center")
362 else if (anchor ==
"bottom right")
370 if (units ==
"pixels")
374 else if (units ==
"percent")
390 template <
class T,
class M>
393 return msg->getDataType() == ros::message_traits::datatype<T>();
398 if (is_instance<std_msgs::String>(msg))
400 message_.setText(QString(msg->instantiate<std_msgs::String>()->data.c_str()));
402 else if (is_instance<marti_common_msgs::StringStamped>(msg))
404 message_.setText(QString(msg->instantiate<marti_common_msgs::StringStamped>()->value.c_str()));
416 std::string anchor_string =
"top left";
420 anchor_string =
"top left";
424 anchor_string =
"top center";
428 anchor_string =
"top right";
432 anchor_string =
"center left";
434 else if (anchor ==
CENTER)
436 anchor_string =
"center";
440 anchor_string =
"center right";
444 anchor_string =
"bottom left";
448 anchor_string =
"bottom center";
452 anchor_string =
"bottom right";
455 return anchor_string;
460 std::string units_string =
"pixels";
464 units_string =
"pixels";
468 units_string =
"percent";
QWidget * GetConfigWidget(QWidget *parent)
static ros::master::TopicInfo selectTopic(const std::string &datatype, QWidget *parent=0)
void PrintInfo(const std::string &message)
void stringCallback(const topic_tools::ShapeShifter::ConstPtr &msg)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void PrintError(const std::string &message)
static const char * COLOR_KEY
std::string AnchorToString(Anchor anchor)
static void PrintWarningHelper(QLabel *status_label, const std::string &message, double throttle=0.0)
static void PrintErrorHelper(QLabel *status_label, const std::string &message, double throttle=0.0)
bool Initialize(QGLWidget *canvas)
ros::Subscriber string_sub_
void SaveConfig(YAML::Emitter &emitter, const std::string &path)
static void PrintInfoHelper(QLabel *status_label, const std::string &message, double throttle=0.0)
static const char * ANCHOR_KEY
static const char * TOPIC_KEY
void PaintText(QPainter *painter)
void SetOffsetY(int offset)
void SetUnits(QString units)
void Paint(QPainter *painter, double x, double y, double scale)
static const char * FONT_KEY
static const char * UNITS_KEY
static const char * OFFSET_Y_KEY
void Draw(double x, double y, double scale)
void LoadConfig(const YAML::Node &node, const std::string &path)
std::string UnitsToString(Units units)
static const char * OFFSET_X_KEY
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
void SetAnchor(QString anchor)
void PrintWarning(const std::string &message)
bool is_instance(const M &msg)
void SetOffsetX(int offset)