QPixmap QS60StylePrivate::part(QS60StyleEnums::SkinParts part, const QSize &size, QPainter *painter, QS60StylePrivate::SkinElementFlags flags) { Q_UNUSED(painter); const QString partKey = QS60Style::partKeys().at(part); const QPicture partPicture = QS60StyleModeSpecifics::m_partPictures.value(partKey); QSize partSize(partPicture.boundingRect().size()); if (flags & (SF_PointEast | SF_PointWest)) { const int temp = partSize.width(); partSize.setWidth(partSize.height()); partSize.setHeight(temp); } const qreal scaleX = size.width() / (qreal)partSize.width(); const qreal scaleY = size.height() / (qreal)partSize.height(); QImage partImage(size, QImage::Format_ARGB32); partImage.fill(Qt::transparent); QPainter resultPainter(&partImage); QTransform t; if (flags & SF_PointEast) t.translate(size.width(), 0); else if (flags & SF_PointSouth) t.translate(size.width(), size.height()); else if (flags & SF_PointWest) t.translate(0, size.height()); t.scale(scaleX, scaleY); if (flags & SF_PointEast) t.rotate(90); else if (flags & SF_PointSouth) t.rotate(180); else if (flags & SF_PointWest) t.rotate(270); resultPainter.setTransform(t, true); const_cast<QPicture *>(&partPicture)->play(&resultPainter); resultPainter.end(); QPixmap result = QPixmap::fromImage(partImage); if (flags & SF_StateDisabled) { QStyleOption opt; QPalette *themePalette = QS60StylePrivate::themePalette(); if (themePalette) opt.palette = *themePalette; result = QApplication::style()->generatedIconPixmap(QIcon::Disabled, result, &opt); } return result; }
// addDropShadow is inspired by QPixmapDropShadowFilter::draw in // qt/src/gui/effects/qpixmapfilter.cpp QPixmap addDropShadow( const QPixmap& source, const QSize& targetSize ) { const QPoint offset( 2, 4 ); const int radius = 4; const QColor shadowColor( 100, 100, 100, 100 ); // If there is no targetSize, then return a larger pixmap with the shadow added on // otherwise, return a bounded pixmap and shrink the source const QSize sizeToUse = targetSize.isEmpty() ? QSize( source.width() + offset.x() + radius, source.height() + offset.y() + radius ) : targetSize; const QSize shrunkToFit( sizeToUse.width() - offset.x() - radius, sizeToUse.height() - offset.y() - radius ); const QPixmap shrunk = source.scaled( shrunkToFit, Qt::KeepAspectRatio, Qt::SmoothTransformation ); QImage tmp( sizeToUse, QImage::Format_ARGB32_Premultiplied ); tmp.fill( 0 ); QPainter tmpPainter( &tmp ); tmpPainter.setCompositionMode( QPainter::CompositionMode_Source ); tmpPainter.drawPixmap( offset, shrunk ); tmpPainter.end(); // blur the alpha channel QImage blurred( sizeToUse, QImage::Format_ARGB32_Premultiplied ); blurred.fill( 0 ); QPainter blurPainter( &blurred ); qt_blurImage( &blurPainter, tmp, radius, false, true ); blurPainter.end(); // blacken the image... QPainter blackenPainter( &blurred ); blackenPainter.setCompositionMode( QPainter::CompositionMode_SourceIn ); blackenPainter.fillRect( blurred.rect(), shadowColor ); blackenPainter.end(); const QRect resultRect( shrunk.rect().united( shrunk.rect().translated( offset ).adjusted( -radius, -radius, radius, radius ) ) ); QPixmap result( resultRect.size() ); result.fill( Qt::transparent ); QPainter resultPainter( &result ); // draw the blurred drop shadow... resultPainter.drawImage( 0, 0, blurred ); // Draw the actual pixmap... resultPainter.drawPixmap( 0, 0, shrunk ); return result; }
void CCell::UpdateView() { Helper * help = Helper::Instance(); if( isVisible && unit != s_original ) { QImage source( ":/" + help->GetItemNameByState( hextype ) ); QImage destination( ":/" + help->GetItemNameByState( unit ) ); //destination = destination.scaled( button->width(), button->height() ); QPainter resultPainter(&source); resultPainter.setCompositionMode( QPainter::CompositionMode_SourceOver ); resultPainter.drawImage( 0, 0, destination ); resultPainter.end(); button->setIcon( QIcon( QPixmap::fromImage( source ) ) ); } else { button->setIcon( QIcon(":/" + help->GetItemNameByVisible( isVisible, hextype ) ) ); //button->setText( "1" ); } }