~ubuntu-branches/ubuntu/saucy/kwin-style-crystal/saucy-proposed

« back to all changes in this revision

Viewing changes to client/imageholder.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Pino Toscano
  • Date: 2009-04-13 16:10:20 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090413161020-sfv3it91oo26artc
Tags: 2.0.3-1
* New upstream release, aimed for KDE 4. (Closes: #522569)
  - Update dependencies to KDE 4.
  - Switch rules to pkg-kde-tools + CDBS.
* Set the kde-extras team as maintainer, putting Hai Zaar and myself as
  uploaders.
* Update copyright, adopt the DEP 5 (r48).
* Bump compat to 7.
* Bump Standards-Version to 3.8.1, no changes required.
* Remove dirs file, unneeded.
* Add Homepage field in control.
* Remove old conflict with 'crystal' package, not even present in Etch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *   Copyright (C) 2006 by Sascha Hlusiak                                  *
3
 
 *   Spam84@gmx.de                                                         *
4
 
 *                                                                         *
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.                                   *
9
 
 *                                                                         *
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.                          *
14
 
 *                                                                         *
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
 
 ***************************************************************************/
20
 
 
21
 
 
22
 
#include <kapp.h>
23
 
#include <qimage.h>
24
 
#include <kimageeffect.h>
25
 
#include <qapplication.h>
26
 
#include <qdesktopwidget.h>
27
 
#include "imageholder.h"
28
 
#include "crystalclient.h"
29
 
 
30
 
 
31
 
QImageHolder::QImageHolder(QImage act,QImage inact)
32
 
:img_active(NULL),img_inactive(NULL)
33
 
{
34
 
        rootpixmap=NULL;
35
 
        setUserdefinedPictures( act,inact);
36
 
        initialized=userdefinedActive && userdefinedInactive;
37
 
 
38
 
        emit repaintNeeded();
39
 
}
40
 
 
41
 
QImageHolder::~QImageHolder()
42
 
{
43
 
        if (rootpixmap)delete rootpixmap;
44
 
        if (img_active && !userdefinedActive)delete img_active;
45
 
        if (img_inactive && !userdefinedInactive)delete img_inactive;
46
 
}
47
 
 
48
 
void QImageHolder::setUserdefinedPictures( QImage act,QImage inact)
49
 
{
50
 
        int w=QApplication::desktop()->width();
51
 
        int h=QApplication::desktop()->height();
52
 
        if (img_active && !userdefinedActive)
53
 
        {
54
 
                delete img_active;      
55
 
                img_active=NULL;
56
 
        }
57
 
        if (img_inactive && !userdefinedInactive)
58
 
        {
59
 
                delete img_inactive;
60
 
                img_inactive=NULL;
61
 
        }
62
 
 
63
 
        if (!act.isNull())
64
 
        {
65
 
                act=act.smoothScale(w,h);
66
 
                img_active=ApplyEffect(act,&::factory->active,factory->options()->colorGroup(KDecoration::ColorTitleBar, true)); 
67
 
        }else img_active=NULL;
68
 
        if (!inact.isNull())
69
 
        {
70
 
                inact=inact.smoothScale(w,h);
71
 
                img_inactive=ApplyEffect(inact,&::factory->inactive,factory->options()->colorGroup(KDecoration::ColorTitleBar, false)); 
72
 
        }else img_inactive=NULL;
73
 
 
74
 
        userdefinedActive=(img_active!=NULL);
75
 
        userdefinedInactive=(img_inactive!=NULL);
76
 
 
77
 
        CheckSanity();
78
 
}
79
 
 
80
 
void QImageHolder::Init()
81
 
{
82
 
        if (initialized)return;
83
 
        
84
 
        rootpixmap=new KMyRootPixmap(NULL/*,this*/);
85
 
        rootpixmap->start();
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)));
89
 
        
90
 
        initialized=true;
91
 
}
92
 
 
93
 
void QImageHolder::repaint(bool force)
94
 
{
95
 
        Init(); 
96
 
        if (rootpixmap)rootpixmap->repaint(force);
97
 
}
98
 
 
99
 
void QImageHolder::handleDesktopChanged(int)
100
 
{
101
 
        repaint(true);
102
 
}
103
 
 
104
 
void QImageHolder::CheckSanity()
105
 
{
106
 
        if (!initialized)return;
107
 
        if (userdefinedActive && userdefinedInactive)return;
108
 
        if (img_active!=NULL && !userdefinedActive)return;
109
 
        if (img_inactive!=NULL && !userdefinedInactive)return;
110
 
 
111
 
        if (rootpixmap)delete rootpixmap;
112
 
        rootpixmap=NULL;
113
 
        
114
 
        initialized=false;
115
 
}
116
 
 
117
 
QPixmap* QImageHolder::ApplyEffect(QImage &src,WND_CONFIG* cfg,QColorGroup colorgroup)
118
 
{
119
 
        QImage dst;
120
 
        
121
 
        switch(cfg->mode)
122
 
        {
123
 
        case 0: if (cfg->amount>0.99)return new QPixmap();
124
 
                dst=KImageEffect::fade(src, cfg->amount, colorgroup.background());
125
 
                break;
126
 
        case 1:dst=KImageEffect::channelIntensity(src,cfg->amount,KImageEffect::All);
127
 
                break;
128
 
        case 2:dst=KImageEffect::intensity(src,cfg->amount);
129
 
                break;
130
 
        case 3:dst=KImageEffect::desaturate(src,cfg->amount);
131
 
                break;
132
 
        case 4: dst=src;
133
 
                KImageEffect::solarize(dst,cfg->amount*100.0);
134
 
                break;
135
 
 
136
 
        default:dst=src;
137
 
                break;  
138
 
        }
139
 
 
140
 
        if (cfg->blur>0)dst=KImageEffect::blur(dst,0,cfg->blur);
141
 
        
142
 
        return new QPixmap(dst);
143
 
}
144
 
 
145
 
void QImageHolder::BackgroundUpdated(const QImage *src)
146
 
{
147
 
        if (img_active && !userdefinedActive)
148
 
        {
149
 
                delete img_active;
150
 
                img_active=NULL;
151
 
        }
152
 
        if (img_inactive && !userdefinedInactive)
153
 
        {
154
 
                delete img_inactive;
155
 
                img_inactive=NULL;
156
 
        }
157
 
        
158
 
        if (src && !src->isNull())
159
 
        {
160
 
                QImage tmp=src->copy();
161
 
 
162
 
                if (!userdefinedInactive)
163
 
                        img_inactive=ApplyEffect(tmp,&::factory->inactive,factory->options()->colorGroup(KDecoration::ColorTitleBar, false));
164
 
 
165
 
                tmp=src->copy();                
166
 
                if (!userdefinedActive)
167
 
                        img_active=ApplyEffect(tmp,&::factory->active,factory->options()->colorGroup(KDecoration::ColorTitleBar, true));
168
 
        }
169
 
        
170
 
        emit repaintNeeded();
171
 
}