2014-07-01 11:48:10 +02:00
|
|
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
|
|
|
*
|
2015-04-02 12:49:40 +02:00
|
|
|
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
2014-07-01 11:48:10 +02:00
|
|
|
*
|
|
|
|
* 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 "CalamaresUtilsGui.h"
|
|
|
|
|
2014-08-26 15:18:30 +02:00
|
|
|
#include "ImageRegistry.h"
|
|
|
|
|
|
|
|
#include <QBrush>
|
2014-07-08 13:22:09 +02:00
|
|
|
#include <QFont>
|
|
|
|
#include <QFontMetrics>
|
2014-07-01 11:48:10 +02:00
|
|
|
#include <QLayout>
|
2014-08-26 15:18:30 +02:00
|
|
|
#include <QPainter>
|
|
|
|
#include <QPen>
|
2014-07-01 11:48:10 +02:00
|
|
|
|
|
|
|
namespace CalamaresUtils
|
|
|
|
{
|
|
|
|
|
2014-07-08 13:22:09 +02:00
|
|
|
static int s_defaultFontSize = 0;
|
|
|
|
static int s_defaultFontHeight = 0;
|
|
|
|
|
|
|
|
|
2014-08-26 15:18:30 +02:00
|
|
|
|
|
|
|
QPixmap
|
|
|
|
defaultPixmap( ImageType type, ImageMode mode, const QSize& size )
|
|
|
|
{
|
|
|
|
QPixmap pixmap;
|
|
|
|
|
|
|
|
switch ( type )
|
|
|
|
{
|
2015-04-02 12:49:40 +02:00
|
|
|
case Yes:
|
|
|
|
pixmap = ImageRegistry::instance()->pixmap( RESPATH "images/yes.svgz", size );
|
|
|
|
break;
|
2014-08-26 15:18:30 +02:00
|
|
|
|
2015-04-02 12:49:40 +02:00
|
|
|
case No:
|
|
|
|
pixmap = ImageRegistry::instance()->pixmap( RESPATH "images/no.svgz", size );
|
|
|
|
break;
|
2014-08-26 15:18:30 +02:00
|
|
|
|
2015-04-02 12:49:40 +02:00
|
|
|
case Information:
|
|
|
|
pixmap = ImageRegistry::instance()->pixmap( RESPATH "images/information.svgz", size );
|
|
|
|
break;
|
2014-08-26 18:21:16 +02:00
|
|
|
|
2015-04-02 12:49:40 +02:00
|
|
|
case Fail:
|
|
|
|
pixmap = ImageRegistry::instance()->pixmap( RESPATH "images/fail.svgz", size );
|
|
|
|
break;
|
2014-08-26 18:21:16 +02:00
|
|
|
|
2015-04-02 12:49:40 +02:00
|
|
|
case Bugs:
|
|
|
|
pixmap = ImageRegistry::instance()->pixmap( RESPATH "images/bugs.svg", size );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Help:
|
|
|
|
pixmap = ImageRegistry::instance()->pixmap( RESPATH "images/help.svg", size );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Release:
|
|
|
|
pixmap = ImageRegistry::instance()->pixmap( RESPATH "images/release.svg", size );
|
|
|
|
break;
|
|
|
|
|
2015-04-02 14:03:12 +02:00
|
|
|
case PartitionAlongside:
|
|
|
|
pixmap = ImageRegistry::instance()->pixmap( RESPATH "images/partition-alongside.svg", size );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PartitionEraseAuto:
|
|
|
|
pixmap = ImageRegistry::instance()->pixmap( RESPATH "images/partition-erase-auto.svg", size );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PartitionManual:
|
|
|
|
pixmap = ImageRegistry::instance()->pixmap( RESPATH "images/partition-manual.svg", size );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PartitionReplaceOs:
|
|
|
|
pixmap = ImageRegistry::instance()->pixmap( RESPATH "images/partition-replace-os.svg", size );
|
|
|
|
break;
|
|
|
|
|
2015-04-02 12:49:40 +02:00
|
|
|
default:
|
|
|
|
break;
|
2014-08-26 15:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( pixmap.isNull() )
|
|
|
|
{
|
|
|
|
Q_ASSERT( false );
|
|
|
|
return QPixmap();
|
|
|
|
}
|
|
|
|
|
|
|
|
return pixmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QPixmap
|
|
|
|
createRoundedImage( const QPixmap& pixmap, const QSize& size, float frameWidthPct )
|
|
|
|
{
|
|
|
|
int height;
|
|
|
|
int width;
|
|
|
|
|
|
|
|
if ( !size.isEmpty() )
|
|
|
|
{
|
|
|
|
height = size.height();
|
|
|
|
width = size.width();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
height = pixmap.height();
|
|
|
|
width = pixmap.width();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !height || !width )
|
|
|
|
return QPixmap();
|
|
|
|
|
|
|
|
QPixmap scaledAvatar = pixmap.scaled( width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
|
|
|
|
if ( frameWidthPct == 0.00 )
|
|
|
|
return scaledAvatar;
|
|
|
|
|
|
|
|
QPixmap frame( width, height );
|
|
|
|
frame.fill( Qt::transparent );
|
|
|
|
|
|
|
|
QPainter painter( &frame );
|
|
|
|
painter.setRenderHint( QPainter::Antialiasing );
|
|
|
|
|
|
|
|
QRect outerRect( 0, 0, width, height );
|
|
|
|
QBrush brush( scaledAvatar );
|
|
|
|
QPen pen;
|
|
|
|
pen.setColor( Qt::transparent );
|
|
|
|
pen.setJoinStyle( Qt::RoundJoin );
|
|
|
|
|
|
|
|
painter.setBrush( brush );
|
|
|
|
painter.setPen( pen );
|
|
|
|
painter.drawRoundedRect( outerRect, frameWidthPct * 100.0, frameWidthPct * 100.0, Qt::RelativeSize );
|
|
|
|
|
|
|
|
/* painter.setBrush( Qt::transparent );
|
|
|
|
painter.setPen( Qt::white );
|
|
|
|
painter.drawRoundedRect( outerRect, frameWidthPct, frameWidthPct, Qt::RelativeSize ); */
|
|
|
|
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-01 11:48:10 +02:00
|
|
|
void
|
|
|
|
unmarginLayout( QLayout* layout )
|
|
|
|
{
|
|
|
|
layout->setContentsMargins( 0, 0, 0, 0 );
|
|
|
|
layout->setMargin( 0 );
|
|
|
|
layout->setSpacing( 0 );
|
|
|
|
|
|
|
|
for ( int i = 0; i < layout->count(); i++ )
|
|
|
|
{
|
|
|
|
QLayout* childLayout = layout->itemAt( i )->layout();
|
|
|
|
if ( childLayout )
|
|
|
|
unmarginLayout( childLayout );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-08 13:22:09 +02:00
|
|
|
|
|
|
|
int
|
|
|
|
defaultFontSize()
|
|
|
|
{
|
|
|
|
return s_defaultFontSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
defaultFontHeight()
|
|
|
|
{
|
|
|
|
if ( s_defaultFontHeight <= 0 )
|
|
|
|
{
|
|
|
|
QFont f;
|
|
|
|
f.setPointSize( defaultFontSize() );
|
|
|
|
s_defaultFontHeight = QFontMetrics( f ).height();
|
|
|
|
}
|
|
|
|
|
|
|
|
return s_defaultFontHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
setDefaultFontSize( int points )
|
|
|
|
{
|
|
|
|
s_defaultFontSize = points;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QSize
|
|
|
|
defaultIconSize()
|
|
|
|
{
|
|
|
|
const int w = defaultFontHeight() * 1.6;
|
|
|
|
return QSize( w, w );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-01 11:48:10 +02:00
|
|
|
}
|