23 #include "kfadewidgeteffect_p.h"
27 #include <QtCore/QEvent>
28 #include <QtGui/QPaintEngine>
29 #include <QtGui/QPainter>
33 #if defined(Q_WS_X11) && defined(HAVE_XRENDER)
34 # include <X11/Xlib.h>
35 # include <X11/extensions/Xrender.h>
41 KFadeWidgetEffectPrivate::KFadeWidgetEffectPrivate(
QWidget *_destWidget)
42 : destWidget(_destWidget), disabled(false)
50 QPixmap KFadeWidgetEffectPrivate::transition(
const QPixmap &from,
const QPixmap &to, qreal amount)
const
52 const int value = int(0xff * amount);
61 color.setAlphaF(amount);
64 if (from.paintEngine()->hasFeature(QPaintEngine::PorterDuff) &&
65 from.paintEngine()->hasFeature(QPaintEngine::BlendModes))
72 p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
73 p.fillRect(over.rect(), color);
77 p.setCompositionMode(QPainter::CompositionMode_DestinationOut);
78 p.fillRect(under.rect(), color);
79 p.setCompositionMode(QPainter::CompositionMode_Plus);
80 p.drawPixmap(0, 0, over);
85 #if defined(Q_WS_X11) && defined(HAVE_XRENDER)
86 else if (from.paintEngine()->hasFeature(QPaintEngine::PorterDuff))
99 QPixmap source(to), destination(from);
102 destination.detach();
104 Display *dpy = QX11Info::display();
106 XRenderPictFormat *format = XRenderFindStandardFormat(dpy, PictStandardA8);
107 XRenderPictureAttributes pa;
111 Pixmap pixmap = XCreatePixmap(dpy, destination.handle(), 1, 1, 8);
112 Picture alpha = XRenderCreatePicture(dpy, pixmap, format, CPRepeat, &pa);
113 XFreePixmap(dpy, pixmap);
117 xcolor.alpha = quint16(0xffff * amount);
118 XRenderFillRectangle(dpy, PictOpSrc, alpha, &xcolor, 0, 0, 1, 1);
121 XRenderComposite(dpy, PictOpOutReverse, alpha, None, destination.x11PictureHandle(),
122 0, 0, 0, 0, 0, 0, destination.width(), destination.height());
125 XRenderComposite(dpy, PictOpAdd, source.x11PictureHandle(), alpha,
126 destination.x11PictureHandle(),
127 0, 0, 0, 0, 0, 0, destination.width(), destination.height());
129 XRenderFreePicture(dpy, alpha);
136 QImage under = from.toImage();
137 QImage over = to.toImage();
141 p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
142 p.fillRect(over.rect(), color);
146 p.setCompositionMode(QPainter::CompositionMode_DestinationOut);
147 p.fillRect(under.rect(), color);
148 p.setCompositionMode(QPainter::CompositionMode_Plus);
149 p.drawImage(0, 0, over);
152 return QPixmap::fromImage(under);
157 :
QWidget(destWidget ? destWidget->parentWidget() : 0),
158 d_ptr(new KFadeWidgetEffectPrivate(destWidget))
162 Q_ASSERT(destWidget && destWidget->parentWidget());
163 if (!destWidget || !destWidget->parentWidget() || !destWidget->isVisible() ||
169 setGeometry(
QRect(destWidget->mapTo(parentWidget(),
QPoint(0, 0)), destWidget->size()));
170 d->oldPixmap = QPixmap::grabWidget(destWidget);
171 d->timeLine.setFrameRange(0, 255);
172 d->timeLine.setCurveShape(QTimeLine::EaseOutCurve);
173 connect(&d->timeLine, SIGNAL(finished()), SLOT(finished()));
174 connect(&d->timeLine, SIGNAL(frameChanged(
int)), SLOT(repaint()));
183 void KFadeWidgetEffectPrivate::finished()
186 destWidget->setUpdatesEnabled(
false);
189 destWidget->setUpdatesEnabled(
true);
199 d->newPixmap = QPixmap::grabWidget(d->destWidget);
200 d->timeLine.setDuration(duration);
208 p.drawPixmap(rect(), d->transition(d->oldPixmap, d->newPixmap, d->timeLine.currentValue()));
212 #include "moc_kfadewidgeteffect.cpp"
static GraphicEffects graphicEffectsLevel()
This function determines the desired level of effects on the GUI.
GUI with simple animations enabled.