|
|
|
@ -36,35 +36,35 @@ ItemView::ItemView( ItemDocument * itemDocument, ViewContainer *viewContainer, u
|
|
|
|
|
: View( itemDocument, viewContainer, viewAreaId, name )
|
|
|
|
|
{
|
|
|
|
|
TDEActionCollection * ac = actionCollection();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
KStdAction::selectAll( itemDocument, TQT_SLOT(selectAll()), ac );
|
|
|
|
|
KStdAction::zoomIn( TQT_TQOBJECT(this), TQT_SLOT(zoomIn()), ac );
|
|
|
|
|
KStdAction::zoomOut( TQT_TQOBJECT(this), TQT_SLOT(zoomOut()), ac );
|
|
|
|
|
KStdAction::actualSize( TQT_TQOBJECT(this), TQT_SLOT(actualSize()), ac )->setEnabled(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TDEAccel *pAccel = new TDEAccel(this);
|
|
|
|
|
pAccel->insert( "Cancel", i18n("Cancel"), i18n("Cancel the current operation"), TQt::Key_Escape, itemDocument, TQT_SLOT(cancelCurrentOperation()) );
|
|
|
|
|
pAccel->readSettings();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
new TDEAction( i18n("Delete"), "edit-delete", TQt::Key_Delete, itemDocument, TQT_SLOT(deleteSelection()), ac, "edit_delete" );
|
|
|
|
|
new TDEAction( i18n("Export as Image..."), 0, 0, itemDocument, TQT_SLOT(exportToImage()), ac, "file_export_image");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//BEGIN Item Alignment actions
|
|
|
|
|
new TDEAction( i18n("AlignQt::Horizontally"), 0, 0, itemDocument, TQT_SLOT(alignHorizontally()), ac, "align_horizontally" );
|
|
|
|
|
new TDEAction( i18n("AlignQt::Vertically"), 0, 0, itemDocument, TQT_SLOT(alignVertically()), ac, "align_vertically" );
|
|
|
|
|
new TDEAction( i18n("DistributeQt::Horizontally"), 0, 0, itemDocument, TQT_SLOT(distributeHorizontally()), ac, "distribute_horizontally" );
|
|
|
|
|
new TDEAction( i18n("DistributeQt::Vertically"), 0, 0, itemDocument, TQT_SLOT(distributeVertically()), ac, "distribute_vertically" );
|
|
|
|
|
new TDEAction( i18n("Align Horizontally"), 0, 0, itemDocument, TQT_SLOT(alignHorizontally()), ac, "align_horizontally" );
|
|
|
|
|
new TDEAction( i18n("Align Vertically"), 0, 0, itemDocument, TQT_SLOT(alignVertically()), ac, "align_vertically" );
|
|
|
|
|
new TDEAction( i18n("Distribute Horizontally"), 0, 0, itemDocument, TQT_SLOT(distributeHorizontally()), ac, "distribute_horizontally" );
|
|
|
|
|
new TDEAction( i18n("Distribute Vertically"), 0, 0, itemDocument, TQT_SLOT(distributeVertically()), ac, "distribute_vertically" );
|
|
|
|
|
//END Item Alignment actions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//BEGIN Draw actions
|
|
|
|
|
TDEToolBarPopupAction * pa = new TDEToolBarPopupAction( i18n("Draw"), "paintbrush", 0, 0, 0, ac, "edit_draw" );
|
|
|
|
|
pa->setDelayed(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TDEPopupMenu * m = pa->popupMenu();
|
|
|
|
|
m->insertTitle( i18n("Draw") );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m->insertItem( TDEGlobal::iconLoader()->loadIcon( "tool_text", TDEIcon::Small ), i18n("Text"), DrawPart::da_text );
|
|
|
|
|
m->insertItem( TDEGlobal::iconLoader()->loadIcon( "tool_line", TDEIcon::Small ), i18n("Line"), DrawPart::da_line );
|
|
|
|
|
m->insertItem( TDEGlobal::iconLoader()->loadIcon( "tool_arrow", TDEIcon::Small ), i18n("Arrow"), DrawPart::da_arrow );
|
|
|
|
@ -72,30 +72,30 @@ ItemView::ItemView( ItemDocument * itemDocument, ViewContainer *viewContainer, u
|
|
|
|
|
m->insertItem( TDEGlobal::iconLoader()->loadIcon( "tool_rectangle", TDEIcon::Small ), i18n("Rectangle"), DrawPart::da_rectangle );
|
|
|
|
|
connect( m, TQT_SIGNAL(activated(int)), itemDocument, TQT_SLOT(slotSetDrawAction(int)) );
|
|
|
|
|
//END Draw actions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//BEGIN Item Control actions
|
|
|
|
|
new TDEAction( i18n("Raise Selection"), "1uparrow", TQt::Key_PageUp, itemDocument, TQT_SLOT(raiseZ()), ac, "edit_raise" );
|
|
|
|
|
new TDEAction( i18n("Lower Selection"), "1downarrow", TQt::Key_PageDown, itemDocument, TQT_SLOT(lowerZ()), ac, "edit_lower" );
|
|
|
|
|
//END Item Control actions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TDEAction * na = new TDEAction( "", 0, 0, 0, 0, ac, "null_action" );
|
|
|
|
|
na->setEnabled(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setXMLFile( "ktechlabitemviewui.rc" );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_pUpdateStatusTmr = new TQTimer(this);
|
|
|
|
|
connect( m_pUpdateStatusTmr, TQT_SIGNAL(timeout()), this, TQT_SLOT(updateStatus()) );
|
|
|
|
|
connect( this, TQT_SIGNAL(viewUnfocused()), this, TQT_SLOT(stopUpdatingStatus()) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p_itemDocument = itemDocument;
|
|
|
|
|
m_zoomLevel = 1.;
|
|
|
|
|
m_CVBEditor = new CVBEditor( p_itemDocument->canvas(), this, "cvbEditor" );
|
|
|
|
|
m_CVBEditor->setLineWidth(1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_layout->insertWidget( 0, m_CVBEditor );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setAcceptDrops(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -119,19 +119,19 @@ void ItemView::zoomIn()
|
|
|
|
|
{
|
|
|
|
|
int currentZoomPercent = int(std::floor((100*m_zoomLevel)+0.5));
|
|
|
|
|
int newZoom = currentZoomPercent;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( currentZoomPercent < 100 )
|
|
|
|
|
newZoom += 25;
|
|
|
|
|
else if ( currentZoomPercent < 200 )
|
|
|
|
|
newZoom += 50;
|
|
|
|
|
else
|
|
|
|
|
newZoom += 100;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_zoomLevel = newZoom/100.;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TQWMatrix m( m_zoomLevel, 0.0, 0.0, m_zoomLevel, 1.0, 1.0 );
|
|
|
|
|
m_CVBEditor->setWorldMatrix(m);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p_itemDocument->requestEvent( ItemDocument::ItemDocumentEvent::ResizeCanvasToItems );
|
|
|
|
|
updateZoomActions();
|
|
|
|
|
}
|
|
|
|
@ -141,7 +141,7 @@ void ItemView::zoomOut()
|
|
|
|
|
{
|
|
|
|
|
int currentZoomPercent = int(std::floor((100*m_zoomLevel)+0.5));
|
|
|
|
|
int newZoom = currentZoomPercent;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( currentZoomPercent <= 25 )
|
|
|
|
|
return;
|
|
|
|
|
if ( currentZoomPercent <= 100 )
|
|
|
|
@ -150,12 +150,12 @@ void ItemView::zoomOut()
|
|
|
|
|
newZoom -= 50;
|
|
|
|
|
else
|
|
|
|
|
newZoom -= 100;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_zoomLevel = newZoom/100.;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TQWMatrix m( m_zoomLevel, 0.0, 0.0, m_zoomLevel, 1.0, 1.0 );
|
|
|
|
|
m_CVBEditor->setWorldMatrix(m);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p_itemDocument->requestEvent( ItemDocument::ItemDocumentEvent::ResizeCanvasToItems );
|
|
|
|
|
updateZoomActions();
|
|
|
|
|
}
|
|
|
|
@ -166,7 +166,7 @@ void ItemView::actualSize()
|
|
|
|
|
m_zoomLevel = 1.0;
|
|
|
|
|
TQWMatrix m( m_zoomLevel, 0.0, 0.0, m_zoomLevel, 1.0, 1.0 );
|
|
|
|
|
m_CVBEditor->setWorldMatrix(m);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p_itemDocument->requestEvent( ItemDocument::ItemDocumentEvent::ResizeCanvasToItems );
|
|
|
|
|
updateZoomActions();
|
|
|
|
|
}
|
|
|
|
@ -193,10 +193,10 @@ void ItemView::dropEvent( TQDropEvent *event )
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( !TQString(event->format()).startsWith("ktechlab/") )
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TQString text;
|
|
|
|
|
TQDataStream stream( event->encodedData(event->format()), IO_ReadOnly );
|
|
|
|
|
stream >> text;
|
|
|
|
@ -207,7 +207,7 @@ void ItemView::dropEvent( TQDropEvent *event )
|
|
|
|
|
|
|
|
|
|
// Get a new component item
|
|
|
|
|
p_itemDocument->addItem( text, position, true );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setFocus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -215,15 +215,15 @@ void ItemView::dropEvent( TQDropEvent *event )
|
|
|
|
|
void ItemView::scrollToMouse( const TQPoint &pos )
|
|
|
|
|
{
|
|
|
|
|
TQPoint position = pos * m_zoomLevel;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int left = m_CVBEditor->contentsX();
|
|
|
|
|
int top = m_CVBEditor->contentsY();
|
|
|
|
|
int right = left + m_CVBEditor->visibleWidth();
|
|
|
|
|
int bottom = top + m_CVBEditor->visibleHeight();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( position.x() < left ) m_CVBEditor->scrollBy( position.x() - left, 0 );
|
|
|
|
|
else if( position.x() > right ) m_CVBEditor->scrollBy( position.x() - right, 0 );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( position.y() < top ) m_CVBEditor->scrollBy( 0, position.y() - top );
|
|
|
|
|
else if( position.y() > bottom ) m_CVBEditor->scrollBy( 0, position.y() - bottom);
|
|
|
|
|
}
|
|
|
|
@ -233,21 +233,21 @@ void ItemView::contentsMousePressEvent( TQMouseEvent *e )
|
|
|
|
|
{
|
|
|
|
|
if (!e)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
e->accept();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// For some reason, when we are initially unfocused, we only receive the
|
|
|
|
|
// release event if the user drags the mouse - not very often. So see if we
|
|
|
|
|
// were initially unfocused, and if so, do unclick as well.
|
|
|
|
|
bool wasFocused = isFocused();
|
|
|
|
|
setFocused();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( !p_itemDocument )
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p_itemDocument->canvas()->setMessage( TQString() );
|
|
|
|
|
p_itemDocument->m_cmManager->mousePressEvent( EventInfo( this, e ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( !wasFocused )
|
|
|
|
|
p_itemDocument->m_cmManager->mouseReleaseEvent( EventInfo( this, e ) );
|
|
|
|
|
}
|
|
|
|
@ -257,9 +257,9 @@ void ItemView::contentsMouseDoubleClickEvent( TQMouseEvent *e )
|
|
|
|
|
{
|
|
|
|
|
if (!e)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
e->accept();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//HACK: Pass this of as a single press event if widget underneath
|
|
|
|
|
TQCanvasItem * atTop = p_itemDocument->itemAtTop( e->pos()/zoomLevel() );
|
|
|
|
|
if ( atTop && atTop->rtti() == ItemDocument::RTTI::Widget )
|
|
|
|
@ -273,9 +273,9 @@ void ItemView::contentsMouseMoveEvent( TQMouseEvent *e )
|
|
|
|
|
{
|
|
|
|
|
if ( !e || !p_itemDocument )
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
e->accept();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p_itemDocument->m_cmManager->mouseMoveEvent( EventInfo( this, e ) );
|
|
|
|
|
if ( !m_pUpdateStatusTmr->isActive() )
|
|
|
|
|
startUpdatingStatus();
|
|
|
|
@ -286,9 +286,9 @@ void ItemView::contentsMouseReleaseEvent( TQMouseEvent *e )
|
|
|
|
|
{
|
|
|
|
|
if (!e)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
e->accept();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p_itemDocument->m_cmManager->mouseReleaseEvent( EventInfo( this, e ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -297,9 +297,9 @@ void ItemView::contentsWheelEvent( TQWheelEvent *e )
|
|
|
|
|
{
|
|
|
|
|
if (!e)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
e->accept();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p_itemDocument->m_cmManager->wheelEvent( EventInfo( this, e ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -307,7 +307,7 @@ void ItemView::contentsWheelEvent( TQWheelEvent *e )
|
|
|
|
|
void ItemView::dragEnterEvent( TQDragEnterEvent *event )
|
|
|
|
|
{
|
|
|
|
|
startUpdatingStatus();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
KURL::List urls;
|
|
|
|
|
if ( KURLDrag::decode( event, urls ) )
|
|
|
|
|
{
|
|
|
|
@ -329,13 +329,13 @@ void ItemView::leaveEvent( TQEvent * e )
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(e);
|
|
|
|
|
stopUpdatingStatus();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Cleanup
|
|
|
|
|
setCursor(TQt::ArrowCursor);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (p_ktechlab)
|
|
|
|
|
p_ktechlab->slotChangeStatusbar(TQString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( p_itemDocument )
|
|
|
|
|
p_itemDocument->m_canvasTip->setVisible(false);
|
|
|
|
|
}
|
|
|
|
@ -345,7 +345,7 @@ void ItemView::slotUpdateConfiguration()
|
|
|
|
|
{
|
|
|
|
|
// m_CVBEditor->setEraseColor( KTLConfig::bgColor() );
|
|
|
|
|
m_CVBEditor->setEraseColor( TQt::white );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( m_pUpdateStatusTmr->isActive() )
|
|
|
|
|
startUpdatingStatus();
|
|
|
|
|
}
|
|
|
|
@ -367,18 +367,18 @@ void ItemView::stopUpdatingStatus()
|
|
|
|
|
void ItemView::updateStatus()
|
|
|
|
|
{
|
|
|
|
|
TQPoint pos = (m_CVBEditor->mapFromGlobal( TQCursor::pos() ) + TQPoint( m_CVBEditor->contentsX(), m_CVBEditor->contentsY() )) / zoomLevel();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ItemDocument * itemDocument = static_cast<ItemDocument*>(document());
|
|
|
|
|
if ( !itemDocument )
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CMManager * cmManager = itemDocument->m_cmManager;
|
|
|
|
|
CanvasTip * canvasTip = itemDocument->m_canvasTip;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool displayTip = false;
|
|
|
|
|
TQCursor cursor = TQt::ArrowCursor;
|
|
|
|
|
TQString statusbar;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( cmManager->cmState() & CMManager::cms_repeated_add )
|
|
|
|
|
{
|
|
|
|
|
cursor = TQt::CrossCursor;
|
|
|
|
@ -413,7 +413,7 @@ void ItemView::updateStatus()
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if ( TQCanvasItem *qcanvasItem = itemDocument->itemAtTop(pos) )
|
|
|
|
|
{
|
|
|
|
@ -424,7 +424,7 @@ void ItemView::updateStatus()
|
|
|
|
|
cursor = TQt::CrossCursor;
|
|
|
|
|
if ( itemDocument->type() != Document::dt_circuit )
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
canvasTip->displayVI( static_cast<Connector*>(qcanvasItem), pos );
|
|
|
|
|
displayTip = true;
|
|
|
|
|
break;
|
|
|
|
@ -435,7 +435,7 @@ void ItemView::updateStatus()
|
|
|
|
|
ECNode * ecnode = dynamic_cast<ECNode*>(qcanvasItem);
|
|
|
|
|
if ( !ecnode )
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
canvasTip->displayVI( ecnode, pos );
|
|
|
|
|
displayTip = true;
|
|
|
|
|
break;
|
|
|
|
@ -452,10 +452,10 @@ void ItemView::updateStatus()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
setCursor(cursor);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (p_ktechlab)
|
|
|
|
|
p_ktechlab->slotChangeStatusbar(statusbar);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
canvasTip->setVisible(displayTip);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -560,7 +560,7 @@ void CVBEditor::contentsWheelEvent( TQWheelEvent *e )
|
|
|
|
|
e->ignore();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (b_passEventsToView)
|
|
|
|
|
p_itemView->contentsWheelEvent(e);
|
|
|
|
|
else
|
|
|
|
|