libs/flake
KoShapeRubberSelectStrategy.cppGo to the documentation of this file.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 #include "KoSnapGuide.h"
00033 #include "KoSnapStrategy.h"
00034
00035 KoShapeRubberSelectStrategy::KoShapeRubberSelectStrategy(KoTool *tool, KoCanvasBase *canvas, const QPointF &clicked, bool useSnapToGrid)
00036 : KoInteractionStrategy(tool, canvas)
00037 , m_snapGuide( new KoSnapGuide( canvas ) )
00038 {
00039 m_snapGuide->enableSnapStrategies( KoSnapStrategy::Grid );
00040 m_snapGuide->enableSnapping( useSnapToGrid );
00041
00042 m_selectRect = QRectF( m_snapGuide->snap(clicked, 0 ), QSizeF(0, 0) );
00043 }
00044
00045 KoShapeRubberSelectStrategy::~KoShapeRubberSelectStrategy()
00046 {
00047 delete m_snapGuide;
00048 }
00049
00050 void KoShapeRubberSelectStrategy::paint(QPainter &painter, const KoViewConverter &converter)
00051 {
00052 painter.setRenderHint(QPainter::Antialiasing, false);
00053
00054 QColor selectColor(Qt::blue);
00055 selectColor.setAlphaF(0.5);
00056 QBrush sb(selectColor, Qt::SolidPattern);
00057 painter.setPen(QPen(sb, 0));
00058 painter.setBrush(sb);
00059 QRectF paintRect = converter.documentToView(m_selectRect);
00060 paintRect = paintRect.normalized();
00061 paintRect.adjust(0., -0.5, 0.5, 0.);
00062 if (painter.hasClipping())
00063 paintRect = paintRect.intersect(painter.clipRegion().boundingRect());
00064 painter.drawRect(paintRect);
00065 }
00066
00067 void KoShapeRubberSelectStrategy::handleMouseMove(const QPointF &p, Qt::KeyboardModifiers modifiers)
00068 {
00069 QPointF point = m_snapGuide->snap( p, modifiers );
00070 if ((modifiers & Qt::AltModifier) != 0) {
00071 m_canvas->updateCanvas(m_selectRect.normalized());
00072 m_selectRect.moveTopLeft(m_selectRect.topLeft() - (m_lastPos - point));
00073 m_lastPos = point;
00074 m_canvas->updateCanvas(m_selectRect.normalized());
00075 return;
00076 }
00077 m_lastPos = point;
00078 QPointF old = m_selectRect.bottomRight();
00079 m_selectRect.setBottomRight(point);
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 QPointF x1 = old;
00091 x1.setY(m_selectRect.topLeft().y());
00092 qreal h1 = point.y() - x1.y();
00093 qreal h2 = old.y() - x1.y();
00094 QRectF A(x1, QSizeF(point.x() - x1.x(), point.y() < m_selectRect.top() ? qMin(h1, h2) : qMax(h1, h2)));
00095 A = A.normalized();
00096 m_canvas->updateCanvas(A);
00097
00098 QPointF x2 = old;
00099 x2.setX(m_selectRect.topLeft().x());
00100 qreal w1 = point.x() - x2.x();
00101 qreal w2 = old.x() - x2.x();
00102 QRectF B(x2, QSizeF(point.x() < m_selectRect.left() ? qMin(w1, w2) : qMax(w1, w2), point.y() - x2.y()));
00103 B = B.normalized();
00104 m_canvas->updateCanvas(B);
00105 }
00106
00107 void KoShapeRubberSelectStrategy::finishInteraction(Qt::KeyboardModifiers modifiers)
00108 {
00109 Q_UNUSED(modifiers);
00110 KoSelection * selection = m_canvas->shapeManager()->selection();
00111 QList<KoShape *> shapes(m_canvas->shapeManager()->shapesAt(m_selectRect));
00112 foreach(KoShape * shape, shapes) {
00113 if (!(shape->isSelectable() && shape->isVisible()))
00114 continue;
00115 selection->select(shape);
00116 }
00117 m_parent->repaintDecorations();
00118 m_canvas->updateCanvas(m_selectRect.normalized());
00119 }
00120
00121 const QRectF KoShapeRubberSelectStrategy::selectRect() const
00122 {
00123 return m_selectRect.normalized();
00124 }
|