31 lines
785 B
C++
31 lines
785 B
C++
#include "psxicon.h"
|
|
#include <QPainter>
|
|
|
|
PSXIcon::PSXIcon( Icon *icon, QWidget *parent ) : QWidget( parent ) {
|
|
this->icon = icon;
|
|
setFixedSize( 64, 64 );
|
|
}
|
|
|
|
void PSXIcon::setIcon( Icon *icon ) {
|
|
this->icon = icon;
|
|
}
|
|
|
|
void PSXIcon::paintEvent( QPaintEvent *event ) {
|
|
QImage image( 16, 16, QImage::Format_Indexed8 );
|
|
image.setNumColors( 16 );
|
|
for( int i = 0; i < 16; i++ ) {
|
|
RGB col = this->icon->paletteColor( i );
|
|
QRgb rgb = QColor::fromRgb( col.r, col.g, col.b ).rgb();
|
|
image.setColor( i, rgb );
|
|
}
|
|
for( int x = 0; x < 16; x++ ) {
|
|
for( int y = 0; y < 16; y++ ) {
|
|
image.setPixel( x, y, icon->pixel( x, y ) );
|
|
}
|
|
}
|
|
QRectF target(0.0, 0.0, 64.0, 64.0);
|
|
QRectF source(0.0, 0.0, 16.0, 16.0);
|
|
QPainter painter( this );
|
|
painter.drawImage(target, image, source);
|
|
|
|
}
|