void GuiPart::updateConnectorPoints( bool add ) { ICNDocument *icnd = dynamic_cast<ICNDocument*>(p_parent->itemDocument()); if ( !icnd) return; Cells * cells = icnd->cells(); if (!cells) return; if ( !isVisible() ) add = false; if ( add == b_pointsAdded ) return; b_pointsAdded = add; int mult = add ? 1 : -1; int sx = roundDown( x(), 8 ); int sy = roundDown( y(), 8 ); int ex = roundDown( x()+width(), 8 ); int ey = roundDown( y()+height(), 8 ); for ( int x=sx; x<=ex; ++x ) { for ( int y=sy; y<=ey; ++y ) { if ( cells->haveCell( x, y ) ) cells->cell( x, y ).CIpenalty += mult*ICNDocument::hs_item/2; } } }
void Canvas::drawBackground(QPainter &p, const QRect & clip) { QCanvas::drawBackground(p, clip); #if 0 const int scx = (int)((clip.left() - 4) / 8); const int ecx = (int)((clip.right() + 4) / 8); const int scy = (int)((clip.top() - 4) / 8); const int ecy = (int)((clip.bottom() + 4) / 8); ICNDocument * icnd = dynamic_cast<ICNDocument*>(p_itemDocument); if (!icnd) return; Cells * c = icnd->cells(); if (!c->haveCell(scx, scy) || !c->haveCell(ecx, ecy)) return; for (int x = scx; x <= ecx; x++) { for (int y = scy; y <= ecy; y++) { const double score = c->cell(x, y).CIpenalty + c->cell(x, y).Cpenalty; int value = (int)std::log(score) * 20; if (value > 255) value = 255; else if (value < 0) value = 0; p.setBrush(QColor(255, (255 - value), (255 - value))); p.setPen(Qt::NoPen); p.drawRect((x*8), (y*8), 8, 8); } } #endif }
void CNItem::updateConnectorPoints( bool add ) { if ( b_deleted || !isVisible() ) add = false; if ( b_pointsAdded == add ) return; b_pointsAdded = add; Cells *cells = p_icnDocument->cells(); if (!cells) return; // Get translation matrix // Hackish... QWMatrix m; if ( Component *c = dynamic_cast<Component*>(this) ) m = c->transMatrix( c->angleDegrees(), c->flipped(), int(x()), int(y()), false ); // Convention used here: _UM = unmapped by both matrix and cell reference, _M = mapped const QPoint start_UM = QPoint( int(x()+offsetX())-8, int(y()+offsetY())-8 ); const QPoint end_UM = start_UM + QPoint( width()+2*8, height()+2*8 ); const QPoint start_M = roundDown( m.map(start_UM), 8 ); const QPoint end_M = roundDown( m.map(end_UM), 8 ); int sx_M = start_M.x(); int ex_M = end_M.x(); int sy_M = start_M.y(); int ey_M = end_M.y(); // Normalise start and end points if ( sx_M > ex_M ) { const int temp = sx_M; sx_M = ex_M; ex_M = temp; } if ( sy_M > ey_M ) { const int temp = sy_M; sy_M = ey_M; ey_M = temp; } ex_M++; ey_M++; const int mult = add ? 1 : -1; for ( int x = sx_M; x < ex_M; x++ ) { for ( int y = sy_M; y < ey_M; y++ ) { if ( cells->haveCell( x, y ) ) { if ( x != sx_M && y != sy_M && x != (ex_M-1) && y != (ey_M-1) ) { cells->cell( x, y ).CIpenalty += mult*ICNDocument::hs_item; } else { // (*cells)[x][y].CIpenalty += mult*ICNDocument::hs_item/2; cells->cell( x, y ).CIpenalty += mult*ICNDocument::hs_connector*5; } } } } #if 0 // And subtract the positions of the node on the border NodeInfoMap::iterator end = m_nodeMap.end(); for ( NodeInfoMap::iterator it = m_nodeMap.begin(); it != end; ++it ) { const int x = (int)((it->second.node->x()-4)/cellSize); const int y = (int)((it->second.node->y()-4)/cellSize); if ( p_icnDocument->isValidCellReference(x,y) ) { (*cells)[x][y].CIpenalty -= mult*ICNDocument::hs_connector*5; } } #endif const TextMap::iterator textMapEnd = m_textMap.end(); for ( TextMap::iterator it = m_textMap.begin(); it != textMapEnd; ++it ) { it.data()->updateConnectorPoints(add); } const WidgetMap::iterator widgetMapEnd = m_widgetMap.end(); for ( WidgetMap::iterator it = m_widgetMap.begin(); it != widgetMapEnd; ++it ) { it.data()->updateConnectorPoints(add); } }