2007-11-27 19:40:25 +00:00
|
|
|
/********************************************************************
|
2007-04-29 17:35:43 +00:00
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2007 Lubos Lunak <l.lunak@kde.org>
|
2007-11-13 16:20:52 +00:00
|
|
|
Copyright (C) 2007 Christian Nitschkowski <christian.nitschkowski@kdemail.net>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2007-11-27 19:40:25 +00:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#include "thumbnailaside.h"
|
|
|
|
|
|
|
|
#include <kactioncollection.h>
|
|
|
|
#include <kaction.h>
|
2007-11-13 16:20:52 +00:00
|
|
|
#include <kconfiggroup.h>
|
2007-04-29 17:35:43 +00:00
|
|
|
#include <klocale.h>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2007-05-28 11:16:18 +00:00
|
|
|
KWIN_EFFECT( thumbnailaside, ThumbnailAsideEffect )
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
ThumbnailAsideEffect::ThumbnailAsideEffect()
|
|
|
|
{
|
2007-11-13 16:20:52 +00:00
|
|
|
KConfigGroup conf = EffectsHandler::effectConfig("ThumbnailAside");
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
KActionCollection* actionCollection = new KActionCollection( this );
|
|
|
|
KAction* a = (KAction*)actionCollection->addAction( "ToggleCurrentThumbnail" );
|
|
|
|
a->setText( i18n("Toggle Thumbnail for Current Window" ));
|
2008-01-03 18:51:15 +00:00
|
|
|
a->setGlobalShortcut(KShortcut(Qt::CTRL + Qt::META + Qt::Key_T));
|
2007-04-29 17:35:43 +00:00
|
|
|
connect(a, SIGNAL(triggered(bool)), this, SLOT(toggleCurrentThumbnail()));
|
2007-11-13 16:20:52 +00:00
|
|
|
|
|
|
|
maxwidth = conf.readEntry("MaxWidth", 200);
|
|
|
|
spacing = conf.readEntry("Spacing", 10);
|
|
|
|
opacity = conf.readEntry("Opacity", 50) / 100.0;
|
2007-11-20 18:58:30 +00:00
|
|
|
screen = conf.readEntry("Screen",-1); // Xinerama screen TODO add gui option
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ThumbnailAsideEffect::paintScreen( int mask, QRegion region, ScreenPaintData& data )
|
|
|
|
{
|
|
|
|
effects->paintScreen( mask, region, data );
|
|
|
|
foreach( const Data& d, windows )
|
|
|
|
{
|
|
|
|
if( region.contains( d.rect ))
|
|
|
|
{
|
2007-08-08 14:42:06 +00:00
|
|
|
WindowPaintData data( d.window );
|
2007-04-29 17:35:43 +00:00
|
|
|
data.opacity = opacity;
|
|
|
|
QRect region;
|
|
|
|
setPositionTransformations( data, region, d.window, d.rect, Qt::KeepAspectRatio );
|
|
|
|
effects->drawWindow( d.window, PAINT_WINDOW_OPAQUE | PAINT_WINDOW_TRANSLUCENT | PAINT_WINDOW_TRANSFORMED,
|
|
|
|
region, data );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThumbnailAsideEffect::windowDamaged( EffectWindow* w, const QRect& )
|
|
|
|
{
|
|
|
|
foreach( const Data& d, windows )
|
|
|
|
{
|
|
|
|
if( d.window == w )
|
|
|
|
effects->addRepaint( d.rect );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThumbnailAsideEffect::windowGeometryShapeChanged( EffectWindow* w, const QRect& old )
|
|
|
|
{
|
|
|
|
if( w->size() == old.size())
|
|
|
|
{
|
|
|
|
foreach( const Data& d, windows )
|
|
|
|
{
|
|
|
|
if( d.window == w )
|
|
|
|
effects->addRepaint( d.rect );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
arrange();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThumbnailAsideEffect::windowClosed( EffectWindow* w )
|
|
|
|
{
|
|
|
|
removeThumbnail( w );
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThumbnailAsideEffect::toggleCurrentThumbnail()
|
|
|
|
{
|
|
|
|
EffectWindow* active = effects->activeWindow();
|
|
|
|
if( active == NULL )
|
|
|
|
return;
|
|
|
|
if( windows.contains( active ))
|
|
|
|
removeThumbnail( active );
|
|
|
|
else
|
|
|
|
addThumbnail( active );
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThumbnailAsideEffect::addThumbnail( EffectWindow* w )
|
|
|
|
{
|
|
|
|
repaintAll(); // repaint old areas
|
|
|
|
Data d;
|
|
|
|
d.window = w;
|
|
|
|
d.index = windows.count();
|
|
|
|
windows[ w ] = d;
|
|
|
|
arrange();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThumbnailAsideEffect::removeThumbnail( EffectWindow* w )
|
|
|
|
{
|
|
|
|
if( !windows.contains( w ))
|
|
|
|
return;
|
|
|
|
repaintAll(); // repaint old areas
|
|
|
|
int index = windows[ w ].index;
|
|
|
|
windows.remove( w );
|
|
|
|
for( QHash< EffectWindow*, Data >::Iterator it = windows.begin();
|
|
|
|
it != windows.end();
|
|
|
|
++it )
|
|
|
|
{
|
|
|
|
Data& d = *it;
|
|
|
|
if( d.index > index )
|
|
|
|
--d.index;
|
|
|
|
}
|
|
|
|
arrange();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThumbnailAsideEffect::arrange()
|
|
|
|
{
|
|
|
|
int height = 0;
|
|
|
|
QVector< int > pos( windows.size());
|
|
|
|
int mwidth = 0;
|
|
|
|
foreach( const Data& d, windows )
|
|
|
|
{
|
|
|
|
height += d.window->height();
|
|
|
|
mwidth = qMax( mwidth, d.window->width());
|
|
|
|
pos[ d.index ] = d.window->height();
|
|
|
|
}
|
2007-11-20 18:58:30 +00:00
|
|
|
QRect area = effects->clientArea( WorkArea, screen, effects->currentDesktop());
|
2007-09-03 15:00:43 +00:00
|
|
|
double scale = area.height() / double( height );
|
|
|
|
scale = qMin( scale, maxwidth / double( mwidth )); // don't be wider than maxwidth pixels
|
2007-04-29 17:35:43 +00:00
|
|
|
int add = 0;
|
|
|
|
for( int i = 0;
|
|
|
|
i < windows.size();
|
|
|
|
++i )
|
|
|
|
{
|
|
|
|
pos[ i ] = int( pos[ i ] * scale );
|
|
|
|
pos[ i ] += spacing + add; // compute offset of each item
|
|
|
|
add = pos[ i ];
|
|
|
|
}
|
|
|
|
for( QHash< EffectWindow*, Data >::Iterator it = windows.begin();
|
|
|
|
it != windows.end();
|
|
|
|
++it )
|
|
|
|
{
|
|
|
|
Data& d = *it;
|
|
|
|
int width = int( d.window->width() * scale );
|
|
|
|
d.rect = QRect( area.right() - width, area.bottom() - pos[ d.index ], width, int( d.window->height() * scale ));
|
|
|
|
}
|
|
|
|
repaintAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThumbnailAsideEffect::repaintAll()
|
|
|
|
{
|
|
|
|
foreach( const Data& d, windows )
|
|
|
|
effects->addRepaint( d.rect );
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#include "thumbnailaside.moc"
|