1 /** 2 * QtAwesome - use font-awesome (or other font icons) in your c++ / Qt Application 3 * 4 * Copyright 2013 - Reliable Bits Software by Blommers IT. All Rights Reserved. 5 * Author Rick Blommers 6 */ 7 8 #ifndef QTAWESOME_H 9 #define QTAWESOME_H 10 11 #include <QIcon> 12 #include <QIconEngine> 13 #include <QPainter> 14 #include <QRect> 15 #include <QVariantMap> 16 17 18 /// A list of all icon-names with the codepoint (unicode-value) on the right 19 /// You can use the names on the page http://fortawesome.github.io/Font-Awesome/design.html ( replace every dash '-' with an underscore '_') 20 enum QtFontAwesomeName { 21 icon_glass = 0xf000, 22 icon_music = 0xf001, 23 icon_search = 0xf002, 24 icon_envelope = 0xf003, 25 icon_heart = 0xf004, 26 icon_star = 0xf005, 27 icon_star_empty = 0xf006, 28 icon_user = 0xf007, 29 icon_film = 0xf008, 30 icon_th_large = 0xf009, 31 icon_th = 0xf00a, 32 icon_th_list = 0xf00b, 33 icon_ok = 0xf00c, 34 icon_remove = 0xf00d, 35 icon_zoom_in = 0xf00e, 36 37 icon_zoom_out = 0xf010, 38 icon_off = 0xf011, 39 icon_signal = 0xf012, 40 icon_cog = 0xf013, 41 icon_gear = icon_cog, 42 icon_trash = 0xf014, 43 icon_home = 0xf015, 44 icon_file_alt = 0xf016, 45 icon_time = 0xf017, 46 icon_road = 0xf018, 47 icon_download_alt = 0xf019, 48 icon_download = 0xf01a, 49 icon_upload = 0xf01b, 50 icon_inbox = 0xf01c, 51 icon_play_circle = 0xf01d, 52 icon_repeat = 0xf01e, 53 54 /* \f020 doesn't work in Safari. all shifted one down */ 55 icon_refresh = 0xf021, 56 icon_list_alt = 0xf022, 57 icon_lock = 0xf023, 58 icon_flag = 0xf024, 59 icon_headphones = 0xf025, 60 icon_volume_off = 0xf026, 61 icon_volume_down = 0xf027, 62 icon_volume_up = 0xf028, 63 icon_qrcode = 0xf029, 64 icon_barcode = 0xf02a, 65 icon_tag = 0xf02b, 66 icon_tags = 0xf02c, 67 icon_book = 0xf02d, 68 icon_bookmark = 0xf02e, 69 icon_print = 0xf02f, 70 71 icon_camera = 0xf030, 72 icon_font = 0xf031, 73 icon_bold = 0xf032, 74 icon_italic = 0xf033, 75 icon_text_height = 0xf034, 76 icon_text_width = 0xf035, 77 icon_align_left = 0xf036, 78 icon_align_center = 0xf037, 79 icon_align_right = 0xf038, 80 icon_align_justify = 0xf039, 81 icon_list = 0xf03a, 82 icon_indent_left = 0xf03b, 83 icon_indent_right = 0xf03c, 84 icon_facetime_video = 0xf03d, 85 icon_picture = 0xf03e, 86 87 icon_pencil = 0xf040, 88 icon_map_marker = 0xf041, 89 icon_adjust = 0xf042, 90 icon_tint = 0xf043, 91 icon_edit = 0xf044, 92 icon_share = 0xf045, 93 icon_check = 0xf046, 94 icon_move = 0xf047, 95 icon_step_backward = 0xf048, 96 icon_fast_backward = 0xf049, 97 icon_backward = 0xf04a, 98 icon_play = 0xf04b, 99 icon_pause = 0xf04c, 100 icon_stop = 0xf04d, 101 icon_forward = 0xf04e, 102 103 icon_fast_forward = 0xf050, 104 icon_step_forward = 0xf051, 105 icon_eject = 0xf052, 106 icon_chevron_left = 0xf053, 107 icon_chevron_right = 0xf054, 108 icon_plus_sign = 0xf055, 109 icon_minus_sign = 0xf056, 110 icon_remove_sign = 0xf057, 111 icon_ok_sign = 0xf058, 112 icon_question_sign = 0xf059, 113 icon_info_sign = 0xf05a, 114 icon_screenshot = 0xf05b, 115 icon_remove_circle = 0xf05c, 116 icon_ok_circle = 0xf05d, 117 icon_ban_circle = 0xf05e, 118 119 icon_arrow_left = 0xf060, 120 icon_arrow_right = 0xf061, 121 icon_arrow_up = 0xf062, 122 icon_arrow_down = 0xf063, 123 icon_share_alt = 0xf064, 124 icon_resize_full = 0xf065, 125 icon_resize_small = 0xf066, 126 icon_plus = 0xf067, 127 icon_minus = 0xf068, 128 icon_asterisk = 0xf069, 129 icon_exclamation_sign = 0xf06a, 130 icon_gift = 0xf06b, 131 icon_leaf = 0xf06c, 132 icon_fire = 0xf06d, 133 icon_eye_open = 0xf06e, 134 135 icon_eye_close = 0xf070, 136 icon_warning_sign = 0xf071, 137 icon_plane = 0xf072, 138 icon_calendar = 0xf073, 139 icon_random = 0xf074, 140 icon_comment = 0xf075, 141 icon_magnet = 0xf076, 142 icon_chevron_up = 0xf077, 143 icon_chevron_down = 0xf078, 144 icon_retweet = 0xf079, 145 icon_shopping_cart = 0xf07a, 146 icon_folder_close = 0xf07b, 147 icon_folder_open = 0xf07c, 148 icon_resize_vertical = 0xf07d, 149 icon_resize_horizontal = 0xf07e, 150 151 icon_bar_chart = 0xf080, 152 icon_twitter_sign = 0xf081, 153 icon_facebook_sign = 0xf082, 154 icon_camera_retro = 0xf083, 155 icon_key = 0xf084, 156 icon_cogs = 0xf085, 157 icon_gears = icon_cogs, 158 icon_comments = 0xf086, 159 icon_thumbs_up_alt = 0xf087, 160 icon_thumbs_down_alt = 0xf088, 161 icon_star_half = 0xf089, 162 icon_heart_empty = 0xf08a, 163 icon_signout = 0xf08b, 164 icon_linkedin_sign = 0xf08c, 165 icon_pushpin = 0xf08d, 166 icon_external_link = 0xf08e, 167 168 icon_signin = 0xf090, 169 icon_trophy = 0xf091, 170 icon_github_sign = 0xf092, 171 icon_upload_alt = 0xf093, 172 icon_lemon = 0xf094, 173 icon_phone = 0xf095, 174 icon_check_empty = 0xf096, 175 icon_bookmark_empty = 0xf097, 176 icon_phone_sign = 0xf098, 177 icon_twitter = 0xf099, 178 icon_facebook = 0xf09a, 179 icon_github = 0xf09b, 180 icon_unlock = 0xf09c, 181 icon_credit_card = 0xf09d, 182 icon_rss = 0xf09e, 183 184 icon_hdd = 0xf0a0, 185 icon_bullhorn = 0xf0a1, 186 icon_bell = 0xf0a2, 187 icon_certificate = 0xf0a3, 188 icon_hand_right = 0xf0a4, 189 icon_hand_left = 0xf0a5, 190 icon_hand_up = 0xf0a6, 191 icon_hand_down = 0xf0a7, 192 icon_circle_arrow_left = 0xf0a8, 193 icon_circle_arrow_right = 0xf0a9, 194 icon_circle_arrow_up = 0xf0aa, 195 icon_circle_arrow_down = 0xf0ab, 196 icon_globe = 0xf0ac, 197 icon_wrench = 0xf0ad, 198 icon_tasks = 0xf0ae, 199 200 icon_filter = 0xf0b0, 201 icon_briefcase = 0xf0b1, 202 icon_fullscreen = 0xf0b2, 203 204 icon_group = 0xf0c0, 205 icon_link = 0xf0c1, 206 icon_cloud = 0xf0c2, 207 icon_beaker = 0xf0c3, 208 icon_cut = 0xf0c4, 209 icon_copy = 0xf0c5, 210 icon_paper_clip = 0xf0c6, 211 icon_save = 0xf0c7, 212 icon_sign_blank = 0xf0c8, 213 icon_reorder = 0xf0c9, 214 icon_list_ul = 0xf0ca, 215 icon_list_ol = 0xf0cb, 216 icon_strikethrough = 0xf0cc, 217 icon_underline = 0xf0cd, 218 icon_table = 0xf0ce, 219 220 icon_magic = 0xf0d0, 221 icon_truck = 0xf0d1, 222 icon_pinterest = 0xf0d2, 223 icon_pinterest_sign = 0xf0d3, 224 icon_google_plus_sign = 0xf0d4, 225 icon_google_plus = 0xf0d5, 226 icon_money = 0xf0d6, 227 icon_caret_down = 0xf107, 228 icon_caret_up = 0xf106, 229 icon_caret_left = 0xf104, 230 icon_caret_right = 0xf105, 231 icon_columns = 0xf0db, 232 icon_sort = 0xf0dc, 233 icon_sort_down = 0xf0dd, 234 icon_sort_up = 0xf0de, 235 236 icon_envelope_alt = 0xf0e0, 237 icon_linkedin = 0xf0e1, 238 icon_undo = 0xf0e2, 239 icon_legal = 0xf0e3, 240 icon_dashboard = 0xf0e4, 241 icon_comment_alt = 0xf0e5, 242 icon_comments_alt = 0xf0e6, 243 icon_bolt = 0xf0e7, 244 icon_sitemap = 0xf0e8, 245 icon_umbrella = 0xf0e9, 246 icon_paste = 0xf0ea, 247 icon_lightbulb = 0xf0eb, 248 icon_exchange = 0xf0ec, 249 icon_cloud_download = 0xf0ed, 250 icon_cloud_upload = 0xf0ee, 251 252 icon_user_md = 0xf0f0, 253 icon_stethoscope = 0xf0f1, 254 icon_suitcase = 0xf0f2, 255 icon_bell_alt = 0xf0f3, 256 icon_coffee = 0xf0f4, 257 icon_food = 0xf0f5, 258 icon_file_text_alt = 0xf0f6, 259 icon_building = 0xf0f7, 260 icon_hospital = 0xf0f8, 261 icon_ambulance = 0xf0f9, 262 icon_medkit = 0xf0fa, 263 icon_fighter_jet = 0xf0fb, 264 icon_beer = 0xf0fc, 265 icon_h_sign = 0xf0fd, 266 icon_plus_sign_alt = 0xf0fe, 267 268 icon_double_angle_left = 0xf100, 269 icon_double_angle_right = 0xf101, 270 icon_double_angle_up = 0xf102, 271 icon_double_angle_down = 0xf103, 272 icon_angle_left = 0xf104, 273 icon_angle_right = 0xf105, 274 icon_angle_up = 0xf106, 275 icon_angle_down = 0xf107, 276 icon_desktop = 0xf108, 277 icon_laptop = 0xf109, 278 icon_tablet = 0xf10a, 279 icon_mobile_phone = 0xf10b, 280 icon_circle_blank = 0xf10c, 281 icon_quote_left = 0xf10d, 282 icon_quote_right = 0xf10e, 283 284 icon_spinner = 0xf110, 285 icon_circle = 0xf111, 286 icon_mail_reply = 0xf112, 287 icon_reply = icon_mail_reply, 288 289 icon_github_alt = 0xf113, 290 icon_folder_close_alt = 0xf114, 291 icon_folder_open_alt = 0xf115, 292 293 icon_expand_alt = 0xf116, 294 icon_collapse_alt = 0xf117, 295 icon_smile = 0xf118, 296 icon_frown = 0xf119, 297 icon_meh = 0xf11a, 298 icon_gamepad = 0xf11b, 299 icon_keyboard = 0xf11c, 300 icon_flag_alt = 0xf11d, 301 icon_flag_checkered = 0xf11e, 302 303 icon_terminal = 0xf120, 304 icon_code = 0xf121, 305 icon_reply_all = 0xf122, 306 icon_mail_reply_all = icon_reply_all, 307 icon_star_half_full = 0xf123, 308 icon_star_half_empty = icon_star_half_full, 309 icon_location_arrow = 0xf124, 310 icon_crop = 0xf125, 311 icon_code_fork = 0xf126, 312 icon_unlink = 0xf127, 313 icon_question = 0xf128, 314 icon_info = 0xf129, 315 icon_exclamation = 0xf12a, 316 icon_superscript = 0xf12b, 317 icon_subscript = 0xf12c, 318 icon_eraser = 0xf12d, 319 icon_puzzle_piece = 0xf12e, 320 321 icon_microphone = 0xf130, 322 icon_microphone_off = 0xf131, 323 icon_shield = 0xf132, 324 icon_calendar_empty = 0xf133, 325 icon_fire_extinguisher = 0xf134, 326 icon_rocket = 0xf135, 327 icon_maxcdn = 0xf136, 328 icon_chevron_sign_left = 0xf137, 329 icon_chevron_sign_right = 0xf138, 330 icon_chevron_sign_up = 0xf139, 331 icon_chevron_sign_down = 0xf13a, 332 icon_html5 = 0xf13b, 333 icon_css3 = 0xf13c, 334 icon_anchor = 0xf13d, 335 icon_unlock_alt = 0xf13e, 336 337 icon_bullseye = 0xf140, 338 icon_ellipsis_horizontal = 0xf141, 339 icon_ellipsis_vertical = 0xf142, 340 icon_rss_sign = 0xf143, 341 icon_play_sign = 0xf144, 342 icon_ticket = 0xf145, 343 icon_minus_sign_alt = 0xf146, 344 icon_check_minus = 0xf147, 345 icon_level_up = 0xf148, 346 icon_level_down = 0xf149, 347 icon_check_sign = 0xf14a, 348 icon_edit_sign = 0xf14b, 349 icon_external_link_sign = 0xf14c, 350 icon_share_sign = 0xf14d, 351 352 // v3.2.0 353 icon_compass = 0xf14e, 354 355 icon_collapse = 0xf150, 356 icon_collapse_top = 0xf151, 357 icon_expand = 0xf152, 358 icon_euro = 0xf153, 359 icon_eur = 0xf153, 360 icon_gbp = 0xf154, 361 icon_dollar = 0xf155, 362 icon_usd = icon_dollar, 363 icon_rupee = 0xf156, 364 icon_inr = icon_rupee, 365 icon_yen = 0xf157, 366 icon_jpy = icon_yen, 367 icon_renminbi = 0xf158, 368 icon_cny = icon_renminbi, 369 icon_won = 0xf159, 370 icon_krw = icon_won, 371 icon_bitcoin = 0xf15a, 372 icon_btc = icon_bitcoin, 373 icon_file = 0xf15b, 374 icon_file_text = 0xf15c, 375 icon_sort_by_alphabet = 0xf15d, 376 icon_sort_by_alphabet_alt = 0xf15e, 377 378 icon_sort_by_attributes = 0xf160, 379 icon_sort_by_attributes_alt = 0xf161, 380 icon_sort_by_order = 0xf162, 381 icon_sort_by_order_alt = 0xf163, 382 icon_thumbs_up = 0xf164, 383 icon_thumbs_down = 0xf165, 384 icon_youtube_sign = 0xf166, 385 icon_youtube = 0xf167, 386 icon_xing = 0xf168, 387 icon_xing_sign = 0xf169, 388 icon_youtube_play = 0xf16a, 389 icon_dropbox = 0xf16b, 390 icon_stackexchange = 0xf16c, 391 icon_instagram = 0xf16d, 392 icon_flickr = 0xf16e, 393 394 icon_adn = 0xf170, 395 icon_bitbucket = 0xf171, 396 icon_bitbucket_sign = 0xf172, 397 icon_tumblr = 0xf173, 398 icon_tumblr_sign = 0xf174, 399 icon_long_arrow_down = 0xf175, 400 icon_long_arrow_up = 0xf176, 401 icon_long_arrow_left = 0xf177, 402 icon_long_arrow_right = 0xf178, 403 icon_apple = 0xf179, 404 icon_windows = 0xf17a, 405 icon_android = 0xf17b, 406 icon_linux = 0xf17c, 407 icon_dribble = 0xf17d, 408 icon_skype = 0xf17e, 409 410 icon_foursquare = 0xf180, 411 icon_trello = 0xf181, 412 icon_female = 0xf182, 413 icon_male = 0xf183, 414 icon_gittip = 0xf184, 415 icon_sun = 0xf185, 416 icon_moon = 0xf186, 417 icon_archive = 0xf187, 418 icon_bug = 0xf188, 419 icon_vk = 0xf189, 420 icon_weibo = 0xf18a, 421 icon_renren = 0xf18b, 422 423 icon_circle_close = 0xf05c 424 }; 425 426 427 //--------------------------------------------------------------------------------------- 428 429 class QtAwesomeIconPainter; 430 431 /// The main class for managing icons 432 /// This class requires a 2-phase construction. You must first create the class and then initialize it via an init* method 433 class QtAwesome : public QObject 434 { 435 Q_OBJECT 436 437 public: 438 439 QtAwesome(QObject *parent = 0); 440 virtual ~QtAwesome(); 441 442 void init( const QString& fontname ); 443 bool initFontAwesome(); 444 445 void addNamedCodepoint( const QString& name, int codePoint ); namedCodePoints()446 QHash<QString,int> namedCodePoints() { return namedCodepoints_; } 447 448 void setDefaultOption( const QString& name, const QVariant& value ); 449 QVariant defaultOption( const QString& name ); 450 451 QIcon icon( int character, const QVariantMap& options = QVariantMap() ); 452 QIcon icon( const QString& name, const QVariantMap& options = QVariantMap() ); 453 QIcon icon(QtAwesomeIconPainter* painter, const QVariantMap& optionMap = QVariantMap() ); 454 QIcon icon(int character, const QColor& color); 455 456 void give( const QString& name, QtAwesomeIconPainter* painter ); 457 458 QFont font( int size ); 459 460 /// Returns the font-name that is used as icon-map fontName()461 QString fontName() { return fontName_ ; } 462 463 private: 464 QString fontName_; ///< The font name used for this map 465 QHash<QString,int> namedCodepoints_; ///< A map with names mapped to code-points 466 467 QHash<QString, QtAwesomeIconPainter*> painterMap_; ///< A map of custom painters 468 QVariantMap defaultOptions_; ///< The default icon options 469 QtAwesomeIconPainter* fontIconPainter_; ///< A special painter fo painting codepoints 470 }; 471 472 473 //--------------------------------------------------------------------------------------- 474 475 476 /// The QtAwesomeIconPainter is a specialized painter for painting icons 477 /// your can implement an iconpainter to create custom font-icon code 478 class QtAwesomeIconPainter 479 { 480 public: ~QtAwesomeIconPainter()481 virtual ~QtAwesomeIconPainter() {} 482 virtual void paint( QtAwesome* awesome, QPainter* painter, const QRect& rect, QIcon::Mode mode, QIcon::State state, const QVariantMap& options ) = 0; 483 }; 484 485 extern QtAwesome *awesome; 486 487 #endif // QTAWESOME_H 488