2007-03-27 14:26:30 +00:00
|
|
|
/*****************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
|
|
|
|
|
|
|
|
You can Freely distribute this program under the GNU General Public
|
|
|
|
License. See the file "COPYING" for the exact licensing terms.
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#include "demo_taskbarthumbnail.h"
|
|
|
|
|
2007-04-12 13:12:11 +00:00
|
|
|
#include <limits.h>
|
2007-03-27 14:26:30 +00:00
|
|
|
|
2007-04-05 12:07:35 +00:00
|
|
|
namespace KWin
|
2007-03-27 14:26:30 +00:00
|
|
|
{
|
|
|
|
|
2007-04-13 10:08:18 +00:00
|
|
|
KWIN_EFFECT( Demo_TaskbarThumbnail, TaskbarThumbnailEffect )
|
2007-04-12 13:12:11 +00:00
|
|
|
|
2007-03-27 14:26:30 +00:00
|
|
|
TaskbarThumbnailEffect::TaskbarThumbnailEffect()
|
|
|
|
{
|
|
|
|
mLastCursorPos = QPoint(-1, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TaskbarThumbnailEffect::prePaintScreen( int* mask, QRegion* region, int time )
|
|
|
|
{
|
|
|
|
// We might need to paint thumbnails if cursor has moved since last
|
|
|
|
// painting or some thumbnails were painted the last time
|
|
|
|
QPoint cpos = cursorPos();
|
|
|
|
if(cpos != mLastCursorPos || mThumbnails.count() > 0)
|
|
|
|
{
|
2007-04-12 13:12:11 +00:00
|
|
|
*mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
|
2007-03-27 14:26:30 +00:00
|
|
|
mThumbnails.clear();
|
|
|
|
mLastCursorPos = cpos;
|
|
|
|
}
|
|
|
|
|
|
|
|
effects->prePaintScreen(mask, region, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TaskbarThumbnailEffect::prePaintWindow( EffectWindow* w, int* mask, QRegion* paint, QRegion* clip, int time )
|
|
|
|
{
|
2007-04-12 13:12:11 +00:00
|
|
|
QRect iconGeo = w->iconGeometry();
|
|
|
|
if(iconGeo.contains( mLastCursorPos ))
|
|
|
|
mThumbnails.append( w );
|
2007-03-27 14:26:30 +00:00
|
|
|
|
|
|
|
effects->prePaintWindow( w, mask, paint, clip, time );
|
|
|
|
}
|
|
|
|
|
|
|
|
void TaskbarThumbnailEffect::postPaintScreen()
|
|
|
|
{
|
|
|
|
// Paint the thumbnails. They need to be painted after other windows
|
|
|
|
// because we want them on top of everything else
|
|
|
|
int space = 4;
|
|
|
|
foreach( EffectWindow* w, mThumbnails )
|
|
|
|
{
|
2007-04-12 13:12:11 +00:00
|
|
|
QRect thumb = getThumbnailPosition( w, &space);
|
2007-03-27 14:26:30 +00:00
|
|
|
WindowPaintData thumbdata;
|
2007-04-12 13:12:11 +00:00
|
|
|
thumbdata.xTranslate = thumb.x() - w->x();
|
|
|
|
thumbdata.yTranslate = thumb.y() - w->y();
|
|
|
|
thumbdata.xScale = thumb.width() / (float)w->width();
|
|
|
|
thumbdata.yScale = thumb.height() / (float)w->height();
|
2007-03-27 14:26:30 +00:00
|
|
|
// From Scene::Window::infiniteRegion()
|
|
|
|
QRegion infRegion = QRegion( INT_MIN / 2, INT_MIN / 2, INT_MAX, INT_MAX );
|
2007-04-12 13:12:11 +00:00
|
|
|
effects->paintWindow( w, PAINT_WINDOW_TRANSFORMED, infRegion, thumbdata );
|
2007-03-27 14:26:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Call the next effect.
|
|
|
|
effects->postPaintScreen();
|
|
|
|
}
|
|
|
|
|
2007-04-12 13:12:11 +00:00
|
|
|
QRect TaskbarThumbnailEffect::getThumbnailPosition( EffectWindow* c, int* space ) const
|
2007-03-27 14:26:30 +00:00
|
|
|
{
|
|
|
|
QRect thumb;
|
|
|
|
QRect icon = c->iconGeometry();
|
|
|
|
|
|
|
|
// Try to figure out if taskbar is horizontal or vertical
|
|
|
|
if( icon.right() < 40 || ( displayWidth() - icon.left()) < 40 )
|
|
|
|
{
|
|
|
|
// Vertical taskbar...
|
|
|
|
float scale = qMin(qMax(icon.height(), 100) / (float)c->height(), 200.0f / c->width());
|
|
|
|
thumb.setSize( QSize( int(scale * c->width()),int(scale * c->height()) ));
|
|
|
|
if( icon.right() < 40 ) // ...on the left
|
|
|
|
thumb.moveTopLeft( QPoint( icon.right() + *space, icon.top() ));
|
|
|
|
else // ...on the right
|
|
|
|
thumb.moveTopRight( QPoint( icon.left() - *space, icon.top()));
|
|
|
|
*space += thumb.width() + 8;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Horizontal taskbar...
|
|
|
|
float scale = qMin(qMax(icon.width(), 75) / (float)c->width(), 200.0f / c->height());
|
|
|
|
thumb.setSize( QSize( int(scale * c->width()),int(scale * c->height()) ));
|
|
|
|
if( icon.top() < ( displayHeight() - icon.bottom())) // ...at the top
|
|
|
|
thumb.moveTopLeft( QPoint( icon.left(), icon.bottom() + *space ));
|
|
|
|
else // ...at the bottom
|
|
|
|
thumb.moveBottomLeft( QPoint( icon.left(), icon.top() - *space ));
|
|
|
|
*space += thumb.height() + 8;
|
|
|
|
}
|
|
|
|
return thumb;
|
|
|
|
}
|
|
|
|
|
2007-04-14 16:10:58 +00:00
|
|
|
void TaskbarThumbnailEffect::cursorMoved( const QPoint& pos, Qt::MouseButtons )
|
|
|
|
{
|
|
|
|
// this should check if the mouse position change actually means something
|
|
|
|
// (just like it should be done in prePaintScreen()), but since this effect
|
|
|
|
// will be replaced in the future, just trigger a repaint
|
|
|
|
if( pos != mLastCursorPos )
|
|
|
|
effects->addRepaintFull();
|
|
|
|
}
|
2007-03-27 14:26:30 +00:00
|
|
|
|
2007-04-14 16:10:58 +00:00
|
|
|
} // namespace
|