36 #include <QFontDialog> 42 const char* StringPlugin::COLOR_KEY =
"color";
43 const char* StringPlugin::FONT_KEY =
"font";
44 const char* StringPlugin::TOPIC_KEY =
"topic";
45 const char* StringPlugin::ANCHOR_KEY =
"anchor";
46 const char* StringPlugin::UNITS_KEY =
"units";
47 const char* StringPlugin::OFFSET_X_KEY =
"offset_x";
48 const char* StringPlugin::OFFSET_Y_KEY =
"offset_y";
50 StringPlugin::StringPlugin() :
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());
300 if (!topic.
name.empty())
302 ui_.topic->setText(QString::fromStdString(topic.
name));
309 std::string topic =
ui_.topic->text().trimmed().toStdString();
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")
392 message_.setText(QString(str->data.c_str()));
402 std::string anchor_string =
"top left";
406 anchor_string =
"top left";
410 anchor_string =
"top center";
414 anchor_string =
"top right";
418 anchor_string =
"center left";
420 else if (anchor ==
CENTER)
422 anchor_string =
"center";
426 anchor_string =
"center right";
430 anchor_string =
"bottom left";
434 anchor_string =
"bottom center";
438 anchor_string =
"bottom right";
441 return anchor_string;
446 std::string units_string =
"pixels";
450 units_string =
"pixels";
454 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)
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 stringCallback(const std_msgs::StringConstPtr &str)
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)
void SetOffsetX(int offset)