Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_draggable_tool_button.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2015 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
9#include <QMouseEvent>
10
11#include "kis_debug.h"
12
13
15 : QToolButton(parent),
16 m_orientation(Qt::Horizontal)
17{
18}
19
23
24void KisDraggableToolButton::beginDrag(const QPoint &pos)
25{
26 m_startPoint = pos;
28}
29
31{
32 QPoint diff = pos - m_startPoint;
33
34 int value = 0;
35
36 qreal tanx = diff.x() != 0 ? qAbs(qreal(diff.y()) / diff.x()) : 100.0;
37
38 if (tanx > 10 && m_orientation == Qt::Horizontal) {
39 m_orientation = Qt::Vertical;
40 } else if (tanx < 0.1 && m_orientation == Qt::Vertical) {
41 m_orientation = Qt::Horizontal;
42 }
43
44 // people like it more when the they can zoom by dragging in both directions
45 Q_UNUSED(m_orientation);
46
47 value = diff.x() - diff.y();
48
49 return value;
50}
51
53{
54 QPoint diff = pos - m_lastPosition;
55 m_lastPosition = pos;
56 return diff.x() - diff.y();
57
58}
59
61{
62 beginDrag(e->pos());
63 QToolButton::mousePressEvent(e);
64}
65
67{
68 int distance = continueDrag(e->pos());
69 Q_EMIT offsetChanged(distance);
70 int delta = movementDelta(e->pos());
71 Q_EMIT valueChanged(delta);
72
73 QToolButton::mouseMoveEvent(e);
74}
float value(const T *src, size_t ch)
qreal distance(const QPointF &p1, const QPointF &p2)
int continueDrag(const QPoint &pos)
int movementDelta(const QPoint &pos)
void valueChanged(int delta)
void mousePressEvent(QMouseEvent *e) override
void mouseMoveEvent(QMouseEvent *e) override
void offsetChanged(int offset)
void beginDrag(const QPoint &pos)