1 /***************************************************************************
2  *   Copyright (C) 2005 by David Saxton                                    *
3  *   david@bluehaze.org                                                    *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  ***************************************************************************/
10 
11 #include "flowcodedocument.h"
12 #include "flowcodeview.h"
13 #include "ktechlab.h"
14 #include "viewiface.h"
15 
16 #include <KLocalizedString>
17 #include <KToolBarPopupAction>
18 #include <KActionCollection>
19 
20 #include <QIcon>
21 #include <QMenu>
22 #include <QDragEnterEvent>
23 #include <QMimeData>
24 
FlowCodeView(FlowCodeDocument * flowCodeDocument,ViewContainer * viewContainer,uint viewAreaId,const char * name)25 FlowCodeView::FlowCodeView( FlowCodeDocument * flowCodeDocument, ViewContainer *viewContainer, uint viewAreaId, const char *name )
26 	: ICNView( flowCodeDocument, viewContainer, viewAreaId, name )
27 {
28 	KActionCollection * ac = actionCollection();
29 
30 	//BEGIN Convert To * Actions
31 	//KToolBarPopupAction * pa = new KToolBarPopupAction( i18n("Convert to..."), "fork", 0, 0, 0, ac, "program_convert" );
32     KToolBarPopupAction * pa = new KToolBarPopupAction( QIcon::fromTheme("fork"), i18n("Convert to..."), ac);
33     pa->setObjectName( "program_convert" );
34 	pa->setDelayed(false);
35 
36 	QMenu * m = pa->menu();
37 
38 	m->setTitle( i18n("Convert To") );
39 	m->addAction( QIcon::fromTheme( "convert_to_microbe" ), i18n("Microbe"))->setData( FlowCodeDocument::MicrobeOutput );
40 	m->addAction( QIcon::fromTheme( "convert_to_assembly" ), i18n("Assembly"))->setData( FlowCodeDocument::AssemblyOutput );
41 	m->addAction( QIcon::fromTheme( "convert_to_hex" ), i18n("Hex"))->setData( FlowCodeDocument::HexOutput );
42 	m->addAction( QIcon::fromTheme( "convert_to_pic" ), i18n("PIC (upload)"))->setData( FlowCodeDocument::PICOutput );
43 	connect( m, SIGNAL(triggered(QAction*)), flowCodeDocument, SLOT(slotConvertTo(QAction*)) );
44     ac->addAction("program_convert" , pa);
45 	//END Convert To * Actions
46 
47 
48 
49 
50 // 	new KAction( i18n("Convert to Microbe"), "convert_to_microbe", Qt::Key_F7, flowCodeDocument, SLOT(convertToMicrobe()), ac, "tools_to_microbe" );
51 // 	new KAction( i18n("Convert to Assembly"), "convert_to_assembly", Qt::Key_F8, flowCodeDocument, SLOT(convertToAssembly()), ac, "tools_to_assembly" );
52 // 	new KAction( i18n("Convert to Hex"), "convert_to_hex", Qt::Key_F9, flowCodeDocument, SLOT(convertToHex()), ac, "tools_to_hex" );
53 // 	new KAction( i18n("Upload PIC Program"), "convert_to_pic", 0, flowCodeDocument, SLOT(convertToPIC()), ac, "tools_to_pic" );
54 
55 
56 
57 
58 	setXMLFile( "ktechlabflowcodeui.rc", true );
59 
60 	setWhatsThis( i18n(
61 			"Construct a FlowCode document by dragging FlowParts from the list on the left. All FlowCharts require an initial \"Start\" part, of which there can only be one.<br><br>"
62 
63 			"Some FlowParts, such as Subroutines, act as a container element for other FlowParts. Drag the items in or out of a container as appropriate. The container that will become the parent of the part being dragged is indicated by being selected.<br><br>"
64 
65 			"Note that connections cannot be made between FlowParts in different containers, or at different levels."
66 							   ) );
67 
68 	m_pViewIface = new FlowCodeViewIface(this);
69 }
70 
71 
~FlowCodeView()72 FlowCodeView::~FlowCodeView()
73 {
74 	delete m_pViewIface;
75 }
76 
77 
dragEnterEvent(QDragEnterEvent * e)78 void FlowCodeView::dragEnterEvent( QDragEnterEvent * e )
79 {
80 	ICNView::dragEnterEvent(e);
81 	if ( e->isAccepted() )
82 		return;
83 
84 	//bool acceptable = e->provides("ktechlab/flowpart");
85     bool acceptable = e->mimeData()->hasFormat("ktechlab/flowpart");
86 
87 	if ( !acceptable )
88 		return;
89 
90 	e->setAccepted( true );
91 	createDragItem( e );
92 }
93