File indexing completed on 2024-04-28 05:38:11

0001 /***************************************************************************
0002  *   Copyright (C) 2015 by Renaud Guezennec                                *
0003  *   https://rolisteam.org/contact                   *
0004  *                                                                         *
0005  *   rolisteam is free software; you can redistribute it and/or modify     *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
0019  ***************************************************************************/
0020 
0021 #ifndef CHILDPOINTITEM_H
0022 #define CHILDPOINTITEM_H
0023 
0024 #include "rwidgets_global.h"
0025 #include <QFlags>
0026 #include <QGraphicsObject>
0027 #include <QPointer>
0028 
0029 #include "media/mediatype.h"
0030 
0031 namespace vmap
0032 {
0033 class VisualItemController;
0034 }
0035 class VisualItem;
0036 /**
0037  * @brief The ChildPointItem class controls and allows geometry transforms to its parent from user inputs.
0038  */
0039 class RWIDGET_EXPORT ChildPointItem : public QGraphicsObject
0040 {
0041     Q_OBJECT
0042     Q_PROPERTY(Control control READ control CONSTANT)
0043 public:
0044     /**
0045      * @brief The MOTION enum, ALL means all axis, MOUSE means the changes are control by mouse event instead of
0046      * geometry event on item. In this case, the ChildPointItem does not mouse, it receives mouse event and ask its
0047      * parent to change its geometry.
0048      */
0049     enum MOTION
0050     {
0051         NONE= 0x0,
0052         X_AXIS= 0x1,
0053         Y_AXIS= 0x2,
0054         MOVE= 0x4,
0055         ROTATION= 0x8,
0056         MOUSE= MOVE | ROTATION,
0057         ALL= MOUSE | MOVE
0058     };
0059     Q_ENUM(MOTION)
0060     Q_DECLARE_FLAGS(MOTIONS, MOTION)
0061     /**
0062      * @brief The PLACEMENT enum
0063      */
0064     enum PLACEMENT
0065     {
0066         TopLeft,
0067         TopRight,
0068         TopCenter,
0069         MiddelLeft,
0070         MiddleRight,
0071         Center,
0072         ButtomLeft,
0073         ButtomRight,
0074         ButtomCenter
0075     };
0076 
0077     enum Change
0078     {
0079         None,
0080         Rotation,
0081         Resizing,
0082         Moving
0083     };
0084 
0085     enum class Control
0086     {
0087         Geometry,
0088         Vision
0089     };
0090 
0091     /**
0092      * @brief ChildPointItem
0093      * @param point
0094      * @param parent
0095      */
0096     ChildPointItem(vmap::VisualItemController* ctrl, int point, VisualItem* parent,
0097                    Control control= ChildPointItem::Control::Geometry);
0098     /**
0099      * @brief ~ChildPointItem
0100      */
0101     virtual ~ChildPointItem();
0102     /**
0103      * @brief itemChange
0104      * @param change
0105      * @param value
0106      * @return
0107      */
0108     QVariant itemChange(GraphicsItemChange change, const QVariant& value);
0109     /**
0110      * @brief boundingRect
0111      * @return
0112      */
0113     QRectF boundingRect() const;
0114     /**
0115      * @brief paint
0116      * @param painter
0117      * @param option
0118      * @param widget
0119      */
0120     void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget);
0121     /**
0122      * @brief setMotion
0123      * @param m
0124      */
0125     void setMotion(ChildPointItem::MOTIONS m);
0126     /**
0127      * @brief setPlacement
0128      * @param p
0129      */
0130     void setPlacement(ChildPointItem::PLACEMENT p);
0131     ChildPointItem::PLACEMENT placement() const;
0132     /**
0133      * @brief setEditableItem
0134      * @param b
0135      */
0136     void setEditableItem(bool b);
0137 
0138     /**
0139      * @brief setPointID
0140      */
0141     void setPointID(int);
0142     /**
0143      * @brief getPointID
0144      * @return
0145      */
0146     int getPointID() const;
0147 
0148     Control control() const;
0149 
0150 signals:
0151     void visibilityModeChanged();
0152 
0153 protected:
0154     /**
0155      * @brief ChildPointItem::mouseMoveEvent
0156      * @param event
0157      */
0158     void mouseMoveEvent(QGraphicsSceneMouseEvent* event);
0159     /**
0160      * @brief ChildPointItem::mouseReleaseEvent
0161      * @param event
0162      */
0163     void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
0164 
0165 private:
0166     QPointer<vmap::VisualItemController> m_ctrl;
0167     Change m_currentChange= None;
0168     int m_pointId;
0169     QPointF m_startPoint;
0170     VisualItem* m_parent;
0171     MOTIONS m_motion= NONE;
0172     bool m_editable;
0173     PLACEMENT m_placement;
0174     Control m_control= Control::Geometry;
0175 };
0176 Q_DECLARE_OPERATORS_FOR_FLAGS(ChildPointItem::MOTIONS)
0177 #endif // CHILDPOINTITEM_H