X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fbase%2Frs_graphicview.cpp;h=a2dcb73fd5e9e17747eb6feb1a7cf6477778fb3a;hb=3b479913b79032e514ce8c74ba915c6c91ab0f15;hp=28d86c9852815bd877e6121e38328b51cb2509bc;hpb=89e127aa3dbd74d3158e6dbe0ca1703420c04395;p=architektonas diff --git a/src/base/rs_graphicview.cpp b/src/base/rs_graphicview.cpp index 28d86c9..a2dcb73 100644 --- a/src/base/rs_graphicview.cpp +++ b/src/base/rs_graphicview.cpp @@ -16,10 +16,10 @@ #include #include "rs_actioninterface.h" -#include "rs_application.h" #include "rs_block.h" -#include "rs_eventhandler.h" +#include "rs_dialogfactory.h" #include "drawing.h" +#include "rs_eventhandler.h" #include "rs_grid.h" #include "rs_insert.h" #include "rs_layer.h" @@ -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,22 +553,18 @@ void RS_GraphicView::mouseReleaseEvent(QMouseEvent * e) { RS_DEBUG->print("RS_GraphicView::mouseReleaseEvent"); - if (eventHandler != NULL) - { - if (RS2::qtToRsButtonState(e->button()) != RS2::RightButton - || eventHandler->hasAction()) - { - eventHandler->mouseReleaseEvent(e); - //e->accept(); - } - else - { - back(); -//#if QT_VERSION>=0x030000 - e->accept(); -//#endif + if (!eventHandler) + return; - } + if (e->button() != Qt::RightButton || eventHandler->hasAction()) + { + eventHandler->mouseReleaseEvent(e); + //e->accept(); + } + else + { + back(); + e->accept(); } RS_DEBUG->print("RS_GraphicView::mouseReleaseEvent: OK"); @@ -599,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(); @@ -607,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); } @@ -630,7 +616,7 @@ void RS_GraphicView::mouseMoveEvent(QMouseEvent * e) */ void RS_GraphicView::mouseLeaveEvent() { - if (eventHandler != NULL) + if (eventHandler) eventHandler->mouseLeaveEvent(); } @@ -640,7 +626,7 @@ void RS_GraphicView::mouseLeaveEvent() */ void RS_GraphicView::mouseEnterEvent() { - if (eventHandler != NULL) + if (eventHandler) eventHandler->mouseEnterEvent(); } @@ -650,7 +636,7 @@ void RS_GraphicView::mouseEnterEvent() */ void RS_GraphicView::keyPressEvent(QKeyEvent * e) { - if (eventHandler != NULL) + if (eventHandler) eventHandler->keyPressEvent(e); } @@ -660,7 +646,7 @@ void RS_GraphicView::keyPressEvent(QKeyEvent * e) */ void RS_GraphicView::keyReleaseEvent(QKeyEvent * e) { - if (eventHandler != NULL) + if (eventHandler) eventHandler->keyReleaseEvent(e); } @@ -669,7 +655,7 @@ void RS_GraphicView::keyReleaseEvent(QKeyEvent * e) */ void RS_GraphicView::commandEvent(RS_CommandEvent * e) { - if (eventHandler != NULL) + if (eventHandler) eventHandler->commandEvent(e); } @@ -678,7 +664,7 @@ void RS_GraphicView::commandEvent(RS_CommandEvent * e) */ void RS_GraphicView::enableCoordinateInput() { - if (eventHandler != NULL) + if (eventHandler) eventHandler->enableCoordinateInput(); } @@ -687,7 +673,7 @@ void RS_GraphicView::enableCoordinateInput() */ void RS_GraphicView::disableCoordinateInput() { - if (eventHandler != NULL) + if (eventHandler) eventHandler->disableCoordinateInput(); } @@ -1209,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); @@ -1240,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()) @@ -1267,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()) @@ -1286,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(); } /** @@ -1520,9 +1483,8 @@ void RS_GraphicView::simulateIt() simulationRunning = true; simulationLast = Vector(0.0, 0.0); - destroyPainter(); +//jlh destroyPainter(); - createDirectPainter(); painter->erase(); // drawing paper border: @@ -1562,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; } @@ -1593,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)); @@ -1653,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); @@ -1770,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)); @@ -1795,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); } @@ -1840,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()) @@ -1860,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); @@ -1881,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()) @@ -1899,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)); @@ -1997,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; @@ -2021,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(); } /** @@ -2044,22 +1996,9 @@ void RS_GraphicView::drawAbsoluteZero() */ void RS_GraphicView::drawRelativeZero() { -//#warning "!!! drawRelativeZero() not working AT ALL !!!" -#if 1 -// bool painterCreated = false; - - if (relativeZero.valid == false) + if (!relativeZero.valid || !painter) return; - // create a temporary painter device - if (painter == NULL) - { - return; -//hrm. createDirectPainter(); -// createPainter(); -// painterCreated = true; - } - // RS_Pen p(Qt::red, RS2::Width00, RS2::SolidLine); // p.setScreenWidth(0); //Using Qt::red doesn't seem to work here... @@ -2076,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 } /** @@ -2091,8 +2025,6 @@ void RS_GraphicView::drawRelativeZero() */ void RS_GraphicView::drawPaper() { - bool painterCreated = false; - if (container == NULL) return; @@ -2104,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)); @@ -2138,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(); } /** @@ -2192,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; icountMetaX(); ++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; icountMetaY(); ++i) painter->drawLine(Vector(0, toGuiY(my[i])), Vector(getWidth(), toGuiY(my[i]))); } - - if (painterCreated) - destroyPainter(); } /** @@ -2419,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()