embed.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * embed.h - misc. stuff for using embedded data (resources linked into binary)
  3. *
  4. * Copyright (c) 2004-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
  5. *
  6. * This file is part of LMMS - https://lmms.io
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with this program (see COPYING); if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. * Boston, MA 02110-1301 USA.
  22. *
  23. */
  24. #ifndef EMBED_H
  25. #define EMBED_H
  26. #include <QPixmap>
  27. #include <QtCore/QString>
  28. #include "lmms_export.h"
  29. #include "lmms_basics.h"
  30. namespace embed
  31. {
  32. /**
  33. * Return an image for the icon pixmap cache.
  34. *
  35. * @param _name Identifier for the pixmap. If it is not in the icon pixmap
  36. * cache, it will be loaded from the artwork QDir search paths (exceptions are
  37. * compiled-in XPMs, you need to provide @p xpm for loading them).
  38. * @param xpm Must be XPM data if the source should be raw XPM data instead of
  39. * a file
  40. */
  41. QPixmap LMMS_EXPORT getIconPixmap( const QString& _name,
  42. int _w = -1, int _h = -1 , const char** xpm = nullptr );
  43. QString LMMS_EXPORT getText( const char * _name );
  44. }
  45. #ifdef PLUGIN_NAME
  46. namespace PLUGIN_NAME
  47. {
  48. inline QPixmap getIconPixmap( const QString& _name,
  49. int _w = -1, int _h = -1, const char** xpm = nullptr )
  50. {
  51. return embed::getIconPixmap(QString("%1/%2").arg(STRINGIFY(PLUGIN_NAME), _name), _w, _h, xpm);
  52. }
  53. //QString getText( const char * _name );
  54. }
  55. #endif
  56. class PixmapLoader
  57. {
  58. public:
  59. PixmapLoader( const PixmapLoader * _ref ) :
  60. m_name( _ref != NULL ? _ref->m_name : QString() ),
  61. m_xpm( _ref->m_xpm )
  62. {
  63. }
  64. PixmapLoader( const QString & _name = QString(),
  65. const char** xpm = nullptr ) :
  66. m_name( _name ),
  67. m_xpm(xpm)
  68. {
  69. }
  70. virtual QPixmap pixmap() const
  71. {
  72. if( !m_name.isEmpty() )
  73. {
  74. return( embed::getIconPixmap(
  75. m_name.toLatin1().constData(), -1, -1, m_xpm ));
  76. }
  77. return( QPixmap() );
  78. }
  79. virtual ~PixmapLoader()
  80. {
  81. }
  82. virtual QString pixmapName() const
  83. {
  84. return m_name;
  85. }
  86. protected:
  87. QString m_name;
  88. const char** m_xpm = nullptr;
  89. } ;
  90. #ifdef PLUGIN_NAME
  91. class PluginPixmapLoader : public PixmapLoader
  92. {
  93. public:
  94. PluginPixmapLoader( const QString & _name = QString() ) :
  95. PixmapLoader( _name )
  96. {
  97. }
  98. virtual QPixmap pixmap() const
  99. {
  100. if( !m_name.isEmpty() )
  101. {
  102. return( PLUGIN_NAME::getIconPixmap(
  103. m_name.toLatin1().constData() ) );
  104. }
  105. return( QPixmap() );
  106. }
  107. virtual QString pixmapName() const
  108. {
  109. return QString( STRINGIFY(PLUGIN_NAME) ) + "::" + m_name;
  110. }
  111. } ;
  112. #endif
  113. #endif