1.1 --- a/mapeditor.cpp Thu Sep 22 12:56:05 2005 +0000
1.2 +++ b/mapeditor.cpp Mon Oct 10 11:20:25 2005 +0000
1.3 @@ -37,35 +37,15 @@
1.4 #include "editxlinkdialog.h"
1.5 #include "settings.h"
1.6
1.7 -#include "icons/flag-note.xpm"
1.8 -#include "icons/flag-url.xpm"
1.9 -#include "icons/flag-vymlink.xpm"
1.10 -#include "icons/flag-scrolled-right.xpm"
1.11 -#include "icons/flag-tmpUnscrolled-right.xpm"
1.12 -#include "icons/flag-questionmark.xpm"
1.13 -#include "icons/flag-exclamationmark.xpm"
1.14 -#include "icons/flag-hook-green.xpm"
1.15 -#include "icons/flag-cross-red.xpm"
1.16 -#include "icons/flag-stopsign.xpm"
1.17 -#include "icons/flag-smiley-good.xpm"
1.18 -#include "icons/flag-smiley-sad.xpm"
1.19 -#include "icons/flag-clock.xpm"
1.20 -#include "icons/flag-lamp.xpm"
1.21 -#include "icons/flag-arrow-up.xpm"
1.22 -#include "icons/flag-arrow-down.xpm"
1.23 -#include "icons/flag-thumb-up.xpm"
1.24 -#include "icons/flag-thumb-down.xpm"
1.25 -#include "icons/flag-heart.xpm"
1.26 -#include "icons/flag-flash.xpm"
1.27 -#include "icons/flag-lifebelt.xpm"
1.28
1.29 extern TextEditor *textEditor;
1.30 extern int statusbarTime;
1.31 extern Main *mainWindow;
1.32 extern QString tmpVymDir;
1.33 +extern QString clipboardDir;
1.34 +extern bool clipboardEmpty;
1.35 extern FlagRowObj *systemFlagsDefault;
1.36 extern FlagRowObj *standardFlagsDefault;
1.37 -extern MapEditor *clipboardME;
1.38
1.39 extern QPtrList <QAction> actionListBranches;
1.40
1.41 @@ -155,6 +135,7 @@
1.42
1.43 mapCanvas = new QCanvas(1000,800);
1.44 mapCanvas->setAdvancePeriod(30);
1.45 + mapCanvas->setBackgroundColor (white);
1.46
1.47 setCanvas (mapCanvas);
1.48
1.49 @@ -162,147 +143,11 @@
1.50 setVScrollBarMode ( QScrollView::AlwaysOn );
1.51 setHScrollBarMode ( QScrollView::AlwaysOn );
1.52
1.53 - // Now create the _global_ system flags _once_:
1.54 - // (Later all OrnamentedObj copy from this
1.55 - // and set their own canvas)
1.56 - if (!systemFlagsDefault)
1.57 - {
1.58 - systemFlagsDefault = new FlagRowObj (mapCanvas);
1.59 - systemFlagsDefault->setVisibility (false);
1.60 - systemFlagsDefault->setName ("systemFlagsDef");
1.61 -
1.62 - FlagObj *fo = new FlagObj (mapCanvas);
1.63 - fo->load(QPixmap(flag_note_xpm));
1.64 - fo->setName("note");
1.65 - fo->setToolTip(tr("Note","Systemflag"));
1.66 - systemFlagsDefault->addFlag (fo); // makes deep copy
1.67 -
1.68 - fo->load(QPixmap(flag_url_xpm));
1.69 - fo->setName("url");
1.70 - fo->setToolTip(tr("WWW Document (external)","Systemflag"));
1.71 - systemFlagsDefault->addFlag (fo);
1.72 -
1.73 - fo->load(QPixmap(flag_vymlink_xpm));
1.74 - fo->setName("vymLink");
1.75 - fo->setToolTip(tr("Link to another vym map","Systemflag"));
1.76 - systemFlagsDefault->addFlag (fo);
1.77 -
1.78 - fo->load(QPixmap(flag_scrolled_right_xpm));
1.79 - fo->setName("scrolledright");
1.80 - fo->setToolTip(tr("subtree is scrolled","Systemflag"));
1.81 - systemFlagsDefault->addFlag (fo);
1.82 -
1.83 - fo->load(QPixmap(flag_tmpUnscrolled_right_xpm));
1.84 - fo->setName("tmpUnscrolledright");
1.85 - fo->setToolTip(tr("subtree is temporary scrolled","Systemflag"));
1.86 - systemFlagsDefault->addFlag (fo);
1.87 - delete (fo);
1.88 - }
1.89 - if (!standardFlagsDefault)
1.90 - {
1.91 - standardFlagsDefault = new FlagRowObj (mapCanvas);
1.92 - standardFlagsDefault->setVisibility (false);
1.93 - standardFlagsDefault->setName ("standardFlagsDef");
1.94 -
1.95 - FlagObj *fo = new FlagObj (mapCanvas);
1.96 - fo->load(QPixmap(flag_exclamationmark_xpm));
1.97 - fo->setName ("exclamationmark");
1.98 - fo->setGroup("standard-mark");
1.99 - fo->setToolTip(tr("Take care!","Standardflag"));
1.100 - standardFlagsDefault->addFlag (fo); // makes deep copy
1.101 -
1.102 - fo->load(QPixmap(flag_questionmark_xpm));
1.103 - fo->setName("questionmark");
1.104 - fo->setGroup("standard-mark");
1.105 - fo->setToolTip(tr("Really?","Standardflag"));
1.106 - standardFlagsDefault->addFlag (fo);
1.107 -
1.108 - fo->load(QPixmap(flag_hook_green_xpm));
1.109 - fo->setName("hook-green");
1.110 - fo->setGroup("standard-hook");
1.111 - fo->setToolTip(tr("ok!","Standardflag"));
1.112 - standardFlagsDefault->addFlag (fo);
1.113 -
1.114 - fo->load(QPixmap(flag_cross_red_xpm));
1.115 - fo->setName("cross-red");
1.116 - fo->setGroup("standard-hook");
1.117 - fo->setToolTip(tr("Not ok!","Standardflag"));
1.118 - standardFlagsDefault->addFlag (fo);
1.119 -
1.120 - fo->load(QPixmap(flag_stopsign_xpm));
1.121 - fo->setName("stopsign");
1.122 - fo->setToolTip(tr("This won't work!","Standardflag"));
1.123 - standardFlagsDefault->addFlag (fo);
1.124 -
1.125 - fo->load(QPixmap(flag_smiley_good_xpm));
1.126 - fo->setName("smiley-good");
1.127 - fo->setGroup("standard-smiley");
1.128 - fo->setToolTip(tr("Good","Standardflag"));
1.129 - standardFlagsDefault->addFlag (fo);
1.130 -
1.131 - fo->load(QPixmap(flag_smiley_sad_xpm));
1.132 - fo->setName("smiley-sad");
1.133 - fo->setGroup("standard-smiley");
1.134 - fo->setToolTip(tr("Bad","Standardflag"));
1.135 - standardFlagsDefault->addFlag (fo);
1.136 -
1.137 - fo->load(QPixmap(flag_clock_xpm));
1.138 - fo->setName("clock");
1.139 - fo->setToolTip(tr("Time critical","Standardflag"));
1.140 - standardFlagsDefault->addFlag (fo);
1.141 -
1.142 - fo->load(QPixmap(flag_lamp_xpm));
1.143 - fo->setName("lamp");
1.144 - fo->setToolTip(tr("Idea!","Standardflag"));
1.145 - standardFlagsDefault->addFlag (fo);
1.146 -
1.147 - fo->load(QPixmap(flag_arrow_up_xpm));
1.148 - fo->setName("arrow-up");
1.149 - fo->setGroup("standard-arrow");
1.150 - fo->setToolTip(tr("Important","Standardflag"));
1.151 - standardFlagsDefault->addFlag (fo);
1.152 -
1.153 - fo->load(QPixmap(flag_arrow_down_xpm));
1.154 - fo->setName("arrow-down");
1.155 - fo->setGroup("standard-arrow");
1.156 - fo->setToolTip(tr("Unimportant","Standardflag"));
1.157 - standardFlagsDefault->addFlag (fo);
1.158 -
1.159 - fo->load(QPixmap(flag_thumb_up_xpm));
1.160 - fo->setName("thumb-up");
1.161 - fo->setGroup("standard-thumb");
1.162 - fo->setToolTip(tr("I like this","Standardflag"));
1.163 - standardFlagsDefault->addFlag (fo);
1.164 -
1.165 - fo->load(QPixmap(flag_thumb_down_xpm));
1.166 - fo->setName("thumb-down");
1.167 - fo->setGroup("standard-thumb");
1.168 - fo->setToolTip(tr("I like this","Standardflag"));
1.169 - fo->setToolTip(tr("I do not like this","Standardflag"));
1.170 - standardFlagsDefault->addFlag (fo);
1.171 -
1.172 - fo->load(QPixmap(flag_heart_xpm));
1.173 - fo->setName("heart");
1.174 - fo->setToolTip(tr("I just love... ","Standardflag"));
1.175 - standardFlagsDefault->addFlag (fo);
1.176 -
1.177 - fo->load(QPixmap(flag_flash_xpm));
1.178 - fo->setName("flash");
1.179 - fo->setToolTip(tr("Dangerous","Standardflag"));
1.180 - standardFlagsDefault->addFlag (fo);
1.181 -
1.182 - fo->load(QPixmap(flag_lifebelt_xpm));
1.183 - fo->setName("lifebelt");
1.184 - fo->setToolTip(tr("This will help","Standardflag"));
1.185 - standardFlagsDefault->addFlag (fo);
1.186 - delete (fo);
1.187 -
1.188 - }
1.189 -
1.190 mapCenter = new MapCenterObj(mapCanvas);
1.191 mapCenter->setVisibility (true);
1.192 mapCenter->setMapEditor (this);
1.193 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
1.194 + mapCenter->move(mapCanvas->width()/2-mapCenter->width()/2,mapCanvas->height()/2-mapCenter->width()/2);
1.195
1.196 printer=NULL;
1.197
1.198 @@ -315,7 +160,6 @@
1.199 defXLinkColor=QColor (180,180,180);
1.200 linkcolorhint=DefaultColor;
1.201 linkstyle=StylePolyParabel;
1.202 - mapCanvas->setBackgroundColor (white);
1.203
1.204 // Create bitmap cursors, patform dependant
1.205 #if defined(Q_OS_MACX)
1.206 @@ -468,6 +312,7 @@
1.207 mapCanvas->resize (cw,ch);
1.208 if ( (dx!=0) || (dy!=0) )
1.209 {
1.210 + cout << "ME:: canvas="<<cw<<","<<ch<<endl;
1.211 mapCenter->moveAllBy(dx,dy);
1.212 mapCenter->reposition();
1.213
1.214 @@ -495,16 +340,6 @@
1.215 removeDir (QDir(tmpMapDir));
1.216 }
1.217
1.218 -
1.219 -void MapEditor::makeSubDirs(const QString &s)
1.220 -{
1.221 - QDir d(s);
1.222 - d.mkdir(s);
1.223 - d.mkdir ("images");
1.224 - d.mkdir ("flags");
1.225 -}
1.226 -
1.227 -
1.228 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSelection)
1.229 {
1.230 // tmpdir temporary directory to which data will be written
1.231 @@ -512,8 +347,6 @@
1.232 // writeflags Only write flags for "real" save of map, not undo
1.233 // offset offset of bbox of whole map in canvas.
1.234 // Needed for XML export
1.235 - // completeMap if false, only vympart will be written, without
1.236 - // mapcenter
1.237
1.238 // Save Header
1.239 QString ls;
1.240 @@ -555,6 +388,9 @@
1.241 // Find the used flags while traversing the tree
1.242 standardFlagsDefault->resetUsedCounter();
1.243
1.244 + // Reset the counters before saving
1.245 + FloatImageObj (mapCanvas).resetSaveCounter();
1.246 +
1.247 // Build xml recursivly
1.248 if (!saveSelection)
1.249 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
1.250 @@ -562,8 +398,10 @@
1.251 {
1.252 if ( typeid(*saveSelection) == typeid(BranchObj) )
1.253 s+=((BranchObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
1.254 - else
1.255 - if (selection && typeid(*selection)==typeid(BranchObj))
1.256 + else if ( typeid(*saveSelection) == typeid(FloatImageObj) )
1.257 + s+=((FloatImageObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
1.258 +
1.259 + else if (selection && typeid(*selection)==typeid(BranchObj))
1.260 // This is used if selected branch is saved from mainwindow
1.261 s+=((BranchObj*)selection)->saveToDir(tmpdir,prefix,offset);
1.262 }
1.263 @@ -921,7 +759,7 @@
1.264 return destPath;
1.265 }
1.266
1.267 -int MapEditor::load (QString &fname, const LoadMode &lmode)
1.268 +int MapEditor::load (QString fname, LoadMode lmode)
1.269 {
1.270 // Finish open lineEdits
1.271 if (lineedit) finishedLineEditNoSave();
1.272 @@ -1394,59 +1232,27 @@
1.273
1.274 if (selection)
1.275 {
1.276 - if (typeid(*selection) == typeid(BranchObj) )
1.277 + // write to directory
1.278 + QString clipfile="part";
1.279 + QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPoint(),selection);
1.280 + QFile file;
1.281 +
1.282 + file.setName ( clipboardDir + "/"+clipfile+".xml");
1.283 + if ( !file.open( IO_WriteOnly ) )
1.284 {
1.285 - BranchObj* to;
1.286 - BranchObj* from;
1.287 - clipboardME->clear();
1.288 - clipboardME->getMapCenter()->addBranch();
1.289 - to=clipboardME->getMapCenter()->getLastBranch();
1.290 - if (to)
1.291 - {
1.292 - from=(BranchObj*)selection;
1.293 - to->copy(from);
1.294 -
1.295 - // keep position relative to parent
1.296 - to->move2RelPos ( from->getRelPos());
1.297 -
1.298 - // select data in clipboard
1.299 - // clipboardME->select ("bo:0");
1.300 -
1.301 - // repositioning makes testing nicer,
1.302 - // but is not needed usually:
1.303 - if (clipboardME->isVisible())
1.304 - clipboardME->getMapCenter()->reposition();
1.305 - else
1.306 - clipboardME->hide();
1.307 - }
1.308 - }
1.309 - /* FIXME rewrite this using import/export
1.310 - Currently there is a bug which would erase note, if
1.311 - branchobj in clipboard is selected...
1.312 - if (typeid(*selection) == typeid(FloatImageObj) )
1.313 - {
1.314 - FloatImageObj* to;
1.315 - FloatImageObj* from;
1.316 - clipboardME->clear();
1.317 - clipboardME->getMapCenter()->addFloatImage();
1.318 - to=clipboardME->getMapCenter()->getLastFloatImage();
1.319 - if (to)
1.320 - {
1.321 - from=(FloatImageObj*)selection;
1.322 - to->copy(from);
1.323 -
1.324 - // select data in clipboard
1.325 - clipboardME->select ("fi:0");
1.326 -
1.327 - // repositioning makes testing nicer,
1.328 - // but is not needed usually:
1.329 - if (clipboardME->isVisible())
1.330 - clipboardME->getMapCenter()->reposition();
1.331 - else
1.332 - clipboardME->hide();
1.333 - }
1.334 - }
1.335 - */
1.336 + // This should neverever happen
1.337 + QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1.338 + return;
1.339 + }
1.340 +
1.341 + // Write it finally, and write in UTF8, no matter what
1.342 + QTextStream ts( &file );
1.343 + ts.setEncoding (QTextStream::UnicodeUTF8);
1.344 + ts << saveFile;
1.345 + file.close();
1.346 +
1.347 + clipboardEmpty=false;
1.348 + updateActions();
1.349 }
1.350 }
1.351
1.352 @@ -1618,74 +1424,30 @@
1.353 }
1.354 }
1.355
1.356 -LinkableMapObj* MapEditor::pasteNoSave()
1.357 +void MapEditor::pasteNoSave()
1.358 {
1.359 // Finish open lineEdits
1.360 if (lineedit) finishedLineEditNoSave();
1.361
1.362 - clipboardME->select ("bo:0");
1.363 - LinkableMapObj *fromLMO=clipboardME->getSelection();
1.364 - LinkableMapObj *returnLMO=NULL;
1.365 -
1.366 - if (selection && fromLMO)
1.367 - {
1.368 - if (typeid(*fromLMO) == typeid(BranchObj) )
1.369 - {
1.370 - if (typeid(*selection) == typeid(MapCenterObj))
1.371 - {
1.372 - returnLMO=mapCenter->addBranch( (BranchObj*)(fromLMO) );
1.373 - ((BranchObj*)(returnLMO))->move2RelPos(normalise(fromLMO->getRelPos() ) );
1.374 - }
1.375 - if (typeid(*selection) == typeid(BranchObj))
1.376 - returnLMO=((BranchObj*)selection)->addBranch((BranchObj*)(fromLMO) );
1.377 - }
1.378 -
1.379 - if (typeid(*fromLMO) == typeid(FloatImageObj) &&
1.380 - (typeid(*selection) == typeid (BranchObj) ||
1.381 - typeid(*selection)==typeid(MapCenterObj)) )
1.382 - returnLMO=((BranchObj*) selection)->addFloatImage ((FloatImageObj*)(fromLMO));
1.383 -
1.384 - }
1.385 - return returnLMO;
1.386 + load (clipboardDir+"/part.xml",ImportAdd);
1.387 }
1.388
1.389 void MapEditor::cutNoSave()
1.390 {
1.391 - // Finish open lineEdits
1.392 - if (lineedit) finishedLineEditNoSave();
1.393 -
1.394 - BranchObj* bo;
1.395 - BranchObj* par;
1.396 - if (selection != NULL) {
1.397 - if (typeid(*selection) == typeid(BranchObj) )
1.398 - {
1.399 - bo=(BranchObj*)selection;
1.400 - par=(BranchObj*)(bo->getParObj());
1.401 - bo->unselect();
1.402 - selection=NULL;
1.403 - par->removeBranch(bo);
1.404 - selection=par;
1.405 - selection->select();
1.406 - }
1.407 - if (typeid(*selection) == typeid(FloatImageObj) )
1.408 - {
1.409 - FloatImageObj* fio=(FloatImageObj*)selection;
1.410 - par=(BranchObj*)(fio->getParObj());
1.411 - fio->unselect();
1.412 - selection=NULL;
1.413 - par->removeFloatImage(fio);
1.414 - selection=par;
1.415 - selection->select();
1.416 - }
1.417 - }
1.418 + copy();
1.419 + deleteSelection();
1.420 }
1.421
1.422 void MapEditor::paste()
1.423 {
1.424 - saveState(selection);
1.425 - pasteNoSave();
1.426 - mapCenter->reposition();
1.427 - adjustCanvasSize();
1.428 + if (selection && (typeid(*selection) == typeid(BranchObj) ||
1.429 + typeid(*selection) == typeid(MapCenterObj)))
1.430 + {
1.431 + saveState(selection);
1.432 + pasteNoSave();
1.433 + mapCenter->reposition();
1.434 + adjustCanvasSize();
1.435 + }
1.436 }
1.437
1.438 void MapEditor::cut()
1.439 @@ -2807,7 +2569,7 @@
1.440
1.441 actionEditCopy->setEnabled (true);
1.442 actionEditCut->setEnabled (true);
1.443 - if (clipboardME->getMapCenter()->countBranches()>0 || clipboardME->getMapCenter()->countFloatImages()>0)
1.444 + if (!clipboardEmpty)
1.445 actionEditPaste->setEnabled (true);
1.446 else
1.447 actionEditPaste->setEnabled (false);
1.448 @@ -3247,8 +3009,7 @@
1.449 void MapEditor::testFunction()
1.450 {
1.451 cout << "MapEditor::testFunction() called\n";
1.452 - QDir d("/fasl");
1.453 - removeDir (d);
1.454 + load (clipboardDir+"/part.xml",ImportAdd);
1.455 }
1.456
1.457 void MapEditor::ensureSelectionVisible()
1.458 @@ -3681,7 +3442,7 @@
1.459 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum());
1.460 } else
1.461 if (e->state() & QMouseEvent::ControlButton)
1.462 - {
1.463 + {
1.464 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum()+1);
1.465 } else
1.466 {
1.467 @@ -3731,9 +3492,6 @@
1.468 void MapEditor::resizeEvent (QResizeEvent* e)
1.469 {
1.470 QCanvasView::resizeEvent( e );
1.471 -
1.472 - QString s="";
1.473 - if (!fileName.isEmpty()) s=fileName;
1.474 adjustCanvasSize();
1.475 }
1.476