diff -r 0dc9286ad3d4 -r 9b9c7e8b9147 mapeditor.cpp --- a/mapeditor.cpp Wed Jul 13 11:36:15 2005 +0000 +++ b/mapeditor.cpp Tue Jul 19 14:44:30 2005 +0000 @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -611,37 +612,93 @@ */ } -void MapEditor::parseAtom(const QString &s) +void MapEditor::parseAtom(const QString &atom) { API api; - QString c,p,p0; - api.parseCommand (s,c,p); - api.getString(p,p0); - /* FIXME testing - cout <<"ME::parseAtom s="<move (x,y); + } + } + } + else if (com=="linkBranchToPos") + { + if (selection && typeid(*selection) == typeid(BranchObj) ) + { + if (api.checkParamCount(4)) + { + s=api.parString(ok,0); + LinkableMapObj *dst=mapCenter->findObjBySelect (s); + if (dst) + { + if (typeid(*dst) == typeid(BranchObj) ) + ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1); + if (typeid(*dst) == typeid(MapCenterObj) ) + { + ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1); + x=api.parInt (ok,2); + if (ok) + { + y=api.parInt (ok,3); + if (ok) ((BranchObj*)(selection))->move (x,y); + } + } + } + } + } + } else if (com=="setHeading") + { + if (api.checkParamCount(1)) + { + s=api.parString (ok,0); + if (ok) setHeading (s); + } + } // Internal commands, used for undo etc. - else if (c==QString("undoMap")) + else if (com==QString("undoMap")) undoXML(""); - else if (c==QString("undoPart")) - undoXML(p0); - else if (c=="select") - select (p0); + else if (com==QString("undoPart")) + { + if (api.checkParamCount(1)) + { + s=api.parString (ok,0); + undoXML(s); + } + } else if (com=="select") + if (api.checkParamCount(1)) + { + s=api.parString(ok,0); + if (ok) select (s); + } else + api.setError ("Unknown command in: "+atom); + + // Any errors? + if (api.error()) { cout << "MapEditor::parseAtom: Error!\n"; - cout << " Command unknown: \""<unselect(); selection=NULL; } + */ parseAtom (undoCommand); mapCenter->reposition(); @@ -1415,6 +1474,21 @@ } } +void MapEditor::linkBranchToPos (LinkableMapObj *dst, const int &pos, const QPoint &p) +{ + // FIXME no saveState, because this is only internal at undo so far + if (selection && typeid(*selection) == typeid(BranchObj) ) + { + if (dst && typeid(*dst) == typeid(BranchObj) ) + ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1); + if (dst && typeid(*dst) == typeid(MapCenterObj) ) + { + ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1); + ((BranchObj*)(selection))->move (p); + } + } +} + void MapEditor::editHeading() { // Finish open lineEdits @@ -3006,7 +3080,6 @@ selection->select(); adjustCanvasSize(); - } // Check, if systemFlag clicked @@ -3035,6 +3108,11 @@ // Left Button Move Branches if (e->button() == QMouseEvent::LeftButton ) { + movingObj_start.setX( p.x() - selection->x() ); + movingObj_start.setY( p.y() - selection->y() ); + movingObj_orgPos.setX (lmo->x() ); + movingObj_orgPos.setY (lmo->y() ); + // If modMode==copy, then we want to "move" the _new_ object around // then we need the offset from p to the _old_ selection, because of tmp if (actionModModeCopy->isOn() && @@ -3043,20 +3121,13 @@ if (typeid(*selection)==typeid(BranchObj) ) { copyingObj=true; - movingObj_start.setX( p.x() - selection->x() ); - movingObj_start.setY( p.y() - selection->y() ); mapCenter->addBranch ((BranchObj*)(selection)); unselect(); selection=mapCenter->getLastBranch(); selection->select(); mapCenter->reposition(); } - } else - { - movingObj_start.setX( p.x() - selection->x() ); - movingObj_start.setY( p.y() - selection->y() ); - } - + } movingObj=selection; } else // Middle Button Toggle Scroll @@ -3137,7 +3208,6 @@ // setLinkStyle calls updateLink, only set it once if (fio->getLinkStyle()!=fio->getDefLinkStyle() ) fio->setLinkStyle (fio->getDefLinkStyle()); - } // TODO if (typeid(*selection) == typeid(FloatTextObj)) } @@ -3156,7 +3226,7 @@ { // depth==1, mainbranch setChanged(); - saveState(lmosel); + saveState("move "+qpointToString(movingObj_orgPos)); lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() ); } else { @@ -3299,50 +3369,34 @@ copyingObj=false; - if (!dst ) + if (dst ) { - if (copyingObj) - { - // remove the current selection, if we have no destination - selection->unselect(); - ((BranchObj*)(selection->getParObj()))->removeBranch ((BranchObj*)(selection)); - if (selectionLast) - { - selection=selectionLast; - selectionLast=NULL; - selection->select(); - } - } - } else - { + BranchObj* bs=((BranchObj*)(selection)); setChanged(); - saveState(); + saveState ("linkBranchToPos (\""+ + (bs->getParObj())->getSelectString()+ + "\","+ + QString("%1").arg(bs->getNum())+ + ","+ + QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ + ")"); // TODO we also could check, if dest and src are on same branch, // then it would be sufficient to saveState of this branch // Modifiers allow to insert above/below dst if (e->state() & QMouseEvent::ShiftButton) { - ((BranchObj*)(selection))->moveBranchTo - ( - (BranchObj*)(dst), - ((BranchObj*)(dst))->getNum() - ); - //if (selection) selection->select(); + bs->moveBranchTo ( (BranchObj*)(dst), ((BranchObj*)(dst))->getNum()); } else if (e->state() & QMouseEvent::ControlButton) { - ((BranchObj*)(selection))->moveBranchTo - ( - (BranchObj*)(dst), - ((BranchObj*)(dst))->getNum()+1 - ); - //if (selection) selection->select(); + bs->moveBranchTo ( (BranchObj*)(dst), ((BranchObj*)(dst))->getNum()+1); } else { - ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1); + bs->moveBranchTo ((BranchObj*)(dst),-1); if (dst->getDepth()==0) - ((BranchObj*)(selection))->move (savePos); + bs->move (savePos); + cout << "ME::release start was: "<format(i);i++) // Debug mime type +// cerr << event->format(i) << endl; + if (selection && (typeid(*selection) == typeid(BranchObj)) || (typeid(*selection) == typeid(MapCenterObj))) { @@ -3414,13 +3472,30 @@ } // If Uri are dragged from firefox - if (event->provides("text/x-moz-url") ){ + if (event->provides("_NETSCAPE_URL")){ event->accept(); return; } + + // If QTextDrag can decode mime type + if (QTextDrag::canDecode(event)) { + event->accept(); + return; + } + } event->ignore(); } + +bool isUnicode16(const QByteArray &d) +{ + // FIXME: make more precise check for unicode 16. + // Guess unicode16 if any of second bytes are zero + unsigned int length = max(0,d.size()-2)/2; + for (unsigned int i = 0; iprovides("image/png")) { QPixmap pix; @@ -3444,7 +3520,7 @@ } else if (event->provides("application/x-moz-file-promise-url") && event->provides("application/x-moz-nativeimage")) { - // Contains url to the img src in UTF-16 + // Contains url to the img src in unicode16 QByteArray d = event->encodedData("application/x-moz-file-promise-url"); QString url = QString((const QChar*)d.data(),d.size()/2); fetchImage(url); @@ -3453,14 +3529,40 @@ } else if (event->provides ("text/uri-list")) { // Uris provided e.g. by konqueror QUriDrag::decode (event,uris); - } else if (event->provides ("text/x-moz-url-data")) + } else if (event->provides ("_NETSCAPE_URL")) { // Uris provided by Mozilla - QString str; - QTextDrag::decode (event,str); - uris.append(str); + QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL")); + uris.append(l[0]); + heading = l[1]; + } else if (event->provides("text/html")) { + + // Handels text mime types + // Look like firefox allways handle text as unicode16 (2 bytes per char.) + QByteArray d = event->encodedData("text/html"); + QString text; + if (isUnicode16(d)) + text = QString((const QChar*)d.data(),d.size()/2); + else + text = QString(d); + + textEditor->setText(text); + + event->accept(); + update=true; + } else if (event->provides("text/plain")) { + QByteArray d = event->encodedData("text/plain"); + QString text; + if (isUnicode16(d)) + text = QString((const QChar*)d.data(),d.size()/2); + else + text = QString(d); + + textEditor->setText(text); + + event->accept(); + update= true; } - if (uris.count()>0) { QStringList files; @@ -3473,12 +3575,23 @@ if (bo) { s=QUriDrag::uriToLocalFile(u); - if (s) - files.append(QDir::convertSeparators(s)); - else - urls.append (u); - bo->setHeading(u); - bo->setURL (u); + if (s) { + QString file = QDir::convertSeparators(s); + heading = QFileInfo(file).baseName(); + files.append(file); + if (file.endsWith(".vym", false)) + bo->setVymLink(file); + else + bo->setURL(u); + } else { + urls.append (u); + bo->setURL(u); + } + + if (heading) + bo->setHeading(heading); + else + bo->setHeading(u); } } update=true; @@ -3486,6 +3599,7 @@ if (update) { + setChanged(); mapCenter->reposition(); adjustCanvasSize(); canvas()->update(); @@ -3515,8 +3629,7 @@ } -void -MapEditor::imageDataFetched(const QByteArray &a, QNetworkOperation */*nop*/) +void MapEditor::imageDataFetched(const QByteArray &a, QNetworkOperation */*nop*/) { if (!imageBuffer) imageBuffer = new QBuffer(); if (!imageBuffer->isOpen()) { @@ -3526,21 +3639,24 @@ } -void -MapEditor::imageDataFinished(QNetworkOperation *nop) +void MapEditor::imageDataFinished(QNetworkOperation *nop) { - imageBuffer->close(); - if (nop->state()==QNetworkProtocol::StDone) { - QPixmap img(imageBuffer->buffer()); - addFloatImage(img); - } - - delete imageBuffer; - imageBuffer = 0; + if (nop->state()==QNetworkProtocol::StDone) { + QPixmap img(imageBuffer->buffer()); + addFloatImage(img); + } + + if (imageBuffer) { + imageBuffer->close(); + if (imageBuffer) { + imageBuffer->close(); + delete imageBuffer; + imageBuffer = 0; + } + } } -void -MapEditor::fetchImage(const QString &url) +void MapEditor::fetchImage(const QString &url) { if (urlOperator) { urlOperator->stop();