File indexing completed on 2024-04-21 05:43:56

0001 /***************************************************************************
0002  *   Copyright (C) 2005 by David Saxton                                    *
0003  *   david@bluehaze.org                                                    *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  ***************************************************************************/
0010 
0011 #include "flowcodeview.h"
0012 #include "flowcodedocument.h"
0013 #include "ktechlab.h"
0014 #include "viewiface.h"
0015 
0016 #include <KActionCollection>
0017 #include <KLocalizedString>
0018 #include <KToolBarPopupAction>
0019 
0020 #include <QDragEnterEvent>
0021 #include <QIcon>
0022 #include <QMenu>
0023 #include <QMimeData>
0024 
0025 FlowCodeView::FlowCodeView(FlowCodeDocument *flowCodeDocument, ViewContainer *viewContainer, uint viewAreaId)
0026     : ICNView(flowCodeDocument, viewContainer, viewAreaId)
0027 {
0028     KActionCollection *ac = actionCollection();
0029 
0030     // BEGIN Convert To * Actions
0031     // KToolBarPopupAction * pa = new KToolBarPopupAction( i18n("Convert to..."), "fork", 0, 0, 0, ac, "program_convert" );
0032     KToolBarPopupAction *pa = new KToolBarPopupAction(QIcon::fromTheme("fork"), i18n("Convert to..."), ac);
0033     pa->setObjectName("program_convert");
0034     pa->setDelayed(false);
0035 
0036     QMenu *m = pa->menu();
0037 
0038     m->setTitle(i18n("Convert To"));
0039     m->addAction(QIcon::fromTheme("convert_to_microbe"), i18n("Microbe"))->setData(FlowCodeDocument::MicrobeOutput);
0040     m->addAction(QIcon::fromTheme("convert_to_assembly"), i18n("Assembly"))->setData(FlowCodeDocument::AssemblyOutput);
0041     m->addAction(QIcon::fromTheme("convert_to_hex"), i18n("Hex"))->setData(FlowCodeDocument::HexOutput);
0042     m->addAction(QIcon::fromTheme("convert_to_pic"), i18n("PIC (upload)"))->setData(FlowCodeDocument::PICOutput);
0043     connect(m, &QMenu::triggered, flowCodeDocument, &FlowCodeDocument::slotConvertTo);
0044     ac->addAction("program_convert", pa);
0045     // END Convert To * Actions
0046 
0047     //  new KAction( i18n("Convert to Microbe"), "convert_to_microbe", Qt::Key_F7, flowCodeDocument, SLOT(convertToMicrobe()), ac, "tools_to_microbe" );
0048     //  new KAction( i18n("Convert to Assembly"), "convert_to_assembly", Qt::Key_F8, flowCodeDocument, SLOT(convertToAssembly()), ac, "tools_to_assembly" );
0049     //  new KAction( i18n("Convert to Hex"), "convert_to_hex", Qt::Key_F9, flowCodeDocument, SLOT(convertToHex()), ac, "tools_to_hex" );
0050     //  new KAction( i18n("Upload PIC Program"), "convert_to_pic", 0, flowCodeDocument, SLOT(convertToPIC()), ac, "tools_to_pic" );
0051 
0052     setXMLFile("ktechlabflowcodeui.rc", true);
0053 
0054     setWhatsThis(
0055         i18n("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>"
0056 
0057              "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 "
0058              "being selected.<br><br>"
0059 
0060              "Note that connections cannot be made between FlowParts in different containers, or at different levels."));
0061 
0062     m_pViewIface = new FlowCodeViewIface(this);
0063 }
0064 
0065 FlowCodeView::~FlowCodeView()
0066 {
0067     delete m_pViewIface;
0068 }
0069 
0070 void FlowCodeView::dragEnterEvent(QDragEnterEvent *e)
0071 {
0072     ICNView::dragEnterEvent(e);
0073     if (e->isAccepted())
0074         return;
0075 
0076     // bool acceptable = e->provides("ktechlab/flowpart");
0077     bool acceptable = e->mimeData()->hasFormat("ktechlab/flowpart");
0078 
0079     if (!acceptable)
0080         return;
0081 
0082     e->setAccepted(true);
0083     createDragItem(e);
0084 }
0085 
0086 #include "moc_flowcodeview.cpp"