// 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
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();
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
}
{
if (e->button() == Qt::LeftButton)
{
- Vector ce(snapPoint(e));
+ Vector ce(graphicView->snapper.snapPoint(e));
coordinateEvent(&ce);
}
else if (e->button() == Qt::RightButton)
graphicView->preview.SetVisible(false);
}
-#if 0
- deletePreview(); // XOR off of screen
- clearPreview(); // Remove entities from the container
-#else
-#endif
init(getStatus() - 1);
}
else
RS_DIALOGFACTORY->updateMouseWidget(tr("Specify next point"), tr("Back"));
}
- break;
+ break;
default:
RS_DIALOGFACTORY->updateMouseWidget("", "");
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."));
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