1 #ifndef RADIAL_MENU_RVIZ_HORIZONTAL_IMAGE_DRAWER_HPP 2 #define RADIAL_MENU_RVIZ_HORIZONTAL_IMAGE_DRAWER_HPP 16 #include <QFontMetrics> 46 std::vector< ElementType > element_types;
47 std::vector< QRect > bg_rects, fg_rects;
48 std::vector< radial_menu_model::ItemConstPtr > items;
49 imageLayout(&image_size, &element_types, &bg_rects, &fg_rects, &items);
53 QPainter painter(&image);
55 painter.setRenderHint(QPainter::TextAntialiasing);
56 painter.setRenderHint(QPainter::Antialiasing);
57 for (std::size_t i = 0; i < element_types.size(); ++i) {
58 switch (element_types[i]) {
73 << static_cast< int >(element_types[i]) <<
"). Will not draw.");
87 void imageLayout(QSize *
const image_size, std::vector< ElementType > *
const element_types,
88 std::vector< QRect > *
const bg_rects, std::vector< QRect > *
const fg_rects,
89 std::vector< radial_menu_model::ItemConstPtr > *
const items)
const {
90 element_types->clear();
102 QRect bg_rect, fg_rect;
104 if (bg_rect.isValid() && fg_rect.isValid()) {
106 bg_rects->push_back(bg_rect);
107 fg_rects->push_back(fg_rect);
108 items->push_back(item);
114 QRect bg_rect, fg_rect;
116 if (bg_rect.isValid() && fg_rect.isValid()) {
118 bg_rects->push_back(bg_rect);
119 fg_rects->push_back(fg_rect);
120 items->push_back(item);
128 QRect bg_rect, fg_rect;
130 if (bg_rect.isValid() && fg_rect.isValid()) {
131 element_types->push_back(PointedElement);
132 bg_rects->push_back(bg_rect);
133 fg_rects->push_back(fg_rect);
134 items->push_back(item);
146 for (
const QRect &bg_rect : *bg_rects) {
147 united_rect |= bg_rect;
149 for (QRect &bg_rect : *bg_rects) {
150 bg_rect.setHeight(united_rect.height());
155 for (std::size_t i = 1; i < bg_rects->size(); ++i) {
156 (*bg_rects)[i].moveLeft((*bg_rects)[i - 1].right() +
prop_.
line_width);
160 for (std::size_t i = 0; i < bg_rects->size(); ++i) {
161 (*fg_rects)[i].moveCenter((*bg_rects)[i].center());
168 image_size->setWidth(bg_rects->empty() ? 0 : bg_rects->back().right());
169 image_size->setHeight(bg_rects->empty() ? 0 : bg_rects->back().bottom());
176 QRect *
const fg_rect)
const {
178 switch (item->displayType()) {
193 << item->name() <<
"' has unexpected type (" 194 <<
static_cast< int >(item->displayType()) <<
")");
195 fg_rect->setHeight(1);
196 fg_rect->setWidth(1);
204 bg_rect->translate(-bg_rect->topLeft());
205 fg_rect->moveCenter(bg_rect->center());
208 static int textWidth(
const QFont &font,
const QString &text) {
209 return QFontMetrics(font).boundingRect(QRect(), Qt::AlignCenter, text).width();
213 return QMargins(margin, margin, margin, margin);
218 void drawBackground(QPainter *
const painter,
const QRgb &rgb,
const QRect &rect)
const {
220 painter->setPen(color);
221 painter->setBrush(color);
222 painter->drawRect(rect);
228 switch (item->displayType()) {
230 painter->drawText(rect, Qt::AlignCenter, QString::fromStdString(item->name()));
233 painter->drawText(rect, Qt::AlignCenter, QString::fromStdString(item->altTxt()));
241 << item->name() <<
"' has unexpected type (" 242 <<
static_cast< int >(item->displayType()) <<
")");
247 static QColor
makeColor(
const QRgb &rgb,
const int alpha) {
250 color.setAlpha(alpha);
#define ROS_ERROR_STREAM(args)
QPixmap loadPixmap(QString url, bool fill_cache)