]> Shamusworld >> Repos - architektonas/blobdiff - src/base/rs_graphicview.cpp
Scrubbed all references to CreatePainter(), CreateDirectPainter() and
[architektonas] / src / base / rs_graphicview.cpp
index 73500e211f8d16baef514699fc55dfb4c9550519..a2dcb73fd5e9e17747eb6feb1a7cf6477778fb3a 100644 (file)
@@ -70,15 +70,6 @@ RS_GraphicView::RS_GraphicView(): background(), foreground(), previewMode(false)
        defaultSnapMode = RS2::SnapFree;
        defaultSnapRes = RS2::RestrictNothing;
 
-       /*
-               background = RS_Color(0,0,0);
-               foreground = RS_Color(255,255,255);
-               gridColor = RS_Color("gray");
-       metaGridColor = RS_Color("#404040");
-               selectedColor = RS_Color("#a54747");
-               highlightedColor = RS_Color("#739373");
-       */
-
        settings.beginGroup("Appearance");
        setBackground(QColor(settings.value("BackgroundColor", "#000000").toString()));
        setGridColor(QColor(settings.value("GridColor", "#7F7F7F").toString()));
@@ -511,7 +502,7 @@ void RS_GraphicView::setCurrentAction(RS_ActionInterface * action)
  */
 void RS_GraphicView::killSelectActions()
 {
-       if (eventHandler != NULL)
+       if (eventHandler)
                eventHandler->killSelectActions();
 }
 
@@ -520,7 +511,7 @@ void RS_GraphicView::killSelectActions()
  */
 void RS_GraphicView::killAllActions()
 {
-       if (eventHandler != NULL)
+       if (eventHandler)
                eventHandler->killAllActions();
 }
 
@@ -529,11 +520,10 @@ void RS_GraphicView::killAllActions()
  */
 void RS_GraphicView::back()
 {
-       if (eventHandler != NULL && eventHandler->hasAction())
+       if (eventHandler && eventHandler->hasAction())
                eventHandler->back();
-       else
-               if (RS_DIALOGFACTORY != NULL)
-                       RS_DIALOGFACTORY->requestPreviousMenu();
+       else if (RS_DIALOGFACTORY)
+               RS_DIALOGFACTORY->requestPreviousMenu();
 }
 
 /**
@@ -541,7 +531,7 @@ void RS_GraphicView::back()
  */
 void RS_GraphicView::enter()
 {
-       if (eventHandler != NULL && eventHandler->hasAction())
+       if (eventHandler && eventHandler->hasAction())
                eventHandler->enter();
 }
 
@@ -551,7 +541,7 @@ void RS_GraphicView::enter()
  */
 void RS_GraphicView::mousePressEvent(QMouseEvent * e)
 {
-       if (eventHandler != NULL)
+       if (eventHandler)
                eventHandler->mousePressEvent(e);
 }
 
@@ -563,18 +553,18 @@ void RS_GraphicView::mouseReleaseEvent(QMouseEvent * e)
 {
        RS_DEBUG->print("RS_GraphicView::mouseReleaseEvent");
 
-       if (eventHandler != NULL)
+       if (!eventHandler)
+               return;
+
+       if (e->button() != Qt::RightButton || eventHandler->hasAction())
        {
-               if (e->button() != Qt::RightButton || eventHandler->hasAction())
-               {
-                       eventHandler->mouseReleaseEvent(e);
-                       //e->accept();
-               }
-               else
-               {
-                       back();
-                       e->accept();
-               }
+               eventHandler->mouseReleaseEvent(e);
+               //e->accept();
+       }
+       else
+       {
+               back();
+               e->accept();
        }
 
        RS_DEBUG->print("RS_GraphicView::mouseReleaseEvent: OK");
@@ -595,7 +585,7 @@ void RS_GraphicView::mouseMoveEvent(QMouseEvent * e)
 
        RS_DEBUG->print("RS_GraphicView::mouseMoveEvent 001");
 
-       if (e != NULL)
+       if (e)
        {
                mx = e->x();
                my = e->y();
@@ -603,17 +593,17 @@ void RS_GraphicView::mouseMoveEvent(QMouseEvent * e)
 
        RS_DEBUG->print("RS_GraphicView::mouseMoveEvent 002");
 
-       if (eventHandler != NULL)
+       if (eventHandler)
                eventHandler->mouseMoveEvent(e);
 
        RS_DEBUG->print("RS_GraphicView::mouseMoveEvent 003");
 
-       if (eventHandler == NULL || !eventHandler->hasAction() && graphic != NULL)
+       if (!eventHandler || !eventHandler->hasAction() && graphic)
        {
                Vector mouse = toGraph(Vector(mx, my));
                Vector relMouse = mouse - getRelativeZero();
 
-               if (RS_DIALOGFACTORY != NULL)
+               if (RS_DIALOGFACTORY)
                        RS_DIALOGFACTORY->updateCoordinateWidget(mouse, relMouse);
        }
 
@@ -626,7 +616,7 @@ void RS_GraphicView::mouseMoveEvent(QMouseEvent * e)
  */
 void RS_GraphicView::mouseLeaveEvent()
 {
-       if (eventHandler != NULL)
+       if (eventHandler)
                eventHandler->mouseLeaveEvent();
 }
 
@@ -636,7 +626,7 @@ void RS_GraphicView::mouseLeaveEvent()
  */
 void RS_GraphicView::mouseEnterEvent()
 {
-       if (eventHandler != NULL)
+       if (eventHandler)
                eventHandler->mouseEnterEvent();
 }
 
@@ -646,7 +636,7 @@ void RS_GraphicView::mouseEnterEvent()
  */
 void RS_GraphicView::keyPressEvent(QKeyEvent * e)
 {
-       if (eventHandler != NULL)
+       if (eventHandler)
                eventHandler->keyPressEvent(e);
 }
 
@@ -656,7 +646,7 @@ void RS_GraphicView::keyPressEvent(QKeyEvent * e)
  */
 void RS_GraphicView::keyReleaseEvent(QKeyEvent * e)
 {
-       if (eventHandler != NULL)
+       if (eventHandler)
                eventHandler->keyReleaseEvent(e);
 }
 
@@ -665,7 +655,7 @@ void RS_GraphicView::keyReleaseEvent(QKeyEvent * e)
  */
 void RS_GraphicView::commandEvent(RS_CommandEvent * e)
 {
-       if (eventHandler != NULL)
+       if (eventHandler)
                eventHandler->commandEvent(e);
 }
 
@@ -674,7 +664,7 @@ void RS_GraphicView::commandEvent(RS_CommandEvent * e)
  */
 void RS_GraphicView::enableCoordinateInput()
 {
-       if (eventHandler != NULL)
+       if (eventHandler)
                eventHandler->enableCoordinateInput();
 }
 
@@ -683,7 +673,7 @@ void RS_GraphicView::enableCoordinateInput()
  */
 void RS_GraphicView::disableCoordinateInput()
 {
-       if (eventHandler != NULL)
+       if (eventHandler)
                eventHandler->disableCoordinateInput();
 }
 
@@ -1205,10 +1195,10 @@ void RS_GraphicView::drawWindow(Vector v1, Vector v2)
        if (simulationRunning)
                return;
 
-       if (container != NULL)
+       if (container)
        {
-               for (RS_Entity * se=container->firstEntity(RS2::ResolveNone);
-                       se!=NULL; se = container->nextEntity(RS2::ResolveNone))
+               for(RS_Entity * se=container->firstEntity(RS2::ResolveNone); se!=NULL;
+                       se=container->nextEntity(RS2::ResolveNone))
                {
                        if (se->isInWindow(v1, v2))
                                drawEntity(se);
@@ -1236,25 +1226,17 @@ void RS_GraphicView::drawIt()
                return;
 //}
 
-//     bool painterCreated = false;
-
        settings.beginGroup("Appearance");
        draftMode = settings.value("DraftMode", false).toBool();
        settings.endGroup();
 
-       //RS_DEBUG->print("RS_GraphicView::drawIt() begin");
-       //RS_DEBUG->print("  factors: %f/%f", factor.x, factor.y);
-       //RS_DEBUG->timestamp();
-
-       if (painter == NULL)
-       {
-printf("RS_GraphicView::drawIt(): painter == NULL!\n");
+       if (!painter)
+//     {
+//printf("RS_GraphicView::drawIt(): painter == NULL!\n");
                return;
-//             createPainter();
-//             painterCreated = true;
-       }
-       else
-               painter->erase();
+//     }
+
+       painter->erase();
 
        // drawing paper border:
        if (isPrintPreview())
@@ -1263,17 +1245,10 @@ printf("RS_GraphicView::drawIt(): painter == NULL!\n");
        else
                drawMetaGrid();
 
-       //if (draftMode) {
-       //    painter->setPen(RS_Pen(foreground, RS2::Width00, RS2::SolidLine));
-       //}
-
        // drawing entities:
 //#warning "!!! This looks like a bug, no match for 'drawEntity(RS_Entity *, bool) !!!"
 // and indeed it *is* a bug... true is converted to 1.0 here. Dumb, dumb, dumb.
-       drawEntity(container, true);
-
-       //RS_DEBUG->timestamp();
-       //RS_DEBUG->print(" draw zero..");
+       drawEntity(container);//, true);
 
        // drawing zero points:
        if (!isPrintPreview())
@@ -1282,17 +1257,9 @@ printf("RS_GraphicView::drawIt(): painter == NULL!\n");
                drawRelativeZero();
        }
 
-       //RS_DEBUG->timestamp();
-       //RS_DEBUG->print(" draw grid..");
-
        // drawing grid:
        if (!isPrintPreview())
                drawGrid();
-
-       //RS_DEBUG->timestamp();
-       //RS_DEBUG->print("RS_GraphicView::drawIt() end");
-//     if (painterCreated == true)
-//             destroyPainter();
 }
 
 /**
@@ -1516,9 +1483,8 @@ void RS_GraphicView::simulateIt()
        simulationRunning = true;
        simulationLast = Vector(0.0, 0.0);
 
-       destroyPainter();
+//jlh  destroyPainter();
 
-       createDirectPainter();
        painter->erase();
 
        // drawing paper border:
@@ -1558,7 +1524,7 @@ void RS_GraphicView::simulateIt()
        //RS_DEBUG->timestamp();
        //RS_DEBUG->print("RS_GraphicView::drawIt() end");
        //if (painterCreated==true) {
-       destroyPainter();
+//jlh  destroyPainter();
        //}
        simulationRunning = false;
 }
@@ -1589,7 +1555,7 @@ void RS_GraphicView::simulateEntity(RS_Entity * e, const RS_Pen & pen)
 
                                        if (sp.distanceTo(simulationLast) > 1.0e-4)
                                        {
-                                               createDirectPainter();
+//jlh                                          createDirectPainter();
                                                RS_Pen rpen(RS_Color(0, 0, 255), RS2::Width00, RS2::SolidLine);
                                                //painter->setPen(pen);
                                                RS_Line rapidLine(NULL, RS_LineData(simulationLast, sp));
@@ -1649,7 +1615,7 @@ void RS_GraphicView::simulateEntity(RS_Entity * e, const RS_Pen & pen)
                }
                else
                {
-                       createDirectPainter();
+//jlh                  createDirectPainter();
                        //RS_Pen pen(foreground, RS2::Width00, RS2::SolidLine);
                        painter->setPen(pen);
                        drawEntityPlain(e);
@@ -1766,7 +1732,7 @@ void RS_GraphicView::drawLineSmooth(const Vector & p1, const Vector & p2, const
                if (lx >= 0.0 && lx <= (double)getWidth() && ly >= 0.0 && ly <= (double)getHeight())
                {
                        //if (painter==NULL) {
-                       createDirectPainter();
+//jlh                  createDirectPainter();
                        //}
                        painter->setPen(pen);
                        painter->drawGridPoint(Vector(lx, ly));
@@ -1791,7 +1757,7 @@ void RS_GraphicView::drawArcSmooth(const Vector & center, double radius, double
 
        if (radius <= 1.4)
        {
-               createDirectPainter();
+//jlh          createDirectPainter();
                painter->setPen(pen);
                painter->drawGridPoint(center);
        }
@@ -1836,7 +1802,7 @@ void RS_GraphicView::drawArcSmooth(const Vector & center, double radius, double
                                k2y = RS_Math::round(center.y-sin(a)*radius);
                                //if(graphic->isPointOnScreen(k2x, k2y) ||
                                //   graphic->isPointOnScreen(k1x, k1y)    ) {
-                               createDirectPainter();
+//jlh                          createDirectPainter();
                                painter->setPen(pen);
                                if ((k2x >= 0 && k2x <= painter->getWidth()
                                        && k2y >= 0 && k2y <= painter->getHeight())
@@ -1856,7 +1822,7 @@ void RS_GraphicView::drawArcSmooth(const Vector & center, double radius, double
                                k1y = k2y;
                        }
 
-                       createDirectPainter();
+//jlh                  createDirectPainter();
                        painter->setPen(pen);
                        painter->drawLine(Vector(k2x, k2y), Vector(ix2, iy2));
                        //painter->lineTo(ix2, iy2);
@@ -1877,7 +1843,7 @@ void RS_GraphicView::drawArcSmooth(const Vector & center, double radius, double
                                k2y = RS_Math::round(center.y - sin(a) * radius);
                                //if(graphic->isPointOnScreen(k2x, k2y) ||
                                //        graphic->isPointOnScreen(k1x, k1y)    ) {
-                               createDirectPainter();
+//jlh                          createDirectPainter();
                                painter->setPen(pen);
                                if ((k2x >=0 && k2x <= painter->getWidth()
                                        && k2y >= 0 && k2y <= painter->getHeight())
@@ -1895,7 +1861,7 @@ void RS_GraphicView::drawArcSmooth(const Vector & center, double radius, double
                                k1y = k2y;
                        }
 
-                       createDirectPainter();
+//jlh                  createDirectPainter();
                        painter->setPen(pen);
                        //painter->lineTo(ix2, iy2);
                        painter->drawLine(Vector(k2x, k2y), Vector(ix2, iy2));
@@ -1993,21 +1959,16 @@ RS_LineTypePattern * RS_GraphicView::getPattern(RS2::LineType t)
  * zero. It's called from within drawIt(). The default implemetation
  * draws a simple red round zero point.
  *
+ * Actually, we have to rework the rendering code because the way that QCad did
+ * it was wrong on so many levels... Part of that is making sure the rendering
+ * path is 100% clear!
+ *
  * @see drawIt()
  */
 void RS_GraphicView::drawAbsoluteZero()
 {
-//RS_DEBUG->print(RS_Debug::D_CRITICAL, "RS_GraphicView::drawAbsoluteZero (painter=%08X)", painter);
-//     bool painterCreated = false;
-
-       // create a temporary painter device
-       if (painter == NULL)
-       {
+       if (!painter)
                return;
-//Hrm.         createDirectPainter();
-//             createPainter();
-//             painterCreated = true;
-       }
 
        int zr = 20;
 
@@ -2017,18 +1978,13 @@ void RS_GraphicView::drawAbsoluteZero()
 //Using Qt::red doesn't seem to work here...
 //It's because Qt colors and RS_Color are not 100% compatible...
        RS_Pen p(RS_Color(255, 0, 0), RS2::Width00, RS2::SolidLine);
-//     p.setScreenWidth(0);
        painter->setPen(p);
-       //painter->setBrush(Qt::NoBrush);
 
        painter->drawLine(Vector(toGuiX(0.0) - zr, toGuiY(0.0)),
                Vector(toGuiX(0.0) + zr, toGuiY(0.0)));
 
        painter->drawLine(Vector(toGuiX(0.0), toGuiY(0.0) - zr),
                Vector(toGuiX(0.0), toGuiY(0.0) + zr));
-
-//     if (painterCreated)
-//             destroyPainter();
 }
 
 /**
@@ -2040,21 +1996,8 @@ void RS_GraphicView::drawAbsoluteZero()
  */
 void RS_GraphicView::drawRelativeZero()
 {
-//#warning "!!! drawRelativeZero() not working AT ALL !!!"
-#if 1
-//     bool painterCreated = false;
-
-       if (relativeZero.valid == false)
-               return;
-
-       // create a temporary painter device
-       if (painter == NULL)
-       {
+       if (!relativeZero.valid || !painter)
                return;
-//hrm.         createDirectPainter();
-//             createPainter();
-//             painterCreated = true;
-       }
 
 //     RS_Pen p(Qt::red, RS2::Width00, RS2::SolidLine);
 //     p.setScreenWidth(0);
@@ -2072,12 +2015,7 @@ void RS_GraphicView::drawRelativeZero()
                Vector(toGuiX(relativeZero.x), toGuiY(relativeZero.y) + zr));
 
        painter->drawCircle(toGui(relativeZero), zr);
-
        painter->setNormalMode();
-
-//     if (painterCreated)
-//             destroyPainter();
-#endif
 }
 
 /**
@@ -2087,8 +2025,6 @@ void RS_GraphicView::drawRelativeZero()
  */
 void RS_GraphicView::drawPaper()
 {
-       bool painterCreated = false;
-
        if (container == NULL)
                return;
 
@@ -2100,12 +2036,8 @@ void RS_GraphicView::drawPaper()
        if (graphic->getPaperScale() < 1.0e-6)
                return;
 
-       // create a temporary painter device
        if (painter == NULL)
-       {
-               createDirectPainter();
-               painterCreated = true;
-       }
+               return;
 
        // draw paper:
        painter->setPen(RS_Pen(Qt::gray));
@@ -2134,9 +2066,6 @@ void RS_GraphicView::drawPaper()
        painter->fillRect((int)(v1.x) + 1, (int)(v1.y) - 1,
                (int)((v2.x - v1.x)) - 2, (int)((v2.y - v1.y)) + 2,
                RS_Color(255, 255, 255));
-
-       if (painterCreated)
-               destroyPainter();
 }
 
 /**
@@ -2188,38 +2117,27 @@ void RS_GraphicView::drawMetaGrid()
        if (grid == NULL || isGridOn() == false /*|| grid->getMetaSpacing()<0.0*/)
                return;
 
-       bool painterCreated = false;
-
-       // create a temporary painter device
        if (painter == NULL)
-       {
-//hrm          createDirectPainter();
-               createPainter();
-               painterCreated = true;
-       }
+               return;
 
        RS_Pen pen(metaGridColor, RS2::Width00, RS2::DotLine);
        painter->setPen(pen);
 
        // draw meta grid:
        double * mx = grid->getMetaX();
+       double * my = grid->getMetaY();
 
-       if (mx != NULL)
+       if (mx)
        {
                for(int i=0; i<grid->countMetaX(); ++i)
                        painter->drawLine(Vector(toGuiX(mx[i]), 0), Vector(toGuiX(mx[i]), getHeight()));
        }
 
-       double * my = grid->getMetaY();
-
-       if (my != NULL)
+       if (my)
        {
                for(int i=0; i<grid->countMetaY(); ++i)
                        painter->drawLine(Vector(0, toGuiY(my[i])), Vector(getWidth(), toGuiY(my[i])));
        }
-
-       if (painterCreated)
-               destroyPainter();
 }
 
 /**
@@ -2415,25 +2333,14 @@ void RS_GraphicView::setRelativeZero(const Vector & pos)
  */
 void RS_GraphicView::moveRelativeZero(const Vector & pos)
 {
-//     bool painterCreated = false;
-
-       if (painter == NULL)
-       {
+#warning "!!! RS_GraphicView::moveRelativeZero(): Bad render path !!!"
+       if (!painter)
                return;
-//hrm          painter = createDirectPainter();
-//             painter = createPainter();
-//             painterCreated = true;
-       }
 
        //painter->setXORMode();
        drawRelativeZero();
-
        setRelativeZero(pos);
-
        drawRelativeZero();
-
-//     if (painterCreated)
-//             destroyPainter();
 }
 
 RS_EventHandler * RS_GraphicView::getEventHandler()