File indexing completed on 2024-06-16 04:35:03

0001 /*
0002     SPDX-FileCopyrightText: 2010 Till Theato <root@ttill.de>
0003     SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004 */
0005 
0006 #pragma once
0007 
0008 #include "../abstractcurvewidget.h"
0009 #include "../../../../bpoint.h"
0010 #include "utils/colortools.h"
0011 #include "cubicbezierspline.h"
0012 
0013 #include <QWidget>
0014 
0015 /** @class BezierSplineEditor
0016     @brief \@todo Describe class BezierSplineEditor
0017     @todo Describe class BezierSplineEditor
0018  */
0019 class BezierSplineEditor : public AbstractCurveWidget<CubicBezierSpline>
0020 {
0021     Q_OBJECT
0022 
0023 public:
0024     using Point_t = BPoint;
0025     explicit BezierSplineEditor(QWidget *parent = nullptr);
0026     ~BezierSplineEditor() override;
0027 
0028     /** @brief Sets the property showAllHandles to @param show.
0029      *
0030      * showAllHandles: Whether to show only handles for the selected point for all points.
0031      */
0032     void setShowAllHandles(bool show);
0033     QList<BPoint> getPoints() const override;
0034 
0035 public Q_SLOTS:
0036 
0037 protected:
0038     void paintEvent(QPaintEvent *event) override;
0039     void mousePressEvent(QMouseEvent *event) override;
0040     void mouseMoveEvent(QMouseEvent *event) override;
0041     void mouseDoubleClickEvent(QMouseEvent *event) override;
0042 
0043 private:
0044     /** Whether to show handles for all points or only for the selected one. */
0045     bool m_showAllHandles{true};
0046 
0047     BPoint::PointType m_currentPointType{BPoint::PointType::P};
0048     double m_grabOffsetX{0};
0049     double m_grabOffsetY{0};
0050     /** selected point before it was modified by dragging (at the time of the mouse press) */
0051     BPoint m_grabPOriginal;
0052     /** point with the index currentPointIndex + 1 at the time of the mouse press */
0053     BPoint m_grabPNext;
0054     /** point with the index currentPointIndex - 1 at the time of the mouse press */
0055     BPoint m_grabPPrevious;
0056 
0057     /** @brief Finds the point nearest to @param p and returns it's index.
0058      * @param sel Is filled with the type of the closest point (h1, p, h2)
0059      *
0060      * If no point is near enough -1 is returned. */
0061     int nearestPointInRange(const QPointF &p, int wWidth, int wHeight, BPoint::PointType *sel);
0062 };