72 QWidget{parent}, onlyQuadrant2and1{!useQuadrant3and4}, nibble{}, steps{0}
75 std::unique_ptr<QGraphicsScene> scene{
new QGraphicsScene{}};
76 QPen pen{Qt::black, 0};
78 scene->addEllipse(-1, -1, 2, 2, pen);
80 scene->addEllipse(-0.13, -0.13, 0.26, 0.26, pen);
82 scene->addLine(0, -1, 0, 1, pen);
83 scene->addLine(-1, 0, 1, 0, pen);
85 QPen penRed{Qt::darkRed};
86 penRed.setCosmetic(
true);
87 nibble = scene->addEllipse(-0.1, -0.1, 0.2, 0.2, penRed, QBrush{Qt::darkRed});
90 std::unique_ptr<JoystickControlWidgetQGraphicsView> viewPtr{
94 view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
95 view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
96 view->setSceneRect(-1, -1, 2, (onlyQuadrant2and1 ? 1 : 2));
100 connect(viewPtr.get(), SIGNAL(
released()),
this, SLOT(mouseReleased()));
101 connect(viewPtr.get(), SIGNAL(
pressed()),
this, SIGNAL(
pressed()));
104 std::unique_ptr<QVBoxLayout> layout{
new QVBoxLayout{}};
105 layout->setSpacing(0);
106 layout->setContentsMargins(0, 0, 0, 0);
107 layout->addWidget(viewPtr.release());
108 setLayout(layout.release());
153 if (onlyQuadrant2and1 && (pos.y() > 0))
159 auto length = std::hypot(pos.x(), pos.y());
160 auto normalized = pos / length;
168 pos = (length > 1) ? normalized : pos;
173 double stepSize = 1.0 / steps;
177 static_cast<unsigned int>(length * steps + 0.3 * stepSize) * stepSize;
178 pos = std::fmin(1, newLength) * normalized;
204 if (onlyQuadrant2and1)
206 height = std::min(contentsRect().width() / 2, contentsRect().height());
211 width = std::min(contentsRect().width(), contentsRect().height());
216 view->setMinimumSize(0.9 * width, 0.9 * height);
217 view->setMaximumSize(width, height);
218 auto viewScaleFactor = 0.49 * width;
219 view->setTransform(QTransform::fromScale(viewScaleFactor, viewScaleFactor));