diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 114a878c64ce6f8223cfd22d76a20eb16d177e5e (patch) | |
tree | acaf47eb0fa12142d3896416a69e74cbf5a72242 /languages/ruby/app_templates/qtrubyapp | |
download | tdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.tar.gz tdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdevelop@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'languages/ruby/app_templates/qtrubyapp')
-rw-r--r-- | languages/ruby/app_templates/qtrubyapp/Makefile.am | 18 | ||||
-rw-r--r-- | languages/ruby/app_templates/qtrubyapp/README | 29 | ||||
-rw-r--r-- | languages/ruby/app_templates/qtrubyapp/app-Makefile | 7 | ||||
-rw-r--r-- | languages/ruby/app_templates/qtrubyapp/app.filelist | 3 | ||||
-rw-r--r-- | languages/ruby/app_templates/qtrubyapp/fileopen.xpm | 22 | ||||
-rw-r--r-- | languages/ruby/app_templates/qtrubyapp/fileprint.xpm | 24 | ||||
-rw-r--r-- | languages/ruby/app_templates/qtrubyapp/filesave.xpm | 22 | ||||
-rw-r--r-- | languages/ruby/app_templates/qtrubyapp/main.rb | 10 | ||||
-rw-r--r-- | languages/ruby/app_templates/qtrubyapp/qtrubyapp.kdevelop | 83 | ||||
-rw-r--r-- | languages/ruby/app_templates/qtrubyapp/qtrubyapp.kdevtemplate | 140 | ||||
-rw-r--r-- | languages/ruby/app_templates/qtrubyapp/qtrubyapp.png | bin | 0 -> 5245 bytes | |||
-rw-r--r-- | languages/ruby/app_templates/qtrubyapp/qtrubyapp.rb | 253 |
12 files changed, 611 insertions, 0 deletions
diff --git a/languages/ruby/app_templates/qtrubyapp/Makefile.am b/languages/ruby/app_templates/qtrubyapp/Makefile.am new file mode 100644 index 00000000..7fc1c803 --- /dev/null +++ b/languages/ruby/app_templates/qtrubyapp/Makefile.am @@ -0,0 +1,18 @@ +dataFiles = main.rb qtrubyapp.rb qtrubyapp.png qtrubyapp.kdevelop \ + filesave.xpm fileopen.xpm fileprint.xpm app.filelist app-Makefile README + +templateName = qtrubyapp + +### no need to change below: +template_DATA = $(templateName).kdevtemplate +templatedir = ${appwizarddatadir}/templates + +appwizarddatadir = ${kde_datadir}/kdevappwizard +$(templateName).tar.gz: ${dataFiles} + $(TAR) -cf $(templateName).tar -C $(srcdir) ${dataFiles} + $(GZIP_COMMAND) -f9 $(templateName).tar + +archivedir = ${appwizarddatadir} +archive_DATA = $(templateName).tar.gz ${templateName}.png + +CLEANFILES = *.tar.gz diff --git a/languages/ruby/app_templates/qtrubyapp/README b/languages/ruby/app_templates/qtrubyapp/README new file mode 100644 index 00000000..9468893b --- /dev/null +++ b/languages/ruby/app_templates/qtrubyapp/README @@ -0,0 +1,29 @@ +QtRuby App template quick start +Author: Anne-Marie Mahfouf +Date: 2006-12-05 +----------------------------------------------- + +This README file explains you some basic things for starting with +this application template. +----------------------------------------------- + +-- REQUIREMENTS -- +you need +- Qt version might be 3.3.4 or 3.3.5. +- kdelibs 3.5 and kdelibs headers 3.5 (devel package) in order to build this template. +- qtruby either from your distribution or from the kdebindings module or also from +http://rubyforge.org/projects/korundum/. +If you use the kdebindings module you need to build kdebindings/smoke/qt and then kdebindings/qtruby. + +----------------------------------------------- + +-- RUN -- +You will see that the Build menu in KDevelop is now adapted to Ruby. +In the Build menu, choose Run or use Shift + F9 to see your project running. + +----------------------------------------------- + +-- RELEVANT LINK -- +http://developer.kde.org/language-bindings/ruby/index.html + +In KDevelop Documentation, you can find a Ruby tutorial.
\ No newline at end of file diff --git a/languages/ruby/app_templates/qtrubyapp/app-Makefile b/languages/ruby/app_templates/qtrubyapp/app-Makefile new file mode 100644 index 00000000..88b5556e --- /dev/null +++ b/languages/ruby/app_templates/qtrubyapp/app-Makefile @@ -0,0 +1,7 @@ +uis := $(wildcard *.ui) + +all: $(uis) + @for name in $^; do rbuic $$name > `echo $$name | awk -F '\\\.ui$$' '{ print $$1 }' 2> /dev/null`.rb; echo "Running rbuic on $$name"; done + +clean: $(uis) + @for name in $^; do rm -f `echo $$name | awk -F '\\\.ui$$' '{ print $$1 }' 2> /dev/null`.rb; done diff --git a/languages/ruby/app_templates/qtrubyapp/app.filelist b/languages/ruby/app_templates/qtrubyapp/app.filelist new file mode 100644 index 00000000..339e6998 --- /dev/null +++ b/languages/ruby/app_templates/qtrubyapp/app.filelist @@ -0,0 +1,3 @@ +# KDevelop Custom Project File List +main.rb +%{APPNAMELC}.rb diff --git a/languages/ruby/app_templates/qtrubyapp/fileopen.xpm b/languages/ruby/app_templates/qtrubyapp/fileopen.xpm new file mode 100644 index 00000000..880417ee --- /dev/null +++ b/languages/ruby/app_templates/qtrubyapp/fileopen.xpm @@ -0,0 +1,22 @@ +/* XPM */ +static const char *fileopen[] = { +" 16 13 5 1", +". c #040404", +"# c #808304", +"a c None", +"b c #f3f704", +"c c #f3f7f3", +"aaaaaaaaa...aaaa", +"aaaaaaaa.aaa.a.a", +"aaaaaaaaaaaaa..a", +"a...aaaaaaaa...a", +".bcb.......aaaaa", +".cbcbcbcbc.aaaaa", +".bcbcbcbcb.aaaaa", +".cbcb...........", +".bcb.#########.a", +".cb.#########.aa", +".b.#########.aaa", +"..#########.aaaa", +"...........aaaaa" +}; diff --git a/languages/ruby/app_templates/qtrubyapp/fileprint.xpm b/languages/ruby/app_templates/qtrubyapp/fileprint.xpm new file mode 100644 index 00000000..6ada912f --- /dev/null +++ b/languages/ruby/app_templates/qtrubyapp/fileprint.xpm @@ -0,0 +1,24 @@ +/* XPM */ +static const char *fileprint[] = { +" 16 14 6 1", +". c #000000", +"# c #848284", +"a c #c6c3c6", +"b c #ffff00", +"c c #ffffff", +"d c None", +"ddddd.........dd", +"dddd.cccccccc.dd", +"dddd.c.....c.ddd", +"ddd.cccccccc.ddd", +"ddd.c.....c....d", +"dd.cccccccc.a.a.", +"d..........a.a..", +".aaaaaaaaaa.a.a.", +".............aa.", +".aaaaaa###aa.a.d", +".aaaaaabbbaa...d", +".............a.d", +"d.aaaaaaaaa.a.dd", +"dd...........ddd" +}; diff --git a/languages/ruby/app_templates/qtrubyapp/filesave.xpm b/languages/ruby/app_templates/qtrubyapp/filesave.xpm new file mode 100644 index 00000000..bd6870f4 --- /dev/null +++ b/languages/ruby/app_templates/qtrubyapp/filesave.xpm @@ -0,0 +1,22 @@ +/* XPM */ +static const char *filesave[] = { +" 14 14 4 1", +". c #040404", +"# c #808304", +"a c #bfc2bf", +"b c None", +"..............", +".#.aaaaaaaa.a.", +".#.aaaaaaaa...", +".#.aaaaaaaa.#.", +".#.aaaaaaaa.#.", +".#.aaaaaaaa.#.", +".#.aaaaaaaa.#.", +".##........##.", +".############.", +".##.........#.", +".##......aa.#.", +".##......aa.#.", +".##......aa.#.", +"b............." +}; diff --git a/languages/ruby/app_templates/qtrubyapp/main.rb b/languages/ruby/app_templates/qtrubyapp/main.rb new file mode 100644 index 00000000..6f4bceae --- /dev/null +++ b/languages/ruby/app_templates/qtrubyapp/main.rb @@ -0,0 +1,10 @@ +require 'Qt' +require '%{APPNAMELC}.rb' + +a = Qt::Application.new( ARGV ) +mw = %{APPNAMESC}.new +mw.caption = "%{APPNAMESC}" +mw.show +a.connect( a, SIGNAL('lastWindowClosed()'), a, SLOT('quit()') ) +a.exec + diff --git a/languages/ruby/app_templates/qtrubyapp/qtrubyapp.kdevelop b/languages/ruby/app_templates/qtrubyapp/qtrubyapp.kdevelop new file mode 100644 index 00000000..4afe7bca --- /dev/null +++ b/languages/ruby/app_templates/qtrubyapp/qtrubyapp.kdevelop @@ -0,0 +1,83 @@ +<?xml version="1.0"?> +<kdevelop> + <general> + <author>%{AUTHOR}</author> + <email>%{EMAIL}</email> + <version>%{VERSION}</version> + <projectmanagement>KDevCustomProject</projectmanagement> + <primarylanguage>Ruby</primarylanguage> + <keywords> + <keyword>Ruby</keyword> + <keyword>Qt</keyword> + </keywords> + </general> + <kdevcustomproject> + <general> + <activedir/> + </general> + </kdevcustomproject> + <kdevfileview> + <groups> + <group pattern="*.rb" name="Ruby files" /> + <group pattern="*.ui" name="QT Designer files" /> + <group pattern="*.png" name="Icons" /> + <group pattern="*" name="Others" /> + </groups> + <tree> + <hidenonprojectfiles>false</hidenonprojectfiles> + <hidepatterns>CVS,.svn</hidepatterns> + </tree> + </kdevfileview> + <kdevdoctreeview> + <ignoretocs> + <toc>bash</toc> + <toc>bash_bugs</toc> + <toc>clanlib</toc> + <toc>fortran_bugs_gcc</toc> + <toc>gnome1</toc> + <toc>gnustep</toc> + <toc>gtk</toc> + <toc>gtk_bugs</toc> + <toc>haskell</toc> + <toc>haskell_bugs_ghc</toc> + <toc>java_bugs_gcc</toc> + <toc>java_bugs_sun</toc> + <toc>kde2book</toc> + <toc>opengl</toc> + <toc>pascal_bugs_fp</toc> + <toc>php</toc> + <toc>php_bugs</toc> + <toc>perl</toc> + <toc>perl_bugs</toc> + <toc>python</toc> + <toc>python_bugs</toc> + <toc>qt-kdev3</toc> + <toc>sdl</toc> + <toc>stl</toc> + <toc>sw</toc> + <toc>w3c-dom-level2-html</toc> + <toc>w3c-svg</toc> + <toc>w3c-uaag10</toc> + <toc>wxwidgets_bugs</toc> + </ignoretocs> + <ignoredoxygen> + <toc>KDE Libraries (Doxygen)</toc> + </ignoredoxygen> + </kdevdoctreeview> + <workspace> + <openfiles/> + </workspace> + <kdevfilecreate> + <useglobaltypes> + <type ext="ui" /> + <type ext="rb" /> + </useglobaltypes> + </kdevfilecreate> + <kdevrubysupport> + <run> + <interpreter>ruby</interpreter> + <terminal>false</terminal> + <mainprogram>./main.rb</mainprogram> + </run> + </kdevrubysupport> +</kdevelop> diff --git a/languages/ruby/app_templates/qtrubyapp/qtrubyapp.kdevtemplate b/languages/ruby/app_templates/qtrubyapp/qtrubyapp.kdevtemplate new file mode 100644 index 00000000..5fd82925 --- /dev/null +++ b/languages/ruby/app_templates/qtrubyapp/qtrubyapp.kdevtemplate @@ -0,0 +1,140 @@ +# KDE Config File +[General] +Name=QtRuby Application +Name[ca]=Aplicació en QtRuby +Name[da]=QtRuby-program +Name[de]=QtRuby-Anwendung +Name[el]=Εφαρμογή QtRuby +Name[es]=Aplicación en QtRuby +Name[et]=QtRuby rakendus +Name[eu]=QtRuby aplikazioa +Name[fa]=کاربرد QtRuby +Name[fr]=Application QtRuby +Name[ga]=Feidhmchlár QtRuby +Name[gl]=Aplicación QtRuby +Name[hu]=QtRuby-alapú alkalmazás +Name[it]=Applicazione QtRuby +Name[ja]=QtRuby アプリケーション +Name[nds]=QtRuby-Programm +Name[ne]=QtRuby अनुप्रयोग +Name[nl]=QtRuby-toepassing +Name[pl]=Program w QtRuby +Name[pt]=Aplicação em QtRuby +Name[pt_BR]=Aplicativo QtRuby +Name[ru]=Приложение QtRuby +Name[sk]=QtRuby Aplikácia +Name[sr]=QtRuby програм +Name[sr@Latn]=QtRuby program +Name[sv]=QtRuby-program +Name[tr]=QtRuby Uygulaması +Name[zh_CN]=QtRuby 应用程序 +Name[zh_TW]=QtRuby 應用程式 +Icon=qtrubyapp.png +Category=Ruby/Qt +Category[fr]=Ruby/Qt +Comment=Generate a QtRuby based application (crossplatform compatible) +Comment[ca]=Genera una aplicació basada en QtRuby (multi plataforma) +Comment[da]=Genererer et QtRuby baseret program (krydsplatform kompatibelt) +Comment[de]=Erstellt eine auf QtRuby basierende Anwendung (plattformunabhängig) +Comment[el]=Δημιουργία μιας εφαρμογής βασισμένης σε QtRuby (συμβατή με πολλαπλές πλατφόρμες) +Comment[es]=Genera una aplicación basada en QtRuby (compatible multiplataforma) +Comment[et]=Rakenduse loomine QtRuby põhjal (mitmeplatvormne) +Comment[eu]=Sortu QtRuby lengoaian oinarritutako aplikazioa (plataforma gurutzatuekin bateragarria) +Comment[fa]=یک کاربرد بر مبنای QtRuby تولید میکند )همساز بین سکویی( +Comment[fr]=Génèrer une application basée sur QtRuby (compatible multi-plateforme) +Comment[gl]=Xera unha aplicación baseada en QtRuby (compatibilidade multiplataforma) +Comment[hu]=Létrehoz egy QtRuby-alapú, keresztfordításra is megfelelő alkalmazást +Comment[it]=Genera un'applicazione basata su QtRuby (compatibile multipiattaforma) +Comment[ja]=QtRuby ベースのアプリケーションを作成 (クロスプラットフォーム) +Comment[nds]=Stellt en op QtRuby opbuut Programm op (över Bedriefümgeven weg kompatibel) +Comment[ne]= QtRuby आधारित अनुप्रयोग (क्रसप्लाटफर्म उपयुक्त) उत्पन्न गर्नुहोस् +Comment[nl]=Genereert een QtRuby-toepassing (crossplatform compatible) +Comment[pl]=Generuj program używający QtRuby (wieloplatformowy) +Comment[pt]=Gera uma aplicação baseada em QtRuby (compatível com várias plataformas) +Comment[pt_BR]=Gera um aplicativo baseado no QtRuby (compatível com várias plataformas) +Comment[ru]=Создание кроссплатформенного приложения на QtRuby +Comment[sk]=Vygeneruje QtRuby aplikáciu (multiplatformovo kompatibilnú) +Comment[sr]=Прави програм на основу QtRuby-ја (прекоплатформски компатибилан) +Comment[sr@Latn]=Pravi program na osnovu QtRuby-ja (prekoplatformski kompatibilan) +Comment[sv]=Skapa ett program baserat på QtRuby (fungerar på andra plattformar) +Comment[tr]=QtRuby tabanlı bir uygulama yarat (platformlararası geçimli) +Comment[zh_TW]=產生一個 QtRuby 為基礎的應用程式(跨平台相容) +FileTemplates=rb,ShellStyle +ShowFilesAfterGeneration=%{dest}/%{APPNAMELC}.rb,%{dest}/README +Archive=qtrubyapp.tar.gz + +[FILE1] +Type=install +Source=%{src}/qtrubyapp.kdevelop +Dest=%{dest}/%{APPNAMELC}.kdevelop + +[FILE2] +Type=install +Source=%{src}/main.rb +Dest=%{dest}/main.rb + +[FILE3] +Type=install +Source=%{src}/qtrubyapp.rb +Dest=%{dest}/%{APPNAMELC}.rb + +[FILE4] +Type=install +Source=%{src}/fileopen.xpm +Dest=%{dest}/fileopen.xpm + +[FILE5] +Type=install +Source=%{src}/filesave.xpm +Dest=%{dest}/filesave.xpm + +[FILE6] +Type=install +Source=%{src}/fileprint.xpm +Dest=%{dest}/fileprint.xpm + +[FILE7] +Type=install +Source=%{src}/app-Makefile +Dest=%{dest}/Makefile + +[FILE8] +Type=install +Source=%{src}/app.filelist +Dest=%{dest}/%{APPNAMELC}.kdevelop.filelist + +[FILE9] +Type=install +Source=%{src}/README +Dest=%{dest}/README + +[MSG] +Type=message +Comment=A QtRuby based application was created in %{dest} +Comment[ca]=Una aplicació basada en QtRuby ha estat creada en %{dest} +Comment[da]=Et QtRuby baseret program blev oprettet i %{dest} +Comment[de]=Eine auf QtRuby basierende Anwendung wurde in %{dest} erstellt. +Comment[el]=Μια εφαρμογή βασισμένη σε QtRuby δημιουργήθηκε στο %{dest} +Comment[es]=Una aplicación basada en QtRuby ha sido creada en %{dest} +Comment[et]=Rakendus QtRuby põhjal loodi asukohta %{dest} +Comment[eu]=QtRuby lengoaian oinarritutako aplikazioa sortu da hemen: %{dest} +Comment[fa]=یک کاربرد بر مبنای QtRuby در %{dest} ایجاد شد +Comment[fr]=Une application basée sur QtRuby a été créée dans %{dest} +Comment[ga]=Cruthaíodh feidhmchlár bunaithe ar QtRuby i %{dest} +Comment[gl]=Creouse unha aplicación baseada en QtRuby en %{dest} +Comment[hu]=Létrejött egy QtRuby-alapú alkalmazás itt: %{dest} +Comment[it]=È stata creata un'applicazione basata su QtRuby in %{dest} +Comment[ja]=QtRuby ベースのアプリケーションを %{dest} に作成しました +Comment[nds]=In %{dest} wöör en op QtRuby opbuut Programm opstellt. +Comment[ne]=QtRuby आधारित अनुप्रयोग %{dest} मा सिर्जना गरियो +Comment[nl]=Een QtRuby-toepassing is aangemaakt in %{dest} +Comment[pl]=Program używający QtRuby został utworzony w %{dest} +Comment[pt]=Foi criada uma aplicação baseada em QtRuby em %{dest} +Comment[pt_BR]=Foi criada uma aplicação baseada em QtRuby em %{dest} +Comment[ru]=Приложение QtRuby создано в %{dest} +Comment[sk]=QtRuby aplikácia bola vytvorená v %{dest} +Comment[sr]=QtRuby програм је направљен у %{dest} +Comment[sr@Latn]=QtRuby program je napravljen u %{dest} +Comment[sv]=Ett program baserat på QtRuby skapades i %{dest} +Comment[tr]=Bir QtRuby tabanlı uygulama %{dest} içinde yaratıldı. +Comment[zh_TW]=一個 QtRuby 為基礎的應用程式框架已建立於 %{dest} diff --git a/languages/ruby/app_templates/qtrubyapp/qtrubyapp.png b/languages/ruby/app_templates/qtrubyapp/qtrubyapp.png Binary files differnew file mode 100644 index 00000000..10f7ecec --- /dev/null +++ b/languages/ruby/app_templates/qtrubyapp/qtrubyapp.png diff --git a/languages/ruby/app_templates/qtrubyapp/qtrubyapp.rb b/languages/ruby/app_templates/qtrubyapp/qtrubyapp.rb new file mode 100644 index 00000000..18ecdc3f --- /dev/null +++ b/languages/ruby/app_templates/qtrubyapp/qtrubyapp.rb @@ -0,0 +1,253 @@ +class %{APPNAMESC} < Qt::MainWindow + + slots 'newDoc()', + 'choose()', + 'load( const QString& )', + 'save()', + 'saveAs()', + 'print()', + 'about()', + 'aboutQt()' + + def initialize() + super( nil, "%{APPNAMESC}", WDestructiveClose ) + @printer = Qt::Printer.new + + fileTools = Qt::ToolBar.new( self, "file operations" ) + fileTools.setLabel( tr("File Operations") ) + + openIcon = Qt::Pixmap.new( "fileopen.xpm" ) + fileOpen = Qt::ToolButton.new( Qt::IconSet.new(openIcon), tr("Open File"), nil, + self, SLOT('choose()'), fileTools, "open file" ) + + saveIcon = Qt::Pixmap.new( "filesave.xpm" ) + fileSave = Qt::ToolButton.new( Qt::IconSet.new(saveIcon), tr("Save File"), nil, + self, SLOT('save()'), fileTools, "save file" ) + + printIcon = Qt::Pixmap.new( "fileprint.xpm" ) + filePrint = Qt::ToolButton.new( Qt::IconSet.new(printIcon), tr("Print File"), nil, + self, SLOT('print()'), fileTools, "print file" ) + + + Qt::WhatsThis.whatsThisButton( fileTools ) + + fileOpenText = tr('<p><img source="fileopen"> ' + + "Click this button to open a <em>new file</em>. <br>" + + "You can also select the <b>Open</b> command " + + "from the <b>File</b> menu.</p>") + + Qt::WhatsThis.add( fileOpen, fileOpenText ) + + Qt::MimeSourceFactory.defaultFactory().setPixmap( "fileopen", openIcon ) + + fileSaveText = tr("<p>Click this button to save the file you " + + "are editing. You will be prompted for a file name.\n" + + "You can also select the <b>Save</b> command " + + "from the <b>File</b> menu.</p>") + + Qt::WhatsThis.add( fileSave, fileSaveText ) + + filePrintText = tr("Click this button to print the file you " + + "are editing.\n You can also select the Print " + + "command from the File menu.") + + Qt::WhatsThis.add( filePrint, filePrintText ) + + + file = Qt::PopupMenu.new( self ) + menuBar().insertItem( tr("&File"), file ) + + + file.insertItem( tr("&New"), self, SLOT('newDoc()'), Qt::KeySequence.new(CTRL+Key_N) ) + + id = file.insertItem( Qt::IconSet.new(openIcon), tr("&Open..."), + self, SLOT('choose()'), Qt::KeySequence.new(CTRL+Key_O) ) + file.setWhatsThis( id, fileOpenText ) + + id = file.insertItem( Qt::IconSet.new(saveIcon), tr("&Save"), + self, SLOT('save()'), Qt::KeySequence.new(CTRL+Key_S) ) + file.setWhatsThis( id, fileSaveText ) + + id = file.insertItem( tr("Save &As..."), self, SLOT('saveAs()') ) + file.setWhatsThis( id, fileSaveText ) + + file.insertSeparator() + + id = file.insertItem( Qt::IconSet.new(printIcon), tr("&Print..."), + self, SLOT('print()'), Qt::KeySequence.new(CTRL+Key_P) ) + file.setWhatsThis( id, filePrintText ) + + file.insertSeparator() + + file.insertItem( tr("&Close"), self, SLOT('close()'), Qt::KeySequence.new(CTRL+Key_W) ) + + file.insertItem( tr("&Quit"), $qApp, SLOT( 'closeAllWindows()' ), Qt::KeySequence.new(CTRL+Key_Q) ) + + menuBar().insertSeparator() + + help = Qt::PopupMenu.new( self ) + menuBar().insertItem( tr("&Help"), help ) + + help.insertItem( tr("&About"), self, SLOT('about()'), Qt::KeySequence.new(Key_F1) ) + help.insertItem( tr("About &Qt"), self, SLOT('aboutQt()') ) + help.insertSeparator() + help.insertItem( tr("What's &This"), self, SLOT('whatsThis()'), Qt::KeySequence.new(SHIFT+Key_F1) ) + + @e = Qt::TextEdit.new( self, "editor" ) + @e.setFocus() + setCentralWidget( @e ) + statusBar().message( tr("Ready"), 2000 ) + + resize( 450, 600 ) + end + + private + + def newDoc() + ed = %{APPNAMESC}.new + ed.setCaption(tr("Qt Example - Application")) + ed.show() + end + + def choose() + fn = Qt::FileDialog.getOpenFileName( nil, nil, + self) + if !fn.nil? + load( fn ) + else + statusBar().message( tr("Loading aborted"), 2000 ) + end + end + + + def load( filename ) + f = Qt::File.new( filename ) + if !f.open( Qt::IO_ReadOnly ) + return + end + + ts = Qt::TextStream.new( f ) + @e.setText( ts.read() ) + @e.setModified( false ) + setCaption( filename ) + statusBar().message( tr("Loaded document %s" % filename), 2000 ) + end + + + def save() + if @filename.nil? + saveAs() + return + end + + text = @e.text() + f = Qt::File.new( @filename ) + if !f.open( Qt::IO_WriteOnly ) + statusBar().message( tr("Could not write to %s" % @filename), + 2000 ) + return + end + + t = Qt::TextStream.new( f ) + t << text + f.close() + + @e.setModified( false ) + + setCaption( @filename ) + + statusBar().message( tr( "File %s saved" % @filename ), 2000 ) + end + + + def saveAs() + fn = Qt::FileDialog.getSaveFileName( nil, nil, + self ) + if !fn.nil? + @filename = fn + save() + else + statusBar().message( tr("Saving aborted"), 2000 ) + end + end + + + def print() + # ###### Rewrite to use Qt::SimpleRichText to print here as well + margin = 10 + pageNo = 1 + + if @printer.setup(self) # @printer dialog + statusBar().message( tr("Printing...") ) + p = Qt::Painter.new + if !p.begin( @printer ) # paint on @printer + return + end + + p.setFont( @e.font() ) + yPos = 0 # y-position for each line + fm = p.fontMetrics() + metrics = Qt::PaintDeviceMetrics.new( @printer ) # need width/height + # of @printer surface + for i in 0...@e.lines() do + if margin + yPos > metrics.height() - margin + msg = "Printing (page " + msg += pageNo.to_s + pageNo += 1 + msg += ")..." + statusBar().message( msg ) + @printer.newPage() # no more room on self page + yPos = 0 # back to top of page + end + p.drawText( margin, margin + yPos, + metrics.width(), fm.lineSpacing(), + ExpandTabs | DontClip, + @e.text( i ) ) + yPos = yPos + fm.lineSpacing() + end + p.end() # send job to @printer + statusBar().message( tr("Printing completed"), 2000 ) + else + statusBar().message( tr("Printing aborted"), 2000 ) + end + end + + protected + + def closeEvent( ce ) + if !@e.modified? + ce.accept() + return + end + + case Qt::MessageBox.information( self, tr("Qt Application Example"), + tr("Do you want to save the changes" + + " to the document?"), + tr("Yes"), tr("No"), tr("Cancel"), + 0, 1 ) + when 0 + save() + ce.accept() + when 1 + ce.accept() + when 2 + ce.ignore() + else # just for sanity + ce.ignore() + end + end + + private + + def about() + Qt::MessageBox.about( self, tr("Qt Application Example"), + tr("This example demonstrates simple use of " + + "Qt::MainWindow,\nQt::MenuBar and Qt::ToolBar.")) + end + + + def aboutQt() + Qt::MessageBox.aboutQt( self, tr("Qt Application Example") ) + end + +end |