mainwindow.cpp
changeset 804 14f2b1b15242
parent 803 338ebdc9b947
child 805 fc7a93ff97c3
     1.1 --- a/mainwindow.cpp	Fri Oct 02 14:31:03 2009 +0000
     1.2 +++ b/mainwindow.cpp	Fri Nov 13 08:32:03 2009 +0000
     1.3 @@ -19,11 +19,12 @@
     1.4  #include "options.h"
     1.5  #include "process.h"
     1.6  #include "settings.h"
     1.7 +#include "shortcuts.h"
     1.8  #include "texteditor.h"
     1.9  #include "warningdialog.h"
    1.10  #include "xlinkitem.h"
    1.11  
    1.12 -//#include <modeltest.h>	// FIXME-3
    1.13 +#include <modeltest.h>	// FIXME-3
    1.14  
    1.15  #if defined(Q_OS_WIN32)
    1.16  // Define only this structure as opposed to
    1.17 @@ -123,7 +124,8 @@
    1.18  	makeSubDirs (clipboardDir);
    1.19  	clipboardEmpty=true;
    1.20  
    1.21 -	procBrowser=NULL;
    1.22 +	browserPID=new qint64;
    1.23 +	*browserPID=0;
    1.24  
    1.25  	// Satellite windows //////////////////////////////////////////
    1.26  	// history window
    1.27 @@ -705,6 +707,29 @@
    1.28  	addAction (a);
    1.29  	actionListBranches.append(actionExpandAll);
    1.30  
    1.31 +	a = new QAction( QPixmap(), tr( "Expand one level","Edit menu" ), this);
    1.32 +	a->setShortcut ( Qt::Key_Greater );		// Expand one level in tree editor
    1.33 +	a->setStatusTip (tr( "Expand one level in tree editor" )); 
    1.34 +    connect( a, SIGNAL( triggered() ), this, SLOT( editExpandOneLevel() ) );
    1.35 +	a->setEnabled (false);
    1.36 +	a->setToggleAction(false);
    1.37 +	actionExpandOneLevel=a;
    1.38 +    //tb->addAction (a);
    1.39 +    editMenu->addAction ( a);
    1.40 +	addAction (a);
    1.41 +	actionListBranches.append(a);
    1.42 +
    1.43 +	a = new QAction( QPixmap(), tr( "Collapse one level","Edit menu" ), this);
    1.44 +	a->setShortcut ( Qt::Key_Less);			// Collapse one level in tree editor
    1.45 +	a->setStatusTip (tr( "Collapse one level in tree editor" )); 
    1.46 +    connect( a, SIGNAL( triggered() ), this, SLOT( editCollapseOneLevel() ) );
    1.47 +	a->setEnabled (false);
    1.48 +	a->setToggleAction(false);
    1.49 +	actionCollapseOneLevel=a;
    1.50 +    //tb->addAction (a);
    1.51 +    editMenu->addAction ( a);
    1.52 +	addAction (a);
    1.53 +	actionListBranches.append(a);
    1.54  
    1.55      a = new QAction( tr( "Unscroll children","Edit menu" ), this);
    1.56  	a->setStatusTip (tr( "Unscroll all scrolled branches in selected subtree" ));
    1.57 @@ -722,7 +747,7 @@
    1.58  	editMenu->addSeparator();
    1.59  
    1.60  	a = new QAction( QPixmap(flagsPath+"flag-url.png"), tr( "Open URL","Edit menu" ), this);
    1.61 -	a->setShortcut (Qt::CTRL + Qt::Key_U );
    1.62 +	a->setShortcut (Qt::SHIFT + Qt::Key_U );
    1.63  	a->setShortcut (tr( "Open URL" ));
    1.64      tb->addAction (a);
    1.65  	addAction(a);
    1.66 @@ -738,6 +763,7 @@
    1.67  
    1.68  	a = new QAction( tr( "Open all URLs in subtree","Edit menu" ), this);
    1.69  	a->setStatusTip (tr( "Open all URLs in subtree" ));
    1.70 +	a->setShortcut ( Qt::CTRL + Qt::Key_U );
    1.71  	addAction(a);
    1.72  	actionListBranches.append(a);
    1.73      connect( a, SIGNAL( triggered() ), this, SLOT( editOpenMultipleURLTabs() ) );
    1.74 @@ -754,7 +780,7 @@
    1.75  	
    1.76  	a = new QAction(QPixmap(), tr( "Edit local URL...","Edit menu"), this);
    1.77  	a->setStatusTip ( tr( "Edit local URL" ) );
    1.78 -	a->setShortcut (Qt::SHIFT +  Qt::Key_U );
    1.79 +	//a->setShortcut (Qt::SHIFT +  Qt::Key_U );
    1.80  	a->setShortcutContext (Qt::WindowShortcut);
    1.81  	actionListBranches.append(a);
    1.82  	addAction(a);
    1.83 @@ -775,7 +801,6 @@
    1.84  	a->setShortcut ( Qt::Key_B );
    1.85  	a->setShortcutContext (Qt::WindowShortcut);
    1.86  	addAction(a);
    1.87 -
    1.88      connect( a, SIGNAL( triggered() ), this, SLOT( editBugzilla2URL() ) );
    1.89  	actionBugzilla2URL=a;
    1.90      
    1.91 @@ -823,6 +848,16 @@
    1.92      connect( a, SIGNAL( triggered() ), this, SLOT( editToggleHideExport() ) );
    1.93  	actionToggleHideExport=a;
    1.94  
    1.95 +	a = new QAction(tr( "Add timestamp","Edit menu" ), this);
    1.96 +	a->setStatusTip ( tr( "Add timestamp" ));
    1.97 +	a->setEnabled (false);
    1.98 +	actionListBranches.append(a);
    1.99 +	a->setShortcut ( Qt::Key_T );	// Add timestamp
   1.100 +	a->setShortcutContext (Qt::WindowShortcut);
   1.101 +	addAction(a);
   1.102 +    connect( a, SIGNAL( triggered() ), this, SLOT( editAddTimestamp() ) );
   1.103 +	actionAddTimestamp=a;
   1.104 +    
   1.105      a = new QAction(tr( "Edit Map Info...","Edit menu" ),this);
   1.106  	a->setStatusTip ( tr( "Edit Map Info" ));
   1.107  	a->setEnabled (true);
   1.108 @@ -925,7 +960,7 @@
   1.109  
   1.110      a= new QAction(QPixmap(iconPath+"formatcolorsubtree.png"), tr( "Color sub&tree","Edit menu" ), this);
   1.111  	a->setStatusTip ( tr( "Color Subtree" ));
   1.112 -	a->setShortcut (Qt::CTRL + Qt::Key_T);
   1.113 +	//FIXME-2 switch back to that a->setShortcut (Qt::CTRL + Qt::Key_T);	// Color subtree
   1.114      connect( a, SIGNAL( triggered() ), this, SLOT( formatColorSubtree() ) );
   1.115  	a->setEnabled (false);
   1.116  	formatMenu->addAction (a);
   1.117 @@ -1010,31 +1045,34 @@
   1.118  	tb->setObjectName ("viewTB");
   1.119      QMenu *viewMenu = menuBar()->addMenu ( tr( "&View" ));
   1.120  
   1.121 +	Switchboard switchboard;	//FIXME-1 testing...
   1.122 +
   1.123      QAction *a;
   1.124      a = new QAction(QPixmap(iconPath+"viewmag-reset.png"), tr( "reset Zoom","View action" ), this);
   1.125  	a->setStatusTip ( tr( "Zoom reset" ) );
   1.126 -	a->setShortcut (Qt::CTRL + Qt::Key_0 );
   1.127 +	a->setShortcut (Qt::CTRL + Qt::Key_0);	// Reset zoom
   1.128 +	switchboard.addConnection(a,"CTRL+0");
   1.129      a->addTo( tb );
   1.130  	viewMenu->addAction (a);
   1.131      connect( a, SIGNAL( triggered() ), this, SLOT(viewZoomReset() ) );
   1.132  	
   1.133      a = new QAction( QPixmap(iconPath+"viewmag+.png"), tr( "Zoom in","View action" ), this);
   1.134  	a->setStatusTip (tr( "Zoom in" ));
   1.135 -	a->setShortcut (Qt::CTRL + Qt::Key_Plus);
   1.136 +	switchboard.addConnection(a,"CTRL++");
   1.137      a->addTo( tb );
   1.138  	viewMenu->addAction (a);
   1.139      connect( a, SIGNAL( triggered() ), this, SLOT(viewZoomIn() ) );
   1.140  	
   1.141      a = new QAction( QPixmap(iconPath+"viewmag-.png"), tr( "Zoom out","View action" ), this);
   1.142  	a->setStatusTip (tr( "Zoom out" ));
   1.143 -	a->setShortcut (Qt::CTRL + Qt::Key_Minus );
   1.144 +	switchboard.addConnection(a,"CTRL+-");
   1.145      a->addTo( tb );
   1.146  	viewMenu->addAction (a);
   1.147      connect( a, SIGNAL( triggered() ), this, SLOT( viewZoomOut() ) );
   1.148  
   1.149      a = new QAction( QPixmap(iconPath+"viewshowsel.png"), tr( "Show selection","View action" ), this);
   1.150  	a->setStatusTip (tr( "Show selection" ));
   1.151 -	a->setShortcut (Qt::Key_Period);
   1.152 +	switchboard.addConnection(a,".");
   1.153      a->addTo( tb );
   1.154  	viewMenu->addAction (a);
   1.155      connect( a, SIGNAL( triggered() ), this, SLOT( viewCenter() ) );
   1.156 @@ -1043,7 +1081,7 @@
   1.157  
   1.158      a = new QAction(QPixmap(flagsPath+"flag-note.png"), tr( "Show Note Editor","View action" ),this);
   1.159  	a->setStatusTip ( tr( "Show Note Editor" ));
   1.160 -	a->setShortcut ( Qt::CTRL + Qt::Key_E );
   1.161 +	a->setShortcut ( Qt::CTRL + Qt::Key_E );	// Toggle Note Editor
   1.162  	a->setToggleAction(true);
   1.163      a->addTo( tb );
   1.164  	viewMenu->addAction (a);
   1.165 @@ -1052,7 +1090,7 @@
   1.166  
   1.167      a = new QAction(QPixmap(iconPath+"history.png"),  tr( "History Window","View action" ),this );
   1.168  	a->setStatusTip ( tr( "Show History Window" ));
   1.169 -	a->setShortcut ( Qt::CTRL + Qt::Key_H  );
   1.170 +	a->setShortcut ( Qt::CTRL + Qt::Key_H  );	// Toggle history window
   1.171  	a->setToggleAction(true);
   1.172      a->addTo( tb );
   1.173  	viewMenu->addAction (a);
   1.174 @@ -1090,6 +1128,8 @@
   1.175  	a->setShortcut (Qt::ALT + Qt::Key_P );
   1.176  	viewMenu->addAction (a);
   1.177      connect( a, SIGNAL( triggered() ), this, SLOT(windowPreviousEditor() ) );
   1.178 +
   1.179 +	switchboard.print();
   1.180  }
   1.181  
   1.182  // Mode Actions
   1.183 @@ -1356,13 +1396,13 @@
   1.184  
   1.185      a = new QAction(  "Start TCPserver for MapEditor",this);
   1.186      //a->setStatusTip ( "Set application to open pdf files"));
   1.187 -	a->setShortcut ( Qt::Key_T );		//New TCP server
   1.188 +	//a->setShortcut ( Qt::ALT + Qt::Key_T );		//New TCP server
   1.189      connect( a, SIGNAL( triggered() ), this, SLOT( networkStartServer() ) );
   1.190  	netMenu->addAction (a);
   1.191  
   1.192      a = new QAction(  "Connect MapEditor to server",this);
   1.193      //a->setStatusTip ( "Set application to open pdf files"));
   1.194 -	a->setShortcut ( Qt::Key_C );		// Connect to server
   1.195 +	a->setShortcut ( Qt::ALT + Qt::Key_C );		// Connect to server
   1.196      connect( a, SIGNAL( triggered() ), this, SLOT( networkConnect() ) );
   1.197  	netMenu->addAction (a);
   1.198  }
   1.199 @@ -1480,12 +1520,13 @@
   1.200      QAction *a;
   1.201      a = new QAction( "Test function 1" , this);
   1.202      a->setStatusTip( "Call test function 1" );
   1.203 +	a->setShortcut (Qt::CTRL + Qt::Key_T);	// Test function 1  //FIXME-2 originally: color subtree
   1.204  	testMenu->addAction (a);
   1.205      connect( a, SIGNAL( triggered() ), this, SLOT( testFunction1() ) );
   1.206  
   1.207      a = new QAction( "Test function 2" , this);
   1.208      a->setStatusTip( "Call test function 2" );
   1.209 -	a->setShortcut (Qt::SHIFT + Qt::Key_T);
   1.210 +	a->setShortcut (Qt::SHIFT + Qt::Key_T);		// Test function 2
   1.211  	testMenu->addAction (a);
   1.212      connect( a, SIGNAL( triggered() ), this, SLOT( testFunction2() ) );
   1.213  
   1.214 @@ -1704,7 +1745,7 @@
   1.215  	VymModel *m;
   1.216  	for (int i=0;i<=tabWidget->count() -1;i++)
   1.217  	{
   1.218 -		m= vymViews.at(tabWidget->currentIndex())->getModel();
   1.219 +		m= vymViews.at(i)->getModel();
   1.220  		if (m) m->unselect();
   1.221  	}
   1.222  	m=currentModel();
   1.223 @@ -1718,7 +1759,7 @@
   1.224  {
   1.225  	VymModel *vm=new VymModel;
   1.226  
   1.227 -//new ModelTest(vm, this);	//FIXME-3
   1.228 +new ModelTest(vm, this);	//FIXME-3
   1.229  
   1.230  
   1.231  	VymView *vv=new VymView (vm);
   1.232 @@ -1728,7 +1769,8 @@
   1.233  	vv->initFocus();
   1.234  
   1.235  	// Create MapCenter for empty map
   1.236 -	//vm->createMapCenter();
   1.237 +	vm->addMapCenter();
   1.238 +	vm->makeDefault();
   1.239  
   1.240  	// For the very first map we do not have flagrows yet...
   1.241  	vm->select("mc:");
   1.242 @@ -2336,7 +2378,7 @@
   1.243  			}
   1.244  		} 
   1.245  		// And here comes the segfault, because removeTab triggers 
   1.246 -		// currentChanged->Main::editorChanged -> updateActions and VM is not NULL yet...
   1.247 +		// FIXME-3 currentChanged->Main::editorChanged -> updateActions and VM is not NULL yet...
   1.248  		vymViews.removeAt (tabWidget->currentIndex() );
   1.249  		tabWidget->removeTab (tabWidget->currentIndex() );
   1.250  
   1.251 @@ -2469,14 +2511,12 @@
   1.252  		bool success=true;
   1.253  		QStringList args;
   1.254  		QString browser=settings.value("/mainwindow/readerURL" ).toString();
   1.255 -		QProcess *p;
   1.256 -		if (!procBrowser ||  procBrowser->state()!=QProcess::Running)
   1.257 +		if (*browserPID==0)	//FIXME-2 need to check if browser is really still there instead of this
   1.258  		{
   1.259  			QString u=urls.takeFirst();
   1.260 -			procBrowser = new QProcess( this );
   1.261  			args<<u;
   1.262 -			procBrowser->start(browser,args);
   1.263 -			if ( !procBrowser->waitForStarted())
   1.264 +			QString workDir=QDir::currentDirPath();
   1.265 +			if (!QProcess::startDetached(browser,args,workDir,browserPID))
   1.266  			{
   1.267  				// try to set path to browser
   1.268  				QMessageBox::warning(0, 
   1.269 @@ -2485,37 +2525,37 @@
   1.270  					tr("Please use Settings->")+tr("Set application to open an URL"));
   1.271  				return;
   1.272  			}
   1.273 +			if (debug) cout << "Main::openTabs  Started konqueror-"<<*browserPID<<endl;
   1.274  #if defined(Q_OS_WIN32)
   1.275              // There's no sleep in VCEE, replace it with Qt's QThread::wait().
   1.276              this->thread()->wait(3000);
   1.277  #else
   1.278 -			sleep (3);
   1.279 +			sleep (3);	//FIXME-3 needed?
   1.280  #endif
   1.281  		}
   1.282 +
   1.283  		if (browser.contains("konqueror"))
   1.284  		{
   1.285  			for (int i=0; i<urls.size(); i++)
   1.286  			{
   1.287  				// Open new browser
   1.288  				// Try to open new tab in existing konqueror started previously by vym
   1.289 -				p=new QProcess (this);
   1.290  				args.clear();
   1.291 -#if defined(Q_OS_WIN32)
   1.292 -                // In Win32, pid is not a longlong, but a pointer to a _PROCESS_INFORMATION structure.
   1.293 -                // Redundant change in Win32, as there's no konqueror, but I wanted to follow the original logic.
   1.294 -				args<< QString("konqueror-%1").arg(procBrowser->pid()->dwProcessId)<<
   1.295 -					"konqueror-mainwindow#1"<<
   1.296 -					"newTab" <<
   1.297 -					urls.at(i);
   1.298 -#else
   1.299 +
   1.300 +/*	On KDE3 use DCOP
   1.301  				args<< QString("konqueror-%1").arg(procBrowser->pid())<<
   1.302  					"konqueror-mainwindow#1"<<
   1.303  					"newTab" <<
   1.304  					urls.at(i);
   1.305 -#endif
   1.306 -				p->start ("dcop",args);
   1.307 -				if (debug) cout << "MainWindo::openURLs  args="<<args.join(" ").toStdString()<<endl;
   1.308 -				if ( !p->waitForStarted() ) success=false;
   1.309 +*/					
   1.310 +				args<< QString("org.kde.konqueror-%1").arg(*browserPID)<<
   1.311 +					"/konqueror/MainWindow_1"<<
   1.312 +					"newTab" <<
   1.313 +					urls.at(i)<<
   1.314 +					"false";
   1.315 +				if (debug) cout << "MainWindow::openURLs  args="<<args.join(" ").toStdString()<<endl;
   1.316 +				if (!QProcess::startDetached ("qdbus",args))
   1.317 +					success=false;
   1.318  			}
   1.319  			if (!success)
   1.320  				QMessageBox::warning(0, 
   1.321 @@ -2527,10 +2567,9 @@
   1.322  			for (int i=0; i<urls.size(); i++)
   1.323  			{
   1.324  				// Try to open new tab in firefox
   1.325 -				p=new QProcess (this);
   1.326  				args<< "-remote"<< QString("openurl(%1,new-tab)").arg(urls.at(i));
   1.327 -				p->start (browser,args);
   1.328 -				if ( !p->waitForStarted() ) success=false;
   1.329 +				if (!QProcess::startDetached (browser,args))
   1.330 +					success=false;
   1.331  			}			
   1.332  			if (!success)
   1.333  				QMessageBox::warning(0, 
   1.334 @@ -2554,10 +2593,9 @@
   1.335  		QStringList args;
   1.336  		if (url=="") return;
   1.337  		QString browser=settings.value("/mainwindow/readerURL" ).toString();
   1.338 -		procBrowser = new QProcess( this );
   1.339  		args<<url;
   1.340 -		procBrowser->start(browser,args);
   1.341 -		if ( !procBrowser->waitForStarted())
   1.342 +		QString workDir=QDir::currentDirPath();
   1.343 +		if (!procBrowser->startDetached(browser,args))
   1.344  		{
   1.345  			// try to set path to browser
   1.346  			QMessageBox::warning(0, 
   1.347 @@ -2704,6 +2742,12 @@
   1.348  	if (m) m->toggleHideExport();	
   1.349  }
   1.350  
   1.351 +void Main::editAddTimestamp()
   1.352 +{
   1.353 +	VymModel *m=currentModel();
   1.354 +	if (m) m->addTimestamp();	
   1.355 +}
   1.356 +
   1.357  void Main::editMapInfo()
   1.358  {
   1.359  	VymModel *m=currentModel();
   1.360 @@ -2724,14 +2768,14 @@
   1.361  	uint xl=0;
   1.362  	BranchItem *cur=NULL;
   1.363  	BranchItem *prev=NULL;
   1.364 -	m->next(cur,prev);
   1.365 +	m->nextBranch(cur,prev);
   1.366  	while (cur) 
   1.367  	{
   1.368  		if (!cur->getNote().isEmpty() ) n++;
   1.369  		f+= cur->imageCount();
   1.370  		b++;
   1.371  		xl+=cur->xlinkCount();
   1.372 -		m->next(cur,prev);
   1.373 +		m->nextBranch(cur,prev);
   1.374  	}
   1.375  
   1.376      stats+=QString ("%1 xLinks \n").arg (xl,6);
   1.377 @@ -2784,6 +2828,18 @@
   1.378  	if (m) m->emitExpandAll();
   1.379  }
   1.380  
   1.381 +void Main::editExpandOneLevel()
   1.382 +{
   1.383 +	VymModel *m=currentModel();
   1.384 +	if (m) m->emitExpandOneLevel();
   1.385 +}
   1.386 +
   1.387 +void Main::editCollapseOneLevel()
   1.388 +{
   1.389 +	VymModel *m=currentModel();
   1.390 +	if (m) m->emitCollapseOneLevel();
   1.391 +}
   1.392 +
   1.393  void Main::editUnscrollChildren()
   1.394  {
   1.395  	VymModel *m=currentModel();
   1.396 @@ -2847,7 +2903,7 @@
   1.397  	}	
   1.398  }
   1.399  
   1.400 -void Main::editNewBranchAbove()
   1.401 +void Main::editNewBranchAbove()	// FIXME-1 can crash
   1.402  {
   1.403  	VymModel *m=currentModel();
   1.404  	if ( m)
   1.405 @@ -3368,10 +3424,20 @@
   1.406  		// History window
   1.407  		historyWindow->setCaption (vymName + " - " +tr("History for %1","Window Caption").arg(m->getFileName()));
   1.408  
   1.409 +
   1.410 +		// Expanding/collapsing
   1.411 +		actionExpandAll->setEnabled (true);
   1.412 +		actionExpandOneLevel->setEnabled (true);
   1.413 +		actionCollapseOneLevel->setEnabled (true);
   1.414  	} else
   1.415  	{
   1.416  		// Printing
   1.417  		actionFilePrint->setEnabled (false);
   1.418 +
   1.419 +		// Expanding/collapsing
   1.420 +		actionExpandAll->setEnabled (false);
   1.421 +		actionExpandOneLevel->setEnabled (false);
   1.422 +		actionCollapseOneLevel->setEnabled (false);
   1.423  	}
   1.424  
   1.425  	if (m && m->getMapLinkColorHint()==LinkableMapObj::HeadingColor) 
   1.426 @@ -3603,10 +3669,11 @@
   1.427  
   1.428  void Main::testFunction1()
   1.429  {
   1.430 +/*
   1.431  	if (!currentMapEditor()) return;
   1.432  	//currentMapEditor()->testFunction1();
   1.433 -	/*
   1.434 -	*/
   1.435 +*/
   1.436 +
   1.437  	VymModel *m=currentModel();
   1.438  	if (!m) return;
   1.439  
   1.440 @@ -3689,8 +3756,7 @@
   1.441  	Process *pdfProc = new Process();
   1.442      args << QDir::toNativeSeparators(docfile.fileName());
   1.443  
   1.444 -	pdfProc->start( settings.value("/mainwindow/readerPDF").toString(),args);
   1.445 -	if ( !pdfProc->waitForStarted() ) 
   1.446 +	if (!pdfProc->startDetached( settings.value("/mainwindow/readerPDF").toString(),args) )
   1.447  	{
   1.448  		// error handling
   1.449  		QMessageBox::warning(0,