From 5fff9923ec698d58ac6e5a8c5979fc4071143568 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 22 Aug 2008 09:40:46 +0000 Subject: [PATCH] Magiclamp supports now panels which are not positioned at the bottom of the screen. svn path=/trunk/KDE/kdebase/workspace/; revision=850763 --- effects/magiclamp.cpp | 157 +++++++++++++++++++++++++++++++++++------- effects/magiclamp.h | 8 +++ 2 files changed, 140 insertions(+), 25 deletions(-) diff --git a/effects/magiclamp.cpp b/effects/magiclamp.cpp index 20e9af9a72..8f38898b3b 100644 --- a/effects/magiclamp.cpp +++ b/effects/magiclamp.cpp @@ -86,37 +86,144 @@ void MagicLampEffect::paintWindow( EffectWindow* w, int mask, QRegion region, Wi QRect icon = w->iconGeometry(); // If there's no icon geometry, minimize to the center of the screen if( !icon.isValid() ) - icon = QRect( displayWidth() / 2, displayHeight() / 2, 0, 0 ); + icon = QRect( displayWidth() / 2, displayHeight(), 0, 0 ); + + QRect area = effects->clientArea( PlacementArea, w ); + IconPosition position = Bottom; + // top + if( icon.y() + icon.height() <= area.y() ) + { + position = Top; + } + // bottom + if( icon.y() >= area.y()+area.height() ) + { + position = Bottom; + } + // left + if( icon.x() + icon.width() <= area.x() ) + { + position = Left; + } + // right + if( icon.x() >= area.x()+ area.width() ) + { + position = Right; + } WindowQuadList newQuads; foreach( WindowQuad quad, data.quads ) { - // quadFactor defines how fast a quad is vertically moved: y coordinates near to window top are slowed down - // it is used as quadFactor^3/windowHeight^3 - // quadFactor is the y position of the quad but is changed towards becomming the window height - // by that the factor becomes 1 and has no influence any more - float quadFactor = quad[0].y() + (geo.height() - quad[0].y())*progress; - // how far has a quad to be moved? Distance between icon and window multiplied by the progress and by the quadFactor - float yOffsetTop = (icon.y() + quad[0].y() - geo.y())*progress* - ((quadFactor*quadFactor*quadFactor)/(geo.height()*geo.height()*geo.height())); - quadFactor = quad[2].y() + (geo.height() - quad[2].y())*progress; - float yOffsetBottom = (icon.y() + quad[2].y() - geo.y())*progress* - ((quadFactor*quadFactor*quadFactor)/(geo.height()*geo.height()*geo.height())); - // top and bottom progress is the factor which defines how far the x values have to be changed - // factor is the current moved y value diveded by the distance between icon and window - float topProgress = qMin( yOffsetTop/(icon.y()+icon.height() - geo.y()-(float)(quad[0].y()/geo.height()*geo.height())), 1.0f ); - float bottomProgress = qMin( yOffsetBottom/(icon.y()+icon.height() - geo.y()-(float)(quad[2].y()/geo.height()*geo.height())), 1.0f ); + if( position == Top || position == Bottom ) + { + // quadFactor defines how fast a quad is vertically moved: y coordinates near to window top are slowed down + // it is used as quadFactor^3/windowHeight^3 + // quadFactor is the y position of the quad but is changed towards becomming the window height + // by that the factor becomes 1 and has no influence any more + float quadFactor; + // how far has a quad to be moved? Distance between icon and window multiplied by the progress and by the quadFactor + float yOffsetTop; + float yOffsetBottom; + // top and bottom progress is the factor which defines how far the x values have to be changed + // factor is the current moved y value diveded by the distance between icon and window + float topProgress; + float bottomProgress; + if( position == Bottom ) + { + quadFactor = quad[0].y() + (geo.height() - quad[0].y())*progress; + yOffsetTop = (icon.y() + quad[0].y() - geo.y())*progress* + ((quadFactor*quadFactor*quadFactor)/(geo.height()*geo.height()*geo.height())); + quadFactor = quad[2].y() + (geo.height() - quad[2].y())*progress; + yOffsetBottom = (icon.y() + quad[2].y() - geo.y())*progress* + ((quadFactor*quadFactor*quadFactor)/(geo.height()*geo.height()*geo.height())); + topProgress = qMin( yOffsetTop/(icon.y()+icon.height() - geo.y()-(float)(quad[0].y()/geo.height()*geo.height())), 1.0f ); + bottomProgress = qMin( yOffsetBottom/(icon.y()+icon.height() - geo.y()-(float)(quad[2].y()/geo.height()*geo.height())), 1.0f ); + } + else + { + quadFactor = geo.height() - quad[0].y() + (quad[0].y())*progress; + yOffsetTop = (geo.y() - icon.height() + geo.height() + quad[0].y() - icon.y())*progress* + ((quadFactor*quadFactor*quadFactor)/(geo.height()*geo.height()*geo.height())); + quadFactor = geo.height() - quad[2].y() + (quad[2].y())*progress; + yOffsetBottom = (geo.y() - icon.height() + geo.height() + quad[2].y() - icon.y())*progress* + ((quadFactor*quadFactor*quadFactor)/(geo.height()*geo.height()*geo.height())); + topProgress = qMin( yOffsetTop/(geo.y() - icon.height() + geo.height() - icon.y() - + (float)((geo.height()-quad[0].y())/geo.height()*geo.height())), 1.0f ); + bottomProgress = qMin( yOffsetBottom/(geo.y() - icon.height() + geo.height() - icon.y() - + (float)((geo.height()-quad[2].y())/geo.height()*geo.height())), 1.0f ); + } + if( position == Top ) + { + yOffsetTop *= -1; + yOffsetBottom *= -1; + } + if( topProgress < 0 ) + topProgress *= -1; + if( bottomProgress < 0 ) + bottomProgress *= -1; - // x values are moved towards the center of the icon - quad[0].setX( (icon.x() + icon.width()*(quad[0].x()/geo.width()) - (quad[0].x() + geo.x()))*topProgress + quad[0].x() ); - quad[1].setX( (icon.x() + icon.width()*(quad[1].x()/geo.width()) - (quad[1].x() + geo.x()))*topProgress + quad[1].x() ); - quad[2].setX( (icon.x() + icon.width()*(quad[2].x()/geo.width()) - (quad[2].x() + geo.x()))*bottomProgress + quad[2].x() ); - quad[3].setX( (icon.x() + icon.width()*(quad[3].x()/geo.width()) - (quad[3].x() + geo.x()))*bottomProgress + quad[3].x() ); + // x values are moved towards the center of the icon + quad[0].setX( (icon.x() + icon.width()*(quad[0].x()/geo.width()) - (quad[0].x() + geo.x()))*topProgress + quad[0].x() ); + quad[1].setX( (icon.x() + icon.width()*(quad[1].x()/geo.width()) - (quad[1].x() + geo.x()))*topProgress + quad[1].x() ); + quad[2].setX( (icon.x() + icon.width()*(quad[2].x()/geo.width()) - (quad[2].x() + geo.x()))*bottomProgress + quad[2].x() ); + quad[3].setX( (icon.x() + icon.width()*(quad[3].x()/geo.width()) - (quad[3].x() + geo.x()))*bottomProgress + quad[3].x() ); - quad[0].setY( quad[0].y() + yOffsetTop ); - quad[1].setY( quad[1].y() + yOffsetTop ); - quad[2].setY( quad[2].y() + yOffsetBottom ); - quad[3].setY( quad[3].y() + yOffsetBottom ); + quad[0].setY( quad[0].y() + yOffsetTop ); + quad[1].setY( quad[1].y() + yOffsetTop ); + quad[2].setY( quad[2].y() + yOffsetBottom ); + quad[3].setY( quad[3].y() + yOffsetBottom ); + } + else + { + float quadFactor; + float xOffsetLeft; + float xOffsetRight; + float leftProgress; + float rightProgress; + if( position == Right ) + { + quadFactor = quad[0].x() + (geo.width() - quad[0].x())*progress; + xOffsetLeft = (icon.x() + quad[0].x() - geo.x())*progress* + ((quadFactor*quadFactor*quadFactor)/(geo.width()*geo.width()*geo.width())); + quadFactor = quad[1].x() + (geo.width() - quad[1].x())*progress; + xOffsetRight = (icon.x() + quad[1].x() - geo.x())*progress* + ((quadFactor*quadFactor*quadFactor)/(geo.width()*geo.width()*geo.width())); + leftProgress = qMin( xOffsetLeft/(icon.x()+icon.width() - geo.x()-(float)(quad[0].x()/geo.width()*geo.width())), 1.0f ); + rightProgress = qMin( xOffsetRight/(icon.x()+icon.width() - geo.x()-(float)(quad[1].x()/geo.width()*geo.width())), 1.0f ); + } + else + { + quadFactor = geo.width() - quad[0].x() + (quad[0].x())*progress; + xOffsetLeft = (geo.x() - icon.width() + geo.width() + quad[0].x() - icon.x())*progress* + ((quadFactor*quadFactor*quadFactor)/(geo.width()*geo.width()*geo.width())); + quadFactor = geo.width() - quad[1].x() + (quad[1].x())*progress; + xOffsetRight = (geo.x() - icon.width() + geo.width() + quad[1].x() - icon.x())*progress* + ((quadFactor*quadFactor*quadFactor)/(geo.width()*geo.width()*geo.width())); + leftProgress = qMin( xOffsetLeft/(geo.x() - icon.width() + geo.width() - icon.x() - + (float)((geo.width()-quad[0].x())/geo.width()*geo.width())), 1.0f ); + rightProgress = qMin( xOffsetRight/(geo.x() - icon.width() + geo.width() - icon.x() - + (float)((geo.width()-quad[1].x())/geo.width()*geo.width())), 1.0f ); + } + if( position == Left ) + { + xOffsetLeft *= -1; + xOffsetRight *= -1; + } + if( leftProgress < 0 ) + leftProgress *= -1; + if( rightProgress < 0 ) + rightProgress *= -1; + + quad[0].setY( (icon.y() + icon.height()*(quad[0].y()/geo.height()) - (quad[0].y() + geo.y()))*leftProgress + quad[0].y() ); + quad[1].setY( (icon.y() + icon.height()*(quad[1].y()/geo.height()) - (quad[1].y() + geo.y()))*rightProgress + quad[1].y() ); + quad[2].setY( (icon.y() + icon.height()*(quad[2].y()/geo.height()) - (quad[2].y() + geo.y()))*rightProgress + quad[2].y() ); + quad[3].setY( (icon.y() + icon.height()*(quad[3].y()/geo.height()) - (quad[3].y() + geo.y()))*leftProgress + quad[3].y() ); + + quad[0].setX( quad[0].x() + xOffsetLeft ); + quad[1].setX( quad[1].x() + xOffsetRight ); + quad[2].setX( quad[2].x() + xOffsetRight ); + quad[3].setX( quad[3].x() + xOffsetLeft ); + } newQuads.append( quad ); } data.quads = newQuads; diff --git a/effects/magiclamp.h b/effects/magiclamp.h index fc60a4893e..087a74070f 100644 --- a/effects/magiclamp.h +++ b/effects/magiclamp.h @@ -43,6 +43,14 @@ class MagicLampEffect private: QHash< EffectWindow*, TimeLine > mTimeLineWindows; int mActiveAnimations; + + enum IconPosition + { + Top, + Bottom, + Left, + Right + }; }; } // namespace