2007-11-27 19:40:25 +00:00
|
|
|
/********************************************************************
|
2007-07-13 13:22:09 +00:00
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
|
2007-11-13 16:20:52 +00:00
|
|
|
Copyright (C) 2007 Christian Nitschkowski <christian.nitschkowski@kdemail.net>
|
2007-07-13 13:22:09 +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.
|
2007-07-13 13:22:09 +00:00
|
|
|
|
2007-11-27 19:40:25 +00:00
|
|
|
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-07-13 13:22:09 +00:00
|
|
|
|
|
|
|
#include "lookingglass.h"
|
|
|
|
|
|
|
|
#include <kwinglutils.h>
|
|
|
|
|
|
|
|
#include <kactioncollection.h>
|
|
|
|
#include <kaction.h>
|
2007-11-13 16:20:52 +00:00
|
|
|
#include <kconfiggroup.h>
|
2007-07-13 13:22:09 +00:00
|
|
|
#include <klocale.h>
|
|
|
|
#include <kdebug.h>
|
|
|
|
|
2007-11-13 16:20:52 +00:00
|
|
|
#include <kmessagebox.h>
|
2007-07-13 13:22:09 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
KWIN_EFFECT( lookingglass, LookingGlassEffect )
|
|
|
|
KWIN_EFFECT_SUPPORTED( lookingglass, ShaderEffect::supported() )
|
|
|
|
|
|
|
|
|
|
|
|
LookingGlassEffect::LookingGlassEffect() : QObject(), ShaderEffect("lookingglass")
|
|
|
|
{
|
|
|
|
zoom = 1.0f;
|
|
|
|
target_zoom = 1.0f;
|
|
|
|
|
2007-11-13 16:20:52 +00:00
|
|
|
KConfigGroup conf = EffectsHandler::effectConfig("LookingGlass");
|
|
|
|
actionCollection = new KActionCollection( this );
|
|
|
|
actionCollection->setConfigGlobal(true);
|
|
|
|
actionCollection->setConfigGroup("LookingGlass");
|
|
|
|
|
2007-07-13 13:22:09 +00:00
|
|
|
KAction* a;
|
|
|
|
a = static_cast< KAction* >( actionCollection->addAction( KStandardAction::ZoomIn, this, SLOT( zoomIn())));
|
|
|
|
a->setGlobalShortcut(KShortcut(Qt::META + Qt::Key_Plus));
|
|
|
|
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-24 13:51:02 +00:00
|
|
|
initialradius = conf.readEntry("Radius", 200);
|
|
|
|
radius = initialradius;
|
2007-11-13 16:20:52 +00:00
|
|
|
|
|
|
|
kDebug(1212) << QString("Radius from config: %1").arg(radius) << endl;
|
|
|
|
|
|
|
|
actionCollection->readSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
LookingGlassEffect::~LookingGlassEffect()
|
|
|
|
{
|
2007-07-13 13:22:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LookingGlassEffect::toggle()
|
|
|
|
{
|
|
|
|
if( target_zoom == 1.0f )
|
|
|
|
target_zoom = 2.0f;
|
|
|
|
else
|
|
|
|
target_zoom = 1.0f;
|
|
|
|
setEnabled( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
void LookingGlassEffect::zoomIn()
|
|
|
|
{
|
2007-09-03 15:00:43 +00:00
|
|
|
target_zoom = qMin(7.0, target_zoom + 0.5);
|
2007-07-13 13:22:09 +00:00
|
|
|
setEnabled( true );
|
|
|
|
effects->addRepaint( cursorPos().x() - radius, cursorPos().y() - radius, 2*radius, 2*radius );
|
|
|
|
}
|
|
|
|
|
|
|
|
void LookingGlassEffect::zoomOut()
|
|
|
|
{
|
|
|
|
target_zoom -= 0.5;
|
|
|
|
if( target_zoom < 1 )
|
|
|
|
{
|
|
|
|
target_zoom = 1;
|
|
|
|
setEnabled( false );
|
|
|
|
}
|
|
|
|
effects->addRepaint( cursorPos().x() - radius, cursorPos().y() - radius, 2*radius, 2*radius );
|
|
|
|
}
|
|
|
|
|
|
|
|
void LookingGlassEffect::prePaintScreen( ScreenPrePaintData& data, int time )
|
|
|
|
{
|
|
|
|
if( zoom != target_zoom )
|
|
|
|
{
|
2007-09-03 15:00:43 +00:00
|
|
|
double diff = time / 500.0;
|
2007-07-13 13:22:09 +00:00
|
|
|
if( target_zoom > zoom )
|
2007-09-03 15:00:43 +00:00
|
|
|
zoom = qMin( zoom * qMax( 1.0 + diff, 1.2 ), target_zoom );
|
2007-07-13 13:22:09 +00:00
|
|
|
else
|
2007-09-03 15:00:43 +00:00
|
|
|
zoom = qMax( zoom * qMin( 1.0 - diff, 0.8 ), target_zoom );
|
2007-08-20 21:33:48 +00:00
|
|
|
kDebug() << "zoom is now " << zoom;
|
2007-11-24 13:51:02 +00:00
|
|
|
radius = qBound((double)initialradius, initialradius * zoom, 3.5*initialradius);
|
2007-07-13 13:22:09 +00:00
|
|
|
|
|
|
|
if( zoom > 1.0f )
|
|
|
|
{
|
|
|
|
shader()->bind();
|
2007-09-03 15:00:43 +00:00
|
|
|
shader()->setUniform("zoom", (float)zoom);
|
2007-07-13 13:22:09 +00:00
|
|
|
shader()->setUniform("radius", (float)radius);
|
|
|
|
shader()->unbind();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setEnabled( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
effects->addRepaint( cursorPos().x() - radius, cursorPos().y() - radius, 2*radius, 2*radius );
|
|
|
|
}
|
|
|
|
|
|
|
|
ShaderEffect::prePaintScreen( data, time );
|
|
|
|
}
|
|
|
|
|
2008-01-02 15:34:12 +00:00
|
|
|
void LookingGlassEffect::mouseChanged( const QPoint& pos, const QPoint& old, Qt::MouseButtons,
|
|
|
|
Qt::MouseButtons, Qt::KeyboardModifiers, Qt::KeyboardModifiers )
|
2007-07-13 13:22:09 +00:00
|
|
|
{
|
|
|
|
if( pos != old && isEnabled() )
|
|
|
|
{
|
|
|
|
effects->addRepaint( pos.x() - radius, pos.y() - radius, 2*radius, 2*radius );
|
|
|
|
effects->addRepaint( old.x() - radius, old.y() - radius, 2*radius, 2*radius );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#include "lookingglass.moc"
|