Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 

239 řádky
8.8 KiB

  1. #include "ConnectorSelectWidget.h"
  2. #include <QPainter>
  3. #include "CableTestBenchDefs.h"
  4. CConnectorSelectWidget::CConnectorSelectWidget(QWidget *parent) :
  5. QWidget(parent)
  6. {
  7. mConnectorLayoutPixmap = new QPixmap("./images/connecteurs.png");
  8. mCurSelConnector = CConnectorDefs::UNKNOWN_CONNECTOR_TYPE;
  9. //Create click zones for all input connectors
  10. CConnectorClickZoneWidget *InputClickZoneHandle;
  11. //6 pins
  12. InputClickZoneHandle = new CConnectorClickZoneWidget(CConnectorDefs::INPUT_6_PINS_CONNECTOR_TYPE,this);
  13. InputClickZoneHandle->setGeometry(7,149,53,54);
  14. InputClickZoneHandle->show();
  15. InputClickZoneHandle->raise();
  16. connect(InputClickZoneHandle,SIGNAL(ConnectorZoneClicked(CConnectorClickZoneWidget*)),this,SLOT(InputConnectorZoneClicked(CConnectorClickZoneWidget*)));
  17. mInputClickZoneList.append(InputClickZoneHandle);
  18. //14 pins
  19. InputClickZoneHandle = new CConnectorClickZoneWidget(CConnectorDefs::INPUT_14_PINS_CONNECTOR_TYPE,this);
  20. InputClickZoneHandle->setGeometry(7,23,53,54);
  21. InputClickZoneHandle->show();
  22. InputClickZoneHandle->raise();
  23. connect(InputClickZoneHandle,SIGNAL(ConnectorZoneClicked(CConnectorClickZoneWidget*)),this,SLOT(InputConnectorZoneClicked(CConnectorClickZoneWidget*)));
  24. mInputClickZoneList.append(InputClickZoneHandle);
  25. //24 pins
  26. InputClickZoneHandle = new CConnectorClickZoneWidget(CConnectorDefs::INPUT_24_PINS_CONNECTOR_TYPE,this);
  27. InputClickZoneHandle->setGeometry(92,23,48,86);
  28. InputClickZoneHandle->show();
  29. InputClickZoneHandle->raise();
  30. connect(InputClickZoneHandle,SIGNAL(ConnectorZoneClicked(CConnectorClickZoneWidget*)),this,SLOT(InputConnectorZoneClicked(CConnectorClickZoneWidget*)));
  31. mInputClickZoneList.append(InputClickZoneHandle);
  32. //72 pins
  33. InputClickZoneHandle = new CConnectorClickZoneWidget(CConnectorDefs::INPUT_72_PINS_CONNECTOR_TYPE,this);
  34. InputClickZoneHandle->setGeometry(92,149,47,120);
  35. InputClickZoneHandle->show();
  36. InputClickZoneHandle->raise();
  37. connect(InputClickZoneHandle,SIGNAL(ConnectorZoneClicked(CConnectorClickZoneWidget*)),this,SLOT(InputConnectorZoneClicked(CConnectorClickZoneWidget*)));
  38. mInputClickZoneList.append(InputClickZoneHandle);
  39. //90 pins
  40. InputClickZoneHandle = new CConnectorClickZoneWidget(CConnectorDefs::INPUT_90_PINS_CONNECTOR_TYPE,this);
  41. InputClickZoneHandle->setGeometry(17,286,33,73);
  42. InputClickZoneHandle->show();
  43. InputClickZoneHandle->raise();
  44. connect(InputClickZoneHandle,SIGNAL(ConnectorZoneClicked(CConnectorClickZoneWidget*)),this,SLOT(InputConnectorZoneClicked(CConnectorClickZoneWidget*)));
  45. mInputClickZoneList.append(InputClickZoneHandle);
  46. //108 pins
  47. InputClickZoneHandle = new CConnectorClickZoneWidget(CConnectorDefs::INPUT_108_PINS_CONNECTOR_TYPE,this);
  48. InputClickZoneHandle->setGeometry(92,308,47,149);
  49. InputClickZoneHandle->show();
  50. InputClickZoneHandle->raise();
  51. connect(InputClickZoneHandle,SIGNAL(ConnectorZoneClicked(CConnectorClickZoneWidget*)),this,SLOT(InputConnectorZoneClicked(CConnectorClickZoneWidget*)));
  52. mInputClickZoneList.append(InputClickZoneHandle);
  53. //120 pins
  54. InputClickZoneHandle = new CConnectorClickZoneWidget(CConnectorDefs::INPUT_120_PINS_CONNECTOR_TYPE,this);
  55. InputClickZoneHandle->setGeometry(13,382,42,74);
  56. InputClickZoneHandle->show();
  57. InputClickZoneHandle->raise();
  58. connect(InputClickZoneHandle,SIGNAL(ConnectorZoneClicked(CConnectorClickZoneWidget*)),this,SLOT(InputConnectorZoneClicked(CConnectorClickZoneWidget*)));
  59. mInputClickZoneList.append(InputClickZoneHandle);
  60. //Create selection zones for all output connectors
  61. CConnectorClickZoneWidget *OutputSelectZoneHandle;
  62. //6 pins
  63. OutputSelectZoneHandle = new CConnectorClickZoneWidget(CConnectorDefs::OUTPUT_6_PINS_CONNECTOR_TYPE,this);
  64. OutputSelectZoneHandle->setGeometry(329,149,38,38);
  65. OutputSelectZoneHandle->show();
  66. OutputSelectZoneHandle->raise();
  67. mOutputSelectZoneList.append(OutputSelectZoneHandle);
  68. //14 pins
  69. OutputSelectZoneHandle = new CConnectorClickZoneWidget(CConnectorDefs::OUTPUT_14_PINS_CONNECTOR_TYPE,this);
  70. OutputSelectZoneHandle->setGeometry(327,23,41,42);
  71. OutputSelectZoneHandle->show();
  72. OutputSelectZoneHandle->raise();
  73. mOutputSelectZoneList.append(OutputSelectZoneHandle);
  74. //24 pins
  75. OutputSelectZoneHandle = new CConnectorClickZoneWidget(CConnectorDefs::OUTPUT_24_PINS_CONNECTOR_TYPE,this);
  76. OutputSelectZoneHandle->setGeometry(235,23,48,86);
  77. OutputSelectZoneHandle->show();
  78. OutputSelectZoneHandle->raise();
  79. mOutputSelectZoneList.append(OutputSelectZoneHandle);
  80. //72 pins
  81. OutputSelectZoneHandle = new CConnectorClickZoneWidget(CConnectorDefs::OUTPUT_72_PINS_CONNECTOR_TYPE,this);
  82. OutputSelectZoneHandle->setGeometry(235,149,46,121);
  83. OutputSelectZoneHandle->show();
  84. OutputSelectZoneHandle->raise();
  85. mOutputSelectZoneList.append(OutputSelectZoneHandle);
  86. //108 pins
  87. OutputSelectZoneHandle = new CConnectorClickZoneWidget(CConnectorDefs::OUTPUT_108_PINS_CONNECTOR_TYPE,this);
  88. OutputSelectZoneHandle->setGeometry(235,308,47,148);
  89. OutputSelectZoneHandle->show();
  90. OutputSelectZoneHandle->raise();
  91. mOutputSelectZoneList.append(OutputSelectZoneHandle);
  92. }
  93. void CConnectorSelectWidget::paintEvent(QPaintEvent *event)
  94. {
  95. QPainter painter(this);
  96. painter.drawPixmap(0,0,*mConnectorLayoutPixmap);
  97. QPen pen;
  98. // pen.setStyle(Qt::SolidLine);
  99. // pen.setWidth(10);
  100. // pen.setBrush(Qt::red);
  101. // painter.setPen(pen);
  102. //painter.drawRect(this->geometry());
  103. // painter.drawRect(QRect(7,149,53,54));
  104. }
  105. void CConnectorSelectWidget::InputConnectorZoneClicked(CConnectorClickZoneWidget *ConClickZone)
  106. {
  107. qDebug("Connector zone clicked: %d",ConClickZone->GetConnectorType());
  108. if(ConClickZone->IsConSelected() == true)
  109. {
  110. ClearAllConnectorsSelections();
  111. mCurSelConnector = CConnectorDefs::UNKNOWN_CONNECTOR_TYPE;
  112. }
  113. else
  114. {
  115. ClearAllConnectorsSelections();
  116. CConnectorClickZoneWidget *OutputSelZone = 0;
  117. switch(ConClickZone->GetConnectorType())
  118. {
  119. case CConnectorDefs::INPUT_6_PINS_CONNECTOR_TYPE:
  120. {
  121. OutputSelZone = FindOutputSelectionZone(CConnectorDefs::OUTPUT_6_PINS_CONNECTOR_TYPE);
  122. break;
  123. }
  124. case CConnectorDefs::INPUT_14_PINS_CONNECTOR_TYPE:
  125. {
  126. OutputSelZone = FindOutputSelectionZone(CConnectorDefs::OUTPUT_14_PINS_CONNECTOR_TYPE);
  127. break;
  128. }
  129. case CConnectorDefs::INPUT_24_PINS_CONNECTOR_TYPE:
  130. {
  131. OutputSelZone = FindOutputSelectionZone(CConnectorDefs::OUTPUT_24_PINS_CONNECTOR_TYPE);
  132. break;
  133. }
  134. case CConnectorDefs::INPUT_72_PINS_CONNECTOR_TYPE:
  135. {
  136. OutputSelZone = FindOutputSelectionZone(CConnectorDefs::OUTPUT_72_PINS_CONNECTOR_TYPE);
  137. break;
  138. }
  139. case CConnectorDefs::INPUT_90_PINS_CONNECTOR_TYPE:
  140. case CConnectorDefs::INPUT_108_PINS_CONNECTOR_TYPE:
  141. case CConnectorDefs::INPUT_120_PINS_CONNECTOR_TYPE:
  142. {
  143. OutputSelZone = FindOutputSelectionZone(CConnectorDefs::OUTPUT_108_PINS_CONNECTOR_TYPE);
  144. break;
  145. }
  146. default:
  147. {
  148. break;
  149. }
  150. }
  151. if(OutputSelZone != 0)
  152. {
  153. OutputSelZone->SelectConnector(true,Qt::darkGreen);
  154. }
  155. ConClickZone->SelectConnector();
  156. mCurSelConnector = ConClickZone->GetConnectorType();
  157. }
  158. }
  159. CConnectorSelectWidget::~CConnectorSelectWidget()
  160. {
  161. qDebug("Destroyed");
  162. for(int i = 0; i < mInputClickZoneList.size(); i++)
  163. {
  164. delete mInputClickZoneList.at(i);
  165. }
  166. mInputClickZoneList.clear();
  167. for(int i = 0; i < mOutputSelectZoneList.size(); i++)
  168. {
  169. delete mOutputSelectZoneList.at(i);
  170. }
  171. mOutputSelectZoneList.clear();
  172. }
  173. int CConnectorSelectWidget::ClearAllOutputConSelections()
  174. {
  175. for(int i = 0; i < mOutputSelectZoneList.size(); i++)
  176. {
  177. mOutputSelectZoneList.at(i)->ClearConnectorSelection();
  178. }
  179. return RET_OK;
  180. }
  181. int CConnectorSelectWidget::ClearAllInputConSelections()
  182. {
  183. for(int i = 0; i < mInputClickZoneList.size(); i++)
  184. {
  185. mInputClickZoneList.at(i)->ClearConnectorSelection();
  186. }
  187. return RET_OK;
  188. }
  189. int CConnectorSelectWidget::ClearAllConnectorsSelections()
  190. {
  191. ClearAllOutputConSelections();
  192. ClearAllInputConSelections();
  193. }
  194. CConnectorClickZoneWidget* CConnectorSelectWidget::FindOutputSelectionZone(CConnectorDefs::eConnectorType type)
  195. {
  196. for(int i = 0; i < mOutputSelectZoneList.size(); i++)
  197. {
  198. if(mOutputSelectZoneList.at(i)->GetConnectorType() == type)
  199. {
  200. return mOutputSelectZoneList.at(i);
  201. }
  202. }
  203. return 0;
  204. }