32 #include <boost/filesystem.hpp> 36 #include <QPixmapCache> 41 boost::filesystem::path
getPath(QString url)
43 boost::filesystem::path path;
45 if (url.indexOf(
"package://", 0, Qt::CaseInsensitive) == 0)
47 QString package_name = url.section(
'/', 2, 2);
48 QString file_name = url.section(
'/', 3);
50 path = path / file_name.toStdString();
52 else if (url.indexOf(
"file://", 0, Qt::CaseInsensitive) == 0)
54 path = url.section(
'/', 2).toStdString();
58 ROS_ERROR(
"Invalid or unsupported URL: '%s'", url.toStdString().c_str());
70 if (QPixmapCache::find(url, &pixmap))
75 boost::filesystem::path path =
getPath(url);
79 if (boost::filesystem::exists(path))
81 ROS_DEBUG_NAMED(
"load_resource",
"Loading '%s'", path.string().c_str());
82 if (!pixmap.load(QString::fromStdString(path.string())))
84 ROS_ERROR(
"Could not load pixmap '%s'", path.string().c_str());
90 QPixmapCache::insert(url, pixmap);
98 return QCursor(Qt::ArrowCursor);
104 if (icon.width() == 0 || icon.height() == 0)
106 ROS_ERROR(
"Could not load pixmap '%s' -- using default cursor instead.", url.toStdString().c_str());
109 QString cache_key = url +
".cursor";
117 if (QPixmapCache::find(cache_key, &cursor_img))
119 return QCursor(cursor_img, 0, 0);
122 QPixmap base_cursor =
loadPixmap(
"package://rviz/icons/cursor.svg", fill_cache);
124 const int cursor_size = 32;
126 cursor_img = QPixmap(cursor_size, cursor_size);
127 cursor_img.fill(QColor(0, 0, 0, 0));
130 QPainter painter(&cursor_img);
136 if (draw_x + icon.width() > cursor_size)
138 draw_x = cursor_size - icon.width();
140 if (draw_y + icon.height() > cursor_size)
142 draw_y = cursor_size - icon.height();
145 painter.drawPixmap(0, 0, base_cursor);
146 painter.drawPixmap(draw_x, draw_y, icon);
150 QPixmapCache::insert(cache_key, cursor_img);
153 return QCursor(cursor_img, 1, 1);
boost::filesystem::path getPath(QString url)
QCursor makeIconCursor(QString url, bool fill_cache)
QCursor getDefaultCursor(bool)
#define ROS_DEBUG_NAMED(name,...)
ROSLIB_DECL std::string getPath(const std::string &package_name)
QPixmap loadPixmap(QString url, bool fill_cache)