QTfrontend/drawmapscene.cpp
changeset 9472 265e5997580e
parent 9080 9b42757d7e71
child 9483 14ad1ac00ac9
equal deleted inserted replaced
9470:9ed07a96349d 9472:265e5997580e
   154 {
   154 {
   155     // cursor is a part of items()
   155     // cursor is a part of items()
   156     if(m_isCursorShown)
   156     if(m_isCursorShown)
   157         return;
   157         return;
   158 
   158 
   159     if(items().size())
   159     if(paths.size())
   160     {
   160     {
   161         removeItem(items().first());
   161         removeItem(items().first());
   162         paths.removeFirst();
   162         paths.removeFirst();
   163 
   163 
   164         emit pathChanged();
   164         emit pathChanged();
   181 
   181 
   182     // don't clear if already cleared
   182     // don't clear if already cleared
   183     if(!items().size())
   183     if(!items().size())
   184         return;
   184         return;
   185 
   185 
       
   186     m_specialPoints.clear();
   186     oldItems.clear();
   187     oldItems.clear();
   187 
   188 
   188     // do this since clear() would _destroy_ all items
   189     // do this since clear() would _destroy_ all items
   189     while(items().size())
   190     for(int i = paths.size() - 1; i >= 0; --i)
   190     {
   191     {
   191         oldItems.push_front(items().first());
   192         oldItems.push_front(items().first());
   192         removeItem(items().first());
   193         removeItem(items().first());
   193     }
   194     }
   194 
   195 
   209         m_pen.setBrush(m_brush);
   210         m_pen.setBrush(m_brush);
   210 }
   211 }
   211 
   212 
   212 QByteArray DrawMapScene::encode()
   213 QByteArray DrawMapScene::encode()
   213 {
   214 {
   214     QByteArray b;
   215     QByteArray b(m_specialPoints);
   215 
   216 
   216     for(int i = paths.size() - 1; i >= 0; --i)
   217     for(int i = paths.size() - 1; i >= 0; --i)
   217     {
   218     {
   218         int cnt = 0;
   219         int cnt = 0;
   219         PathParams params = paths.at(i);
   220         PathParams params = paths.at(i);
   245 
   246 
   246     oldItems.clear();
   247     oldItems.clear();
   247     oldPaths.clear();
   248     oldPaths.clear();
   248     clear();
   249     clear();
   249     paths.clear();
   250     paths.clear();
       
   251     m_specialPoints.clear();
   250 
   252 
   251     PathParams params;
   253     PathParams params;
       
   254 
       
   255     bool isSpecial = true;
   252 
   256 
   253     while(data.size() >= 5)
   257     while(data.size() >= 5)
   254     {
   258     {
   255         qint16 px = qFromBigEndian(*(qint16 *)data.data());
   259         qint16 px = qFromBigEndian(*(qint16 *)data.data());
   256         data.remove(0, 2);
   260         data.remove(0, 2);
   257         qint16 py = qFromBigEndian(*(qint16 *)data.data());
   261         qint16 py = qFromBigEndian(*(qint16 *)data.data());
   258         data.remove(0, 2);
   262         data.remove(0, 2);
   259         quint8 flags = *(quint8 *)data.data();
   263         quint8 flags = *(quint8 *)data.data();
   260         data.remove(0, 1);
   264         data.remove(0, 1);
   261 
   265         qDebug() << px << py;
   262         if(flags & 0x80)
   266         if(flags & 0x80)
   263         {
   267         {
       
   268             isSpecial = false;
       
   269 
   264             if(params.points.size())
   270             if(params.points.size())
   265             {
   271             {
   266                 addPath(pointsToPath(params.points), m_pen);
   272                 addPath(pointsToPath(params.points), m_pen);
   267 
   273 
   268                 paths.prepend(params);
   274                 paths.prepend(params);
   276             if(params.erasing)
   282             if(params.erasing)
   277                 m_pen.setBrush(m_eraser);
   283                 m_pen.setBrush(m_eraser);
   278             else
   284             else
   279                 m_pen.setBrush(m_brush);
   285                 m_pen.setBrush(m_brush);
   280             params.width = penWidth;
   286             params.width = penWidth;
   281         }
   287         } else
   282 
   288             if(isSpecial)
   283         params.points.append(QPoint(px, py));
   289             {
       
   290                 QPainterPath path;
       
   291                 path.addEllipse(QPointF(px, py), 10, 10);
       
   292 
       
   293                 addPath(path);
       
   294 
       
   295                 qint16 x = qToBigEndian(px);
       
   296                 qint16 y = qToBigEndian(py);
       
   297                 m_specialPoints.append((const char *)&x, 2);
       
   298                 m_specialPoints.append((const char *)&y, 2);
       
   299                 m_specialPoints.append((const char *)&flags, 1);
       
   300             }
       
   301 
       
   302         if(!isSpecial)
       
   303             params.points.append(QPoint(px, py));
   284     }
   304     }
   285 
   305 
   286     if(params.points.size())
   306     if(params.points.size())
   287     {
   307     {
   288         addPath(pointsToPath(params.points), m_pen);
   308         addPath(pointsToPath(params.points), m_pen);