~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to plugins/treeshape/SelectionDecorator.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-10-27 17:52:57 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101027175257-s04zqqk5bs8ckm9o
Tags: 1:2.2.83-0ubuntu1
* Merge with Debian git remaining changes:
 - Add build-deps on librcps-dev, opengtl-dev, libqtgtl-dev, freetds-dev,
   create-resources, libspnav-dev
 - Remove needless build-dep on libwv2-dev
 - koffice-libs recommends create-resources
 - krita recommends pstoedit
 - Keep our patches
* New upstream release 2.3 beta 3
  - Remove debian/patches fixed by upstream
  - Update install files

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
 
 
3
   Copyright (c) 2010 Cyril Oblikov <munknex@gmail.com>
 
4
 
 
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.
 
9
 
 
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.
 
14
 
 
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.
 
19
*/
 
20
 
 
21
#include "SelectionDecorator.h"
 
22
 
 
23
#include <KoShape.h>
 
24
#include <KoSelection.h>
 
25
 
 
26
SelectionDecorator::SelectionDecorator()
 
27
{
 
28
}
 
29
 
 
30
SelectionDecorator::~SelectionDecorator()
 
31
{
 
32
}
 
33
 
 
34
void SelectionDecorator::setSelection(KoSelection *selection) {
 
35
    m_selection = selection;
 
36
}
 
37
 
 
38
void SelectionDecorator::paint(QPainter &painter, const KoViewConverter &converter) {
 
39
    painter.save();
 
40
 
 
41
    // save the original painter transformation
 
42
    QTransform painterMatrix = painter.worldTransform();
 
43
 
 
44
    painter.setPen( Qt::green );
 
45
    bool editable=false;
 
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() ) );
 
53
 
 
54
        if(!shape->isGeometryProtected())
 
55
            editable = true;
 
56
    }
 
57
 
 
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 );
 
71
    }
 
72
    painter.restore();
 
73
}
 
74