mainwindow.cpp
branchqt4-port
changeset 16 41c3d7f9f532
parent 15 699f28529079
child 17 557239819c45
     1.1 --- a/mainwindow.cpp	Tue Aug 15 12:01:14 2006 +0000
     1.2 +++ b/mainwindow.cpp	Tue Aug 29 08:31:42 2006 +0000
     1.3 @@ -63,6 +63,7 @@
     1.4  extern QAction *actionEditToggleScroll;
     1.5  extern QAction* actionEditOpenURL;
     1.6  extern QAction* actionEditOpenURLTab;
     1.7 +extern QAction* actionEditOpenMultipleURLTabs;
     1.8  extern QAction* actionEditURL;
     1.9  extern QAction* actionEditHeading2URL;
    1.10  extern QAction* actionEditBugzilla2URL;
    1.11 @@ -214,6 +215,9 @@
    1.12  	connect( tabWidget, SIGNAL( currentChanged( QWidget * ) ), 
    1.13  		this, SLOT( editorChanged( QWidget * ) ) );
    1.14  
    1.15 +	lineedit=new QLineEdit (this);
    1.16 +	lineedit->hide();
    1.17 +
    1.18  	setCentralWidget(tabWidget);	
    1.19  
    1.20      setupFileActions();
    1.21 @@ -459,14 +463,13 @@
    1.22  	editMenu->addAction (a);
    1.23  	actionEditUndo=a;
    1.24      
    1.25 -    if (settings.value( "/mainwindow/showTestMenu",false).toBool()) 
    1.26 -	{
    1.27 -		a = new QAction( QPixmap( iconPath+"redo.png"), tr( "&Redo" ), this); 
    1.28 -		a->setStatusTip (tr( "Redo" ));
    1.29 -		a->setShortcut (Qt::CTRL + Qt::Key_Y );
    1.30 -		editMenu->addAction (a);
    1.31 -		connect( a, SIGNAL( triggered() ), this, SLOT( editRedo() ) );
    1.32 -	}
    1.33 +	a = new QAction( QPixmap( iconPath+"redo.png"), tr( "&Redo" ), this); 
    1.34 +	a->setStatusTip (tr( "Redo" ));
    1.35 +	a->setShortcut (Qt::CTRL + Qt::Key_Y );
    1.36 +    tb->addAction (a);
    1.37 +	editMenu->addAction (a);
    1.38 +	connect( a, SIGNAL( triggered() ), this, SLOT( editRedo() ) );
    1.39 +	actionEditRedo=a;
    1.40     
    1.41  	editMenu->addSeparator();
    1.42      a = new QAction(QPixmap( iconPath+"editcopy.png"), tr( "&Copy" ), this);
    1.43 @@ -500,14 +503,14 @@
    1.44      a = new QAction(tr( "Edit heading" ),this);
    1.45  	a->setStatusTip ( tr( "edit Heading" ));
    1.46  	a->setShortcut ( Qt::Key_Enter);
    1.47 -	a->setShortcutContext (Qt::WindowShortcut);
    1.48 +//	a->setShortcutContext (Qt::WindowShortcut);
    1.49  	addAction (a);
    1.50      connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
    1.51  	actionListBranches.append(a);
    1.52      a = new QAction( tr( "Edit heading" ), this);
    1.53  	a->setStatusTip (tr( "edit Heading" ));
    1.54  	a->setShortcut (Qt::Key_Return );
    1.55 -	a->setShortcutContext (Qt::WindowShortcut);
    1.56 +	//a->setShortcutContext (Qt::WindowShortcut);
    1.57  	addAction (a);
    1.58      connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
    1.59  	actionListBranches.append(a);
    1.60 @@ -675,6 +678,13 @@
    1.61      connect( a, SIGNAL( triggered() ), this, SLOT( editOpenURLTab() ) );
    1.62  	actionEditOpenURLTab=a;
    1.63  
    1.64 +	a = new QAction( tr( "Open all URLs in subtree" ), this);
    1.65 +	a->setStatusTip (tr( "Open all URLs in subtree" ));
    1.66 +	a->setShortcut (Qt::CTRL+Qt::Key_U );
    1.67 +	addAction(a);
    1.68 +    connect( a, SIGNAL( triggered() ), this, SLOT( editOpenMultipleURLTabs() ) );
    1.69 +	actionEditOpenMultipleURLTabs=a;
    1.70 +
    1.71  	a = new QAction(QPixmap(), tr( "Edit URL"+QString("...") ), this);
    1.72  	a->setStatusTip ( tr( "Edit URL" ) );
    1.73  	a->setShortcut (Qt::SHIFT + Qt::CTRL + Qt::Key_U );
    1.74 @@ -1503,7 +1513,6 @@
    1.75  		branchAddContextMenu->addSeparator();	
    1.76  		branchAddContextMenu->addAction ( actionEditLoadImage);
    1.77  		branchAddContextMenu->addSeparator();	
    1.78 -		branchAddContextMenu->addAction ( actionEditLoadImage);
    1.79  		branchAddContextMenu->addAction ( actionEditImportAdd );
    1.80  		branchAddContextMenu->addAction ( actionEditImportReplace );
    1.81  
    1.82 @@ -1520,10 +1529,11 @@
    1.83  	branchContextMenu->addSeparator();	
    1.84  	branchContextMenu->addAction ( actionEditOpenURL );
    1.85  	branchContextMenu->addAction ( actionEditOpenURLTab );
    1.86 +	branchContextMenu->addAction ( actionEditOpenMultipleURLTabs );
    1.87  	branchContextMenu->addAction ( actionEditURL );
    1.88  	branchContextMenu->addAction ( actionEditHeading2URL );
    1.89  	branchContextMenu->addAction ( actionEditBugzilla2URL );
    1.90 -    if (settings.value( "/mainwindow/showTestMenu",false).toBool() )
    1.91 +    if (settings.value( "/mainwindow/showTestMenu",true).toBool() )
    1.92  	{
    1.93  		branchContextMenu->addAction ( actionEditFATE2URL );
    1.94  	}	
    1.95 @@ -2433,6 +2443,7 @@
    1.96  				QMessageBox::Cancel | QMessageBox::Escape );
    1.97  			mb.setButtonText( QMessageBox::Yes, tr("Save map") );
    1.98  			mb.setButtonText( QMessageBox::No, tr("Discard changes") );
    1.99 +			mb.setModal (true);
   1.100  			mb.show();
   1.101  			mb.setActiveWindow();
   1.102  			switch( mb.exec() ) {
   1.103 @@ -2508,20 +2519,86 @@
   1.104  	currentMapEditor()->findReset();
   1.105  }
   1.106  
   1.107 +void Main::openTabs(QStringList urls)
   1.108 +{
   1.109 +	if (!urls.isEmpty())
   1.110 +	{	
   1.111 +		bool success=true;
   1.112 +		QStringList args;
   1.113 +		QString browser=settings.value("/mainwindow/readerURL" ).toString();
   1.114 +		QProcess *p;
   1.115 +		if (!procBrowser ||  procBrowser->state()!=QProcess::Running)
   1.116 +		{
   1.117 +			QString u=urls.takeFirst();
   1.118 +			procBrowser = new QProcess( this );
   1.119 +			args<<u;
   1.120 +			procBrowser->start(browser,args);
   1.121 +			if ( !procBrowser->waitForStarted())
   1.122 +			{
   1.123 +				// try to set path to browser
   1.124 +				QMessageBox::warning(0, 
   1.125 +					tr("Warning"),
   1.126 +					tr("Couldn't find a viewer to open %1.\n").arg(u)+
   1.127 +					tr("Please use Settings->")+tr("Set application to open an URL"));
   1.128 +				return;
   1.129 +			}
   1.130 +			sleep (3);
   1.131 +		}
   1.132 +		if (browser.contains("konqueror"))
   1.133 +		{
   1.134 +			for (int i=0; i<urls.size(); i++)
   1.135 +			{
   1.136 +				// Open new browser
   1.137 +				// Try to open new tab in existing konqueror started previously by vym
   1.138 +				p=new QProcess (this);
   1.139 +				args.clear();
   1.140 +				args<< QString("konqueror-%1").arg(procBrowser->pid())<< 
   1.141 +					"konqueror-mainwindow#1"<< 
   1.142 +					"newTab" << 
   1.143 +					urls.at(i);
   1.144 +				p->start ("dcop",args);
   1.145 +				if ( !p->waitForStarted() ) success=false;
   1.146 +			}
   1.147 +			if (!success)
   1.148 +				QMessageBox::warning(0, 
   1.149 +					tr("Warning"),
   1.150 +					tr("Couldn't start %1 to open a new tab in %2.").arg("dcop").arg("konqueror"));
   1.151 +			return;		
   1.152 +		} else if (browser.contains ("firefox") || browser.contains ("mozilla") )
   1.153 +		{
   1.154 +			for (int i=0; i<urls.size(); i++)
   1.155 +			{
   1.156 +				// Try to open new tab in firefox
   1.157 +				p=new QProcess (this);
   1.158 +				args<< "-remote"<< QString("openurl(%1,new-tab)").arg(urls.at(i));
   1.159 +				p->start (browser,args);
   1.160 +				if ( !p->waitForStarted() ) success=false;
   1.161 +			}			
   1.162 +			if (!success)
   1.163 +				QMessageBox::warning(0, 
   1.164 +					tr("Warning"),
   1.165 +					tr("Couldn't start %1 to open a new tab").arg(browser));
   1.166 +			return;		
   1.167 +		}			
   1.168 +		QMessageBox::warning(0, 
   1.169 +			tr("Warning"),
   1.170 +			tr("Sorry, currently only Konqueror and Mozilla support tabbed browsing."));
   1.171 +	}	
   1.172 +}
   1.173 +
   1.174  void Main::editOpenURL()
   1.175  {
   1.176  	// Open new browser
   1.177  	if (currentMapEditor())
   1.178  	{	
   1.179  	    QString url=currentMapEditor()->getURL();
   1.180 +		QStringList args;
   1.181  		if (url=="") return;
   1.182  		QString browser=settings.value("/mainwindow/readerURL" ).toString();
   1.183 -		procBrowser = new Q3Process( this );
   1.184 -
   1.185 -		procBrowser->addArgument( browser);
   1.186 -		procBrowser->addArgument( url);
   1.187 -
   1.188 -		if ( !procBrowser->start() ) 
   1.189 +		procBrowser = new QProcess( this );
   1.190 +		args<<url;
   1.191 +		procBrowser->start(browser,args);
   1.192 +		if ( !procBrowser->waitForStarted())
   1.193  		{
   1.194  			// try to set path to browser
   1.195  			QMessageBox::warning(0, 
   1.196 @@ -2536,45 +2613,24 @@
   1.197  {
   1.198  	if (currentMapEditor())
   1.199  	{	
   1.200 -	    QString url=currentMapEditor()->getURL();
   1.201 -		if (url=="") return;
   1.202 -		QString browser=settings.value("/mainwindow/readerURL" ).toString();
   1.203 -		if (procBrowser && procBrowser->isRunning())
   1.204 -		{
   1.205 -			if (browser.contains("konqueror"))
   1.206 -			{
   1.207 -				// Try to open new tab in existing konqueror started previously by vym
   1.208 -				Q3Process *p=new Q3Process (this);
   1.209 -				p->addArgument ("dcop");
   1.210 -				p->addArgument (QString("konqueror-%1").arg(procBrowser->processIdentifier()));
   1.211 -				p->addArgument ("konqueror-mainwindow#1");
   1.212 -				p->addArgument ("newTab");
   1.213 -				p->addArgument (url);
   1.214 -				if ( !p->start() ) 
   1.215 -					// try to set browser
   1.216 -					QMessageBox::warning(0, 
   1.217 -						tr("Warning"),
   1.218 -						tr("Couldn't start %1 to open a new tab in %2.").arg("dcop").arg("konqueror"));
   1.219 -				return;		
   1.220 -			} else if (browser.contains ("firefox") || browser.contains ("mozilla") )
   1.221 -			{
   1.222 -				// Try to open new tab in firefox
   1.223 -				Q3Process *p=new Q3Process (this);
   1.224 -				p->addArgument (browser);
   1.225 -				p->addArgument ("-remote");
   1.226 -				p->addArgument (QString("openurl(%1,new-tab)").arg(url));
   1.227 -				if ( !p->start() ) 
   1.228 -					// try to set browser
   1.229 -					QMessageBox::warning(0, 
   1.230 -						tr("Warning"),
   1.231 -						tr("Couldn't start %1 to open a new tab").arg(browser));
   1.232 -				return;		
   1.233 -			}
   1.234 -		}
   1.235 -		// Open new browser
   1.236 -		editOpenURL();
   1.237 +	    QStringList urls;
   1.238 +		urls.append(currentMapEditor()->getURL());
   1.239 +		openTabs (urls);
   1.240  	}	
   1.241  }
   1.242 +void Main::editOpenMultipleURLTabs()
   1.243 +{
   1.244 +	if (currentMapEditor())
   1.245 +	{	
   1.246 +	    QStringList urls;
   1.247 +		urls.append ("www.suse.de");
   1.248 +		urls.append ("www.google.de");
   1.249 +		urls.append ("www.heise.de");
   1.250 +		urls.append ("www.insilmaril.de");
   1.251 +		openTabs (urls);
   1.252 +	}	
   1.253 +}
   1.254 +
   1.255  
   1.256  void Main::editURL()
   1.257  {
   1.258 @@ -2600,6 +2656,54 @@
   1.259  	    currentMapEditor()->editFATE2URL();
   1.260  }
   1.261  
   1.262 +void Main::editHeading()
   1.263 +{
   1.264 +	if (lineedit->isVisible())
   1.265 +	{
   1.266 +		if (currentMapEditor())
   1.267 +			currentMapEditor()->setHeading(lineedit->text());
   1.268 +		lineedit->releaseKeyboard();
   1.269 +		lineedit->hide();
   1.270 +		setFocus();
   1.271 +	} else
   1.272 +	{
   1.273 +		if (currentMapEditor())
   1.274 +		{
   1.275 +			bool ok;
   1.276 +			QPoint p;
   1.277 +			QString s=currentMapEditor()->getHeading(ok,p);
   1.278 +
   1.279 +			if (ok)
   1.280 +			{
   1.281 +#if defined(Q_OS_MACX)
   1.282 +				p = currentMapEditor()->mapToGlobal( currentMapEditor()->worldMatrix().map( p));
   1.283 +				QDialog *d =new QDialog(NULL);
   1.284 +				QLineEdit *le=new QLineEdit (d);
   1.285 +				d->setWindowFlags (Qt::FramelessWindowHint);
   1.286 +				d->setGeometry(p.x(),p.y(),200,25);
   1.287 +				le->resize (d->size());
   1.288 +				le->setText (s);
   1.289 +				le->selectAll();
   1.290 +				connect (le, SIGNAL (returnPressed()), d, SLOT (accept()));
   1.291 +				d->activateWindow();
   1.292 +				d->exec();
   1.293 +				currentMapEditor()->setHeading (le->text());
   1.294 +#else
   1.295 +				p = currentMapEditor()->mapTo(this, currentMapEditor()->worldMatrix().map( p));
   1.296 +				lineedit->setGeometry(p.x(),p.y(),200,25);
   1.297 +				lineedit->setText(s);
   1.298 +				lineedit->setCursorPosition(1);
   1.299 +				lineedit->selectAll();
   1.300 +				lineedit->show();
   1.301 +				lineedit->grabKeyboard();
   1.302 +				lineedit->setFocus();
   1.303 +#endif
   1.304 +
   1.305 +			}
   1.306 +		}
   1.307 +	}
   1.308 +}
   1.309 +
   1.310  void Main::editOpenVymLink()
   1.311  {
   1.312  	// Get current path to map
   1.313 @@ -2689,15 +2793,10 @@
   1.314  	}	
   1.315  }
   1.316  
   1.317 -void Main::editHeading()
   1.318 -{
   1.319 -	if (currentMapEditor())
   1.320 -		currentMapEditor()->editHeading();
   1.321 -}
   1.322 -
   1.323  void Main::editNewBranch()
   1.324  {
   1.325 -	if (currentMapEditor())
   1.326 +
   1.327 +	if (!lineedit->isVisible() && currentMapEditor())
   1.328  		currentMapEditor()->addNewBranch(0);
   1.329  }
   1.330