This repository was archived by the owner on Dec 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditWindow.cpp
More file actions
90 lines (81 loc) · 2.67 KB
/
Copy pathEditWindow.cpp
File metadata and controls
90 lines (81 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "EditWindow.h"
#include "CatConfig.h"
//============================================================================
EditWindowWidget::EditWindowWidget(QWidget* parent, const char* name, bool modal, WFlags fl ): QDialog(parent, name, modal, fl)
{
setCaption("Edit memo");
QGridLayout *gridLayout = new QGridLayout(this, 2, 3, 5, 5);
editArea = new QMultiLineEdit(this, "editArea");
gridLayout->addMultiCellWidget(editArea, 0, 0, 0, 2);
QPushButton *btnOk = new QPushButton("OK", this, "btnOk");
gridLayout->addWidget(btnOk, 1, 0);
QPushButton *btnCancel = new QPushButton("Cancel", this, "btnCancel");
gridLayout->addWidget(btnCancel, 1, 1);
comboCategories = new QComboBox(this, "comboCategories");
gridLayout->addWidget(comboCategories, 1, 2);
RefreshWindow();
showMaximized();
QObject::connect(btnOk, SIGNAL(clicked()), this, SLOT(PressedOk()));
QObject::connect(btnCancel, SIGNAL(clicked()), this, SLOT(PressedCancel()));
QObject::connect(comboCategories, SIGNAL(activated(int)), this, SLOT(ChangeCategory()));
}
//============================================================================
void EditWindowWidget::LoadMemo()
{
setCaption("Edit memo");
QFile file(fileName);
if (file.exists())
{
if (!file.open(IO_ReadOnly))
{
QString message = "Could not read file '" + fileName + "'";
QMessageBox::warning(0, "File i/o error", message);
}
else
{
QTextStream inStream(&file);
editArea->setText(QString::fromUtf8(inStream.read()));
file.close();
}
}
}
//============================================================================
void EditWindowWidget::SaveMemo()
{
QFile file(fileName);
if(!file.open(IO_WriteOnly))
{
QString message = "Could not write file '" + fileName + "'";
QMessageBox::warning(0, "File i/o error", message);
}
else
{
QTextStream outStream(&file);
outStream << editArea->text().utf8();
file.close();
this->accept();
}
}
//============================================================================
void EditWindowWidget::PressedOk()
{
accept();
}
//============================================================================
void EditWindowWidget::PressedCancel()
{
reject();
}
//============================================================================
void EditWindowWidget::ChangeCategory()
{
catIndex = comboCategories->currentItem();
}
//============================================================================
void EditWindowWidget::RefreshWindow()
{
CategoryConfig *catConfig = new CategoryConfig();
catConfig->BuildCategoryCombo(comboCategories, FALSE);
comboCategories->setCurrentItem(catIndex);
delete(catConfig);
}