File indexing completed on 2024-05-12 16:36:01

0001 /* This file is part of the KDE project
0002    Copyright 2008 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017    Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #ifndef CALLIGRA_SHEETS_ABSTRACT_SELECTION_STRATEGY
0021 #define CALLIGRA_SHEETS_ABSTRACT_SELECTION_STRATEGY
0022 
0023 #include <KoInteractionStrategy.h>
0024 
0025 #include <Qt>
0026 
0027 class KoCanvasBase;
0028 
0029 namespace Calligra
0030 {
0031 namespace Sheets
0032 {
0033 class CellToolBase;
0034 class Selection;
0035 
0036 /**
0037  * An abstract selection strategy.
0038  *
0039  * Derive from this class, if you are only interested in updating the selection on mouse movements.
0040  * For the case, that you will also need to select the cell, where the mouse press occurred, derive
0041  * from SelectionStrategy.
0042  *
0043  * \see SelectionStrategy
0044  */
0045 class AbstractSelectionStrategy : public KoInteractionStrategy
0046 {
0047 public:
0048     /**
0049      * Constructor.
0050      */
0051     AbstractSelectionStrategy(CellToolBase *cellTool, const QPointF &position, Qt::KeyboardModifiers modifiers);
0052 
0053     /**
0054      * Destructor.
0055      */
0056     ~AbstractSelectionStrategy() override;
0057 
0058     void handleMouseMove(const QPointF& mouseLocation, Qt::KeyboardModifiers modifiers) override;
0059     KUndo2Command* createCommand() override;
0060     void finishInteraction(Qt::KeyboardModifiers modifiers) override;
0061 
0062     /**
0063      * Checks, if there is a size grip for the (normal) selection at
0064      * \p position.
0065      * \param canvas the canvas
0066      * \param selection the selection
0067      * \param position the document coordinate (relative to the shape's origin)
0068      * to check
0069      * \return \c true if there is a size grip; \c false otherwise.
0070      */
0071     static bool hitTestSelectionSizeGrip(KoCanvasBase *canvas, Selection *selection,
0072                                          const QPointF &position);
0073 
0074     /**
0075      * Checks, if there is a size grip for the reference selection at
0076      * \p position.
0077      * \param canvas the canvas
0078      * \param selection the selection
0079      * \param position the document coordinate (relative to the shape's origin)
0080      * to check
0081      * \return \c true if there is a size grip; \c false otherwise.
0082      */
0083     static bool hitTestReferenceSizeGrip(KoCanvasBase *canvas, Selection *selection,
0084                                          const QPointF &position);
0085 
0086 protected:
0087     CellToolBase *cellTool() const;
0088     Selection* selection() const;
0089     const QPointF& startPosition() const;
0090 
0091 private:
0092     class Private;
0093     Private * const d;
0094 };
0095 
0096 } // namespace Sheets
0097 } // namespace Calligra
0098 
0099 #endif // CALLIGRA_SHEETS_ABSTRACT_SELECTION_STRATEGY