File indexing completed on 2024-05-12 16:36:45
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2009 Alexia Allanic <alexia_allanic@yahoo.fr> 0003 * Copyright (C) 2009 Jean-Nicolas Artaud <jeannicolasartaud@gmail.com> 0004 * Copyright (C) 2009 Thorsten Zachmann <zachmann@kde.org> 0005 * 0006 * This library is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU Library General Public 0008 * License as published by the Free Software Foundation; either 0009 * version 2 of the License, or (at your option) any later version. 0010 * 0011 * This library is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 * Library General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU Library General Public License 0017 * along with this library; see the file COPYING.LIB. If not, write to 0018 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0019 * Boston, MA 02110-1301, USA. 0020 */ 0021 0022 #include "KPrPresentationHighlightWidget.h" 0023 0024 #include <KoPACanvasBase.h> 0025 0026 #include <QMouseEvent> 0027 #include <QColor> 0028 #include <QPainter> 0029 #include <QPainterPath> 0030 0031 KPrPresentationHighlightWidget::KPrPresentationHighlightWidget( KoPACanvasBase * canvas ) 0032 : KPrPresentationToolEventForwarder(canvas) 0033 , m_size( canvas->canvasWidget()->size() ) 0034 { 0035 // The focus and the track for have the mouse position every time 0036 setFocusPolicy( Qt::StrongFocus ); 0037 setMouseTracking( true ); 0038 // Size of the canvas is saved because it's used in the paintEvent 0039 resize( m_size ); 0040 0041 m_center = QCursor::pos(); 0042 update(); 0043 } 0044 0045 KPrPresentationHighlightWidget::~KPrPresentationHighlightWidget() 0046 { 0047 } 0048 0049 /** paintEvent call with the update in the mouseMoveEvent */ 0050 void KPrPresentationHighlightWidget::paintEvent( QPaintEvent * event ) 0051 { 0052 Q_UNUSED(event); 0053 QPainter painter( this ); 0054 QPen myPen(Qt::black, 0); 0055 QColor c( Qt::black ); 0056 // TODO make alpha configurable 0057 c.setAlphaF( 0.5 ); 0058 // The circle we want 0059 QPainterPath ellipse; 0060 // TODO make radius configurable 0061 ellipse.addEllipse( m_center.x() - 75, m_center.y() - 75, 150, 150 ); 0062 // All the 'background' 0063 QPainterPath myPath; 0064 myPath.addRect( 0, 0, m_size.rwidth(), m_size.rheight() ); 0065 // We draw the difference 0066 painter.setPen( myPen ); 0067 painter.fillPath( myPath.subtracted( ellipse ), c ); 0068 } 0069 0070 /** Take the mouse position every time the mouse is moving */ 0071 void KPrPresentationHighlightWidget::mouseMoveEvent( QMouseEvent* e ) 0072 { 0073 // Save the position of the mouse 0074 m_center = e->pos(); 0075 // Update the screen : move the circle with a paint event 0076 // TODO maybe only update what has changed 0077 update(); 0078 }