[PATCH] Make kslideshow.kss work again
- Date: Thu, 1 May 2008 13:42:06 +0200
- From: Arno <arno@xxxxxxxxxxxxx>
- Subject: [PATCH] Make kslideshow.kss work again
Hello,
When I finally installed kde 4.0.3 I noticed that the kslideshow.kss
screensaver didn't work any more. It only painted blank screens.
It tried to paint outside a paintEvent. The attached patch fixes this. Maybe
it would have been enough to just put a
setAttribute(Qt::WA_PaintOutsidePaintEvent) in the constructor, but that
would make it non-portable and mostly, it wouldn't have been fun.
Now it paints inside the paintEvent. While at it, I also removed all the
bitBlt-calls, since bitBlt is deprecated and replaced them with drawPixmap.
While at it, I included the proper qt4-headers.
This fixes bug 158016.
--
Regards,
Arno.
--- slideshow.cpp.old 2008-05-01 13:13:07.631248708 +0200
+++ slideshow.cpp 2008-05-01 13:16:55.302795417 +0200
@@ -10,18 +10,19 @@
*/
-#include <qdir.h>
-#include <qcolor.h>
-#include <qlabel.h>
-#include <qlayout.h>
-#include <qfile.h>
-#include <qcheckbox.h>
-#include <qcombobox.h>
-#include <qspinbox.h>
-#include <qdesktopwidget.h>
+#include <QDir>
+#include <QColor>
+#include <QLabel>
+#include <QLayout>
+#include <QFile>
+#include <QCheckBox>
+#include <QComboBox>
+#include <QSpinBox>
+#include <QDesktopWidget>
#include <QImage>
#include <QPixmap>
#include <QPolygon>
+#include <QPainterPath>
#include <kconfig.h>
@@ -103,7 +104,6 @@
mEffectRunning = false;
- mTimer.start(10, true);
connect(&mTimer, SIGNAL(timeout()), SLOT(slotTimeout()));
QDesktopWidget *d = QApplication::desktop();
@@ -119,7 +119,9 @@
{
mGeoList.append(mScreenGeo(width(), height(), 0, 0));
}
+ setAttribute(Qt::WA_NoSystemBackground);
createNextScreen();
+ mTimer.start(10, true);
}
@@ -194,7 +196,6 @@
if (aInit)
{
- startPainter();
mw = width();
mh = height();
mx = mw;
@@ -211,11 +212,11 @@
if (mAlpha < 0)
{
- mPainter.end();
showNextScreen();
return -1;
}
+ QPainter p(this);
for (alpha=mAlpha, i=mi; i>=0; i--, alpha+=mfd)
{
x = (mw>>1) + (int)(mfy * cos(-alpha));
@@ -226,8 +227,14 @@
pa.setPoint(1, x, y);
pa.setPoint(2, mx, my);
+
+ QPainterPath ppath;
+ ppath.addPolygon(pa);
- mPainter.drawPolygon(pa);
+ QBrush brush;
+ brush.setPixmap(mNextScreen);
+ p.setBrush(brush);
+ p.fillPath(ppath, brush);
}
mAlpha -= mfx;
@@ -240,7 +247,6 @@
{
if (aInit)
{
- startPainter();
mw = width();
mh = height();
mix = mw / 8;
@@ -259,7 +265,6 @@
if (mi==0 && mx0>=mx1)
{
- mPainter.end();
showNextScreen();
return -1;
}
@@ -293,8 +298,9 @@
my0 += miy;
}
- bitBlt(this, mx, my, &mNextScreen, mx, my, mix, miy);
-
+ QPainter p(this);
+ p.drawPixmap(mx, my, mNextScreen, mx, my, mix, miy);
+
mx += mdx;
my += mdy;
mj--;
@@ -329,8 +335,8 @@
if (y >= mh) continue;
done = false;
if ((KRandom::random()&15) < 6) continue;
- bitBlt(this, x, y+mdy, this, x, y, mdx, mh-y-mdy);
- bitBlt(this, x, y, &mNextScreen, x, y, mdx, mdy);
+ QPainter p(this);
+ p.drawPixmap(x, y, mNextScreen, x, y, mdx, mdy);
mIntArray[i] += mdy;
}
@@ -353,7 +359,6 @@
if (aInit)
{
- startPainter();
mw = width();
mh = height();
mx = mw;
@@ -367,7 +372,6 @@
if (mAlpha < 0)
{
- mPainter.end();
showNextScreen();
return -1;
}
@@ -381,7 +385,15 @@
pa.setPoint(1, x, y);
pa.setPoint(2, mx, my);
- mPainter.drawPolygon(pa);
+ QPainterPath ppath;
+ ppath.addPolygon(pa);
+
+ QBrush brush;
+ brush.setPixmap(mNextScreen);
+ QPainter p(this);
+ p.setBrush(brush);
+
+ p.fillPath(ppath, brush);
return 20;
}
@@ -405,6 +417,7 @@
my = (mSubType==3 ? 0 : mh);
}
+ QPainter p(this);
if (mSubType==0 || mSubType==1)
{
// horizontal sweep
@@ -415,7 +428,7 @@
}
for (w=2,i=4,x=mx; i>0; i--, w<<=1, x-=mdx)
{
- bitBlt(this, x, 0, &mNextScreen, x, 0, w, mh);
+ p.drawPixmap(x, 0, mNextScreen, x, 0, w, mh);
}
mx += mdx;
}
@@ -429,7 +442,7 @@
}
for (h=2,i=4,y=my; i>0; i--, h<<=1, y-=mdy)
{
- bitBlt(this, 0, y, &mNextScreen, 0, y, mw, h);
+ p.drawPixmap(0, y, mNextScreen, 0, y, mw, h);
}
my += mdy;
}
@@ -445,7 +458,6 @@
if (aInit)
{
- startPainter();
mAlpha = M_PI * 2;
mw = width();
mh = height();
@@ -454,7 +466,6 @@
if (mi <= 0)
{
- mPainter.end();
showNextScreen();
return -1;
}
@@ -463,7 +474,15 @@
my = KRandom::random() % mh;
r = (KRandom::random() % 200) + 50;
- mPainter.drawEllipse(mx-r, my-r, r, r);
+ QPainterPath ppath;
+ ppath.addEllipse(mx-r, my-r, r, r);
+ QBrush brush;
+ brush.setPixmap(mNextScreen);
+
+ QPainter p(this);
+ p.setBrush(brush);
+ p.fillPath(ppath, brush);
+
mi--;
return 10;
@@ -481,11 +500,12 @@
h = height() >> fact;
sz = 1 << fact;
+ QPainter p(this);
for (i = (w*h)<<1; i > 0; i--)
{
x = (KRandom::random() % w) << fact;
y = (KRandom::random() % h) << fact;
- bitBlt(this, x, y, &mNextScreen, x, y, sz, sz);
+ p.drawPixmap(x, y, mNextScreen, x, y, sz, sz);
}
showNextScreen();
@@ -496,6 +516,7 @@
//----------------------------------------------------------------------------
int kSlideShowSaver::effectGrowing(bool aInit)
{
+ QPainter p(this);
if (aInit)
{
mw = width();
@@ -510,14 +531,17 @@
mx = (mw>>1) - (int)(mi * mfx);
my = (mh>>1) - (int)(mi * mfy);
mi++;
-
+
if (mx<0 || my<0)
{
showNextScreen();
return -1;
}
-
- bitBlt(this, mx, my, &mNextScreen, mx, my,
+
+ if((mw - (mx<<1) == 0) && (mh - (my<<1) == 0))
+ return 1;
+
+ p.drawPixmap(mx, my, mNextScreen, mx, my,
mw - (mx<<1), mh - (my<<1));
return 20;
@@ -554,11 +578,12 @@
miy = miy ? 0 : mdy;
my = my ? 0 : mdy;
+ QPainter p(this);
for (y=0; y<mw; y+=(mdy<<1))
{
- bitBlt(this, mix, y+miy, &mNextScreen, mix, y+miy,
+ p.drawPixmap(mix, y+miy, mNextScreen, mix, y+miy,
mdx, mdy);
- bitBlt(this, mx, y+my, &mNextScreen, mx, y+my,
+ p.drawPixmap(mx, y+my, mNextScreen, mx, y+my,
mdx, mdy);
}
@@ -595,22 +620,27 @@
x1 = mw - mx;
y1 = mh - my;
mi++;
+
+ if((mx == 0) && (my == 0))
+ return 1; // otherwise drawPixmap draws the bottom-right of mNextScreen
+ QPainter p;
+ p.begin(this);
if (mSubType)
{
// moving image edges
- bitBlt(this, 0, 0, &mNextScreen, mix-mx, miy-my, mx, my);
- bitBlt(this, x1, 0, &mNextScreen, mix, miy-my, mx, my);
- bitBlt(this, 0, y1, &mNextScreen, mix-mx, miy, mx, my);
- bitBlt(this, x1, y1, &mNextScreen, mix, miy, mx, my);
+ p.drawPixmap(0, 0, mNextScreen, mix-mx, miy-my, mx, my);
+ p.drawPixmap(x1, 0, mNextScreen, mix, miy-my, mx, my);
+ p.drawPixmap(0, y1, mNextScreen, mix-mx, miy, mx, my);
+ p.drawPixmap(x1, y1, mNextScreen, mix, miy, mx, my);
}
else
{
// fixed image edges
- bitBlt(this, 0, 0, &mNextScreen, 0, 0, mx, my);
- bitBlt(this, x1, 0, &mNextScreen, x1, 0, mx, my);
- bitBlt(this, 0, y1, &mNextScreen, 0, y1, mx, my);
- bitBlt(this, x1, y1, &mNextScreen, x1, y1, mx, my);
+ p.drawPixmap(0, 0, mNextScreen, 0, 0, mx, my);
+ p.drawPixmap(x1, 0, mNextScreen, x1, 0, mx, my);
+ p.drawPixmap(0, y1, mNextScreen, 0, y1, mx, my);
+ p.drawPixmap(x1, y1, mNextScreen, x1, y1, mx, my);
}
return 20;
}
@@ -631,9 +661,10 @@
if (iyPos[mi] < 0) return -1;
+ QPainter p(this);
for (y=iyPos[mi]; y<mh; y+=8)
{
- bitBlt(this, 0, y, &mNextScreen, 0, y, mw, 1);
+ p.drawPixmap(0, y, mNextScreen, 0, y, mw, 1);
}
mi++;
@@ -657,9 +688,10 @@
if (ixPos[mi] < 0) return -1;
+ QPainter p(this);
for (x=ixPos[mi]; x<mw; x+=8)
{
- bitBlt(this, x, 0, &mNextScreen, x, 0, 1, mh);
+ p.drawPixmap(x, 0, mNextScreen, x, 0, 1, mh);
}
mi++;
@@ -669,18 +701,6 @@
//-----------------------------------------------------------------------------
-void kSlideShowSaver::startPainter(Qt::PenStyle aPen)
-{
- QBrush brush;
- brush.setPixmap(mNextScreen);
- if (mPainter.isActive()) mPainter.end();
- mPainter.begin(this);
- mPainter.setBrush(brush);
- mPainter.setPen(aPen);
-}
-
-
-//-----------------------------------------------------------------------------
void kSlideShowSaver::restart()
{
mEffectRunning = false;
@@ -693,6 +713,13 @@
//-----------------------------------------------------------------------------
void kSlideShowSaver::slotTimeout()
{
+ update();
+}
+
+
+//-----------------------------------------------------------------------------
+void kSlideShowSaver::paintEvent(QPaintEvent *)
+{
int tmout = -1;
int i;
@@ -724,7 +751,8 @@
//----------------------------------------------------------------------------
void kSlideShowSaver::showNextScreen()
{
- bitBlt(this, 0, 0, &mNextScreen, 0, 0,
+ QPainter p(this);
+ p.drawPixmap(0, 0, mNextScreen, 0, 0,
mNextScreen.width(), mNextScreen.height());
}
--- slideshow.h.old 2008-05-01 13:13:16.633547111 +0200
+++ slideshow.h 2008-05-01 13:38:19.771388072 +0200
@@ -7,11 +7,11 @@
#ifndef SLIDESHOW_H
#define SLIDESHOW_H
-#include <qtimer.h>
-#include <qstringlist.h>
-#include <qpixmap.h>
-#include <qpainter.h>
-#include <qimage.h>
+#include <QTimer>
+#include <QStringList>
+#include <QPixmap>
+#include <QPainter>
+#include <QImage>
#include <kscreensaver.h>
#include <kdialog.h>
@@ -86,9 +86,7 @@
int effectMultiCircleOut(bool doInit);
protected:
- /** Init mPainter with next-screen's pixmap and call
- mPainter.begin(&mWidget) */
- void startPainter(Qt::PenStyle penStyle=Qt::NoPen);
+ void paintEvent(QPaintEvent *);
protected:
struct mScreenGeo {
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<