Pencil2D Animation
Download Community News Docs Contribute
  • Overview
  • Articles
  • Code
  •  
  • Class List
  • Class Index
  • Class Hierarchy
  • Class Members
  • File List
Loading...
Searching...
No Matches
  • core_lib
  • src
  • tool
radialoffsettool.cpp
1/*
2
3Pencil2D - Traditional Animation Software
4Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5Copyright (C) 2012-2020 Matthew Chiawen Chang
6Copyright (C) 2025-2099 Oliver S. Larsen
7
8This program is free software; you can redistribute it and/or
9modify it under the terms of the GNU General Public License
10as published by the Free Software Foundation; version 2 of the License.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17*/
18
19#include "radialoffsettool.h"
20
21#include "pointerevent.h"
22
23#include <QLineF>
24
25RadialOffsetTool::RadialOffsetTool(QObject* parent) : QObject(parent)
26{
27
28}
29
30RadialOffsetTool::~RadialOffsetTool()
31{
32}
33
34void RadialOffsetTool::pointerEvent(PointerEvent* event)
35{
36 if (event->eventType() == PointerEvent::Press) {
37 startAdjusting(event);
38 } else if (event->eventType() == PointerEvent::Move) {
39 if (event->buttons() & Qt::LeftButton && mIsAdjusting) {
40 adjust(event);
41 }
42 } else if (event->eventType() == PointerEvent::Release && mIsAdjusting) {
43 stopAdjusting();
44 }
45}
46
47void RadialOffsetTool::adjust(PointerEvent* event)
48{
49 const qreal newValue = QLineF(mAdjustPoint, event->canvasPos()).length();
50
51 emit offsetChanged(newValue);
52}
53
54bool RadialOffsetTool::startAdjusting(PointerEvent* event)
55{
56 const qreal rad = mOffset;
57
58 QPointF directionDelta;
59 if (mAdjustPoint.isNull()) {
60 directionDelta = QPointF(-1, -1); // 45 deg back
61 } else {
62 directionDelta = -(event->canvasPos() - mAdjustPoint);
63 }
64
65 QLineF line(event->canvasPos(), event->canvasPos() + directionDelta);
66 line.setLength(rad);
67
68 mAdjustPoint = line.p2(); // Adjusted point on circle boundary
69
70 mIsAdjusting = true;
71 return true;
72}
73
74void RadialOffsetTool::stopAdjusting()
75{
76 mIsAdjusting = false;
77}
PointerEvent
Definition: pointerevent.h:8
QLineF
QLineF::length
qreal length() const const
QObject
QObject::event
virtual bool event(QEvent *e)
QPointF
QPointF::isNull
bool isNull() const const
Qt::LeftButton
LeftButton
Generated on Fri Dec 19 2025 07:54:21 for Pencil2D by doxygen 1.9.6 based on revision 7fd8cd9e03f2d31750e199ecec202e5c0f30e532