2021-08-26 17:02:31 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Copyright (C) 2021 Edelhirsch Software GmbH
|
2023-04-06 10:15:03 +02:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2021-08-26 17:02:31 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "GraphicProvider.h"
|
|
|
|
|
|
|
|
#include <QskGraphic.h>
|
2022-11-24 09:06:39 +01:00
|
|
|
#include <QskGraphicIO.h>
|
2021-08-26 17:02:31 +02:00
|
|
|
|
|
|
|
#include <QFile>
|
|
|
|
|
|
|
|
const inline QString pathName( const QString& baseName, const QString& suffix )
|
|
|
|
{
|
|
|
|
QString fileName = baseName;
|
|
|
|
if ( !suffix.isEmpty() )
|
|
|
|
fileName += suffix;
|
|
|
|
|
|
|
|
return QFile( fileName ).exists() ? fileName : QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
const QskGraphic* GraphicProvider::loadGraphic( const QString& id ) const
|
|
|
|
{
|
2022-11-24 09:06:39 +01:00
|
|
|
static QString scope = QStringLiteral( ":/images/qvg/" );
|
2021-08-26 17:02:31 +02:00
|
|
|
|
|
|
|
QString baseName = scope;
|
|
|
|
baseName += id.toLower().replace( ' ', '-' );
|
|
|
|
|
|
|
|
auto path = pathName( baseName, QString() );
|
|
|
|
|
|
|
|
if ( path.isEmpty() )
|
2022-11-24 09:06:39 +01:00
|
|
|
path = pathName( baseName, ".qvg" );
|
2021-08-26 17:02:31 +02:00
|
|
|
|
|
|
|
QskGraphic graphic;
|
|
|
|
|
|
|
|
if ( !path.isEmpty() )
|
2022-11-24 09:06:39 +01:00
|
|
|
graphic = QskGraphicIO::read( path );
|
2021-08-26 17:02:31 +02:00
|
|
|
|
|
|
|
return graphic.isNull() ? nullptr : new QskGraphic( graphic );
|
|
|
|
}
|