1 /********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 2007 Lubos Lunak <l.lunak@kde.org>
6 Copyright (C) 2007 Christian Nitschkowski <christian.nitschkowski@kdemail.net>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *********************************************************************/
22 #include "thumbnailaside.h"
24 #include <kactioncollection.h>
26 #include <kconfiggroup.h>
32 KWIN_EFFECT( thumbnailaside
, ThumbnailAsideEffect
)
34 ThumbnailAsideEffect::ThumbnailAsideEffect()
36 KActionCollection
* actionCollection
= new KActionCollection( this );
37 KAction
* a
= (KAction
*)actionCollection
->addAction( "ToggleCurrentThumbnail" );
38 a
->setText( i18n("Toggle Thumbnail for Current Window" ));
39 a
->setGlobalShortcut(KShortcut(Qt::CTRL
+ Qt::META
+ Qt::Key_T
));
40 connect(a
, SIGNAL(triggered(bool)), this, SLOT(toggleCurrentThumbnail()));
41 reconfigure( ReconfigureAll
);
44 void ThumbnailAsideEffect::reconfigure( ReconfigureFlags
)
46 KConfigGroup conf
= EffectsHandler::effectConfig("ThumbnailAside");
47 maxwidth
= conf
.readEntry("MaxWidth", 200);
48 spacing
= conf
.readEntry("Spacing", 10);
49 opacity
= conf
.readEntry("Opacity", 50) / 100.0;
50 screen
= conf
.readEntry("Screen",-1); // Xinerama screen TODO add gui option
54 void ThumbnailAsideEffect::paintScreen( int mask
, QRegion region
, ScreenPaintData
& data
)
56 effects
->paintScreen( mask
, region
, data
);
57 foreach( const Data
& d
, windows
)
59 if( region
.contains( d
.rect
))
61 WindowPaintData
data( d
.window
);
62 data
.opacity
= opacity
;
64 setPositionTransformations( data
, region
, d
.window
, d
.rect
, Qt::KeepAspectRatio
);
65 effects
->drawWindow( d
.window
, PAINT_WINDOW_OPAQUE
| PAINT_WINDOW_TRANSLUCENT
| PAINT_WINDOW_TRANSFORMED
,
71 void ThumbnailAsideEffect::windowDamaged( EffectWindow
* w
, const QRect
& )
73 foreach( const Data
& d
, windows
)
76 effects
->addRepaint( d
.rect
);
80 void ThumbnailAsideEffect::windowGeometryShapeChanged( EffectWindow
* w
, const QRect
& old
)
82 foreach( const Data
& d
, windows
)
86 if( w
->size() == old
.size())
87 effects
->addRepaint( d
.rect
);
95 void ThumbnailAsideEffect::windowClosed( EffectWindow
* w
)
100 void ThumbnailAsideEffect::toggleCurrentThumbnail()
102 EffectWindow
* active
= effects
->activeWindow();
105 if( windows
.contains( active
))
106 removeThumbnail( active
);
108 addThumbnail( active
);
111 void ThumbnailAsideEffect::addThumbnail( EffectWindow
* w
)
113 repaintAll(); // repaint old areas
116 d
.index
= windows
.count();
121 void ThumbnailAsideEffect::removeThumbnail( EffectWindow
* w
)
123 if( !windows
.contains( w
))
125 repaintAll(); // repaint old areas
126 int index
= windows
[ w
].index
;
128 for( QHash
< EffectWindow
*, Data
>::Iterator it
= windows
.begin();
133 if( d
.index
> index
)
139 void ThumbnailAsideEffect::arrange()
141 if( windows
.size() == 0 )
144 QVector
< int > pos( windows
.size());
146 foreach( const Data
& d
, windows
)
148 height
+= d
.window
->height();
149 mwidth
= qMax( mwidth
, d
.window
->width());
150 pos
[ d
.index
] = d
.window
->height();
152 QRect area
= effects
->clientArea( MaximizeArea
, screen
, effects
->currentDesktop());
153 double scale
= area
.height() / double( height
);
154 scale
= qMin( scale
, maxwidth
/ double( mwidth
)); // don't be wider than maxwidth pixels
160 pos
[ i
] = int( pos
[ i
] * scale
);
161 pos
[ i
] += spacing
+ add
; // compute offset of each item
164 for( QHash
< EffectWindow
*, Data
>::Iterator it
= windows
.begin();
169 int width
= int( d
.window
->width() * scale
);
170 d
.rect
= QRect( area
.right() - width
, area
.bottom() - pos
[ d
.index
], width
, int( d
.window
->height() * scale
));
175 void ThumbnailAsideEffect::repaintAll()
177 foreach( const Data
& d
, windows
)
178 effects
->addRepaint( d
.rect
);
183 #include "thumbnailaside.moc"