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.
|
|
|
|
|
2007-11-27 19:40:25 +00:00
|
|
|
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
|
|
|
|
2007-12-17 14:14:53 +00:00
|
|
|
#include <kwinconfig.h>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#include "magnifier.h"
|
|
|
|
|
|
|
|
#include <kaction.h>
|
|
|
|
#include <kactioncollection.h>
|
2007-11-13 16:20:52 +00:00
|
|
|
#include <kconfiggroup.h>
|
2007-04-29 17:35:43 +00:00
|
|
|
#include <kstandardaction.h>
|
|
|
|
|
2007-12-17 14:14:53 +00:00
|
|
|
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
|
2007-04-29 17:35:43 +00:00
|
|
|
#include <GL/gl.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2007-05-28 11:16:18 +00:00
|
|
|
KWIN_EFFECT( magnifier, MagnifierEffect )
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
const int FRAME_WIDTH = 5;
|
|
|
|
|
|
|
|
MagnifierEffect::MagnifierEffect()
|
|
|
|
: zoom( 1 )
|
|
|
|
, target_zoom( 1 )
|
|
|
|
{
|
2007-11-13 16:20:52 +00:00
|
|
|
KConfigGroup conf = EffectsHandler::effectConfig("Magnifier");
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
KActionCollection* actionCollection = new KActionCollection( this );
|
|
|
|
KAction* a;
|
|
|
|
a = static_cast< KAction* >( actionCollection->addAction( KStandardAction::ZoomIn, this, SLOT( zoomIn())));
|
|
|
|
a->setGlobalShortcut(KShortcut(Qt::META + Qt::Key_Equal));
|
|
|
|
a = static_cast< KAction* >( actionCollection->addAction( KStandardAction::ZoomOut, this, SLOT( zoomOut())));
|
|
|
|
a->setGlobalShortcut(KShortcut(Qt::META + Qt::Key_Minus));
|
|
|
|
a = static_cast< KAction* >( actionCollection->addAction( KStandardAction::ActualSize, this, SLOT( toggle())));
|
|
|
|
a->setGlobalShortcut(KShortcut(Qt::META + Qt::Key_0));
|
2007-11-13 16:20:52 +00:00
|
|
|
|
|
|
|
int width, height;
|
|
|
|
width = conf.readEntry("Width", 200);
|
|
|
|
height = conf.readEntry("Height", 200);
|
|
|
|
magnifier_size = QSize( width, height );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
2007-07-07 14:01:32 +00:00
|
|
|
void MagnifierEffect::prePaintScreen( ScreenPrePaintData& data, int time )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
if( zoom != target_zoom )
|
|
|
|
{
|
2007-09-03 15:00:43 +00:00
|
|
|
double diff = time / 500.0;
|
2007-04-29 17:35:43 +00:00
|
|
|
if( target_zoom > zoom )
|
2007-09-03 15:00:43 +00:00
|
|
|
zoom = qMin( zoom * qMax( 1 + diff, 1.2 ), target_zoom );
|
2007-04-29 17:35:43 +00:00
|
|
|
else
|
2007-09-03 15:00:43 +00:00
|
|
|
zoom = qMax( zoom * qMin( 1 - diff, 0.8 ), target_zoom );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2007-07-07 14:01:32 +00:00
|
|
|
effects->prePaintScreen( data, time );
|
2007-08-08 15:54:21 +00:00
|
|
|
if( zoom != 1.0 )
|
|
|
|
data.paint |= magnifierArea().adjusted( -FRAME_WIDTH, -FRAME_WIDTH, FRAME_WIDTH, FRAME_WIDTH );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MagnifierEffect::paintScreen( int mask, QRegion region, ScreenPaintData& data )
|
|
|
|
{
|
|
|
|
ScreenPaintData data2 = data;
|
|
|
|
effects->paintScreen( mask, region, data ); // paint normal screen
|
|
|
|
if( zoom != 1.0 )
|
|
|
|
{ // paint magnifier
|
|
|
|
QRect area = magnifierArea();
|
2008-02-25 11:32:21 +00:00
|
|
|
PaintClipper::push( area ); // don't allow any painting outside of the area
|
2007-04-29 17:35:43 +00:00
|
|
|
mask |= PAINT_SCREEN_TRANSFORMED;
|
|
|
|
data2.xScale *= zoom;
|
|
|
|
data2.yScale *= zoom;
|
|
|
|
QPoint cursor = cursorPos();
|
|
|
|
// set the position so that the cursor is in the same position in the scaled view
|
|
|
|
data2.xTranslate = - int( cursor.x() * ( zoom - 1 ));
|
|
|
|
data2.yTranslate = - int( cursor.y() * ( zoom - 1 ));
|
|
|
|
effects->paintScreen( mask, region, data2 );
|
2008-02-25 11:32:21 +00:00
|
|
|
PaintClipper::pop( area );
|
|
|
|
// ## TODO this should be inside KWIN_HAVE_OPENGL_COMPOSITING
|
2007-04-29 17:35:43 +00:00
|
|
|
glPushAttrib( GL_CURRENT_BIT );
|
|
|
|
glColor4f( 0, 0, 0, 1 ); // black
|
2008-02-25 11:32:21 +00:00
|
|
|
for( PaintClipper::Iterator iterator;
|
|
|
|
!iterator.isDone();
|
|
|
|
iterator.next())
|
|
|
|
{
|
|
|
|
glBegin( GL_QUADS );
|
|
|
|
glVertex2i( area.left() - FRAME_WIDTH, area.top() - FRAME_WIDTH ); // top frame
|
|
|
|
glVertex2i( area.right() + FRAME_WIDTH, area.top() - FRAME_WIDTH );
|
|
|
|
glVertex2i( area.right() + FRAME_WIDTH, area.top() - 1 );
|
|
|
|
glVertex2i( area.left() - FRAME_WIDTH, area.top() - 1 );
|
|
|
|
glVertex2i( area.left() - FRAME_WIDTH, area.top() - FRAME_WIDTH ); // left frame
|
|
|
|
glVertex2i( area.left() - 1, area.top() - FRAME_WIDTH );
|
|
|
|
glVertex2i( area.left() - 1, area.bottom() + FRAME_WIDTH );
|
|
|
|
glVertex2i( area.left() - FRAME_WIDTH, area.bottom() + FRAME_WIDTH );
|
|
|
|
glVertex2i( area.right() + 1, area.top() - FRAME_WIDTH ); // right frame
|
|
|
|
glVertex2i( area.right() + FRAME_WIDTH, area.top() - FRAME_WIDTH );
|
|
|
|
glVertex2i( area.right() + FRAME_WIDTH, area.bottom() + FRAME_WIDTH );
|
|
|
|
glVertex2i( area.right() + 1, area.bottom() + FRAME_WIDTH );
|
|
|
|
glVertex2i( area.left() - FRAME_WIDTH, area.bottom() + 1 ); // bottom frame
|
|
|
|
glVertex2i( area.right() + FRAME_WIDTH, area.bottom() + 1 );
|
|
|
|
glVertex2i( area.right() + FRAME_WIDTH, area.bottom() + FRAME_WIDTH );
|
|
|
|
glVertex2i( area.left() - FRAME_WIDTH, area.bottom() + FRAME_WIDTH );
|
|
|
|
glEnd();
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
glPopAttrib();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MagnifierEffect::postPaintScreen()
|
|
|
|
{
|
|
|
|
if( zoom != target_zoom )
|
2007-09-14 13:40:26 +00:00
|
|
|
{
|
|
|
|
QRect framedarea = magnifierArea().adjusted( -FRAME_WIDTH, -FRAME_WIDTH, FRAME_WIDTH, FRAME_WIDTH );
|
|
|
|
effects->addRepaint( framedarea );
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
effects->postPaintScreen();
|
|
|
|
}
|
|
|
|
|
2007-09-02 20:47:42 +00:00
|
|
|
QRect MagnifierEffect::magnifierArea( QPoint pos ) const
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
return QRect( pos.x() - magnifier_size.width() / 2, pos.y() - magnifier_size.height() / 2,
|
|
|
|
magnifier_size.width(), magnifier_size.height());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MagnifierEffect::zoomIn()
|
|
|
|
{
|
|
|
|
target_zoom *= 1.2;
|
|
|
|
effects->addRepaint( magnifierArea().adjusted( -FRAME_WIDTH, -FRAME_WIDTH, FRAME_WIDTH, FRAME_WIDTH ));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MagnifierEffect::zoomOut()
|
|
|
|
{
|
|
|
|
target_zoom /= 1.2;
|
|
|
|
if( target_zoom < 1 )
|
|
|
|
target_zoom = 1;
|
|
|
|
effects->addRepaint( magnifierArea().adjusted( -FRAME_WIDTH, -FRAME_WIDTH, FRAME_WIDTH, FRAME_WIDTH ));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MagnifierEffect::toggle()
|
|
|
|
{
|
|
|
|
if( target_zoom == 1.0 )
|
|
|
|
target_zoom = 2;
|
|
|
|
else
|
|
|
|
target_zoom = 1;
|
|
|
|
effects->addRepaint( magnifierArea().adjusted( -FRAME_WIDTH, -FRAME_WIDTH, FRAME_WIDTH, FRAME_WIDTH ));
|
|
|
|
}
|
|
|
|
|
2008-01-02 15:34:12 +00:00
|
|
|
void MagnifierEffect::mouseChanged( const QPoint& pos, const QPoint& old,
|
|
|
|
Qt::MouseButtons, Qt::MouseButtons, Qt::KeyboardModifiers, Qt::KeyboardModifiers )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
if( pos != old && zoom != 1 )
|
|
|
|
effects->addRepaint( magnifierArea( old ).adjusted( -FRAME_WIDTH, -FRAME_WIDTH, FRAME_WIDTH, FRAME_WIDTH ));
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#include "magnifier.moc"
|