@@ -165,7 +165,7 @@ void GraphicsArcItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
165165
166166 switch (mouseRegion ()) {
167167 case GraphicsBasicItem::MouseRegion::All: pts_tmp.translate (dp); break ;
168- case GraphicsBasicItem::MouseRegion::None : {
168+ case GraphicsBasicItem::MouseRegion::Edge : {
169169 switch (d_ptr->mouseRegion ) {
170170 case InEdge0:
171171 setMyCursor (d_ptr->arch .center , event->scenePos ());
@@ -206,71 +206,22 @@ void GraphicsArcItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
206206 pointsChanged (pts_tmp);
207207}
208208
209- void GraphicsArcItem::hoverMoveEvent (QGraphicsSceneHoverEvent *event)
210- {
211- auto pts_tmp = geometryCache ()->controlPoints ();
212- QPointF point = event->scenePos ();
213- if (pts_tmp.size () == 2 || pts_tmp.size () == 3 ) {
214- pts_tmp.append (point);
215- showHoverArc (pts_tmp);
216- }
217- if (!isValid ()) {
218- return ;
219- }
220- GraphicsBasicItem::hoverMoveEvent (event);
221- if (mouseRegion () == GraphicsBasicItem::MouseRegion::DotRegion) {
222- return ;
223- }
224- setMouseRegion (GraphicsBasicItem::MouseRegion::None);
225-
226- QPointF p1 = Utils::pointFromCenter (d_ptr->arch .center ,
227- d_ptr->arch .maxRadius ,
228- d_ptr->arch .startAngle );
229- QPointF p2 = Utils::pointFromCenter (d_ptr->arch .center ,
230- d_ptr->arch .maxRadius ,
231- d_ptr->arch .endAngle );
232- QLineF line1 (p1, pts_tmp.at (0 ));
233- QLineF line2 (p2, pts_tmp.at (1 ));
234- if (qAbs (Utils::distance (point, d_ptr->arch .center ) - d_ptr->arch .minRadius ) < margin () / 3 ) {
235- d_ptr->mouseRegion = InEdge0;
236- setMyCursor (d_ptr->arch .center , point);
237- } else if (qAbs (Utils::distance (point, d_ptr->arch .center ) - d_ptr->arch .maxRadius )
238- < margin () / 3 ) {
239- d_ptr->mouseRegion = InEdge1;
240- setMyCursor (d_ptr->arch .center , point);
241- } else if (Utils::boundingFromLine (line1, margin () / 4 ).containsPoint (point, Qt::OddEvenFill)) {
242- d_ptr->mouseRegion = InEdgeL;
243- setCursor (Utils::cursorForDirection (line1.angle ()));
244- } else if (Utils::boundingFromLine (line2, margin () / 4 ).containsPoint (point, Qt::OddEvenFill)) {
245- d_ptr->mouseRegion = InEdgeH;
246- setCursor (Utils::cursorForDirection (line2.angle ()));
247- } else if (d_ptr->arcPath .contains (point)) {
248- setMouseRegion (GraphicsBasicItem::MouseRegion::All);
249- setCursor (Qt::SizeAllCursor);
250- } else {
251- unsetCursor ();
252- }
253- }
254-
255209void GraphicsArcItem::drawContent (QPainter *painter)
256210{
257211 painter->drawPath (isValid () ? d_ptr->arcPath : d_ptr->cachePath );
258212}
259213
260214void GraphicsArcItem::pointsChanged (const QPolygonF &ply)
261215{
262- auto rect = scene ()->sceneRect ();
263- if (!rect.contains (ply.last ())) {
264- return ;
265- }
266-
267216 if (ply.size () == 3 ) {
268217 double deltaAngle = QLineF (ply[0 ], ply[1 ]).angleTo (QLineF (ply[0 ], ply[2 ]));
269218 if (deltaAngle < 0.00001 || deltaAngle > 355.99999 ) {
270219 return ;
271220 }
272221 }
273222
223+ auto sceneRect = scene ()->sceneRect ();
224+
274225 switch (ply.size ()) {
275226 case 1 :
276227 case 2 : geometryCache ()->setControlPoints (ply); break ;
@@ -279,7 +230,7 @@ void GraphicsArcItem::pointsChanged(const QPolygonF &ply)
279230 return ;
280231 }
281232 QPolygonF polygon = d_ptr->cachePath .toFillPolygon () + ply;
282- if (!rect .contains (polygon.boundingRect ())) {
233+ if (!sceneRect .contains (polygon.boundingRect ())) {
283234 return ;
284235 }
285236 geometryCache ()->setControlPoints (ply);
@@ -295,21 +246,69 @@ void GraphicsArcItem::pointsChanged(const QPolygonF &ply)
295246 update ();
296247}
297248
298- void GraphicsArcItem::showHoverArc (const QPolygonF &ply )
249+ void GraphicsArcItem::updateHoverPreview (const QPointF &scenePos )
299250{
300- switch (ply.size ()) {
251+ auto controlPoints = geometryCache ()->controlPoints ();
252+ auto size = controlPoints.size ();
253+ if (size < 2 || size > 3 ) {
254+ return ;
255+ }
256+
257+ controlPoints.append (scenePos);
258+ size = controlPoints.size ();
259+
260+ switch (size) {
301261 case 3 :
302262 // QPainterPath::arcTo: Adding point with invalid coordinates, ignoring call
303- if (Utils::distance (ply [1 ], ply [2 ]) < margin ()) {
263+ if (Utils::distance (controlPoints [1 ], controlPoints [2 ]) < margin ()) {
304264 return ;
305265 }
306- Utils::calculateHalfArc (ply , d_ptr->cachePath );
266+ Utils::calculateHalfArc (controlPoints , d_ptr->cachePath );
307267 break ;
308- case 4 : Utils::calculateAllArc (ply , d_ptr->cachePath , margin ()); break ;
268+ case 4 : Utils::calculateAllArc (controlPoints , d_ptr->cachePath , margin ()); break ;
309269 default : return ;
310270 }
311271
312272 update ();
313273}
314274
275+ GraphicsBasicItem::MouseRegion GraphicsArcItem::detectEdgeRegion (const QPointF &scenePos)
276+ {
277+ const double marginValue = margin () / 2.0 ;
278+ auto controlPoints = geometryCache ()->controlPoints ();
279+ auto p1 = Utils::pointFromCenter (d_ptr->arch .center ,
280+ d_ptr->arch .maxRadius ,
281+ d_ptr->arch .startAngle );
282+ auto p2 = Utils::pointFromCenter (d_ptr->arch .center ,
283+ d_ptr->arch .maxRadius ,
284+ d_ptr->arch .endAngle );
285+ QLineF line1 (p1, controlPoints[0 ]);
286+ QLineF line2 (p2, controlPoints[1 ]);
287+
288+ if (qAbs (Utils::distance (scenePos, d_ptr->arch .center ) - d_ptr->arch .minRadius ) < marginValue) {
289+ d_ptr->mouseRegion = InEdge0;
290+ setMyCursor (d_ptr->arch .center , scenePos);
291+ } else if (qAbs (Utils::distance (scenePos, d_ptr->arch .center ) - d_ptr->arch .maxRadius )
292+ < marginValue) {
293+ d_ptr->mouseRegion = InEdge1;
294+ setMyCursor (d_ptr->arch .center , scenePos);
295+ } else if (Utils::isPointNearEdge (scenePos, line1, marginValue)) {
296+ d_ptr->mouseRegion = InEdgeL;
297+ setCursor (Utils::cursorForDirection (line1.angle ()));
298+ } else if (Utils::isPointNearEdge (scenePos, line2, marginValue)) {
299+ d_ptr->mouseRegion = InEdgeH;
300+ setCursor (Utils::cursorForDirection (line2.angle ()));
301+ } else if (d_ptr->arcPath .contains (scenePos)) {
302+ setMouseRegion (GraphicsBasicItem::MouseRegion::All);
303+ setCursor (Qt::SizeAllCursor);
304+ } else {
305+ d_ptr->mouseRegion = None;
306+ setMouseRegion (GraphicsBasicItem::MouseRegion::None);
307+ return GraphicsBasicItem::MouseRegion::None;
308+ }
309+
310+ setMouseRegion (GraphicsBasicItem::MouseRegion::Edge);
311+ return GraphicsBasicItem::MouseRegion::Edge;
312+ }
313+
315314} // namespace Graphics
0 commit comments