void DPEllipse::postResize() { QRect br = m_sizeRect; // Make octagon that roughly covers ellipse QPolygon pa(8); pa[0] = QPoint( br.x() + br.width()/4, br.y() ); pa[1] = QPoint( br.x() + 3*br.width()/4, br.y() ); pa[2] = QPoint( br.x() + br.width(), br.y() + br.height()/4 ); pa[3] = QPoint( br.x() + br.width(), br.y() + 3*br.height()/4 ); pa[4] = QPoint( br.x() + 3*br.width()/4, br.y() + br.height() ); pa[5] = QPoint( br.x() + br.width()/4, br.y() + br.height() ); pa[6] = QPoint( br.x(), br.y() + 3*br.height()/4 ); pa[7] = QPoint( br.x(), br.y() + br.height()/4 ); setItemPoints( pa, false ); }
void DPLine::postResize() { int x1 = offsetX(); int y1 = offsetY(); int x2 = x1+width(); int y2 = y1+height(); QPointArray p(4); int pw = pen().width(); int dx = abs(x1-x2); int dy = abs(y1-y2); pw = pw * 4 / 3 + 2; // approx pw*sqrt(2) int px = x1<x2 ? -pw : pw ; int py = y1<y2 ? -pw : pw ; if ( dx && dy && (dx > dy ? (dx*2/dy <= 2) : (dy*2/dx <= 2)) ) { // steep if ( px == py ) { p[0] = QPoint(x1 ,y1+py); p[1] = QPoint(x2-px,y2 ); p[2] = QPoint(x2 ,y2-py); p[3] = QPoint(x1+px,y1 ); } else { p[0] = QPoint(x1+px,y1 ); p[1] = QPoint(x2 ,y2-py); p[2] = QPoint(x2-px,y2 ); p[3] = QPoint(x1 ,y1+py); } } else if ( dx > dy ) { // horizontal p[0] = QPoint(x1+px,y1+py); p[1] = QPoint(x2-px,y2+py); p[2] = QPoint(x2-px,y2-py); p[3] = QPoint(x1+px,y1-py); } else { // vertical p[0] = QPoint(x1+px,y1+py); p[1] = QPoint(x2+px,y2-py); p[2] = QPoint(x2-px,y2-py); p[3] = QPoint(x1-px,y1+py); } setItemPoints( p, false ); }
void Item::setSize( QRect sizeRect, bool forceItemPoints ) { if ( !canvas() ) return; if ( m_sizeRect == sizeRect && !forceItemPoints ) return; if ( !preResize(sizeRect) ) return; canvas()->setChanged(areaPoints().boundingRect()); m_sizeRect = sizeRect; if ( m_itemPoints.isEmpty() || forceItemPoints ) { setItemPoints( QPolygon( m_sizeRect ), false ); } canvas()->setChanged(areaPoints().boundingRect()); postResize(); emit resized(); }
void DPText::postResize() { setItemPoints( QPolygon(m_sizeRect), false ); }
void DPRectangle::postResize() { setItemPoints( m_sizeRect, false ); }
void FlowPart::initSymbol(FlowPart::FlowSymbol symbol, int width) { m_flowSymbol = symbol; switch (symbol) { case FlowPart::ps_other: return; case FlowPart::ps_call: case FlowPart::ps_process: setItemPoints(QRect(-width / 2, -16, width, 24)); break; case FlowPart::ps_io: { // define parallelogram shape QPointArray pa(4); pa[0] = QPoint(-(width - 10) / 2, -16); pa[1] = QPoint(width / 2, -16); pa[2] = QPoint((width - 10) / 2, 8); pa[3] = QPoint(-width / 2, 8); setItemPoints(pa); break; } case FlowPart::ps_round: { // define rounded rectangles as two semicricles with RP_NUM/2 points with gap inbetween // These points are not used for drawing; merely for passing to qcanvaspolygonitem for collision detection // If there is a better way for a rounder rectangle + collision detection, please let me know... int halfHeight = 12; // Draw semicircle double x; const int RP_NUM = 48; QPointArray pa(RP_NUM); int point = 0; for (double y = -1.0; y <= 1.0; y += 4.0 / (RP_NUM - 2)) { x = sqrt(1 - y * y) * halfHeight; pa[point] = QPoint((int)(width + x) - halfHeight, (int)(halfHeight * y)); pa[RP_NUM-1-point] = QPoint((int)(halfHeight - x), (int)(halfHeight * y)); point++; } pa.translate(-width / 2, 4); setItemPoints(pa); break; } case FlowPart::ps_decision: { // define rhombus QPointArray pa(6); pa[0] = QPoint(0, -24); pa[1] = QPoint(width / 2, -6); pa[2] = QPoint(width / 2, 6); pa[3] = QPoint(0, 24); pa[4] = QPoint(-width / 2, 6); pa[5] = QPoint(-width / 2, -6); setItemPoints(pa); break; } default: kdError() << k_funcinfo << "Unknown flowSymbol: " << symbol << endl; } }
ParallelPortComponent::ParallelPortComponent(ICNDocument *icnDocument, bool newItem, const char *id) : DSubCon(icnDocument, newItem, id ? id : "parallel_port") { m_name = i18n("Parallel Port"); Q3PointArray pa(4); pa[0] = QPoint(-32, -112); pa[1] = QPoint(32, -104); pa[2] = QPoint(32, 104); pa[3] = QPoint(-32, 112); setItemPoints(pa); m_pParallelPort = new ParallelPort(); for (unsigned i = 0; i < 24; ++i) m_pLogic[i] = 0; ECNode *pin = 0; //BEGIN Data register for (int i = 0; i < 8; ++i) { QString id = QString("D%1").arg(i); QString name = id; pin = createPin(-40, -80 + 16 * i, 0, id); addDisplayText(id, QRect(-28, -88 + 16 * i, 28, 16), name, true, Qt::AlignLeft | Qt::AlignVCenter); m_pLogic[i] = new LogicOut(LogicConfig(), false); setup1pinElement(*(m_pLogic[i]), createPin(-40, -80 + 16 * i, 0, id)->pin()); // m_pLogic[i]->setCallback(this, (CallbackPtr)(&ParallelPortComponent::dataCallback)); } //END Data register //BEGIN Status register QString statusNames[] = {"ERR", "ON", "PE", "ACK", "BUSY"}; // The statusIDs are referenced in the save file and must not change QString statusIDs[] = {"ERROR", "ONLINE", "PE", "ACK", "BUSY"}; // Bits 0...2 in the Status register are not used for (int i = 3; i < 8; ++i) { QString id = statusIDs[i - 3]; QString name = statusNames[i - 3]; // Bit 3 (pin 15) doesn't not follow the same positioning pattern as // the other pins in the Status register. if (i == 3) { pin = createPin(40, -72, 180, id); addDisplayText(id, QRect(0, -80, 28, 16), name, true, Qt::AlignRight | Qt::AlignVCenter); } else { pin = createPin(-40, -16 + 16 * i, 0, id); addDisplayText(id, QRect(-28, -24 + 16*i, 28, 16), name, true, Qt::AlignLeft | Qt::AlignVCenter); } m_pLogic[i + 8] = new LogicOut(LogicConfig(), false); setup1pinElement(*(m_pLogic[i + 8]), pin->pin()); } //END Status register //BEGIN Control register QString controlNames[] = { "STR", "AUT", "INIT", "SEL" }; // The controlIDs are referenced in the save file and must not change QString controlIDs[] = { "STROBE", "AUTO", "INIT", "SELECT" }; // Bits 4..7 are not used (well; bit 5 is, but not as a pin) for (int i = 0; i < 4; ++i) { QString id = controlIDs[i]; QString name = controlNames[i]; if (i == 0) { pin = createPin(-40, -96, 0, id); addDisplayText(id, QRect(-28, -104, 28, 16), name, true, Qt::AlignLeft | Qt::AlignVCenter); } else if (i == 1) { pin = createPin(40, -88, 180, id); addDisplayText(id, QRect(0, -96, 28, 16), name, true, Qt::AlignRight | Qt::AlignVCenter); } else { pin = createPin(40, -88 + i * 16, 180, id); addDisplayText(id, QRect(0, -96 + i * 16, 28, 16), name, true, Qt::AlignRight | Qt::AlignVCenter); } m_pLogic[i + 16] = new LogicOut(LogicConfig(), false); setup1pinElement(*(m_pLogic[i + 16]), pin->pin()); // m_pLogic[i + 16]->setCallback(this, (CallbackPtr)(&ParallelPortComponent::controlCallback)); } //END Control register #if 0 // And make the rest of the pins ground for (int i = 0; i < 8; ++i) { pin = createPin(40, -24 + i * 16, 180, QString("GND%1").arg(i)); pin->pin()->setGroundType(Pin::gt_always); } #endif Variant *v = createProperty("port", Variant::Type::Combo); v->setAllowed(ParallelPort::ports(Port::ExistsAndRW)); v->setCaption(i18n("Port")); }
SerialPortComponent::SerialPortComponent( ICNDocument *icnDocument, bool newItem, const char *id ) : Component( icnDocument, newItem, id ? id : "serial_port" ) { m_name = i18n("Serial Port"); Q3PointArray pa( 4 ); pa[0] = QPoint( -32, -48 ); pa[1] = QPoint( 32, -40 ); pa[2] = QPoint( 32, 40 ); pa[3] = QPoint( -32, 48 ); setItemPoints( pa ); m_pSerialPort = new SerialPort(); ECNode * pin = 0; // Works pin = createPin( -40, 32, 0, "CD" ); addDisplayText( "CD", QRect( -28, 24, 28, 16 ), "CD", true, Qt::AlignLeft | Qt::AlignVCenter ); m_pCD = createLogicOut( pin, false ); // Doesn't work // pin = createPin( -40, 16, 0, "RD" ); addDisplayText( "RD", QRect( -28, 8, 28, 16 ), "RD", true, Qt::AlignLeft | Qt::AlignVCenter ); // m_pRD = createLogicOut( pin, false ); // Works pin = createPin( -40, 0, 0, "TD" ); addDisplayText( "TD", QRect( -28, -8, 28, 16 ), "TD", true, Qt::AlignLeft | Qt::AlignVCenter ); m_pTD = createLogicIn( pin); m_pTD->setCallback( this, (CallbackPtr)(&SerialPortComponent::tdCallback) ); // Works pin = createPin( -40, -16, 0, "DTR" ); addDisplayText( "DTR", QRect( -28, -24, 28, 16 ), "DTR", true, Qt::AlignLeft | Qt::AlignVCenter ); m_pDTR = createLogicIn( pin ); m_pDTR->setCallback( this, (CallbackPtr)(&SerialPortComponent::dtrCallback) ); // N/A pin = createPin( -40, -32, 0, "GND" ); addDisplayText( "GND", QRect( -28, -40, 28, 16 ), "GND", true, Qt::AlignLeft | Qt::AlignVCenter ); pin->pin()->setGroundType( Pin::gt_always ); // Doesn't work // pin = createPin( 40, 24, 180, "DSR" ); addDisplayText( "DSR", QRect( 0, 16, 28, 16 ), "DSR", true, Qt::AlignRight | Qt::AlignVCenter ); // m_pDSR = createLogicIn( pin ); // m_pDSR->setCallback( this, (CallbackPtr)(&SerialPortComponent::dsrCallback) ); // Doesn't work // pin = createPin( 40, 8, 180, "RTS" ); addDisplayText( "RTS", QRect( 0, 0, 28, 16 ), "RTS", true, Qt::AlignRight | Qt::AlignVCenter ); // m_pRTS = createLogicIn( pin ); // m_pRTS->setCallback( this, (CallbackPtr)(&SerialPortComponent::rtsCallback) ); // Works pin = createPin( 40, -8, 180, "CTS" ); addDisplayText( "CTS", QRect( 0, -16, 28, 16 ), "CTS", true, Qt::AlignRight | Qt::AlignVCenter ); m_pCTS = createLogicOut( pin, false ); // Works pin = createPin( 40, -24, 180, "RI" ); addDisplayText( "RI", QRect( 0, -32, 28, 16 ), "RI", true, Qt::AlignRight | Qt::AlignVCenter ); m_pRI = createLogicOut( pin, false ); Variant * v = createProperty( "port", Variant::Type::Combo ); v->setAllowed( SerialPort::ports( Port::ExistsAndRW ) ); v->setCaption( i18n("Port") ); // v = createProperty( "baudRate", Variant::Type::Select ); // v->setAllowed( QStringList::split( ",", "B0,B50,B75,B110,B134,B150,B200,B300,B600,B1200,B1800,B2400,B4800,B9600,B19200,B38400" ) ); // v->setCaption( i18n("Baud rate") ); // v->setValue("B9600"); }
void DPImage::postResize() { setItemPoints( QPointArray(m_sizeRect), false ); m_bSettingsChanged = true; }