File indexing completed on 2024-04-21 05:43:37

0001 //
0002 // C++ Implementation: outputflownode
0003 //
0004 // Description:
0005 //
0006 //
0007 // Author: David Saxton <david@bluehaze.org>, (C) 2008
0008 //
0009 // Copyright: See COPYING file that comes with this distribution
0010 //
0011 //
0012 #include "outputflownode.h"
0013 #include "connector.h"
0014 
0015 #include <QPainter>
0016 
0017 #include <ktechlab_debug.h>
0018 
0019 OutputFlowNode::OutputFlowNode(ICNDocument *_icnView, int dir, const QPoint &pos, QString *id)
0020     : FPNode(_icnView, Node::fp_out, dir, pos, id)
0021 {
0022 }
0023 
0024 OutputFlowNode::~OutputFlowNode()
0025 {
0026 }
0027 
0028 bool OutputFlowNode::acceptInput() const
0029 {
0030     return false;
0031 }
0032 
0033 bool OutputFlowNode::acceptOutput() const
0034 {
0035     return true;
0036 }
0037 
0038 void OutputFlowNode::addInputConnector(Connector *const /*connector*/)
0039 {
0040     qCDebug(KTL_LOG) << "BUG: trying to add input connector to an output node";
0041 }
0042 
0043 inline QPolygon arrowPoints(int dir)
0044 {
0045     QPolygon pa(3);
0046     switch (dir) {
0047     case 0:
0048         pa[0] = QPoint(3, 0);
0049         pa[1] = QPoint(0, 2);
0050         pa[2] = QPoint(0, -2);
0051         break;
0052     case 180:
0053         pa[0] = QPoint(-3, 0);
0054         pa[1] = QPoint(0, 2);
0055         pa[2] = QPoint(0, -2);
0056         break;
0057     case 90:
0058         pa[0] = QPoint(2, 0);
0059         pa[1] = QPoint(-2, 0);
0060         pa[2] = QPoint(0, 3);
0061         break;
0062     case 270:
0063         pa[0] = QPoint(2, 0);
0064         pa[1] = QPoint(-2, 0);
0065         pa[2] = QPoint(0, -3);
0066         break;
0067     };
0068     return pa;
0069 }
0070 
0071 void OutputFlowNode::drawShape(QPainter &p)
0072 {
0073     const int _x = int(x());
0074     const int _y = int(y());
0075 
0076     if (m_dir == 0)
0077         p.drawLine(_x, _y, _x - 8, _y);
0078     else if (m_dir == 90)
0079         p.drawLine(_x, _y, _x, _y - 8);
0080     else if (m_dir == 180)
0081         p.drawLine(_x, _y, _x + 8, _y);
0082     else if (m_dir == 270)
0083         p.drawLine(_x, _y, _x, _y + 8);
0084 
0085     QPolygon pa(3);
0086 
0087     switch (m_dir) {
0088     case 0: // right
0089         pa = arrowPoints(0);
0090         break;
0091     case 180: // left
0092         pa = arrowPoints(180);
0093         break;
0094     case 90: // down
0095         pa = arrowPoints(90);
0096         break;
0097     case 270: // up
0098         pa = arrowPoints(270);
0099         break;
0100     default:
0101         qCCritical(KTL_LOG) << "BUG: m_dir = " << m_dir;
0102     }
0103 
0104     // Note: I have not tested the positioning of the arrows for all combinations.
0105     // In fact, most almost definitely do not work. So feel free to change the code
0106     // as you see fit if necessary.
0107 
0108     if (m_dir == 0)
0109         pa.translate(-5, 0);
0110     else if (m_dir == 90)
0111         pa.translate(0, -5);
0112     else if (m_dir == 180)
0113         pa.translate(5, 0);
0114     else if (m_dir == 270)
0115         pa.translate(0, 5);
0116 
0117     pa.translate(_x, _y);
0118     p.drawPolygon(pa);
0119 }