Make buttons toggleable by single clicking

This commit is contained in:
xypwn
2020-04-04 14:07:16 +02:00
parent 5340635389
commit 7ade16be8b
20 changed files with 80 additions and 65 deletions

View File

@@ -1,12 +1,11 @@
#include "Part.h"
#include <QDebug>
#include <QPainter>
#include <QStyleOptionGraphicsItem>
#include <QGraphicsSceneDragDropEvent>
#include <QLabel>
#include <QGraphicsProxyWidget>
#include <QtMath>
#include "eAlignMode.h"
#include "eConnectorType.h"
@@ -16,8 +15,6 @@
#include "Logic.h"
#include "Label.h"
#include <QDebug>
// PUBLIC
Part::Part(Logic* logic, CircuitItemBaseShape baseShape)
:m_logic(logic), m_baseShape(baseShape)
@@ -91,7 +88,7 @@ void Part::setWidth(int factor)
void Part::recalculateLayout()
{
// Return if the part isn't in any scene
// No need to recalculate any graphical things if this part isn't in any scene
if(m_logic->parentScene() == nullptr)
return;
// Add inputs and outputs and position them correctly
@@ -215,6 +212,27 @@ QVariant Part::itemChange(GraphicsItemChange change, const QVariant & value)
return QGraphicsItem::itemChange(change, value);
}
// PROTECTED
void Part::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
m_dragBeginPos = event->screenPos();
QGraphicsItem::mousePressEvent(event);
}
void Part::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
QPointF deltaPos = event->screenPos() - m_dragBeginPos;
qreal dist = qSqrt(deltaPos.x()*deltaPos.x() + deltaPos.y()*deltaPos.y());
if(dist <= 5)
{
partClickedEvent();
return;
}
if(m_logic->parentScene() != nullptr)
m_logic->parentScene()->partMoved(deltaPos);
QGraphicsItem::mouseReleaseEvent(event);
}
// PRIVATE
void Part::updateState()
{