mainwindow.cpp
changeset 445 0796c5592f00
parent 442 dfbc371b7280
child 447 72afe12da1c8
     1.1 --- a/mainwindow.cpp	Sat Mar 31 09:28:30 2007 +0000
     1.2 +++ b/mainwindow.cpp	Mon Apr 09 15:42:21 2007 +0000
     1.3 @@ -154,6 +154,7 @@
     1.4  	setupFlagActions();
     1.5      setupSettingsActions();
     1.6  	setupContextMenus();
     1.7 +	setupMacros();
     1.8      if (settings.value( "/mainwindow/showTestMenu",false).toBool()) setupTestActions();
     1.9      setupHelpActions();
    1.10      
    1.11 @@ -446,7 +447,7 @@
    1.12  	actionEditHeading=a;
    1.13      a = new QAction( tr( "Edit heading","Edit menu" ), this);
    1.14  	a->setStatusTip (tr( "edit Heading" ));
    1.15 -	a->setShortcut ( Qt::Key_F2 );					//Edit heading
    1.16 +	//a->setShortcut ( Qt::Key_F2 );					//Edit heading
    1.17  	a->setShortcutContext (Qt::WindowShortcut);
    1.18  	addAction (a);
    1.19      connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
    1.20 @@ -1427,12 +1428,12 @@
    1.21      QAction *a;
    1.22      a = new QAction( "Test function" , this);
    1.23      a->setStatusTip( "Call test function" );
    1.24 -	a->setShortcut (Qt::Key_F4 );
    1.25 +	//a->setShortcut (Qt::Key_F4 );
    1.26      connect( a, SIGNAL( triggered() ), this, SLOT( testFunction() ) );
    1.27  	testMenu->addAction (a);
    1.28      a = new QAction( "Command" , this);
    1.29      a->setStatusTip( "Enter command to call in editor" );
    1.30 -	a->setShortcut (Qt::Key_F5 );
    1.31 +	//a->setShortcut (Qt::Key_F5 );
    1.32      connect( a, SIGNAL( triggered() ), this, SLOT( testCommand() ) );
    1.33  	testMenu->addAction (a);
    1.34  }
    1.35 @@ -1556,10 +1557,10 @@
    1.36  	// Create actions
    1.37  	for (int i = 0; i < MaxRecentFiles; ++i) 
    1.38  	{
    1.39 -        recentFileActs[i] = new QAction(this);
    1.40 -        recentFileActs[i]->setVisible(false);
    1.41 -        fileLastMapsMenu->addAction(recentFileActs[i]);
    1.42 -        connect(recentFileActs[i], SIGNAL(triggered()),
    1.43 +        recentFileActions[i] = new QAction(this);
    1.44 +        recentFileActions[i]->setVisible(false);
    1.45 +        fileLastMapsMenu->addAction(recentFileActions[i]);
    1.46 +        connect(recentFileActions[i], SIGNAL(triggered()),
    1.47                  this, SLOT(fileLoadRecent()));
    1.48      }
    1.49  	setupRecentMapsMenu();
    1.50 @@ -1572,14 +1573,37 @@
    1.51      int numRecentFiles = qMin(files.size(), (int)MaxRecentFiles);
    1.52  
    1.53      for (int i = 0; i < numRecentFiles; ++i) {
    1.54 -        //QString text = tr("&%1 %2").arg(i + 1).arg(strippedName(files[i]));
    1.55          QString text = tr("&%1 %2").arg(i + 1).arg(files[i]);
    1.56 -        recentFileActs[i]->setText(text);
    1.57 -        recentFileActs[i]->setData(files[i]);
    1.58 -        recentFileActs[i]->setVisible(true);
    1.59 +        recentFileActions[i]->setText(text);
    1.60 +        recentFileActions[i]->setData(files[i]);
    1.61 +        recentFileActions[i]->setVisible(true);
    1.62      }
    1.63      for (int j = numRecentFiles; j < MaxRecentFiles; ++j)
    1.64 -        recentFileActs[j]->setVisible(false);
    1.65 +        recentFileActions[j]->setVisible(false);
    1.66 +}
    1.67 +
    1.68 +void Main::setupMacros()
    1.69 +{
    1.70 +    for (int i = 0; i <= 11; i++) 
    1.71 +	{
    1.72 +        macroActions[i] = new QAction(this);
    1.73 +        macroActions[i]->setData(i);
    1.74 +        addAction (macroActions[i]);
    1.75 +        connect(macroActions[i], SIGNAL(triggered()),
    1.76 +                this, SLOT(callMacro()));
    1.77 +	}			
    1.78 +	macroActions[0]->setShortcut ( Qt::Key_F1 );
    1.79 +	macroActions[1]->setShortcut ( Qt::Key_F2 );
    1.80 +	macroActions[2]->setShortcut ( Qt::Key_F3 );
    1.81 +	macroActions[3]->setShortcut ( Qt::Key_F4 );
    1.82 +	macroActions[4]->setShortcut ( Qt::Key_F5 );
    1.83 +	macroActions[5]->setShortcut ( Qt::Key_F6 );
    1.84 +	macroActions[6]->setShortcut ( Qt::Key_F7 );
    1.85 +	macroActions[7]->setShortcut ( Qt::Key_F8 );
    1.86 +	macroActions[8]->setShortcut ( Qt::Key_F9 );
    1.87 +	macroActions[9]->setShortcut ( Qt::Key_F10 );
    1.88 +	macroActions[10]->setShortcut ( Qt::Key_F11 );
    1.89 +	macroActions[11]->setShortcut ( Qt::Key_F12 );
    1.90  }
    1.91  
    1.92  void Main::hideEvent (QHideEvent * )
    1.93 @@ -2257,9 +2281,9 @@
    1.94  		QStringList fl;
    1.95  		QFileDialog *fd=new QFileDialog (this);
    1.96  		fd->setCaption (tr("Export map as image"));
    1.97 +		fd->setDirectory (lastImageDir);
    1.98  		fd->setFileMode(QFileDialog::AnyFile);
    1.99  		fd->setFilters  (imageIO.getFilters() );
   1.100 -		fd->setDirectory (lastImageDir);
   1.101  		if (fd->exec())
   1.102  		{
   1.103  			fl=fd->selectedFiles();
   1.104 @@ -3603,3 +3627,19 @@
   1.105  	QMessageBox::aboutQt( this, "Qt Application Example" );
   1.106  }
   1.107  
   1.108 +void Main::callMacro ()
   1.109 +{
   1.110 +    QAction *action = qobject_cast<QAction *>(sender());
   1.111 +	int i=-1;
   1.112 +    if (action)
   1.113 +	{
   1.114 +        i=action->data().toInt();
   1.115 +		QString m=settings.value(QString("/macros/macro-%1").arg(i) ).toString();
   1.116 +		if (! m.isEmpty())
   1.117 +		{
   1.118 +			cout <<"Main::callMacro  m="<<m.ascii()<<endl;
   1.119 +			currentMapEditor()->runScript (m);
   1.120 +		}	
   1.121 +	}	
   1.122 +}
   1.123 +