1.1 --- a/mainwindow.cpp Fri Nov 09 12:07:21 2007 +0000
1.2 +++ b/mainwindow.cpp Fri Nov 09 12:07:22 2007 +0000
1.3 @@ -68,6 +68,9 @@
1.4 extern QDir vymBaseDir;
1.5 extern QDir lastImageDir;
1.6 extern QDir lastFileDir;
1.7 +#if defined(Q_OS_WIN32)
1.8 +extern QDir vymInstallDir;
1.9 +#endif
1.10 extern QString iconPath;
1.11 extern QString flagsPath;
1.12
1.13 @@ -79,9 +82,17 @@
1.14 setCaption ("VYM - View Your Mind");
1.15
1.16 // Load window settings
1.17 - resize (settings.value( "/mainwindow/geometry/size",QSize (800,600)).toSize());
1.18 - move (settings.value( "/mainwindow/geometry/pos", QPoint(300,100)).toPoint());
1.19 -
1.20 +#if defined(Q_OS_WIN32)
1.21 + if (settings.value("/mainwindow/geometry/maximized", false).toBool())
1.22 + {
1.23 + showMaximized();
1.24 + }
1.25 + else
1.26 +#endif
1.27 + {
1.28 + resize (settings.value("/mainwindow/geometry/size", QSize (800,600)).toSize());
1.29 + move (settings.value("/mainwindow/geometry/pos", QPoint(300,100)).toPoint());
1.30 + }
1.31
1.32 // Sometimes we may need to remember old selections
1.33 prevSelection="";
1.34 @@ -174,6 +185,8 @@
1.35 #else
1.36 #if defined(Q_OS_MACX)
1.37 s=settings.value (p,"/usr/bin/open").toString();
1.38 + #elif defined(Q_OS_WIN32)
1.39 + s=settings.value (p,"acrord32").toString();
1.40 #else
1.41 s=settings.value (p,"acroread").toString();
1.42 #endif
1.43 @@ -216,8 +229,11 @@
1.44 Main::~Main()
1.45 {
1.46 // Save Settings
1.47 - settings.setValue ( "/mainwindow/geometry/size", size() );
1.48 - settings.setValue ( "/mainwindow/geometry/pos", pos() );
1.49 +#if defined(Q_OS_WIN32)
1.50 + settings.setValue ("/mainwindow/geometry/maximized", isMaximized());
1.51 +#endif
1.52 + settings.setValue ("/mainwindow/geometry/size", size());
1.53 + settings.setValue ("/mainwindow/geometry/pos", pos());
1.54 settings.setValue ("/mainwindow/state",saveState(0));
1.55
1.56 settings.setValue ("/mainwindow/view/AntiAlias",actionViewToggleAntiAlias->isOn());
1.57 @@ -227,6 +243,7 @@
1.58
1.59 settings.setValue( "/mapeditor/autosave/use",actionSettingsAutosaveToggle->isOn() );
1.60 settings.setValue( "/mapeditor/editmode/autoSelectNewBranch",actionSettingsAutoSelectNewBranch->isOn() );
1.61 + settings.setValue( "/mainwindow/writeBackupFile",actionSettingsWriteBackupFile->isOn() );
1.62 settings.setValue( "/mapeditor/editmode/autoSelectText",actionSettingsAutoSelectText->isOn() );
1.63 settings.setValue( "/mapeditor/editmode/autoEditNewBranch",actionSettingsAutoEditNewBranch->isOn() );
1.64 settings.setValue( "/mapeditor/editmode/useDelKey",actionSettingsUseDelKey->isOn() );
1.65 @@ -1389,6 +1406,14 @@
1.66 settingsMenu->addAction (a);
1.67 actionSettingsAutosaveTime=a;
1.68
1.69 + a = new QAction( tr( "Backup file","Settings action"), this);
1.70 + a->setStatusTip( tr( "Write backup file"));
1.71 + a->setToggleAction(true);
1.72 + a->setOn ( settings.value ("/mainwindow/writeBackupFile",false).toBool());
1.73 + connect( a, SIGNAL( triggered() ), this, SLOT( settingsWriteBackupFileToggle() ) );
1.74 + settingsMenu->addAction (a);
1.75 + actionSettingsWriteBackupFile=a;
1.76 +
1.77 settingsMenu->addSeparator();
1.78
1.79 a = new QAction( tr( "Edit branch after adding it","Settings action" ), this );
1.80 @@ -1812,7 +1837,7 @@
1.81
1.82 // Create temporary directory for packing
1.83 bool ok;
1.84 - QString tmpMapDir=makeTmpDir (ok,"vym-pack");
1.85 + QString tmpZipDir=makeTmpDir (ok,"vym-pack");
1.86 if (!ok)
1.87 {
1.88 QMessageBox::critical( 0, tr( "Critical Load Error" ),
1.89 @@ -1821,7 +1846,7 @@
1.90 }
1.91
1.92 // Try to unzip file
1.93 - err=unzipDir (tmpMapDir,fn);
1.94 + err=unzipDir (tmpZipDir,fn);
1.95 if (err==nozip)
1.96 {
1.97 mapfile=fn;
1.98 @@ -1833,22 +1858,22 @@
1.99 // Look for mapname.xml
1.100 mapfile= fn.left(fn.findRev(".",-1,true));
1.101 mapfile=mapfile.section( '/', -1 );
1.102 - QFile file( tmpMapDir + "/" + mapfile + ".xml");
1.103 + QFile file( tmpZipDir + "/" + mapfile + ".xml");
1.104 if (!file.exists() )
1.105 {
1.106 // mapname.xml does not exist, well,
1.107 // maybe someone renamed the mapname.vym file...
1.108 // Try to find any .xml in the toplevel
1.109 // directory of the .vym file
1.110 - QStringList flist=QDir (tmpMapDir).entryList("*.xml");
1.111 + QStringList flist=QDir (tmpZipDir).entryList("*.xml");
1.112 if (flist.count()==1)
1.113 {
1.114 // Only one entry, take this one
1.115 - mapfile=tmpMapDir + "/"+flist.first();
1.116 + mapfile=tmpZipDir + "/"+flist.first();
1.117 } else
1.118 {
1.119 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
1.120 - *it=tmpMapDir + "/" + *it;
1.121 + *it=tmpZipDir + "/" + *it;
1.122 // TODO Multiple entries, load all (but only the first one into this ME)
1.123 //mainWindow->fileLoadFromTmp (flist);
1.124 //returnCode=1; // Silently forget this attempt to load
1.125 @@ -1903,7 +1928,7 @@
1.126 }
1.127
1.128 // Delete tmpDir
1.129 - removeDir (QDir(tmpMapDir));
1.130 + removeDir (QDir(tmpZipDir));
1.131 }
1.132 return err;
1.133 }
1.134 @@ -1976,7 +2001,7 @@
1.135 void Main::fileSave(MapEditor *me, const SaveMode &savemode)
1.136 {
1.137 // tmp dir for zipping
1.138 - QString tmpMapDir;
1.139 + QString tmpZipDir;
1.140
1.141 // Error codes
1.142 ErrorCode err=success;
1.143 @@ -1992,13 +2017,6 @@
1.144 if ( !fn.isEmpty() )
1.145 {
1.146 // We have a filepath, go on saving
1.147 - // First remove existing file, we
1.148 - // don't want to add to old zip archives
1.149 - QFile f(fn);
1.150 - if (f.exists() )
1.151 - if (!f.remove())
1.152 - QMessageBox::warning( 0, tr( "Save Error" ),
1.153 - fn+ tr("\ncould not be removed before saving"));
1.154
1.155 // Look, if we should zip the data:
1.156 if (!saveZipped)
1.157 @@ -2033,11 +2051,33 @@
1.158 me->setZipped (saveZipped);
1.159 }
1.160
1.161 + // First backup existing file, we
1.162 + // don't want to add to old zip archives
1.163 + QFile f(fn);
1.164 + if (f.exists())
1.165 + {
1.166 + if (actionSettingsWriteBackupFile->isOn())
1.167 + {
1.168 + QString bfn(fn + "~");
1.169 + QFile bf(bfn);
1.170 + if (bf.exists() && !bf.remove())
1.171 + {
1.172 + QMessageBox::warning(0, tr("Save Error"),
1.173 + bfn + tr("\ncould not be removed before saving"));
1.174 + }
1.175 + else if (!f.rename(bfn))
1.176 + {
1.177 + QMessageBox::warning(0, tr("Save Error"),
1.178 + fn + tr("\ncould not be renamed before saving"));
1.179 + }
1.180 + }
1.181 + }
1.182 +
1.183 if (saveZipped)
1.184 {
1.185 // Create temporary directory for packing
1.186 bool ok;
1.187 - QString tmpMapDir=makeTmpDir (ok,"vym-zip");
1.188 + tmpZipDir=makeTmpDir (ok,"vym-zip");
1.189 if (!ok)
1.190 {
1.191 QMessageBox::critical( 0, tr( "Critical Load Error" ),
1.192 @@ -2046,13 +2086,13 @@
1.193 }
1.194
1.195 safeFilePath=me->getFilePath();
1.196 - me->setFilePath (tmpMapDir+"/"+
1.197 + me->setFilePath (tmpZipDir+"/"+
1.198 me->getMapName()+ ".xml",
1.199 safeFilePath);
1.200 me->save (savemode);
1.201 me->setFilePath (safeFilePath);
1.202
1.203 - zipDir (tmpMapDir,fn);
1.204 + zipDir (tmpZipDir,fn);
1.205 } // save zipped
1.206 else
1.207 {
1.208 @@ -2074,9 +2114,9 @@
1.209 }
1.210 }
1.211
1.212 - if (saveZipped && !tmpMapDir.isEmpty())
1.213 + if (saveZipped && !tmpZipDir.isEmpty())
1.214 // Delete tmpDir
1.215 - removeDir (QDir(tmpMapDir));
1.216 + removeDir (QDir(tmpZipDir));
1.217
1.218 if (err==success)
1.219 {
1.220 @@ -2399,12 +2439,13 @@
1.221
1.222 void Main::fileCloseMap()
1.223 {
1.224 - if (currentMapEditor())
1.225 + MapEditor *me = currentMapEditor();
1.226 + if (me)
1.227 {
1.228 - if (currentMapEditor()->hasChanged())
1.229 + if (me->hasChanged())
1.230 {
1.231 QMessageBox mb( vymName,
1.232 - tr("The map %1 has been modified but not saved yet. Do you want to").arg(currentMapEditor()->getFileName()),
1.233 + tr("The map %1 has been modified but not saved yet. Do you want to").arg(me->getFileName()),
1.234 QMessageBox::Warning,
1.235 QMessageBox::Yes | QMessageBox::Default,
1.236 QMessageBox::No,
1.237 @@ -2415,7 +2456,7 @@
1.238 {
1.239 case QMessageBox::Yes:
1.240 // save and close
1.241 - fileSave(currentMapEditor(), CompleteMap);
1.242 + fileSave(me, CompleteMap);
1.243 break;
1.244 case QMessageBox::No:
1.245 // close without saving
1.246 @@ -2425,11 +2466,12 @@
1.247 return;
1.248 }
1.249 }
1.250 - currentMapEditor()->closeMap();
1.251 - tabWidget->removePage(currentMapEditor());
1.252 + me->closeMap();
1.253 + tabWidget->removePage(me);
1.254 if (tabWidget->count()==0)
1.255 actionFilePrint->setEnabled (false);
1.256 - }
1.257 + delete me;
1.258 + }
1.259 }
1.260
1.261 void Main::filePrint()
1.262 @@ -2708,7 +2750,7 @@
1.263 bool ok;
1.264 QString s=me->getHeading(ok,p);
1.265
1.266 -#if defined(Q_OS_MACX)
1.267 +#if defined(Q_OS_MACX) || defined(Q_OS_WIN32)
1.268 #else
1.269 if (ok && s!=lineedit->text())
1.270 me->setHeading(lineedit->text());
1.271 @@ -2742,7 +2784,7 @@
1.272 if (ok)
1.273 {
1.274 me->setStateEditHeading (true);
1.275 -#if defined(Q_OS_MACX)
1.276 +#if defined(Q_OS_MACX) || defined(Q_OS_WIN32)
1.277 p=me->mapToGlobal (p);
1.278 QDialog *d =new QDialog(NULL);
1.279 QLineEdit *le=new QLineEdit (d);
1.280 @@ -2803,8 +2845,11 @@
1.281 */
1.282 }
1.283
1.284 +#include "attributedialog.h"
1.285 void Main::editAttribute()
1.286 {
1.287 + AttributeDialog dia;
1.288 + dia.exec();
1.289 /*
1.290 if (currentMapEditor())
1.291 {
1.292 @@ -3192,25 +3237,37 @@
1.293 void Main::formatLinkStyleLine()
1.294 {
1.295 if (currentMapEditor())
1.296 + {
1.297 currentMapEditor()->setMapLinkStyle("StyleLine");
1.298 + actionFormatLinkStyleLine->setOn(true);
1.299 + }
1.300 }
1.301
1.302 void Main::formatLinkStyleParabel()
1.303 {
1.304 if (currentMapEditor())
1.305 + {
1.306 currentMapEditor()->setMapLinkStyle("StyleParabel");
1.307 + actionFormatLinkStyleParabel->setOn(true);
1.308 + }
1.309 }
1.310
1.311 void Main::formatLinkStylePolyLine()
1.312 {
1.313 if (currentMapEditor())
1.314 + {
1.315 currentMapEditor()->setMapLinkStyle("StylePolyLine");
1.316 + actionFormatLinkStylePolyLine->setOn(true);
1.317 + }
1.318 }
1.319
1.320 void Main::formatLinkStylePolyParabel()
1.321 {
1.322 if (currentMapEditor())
1.323 + {
1.324 currentMapEditor()->setMapLinkStyle("StylePolyParabel");
1.325 + actionFormatLinkStylePolyParabel->setOn(true);
1.326 + }
1.327 }
1.328
1.329 void Main::formatSelectBackColor()
1.330 @@ -3328,8 +3385,7 @@
1.331
1.332 void Main::settingsMacroDir()
1.333 {
1.334 - QDir defdir=vymBaseDir;
1.335 - defdir.cd("macros");
1.336 + QDir defdir(vymBaseDir.path() + "/macros");
1.337 if (!defdir.exists())
1.338 defdir=vymBaseDir;
1.339 QDir dir=QFileDialog::getExistingDirectory (
1.340 @@ -3338,7 +3394,7 @@
1.341 settings.value ("/macros/macroDir",defdir.path()).toString()
1.342 );
1.343 if (dir.exists())
1.344 - settings.setValue ("/macros/macroDir",dir.path());
1.345 + settings.setValue ("/macros/macroDir",dir.absolutePath());
1.346 }
1.347
1.348 void Main::settingsUndoLevels()
1.349 @@ -3374,6 +3430,11 @@
1.350 }
1.351 }
1.352
1.353 +void Main::settingsWriteBackupFileToggle()
1.354 +{
1.355 + settings.setValue ("/mapeditor/writeBackupFile",actionSettingsWriteBackupFile->isOn() );
1.356 +}
1.357 +
1.358 void Main::settingsToggleDelKey()
1.359 {
1.360 if (actionSettingsUseDelKey->isOn())
1.361 @@ -3763,12 +3824,14 @@
1.362 QDir docdir;
1.363 #if defined(Q_OS_MACX)
1.364 searchList << "./vym.app/Contents/Resources/doc";
1.365 + #elif defined(Q_OS_WIN32)
1.366 + searchList << vymInstallDir.path() + "/share/doc/packages/vym";
1.367 #else
1.368 #if defined(VYM_DOCDIR)
1.369 searchList << VYM_DOCDIR;
1.370 #endif
1.371 // default path in SUSE LINUX
1.372 - searchList <<"/usr/share/doc/packages/vym";
1.373 + searchList << "/usr/share/doc/packages/vym";
1.374 #endif
1.375
1.376 searchList << "doc"; // relative path for easy testing in tarball
1.377 @@ -3780,14 +3843,14 @@
1.378 QFile docfile;
1.379 for (int i=0; i<searchList.count(); ++i)
1.380 {
1.381 - docfile.setFileName(QDir::convertSeparators(searchList.at(i)+"/"+docname));
1.382 - if (docfile.exists() )
1.383 + docfile.setFileName(searchList.at(i)+"/"+docname);
1.384 + if (docfile.exists())
1.385 {
1.386 found=true;
1.387 break;
1.388 }
1.389 -
1.390 }
1.391 +
1.392 if (!found)
1.393 {
1.394 QMessageBox::critical(0,
1.395 @@ -3798,7 +3861,7 @@
1.396
1.397 QStringList args;
1.398 Process *pdfProc = new Process();
1.399 - args <<docfile.fileName();
1.400 + args << QDir::toNativeSeparators(docfile.fileName());
1.401
1.402 pdfProc->start( settings.value("/mainwindow/readerPDF").toString(),args);
1.403 if ( !pdfProc->waitForStarted() )