Slightly improved scripting abilities
authorinsilmaril
Wed Mar 21 11:51:38 2007 +0000 (2007-03-21)
changeset 438eae9abe70d7c
parent 437 918417b015e0
child 439 717b20c56358
Slightly improved scripting abilities
simplescripteditor.cpp
simplescripteditor.h
simplescripteditor.ui
     1.1 --- a/simplescripteditor.cpp	Wed Mar 21 11:51:38 2007 +0000
     1.2 +++ b/simplescripteditor.cpp	Wed Mar 21 11:51:38 2007 +0000
     1.3 @@ -12,16 +12,17 @@
     1.4  {
     1.5  	ui.setupUi (this);
     1.6  
     1.7 -	connect ( ui.loadButton, SIGNAL (clicked() ), this, SLOT (loadScriptClicked() ));
     1.8 -	connect ( ui.saveButton, SIGNAL (clicked() ), this, SLOT (saveScriptClicked() ));
     1.9 -	connect ( ui.runButton,  SIGNAL (clicked() ), this, SLOT (runScriptClicked() ));
    1.10 +	connect ( ui.openButton, SIGNAL (clicked() ), this, SLOT (openClicked() ));
    1.11 +	connect ( ui.saveButton, SIGNAL (clicked() ), this, SLOT (saveClicked() ));
    1.12 +	connect ( ui.saveAsButton, SIGNAL (clicked() ), this, SLOT (saveAsClicked() ));
    1.13 +	connect ( ui.runButton,  SIGNAL (clicked() ), this, SLOT (runClicked() ));
    1.14  
    1.15  
    1.16  	// Initialize Editor
    1.17  	QFont font;
    1.18  	font.setFamily("Courier");
    1.19  	font.setFixedPitch(true);
    1.20 -	font.setPointSize(10);
    1.21 +	font.setPointSize(12);
    1.22  	ui.editor->setFont(font);
    1.23  
    1.24  	highlighter = new Highlighter(ui.editor->document());
    1.25 @@ -45,7 +46,15 @@
    1.26  	ui.editor->setText(s);
    1.27  }
    1.28  
    1.29 -void SimpleScriptEditor::saveScriptClicked()
    1.30 +void SimpleScriptEditor::saveClicked()
    1.31 +{
    1.32 +	if (filename.isEmpty() )
    1.33 +		saveAsClicked();
    1.34 +	else
    1.35 +		saveScript();
    1.36 +}
    1.37 +
    1.38 +void SimpleScriptEditor::saveAsClicked()
    1.39  {
    1.40  	QString fn = QFileDialog::getSaveFileName( 
    1.41  		this, 
    1.42 @@ -85,7 +94,7 @@
    1.43      }
    1.44  }
    1.45  
    1.46 -void SimpleScriptEditor::loadScriptClicked()
    1.47 +void SimpleScriptEditor::openClicked()
    1.48  {
    1.49  	QFileDialog *fd=new QFileDialog( this);
    1.50  	QStringList types;
    1.51 @@ -95,18 +104,17 @@
    1.52  	fd->setDirectory (QDir().current());
    1.53  	fd->setCaption (vymName + " - " + tr("Load script"));
    1.54  	fd->show();
    1.55 -	QString fn;
    1.56  	if ( fd->exec() == QDialog::Accepted )
    1.57 -		fn = fd->selectedFile();
    1.58 +		filename = fd->selectedFile();
    1.59  
    1.60 -	if ( !fn.isEmpty() )
    1.61 +	if ( !filename.isEmpty() )
    1.62  	{
    1.63 -		QFile f( fn );
    1.64 +		QFile f( filename );
    1.65  		if ( !f.open( QIODevice::ReadOnly ) )
    1.66  		{
    1.67  			QMessageBox::warning(0, 
    1.68  				tr("Error"),
    1.69 -				tr("Couldn't open %1.\n").arg(fn));
    1.70 +				tr("Couldn't open %1.\n").arg(filename));
    1.71  			return;
    1.72  		}	
    1.73  
    1.74 @@ -116,7 +124,7 @@
    1.75  	}
    1.76  }
    1.77  
    1.78 -void SimpleScriptEditor::runScriptClicked()
    1.79 +void SimpleScriptEditor::runClicked()
    1.80  {
    1.81  	emit runScript (ui.editor->text() );
    1.82  }
     2.1 --- a/simplescripteditor.h	Wed Mar 21 11:51:38 2007 +0000
     2.2 +++ b/simplescripteditor.h	Wed Mar 21 11:51:38 2007 +0000
     2.3 @@ -15,9 +15,10 @@
     2.4  	void setScript(const QString &);
     2.5  
     2.6  public slots:
     2.7 -	void saveScriptClicked();
     2.8 -	void loadScriptClicked();
     2.9 -	void runScriptClicked();
    2.10 +	void saveClicked();
    2.11 +	void saveAsClicked();
    2.12 +	void openClicked();
    2.13 +	void runClicked();
    2.14  
    2.15  signals:
    2.16  	void runScript (QString);
     3.1 --- a/simplescripteditor.ui	Wed Mar 21 11:51:38 2007 +0000
     3.2 +++ b/simplescripteditor.ui	Wed Mar 21 11:51:38 2007 +0000
     3.3 @@ -12,67 +12,76 @@
     3.4    <property name="windowTitle" >
     3.5     <string>Simple Script Editor</string>
     3.6    </property>
     3.7 -  <layout class="QHBoxLayout" >
     3.8 +  <layout class="QGridLayout" >
     3.9     <property name="margin" >
    3.10      <number>9</number>
    3.11     </property>
    3.12     <property name="spacing" >
    3.13      <number>6</number>
    3.14     </property>
    3.15 -   <item>
    3.16 +   <item row="4" column="1" >
    3.17 +    <spacer>
    3.18 +     <property name="orientation" >
    3.19 +      <enum>Qt::Vertical</enum>
    3.20 +     </property>
    3.21 +     <property name="sizeHint" >
    3.22 +      <size>
    3.23 +       <width>75</width>
    3.24 +       <height>211</height>
    3.25 +      </size>
    3.26 +     </property>
    3.27 +    </spacer>
    3.28 +   </item>
    3.29 +   <item row="3" column="1" >
    3.30 +    <widget class="QPushButton" name="saveAsButton" >
    3.31 +     <property name="text" >
    3.32 +      <string>Save as</string>
    3.33 +     </property>
    3.34 +     <property name="shortcut" >
    3.35 +      <string/>
    3.36 +     </property>
    3.37 +    </widget>
    3.38 +   </item>
    3.39 +   <item row="2" column="1" >
    3.40 +    <widget class="QPushButton" name="saveButton" >
    3.41 +     <property name="text" >
    3.42 +      <string>Save</string>
    3.43 +     </property>
    3.44 +     <property name="shortcut" >
    3.45 +      <string>Qt::CTRL + Qt::Key_S</string>
    3.46 +     </property>
    3.47 +    </widget>
    3.48 +   </item>
    3.49 +   <item row="1" column="1" >
    3.50 +    <widget class="QPushButton" name="openButton" >
    3.51 +     <property name="text" >
    3.52 +      <string>Open</string>
    3.53 +     </property>
    3.54 +     <property name="shortcut" >
    3.55 +      <string>Qt::CTRL +Qt::Key_O</string>
    3.56 +     </property>
    3.57 +    </widget>
    3.58 +   </item>
    3.59 +   <item row="0" column="1" >
    3.60 +    <widget class="QPushButton" name="runButton" >
    3.61 +     <property name="text" >
    3.62 +      <string>Run</string>
    3.63 +     </property>
    3.64 +     <property name="shortcut" >
    3.65 +      <string>Qt::CTRL + Qt::Key_R</string>
    3.66 +     </property>
    3.67 +    </widget>
    3.68 +   </item>
    3.69 +   <item row="5" column="1" >
    3.70 +    <widget class="QPushButton" name="closeButton" >
    3.71 +     <property name="text" >
    3.72 +      <string>Close</string>
    3.73 +     </property>
    3.74 +    </widget>
    3.75 +   </item>
    3.76 +   <item rowspan="6" row="0" column="0" >
    3.77      <widget class="QTextEdit" name="editor" />
    3.78     </item>
    3.79 -   <item>
    3.80 -    <layout class="QVBoxLayout" >
    3.81 -     <property name="margin" >
    3.82 -      <number>0</number>
    3.83 -     </property>
    3.84 -     <property name="spacing" >
    3.85 -      <number>6</number>
    3.86 -     </property>
    3.87 -     <item>
    3.88 -      <widget class="QPushButton" name="runButton" >
    3.89 -       <property name="text" >
    3.90 -        <string>Run</string>
    3.91 -       </property>
    3.92 -      </widget>
    3.93 -     </item>
    3.94 -     <item>
    3.95 -      <widget class="QPushButton" name="loadButton" >
    3.96 -       <property name="text" >
    3.97 -        <string>Load</string>
    3.98 -       </property>
    3.99 -      </widget>
   3.100 -     </item>
   3.101 -     <item>
   3.102 -      <widget class="QPushButton" name="saveButton" >
   3.103 -       <property name="text" >
   3.104 -        <string>Save</string>
   3.105 -       </property>
   3.106 -      </widget>
   3.107 -     </item>
   3.108 -     <item>
   3.109 -      <spacer>
   3.110 -       <property name="orientation" >
   3.111 -        <enum>Qt::Vertical</enum>
   3.112 -       </property>
   3.113 -       <property name="sizeHint" >
   3.114 -        <size>
   3.115 -         <width>20</width>
   3.116 -         <height>40</height>
   3.117 -        </size>
   3.118 -       </property>
   3.119 -      </spacer>
   3.120 -     </item>
   3.121 -     <item>
   3.122 -      <widget class="QPushButton" name="closeButton" >
   3.123 -       <property name="text" >
   3.124 -        <string>Close</string>
   3.125 -       </property>
   3.126 -      </widget>
   3.127 -     </item>
   3.128 -    </layout>
   3.129 -   </item>
   3.130    </layout>
   3.131   </widget>
   3.132   <resources/>