|
1 #include <QGridLayout> |
|
2 #include <QImage> |
|
3 #include <QPixmap> |
|
4 #include <QMessageBox> |
|
5 #include <QFile> |
|
6 #include <QTextStream> |
|
7 #include <QRegExp> |
|
8 #include <QDebug> |
|
9 #include "mainform.h" |
|
10 |
|
11 MyWindow::MyWindow(QWidget * parent, Qt::WFlags flags) |
|
12 : QMainWindow(parent, flags) |
|
13 |
|
14 { |
|
15 QWidget * centralWidget = new QWidget(this); |
|
16 QGridLayout * mainlayout = new QGridLayout(centralWidget); |
|
17 mainlayout->setMargin(1); |
|
18 mainlayout->setSpacing(1); |
|
19 |
|
20 sa_xy = new QScrollArea(centralWidget); |
|
21 xy = new PixLabel(); |
|
22 xy->setFixedSize(1024, 512); |
|
23 sa_xy->setWidget(xy); |
|
24 |
|
25 mainlayout->addWidget(sa_xy, 0, 0, 1, 4); |
|
26 |
|
27 setCentralWidget(centralWidget); |
|
28 |
|
29 buttAdd = new QPushButton(centralWidget); |
|
30 buttAdd->setText(tr("Add")); |
|
31 mainlayout->addWidget(buttAdd, 1, 0); |
|
32 |
|
33 buttCode = new QPushButton(centralWidget); |
|
34 buttCode->setText(tr("Code")); |
|
35 mainlayout->addWidget(buttCode, 1, 1); |
|
36 |
|
37 buttSave = new QPushButton(centralWidget); |
|
38 buttSave->setText(tr("Save")); |
|
39 mainlayout->addWidget(buttSave, 1, 3); |
|
40 |
|
41 buttLoad = new QPushButton(centralWidget); |
|
42 buttLoad->setText(tr("Load")); |
|
43 mainlayout->addWidget(buttLoad, 1, 2); |
|
44 |
|
45 connect(buttAdd, SIGNAL(clicked()), xy, SLOT(AddRect())); |
|
46 connect(buttCode, SIGNAL(clicked()), this, SLOT(Code())); |
|
47 connect(buttSave, SIGNAL(clicked()), this, SLOT(Save())); |
|
48 connect(buttLoad, SIGNAL(clicked()), this, SLOT(Load())); |
|
49 } |
|
50 |
|
51 void MyWindow::Code() |
|
52 { |
|
53 if (xy->rects.size()) |
|
54 { |
|
55 QFile f("template.pas"); |
|
56 if (!f.open(QIODevice::WriteOnly)) |
|
57 { |
|
58 QMessageBox::information(this, tr("Error"), |
|
59 tr("Cannot save")); |
|
60 return ; |
|
61 } |
|
62 |
|
63 QTextStream stream(&f); |
|
64 stream << QString("const Template0Points: array[0..%1] of TSDL_Rect =").arg(xy->rects.size() - 1) << endl; |
|
65 stream << " (" << endl; |
|
66 for(int i = 0; i < xy->rects.size(); i++) |
|
67 { |
|
68 QRect r = xy->rects[i].normalized(); |
|
69 stream << QString(" (x: %1; y: %2; w: %3; h: %4),"). |
|
70 arg(r.x() * 2, 4).arg(r.y() * 2, 4).arg(r.width() * 2, 4).arg(r.height() * 2, 4) << endl; |
|
71 } |
|
72 stream << " );" << endl; |
|
73 f.close(); |
|
74 } |
|
75 } |
|
76 |
|
77 void MyWindow::Save() |
|
78 { |
|
79 if (xy->rects.size()) |
|
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 } |
|
98 |
|
99 void MyWindow::Load() |
|
100 { |
|
101 |
|
102 } |