Licensing: re-import ImageRegistry
- include full license headers, - copied from - repo: https://github.com/tomahawk-player/tomahawk/ - rev: 00f602e10203b76fc28b4615868c567e6bd4ced4 - path: src/libtomahawk/utils/ImageRegistry.cpp
This commit is contained in:
parent
d23818b27c
commit
a65bc7d756
16
LICENSES/GPLv3+-ImageRegistry
Normal file
16
LICENSES/GPLv3+-ImageRegistry
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
@ -1,35 +1,30 @@
|
|||||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
/*
|
||||||
*
|
|
||||||
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
|
||||||
* Copyright 2017, Adriaan de Groot <groot@kde.org>
|
|
||||||
*
|
|
||||||
* Originally from Tomahawk,
|
|
||||||
* Copyright 2012, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
* Copyright 2012, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||||
*
|
|
||||||
* Calamares is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
(at your option) any later version.
|
||||||
*
|
|
||||||
* Calamares is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ImageRegistry.h"
|
#include "ImageRegistry.h"
|
||||||
|
|
||||||
#include <QSvgRenderer>
|
#include <QSvgRenderer>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QIcon>
|
#include <qicon.h>
|
||||||
|
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
static QHash< QString, QHash< int, QHash< qint64, QPixmap > > > s_cache;
|
static QHash< QString, QHash< int, QHash< qint64, QPixmap > > > s_cache;
|
||||||
ImageRegistry* ImageRegistry::s_instance = nullptr;
|
ImageRegistry* ImageRegistry::s_instance = 0;
|
||||||
|
|
||||||
|
|
||||||
ImageRegistry*
|
ImageRegistry*
|
||||||
@ -46,22 +41,28 @@ ImageRegistry::ImageRegistry()
|
|||||||
|
|
||||||
|
|
||||||
QIcon
|
QIcon
|
||||||
ImageRegistry::icon( const QString& image, CalamaresUtils::ImageMode mode )
|
ImageRegistry::icon( const QString& image, TomahawkUtils::ImageMode mode )
|
||||||
{
|
{
|
||||||
return pixmap( image, CalamaresUtils::defaultIconSize(), mode );
|
return pixmap( image, TomahawkUtils::defaultIconSize(), mode );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
qint64
|
qint64
|
||||||
ImageRegistry::cacheKey( const QSize& size, qreal opacity, QColor tint )
|
ImageRegistry::cacheKey( const QSize& size, float opacity, QColor tint )
|
||||||
{
|
{
|
||||||
return size.width() * 100 + size.height() * 10 + int( opacity * 100.0 ) + tint.value();
|
return size.width() * 100 + size.height() * 10 + ( opacity * 100.0 ) + tint.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QPixmap
|
QPixmap
|
||||||
ImageRegistry::pixmap( const QString& image, const QSize& size, CalamaresUtils::ImageMode mode, qreal opacity, QColor tint )
|
ImageRegistry::pixmap( const QString& image, const QSize& size, TomahawkUtils::ImageMode mode, float opacity, QColor tint )
|
||||||
{
|
{
|
||||||
|
if ( size.width() < 0 || size.height() < 0 )
|
||||||
|
{
|
||||||
|
Q_ASSERT( false );
|
||||||
|
return QPixmap();
|
||||||
|
}
|
||||||
|
|
||||||
QHash< qint64, QPixmap > subsubcache;
|
QHash< qint64, QPixmap > subsubcache;
|
||||||
QHash< int, QHash< qint64, QPixmap > > subcache;
|
QHash< int, QHash< qint64, QPixmap > > subcache;
|
||||||
|
|
||||||
@ -83,11 +84,10 @@ ImageRegistry::pixmap( const QString& image, const QSize& size, CalamaresUtils::
|
|||||||
|
|
||||||
// Image not found in cache. Let's load it.
|
// Image not found in cache. Let's load it.
|
||||||
QPixmap pixmap;
|
QPixmap pixmap;
|
||||||
if ( image.toLower().endsWith( ".svg" ) ||
|
if ( image.toLower().endsWith( ".svg" ) )
|
||||||
image.toLower().endsWith( ".svgz" ) )
|
|
||||||
{
|
{
|
||||||
QSvgRenderer svgRenderer( image );
|
QSvgRenderer svgRenderer( image );
|
||||||
QPixmap p( size.isNull() ? svgRenderer.defaultSize() : size );
|
QPixmap p( size.isNull() || size.height() == 0 || size.width() == 0 ? svgRenderer.defaultSize() : size );
|
||||||
p.fill( Qt::transparent );
|
p.fill( Qt::transparent );
|
||||||
|
|
||||||
QPainter pixPainter( &p );
|
QPainter pixPainter( &p );
|
||||||
@ -96,17 +96,7 @@ ImageRegistry::pixmap( const QString& image, const QSize& size, CalamaresUtils::
|
|||||||
pixPainter.end();
|
pixPainter.end();
|
||||||
|
|
||||||
if ( tint.alpha() > 0 )
|
if ( tint.alpha() > 0 )
|
||||||
{
|
p = TomahawkUtils::tinted( p, tint );
|
||||||
QImage resultImage( p.size(), QImage::Format_ARGB32_Premultiplied );
|
|
||||||
QPainter painter( &resultImage );
|
|
||||||
painter.drawPixmap( 0, 0, p );
|
|
||||||
painter.setCompositionMode( QPainter::CompositionMode_Screen );
|
|
||||||
painter.fillRect( resultImage.rect(), tint );
|
|
||||||
painter.end();
|
|
||||||
|
|
||||||
resultImage.setAlphaChannel( p.toImage().alphaChannel() );
|
|
||||||
p = QPixmap::fromImage( resultImage );
|
|
||||||
}
|
|
||||||
|
|
||||||
pixmap = p;
|
pixmap = p;
|
||||||
}
|
}
|
||||||
@ -117,8 +107,8 @@ ImageRegistry::pixmap( const QString& image, const QSize& size, CalamaresUtils::
|
|||||||
{
|
{
|
||||||
switch ( mode )
|
switch ( mode )
|
||||||
{
|
{
|
||||||
case CalamaresUtils::RoundedCorners:
|
case TomahawkUtils::RoundedCorners:
|
||||||
pixmap = CalamaresUtils::createRoundedImage( pixmap, size );
|
pixmap = TomahawkUtils::createRoundedImage( pixmap, size );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -126,7 +116,18 @@ ImageRegistry::pixmap( const QString& image, const QSize& size, CalamaresUtils::
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( !size.isNull() && pixmap.size() != size )
|
if ( !size.isNull() && pixmap.size() != size )
|
||||||
pixmap = pixmap.scaled( size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
|
{
|
||||||
|
if ( size.width() == 0 )
|
||||||
|
{
|
||||||
|
pixmap = pixmap.scaledToHeight( size.height(), Qt::SmoothTransformation );
|
||||||
|
}
|
||||||
|
else if ( size.height() == 0 )
|
||||||
|
{
|
||||||
|
pixmap = pixmap.scaledToWidth( size.width(), Qt::SmoothTransformation );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
pixmap = pixmap.scaled( size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
|
||||||
|
}
|
||||||
|
|
||||||
putInCache( image, size, mode, opacity, pixmap, tint );
|
putInCache( image, size, mode, opacity, pixmap, tint );
|
||||||
}
|
}
|
||||||
@ -136,9 +137,9 @@ ImageRegistry::pixmap( const QString& image, const QSize& size, CalamaresUtils::
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ImageRegistry::putInCache( const QString& image, const QSize& size, CalamaresUtils::ImageMode mode, qreal opacity, const QPixmap& pixmap, QColor tint )
|
ImageRegistry::putInCache( const QString& image, const QSize& size, TomahawkUtils::ImageMode mode, float opacity, const QPixmap& pixmap, QColor tint )
|
||||||
{
|
{
|
||||||
// cDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Adding to image cache:" << image << size << mode;
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Adding to image cache:" << image << size << mode;
|
||||||
|
|
||||||
QHash< qint64, QPixmap > subsubcache;
|
QHash< qint64, QPixmap > subsubcache;
|
||||||
QHash< int, QHash< qint64, QPixmap > > subcache;
|
QHash< int, QHash< qint64, QPixmap > > subcache;
|
||||||
|
@ -1,45 +1,41 @@
|
|||||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
/*
|
||||||
*
|
|
||||||
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
|
||||||
*
|
|
||||||
* Originally from Tomahawk,
|
|
||||||
* Copyright 2012, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
* Copyright 2012, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||||
*
|
|
||||||
* Calamares is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
(at your option) any later version.
|
||||||
*
|
|
||||||
* Calamares is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef IMAGE_REGISTRY_H
|
#ifndef IMAGE_REGISTRY_H
|
||||||
#define IMAGE_REGISTRY_H
|
#define IMAGE_REGISTRY_H
|
||||||
|
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
|
||||||
#include "utils/CalamaresUtilsGui.h"
|
#include "utils/TomahawkUtilsGui.h"
|
||||||
#include "UiDllMacro.h"
|
#include "DllMacro.h"
|
||||||
|
|
||||||
class UIDLLEXPORT ImageRegistry
|
class DLLEXPORT ImageRegistry
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static ImageRegistry* instance();
|
static ImageRegistry* instance();
|
||||||
|
|
||||||
explicit ImageRegistry();
|
explicit ImageRegistry();
|
||||||
|
|
||||||
QIcon icon( const QString& image, CalamaresUtils::ImageMode mode = CalamaresUtils::Original );
|
QIcon icon( const QString& image, TomahawkUtils::ImageMode mode = TomahawkUtils::Original );
|
||||||
QPixmap pixmap( const QString& image, const QSize& size, CalamaresUtils::ImageMode mode = CalamaresUtils::Original, qreal opacity = 1.0, QColor tint = QColor( 0, 0, 0, 0 ) );
|
QPixmap pixmap( const QString& image, const QSize& size, TomahawkUtils::ImageMode mode = TomahawkUtils::Original, float opacity = 1.0, QColor tint = QColor( 0, 0, 0, 0 ) );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
qint64 cacheKey( const QSize& size, qreal opacity, QColor tint );
|
qint64 cacheKey( const QSize& size, float opacity, QColor tint );
|
||||||
void putInCache( const QString& image, const QSize& size, CalamaresUtils::ImageMode mode, qreal opacity, const QPixmap& pixmap, QColor tint );
|
void putInCache( const QString& image, const QSize& size, TomahawkUtils::ImageMode mode, float opacity, const QPixmap& pixmap, QColor tint );
|
||||||
|
|
||||||
static ImageRegistry* s_instance;
|
static ImageRegistry* s_instance;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user