|
Packit Service |
b98cfc |
/*
|
|
Packit Service |
b98cfc |
* qlo10k1 - GUI frontend for ld10k1
|
|
Packit Service |
b98cfc |
*
|
|
Packit Service |
b98cfc |
* Copyright (c) 2004 by Peter Zubaj
|
|
Packit Service |
b98cfc |
*
|
|
Packit Service |
b98cfc |
* This program is free software; you can redistribute it and/or modify
|
|
Packit Service |
b98cfc |
* it under the terms of the GNU General Public License as published by
|
|
Packit Service |
b98cfc |
* the Free Software Foundation; either version 2 of the License, or
|
|
Packit Service |
b98cfc |
* (at your option) any later version.
|
|
Packit Service |
b98cfc |
*
|
|
Packit Service |
b98cfc |
* This program is distributed in the hope that it will be useful,
|
|
Packit Service |
b98cfc |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
b98cfc |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
b98cfc |
* GNU General Public License for more details.
|
|
Packit Service |
b98cfc |
*
|
|
Packit Service |
b98cfc |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
b98cfc |
* along with this program; if not, write to the Free Software
|
|
Packit Service |
b98cfc |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
Packit Service |
b98cfc |
*
|
|
Packit Service |
b98cfc |
*/
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
#include <qpopupmenu.h>
|
|
Packit Service |
b98cfc |
#include <qmessagebox.h>
|
|
Packit Service |
b98cfc |
#include <qfiledialog.h>
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
#include "app_global.h"
|
|
Packit Service |
b98cfc |
#include "routingwidget.h"
|
|
Packit Service |
b98cfc |
#include "structure.h"
|
|
Packit Service |
b98cfc |
#include "structure_io.h"
|
|
Packit Service |
b98cfc |
#include "structure_link.h"
|
|
Packit Service |
b98cfc |
#include "structure_patch.h"
|
|
Packit Service |
b98cfc |
#include "strglobal.h"
|
|
Packit Service |
b98cfc |
#include "ld10k1file.h"
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
extern QString gLastFileDir;
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
void RoutingWidget::openObjectMenuAt(RSItemBaseWithType *item, MenuMode mm, int xp, int yp, int mxp, int myp)
|
|
Packit Service |
b98cfc |
{
|
|
Packit Service |
b98cfc |
QPopupMenu *contextMenu = new QPopupMenu();
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
enum Action {Refresh, ClearDSP, Delete, Rename, Disconnect, DelPoint, AddPoint, Connect, Save};
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
int rn = -1;
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
if (mm == MenuNone)
|
|
Packit Service |
b98cfc |
{
|
|
Packit Service |
b98cfc |
contextMenu->insertItem(tr("&Refresh"), Refresh);
|
|
Packit Service |
b98cfc |
//contextMenu->insertItem(tr("&AutoArange")/*, this, SLOT(menuQuitActivated(int))*/);
|
|
Packit Service |
b98cfc |
contextMenu->insertItem(tr("&Clear DSP"), ClearDSP);
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
else if (mm == MenuObjects)
|
|
Packit Service |
b98cfc |
{
|
|
Packit Service |
b98cfc |
contextMenu->insertItem(tr("&Delete (Unload)"), Delete);
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
else if (mm == MenuIO)
|
|
Packit Service |
b98cfc |
{
|
|
Packit Service |
b98cfc |
//contextMenu->insertItem(tr("&Rename"), Rename);
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
bool isConnected = false;
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
if (item->type() == RSItemBaseWithType::Out)
|
|
Packit Service |
b98cfc |
isConnected = item->getIO(false, 0)->getConnectedTo() != NULL;
|
|
Packit Service |
b98cfc |
else
|
|
Packit Service |
b98cfc |
isConnected = item->getIO(true, 0)->getConnectedTo() != NULL;
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
if (isConnected)
|
|
Packit Service |
b98cfc |
contextMenu->insertItem(tr("D&isconnect"), Disconnect);
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
contextMenu->insertSeparator();
|
|
Packit Service |
b98cfc |
contextMenu->insertItem(tr("&Delete"), Delete);
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
else if (mm == MenuLink)
|
|
Packit Service |
b98cfc |
{
|
|
Packit Service |
b98cfc |
int pn = item->getHandlePointNum(xp, yp);
|
|
Packit Service |
b98cfc |
if (pn > 0)
|
|
Packit Service |
b98cfc |
contextMenu->insertItem(tr("D&elete point"), DelPoint);
|
|
Packit Service |
b98cfc |
else if (pn < 0)
|
|
Packit Service |
b98cfc |
contextMenu->insertItem(tr("A&dd point"), AddPoint);
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
if (item->type() == RSItemBaseWithType::Link)
|
|
Packit Service |
b98cfc |
{
|
|
Packit Service |
b98cfc |
StrLink *lnk = (StrLink *)item;
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
rn = lnk->getRouteNumFromPoint(xp, yp);
|
|
Packit Service |
b98cfc |
if(rn >= 0)
|
|
Packit Service |
b98cfc |
{
|
|
Packit Service |
b98cfc |
RSItemIO *io = NULL;
|
|
Packit Service |
b98cfc |
RSItemBaseWithType *own = NULL;
|
|
Packit Service |
b98cfc |
io = lnk->getRoutePoint(rn);
|
|
Packit Service |
b98cfc |
if(io)
|
|
Packit Service |
b98cfc |
{
|
|
Packit Service |
b98cfc |
own = (RSItemBaseWithType*)io->getOwner();
|
|
Packit Service |
b98cfc |
if(own && (own->type() == RSItemBaseWithType::Patch))
|
|
Packit Service |
b98cfc |
contextMenu->insertItem(tr("D&isconnect"), Disconnect);
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
contextMenu->insertSeparator();
|
|
Packit Service |
b98cfc |
contextMenu->insertItem(tr("&Delete"), Delete);
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
else if (mm == MenuPatch)
|
|
Packit Service |
b98cfc |
{
|
|
Packit Service |
b98cfc |
//contextMenu->insertItem(tr("&Rename"), Rename);
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
RSItemIO *io = item->getIOAtPoint(xp, yp);
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
if (io)
|
|
Packit Service |
b98cfc |
{
|
|
Packit Service |
b98cfc |
//contextMenu->insertItem(tr("&IO Rename"), Rename);
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
if (io->getConnectedTo())
|
|
Packit Service |
b98cfc |
contextMenu->insertItem(tr("D&isconnect"), Disconnect);
|
|
Packit Service |
b98cfc |
else
|
|
Packit Service |
b98cfc |
contextMenu->insertItem(tr("&Connect"), Connect);
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
else
|
|
Packit Service |
b98cfc |
contextMenu->insertItem(tr("&Save"), Save);
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
contextMenu->insertSeparator();
|
|
Packit Service |
b98cfc |
contextMenu->insertItem(tr("&Unload"), Delete);
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
int id = contextMenu->exec(QPoint(mxp, myp));
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
delete contextMenu;
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
if (id < 0)
|
|
Packit Service |
b98cfc |
return;
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
if (id == AddPoint)
|
|
Packit Service |
b98cfc |
{
|
|
Packit Service |
b98cfc |
StrLink *l = (StrLink *)item;
|
|
Packit Service |
b98cfc |
if (l->addSegmentPoint(xp, yp))
|
|
Packit Service |
b98cfc |
{
|
|
Packit Service |
b98cfc |
l->updateContents(drawing, getZoomLevel());
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
else if (id == DelPoint)
|
|
Packit Service |
b98cfc |
{
|
|
Packit Service |
b98cfc |
StrLink *l = (StrLink *)item;
|
|
Packit Service |
b98cfc |
// FIXME - update before del
|
|
Packit Service |
b98cfc |
l->updateContents(drawing, getZoomLevel());
|
|
Packit Service |
b98cfc |
l->delSegmentPoint(l->getHandlePointNum(xp, yp));
|
|
Packit Service |
b98cfc |
l->calcSize();
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
else if (id == Delete)
|
|
Packit Service |
b98cfc |
{
|
|
Packit Service |
b98cfc |
drawing->deleteAllSelected();
|
|
Packit Service |
b98cfc |
structure->loadFromLD();
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
else if (id == Connect)
|
|
Packit Service |
b98cfc |
{
|
|
Packit Service |
b98cfc |
StrPatch *p = (StrPatch *)item;
|
|
Packit Service |
b98cfc |
RSItemIO *pio = p->getIOAtPoint(xp, yp);
|
|
Packit Service |
b98cfc |
if (pio)
|
|
Packit Service |
b98cfc |
drawing->startLinkDrag(pio, xp, yp);
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
else if (id == Disconnect)
|
|
Packit Service |
b98cfc |
{
|
|
Packit Service |
b98cfc |
RSItemIO *io = NULL;
|
|
Packit Service |
b98cfc |
if (item->type() == RSItemBaseWithType::Patch)
|
|
Packit Service |
b98cfc |
{
|
|
Packit Service |
b98cfc |
int err;
|
|
Packit Service |
b98cfc |
StrPatch *p = (StrPatch *)item;
|
|
Packit Service |
b98cfc |
io = p->getIOAtPoint(xp, yp);
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
StrLink *l = io->getConnectedTo();
|
|
Packit Service |
b98cfc |
// FIXME - update before disconnect
|
|
Packit Service |
b98cfc |
l->updateContents(drawing, getZoomLevel());
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
if ((err = structure->disconnectFromLink(io)) < 0)
|
|
Packit Service |
b98cfc |
QMessageBox::critical(0, APP_NAME, QString("Couldn't disconnect !\n(ld10k1 error:%1)").arg(structure->errorStr(err)));
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
else
|
|
Packit Service |
b98cfc |
{
|
|
Packit Service |
b98cfc |
if (item->type() == RSItemBaseWithType::In)
|
|
Packit Service |
b98cfc |
{
|
|
Packit Service |
b98cfc |
StrInput *in = (StrInput *)item;
|
|
Packit Service |
b98cfc |
io = in->getIO(true, 0);
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
else if (item->type() == RSItemBaseWithType::Out)
|
|
Packit Service |
b98cfc |
{
|
|
Packit Service |
b98cfc |
StrOutput *out = (StrOutput *)item;
|
|
Packit Service |
b98cfc |
io = out->getIO(false, 0);
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
else if (item->type() == RSItemBaseWithType::FX)
|
|
Packit Service |
b98cfc |
{
|
|
Packit Service |
b98cfc |
StrFX *fx = (StrFX *)item;
|
|
Packit Service |
b98cfc |
io = fx->getIO(true, 0);
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
if(io)
|
|
Packit Service |
b98cfc |
{
|
|
Packit Service |
b98cfc |
StrLink *l = io->getConnectedTo();
|
|
Packit Service |
b98cfc |
structure->deleteOneLink(l);
|
|
Packit Service |
b98cfc |
structure->loadFromLD();
|
|
Packit Service |
b98cfc |
drawing->updateContents();
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
else if (item->type() == RSItemBaseWithType::Link)
|
|
Packit Service |
b98cfc |
{
|
|
Packit Service |
b98cfc |
StrLink *lnk = (StrLink *)item;
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
if(rn >= 0)
|
|
Packit Service |
b98cfc |
{
|
|
Packit Service |
b98cfc |
io = lnk->getRoutePoint(rn);
|
|
Packit Service |
b98cfc |
if(io)
|
|
Packit Service |
b98cfc |
{
|
|
Packit Service |
b98cfc |
RSItemBaseWithType *own = NULL;
|
|
Packit Service |
b98cfc |
own = (RSItemBaseWithType*)io->getOwner();
|
|
Packit Service |
b98cfc |
if(own && (own->type() == RSItemBaseWithType::Patch))
|
|
Packit Service |
b98cfc |
{
|
|
Packit Service |
b98cfc |
int err;
|
|
Packit Service |
b98cfc |
if ((err = structure->disconnectFromLink(io)) < 0)
|
|
Packit Service |
b98cfc |
QMessageBox::critical(0, APP_NAME, QString("Couldn't disconnect !\n(ld10k1 error:%1)").arg(structure->errorStr(err)));
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
drawing->updateContents();
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
else if (id == ClearDSP)
|
|
Packit Service |
b98cfc |
{
|
|
Packit Service |
b98cfc |
structure->clearDSP();
|
|
Packit Service |
b98cfc |
drawing->updateContents();
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
else if (id == Refresh)
|
|
Packit Service |
b98cfc |
{
|
|
Packit Service |
b98cfc |
structure->loadFromLD();
|
|
Packit Service |
b98cfc |
drawing->updateContents();
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
else if (id == Save)
|
|
Packit Service |
b98cfc |
{
|
|
Packit Service |
b98cfc |
StrPatch *p = (StrPatch *)item;
|
|
Packit Service |
b98cfc |
int err;
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
QFileDialog *fd = new QFileDialog(this, "file dialog", TRUE);
|
|
Packit Service |
b98cfc |
fd->setMode(QFileDialog::AnyFile);
|
|
Packit Service |
b98cfc |
fd->setFilter("ld10k1 Native effect files (*.ld10k1)");
|
|
Packit Service |
b98cfc |
fd->setCaption("Save patch");
|
|
Packit Service |
b98cfc |
fd->setDir(gLastFileDir);
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
QString fileName;
|
|
Packit Service |
b98cfc |
if (fd->exec() == QDialog::Accepted)
|
|
Packit Service |
b98cfc |
{
|
|
Packit Service |
b98cfc |
fileName = fd->selectedFile();
|
|
Packit Service |
b98cfc |
gLastFileDir = fd->dirPath();
|
|
Packit Service |
b98cfc |
delete fd;
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
if (!fileName.endsWith(".ld10k1"))
|
|
Packit Service |
b98cfc |
fileName += ".ld10k1";
|
|
Packit Service |
b98cfc |
if (QFile::exists(fileName))
|
|
Packit Service |
b98cfc |
{
|
|
Packit Service |
b98cfc |
if (QMessageBox::question(0, APP_NAME, QString("File with name %1 exists. Overwrite ?").arg(fileName), QMessageBox::Yes, QMessageBox::Cancel) != QMessageBox::Yes)
|
|
Packit Service |
b98cfc |
return;
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
LD10k1File *pf = NULL;
|
|
Packit Service |
b98cfc |
if ((err = structure->get(p->num(), &pf)) < 0)
|
|
Packit Service |
b98cfc |
{
|
|
Packit Service |
b98cfc |
QMessageBox::critical(0, APP_NAME, QString("Couldn't get patch !\n(ld10k1 error:%1)").arg(structure->errorStr(err)));
|
|
Packit Service |
b98cfc |
return;
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
|
|
Packit Service |
b98cfc |
if ((err = pf->SaveToFile(fileName)) < 0)
|
|
Packit Service |
b98cfc |
QMessageBox::critical(0, APP_NAME, QString("Couldn't save patch\n(ld10k1 error:%1)").arg(structure->errorStr(err)));
|
|
Packit Service |
b98cfc |
delete pf;
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
else
|
|
Packit Service |
b98cfc |
delete fd;
|
|
Packit Service |
b98cfc |
}
|
|
Packit Service |
b98cfc |
}
|