circuitview.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 "circuitdocument.h"
00012 #include "circuitview.h"
00013 #include "config.h"
00014 #include "ktechlab.h"
00015 #include "simulator.h"
00016 #include "viewiface.h"
00017 
00018 #include <klocale.h>
00019 #include <qwhatsthis.h>
00020 
00021 CircuitView::CircuitView( CircuitDocument * circuitDocument, ViewContainer *viewContainer, uint viewAreaId, const char *name )
00022         : ICNView( circuitDocument, viewContainer, viewAreaId, name ),
00023         p_circuitDocument(circuitDocument)
00024 {
00025         KActionCollection * ac = actionCollection();
00026         
00027         new KAction( "Dump linear equations", Qt::CTRL|Qt::Key_D, circuitDocument, SLOT(displayEquations()), ac, "dump_les" );
00028         
00029         //BEGIN Item Control Actions
00030         KRadioAction * ra;
00031         ra = new KRadioAction( i18n("0 Degrees"), "", 0, circuitDocument, SLOT(setOrientation0()), ac, "edit_orientation_0" );
00032         ra->setExclusiveGroup("orientation");
00033         ra->setChecked(true);
00034         ra = new KRadioAction( i18n("90 Degrees"), "", 0, circuitDocument, SLOT(setOrientation90()), ac, "edit_orientation_90" );
00035         ra->setExclusiveGroup("orientation");
00036         ra = new KRadioAction( i18n("180 Degrees"), "", 0, circuitDocument, SLOT(setOrientation180()), ac, "edit_orientation_180" );
00037         ra->setExclusiveGroup("orientation");
00038         ra =new KRadioAction( i18n("270 Degrees"), "", 0, circuitDocument, SLOT(setOrientation270()), ac, "edit_orientation_270" );
00039         ra->setExclusiveGroup("orientation");
00040         
00041         new KAction( i18n("Create Subcircuit"), "", 0, circuitDocument, SLOT(createSubcircuit()), ac, "circuit_create_subcircuit" );
00042         new KAction( i18n("Rotate Clockwise"), "rotate_cw", "]", circuitDocument, SLOT(rotateClockwise()), ac, "edit_rotate_cw" );
00043         new KAction( i18n("Rotate Counter-Clockwise"), "rotate_ccw", "[", circuitDocument, SLOT(rotateCounterClockwise()), ac, "edit_rotate_ccw" );
00044         new KAction( i18n("Flip"), "", 0, circuitDocument, SLOT(itemFlip()), ac, "edit_flip" );
00045         //END Item Control Actions
00046         
00047         setXMLFile( "ktechlabcircuitui.rc", true );
00048         
00049         QWhatsThis::add( this, i18n(
00050                         "Construct a circuit by dragging components from the Component selector from the left. Create the connections by dragging a wire from the component connectors.<br><br>"
00051 
00052                         "The simulation is running by default, but can be paused and resumed from the Tools menu.<br><br>"
00053 
00054                         "To delete a wire, select it with a select box, and hit delete.<br><br>"
00055 
00056                         "To edit the attributes of a component, select it (making sure that no components of another type are also selected), and edit in the toolbar. More advanced properties can be edited using the item editor on the right.<br><br>"
00057         
00058                         "Subcircuits can be created by connecting the components with an External Connection, selecting the desired components and clicking on \"Create Subcircuit\" in the right-click menu.")
00059                                    );
00060         
00061         m_pViewIface = new CircuitViewIface(this);
00062         
00063         m_statusBar->insertItem( "", ViewStatusBar::SimulationState );
00064         connect( Simulator::self(), SIGNAL(simulatingStateChanged(bool )), this, SLOT(slotUpdateRunningStatus(bool )) );
00065         slotUpdateRunningStatus( Simulator::self()->isSimulating() );
00066 }
00067 
00068 CircuitView::~CircuitView()
00069 {
00070         delete m_pViewIface;
00071 }
00072 
00073 void CircuitView::slotUpdateRunningStatus( bool isRunning )
00074 {
00075         m_statusBar->changeItem( isRunning ? i18n("Simulation Running") : i18n("Simulation Paused"), ViewStatusBar::SimulationState );
00076 }
00077 
00078 void CircuitView::dragEnterEvent( QDragEnterEvent * e )
00079 {
00080         ICNView::dragEnterEvent(e);
00081         if ( e->isAccepted() ) return;
00082 
00083         e->accept( e->provides("ktechlab/component") || e->provides("ktechlab/subcircuit") );
00084 }
00085 
00086 #include "circuitview.moc"

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