icnview.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 2005 by David Saxton                                    *
00003  *   david@bluehaze.org                                                    *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  ***************************************************************************/
00010 
00011 #include "canvasmanipulator.h"
00012 #include "icndocument.h"
00013 #include "icnview.h"
00014 #include "ktechlab.h"
00015 
00016 #include <kconfig.h>
00017 #include <kglobal.h>
00018 #include <kiconloader.h>
00019 #include <klocale.h>
00020 #include <kpopupmenu.h>
00021 
00022 ICNView::ICNView( ICNDocument *icnDocument, ViewContainer *viewContainer, uint viewAreaId, const char *name )
00023         : ItemView( icnDocument, viewContainer, viewAreaId, name )
00024 {
00025         bool manualRouting = (icnDocument->m_cmManager->cmState() & CMManager::cms_manual_route);
00026         
00027         KActionCollection * ac = actionCollection();
00028         
00029         //BEGIN Routing Actions
00030         // These actions get inserted into the main menu
00031         m_pAutoRoutingAction = new KRadioAction( i18n("Automatic"), "", 0, this, SLOT(slotSetRoutingAuto()), ac, "routing_mode_auto" );
00032         m_pAutoRoutingAction->setExclusiveGroup("routing_mode");
00033         if ( !manualRouting )
00034                 m_pAutoRoutingAction->setChecked( true );
00035         
00036         m_pManualRoutingAction = new KRadioAction( i18n("Manual"), "", 0, this, SLOT(slotSetRoutingManual()), ac, "routing_mode_manual" );
00037         m_pManualRoutingAction->setExclusiveGroup("routing_mode");
00038         if ( manualRouting )
00039                 m_pManualRoutingAction->setChecked( true );
00040         
00041         
00042         // This popup gets inserted into the toolbar
00043         m_pRoutingModeToolbarPopup = new KToolBarPopupAction( i18n("Connection Routing Mode"), "pencil", 0, 0, 0, ac, "routing_mode" );
00044         m_pRoutingModeToolbarPopup->setDelayed(false);
00045         
00046         KPopupMenu * m = m_pRoutingModeToolbarPopup->popupMenu();
00047         m->insertTitle( i18n("Connection Routing Mode") );
00048         
00049         m->insertItem( /*KGlobal::iconLoader()->loadIcon( "routing_mode_auto",  KIcon::Small ), */i18n("Automatic"), 0 );
00050         m->insertItem( /*KGlobal::iconLoader()->loadIcon( "routing_mode_manual",        KIcon::Small ),*/ i18n("Manual"), 1 );
00051         
00052         m->setCheckable(true);
00053         m->setItemChecked( manualRouting ? 1 : 0, true );
00054         
00055         connect( m, SIGNAL(activated(int)), this, SLOT(slotSetRoutingMode(int)) );
00056         //END Routing Actions
00057         
00058         connect( icnDocument->m_cmManager, SIGNAL(manualRoutingChanged(bool )), this, SLOT(slotUpdateRoutingToggles(bool )) );
00059 }
00060 
00061 
00062 ICNView::~ICNView()
00063 {
00064 }
00065 
00066 
00067 void ICNView::slotSetRoutingMode( int mode )
00068 {
00069         // This function is called when the user selects a mode from the toolbar drop-down menu
00070         bool manualEnabled = (mode == 1);
00071         
00072         if ( bool(p_itemDocument->m_cmManager->cmState() & CMManager::cms_manual_route) == manualEnabled )
00073                 return;
00074         
00075         slotUpdateRoutingMode( manualEnabled );
00076         slotUpdateRoutingToggles( manualEnabled );
00077 }
00078 
00079 
00080 void ICNView::slotSetRoutingManual()
00081 {
00082         slotUpdateRoutingMode( true );
00083         slotUpdateRoutingToggles( true );
00084 }
00085 
00086 
00087 void ICNView::slotSetRoutingAuto()
00088 {
00089         slotUpdateRoutingMode( false );
00090         slotUpdateRoutingToggles( false );
00091 }
00092 
00093 
00094 void ICNView::slotUpdateRoutingMode( bool manualRouting )
00095 {
00096         p_itemDocument->m_cmManager->slotSetManualRoute( manualRouting );
00097         p_itemDocument->canvas()->setMessage( manualRouting ? i18n("<b>Manual</b> connection routing enabled.") : i18n("<b>Automatic</b> connection routing enabled.") );
00098 }
00099 
00100 
00101 void ICNView::slotUpdateRoutingToggles( bool manualRouting )
00102 {
00103         m_pRoutingModeToolbarPopup->popupMenu()->setItemChecked( !manualRouting, 0 );
00104         m_pRoutingModeToolbarPopup->popupMenu()->setItemChecked(  manualRouting, 1 );
00105         
00106         if ( manualRouting )
00107                 m_pManualRoutingAction->setChecked(true);
00108         
00109         else
00110                 m_pAutoRoutingAction->setChecked(true);
00111 }
00112 
00113 
00114 #include "icnview.moc"

Generated on Tue May 8 17:05:30 2007 for KTechLab by  doxygen 1.5.1