]> Shamusworld >> Repos - architektonas/commitdiff
Fixed preview rendering for ActionDrawLine...
authorShamus Hammons <jlhamm@acm.org>
Wed, 7 Jul 2010 13:38:10 +0000 (13:38 +0000)
committerShamus Hammons <jlhamm@acm.org>
Wed, 7 Jul 2010 13:38:10 +0000 (13:38 +0000)
13 files changed:
src/actions/rs_actiondrawline.cpp
src/actions/rs_actionzoompan.cpp
src/base/rs_entitycontainer.cpp
src/base/rs_eventhandler.cpp
src/base/rs_line.cpp
src/base/rs_preview.cpp
src/base/rs_preview.h
src/base/rs_previewactioninterface.cpp
src/base/rs_previewactioninterface.h
src/base/rs_snapper.cpp
src/mainapp/graphicview.cpp
src/mainapp/graphicview.h
src/widgets/qg_graphicview.cpp

index 1c1860af04f88143cb0a84b63d1590c1a1f6b484..d911e779c02016f7258631b1c4d6a58075bbdc6b 100644 (file)
@@ -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."));
index 2066442bd361d8277e9340785a1a4ed92f99e876..e4ce07afef8e813f1e2ee97c309e933d4f6f5e06 100644 (file)
@@ -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();
 }
 
index 8434b9cc86a22e009e3e7c56f2470ca35c2af724..a13c0d6fc82ea385193d560c8f8da65eade50357 100644 (file)
@@ -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)
index d12d76bab277ed44e100cd1a3aaed0725b2f15bc..a92775c000a6bc46ae54318b8e1bfa51cae9565c 100644 (file)
@@ -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;
index f67d1089c056e101a979a17490f4cdedef5d22c2..224d17033982688ab005d6fe53cd0ac411ebb5ad 100644 (file)
@@ -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");
index 6bbbb661978588081b1cf4a2e7ac5d7bb45d1e32..1de0166b68947bdec3f5587888f86787e3e002c6 100644 (file)
 #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));
+}
index f8a98c32f7e9d8607fe75c69c7e5fe4da4206cbd..e1151de3efaae88f51163a13cf03da0deab00899 100644 (file)
@@ -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
index 3301ac6e783cd80b16aca559d397b52844f2947a..d8431525c1ce7670acb1f6bda46fdbbaaa6f8980 100644 (file)
@@ -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
index 2b356dca48f766c37eb645860c3d551dd0232df5..a8f678042f962b0d71ca7adc73a4318a5776fb4d 100644 (file)
@@ -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;
 };
 
index 542810eb427a2a1b3f8e4daaa953a7b63bf64f0b..0767b6ecd30593c5be9ae958ea68d35ea38fc8ca 100644 (file)
@@ -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));
index d3b39cab24ae487a32cd6b3cd3633798dcdfc91e..a79ce63273ebcee5118871a5e63ee43036e8885a 100644 (file)
@@ -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
index e2d7b5456a39912eaee93d74764e3b3d07960c2c..94e5be2c50fa4f20a736bedf7e13834ee93fbf87 100644 (file)
@@ -4,6 +4,7 @@
 #include <QtGui>
 #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
index 57c826758de613121b8ccf96edab7a95310f6724..b6d66dd9b499b133e67a6d4288d043c5d59a00d5 100644 (file)
@@ -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;