32 #include <boost/filesystem.hpp> 36 #include <QPixmapCache> 42 boost::filesystem::path
getPath( QString url )
44 boost::filesystem::path path;
46 if ( url.indexOf(
"package://", 0, Qt::CaseInsensitive) == 0 )
48 QString package_name = url.section(
'/',2,2);
49 QString file_name = url.section(
'/',3);
51 path = path / file_name.toStdString();
53 else if ( url.indexOf(
"file://", 0, Qt::CaseInsensitive) == 0 )
55 path = url.section(
'/',2).toStdString();
59 ROS_ERROR(
"Invalid or unsupported URL: '%s'", url.toStdString().c_str() );
71 if ( QPixmapCache::find( url, &pixmap ) )
76 boost::filesystem::path path =
getPath( url );
80 if ( boost::filesystem::exists( path ) )
82 ROS_DEBUG_NAMED(
"load_resource",
"Loading '%s'", path.string().c_str() );
83 if ( !pixmap.load( QString::fromStdString( path.string() ) ) )
85 ROS_ERROR(
"Could not load pixmap '%s'", path.string().c_str() );
91 QPixmapCache::insert( url, pixmap );
99 return QCursor(Qt::ArrowCursor);
105 if (icon.width() == 0 || icon.height() == 0)
107 ROS_ERROR(
"Could not load pixmap '%s' -- using default cursor instead.", url.toStdString().c_str() );
110 QString cache_key = url +
".cursor";
118 if ( QPixmapCache::find( cache_key, &cursor_img ) )
120 return QCursor( cursor_img, 0, 0 );
123 QPixmap base_cursor =
loadPixmap(
"package://rviz/icons/cursor.svg", fill_cache );
125 const int cursor_size = 32;
127 cursor_img = QPixmap( cursor_size, cursor_size );
128 cursor_img.fill( QColor(0,0,0,0) );
131 QPainter painter(&cursor_img);
137 if( draw_x+icon.width() > cursor_size )
139 draw_x = cursor_size-icon.width();
141 if( draw_y+icon.height() > cursor_size )
143 draw_y = cursor_size-icon.height();
146 painter.drawPixmap( 0, 0, base_cursor );
147 painter.drawPixmap( draw_x, draw_y, icon );
151 QPixmapCache::insert( cache_key, cursor_img );
154 return QCursor( cursor_img, 1, 1 );
boost::filesystem::path getPath(QString url)
QCursor makeIconCursor(QString url, bool fill_cache)
#define ROS_DEBUG_NAMED(name,...)
QCursor getDefaultCursor(bool fill_cache)
ROSLIB_DECL std::string getPath(const std::string &package_name)
QPixmap loadPixmap(QString url, bool fill_cache)