2022-05-10 10:06:48 +00:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
#include "knob.h"
|
|
|
|
|
|
|
|
#include <QBrush>
|
|
|
|
#include <QTouchEvent>
|
|
|
|
|
|
|
|
Knob::Knob()
|
|
|
|
: QGraphicsEllipseItem(-50, -50, 100, 100)
|
|
|
|
{
|
|
|
|
setAcceptTouchEvents(true);
|
|
|
|
setBrush(Qt::lightGray);
|
|
|
|
|
|
|
|
QGraphicsEllipseItem *leftItem = new QGraphicsEllipseItem(0, 0, 20, 20, this);
|
|
|
|
leftItem->setPos(-40, -10);
|
|
|
|
leftItem->setBrush(Qt::darkGreen);
|
|
|
|
|
|
|
|
QGraphicsEllipseItem *rightItem = new QGraphicsEllipseItem(0, 0, 20, 20, this);
|
|
|
|
rightItem->setPos(20, -10);
|
|
|
|
rightItem->setBrush(Qt::darkRed);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Knob::sceneEvent(QEvent *event)
|
|
|
|
{
|
|
|
|
switch (event->type()) {
|
|
|
|
case QEvent::TouchBegin:
|
|
|
|
case QEvent::TouchUpdate:
|
|
|
|
case QEvent::TouchEnd:
|
|
|
|
{
|
|
|
|
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
|
|
|
|
|
2021-04-16 09:29:12 +00:00
|
|
|
if (touchEvent->points().count() == 2) {
|
|
|
|
const QEventPoint &touchPoint1 = touchEvent->points().first();
|
|
|
|
const QEventPoint &touchPoint2 = touchEvent->points().last();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2021-04-16 09:29:12 +00:00
|
|
|
QLineF line1(touchPoint1.sceneLastPosition(), touchPoint2.sceneLastPosition());
|
2020-06-04 16:07:06 +00:00
|
|
|
QLineF line2(touchPoint1.scenePosition(), touchPoint2.scenePosition());
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-06-25 17:44:44 +00:00
|
|
|
setTransform(QTransform().rotate(line2.angleTo(line1)), true);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return QGraphicsItem::sceneEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|