1 /************************************************************************
2  **
3  **  @file   vmaingraphicsscene.h
4  **  @author Roman Telezhynskyi <dismine(at)gmail.com>
5  **  @date   November 15, 2013
6  **
7  **  @brief
8  **  @copyright
9  **  This source code is part of the Valentina project, a pattern making
10  **  program, whose allow create and modeling patterns of clothing.
11  **  Copyright (C) 2013-2015 Valentina project
12  **  <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
13  **
14  **  Valentina is free software: you can redistribute it and/or modify
15  **  it under the terms of the GNU General Public License as published by
16  **  the Free Software Foundation, either version 3 of the License, or
17  **  (at your option) any later version.
18  **
19  **  Valentina is distributed in the hope that it will be useful,
20  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  **  GNU General Public License for more details.
23  **
24  **  You should have received a copy of the GNU General Public License
25  **  along with Valentina.  If not, see <http://www.gnu.org/licenses/>.
26  **
27  *************************************************************************/
28 
29 #ifndef VMAINGRAPHICSSCENE_H
30 #define VMAINGRAPHICSSCENE_H
31 
32 #include <qcompilerdetection.h>
33 #include <QGraphicsScene>
34 #include <QMetaObject>
35 #include <QObject>
36 #include <QPointF>
37 #include <QRectF>
38 #include <QString>
39 #include <QTransform>
40 #include <QVector>
41 #include <QtGlobal>
42 
43 #include "../vmisc/def.h"
44 
45 /**
46  * @brief The VMainGraphicsScene class main scene.
47  */
48 class VMainGraphicsScene : public QGraphicsScene
49 {
50     Q_OBJECT
51 public:
52     explicit VMainGraphicsScene(QObject *parent = nullptr);
53     explicit VMainGraphicsScene(const QRectF & sceneRect, QObject * parent = nullptr);
54     qint32        getHorScrollBar() const;
55     void          setHorScrollBar(const qint32 &value);
56     qint32        getVerScrollBar() const;
57     void          setVerScrollBar(const qint32 &value);
58     QTransform    transform() const;
59     void          setTransform(const QTransform &transform);
60     void          SetDisableTools(bool disable, const QString &namePP);
61     QPointF       getScenePos() const;
62 
63     QRectF        VisibleItemsBoundingRect() const;
64     void          InitOrigins();
65     void          SetOriginsVisible(bool visible);
66 
67     bool          IsNonInteractive() const;
68     void          SetNonInteractive(bool nonInteractive);
69 
70 public slots:
71     void          ChoosedItem(quint32 id, const SceneObject &type);
72     void          SelectedItem(bool selected, quint32 object, quint32 tool);
73     void          EnableItemMove(bool move);
74     void          EnableDetailsMode(bool mode);
75     void          ItemsSelection(const SelectionType &type);
76     void          HighlightItem(quint32 id);
77     void          UpdatePiecePassmarks();
78 
79     void          ToggleLabelSelection(bool enabled);
80     void          TogglePointSelection(bool enabled);
81     void          ToggleLineSelection(bool enabled);
82     void          ToggleArcSelection(bool enabled);
83     void          ToggleElArcSelection(bool enabled);
84     void          ToggleSplineSelection(bool enabled);
85     void          ToggleSplinePathSelection(bool enabled);
86     void          ToggleNodeLabelSelection(bool enabled);
87     void          ToggleNodePointSelection(bool enabled);
88     void          ToggleDetailSelection(bool enabled);
89 
90     void          ToggleLabelHover(bool enabled);
91     void          TogglePointHover(bool enabled);
92     void          ToggleLineHover(bool enabled);
93     void          ToggleArcHover(bool enabled);
94     void          ToggleElArcHover(bool enabled);
95     void          ToggleSplineHover(bool enabled);
96     void          ToggleSplinePathHover(bool enabled);
97     void          ToggleNodeLabelHover(bool enabled);
98     void          ToggleNodePointHover(bool enabled);
99     void          ToggleDetailHover(bool enabled);
100 protected:
101     virtual void  mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
102     virtual void  mousePressEvent(QGraphicsSceneMouseEvent *event) override;
103     virtual void  mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
104 signals:
105     /**
106      * @brief mouseMove send new mouse position.
107      * @param scenePos new mouse position.
108      */
109     void          mouseMove(const QPointF &scenePos);
110 
111     void          MouseLeftPressed();
112     void          MouseLeftReleased();
113     void          ItemClicked(QGraphicsItem* pItem);
114 
115     /**
116      * @brief ChoosedObject send option choosed object.
117      * @param id object id.
118      * @param type object scene type.
119      */
120     void          ChoosedObject(quint32 id, SceneObject type);
121     void          SelectedObject(bool selected, quint32 object, quint32 tool);
122     void          DisableItem(bool disable, const QString &namePP);
123     void          EnableToolMove(bool move);
124     void          CurveDetailsMode(bool mode);
125     void          ItemSelection(const SelectionType &type);
126     void          HighlightDetail(quint32 id);
127     void          UpdatePassmarks();
128 
129     void          EnableLabelItemSelection(bool enable);
130     void          EnablePointItemSelection(bool enable);
131     void          EnableLineItemSelection(bool enable);
132     void          EnableArcItemSelection(bool enable);
133     void          EnableElArcItemSelection(bool enable);
134     void          EnableSplineItemSelection(bool enable);
135     void          EnableSplinePathItemSelection(bool enable);
136     void          EnableNodeLabelItemSelection(bool enabled);
137     void          EnableNodePointItemSelection(bool enabled);
138     void          EnableDetailItemSelection(bool enabled);
139 
140     void          EnableLabelItemHover(bool enable);
141     void          EnablePointItemHover(bool enable);
142     void          EnableArcItemHover(bool enable);
143     void          EnableElArcItemHover(bool enable);
144     void          EnableSplineItemHover(bool enable);
145     void          EnableSplinePathItemHover(bool enable);
146     void          EnableNodeLabelItemHover(bool enabled);
147     void          EnableNodePointItemHover(bool enabled);
148     void          EnableDetailItemHover(bool enabled);
149     void          EnableLineItemHover(bool enabled);
150     void          DimensionsChanged();
151     void          LanguageChanged();
152 
153 private:
154     Q_DISABLE_COPY(VMainGraphicsScene)
155     /** @brief horScrollBar value horizontal scroll bar. */
156     qint32        horScrollBar;
157 
158     /** @brief verScrollBar value vertical scroll bar. */
159     qint32        verScrollBar;
160 
161     /** @brief _transform view transform value. */
162     QTransform    _transform;
163     QPointF       scenePos;
164     QVector<QGraphicsItem *> origins;
165 
166     /** @brief m_nonInteractive all item on scene in non interactive. */
167     bool          m_nonInteractive{false};
168 };
169 
170 //---------------------------------------------------------------------------------------------------------------------
171 /**
172  * @brief getHorScrollBar return scene horizontal scrollbar.
173  * @return horizontal scrollbar.
174  */
getHorScrollBar()175 inline qint32 VMainGraphicsScene::getHorScrollBar() const
176 {
177     return horScrollBar;
178 }
179 
180 //---------------------------------------------------------------------------------------------------------------------
181 /**
182  * @brief setHorScrollBar set scene horizontal scrollbar.
183  * @param value horizontal scrollbar.
184  */
setHorScrollBar(const qint32 & value)185 inline void VMainGraphicsScene::setHorScrollBar(const qint32 &value)
186 {
187     horScrollBar = value;
188 }
189 
190 //---------------------------------------------------------------------------------------------------------------------
191 /**
192  * @brief getVerScrollBar return scene vertical scrollbar.
193  * @return vertical scrollbar.
194  */
getVerScrollBar()195 inline qint32 VMainGraphicsScene::getVerScrollBar() const
196 {
197     return verScrollBar;
198 }
199 
200 //---------------------------------------------------------------------------------------------------------------------
201 /**
202  * @brief setVerScrollBar set scene vertical scrollbar.
203  * @param value vertical scrollbar.
204  */
setVerScrollBar(const qint32 & value)205 inline void VMainGraphicsScene::setVerScrollBar(const qint32 &value)
206 {
207     verScrollBar = value;
208 }
209 
210 #endif // VMAINGRAPHICSSCENE_H
211