]> Shamusworld >> Repos - architektonas/blobdiff - src/widgets/qg_graphicview.cpp
In the middle of major refactoring...
[architektonas] / src / widgets / qg_graphicview.cpp
index b7d010ca178f4b2f4ebce28c3842c35a7e19ac20..9e68c5df957d12cf19b0cf2b31b4960bbbd5204b 100644 (file)
 
 #include "qg_graphicview.h"
 
-#include "rs_actionzoomin.h"
-#include "rs_actionzoompan.h"
-#include "rs_actionzoomscroll.h"
-#include "rs_actionmodifydelete.h"
-#include "rs_actionselectsingle.h"
-#include "rs_graphic.h"
+#include "qg_dialogfactory.h"
+#include "actiondefault.h"
+#include "actionzoomin.h"
+#include "actionzoompan.h"
+#include "actionzoomscroll.h"
+#include "actionmodifydelete.h"
+#include "actionselectsingle.h"
+#include "cadtoolbar.h"
+#include "rs_dialogfactory.h"
+#include "drawing.h"
+#include "graphicview.h"
+#include "rs_patternlist.h"
+#include "paintinterface.h"
+#include "rs_preview.h"
 #include "settings.h"
 #include "rs_system.h"
-#include "rs_patternlist.h"
-#include "cadtoolbar.h"
-#include "paintintf.h"
-#include "qg_dialogfactory.h"
 
 #define QG_SCROLLMARGIN 400
 
  * Constructor.
  */
 QG_GraphicView::QG_GraphicView(QWidget * parent, const char */*name*/, Qt::WindowFlags f):
-       QWidget(parent, f), RS_GraphicView()//, refCount(0)
+       QWidget(parent, f), GraphicView()//, refCount(0)
+{
+       RS_DEBUG->print("QG_GraphicView::QG_GraphicView(parent, name, flags)...");
+       CommonInitialization();
+}
+
+/**
+ * Constructor II.
+ */
+QG_GraphicView::QG_GraphicView(RS_Document * doc, QWidget * parent)
+{
+//     QG_GraphicView(parent, "graphicview");
+       CommonInitialization();
+
+       RS_DEBUG->print("QG_GraphicView::QG_GraphicView(doc, parent)...");
+       //document = doc;
+       RS_DEBUG->print("  Setting Container...");
+
+       if (doc)
+               setContainer(doc);
+
+       RS_DEBUG->print("  container set.");
+       setFactorX(4.0);
+       setFactorY(4.0);
+       setOffset(50, 50);
+       setBorders(10, 10, 10, 10);
+
+       if (doc)
+               setDefaultAction(new ActionDefault(*doc, *this));
+}
+
+void QG_GraphicView::CommonInitialization(void)
 {
        setBackground(background);
-       buffer = NULL;
+//meh  buffer = NULL;
        lastWidth = 0;
        lastHeight = 0;
-       //coordinateWidget = NULL;
-       //mouseWidget = NULL;
-       //optionWidget = NULL;
-       //cadToolBar = NULL;
-       //commandWidget = NULL;
 //hrm.
 painter = NULL;
 
-//    layout = new Q3GridLayout(this, 3, 2);
-//    layout->setColStretch(0, 1);
-//    layout->setColStretch(1, 0);
-//    layout->setColStretch(2, 0);
-//    layout->setRowStretch(0, 1);
-//    layout->setRowStretch(1, 0);
-       layout = new QGridLayout(this);
+       RS_DEBUG->print("--> Setting up layout...");
+       QGridLayout * layout = new QGridLayout(this);
        layout->setColumnStretch(0, 1);
        layout->setColumnStretch(1, 0);
        layout->setColumnStretch(2, 0);
@@ -68,57 +93,52 @@ Alignment is specified by alignment, which is a bitwise OR of Qt::AlignmentFlags
 
 A non-zero alignment indicates that the widget should not grow to fill the available space but should be sized according to sizeHint().
 */
-       hScrollBar = new QG_ScrollBar(Qt::Horizontal, this);
+       RS_DEBUG->print("--> Creating hScrollBar...");
+//     hScrollBar = new QG_ScrollBar(Qt::Horizontal, this);
+       hScrollBar = new QScrollBar(Qt::Horizontal, this);
 //    hScrollBar->setLineStep(50);
        hScrollBar->setSingleStep(50);
 //    layout->addMultiCellWidget(hScrollBar, 1, 1, 0, 0);
        layout->addWidget(hScrollBar, 1, 0);
 //    layout->addRowSpacing(1, hScrollBar->sizeHint().height());
        layout->addItem(new QSpacerItem(0, hScrollBar->sizeHint().height()), 1, 0);
-       connect(hScrollBar, SIGNAL(valueChanged(int)), this, SLOT(slotHScrolled(int)));
 
-       vScrollBar = new QG_ScrollBar(Qt::Vertical, this);
+       RS_DEBUG->print("--> Creating vScrollBar...");
+//     vScrollBar = new QG_ScrollBar(Qt::Vertical, this);
+       vScrollBar = new QScrollBar(Qt::Vertical, this);
 //    vScrollBar->setLineStep(50);
        vScrollBar->setSingleStep(50);
 //    layout->addMultiCellWidget(vScrollBar, 0, 0, 2, 2);
        layout->addWidget(vScrollBar, 0, 2);
 //    layout->addColSpacing(2, vScrollBar->sizeHint().width());
        layout->addItem(new QSpacerItem(vScrollBar->sizeHint().width(), 0), 0, 2);
+
+       connect(hScrollBar, SIGNAL(valueChanged(int)), this, SLOT(slotHScrolled(int)));
        connect(vScrollBar, SIGNAL(valueChanged(int)), this, SLOT(slotVScrolled(int)));
 
 #ifndef __APPLE__
        // Mouse Cursors:
        QBitmap bmp;
-//     QPixmap cur1(cur_cad_bmp_xpm);
-//     bmp = QPixmap(cur_cad_mask_xpm);
        QPixmap cur1(":/res/cur_cad_bmp.xpm");
        bmp = QPixmap(":/res/cur_cad_mask.xpm");
        cur1.setMask(bmp);
        curCad = new QCursor(cur1, 15, 15);
 
-//     QPixmap cur2(cur_glass_bmp_xpm);
-//     bmp = QPixmap(cur_glass_mask_xpm);
        QPixmap cur2(":/res/cur_glass_bmp.xpm");
        bmp = QPixmap(":/res/cur_glass_mask.xpm");
        cur2.setMask(bmp);
        curMagnifier = new QCursor(cur2, 12, 12);
 
-//     QPixmap cur3(cur_del_bmp_xpm);
-//     bmp = QPixmap(cur_del_mask_xpm);
        QPixmap cur3(":/res/cur_del_bmp.xpm");
        bmp = QPixmap(":/res/cur_del_mask.xpm");
        cur3.setMask(bmp);
        curDel = new QCursor(cur3, 15, 15);
 
-//     QPixmap cur4(cur_select_bmp_xpm);
-//     bmp = QPixmap(cur_select_mask_xpm);
        QPixmap cur4(":/res/cur_select_bmp.xpm");
        bmp = QPixmap(":/res/cur_select_mask.xpm");
        cur4.setMask(bmp);
        curSelect = new QCursor(cur4, 15, 15);
 
-//     QPixmap cur5(cur_hand_bmp_xpm);
-//     bmp = QPixmap(cur_hand_mask_xpm);
        QPixmap cur5(":/res/cur_hand_bmp.xpm");
        bmp = QPixmap(":/res/cur_hand_mask.xpm");
        cur5.setMask(bmp);
@@ -138,6 +158,7 @@ A non-zero alignment indicates that the widget should not grow to fill the avail
        //w->setEraseColor(QColor(255,0,0));
        gridStatus = new QLabel("-", this);
        gridStatus->setAlignment(Qt::AlignRight);
+//     gridStatus->setAutoFillBackground(true);
 //    layout->addMultiCellWidget(gridStatus, 1, 1, 1, 2);
        layout->addWidget(gridStatus, 1, 1, 1, 2);
 //    layout->addColSpacing(1, 50);
@@ -159,18 +180,14 @@ A non-zero alignment indicates that the widget should not grow to fill the avail
  */
 QG_GraphicView::~QG_GraphicView()
 {
-       if (painter != NULL)
-       {
-//Not sure about this...
-//             ((RS_PainterQt *)painter)->end();
+       if (painter)
                delete painter;
-       }
 
-       if (buffer != NULL)
-       {
-               delete buffer;
-               buffer = NULL;
-       }
+//meh  if (buffer)
+//     {
+//             delete buffer;
+//             buffer = NULL;
+//     }
 
        cleanUp();
 }
@@ -191,110 +208,12 @@ int QG_GraphicView::getHeight()
        return height() - hScrollBar->sizeHint().height();
 }
 
-/**
- * Creates a new painter for the buffer of this widget and returns a
- * pointer to it. The class variable 'painter' also
- * points to that object.
- */
-//'painter' is NOT a class variable!
-//RS_Painter * QG_GraphicView::createPainter()
-PaintInterface * QG_GraphicView::createPainter()
-{
-#if 1
-       return NULL;
-#else
-//RS_DEBUG->print(RS_Debug::D_CRITICAL, "QG_GraphicView::createPainter called...");
-       RS_DEBUG->print("QG_GraphicView::createPainter begin");
-
-       if (lastWidth != getWidth() || lastHeight != getHeight())
-       {
-               destroyPainter();
-
-               if (buffer != NULL)
-               {
-                       delete buffer;
-                       buffer = NULL;
-               }
-
-               lastWidth = getWidth();
-               lastHeight = getHeight();
-       }
-
-       if (buffer == NULL)
-       {
-               //RS_DEBUG->timestamp();
-               RS_DEBUG->print("creating buffer: %d,%d", getWidth(), getHeight());
-               buffer = new QPixmap(getWidth(), getHeight());
-               RS_DEBUG->print("ok");
-       }
-
-       if (painter == NULL)
-       {
-               painter = new RS_PainterQt(buffer);
-               painter->setDrawingMode(drawingMode);
-               ((RS_PainterQt *)painter)->setBackgroundMode(Qt::OpaqueMode);
-               ((RS_PainterQt *)painter)->setBackgroundColor(background);
-               ((RS_PainterQt *)painter)->eraseRect(0, 0, getWidth(), getHeight());
-
-               //RS_DEBUG->timestamp();
-       }
-
-       RS_DEBUG->print("QG_GraphicView::createPainter end");
-
-       return painter;
-#endif
-}
-
-/**
- * Creates a new painter for this widget and returns a
- * pointer to it. The class variable 'painter' also
- * automatically points to that object.
- */
-//RS_Painter * QG_GraphicView::createDirectPainter()
-PaintInterface * QG_GraphicView::createDirectPainter()
-{
-#if 1
-       return NULL;
-#else
-//RS_DEBUG->print(RS_Debug::D_CRITICAL, "QG_GraphicView::createDirectPainter called...");
-       RS_DEBUG->print("QG_GraphicView::createDirectPainter begin");
-
-       destroyPainter();
-       painter = new RS_PainterQt(this);
-       painter->setDrawingMode(drawingMode);
-
-       RS_DEBUG->print("QG_GraphicView::createDirectPainter end");
-
-       return painter;
-#endif
-}
-
-/**
- * Deletes the painter.
- */
-void QG_GraphicView::destroyPainter()
-{
-#if 1
-       return;
-#else
-    RS_DEBUG->print("QG_GraphicView::destroyPainter begin");
-
-    if (painter != NULL)
-       {
-        delete painter;
-        painter = NULL;
-    }
-
-    RS_DEBUG->print("QG_GraphicView::destroyPainter end");
-#endif
-}
-
 /**
  * Changes the current background color of this view.
  */
 void QG_GraphicView::setBackground(const RS_Color & bg)
 {
-       RS_GraphicView::setBackground(bg);
+       GraphicView::setBackground(bg);
 
 //     setBackgroundColor(bg);
        QPalette palette;
@@ -449,6 +368,13 @@ void QG_GraphicView::resizeEvent(QResizeEvent * /*e*/)
        RS_DEBUG->print("QG_GraphicView::resizeEvent end");
 }
 
+/*
+This is retarded. There is absolutely no reason to have this shit in here.
+This could be easily called from whoever calls this crap.
+
+And so... We remove it.
+*/
+#if 0
 // Next three methods from RS_LayerListListener Interface:
 void QG_GraphicView::layerEdited(RS_Layer *)
 {
@@ -464,6 +390,7 @@ void QG_GraphicView::layerToggled(RS_Layer *)
 {
        redraw();
 }
+#endif
 
 void QG_GraphicView::emulateMouseMoveEvent()
 {
@@ -475,21 +402,21 @@ void QG_GraphicView::mousePressEvent(QMouseEvent * e)
 {
        // pan zoom with middle mouse button
        if (e->button() == Qt::MidButton /*|| (e->state()==Qt::LeftButton|Qt::AltButton)*/)
-               setCurrentAction(new RS_ActionZoomPan(*container, *this));
+               setCurrentAction(new ActionZoomPan(*container, *this));
 
-       RS_GraphicView::mousePressEvent(e);
+       GraphicView::mousePressEvent(e);
        QWidget::mousePressEvent(e);
 }
 
 void QG_GraphicView::mouseReleaseEvent(QMouseEvent * e)
 {
        RS_DEBUG->print("QG_GraphicView::mouseReleaseEvent");
-       RS_GraphicView::mouseReleaseEvent(e);
+       GraphicView::mouseReleaseEvent(e);
        //QWidget::mouseReleaseEvent(e);
 
        if (!e->isAccepted())
        {
-               if (QG_DIALOGFACTORY != NULL && QG_DIALOGFACTORY->getCadToolBar() != NULL)
+               if (QG_DIALOGFACTORY && QG_DIALOGFACTORY->getCadToolBar())
                {
                        RS_DEBUG->print("QG_GraphicView::mouseReleaseEvent: fwd to cadtoolbar");
                        QG_DIALOGFACTORY->getCadToolBar()->mouseReleaseEvent(e);
@@ -501,20 +428,8 @@ void QG_GraphicView::mouseReleaseEvent(QMouseEvent * e)
 
 void QG_GraphicView::mouseMoveEvent(QMouseEvent * e)
 {
-       //RS_DEBUG->print("QG_GraphicView::mouseMoveEvent begin");
-       //QMouseEvent rsm = QG_Qt2Rs::mouseEvent(e);
-
-       RS_GraphicView::mouseMoveEvent(e);
+       GraphicView::mouseMoveEvent(e);
        QWidget::mouseMoveEvent(e);
-
-//What kind of cacamamie crap is this???
-//#ifdef Q_OS_WIN32
-//     // make sure that we can still use hotkeys and the mouse wheel
-//     if (parent() != NULL)
-//             ((QWidget *)parent())->setFocus();
-//#endif
-
-       //RS_DEBUG->print("QG_GraphicView::mouseMoveEvent end");
 }
 
 /**
@@ -532,7 +447,7 @@ void QG_GraphicView::tabletEvent(QTabletEvent * e)
                        {
                                if (container != NULL)
                                {
-                                       RS_ActionSelectSingle * a = new RS_ActionSelectSingle(*container, *this);
+                                       ActionSelectSingle * a = new ActionSelectSingle(*container, *this);
                                        setCurrentAction(a);
 #warning "!!! !!!"
 //                                     QMouseEvent ev(QEvent::MouseButtonRelease, e->pos(), Qt::LeftButton, Qt::LeftButton);
@@ -540,7 +455,7 @@ void QG_GraphicView::tabletEvent(QTabletEvent * e)
                                        a->finish();
 
                                        if (container->countSelected() > 0)
-                                               setCurrentAction(new RS_ActionModifyDelete(*container, *this));
+                                               setCurrentAction(new ActionModifyDelete(*container, *this));
                                }
                        }
                        break;
@@ -595,13 +510,13 @@ void QG_GraphicView::tabletEvent(QTabletEvent * e)
 
 void QG_GraphicView::leaveEvent(QEvent * e)
 {
-       RS_GraphicView::mouseLeaveEvent();
+       GraphicView::mouseLeaveEvent();
        QWidget::leaveEvent(e);
 }
 
 void QG_GraphicView::enterEvent(QEvent * e)
 {
-       RS_GraphicView::mouseEnterEvent();
+       GraphicView::mouseEnterEvent();
        QWidget::enterEvent(e);
 }
 
@@ -613,7 +528,7 @@ void QG_GraphicView::focusOutEvent(QFocusEvent * e)
 void QG_GraphicView::focusInEvent(QFocusEvent * e)
 {
 //printf("-->QG_GraphicView::focusInEvent(): Start. this %s focus...\n", (hasFocus() ? "has" : "DOES NOT HAVE"));
-       RS_GraphicView::mouseEnterEvent();
+       GraphicView::mouseEnterEvent();
        QWidget::focusInEvent(e);
 //printf("-->QG_GraphicView::focusInEvent(): End.   this %s focus...\n", (hasFocus() ? "has" : "DOES NOT HAVE"));
 }
@@ -628,11 +543,10 @@ void QG_GraphicView::wheelEvent(QWheelEvent * e)
 
        //printf("state: %d\n", e->state());
        //printf("ctrl: %d\n", Qt::ControlButton);
-Qt::KeyboardModifiers keyState = QApplication::keyboardModifiers();
-
-       if (container == NULL)
+       if (!container)
                return;
 
+       Qt::KeyboardModifiers keyState = QApplication::keyboardModifiers();
        Vector mouse = toGraph(Vector(e->x(), e->y()));
 
        bool scroll = false;
@@ -662,15 +576,15 @@ Qt::KeyboardModifiers keyState = QApplication::keyboardModifiers();
        }
 
        if (scroll)
-               setCurrentAction(new RS_ActionZoomScroll(direction, *container, *this));
+               setCurrentAction(new ActionZoomScroll(direction, *container, *this));
        // zoom in / out:
 //     else if (e->state() == 0)
        else if (keyState == 0)
        {
                if (e->delta() > 0)
-                       setCurrentAction(new RS_ActionZoomIn(*container, *this, RS2::In, RS2::Both, mouse));
+                       setCurrentAction(new ActionZoomIn(*container, *this, RS2::In, RS2::Both, mouse));
                else
-                       setCurrentAction(new RS_ActionZoomIn(*container, *this, RS2::Out, RS2::Both, mouse));
+                       setCurrentAction(new ActionZoomIn(*container, *this, RS2::Out, RS2::Both, mouse));
        }
 
        e->accept();
@@ -678,7 +592,7 @@ Qt::KeyboardModifiers keyState = QApplication::keyboardModifiers();
 
 void QG_GraphicView::keyPressEvent(QKeyEvent * e)
 {
-       if (container == NULL)
+       if (!container)
                return;
 
        bool scroll = false;
@@ -708,14 +622,14 @@ void QG_GraphicView::keyPressEvent(QKeyEvent * e)
        }
 
        if (scroll)
-               setCurrentAction(new RS_ActionZoomScroll(direction, *container, *this));
+               setCurrentAction(new ActionZoomScroll(direction, *container, *this));
 
-       RS_GraphicView::keyPressEvent(e);
+       GraphicView::keyPressEvent(e);
 }
 
 void QG_GraphicView::keyReleaseEvent(QKeyEvent * e)
 {
-       RS_GraphicView::keyReleaseEvent(e);
+       GraphicView::keyReleaseEvent(e);
 }
 
 /**
@@ -733,7 +647,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();
@@ -744,11 +658,11 @@ void QG_GraphicView::adjustOffsetControls()
        Vector max = container->getMax();
 
        // no drawing yet - still allow to scroll
-       if (max.x < min.x+1.0e-6 || max.y < min.y+1.0e-6 ||
-               max.x > RS_MAXDOUBLE || max.x < RS_MINDOUBLE ||
-               min.x > RS_MAXDOUBLE || min.x < RS_MINDOUBLE ||
-               max.y > RS_MAXDOUBLE || max.y < RS_MINDOUBLE ||
-               min.y > RS_MAXDOUBLE || min.y < RS_MINDOUBLE)
+       if (max.x < min.x + 1.0e-6 || max.y < min.y + 1.0e-6
+               || max.x > RS_MAXDOUBLE || max.x < RS_MINDOUBLE
+               || min.x > RS_MAXDOUBLE || min.x < RS_MINDOUBLE
+               || max.y > RS_MAXDOUBLE || max.y < RS_MINDOUBLE
+               || min.y > RS_MAXDOUBLE || min.y < RS_MINDOUBLE)
        {
                min = Vector(-10, -10);
                max = Vector(100, 100);
@@ -855,6 +769,11 @@ void QG_GraphicView::slotVScrolled(int value)
  * Handles paint events by redrawing the graphic in this view.
  * usually that's very fast since we only paint the buffer we
  * have from the last call..
+ *
+ * This is not true anymore--even if it was true in the first place, which
+ * seems doubtful to me. Everything is redrawn every time; we need to see if
+ * relying on Qt do to the clipping is wise or not... Also, we need to clarify
+ * all rendering paths since they are not all logical or consistent.
  */
 void QG_GraphicView::paintEvent(QPaintEvent *)
 {
@@ -890,137 +809,45 @@ of VectorWorks & etc. as well...
 // 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
-
-#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 (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;
-       }
-#endif
 
-       if (snapperDraw)
-//     if (false)
+       // 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())
+#if 0
        {
-               snapperDraw = false;
+               painter->setPen(RS_Pen(RS_Color(60, 255, 80), RS2::Width00, RS2::SolidLine));
+               painter->setOffset(preview.Offset());
 
-               if (snapCoord1.valid)
+               // 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))
                {
-                       // 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));
+                       drawEntityPlain(e);
                }
-#endif
+
+               painter->setOffset(Vector(0, 0));
        }
+#else
+               preview.Draw(this, painter);
+#endif
 
        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 RS_Graphic* gr = new RS_Graphic();
-
-       RS_DEBUG->print("QG_GraphicView::previewUrl");
-
-       if (container != NULL && container->rtti() == RS2::EntityGraphic)
-       {
-               ((RS_Graphic *)container)->open(u.path(), RS2::FormatUnknown);
-               zoomAuto();
-       }
-       //setContainer(gr);
-
-       RS_DEBUG->print("QG_GraphicView::previewUrl: OK");
-}
-#endif