1
/* This file is part of the KDE project
3
Copyright (c) 2010 Cyril Oblikov <munknex@gmail.com>
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
7
License as published by the Free Software Foundation; either
8
version 2 of the License, or (at your option) any later version.
10
This library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Library General Public License for more details.
15
You should have received a copy of the GNU Library General Public License
16
along with this library; see the file COPYING.LIB. If not, write to
17
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
* Boston, MA 02110-1301, USA.
21
#include "SelectionDecorator.h"
24
#include <KoSelection.h>
26
SelectionDecorator::SelectionDecorator()
30
SelectionDecorator::~SelectionDecorator()
34
void SelectionDecorator::setSelection(KoSelection *selection) {
35
m_selection = selection;
38
void SelectionDecorator::paint(QPainter &painter, const KoViewConverter &converter) {
41
// save the original painter transformation
42
QTransform painterMatrix = painter.worldTransform();
44
painter.setPen( Qt::green );
46
foreach(KoShape *shape, m_selection->selectedShapes(KoFlake::StrippedSelection)) {
47
// apply the shape transformation on top of the old painter transformation
48
painter.setWorldTransform( shape->absoluteTransformation(&converter) * painterMatrix );
49
// apply the zoom factor
50
KoShape::applyConversion( painter, converter );
51
// draw the shape bounding rect
52
painter.drawRect( QRectF( QPointF(), shape->size() ) );
54
if(!shape->isGeometryProtected())
58
if(m_selection->count()>1) {
59
// more than one shape selected, so we need to draw the selection bounding rect
60
painter.setPen( Qt::blue );
61
// apply the selection transformation on top of the old painter transformation
62
painter.setWorldTransform(m_selection->absoluteTransformation(&converter) * painterMatrix);
63
// apply the zoom factor
64
KoShape::applyConversion( painter, converter );
65
// draw the selection bounding rect
66
painter.drawRect( QRectF( QPointF(), m_selection->size() ) );
67
} else if( m_selection->firstSelectedShape() ) {
68
// only one shape selected, so we compose the correct painter matrix
69
painter.setWorldTransform(m_selection->firstSelectedShape()->absoluteTransformation(&converter) * painterMatrix);
70
KoShape::applyConversion( painter, converter );