1 /********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
6 Copyright (C) 2007 Christian Nitschkowski <christian.nitschkowski@kdemail.net>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *********************************************************************/
22 #include "lookingglass.h"
24 #include <kwinglutils.h>
26 #include <kactioncollection.h>
28 #include <kconfiggroup.h>
32 #include <kmessagebox.h>
37 KWIN_EFFECT( lookingglass
, LookingGlassEffect
)
38 KWIN_EFFECT_SUPPORTED( lookingglass
, ShaderEffect::supported() )
41 LookingGlassEffect::LookingGlassEffect() : QObject(), ShaderEffect("lookingglass")
46 actionCollection
= new KActionCollection( this );
47 actionCollection
->setConfigGlobal(true);
48 actionCollection
->setConfigGroup("LookingGlass");
51 a
= static_cast< KAction
* >( actionCollection
->addAction( KStandardAction::ZoomIn
, this, SLOT( zoomIn())));
52 a
->setGlobalShortcut(KShortcut(Qt::META
+ Qt::Key_Plus
));
53 a
= static_cast< KAction
* >( actionCollection
->addAction( KStandardAction::ZoomOut
, this, SLOT( zoomOut())));
54 a
->setGlobalShortcut(KShortcut(Qt::META
+ Qt::Key_Minus
));
55 a
= static_cast< KAction
* >( actionCollection
->addAction( KStandardAction::ActualSize
, this, SLOT( toggle())));
56 a
->setGlobalShortcut(KShortcut(Qt::META
+ Qt::Key_0
));
57 reconfigure( ReconfigureAll
);
60 LookingGlassEffect::~LookingGlassEffect()
64 void LookingGlassEffect::reconfigure( ReconfigureFlags
)
66 KConfigGroup conf
= EffectsHandler::effectConfig("LookingGlass");
67 initialradius
= conf
.readEntry("Radius", 200);
68 radius
= initialradius
;
69 kDebug(1212) << QString("Radius from config: %1").arg(radius
) << endl
;
70 actionCollection
->readSettings();
73 void LookingGlassEffect::toggle()
75 if( target_zoom
== 1.0f
)
82 void LookingGlassEffect::zoomIn()
84 target_zoom
= qMin(7.0, target_zoom
+ 0.5);
86 effects
->addRepaint( cursorPos().x() - radius
, cursorPos().y() - radius
, 2*radius
, 2*radius
);
89 void LookingGlassEffect::zoomOut()
97 effects
->addRepaint( cursorPos().x() - radius
, cursorPos().y() - radius
, 2*radius
, 2*radius
);
100 void LookingGlassEffect::prePaintScreen( ScreenPrePaintData
& data
, int time
)
102 if( zoom
!= target_zoom
)
104 double diff
= time
/ animationTime( 500.0 );
105 if( target_zoom
> zoom
)
106 zoom
= qMin( zoom
* qMax( 1.0 + diff
, 1.2 ), target_zoom
);
108 zoom
= qMax( zoom
* qMin( 1.0 - diff
, 0.8 ), target_zoom
);
109 kDebug(1212) << "zoom is now " << zoom
;
110 radius
= qBound((double)initialradius
, initialradius
* zoom
, 3.5*initialradius
);
115 shader()->setUniform("zoom", (float)zoom
);
116 shader()->setUniform("radius", (float)radius
);
124 effects
->addRepaint( cursorPos().x() - radius
, cursorPos().y() - radius
, 2*radius
, 2*radius
);
127 ShaderEffect::prePaintScreen( data
, time
);
130 void LookingGlassEffect::mouseChanged( const QPoint
& pos
, const QPoint
& old
, Qt::MouseButtons
,
131 Qt::MouseButtons
, Qt::KeyboardModifiers
, Qt::KeyboardModifiers
)
133 if( pos
!= old
&& isEnabled() )
135 effects
->addRepaint( pos
.x() - radius
, pos
.y() - radius
, 2*radius
, 2*radius
);
136 effects
->addRepaint( old
.x() - radius
, old
.y() - radius
, 2*radius
, 2*radius
);
142 #include "lookingglass.moc"