CableTestBench/Sources/Widgets/ConnectorSelectWidget.cpp
2019-04-17 01:01:32 -04:00

238 lines
8.7 KiB
C++

#include "ConnectorSelectWidget.h"
#include <QPainter>
#include "CableTestBenchDefs.h"
CConnectorSelectWidget::CConnectorSelectWidget(QWidget *parent) :
QWidget(parent)
{
mConnectorLayoutPixmap = new QPixmap("./images/connecteurs.png");
mCurSelConnector = CConnectorDefs::UNKNOWN_CONNECTOR_TYPE;
//Create click zones for all input connectors
CConnectorClickZoneWidget *InputClickZoneHandle;
//6 pins
InputClickZoneHandle = new CConnectorClickZoneWidget(CConnectorDefs::INPUT_6_PINS_CONNECTOR_TYPE,this);
InputClickZoneHandle->setGeometry(7,149,53,54);
InputClickZoneHandle->show();
InputClickZoneHandle->raise();
connect(InputClickZoneHandle,SIGNAL(ConnectorZoneClicked(CConnectorClickZoneWidget*)),this,SLOT(InputConnectorZoneClicked(CConnectorClickZoneWidget*)));
mInputClickZoneList.append(InputClickZoneHandle);
//14 pins
InputClickZoneHandle = new CConnectorClickZoneWidget(CConnectorDefs::INPUT_14_PINS_CONNECTOR_TYPE,this);
InputClickZoneHandle->setGeometry(7,23,53,54);
InputClickZoneHandle->show();
InputClickZoneHandle->raise();
connect(InputClickZoneHandle,SIGNAL(ConnectorZoneClicked(CConnectorClickZoneWidget*)),this,SLOT(InputConnectorZoneClicked(CConnectorClickZoneWidget*)));
mInputClickZoneList.append(InputClickZoneHandle);
//24 pins
InputClickZoneHandle = new CConnectorClickZoneWidget(CConnectorDefs::INPUT_24_PINS_CONNECTOR_TYPE,this);
InputClickZoneHandle->setGeometry(92,23,48,86);
InputClickZoneHandle->show();
InputClickZoneHandle->raise();
connect(InputClickZoneHandle,SIGNAL(ConnectorZoneClicked(CConnectorClickZoneWidget*)),this,SLOT(InputConnectorZoneClicked(CConnectorClickZoneWidget*)));
mInputClickZoneList.append(InputClickZoneHandle);
//72 pins
InputClickZoneHandle = new CConnectorClickZoneWidget(CConnectorDefs::INPUT_72_PINS_CONNECTOR_TYPE,this);
InputClickZoneHandle->setGeometry(92,149,47,120);
InputClickZoneHandle->show();
InputClickZoneHandle->raise();
connect(InputClickZoneHandle,SIGNAL(ConnectorZoneClicked(CConnectorClickZoneWidget*)),this,SLOT(InputConnectorZoneClicked(CConnectorClickZoneWidget*)));
mInputClickZoneList.append(InputClickZoneHandle);
//90 pins
InputClickZoneHandle = new CConnectorClickZoneWidget(CConnectorDefs::INPUT_90_PINS_CONNECTOR_TYPE,this);
InputClickZoneHandle->setGeometry(17,286,33,73);
InputClickZoneHandle->show();
InputClickZoneHandle->raise();
connect(InputClickZoneHandle,SIGNAL(ConnectorZoneClicked(CConnectorClickZoneWidget*)),this,SLOT(InputConnectorZoneClicked(CConnectorClickZoneWidget*)));
mInputClickZoneList.append(InputClickZoneHandle);
//108 pins
InputClickZoneHandle = new CConnectorClickZoneWidget(CConnectorDefs::INPUT_108_PINS_CONNECTOR_TYPE,this);
InputClickZoneHandle->setGeometry(92,308,47,149);
InputClickZoneHandle->show();
InputClickZoneHandle->raise();
connect(InputClickZoneHandle,SIGNAL(ConnectorZoneClicked(CConnectorClickZoneWidget*)),this,SLOT(InputConnectorZoneClicked(CConnectorClickZoneWidget*)));
mInputClickZoneList.append(InputClickZoneHandle);
//120 pins
InputClickZoneHandle = new CConnectorClickZoneWidget(CConnectorDefs::INPUT_120_PINS_CONNECTOR_TYPE,this);
InputClickZoneHandle->setGeometry(13,382,42,74);
InputClickZoneHandle->show();
InputClickZoneHandle->raise();
connect(InputClickZoneHandle,SIGNAL(ConnectorZoneClicked(CConnectorClickZoneWidget*)),this,SLOT(InputConnectorZoneClicked(CConnectorClickZoneWidget*)));
mInputClickZoneList.append(InputClickZoneHandle);
//Create selection zones for all output connectors
CConnectorClickZoneWidget *OutputSelectZoneHandle;
//6 pins
OutputSelectZoneHandle = new CConnectorClickZoneWidget(CConnectorDefs::OUTPUT_6_PINS_CONNECTOR_TYPE,this);
OutputSelectZoneHandle->setGeometry(329,149,38,38);
OutputSelectZoneHandle->show();
OutputSelectZoneHandle->raise();
mOutputSelectZoneList.append(OutputSelectZoneHandle);
//14 pins
OutputSelectZoneHandle = new CConnectorClickZoneWidget(CConnectorDefs::OUTPUT_14_PINS_CONNECTOR_TYPE,this);
OutputSelectZoneHandle->setGeometry(327,23,41,42);
OutputSelectZoneHandle->show();
OutputSelectZoneHandle->raise();
mOutputSelectZoneList.append(OutputSelectZoneHandle);
//24 pins
OutputSelectZoneHandle = new CConnectorClickZoneWidget(CConnectorDefs::OUTPUT_24_PINS_CONNECTOR_TYPE,this);
OutputSelectZoneHandle->setGeometry(235,23,48,86);
OutputSelectZoneHandle->show();
OutputSelectZoneHandle->raise();
mOutputSelectZoneList.append(OutputSelectZoneHandle);
//72 pins
OutputSelectZoneHandle = new CConnectorClickZoneWidget(CConnectorDefs::OUTPUT_72_PINS_CONNECTOR_TYPE,this);
OutputSelectZoneHandle->setGeometry(235,149,46,121);
OutputSelectZoneHandle->show();
OutputSelectZoneHandle->raise();
mOutputSelectZoneList.append(OutputSelectZoneHandle);
//108 pins
OutputSelectZoneHandle = new CConnectorClickZoneWidget(CConnectorDefs::OUTPUT_108_PINS_CONNECTOR_TYPE,this);
OutputSelectZoneHandle->setGeometry(235,308,47,148);
OutputSelectZoneHandle->show();
OutputSelectZoneHandle->raise();
mOutputSelectZoneList.append(OutputSelectZoneHandle);
}
void CConnectorSelectWidget::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.drawPixmap(0,0,*mConnectorLayoutPixmap);
QPen pen;
// pen.setStyle(Qt::SolidLine);
// pen.setWidth(10);
// pen.setBrush(Qt::red);
// painter.setPen(pen);
//painter.drawRect(this->geometry());
// painter.drawRect(QRect(7,149,53,54));
}
void CConnectorSelectWidget::InputConnectorZoneClicked(CConnectorClickZoneWidget *ConClickZone)
{
qDebug("Connector zone clicked: %d",ConClickZone->GetConnectorType());
if(ConClickZone->IsConSelected() == true)
{
ClearAllConnectorsSelections();
mCurSelConnector = CConnectorDefs::UNKNOWN_CONNECTOR_TYPE;
}
else
{
CConnectorClickZoneWidget *OutputSelZone = 0;
switch(ConClickZone->GetConnectorType())
{
case CConnectorDefs::INPUT_6_PINS_CONNECTOR_TYPE:
{
OutputSelZone = FindOutputSelectionZone(CConnectorDefs::OUTPUT_6_PINS_CONNECTOR_TYPE);
break;
}
case CConnectorDefs::INPUT_14_PINS_CONNECTOR_TYPE:
{
OutputSelZone = FindOutputSelectionZone(CConnectorDefs::OUTPUT_14_PINS_CONNECTOR_TYPE);
break;
}
case CConnectorDefs::INPUT_24_PINS_CONNECTOR_TYPE:
{
OutputSelZone = FindOutputSelectionZone(CConnectorDefs::OUTPUT_24_PINS_CONNECTOR_TYPE);
break;
}
case CConnectorDefs::INPUT_72_PINS_CONNECTOR_TYPE:
{
OutputSelZone = FindOutputSelectionZone(CConnectorDefs::OUTPUT_72_PINS_CONNECTOR_TYPE);
break;
}
case CConnectorDefs::INPUT_90_PINS_CONNECTOR_TYPE:
case CConnectorDefs::INPUT_108_PINS_CONNECTOR_TYPE:
case CConnectorDefs::INPUT_120_PINS_CONNECTOR_TYPE:
{
OutputSelZone = FindOutputSelectionZone(CConnectorDefs::OUTPUT_108_PINS_CONNECTOR_TYPE);
break;
}
default:
{
break;
}
}
if(OutputSelZone != 0)
{
OutputSelZone->SelectConnector(true,Qt::darkGreen);
}
ConClickZone->SelectConnector();
}
}
CConnectorSelectWidget::~CConnectorSelectWidget()
{
qDebug("Destroyed");
for(int i = 0; i < mInputClickZoneList.size(); i++)
{
delete mInputClickZoneList.at(i);
}
mInputClickZoneList.clear();
for(int i = 0; i < mOutputSelectZoneList.size(); i++)
{
delete mOutputSelectZoneList.at(i);
}
mOutputSelectZoneList.clear();
}
int CConnectorSelectWidget::ClearAllOutputConSelections()
{
for(int i = 0; i < mOutputSelectZoneList.size(); i++)
{
mOutputSelectZoneList.at(i)->ClearConnectorSelection();
}
return RET_OK;
}
int CConnectorSelectWidget::ClearAllInputConSelections()
{
for(int i = 0; i < mInputClickZoneList.size(); i++)
{
mInputClickZoneList.at(i)->ClearConnectorSelection();
}
return RET_OK;
}
int CConnectorSelectWidget::ClearAllConnectorsSelections()
{
ClearAllOutputConSelections();
ClearAllInputConSelections();
}
CConnectorClickZoneWidget* CConnectorSelectWidget::FindOutputSelectionZone(CConnectorDefs::eConnectorType type)
{
for(int i = 0; i < mOutputSelectZoneList.size(); i++)
{
if(mOutputSelectZoneList.at(i)->GetConnectorType() == type)
{
return mOutputSelectZoneList.at(i);
}
}
return 0;
}