mainwindow.cpp
changeset 473 8b9cfc26638c
parent 450 beb875135811
child 486 9c86935835a4
     1.1 --- a/mainwindow.cpp	Wed Apr 25 16:02:54 2007 +0000
     1.2 +++ b/mainwindow.cpp	Wed Apr 25 16:02:54 2007 +0000
     1.3 @@ -98,6 +98,9 @@
     1.4  	// Initialize properties window
     1.5  	branchPropertyWindow = new BranchPropertyWindow();
     1.6  	branchPropertyWindow->move (20,20);
     1.7 +	branchPropertyWindow->resize (settings.value( "/branchpropertywindow/geometry/size",QSize (150,100)).toSize());
     1.8 +	branchPropertyWindow->move   (settings.value( "/branchpropertywindow/geometry/pos", QPoint(20,20)).toPoint());
     1.9 +
    1.10  
    1.11  	// Initialize script editor
    1.12  	scriptEditor = new SimpleScriptEditor();
    1.13 @@ -201,12 +204,12 @@
    1.14  	settings.setValue( "/mapeditor/editmode/useFlagGroups",actionSettingsUseFlagGroups->isOn() );
    1.15  	settings.setValue( "/export/useHideExport",actionSettingsUseHideExport->isOn() );
    1.16  
    1.17 -	//FIXME save branchPropWindow settings
    1.18 -	//FIXME save scriptEditor settings
    1.19 +	//TODO save scriptEditor settings
    1.20  
    1.21  	// call the destructors
    1.22  	delete textEditor;
    1.23  	delete historyWindow;
    1.24 +	delete branchPropertyWindow;
    1.25  
    1.26  	// Remove temporary directory
    1.27  	removeDir (QDir(tmpVymDir));
    1.28 @@ -361,7 +364,7 @@
    1.29  
    1.30      a = new QAction( QPixmap(iconPath+"fileclose.png"), tr( "&Close Map","File menu" ), this);
    1.31  	a->setStatusTip (tr( "Close Map" ) );
    1.32 -	a->setShortcut (Qt::ALT + Qt::Key_C );			//Close map
    1.33 +	a->setShortcut (Qt::CTRL + Qt::Key_W );			//Close map
    1.34  	fileMenu->addAction (a);
    1.35      connect( a, SIGNAL( triggered() ), this, SLOT( fileCloseMap() ) );
    1.36  
    1.37 @@ -580,10 +583,10 @@
    1.38  	addAction (alt);
    1.39  	actionListBranches.append(actionEditToggleScroll);
    1.40  	
    1.41 -    a = new QAction( tr( "Unscroll all scrolled branches","Edit menu" ), this);
    1.42 -	a->setStatusTip (tr( "Unscroll all" ));
    1.43 +    a = new QAction( tr( "Unscroll childs","Edit menu" ), this);
    1.44 +	a->setStatusTip (tr( "Unscroll all scrolled branches in selected subtree" ));
    1.45  	editMenu->addAction (a);
    1.46 -    connect( a, SIGNAL( triggered() ), this, SLOT( editUnScrollAll() ) );
    1.47 +    connect( a, SIGNAL( triggered() ), this, SLOT( editUnscrollChilds() ) );
    1.48  	
    1.49  	editMenu->addSeparator();
    1.50  
    1.51 @@ -785,13 +788,13 @@
    1.52      connect( a, SIGNAL( triggered() ), this, SLOT( editLoadImage() ) );
    1.53  	actionEditLoadImage=a;
    1.54  
    1.55 -    a = new QAction( tr( "Property Dialog","Dialog to edit properties of selection" )+QString ("..."), this);
    1.56 +    a = new QAction( tr( "Property window","Dialog to edit properties of selection" )+QString ("..."), this);
    1.57  	a->setStatusTip (tr( "Set properties for selection" ));
    1.58  	a->setShortcut ( Qt::CTRL + Qt::Key_I );		//Property window
    1.59  	a->setShortcutContext (Qt::WindowShortcut);
    1.60  	addAction (a);
    1.61 -    connect( a, SIGNAL( triggered() ), this, SLOT( showPropertyDialog() ) );
    1.62 -	actionTogglePropertyDialog=a;
    1.63 +    connect( a, SIGNAL( triggered() ), this, SLOT( windowToggleProperty() ) );
    1.64 +	actionTogglePropertyWindow=a;
    1.65  }
    1.66  
    1.67  // Format Actions
    1.68 @@ -869,18 +872,6 @@
    1.69  	formatMenu->addAction (a);
    1.70  	actionFormatLinkStylePolyParabel=a;
    1.71  	
    1.72 -    a = new QAction( tr( "Include images vertically","Branch attribute" ),  this);
    1.73 -	a->setStatusTip ( tr ("Include top and bottom position of images into branch"));
    1.74 -	a->setToggleAction(true);
    1.75 -    connect( a, SIGNAL( triggered() ), this, SLOT( formatIncludeImagesVer() ) );
    1.76 -	actionFormatIncludeImagesVer=a;
    1.77 -
    1.78 -    a = new QAction( tr( "Include images horizontally","Branch attribute" ),  this);
    1.79 -	a->setStatusTip ( tr ("Include left and right position of images into branch"));
    1.80 -	a->setToggleAction(true);
    1.81 -    connect( a, SIGNAL( triggered() ), this, SLOT( formatIncludeImagesHor() ) );
    1.82 -	actionFormatIncludeImagesHor=a;
    1.83 -
    1.84      a = new QAction( tr( "Hide link if object is not selected","Branch attribute" ), this);
    1.85  	a->setStatusTip (tr( "Hide link" ));
    1.86  	a->setToggleAction(true);
    1.87 @@ -974,7 +965,7 @@
    1.88      connect( a, SIGNAL( triggered() ), this, SLOT(windowToggleHistory() ) );
    1.89  	actionViewToggleHistoryWindow=a;
    1.90  
    1.91 -	viewMenu->addAction (actionTogglePropertyDialog );
    1.92 +	viewMenu->addAction (actionTogglePropertyWindow);
    1.93  
    1.94      a = new QAction(tr( "Antialiasing","View action" ),this );
    1.95  	a->setStatusTip ( tr( "Antialiasing" ));
    1.96 @@ -992,13 +983,13 @@
    1.97      connect( a, SIGNAL( triggered() ), this, SLOT(windowToggleSmoothPixmap() ) );
    1.98  	actionViewToggleSmoothPixmapTransform=a;
    1.99  
   1.100 -    a = new QAction(tr( "Next Window","View action" ), this);
   1.101 +    a = new QAction(tr( "Next Map","View action" ), this);
   1.102  	a->setStatusTip (a->text());
   1.103  	a->setShortcut (Qt::ALT + Qt::Key_N );
   1.104  	viewMenu->addAction (a);
   1.105      connect( a, SIGNAL( triggered() ), this, SLOT(windowNextEditor() ) );
   1.106  
   1.107 -    a = new QAction (tr( "Previous Window","View action" ), this );
   1.108 +    a = new QAction (tr( "Previous Map","View action" ), this );
   1.109  	a->setStatusTip (a->text());
   1.110  	a->setShortcut (Qt::ALT + Qt::Key_P );
   1.111  	viewMenu->addAction (a);
   1.112 @@ -1375,12 +1366,34 @@
   1.113      connect( a, SIGNAL( triggered() ), this, SLOT( settingsURL() ) );
   1.114  	settingsMenu->addAction (a);
   1.115  
   1.116 -    a = new QAction( tr( "Set path for macros","Settings action"), this);
   1.117 +    a = new QAction( tr( "Set path for macros","Settings action")+"...", this);
   1.118      a->setStatusTip( tr( "Set path for macros"));
   1.119      connect( a, SIGNAL( triggered() ), this, SLOT( settingsMacroDir() ) );
   1.120  	settingsMenu->addAction (a);
   1.121  
   1.122 +    a = new QAction( tr( "Set number of undo levels","Settings action")+"...", this);
   1.123 +    a->setStatusTip( tr( "Set number of undo levels"));
   1.124 +    connect( a, SIGNAL( triggered() ), this, SLOT( settingsUndoLevels() ) );
   1.125 +	settingsMenu->addAction (a);
   1.126 +
   1.127  	settingsMenu->addSeparator();
   1.128 +
   1.129 +    a = new QAction( tr( "Autosave","Settings action"), this);
   1.130 +    a->setStatusTip( tr( "Autosave"));
   1.131 +	a->setToggleAction(true);
   1.132 +	a->setOn ( settings.value ("/mapeditor/autosave/use",true).toBool());
   1.133 +    connect( a, SIGNAL( triggered() ), this, SLOT( settingsAutosaveToggle() ) );
   1.134 +	settingsMenu->addAction (a);
   1.135 +	actionSettingsAutosaveToggle=a;
   1.136 +
   1.137 +    a = new QAction( tr( "Autosave time","Settings action")+"...", this);
   1.138 +    a->setStatusTip( tr( "Autosave time"));
   1.139 +    connect( a, SIGNAL( triggered() ), this, SLOT( settingsAutosaveTime() ) );
   1.140 +	settingsMenu->addAction (a);
   1.141 +	actionSettingsAutosaveTime=a;
   1.142 +
   1.143 +	settingsMenu->addSeparator();
   1.144 +
   1.145      a = new QAction( tr( "Edit branch after adding it","Settings action" ), this );
   1.146      a->setStatusTip( tr( "Edit branch after adding it" ));
   1.147  	a->setToggleAction(true);
   1.148 @@ -1472,7 +1485,7 @@
   1.149  
   1.150  	// Context Menu for branch or mapcenter
   1.151  	branchContextMenu =new QMenu (this);
   1.152 -	branchContextMenu->addAction (actionTogglePropertyDialog);
   1.153 +	branchContextMenu->addAction (actionTogglePropertyWindow);
   1.154  	branchContextMenu->addSeparator();	
   1.155  
   1.156  		// Submenu "Add"
   1.157 @@ -1498,14 +1511,12 @@
   1.158  
   1.159  	branchContextMenu->addSeparator();	
   1.160  	branchContextMenu->addAction ( actionEditLoadImage);
   1.161 -	branchContextMenu->addAction ( actionFormatIncludeImagesVer );
   1.162 -	branchContextMenu->addAction ( actionFormatIncludeImagesHor );
   1.163  
   1.164  	// Submenu for Links (URLs, vymLinks)
   1.165  	branchLinksContextMenu =new QMenu (this);
   1.166  
   1.167  		branchContextMenu->addSeparator();	
   1.168 -		branchLinksContextMenu=branchContextMenu->addMenu(tr("URLs and vymLinks","Context menu name"));	
   1.169 +		branchLinksContextMenu=branchContextMenu->addMenu(tr("References (URLs, vymLinks, ...)","Context menu name"));	
   1.170  		branchLinksContextMenu->addAction ( actionEditOpenURL );
   1.171  		branchLinksContextMenu->addAction ( actionEditOpenURLTab );
   1.172  		branchLinksContextMenu->addAction ( actionEditOpenMultipleURLTabs );
   1.173 @@ -1677,9 +1688,8 @@
   1.174  {
   1.175  	// Unselect all possibly selected objects
   1.176  	// (Important to update note editor)
   1.177 -	int i;
   1.178  	MapEditor *me;
   1.179 -	for (i=0;i<=tabWidget->count() -1;i++)
   1.180 +	for (int i=0;i<=tabWidget->count() -1;i++)
   1.181  	{
   1.182  		
   1.183  		me=(MapEditor*)tabWidget->page(i);
   1.184 @@ -1972,7 +1982,7 @@
   1.185  	setupRecentMapsMenu();
   1.186  }
   1.187  
   1.188 -void Main::fileSave(const SaveMode &savemode)
   1.189 +void Main::fileSave(MapEditor *me, const SaveMode &savemode)
   1.190  {
   1.191  	// tmp dir for zipping 
   1.192  	QString tmpMapDir;
   1.193 @@ -1982,13 +1992,12 @@
   1.194  	
   1.195  	QString safeFilePath;
   1.196  
   1.197 -	bool saveZipped=currentMapEditor()->saveZipped();
   1.198 -
   1.199 -	MapEditor *	me=currentMapEditor();
   1.200 +	bool saveZipped=me->saveZipped();
   1.201 +
   1.202  	if (me)
   1.203  	{
   1.204  		QString fn=me->getFilePath();
   1.205 -		// filename=unnamed, filepath="" in constructor...
   1.206 +		// filename=unnamed, filepath="" in constructor of mapEditor
   1.207  		if ( !fn.isEmpty() ) 
   1.208  		{	
   1.209  			// We have a filepath, go on saving			
   1.210 @@ -2067,6 +2076,8 @@
   1.211  			// We have  no filepath yet,
   1.212  			// call fileSaveAs() now, this will call fileSave() 
   1.213  			// again.
   1.214 +			// First switch to editor
   1.215 +			tabWidget->setCurrentWidget (me);
   1.216  			fileSaveAs(savemode);
   1.217  		}
   1.218      }
   1.219 @@ -2089,7 +2100,12 @@
   1.220  
   1.221  void Main::fileSave()
   1.222  {
   1.223 -	fileSave (CompleteMap);
   1.224 +	fileSave (currentMapEditor(), CompleteMap);
   1.225 +}
   1.226 +
   1.227 +void Main::fileSave(MapEditor *me)
   1.228 +{
   1.229 +	fileSave (me,CompleteMap);
   1.230  }
   1.231  
   1.232  void Main::fileSaveAs(const SaveMode& savemode)
   1.233 @@ -2145,7 +2161,7 @@
   1.234  
   1.235  			// Save now
   1.236  			currentMapEditor()->setFilePath(fn);
   1.237 -			fileSave(savemode);
   1.238 +			fileSave(currentMapEditor(), savemode);
   1.239  
   1.240  			// Set name of tab
   1.241  			if (savemode==CompleteMap)
   1.242 @@ -2415,7 +2431,7 @@
   1.243  			{
   1.244  				case QMessageBox::Yes:
   1.245  					// save and close
   1.246 -					fileSave(CompleteMap);
   1.247 +					fileSave(currentMapEditor(), CompleteMap);
   1.248  					break;
   1.249  				case QMessageBox::No:
   1.250  				// close  without saving
   1.251 @@ -2466,7 +2482,7 @@
   1.252  			switch( mb.exec() ) {
   1.253  				case QMessageBox::Yes:
   1.254  					// save (the changed editors) and exit
   1.255 -					fileSave(CompleteMap);
   1.256 +					fileSave(currentMapEditor(), CompleteMap);
   1.257  					break;
   1.258  				case QMessageBox::No:
   1.259  					// exit without saving
   1.260 @@ -2846,7 +2862,7 @@
   1.261  	}	
   1.262  }
   1.263  
   1.264 -void Main::editUnScrollAll()
   1.265 +void Main::editUnscrollChilds()
   1.266  {
   1.267  	if (currentMapEditor())
   1.268  		currentMapEditor()->unscrollChilds();	
   1.269 @@ -3124,18 +3140,6 @@
   1.270  }
   1.271  
   1.272  
   1.273 -void Main::formatIncludeImagesVer()
   1.274 -{
   1.275 -	if (currentMapEditor())
   1.276 -		currentMapEditor()->setIncludeImagesVer(actionFormatIncludeImagesVer->isOn());
   1.277 -}
   1.278 -
   1.279 -void Main::formatIncludeImagesHor()
   1.280 -{
   1.281 -	if (currentMapEditor())
   1.282 -		currentMapEditor()->setIncludeImagesHor(actionFormatIncludeImagesHor->isOn());
   1.283 -}
   1.284 -
   1.285  void Main::formatHideLinkUnselected()	//FIXME get rid of this with imagepropertydialog
   1.286  {
   1.287  	if (currentMapEditor())
   1.288 @@ -3213,6 +3217,39 @@
   1.289  		settings.setValue ("/macros/macroDir",dir.path());
   1.290  }
   1.291  
   1.292 +void Main::settingsUndoLevels()
   1.293 +{
   1.294 +	bool ok;
   1.295 +	int i = QInputDialog::getInteger(
   1.296 +		this, 
   1.297 +		tr("QInputDialog::getInteger()"),
   1.298 +	    tr("Number of undo/redo levels:"), settings.value("/mapeditor/stepsTotal").toInt(), 0, 1000, 1, &ok);
   1.299 +	if (ok)
   1.300 +	{
   1.301 +		settings.setValue ("/mapeditor/stepsTotal",i);
   1.302 +		QMessageBox::information( this, tr( "VYM -Information:" ),
   1.303 +		   tr("Settings have been changed. The next map opened will have \"%1\" undo/redo levels").arg(i)); 
   1.304 +   }	
   1.305 +}
   1.306 +
   1.307 +void Main::settingsAutosaveToggle()
   1.308 +{
   1.309 +	settings.setValue ("/mapeditor/autosave/used",actionSettingsAutosaveToggle->isOn() );
   1.310 +}
   1.311 +
   1.312 +void Main::settingsAutosaveTime()
   1.313 +{
   1.314 +	bool ok;
   1.315 +	int i = QInputDialog::getInteger(
   1.316 +		this, 
   1.317 +		tr("QInputDialog::getInteger()"),
   1.318 +	    tr("Number of seconds before autosave:"), settings.value("/mapeditor/autosave/ms").toInt() / 1000, 10, 10000, 1, &ok);
   1.319 +	if (ok)
   1.320 +	{
   1.321 +		settings.setValue ("/mapeditor/autosave/ms",i * 1000);
   1.322 +    }	
   1.323 +}
   1.324 +
   1.325  void Main::settingsToggleDelKey()
   1.326  {
   1.327  	if (actionSettingsUseDelKey->isOn())
   1.328 @@ -3241,6 +3278,27 @@
   1.329  
   1.330  }
   1.331  
   1.332 +void Main::windowToggleProperty()
   1.333 +{
   1.334 +	if (branchPropertyWindow->isVisible())
   1.335 +		branchPropertyWindow->hide();
   1.336 +	else	
   1.337 +		branchPropertyWindow->show();
   1.338 +	if(currentMapEditor())
   1.339 +	{
   1.340 +		LinkableMapObj *sel=currentMapEditor()->getSelection();
   1.341 +		if (sel && (typeid(*sel) == typeid(BranchObj) ||
   1.342 +		           typeid(*sel) == typeid(MapCenterObj)))
   1.343 +		{
   1.344 +			branchPropertyWindow->setMapEditor(currentMapEditor());
   1.345 +			branchPropertyWindow->setBranch((BranchObj*)sel);
   1.346 +			return;
   1.347 +		}
   1.348 +		
   1.349 +	}	
   1.350 +	branchPropertyWindow->setBranch(NULL);
   1.351 +}
   1.352 +
   1.353  void Main::windowToggleAntiAlias()
   1.354  {
   1.355  	bool b=actionViewToggleAntiAlias->isOn();
   1.356 @@ -3293,23 +3351,23 @@
   1.357  	actionViewToggleNoteEditor->setOn (textEditor->showWithMain());
   1.358  	actionViewToggleHistoryWindow->setOn (historyWindow->showWithMain());
   1.359  
   1.360 -	if (me->getMapLinkColorHint()==HeadingColor) 
   1.361 +	if (me->getMapLinkColorHint()==LinkableMapObj::HeadingColor) 
   1.362  		actionFormatLinkColorHint->setOn(true);
   1.363  	else	
   1.364  		actionFormatLinkColorHint->setOn(false);
   1.365  
   1.366  	switch (me->getMapLinkStyle())
   1.367  	{
   1.368 -		case StyleLine: 
   1.369 +		case LinkableMapObj::Line: 
   1.370  			actionFormatLinkStyleLine->setOn(true);
   1.371  			break;
   1.372 -		case StyleParabel:
   1.373 +		case LinkableMapObj::Parabel:
   1.374  			actionFormatLinkStyleParabel->setOn(true);
   1.375  			break;
   1.376 -		case StylePolyLine:	
   1.377 +		case LinkableMapObj::PolyLine:	
   1.378  			actionFormatLinkStylePolyLine->setOn(true);
   1.379  			break;
   1.380 -		case StylePolyParabel:	
   1.381 +		case LinkableMapObj::PolyParabel:	
   1.382  			actionFormatLinkStylePolyParabel->setOn(true);
   1.383  			break;
   1.384  		default:
   1.385 @@ -3419,10 +3477,6 @@
   1.386  			for (int i=0; i<actionListBranches.size(); ++i)	
   1.387  				actionListBranches.at(i)->setEnabled(true);
   1.388  			actionEditDelete->setEnabled (true);
   1.389 -			actionFormatIncludeImagesVer->setOn
   1.390 -				( ((BranchObj*)selection)->getIncludeImagesVer());
   1.391 -			actionFormatIncludeImagesHor->setOn
   1.392 -				( ((BranchObj*)selection)->getIncludeImagesHor());
   1.393  			actionFormatHideLinkUnselected->setOn
   1.394  				(selection->getHideLinkUnselected());
   1.395  		}
   1.396 @@ -3469,7 +3523,7 @@
   1.397  	}	
   1.398  }
   1.399  
   1.400 -ModMode Main::getModMode()
   1.401 +Main::ModMode Main::getModMode()
   1.402  {
   1.403  	if (actionModModeColor->isOn()) return ModModeColor;
   1.404  	if (actionModModeCopy->isOn()) return ModModeCopy;
   1.405 @@ -3517,24 +3571,6 @@
   1.406  		currentMapEditor()->runScript (script);
   1.407  }
   1.408  
   1.409 -void Main::showPropertyDialog()
   1.410 -{
   1.411 -	if(currentMapEditor())
   1.412 -	{
   1.413 -		LinkableMapObj *sel=currentMapEditor()->getSelection();
   1.414 -		if (sel && (typeid(*sel) == typeid(BranchObj) ||
   1.415 -		           typeid(*sel) == typeid(MapCenterObj)))
   1.416 -		{
   1.417 -			branchPropertyWindow->show();
   1.418 -			branchPropertyWindow->setMapEditor(currentMapEditor());
   1.419 -			branchPropertyWindow->setBranch((BranchObj*)sel);
   1.420 -			return;
   1.421 -		}
   1.422 -		
   1.423 -	}	
   1.424 -	branchPropertyWindow->setBranch(NULL);
   1.425 -}
   1.426 -
   1.427  void Main::windowNextEditor()
   1.428  {
   1.429  	if (tabWidget->currentPageIndex() < tabWidget->count())