-rw-r--r-- | core/pim/notes/editwindow.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/core/pim/notes/editwindow.cpp b/core/pim/notes/editwindow.cpp new file mode 100644 index 0000000..1b2d4a6 --- a/dev/null +++ b/core/pim/notes/editwindow.cpp | |||
@@ -0,0 +1,57 @@ | |||
1 | #include "editwindow.h" | ||
2 | |||
3 | editWindowWidget::editWindowWidget( QWidget* parent, const char* name, bool modal, WFlags fl ) : QDialog( parent, name, modal, fl ) | ||
4 | { | ||
5 | setCaption( tr( "Information:" ) ); | ||
6 | QGridLayout *gridLayout = new QGridLayout(this, 1, 1, 5, 5); | ||
7 | editArea = new QMultiLineEdit(this, "editArea"); | ||
8 | gridLayout->addWidget(editArea, 0, 0); | ||
9 | editArea->setWordWrap(QMultiLineEdit::WidgetWidth); | ||
10 | |||
11 | showMaximized(); | ||
12 | } | ||
13 | |||
14 | void editWindowWidget::loadFile(QString fileName) | ||
15 | { | ||
16 | QFileInfo fileinfo(fileName); | ||
17 | setCaption(fileinfo.fileName()); | ||
18 | |||
19 | QFile file(fileName); | ||
20 | |||
21 | if (file.exists()) | ||
22 | { | ||
23 | if (!file.open(IO_ReadOnly)) | ||
24 | { | ||
25 | QMessageBox::warning(0, tr("File i/o error"), fileName.sprintf(tr("Could not read file '%s'"), fileName)); | ||
26 | } | ||
27 | else | ||
28 | { | ||
29 | QTextStream inStream(&file); | ||
30 | inStream.setEncoding(QTextStream::UnicodeUTF8); | ||
31 | editArea->setText(inStream.read()); | ||
32 | file.close(); | ||
33 | } | ||
34 | } | ||
35 | } | ||
36 | |||
37 | void editWindowWidget::saveFile(QString fileName) | ||
38 | { | ||
39 | QFile file(fileName); | ||
40 | |||
41 | if(!file.open(IO_WriteOnly)) | ||
42 | { | ||
43 | QMessageBox::warning(0, tr("File i/o error"), fileName.sprintf(tr("Could not write file '%s'"), fileName)); | ||
44 | } | ||
45 | else | ||
46 | { | ||
47 | QTextStream outStream(&file); | ||
48 | outStream.setEncoding(QTextStream::UnicodeUTF8); | ||
49 | outStream << editArea->text(); | ||
50 | file.close(); | ||
51 | this->accept(); | ||
52 | } | ||
53 | } | ||
54 | |||
55 | editWindowWidget::~editWindowWidget() | ||
56 | { | ||
57 | } | ||