Ejemplo n.º 1
0
void do_savedialog()
{
    changeFullScreen(0);
    FILE * fh = savefiledialog(NULL);
    if (fh)
    {
        do_savexml(fh);      
    }
}
Ejemplo n.º 2
0
void do_resetdialog()
{
    changeFullScreen(0);
    save_undo();
    if (okcancel("Are you sure you want to reset?\nAny unsaved changes will be lost."))
	{
		resetfilename();
        do_reset();
	}
}
Ejemplo n.º 3
0
void do_loaddialog(int merge, const char *aFilename)
{
    changeFullScreen(0);
	clear_boxcache();
    FILE *fh = 0;
	char *boxfn = NULL;
	char *origactivefilename = NULL;
	if (gFilename)
		origactivefilename = mystrdup(gFilename);
    if (aFilename)
    {
        fh = fopen(aFilename, "rb");
		storefilename(aFilename);
    }
    else
    {
		if (merge == 2)
		{
			// pop up the dialog
			fh = openfiledialog(NULL);
			
			if (fh)
			{
				// find the last part of the file without path
				char * s1 = strrchr(gFilename,'\\');
			
				if (s1 == NULL)
				{
					s1 = strrchr(gFilename,'/');
				}
			
				// if above fails, just use the whole name
				if (s1 == NULL)
				{
					s1 = gFilename;
				}
				else
				{
					// skip the last slash/backslash
					s1++;
				}
			
				// this shall be the box filename
				boxfn = mystrdup(s1);
			}
		}
		else
		{
			fh = openfiledialog(NULL);
		}
    }

    if (fh)
    {
        save_undo();
		if (!merge)
			do_reset();
        File * f = new File(fh);
        int id = f->readint();
        f->seek(0);
        if (id == 0x00617441) // 'Ata\0'
        {
            // It's binary
            do_loadoldbinary(f);
        }
        else
        {
            // It's XML
			if (merge == 2)
			{
				// boxing
				BoxStitchingInformation * bsi = do_preparse_box(boxfn);
				if (bsi == NULL)
				{
					// box loading failed
					delete[] boxfn;
					delete f;
					storefilename(origactivefilename);
					delete[] origactivefilename;
					return;
				}
				Box * b = new Box(boxfn, bsi);

				// do actual loading
				do_flush_boxloadqueue();

				gNewChip = b;
				gNewChipName = boxfn;

				do_build_nets(); // causes cancel; otherwise the drag mode gets cancelled.

				gDragMode = DRAGMODE_NEWCHIP;
				storefilename(origactivefilename);
				delete[] origactivefilename;
			}
			else
			{
				int oldmaxchip = gChip.size();
				int oldmaxwire = gWire.size();
				do_loadxml(fh, 0);
				if (merge)
				{
					int i;
					for (i = oldmaxchip; i < (signed)gChip.size(); i++)
					{
						if (gChip[i]->mBox == 0)
						{
							gMultiSelectChip.push_back(gChip[i]);
							gChip[i]->mMultiSelectState = 1;
						}
					}
					for (i = oldmaxwire; i < (signed)gWire.size(); i++)
					{
						if (gWire[i]->mBox == 0)
						{
							gMultiSelectWire.push_back(gWire[i]);
							gWire[i]->mMultiSelectState = 1;
						}
					}
					storefilename(origactivefilename);
					delete[] origactivefilename;
				}
			}
        }
        delete f; // closes handle
    }
}
Ejemplo n.º 4
0
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
    switch(event->type()) {
    case QEvent::ToolTip:
    {
        if (obj != viewer) break;

        QHelpEvent* e = static_cast<QHelpEvent*>(event);
        if (attributeRect.contains(e->pos())){
            QString attribute = viewer->attribute();
            if(!attribute.isEmpty())
                ToolTip::showText(e->globalPos(),
                                  attribute.prepend("<b>").append("</b>"),
                                  false, 0.8);
        }
        return true;
    }
    case QEvent::MouseButtonDblClick:
    {
        if (obj != viewer && obj != bottomFrame) break;

        QMouseEvent *e = static_cast<QMouseEvent*>(event);
        if(e->button() & Qt::LeftButton)
            changeFullScreen();
        return true;
    }
    case QEvent::ContextMenu:
    {
        QContextMenuEvent *e = static_cast<QContextMenuEvent*>(event);
        showContextMenu(e->globalPos());
        return true;
    }
    case QEvent::Wheel:
    {
        QWheelEvent *e = static_cast<QWheelEvent *>(event);

//        if (e->delta() < 0)
//            viewer->nextPic();
//        else
//            viewer->prePic();

        qreal factor = 0.1;
        switch(e->modifiers()){
        case Qt::ShiftModifier:
            factor = e->delta() / qreal(2400); // e->delta() is +120 or -120
            break;
        case Qt::ControlModifier:
            factor = e->delta() / qreal(600);
            break;
        default:
            factor = e->delta() / qreal(1200);
            break;
        }
        viewer->zoomIn(factor, viewer->mapFromGlobal(e->globalPos()));
        break;
    }
    default:
        break;
    }

    return false;
}