insilmaril@0: #include "mapeditor.h" insilmaril@0: insilmaril@39: #include insilmaril@0: insilmaril@0: #include insilmaril@39: #include insilmaril@0: #include insilmaril@0: insilmaril@39: #include "parser.h" insilmaril@39: #include "editxlinkdialog.h" insilmaril@39: #include "exports.h" insilmaril@39: #include "exportxhtmldialog.h" insilmaril@39: #include "extrainfodialog.h" insilmaril@39: #include "file.h" insilmaril@39: #include "linkablemapobj.h" insilmaril@39: #include "mainwindow.h" insilmaril@39: #include "misc.h" insilmaril@0: #include "texteditor.h" insilmaril@39: #include "warningdialog.h" insilmaril@39: #include "xml-freemind.h" insilmaril@39: #include "xml-vym.h" insilmaril@39: insilmaril@0: insilmaril@0: extern TextEditor *textEditor; insilmaril@0: extern int statusbarTime; insilmaril@0: extern Main *mainWindow; insilmaril@39: extern QString tmpVymDir; insilmaril@39: extern QString clipboardDir; insilmaril@39: extern QString clipboardFile; insilmaril@39: extern bool clipboardEmpty; insilmaril@39: extern bool debug; insilmaril@0: extern FlagRowObj *standardFlagsDefault; insilmaril@39: insilmaril@39: extern QMenu* branchContextMenu; insilmaril@39: extern QMenu* branchAddContextMenu; insilmaril@39: extern QMenu* branchRemoveContextMenu; insilmaril@39: extern QMenu* branchLinksContextMenu; insilmaril@39: extern QMenu* branchXLinksContextMenuEdit; insilmaril@39: extern QMenu* branchXLinksContextMenuFollow; insilmaril@39: extern QMenu* floatimageContextMenu; insilmaril@39: extern QMenu* canvasContextMenu; insilmaril@39: insilmaril@0: insilmaril@0: extern Settings settings; insilmaril@39: extern ImageIO imageIO; insilmaril@39: insilmaril@39: extern QString vymName; insilmaril@39: extern QString vymVersion; insilmaril@39: insilmaril@39: extern QString iconPath; insilmaril@39: extern QDir vymBaseDir; insilmaril@39: extern QDir lastImageDir; insilmaril@39: extern QDir lastFileDir; insilmaril@39: insilmaril@39: int MapEditor::mapNum=0; // make instance insilmaril@0: insilmaril@0: /////////////////////////////////////////////////////////////////////// insilmaril@0: /////////////////////////////////////////////////////////////////////// insilmaril@39: MapEditor::MapEditor( QWidget* parent) : insilmaril@39: QGraphicsView(parent) insilmaril@39: { insilmaril@39: setObjectName ("MapEditor"); insilmaril@39: insilmaril@0: //cout << "Constructor ME "<setBackgroundBrush (QBrush(Qt::white, Qt::SolidPattern)); insilmaril@39: insilmaril@39: model=new VymModel(); insilmaril@39: model->setScene (mapScene); insilmaril@39: model->setMapEditor (this); insilmaril@39: insilmaril@39: setScene (mapScene); insilmaril@0: insilmaril@0: printer=NULL; insilmaril@0: insilmaril@39: defLinkColor=QColor (0,0,255); insilmaril@39: defXLinkColor=QColor (180,180,180); insilmaril@39: linkcolorhint=LinkableMapObj::DefaultColor; insilmaril@39: linkstyle=LinkableMapObj::PolyParabel; insilmaril@39: insilmaril@39: // Create bitmap cursors, platform dependant insilmaril@39: HandOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1); insilmaril@39: PickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 ); insilmaril@39: CopyCursor=QCursor ( QPixmap(iconPath+"cursorcopy.png"), 1,1 ); insilmaril@39: XLinkCursor=QCursor ( QPixmap(iconPath+"cursorxlink.png"), 1,7 ); insilmaril@39: insilmaril@39: setFocusPolicy (Qt::StrongFocus); insilmaril@0: insilmaril@0: pickingColor=false; insilmaril@39: drawingLink=false; insilmaril@39: copyingObj=false; insilmaril@0: insilmaril@0: editingBO=NULL; insilmaril@0: movingObj=NULL; insilmaril@0: insilmaril@39: xelection.setModel (model); insilmaril@39: xelection.unselect(); insilmaril@39: insilmaril@39: defXLinkWidth=1; insilmaril@39: defXLinkColor=QColor (230,230,230); insilmaril@39: insilmaril@0: mapChanged=false; insilmaril@0: mapDefault=true; insilmaril@0: mapUnsaved=false; insilmaril@0: insilmaril@0: zipped=true; insilmaril@0: filePath=""; insilmaril@39: fileName=tr("unnamed"); insilmaril@0: mapName=""; insilmaril@0: insilmaril@39: stepsTotal=settings.readNumEntry("/mapeditor/stepsTotal",100); insilmaril@39: undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal)); insilmaril@39: mainWindow->updateHistory (undoSet); insilmaril@39: insilmaril@0: // Initialize find routine insilmaril@0: itFind=NULL; insilmaril@0: EOFind=false; insilmaril@0: insilmaril@0: printFrame=true; insilmaril@0: printFooter=true; insilmaril@0: insilmaril@39: blockReposition=false; insilmaril@39: blockSaveState=false; insilmaril@39: insilmaril@39: hidemode=HideNone; insilmaril@39: insilmaril@39: // Create temporary files insilmaril@39: makeTmpDirs(); insilmaril@39: insilmaril@39: curStep=0; insilmaril@39: redosAvail=0; insilmaril@39: undosAvail=0; insilmaril@39: insilmaril@39: setAcceptDrops (true); insilmaril@39: insilmaril@39: model->reposition(); insilmaril@39: insilmaril@39: // autosave insilmaril@39: autosaveTimer=new QTimer (this); insilmaril@39: connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave())); insilmaril@39: insilmaril@39: fileChangedTimer=new QTimer (this); insilmaril@39: fileChangedTimer->start(3000); insilmaril@39: connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged())); insilmaril@39: insilmaril@39: // Network insilmaril@39: netstate=Offline; insilmaril@39: insilmaril@39: // Attributes //FIXME testing only... insilmaril@39: QString k; insilmaril@39: AttributeDef *ad; insilmaril@39: attrTable= new AttributeTable(); insilmaril@39: k="A - StringList"; insilmaril@39: ad=attrTable->addKey (k,StringList); insilmaril@39: if (ad) insilmaril@39: { insilmaril@39: QStringList sl; insilmaril@39: sl <<"val 1"<<"val 2"<< "val 3"; insilmaril@39: ad->setValue (QVariant (sl)); insilmaril@39: } insilmaril@39: //attrTable->addValue ("Key A","P 1"); insilmaril@39: //attrTable->addValue ("Key A","P 2"); insilmaril@39: //attrTable->addValue ("Key A","P 3"); insilmaril@39: //attrTable->addValue ("Key A","P 4"); insilmaril@39: k="B - FreeString"; insilmaril@39: ad=attrTable->addKey (k,FreeString); insilmaril@39: if (ad) insilmaril@39: { insilmaril@39: //attrTable->addValue ("Key B","w1"); insilmaril@39: //attrTable->addValue ("Key B","w2"); insilmaril@39: } insilmaril@39: k="C - UniqueString"; insilmaril@39: ad=attrTable->addKey (k,UniqueString); insilmaril@39: if (ad) insilmaril@39: { insilmaril@39: //attrTable->addKey ("Key Prio"); insilmaril@39: //attrTable->addValue ("Key Prio","Prio 1"); insilmaril@39: //attrTable->addValue ("Key Prio","Prio 2"); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@39: MapEditor::~MapEditor() insilmaril@39: { insilmaril@59: //cout <<"Destructor MapEditor "<stop(); insilmaril@59: clear(); insilmaril@39: insilmaril@39: // tmpMapDir is in tmpVymDir, so it gets removed automagically when vym closes insilmaril@39: insilmaril@39: //removeDir(QDir(tmpMapDir)); insilmaril@39: delete (model); insilmaril@0: } insilmaril@0: insilmaril@39: VymModel* MapEditor::getModel() insilmaril@39: { insilmaril@39: return model; insilmaril@39: } insilmaril@39: insilmaril@39: QGraphicsScene * MapEditor::getScene() insilmaril@39: { insilmaril@39: return mapScene; insilmaril@39: } insilmaril@39: insilmaril@39: MapEditor::State MapEditor::getState() insilmaril@39: { insilmaril@39: return state; insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::setStateEditHeading(bool s) insilmaril@39: { insilmaril@39: if (s) insilmaril@39: { insilmaril@39: if (state==Idle) state=EditHeading; insilmaril@39: } insilmaril@39: else insilmaril@39: state=Idle; insilmaril@39: } insilmaril@39: insilmaril@39: bool MapEditor::isRepositionBlocked() insilmaril@39: { insilmaril@39: return blockReposition; insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::setSaveStateBlocked(bool b) insilmaril@39: { insilmaril@39: blockSaveState=b; insilmaril@39: } insilmaril@39: insilmaril@39: bool MapEditor::isSelectBlocked() insilmaril@39: { insilmaril@39: if (state==EditHeading) insilmaril@39: return true; insilmaril@39: else insilmaril@39: return false; insilmaril@39: } insilmaril@39: insilmaril@39: QString MapEditor::getName (const LinkableMapObj *lmo) insilmaril@39: { insilmaril@39: QString s; insilmaril@39: if (!lmo) return QString("Error: NULL has no name!"); insilmaril@39: insilmaril@39: if ((typeid(*lmo) == typeid(BranchObj) || insilmaril@39: typeid(*lmo) == typeid(MapCenterObj))) insilmaril@39: { insilmaril@39: insilmaril@39: s=(((BranchObj*)lmo)->getHeading()); insilmaril@39: if (s=="") s="unnamed"; insilmaril@74: if ((typeid(*lmo) == typeid(BranchObj) ) ) insilmaril@74: return QString("branch (%1)").arg(s); insilmaril@74: return QString("mapcenter (%1)").arg(s); insilmaril@39: } insilmaril@39: if ((typeid(*lmo) == typeid(FloatImageObj) )) insilmaril@39: return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename()); insilmaril@39: return QString("Unknown type has no name!"); insilmaril@39: } insilmaril@39: insilmaril@0: void MapEditor::makeTmpDirs() insilmaril@0: { insilmaril@0: // Create unique temporary directories insilmaril@39: tmpMapDir = tmpVymDir+QString("/mapeditor-%1").arg(mapNum); insilmaril@39: histPath = tmpMapDir+"/history"; insilmaril@39: QDir d; insilmaril@39: d.mkdir (tmpMapDir); insilmaril@0: } insilmaril@0: insilmaril@39: QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel) insilmaril@39: { insilmaril@39: // tmpdir temporary directory to which data will be written insilmaril@0: // prefix mapname, which will be appended to images etc. insilmaril@0: // writeflags Only write flags for "real" save of map, not undo insilmaril@39: // offset offset of bbox of whole map in scene. insilmaril@0: // Needed for XML export insilmaril@0: insilmaril@0: // Save Header insilmaril@0: QString ls; insilmaril@0: switch (linkstyle) insilmaril@0: { insilmaril@39: case LinkableMapObj::Line: insilmaril@0: ls="StyleLine"; insilmaril@0: break; insilmaril@39: case LinkableMapObj::Parabel: insilmaril@0: ls="StyleParabel"; insilmaril@0: break; insilmaril@39: case LinkableMapObj::PolyLine: insilmaril@0: ls="StylePolyLine"; insilmaril@0: break; insilmaril@0: default: insilmaril@0: ls="StylePolyParabel"; insilmaril@0: break; insilmaril@0: } insilmaril@0: insilmaril@0: QString s="\n"; insilmaril@0: QString colhint=""; insilmaril@39: if (linkcolorhint==LinkableMapObj::HeadingColor) insilmaril@0: colhint=attribut("linkColorHint","HeadingColor"); insilmaril@0: insilmaril@39: QString mapAttr=attribut("version",vymVersion); insilmaril@39: if (!saveSel) insilmaril@39: mapAttr+= attribut("author",model->getAuthor()) + insilmaril@39: attribut("comment",model->getComment()) + insilmaril@39: attribut("date",model->getDate()) + insilmaril@64: attribut("branchCount", QString().number(model->countBranches())) + insilmaril@62: insilmaril@39: attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) + insilmaril@39: attribut("selectionColor", xelection.getColor().name() ) + insilmaril@0: attribut("linkStyle", ls ) + insilmaril@39: attribut("linkColor", defLinkColor.name() ) + insilmaril@39: attribut("defXLinkColor", defXLinkColor.name() ) + insilmaril@39: attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) + insilmaril@0: colhint; insilmaril@0: s+=beginElement("vymmap",mapAttr); insilmaril@0: incIndent(); insilmaril@0: insilmaril@0: // Find the used flags while traversing the tree insilmaril@0: standardFlagsDefault->resetUsedCounter(); insilmaril@0: insilmaril@39: // Reset the counters before saving insilmaril@39: // TODO constr. of FIO creates lots of objects, better do this in some other way... insilmaril@39: FloatImageObj (mapScene).resetSaveCounter(); insilmaril@39: insilmaril@0: // Build xml recursivly insilmaril@74: if (!saveSel ) insilmaril@39: // Save complete map, if saveSel not set insilmaril@39: s+=model->saveToDir(tmpdir,prefix,writeflags,offset); insilmaril@0: else insilmaril@0: { insilmaril@74: if ( typeid (*saveSel) == typeid (MapCenterObj)) insilmaril@74: // Save Subtree insilmaril@74: s+=((MapCenterObj*)saveSel)->saveToDir(tmpdir,prefix,0,offset); insilmaril@74: else if ( typeid(*saveSel) == typeid(BranchObj) ) insilmaril@39: // Save Subtree insilmaril@58: s+=((BranchObj*)saveSel)->saveToDir(tmpdir,prefix,offset); insilmaril@58: else insilmaril@58: { insilmaril@58: if ( typeid(*saveSel) == typeid(FloatImageObj) ) insilmaril@58: // Save image insilmaril@58: s+=((FloatImageObj*)saveSel)->saveToDir(tmpdir,prefix); insilmaril@58: } insilmaril@0: } insilmaril@0: insilmaril@0: // Save local settings insilmaril@39: s+=settings.getDataXML (destPath); insilmaril@0: insilmaril@0: // Save selection insilmaril@39: if (!xelection.isEmpty() && !saveSel ) insilmaril@39: s+=valueElement("select",xelection.getSelectString()); insilmaril@0: insilmaril@0: decIndent(); insilmaril@0: s+=endElement("vymmap"); insilmaril@0: insilmaril@0: if (writeflags) insilmaril@0: standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags); insilmaril@0: return s; insilmaril@0: } insilmaril@0: insilmaril@39: QString MapEditor::getHistoryDir() insilmaril@39: { insilmaril@39: QString histName(QString("history-%1").arg(curStep)); insilmaril@39: return (tmpMapDir+"/"+histName); insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel) insilmaril@39: { insilmaril@39: sendData(redoCom); //FIXME testing insilmaril@39: insilmaril@39: // Main saveState insilmaril@39: insilmaril@39: insilmaril@39: if (blockSaveState) return; insilmaril@39: insilmaril@39: if (debug) cout << "ME::saveState() for "<stepsTotal) curStep=1; insilmaril@39: insilmaril@39: QString backupXML=""; insilmaril@39: QString histDir=getHistoryDir(); insilmaril@39: QString bakMapPath=histDir+"/map.xml"; insilmaril@39: insilmaril@39: // Create histDir if not available insilmaril@39: QDir d(histDir); insilmaril@39: if (!d.exists()) insilmaril@39: makeSubDirs (histDir); insilmaril@39: insilmaril@39: // Save depending on how much needs to be saved insilmaril@39: if (saveSel) insilmaril@39: backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel); insilmaril@39: insilmaril@39: QString undoCommand=""; insilmaril@39: if (savemode==UndoCommand) insilmaril@39: { insilmaril@39: undoCommand=undoCom; insilmaril@0: } insilmaril@39: else if (savemode==PartOfMap ) insilmaril@39: { insilmaril@39: undoCommand=undoCom; insilmaril@39: undoCommand.replace ("PATH",bakMapPath); insilmaril@39: } insilmaril@39: insilmaril@39: if (!backupXML.isEmpty()) insilmaril@39: // Write XML Data to disk insilmaril@39: saveStringToDisk (bakMapPath,backupXML); insilmaril@39: insilmaril@39: // We would have to save all actions in a tree, to keep track of insilmaril@39: // possible redos after a action. Possible, but we are too lazy: forget about redos. insilmaril@39: redosAvail=0; insilmaril@39: insilmaril@39: // Write the current state to disk insilmaril@39: undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail)); insilmaril@39: undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail)); insilmaril@39: undoSet.setEntry ("/history/curStep",QString::number(curStep)); insilmaril@39: undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand); insilmaril@39: undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection); insilmaril@39: undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom); insilmaril@39: undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection); insilmaril@39: undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment); insilmaril@39: undoSet.setEntry (QString("/history/version"),vymVersion); insilmaril@39: undoSet.writeSettings(histPath); insilmaril@39: insilmaril@39: if (debug) insilmaril@39: { insilmaril@39: // TODO remove after testing insilmaril@39: //cout << " into="<< histPath.toStdString()<updateHistory (undoSet); insilmaril@39: setChanged(); insilmaril@39: updateActions(); insilmaril@0: } insilmaril@0: insilmaril@39: insilmaril@39: void MapEditor::saveStateChangingPart(LinkableMapObj *undoSel, LinkableMapObj* redoSel, const QString &rc, const QString &comment) insilmaril@39: { insilmaril@39: // save the selected part of the map, Undo will replace part of map insilmaril@39: QString undoSelection=""; insilmaril@39: if (undoSel) insilmaril@39: undoSelection=model->getSelectString(undoSel); insilmaril@39: else insilmaril@39: qWarning ("MapEditor::saveStateChangingPart no undoSel given!"); insilmaril@39: QString redoSelection=""; insilmaril@39: if (redoSel) insilmaril@39: redoSelection=model->getSelectString(undoSel); insilmaril@39: else insilmaril@39: qWarning ("MapEditor::saveStateChangingPart no redoSel given!"); insilmaril@39: insilmaril@39: insilmaril@39: saveState (PartOfMap, insilmaril@39: undoSelection, "addMapReplace (\"PATH\")", insilmaril@39: redoSelection, rc, insilmaril@39: comment, insilmaril@39: undoSel); insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::saveStateRemovingPart(LinkableMapObj *redoSel, const QString &comment) insilmaril@39: { insilmaril@39: if (!redoSel) insilmaril@39: { insilmaril@39: qWarning ("MapEditor::saveStateRemovingPart no redoSel given!"); insilmaril@39: return; insilmaril@39: } insilmaril@74: insilmaril@74: QString undoSelection; insilmaril@39: QString redoSelection=model->getSelectString(redoSel); insilmaril@39: if (typeid(*redoSel) == typeid(BranchObj) ) insilmaril@39: { insilmaril@74: undoSelection=model->getSelectString (redoSel->getParObj()); insilmaril@39: // save the selected branch of the map, Undo will insert part of map insilmaril@39: saveState (PartOfMap, insilmaril@39: undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()), insilmaril@39: redoSelection, "delete ()", insilmaril@39: comment, insilmaril@39: redoSel); insilmaril@39: } insilmaril@74: if (typeid(*redoSel) == typeid(MapCenterObj) ) insilmaril@74: { insilmaril@74: undoSelection.clear(); insilmaril@74: // save the selected branch of the map, Undo will insert part of map insilmaril@74: saveState (PartOfMap, insilmaril@74: undoSelection, QString("addMapInsert (\"PATH\")"), insilmaril@74: redoSelection, "delete ()", insilmaril@74: comment, insilmaril@74: redoSel); insilmaril@74: } insilmaril@39: } insilmaril@39: insilmaril@39: insilmaril@39: void MapEditor::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment) insilmaril@39: { insilmaril@39: // "Normal" savestate: save commands, selections and comment insilmaril@39: // so just save commands for undo and redo insilmaril@39: // and use current selection insilmaril@39: insilmaril@39: QString redoSelection=""; insilmaril@39: if (redoSel) redoSelection=model->getSelectString(redoSel); insilmaril@39: QString undoSelection=""; insilmaril@39: if (undoSel) undoSelection=model->getSelectString(undoSel); insilmaril@39: insilmaril@39: saveState (UndoCommand, insilmaril@39: undoSelection, uc, insilmaril@39: redoSelection, rc, insilmaril@39: comment, insilmaril@39: NULL); insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment) insilmaril@39: { insilmaril@39: // "Normal" savestate: save commands, selections and comment insilmaril@39: // so just save commands for undo and redo insilmaril@39: // and use current selection insilmaril@39: saveState (UndoCommand, insilmaril@39: undoSel, uc, insilmaril@39: redoSel, rc, insilmaril@39: comment, insilmaril@39: NULL); insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::saveState(const QString &uc, const QString &rc, const QString &comment) insilmaril@39: { insilmaril@39: // "Normal" savestate applied to model (no selection needed): insilmaril@39: // save commands and comment insilmaril@39: saveState (UndoCommand, insilmaril@39: NULL, uc, insilmaril@39: NULL, rc, insilmaril@39: comment, insilmaril@39: NULL); insilmaril@39: } insilmaril@39: insilmaril@39: insilmaril@39: void MapEditor::parseAtom(const QString &atom) insilmaril@39: { insilmaril@39: BranchObj *selb=xelection.getBranch(); insilmaril@39: QString s,t; insilmaril@39: double x,y; insilmaril@39: int n; insilmaril@39: bool b,ok; insilmaril@39: insilmaril@39: // Split string s into command and parameters insilmaril@39: parser.parseAtom (atom); insilmaril@39: QString com=parser.getCommand(); insilmaril@39: insilmaril@39: // External commands insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: if (com=="addBranch") insilmaril@39: { insilmaril@39: if (xelection.isEmpty()) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if (! selb ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@39: } else insilmaril@39: { insilmaril@39: QList pl; insilmaril@39: pl << 0 <<1; insilmaril@39: if (parser.checkParCount(pl)) insilmaril@39: { insilmaril@39: if (parser.parCount()==0) insilmaril@39: addNewBranch (0); insilmaril@39: else insilmaril@39: { insilmaril@39: n=parser.parInt (ok,0); insilmaril@39: if (ok ) addNewBranch (n); insilmaril@39: } insilmaril@39: } insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="addBranchBefore") insilmaril@39: { insilmaril@39: if (xelection.isEmpty()) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if (! selb ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@39: } else insilmaril@39: { insilmaril@39: if (parser.parCount()==0) insilmaril@39: { insilmaril@39: addNewBranchBefore (); insilmaril@39: } insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com==QString("addMapCenter")) insilmaril@39: { insilmaril@39: if (parser.checkParCount(2)) insilmaril@39: { insilmaril@39: x=parser.parDouble (ok,0); insilmaril@39: if (ok) insilmaril@39: { insilmaril@39: y=parser.parDouble (ok,1); insilmaril@39: if (ok) model->addMapCenter (QPointF(x,y)); insilmaril@39: } insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com==QString("addMapReplace")) insilmaril@39: { insilmaril@39: if (xelection.isEmpty()) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if (! selb ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@39: } else if (parser.checkParCount(1)) insilmaril@39: { insilmaril@39: //s=parser.parString (ok,0); // selection insilmaril@39: t=parser.parString (ok,0); // path to map insilmaril@39: if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t); insilmaril@39: addMapReplaceInt(model->getSelectString(selb),t); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com==QString("addMapInsert")) insilmaril@39: { insilmaril@74: if (parser.parCount()==2) insilmaril@39: { insilmaril@74: if (xelection.isEmpty()) insilmaril@74: { insilmaril@74: parser.setError (Aborted,"Nothing selected"); insilmaril@74: } else if (! selb ) insilmaril@74: { insilmaril@74: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@74: } else insilmaril@39: { insilmaril@39: t=parser.parString (ok,0); // path to map insilmaril@39: n=parser.parInt(ok,1); // position insilmaril@39: if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t); insilmaril@74: addMapInsertInt(t,n); insilmaril@39: } insilmaril@74: } else if (parser.parCount ()==1) insilmaril@74: { insilmaril@74: t=parser.parString (ok,0); // path to map insilmaril@74: if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t); insilmaril@74: addMapInsertInt(t); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="clearFlags") insilmaril@39: { insilmaril@39: if (xelection.isEmpty() ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if (! selb ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@39: } else if (parser.checkParCount(0)) insilmaril@39: { insilmaril@39: selb->clearStandardFlags(); insilmaril@39: selb->updateFlagsToolbar(); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="colorBranch") insilmaril@39: { insilmaril@39: if (xelection.isEmpty()) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if (! selb ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@39: } else if (parser.checkParCount(1)) insilmaril@39: { insilmaril@39: QColor c=parser.parColor (ok,0); insilmaril@39: if (ok) colorBranch (c); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="colorSubtree") insilmaril@39: { insilmaril@39: if (xelection.isEmpty()) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if (! selb ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@39: } else if (parser.checkParCount(1)) insilmaril@39: { insilmaril@39: QColor c=parser.parColor (ok,0); insilmaril@39: if (ok) colorSubtree (c); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="copy") insilmaril@39: { insilmaril@39: if (xelection.isEmpty()) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if (! selb ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@39: } else if (parser.checkParCount(0)) insilmaril@39: { insilmaril@39: //FIXME missing action for copy insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="cut") insilmaril@39: { insilmaril@39: if (xelection.isEmpty()) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if ( xelection.type()!=Selection::Branch && insilmaril@39: xelection.type()!=Selection::MapCenter && insilmaril@39: xelection.type()!=Selection::FloatImage ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch or floatimage"); insilmaril@39: } else if (parser.checkParCount(0)) insilmaril@39: { insilmaril@39: cut(); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="delete") insilmaril@39: { insilmaril@39: if (xelection.isEmpty()) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } insilmaril@39: /*else if (xelection.type() != Selection::Branch && xelection.type() != Selection::FloatImage ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is wrong."); insilmaril@39: } insilmaril@39: */ insilmaril@39: else if (parser.checkParCount(0)) insilmaril@39: { insilmaril@39: deleteSelection(); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="deleteKeepChilds") insilmaril@39: { insilmaril@39: if (xelection.isEmpty()) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if (! selb ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@39: } else if (parser.checkParCount(0)) insilmaril@39: { insilmaril@39: deleteKeepChilds(); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="deleteChilds") insilmaril@39: { insilmaril@39: if (xelection.isEmpty()) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if (! selb) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@39: } else if (parser.checkParCount(0)) insilmaril@39: { insilmaril@39: deleteChilds(); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="exportASCII") insilmaril@39: { insilmaril@39: QString fname=""; insilmaril@39: ok=true; insilmaril@39: if (parser.parCount()>=1) insilmaril@39: // Hey, we even have a filename insilmaril@39: fname=parser.parString(ok,0); insilmaril@39: if (!ok) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Could not read filename"); insilmaril@39: } else insilmaril@39: { insilmaril@39: exportASCII (fname,false); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="exportImage") insilmaril@39: { insilmaril@39: QString fname=""; insilmaril@39: ok=true; insilmaril@39: if (parser.parCount()>=2) insilmaril@39: // Hey, we even have a filename insilmaril@39: fname=parser.parString(ok,0); insilmaril@39: if (!ok) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Could not read filename"); insilmaril@39: } else insilmaril@39: { insilmaril@39: QString format="PNG"; insilmaril@39: if (parser.parCount()>=2) insilmaril@39: { insilmaril@39: format=parser.parString(ok,1); insilmaril@39: } insilmaril@39: exportImage (fname,false,format); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="exportXHTML") insilmaril@39: { insilmaril@39: QString fname=""; insilmaril@39: ok=true; insilmaril@39: if (parser.parCount()>=2) insilmaril@39: // Hey, we even have a filename insilmaril@39: fname=parser.parString(ok,1); insilmaril@39: if (!ok) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Could not read filename"); insilmaril@39: } else insilmaril@39: { insilmaril@39: exportXHTML (fname,false); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="exportXML") insilmaril@39: { insilmaril@39: QString fname=""; insilmaril@39: ok=true; insilmaril@39: if (parser.parCount()>=2) insilmaril@39: // Hey, we even have a filename insilmaril@39: fname=parser.parString(ok,1); insilmaril@39: if (!ok) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Could not read filename"); insilmaril@39: } else insilmaril@39: { insilmaril@39: exportXML (fname,false); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="importDir") insilmaril@39: { insilmaril@39: if (xelection.isEmpty()) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if (! selb ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@39: } else if (parser.checkParCount(1)) insilmaril@39: { insilmaril@39: s=parser.parString(ok,0); insilmaril@39: if (ok) importDirInt(s); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="linkTo") insilmaril@39: { insilmaril@39: if (xelection.isEmpty()) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if ( selb) insilmaril@39: { insilmaril@39: if (parser.checkParCount(4)) insilmaril@39: { insilmaril@39: // 0 selectstring of parent insilmaril@39: // 1 num in parent (for branches) insilmaril@39: // 2,3 x,y of mainbranch or mapcenter insilmaril@39: s=parser.parString(ok,0); insilmaril@39: LinkableMapObj *dst=model->findObjBySelect (s); insilmaril@39: if (dst) insilmaril@39: { insilmaril@39: if (typeid(*dst) == typeid(BranchObj) ) insilmaril@39: { insilmaril@39: // Get number in parent insilmaril@39: n=parser.parInt (ok,1); insilmaril@39: if (ok) insilmaril@39: { insilmaril@39: selb->linkTo ((BranchObj*)(dst),n); insilmaril@39: xelection.update(); insilmaril@39: } insilmaril@39: } else if (typeid(*dst) == typeid(MapCenterObj) ) insilmaril@39: { insilmaril@39: selb->linkTo ((BranchObj*)(dst),-1); insilmaril@39: // Get coordinates of mainbranch insilmaril@39: x=parser.parDouble(ok,2); insilmaril@39: if (ok) insilmaril@39: { insilmaril@39: y=parser.parDouble(ok,3); insilmaril@39: if (ok) insilmaril@39: { insilmaril@39: selb->move (x,y); insilmaril@39: xelection.update(); insilmaril@39: } insilmaril@39: } insilmaril@39: } insilmaril@39: } insilmaril@39: } insilmaril@39: } else if ( xelection.type() == Selection::FloatImage) insilmaril@39: { insilmaril@39: if (parser.checkParCount(1)) insilmaril@39: { insilmaril@39: // 0 selectstring of parent insilmaril@39: s=parser.parString(ok,0); insilmaril@39: LinkableMapObj *dst=model->findObjBySelect (s); insilmaril@39: if (dst) insilmaril@39: { insilmaril@39: if (typeid(*dst) == typeid(BranchObj) || insilmaril@39: typeid(*dst) == typeid(MapCenterObj)) insilmaril@39: linkTo (model->getSelectString(dst)); insilmaril@39: } else insilmaril@39: parser.setError (Aborted,"Destination is not a branch"); insilmaril@39: } insilmaril@39: } else insilmaril@39: parser.setError (Aborted,"Type of selection is not a floatimage or branch"); insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="loadImage") insilmaril@39: { insilmaril@39: if (xelection.isEmpty()) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if (! selb ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@39: } else if (parser.checkParCount(1)) insilmaril@39: { insilmaril@39: s=parser.parString(ok,0); insilmaril@39: if (ok) loadFloatImageInt (s); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="moveBranchUp") insilmaril@39: { insilmaril@39: if (xelection.isEmpty() ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if (! selb ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@39: } else if (parser.checkParCount(0)) insilmaril@39: { insilmaril@39: moveBranchUp(); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="moveBranchDown") insilmaril@39: { insilmaril@39: if (xelection.isEmpty() ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if (! selb ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@39: } else if (parser.checkParCount(0)) insilmaril@39: { insilmaril@39: moveBranchDown(); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="move") insilmaril@39: { insilmaril@39: if (xelection.isEmpty() ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if ( xelection.type()!=Selection::Branch && insilmaril@39: xelection.type()!=Selection::MapCenter && insilmaril@39: xelection.type()!=Selection::FloatImage ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch or floatimage"); insilmaril@39: } else if (parser.checkParCount(2)) insilmaril@39: { insilmaril@39: x=parser.parDouble (ok,0); insilmaril@39: if (ok) insilmaril@39: { insilmaril@39: y=parser.parDouble (ok,1); insilmaril@39: if (ok) move (x,y); insilmaril@39: } insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="moveRel") insilmaril@39: { insilmaril@39: if (xelection.isEmpty() ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if ( xelection.type()!=Selection::Branch && insilmaril@39: xelection.type()!=Selection::MapCenter && insilmaril@39: xelection.type()!=Selection::FloatImage ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch or floatimage"); insilmaril@39: } else if (parser.checkParCount(2)) insilmaril@39: { insilmaril@39: x=parser.parDouble (ok,0); insilmaril@39: if (ok) insilmaril@39: { insilmaril@39: y=parser.parDouble (ok,1); insilmaril@39: if (ok) moveRel (x,y); insilmaril@39: } insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="nop") insilmaril@39: { insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="paste") insilmaril@39: { insilmaril@39: if (xelection.isEmpty() ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if (! selb ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@39: } else if (parser.checkParCount(1)) insilmaril@39: { insilmaril@39: n=parser.parInt (ok,0); insilmaril@39: if (ok) pasteNoSave(n); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="qa") insilmaril@39: { insilmaril@39: if (xelection.isEmpty() ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if (! selb ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@39: } else if (parser.checkParCount(4)) insilmaril@39: { insilmaril@39: QString c,u; insilmaril@39: c=parser.parString (ok,0); insilmaril@39: if (!ok) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"No comment given"); insilmaril@39: } else insilmaril@39: { insilmaril@39: s=parser.parString (ok,1); insilmaril@39: if (!ok) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"First parameter is not a string"); insilmaril@39: } else insilmaril@39: { insilmaril@39: t=parser.parString (ok,2); insilmaril@39: if (!ok) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Condition is not a string"); insilmaril@39: } else insilmaril@39: { insilmaril@39: u=parser.parString (ok,3); insilmaril@39: if (!ok) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Third parameter is not a string"); insilmaril@39: } else insilmaril@39: { insilmaril@39: if (s!="heading") insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Unknown type: "+s); insilmaril@39: } else insilmaril@39: { insilmaril@39: if (! (t=="eq") ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Unknown operator: "+t); insilmaril@39: } else insilmaril@39: { insilmaril@39: if (! selb ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@39: } else insilmaril@39: { insilmaril@39: if (selb->getHeading() == u) insilmaril@39: { insilmaril@39: cout << "PASSED: " << qPrintable (c) << endl; insilmaril@39: } else insilmaril@39: { insilmaril@39: cout << "FAILED: " << qPrintable (c) << endl; insilmaril@39: } insilmaril@39: } insilmaril@39: } insilmaril@39: } insilmaril@39: } insilmaril@39: } insilmaril@39: } insilmaril@39: } insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="saveImage") insilmaril@39: { insilmaril@39: FloatImageObj *fio=xelection.getFloatImage(); insilmaril@39: if (!fio) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not an image"); insilmaril@39: } else if (parser.checkParCount(2)) insilmaril@39: { insilmaril@39: s=parser.parString(ok,0); insilmaril@39: if (ok) insilmaril@39: { insilmaril@39: t=parser.parString(ok,1); insilmaril@39: if (ok) saveFloatImageInt (fio,t,s); insilmaril@39: } insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="scroll") insilmaril@39: { insilmaril@39: if (xelection.isEmpty() ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if (! selb ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@39: } else if (parser.checkParCount(0)) insilmaril@39: { insilmaril@39: if (!scrollBranch (selb)) insilmaril@39: parser.setError (Aborted,"Could not scroll branch"); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="select") insilmaril@39: { insilmaril@39: if (parser.checkParCount(1)) insilmaril@39: { insilmaril@39: s=parser.parString(ok,0); insilmaril@39: if (ok) select (s); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="selectLastBranch") insilmaril@39: { insilmaril@39: if (xelection.isEmpty() ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if (! selb ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@39: } else if (parser.checkParCount(0)) insilmaril@39: { insilmaril@39: BranchObj *bo=selb->getLastBranch(); insilmaril@39: if (!bo) insilmaril@39: parser.setError (Aborted,"Could not select last branch"); insilmaril@39: selectInt (bo); insilmaril@39: insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="selectLastImage") insilmaril@39: { insilmaril@39: if (xelection.isEmpty() ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if (! selb ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@39: } else if (parser.checkParCount(0)) insilmaril@39: { insilmaril@39: FloatImageObj *fio=selb->getLastFloatImage(); insilmaril@39: if (!fio) insilmaril@39: parser.setError (Aborted,"Could not select last image"); insilmaril@39: selectInt (fio); insilmaril@39: insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="selectLatestAdded") insilmaril@39: { insilmaril@39: if (latestSelection.isEmpty() ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"No latest added object"); insilmaril@39: } else insilmaril@39: { insilmaril@39: if (!select (latestSelection)) insilmaril@39: parser.setError (Aborted,"Could not select latest added object "+latestSelection); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="setFrameType") insilmaril@39: { insilmaril@39: if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection does not allow setting frame type"); insilmaril@39: } insilmaril@39: else if (parser.checkParCount(1)) insilmaril@39: { insilmaril@39: s=parser.parString(ok,0); insilmaril@39: if (ok) setFrameType (s); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="setFramePenColor") insilmaril@39: { insilmaril@39: if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection does not allow setting of pen color"); insilmaril@39: } insilmaril@39: else if (parser.checkParCount(1)) insilmaril@39: { insilmaril@39: QColor c=parser.parColor(ok,0); insilmaril@39: if (ok) setFramePenColor (c); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="setFrameBrushColor") insilmaril@39: { insilmaril@39: if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection does not allow setting brush color"); insilmaril@39: } insilmaril@39: else if (parser.checkParCount(1)) insilmaril@39: { insilmaril@39: QColor c=parser.parColor(ok,0); insilmaril@39: if (ok) setFrameBrushColor (c); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="setFramePadding") insilmaril@39: { insilmaril@39: if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection does not allow setting frame padding"); insilmaril@39: } insilmaril@39: else if (parser.checkParCount(1)) insilmaril@39: { insilmaril@39: n=parser.parInt(ok,0); insilmaril@39: if (ok) setFramePadding(n); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="setFrameBorderWidth") insilmaril@39: { insilmaril@39: if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection does not allow setting frame border width"); insilmaril@39: } insilmaril@39: else if (parser.checkParCount(1)) insilmaril@39: { insilmaril@39: n=parser.parInt(ok,0); insilmaril@39: if (ok) setFrameBorderWidth (n); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="setMapAuthor") insilmaril@39: { insilmaril@39: if (parser.checkParCount(1)) insilmaril@39: { insilmaril@39: s=parser.parString(ok,0); insilmaril@39: if (ok) setMapAuthor (s); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="setMapComment") insilmaril@39: { insilmaril@39: if (parser.checkParCount(1)) insilmaril@39: { insilmaril@39: s=parser.parString(ok,0); insilmaril@39: if (ok) setMapComment(s); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="setMapBackgroundColor") insilmaril@39: { insilmaril@39: if (xelection.isEmpty() ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if (! xelection.getBranch() ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@39: } else if (parser.checkParCount(1)) insilmaril@39: { insilmaril@39: QColor c=parser.parColor (ok,0); insilmaril@39: if (ok) setMapBackgroundColor (c); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="setMapDefLinkColor") insilmaril@39: { insilmaril@39: if (xelection.isEmpty() ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if (! selb ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@39: } else if (parser.checkParCount(1)) insilmaril@39: { insilmaril@39: QColor c=parser.parColor (ok,0); insilmaril@39: if (ok) setMapDefLinkColor (c); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="setMapLinkStyle") insilmaril@39: { insilmaril@39: if (parser.checkParCount(1)) insilmaril@39: { insilmaril@39: s=parser.parString (ok,0); insilmaril@39: if (ok) setMapLinkStyle(s); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="setHeading") insilmaril@39: { insilmaril@39: if (xelection.isEmpty() ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if (! selb ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@39: } else if (parser.checkParCount(1)) insilmaril@39: { insilmaril@39: s=parser.parString (ok,0); insilmaril@39: if (ok) insilmaril@39: setHeading (s); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="setHideExport") insilmaril@39: { insilmaril@39: if (xelection.isEmpty() ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if (xelection.type()!=Selection::Branch && xelection.type() != Selection::MapCenter &&xelection.type()!=Selection::FloatImage) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch or floatimage"); insilmaril@39: } else if (parser.checkParCount(1)) insilmaril@39: { insilmaril@39: b=parser.parBool(ok,0); insilmaril@39: if (ok) setHideExport (b); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="setIncludeImagesHorizontally") insilmaril@39: { insilmaril@39: if (xelection.isEmpty() ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if (! selb) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@39: } else if (parser.checkParCount(1)) insilmaril@39: { insilmaril@39: b=parser.parBool(ok,0); insilmaril@39: if (ok) setIncludeImagesHor(b); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="setIncludeImagesVertically") insilmaril@39: { insilmaril@39: if (xelection.isEmpty() ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if (! selb) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@39: } else if (parser.checkParCount(1)) insilmaril@39: { insilmaril@39: b=parser.parBool(ok,0); insilmaril@39: if (ok) setIncludeImagesVer(b); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="setHideLinkUnselected") insilmaril@39: { insilmaril@39: if (xelection.isEmpty() ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection does not allow hiding the link"); insilmaril@39: } else if (parser.checkParCount(1)) insilmaril@39: { insilmaril@39: b=parser.parBool(ok,0); insilmaril@39: if (ok) setHideLinkUnselected(b); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="setSelectionColor") insilmaril@39: { insilmaril@39: if (parser.checkParCount(1)) insilmaril@39: { insilmaril@39: QColor c=parser.parColor (ok,0); insilmaril@39: if (ok) setSelectionColorInt (c); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="setURL") insilmaril@39: { insilmaril@39: if (xelection.isEmpty() ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if (! selb ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@39: } else if (parser.checkParCount(1)) insilmaril@39: { insilmaril@39: s=parser.parString (ok,0); insilmaril@39: if (ok) setURL(s); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="setVymLink") insilmaril@39: { insilmaril@39: if (xelection.isEmpty() ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if (! selb ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@39: } else if (parser.checkParCount(1)) insilmaril@39: { insilmaril@39: s=parser.parString (ok,0); insilmaril@39: if (ok) setVymLinkInt(s); insilmaril@39: } insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: else if (com=="setFlag") insilmaril@39: { insilmaril@39: if (xelection.isEmpty() ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if (! selb ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@39: } else if (parser.checkParCount(1)) insilmaril@39: { insilmaril@39: s=parser.parString(ok,0); insilmaril@39: if (ok) insilmaril@39: { insilmaril@39: selb->activateStandardFlag(s); insilmaril@39: selb->updateFlagsToolbar(); insilmaril@39: } insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="setFrameType") insilmaril@39: { insilmaril@39: if (xelection.isEmpty() ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if (! selb ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@39: } else if (parser.checkParCount(1)) insilmaril@39: { insilmaril@39: s=parser.parString(ok,0); insilmaril@39: if (ok) insilmaril@39: setFrameType (s); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="sortChildren") insilmaril@39: { insilmaril@39: if (xelection.isEmpty() ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if (! selb ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@39: } else if (parser.checkParCount(0)) insilmaril@39: { insilmaril@39: sortChildren(); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="toggleFlag") insilmaril@39: { insilmaril@39: if (xelection.isEmpty() ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if (! selb ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@39: } else if (parser.checkParCount(1)) insilmaril@39: { insilmaril@39: s=parser.parString(ok,0); insilmaril@39: if (ok) insilmaril@39: { insilmaril@39: selb->toggleStandardFlag(s); insilmaril@39: selb->updateFlagsToolbar(); insilmaril@39: } insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="unscroll") insilmaril@39: { insilmaril@39: if (xelection.isEmpty() ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if (! selb ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@39: } else if (parser.checkParCount(0)) insilmaril@39: { insilmaril@39: if (!unscrollBranch (selb)) insilmaril@39: parser.setError (Aborted,"Could not unscroll branch"); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="unscrollChilds") insilmaril@39: { insilmaril@39: if (xelection.isEmpty() ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if (! selb ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@39: } else if (parser.checkParCount(0)) insilmaril@39: { insilmaril@39: unscrollChilds (); insilmaril@39: } insilmaril@39: ///////////////////////////////////////////////////////////////////// insilmaril@39: } else if (com=="unsetFlag") insilmaril@39: { insilmaril@39: if (xelection.isEmpty() ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Nothing selected"); insilmaril@39: } else if (! selb ) insilmaril@39: { insilmaril@39: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@39: } else if (parser.checkParCount(1)) insilmaril@39: { insilmaril@39: s=parser.parString(ok,0); insilmaril@39: if (ok) insilmaril@39: { insilmaril@39: selb->deactivateStandardFlag(s); insilmaril@39: selb->updateFlagsToolbar(); insilmaril@39: } insilmaril@39: } insilmaril@39: } else insilmaril@39: parser.setError (Aborted,"Unknown command"); insilmaril@39: insilmaril@39: // Any errors? insilmaril@39: if (parser.errorLevel()==NoError) insilmaril@39: { insilmaril@39: // setChanged(); FIXME should not be called e.g. for export?! insilmaril@39: model->reposition(); insilmaril@39: } insilmaril@39: else insilmaril@39: { insilmaril@39: // TODO Error handling insilmaril@39: qWarning("MapEditor::parseAtom: Error!"); insilmaril@39: qWarning(parser.errorMessage()); insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::runScript (QString script) insilmaril@39: { insilmaril@39: parser.setScript (script); insilmaril@39: parser.runScript(); insilmaril@39: while (parser.next() ) insilmaril@39: parseAtom(parser.getAtom()); insilmaril@39: } insilmaril@0: insilmaril@0: bool MapEditor::isDefault() insilmaril@0: { insilmaril@0: return mapDefault; insilmaril@0: } insilmaril@0: insilmaril@0: bool MapEditor::hasChanged() insilmaril@0: { insilmaril@0: return mapChanged; insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::setChanged() insilmaril@0: { insilmaril@39: if (!mapChanged) insilmaril@60: { insilmaril@66: autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt()); insilmaril@60: fileChangedTimer->start (3000); insilmaril@60: } insilmaril@0: mapChanged=true; insilmaril@0: mapDefault=false; insilmaril@0: mapUnsaved=true; insilmaril@0: findReset(); insilmaril@39: insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::closeMap() insilmaril@0: { insilmaril@0: // Unselect before disabling the toolbar actions insilmaril@39: if (!xelection.isEmpty() ) xelection.unselect(); insilmaril@39: xelection.clear(); insilmaril@0: updateActions(); insilmaril@0: insilmaril@0: clear(); insilmaril@39: // close(); FIXME needed? insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::setFilePath(QString fpath, QString destname) insilmaril@39: { insilmaril@39: if (fpath.isEmpty() || fpath=="") insilmaril@39: { insilmaril@39: filePath=""; insilmaril@39: fileName=""; insilmaril@39: destPath=""; insilmaril@39: } else insilmaril@39: { insilmaril@39: filePath=fpath; // becomes absolute path insilmaril@39: fileName=fpath; // gets stripped of path insilmaril@39: destPath=destname; // needed for vymlinks and during load to reset fileChangedTime insilmaril@39: insilmaril@39: // If fpath is not an absolute path, complete it insilmaril@39: filePath=QDir(fpath).absPath(); insilmaril@39: fileDir=filePath.left (1+filePath.findRev ("/")); insilmaril@39: insilmaril@39: // Set short name, too. Search from behind: insilmaril@39: int i=fileName.findRev("/"); insilmaril@39: if (i>=0) fileName=fileName.remove (0,i+1); insilmaril@39: insilmaril@39: // Forget the .vym (or .xml) for name of map insilmaril@39: mapName=fileName.left(fileName.findRev(".",-1,true) ); insilmaril@39: } insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::setFilePath(QString fpath) insilmaril@39: { insilmaril@39: setFilePath (fpath,fpath); insilmaril@0: } insilmaril@0: insilmaril@0: QString MapEditor::getFilePath() insilmaril@0: { insilmaril@0: return filePath; insilmaril@0: } insilmaril@0: insilmaril@0: QString MapEditor::getFileName() insilmaril@0: { insilmaril@0: return fileName; insilmaril@0: } insilmaril@0: insilmaril@0: QString MapEditor::getMapName() insilmaril@0: { insilmaril@0: return mapName; insilmaril@0: } insilmaril@0: insilmaril@0: QString MapEditor::getDestPath() insilmaril@0: { insilmaril@0: return destPath; insilmaril@0: } insilmaril@0: insilmaril@39: ErrorCode MapEditor::load (QString fname, const LoadMode &lmode, const FileType &ftype) insilmaril@39: { insilmaril@39: ErrorCode err=success; insilmaril@39: insilmaril@39: parseBaseHandler *handler; insilmaril@39: fileType=ftype; insilmaril@39: switch (fileType) insilmaril@39: { insilmaril@39: case VymMap: handler=new parseVYMHandler; break; insilmaril@39: case FreemindMap : handler=new parseFreemindHandler; break; insilmaril@39: default: insilmaril@39: QMessageBox::critical( 0, tr( "Critical Parse Error" ), insilmaril@39: "Unknown FileType in MapEditor::load()"); insilmaril@39: return aborted; insilmaril@39: } insilmaril@54: insilmaril@54: // Save original zip state, important for inserting complete maps insilmaril@54: bool zipped_org=zipped; insilmaril@54: insilmaril@0: if (lmode==NewMap) insilmaril@0: { insilmaril@39: xelection.clear(); insilmaril@39: model->setMapEditor(this); insilmaril@0: // (map state is set later at end of load...) insilmaril@0: } else insilmaril@0: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (!bo) return aborted; insilmaril@39: if (lmode==ImportAdd) insilmaril@39: saveStateChangingPart( insilmaril@39: bo, insilmaril@39: bo, insilmaril@39: QString("addMapInsert (%1)").arg(fname), insilmaril@39: QString("Add map %1 to %2").arg(fname).arg(getName(bo))); insilmaril@39: else insilmaril@39: saveStateChangingPart( insilmaril@39: bo, insilmaril@39: bo, insilmaril@39: QString("addMapReplace(%1)").arg(fname), insilmaril@39: QString("Add map %1 to %2").arg(fname).arg(getName(bo))); insilmaril@0: } insilmaril@0: insilmaril@39: insilmaril@39: // Create temporary directory for packing insilmaril@39: bool ok; insilmaril@39: QString tmpZipDir=makeTmpDir (ok,"vym-pack"); insilmaril@39: if (!ok) insilmaril@39: { insilmaril@39: QMessageBox::critical( 0, tr( "Critical Load Error" ), insilmaril@39: tr("Couldn't create temporary directory before load\n")); insilmaril@39: return aborted; insilmaril@39: } insilmaril@39: insilmaril@39: // Try to unzip file insilmaril@39: err=unzipDir (tmpZipDir,fname); insilmaril@39: QString xmlfile; insilmaril@39: if (err==nozip) insilmaril@39: { insilmaril@39: xmlfile=fname; insilmaril@39: zipped=false; insilmaril@39: } else insilmaril@39: { insilmaril@39: zipped=true; insilmaril@39: insilmaril@39: // Look for mapname.xml insilmaril@39: xmlfile= fname.left(fname.findRev(".",-1,true)); insilmaril@39: xmlfile=xmlfile.section( '/', -1 ); insilmaril@39: QFile mfile( tmpZipDir + "/" + xmlfile + ".xml"); insilmaril@39: if (!mfile.exists() ) insilmaril@39: { insilmaril@39: // mapname.xml does not exist, well, insilmaril@39: // maybe someone renamed the mapname.vym file... insilmaril@39: // Try to find any .xml in the toplevel insilmaril@39: // directory of the .vym file insilmaril@39: QStringList flist=QDir (tmpZipDir).entryList("*.xml"); insilmaril@39: if (flist.count()==1) insilmaril@39: { insilmaril@39: // Only one entry, take this one insilmaril@39: xmlfile=tmpZipDir + "/"+flist.first(); insilmaril@39: } else insilmaril@39: { insilmaril@39: for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) insilmaril@39: *it=tmpZipDir + "/" + *it; insilmaril@39: // TODO Multiple entries, load all (but only the first one into this ME) insilmaril@39: //mainWindow->fileLoadFromTmp (flist); insilmaril@39: //returnCode=1; // Silently forget this attempt to load insilmaril@39: qWarning ("MainWindow::load (fn) multimap found..."); insilmaril@39: } insilmaril@39: insilmaril@39: if (flist.isEmpty() ) insilmaril@39: { insilmaril@39: QMessageBox::critical( 0, tr( "Critical Load Error" ), insilmaril@39: tr("Couldn't find a map (*.xml) in .vym archive.\n")); insilmaril@39: err=aborted; insilmaril@39: } insilmaril@39: } //file doesn't exist insilmaril@39: else insilmaril@39: xmlfile=mfile.name(); insilmaril@39: } insilmaril@39: insilmaril@39: QFile file( xmlfile); insilmaril@0: insilmaril@0: // I am paranoid: file should exist anyway insilmaril@0: // according to check in mainwindow. insilmaril@0: if (!file.exists() ) insilmaril@0: { insilmaril@0: QMessageBox::critical( 0, tr( "Critical Parse Error" ), insilmaril@39: tr(QString("Couldn't open map %1").arg(file.name()))); insilmaril@39: err=aborted; insilmaril@0: } else insilmaril@0: { insilmaril@39: bool blockSaveStateOrg=blockSaveState; insilmaril@39: blockReposition=true; insilmaril@39: blockSaveState=true; insilmaril@0: QXmlInputSource source( file); insilmaril@0: QXmlSimpleReader reader; insilmaril@39: reader.setContentHandler( handler ); insilmaril@39: reader.setErrorHandler( handler ); insilmaril@39: handler->setModel ( model); insilmaril@39: insilmaril@39: insilmaril@39: // We need to set the tmpDir in order to load files with rel. path insilmaril@39: QString tmpdir; insilmaril@39: if (zipped) insilmaril@39: tmpdir=tmpZipDir; insilmaril@39: else insilmaril@39: tmpdir=fname.left(fname.findRev("/",-1)); insilmaril@39: handler->setTmpDir (tmpdir); insilmaril@39: handler->setInputFile (file.name()); insilmaril@39: handler->setLoadMode (lmode); insilmaril@0: bool ok = reader.parse( source ); insilmaril@39: blockReposition=false; insilmaril@39: blockSaveState=blockSaveStateOrg; insilmaril@0: file.close(); insilmaril@0: if ( ok ) insilmaril@0: { insilmaril@39: model->reposition(); // FIXME reposition the view instead... insilmaril@39: xelection.update(); insilmaril@0: if (lmode==NewMap) insilmaril@0: { insilmaril@0: mapDefault=false; insilmaril@0: mapChanged=false; insilmaril@0: mapUnsaved=false; insilmaril@39: autosaveTimer->stop(); insilmaril@0: } insilmaril@39: insilmaril@39: // Reset timestamp to check for later updates of file insilmaril@39: fileChangedTime=QFileInfo (destPath).lastModified(); insilmaril@0: } else insilmaril@0: { insilmaril@0: QMessageBox::critical( 0, tr( "Critical Parse Error" ), insilmaril@39: tr( handler->errorProtocol() ) ); insilmaril@0: // returnCode=1; insilmaril@0: // Still return "success": the map maybe at least insilmaril@0: // partially read by the parser insilmaril@0: } insilmaril@0: } insilmaril@39: insilmaril@39: // Delete tmpZipDir insilmaril@39: removeDir (QDir(tmpZipDir)); insilmaril@39: insilmaril@54: // Restore original zip state insilmaril@54: zipped=zipped_org; insilmaril@54: insilmaril@0: updateActions(); insilmaril@39: insilmaril@39: return err; insilmaril@0: } insilmaril@0: insilmaril@39: ErrorCode MapEditor::save (const SaveMode &savemode) insilmaril@39: { insilmaril@39: QString tmpZipDir; insilmaril@39: QString mapFileName; insilmaril@39: QString safeFilePath; insilmaril@39: insilmaril@39: ErrorCode err=success; insilmaril@39: insilmaril@39: if (zipped) insilmaril@39: // save as .xml insilmaril@39: mapFileName=mapName+".xml"; insilmaril@39: else insilmaril@39: // use name given by user, even if he chooses .doc insilmaril@39: mapFileName=fileName; insilmaril@39: insilmaril@39: // Look, if we should zip the data: insilmaril@39: if (!zipped) insilmaril@39: { insilmaril@39: QMessageBox mb( vymName, insilmaril@39: tr("The map %1\ndid not use the compressed " insilmaril@39: "vym file format.\nWriting it uncompressed will also write images \n" insilmaril@39: "and flags and thus may overwrite files in the " insilmaril@39: "given directory\n\nDo you want to write the map").arg(filePath), insilmaril@39: QMessageBox::Warning, insilmaril@39: QMessageBox::Yes | QMessageBox::Default, insilmaril@39: QMessageBox::No , insilmaril@39: QMessageBox::Cancel | QMessageBox::Escape); insilmaril@39: mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") ); insilmaril@39: mb.setButtonText( QMessageBox::No, tr("uncompressed") ); insilmaril@39: mb.setButtonText( QMessageBox::Cancel, tr("Cancel")); insilmaril@39: switch( mb.exec() ) insilmaril@39: { insilmaril@39: case QMessageBox::Yes: insilmaril@39: // save compressed (default file format) insilmaril@39: zipped=true; insilmaril@39: break; insilmaril@39: case QMessageBox::No: insilmaril@39: // save uncompressed insilmaril@39: zipped=false; insilmaril@39: break; insilmaril@39: case QMessageBox::Cancel: insilmaril@39: // do nothing insilmaril@39: return aborted; insilmaril@39: break; insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: // First backup existing file, we insilmaril@39: // don't want to add to old zip archives insilmaril@39: QFile f(destPath); insilmaril@39: if (f.exists()) insilmaril@39: { insilmaril@39: if ( settings.value ("/mapeditor/writeBackupFile").toBool()) insilmaril@39: { insilmaril@39: QString backupFileName(destPath + "~"); insilmaril@39: QFile backupFile(backupFileName); insilmaril@39: if (backupFile.exists() && !backupFile.remove()) insilmaril@39: { insilmaril@39: QMessageBox::warning(0, tr("Save Error"), insilmaril@39: tr("%1\ncould not be removed before saving").arg(backupFileName)); insilmaril@39: } insilmaril@39: else if (!f.rename(backupFileName)) insilmaril@39: { insilmaril@39: QMessageBox::warning(0, tr("Save Error"), insilmaril@39: tr("%1\ncould not be renamed before saving").arg(destPath)); insilmaril@39: } insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: if (zipped) insilmaril@39: { insilmaril@39: // Create temporary directory for packing insilmaril@39: bool ok; insilmaril@39: tmpZipDir=makeTmpDir (ok,"vym-zip"); insilmaril@39: if (!ok) insilmaril@39: { insilmaril@39: QMessageBox::critical( 0, tr( "Critical Load Error" ), insilmaril@39: tr("Couldn't create temporary directory before save\n")); insilmaril@39: return aborted; insilmaril@39: } insilmaril@39: insilmaril@55: // cout <<"ME::save filePath="<stop(); insilmaril@0: } insilmaril@39: else insilmaril@39: { insilmaril@39: // Save part of map insilmaril@39: if (xelection.type()==Selection::FloatImage) insilmaril@39: saveFloatImage(); insilmaril@39: else insilmaril@39: saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),xelection.getBranch()); insilmaril@39: // TODO take care of multiselections insilmaril@39: } insilmaril@39: insilmaril@58: // FIXME trying to debug save problem insilmaril@58: if (saveFile.length()<1000) insilmaril@59: QMessageBox::critical (0,"Critical error in MapEditor::save",QString("saveFile is too small, try make a backup NOW\nof your original file\nbefore vym writes to\"%1\":\n%2").arg(mapName).arg(saveFile)); insilmaril@39: if (!saveStringToDisk(fileDir+mapFileName,saveFile)) insilmaril@39: { insilmaril@39: err=aborted; insilmaril@62: QMessageBox::critical (0,"Critical error in MapEditor::save",QString("could not save %1").arg(fileDir+mapFileName)); insilmaril@39: } insilmaril@39: insilmaril@39: if (zipped) insilmaril@39: { insilmaril@39: // zip insilmaril@39: if (err==success) err=zipDir (tmpZipDir,destPath); insilmaril@39: insilmaril@39: // Delete tmpDir insilmaril@39: removeDir (QDir(tmpZipDir)); insilmaril@39: insilmaril@39: // Restore original filepath outside of tmp zip dir insilmaril@39: setFilePath (safeFilePath); insilmaril@39: } insilmaril@39: insilmaril@39: updateActions(); insilmaril@39: fileChangedTime=QFileInfo (destPath).lastModified(); insilmaril@39: return err; insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@0: void MapEditor::print() insilmaril@0: { insilmaril@0: if ( !printer ) insilmaril@0: { insilmaril@0: printer = new QPrinter; insilmaril@0: printer->setColorMode (QPrinter::Color); insilmaril@39: printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString()); insilmaril@39: printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt()); insilmaril@39: printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString()); insilmaril@0: } insilmaril@0: insilmaril@39: QRectF totalBBox=model->getTotalBBox(); insilmaril@0: insilmaril@0: // Try to set orientation automagically insilmaril@0: // Note: Interpretation of generated postscript is amibiguous, if insilmaril@0: // there are problems with landscape mode, see insilmaril@0: // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html insilmaril@0: insilmaril@0: if (totalBBox.width()>totalBBox.height()) insilmaril@0: // recommend landscape insilmaril@0: printer->setOrientation (QPrinter::Landscape); insilmaril@0: else insilmaril@0: // recommend portrait insilmaril@0: printer->setOrientation (QPrinter::Portrait); insilmaril@0: insilmaril@0: if ( printer->setup(this) ) insilmaril@0: // returns false, if printing is canceled insilmaril@0: { insilmaril@0: QPainter pp(printer); insilmaril@0: insilmaril@39: pp.setRenderHint(QPainter::Antialiasing,true); insilmaril@39: insilmaril@0: // Don't print the visualisation of selection insilmaril@39: xelection.unselect(); insilmaril@39: insilmaril@39: QRectF mapRect=totalBBox; insilmaril@39: QGraphicsRectItem *frame=NULL; insilmaril@39: insilmaril@39: if (printFrame) insilmaril@0: { insilmaril@39: // Print frame around map insilmaril@39: mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10, insilmaril@39: totalBBox.width()+20, totalBBox.height()+20); insilmaril@39: frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush)); insilmaril@39: frame->setZValue(0); insilmaril@39: frame->show(); insilmaril@39: } insilmaril@39: insilmaril@39: insilmaril@39: double paperAspect = (double)printer->width() / (double)printer->height(); insilmaril@39: double mapAspect = (double)mapRect.width() / (double)mapRect.height(); insilmaril@39: int viewBottom; insilmaril@0: if (mapAspect>=paperAspect) insilmaril@0: { insilmaril@0: // Fit horizontally to paper width insilmaril@39: //pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) ); insilmaril@39: viewBottom=(int)(printer->width()/mapAspect); insilmaril@0: } else insilmaril@0: { insilmaril@0: // Fit vertically to paper height insilmaril@39: //pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height()); insilmaril@39: viewBottom=printer->height(); insilmaril@0: } insilmaril@39: insilmaril@39: if (printFooter) insilmaril@0: { insilmaril@39: // Print footer below map insilmaril@39: QFont font; insilmaril@39: font.setPointSize(10); insilmaril@39: pp.setFont (font); insilmaril@39: QRectF footerBox(0,viewBottom,printer->width(),15); insilmaril@39: pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName); insilmaril@39: pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate)); insilmaril@39: } insilmaril@39: mapScene->render ( insilmaril@39: &pp, insilmaril@39: QRectF (0,0,printer->width(),printer->height()-15), insilmaril@39: QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height()) insilmaril@39: ); insilmaril@39: insilmaril@39: // Viewport has paper dimension insilmaril@0: if (frame) delete (frame); insilmaril@0: insilmaril@0: // Restore selection insilmaril@39: xelection.reselect(); insilmaril@39: insilmaril@39: // Save settings in vymrc insilmaril@39: settings.writeEntry("/mainwindow/printerName",printer->printerName()); insilmaril@39: settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat()); insilmaril@39: settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName()); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::setAntiAlias (bool b) insilmaril@39: { insilmaril@39: setRenderHint(QPainter::Antialiasing,b); insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::setSmoothPixmap(bool b) insilmaril@39: { insilmaril@39: setRenderHint(QPainter::SmoothPixmapTransform,b); insilmaril@39: } insilmaril@39: insilmaril@0: QPixmap MapEditor::getPixmap() insilmaril@0: { insilmaril@39: QRectF mapRect=model->getTotalBBox(); insilmaril@39: QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1); insilmaril@0: QPainter pp (&pix); insilmaril@39: insilmaril@39: pp.setRenderHints(renderHints()); insilmaril@0: insilmaril@0: // Don't print the visualisation of selection insilmaril@39: xelection.unselect(); insilmaril@39: insilmaril@39: mapScene->render ( &pp, insilmaril@39: QRectF(0,0,mapRect.width()+1,mapRect.height()+1), insilmaril@39: QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() )); insilmaril@0: insilmaril@0: // Restore selection insilmaril@39: xelection.reselect(); insilmaril@0: insilmaril@0: return pix; insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::setHideTmpMode (HideTmpMode mode) insilmaril@39: { insilmaril@39: hidemode=mode; insilmaril@39: model->setHideTmp (hidemode); insilmaril@39: model->reposition(); insilmaril@39: scene()->update(); insilmaril@0: } insilmaril@0: insilmaril@39: HideTmpMode MapEditor::getHideTmpMode() insilmaril@39: { insilmaril@39: return hidemode; insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::setExportMode (bool b) insilmaril@39: { insilmaril@39: // should be called before and after exports insilmaril@39: // depending on the settings insilmaril@39: if (b && settings.value("/export/useHideExport","true")=="true") insilmaril@39: setHideTmpMode (HideExport); insilmaril@39: else insilmaril@39: setHideTmpMode (HideNone); insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::exportASCII(QString fname,bool askName) insilmaril@39: { insilmaril@39: ExportASCII ex; insilmaril@39: ex.setModel (model); insilmaril@39: if (fname=="") insilmaril@39: ex.setFile (mapName+".txt"); insilmaril@39: else insilmaril@39: ex.setFile (fname); insilmaril@39: insilmaril@39: if (askName) insilmaril@39: { insilmaril@39: //ex.addFilter ("TXT (*.txt)"); insilmaril@39: ex.setDir(lastImageDir); insilmaril@39: //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)")); insilmaril@39: ex.execDialog() ; insilmaril@39: } insilmaril@39: if (!ex.canceled()) insilmaril@39: { insilmaril@39: setExportMode(true); insilmaril@39: ex.doExport(); insilmaril@39: setExportMode(false); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::exportImage(QString fname, bool askName, QString format) insilmaril@39: { insilmaril@39: if (fname=="") insilmaril@39: { insilmaril@39: fname=mapName+".png"; insilmaril@39: format="PNG"; insilmaril@39: } insilmaril@39: insilmaril@39: if (askName) insilmaril@39: { insilmaril@39: QStringList fl; insilmaril@39: QFileDialog *fd=new QFileDialog (this); insilmaril@39: fd->setCaption (tr("Export map as image")); insilmaril@39: fd->setDirectory (lastImageDir); insilmaril@39: fd->setFileMode(QFileDialog::AnyFile); insilmaril@39: fd->setFilters (imageIO.getFilters() ); insilmaril@39: if (fd->exec()) insilmaril@39: { insilmaril@39: fl=fd->selectedFiles(); insilmaril@39: fname=fl.first(); insilmaril@39: format=imageIO.getType(fd->selectedFilter()); insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: setExportMode (true); insilmaril@39: QPixmap pix (getPixmap()); insilmaril@39: pix.save(fname, format); insilmaril@39: setExportMode (false); insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::exportOOPresentation(const QString &fn, const QString &cf) insilmaril@39: { insilmaril@39: ExportOO ex; insilmaril@39: ex.setFile (fn); insilmaril@39: ex.setModel (model); insilmaril@39: if (ex.setConfigFile(cf)) insilmaril@39: { insilmaril@39: setExportMode (true); insilmaril@39: ex.exportPresentation(); insilmaril@39: setExportMode (false); insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::exportXHTML (const QString &dir, bool askForName) insilmaril@39: { insilmaril@39: ExportXHTMLDialog dia(this); insilmaril@39: dia.setFilePath (filePath ); insilmaril@39: dia.setMapName (mapName ); insilmaril@39: dia.readSettings(); insilmaril@39: if (dir!="") dia.setDir (dir); insilmaril@39: insilmaril@39: bool ok=true; insilmaril@39: insilmaril@39: if (askForName) insilmaril@39: { insilmaril@39: if (dia.exec()!=QDialog::Accepted) insilmaril@39: ok=false; insilmaril@39: else insilmaril@39: { insilmaril@39: QDir d (dia.getDir()); insilmaril@39: // Check, if warnings should be used before overwriting insilmaril@39: // the output directory insilmaril@39: if (d.exists() && d.count()>0) insilmaril@39: { insilmaril@39: WarningDialog warn; insilmaril@39: warn.showCancelButton (true); insilmaril@39: warn.setText(QString( insilmaril@39: "The directory %1 is not empty.\n" insilmaril@39: "Do you risk to overwrite some of its contents?").arg(d.path() )); insilmaril@39: warn.setCaption("Warning: Directory not empty"); insilmaril@39: warn.setShowAgainName("mainwindow/overwrite-dir-xhtml"); insilmaril@39: insilmaril@39: if (warn.exec()!=QDialog::Accepted) ok=false; insilmaril@39: } insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: if (ok) insilmaril@39: { insilmaril@39: exportXML (dia.getDir(),false ); insilmaril@39: dia.doExport(mapName ); insilmaril@39: //if (dia.hasChanged()) setChanged(); insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::exportXML(QString dir, bool askForName) insilmaril@39: { insilmaril@39: if (askForName) insilmaril@39: { insilmaril@39: dir=browseDirectory(this,tr("Export XML to directory")); insilmaril@39: if (dir =="" && !reallyWriteDirectory(dir) ) insilmaril@39: return; insilmaril@39: } insilmaril@39: insilmaril@39: // Hide stuff during export, if settings want this insilmaril@39: setExportMode (true); insilmaril@39: insilmaril@0: // Create subdirectories insilmaril@0: makeSubDirs (dir); insilmaril@0: insilmaril@0: // write to directory insilmaril@39: QString saveFile=saveToDir (dir,mapName+"-",true,model->getTotalBBox().topLeft() ,NULL); insilmaril@0: QFile file; insilmaril@0: insilmaril@0: file.setName ( dir + "/"+mapName+".xml"); insilmaril@39: if ( !file.open( QIODevice::WriteOnly ) ) insilmaril@0: { insilmaril@0: // This should neverever happen insilmaril@39: QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name())); insilmaril@0: return; insilmaril@0: } insilmaril@0: insilmaril@0: // Write it finally, and write in UTF8, no matter what insilmaril@0: QTextStream ts( &file ); insilmaril@0: ts.setEncoding (QTextStream::UnicodeUTF8); insilmaril@0: ts << saveFile; insilmaril@0: file.close(); insilmaril@0: insilmaril@0: // Now write image, too insilmaril@39: exportImage (dir+"/images/"+mapName+".png",false,"PNG"); insilmaril@39: insilmaril@39: setExportMode (false); insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::clear() insilmaril@0: { insilmaril@59: //cout << "ME::clear() "<stop(); insilmaril@60: fileChangedTimer->stop(); insilmaril@39: model->clear(); insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::copy() insilmaril@39: { insilmaril@39: LinkableMapObj *sel=xelection.single(); insilmaril@39: if (sel) insilmaril@39: { insilmaril@39: if (redosAvail == 0) insilmaril@39: { insilmaril@39: // Copy to history insilmaril@39: QString s=model->getSelectString(sel); insilmaril@39: saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",sel ); insilmaril@39: curClipboard=curStep; insilmaril@39: } insilmaril@39: insilmaril@39: // Copy also to global clipboard, because we are at last step in history insilmaril@39: QString bakMapName(QString("history-%1").arg(curStep)); insilmaril@39: QString bakMapDir(tmpMapDir +"/"+bakMapName); insilmaril@39: copyDir (bakMapDir,clipboardDir ); insilmaril@39: insilmaril@39: clipboardEmpty=false; insilmaril@39: updateActions(); insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::redo() insilmaril@39: { insilmaril@39: // Can we undo at all? insilmaril@39: if (redosAvail<1) return; insilmaril@39: insilmaril@39: bool blockSaveStateOrg=blockSaveState; insilmaril@39: blockSaveState=true; insilmaril@39: insilmaril@39: redosAvail--; insilmaril@39: insilmaril@39: if (undosAvailstepsTotal) curStep=1; insilmaril@39: QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep)); insilmaril@39: QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep)); insilmaril@39: QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep)); insilmaril@39: QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep)); insilmaril@39: QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep)); insilmaril@39: QString version=undoSet.readEntry ("/history/version"); insilmaril@39: insilmaril@39: /* TODO Maybe check for version, if we save the history insilmaril@39: if (!checkVersion(version)) insilmaril@39: QMessageBox::warning(0,tr("Warning"), insilmaril@39: tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion)); insilmaril@39: */ insilmaril@39: insilmaril@39: // Find out current undo directory insilmaril@39: QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep)); insilmaril@39: insilmaril@39: if (debug) insilmaril@39: { insilmaril@39: cout << "ME::redo() begin\n"; insilmaril@39: cout << " undosAvail="<reposition(); insilmaril@39: insilmaril@39: blockSaveState=blockSaveStateOrg; insilmaril@39: insilmaril@39: undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail)); insilmaril@39: undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail)); insilmaril@39: undoSet.setEntry ("/history/curStep",QString::number(curStep)); insilmaril@39: undoSet.writeSettings(histPath); insilmaril@39: insilmaril@39: mainWindow->updateHistory (undoSet); insilmaril@39: updateActions(); insilmaril@39: insilmaril@39: /* TODO remove testing insilmaril@39: cout << "ME::redo() end\n"; insilmaril@39: cout << " undosAvail="<0) insilmaril@39: return true; insilmaril@39: else insilmaril@39: return false; insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::undo() insilmaril@39: { insilmaril@39: // Can we undo at all? insilmaril@39: if (undosAvail<1) return; insilmaril@39: insilmaril@39: mainWindow->statusMessage (tr("Autosave disabled during undo.")); insilmaril@39: insilmaril@39: bool blockSaveStateOrg=blockSaveState; insilmaril@39: blockSaveState=true; insilmaril@39: insilmaril@39: QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep)); insilmaril@39: QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep)); insilmaril@39: QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep)); insilmaril@39: QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep)); insilmaril@39: QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep)); insilmaril@39: QString version=undoSet.readEntry ("/history/version"); insilmaril@39: insilmaril@39: /* TODO Maybe check for version, if we save the history insilmaril@39: if (!checkVersion(version)) insilmaril@39: QMessageBox::warning(0,tr("Warning"), insilmaril@39: tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion)); insilmaril@39: */ insilmaril@39: insilmaril@39: // Find out current undo directory insilmaril@39: QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep)); insilmaril@39: insilmaril@39: // select object before undo insilmaril@74: select (undoSelection); insilmaril@39: insilmaril@39: if (debug) insilmaril@39: { insilmaril@39: cout << "ME::undo() begin\n"; insilmaril@39: cout << " undosAvail="<reposition(); insilmaril@39: insilmaril@39: undosAvail--; insilmaril@39: curStep--; insilmaril@39: if (curStep<1) curStep=stepsTotal; insilmaril@39: insilmaril@39: redosAvail++; insilmaril@39: insilmaril@39: blockSaveState=blockSaveStateOrg; insilmaril@39: /* TODO remove testing insilmaril@39: cout << "ME::undo() end\n"; insilmaril@39: cout << " undosAvail="<updateHistory (undoSet); insilmaril@39: updateActions(); insilmaril@39: xelection.update(); insilmaril@39: ensureSelectionVisible(); insilmaril@0: } insilmaril@0: insilmaril@39: bool MapEditor::isUndoAvailable() insilmaril@39: { insilmaril@39: if (undoSet.readNumEntry("/history/undosAvail",0)>0) insilmaril@39: return true; insilmaril@39: else insilmaril@39: return false; insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::gotoHistoryStep (int i) insilmaril@39: { insilmaril@39: // Restore variables insilmaril@39: int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail")); insilmaril@39: int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail")); insilmaril@39: insilmaril@39: if (i<0) i=undosAvail+redosAvail; insilmaril@39: insilmaril@39: // Clicking above current step makes us undo things insilmaril@39: if (iundosAvail) insilmaril@39: for (int j=undosAvail; jclear(); insilmaril@39: handler.setLoadMode (NewMap); insilmaril@0: } else insilmaril@0: { insilmaril@39: select (undoSel); insilmaril@39: handler.setLoadMode (ImportReplace); insilmaril@0: } insilmaril@39: blockReposition=true; insilmaril@0: bool ok = reader.parse( source ); insilmaril@39: blockReposition=false; insilmaril@39: if (! ok ) insilmaril@0: { insilmaril@0: // This should never ever happen insilmaril@39: QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path), insilmaril@39: handler.errorProtocol()); insilmaril@0: } insilmaril@0: } else insilmaril@39: QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path)); insilmaril@0: } insilmaril@0: insilmaril@74: bool MapEditor::addMapInsertInt (const QString &path) insilmaril@74: { insilmaril@74: QString pathDir=path.left(path.findRev("/")); insilmaril@74: QDir d(pathDir); insilmaril@74: QFile file (path); insilmaril@74: insilmaril@74: if (d.exists() ) insilmaril@74: { insilmaril@74: // We need to parse saved XML data insilmaril@74: parseVYMHandler handler; insilmaril@74: QXmlInputSource source( file); insilmaril@74: QXmlSimpleReader reader; insilmaril@74: reader.setContentHandler( &handler ); insilmaril@74: reader.setErrorHandler( &handler ); insilmaril@74: handler.setModel (model); insilmaril@74: handler.setTmpDir ( pathDir ); // needed to load files with rel. path insilmaril@74: handler.setLoadMode (ImportAdd); insilmaril@74: blockReposition=true; insilmaril@74: bool ok = reader.parse( source ); insilmaril@74: blockReposition=false; insilmaril@74: if ( ok ) return true; insilmaril@74: insilmaril@74: // This should never ever happen insilmaril@74: QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path), insilmaril@74: handler.errorProtocol()); insilmaril@74: } else insilmaril@74: QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path)); insilmaril@74: return false; insilmaril@74: } insilmaril@74: insilmaril@74: bool MapEditor::addMapInsertInt (const QString &path, int pos) insilmaril@39: { insilmaril@39: BranchObj *sel=xelection.getBranch(); insilmaril@39: if (sel) insilmaril@39: { insilmaril@74: if (addMapInsertInt (path)) insilmaril@0: { insilmaril@74: { insilmaril@74: if (sel->getDepth()>0) insilmaril@74: sel->getLastBranch()->linkTo (sel,pos); insilmaril@0: } insilmaril@74: return true; insilmaril@39: } else insilmaril@74: { insilmaril@39: QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path)); insilmaril@74: return false; insilmaril@74: } insilmaril@39: } insilmaril@74: qWarning ("ME::addMapInsertInt nothing selected"); insilmaril@74: return false; insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::pasteNoSave(const int &n) insilmaril@39: { insilmaril@39: bool old=blockSaveState; insilmaril@39: blockSaveState=true; insilmaril@39: bool zippedOrg=zipped; insilmaril@39: if (redosAvail > 0 || n!=0) insilmaril@39: { insilmaril@39: // Use the "historical" buffer insilmaril@39: QString bakMapName(QString("history-%1").arg(n)); insilmaril@39: QString bakMapDir(tmpMapDir +"/"+bakMapName); insilmaril@39: load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap); insilmaril@39: } else insilmaril@39: // Use the global buffer insilmaril@39: load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap); insilmaril@39: zipped=zippedOrg; insilmaril@39: blockSaveState=old; insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::paste() insilmaril@39: { insilmaril@39: BranchObj *sel=xelection.getBranch(); insilmaril@39: if (sel) insilmaril@39: { insilmaril@39: saveStateChangingPart( insilmaril@39: sel, insilmaril@39: sel, insilmaril@39: QString ("paste (%1)").arg(curClipboard), insilmaril@39: QString("Paste to %1").arg( getName(sel)) insilmaril@39: ); insilmaril@39: pasteNoSave(0); insilmaril@39: model->reposition(); insilmaril@39: } insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::cut() insilmaril@39: { insilmaril@39: LinkableMapObj *sel=xelection.single(); insilmaril@39: if ( sel && (xelection.type() == Selection::Branch || insilmaril@39: xelection.type()==Selection::MapCenter || insilmaril@39: xelection.type()==Selection::FloatImage)) insilmaril@39: { insilmaril@39: /* No savestate! savestate is called in cutNoSave insilmaril@39: saveStateChangingPart( insilmaril@39: sel->getParObj(), insilmaril@39: sel, insilmaril@39: "cut ()", insilmaril@39: QString("Cut %1").arg(getName(sel )) insilmaril@39: ); insilmaril@39: */ insilmaril@39: copy(); insilmaril@39: deleteSelection(); insilmaril@39: model->reposition(); insilmaril@39: } insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::move(const double &x, const double &y) insilmaril@39: { insilmaril@39: LinkableMapObj *sel=xelection.single(); insilmaril@39: if (sel) insilmaril@39: { insilmaril@39: QPointF ap(sel->getAbsPos()); insilmaril@39: QPointF to(x, y); insilmaril@39: if (ap != to) insilmaril@39: { insilmaril@39: QString ps=qpointfToString(ap); insilmaril@39: QString s=xelection.getSelectString(); insilmaril@39: saveState( insilmaril@39: s, "move "+ps, insilmaril@39: s, "move "+qpointfToString(to), insilmaril@39: QString("Move %1 to %2").arg(getName(sel)).arg(ps)); insilmaril@39: sel->move(x,y); insilmaril@39: model->reposition(); insilmaril@39: xelection.update(); insilmaril@39: } insilmaril@39: } insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::moveRel (const double &x, const double &y) insilmaril@39: { insilmaril@39: LinkableMapObj *sel=xelection.single(); insilmaril@39: if (sel) insilmaril@39: { insilmaril@39: QPointF rp(sel->getRelPos()); insilmaril@39: QPointF to(x, y); insilmaril@39: if (rp != to) insilmaril@39: { insilmaril@39: QString ps=qpointfToString (sel->getRelPos()); insilmaril@39: QString s=model->getSelectString(sel); insilmaril@39: saveState( insilmaril@39: s, "moveRel "+ps, insilmaril@39: s, "moveRel "+qpointfToString(to), insilmaril@39: QString("Move %1 to relative position %2").arg(getName(sel)).arg(ps)); insilmaril@39: ((OrnamentedObj*)sel)->move2RelPos (x,y); insilmaril@39: model->reposition(); insilmaril@39: sel->updateLink(); insilmaril@39: xelection.update(); insilmaril@39: } insilmaril@39: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::moveBranchUp() insilmaril@0: { insilmaril@39: BranchObj* bo=xelection.getBranch(); insilmaril@0: BranchObj* par; insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: if (!bo->canMoveBranchUp()) return; insilmaril@0: par=(BranchObj*)(bo->getParObj()); insilmaril@39: BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection insilmaril@39: saveState (model->getSelectString(bo),"moveBranchDown ()",model->getSelectString(obo),"moveBranchUp ()",QString("Move up %1").arg(getName(bo))); insilmaril@39: model->reposition(); insilmaril@39: scene()->update(); insilmaril@39: xelection.update(); insilmaril@0: ensureSelectionVisible(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::moveBranchDown() insilmaril@0: { insilmaril@39: BranchObj* bo=xelection.getBranch(); insilmaril@0: BranchObj* par; insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: if (!bo->canMoveBranchDown()) return; insilmaril@0: par=(BranchObj*)(bo->getParObj()); insilmaril@39: BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection insilmaril@39: saveState(model->getSelectString(bo),"moveBranchUp ()",model->getSelectString(obo),"moveBranchDown ()",QString("Move down %1").arg(getName(bo))); insilmaril@39: model->reposition(); insilmaril@39: scene()->update(); insilmaril@39: xelection.update(); insilmaril@0: ensureSelectionVisible(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::sortChildren() insilmaril@39: { insilmaril@39: BranchObj* bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: if(bo->countBranches()>1) insilmaril@39: { insilmaril@39: saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getName(bo))); insilmaril@39: bo->sortChildren(); insilmaril@39: model->reposition(); insilmaril@39: ensureSelectionVisible(); insilmaril@39: } insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::linkTo(const QString &dstString) insilmaril@39: { insilmaril@39: FloatImageObj *fio=xelection.getFloatImage(); insilmaril@39: if (fio) insilmaril@39: { insilmaril@39: BranchObj *dst=(BranchObj*)(model->findObjBySelect(dstString)); insilmaril@39: if (dst && (typeid(*dst)==typeid (BranchObj) || insilmaril@39: typeid(*dst)==typeid (MapCenterObj))) insilmaril@39: { insilmaril@39: LinkableMapObj *dstPar=dst->getParObj(); insilmaril@39: QString parString=model->getSelectString(dstPar); insilmaril@39: QString fioPreSelectString=model->getSelectString(fio); insilmaril@39: QString fioPreParentSelectString=model->getSelectString (fio->getParObj()); insilmaril@39: ((BranchObj*)(dst))->addFloatImage (fio); insilmaril@39: xelection.unselect(); insilmaril@39: ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio); insilmaril@39: fio=((BranchObj*)(dst))->getLastFloatImage(); insilmaril@39: fio->setRelPos(); insilmaril@39: fio->reposition(); insilmaril@39: xelection.select(fio); insilmaril@39: saveState( insilmaril@39: model->getSelectString(fio), insilmaril@39: QString("linkTo (\"%1\")").arg(fioPreParentSelectString), insilmaril@39: fioPreSelectString, insilmaril@39: QString ("linkTo (\"%1\")").arg(dstString), insilmaril@39: QString ("Link floatimage to %1").arg(getName(dst))); insilmaril@39: } insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: QString MapEditor::getHeading(bool &ok, QPoint &p) insilmaril@39: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: ok=true; insilmaril@39: p=mapFromScene(bo->getAbsPos()); insilmaril@39: return bo->getHeading(); insilmaril@39: } insilmaril@39: ok=false; insilmaril@39: return QString(); insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::setHeading(const QString &s) insilmaril@39: { insilmaril@39: BranchObj *sel=xelection.getBranch(); insilmaril@39: if (sel) insilmaril@39: { insilmaril@39: saveState( insilmaril@39: sel, insilmaril@39: "setHeading (\""+sel->getHeading()+"\")", insilmaril@39: sel, insilmaril@39: "setHeading (\""+s+"\")", insilmaril@39: QString("Set heading of %1 to \"%2\"").arg(getName(sel)).arg(s) ); insilmaril@39: sel->setHeading(s ); insilmaril@39: model->reposition(); insilmaril@39: xelection.update(); insilmaril@0: ensureSelectionVisible(); insilmaril@39: } insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::setHeadingInt(const QString &s) insilmaril@39: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: bo->setHeading(s); insilmaril@39: model->reposition(); insilmaril@39: xelection.update(); insilmaril@39: ensureSelectionVisible(); insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::setVymLinkInt (const QString &s) insilmaril@39: { insilmaril@39: // Internal function, no saveState needed insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: bo->setVymLink(s); insilmaril@39: model->reposition(); insilmaril@39: updateActions(); insilmaril@39: xelection.update(); insilmaril@39: ensureSelectionVisible(); insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: BranchObj* MapEditor::addMapCenter () insilmaril@39: { insilmaril@39: MapCenterObj *mco= model->addMapCenter(contextMenuPos); insilmaril@39: xelection.select (mco); insilmaril@39: updateActions(); insilmaril@39: ensureSelectionVisible(); insilmaril@39: saveState ( insilmaril@39: mco, insilmaril@39: "delete()", insilmaril@39: NULL, insilmaril@39: QString ("addMapCenter (%1,%2)").arg (contextMenuPos.x()).arg(contextMenuPos.y()), insilmaril@39: QString ("Adding MapCenter to (%1,%2").arg (contextMenuPos.x()).arg(contextMenuPos.y()) insilmaril@39: ); insilmaril@39: return mco; insilmaril@39: } insilmaril@39: insilmaril@39: BranchObj* MapEditor::addNewBranchInt(int num) insilmaril@39: { insilmaril@39: // Depending on pos: insilmaril@39: // -3 insert in childs of parent above selection insilmaril@39: // -2 add branch to selection insilmaril@39: // -1 insert in childs of parent below selection insilmaril@39: // 0..n insert in childs of parent at pos insilmaril@39: BranchObj *newbo=NULL; insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: if (num==-2) insilmaril@0: { insilmaril@0: // save scroll state. If scrolled, automatically select insilmaril@0: // new branch in order to tmp unscroll parent... insilmaril@39: newbo=bo->addBranch(); insilmaril@39: insilmaril@39: }else if (num==-1) insilmaril@0: { insilmaril@39: num=bo->getNum()+1; insilmaril@39: bo=(BranchObj*)bo->getParObj(); insilmaril@39: if (bo) newbo=bo->insertBranch(num); insilmaril@39: }else if (num==-3) insilmaril@39: { insilmaril@39: num=bo->getNum(); insilmaril@39: bo=(BranchObj*)bo->getParObj(); insilmaril@39: if (bo) newbo=bo->insertBranch(num); insilmaril@39: } insilmaril@39: if (!newbo) return NULL; insilmaril@39: } insilmaril@39: return newbo; insilmaril@39: } insilmaril@39: insilmaril@39: BranchObj* MapEditor::addNewBranch(int pos) insilmaril@39: { insilmaril@39: // Different meaning than num in addNewBranchInt! insilmaril@39: // -1 add above insilmaril@39: // 0 add as child insilmaril@39: // +1 add below insilmaril@39: BranchObj *bo = xelection.getBranch(); insilmaril@39: BranchObj *newbo=NULL; insilmaril@39: insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: setCursor (Qt::ArrowCursor); insilmaril@39: insilmaril@39: newbo=addNewBranchInt (pos-2); insilmaril@39: insilmaril@39: if (newbo) insilmaril@39: { insilmaril@39: saveState( insilmaril@39: newbo, insilmaril@39: "delete ()", insilmaril@39: bo, insilmaril@39: QString ("addBranch (%1)").arg(pos), insilmaril@39: QString ("Add new branch to %1").arg(getName(bo))); insilmaril@39: insilmaril@39: model->reposition(); insilmaril@39: xelection.update(); insilmaril@39: latestSelection=model->getSelectString(newbo); insilmaril@39: // In Network mode, the client needs to know where the new branch is, insilmaril@39: // so we have to pass on this information via saveState. insilmaril@39: // TODO: Get rid of this positioning workaround insilmaril@39: QString ps=qpointfToString (newbo->getAbsPos()); insilmaril@39: sendData ("selectLatestAdded ()"); insilmaril@39: sendData (QString("move %1").arg(ps)); insilmaril@39: sendSelection(); insilmaril@39: } insilmaril@39: } insilmaril@39: return newbo; insilmaril@39: } insilmaril@39: insilmaril@39: insilmaril@39: BranchObj* MapEditor::addNewBranchBefore() insilmaril@39: { insilmaril@39: BranchObj *newbo=NULL; insilmaril@39: BranchObj *bo = xelection.getBranch(); insilmaril@39: if (bo && xelection.type()==Selection::Branch) insilmaril@39: // We accept no MapCenterObj here, so we _have_ a parent insilmaril@39: { insilmaril@39: QPointF p=bo->getRelPos(); insilmaril@39: insilmaril@39: insilmaril@39: BranchObj *parbo=(BranchObj*)(bo->getParObj()); insilmaril@39: insilmaril@39: // add below selection insilmaril@39: newbo=parbo->insertBranch(bo->getNum()+1); insilmaril@39: if (newbo) insilmaril@39: { insilmaril@39: newbo->move2RelPos (p); insilmaril@39: insilmaril@39: // Move selection to new branch insilmaril@39: bo->linkTo (newbo,-1); insilmaril@39: insilmaril@39: saveState (newbo, "deleteKeepChilds ()", newbo, "addBranchBefore ()", insilmaril@39: QString ("Add branch before %1").arg(getName(bo))); insilmaril@39: insilmaril@39: model->reposition(); insilmaril@39: xelection.update(); insilmaril@39: } insilmaril@39: } insilmaril@39: latestSelection=xelection.getSelectString(); insilmaril@39: return newbo; insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::deleteSelection() insilmaril@39: { insilmaril@39: BranchObj *bo = xelection.getBranch(); insilmaril@39: if (bo && xelection.type()==Selection::MapCenter) insilmaril@39: { insilmaril@39: xelection.unselect(); insilmaril@39: saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo))); insilmaril@39: bo=model->removeMapCenter ((MapCenterObj*)bo); insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: xelection.select (bo); insilmaril@39: ensureSelectionVisible(); insilmaril@39: xelection.update(); insilmaril@0: } insilmaril@39: model->reposition(); insilmaril@39: return; insilmaril@39: } insilmaril@39: if (bo && xelection.type()==Selection::Branch) insilmaril@39: { insilmaril@39: BranchObj* par=(BranchObj*)bo->getParObj(); insilmaril@39: xelection.unselect(); insilmaril@39: saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo))); insilmaril@39: par->removeBranch(bo); insilmaril@39: xelection.select (par); insilmaril@39: ensureSelectionVisible(); insilmaril@39: model->reposition(); insilmaril@39: xelection.update(); insilmaril@39: return; insilmaril@39: } insilmaril@39: FloatImageObj *fio=xelection.getFloatImage(); insilmaril@39: if (fio) insilmaril@39: { insilmaril@39: BranchObj* par=(BranchObj*)fio->getParObj(); insilmaril@39: saveStateChangingPart( insilmaril@39: par, insilmaril@39: fio, insilmaril@39: "delete ()", insilmaril@39: QString("Delete %1").arg(getName(fio)) insilmaril@39: ); insilmaril@39: xelection.unselect(); insilmaril@39: par->removeFloatImage(fio); insilmaril@39: xelection.select (par); insilmaril@39: model->reposition(); insilmaril@39: xelection.update(); insilmaril@39: ensureSelectionVisible(); insilmaril@39: return; insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: LinkableMapObj* MapEditor::getSelection() insilmaril@39: { insilmaril@39: return xelection.single(); insilmaril@39: } insilmaril@39: insilmaril@39: BranchObj* MapEditor::getSelectedBranch() insilmaril@39: { insilmaril@39: return xelection.getBranch(); insilmaril@39: } insilmaril@39: insilmaril@39: FloatImageObj* MapEditor::getSelectedFloatImage() insilmaril@39: { insilmaril@39: return xelection.getFloatImage(); insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::unselect() insilmaril@39: { insilmaril@39: xelection.unselect(); insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::reselect() insilmaril@39: { insilmaril@39: xelection.reselect(); insilmaril@39: } insilmaril@39: insilmaril@39: bool MapEditor::select (const QString &s) insilmaril@39: { insilmaril@39: if (xelection.select(s)) insilmaril@39: { insilmaril@39: xelection.update(); insilmaril@39: ensureSelectionVisible(); insilmaril@39: sendSelection (); insilmaril@39: return true; insilmaril@39: } insilmaril@39: return false; insilmaril@39: } insilmaril@39: insilmaril@39: bool MapEditor::select (LinkableMapObj *lmo) insilmaril@39: { insilmaril@39: if (xelection.select(lmo)) insilmaril@39: { insilmaril@39: xelection.update(); insilmaril@39: ensureSelectionVisible(); insilmaril@39: sendSelection (); insilmaril@39: return true; insilmaril@39: } insilmaril@39: return false; insilmaril@39: } insilmaril@39: insilmaril@39: QString MapEditor::getSelectString() insilmaril@39: { insilmaril@39: return xelection.getSelectString(); insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::selectInt (LinkableMapObj *lmo) insilmaril@39: { insilmaril@39: if (lmo && xelection.single()!= lmo && isSelectBlocked()==false ) insilmaril@39: { insilmaril@39: xelection.select(lmo); insilmaril@39: xelection.update(); insilmaril@39: sendSelection (); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::selectNextBranchInt() insilmaril@0: { insilmaril@0: // Increase number of branch insilmaril@39: LinkableMapObj *sel=xelection.single(); insilmaril@39: if (sel) insilmaril@39: { insilmaril@39: QString s=xelection.getSelectString(); insilmaril@0: QString part; insilmaril@0: QString typ; insilmaril@0: QString num; insilmaril@0: insilmaril@0: // Where am I? insilmaril@0: part=s.section(",",-1); insilmaril@0: typ=part.left (3); insilmaril@0: num=part.right(part.length() - 3); insilmaril@0: insilmaril@0: s=s.left (s.length() -num.length()); insilmaril@0: insilmaril@0: // Go to next lmo insilmaril@0: num=QString ("%1").arg(num.toUInt()+1); insilmaril@0: insilmaril@0: s=s+num; insilmaril@0: insilmaril@0: // Try to select this one insilmaril@0: if (select (s)) return; insilmaril@0: insilmaril@0: // We have no direct successor, insilmaril@0: // try to increase the parental number in order to insilmaril@0: // find a successor with same depth insilmaril@0: insilmaril@39: int d=xelection.single()->getDepth(); insilmaril@0: int oldDepth=d; insilmaril@0: int i; insilmaril@0: bool found=false; insilmaril@0: bool b; insilmaril@0: while (!found && d>0) insilmaril@0: { insilmaril@0: s=s.section (",",0,d-1); insilmaril@0: // replace substring of current depth in s with "1" insilmaril@0: part=s.section(",",-1); insilmaril@0: typ=part.left (3); insilmaril@0: num=part.right(part.length() - 3); insilmaril@0: insilmaril@0: if (d>1) insilmaril@0: { insilmaril@0: // increase number of parent insilmaril@0: num=QString ("%1").arg(num.toUInt()+1); insilmaril@0: s=s.section (",",0,d-2) + ","+ typ+num; insilmaril@0: } else insilmaril@0: { insilmaril@0: // Special case, look at orientation insilmaril@39: if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter) insilmaril@0: num=QString ("%1").arg(num.toUInt()+1); insilmaril@0: else insilmaril@0: num=QString ("%1").arg(num.toUInt()-1); insilmaril@0: s=typ+num; insilmaril@0: } insilmaril@0: insilmaril@0: if (select (s)) insilmaril@0: // pad to oldDepth, select the first branch for each depth insilmaril@0: for (i=d;icountBranches()>0) insilmaril@0: s+=",bo:0"; insilmaril@0: else insilmaril@0: break; insilmaril@0: } else insilmaril@0: break; insilmaril@0: } insilmaril@0: insilmaril@0: // try to select the freshly built string insilmaril@0: found=select(s); insilmaril@0: d--; insilmaril@0: } insilmaril@0: return; insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::selectPrevBranchInt() insilmaril@0: { insilmaril@0: // Decrease number of branch insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: QString s=xelection.getSelectString(); insilmaril@0: QString part; insilmaril@0: QString typ; insilmaril@0: QString num; insilmaril@0: insilmaril@0: // Where am I? insilmaril@0: part=s.section(",",-1); insilmaril@0: typ=part.left (3); insilmaril@0: num=part.right(part.length() - 3); insilmaril@0: insilmaril@0: s=s.left (s.length() -num.length()); insilmaril@0: insilmaril@39: int n=num.toInt()-1; insilmaril@39: insilmaril@0: // Go to next lmo insilmaril@39: num=QString ("%1").arg(n); insilmaril@0: s=s+num; insilmaril@0: insilmaril@0: // Try to select this one insilmaril@39: if (n>=0 && select (s)) return; insilmaril@0: insilmaril@0: // We have no direct precessor, insilmaril@0: // try to decrease the parental number in order to insilmaril@0: // find a precessor with same depth insilmaril@0: insilmaril@39: int d=xelection.single()->getDepth(); insilmaril@0: int oldDepth=d; insilmaril@0: int i; insilmaril@0: bool found=false; insilmaril@0: bool b; insilmaril@0: while (!found && d>0) insilmaril@0: { insilmaril@0: s=s.section (",",0,d-1); insilmaril@0: // replace substring of current depth in s with "1" insilmaril@0: part=s.section(",",-1); insilmaril@0: typ=part.left (3); insilmaril@0: num=part.right(part.length() - 3); insilmaril@0: insilmaril@0: if (d>1) insilmaril@0: { insilmaril@0: // decrease number of parent insilmaril@39: num=QString ("%1").arg(num.toInt()-1); insilmaril@0: s=s.section (",",0,d-2) + ","+ typ+num; insilmaril@0: } else insilmaril@0: { insilmaril@0: // Special case, look at orientation insilmaril@39: if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter) insilmaril@39: num=QString ("%1").arg(num.toInt()-1); insilmaril@0: else insilmaril@39: num=QString ("%1").arg(num.toInt()+1); insilmaril@0: s=typ+num; insilmaril@0: } insilmaril@0: insilmaril@0: if (select(s)) insilmaril@0: // pad to oldDepth, select the last branch for each depth insilmaril@0: for (i=d;icountBranches()>0) insilmaril@39: s+=",bo:"+ QString ("%1").arg( xelection.getBranch()->countBranches()-1 ); insilmaril@0: else insilmaril@0: break; insilmaril@0: else insilmaril@0: break; insilmaril@0: } insilmaril@0: insilmaril@0: // try to select the freshly built string insilmaril@0: found=select(s); insilmaril@0: d--; insilmaril@0: } insilmaril@0: return; insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::selectUpperBranch() insilmaril@0: { insilmaril@39: if (isSelectBlocked() ) return; insilmaril@39: insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo && xelection.type()==Selection::Branch) insilmaril@39: { insilmaril@39: if (bo->getOrientation()==LinkableMapObj::RightOfCenter) insilmaril@39: selectPrevBranchInt(); insilmaril@39: else insilmaril@39: if (bo->getDepth()==1) insilmaril@39: selectNextBranchInt(); insilmaril@0: else insilmaril@39: selectPrevBranchInt(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::selectLowerBranch() insilmaril@0: { insilmaril@39: if (isSelectBlocked() ) return; insilmaril@39: insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo && xelection.type()==Selection::Branch) insilmaril@39: { insilmaril@39: if (bo->getOrientation()==LinkableMapObj::RightOfCenter) insilmaril@39: selectNextBranchInt(); insilmaril@39: else insilmaril@39: if (bo->getDepth()==1) insilmaril@39: selectPrevBranchInt(); insilmaril@0: else insilmaril@39: selectNextBranchInt(); insilmaril@39: } insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@0: void MapEditor::selectLeftBranch() insilmaril@0: { insilmaril@39: if (isSelectBlocked() ) return; insilmaril@0: insilmaril@0: BranchObj* bo; insilmaril@0: BranchObj* par; insilmaril@39: LinkableMapObj *sel=xelection.single(); insilmaril@39: if (sel) insilmaril@39: { insilmaril@39: if (xelection.type()== Selection::MapCenter) insilmaril@0: { insilmaril@39: par=xelection.getBranch(); insilmaril@0: bo=par->getLastSelectedBranch(); insilmaril@0: if (bo) insilmaril@0: { insilmaril@0: // Workaround for reselecting on left and right side insilmaril@39: if (bo->getOrientation()==LinkableMapObj::RightOfCenter) insilmaril@39: bo=par->getLastBranch(); insilmaril@39: if (bo) insilmaril@0: { insilmaril@0: bo=par->getLastBranch(); insilmaril@39: xelection.select(bo); insilmaril@39: xelection.update(); insilmaril@0: ensureSelectionVisible(); insilmaril@39: sendSelection(); insilmaril@0: } insilmaril@0: } insilmaril@0: } else insilmaril@0: { insilmaril@39: par=(BranchObj*)(sel->getParObj()); insilmaril@39: if (sel->getOrientation()==LinkableMapObj::RightOfCenter) insilmaril@0: { insilmaril@39: if (xelection.type() == Selection::Branch || insilmaril@39: xelection.type() == Selection::FloatImage) insilmaril@0: { insilmaril@39: xelection.select(par); insilmaril@39: xelection.update(); insilmaril@0: ensureSelectionVisible(); insilmaril@39: sendSelection(); insilmaril@0: } insilmaril@0: } else insilmaril@0: { insilmaril@39: if (xelection.type() == Selection::Branch ) insilmaril@0: { insilmaril@39: bo=xelection.getBranch()->getLastSelectedBranch(); insilmaril@0: if (bo) insilmaril@0: { insilmaril@39: xelection.select(bo); insilmaril@39: xelection.update(); insilmaril@0: ensureSelectionVisible(); insilmaril@39: sendSelection(); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::selectRightBranch() insilmaril@0: { insilmaril@39: if (isSelectBlocked() ) return; insilmaril@0: insilmaril@0: BranchObj* bo; insilmaril@0: BranchObj* par; insilmaril@39: LinkableMapObj *sel=xelection.single(); insilmaril@39: if (sel) insilmaril@39: { insilmaril@39: if (xelection.type()==Selection::MapCenter) insilmaril@0: { insilmaril@39: par=xelection.getBranch(); insilmaril@0: bo=par->getLastSelectedBranch(); insilmaril@0: if (bo) insilmaril@0: { insilmaril@39: // Workaround for reselecting on left and right side insilmaril@39: if (bo->getOrientation()==LinkableMapObj::LeftOfCenter) insilmaril@0: bo=par->getFirstBranch(); insilmaril@0: if (bo) insilmaril@0: { insilmaril@39: xelection.select(bo); insilmaril@39: xelection.update(); insilmaril@0: ensureSelectionVisible(); insilmaril@39: sendSelection(); insilmaril@0: } insilmaril@0: } insilmaril@0: } else insilmaril@0: { insilmaril@39: par=(BranchObj*)(xelection.single()->getParObj()); insilmaril@39: if (xelection.single()->getOrientation()==LinkableMapObj::LeftOfCenter) insilmaril@0: { insilmaril@39: if (xelection.type() == Selection::Branch || insilmaril@39: xelection.type() == Selection::FloatImage) insilmaril@0: { insilmaril@39: xelection.select(par); insilmaril@39: xelection.update(); insilmaril@0: ensureSelectionVisible(); insilmaril@39: sendSelection(); insilmaril@0: } insilmaril@0: } else insilmaril@0: { insilmaril@39: if (xelection.type() == Selection::Branch) insilmaril@0: { insilmaril@39: bo=xelection.getBranch()->getLastSelectedBranch(); insilmaril@0: if (bo) insilmaril@0: { insilmaril@39: xelection.select(bo); insilmaril@39: xelection.update(); insilmaril@0: ensureSelectionVisible(); insilmaril@39: sendSelection(); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::selectFirstBranch() insilmaril@0: { insilmaril@39: BranchObj *bo1=xelection.getBranch(); insilmaril@0: BranchObj *bo2; insilmaril@0: BranchObj* par; insilmaril@39: if (bo1) insilmaril@39: { insilmaril@39: par=(BranchObj*)(bo1->getParObj()); insilmaril@39: if (!par) return; insilmaril@39: bo2=par->getFirstBranch(); insilmaril@39: if (bo2) { insilmaril@39: xelection.select(bo2); insilmaril@39: xelection.update(); insilmaril@39: ensureSelectionVisible(); insilmaril@39: sendSelection(); insilmaril@39: } insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::selectLastBranch() insilmaril@39: { insilmaril@39: BranchObj *bo1=xelection.getBranch(); insilmaril@39: BranchObj *bo2; insilmaril@39: BranchObj* par; insilmaril@39: if (bo1) insilmaril@39: { insilmaril@39: par=(BranchObj*)(bo1->getParObj()); insilmaril@39: if (!par) return; insilmaril@39: bo2=par->getLastBranch(); insilmaril@39: if (bo2) insilmaril@0: { insilmaril@39: xelection.select(bo2); insilmaril@39: xelection.update(); insilmaril@39: ensureSelectionVisible(); insilmaril@39: sendSelection(); insilmaril@39: } insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::selectMapBackgroundImage () insilmaril@39: { insilmaril@39: Q3FileDialog *fd=new Q3FileDialog( this); insilmaril@39: fd->setMode (Q3FileDialog::ExistingFile); insilmaril@39: fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)")); insilmaril@39: ImagePreview *p =new ImagePreview (fd); insilmaril@39: fd->setContentsPreviewEnabled( TRUE ); insilmaril@39: fd->setContentsPreview( p, p ); insilmaril@39: fd->setPreviewMode( Q3FileDialog::Contents ); insilmaril@39: fd->setCaption(vymName+" - " +tr("Load background image")); insilmaril@39: fd->setDir (lastImageDir); insilmaril@39: fd->show(); insilmaril@39: insilmaril@39: if ( fd->exec() == QDialog::Accepted ) insilmaril@39: { insilmaril@39: // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory(); insilmaril@39: lastImageDir=QDir (fd->dirPath()); insilmaril@39: setMapBackgroundImage (fd->selectedFile()); insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::setMapBackgroundImage (const QString &fn) //FIXME missing savestate insilmaril@39: { insilmaril@39: QColor oldcol=mapScene->backgroundBrush().color(); insilmaril@39: /* insilmaril@39: saveState( insilmaril@39: selection, insilmaril@39: QString ("setMapBackgroundImage (%1)").arg(oldcol.name()), insilmaril@39: selection, insilmaril@39: QString ("setMapBackgroundImage (%1)").arg(col.name()), insilmaril@39: QString("Set background color of map to %1").arg(col.name())); insilmaril@39: */ insilmaril@39: QBrush brush; insilmaril@39: brush.setTextureImage (QPixmap (fn)); insilmaril@39: mapScene->setBackgroundBrush(brush); insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::selectMapBackgroundColor() insilmaril@39: { insilmaril@39: QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), this ); insilmaril@39: if ( !col.isValid() ) return; insilmaril@39: setMapBackgroundColor( col ); insilmaril@39: } insilmaril@39: insilmaril@39: insilmaril@39: void MapEditor::setMapBackgroundColor(QColor col) insilmaril@39: { insilmaril@39: QColor oldcol=mapScene->backgroundBrush().color(); insilmaril@39: saveState( insilmaril@39: QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()), insilmaril@39: QString ("setMapBackgroundColor (\"%1\")").arg(col.name()), insilmaril@39: QString("Set background color of map to %1").arg(col.name())); insilmaril@39: mapScene->setBackgroundBrush(col); insilmaril@39: } insilmaril@39: insilmaril@39: QColor MapEditor::getMapBackgroundColor() insilmaril@39: { insilmaril@39: return mapScene->backgroundBrush().color(); insilmaril@39: } insilmaril@39: insilmaril@39: QColor MapEditor::getCurrentHeadingColor() insilmaril@39: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) return bo->getColor(); insilmaril@39: insilmaril@39: QMessageBox::warning(0,tr("Warning"),tr("Can't get color of heading,\nthere's no branch selected")); insilmaril@39: return Qt::black; insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::colorBranch (QColor c) insilmaril@39: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: saveState( insilmaril@39: bo, insilmaril@39: QString ("colorBranch (\"%1\")").arg(bo->getColor().name()), insilmaril@39: bo, insilmaril@39: QString ("colorBranch (\"%1\")").arg(c.name()), insilmaril@39: QString("Set color of %1 to %2").arg(getName(bo)).arg(c.name()) insilmaril@39: ); insilmaril@39: bo->setColor(c); // color branch insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::colorSubtree (QColor c) insilmaril@39: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: saveStateChangingPart( insilmaril@39: bo, insilmaril@39: bo, insilmaril@39: QString ("colorSubtree (\"%1\")").arg(c.name()), insilmaril@39: QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(c.name()) insilmaril@39: ); insilmaril@39: bo->setColorSubtree (c); // color links, color childs insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@39: insilmaril@39: void MapEditor::toggleStandardFlag(QString f) insilmaril@39: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: QString u,r; insilmaril@39: if (bo->isSetStandardFlag(f)) insilmaril@0: { insilmaril@39: r="unsetFlag"; insilmaril@39: u="setFlag"; insilmaril@39: } insilmaril@39: else insilmaril@0: { insilmaril@39: u="unsetFlag"; insilmaril@39: r="setFlag"; insilmaril@39: } insilmaril@39: saveState( insilmaril@39: bo, insilmaril@39: QString("%1 (\"%2\")").arg(u).arg(f), insilmaril@39: bo, insilmaril@39: QString("%1 (\"%2\")").arg(r).arg(f), insilmaril@39: QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo))); insilmaril@39: bo->toggleStandardFlag (f,mainWindow->useFlagGroups()); insilmaril@39: xelection.update(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@0: BranchObj* MapEditor::findText (QString s, bool cs) insilmaril@0: { insilmaril@39: QTextDocument::FindFlags flags=0; insilmaril@39: if (cs) flags=QTextDocument::FindCaseSensitively; insilmaril@39: insilmaril@0: if (!itFind) insilmaril@0: { // Nothing found or new find process insilmaril@0: if (EOFind) insilmaril@0: // nothing found, start again insilmaril@0: EOFind=false; insilmaril@39: itFind=model->first(); insilmaril@0: } insilmaril@0: bool searching=true; insilmaril@0: bool foundNote=false; insilmaril@0: while (searching && !EOFind) insilmaril@0: { insilmaril@0: if (itFind) insilmaril@0: { insilmaril@0: // Searching in Note insilmaril@0: if (itFind->getNote().contains(s,cs)) insilmaril@0: { insilmaril@39: if (xelection.single()!=itFind) insilmaril@0: { insilmaril@39: xelection.select(itFind); insilmaril@0: ensureSelectionVisible(); insilmaril@0: } insilmaril@39: if (textEditor->findText(s,flags)) insilmaril@0: { insilmaril@0: searching=false; insilmaril@0: foundNote=true; insilmaril@0: } insilmaril@0: } insilmaril@0: // Searching in Heading insilmaril@0: if (searching && itFind->getHeading().contains (s,cs) ) insilmaril@0: { insilmaril@39: xelection.select(itFind); insilmaril@0: ensureSelectionVisible(); insilmaril@0: searching=false; insilmaril@0: } insilmaril@0: } insilmaril@0: if (!foundNote) insilmaril@0: { insilmaril@39: itFind=model->next(itFind); insilmaril@0: if (!itFind) EOFind=true; insilmaril@0: } insilmaril@39: //cout <<"still searching... "<getHeading())<getURL(); insilmaril@39: bo->setURL (url); insilmaril@39: saveState ( insilmaril@39: bo, insilmaril@39: QString ("setURL (\"%1\")").arg(oldurl), insilmaril@39: bo, insilmaril@39: QString ("setURL (\"%1\")").arg(url), insilmaril@39: QString ("set URL of %1 to %2").arg(getName(bo)).arg(url) insilmaril@39: ); insilmaril@39: updateActions(); insilmaril@39: model->reposition(); insilmaril@39: xelection.update(); insilmaril@39: ensureSelectionVisible(); insilmaril@39: } insilmaril@39: } insilmaril@0: insilmaril@0: void MapEditor::editURL() insilmaril@0: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@0: { insilmaril@0: bool ok; insilmaril@0: QString text = QInputDialog::getText( insilmaril@0: "VYM", tr("Enter URL:"), QLineEdit::Normal, insilmaril@39: bo->getURL(), &ok, this ); insilmaril@0: if ( ok) insilmaril@0: // user entered something and pressed OK insilmaril@39: setURL (text); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::editLocalURL() insilmaril@39: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: QStringList filters; insilmaril@39: filters <<"All files (*)"; insilmaril@39: filters << tr("Text","Filedialog") + " (*.txt)"; insilmaril@39: filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)"; insilmaril@39: filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)"; insilmaril@39: filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"; insilmaril@39: QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Set URL to a local file")); insilmaril@39: fd->setFilters (filters); insilmaril@39: fd->setCaption(vymName+" - " +tr("Set URL to a local file")); insilmaril@39: fd->setDirectory (lastFileDir); insilmaril@39: if (! bo->getVymLink().isEmpty() ) insilmaril@39: fd->selectFile( bo->getURL() ); insilmaril@39: fd->show(); insilmaril@39: insilmaril@39: if ( fd->exec() == QDialog::Accepted ) insilmaril@39: { insilmaril@39: lastFileDir=QDir (fd->directory().path()); insilmaril@39: setURL (fd->selectedFile() ); insilmaril@39: } insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: QString MapEditor::getURL() insilmaril@39: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: return bo->getURL(); insilmaril@39: else insilmaril@39: return ""; insilmaril@39: } insilmaril@39: insilmaril@39: QStringList MapEditor::getURLs() insilmaril@39: { insilmaril@39: QStringList urls; insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: bo=bo->first(); insilmaril@39: while (bo) insilmaril@39: { insilmaril@39: if (!bo->getURL().isEmpty()) urls.append( bo->getURL()); insilmaril@39: bo=bo->next(); insilmaril@39: } insilmaril@39: } insilmaril@39: return urls; insilmaril@39: } insilmaril@39: insilmaril@39: insilmaril@0: void MapEditor::editHeading2URL() insilmaril@0: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: setURL (bo->getHeading()); insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::editBugzilla2URL() insilmaril@39: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@0: { insilmaril@39: QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading(); insilmaril@39: setURL (url); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::editFATE2URL() insilmaril@39: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@0: { insilmaril@39: QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading(); insilmaril@39: saveState( insilmaril@39: bo, insilmaril@39: "setURL (\""+bo->getURL()+"\")", insilmaril@39: bo, insilmaril@39: "setURL (\""+url+"\")", insilmaril@39: QString("Use heading of %1 as link to FATE").arg(getName(bo)) insilmaril@39: ); insilmaril@39: bo->setURL (url); insilmaril@0: updateActions(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::editVymLink() insilmaril@0: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@0: { insilmaril@39: QStringList filters; insilmaril@39: filters <<"VYM map (*.vym)"; insilmaril@39: QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Link to another map")); insilmaril@39: fd->setFilters (filters); insilmaril@39: fd->setCaption(vymName+" - " +tr("Link to another map")); insilmaril@39: fd->setDirectory (lastFileDir); insilmaril@39: if (! bo->getVymLink().isEmpty() ) insilmaril@39: fd->selectFile( bo->getVymLink() ); insilmaril@0: fd->show(); insilmaril@0: insilmaril@0: QString fn; insilmaril@0: if ( fd->exec() == QDialog::Accepted ) insilmaril@39: { insilmaril@39: lastFileDir=QDir (fd->directory().path()); insilmaril@39: saveState( insilmaril@39: bo, insilmaril@39: "setVymLink (\""+bo->getVymLink()+"\")", insilmaril@39: bo, insilmaril@39: "setVymLink (\""+fd->selectedFile()+"\")", insilmaril@39: QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile()) insilmaril@39: ); insilmaril@39: setVymLinkInt (fd->selectedFile() ); insilmaril@39: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::deleteVymLink() insilmaril@0: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@0: { insilmaril@39: saveState( insilmaril@39: bo, insilmaril@39: "setVymLink (\""+bo->getVymLink()+"\")", insilmaril@39: bo, insilmaril@39: "setVymLink (\"\")", insilmaril@39: QString("Unset vymlink of %1").arg(getName(bo)) insilmaril@39: ); insilmaril@39: bo->setVymLink ("" ); insilmaril@0: updateActions(); insilmaril@39: model->reposition(); insilmaril@39: scene()->update(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::setHideExport(bool b) insilmaril@39: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: bo->setHideInExport (b); insilmaril@39: QString u= b ? "false" : "true"; insilmaril@39: QString r=!b ? "false" : "true"; insilmaril@39: insilmaril@39: saveState( insilmaril@39: bo, insilmaril@39: QString ("setHideExport (%1)").arg(u), insilmaril@39: bo, insilmaril@39: QString ("setHideExport (%1)").arg(r), insilmaril@39: QString ("Set HideExport flag of %1 to %2").arg(getName(bo)).arg (r) insilmaril@39: ); insilmaril@39: updateActions(); insilmaril@39: model->reposition(); insilmaril@39: xelection.update(); insilmaril@39: scene()->update(); insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::toggleHideExport() insilmaril@39: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: setHideExport ( !bo->hideInExport() ); insilmaril@39: } insilmaril@39: insilmaril@0: QString MapEditor::getVymLink() insilmaril@0: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: return bo->getVymLink(); insilmaril@39: else insilmaril@39: return ""; insilmaril@0: insilmaril@0: } insilmaril@0: insilmaril@39: QStringList MapEditor::getVymLinks() insilmaril@39: { insilmaril@39: QStringList links; insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: bo=bo->first(); insilmaril@39: while (bo) insilmaril@39: { insilmaril@39: if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink()); insilmaril@39: bo=bo->next(); insilmaril@39: } insilmaril@39: } insilmaril@39: return links; insilmaril@39: } insilmaril@39: insilmaril@39: insilmaril@39: void MapEditor::deleteKeepChilds() insilmaril@39: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: BranchObj *par; insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: par=(BranchObj*)(bo->getParObj()); insilmaril@49: insilmaril@49: // Don't use this on mapcenter insilmaril@49: if (!par) return; insilmaril@49: insilmaril@49: // Check if we have childs at all to keep insilmaril@49: if (bo->countBranches()==0) insilmaril@49: { insilmaril@49: deleteSelection(); insilmaril@49: return; insilmaril@49: } insilmaril@49: insilmaril@39: QPointF p=bo->getRelPos(); insilmaril@39: saveStateChangingPart( insilmaril@39: bo->getParObj(), insilmaril@39: bo, insilmaril@39: "deleteKeepChilds ()", insilmaril@39: QString("Remove %1 and keep its childs").arg(getName(bo)) insilmaril@39: ); insilmaril@39: insilmaril@39: QString sel=model->getSelectString(bo); insilmaril@39: unselect(); insilmaril@39: par->removeBranchHere(bo); insilmaril@39: model->reposition(); insilmaril@39: select (sel); insilmaril@39: xelection.getBranch()->move2RelPos (p); insilmaril@39: model->reposition(); insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::deleteChilds() insilmaril@39: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: saveStateChangingPart( insilmaril@39: bo, insilmaril@39: bo, insilmaril@39: "deleteChilds ()", insilmaril@39: QString( "Remove childs of branch %1").arg(getName(bo)) insilmaril@39: ); insilmaril@39: bo->removeChilds(); insilmaril@39: model->reposition(); insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@0: void MapEditor::editMapInfo() insilmaril@0: { insilmaril@0: ExtraInfoDialog dia; insilmaril@0: dia.setMapName (getFileName() ); insilmaril@39: dia.setAuthor (model->getAuthor() ); insilmaril@39: dia.setComment(model->getComment() ); insilmaril@0: insilmaril@0: // Calc some stats insilmaril@0: QString stats; insilmaril@39: stats+=tr("%1 items on map\n","Info about map").arg (mapScene->items().size(),6); insilmaril@0: insilmaril@0: uint b=0; insilmaril@0: uint f=0; insilmaril@0: uint n=0; insilmaril@39: uint xl=0; insilmaril@0: BranchObj *bo; insilmaril@39: bo=model->first(); insilmaril@0: while (bo) insilmaril@0: { insilmaril@0: if (!bo->getNote().isEmpty() ) n++; insilmaril@0: f+= bo->countFloatImages(); insilmaril@0: b++; insilmaril@39: xl+=bo->countXLinks(); insilmaril@39: bo=model->next(bo); insilmaril@0: } insilmaril@0: stats+=QString ("%1 branches\n").arg (b-1,6); insilmaril@39: stats+=QString ("%1 xLinks \n").arg (xl,6); insilmaril@0: stats+=QString ("%1 notes\n").arg (n,6); insilmaril@0: stats+=QString ("%1 images\n").arg (f,6); insilmaril@0: dia.setStats (stats); insilmaril@0: insilmaril@0: // Finally show dialog insilmaril@0: if (dia.exec() == QDialog::Accepted) insilmaril@0: { insilmaril@39: setMapAuthor (dia.getAuthor() ); insilmaril@39: setMapComment (dia.getComment() ); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::ensureSelectionVisible() insilmaril@39: { insilmaril@39: LinkableMapObj *lmo=xelection.single(); insilmaril@39: if (lmo) ensureVisible (lmo->getBBox() ); insilmaril@39: insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::updateSelection() insilmaril@39: { insilmaril@39: // Tell selection to update geometries insilmaril@39: xelection.update(); insilmaril@39: } insilmaril@39: insilmaril@0: void MapEditor::updateActions() insilmaril@0: { insilmaril@39: // Tell mainwindow to update states of actions insilmaril@39: mainWindow->updateActions(); insilmaril@39: // TODO maybe don't update if blockReposition is set insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::updateNoteFlag() insilmaril@39: { insilmaril@39: setChanged(); insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: bo->updateNoteFlag(); insilmaril@39: mainWindow->updateActions(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::setMapAuthor (const QString &s) insilmaril@39: { insilmaril@39: saveState ( insilmaril@39: QString ("setMapAuthor (\"%1\")").arg(model->getAuthor()), insilmaril@39: QString ("setMapAuthor (\"%1\")").arg(s), insilmaril@39: QString ("Set author of map to \"%1\"").arg(s) insilmaril@39: ); insilmaril@39: model->setAuthor (s); insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::setMapComment (const QString &s) insilmaril@39: { insilmaril@39: saveState ( insilmaril@39: QString ("setMapComment (\"%1\")").arg(model->getComment()), insilmaril@39: QString ("setMapComment (\"%1\")").arg(s), insilmaril@39: QString ("Set comment of map") insilmaril@39: ); insilmaril@39: model->setComment (s); insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::setMapLinkStyle (const QString & s) insilmaril@39: { insilmaril@39: QString snow; insilmaril@39: if (linkstyle==LinkableMapObj::Line) insilmaril@39: snow="StyleLine"; insilmaril@39: else if (linkstyle==LinkableMapObj::Parabel) insilmaril@39: snow="StyleParabel"; insilmaril@39: else if (linkstyle==LinkableMapObj::PolyLine) insilmaril@39: snow="StylePolyLine"; insilmaril@39: else if (linkstyle==LinkableMapObj::PolyParabel) insilmaril@39: snow="StyleParabel"; insilmaril@39: insilmaril@39: saveState ( insilmaril@39: QString("setMapLinkStyle (\"%1\")").arg(s), insilmaril@39: QString("setMapLinkStyle (\"%1\")").arg(snow), insilmaril@39: QString("Set map link style (\"%1\")").arg(s) insilmaril@39: ); insilmaril@39: insilmaril@39: if (s=="StyleLine") insilmaril@39: linkstyle=LinkableMapObj::Line; insilmaril@39: else if (s=="StyleParabel") insilmaril@39: linkstyle=LinkableMapObj::Parabel; insilmaril@39: else if (s=="StylePolyLine") insilmaril@39: linkstyle=LinkableMapObj::PolyLine; insilmaril@39: else insilmaril@39: linkstyle=LinkableMapObj::PolyParabel; insilmaril@0: insilmaril@0: BranchObj *bo; insilmaril@39: bo=model->first(); insilmaril@39: bo=model->next(bo); insilmaril@0: while (bo) insilmaril@0: { insilmaril@0: bo->setLinkStyle(bo->getDefLinkStyle()); insilmaril@39: bo=model->next(bo); insilmaril@0: } insilmaril@39: model->reposition(); insilmaril@0: } insilmaril@0: insilmaril@39: LinkableMapObj::Style MapEditor::getMapLinkStyle () insilmaril@0: { insilmaril@0: return linkstyle; insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::setMapDefLinkColor(QColor c) insilmaril@39: { insilmaril@39: defLinkColor=c; insilmaril@39: BranchObj *bo; insilmaril@39: bo=model->first(); insilmaril@39: while (bo) insilmaril@39: { insilmaril@39: bo->setLinkColor(); insilmaril@39: bo=model->next(bo); insilmaril@39: } insilmaril@0: updateActions(); insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::setMapLinkColorHintInt() insilmaril@39: { insilmaril@39: // called from setMapLinkColorHint(lch) or at end of parse insilmaril@0: BranchObj *bo; insilmaril@39: bo=model->first(); insilmaril@0: while (bo) insilmaril@0: { insilmaril@0: bo->setLinkColor(); insilmaril@39: bo=model->next(bo); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::setMapLinkColorHint(LinkableMapObj::ColorHint lch) insilmaril@0: { insilmaril@0: linkcolorhint=lch; insilmaril@39: setMapLinkColorHintInt(); insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::toggleMapLinkColorHint() insilmaril@39: { insilmaril@39: if (linkcolorhint==LinkableMapObj::HeadingColor) insilmaril@39: linkcolorhint=LinkableMapObj::DefaultColor; insilmaril@0: else insilmaril@39: linkcolorhint=LinkableMapObj::HeadingColor; insilmaril@0: BranchObj *bo; insilmaril@39: bo=model->first(); insilmaril@0: while (bo) insilmaril@0: { insilmaril@0: bo->setLinkColor(); insilmaril@39: bo=model->next(bo); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@39: LinkableMapObj::ColorHint MapEditor::getMapLinkColorHint() insilmaril@0: { insilmaril@0: return linkcolorhint; insilmaril@0: } insilmaril@0: insilmaril@39: QColor MapEditor::getMapDefLinkColor() insilmaril@39: { insilmaril@39: return defLinkColor; insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::setMapDefXLinkColor(QColor col) insilmaril@39: { insilmaril@39: defXLinkColor=col; insilmaril@39: } insilmaril@39: insilmaril@39: QColor MapEditor::getMapDefXLinkColor() insilmaril@39: { insilmaril@39: return defXLinkColor; insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::setMapDefXLinkWidth (int w) insilmaril@39: { insilmaril@39: defXLinkWidth=w; insilmaril@39: } insilmaril@39: insilmaril@39: int MapEditor::getMapDefXLinkWidth() insilmaril@39: { insilmaril@39: return defXLinkWidth; insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::selectMapLinkColor() insilmaril@39: { insilmaril@39: QColor col = QColorDialog::getColor( defLinkColor, this ); insilmaril@0: if ( !col.isValid() ) return; insilmaril@39: saveState ( insilmaril@39: QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()), insilmaril@39: QString("setMapDefLinkColor (\"%1\")").arg(col.name()), insilmaril@39: QString("Set map link color to %1").arg(col.name()) insilmaril@39: ); insilmaril@39: setMapDefLinkColor( col ); insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::selectMapSelectionColor() insilmaril@39: { insilmaril@39: QColor col = QColorDialog::getColor( defLinkColor, this ); insilmaril@39: setSelectionColor (col); insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::setSelectionColorInt (QColor col) insilmaril@39: { insilmaril@39: if ( !col.isValid() ) return; insilmaril@39: xelection.setColor (col); insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::setSelectionColor(QColor col) insilmaril@39: { insilmaril@39: if ( !col.isValid() ) return; insilmaril@39: saveState ( insilmaril@39: QString("setSelectionColor (%1)").arg(xelection.getColor().name()), insilmaril@39: QString("setSelectionColor (%1)").arg(col.name()), insilmaril@39: QString("Set color of selection box to %1").arg(col.name()) insilmaril@39: ); insilmaril@39: setSelectionColorInt (col); insilmaril@39: } insilmaril@39: insilmaril@39: QColor MapEditor::getSelectionColor() insilmaril@39: { insilmaril@39: return xelection.getColor(); insilmaril@39: } insilmaril@39: insilmaril@39: bool MapEditor::scrollBranch(BranchObj *bo) insilmaril@39: { insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: if (bo->isScrolled()) return false; insilmaril@39: if (bo->countBranches()==0) return false; insilmaril@39: if (bo->getDepth()==0) return false; insilmaril@39: QString u,r; insilmaril@39: r="scroll"; insilmaril@39: u="unscroll"; insilmaril@39: saveState( insilmaril@39: bo, insilmaril@39: QString ("%1 ()").arg(u), insilmaril@39: bo, insilmaril@39: QString ("%1 ()").arg(r), insilmaril@39: QString ("%1 %2").arg(r).arg(getName(bo)) insilmaril@39: ); insilmaril@39: bo->toggleScroll(); insilmaril@39: xelection.update(); insilmaril@39: scene()->update(); insilmaril@39: return true; insilmaril@39: } insilmaril@39: return false; insilmaril@39: } insilmaril@39: insilmaril@39: bool MapEditor::unscrollBranch(BranchObj *bo) insilmaril@39: { insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: if (!bo->isScrolled()) return false; insilmaril@39: if (bo->countBranches()==0) return false; insilmaril@39: if (bo->getDepth()==0) return false; insilmaril@39: QString u,r; insilmaril@39: u="scroll"; insilmaril@39: r="unscroll"; insilmaril@39: saveState( insilmaril@39: bo, insilmaril@39: QString ("%1 ()").arg(u), insilmaril@39: bo, insilmaril@39: QString ("%1 ()").arg(r), insilmaril@39: QString ("%1 %2").arg(r).arg(getName(bo)) insilmaril@39: ); insilmaril@39: bo->toggleScroll(); insilmaril@39: xelection.update(); insilmaril@39: scene()->update(); insilmaril@39: return true; insilmaril@39: } insilmaril@39: return false; insilmaril@39: } insilmaril@39: insilmaril@0: void MapEditor::toggleScroll() insilmaril@0: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (xelection.type()==Selection::Branch ) insilmaril@39: { insilmaril@39: if (bo->isScrolled()) insilmaril@39: unscrollBranch (bo); insilmaril@39: else insilmaril@39: scrollBranch (bo); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::unscrollChilds() insilmaril@39: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: bo->first(); insilmaril@39: while (bo) insilmaril@39: { insilmaril@39: if (bo->isScrolled()) unscrollBranch (bo); insilmaril@39: bo=bo->next(); insilmaril@39: } insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: FloatImageObj* MapEditor::loadFloatImageInt (QString fn) insilmaril@39: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: FloatImageObj *fio; insilmaril@39: bo->addFloatImage(); insilmaril@39: fio=bo->getLastFloatImage(); insilmaril@39: fio->load(fn); insilmaril@39: model->reposition(); insilmaril@39: scene()->update(); insilmaril@39: return fio; insilmaril@0: } insilmaril@39: return NULL; insilmaril@39: } insilmaril@0: insilmaril@0: void MapEditor::loadFloatImage () insilmaril@0: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: insilmaril@39: Q3FileDialog *fd=new Q3FileDialog( this); insilmaril@39: fd->setMode (Q3FileDialog::ExistingFiles); insilmaril@0: fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)")); insilmaril@0: ImagePreview *p =new ImagePreview (fd); insilmaril@0: fd->setContentsPreviewEnabled( TRUE ); insilmaril@0: fd->setContentsPreview( p, p ); insilmaril@39: fd->setPreviewMode( Q3FileDialog::Contents ); insilmaril@39: fd->setCaption(vymName+" - " +tr("Load image")); insilmaril@0: fd->setDir (lastImageDir); insilmaril@0: fd->show(); insilmaril@0: insilmaril@0: if ( fd->exec() == QDialog::Accepted ) insilmaril@0: { insilmaril@39: // TODO loadFIO in QT4 use: lastImageDir=fd->directory(); insilmaril@39: lastImageDir=QDir (fd->dirPath()); insilmaril@39: QString s; insilmaril@39: FloatImageObj *fio; insilmaril@39: for (int j=0; jselectedFiles().count(); j++) insilmaril@39: { insilmaril@39: s=fd->selectedFiles().at(j); insilmaril@39: fio=loadFloatImageInt (s); insilmaril@39: if (fio) insilmaril@39: saveState( insilmaril@39: (LinkableMapObj*)fio, insilmaril@39: "delete ()", insilmaril@39: bo, insilmaril@39: QString ("loadImage (%1)").arg(s ), insilmaril@39: QString("Add image %1 to %2").arg(s).arg(getName(bo)) insilmaril@39: ); insilmaril@39: else insilmaril@39: // TODO loadFIO error handling insilmaril@39: qWarning ("Failed to load "+s); insilmaril@39: } insilmaril@0: } insilmaril@39: delete (p); insilmaril@39: delete (fd); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn) insilmaril@39: { insilmaril@39: fio->save (fn,type); insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::saveFloatImage () insilmaril@39: { insilmaril@39: FloatImageObj *fio=xelection.getFloatImage(); insilmaril@39: if (fio) insilmaril@39: { insilmaril@39: QFileDialog *fd=new QFileDialog( this); insilmaril@39: fd->setFilters (imageIO.getFilters()); insilmaril@39: fd->setCaption(vymName+" - " +tr("Save image")); insilmaril@39: fd->setFileMode( QFileDialog::AnyFile ); insilmaril@39: fd->setDirectory (lastImageDir); insilmaril@39: // fd->setSelection (fio->getOriginalFilename()); insilmaril@0: fd->show(); insilmaril@0: insilmaril@0: QString fn; insilmaril@39: if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1) insilmaril@0: { insilmaril@39: fn=fd->selectedFiles().at(0); insilmaril@39: if (QFile (fn).exists() ) insilmaril@0: { insilmaril@39: QMessageBox mb( vymName, insilmaril@39: tr("The file %1 exists already.\n" insilmaril@39: "Do you want to overwrite it?").arg(fn), insilmaril@0: QMessageBox::Warning, insilmaril@0: QMessageBox::Yes | QMessageBox::Default, insilmaril@0: QMessageBox::Cancel | QMessageBox::Escape, insilmaril@39: QMessageBox::NoButton ); insilmaril@0: insilmaril@0: mb.setButtonText( QMessageBox::Yes, tr("Overwrite") ); insilmaril@0: mb.setButtonText( QMessageBox::No, tr("Cancel")); insilmaril@0: switch( mb.exec() ) insilmaril@0: { insilmaril@0: case QMessageBox::Yes: insilmaril@0: // save insilmaril@39: break; insilmaril@0: case QMessageBox::Cancel: insilmaril@0: // do nothing insilmaril@39: delete (fd); insilmaril@0: return; insilmaril@0: break; insilmaril@0: } insilmaril@0: } insilmaril@39: saveFloatImageInt (fio,fd->selectedFilter(),fn ); insilmaril@39: } insilmaril@39: delete (fd); insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::setFrameType(const FrameObj::FrameType &t) insilmaril@39: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: QString s=bo->getFrameTypeName(); insilmaril@39: bo->setFrameType (t); insilmaril@39: saveState (bo, QString("setFrameType (\"%1\")").arg(s), insilmaril@39: bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s)); insilmaril@39: model->reposition(); insilmaril@39: bo->updateLink(); insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::setFrameType(const QString &s) insilmaril@39: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()), insilmaril@39: bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s)); insilmaril@39: bo->setFrameType (s); insilmaril@39: model->reposition(); insilmaril@39: bo->updateLink(); insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::setFramePenColor(const QColor &c) insilmaril@39: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ), insilmaril@39: bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() )); insilmaril@39: bo->setFramePenColor (c); insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::setFrameBrushColor(const QColor &c) insilmaril@39: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ), insilmaril@39: bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() )); insilmaril@39: bo->setFrameBrushColor (c); insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::setFramePadding (const int &i) insilmaril@39: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ), insilmaril@39: bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i)); insilmaril@39: bo->setFramePadding (i); insilmaril@39: model->reposition(); insilmaril@39: bo->updateLink(); insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::setFrameBorderWidth(const int &i) insilmaril@39: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ), insilmaril@39: bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i)); insilmaril@39: bo->setFrameBorderWidth (i); insilmaril@39: model->reposition(); insilmaril@39: bo->updateLink(); insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::setIncludeImagesVer(bool b) insilmaril@39: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: QString u= b ? "false" : "true"; insilmaril@39: QString r=!b ? "false" : "true"; insilmaril@39: insilmaril@39: saveState( insilmaril@39: bo, insilmaril@39: QString("setIncludeImagesVertically (%1)").arg(u), insilmaril@39: bo, insilmaril@39: QString("setIncludeImagesVertically (%1)").arg(r), insilmaril@39: QString("Include images vertically in %1").arg(getName(bo)) insilmaril@39: ); insilmaril@39: bo->setIncludeImagesVer(b); insilmaril@39: model->reposition(); insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::setIncludeImagesHor(bool b) insilmaril@39: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: QString u= b ? "false" : "true"; insilmaril@39: QString r=!b ? "false" : "true"; insilmaril@39: insilmaril@39: saveState( insilmaril@39: bo, insilmaril@39: QString("setIncludeImagesHorizontally (%1)").arg(u), insilmaril@39: bo, insilmaril@39: QString("setIncludeImagesHorizontally (%1)").arg(r), insilmaril@39: QString("Include images horizontally in %1").arg(getName(bo)) insilmaril@39: ); insilmaril@39: bo->setIncludeImagesHor(b); insilmaril@39: model->reposition(); insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::setHideLinkUnselected (bool b) insilmaril@39: { insilmaril@39: LinkableMapObj *sel=xelection.single(); insilmaril@39: if (sel && insilmaril@39: (xelection.type() == Selection::Branch || insilmaril@39: xelection.type() == Selection::MapCenter || insilmaril@39: xelection.type() == Selection::FloatImage )) insilmaril@39: { insilmaril@39: QString u= b ? "false" : "true"; insilmaril@39: QString r=!b ? "false" : "true"; insilmaril@39: insilmaril@39: saveState( insilmaril@39: sel, insilmaril@39: QString("setHideLinkUnselected (%1)").arg(u), insilmaril@39: sel, insilmaril@39: QString("setHideLinkUnselected (%1)").arg(r), insilmaril@39: QString("Hide link of %1 if unselected").arg(getName(sel)) insilmaril@39: ); insilmaril@39: sel->setHideLinkUnselected(b); insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::importDirInt(BranchObj *dst, QDir d) insilmaril@39: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: // Traverse directories insilmaril@39: d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks ); insilmaril@39: QFileInfoList list = d.entryInfoList(); insilmaril@39: QFileInfo fi; insilmaril@39: insilmaril@39: for (int i = 0; i < list.size(); ++i) insilmaril@39: { insilmaril@39: fi=list.at(i); insilmaril@39: if (fi.fileName() != "." && fi.fileName() != ".." ) insilmaril@39: { insilmaril@39: dst->addBranch(); insilmaril@39: bo=dst->getLastBranch(); insilmaril@39: bo->setHeading (fi.fileName() ); insilmaril@39: bo->setColor (QColor("blue")); insilmaril@39: bo->toggleScroll(); insilmaril@39: if ( !d.cd(fi.fileName()) ) insilmaril@39: QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName())); insilmaril@39: else insilmaril@39: { insilmaril@39: // Recursively add subdirs insilmaril@39: importDirInt (bo,d); insilmaril@39: d.cdUp(); insilmaril@39: } insilmaril@39: } insilmaril@39: } insilmaril@39: // Traverse files insilmaril@39: d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks ); insilmaril@39: list = d.entryInfoList(); insilmaril@39: insilmaril@39: for (int i = 0; i < list.size(); ++i) insilmaril@39: { insilmaril@39: fi=list.at(i); insilmaril@39: dst->addBranch(); insilmaril@39: bo=dst->getLastBranch(); insilmaril@39: bo->setHeading (fi.fileName() ); insilmaril@39: bo->setColor (QColor("black")); insilmaril@39: if (fi.fileName().right(4) == ".vym" ) insilmaril@39: bo->setVymLink (fi.filePath()); insilmaril@39: } insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::importDirInt (const QString &s) insilmaril@39: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s)); insilmaril@39: insilmaril@39: QDir d(s); insilmaril@39: importDirInt (bo,d); insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::importDir() insilmaril@39: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: QStringList filters; insilmaril@39: filters <<"VYM map (*.vym)"; insilmaril@39: QFileDialog *fd=new QFileDialog( this,vymName+ " - " +tr("Choose directory structure to import")); insilmaril@39: fd->setMode (QFileDialog::DirectoryOnly); insilmaril@39: fd->setFilters (filters); insilmaril@39: fd->setCaption(vymName+" - " +tr("Choose directory structure to import")); insilmaril@39: fd->show(); insilmaril@39: insilmaril@39: QString fn; insilmaril@39: if ( fd->exec() == QDialog::Accepted ) insilmaril@39: { insilmaril@39: importDirInt (fd->selectedFile() ); insilmaril@39: model->reposition(); insilmaril@39: scene()->update(); insilmaril@39: } insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::followXLink(int i) insilmaril@39: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: bo=bo->XLinkTargetAt(i); insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: xelection.select(bo); insilmaril@39: ensureSelectionVisible(); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::editXLink(int i) // FIXME missing saveState insilmaril@39: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: XLinkObj *xlo=bo->XLinkAt(i); insilmaril@39: if (xlo) insilmaril@39: { insilmaril@39: EditXLinkDialog dia; insilmaril@39: dia.setXLink (xlo); insilmaril@39: dia.setSelection(bo); insilmaril@39: if (dia.exec() == QDialog::Accepted) insilmaril@39: { insilmaril@39: if (dia.useSettingsGlobal() ) insilmaril@39: { insilmaril@39: setMapDefXLinkColor (xlo->getColor() ); insilmaril@39: setMapDefXLinkWidth (xlo->getWidth() ); insilmaril@39: } insilmaril@39: if (dia.deleteXLink()) insilmaril@39: bo->deleteXLinkAt(i); insilmaril@39: } insilmaril@39: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@39: AttributeTable* MapEditor::attributeTable() insilmaril@39: { insilmaril@39: return attrTable; insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::testFunction1() insilmaril@39: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) model->moveAway (bo); insilmaril@39: insilmaril@39: /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere insilmaril@39: if (hidemode==HideNone) insilmaril@39: { insilmaril@39: setHideTmpMode (HideExport); insilmaril@39: mapCenter->calcBBoxSizeWithChilds(); insilmaril@39: QRectF totalBBox=mapCenter->getTotalBBox(); insilmaril@39: QRectF mapRect=totalBBox; insilmaril@39: QCanvasRectangle *frame=NULL; insilmaril@39: insilmaril@39: cout << " map has =("<setBrush (QColor(white)); insilmaril@39: frame->setPen (QColor(black)); insilmaril@39: frame->setZValue(0); insilmaril@39: frame->show(); insilmaril@39: } insilmaril@39: else insilmaril@39: { insilmaril@39: setHideTmpMode (HideNone); insilmaril@39: } insilmaril@39: cout <<" hidemode="<pos()); insilmaril@39: LinkableMapObj* lmo=model->findMapObj(p, NULL); insilmaril@0: insilmaril@0: if (lmo) insilmaril@0: { // MapObj was found insilmaril@39: if (xelection.single() != lmo) insilmaril@0: { insilmaril@0: // select the MapObj insilmaril@39: xelection.select(lmo); insilmaril@0: } insilmaril@0: // Context Menu insilmaril@39: if (xelection.getBranch() ) insilmaril@0: { insilmaril@39: // Context Menu on branch or mapcenter insilmaril@39: updateActions(); insilmaril@39: branchContextMenu->popup(e->globalPos() ); insilmaril@39: } else insilmaril@39: { insilmaril@39: if (xelection.getFloatImage() ) insilmaril@0: { insilmaril@0: // Context Menu on floatimage insilmaril@0: updateActions(); insilmaril@0: floatimageContextMenu->popup(e->globalPos() ); insilmaril@0: } insilmaril@0: } insilmaril@0: } else insilmaril@0: { // No MapObj found, we are on the Canvas itself insilmaril@39: // Context Menu on scene insilmaril@0: updateActions(); insilmaril@39: contextMenuPos=p; insilmaril@0: canvasContextMenu->popup(e->globalPos() ); insilmaril@0: } insilmaril@39: e->accept(); insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::keyPressEvent(QKeyEvent* e) insilmaril@39: { insilmaril@39: if (e->modifiers() & Qt::ControlModifier) insilmaril@39: { insilmaril@39: switch (mainWindow->getModMode()) insilmaril@39: { insilmaril@39: case Main::ModModeColor: insilmaril@39: setCursor (PickColorCursor); insilmaril@39: break; insilmaril@39: case Main::ModModeCopy: insilmaril@39: setCursor (CopyCursor); insilmaril@39: break; insilmaril@39: case Main::ModModeXLink: insilmaril@39: setCursor (XLinkCursor); insilmaril@39: break; insilmaril@39: default : insilmaril@39: setCursor (Qt::ArrowCursor); insilmaril@39: break; insilmaril@39: } insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::keyReleaseEvent(QKeyEvent* e) insilmaril@39: { insilmaril@39: if (!(e->modifiers() & Qt::ControlModifier)) insilmaril@39: setCursor (Qt::ArrowCursor); insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::mousePressEvent(QMouseEvent* e) insilmaril@39: { insilmaril@39: // Ignore right clicks, these will go to context menus insilmaril@39: if (e->button() == Qt::RightButton ) insilmaril@39: { insilmaril@39: e->ignore(); insilmaril@0: return; insilmaril@0: } insilmaril@0: insilmaril@39: //Ignore clicks while editing heading insilmaril@39: if (isSelectBlocked() ) insilmaril@39: { insilmaril@39: e->ignore(); insilmaril@39: return; insilmaril@39: } insilmaril@39: insilmaril@39: QPointF p = mapToScene(e->pos()); insilmaril@39: LinkableMapObj* lmo=model->findMapObj(p, NULL); insilmaril@39: insilmaril@39: e->accept(); insilmaril@39: insilmaril@39: //Take care of system flags _or_ modifier modes insilmaril@39: // insilmaril@39: if (lmo && (typeid(*lmo)==typeid(BranchObj) || insilmaril@39: typeid(*lmo)==typeid(MapCenterObj) )) insilmaril@39: { insilmaril@39: QString foname=((BranchObj*)lmo)->getSystemFlagName(p); insilmaril@39: if (!foname.isEmpty()) insilmaril@39: { insilmaril@39: // systemFlag clicked insilmaril@39: selectInt (lmo); insilmaril@39: if (foname=="url") insilmaril@39: { insilmaril@39: if (e->state() & Qt::ControlModifier) insilmaril@39: mainWindow->editOpenURLTab(); insilmaril@39: else insilmaril@39: mainWindow->editOpenURL(); insilmaril@39: } insilmaril@39: else if (foname=="vymLink") insilmaril@39: { insilmaril@39: mainWindow->editOpenVymLink(); insilmaril@39: // tabWidget may change, better return now insilmaril@39: // before segfaulting... insilmaril@39: } else if (foname=="note") insilmaril@39: mainWindow->windowToggleNoteEditor(); insilmaril@39: else if (foname=="hideInExport") insilmaril@39: toggleHideExport(); insilmaril@39: xelection.update(); insilmaril@39: return; insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: // No system flag clicked, take care of modmodes (CTRL-Click) insilmaril@39: if (e->state() & Qt::ControlModifier) insilmaril@39: { insilmaril@39: if (mainWindow->getModMode()==Main::ModModeColor) insilmaril@39: { insilmaril@65: pickingColor=true; insilmaril@65: setCursor (PickColorCursor); insilmaril@65: return; insilmaril@65: } insilmaril@65: if (mainWindow->getModMode()==Main::ModModeCopy) insilmaril@65: { insilmaril@65: if (lmo && (typeid(*lmo)==typeid(BranchObj) || insilmaril@65: typeid(*lmo)==typeid(MapCenterObj) )) insilmaril@65: { insilmaril@65: insilmaril@65: selectInt (lmo); insilmaril@65: copy(); insilmaril@65: if (lmo->getDepth()>0) select (lmo->getParObj() ); insilmaril@65: paste(); insilmaril@65: cout << "sel 1="<getHeading().toStdString()<getLastBranch(); insilmaril@65: cout << "sel 2="<getHeading().toStdString()<getModMode()==Main::ModModeXLink) insilmaril@39: { insilmaril@39: BranchObj *bo_begin=NULL; insilmaril@39: if (lmo) insilmaril@39: bo_begin=(BranchObj*)(lmo); insilmaril@39: else insilmaril@39: if (xelection.getBranch() ) insilmaril@39: bo_begin=xelection.getBranch(); insilmaril@39: if (bo_begin) insilmaril@39: { insilmaril@39: drawingLink=true; insilmaril@39: linkingObj_src=bo_begin; insilmaril@39: tmpXLink=new XLinkObj (mapScene); insilmaril@39: tmpXLink->setBegin (bo_begin); insilmaril@39: tmpXLink->setEnd (p); insilmaril@39: tmpXLink->setColor(defXLinkColor); insilmaril@39: tmpXLink->setWidth(defXLinkWidth); insilmaril@39: tmpXLink->updateXLink(); insilmaril@39: tmpXLink->setVisibility (true); insilmaril@39: return; insilmaril@39: } insilmaril@39: } insilmaril@39: } // End of modmodes insilmaril@39: insilmaril@0: if (lmo) insilmaril@39: { insilmaril@39: // Select the clicked object insilmaril@39: selectInt (lmo); insilmaril@39: insilmaril@39: // Left Button Move Branches insilmaril@39: if (e->button() == Qt::LeftButton ) insilmaril@0: { insilmaril@39: //movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here insilmaril@39: //movingObj_start.setY( p.y() - selection->y() ); insilmaril@39: movingObj_start.setX( p.x() - lmo->x() ); insilmaril@39: movingObj_start.setY( p.y() - lmo->y() ); insilmaril@39: movingObj_orgPos.setX (lmo->x() ); insilmaril@39: movingObj_orgPos.setY (lmo->y() ); insilmaril@39: movingObj_orgRelPos=lmo->getRelPos(); insilmaril@39: insilmaril@39: // If modMode==copy, then we want to "move" the _new_ object around insilmaril@39: // then we need the offset from p to the _old_ selection, because of tmp insilmaril@65: /* insilmaril@39: if (mainWindow->getModMode()==Main::ModModeCopy && insilmaril@39: e->state() & Qt::ControlModifier) insilmaril@0: { insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: copyingObj=true; insilmaril@39: bo->addBranch ((BranchObj*)xelection.single()); insilmaril@39: unselect(); insilmaril@39: xelection.select(bo->getLastBranch()); insilmaril@39: model->reposition(); insilmaril@39: } insilmaril@39: } insilmaril@65: */ insilmaril@39: insilmaril@39: movingObj=xelection.single(); insilmaril@0: } else insilmaril@0: // Middle Button Toggle Scroll insilmaril@0: // (On Mac OS X this won't work, but we still have insilmaril@0: // a button in the toolbar) insilmaril@39: if (e->button() == Qt::MidButton ) insilmaril@0: toggleScroll(); insilmaril@0: updateActions(); insilmaril@39: xelection.update(); insilmaril@0: } else insilmaril@39: { // No MapObj found, we are on the scene itself insilmaril@39: // Left Button move Pos of sceneView insilmaril@39: if (e->button() == Qt::LeftButton ) insilmaril@0: { insilmaril@0: movingObj=NULL; // move Content not Obj insilmaril@0: movingObj_start=e->globalPos(); insilmaril@39: movingCont_start=QPointF ( insilmaril@39: horizontalScrollBar()->value(), insilmaril@39: verticalScrollBar()->value()); insilmaril@39: movingVec=QPointF(0,0); insilmaril@39: setCursor(HandOpenCursor); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::mouseMoveEvent(QMouseEvent* e) insilmaril@39: { insilmaril@39: QPointF p = mapToScene(e->pos()); insilmaril@39: LinkableMapObj *lmosel=xelection.single(); insilmaril@39: insilmaril@0: // Move the selected MapObj insilmaril@39: if ( lmosel && movingObj) insilmaril@0: { insilmaril@39: // reset cursor if we are moving and don't copy insilmaril@39: if (mainWindow->getModMode()!=Main::ModModeCopy) insilmaril@39: setCursor (Qt::ArrowCursor); insilmaril@39: insilmaril@39: // To avoid jumping of the sceneView, only insilmaril@39: // ensureSelectionVisible, if not tmp linked insilmaril@39: if (!lmosel->hasParObjTmp()) insilmaril@39: ensureSelectionVisible (); insilmaril@0: insilmaril@39: // Now move the selection, but add relative position insilmaril@39: // (movingObj_start) where selection was chosen with insilmaril@39: // mousepointer. (This avoids flickering resp. jumping insilmaril@0: // of selection back to absPos) insilmaril@0: insilmaril@0: // Check if we could link insilmaril@39: LinkableMapObj* lmo=model->findMapObj(p, lmosel); insilmaril@0: insilmaril@0: insilmaril@39: FloatObj *fio=xelection.getFloatImage(); insilmaril@39: if (fio) insilmaril@0: { insilmaril@39: fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() ); insilmaril@39: fio->setRelPos(); insilmaril@39: fio->updateLink(); //no need for reposition, if we update link here insilmaril@39: xelection.update(); insilmaril@0: insilmaril@0: // Relink float to new mapcenter or branch, if shift is pressed insilmaril@0: // Only relink, if selection really has a new parent insilmaril@39: if ( (e->modifiers()==Qt::ShiftModifier) && lmo && insilmaril@0: ( (typeid(*lmo)==typeid(BranchObj)) || insilmaril@0: (typeid(*lmo)==typeid(MapCenterObj)) ) && insilmaril@39: ( lmo != fio->getParObj()) insilmaril@0: ) insilmaril@0: { insilmaril@39: if (typeid(*fio) == typeid(FloatImageObj) && insilmaril@39: ( (typeid(*lmo)==typeid(BranchObj) || insilmaril@39: typeid(*lmo)==typeid(MapCenterObj)) )) insilmaril@0: { insilmaril@39: insilmaril@39: // Also save the move which was done so far insilmaril@39: QString pold=qpointfToString(movingObj_orgRelPos); insilmaril@39: QString pnow=qpointfToString(fio->getRelPos()); insilmaril@39: saveState( insilmaril@39: fio, insilmaril@39: "moveRel "+pold, insilmaril@39: fio, insilmaril@39: "moveRel "+pnow, insilmaril@39: QString("Move %1 to relative position %2").arg(getName(fio)).arg(pnow)); insilmaril@39: fio->getParObj()->requestReposition(); insilmaril@39: model->reposition(); insilmaril@39: insilmaril@39: linkTo (model->getSelectString(lmo)); insilmaril@39: //movingObj=lmosel; insilmaril@39: //movingObj_orgRelPos=lmosel->getRelPos(); insilmaril@39: insilmaril@39: model->reposition(); insilmaril@0: } insilmaril@0: } insilmaril@39: } else insilmaril@39: { // selection != a FloatObj insilmaril@0: if (lmosel->getDepth()==0) insilmaril@0: { insilmaril@39: // Move MapCenter insilmaril@39: if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier) insilmaril@39: ((MapCenterObj*)lmosel)->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() ); insilmaril@0: else insilmaril@39: lmosel->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() ); insilmaril@39: model->updateRelPositions(); insilmaril@0: } else insilmaril@0: { insilmaril@0: if (lmosel->getDepth()==1) insilmaril@0: { insilmaril@39: // Move mainbranch insilmaril@0: lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() ); insilmaril@39: lmosel->setRelPos(); insilmaril@0: } else insilmaril@0: { insilmaril@39: // Move ordinary branch insilmaril@41: lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() ); insilmaril@0: } insilmaril@39: insilmaril@39: // Maybe we can relink temporary? insilmaril@39: if (lmo && (lmo!=lmosel) && xelection.getBranch() && insilmaril@39: (typeid(*lmo)==typeid(BranchObj) || insilmaril@39: typeid(*lmo)==typeid(MapCenterObj)) ) insilmaril@39: insilmaril@0: { insilmaril@39: if (e->modifiers()==Qt::ControlModifier) insilmaril@0: { insilmaril@0: // Special case: CTRL to link below lmo insilmaril@0: lmosel->setParObjTmp (lmo,p,+1); insilmaril@0: } insilmaril@39: else if (e->modifiers()==Qt::ShiftModifier) insilmaril@0: lmosel->setParObjTmp (lmo,p,-1); insilmaril@0: else insilmaril@0: lmosel->setParObjTmp (lmo,p,0); insilmaril@0: } else insilmaril@0: { insilmaril@39: lmosel->unsetParObjTmp(); insilmaril@0: } insilmaril@39: // reposition subbranch insilmaril@39: lmosel->reposition(); insilmaril@0: } // depth>0 insilmaril@0: insilmaril@39: xelection.update(); insilmaril@0: } // no FloatImageObj insilmaril@0: insilmaril@39: scene()->update(); insilmaril@0: return; insilmaril@0: } // selection && moving_obj insilmaril@0: insilmaril@39: // Draw a link from one branch to another insilmaril@39: if (drawingLink) insilmaril@39: { insilmaril@39: tmpXLink->setEnd (p); insilmaril@39: tmpXLink->updateXLink(); insilmaril@39: } insilmaril@39: insilmaril@39: // Move sceneView insilmaril@39: if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton ) insilmaril@39: { insilmaril@39: QPointF p=e->globalPos(); insilmaril@0: movingVec.setX(-p.x() + movingObj_start.x() ); insilmaril@0: movingVec.setY(-p.y() + movingObj_start.y() ); insilmaril@39: horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() )); insilmaril@39: verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) ); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@39: void MapEditor::mouseReleaseEvent(QMouseEvent* e) insilmaril@39: { insilmaril@39: QPointF p = mapToScene(e->pos()); insilmaril@0: LinkableMapObj *dst; insilmaril@39: LinkableMapObj *lmosel=xelection.single(); insilmaril@0: // Have we been picking color? insilmaril@0: if (pickingColor) insilmaril@0: { insilmaril@0: pickingColor=false; insilmaril@39: setCursor (Qt::ArrowCursor); insilmaril@0: // Check if we are over another branch insilmaril@39: dst=model->findMapObj(p, NULL); insilmaril@39: if (dst && lmosel) insilmaril@0: { insilmaril@39: if (e->state() & Qt::ShiftModifier) insilmaril@39: colorBranch (((BranchObj*)dst)->getColor()); insilmaril@0: else insilmaril@39: colorSubtree (((BranchObj*)dst)->getColor()); insilmaril@0: } insilmaril@0: return; insilmaril@0: } insilmaril@39: insilmaril@39: // Have we been drawing a link? insilmaril@39: if (drawingLink) insilmaril@39: { insilmaril@39: drawingLink=false; insilmaril@39: // Check if we are over another branch insilmaril@39: dst=model->findMapObj(p, NULL); insilmaril@39: if (dst && lmosel) insilmaril@39: { insilmaril@39: tmpXLink->setEnd ( ((BranchObj*)(dst)) ); insilmaril@39: tmpXLink->updateXLink(); insilmaril@39: tmpXLink->activate(); //FIXME savestate missing insilmaril@39: //saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) ); insilmaril@39: } else insilmaril@39: { insilmaril@39: delete(tmpXLink); insilmaril@39: tmpXLink=NULL; insilmaril@39: } insilmaril@39: return; insilmaril@39: } insilmaril@39: insilmaril@0: // Have we been moving something? insilmaril@39: if ( lmosel && movingObj ) insilmaril@0: { insilmaril@39: FloatImageObj *fo=xelection.getFloatImage(); insilmaril@39: if(fo) insilmaril@39: { insilmaril@39: // Moved FloatObj. Maybe we need to reposition insilmaril@39: QString pold=qpointfToString(movingObj_orgRelPos); insilmaril@39: QString pnow=qpointfToString(fo->getRelPos()); insilmaril@39: saveState( insilmaril@39: fo, insilmaril@39: "moveRel "+pold, insilmaril@39: fo, insilmaril@39: "moveRel "+pnow, insilmaril@39: QString("Move %1 to relative position %2").arg(getName(fo)).arg(pnow)); insilmaril@39: insilmaril@39: fo->getParObj()->requestReposition(); insilmaril@39: model->reposition(); insilmaril@39: } insilmaril@39: insilmaril@0: // Check if we are over another branch, but ignore insilmaril@0: // any found LMOs, which are FloatObjs insilmaril@39: dst=model->findMapObj(mapToScene(e->pos() ), lmosel); insilmaril@39: insilmaril@39: if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj))) insilmaril@0: dst=NULL; insilmaril@0: insilmaril@39: BranchObj *bo=xelection.getBranch(); insilmaril@39: if (bo && bo->getDepth()==0) insilmaril@39: { insilmaril@39: if (movingObj_orgPos != bo->getAbsPos()) insilmaril@39: { insilmaril@39: QString pold=qpointfToString(movingObj_orgPos); insilmaril@39: QString pnow=qpointfToString(bo->getAbsPos()); insilmaril@39: saveState( insilmaril@39: fo, insilmaril@39: "move "+pold, insilmaril@39: fo, insilmaril@39: "move "+pnow, insilmaril@39: QString("Move mapcenter %1 to position %2").arg(getName(bo)).arg(pnow)); insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: if (xelection.type() == Selection::Branch ) insilmaril@39: { // A branch was moved insilmaril@39: insilmaril@0: // save the position in case we link to mapcenter insilmaril@39: QPointF savePos=QPointF (lmosel->getAbsPos() ); insilmaril@0: insilmaril@0: // Reset the temporary drawn link to the original one insilmaril@39: lmosel->unsetParObjTmp(); insilmaril@39: insilmaril@39: // For Redo we may need to save original selection insilmaril@39: QString preSelStr=model->getSelectString(lmosel); insilmaril@39: insilmaril@39: copyingObj=false; insilmaril@0: if (dst ) insilmaril@39: { insilmaril@70: // Don't unscroll if relinked to a scrolled parent, but insilmaril@70: // select parent instead insilmaril@70: bool selectParent=false; insilmaril@70: insilmaril@39: // We have a destination, relink to that insilmaril@39: insilmaril@39: BranchObj* bsel=xelection.getBranch(); insilmaril@39: BranchObj* bdst=(BranchObj*)dst; insilmaril@39: insilmaril@39: QString preParStr=model->getSelectString (bsel->getParObj()); insilmaril@39: QString preNum=QString::number (bsel->getNum(),10); insilmaril@39: QString preDstParStr; insilmaril@39: insilmaril@39: if (e->state() & Qt::ShiftModifier && dst->getParObj()) insilmaril@39: { // Link above dst insilmaril@39: preDstParStr=model->getSelectString (dst->getParObj()); insilmaril@39: bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()); insilmaril@39: } else insilmaril@39: if (e->state() & Qt::ControlModifier && dst->getParObj()) insilmaril@0: { insilmaril@39: // Link below dst insilmaril@39: preDstParStr=model->getSelectString (dst->getParObj()); insilmaril@39: bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1); insilmaril@39: } else insilmaril@39: { // Append to dst insilmaril@70: if (bdst->isScrolled()) selectParent=true; insilmaril@39: preDstParStr=model->getSelectString(dst); insilmaril@39: bsel->linkTo (bdst,-1); insilmaril@39: if (dst->getDepth()==0) bsel->move (savePos); insilmaril@39: } insilmaril@39: QString postSelStr=model->getSelectString(lmosel); insilmaril@39: QString postNum=QString::number (bsel->getNum(),10); insilmaril@39: insilmaril@39: QString undoCom="linkTo (\""+ insilmaril@39: preParStr+ "\"," + preNum +"," + insilmaril@39: QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")"; insilmaril@39: insilmaril@39: QString redoCom="linkTo (\""+ insilmaril@39: preDstParStr + "\"," + postNum + "," + insilmaril@39: QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")"; insilmaril@39: insilmaril@39: saveState ( insilmaril@39: postSelStr,undoCom, insilmaril@39: preSelStr, redoCom, insilmaril@39: QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) ); insilmaril@39: insilmaril@70: if (selectParent) select (bdst); insilmaril@70: insilmaril@39: model->reposition(); // not necessary if we undo temporary move below insilmaril@39: } else insilmaril@39: { insilmaril@39: // No destination, undo temporary move insilmaril@39: insilmaril@39: if (lmosel->getDepth()==1) insilmaril@0: { insilmaril@39: // The select string might be different _after_ moving around. insilmaril@39: // Therefor reposition and then use string of old selection, too insilmaril@39: model->reposition(); insilmaril@39: insilmaril@39: QPointF rp(lmosel->getRelPos()); insilmaril@39: if (rp != movingObj_orgRelPos) insilmaril@39: { insilmaril@39: QString ps=qpointfToString(rp); insilmaril@39: saveState( insilmaril@39: model->getSelectString(lmosel), "moveRel "+qpointfToString(movingObj_orgRelPos), insilmaril@39: preSelStr, "moveRel "+ps, insilmaril@39: QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps)); insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: // Draw the original link, before selection was moved around insilmaril@39: if (settings.value("/animation/use",false).toBool() && lmosel->getDepth()>1) insilmaril@0: { insilmaril@39: QPointF p=bo->getParObj()->getChildPos(); insilmaril@39: lmosel->setRelPos(); // calc relPos first insilmaril@39: model->startAnimation( insilmaril@39: lmosel->getRelPos(), insilmaril@39: QPointF (movingObj_orgPos.x() - p.x(), movingObj_orgPos.y() - p.y() ) insilmaril@39: ); insilmaril@39: } else insilmaril@39: model->reposition(); insilmaril@39: } insilmaril@0: } insilmaril@39: xelection.update(); insilmaril@39: // Finally resize scene, if needed insilmaril@39: scene()->update(); insilmaril@0: movingObj=NULL; insilmaril@39: insilmaril@39: // Just make sure, that actions are still ok,e.g. the move branch up/down buttons... insilmaril@39: updateActions(); insilmaril@0: } else insilmaril@39: // maybe we moved View: set old cursor insilmaril@39: setCursor (Qt::ArrowCursor); insilmaril@39: insilmaril@0: } insilmaril@0: insilmaril@39: void MapEditor::mouseDoubleClickEvent(QMouseEvent* e) insilmaril@39: { insilmaril@39: if (isSelectBlocked() ) insilmaril@39: { insilmaril@39: e->ignore(); insilmaril@39: return; insilmaril@39: } insilmaril@39: insilmaril@39: if (e->button() == Qt::LeftButton ) insilmaril@39: { insilmaril@39: QPointF p = mapToScene(e->pos()); insilmaril@39: LinkableMapObj *lmo=model->findMapObj(p, NULL); insilmaril@0: if (lmo) { // MapObj was found insilmaril@0: // First select the MapObj than edit heading insilmaril@39: xelection.select(lmo); insilmaril@39: mainWindow->editHeading(); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::resizeEvent (QResizeEvent* e) insilmaril@0: { insilmaril@39: QGraphicsView::resizeEvent( e ); insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::dragEnterEvent(QDragEnterEvent *event) insilmaril@39: { insilmaril@39: //for (unsigned int i=0;event->format(i);i++) // Debug mime type insilmaril@39: // cerr << event->format(i) << endl; insilmaril@39: insilmaril@39: if (event->mimeData()->hasImage()) insilmaril@39: event->acceptProposedAction(); insilmaril@39: else insilmaril@39: if (event->mimeData()->hasUrls()) insilmaril@39: event->acceptProposedAction(); insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::dragMoveEvent(QDragMoveEvent *) insilmaril@39: { insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::dragLeaveEvent(QDragLeaveEvent *event) insilmaril@39: { insilmaril@39: event->accept(); insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::dropEvent(QDropEvent *event) insilmaril@39: { insilmaril@39: BranchObj *sel=xelection.getBranch(); insilmaril@39: if (sel) insilmaril@39: { insilmaril@39: if (debug) insilmaril@39: foreach (QString format,event->mimeData()->formats()) insilmaril@39: cout << "MapEditor: Dropped format: "< uris; insilmaril@39: if (event->mimeData()->hasImage()) insilmaril@39: { insilmaril@39: QVariant imageData = event->mimeData()->imageData(); insilmaril@39: addFloatImageInt (qvariant_cast(imageData)); insilmaril@39: } else insilmaril@39: if (event->mimeData()->hasUrls()) insilmaril@39: uris=event->mimeData()->urls(); insilmaril@39: insilmaril@39: if (uris.count()>0) insilmaril@39: { insilmaril@39: QStringList files; insilmaril@39: QString s; insilmaril@39: QString heading; insilmaril@39: BranchObj *bo; insilmaril@39: for (int i=0; iaddBranch(); insilmaril@39: if (bo) insilmaril@39: { insilmaril@39: s=uris.at(i).toLocalFile(); insilmaril@39: if (!s.isEmpty()) insilmaril@39: { insilmaril@39: QString file = QDir::fromNativeSeparators(s); insilmaril@39: heading = QFileInfo(file).baseName(); insilmaril@39: files.append(file); insilmaril@39: if (file.endsWith(".vym", false)) insilmaril@39: bo->setVymLink(file); insilmaril@39: else insilmaril@39: bo->setURL(uris.at(i).toString()); insilmaril@39: } else insilmaril@39: { insilmaril@39: bo->setURL(uris.at(i).toString()); insilmaril@39: } insilmaril@39: insilmaril@39: if (!heading.isEmpty()) insilmaril@39: bo->setHeading(heading); insilmaril@39: else insilmaril@39: bo->setHeading(uris.at(i).toString()); insilmaril@39: } insilmaril@39: } insilmaril@39: } insilmaril@39: model->reposition(); insilmaril@39: } insilmaril@39: } insilmaril@39: event->acceptProposedAction(); insilmaril@39: } insilmaril@39: insilmaril@39: insilmaril@39: void MapEditor::sendSelection() insilmaril@39: { insilmaril@39: if (netstate!=Server) return; insilmaril@39: sendData (QString("select (\"%1\")").arg(xelection.getSelectString()) ); insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::newServer() insilmaril@39: { insilmaril@39: port=54321; insilmaril@39: sendCounter=0; insilmaril@39: tcpServer = new QTcpServer(this); insilmaril@39: if (!tcpServer->listen(QHostAddress::Any,port)) { insilmaril@39: QMessageBox::critical(this, "vym server", insilmaril@39: QString("Unable to start the server: %1.").arg(tcpServer->errorString())); insilmaril@39: close(); insilmaril@39: return; insilmaril@39: } insilmaril@39: connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient())); insilmaril@39: netstate=Server; insilmaril@39: cout<<"Server is running on port "<serverPort()<abort(); insilmaril@39: clientSocket->connectToHost(server ,port); insilmaril@39: connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData())); insilmaril@39: connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)), insilmaril@39: this, SLOT(displayNetworkError(QAbstractSocket::SocketError))); insilmaril@39: netstate=Client; insilmaril@39: cout<<"connected to "<nextPendingConnection(); insilmaril@39: connect(newClient, SIGNAL(disconnected()), insilmaril@39: newClient, SLOT(deleteLater())); insilmaril@39: insilmaril@39: cout <<"ME::newClient at "<peerAddress().toString() )<seek(0); insilmaril@39: quint16 bs=(quint16)(block.size() - 2*sizeof(quint16)); insilmaril@39: out << bs; insilmaril@39: insilmaril@39: if (debug) insilmaril@39: cout << "ME::sendData bs="<peerAddress().toString())<write (block); insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::readData () insilmaril@39: { insilmaril@39: while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) ) insilmaril@39: { insilmaril@39: if (debug) insilmaril@39: cout <<"readData bytesAvail="<bytesAvailable(); insilmaril@39: quint16 recCounter; insilmaril@39: quint16 blockSize; insilmaril@39: insilmaril@39: QDataStream in(clientSocket); insilmaril@39: in.setVersion(QDataStream::Qt_4_0); insilmaril@39: insilmaril@39: in >> blockSize; insilmaril@39: in >> recCounter; insilmaril@39: insilmaril@39: QString t; insilmaril@39: in >>t; insilmaril@39: if (debug) insilmaril@39: cout << " t="<errorString())); insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::autosave() insilmaril@39: { insilmaril@62: if (filePath=="") insilmaril@62: { insilmaril@62: if (debug) cout <<" ME::autosave rejected, no filepath available\n"; insilmaril@62: return; insilmaril@62: } insilmaril@62: insilmaril@39: QDateTime now=QDateTime().currentDateTime(); insilmaril@39: /* FIXME debug insilmaril@39: cout << "ME::autosave checking "<0) return; insilmaril@39: insilmaril@39: // Also disable autosave for new map without filename insilmaril@39: if (filePath.isEmpty()) return; insilmaril@39: insilmaril@39: insilmaril@66: if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() ) insilmaril@39: { insilmaril@39: if (QFileInfo(filePath).lastModified()<=fileChangedTime) insilmaril@39: mainWindow->fileSave (this); insilmaril@39: else insilmaril@39: if (debug) insilmaril@39: cout <<" ME::autosave rejected, file on disk is newer than last save.\n"; insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::fileChanged() insilmaril@39: { insilmaril@39: // Check if file on disk has changed meanwhile insilmaril@39: if (!filePath.isEmpty()) insilmaril@39: { insilmaril@39: QDateTime tmod=QFileInfo (filePath).lastModified(); insilmaril@39: if (tmod>fileChangedTime) insilmaril@39: { insilmaril@39: insilmaril@39: /* FIXME debug message, sometimes there's a glitch in the metrics... insilmaril@39: cout << "ME::fileChanged()\n" insilmaril@39: << " last saved: "<provides("application/x-moz-file-promise-url") && insilmaril@39: event->provides("application/x-moz-nativeimage")) insilmaril@39: { insilmaril@39: // Contains url to the img src in unicode16 insilmaril@39: QByteArray d = event->encodedData("application/x-moz-file-promise-url"); insilmaril@39: QString url = QString((const QChar*)d.data(),d.size()/2); insilmaril@39: fetchImage(url); insilmaril@39: event->accept(); insilmaril@39: update=true; insilmaril@39: } else if (event->provides ("text/uri-list")) insilmaril@39: { // Uris provided e.g. by konqueror insilmaril@39: Q3UriDrag::decode (event,uris); insilmaril@39: } else if (event->provides ("_NETSCAPE_URL")) insilmaril@39: { // Uris provided by Mozilla insilmaril@39: QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL")); insilmaril@39: uris.append(l[0]); insilmaril@39: heading = l[1]; insilmaril@39: } else if (event->provides("text/html")) { insilmaril@39: insilmaril@39: // Handels text mime types insilmaril@39: // Look like firefox allways handle text as unicode16 (2 bytes per char.) insilmaril@39: QByteArray d = event->encodedData("text/html"); insilmaril@39: QString text; insilmaril@39: if (isUnicode16(d)) insilmaril@39: text = QString((const QChar*)d.data(),d.size()/2); insilmaril@39: else insilmaril@39: text = QString(d); insilmaril@39: insilmaril@39: textEditor->setText(text); insilmaril@39: insilmaril@39: event->accept(); insilmaril@39: update=true; insilmaril@39: } else if (event->provides("text/plain")) { insilmaril@39: QByteArray d = event->encodedData("text/plain"); insilmaril@39: QString text; insilmaril@39: if (isUnicode16(d)) insilmaril@39: text = QString((const QChar*)d.data(),d.size()/2); insilmaril@39: else insilmaril@39: text = QString(d); insilmaril@39: insilmaril@39: textEditor->setText(text); insilmaril@39: insilmaril@39: event->accept(); insilmaril@39: update= true; insilmaril@39: } insilmaril@39: insilmaril@39: */ insilmaril@39: insilmaril@39: insilmaril@39: insilmaril@39: bool isUnicode16(const QByteArray &d) insilmaril@39: { insilmaril@39: // TODO: make more precise check for unicode 16. insilmaril@39: // Guess unicode16 if any of second bytes are zero insilmaril@39: unsigned int length = max(0,d.size()-2)/2; insilmaril@39: for (unsigned int i = 0; iaddFloatImage(); insilmaril@39: fio->load(img); insilmaril@39: fio->setOriginalFilename("No original filename (image added by dropevent)"); insilmaril@39: QString s=model->getSelectString(bo); insilmaril@39: saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio ); insilmaril@39: saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image"); insilmaril@39: model->reposition(); insilmaril@39: scene()->update(); insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: /* insilmaril@39: insilmaril@39: void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation * / *nop* /) insilmaril@39: { insilmaril@39: if (!imageBuffer) imageBuffer = new QBuffer(); insilmaril@39: if (!imageBuffer->isOpen()) { insilmaril@39: imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append); insilmaril@39: } insilmaril@39: imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a)); insilmaril@39: } insilmaril@39: insilmaril@39: insilmaril@39: void MapEditor::imageDataFinished(Q3NetworkOperation *nop) insilmaril@39: { insilmaril@39: if (nop->state()==Q3NetworkProtocol::StDone) { insilmaril@39: QPixmap img(imageBuffer->buffer()); insilmaril@39: addFloatImageInt (img); insilmaril@39: } insilmaril@39: insilmaril@39: if (imageBuffer) { insilmaril@39: imageBuffer->close(); insilmaril@39: if (imageBuffer) { insilmaril@39: imageBuffer->close(); insilmaril@39: delete imageBuffer; insilmaril@39: imageBuffer = 0; insilmaril@39: } insilmaril@39: } insilmaril@39: } insilmaril@39: insilmaril@39: void MapEditor::fetchImage(const QString &url) insilmaril@39: { insilmaril@39: if (urlOperator) { insilmaril@39: urlOperator->stop(); insilmaril@39: disconnect(urlOperator); insilmaril@39: delete urlOperator; insilmaril@39: } insilmaril@39: insilmaril@39: urlOperator = new Q3UrlOperator(url); insilmaril@39: connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)), insilmaril@39: this, SLOT(imageDataFinished(Q3NetworkOperation*))); insilmaril@39: insilmaril@39: connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)), insilmaril@39: this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *))); insilmaril@39: urlOperator->get(); insilmaril@39: } insilmaril@39: */ insilmaril@39: