int main(int argc, char *argv[]) { QApplication a(argc, argv); QPixmap startPixmap(":/new/icon/icon/flower.gif"); startPixmap.size(); QSplashScreen splash(startPixmap); splash.show(); for(long i=0; i<100000000;i++); MainWindow w; w.show(); splash.finish(&w); QMediaPlayer *player = new QMediaPlayer; player->setMedia(QUrl::fromUserInput("qrc:/new/sound/1.wav")); player->setVolume(50); player->play(); return a.exec(); }
QPixmap transition(const QPixmap &from, const QPixmap &to, qreal amount) { if (from.isNull() && to.isNull()) { return from; } if (qFuzzyCompare(amount + 1, qreal(1.0))) { return from; } QRect startRect(from.rect()); QRect targetRect(to.rect()); QSize pixmapSize = startRect.size().expandedTo(targetRect.size()); QRect toRect = QRect(QPoint(0,0), pixmapSize); targetRect.moveCenter(toRect.center()); startRect.moveCenter(toRect.center()); //paint to in the center of from QColor color; color.setAlphaF(amount); // If the native paint engine supports Porter/Duff compositing and CompositionMode_Plus QPaintEngine *paintEngine = from.paintEngine(); if (paintEngine && paintEngine->hasFeature(QPaintEngine::PorterDuff) && paintEngine->hasFeature(QPaintEngine::BlendModes)) { QPixmap startPixmap(pixmapSize); startPixmap.fill(Qt::transparent); QPixmap targetPixmap(pixmapSize); targetPixmap.fill(Qt::transparent); QPainter p; p.begin(&targetPixmap); p.drawPixmap(targetRect, to); p.setCompositionMode(QPainter::CompositionMode_DestinationIn); p.fillRect(targetRect, color); p.end(); p.begin(&startPixmap); p.drawPixmap(startRect, from); p.setCompositionMode(QPainter::CompositionMode_DestinationOut); p.fillRect(startRect, color); p.setCompositionMode(QPainter::CompositionMode_Plus); p.drawPixmap(targetRect, targetPixmap); p.end(); return startPixmap; } #if defined(Q_WS_X11) && defined(HAVE_XRENDER) // We have Xrender support else if (paintEngine && paintEngine->hasFeature(QPaintEngine::PorterDuff)) { // QX11PaintEngine doesn't implement CompositionMode_Plus in Qt 4.3, // which we need to be able to do a transition from one pixmap to // another. // // In order to avoid the overhead of converting the pixmaps to images // and doing the operation entirely in software, this function has a // specialized path for X11 that uses Xrender directly to do the // transition. This operation can be fully accelerated in HW. // // This specialization can be removed when QX11PaintEngine supports // CompositionMode_Plus. QPixmap source(targetPixmap), destination(startPixmap); source.detach(); destination.detach(); Display *dpy = QX11Info::display(); XRenderPictFormat *format = XRenderFindStandardFormat(dpy, PictStandardA8); XRenderPictureAttributes pa; pa.repeat = 1; // RepeatNormal // Create a 1x1 8 bit repeating alpha picture Pixmap pixmap = XCreatePixmap(dpy, destination.handle(), 1, 1, 8); Picture alpha = XRenderCreatePicture(dpy, pixmap, format, CPRepeat, &pa); XFreePixmap(dpy, pixmap); // Fill the alpha picture with the opacity value XRenderColor xcolor; xcolor.alpha = quint16(0xffff * amount); XRenderFillRectangle(dpy, PictOpSrc, alpha, &xcolor, 0, 0, 1, 1); // Reduce the alpha of the destination with 1 - opacity XRenderComposite(dpy, PictOpOutReverse, alpha, None, destination.x11PictureHandle(), 0, 0, 0, 0, 0, 0, destination.width(), destination.height()); // Add source * opacity to the destination XRenderComposite(dpy, PictOpAdd, source.x11PictureHandle(), alpha, destination.x11PictureHandle(), toRect.x(), toRect.y(), 0, 0, 0, 0, destination.width(), destination.height()); XRenderFreePicture(dpy, alpha); return destination; } #endif else { // Fall back to using QRasterPaintEngine to do the transition. QImage under(pixmapSize, QImage::Format_ARGB32_Premultiplied); under.fill(Qt::transparent); QImage over(pixmapSize, QImage::Format_ARGB32_Premultiplied); over.fill(Qt::transparent); QPainter p; p.begin(&over); p.drawPixmap(targetRect, to); p.setCompositionMode(QPainter::CompositionMode_DestinationIn); p.fillRect(over.rect(), color); p.end(); p.begin(&under); p.drawPixmap(startRect, from); p.setCompositionMode(QPainter::CompositionMode_DestinationOut); p.fillRect(startRect, color); p.setCompositionMode(QPainter::CompositionMode_Plus); p.drawImage(toRect.topLeft(), over); p.end(); return QPixmap::fromImage(under); } }