From 0b2f7266348a5a3547392a93a8cc55e64b1e9a0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= Date: Tue, 8 Jan 2008 16:21:04 +0000 Subject: [PATCH] Add support to Mousemark for drawing arrows. svn path=/trunk/KDE/kdebase/workspace/; revision=758640 --- effects/mousemark.cpp | 32 ++++++++++++++++++++++++++++++++ effects/mousemark.h | 2 ++ 2 files changed, 34 insertions(+) diff --git a/effects/mousemark.cpp b/effects/mousemark.cpp index 8a95d17049..0cfa75706e 100644 --- a/effects/mousemark.cpp +++ b/effects/mousemark.cpp @@ -41,6 +41,8 @@ along with this program. If not, see . namespace KWin { +#define NULL_POINT (QPoint( -1, -1 )) // null point is (0,0), which is valid :-/ + KWIN_EFFECT( mousemark, MouseMarkEffect ) MouseMarkEffect::MouseMarkEffect() @@ -54,6 +56,8 @@ MouseMarkEffect::MouseMarkEffect() KConfigGroup conf = EffectsHandler::effectConfig("MouseMark"); width = conf.readEntry( "LineWidth", 3 ); color = conf.readEntry( "Color", QColor( Qt::red )); + + arrow_start = NULL_POINT; } void MouseMarkEffect::paintScreen( int mask, QRegion region, ScreenPaintData& data ) @@ -86,6 +90,20 @@ void MouseMarkEffect::mouseChanged( const QPoint& pos, const QPoint&, Qt::MouseButtons, Qt::MouseButtons, Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers ) { + if( modifiers == ( Qt::META | Qt::SHIFT | Qt::CTRL )) // start/finish arrow + { + if( arrow_start != NULL_POINT ) + { + marks.append( createArrow( arrow_start, pos )); + arrow_start = NULL_POINT; + effects->addRepaintFull(); + return; + } + else + arrow_start = pos; + } + if( arrow_start != NULL_POINT ) + return; if( modifiers == ( Qt::META | Qt::SHIFT )) // activated { if( drawing.isEmpty()) @@ -113,6 +131,20 @@ void MouseMarkEffect::clear() effects->addRepaintFull(); } +MouseMarkEffect::Mark MouseMarkEffect::createArrow( QPoint arrow_start, QPoint arrow_end ) + { + Mark ret; + double angle = atan2( arrow_end.y() - arrow_start.y(), arrow_end.x() - arrow_start.x()); + ret += arrow_start + QPoint( 50 * cos( angle + M_PI / 6 ), + 50 * sin( angle + M_PI / 6 )); // right one + ret += arrow_start; + ret += arrow_end; + ret += arrow_start; // it's connected lines, so go back with the middle one + ret += arrow_start + QPoint( 50 * cos( angle - M_PI / 6 ), + 50 * sin( angle - M_PI / 6 )); // left one + return ret; + } + } // namespace #include "mousemark.moc" diff --git a/effects/mousemark.h b/effects/mousemark.h index a7d36f8c73..5b12f40dbf 100644 --- a/effects/mousemark.h +++ b/effects/mousemark.h @@ -41,8 +41,10 @@ class MouseMarkEffect void clear(); private: typedef QVector< QPoint > Mark; + static Mark createArrow( QPoint arrow_start, QPoint arrow_end ); QVector< Mark > marks; Mark drawing; + QPoint arrow_start; int width; QColor color; };