equal
deleted
inserted
replaced
74 } |
74 } |
75 } |
75 } |
76 |
76 |
77 void MyWindow::Save() |
77 void MyWindow::Save() |
78 { |
78 { |
79 if (xy->rects.size()) |
79 Code(); |
80 { |
|
81 QFile f("rects.txt"); |
|
82 if (!f.open(QIODevice::WriteOnly)) |
|
83 { |
|
84 QMessageBox::information(this, tr("Error"), |
|
85 tr("Cannot save")); |
|
86 return ; |
|
87 } |
|
88 |
|
89 QTextStream stream(&f); |
|
90 for(int i = 0; i < xy->rects.size(); i++) |
|
91 { |
|
92 QRect r = xy->rects[i].normalized(); |
|
93 stream << r.x() << " " << r.y() << " " << r.width() << " " << r.height() << endl; |
|
94 } |
|
95 f.close(); |
|
96 } |
|
97 } |
80 } |
98 |
81 |
99 void MyWindow::Load() |
82 void MyWindow::Load() |
100 { |
83 { |
|
84 QFile f("template.pas"); |
|
85 if (!f.open(QIODevice::ReadOnly)) |
|
86 { |
|
87 QMessageBox::information(this, tr("Error"), |
|
88 tr("Cannot open file")); |
|
89 return ; |
|
90 } |
101 |
91 |
|
92 QTextStream stream(&f); |
|
93 QStringList sl; |
|
94 while (!stream.atEnd()) |
|
95 { |
|
96 sl << stream.readLine(); |
|
97 } |
|
98 xy->rects.clear(); |
|
99 for (int i = 0; i < sl.size(); ++i) |
|
100 { |
|
101 QRegExp re("x:\\s+(\\d+);\\sy:\\s+(\\d+);\\sw:\\s+(\\d+);\\sh:\\s+(\\d+)"); |
|
102 re.indexIn(sl.at(i)); |
|
103 QStringList coords = re.capturedTexts(); |
|
104 qDebug() << sl.at(i) << coords; |
|
105 if ((coords.size() == 5) && (coords[0].size())) |
|
106 xy->rects.push_back(QRect(coords[1].toInt() / 2, coords[2].toInt() / 2, coords[3].toInt() / 2, coords[4].toInt() / 2)); |
|
107 } |
|
108 f.close(); |
|
109 xy->repaint(); |
102 } |
110 } |