F:/KPlato/koffice/libs/flake/KoShapeRubberSelectStrategy.cpp

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002 
00003    Copyright (C) 2006 Thorsten Zachmann <zachmann@kde.org>
00004    Copyright (C) 2006 Thomas Zander <zander@kde.org>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
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 ); // TODO make configurable
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     |               |  |    We need to figure out rects A and B based on the two points. BUT
00075     |          old  | A|    we need to do that even if the points are switched places
00076     |             \ |  |    (i.e. the rect got smaller) and even if the rect is mirrored
00077     +---------------+  |    in either the horizontal or vertical axis.
00078     |       B          |
00079     +------------------+
00080                         `- point
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 }

Généré le Wed Nov 22 23:41:00 2006 pour KPlato par  doxygen 1.5.1-p1