mainwindow.cpp
changeset 772 e3f722759c7e
parent 771 01f2f6d6789d
child 773 340bc29da9a0
     1.1 --- a/mainwindow.cpp	Mon May 18 11:22:41 2009 +0000
     1.2 +++ b/mainwindow.cpp	Wed May 20 15:40:14 2009 +0000
     1.3 @@ -542,34 +542,6 @@
     1.4  	editMenu->addAction (a);
     1.5  	actionPaste=a;
     1.6  
     1.7 -/*	FIXME-5
     1.8 -    // Shortcuts to modify heading:
     1.9 -    a = new QAction(tr( "Edit heading","Edit menu" ),this);
    1.10 -	a->setStatusTip ( tr( "edit Heading" ));
    1.11 -	a->setShortcut ( Qt::Key_Enter);				//Edit heading
    1.12 -//	a->setShortcutContext (Qt::WindowShortcut);
    1.13 -	addAction (a);
    1.14 -    connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
    1.15 -	actionListBranches.append(a);
    1.16 -    a = new QAction( tr( "Edit heading","Edit menu" ), this);
    1.17 -	a->setStatusTip (tr( "edit Heading" ));
    1.18 -	a->setShortcut (Qt::Key_Return );				//Edit heading
    1.19 -	//a->setShortcutContext (Qt::WindowShortcut);
    1.20 -	addAction (a);
    1.21 -    connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
    1.22 -	actionListBranches.append(a);
    1.23 -	editMenu->addAction (a);
    1.24 -	actionHeading=a;
    1.25 -
    1.26 -    a = new QAction( tr( "Edit heading","Edit menu" ), this);
    1.27 -	a->setStatusTip (tr( "edit Heading" ));
    1.28 -	//a->setShortcut ( Qt::Key_F2 );					//Edit heading
    1.29 -	a->setShortcutContext (Qt::WindowShortcut);
    1.30 -	addAction (a);
    1.31 -    connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
    1.32 -	actionListBranches.append(a);
    1.33 -*/	
    1.34 -    
    1.35      // Shortcut to delete selection
    1.36      a = new QAction( tr( "Delete Selection","Edit menu" ),this);
    1.37  	a->setStatusTip (tr( "Delete Selection" ));
    1.38 @@ -1144,6 +1116,7 @@
    1.39  	QToolBar *tb=NULL;
    1.40  
    1.41  	Flag *flag=new Flag;;
    1.42 +	flag->setVisible(true);
    1.43  
    1.44  	flag->load(QPixmap(flagsPath+"flag-note.png"));
    1.45  	setupFlag (flag,tb,"system-note",tr("Note","SystemFlag"));
    1.46 @@ -1167,7 +1140,6 @@
    1.47  	tb=addToolBar (tr ("Standard Flags","Standard Flag Toolbar"));
    1.48  	tb->setObjectName ("standardFlagTB");
    1.49  	standardFlagsMaster->setToolBar (tb);
    1.50 -
    1.51  	
    1.52  	flag->load(flagsPath+"flag-exclamationmark.png");
    1.53  	flag->setGroup("standard-mark");
    1.54 @@ -1259,7 +1231,7 @@
    1.55  	setupFlag (flag,tb,"lifebelt",tr("This will help","Standardflag"));
    1.56  
    1.57  	// Freemind flags
    1.58 -
    1.59 +	flag->setVisible(false);
    1.60  	flag->load(flagsPath+"freemind/warning.png");
    1.61  	setupFlag (flag,tb,  "freemind-warning",tr("Important","Freemind-Flag"));
    1.62  
    1.63 @@ -1343,6 +1315,7 @@
    1.64  		// StandardFlag
    1.65  		tb->addAction (a);
    1.66  		flag->setAction (a);
    1.67 +		a->setVisible (flag->isVisible());
    1.68  		a->setCheckable(true);
    1.69  		a->setObjectName(name);
    1.70  		a->setToolTip(tooltip);
    1.71 @@ -1696,14 +1669,14 @@
    1.72  MapEditor* Main::currentMapEditor() const
    1.73  {
    1.74      if ( tabWidget->currentPage())
    1.75 -		return tabModel.at(tabWidget->currentIndex())->getMapEditor();
    1.76 +		return vymViews.at(tabWidget->currentIndex())->getMapEditor();
    1.77      return NULL;	
    1.78  }
    1.79  
    1.80  VymModel* Main::currentModel() const
    1.81  {
    1.82      if ( tabWidget->currentPage())
    1.83 -		return tabModel.at(tabWidget->currentIndex());
    1.84 +		return vymViews.at(tabWidget->currentIndex())->getModel();
    1.85      return NULL;	
    1.86  }
    1.87  
    1.88 @@ -1712,11 +1685,13 @@
    1.89  {
    1.90  	// Unselect all possibly selected objects
    1.91  	// (Important to update note editor)
    1.92 +	VymModel *m;
    1.93  	for (int i=0;i<=tabWidget->count() -1;i++)
    1.94  	{
    1.95 -		tabModel.at(i)->unselect();
    1.96 -	}	
    1.97 -	VymModel *m=currentModel();
    1.98 +		m= vymViews.at(tabWidget->currentIndex())->getModel();
    1.99 +		if (m) m->unselect();
   1.100 +	}
   1.101 +	m=currentModel();
   1.102  	if (m) m->reselect();
   1.103  
   1.104  	// Update actions to in menus and toolbars according to editor
   1.105 @@ -1726,11 +1701,11 @@
   1.106  void Main::fileNew()
   1.107  {
   1.108  	VymModel *vm=new VymModel;
   1.109 -	tabModel.append (vm);
   1.110  
   1.111  	VymView *vv=new VymView (vm);
   1.112 +	vymViews.append (vv);
   1.113  	tabWidget->addTab (vv,tr("unnamed","MainWindow: name for new and empty file"));
   1.114 -	tabWidget->setCurrentIndex (tabModel.count() );
   1.115 +	tabWidget->setCurrentIndex (vymViews.count() );
   1.116  	vv->initFocus();
   1.117  
   1.118  	
   1.119 @@ -1746,7 +1721,7 @@
   1.120  	{
   1.121  		srcModel->copy();
   1.122  		fileNew();
   1.123 -		VymModel *dstModel=tabModel.last ();
   1.124 +		VymModel *dstModel=vymViews.last()->getModel();
   1.125  		dstModel->select("mc:");
   1.126  		dstModel->load (clipboardDir+"/"+clipboardFile,ImportReplace, VymMap);
   1.127  	}
   1.128 @@ -1770,7 +1745,7 @@
   1.129  		int i=0;
   1.130  		while (i<=tabWidget->count() -1)
   1.131  		{
   1.132 -			if (tabModel.at(i)->getFilePath() == fn)
   1.133 +			if (vymViews.at(i)->getModel()->getFilePath() == fn)
   1.134  			{
   1.135  				// Already there, ask for confirmation
   1.136  				QMessageBox mb( vymName,
   1.137 @@ -1813,7 +1788,7 @@
   1.138  		{
   1.139  			vm=new VymModel;
   1.140  			VymView *vv=new VymView (vm);
   1.141 -			tabModel.append (vm);
   1.142 +			vymViews.append (vv);
   1.143  			tabWidget->addTab (vv,fn);
   1.144  			tabIndex=tabWidget->count()-1;
   1.145  			tabWidget->setCurrentPage (tabIndex);
   1.146 @@ -2310,16 +2285,15 @@
   1.147  	}
   1.148  }
   1.149  
   1.150 -void Main::fileCloseMap()
   1.151 +void Main::fileCloseMap()	
   1.152  {
   1.153 -	MapEditor *me = currentMapEditor();
   1.154  	VymModel *m=currentModel();
   1.155  	if (m)
   1.156  	{
   1.157  		if (m->hasChanged())
   1.158  		{
   1.159  			QMessageBox mb( vymName,
   1.160 -				tr("The map %1 has been modified but not saved yet. Do you want to").arg(me->getModel()->getFileName()),
   1.161 +				tr("The map %1 has been modified but not saved yet. Do you want to").arg(m->getFileName()),
   1.162  				QMessageBox::Warning,
   1.163  				QMessageBox::Yes | QMessageBox::Default,
   1.164  				QMessageBox::No,
   1.165 @@ -2340,14 +2314,16 @@
   1.166  				return;
   1.167  			}
   1.168  		} 
   1.169 -		tabModel.removeAt (tabWidget->currentIndex() );
   1.170 +		// And here comes the segfault, because removeTab triggers 
   1.171 +		// currentChanged->Main::editorChanged -> updateActions and VM is not NULL yet...
   1.172 +		vymViews.removeAt (tabWidget->currentIndex() );
   1.173  		tabWidget->removeTab (tabWidget->currentIndex() );
   1.174  
   1.175 -		// Remove mapEditor;
   1.176 +		// Remove mapEditor/model FIXME-5
   1.177  		// Better would be delete (me), but then we could have a Qt error:
   1.178  		// "QObject: Do not delete object, 'MapEditor', during its event handler!"
   1.179  		// So we only remove data now and call deconstructor when vym closes later
   1.180 -		// FIXME-3  this needs to be moved to vymview...   me->clear();
   1.181 +		// this needs to be moved to vymview...   me->clear();
   1.182  		// some model->clear is needed to free up memory ...
   1.183  
   1.184  		updateActions();
   1.185 @@ -2364,10 +2340,10 @@
   1.186  {
   1.187  	// Check if one or more editors have changed
   1.188  	int i;
   1.189 -	for (i=0;i<=tabModel.count() -1;i++)
   1.190 +	for (i=0;i<=vymViews.count() -1;i++)
   1.191  	{
   1.192  		// If something changed, ask what to do
   1.193 -		if (tabModel.at(i)->hasChanged())
   1.194 +		if (vymViews.at(i)->getModel()->hasChanged())
   1.195  		{
   1.196  			tabWidget->setCurrentPage(i);
   1.197  			QMessageBox mb( vymName,
   1.198 @@ -2641,9 +2617,9 @@
   1.199  		// compare path with already loaded maps
   1.200  		int index=-1;
   1.201  		int i;
   1.202 -		for (i=0;i<=tabModel.count() -1;i++)
   1.203 +		for (i=0;i<=vymViews.count() -1;i++)
   1.204  		{
   1.205 -			if (vl.at(j)==tabModel.at(i)->getFilePath() )
   1.206 +			if (vl.at(j)==vymViews.at(i)->getModel()->getFilePath() )
   1.207  			{
   1.208  				index=i;
   1.209  				break;
   1.210 @@ -2789,11 +2765,7 @@
   1.211  void Main::editAddMapCenter()
   1.212  {
   1.213  	VymModel *m=currentModel();
   1.214 -	if (m)
   1.215 -	{
   1.216 -		cout <<"Main::editAddMapCenter\n";
   1.217 -		m->addMapCenter ();
   1.218 -	}	
   1.219 +	if (m) m->addMapCenter ();
   1.220  }
   1.221  
   1.222  void Main::editNewBranch()
   1.223 @@ -3226,9 +3198,9 @@
   1.224  {
   1.225  	bool b=actionViewToggleAntiAlias->isOn();
   1.226  	MapEditor *me;
   1.227 -	for (int i=0;i<tabModel.count();i++)
   1.228 +	for (int i=0;i<vymViews.count();i++)
   1.229  	{
   1.230 -		me=tabModel.at(i)->getMapEditor();
   1.231 +		me=vymViews.at(i)->getMapEditor();
   1.232  		if (me) me->setAntiAlias(b);
   1.233  	}	
   1.234  
   1.235 @@ -3248,10 +3220,10 @@
   1.236  {
   1.237  	bool b=actionViewToggleSmoothPixmapTransform->isOn();
   1.238  	MapEditor *me;
   1.239 -	for (int i=0;i<tabModel.count();i++)
   1.240 +	for (int i=0;i<vymViews.count();i++)
   1.241  	{
   1.242  		
   1.243 -		me=tabModel.at(i)->getMapEditor();
   1.244 +		me=vymViews.at(i)->getMapEditor();
   1.245  		if (me) me->setSmoothPixmap(b);
   1.246  	}	
   1.247  }
   1.248 @@ -3388,139 +3360,142 @@
   1.249  	else	
   1.250  		actionRedo->setEnabled( false);
   1.251  
   1.252 -	TreeItem *selti=m->getSelectedItem();
   1.253 -	BranchItem *selbi=m->getSelectedBranchItem();
   1.254 -	if (selti)
   1.255 +	if (m)
   1.256  	{
   1.257 -		if (selbi)
   1.258 +		TreeItem *selti=m->getSelectedItem();
   1.259 +		BranchItem *selbi=m->getSelectedBranchItem();
   1.260 +		if (selti)
   1.261  		{
   1.262 -			// Take care of links  // FIXME-1
   1.263 -			/*
   1.264 -			if (bo->countXLinks()==0)
   1.265 +			if (selbi)
   1.266  			{
   1.267 -				branchXLinksContextMenuEdit->clear();
   1.268 -				branchXLinksContextMenuFollow->clear();
   1.269 -			} else
   1.270 +				// Take care of links  // FIXME-1
   1.271 +				/*
   1.272 +				if (bo->countXLinks()==0)
   1.273 +				{
   1.274 +					branchXLinksContextMenuEdit->clear();
   1.275 +					branchXLinksContextMenuFollow->clear();
   1.276 +				} else
   1.277 +				{
   1.278 +					BranchObj *bot;
   1.279 +					QString s;
   1.280 +					branchXLinksContextMenuEdit->clear();
   1.281 +					branchXLinksContextMenuFollow->clear();
   1.282 +					for (int i=0; i<=bo->countXLinks();i++)
   1.283 +					{
   1.284 +						bot=bo->XLinkTargetAt(i);
   1.285 +						if (bot)
   1.286 +						{
   1.287 +							s=bot->getHeading();
   1.288 +							if (s.length()>xLinkMenuWidth)
   1.289 +								s=s.left(xLinkMenuWidth)+"...";
   1.290 +							branchXLinksContextMenuFollow->addAction (s);
   1.291 +							branchXLinksContextMenuEdit->addAction (s);
   1.292 +						}	
   1.293 +					}
   1.294 +				}
   1.295 +				*/
   1.296 +				//Standard Flags
   1.297 +				standardFlagsMaster->updateToolBar (selbi->activeStandardFlagNames() );
   1.298 +
   1.299 +				// System Flags
   1.300 +				actionToggleScroll->setEnabled (true);
   1.301 +				if ( selbi->isScrolled() )
   1.302 +					actionToggleScroll->setOn(true);
   1.303 +				else	
   1.304 +					actionToggleScroll->setOn(false);
   1.305 +
   1.306 +				if ( selti->getURL().isEmpty() )
   1.307 +				{
   1.308 +					actionOpenURL->setEnabled (false);
   1.309 +					actionOpenURLTab->setEnabled (false);
   1.310 +				}	
   1.311 +				else	
   1.312 +				{
   1.313 +					actionOpenURL->setEnabled (true);
   1.314 +					actionOpenURLTab->setEnabled (true);
   1.315 +				}
   1.316 +				if ( selti->getVymLink().isEmpty() )
   1.317 +				{
   1.318 +					actionOpenVymLink->setEnabled (false);
   1.319 +					actionDeleteVymLink->setEnabled (false);
   1.320 +				} else	
   1.321 +				{
   1.322 +					actionOpenVymLink->setEnabled (true);
   1.323 +					actionDeleteVymLink->setEnabled (true);
   1.324 +				}	
   1.325 +
   1.326 +				if (selbi->canMoveUp()) 
   1.327 +					actionMoveUp->setEnabled (true);
   1.328 +				else	
   1.329 +					actionMoveUp->setEnabled (false);
   1.330 +				if (selbi->canMoveDown()) 
   1.331 +					actionMoveDown->setEnabled (true);
   1.332 +				else	
   1.333 +					actionMoveDown->setEnabled (false);
   1.334 +
   1.335 +				actionSortChildren->setEnabled (true);
   1.336 +
   1.337 +				actionToggleHideExport->setEnabled (true);	
   1.338 +				actionToggleHideExport->setOn (selbi->hideInExport() );	
   1.339 +
   1.340 +				actionFileSave->setEnabled (true);	
   1.341 +				actionCopy->setEnabled (true);	
   1.342 +				actionCut->setEnabled (true);	
   1.343 +				if (!clipboardEmpty)
   1.344 +					actionPaste->setEnabled (true);	
   1.345 +				else	
   1.346 +					actionPaste->setEnabled (false);	
   1.347 +				for (int i=0; i<actionListBranches.size(); ++i)	
   1.348 +					actionListBranches.at(i)->setEnabled(true);
   1.349 +				actionDelete->setEnabled (true);
   1.350 +				//FIXME-2 actionFormatHideLinkUnselected->setOn (selection->getHideLinkUnselected());
   1.351 +			}
   1.352 +			if ( selti->getType()==TreeItem::Image)
   1.353  			{
   1.354 -				BranchObj *bot;
   1.355 -				QString s;
   1.356 -				branchXLinksContextMenuEdit->clear();
   1.357 -				branchXLinksContextMenuFollow->clear();
   1.358 -				for (int i=0; i<=bo->countXLinks();i++)
   1.359 -				{
   1.360 -					bot=bo->XLinkTargetAt(i);
   1.361 -					if (bot)
   1.362 -					{
   1.363 -						s=bot->getHeading();
   1.364 -						if (s.length()>xLinkMenuWidth)
   1.365 -							s=s.left(xLinkMenuWidth)+"...";
   1.366 -						branchXLinksContextMenuFollow->addAction (s);
   1.367 -						branchXLinksContextMenuEdit->addAction (s);
   1.368 -					}	
   1.369 -				}
   1.370 -			}
   1.371 -			*/
   1.372 -			//Standard Flags
   1.373 -			standardFlagsMaster->updateToolBar (selbi->activeStandardFlagNames() );
   1.374 -
   1.375 -			// System Flags
   1.376 -			actionToggleScroll->setEnabled (true);
   1.377 -			if ( selbi->isScrolled() )
   1.378 -				actionToggleScroll->setOn(true);
   1.379 -			else	
   1.380 -				actionToggleScroll->setOn(false);
   1.381 -
   1.382 -			if ( selti->getURL().isEmpty() )
   1.383 -			{
   1.384 +			/* FIXME-2
   1.385 +				FloatObj *fo=(FloatImageObj*)selection;
   1.386 +
   1.387  				actionOpenURL->setEnabled (false);
   1.388 -				actionOpenURLTab->setEnabled (false);
   1.389 -			}	
   1.390 -			else	
   1.391 -			{
   1.392 -				actionOpenURL->setEnabled (true);
   1.393 -				actionOpenURLTab->setEnabled (true);
   1.394 -			}
   1.395 -			if ( selti->getVymLink().isEmpty() )
   1.396 -			{
   1.397  				actionOpenVymLink->setEnabled (false);
   1.398 -				actionDeleteVymLink->setEnabled (false);
   1.399 -			} else	
   1.400 -			{
   1.401 -				actionOpenVymLink->setEnabled (true);
   1.402 -				actionDeleteVymLink->setEnabled (true);
   1.403 -			}	
   1.404 -
   1.405 -            if (selbi->canMoveUp()) 
   1.406 -				actionMoveUp->setEnabled (true);
   1.407 -			else	
   1.408 +				actionDeleteVymLink->setEnabled (false);	
   1.409 +				actionToggleHideExport->setEnabled (true);	
   1.410 +				actionToggleHideExport->setOn (fo->hideInExport() );	
   1.411 +
   1.412 +
   1.413 +				actionCopy->setEnabled (true);
   1.414 +				actionCut->setEnabled (true);	
   1.415 +				actionPaste->setEnabled (false);	//FIXME-4 why not allowing copy of images?
   1.416 +				for (int i=0; i<actionListBranches.size(); ++i)	
   1.417 +					actionListBranches.at(i)->setEnabled(false);
   1.418 +				actionDelete->setEnabled (true);
   1.419 +				actionFormatHideLinkUnselected->setOn
   1.420 +					( selection->getHideLinkUnselected());
   1.421  				actionMoveUp->setEnabled (false);
   1.422 -			if (selbi->canMoveDown()) 
   1.423 -				actionMoveDown->setEnabled (true);
   1.424 -			else	
   1.425  				actionMoveDown->setEnabled (false);
   1.426 -
   1.427 -			actionSortChildren->setEnabled (true);
   1.428 -
   1.429 -			actionToggleHideExport->setEnabled (true);	
   1.430 -			actionToggleHideExport->setOn (selbi->hideInExport() );	
   1.431 -
   1.432 -			actionFileSave->setEnabled (true);	
   1.433 -			actionCopy->setEnabled (true);	
   1.434 -			actionCut->setEnabled (true);	
   1.435 -			if (!clipboardEmpty)
   1.436 -				actionPaste->setEnabled (true);	
   1.437 -			else	
   1.438 -				actionPaste->setEnabled (false);	
   1.439 +				*/
   1.440 +			}	//image
   1.441 +
   1.442 +		} else
   1.443 +		{	// !selti
   1.444 +			actionFileSave->setEnabled (false);	
   1.445 +			actionCopy->setEnabled (false);	
   1.446 +			actionCut->setEnabled (false);	
   1.447 +			actionPaste->setEnabled (false);	
   1.448  			for (int i=0; i<actionListBranches.size(); ++i)	
   1.449 -				actionListBranches.at(i)->setEnabled(true);
   1.450 -			actionDelete->setEnabled (true);
   1.451 -			//FIXME-2 actionFormatHideLinkUnselected->setOn (selection->getHideLinkUnselected());
   1.452 -		}
   1.453 -		if ( selti->getType()==TreeItem::Image)
   1.454 -		{
   1.455 -		/* FIXME-2
   1.456 -			FloatObj *fo=(FloatImageObj*)selection;
   1.457 -
   1.458 +				actionListBranches.at(i)->setEnabled(false);
   1.459 +
   1.460 +			actionToggleScroll->setEnabled (false);
   1.461  			actionOpenURL->setEnabled (false);
   1.462  			actionOpenVymLink->setEnabled (false);
   1.463  			actionDeleteVymLink->setEnabled (false);	
   1.464 -			actionToggleHideExport->setEnabled (true);	
   1.465 -			actionToggleHideExport->setOn (fo->hideInExport() );	
   1.466 -
   1.467 -
   1.468 -			actionCopy->setEnabled (true);
   1.469 -			actionCut->setEnabled (true);	
   1.470 -			actionPaste->setEnabled (false);	//FIXME-4 why not allowing copy of images?
   1.471 -			for (int i=0; i<actionListBranches.size(); ++i)	
   1.472 -				actionListBranches.at(i)->setEnabled(false);
   1.473 -			actionDelete->setEnabled (true);
   1.474 -			actionFormatHideLinkUnselected->setOn
   1.475 -				( selection->getHideLinkUnselected());
   1.476 +			actionHeading2URL->setEnabled (false);	
   1.477 +			actionDelete->setEnabled (false);
   1.478  			actionMoveUp->setEnabled (false);
   1.479  			actionMoveDown->setEnabled (false);
   1.480 -			*/
   1.481 -		}
   1.482 -
   1.483 -	} else
   1.484 -	{
   1.485 -		actionFileSave->setEnabled (false);	
   1.486 -		actionCopy->setEnabled (false);	
   1.487 -		actionCut->setEnabled (false);	
   1.488 -		actionPaste->setEnabled (false);	
   1.489 -		for (int i=0; i<actionListBranches.size(); ++i)	
   1.490 -			actionListBranches.at(i)->setEnabled(false);
   1.491 -
   1.492 -		actionToggleScroll->setEnabled (false);
   1.493 -		actionOpenURL->setEnabled (false);
   1.494 -		actionOpenVymLink->setEnabled (false);
   1.495 -		actionDeleteVymLink->setEnabled (false);	
   1.496 -		actionHeading2URL->setEnabled (false);	
   1.497 -		actionDelete->setEnabled (false);
   1.498 -		actionMoveUp->setEnabled (false);
   1.499 -		actionMoveDown->setEnabled (false);
   1.500 -		actionSortChildren->setEnabled (false);
   1.501 -		actionToggleHideExport->setEnabled (false);	
   1.502 -	}	
   1.503 +			actionSortChildren->setEnabled (false);
   1.504 +			actionToggleHideExport->setEnabled (false);	
   1.505 +		}	
   1.506 +	} // m
   1.507  }
   1.508  
   1.509  Main::ModMode Main::getModMode()