mirror of https://github.com/cutefishos/calamares
Add proper QResrouce system to libcalamaresui, finish up prepare checks
This also adds ImageRegistry, a SVG cache, a bunch of utility functions for shared pixmaps in CalamaresUtilsGui and renames several qrc files in viewmodules.main
parent
0404413b05
commit
d97bb47f09
Binary file not shown.
Before Width: | Height: | Size: 149 KiB After Width: | Height: | Size: 149 KiB |
Before Width: | Height: | Size: 122 KiB After Width: | Height: | Size: 122 KiB |
Binary file not shown.
@ -0,0 +1,6 @@
|
||||
<RCC>
|
||||
<qresource prefix="/data">
|
||||
<file alias="images/yes.svgz">../../data/images/yes.svgz</file>
|
||||
<file alias="images/no.svgz">../../data/images/no.svgz</file>
|
||||
</qresource>
|
||||
</RCC>
|
@ -0,0 +1,163 @@
|
||||
/* === 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>
|
||||
*
|
||||
* Calamares 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.
|
||||
*
|
||||
* Calamares 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 Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "ImageRegistry.h"
|
||||
|
||||
#include <QSvgRenderer>
|
||||
#include <QPainter>
|
||||
#include <QIcon>
|
||||
|
||||
#include "utils/Logger.h"
|
||||
|
||||
static QHash< QString, QHash< int, QHash< qint64, QPixmap > > > s_cache;
|
||||
ImageRegistry* ImageRegistry::s_instance = 0;
|
||||
|
||||
|
||||
ImageRegistry*
|
||||
ImageRegistry::instance()
|
||||
{
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
|
||||
ImageRegistry::ImageRegistry()
|
||||
{
|
||||
s_instance = this;
|
||||
}
|
||||
|
||||
|
||||
QIcon
|
||||
ImageRegistry::icon( const QString& image, CalamaresUtils::ImageMode mode )
|
||||
{
|
||||
return pixmap( image, CalamaresUtils::defaultIconSize(), mode );
|
||||
}
|
||||
|
||||
|
||||
qint64
|
||||
ImageRegistry::cacheKey( const QSize& size, float opacity, QColor tint )
|
||||
{
|
||||
return size.width() * 100 + size.height() * 10 + ( opacity * 100.0 ) + tint.value();
|
||||
}
|
||||
|
||||
|
||||
QPixmap
|
||||
ImageRegistry::pixmap( const QString& image, const QSize& size, CalamaresUtils::ImageMode mode, float opacity, QColor tint )
|
||||
{
|
||||
QHash< qint64, QPixmap > subsubcache;
|
||||
QHash< int, QHash< qint64, QPixmap > > subcache;
|
||||
|
||||
if ( s_cache.contains( image ) )
|
||||
{
|
||||
subcache = s_cache.value( image );
|
||||
|
||||
if ( subcache.contains( mode ) )
|
||||
{
|
||||
subsubcache = subcache.value( mode );
|
||||
|
||||
const qint64 ck = cacheKey( size, opacity, tint );
|
||||
if ( subsubcache.contains( ck ) )
|
||||
{
|
||||
return subsubcache.value( ck );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Image not found in cache. Let's load it.
|
||||
QPixmap pixmap;
|
||||
if ( image.toLower().endsWith( ".svg" ) ||
|
||||
image.toLower().endsWith( ".svgz" ) )
|
||||
{
|
||||
QSvgRenderer svgRenderer( image );
|
||||
QPixmap p( size.isNull() ? svgRenderer.defaultSize() : size );
|
||||
p.fill( Qt::transparent );
|
||||
|
||||
QPainter pixPainter( &p );
|
||||
pixPainter.setOpacity( opacity );
|
||||
svgRenderer.render( &pixPainter );
|
||||
pixPainter.end();
|
||||
|
||||
if ( tint.alpha() > 0 )
|
||||
{
|
||||
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;
|
||||
}
|
||||
else
|
||||
pixmap = QPixmap( image );
|
||||
|
||||
if ( !pixmap.isNull() )
|
||||
{
|
||||
switch ( mode )
|
||||
{
|
||||
case CalamaresUtils::RoundedCorners:
|
||||
pixmap = CalamaresUtils::createRoundedImage( pixmap, size );
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if ( !size.isNull() && pixmap.size() != size )
|
||||
pixmap = pixmap.scaled( size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
|
||||
|
||||
putInCache( image, size, mode, opacity, pixmap, tint );
|
||||
}
|
||||
|
||||
return pixmap;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ImageRegistry::putInCache( const QString& image, const QSize& size, CalamaresUtils::ImageMode mode, float opacity, const QPixmap& pixmap, QColor tint )
|
||||
{
|
||||
cDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Adding to image cache:" << image << size << mode;
|
||||
|
||||
QHash< qint64, QPixmap > subsubcache;
|
||||
QHash< int, QHash< qint64, QPixmap > > subcache;
|
||||
|
||||
if ( s_cache.contains( image ) )
|
||||
{
|
||||
subcache = s_cache.value( image );
|
||||
|
||||
if ( subcache.contains( mode ) )
|
||||
{
|
||||
subsubcache = subcache.value( mode );
|
||||
|
||||
/* if ( subsubcache.contains( size.width() * size.height() ) )
|
||||
{
|
||||
Q_ASSERT( false );
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
subsubcache.insert( cacheKey( size, opacity, tint ), pixmap );
|
||||
subcache.insert( mode, subsubcache );
|
||||
s_cache.insert( image, subcache );
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/* === 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>
|
||||
*
|
||||
* Calamares 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.
|
||||
*
|
||||
* Calamares 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 Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IMAGE_REGISTRY_H
|
||||
#define IMAGE_REGISTRY_H
|
||||
|
||||
#include <QPixmap>
|
||||
|
||||
#include "utils/CalamaresUtilsGui.h"
|
||||
#include "UiDllMacro.h"
|
||||
|
||||
class UIDLLEXPORT ImageRegistry
|
||||
{
|
||||
public:
|
||||
static ImageRegistry* instance();
|
||||
|
||||
explicit ImageRegistry();
|
||||
|
||||
QIcon icon( const QString& image, CalamaresUtils::ImageMode mode = CalamaresUtils::Original );
|
||||
QPixmap pixmap( const QString& image, const QSize& size, CalamaresUtils::ImageMode mode = CalamaresUtils::Original, float opacity = 1.0, QColor tint = QColor( 0, 0, 0, 0 ) );
|
||||
|
||||
private:
|
||||
qint64 cacheKey( const QSize& size, float opacity, QColor tint );
|
||||
void putInCache( const QString& image, const QSize& size, CalamaresUtils::ImageMode mode, float opacity, const QPixmap& pixmap, QColor tint );
|
||||
|
||||
static ImageRegistry* s_instance;
|
||||
};
|
||||
|
||||
#endif // IMAGE_REGISTRY_H
|
@ -0,0 +1,50 @@
|
||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
||||
*
|
||||
* Calamares 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.
|
||||
*
|
||||
* Calamares 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 Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "PrepareCheckWidget.h"
|
||||
|
||||
#include "utils/CalamaresUtilsGui.h"
|
||||
#include "utils/Logger.h"
|
||||
|
||||
#include <QBoxLayout>
|
||||
|
||||
PrepareCheckWidget::PrepareCheckWidget( const QString &text,
|
||||
bool checked,
|
||||
QWidget* parent )
|
||||
: QWidget( parent )
|
||||
{
|
||||
QBoxLayout* mainLayout = new QHBoxLayout;
|
||||
setLayout( mainLayout );
|
||||
|
||||
m_iconLabel = new QLabel( this );
|
||||
mainLayout->addWidget( m_iconLabel );
|
||||
m_textLabel = new QLabel( text, this );
|
||||
mainLayout->addWidget( m_textLabel );
|
||||
m_textLabel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
|
||||
|
||||
if ( checked )
|
||||
m_iconLabel->setPixmap( CalamaresUtils::defaultPixmap( CalamaresUtils::Yes,
|
||||
CalamaresUtils::Original,
|
||||
QSize( m_iconLabel->height(),
|
||||
m_iconLabel->height() ) ) );
|
||||
else
|
||||
m_iconLabel->setPixmap( CalamaresUtils::defaultPixmap( CalamaresUtils::No,
|
||||
CalamaresUtils::Original,
|
||||
QSize( m_iconLabel->height(),
|
||||
m_iconLabel->height() ) ) );
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
||||
*
|
||||
* Calamares 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.
|
||||
*
|
||||
* Calamares 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 Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PREPARECHECKWIDGET_H
|
||||
#define PREPARECHECKWIDGET_H
|
||||
|
||||
#include <QLabel>
|
||||
|
||||
class PrepareCheckWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit PrepareCheckWidget( const QString &text,
|
||||
bool checked,
|
||||
QWidget* parent = nullptr );
|
||||
private:
|
||||
QLabel* m_textLabel;
|
||||
QLabel* m_iconLabel;
|
||||
};
|
||||
|
||||
#endif // PREPARECHECKWIDGET_H
|
Loading…
Reference in New Issue