- Show sample line
authorunc0rr
Tue, 23 Jan 2007 22:48:08 +0000
changeset 361 c3eebac100c0
parent 360 ab6a94334d6d
child 362 b28e0dd48269
- Show sample line - Load() works
tools/templates/mainform.cpp
tools/templates/pixlabel.cpp
--- a/tools/templates/mainform.cpp	Tue Jan 23 21:24:18 2007 +0000
+++ b/tools/templates/mainform.cpp	Tue Jan 23 22:48:08 2007 +0000
@@ -76,27 +76,35 @@
 
 void MyWindow::Save()
 {
-	if (xy->rects.size())
-	{
-		QFile f("rects.txt");
-		if (!f.open(QIODevice::WriteOnly))
-		{
-			QMessageBox::information(this, tr("Error"),
-						tr("Cannot save"));
-			return ;
-		}
-
-		QTextStream stream(&f);
-		for(int i = 0; i < xy->rects.size(); i++)
-		{
-			QRect r = xy->rects[i].normalized();
-			stream << r.x() << " " << r.y() << " " << r.width() << " " << r.height() << endl;
-		}
-		f.close();
-	}
+	Code();
 }
 
 void MyWindow::Load()
 {
+	QFile f("template.pas");
+	if (!f.open(QIODevice::ReadOnly))
+	{
+		QMessageBox::information(this, tr("Error"),
+					tr("Cannot open file"));
+		return ;
+	}
 
+	QTextStream stream(&f);
+	QStringList sl;
+	while (!stream.atEnd())
+	{
+		sl << stream.readLine();
+	}
+	xy->rects.clear();
+	for (int i = 0; i < sl.size(); ++i)
+	{
+		QRegExp re("x:\\s+(\\d+);\\sy:\\s+(\\d+);\\sw:\\s+(\\d+);\\sh:\\s+(\\d+)");
+		re.indexIn(sl.at(i));
+		QStringList coords = re.capturedTexts();
+		qDebug() << sl.at(i) << coords;
+		if ((coords.size() == 5) && (coords[0].size()))
+			xy->rects.push_back(QRect(coords[1].toInt() / 2, coords[2].toInt() / 2, coords[3].toInt() / 2, coords[4].toInt() / 2));
+	}
+	f.close();
+	xy->repaint();
 }
--- a/tools/templates/pixlabel.cpp	Tue Jan 23 21:24:18 2007 +0000
+++ b/tools/templates/pixlabel.cpp	Tue Jan 23 22:48:08 2007 +0000
@@ -15,11 +15,17 @@
 
 	p.fillRect(QRect(0, 0, 1024, 512), QBrush(Qt::black));
 
-	p.setPen(QPen(Qt::white));
-	p.drawRects(rects.toVector());
-
 	if (rects.size())
 	{
+		p.setPen(QPen(Qt::lightGray));
+		QVector<QPoint> centers;
+		for(QList<QRect>::const_iterator it = rects.begin(); it != rects.end(); ++it)
+			centers.push_back((*it).center());
+		p.drawPolyline(QPolygon(centers));
+
+		p.setPen(QPen(Qt::white));
+		p.drawRects(rects.toVector());
+
 		p.setPen(QPen(Qt::yellow));
 		p.drawRect(rects.last());
 	}