# HG changeset patch # User unC0Rr # Date 1291225505 -10800 # Node ID 27a896207aaeeb48590a94cd1cba0b4aee2530da # Parent 39ab70b37e01845e8592d25fc8bf959d7a569481 Some more improvements diff -r 39ab70b37e01 -r 27a896207aae tools/drawMapTest/drawmapscene.cpp --- a/tools/drawMapTest/drawmapscene.cpp Wed Dec 01 01:43:55 2010 +0100 +++ b/tools/drawMapTest/drawmapscene.cpp Wed Dec 01 20:45:05 2010 +0300 @@ -37,7 +37,7 @@ { QPainterPath path = m_currPath->path(); path.lineTo(mouseEvent->scenePos()); - paths.last().append(mouseEvent->scenePos().toPoint()); + paths.first().append(mouseEvent->scenePos().toPoint()); m_currPath->setPath(path); emit pathChanged(); @@ -55,7 +55,7 @@ p += QPointF(0.01, 0.01); path.moveTo(p); path.lineTo(mouseEvent->scenePos()); - paths.append(QList() << mouseEvent->scenePos().toPoint()); + paths.prepend(QList() << mouseEvent->scenePos().toPoint()); m_currPath->setPath(path); emit pathChanged(); @@ -65,6 +65,8 @@ { qDebug() << "release" << mouseEvent->scenePos(); + simplifyLast(); + m_currPath = 0; } @@ -73,7 +75,7 @@ if(items().size()) { removeItem(items().first()); - paths.removeLast(); + paths.removeFirst(); emit pathChanged(); } @@ -104,23 +106,40 @@ return b; } -void DrawMapScene::simplify() +void DrawMapScene::simplifyLast() { - for(int pit = 0; pit < paths.size(); ++pit) + QList points = paths[0]; + + QPoint prevPoint = points.first(); + int i = 1; + while(i < points.size()) { - QList points = paths[pit]; + if(sqr(prevPoint.x() - points[i].x()) + sqr(prevPoint.y() - points[i].y()) < 1000) + points.removeAt(i); + else + { + prevPoint = points[i]; + ++i; + } + } - QPoint prevPoint = points.first(); - int i = 1; - while(i < points.size()) - { - if(sqr(prevPoint.x() - points[i].x()) + sqr(prevPoint.y() - points[i].y()) < 1000) - points.removeAt(i); - else - ++i; - } + paths[0] = points; + + + // redraw path + { - paths[pit] = points; + QPainterPath path; + QPointF p = paths[0][0] + QPointF(0.01, 0.01); + path.moveTo(p); + + foreach(QPoint p, paths[0]) + path.lineTo(p); + + QGraphicsPathItem * pathItem = static_cast(items()[0]); + pathItem->setPath(path); + + ++i; } emit pathChanged(); diff -r 39ab70b37e01 -r 27a896207aae tools/drawMapTest/drawmapscene.h --- a/tools/drawMapTest/drawmapscene.h Wed Dec 01 01:43:55 2010 +0100 +++ b/tools/drawMapTest/drawmapscene.h Wed Dec 01 20:45:05 2010 +0300 @@ -20,7 +20,7 @@ public slots: void undo(); - void simplify(); + void simplifyLast(); private: QPen m_pen; diff -r 39ab70b37e01 -r 27a896207aae tools/drawMapTest/mainwindow.cpp --- a/tools/drawMapTest/mainwindow.cpp Wed Dec 01 01:43:55 2010 +0100 +++ b/tools/drawMapTest/mainwindow.cpp Wed Dec 01 20:45:05 2010 +0300 @@ -42,10 +42,12 @@ void MainWindow::scene_pathChanged() { - ui->plainTextEdit->setPlainText(scene->encode().toBase64()); + QString str = scene->encode().toBase64(); + ui->plainTextEdit->setPlainText(str); + ui->sbBytes->setValue(str.size()); } void MainWindow::on_pbSimplify_clicked() { - scene->simplify(); + scene->simplifyLast(); } diff -r 39ab70b37e01 -r 27a896207aae tools/drawMapTest/mainwindow.ui --- a/tools/drawMapTest/mainwindow.ui Wed Dec 01 01:43:55 2010 +0100 +++ b/tools/drawMapTest/mainwindow.ui Wed Dec 01 20:45:05 2010 +0300 @@ -14,19 +14,12 @@ MainWindow - + - - - - 16777215 - 80 - - - + @@ -51,9 +44,18 @@ - - - Simplify + + + true + + + QAbstractSpinBox::NoButtons + + + bytes + + + 999999