Back to index

scribus-ng  1.3.4.dfsg+svn20071115
editor.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 #include "editor.h"
00008 #include "editor.moc"
00009 #include "selfield.h"
00010 #include "prefsmanager.h"
00011 #include "prefsfile.h"
00012 #include "prefscontext.h"
00013 #include "scribusview.h"
00014 
00015 #include <qfile.h>
00016 #include <qtextstream.h>
00017 #include <qfiledialog.h>
00018 
00019 extern QPixmap loadIcon(QString nam);
00020 
00021 Editor::Editor( QWidget* parent, QString daten, ScribusView* vie) : QDialog( parent, "editor", true, 0 )
00022 {
00023        setCaption( tr( "Editor" ) );
00024        setIcon(loadIcon("AppIcon.png"));
00025        view = vie;
00026        dirs = PrefsManager::instance()->prefsFile->getContext("dirs");
00027        EditorLayout = new QVBoxLayout( this, 0, 0, "EditorLayout");
00028        EditTex = new QTextEdit( this, "EditTex" );
00029 
00030        fmenu = new QPopupMenu();
00031        fmenu->insertItem(loadIcon("DateiNeu16.png"), tr("&New"), EditTex, SLOT(clear()), CTRL+Key_N);
00032        fmenu->insertItem(loadIcon("DateiOpen16.png"), tr("&Open..."), this, SLOT(OpenScript()));
00033        fmenu->insertItem( tr("Save &As..."), this, SLOT(SaveAs()));
00034        fmenu->insertSeparator();
00035        fmenu->insertItem( tr("&Save and Exit"), this, SLOT(accept()));
00036        fmenu->insertItem( tr("&Exit without Saving"), this, SLOT(reject()));
00037        emenu = new QPopupMenu();
00038        emenu->insertItem( tr("&Undo"), EditTex, SLOT(undo()), CTRL+Key_Z);
00039        emenu->insertItem( tr("&Redo"), EditTex, SLOT(redo()));
00040        emenu->insertSeparator();
00041        emenu->insertItem(loadIcon("editcut.png"), tr("Cu&t"), EditTex, SLOT(cut()), CTRL+Key_X);
00042        emenu->insertItem(loadIcon("editcopy.png"), tr("&Copy"), EditTex, SLOT(copy()), CTRL+Key_C);
00043        emenu->insertItem(loadIcon("editpaste.png"), tr("&Paste"), EditTex, SLOT(paste()), CTRL+Key_V);
00044        emenu->insertItem(loadIcon("editdelete.png"), tr("C&lear"), EditTex, SLOT(del()), CTRL+Key_V);
00045        emenu->insertSeparator();
00046        emenu->insertItem( tr("&Get Field Names"), this, SLOT(GetFieldN()));
00047        menuBar = new QMenuBar(this);
00048        menuBar->insertItem( tr("&File"), fmenu);
00049        menuBar->insertItem( tr("&Edit"), emenu);
00050        EditorLayout->setMenuBar( menuBar );
00051 
00052        EditTex->setMinimumSize( QSize( 400, 400 ) );
00053        EditTex->setText(daten);
00054        EditorLayout->addWidget( EditTex );
00055 }
00056 
00057 void Editor::GetFieldN()
00058 {
00059        if (view != 0)
00060        {
00061               SelectFields* dia = new SelectFields(this, "", "", view->Doc, 0);
00062               if (dia->exec())
00063                      EditTex->insert(dia->S_Fields);
00064               delete dia;
00065        }
00066 }
00067 
00068 void Editor::OpenScript()
00069 {
00070        QString fileName = QFileDialog::getOpenFileName(dirs->get("editor_open", "."), tr("JavaScripts (*.js);;All Files (*)"),this);
00071        if (!fileName.isEmpty())
00072        {
00073               dirs->set("editor_open", fileName.left(fileName.findRev("/")));
00074               QFile file( fileName );
00075               if ( file.open( IO_ReadOnly ) )
00076               {
00077                      QTextStream ts( &file );
00078                      EditTex->setText( ts.read() );
00079                      file.close();
00080               }
00081        }
00082 }
00083 
00084 void Editor::SaveAs()
00085 {
00086        QString fn = QFileDialog::getSaveFileName(dirs->get("editor_save", "."), tr("JavaScripts (*.js);;All Files (*)"), this);
00087        if (!fn.isEmpty())
00088        {
00089               dirs->set("editor_save", fn.left(fn.findRev("/")));
00090               QFile file( fn );
00091               if ( file.open( IO_WriteOnly ) )
00092               {
00093                      QTextStream ts( &file );
00094                      ts << EditTex->text();
00095                      EditTex->setModified(false);
00096                      file.close();
00097               }
00098        }
00099 }