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.
|
|
|
|
|
|
|
|
Copyright (C) 2006 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
|
|
|
|
|
|
|
#include "mousemark.h"
|
|
|
|
|
2007-12-17 14:14:53 +00:00
|
|
|
#include <kwinconfig.h>
|
2007-05-13 17:47:20 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
#include <kaction.h>
|
|
|
|
#include <kactioncollection.h>
|
|
|
|
#include <kglobal.h>
|
|
|
|
#include <klocale.h>
|
|
|
|
#include <kstandarddirs.h>
|
2007-11-24 14:23:04 +00:00
|
|
|
#include <kconfiggroup.h>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#include <math.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
|
|
|
|
|
|
|
|
#include <kdebug.h>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2007-05-28 11:16:18 +00:00
|
|
|
KWIN_EFFECT( mousemark, MouseMarkEffect )
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
MouseMarkEffect::MouseMarkEffect()
|
|
|
|
{
|
|
|
|
KActionCollection* actionCollection = new KActionCollection( this );
|
|
|
|
KAction* a = static_cast< KAction* >( actionCollection->addAction( "ClearMouseMarks" ));
|
2007-11-24 14:23:04 +00:00
|
|
|
a->setText( i18n( "Clear Mouse Marks" ));
|
2007-04-29 17:35:43 +00:00
|
|
|
a->setGlobalShortcut( KShortcut( Qt::SHIFT + Qt::META + Qt::Key_F11 ));
|
|
|
|
connect( a, SIGNAL( triggered( bool )), this, SLOT( clear()));
|
2007-11-24 14:23:04 +00:00
|
|
|
|
|
|
|
KConfigGroup conf = EffectsHandler::effectConfig("MouseMark");
|
|
|
|
width = conf.readEntry( "LineWidth", 3 );
|
2007-11-24 14:55:46 +00:00
|
|
|
color = conf.readEntry( "Color", QColor( Qt::red ));
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MouseMarkEffect::paintScreen( int mask, QRegion region, ScreenPaintData& data )
|
|
|
|
{
|
|
|
|
effects->paintScreen( mask, region, data ); // paint normal screen
|
|
|
|
if( marks.isEmpty() && drawing.isEmpty())
|
|
|
|
return;
|
|
|
|
glPushAttrib( GL_ENABLE_BIT | GL_CURRENT_BIT | GL_LINE_BIT );
|
2007-11-24 14:55:46 +00:00
|
|
|
glColor4f( color.redF(), color.greenF(), color.blueF(), 1 );
|
2007-04-29 17:35:43 +00:00
|
|
|
glEnable( GL_LINE_SMOOTH );
|
2007-11-24 14:23:04 +00:00
|
|
|
glLineWidth( width );
|
2007-04-29 17:35:43 +00:00
|
|
|
foreach( const Mark& mark, marks )
|
|
|
|
{
|
|
|
|
glBegin( GL_LINE_STRIP );
|
|
|
|
foreach( const QPoint& p, mark )
|
|
|
|
glVertex2i( p.x(), p.y());
|
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
if( !drawing.isEmpty())
|
|
|
|
{
|
|
|
|
glBegin( GL_LINE_STRIP );
|
|
|
|
foreach( const QPoint& p, drawing )
|
|
|
|
glVertex2i( p.x(), p.y());
|
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
glPopAttrib();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MouseMarkEffect::mouseChanged( const QPoint& pos, const QPoint&,
|
2008-01-02 15:34:12 +00:00
|
|
|
Qt::MouseButtons, Qt::MouseButtons,
|
|
|
|
Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
if( modifiers == ( Qt::META | Qt::SHIFT )) // activated
|
|
|
|
{
|
|
|
|
if( drawing.isEmpty())
|
|
|
|
drawing.append( pos );
|
|
|
|
if( drawing.last() == pos )
|
|
|
|
return;
|
|
|
|
QPoint pos2 = drawing.last();
|
|
|
|
drawing.append( pos );
|
2007-11-24 14:23:04 +00:00
|
|
|
QRect repaint = QRect( qMin( pos.x(), pos2.x()), qMin( pos.y(), pos2.y()),
|
|
|
|
qMax( pos.x(), pos2.x()), qMax( pos.y(), pos2.y()));
|
|
|
|
repaint.adjust( -width, -width, width, width );
|
|
|
|
effects->addRepaint( repaint );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
else if( !drawing.isEmpty())
|
|
|
|
{
|
|
|
|
marks.append( drawing );
|
|
|
|
drawing.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MouseMarkEffect::clear()
|
|
|
|
{
|
|
|
|
drawing.clear();
|
|
|
|
marks.clear();
|
|
|
|
effects->addRepaintFull();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#include "mousemark.moc"
|