File indexing completed on 2024-12-22 04:09:14

0001 /* This file is part of the KDE project
0002  * SPDX-FileCopyrightText: 2006, 2008 Jan Hambrecht <jaham@gmx.net>
0003  * SPDX-FileCopyrightText: 2006, 2007 Thorsten Zachmann <zachmann@kde.org>
0004  * SPDX-FileCopyrightText: 2007 Thomas Zander <zander@kde.org>
0005  * SPDX-FileCopyrightText: 2007 Boudewijn Rempt <boud@valdyas.org>
0006  *
0007  * SPDX-License-Identifier: LGPL-2.0-or-later
0008  */
0009 
0010 #ifndef KOPATHTOOLSELECTION_H
0011 #define KOPATHTOOLSELECTION_H
0012 
0013 #include <KoToolSelection.h>
0014 #include <KoPathShape.h>
0015 
0016 class KoPathTool;
0017 class KoPathPoint;
0018 class KoPathPointData;
0019 class KoViewConverter;
0020 class QPainter;
0021 
0022 /**
0023 * @brief Handle the selection of points
0024 *
0025 * This class handles the selection of points. It makes sure
0026 * the canvas is repainted when the selection changes.
0027 */
0028 class KRITAFLAKE_EXPORT KoPathToolSelection : public KoToolSelection, public KoPathShape::PointSelectionChangeListener
0029 {
0030     Q_OBJECT
0031 
0032 public:
0033     explicit KoPathToolSelection(KoPathTool *tool);
0034 
0035     ~KoPathToolSelection() override;
0036 
0037     /// @brief Draw the selected points
0038     void paint(QPainter &painter, const KoViewConverter &converter, qreal handleRadius);
0039 
0040     /**
0041     * @brief Add a point to the selection
0042     *
0043     * @param point to add to the selection
0044     * @param clear if true the selection will be cleared before adding the point
0045     */
0046     void add(KoPathPoint *point, bool clear);
0047 
0048     /**
0049     * @brief Remove a point form the selection
0050     *
0051     * @param point to remove from the selection
0052     */
0053     void remove(KoPathPoint *point);
0054 
0055     /**
0056     * @brief Clear the selection
0057     */
0058     void clear();
0059 
0060     /**
0061      * @brief Select points in rect
0062      *
0063      * @param rect the selection rectangle in document coordinates
0064      * @param clearSelection if set clear the current selection before the selection
0065      */
0066     void selectPoints(const QRectF &rect, bool clearSelection);
0067 
0068     void selectAll();
0069 
0070     /**
0071     * @brief Get the number of path objects in the selection
0072     *
0073     * @return number of path object in the point selection
0074     */
0075     int objectCount() const;
0076 
0077     /**
0078     * @brief Get the number of path points in the selection
0079     *
0080     * @return number of points in the selection
0081     */
0082     int size() const;
0083 
0084     /**
0085     * @brief Check if a point is in the selection
0086     *
0087     * @return true when the point is in the selection, false otherwise
0088     */
0089     bool contains(KoPathPoint *point);
0090 
0091     /**
0092     * @brief Get all selected points
0093     *
0094     * @return set of selected points
0095     */
0096     const QSet<KoPathPoint *> &selectedPoints() const;
0097 
0098     /**
0099     * @brief Get the point data of all selected points
0100     *
0101     * This is subject to change
0102     */
0103     QList<KoPathPointData> selectedPointsData() const;
0104 
0105     /**
0106     * @brief Get the point data of all selected segments
0107     *
0108     * This is subject to change
0109     */
0110     QList<KoPathPointData> selectedSegmentsData() const;
0111 
0112     /// Returns list of selected shapes
0113     QList<KoPathShape*> selectedShapes() const;
0114 
0115     /// Sets list of selected shapes
0116     void setSelectedShapes(const QList<KoPathShape*> shapes);
0117 
0118     /**
0119     * @brief Update the selection to contain only valid points
0120     *
0121     * This function checks which points are no longer valid and removes them
0122     * from the selection.
0123     * If e.g. some points are selected and the shape which contains the points
0124     * is removed by undo, the points are no longer valid and have therefore to
0125     * be removed from the selection.
0126     */
0127     void update();
0128 
0129     /// reimplemented from KoToolSelection
0130     bool hasSelection() override;
0131 
0132 
0133     void recommendPointSelectionChange(KoPathShape *shape, const QList<KoPathPointIndex> &newSelection) override;
0134     void notifyPathPointsChanged(KoPathShape *shape) override;
0135     void notifyShapeChanged(KoShape::ChangeType type, KoShape *shape) override;
0136 
0137 Q_SIGNALS:
0138     void selectionChanged();
0139 
0140 private:
0141     typedef QMap<KoPathShape *, QSet<KoPathPoint *> > PathShapePointMap;
0142 
0143     QSet<KoPathPoint *> m_selectedPoints;
0144     PathShapePointMap m_shapePointMap;
0145     KoPathTool *m_tool;
0146     QList<KoPathShape*> m_selectedShapes;
0147 };
0148 
0149 #endif // KOPATHTOOLSELECTION_H