244 lines
8.8 KiB
C++
244 lines
8.8 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(316,152,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(316,21,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(236,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(234,150,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(320,306,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(235,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(316,403,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(12,148,38,38);
|
|
OutputSelectZoneHandle->show();
|
|
OutputSelectZoneHandle->raise();
|
|
mOutputSelectZoneList.append(OutputSelectZoneHandle);
|
|
|
|
//14 pins
|
|
OutputSelectZoneHandle = new CConnectorClickZoneWidget(CConnectorDefs::OUTPUT_14_PINS_CONNECTOR_TYPE,this);
|
|
OutputSelectZoneHandle->setGeometry(13,24,41,42);
|
|
OutputSelectZoneHandle->show();
|
|
OutputSelectZoneHandle->raise();
|
|
mOutputSelectZoneList.append(OutputSelectZoneHandle);
|
|
|
|
//24 pins
|
|
OutputSelectZoneHandle = new CConnectorClickZoneWidget(CConnectorDefs::OUTPUT_24_PINS_CONNECTOR_TYPE,this);
|
|
OutputSelectZoneHandle->setGeometry(91,23,48,86);
|
|
OutputSelectZoneHandle->show();
|
|
OutputSelectZoneHandle->raise();
|
|
mOutputSelectZoneList.append(OutputSelectZoneHandle);
|
|
|
|
//72 pins
|
|
OutputSelectZoneHandle = new CConnectorClickZoneWidget(CConnectorDefs::OUTPUT_72_PINS_CONNECTOR_TYPE,this);
|
|
OutputSelectZoneHandle->setGeometry(92,150,46,121);
|
|
OutputSelectZoneHandle->show();
|
|
OutputSelectZoneHandle->raise();
|
|
mOutputSelectZoneList.append(OutputSelectZoneHandle);
|
|
|
|
//108 pins
|
|
OutputSelectZoneHandle = new CConnectorClickZoneWidget(CConnectorDefs::OUTPUT_108_PINS_CONNECTOR_TYPE,this);
|
|
OutputSelectZoneHandle->setGeometry(92,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;
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
ClearAllConnectorsSelections();
|
|
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();
|
|
mCurSelConnector = ConClickZone->GetConnectorType();
|
|
}
|
|
|
|
emit ConnectorSelected(mCurSelConnector);
|
|
}
|
|
|
|
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();
|
|
|
|
return RET_OK;
|
|
}
|
|
|
|
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;
|
|
}
|