From c715d05d11ffe2913fe3465ec43d456ee9b85964 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Wed, 7 Jul 2010 13:38:10 +0000 Subject: [PATCH] Fixed preview rendering for ActionDrawLine... --- src/actions/rs_actiondrawline.cpp | 48 +++++++--- src/actions/rs_actionzoompan.cpp | 6 +- src/base/rs_entitycontainer.cpp | 2 +- src/base/rs_eventhandler.cpp | 20 ++-- src/base/rs_line.cpp | 4 +- src/base/rs_preview.cpp | 57 +++++++++--- src/base/rs_preview.h | 10 ++ src/base/rs_previewactioninterface.cpp | 1 + src/base/rs_previewactioninterface.h | 12 +-- src/base/rs_snapper.cpp | 27 ++---- src/mainapp/graphicview.cpp | 121 +++++++++++++------------ src/mainapp/graphicview.h | 75 ++------------- src/widgets/qg_graphicview.cpp | 68 ++++++-------- 13 files changed, 227 insertions(+), 224 deletions(-) diff --git a/src/actions/rs_actiondrawline.cpp b/src/actions/rs_actiondrawline.cpp index 1c1860a..d911e77 100644 --- a/src/actions/rs_actiondrawline.cpp +++ b/src/actions/rs_actiondrawline.cpp @@ -29,6 +29,7 @@ RS_ActionDrawLine::RS_ActionDrawLine(RS_EntityContainer & container, GraphicView graphicView.snapper.SetContainer(&container); graphicView.snapper.SetGraphicView(&graphicView); graphicView.snapper.SetVisible(); + graphicView.preview.SetVisible(); RS_DEBUG->print("RS_ActionDrawLine::RS_ActionDrawLine: OK"); } @@ -61,7 +62,12 @@ void RS_ActionDrawLine::init(int status) void RS_ActionDrawLine::trigger() { +#if 0 RS_PreviewActionInterface::trigger(); // XOR off screen, delete entities in container +#else + graphicView->preview.clear(); +// graphicView->redraw(); +#endif RS_Line * line = new RS_Line(container, data); line->setLayerToActive(); @@ -81,13 +87,9 @@ void RS_ActionDrawLine::trigger() document->endUndoCycle(); } -// deleteSnapper(); // XOR off of screen -// graphicView->moveRelativeZero(Vector(0.0, 0.0)); -//This is unnecessary, because we added this to the container... -//#warning "!!! Here's the trouble... Trying to draw direct !!!" -// graphicView->drawEntity(line); graphicView->moveRelativeZero(line->getEndpoint()); -// drawSnapper(); // XOR on screen + //hm. [OK, it just moves the relative zero tho. Overkill. And remove preview, so OK.] + graphicView->redraw(); RS_DEBUG->print("RS_ActionDrawLine::trigger(): line added: %d", line->getId()); } @@ -96,14 +98,13 @@ void RS_ActionDrawLine::mouseMoveEvent(QMouseEvent * e) RS_DEBUG->print("RS_ActionDrawLine::mouseMoveEvent begin"); RS_DEBUG->print("RS_ActionDrawLine::mouseMoveEvent: snap point"); -//This used to draw the snapper, but now that's defunct... so, !!! FIX !!! -// Vector mouse = snapPoint(e); Vector mouse = graphicView->snapper.snapPoint(e); RS_DEBUG->print("RS_ActionDrawLine::mouseMoveEvent: snap point: OK"); if (getStatus() == SetEndpoint && data.startpoint.valid) { RS_DEBUG->print("RS_ActionDrawLine::mouseMoveEvent: update preview"); +#if 0 //not needed, but without this, it doesn't draw... strange... //obviously we haven't gotten our rendering path correct... // deletePreview(); // XOR off of screen @@ -112,9 +113,18 @@ void RS_ActionDrawLine::mouseMoveEvent(QMouseEvent * e) RS_DEBUG->print("RS_ActionDrawLine::mouseMoveEvent: draw preview"); // drawPreview(); // XOR on screen xorPreview(); // XOR on screen +#else + // This is lame. Creating a new Line every time the endpoint moves. + // Surely we can alter the line entity inside the preview, no? + graphicView->preview.clear(); // Remove entities from the container + RS_Line * line = new RS_Line(&(graphicView->preview), RS_LineData(data.startpoint, mouse)); +//wha? Even THIS doesn't work!!! It was the container... +// line->setPen(RS_Pen(RS_Color(60, 255, 60), RS2::Width00, RS2::SolidLine)); + graphicView->preview.addEntity(line); +#endif } - //hm. + //hm. [ok, this works. :-D] graphicView->redraw(); RS_DEBUG->print("RS_ActionDrawLine::mouseMoveEvent end"); } @@ -128,11 +138,23 @@ void RS_ActionDrawLine::mouseReleaseEvent(QMouseEvent * e) } else if (e->button() == Qt::RightButton) { + if (getStatus() == 0) + { + graphicView->snapper.SetVisible(false); + graphicView->preview.SetVisible(false); + } + +#if 0 deletePreview(); // XOR off of screen clearPreview(); // Remove entities from the container -// deleteSnapper(); // XOR off of screen +#else +#endif init(getStatus() - 1); } + + //hm. [Seems to work OK.] + graphicView->preview.clear(); // Remove entities from container + graphicView->redraw(); } void RS_ActionDrawLine::coordinateEvent(Vector * e) @@ -323,11 +345,13 @@ void RS_ActionDrawLine::undo() if (history.count() > 1) { history.removeLast(); - deletePreview(); // XOR off of screen - clearPreview(); // Delete entities in container +// deletePreview(); // XOR off of screen +// clearPreview(); // Delete entities in container graphicView->setCurrentAction(new RS_ActionEditUndo(true, *container, *graphicView)); data.startpoint = *history.last(); graphicView->moveRelativeZero(data.startpoint); +graphicView->preview.clear(); +graphicView->redraw(); } else RS_DIALOGFACTORY->commandMessage(tr("Cannot undo: Not enough entities defined yet.")); diff --git a/src/actions/rs_actionzoompan.cpp b/src/actions/rs_actionzoompan.cpp index 2066442..e4ce07a 100644 --- a/src/actions/rs_actionzoompan.cpp +++ b/src/actions/rs_actionzoompan.cpp @@ -43,13 +43,17 @@ void RS_ActionZoomPan::trigger() } } +#define SCROLL_DELTA 4 void RS_ActionZoomPan::mouseMoveEvent(QMouseEvent * e) { x2 = e->x(); y2 = e->y(); //This is where we see if the delta was big enough to warrant a redraw... - if (getStatus() == 1 && (abs(x2 - x1) > 7 || abs(y2 - y1) > 7)) +//Dunno if this is needed anymore, the Qt rendering pipeline should be able to +//hang with this... +// if (getStatus() == 1 && (abs(x2 - x1) > 7 || abs(y2 - y1) > 7)) + if (getStatus() == 1 && (abs(x2 - x1) > SCROLL_DELTA || abs(y2 - y1) > SCROLL_DELTA)) trigger(); } diff --git a/src/base/rs_entitycontainer.cpp b/src/base/rs_entitycontainer.cpp index 8434b9c..a13c0d6 100644 --- a/src/base/rs_entitycontainer.cpp +++ b/src/base/rs_entitycontainer.cpp @@ -348,7 +348,7 @@ void RS_EntityContainer::addEntity(RS_Entity * entity) */ //printf("RS_EntityContainer::addEntity(): entity=%08X\n", entity); - if (entity == NULL) + if (!entity) return; if (entity->rtti() == RS2::EntityImage || entity->rtti() == RS2::EntityHatch) diff --git a/src/base/rs_eventhandler.cpp b/src/base/rs_eventhandler.cpp index d12d76b..a92775c 100644 --- a/src/base/rs_eventhandler.cpp +++ b/src/base/rs_eventhandler.cpp @@ -132,7 +132,7 @@ void RS_EventHandler::mouseReleaseEvent(QMouseEvent * e) } else { - if (defaultAction != NULL) + if (defaultAction) defaultAction->mouseReleaseEvent(e); else e->ignore(); @@ -144,7 +144,7 @@ void RS_EventHandler::mouseReleaseEvent(QMouseEvent * e) */ void RS_EventHandler::mouseMoveEvent(QMouseEvent * e) { - if (actionIndex >= 0 && currentActions[actionIndex] != NULL + if (actionIndex >= 0 && currentActions[actionIndex] && !currentActions[actionIndex]->isFinished()) { currentActions[actionIndex]->mouseMoveEvent(e); @@ -152,7 +152,7 @@ void RS_EventHandler::mouseMoveEvent(QMouseEvent * e) } else { - if (defaultAction!=NULL) + if (defaultAction) { defaultAction->mouseMoveEvent(e); e->accept(); @@ -375,7 +375,7 @@ void RS_EventHandler::commandEvent(RS_CommandEvent * e) } else { - if (RS_DIALOGFACTORY != NULL) + if (RS_DIALOGFACTORY) RS_DIALOGFACTORY->commandMessage("Expression Syntax Error"); } @@ -388,7 +388,7 @@ void RS_EventHandler::commandEvent(RS_CommandEvent * e) // send command event directly to current action: if (!e->isAccepted()) { - if (actionIndex >= 0 && currentActions[actionIndex] != NULL + if (actionIndex >= 0 && currentActions[actionIndex] && !currentActions[actionIndex]->isFinished()) { currentActions[actionIndex]->commandEvent(e); @@ -396,7 +396,7 @@ void RS_EventHandler::commandEvent(RS_CommandEvent * e) } else { - if (defaultAction != NULL) + if (defaultAction) defaultAction->commandEvent(e); } } @@ -462,14 +462,14 @@ void RS_EventHandler::setCurrentAction(RS_ActionInterface * action) { RS_DEBUG->print("RS_EventHandler::setCurrentAction"); - if (action == NULL) + if (!action) return; // Predecessor of the new action or NULL: RS_ActionInterface * predecessor = NULL; // Suspend current action: - if (actionIndex >= 0 && currentActions[actionIndex] != NULL + if (actionIndex >= 0 && currentActions[actionIndex] && !currentActions[actionIndex]->isFinished()) { predecessor = currentActions[actionIndex]; @@ -478,7 +478,7 @@ void RS_EventHandler::setCurrentAction(RS_ActionInterface * action) } else { - if (defaultAction != NULL) + if (defaultAction) { predecessor = defaultAction; predecessor->suspend(); @@ -570,7 +570,7 @@ void RS_EventHandler::killAllActions() */ bool RS_EventHandler::hasAction() { - if (actionIndex != -1 || defaultAction != NULL) + if (actionIndex != -1 || defaultAction) return true; return false; diff --git a/src/base/rs_line.cpp b/src/base/rs_line.cpp index f67d108..224d170 100644 --- a/src/base/rs_line.cpp +++ b/src/base/rs_line.cpp @@ -487,7 +487,7 @@ void RS_Line::moveRef(const Vector& ref, const Vector& offset) void RS_Line::draw(PaintInterface * painter, GraphicView * view, double patternOffset) { - if (painter == NULL || view == NULL) + if (!painter || !view) //{ //printf("RS_Line::draw(): Bailing out!!! painter=%08X, view=%08X\n", painter, view); return; @@ -516,7 +516,7 @@ void RS_Line::draw(PaintInterface * painter, GraphicView * view, double patternO RS_LineTypePattern * pat = (isSelected() ? &patternSelected : view->getPattern(getPen().getLineType())); #endif - if (pat == NULL) + if (!pat) { //printf("RS_Line::draw(): Pattern == NULL!\n"); RS_DEBUG->print(RS_Debug::D_WARNING, "RS_Line::draw: Invalid line pattern"); diff --git a/src/base/rs_preview.cpp b/src/base/rs_preview.cpp index 6bbbb66..1de0166 100644 --- a/src/base/rs_preview.cpp +++ b/src/base/rs_preview.cpp @@ -17,12 +17,14 @@ #include "rs_entitycontainer.h" #include "graphicview.h" #include "rs_information.h" +#include "paintintf.h" #include "settings.h" /** * Constructor. */ -RS_Preview::RS_Preview(RS_EntityContainer * parent): RS_EntityContainer(parent) +RS_Preview::RS_Preview(RS_EntityContainer * parent): RS_EntityContainer(parent), + visible(false) { settings.beginGroup("Appearance"); maxEntities = settings.value("MaxPreview", 100).toInt(); @@ -93,11 +95,11 @@ void RS_Preview::addEntity(RS_Entity * entity) } /** -* Clones the given entity and adds the clone to the preview. -*/ -void RS_Preview::addCloneOf(RS_Entity* entity) + * Clones the given entity and adds the clone to the preview. + */ +void RS_Preview::addCloneOf(RS_Entity * entity) { - if (entity == NULL) + if (!entity) return; RS_Entity * clone = entity->clone(); @@ -105,8 +107,8 @@ void RS_Preview::addCloneOf(RS_Entity* entity) } /** -* Adds all entities from 'container' to the preview (unselected). -*/ + * Adds all entities from 'container' to the preview (unselected). + */ void RS_Preview::addAllFrom(RS_EntityContainer & container) { int c = 0; @@ -127,8 +129,8 @@ void RS_Preview::addAllFrom(RS_EntityContainer & container) } /** -* Adds all selected entities from 'container' to the preview (unselected). -*/ + * Adds all selected entities from 'container' to the preview (unselected). + */ void RS_Preview::addSelectionFrom(RS_EntityContainer & container) { int c = 0; @@ -149,9 +151,9 @@ void RS_Preview::addSelectionFrom(RS_EntityContainer & container) } /** -* Adds all entities in the given range and those which have endpoints -* in the given range to the preview. -*/ + * Adds all entities in the given range and those which have endpoints in the + * given range to the preview. + */ void RS_Preview::addStretchablesFrom(RS_EntityContainer & container, const Vector & v1, const Vector & v2) { @@ -172,3 +174,34 @@ void RS_Preview::addStretchablesFrom(RS_EntityContainer & container, const Vecto } } } + +void RS_Preview::SetOffset(Vector v) +{ + offset = v; +} + +Vector RS_Preview::Offset(void) +{ + return offset; +} + +void RS_Preview::SetVisible(bool visibility/*= true*/) +{ + visible = visibility; +} + +bool RS_Preview::Visible(void) +{ + return visible; +} + +void RS_Preview::Draw(GraphicView * view, PaintInterface * painter) +{ + if (isEmpty()) + return; + +// painter->setPreviewMode(); + painter->setOffset(offset); + view->drawEntity(this, false); + painter->setOffset(Vector(0, 0)); +} diff --git a/src/base/rs_preview.h b/src/base/rs_preview.h index f8a98c3..e1151de 100644 --- a/src/base/rs_preview.h +++ b/src/base/rs_preview.h @@ -2,8 +2,10 @@ #define RS_PREVIEW_H #include "rs_entitycontainer.h" +#include "vector.h" class RS_Entity; +class PaintInterface; /** * This class supports previewing. The RS_Snapper class uses @@ -25,8 +27,16 @@ class RS_Preview: public RS_EntityContainer virtual void addStretchablesFrom(RS_EntityContainer & container, const Vector & v1, const Vector & v2); + void SetOffset(Vector); + Vector Offset(void); + void SetVisible(bool visibility = true); + bool Visible(void); + void Draw(GraphicView *, PaintInterface *); + private: int maxEntities; + bool visible; + Vector offset; }; #endif diff --git a/src/base/rs_previewactioninterface.cpp b/src/base/rs_previewactioninterface.cpp index 3301ac6..d843152 100644 --- a/src/base/rs_previewactioninterface.cpp +++ b/src/base/rs_previewactioninterface.cpp @@ -109,6 +109,7 @@ void RS_PreviewActionInterface::deletePreview() */ void RS_PreviewActionInterface::xorPreview() { +#warning "!!! RS_PreviewActionInterface::xorPreview() is DEPRECATED !!!" //not true anymore.. //#warning "!!! xorPreview() not working AT ALL !!!" #if 0 diff --git a/src/base/rs_previewactioninterface.h b/src/base/rs_previewactioninterface.h index 2b356dc..a8f6780 100644 --- a/src/base/rs_previewactioninterface.h +++ b/src/base/rs_previewactioninterface.h @@ -34,16 +34,16 @@ class RS_PreviewActionInterface: public RS_ActionInterface protected: /** - * Preview that holds the entities to be previewed. - */ + * Preview that holds the entities to be previewed. + */ RS_Preview * preview; /** - * Keeps track of the drawings in XOR mode. - */ + * Keeps track of the drawings in XOR mode. + */ bool visible; /** - * Current offset of the preview. - */ + * Current offset of the preview. + */ Vector offset; }; diff --git a/src/base/rs_snapper.cpp b/src/base/rs_snapper.cpp index 542810e..0767b6e 100644 --- a/src/base/rs_snapper.cpp +++ b/src/base/rs_snapper.cpp @@ -79,6 +79,7 @@ void RS_Snapper::finish() finished = true; } +//bleh void RS_Snapper::SetContainer(RS_EntityContainer * c) { container = c; @@ -133,8 +134,6 @@ void RS_Snapper::setSnapRange(int r) Vector RS_Snapper::snapPoint(QMouseEvent * e) { RS_DEBUG->print("RS_Snapper::snapPoint"); - -//meh deleteSnapper(); snapSpot = Vector(false); if (!e) @@ -183,8 +182,7 @@ Vector RS_Snapper::snapPoint(QMouseEvent * e) break; } - // handle snap restrictions that can be activated in addition - // to the ones above: + // Handle snap restrictions that can be activated in addition to the ones above: switch (snapRes) { case RS2::RestrictOrthogonal: @@ -202,9 +200,6 @@ Vector RS_Snapper::snapPoint(QMouseEvent * e) break; } -//#warning "!!! THIS IS WHERE THE SNAPPER IS BEING DRAWN... !!!" -// drawSnapper(); - if (RS_DIALOGFACTORY) RS_DIALOGFACTORY->updateCoordinateWidget(snapCoord, snapCoord - graphicView->getRelativeZero()); @@ -394,8 +389,7 @@ Vector RS_Snapper::restrictOrthogonal(Vector coord) Vector RS_Snapper::restrictHorizontal(Vector coord) { Vector rz = graphicView->getRelativeZero(); -// Vector ret = Vector(coord.x, rz.y); -// return ret; + return Vector(coord.x, rz.y); } @@ -409,8 +403,7 @@ Vector RS_Snapper::restrictHorizontal(Vector coord) Vector RS_Snapper::restrictVertical(Vector coord) { Vector rz = graphicView->getRelativeZero(); -// Vector ret = Vector(rz.x, coord.y); -// return ret; + return Vector(rz.x, coord.y); } @@ -529,6 +522,7 @@ printf("RS_Snapper::deleteSnapper(): Using DEPRECATED function!!!\n"); */ void RS_Snapper::xorSnapper() { +#warning "!!! RS_Snapper::xorSnapper() is DEPRECATED !!!" //Not completely true... //#warning "!!! xorSnapper() not working AT ALL !!!" #if 0 @@ -568,7 +562,7 @@ void RS_Snapper::xorSnapper() graphicView->destroyPainter(); visible = !visible; } -#else +//#else if (finished || !snapSpot.valid || !graphicView) return; @@ -583,24 +577,18 @@ void RS_Snapper::xorSnapper() void RS_Snapper::SetVisible(bool visibility/*= true*/) { -// graphicView->SetSnapperDraw(visibility); visible = visibility; } bool RS_Snapper::Visible(void) { -// graphicView->SetSnapperDraw(visibility); return visible; } void RS_Snapper::Draw(GraphicView * view, PaintInterface * painter) { -//printf("RS_Snapper::Draw()..."); if (finished || !snapSpot.valid) return; -//printf("{D}\n"); - -//meh painter->setPreviewMode(); //hm, I don't like graphicView kicking around in here, especially since it now //lives inside GraphicView... How to !!! FIX !!!? @@ -608,9 +596,10 @@ void RS_Snapper::Draw(GraphicView * view, PaintInterface * painter) if (snapCoord.valid) { // snap point + painter->setPen(RS_Pen(RS_Color(0, 127, 255), RS2::Width00, RS2::DashLine)); painter->drawCircle(view->toGui(snapCoord), 4); - // crosshairs: + // crosshairs if (showCrosshairs) { painter->setPen(RS_Pen(RS_Color(0, 255, 255), RS2::Width00, RS2::DashLine)); diff --git a/src/mainapp/graphicview.cpp b/src/mainapp/graphicview.cpp index d3b39ca..a79ce63 100644 --- a/src/mainapp/graphicview.cpp +++ b/src/mainapp/graphicview.cpp @@ -28,7 +28,7 @@ * Constructor. */ GraphicView::GraphicView(): background(), foreground(), previewMode(false), - previewOffset(Vector(0, 0)), snapperDraw(false) + previewOffset(Vector(0, 0))//, snapperDraw(false) { drawingMode = RS2::ModeFull; printing = false; @@ -88,7 +88,7 @@ GraphicView::GraphicView(): background(), foreground(), previewMode(false), GraphicView::~GraphicView() { //delete eventHandler; - if (painter != NULL) + if (painter) delete painter; delete grid; @@ -109,10 +109,10 @@ void GraphicView::cleanUp() */ Drawing * GraphicView::getGraphic() { - if (container != NULL && container->rtti() == RS2::EntityGraphic) - return (Drawing*)container; - else - return NULL; + if (container && container->rtti() == RS2::EntityGraphic) + return (Drawing *)container; + + return NULL; } /** @@ -160,6 +160,7 @@ void GraphicView::adjustZoomControls() { } +#if 0 /** * Sets an external painter device. */ @@ -168,6 +169,7 @@ void GraphicView::setPainter(PaintInterface * p) { painter = p; } +#endif /** * Sets the background color. Note that applying the background @@ -1264,69 +1266,69 @@ void GraphicView::setPenForEntity(RS_Entity * e) if (drawingMode == RS2::ModePreview /*|| draftMode==true*/) return; - // set color of entity - if (painter && !painter->isPreviewMode()) - { - // Getting pen from entity (or layer) - RS_Pen pen = e->getPen(true); - - int w = pen.getWidth(); + if (!painter || painter->isPreviewMode()) + return; - if (w < 0) - w = 0; + // set color of entity + // Getting pen from entity (or layer) + RS_Pen pen = e->getPen(true); - // scale pen width: - if (!draftMode) - { - double uf = 1.0; // unit factor - double wf = 1.0; // width factor - Drawing * graphic = container->getGraphic(); + int w = pen.getWidth(); - if (graphic != NULL) - { - uf = RS_Units::convert(1.0, RS2::Millimeter, graphic->getUnit()); + if (w < 0) + w = 0; - if ((isPrinting() || isPrintPreview()) && graphic->getPaperScale() > 1.0e-6) - wf = 1.0 / graphic->getPaperScale(); - } + // scale pen width: + if (!draftMode) + { + double uf = 1.0; // unit factor + double wf = 1.0; // width factor + Drawing * graphic = container->getGraphic(); - pen.setScreenWidth(toGuiDX(w / 100.0 * uf * wf)); - } - else + if (graphic) { - //pen.setWidth(RS2::Width00); - pen.setScreenWidth(0); - } + uf = RS_Units::convert(1.0, RS2::Millimeter, graphic->getUnit()); - // prevent drawing with 1-width which is slow: - if (RS_Math::round(pen.getScreenWidth()) == 1) - pen.setScreenWidth(0.0); + if ((isPrinting() || isPrintPreview()) && graphic->getPaperScale() > 1.0e-6) + wf = 1.0 / graphic->getPaperScale(); + } - // prevent background color on background drawing: - if (pen.getColor().stripFlags() == background.stripFlags()) - pen.setColor(foreground); + pen.setScreenWidth(toGuiDX(w / 100.0 * uf * wf)); + } + else + { + //pen.setWidth(RS2::Width00); + pen.setScreenWidth(0); + } - // this entity is selected: - if (e->isSelected()) - { - pen.setLineType(RS2::DotLine); - //pen.setColor(RS_Color(0xa5,0x47,0x47)); - pen.setColor(selectedColor); - } + // prevent drawing with 1-width which is slow: + if (RS_Math::round(pen.getScreenWidth()) == 1) + pen.setScreenWidth(0.0); - // this entity is highlighted: - if (e->isHighlighted()) - { - //pen.setColor(RS_Color(0x73, 0x93, 0x73)); - pen.setColor(highlightedColor); - } + // prevent background color on background drawing: + if (pen.getColor().stripFlags() == background.stripFlags()) + pen.setColor(foreground); - // deleting not drawing: - if (getDeleteMode()) - pen.setColor(background); + // this entity is selected: + if (e->isSelected()) + { + pen.setLineType(RS2::DotLine); + //pen.setColor(RS_Color(0xa5,0x47,0x47)); + pen.setColor(selectedColor); + } - painter->setPen(pen); + // this entity is highlighted: + if (e->isHighlighted()) + { + //pen.setColor(RS_Color(0x73, 0x93, 0x73)); + pen.setColor(highlightedColor); } + + // deleting not drawing: + if (getDeleteMode()) + pen.setColor(background); + + painter->setPen(pen); } /** @@ -1454,7 +1456,7 @@ void GraphicView::deleteEntity(RS_Entity * e) * Draws an entity. * The painter must be initialized and all the attributes (pen) must be set. */ -void GraphicView::drawEntityPlain(RS_Entity * e, double patternOffset) +void GraphicView::drawEntityPlain(RS_Entity * e, double patternOffset/*= 0.0*/) { //Problems can still occur here when passing in a deleted object... It won't be //NULL, but it will cause a segfault here... @@ -2179,7 +2181,7 @@ void GraphicView::setDefaultSnapMode(RS2::SnapMode sm) //OK, the above sets the snap mode in the snapper that's derived from //the RS_ActionInterface and RS_Snapper. So the following should fix - //us up, hm notwithstanding. + //us up, hm notwithstanding. [and it does. :-)] //hm. snapper.setSnapMode(sm); } @@ -2453,6 +2455,8 @@ void GraphicView::SetPreviewOffset(Vector o) previewOffset = o; } +//Don't need this no more... +#if 0 void GraphicView::SetSnapperDraw(bool mode) { snapperDraw = mode; @@ -2464,3 +2468,4 @@ void GraphicView::SetSnapperVars(Vector snapSpot, Vector snapCoord, bool showCro snapCoord1 = snapCoord; showCrosshairs1 = showCrosshairs; } +#endif diff --git a/src/mainapp/graphicview.h b/src/mainapp/graphicview.h index e2d7b54..94e5be2 100644 --- a/src/mainapp/graphicview.h +++ b/src/mainapp/graphicview.h @@ -4,6 +4,7 @@ #include #include "rs.h" #include "rs_color.h" +#include "rs_preview.h" #include "rs_snapper.h" #include "vector.h" @@ -50,10 +51,6 @@ class GraphicView /** This virtual method must be overwritten and is then called whenever the view changed */ virtual void adjustZoomControls(); - /** - * Sets an external painter device. - */ - virtual void setPainter(PaintInterface * p); virtual void setBackground(const RS_Color & bg); RS_Color getBackground(); @@ -203,8 +200,9 @@ class GraphicView void SetPreviewMode(bool mode = true); void SetPreviewEntity(RS_Preview *); void SetPreviewOffset(Vector); - void SetSnapperDraw(bool); - void SetSnapperVars(Vector snapSpot, Vector snapCoord, bool showCrosshairs); +//We can remove this now... +// void SetSnapperDraw(bool); +// void SetSnapperVars(Vector snapSpot, Vector snapCoord, bool showCrosshairs); protected: RS_EntityContainer * container; @@ -287,16 +285,17 @@ class GraphicView // We use this here instead of deriving ActionInterface from it because // this makes more sense. RS_Snapper snapper; + RS_Preview preview; protected: // crap to make painting with update() possible RS_Preview * previewEntity; bool previewMode; Vector previewOffset; - bool snapperDraw; - Vector snapSpot1; - Vector snapCoord1; - bool showCrosshairs1; +// bool snapperDraw; +// Vector snapSpot1; +// Vector snapCoord1; +// bool showCrosshairs1; //QG protected: @@ -327,8 +326,7 @@ class GraphicView #endif // __GRAPHICVIEW_H__ #if 0 -class QG_GraphicView: public QWidget, public RS_GraphicView, //public Q3FilePreview, - public RS_LayerListListener, public RS_BlockListListener +class QG_GraphicView: public QWidget, public RS_GraphicView { Q_OBJECT @@ -341,21 +339,10 @@ class QG_GraphicView: public QWidget, public RS_GraphicView, //public Q3FilePrev virtual void redraw(); virtual void adjustOffsetControls(); virtual void adjustZoomControls(); -// virtual RS_Painter * createPainter(); -// virtual RS_Painter * createDirectPainter(); -#warning "!!! Need to scrub out all instances of createPainter and createDirectPainter !!!" -// virtual PaintInterface * createPainter(); -// virtual PaintInterface * createDirectPainter(); -// virtual void destroyPainter(); virtual void setBackground(const RS_Color & bg); virtual void setMouseCursor(RS2::CursorType c); virtual void updateGridStatusWidget(const QString & text); - // Methods from RS_LayerListListener Interface: - virtual void layerEdited(RS_Layer *); - virtual void layerRemoved(RS_Layer *); - virtual void layerToggled(RS_Layer *); - protected: virtual void emulateMouseMoveEvent(); virtual void mousePressEvent(QMouseEvent * e); @@ -373,50 +360,8 @@ class QG_GraphicView: public QWidget, public RS_GraphicView, //public Q3FilePrev void paintEvent(QPaintEvent *); virtual void resizeEvent(QResizeEvent * e); -#warning "!!! File preview needs porting to Qt4 !!!" -// void previewUrl(const Q3Url &u); - private slots: void slotHScrolled(int value); void slotVScrolled(int value); - - private: -#warning "!!! Double buffering is not necessary anymore !!!" - //! Buffer for double-buffering - QPixmap * buffer; -// int refCount; - - protected: - int lastWidth; - int lastHeight; - //! Horizontal scrollbar. - QG_ScrollBar * hScrollBar; - //! Vertical scrollbar. - QG_ScrollBar * vScrollBar; - //! Layout used to fit in the view and the scrollbars. - QGridLayout * layout; - //! Label for grid spacing. - QLabel * gridStatus; - //! CAD mouse cursor - QCursor * curCad; - //! Delete mouse cursor - QCursor * curDel; - //! Select mouse cursor - QCursor * curSelect; - //! Magnifying glass mouse cursor - QCursor * curMagnifier; - //! Hand mouse cursor - QCursor * curHand; -}; -#endif - -#if 0 -class QC_GraphicView: public QG_GraphicView -{ - public: - QC_GraphicView(RS_Document * doc, QWidget * parent = 0); - virtual ~QC_GraphicView(); - - virtual void drawIt(); }; #endif diff --git a/src/widgets/qg_graphicview.cpp b/src/widgets/qg_graphicview.cpp index 57c8267..b6d66dd 100644 --- a/src/widgets/qg_graphicview.cpp +++ b/src/widgets/qg_graphicview.cpp @@ -659,7 +659,7 @@ void QG_GraphicView::adjustOffsetControls() RS_DEBUG->print("QG_GraphicView::adjustOffsetControls() begin"); - if (container == NULL || hScrollBar == NULL || vScrollBar == NULL) + if (!container || !hScrollBar || !vScrollBar) return; disableUpdate(); @@ -880,13 +880,13 @@ What's needed: } #endif -#if 1 //Note that we do drawIt() regardless here because paintEvent() clears the background //*unless* we create the window with a specific style. Depending on our draw code, we //just may go that way... drawIt(); //Need some logic here to do drawing in preview mode, since it'll be calling //update now instead of trying to do a direct draw... +#if 0 if (previewMode) { //hrm. painter->setCompositionMode(QPainter::CompositionMode_Xor); @@ -897,48 +897,40 @@ What's needed: // We'll set previewMode to false here, just because we can previewMode = false; } -#endif - - if (snapper.Visible()) - snapper.Draw(this, painter); -#if 0 - if (snapperDraw) -// if (false) +#else + if (preview.Visible()) { - snapperDraw = false; - - if (snapCoord1.valid) + RS_Pen oldPen = painter->getPen(); + //ick. doesn't work... +// pntr.setCompositionMode(QPainter::CompositionMode_Xor); + // One of these has GOT to work... (but NEITHER do...!) + // It's because this is the pen for the container, not the entities INSIDE... + // How do we fix that??? [by drawing the container ourselves, that's how. :-/] + painter->setPen(RS_Pen(RS_Color(60, 255, 80), RS2::Width00, RS2::SolidLine)); +// preview.setPen(RS_Pen(RS_Color(60, 255, 60), RS2::Width00, RS2::SolidLine)); + painter->setOffset(preview.Offset()); +//This is green, but in the upper left hand corner... +//painter->drawLine(Vector(15, 15), Vector(15, -15)); +//painter->drawLine(Vector(15, -15), Vector(-15, -15)); +//painter->drawLine(Vector(-15, -15), Vector(-15, 15)); +//painter->drawLine(Vector(-15, 15), Vector(15, 15)); +// drawEntityPlain(&preview); + for(RS_Entity * e=preview.firstEntity(RS2::ResolveNone); e!=NULL; + e = preview.nextEntity(RS2::ResolveNone)) { - // snap point -//This is causing segfaults in the Qt::Painter code... -//*This* is causing the segfault! -//Actually, it looks like buggy painting code in PaintInterface()... - painter->drawCircle(toGui(snapCoord1), 4); - - #if 1 - // crosshairs: - if (showCrosshairs1 == true) - { - painter->setPen(RS_Pen(RS_Color(0, 255, 255), RS2::Width00, RS2::DashLine)); - painter->drawLine(Vector(0, toGuiY(snapCoord1.y)), - Vector(getWidth(), toGuiY(snapCoord1.y))); - painter->drawLine(Vector(toGuiX(snapCoord1.x), 0), - Vector(toGuiX(snapCoord1.x), getHeight())); - } - #endif - } - #if 1 - if (snapCoord1.valid && snapCoord1 != snapSpot1) - { - painter->drawLine(toGui(snapSpot1) + Vector(-5, 0), toGui(snapSpot1) + Vector(-1, 4)); - painter->drawLine(toGui(snapSpot1) + Vector(0, 5), toGui(snapSpot1) + Vector(4, 1)); - painter->drawLine(toGui(snapSpot1) + Vector(5, 0), toGui(snapSpot1) + Vector(1, -4)); - painter->drawLine(toGui(snapSpot1) + Vector(0, -5), toGui(snapSpot1) + Vector(-4, -1)); +// e->setPen(RS_Pen(RS_Color(60, 255, 80), RS2::Width00, RS2::SolidLine)); + drawEntityPlain(e); } - #endif + //ick +// pntr.setCompositionMode(QPainter::CompositionMode_Source); + painter->setOffset(Vector(0, 0)); + painter->setPen(oldPen); } #endif + if (snapper.Visible()) + snapper.Draw(this, painter); + delete painter; painter = NULL; -- 2.37.2