/*************************************************************************** * Copyright (C) 2003-2005 by David Saxton * * david@bluehaze.org * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * ***************************************************************************/ #include "canvasitemparts.h" #include "cells.h" #include "icndocument.h" #include "flowcontainer.h" #include "fpnode.h" #include "nodegroup.h" #include "resizeoverlay.h" #include #include #include const int topStrip = 24; const int botStrip = 16; FlowContainer::FlowContainer( ICNDocument *_icnDocument, bool newItem, const TQString &id ) : FlowPart( _icnDocument, newItem, id ) { m_ext_in = m_int_in = m_int_out = m_ext_out = 0l; b_expanded = true; addButton( "expandBtn", TQRect( offsetX(), offsetY()+24 - 11, 22, 22 ), TDEGlobal::iconLoader()->loadIcon( "go-down", TDEIcon::Small ), true ); m_rectangularOverlay = new RectangularOverlay( this, 8, 8 ); setSize( -160, -120, 320, 240 ); m_int_in = (FPNode*)createNode( width()/2, 8+topStrip, Node::dir_down, "int_in", Node::fp_out ); m_int_out = (FPNode*)createNode( width()/2, height()-8-botStrip, Node::dir_up, "int_out", Node::fp_in ); button("expandBtn")->setState(true); updateAttachedPositioning(); updateNodeLevels(); } FlowContainer::~FlowContainer() { } void FlowContainer::updateNodeLevels() { FlowPart::updateNodeLevels(); int l = level(); if (m_ext_in) m_ext_in->setLevel(l); if (m_ext_out) m_ext_out->setLevel(l); if (m_int_in) m_int_in->setLevel(l+1); if (m_int_out) m_int_out->setLevel(l+1); } void FlowContainer::filterEndPartIDs( TQStringList *ids ) { // Remove *all* nodes except for very bottom one if (m_int_out) { ids->remove(m_int_out->childId()); } if (m_ext_in) { ids->remove(m_ext_in->childId()); } if (m_int_in) { ids->remove(m_int_in->childId()); } } void FlowContainer::createTopContainerNode() { m_ext_in = (FPNode*)createNode( width()/2, -8, Node::dir_up, "ext_in", Node::fp_in ); m_ext_in->setLevel( level() ); m_rectangularOverlay->removeTopMiddle(); updateAttachedPositioning(); } void FlowContainer::createBotContainerNode() { m_ext_out = (FPNode*)createNode( width()/2, height()+8, Node::dir_down, "ext_out", Node::fp_out ); m_ext_out->setLevel( level() ); m_rectangularOverlay->removeBotMiddle(); updateAttachedPositioning(); } TQSize FlowContainer::minimumSize() const { return TQSize( 160, 64 ); } void FlowContainer::drawShape( TQPainter &p ) { if (b_deleted) return; if ( !m_sizeRect.isValid() ) return; const int _x = (int)x()+offsetX(); const int _y = (int)y()+offsetY(); int col = 0xef + level()*0x6; if ( col > 0xff ) col = 0xff; p.setBrush( TQColor( col, 0xff, col ) ); if( b_expanded ) { p.setPen(TQt::DotLine); p.drawRoundRect( _x, _y, width(), topStrip, 1500/width(), 1500/topStrip ); p.drawRoundRect( _x, _y+height()-botStrip, width(), botStrip, 1500/width(), 1500/botStrip ); } else { p.setPen(TQPen((isSelected()?m_selectedCol:TQt::black),1,TQt::SolidLine)); p.drawRoundRect( _x, _y, width(), topStrip, 1500/width(), 1500/topStrip ); } p.setPen( TQt::black ); p.setFont( font() ); p.drawText( TQRect( 22 + _x+8, _y, width()-8, topStrip ), TQt::AlignLeft | TQt::AlignVCenter, m_caption ); if( b_expanded ) { p.setPen(TQt::SolidLine); p.setBrush( TQt::NoBrush ); p.drawRoundRect( _x, _y, width(), height(), 1500/width(), 1500/height() ); } } void FlowContainer::childAdded( Item *child ) { if (!child) return; FlowPart::childAdded(child); connect( this, TQT_SIGNAL(movedBy(double, double )), child, TQT_SLOT(moveBy(double, double )) ); child->setZ( ICNDocument::Z::Item + child->level() ); updateContainedVisibility(); } void FlowContainer::childRemoved( Item *child ) { FlowPart::childRemoved(child); if (!b_expanded) child->setVisible(true); disconnect( this, TQT_SIGNAL(movedBy(double, double )), child, TQT_SLOT(moveBy(double, double )) ); } void FlowContainer::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; int _x = (int)x()+offsetX(); int _y = (int)y()+offsetY(); int w = width(); int h = b_expanded ? height() : topStrip; const int mult = add ? 1 : -1; // Top strip for ( int y=_y; y <_y+24; ++y ) { for ( int x = _x; x<=_x+w; x += 8 ) { if ( p_icnDocument->isValidCellReference( x/8, y/8 ) ) { (*cells)[x/8][y/8].CIpenalty += mult*ICNDocument::hs_item; } } } // Bottom strip for ( int y = _y+h-16; y <= _y+h; ++y ) { for ( int x = _x; x<=_x+width(); x += 8 ) { if ( p_icnDocument->isValidCellReference( x/8, y/8 ) ) { (*cells)[x/8][y/8].CIpenalty += mult*ICNDocument::hs_item; } } } // Left strip int x = _x; for ( int y = _y+24; y<_y+h-16; y += 8 ) { if ( p_icnDocument->isValidCellReference( x/8, y/8 ) ) { (*cells)[x/8][y/8].CIpenalty += mult*ICNDocument::hs_item; } } // Right strip x = _x+width(); for ( int y = _y+24; y<_y+h-16; y += 8 ) { if ( p_icnDocument->isValidCellReference( x/8, y/8 ) ) { (*cells)[x/8][y/8].CIpenalty += mult*ICNDocument::hs_item; } } } void FlowContainer::setFullBounds( bool full ) { if ( full || !b_expanded ) { TQRect bounds = b_expanded ? m_sizeRect : TQRect( m_sizeRect.x(), m_sizeRect.y(), m_sizeRect.width(), topStrip ); setPoints( TQPointArray(bounds) ); return; } // kdDebug() << k_funcinfo << "width="<setGuiPartSize( 22, 22 ); button("expandBtn")->move( int(x())+offsetX()+7, int(y())+offsetY()+1 ); } void FlowContainer::updateContainedVisibility() { if (b_deleted) return; if (m_ext_in) m_ext_in->setVisible( isVisible() ); if (m_int_in) m_int_in->setVisible( isVisible() && b_expanded ); if (m_int_out) m_int_out->setVisible( isVisible() && b_expanded ); if (m_ext_out) m_ext_out->setVisible( isVisible() ); const ItemList::iterator cEnd = m_children.end(); for ( ItemList::iterator it = m_children.begin(); it != cEnd; ++it ) { if (*it) (*it)->setVisible( isVisible() && b_expanded ); } m_rectangularOverlay->setVisible( isVisible() && b_expanded ); NodeGroupList hidableNodeGroups; p_icnDocument->getTranslatable( children(true) += GuardedItem(this), 0, 0, &hidableNodeGroups ); NodeGroupList::iterator hngEnd = hidableNodeGroups.end(); for ( NodeGroupList::iterator it = hidableNodeGroups.begin(); it != hngEnd; ++it ) (*it)->setVisible(b_expanded); } void FlowContainer::setVisible( bool yes ) { if (b_deleted) { FlowPart::setVisible(false); return; } FlowPart::setVisible(yes); updateContainedVisibility(); } #include "flowcontainer.moc"