00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "KoShapeRubberSelectStrategy.h"
00023
00024 #include <QPainter>
00025 #include <QMouseEvent>
00026
00027 #include "KoPointerEvent.h"
00028 #include "KoShapeManager.h"
00029 #include "KoSelection.h"
00030 #include "KoCanvasBase.h"
00031 #include "KoTool.h"
00032
00033 KoShapeRubberSelectStrategy::KoShapeRubberSelectStrategy( KoTool *tool, KoCanvasBase *canvas, const QPointF &clicked )
00034 : KoInteractionStrategy(tool, canvas )
00035 , m_selectRect(clicked, QSizeF(0, 0))
00036 {
00037 }
00038
00039
00040 KoShapeRubberSelectStrategy::~KoShapeRubberSelectStrategy()
00041 {
00042 }
00043
00044
00045 void KoShapeRubberSelectStrategy::paint( QPainter &painter, KoViewConverter &converter)
00046 {
00047 painter.setRenderHint( QPainter::Antialiasing, false );
00048
00049 QColor selectColor( Qt::blue );
00050 selectColor.setAlphaF( 0.5 );
00051 QBrush sb( selectColor, Qt::SolidPattern );
00052 painter.setPen( QPen( sb, 0 ) );
00053 painter.setBrush( sb );
00054 QRectF paintRect = converter.documentToView(m_selectRect);
00055 if(painter.hasClipping())
00056 paintRect = paintRect.intersect(painter.clipRegion().boundingRect());
00057 painter.drawRect( paintRect);
00058 }
00059
00060
00061 void KoShapeRubberSelectStrategy::handleMouseMove(const QPointF &point, Qt::KeyboardModifiers modifiers) {
00062 if(modifiers == Qt::AltModifier) {
00063 m_canvas->updateCanvas(m_selectRect.normalized());
00064 m_selectRect.moveTopLeft(m_selectRect.topLeft() - (m_lastPos - point));
00065 m_lastPos = point;
00066 m_canvas->updateCanvas(m_selectRect.normalized());
00067 return;
00068 }
00069 m_lastPos = point;
00070 QPointF old = m_selectRect.bottomRight();
00071 m_selectRect.setBottomRight( point );
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 QPointF x1 = old;
00083 x1.setY(m_selectRect.topLeft().y());
00084 double h1 = point.y() - x1.y();
00085 double h2 = old.y() - x1.y();
00086 QRectF A(x1, QSizeF(point.x() - x1.x(), point.y() < m_selectRect.top() ? qMin(h1, h2) : qMax (h1, h2) ));
00087 A = A.normalized();
00088 m_canvas->updateCanvas(A);
00089
00090 QPointF x2 = old;
00091 x2.setX(m_selectRect.topLeft().x());
00092 double w1 = point.x() - x2.x();
00093 double w2 = old.x() - x2.x();
00094 QRectF B(x2, QSizeF(point.x() < m_selectRect.left() ? qMin(w1, w2) : qMax(w1, w2), point.y() - x2.y()));
00095 B = B.normalized();
00096 m_canvas->updateCanvas(B);
00097 }
00098
00099 void KoShapeRubberSelectStrategy::finishInteraction( Qt::KeyboardModifiers modifiers )
00100 {
00101 Q_UNUSED( modifiers );
00102 KoSelection * selection = m_canvas->shapeManager()->selection();
00103 QList<KoShape *> shapes( m_canvas->shapeManager()->shapesAt( m_selectRect ) );
00104 foreach ( KoShape * shape, shapes )
00105 {
00106 if(! (shape->isSelectable() && shape->isVisible()))
00107 continue;
00108 selection->select( shape );
00109 }
00110 m_parent->repaintDecorations();
00111 m_canvas->updateCanvas(m_selectRect.normalized());
00112 }
00113
00114 const QRectF KoShapeRubberSelectStrategy::selectRect() const {
00115 return m_selectRect.normalized();
00116 }