kspread
AbstractSelectionStrategy.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 #include "AbstractSelectionStrategy.h"
00021
00022 #include "Selection.h"
00023 #include "Sheet.h"
00024
00025 #include <KoCanvasBase.h>
00026 #include <KoSelection.h>
00027 #include <KoShapeManager.h>
00028 #include <KoTool.h>
00029
00030 using namespace KSpread;
00031
00032 class AbstractSelectionStrategy::Private
00033 {
00034 public:
00035 Selection* selection;
00036 QPointF start;
00037 };
00038
00039 AbstractSelectionStrategy::AbstractSelectionStrategy(KoTool* parent, KoCanvasBase* canvas, Selection* selection,
00040 const QPointF documentPos, Qt::KeyboardModifiers modifiers)
00041 : KoInteractionStrategy(parent, canvas)
00042 , d(new Private)
00043 {
00044 Q_UNUSED(modifiers)
00045 d->selection = selection;
00046 d->start = documentPos;
00047 }
00048
00049 AbstractSelectionStrategy::~AbstractSelectionStrategy()
00050 {
00051 delete d;
00052 }
00053
00054 void AbstractSelectionStrategy::handleMouseMove(const QPointF& documentPos, Qt::KeyboardModifiers modifiers)
00055 {
00056 Q_UNUSED(modifiers)
00057 const KoShape* shape = m_canvas->shapeManager()->selection()->firstSelectedShape();
00058 const QPointF position = documentPos - (shape ? shape->position() : QPointF(0.0, 0.0));
00059
00060 double xpos;
00061 double ypos;
00062 int col = d->selection->activeSheet()->leftColumn(position.x(), xpos);
00063 int row = d->selection->activeSheet()->topRow(position.y(), ypos);
00064
00065 if (col > KS_colMax || row > KS_rowMax)
00066 {
00067 kDebug(36005) << "col or row is out of range:" << "col:" << col << " row:" << row;
00068 return;
00069 }
00070
00071 const QRectF selectionHandle = d->selection->selectionHandleArea(m_canvas->viewConverter());
00072 if (selectionHandle.contains(position))
00073 {
00074
00075
00076 col = d->selection->activeSheet()->leftColumn(position.x() - m_canvas->viewConverter()->viewToDocumentX(2.0), xpos);
00077 row = d->selection->activeSheet()->topRow(position.y() - m_canvas->viewConverter()->viewToDocumentY(2.0), ypos);
00078 }
00079
00080 d->selection->update(QPoint(col, row));
00081 m_parent->repaintDecorations();
00082 }
00083
00084 QUndoCommand* AbstractSelectionStrategy::createCommand()
00085 {
00086 return 0;
00087 }
00088
00089 void AbstractSelectionStrategy::finishInteraction(Qt::KeyboardModifiers modifiers)
00090 {
00091 Q_UNUSED(modifiers)
00092 m_parent->repaintDecorations();
00093 }
00094
00095 Selection* AbstractSelectionStrategy::selection() const
00096 {
00097 return d->selection;
00098 }
00099
00100 const QPointF& AbstractSelectionStrategy::startPosition() const
00101 {
00102 return d->start;
00103 }
|