00001 #include "editwindow.h"
00002
00003 editWindowWidget::editWindowWidget( QWidget* parent, const char* name, bool modal, WFlags fl ) : QDialog( parent, name, modal, fl )
00004 {
00005 setCaption( tr( "Information:" ) );
00006 QGridLayout *gridLayout = new QGridLayout(this, 1, 1, 5, 5);
00007 editArea = new QMultiLineEdit(this, "editArea");
00008 gridLayout->addWidget(editArea, 0, 0);
00009 editArea->setWordWrap(QMultiLineEdit::WidgetWidth);
00010
00011 showMaximized();
00012 }
00013
00014 void editWindowWidget::loadFile(QString fileName)
00015 {
00016 QFileInfo fileinfo(fileName);
00017 setCaption(fileinfo.fileName());
00018
00019 QFile file(fileName);
00020
00021 if (file.exists())
00022 {
00023 if (!file.open(IO_ReadOnly))
00024 {
00025 QMessageBox::warning(0, tr("File i/o error"), fileName.sprintf(tr("Could not read file '%s'"), fileName));
00026 }
00027 else
00028 {
00029 QTextStream inStream(&file);
00030 inStream.setEncoding(QTextStream::UnicodeUTF8);
00031 editArea->setText(inStream.read());
00032 file.close();
00033 }
00034 }
00035 }
00036
00037 void editWindowWidget::saveFile(QString fileName)
00038 {
00039 QFile file(fileName);
00040
00041 if(!file.open(IO_WriteOnly))
00042 {
00043 QMessageBox::warning(0, tr("File i/o error"), fileName.sprintf(tr("Could not write file '%s'"), fileName));
00044 }
00045 else
00046 {
00047 QTextStream outStream(&file);
00048 outStream.setEncoding(QTextStream::UnicodeUTF8);
00049 outStream << editArea->text();
00050 file.close();
00051 this->accept();
00052 }
00053 }
00054
00055 editWindowWidget::~editWindowWidget()
00056 {
00057 }