Use Qt's Resource System (2nd approach) (#1891)
* Remove bin2res, use Qt's resource system * Use QDir search paths and QImageReader in getIconPixmap * Don't include "embed.cpp" in plugins * getIconPixmap: Use QPixmapCache, use QPixmap::fromImageReader * Require CMake 2.8.9 * Fix ReverbSC embed usage
This commit is contained in:
@@ -41,12 +41,12 @@ IF(WIN32)
|
||||
DEPENDS "${CMAKE_BINARY_DIR}/lmms.rc")
|
||||
ENDIF()
|
||||
|
||||
SET(lmms_EMBEDDED_RESOURCES
|
||||
INCLUDE(GenQrc)
|
||||
ADD_GEN_QRC(LMMS_RCC_OUT lmms.qrc
|
||||
"${CMAKE_SOURCE_DIR}/doc/AUTHORS"
|
||||
"${CMAKE_SOURCE_DIR}/LICENSE.txt"
|
||||
"${CMAKE_SOURCE_DIR}/doc/CONTRIBUTORS")
|
||||
SET(LMMS_ER_H "${CMAKE_CURRENT_BINARY_DIR}/embedded_resources.h")
|
||||
ADD_CUSTOM_COMMAND(OUTPUT "${LMMS_ER_H}" COMMAND "${BIN2RES}" ARGS ${lmms_EMBEDDED_RESOURCES} > "\"${LMMS_ER_H}\"" DEPENDS bin2res)
|
||||
"${CMAKE_SOURCE_DIR}/doc/CONTRIBUTORS"
|
||||
)
|
||||
|
||||
# Paths relative to lmms executable
|
||||
FILE(RELATIVE_PATH LIB_DIR_RELATIVE "/${BIN_DIR}" "/${LIB_DIR}")
|
||||
@@ -89,28 +89,25 @@ IF(CMAKE_VERSION VERSION_GREATER "2.8.7")
|
||||
${LMMS_SRCS}
|
||||
${LMMS_INCLUDES}
|
||||
${LMMS_UI_OUT}
|
||||
${LMMS_ER_H}
|
||||
${LMMS_RCC_OUT}
|
||||
)
|
||||
ADD_EXECUTABLE(lmms
|
||||
core/main.cpp
|
||||
$<TARGET_OBJECTS:lmmsobjs>
|
||||
"${WINRC}"
|
||||
)
|
||||
|
||||
SET(iwyu include-what-you-use -Xiwyu --mapping_file=/usr/share/include-what-you-use/qt5_4.imp)
|
||||
#SET_PROPERTY(TARGET lmmsobjs PROPERTY CXX_INCLUDE_WHAT_YOU_USE ${iwyu})
|
||||
ELSE()
|
||||
ADD_EXECUTABLE(lmms
|
||||
core/main.cpp
|
||||
${LMMS_SRCS}
|
||||
${LMMS_INCLUDES}
|
||||
${LMMS_UI_OUT}
|
||||
${LMMS_ER_H}
|
||||
${LMMS_RCC_OUT}
|
||||
"${WINRC}"
|
||||
)
|
||||
ENDIF()
|
||||
|
||||
SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${LMMS_ER_H} ${LMMS_UI_OUT} lmmsconfig.h lmms.1.gz")
|
||||
SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${LMMS_RCC_OUT} ${LMMS_UI_OUT} lmmsconfig.h lmms.1.gz")
|
||||
|
||||
IF(LMMS_BUILD_WIN32)
|
||||
SET(EXTRA_LIBRARIES "-lwinmm")
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include "SongEditor.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDir>
|
||||
#include <QMessageBox>
|
||||
#include <QSplashScreen>
|
||||
|
||||
@@ -65,6 +66,10 @@ GuiApplication::GuiApplication()
|
||||
ConfigManager::inst()->createWorkingDir();
|
||||
}
|
||||
// Init style and palette
|
||||
QDir::addSearchPath("artwork", ConfigManager::inst()->artworkDir());
|
||||
QDir::addSearchPath("artwork", ConfigManager::inst()->defaultArtworkDir());
|
||||
QDir::addSearchPath("artwork", ":/artwork");
|
||||
|
||||
LmmsStyle* lmmsstyle = new LmmsStyle();
|
||||
QApplication::setStyle(lmmsstyle);
|
||||
|
||||
|
||||
@@ -22,92 +22,58 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <QImage>
|
||||
#include <QHash>
|
||||
#include <QDebug>
|
||||
#include <QImageReader>
|
||||
#include <QPixmapCache>
|
||||
#include <QResource>
|
||||
#include "embed.h"
|
||||
|
||||
#ifndef PLUGIN_NAME
|
||||
namespace embed
|
||||
#else
|
||||
namespace PLUGIN_NAME
|
||||
#endif
|
||||
{
|
||||
|
||||
namespace
|
||||
|
||||
QPixmap getIconPixmap(const QString& pixmapName, int width, int height )
|
||||
{
|
||||
static QHash<QString, QPixmap> s_pixmapCache;
|
||||
}
|
||||
|
||||
#include "embedded_resources.h"
|
||||
|
||||
|
||||
QPixmap getIconPixmap( const char * pixmapName, int width, int height )
|
||||
{
|
||||
if( width == -1 || height == -1 )
|
||||
QString cacheName;
|
||||
if (width > 0 && height > 0)
|
||||
{
|
||||
// Return cached pixmap
|
||||
QPixmap cached = s_pixmapCache.value( pixmapName );
|
||||
if( !cached.isNull() )
|
||||
{
|
||||
return cached;
|
||||
}
|
||||
|
||||
// Or try to load it
|
||||
QList<QByteArray> formats = QImageReader::supportedImageFormats();
|
||||
QList<QString> candidates;
|
||||
QPixmap pixmap;
|
||||
QString name;
|
||||
int i;
|
||||
|
||||
for ( i = 0; i < formats.size() && pixmap.isNull(); ++i )
|
||||
{
|
||||
candidates << QString( pixmapName ) + "." + formats.at( i ).data();
|
||||
}
|
||||
|
||||
#ifdef PLUGIN_NAME
|
||||
for ( i = 0; i < candidates.size() && pixmap.isNull(); ++i ) {
|
||||
name = candidates.at( i );
|
||||
pixmap = QPixmap( "resources:plugins/" STRINGIFY( PLUGIN_NAME ) "_" + name );
|
||||
}
|
||||
#endif
|
||||
for ( i = 0; i < candidates.size() && pixmap.isNull(); ++i ) {
|
||||
name = candidates.at( i );
|
||||
pixmap = QPixmap( "resources:" + name );
|
||||
}
|
||||
|
||||
for ( i = 0; i < candidates.size() && pixmap.isNull(); ++i ) {
|
||||
name = candidates.at( i );
|
||||
const embed::descriptor & e =
|
||||
findEmbeddedData( name.toUtf8().constData() );
|
||||
// found?
|
||||
if( name == e.name )
|
||||
{
|
||||
pixmap.loadFromData( e.data, e.size );
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback
|
||||
if( pixmap.isNull() )
|
||||
{
|
||||
pixmap = QPixmap( 1, 1 );
|
||||
}
|
||||
// Save to cache and return
|
||||
s_pixmapCache.insert( pixmapName, pixmap );
|
||||
return pixmap;
|
||||
cacheName = QString("%1_%2_%3").arg(pixmapName, width, height);
|
||||
}
|
||||
else
|
||||
{
|
||||
cacheName = pixmapName;
|
||||
}
|
||||
|
||||
return getIconPixmap( pixmapName ).
|
||||
scaled( width, height, Qt::IgnoreAspectRatio,
|
||||
Qt::SmoothTransformation );
|
||||
// Return cached pixmap
|
||||
QPixmap pixmap;
|
||||
if( QPixmapCache::find(cacheName, &pixmap) )
|
||||
{
|
||||
return pixmap;
|
||||
}
|
||||
QImageReader reader(QString("artwork:%1").arg(pixmapName));
|
||||
|
||||
if (width > 0 && height > 0)
|
||||
{
|
||||
reader.setScaledSize(QSize(width, height));
|
||||
}
|
||||
|
||||
pixmap = QPixmap::fromImageReader(&reader);
|
||||
if (pixmap.isNull())
|
||||
{
|
||||
qWarning().nospace() << "Error loading icon pixmap " << pixmapName << ": " <<
|
||||
reader.errorString().toLocal8Bit().data();
|
||||
return QPixmap(1,1);
|
||||
}
|
||||
|
||||
// Save to cache and return
|
||||
QPixmapCache::insert(cacheName, pixmap);
|
||||
return pixmap;
|
||||
}
|
||||
|
||||
|
||||
QString getText( const char * _name )
|
||||
QString getText( const char * name )
|
||||
{
|
||||
const embed::descriptor & e = findEmbeddedData( _name );
|
||||
return QString::fromUtf8( (const char *) e.data, e.size );
|
||||
return QString::fromUtf8( (const char*) QResource(QString(":/%1").arg(name)).data());
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user