1
/***************************************************************************
2
* Copyright (C) 2006 by Sascha Hlusiak *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
***************************************************************************/
24
#include <kimageeffect.h>
25
#include <qapplication.h>
26
#include <qdesktopwidget.h>
27
#include "imageholder.h"
28
#include "crystalclient.h"
31
QImageHolder::QImageHolder(QImage act,QImage inact)
32
:img_active(NULL),img_inactive(NULL)
35
setUserdefinedPictures( act,inact);
36
initialized=userdefinedActive && userdefinedInactive;
41
QImageHolder::~QImageHolder()
43
if (rootpixmap)delete rootpixmap;
44
if (img_active && !userdefinedActive)delete img_active;
45
if (img_inactive && !userdefinedInactive)delete img_inactive;
48
void QImageHolder::setUserdefinedPictures( QImage act,QImage inact)
50
int w=QApplication::desktop()->width();
51
int h=QApplication::desktop()->height();
52
if (img_active && !userdefinedActive)
57
if (img_inactive && !userdefinedInactive)
65
act=act.smoothScale(w,h);
66
img_active=ApplyEffect(act,&::factory->active,factory->options()->colorGroup(KDecoration::ColorTitleBar, true));
67
}else img_active=NULL;
70
inact=inact.smoothScale(w,h);
71
img_inactive=ApplyEffect(inact,&::factory->inactive,factory->options()->colorGroup(KDecoration::ColorTitleBar, false));
72
}else img_inactive=NULL;
74
userdefinedActive=(img_active!=NULL);
75
userdefinedInactive=(img_inactive!=NULL);
80
void QImageHolder::Init()
82
if (initialized)return;
84
rootpixmap=new KMyRootPixmap(NULL/*,this*/);
86
rootpixmap->repaint(true);
87
connect( rootpixmap,SIGNAL(backgroundUpdated(const QImage*)),this, SLOT(BackgroundUpdated(const QImage*)));
88
connect(kapp, SIGNAL(backgroundChanged(int)),SLOT(handleDesktopChanged(int)));
93
void QImageHolder::repaint(bool force)
96
if (rootpixmap)rootpixmap->repaint(force);
99
void QImageHolder::handleDesktopChanged(int)
104
void QImageHolder::CheckSanity()
106
if (!initialized)return;
107
if (userdefinedActive && userdefinedInactive)return;
108
if (img_active!=NULL && !userdefinedActive)return;
109
if (img_inactive!=NULL && !userdefinedInactive)return;
111
if (rootpixmap)delete rootpixmap;
117
QPixmap* QImageHolder::ApplyEffect(QImage &src,WND_CONFIG* cfg,QColorGroup colorgroup)
123
case 0: if (cfg->amount>0.99)return new QPixmap();
124
dst=KImageEffect::fade(src, cfg->amount, colorgroup.background());
126
case 1:dst=KImageEffect::channelIntensity(src,cfg->amount,KImageEffect::All);
128
case 2:dst=KImageEffect::intensity(src,cfg->amount);
130
case 3:dst=KImageEffect::desaturate(src,cfg->amount);
133
KImageEffect::solarize(dst,cfg->amount*100.0);
140
if (cfg->blur>0)dst=KImageEffect::blur(dst,0,cfg->blur);
142
return new QPixmap(dst);
145
void QImageHolder::BackgroundUpdated(const QImage *src)
147
if (img_active && !userdefinedActive)
152
if (img_inactive && !userdefinedInactive)
158
if (src && !src->isNull())
160
QImage tmp=src->copy();
162
if (!userdefinedInactive)
163
img_inactive=ApplyEffect(tmp,&::factory->inactive,factory->options()->colorGroup(KDecoration::ColorTitleBar, false));
166
if (!userdefinedActive)
167
img_active=ApplyEffect(tmp,&::factory->active,factory->options()->colorGroup(KDecoration::ColorTitleBar, true));
170
emit repaintNeeded();