]> Shamusworld >> Repos - architektonas/commitdiff
Last checkin before major refactor...
authorShamus Hammons <jlhamm@acm.org>
Mon, 12 Jul 2010 02:04:56 +0000 (02:04 +0000)
committerShamus Hammons <jlhamm@acm.org>
Mon, 12 Jul 2010 02:04:56 +0000 (02:04 +0000)
src/actions/rs_actiondrawline.cpp
src/base/rs_previewactioninterface.cpp
src/widgets/qg_graphicview.cpp

index d911e779c02016f7258631b1c4d6a58075bbdc6b..d3fad7284b9939c27f3deda7411751eb78d12b24 100644 (file)
@@ -1,5 +1,6 @@
 // rs_actiondrawline.cpp
 //
+// Part of the Architektonas Project
 // Originally part of QCad Community Edition by Andrew Mustun
 // Extensively rewritten and refactored by James L. Hammons
 // (C) 2010 Underground Software
@@ -55,19 +56,15 @@ void RS_ActionDrawLine::reset()
 void RS_ActionDrawLine::init(int status)
 {
        RS_DEBUG->print("RS_ActionDrawLine::init");
-       RS_PreviewActionInterface::init(status);
+//     RS_PreviewActionInterface::init(status);
+       RS_ActionInterface::init(status);
        reset();
        RS_DEBUG->print("RS_ActionDrawLine::init: OK");
 }
 
 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();
@@ -104,23 +101,25 @@ void RS_ActionDrawLine::mouseMoveEvent(QMouseEvent * e)
        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
-               clearPreview();                 // Remove entities from the container
-               preview->addEntity(new RS_Line(preview, RS_LineData(data.startpoint, mouse)));
-               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?
+#if 0
                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);
+#else
+               // We can assume there's only one line in there, can't we?
+               RS_Line * line = (RS_Line *)graphicView->preview.firstEntity(RS2::ResolveNone);
+
+               if (line)
+               {
+                       line->setEndpoint(mouse);
+               }
+               else
+               {
+                       line = new RS_Line(&(graphicView->preview), RS_LineData(data.startpoint, mouse));
+                       graphicView->preview.addEntity(line);
+               }
 #endif
        }
 
@@ -133,7 +132,7 @@ void RS_ActionDrawLine::mouseReleaseEvent(QMouseEvent * e)
 {
        if (e->button() == Qt::LeftButton)
        {
-               Vector ce(snapPoint(e));
+               Vector ce(graphicView->snapper.snapPoint(e));
                coordinateEvent(&ce);
        }
        else if (e->button() == Qt::RightButton)
@@ -144,11 +143,6 @@ void RS_ActionDrawLine::mouseReleaseEvent(QMouseEvent * e)
                        graphicView->preview.SetVisible(false);
                }
 
-#if 0
-               deletePreview();                // XOR off of screen
-               clearPreview();                 // Remove entities from the container
-#else
-#endif
                init(getStatus() - 1);
        }
 
@@ -289,7 +283,7 @@ void RS_ActionDrawLine::updateMouseButtonHints()
                else
                        RS_DIALOGFACTORY->updateMouseWidget(tr("Specify next point"), tr("Back"));
        }
-       break;
+               break;
 
        default:
                RS_DIALOGFACTORY->updateMouseWidget("", "");
@@ -345,13 +339,11 @@ void RS_ActionDrawLine::undo()
        if (history.count() > 1)
        {
                history.removeLast();
-//             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();
+               graphicView->preview.clear();
+               graphicView->redraw();
        }
        else
                RS_DIALOGFACTORY->commandMessage(tr("Cannot undo: Not enough entities defined yet."));
index d8431525c1ce7670acb1f6bda46fdbbaaa6f8980..e25a4e648d470eeeeaaebabe50ec709f0de3bf42 100644 (file)
@@ -30,8 +30,8 @@ RS_PreviewActionInterface::RS_PreviewActionInterface(const char * name,
 {
        RS_DEBUG->print("RS_PreviewActionInterface::RS_PreviewActionInterface: Setting up action with preview: \"%s\"", name);
 
-       // preview is linked to the container for getting access to
-       //   document settings / dictionary variables
+       // Preview is linked to the container for getting access to document
+       // settings / dictionary variables
        preview = new RS_Preview(&container);
        visible = false;
 
@@ -47,7 +47,6 @@ RS_PreviewActionInterface::~RS_PreviewActionInterface()
 void RS_PreviewActionInterface::init(int status)
 {
        RS_ActionInterface::init(status);
-       //deletePreview();
        clearPreview();
 }
 
@@ -62,7 +61,6 @@ void RS_PreviewActionInterface::suspend()
 {
        RS_ActionInterface::suspend();
        deletePreview();
-       //clearPreview();
 }
 
 void RS_PreviewActionInterface::resume()
index b6d66dd9b499b133e67a6d4288d043c5d59a00d5..3c825c780fae70271f1b72ada736d0f31619bac1 100644 (file)
@@ -816,147 +816,46 @@ have something back in portage. We can make it better, faster, stronger. ;-)
 
 If we can make the UI more like Inkscape we'll be in good shape. Plus elements
 of VectorWorks & etc. as well...
-
--------------------------------------------------------------------------------
-
-What's needed:
-
-- Draw the entities
-- Draw the preview (if any)
-- Draw the snapper (if any)
-
 */
 
 // Qt4 handles double buffering of screen writes now, so this needs
 // a rewrite.
 #warning "!!! Need to pass a valid QPainter to drawIt() !!!"
-#if 0
-       drawIt();
-
-//#warning "!!! Double buffering is out... !!!"
-// Seems most rendering is going through this path... Hrm.
-       if (buffer != NULL)
-       {
-               QPainter wPainter;
-               wPainter.begin(this);
-               wPainter.drawPixmap(0, 0, *buffer);
-               wPainter.end();
-       }
-#else
-//     refCount++;
-//if (refCount > 1)
-//{
-////   RS_DEBUG->print(RS_Debug::D_CRITICAL, "paintEvent seems to be called recursively: refCount=%u", refCount);
-//     printf("paintEvent seems to be called recursively: refCount=%u\n", refCount);
-//}
 
        QPainter pntr(this);
        pntr.setBackgroundMode(Qt::OpaqueMode);
-//     pntr.setBackgroundColor(background);
        pntr.setBackground(QBrush(background));
 
        painter = new PaintInterface(&pntr);
 
-#if 0
-       if (!painter)
-       {
-               painter = new RS_PainterQt(this);
-
-               //Nope, this didn't fix the problem...
-               //The problem is, unless we specifically tell Qt NOT to
-               //clear the window every time, it will...
-               //So...
-//             if (!previewMode)
-               {
-                       painter->setDrawingMode(drawingMode);
-                       ((RS_PainterQt *)painter)->setBackgroundMode(Qt::OpaqueMode);
-                       ((RS_PainterQt *)painter)->setBackgroundColor(background);
-//                     ((RS_PainterQt *)painter)->eraseRect(0, 0, getWidth(), getHeight());
-               }
-       }
-       else
-       {
-               printf("QG_GraphicView::paintEvent: painter is NOT NULL!\n");
-       }
-#endif
-
 //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);
-//needed anymore?              painter->setXORMode();
-               painter->setOffset(previewOffset);
-               drawEntity(previewEntity);//meh -> , 1.0, false);
-               painter->setOffset(Vector(0, 0));
-               // We'll set previewMode to false here, just because we can
-               previewMode = false;
-       }
-#else
+
+       // Draw the snapper first, we want to be able to see the preview on top of
+       // this...
+       if (snapper.Visible())
+               snapper.Draw(this, painter);
+
        if (preview.Visible())
        {
-               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);
+
+               // We have to traverse the container ourselves, because RS_Container::draw()
+               // uses drawEntity() instead of drawEntityPlain()...
                for(RS_Entity * e=preview.firstEntity(RS2::ResolveNone); e!=NULL;
                        e = preview.nextEntity(RS2::ResolveNone))
                {
-//                     e->setPen(RS_Pen(RS_Color(60, 255, 80), RS2::Width00, RS2::SolidLine));
                        drawEntityPlain(e);
                }
-               //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;
 
-//     refCount--;
-#endif
-
        RS_DEBUG->print("QG_GraphicView::paintEvent end");
 }
-
-#if 0 //JLH
-/**
- * Previews the given url for the file open dialog.
- */
-void QG_GraphicView::previewUrl(const Q3Url & u)
-{
-       //static Drawing* gr = new Drawing();
-
-       RS_DEBUG->print("QG_GraphicView::previewUrl");
-
-       if (container != NULL && container->rtti() == RS2::EntityGraphic)
-       {
-               ((Drawing *)container)->open(u.path(), RS2::FormatUnknown);
-               zoomAuto();
-       }
-       //setContainer(gr);
-
-       RS_DEBUG->print("QG_GraphicView::previewUrl: OK");
-}
-#endif