3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // (C) 2010 Underground Software
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 05/10/2010 Added this text. :-)
15 #include "qg_graphicview.h"
17 #include "rs_actionzoomin.h"
18 #include "rs_actionzoompan.h"
19 #include "rs_actionzoomscroll.h"
20 #include "rs_actionmodifydelete.h"
21 #include "rs_actionselectsingle.h"
22 #include "rs_dialogfactory.h"
23 #include "rs_graphicview.h"
24 #include "rs_preview.h"
27 #include "rs_system.h"
28 #include "rs_patternlist.h"
29 #include "cadtoolbar.h"
30 #include "paintintf.h"
31 #include "qg_dialogfactory.h"
33 #define QG_SCROLLMARGIN 400
38 QG_GraphicView::QG_GraphicView(QWidget * parent, const char */*name*/, Qt::WindowFlags f):
39 QWidget(parent, f), RS_GraphicView()//, refCount(0)
41 setBackground(background);
45 //coordinateWidget = NULL;
47 //optionWidget = NULL;
49 //commandWidget = NULL;
53 // layout = new Q3GridLayout(this, 3, 2);
54 // layout->setColStretch(0, 1);
55 // layout->setColStretch(1, 0);
56 // layout->setColStretch(2, 0);
57 // layout->setRowStretch(0, 1);
58 // layout->setRowStretch(1, 0);
59 layout = new QGridLayout(this);
60 layout->setColumnStretch(0, 1);
61 layout->setColumnStretch(1, 0);
62 layout->setColumnStretch(2, 0);
63 layout->setRowStretch(0, 1);
64 layout->setRowStretch(1, 0);
67 void QGridLayout::addMultiCellWidget ( QWidget * w, int fromRow, int toRow, int fromCol, int toCol, int alignment = 0 )
68 Adds the widget w to the cell grid, spanning multiple rows/columns. The cell will span from fromRow, fromCol to toRow, toCol.
70 Alignment is specified by alignment, which is a bitwise OR of Qt::AlignmentFlags values. The default alignment is 0, which means that the widget fills the entire cell.
72 A non-zero alignment indicates that the widget should not grow to fill the available space but should be sized according to sizeHint().
74 hScrollBar = new QG_ScrollBar(Qt::Horizontal, this);
75 // hScrollBar->setLineStep(50);
76 hScrollBar->setSingleStep(50);
77 // layout->addMultiCellWidget(hScrollBar, 1, 1, 0, 0);
78 layout->addWidget(hScrollBar, 1, 0);
79 // layout->addRowSpacing(1, hScrollBar->sizeHint().height());
80 layout->addItem(new QSpacerItem(0, hScrollBar->sizeHint().height()), 1, 0);
81 connect(hScrollBar, SIGNAL(valueChanged(int)), this, SLOT(slotHScrolled(int)));
83 vScrollBar = new QG_ScrollBar(Qt::Vertical, this);
84 // vScrollBar->setLineStep(50);
85 vScrollBar->setSingleStep(50);
86 // layout->addMultiCellWidget(vScrollBar, 0, 0, 2, 2);
87 layout->addWidget(vScrollBar, 0, 2);
88 // layout->addColSpacing(2, vScrollBar->sizeHint().width());
89 layout->addItem(new QSpacerItem(vScrollBar->sizeHint().width(), 0), 0, 2);
90 connect(vScrollBar, SIGNAL(valueChanged(int)), this, SLOT(slotVScrolled(int)));
95 // QPixmap cur1(cur_cad_bmp_xpm);
96 // bmp = QPixmap(cur_cad_mask_xpm);
97 QPixmap cur1(":/res/cur_cad_bmp.xpm");
98 bmp = QPixmap(":/res/cur_cad_mask.xpm");
100 curCad = new QCursor(cur1, 15, 15);
102 // QPixmap cur2(cur_glass_bmp_xpm);
103 // bmp = QPixmap(cur_glass_mask_xpm);
104 QPixmap cur2(":/res/cur_glass_bmp.xpm");
105 bmp = QPixmap(":/res/cur_glass_mask.xpm");
107 curMagnifier = new QCursor(cur2, 12, 12);
109 // QPixmap cur3(cur_del_bmp_xpm);
110 // bmp = QPixmap(cur_del_mask_xpm);
111 QPixmap cur3(":/res/cur_del_bmp.xpm");
112 bmp = QPixmap(":/res/cur_del_mask.xpm");
114 curDel = new QCursor(cur3, 15, 15);
116 // QPixmap cur4(cur_select_bmp_xpm);
117 // bmp = QPixmap(cur_select_mask_xpm);
118 QPixmap cur4(":/res/cur_select_bmp.xpm");
119 bmp = QPixmap(":/res/cur_select_mask.xpm");
121 curSelect = new QCursor(cur4, 15, 15);
123 // QPixmap cur5(cur_hand_bmp_xpm);
124 // bmp = QPixmap(cur_hand_mask_xpm);
125 QPixmap cur5(":/res/cur_hand_bmp.xpm");
126 bmp = QPixmap(":/res/cur_hand_mask.xpm");
128 curHand = new QCursor(cur5, 15, 15);
130 // No individual cursors for the Mac
138 // Dummy widgets for scrollbar corners:
139 //layout->addWidget(new QWidget(this), 1, 1);
140 //QWidget* w = new QWidget(this);
141 //w->setEraseColor(QColor(255,0,0));
142 gridStatus = new QLabel("-", this);
143 gridStatus->setAlignment(Qt::AlignRight);
144 // layout->addMultiCellWidget(gridStatus, 1, 1, 1, 2);
145 layout->addWidget(gridStatus, 1, 1, 1, 2);
146 // layout->addColSpacing(1, 50);
147 layout->addItem(new QSpacerItem(50, 0), 0, 1);
149 setMouseTracking(true);
150 // flickering under win:
151 //setFocusPolicy(WheelFocus);
153 #warning "QG_GraphicView constructor is setting Qt::NoFocus!!!"
154 // A-HAH! THIS IS THE PROBLEM!!!
155 // setFocusPolicy(Qt::NoFocus);
157 // setFocusPolicy(Qt::StrongFocus);
163 QG_GraphicView::~QG_GraphicView()
167 //Not sure about this...
168 // ((RS_PainterQt *)painter)->end();
182 * @return width of widget.
184 int QG_GraphicView::getWidth()
186 return width() - vScrollBar->sizeHint().width();
190 * @return height of widget.
192 int QG_GraphicView::getHeight()
194 return height() - hScrollBar->sizeHint().height();
198 * Creates a new painter for the buffer of this widget and returns a
199 * pointer to it. The class variable 'painter' also
200 * points to that object.
202 //'painter' is NOT a class variable!
203 //RS_Painter * QG_GraphicView::createPainter()
204 PaintInterface * QG_GraphicView::createPainter()
209 //RS_DEBUG->print(RS_Debug::D_CRITICAL, "QG_GraphicView::createPainter called...");
210 RS_DEBUG->print("QG_GraphicView::createPainter begin");
212 if (lastWidth != getWidth() || lastHeight != getHeight())
222 lastWidth = getWidth();
223 lastHeight = getHeight();
228 //RS_DEBUG->timestamp();
229 RS_DEBUG->print("creating buffer: %d,%d", getWidth(), getHeight());
230 buffer = new QPixmap(getWidth(), getHeight());
231 RS_DEBUG->print("ok");
236 painter = new RS_PainterQt(buffer);
237 painter->setDrawingMode(drawingMode);
238 ((RS_PainterQt *)painter)->setBackgroundMode(Qt::OpaqueMode);
239 ((RS_PainterQt *)painter)->setBackgroundColor(background);
240 ((RS_PainterQt *)painter)->eraseRect(0, 0, getWidth(), getHeight());
242 //RS_DEBUG->timestamp();
245 RS_DEBUG->print("QG_GraphicView::createPainter end");
252 * Creates a new painter for this widget and returns a
253 * pointer to it. The class variable 'painter' also
254 * automatically points to that object.
256 //RS_Painter * QG_GraphicView::createDirectPainter()
257 PaintInterface * QG_GraphicView::createDirectPainter()
262 //RS_DEBUG->print(RS_Debug::D_CRITICAL, "QG_GraphicView::createDirectPainter called...");
263 RS_DEBUG->print("QG_GraphicView::createDirectPainter begin");
266 painter = new RS_PainterQt(this);
267 painter->setDrawingMode(drawingMode);
269 RS_DEBUG->print("QG_GraphicView::createDirectPainter end");
276 * Deletes the painter.
278 void QG_GraphicView::destroyPainter()
283 RS_DEBUG->print("QG_GraphicView::destroyPainter begin");
291 RS_DEBUG->print("QG_GraphicView::destroyPainter end");
296 * Changes the current background color of this view.
298 void QG_GraphicView::setBackground(const RS_Color & bg)
300 RS_GraphicView::setBackground(bg);
302 // setBackgroundColor(bg);
304 palette.setColor(backgroundRole(), bg);
309 * Sets the mouse cursor to the given type.
311 void QG_GraphicView::setMouseCursor(RS2::CursorType c)
316 case RS2::ArrowCursor:
317 setCursor(Qt::ArrowCursor);
319 case RS2::UpArrowCursor:
320 setCursor(Qt::UpArrowCursor);
322 case RS2::CrossCursor:
323 setCursor(Qt::CrossCursor);
325 case RS2::WaitCursor:
326 setCursor(Qt::WaitCursor);
328 case RS2::IbeamCursor:
329 setCursor(Qt::IBeamCursor);
331 case RS2::SizeVerCursor:
332 setCursor(Qt::SizeVerCursor);
334 case RS2::SizeHorCursor:
335 setCursor(Qt::SizeHorCursor);
337 case RS2::SizeBDiagCursor:
338 setCursor(Qt::SizeBDiagCursor);
340 case RS2::SizeFDiagCursor:
341 setCursor(Qt::SizeFDiagCursor);
343 case RS2::SizeAllCursor:
344 setCursor(Qt::SizeAllCursor);
346 case RS2::BlankCursor:
347 setCursor(Qt::BlankCursor);
349 case RS2::SplitVCursor:
350 setCursor(Qt::SplitVCursor);
352 case RS2::SplitHCursor:
353 setCursor(Qt::SplitHCursor);
355 case RS2::PointingHandCursor:
356 setCursor(Qt::PointingHandCursor);
358 case RS2::ForbiddenCursor:
359 setCursor(Qt::ForbiddenCursor);
361 case RS2::WhatsThisCursor:
362 setCursor(Qt::WhatsThisCursor);
372 case RS2::SelectCursor:
373 setCursor(*curSelect);
375 case RS2::MagnifierCursor:
376 setCursor(*curMagnifier);
378 case RS2::MovingHandCursor:
382 // Reduced cursor selection for the Mac:
384 setCursor(Qt::CrossCursor);
387 setCursor(Qt::CrossCursor);
389 case RS2::SelectCursor:
390 setCursor(Qt::CrossCursor);
392 case RS2::MagnifierCursor:
393 setCursor(Qt::CrossCursor);
395 case RS2::MovingHandCursor:
396 setCursor(Qt::PointingHandCursor);
403 * Sets the text for the grid status widget in the left bottom corner.
405 void QG_GraphicView::updateGridStatusWidget(const QString & text)
407 gridStatus->setText(text);
411 * Redraws the widget.
413 void QG_GraphicView::redraw()
415 RS_DEBUG->print("QG_GraphicView::redraw begin 1");
417 if (simulationRunning)
420 //Also, this stuff is properly taken care of by the Qt toolkit--
421 //so we don't have to be concerned with shit like this as long
422 //as we use update() instead of repaint()
424 static bool running = false;
429 RS_DEBUG->print("QG_GraphicView::redraw begin 2");
432 This is the only place in the entire codebase that a proper update is
435 if (isUpdateEnabled())
439 RS_DEBUG->print("QG_GraphicView::redraw end 2");
443 RS_DEBUG->print("QG_GraphicView::redraw end 1");
446 void QG_GraphicView::resizeEvent(QResizeEvent * /*e*/)
448 RS_DEBUG->print("QG_GraphicView::resizeEvent begin");
449 adjustOffsetControls();
450 adjustZoomControls();
452 RS_DEBUG->print("QG_GraphicView::resizeEvent end");
455 // Next three methods from RS_LayerListListener Interface:
456 void QG_GraphicView::layerEdited(RS_Layer *)
461 void QG_GraphicView::layerRemoved(RS_Layer *)
466 void QG_GraphicView::layerToggled(RS_Layer *)
471 void QG_GraphicView::emulateMouseMoveEvent()
473 // QMouseEvent e(QEvent::MouseMove, QPoint(mx, my), Qt::NoButton, Qt::NoButton);
474 //mouseMoveEvent(&e);
477 void QG_GraphicView::mousePressEvent(QMouseEvent * e)
479 // pan zoom with middle mouse button
480 if (e->button() == Qt::MidButton /*|| (e->state()==Qt::LeftButton|Qt::AltButton)*/)
481 setCurrentAction(new RS_ActionZoomPan(*container, *this));
483 RS_GraphicView::mousePressEvent(e);
484 QWidget::mousePressEvent(e);
487 void QG_GraphicView::mouseReleaseEvent(QMouseEvent * e)
489 RS_DEBUG->print("QG_GraphicView::mouseReleaseEvent");
490 RS_GraphicView::mouseReleaseEvent(e);
491 //QWidget::mouseReleaseEvent(e);
493 if (!e->isAccepted())
495 if (QG_DIALOGFACTORY != NULL && QG_DIALOGFACTORY->getCadToolBar() != NULL)
497 RS_DEBUG->print("QG_GraphicView::mouseReleaseEvent: fwd to cadtoolbar");
498 QG_DIALOGFACTORY->getCadToolBar()->mouseReleaseEvent(e);
502 RS_DEBUG->print("QG_GraphicView::mouseReleaseEvent: OK");
505 void QG_GraphicView::mouseMoveEvent(QMouseEvent * e)
507 //RS_DEBUG->print("QG_GraphicView::mouseMoveEvent begin");
508 //QMouseEvent rsm = QG_Qt2Rs::mouseEvent(e);
510 RS_GraphicView::mouseMoveEvent(e);
511 QWidget::mouseMoveEvent(e);
513 //What kind of cacamamie crap is this???
515 // // make sure that we can still use hotkeys and the mouse wheel
516 // if (parent() != NULL)
517 // ((QWidget *)parent())->setFocus();
520 //RS_DEBUG->print("QG_GraphicView::mouseMoveEvent end");
524 * support for the wacom graphic tablet.
526 void QG_GraphicView::tabletEvent(QTabletEvent * e)
529 if (testAttribute(Qt::WA_UnderMouse))
533 case QTabletEvent::Eraser:
534 if (e->type() == QEvent::TabletRelease)
536 if (container != NULL)
538 RS_ActionSelectSingle * a = new RS_ActionSelectSingle(*container, *this);
541 // QMouseEvent ev(QEvent::MouseButtonRelease, e->pos(), Qt::LeftButton, Qt::LeftButton);
542 // mouseReleaseEvent(&ev);
545 if (container->countSelected() > 0)
546 setCurrentAction(new RS_ActionModifyDelete(*container, *this));
551 case QTabletEvent::Stylus:
552 case QTabletEvent::Puck:
553 if (e->type() == QEvent::TabletPress)
556 // QMouseEvent ev(QEvent::MouseButtonPress, e->pos(), Qt::LeftButton, Qt::LeftButton);
557 // mousePressEvent(&ev);
559 else if (e->type() == QEvent::TabletRelease)
562 // QMouseEvent ev(QEvent::MouseButtonRelease, e->pos(), Qt::LeftButton, Qt::LeftButton);
563 // mouseReleaseEvent(&ev);
565 else if (e->type() == QEvent::TabletMove)
568 // QMouseEvent ev(QEvent::MouseMove, e->pos(), Qt::NoButton, 0);
569 // mouseMoveEvent(&ev);
579 /*if (e->pressure()>10 && lastPressure<10) {
580 QMouseEvent e(QEvent::MouseButtonPress, e->pos(),
581 Qt::LeftButton, Qt::LeftButton);
584 else if (e->pressure()<10 && lastPressure>10) {
585 QMouseEvent e(QEvent::MouseButtonRelease, e->pos(),
586 Qt::LeftButton, Qt::LeftButton);
587 mouseReleaseEvent(&e);
588 } else if (lastPos!=e->pos()) {
589 QMouseEvent e(QEvent::MouseMove, e->pos(),
594 lastPressure = e->pressure();
599 void QG_GraphicView::leaveEvent(QEvent * e)
601 RS_GraphicView::mouseLeaveEvent();
602 QWidget::leaveEvent(e);
605 void QG_GraphicView::enterEvent(QEvent * e)
607 RS_GraphicView::mouseEnterEvent();
608 QWidget::enterEvent(e);
611 void QG_GraphicView::focusOutEvent(QFocusEvent * e)
613 QWidget::focusOutEvent(e);
616 void QG_GraphicView::focusInEvent(QFocusEvent * e)
618 //printf("-->QG_GraphicView::focusInEvent(): Start. this %s focus...\n", (hasFocus() ? "has" : "DOES NOT HAVE"));
619 RS_GraphicView::mouseEnterEvent();
620 QWidget::focusInEvent(e);
621 //printf("-->QG_GraphicView::focusInEvent(): End. this %s focus...\n", (hasFocus() ? "has" : "DOES NOT HAVE"));
625 * mouse wheel event. zooms in/out or scrolls when
626 * shift or ctrl is pressed.
628 void QG_GraphicView::wheelEvent(QWheelEvent * e)
630 //RS_DEBUG->print("wheel: %d", e->delta());
632 //printf("state: %d\n", e->state());
633 //printf("ctrl: %d\n", Qt::ControlButton);
634 Qt::KeyboardModifiers keyState = QApplication::keyboardModifiers();
636 if (container == NULL)
639 Vector mouse = toGraph(Vector(e->x(), e->y()));
642 RS2::Direction direction = RS2::Up;
645 // if (e->state() == Qt::ControlModifier)
646 if (keyState == Qt::ControlModifier)
653 direction = RS2::Down;
655 // scroll left / right:
656 // else if (e->state() == Qt::ShiftModifier)
657 else if (keyState == Qt::ShiftModifier)
662 direction = RS2::Right;
664 direction = RS2::Left;
668 setCurrentAction(new RS_ActionZoomScroll(direction, *container, *this));
670 // else if (e->state() == 0)
671 else if (keyState == 0)
674 setCurrentAction(new RS_ActionZoomIn(*container, *this, RS2::In, RS2::Both, mouse));
676 setCurrentAction(new RS_ActionZoomIn(*container, *this, RS2::Out, RS2::Both, mouse));
682 void QG_GraphicView::keyPressEvent(QKeyEvent * e)
684 if (container == NULL)
688 RS2::Direction direction = RS2::Up;
694 direction = RS2::Right;
698 direction = RS2::Left;
706 direction = RS2::Down;
714 setCurrentAction(new RS_ActionZoomScroll(direction, *container, *this));
716 RS_GraphicView::keyPressEvent(e);
719 void QG_GraphicView::keyReleaseEvent(QKeyEvent * e)
721 RS_GraphicView::keyReleaseEvent(e);
725 * Called whenever the graphic view has changed.
726 * Adjusts the scrollbar ranges / steps.
728 void QG_GraphicView::adjustOffsetControls()
730 static bool running = false;
737 RS_DEBUG->print("QG_GraphicView::adjustOffsetControls() begin");
739 if (container == NULL || hScrollBar == NULL || vScrollBar == NULL)
743 int ox = getOffsetX();
744 int oy = getOffsetY();
746 Vector min = container->getMin();
747 Vector max = container->getMax();
749 // no drawing yet - still allow to scroll
750 if (max.x < min.x+1.0e-6 || max.y < min.y+1.0e-6 ||
751 max.x > RS_MAXDOUBLE || max.x < RS_MINDOUBLE ||
752 min.x > RS_MAXDOUBLE || min.x < RS_MINDOUBLE ||
753 max.y > RS_MAXDOUBLE || max.y < RS_MINDOUBLE ||
754 min.y > RS_MAXDOUBLE || min.y < RS_MINDOUBLE)
756 min = Vector(-10, -10);
757 max = Vector(100, 100);
760 int minVal = (int)(min.x * getFactor().x - QG_SCROLLMARGIN - getBorderLeft());
761 int maxVal = (int)(max.x * getFactor().x - getWidth() + QG_SCROLLMARGIN + getBorderRight());
763 hScrollBar->setValue(0);
765 if (minVal <= maxVal)
766 hScrollBar->setRange(minVal, maxVal);
768 minVal = (int)(getHeight() - max.y * getFactor().y
769 - QG_SCROLLMARGIN - getBorderTop());
770 maxVal = (int)(QG_SCROLLMARGIN + getBorderBottom()
771 - (min.y * getFactor().y));
773 if (minVal <= maxVal)
774 vScrollBar->setRange(minVal, maxVal);
776 hScrollBar->setPageStep((int)(getWidth()));
777 vScrollBar->setPageStep((int)(getHeight()));
779 hScrollBar->setValue(-ox);
780 vScrollBar->setValue(oy);
785 RS_DEBUG->print("H min: %d / max: %d / step: %d / value: %d\n",
786 hScrollBar->minimum(), hScrollBar->maximum(), hScrollBar->pageStep(), ox);
787 RS_DEBUG->print("V min: %d / max: %d / step: %d / value: %d\n",
788 vScrollBar->minimum(), vScrollBar->maximum(), vScrollBar->pageStep(), oy);
792 RS_DEBUG->print("QG_GraphicView::adjustOffsetControls() end");
798 * override this to adjust controls and widgets that
799 * control the zoom factor of the graphic.
801 void QG_GraphicView::adjustZoomControls()
806 * Slot for horizontal scroll events.
808 void QG_GraphicView::slotHScrolled(int value)
810 // Scrollbar behaviour tends to change with every Qt version..
811 // so let's keep old code in here for now
813 //static int running = false;
816 ////RS_DEBUG->print("value x: %d\n", value);
817 if (hScrollBar->maximum() == hScrollBar->minimum())
822 //if (isUpdateEnabled()) {
832 * Slot for vertical scroll events.
834 void QG_GraphicView::slotVScrolled(int value)
836 // Scrollbar behaviour tends to change with every Qt version..
837 // so let's keep old code in here for now
839 //static int running = false;
842 ////RS_DEBUG->print("value y: %d\n", value);
843 if (vScrollBar->maximum() == vScrollBar->minimum())
848 //if (isUpdateEnabled()) {
858 * Handles paint events by redrawing the graphic in this view.
859 * usually that's very fast since we only paint the buffer we
860 * have from the last call..
862 void QG_GraphicView::paintEvent(QPaintEvent *)
864 RS_DEBUG->print("QG_GraphicView::paintEvent begin");
866 if (simulationRunning)
870 To fix the broken rendering here, we need to do one of the following:
872 1) Put preview object here and fix draw code to do an update() instead
873 of trying to draw directly to a widget context
874 2) Use a QPixmap as a randomly drawable surface and fix createDirectPainter()
875 to do an update() after drawing to the pixmap which will eventually end
878 I think 1) is cleaner in the long run, and will make the codebase much more
879 maintainable. However, 2) would make it possible to fix things fairly easily
880 without having to rearrange classes too much.
882 The way the UI is written is crap. It tries to be clever by doing direct
883 painting, bypassing the toolkit's built in rendering pipeline. Also, there
884 are tons of references to Qt stuff in what is supposed to be a toolkit
885 independent manner, resulting in unnecessary divisions of code and rendundant
886 class definitions. Still, the core is still useful and worth fixing just to
887 have something back in portage. We can make it better, faster, stronger. ;-)
889 If we can make the UI more like Inkscape we'll be in good shape. Plus elements
890 of VectorWorks & etc. as well...
893 // Qt4 handles double buffering of screen writes now, so this needs
895 #warning "!!! Need to pass a valid QPainter to drawIt() !!!"
899 //#warning "!!! Double buffering is out... !!!"
900 // Seems most rendering is going through this path... Hrm.
904 wPainter.begin(this);
905 wPainter.drawPixmap(0, 0, *buffer);
912 //// RS_DEBUG->print(RS_Debug::D_CRITICAL, "paintEvent seems to be called recursively: refCount=%u", refCount);
913 // printf("paintEvent seems to be called recursively: refCount=%u\n", refCount);
917 pntr.setBackgroundMode(Qt::OpaqueMode);
918 // pntr.setBackgroundColor(background);
919 pntr.setBackground(QBrush(background));
921 painter = new PaintInterface(&pntr);
926 painter = new RS_PainterQt(this);
928 //Nope, this didn't fix the problem...
929 //The problem is, unless we specifically tell Qt NOT to
930 //clear the window every time, it will...
934 painter->setDrawingMode(drawingMode);
935 ((RS_PainterQt *)painter)->setBackgroundMode(Qt::OpaqueMode);
936 ((RS_PainterQt *)painter)->setBackgroundColor(background);
937 // ((RS_PainterQt *)painter)->eraseRect(0, 0, getWidth(), getHeight());
942 printf("QG_GraphicView::paintEvent: painter is NOT NULL!\n");
947 //Note that we do drawIt() regardless here because paintEvent() clears the background
948 //*unless* we create the window with a specific style. Depending on our draw code, we
949 //just may go that way...
951 //Need some logic here to do drawing in preview mode, since it'll be calling
952 //update now instead of trying to do a direct draw...
955 //hrm. painter->setCompositionMode(QPainter::CompositionMode_Xor);
956 //needed anymore? painter->setXORMode();
957 painter->setOffset(previewOffset);
958 drawEntity(previewEntity);//meh -> , 1.0, false);
959 painter->setOffset(Vector(0, 0));
960 // We'll set previewMode to false here, just because we can
970 if (snapCoord1.valid)
973 //This is causing segfaults in the Qt::Painter code...
974 //*This* is causing the segfault!
975 //Actually, it looks like buggy painting code in PaintInterface()...
976 painter->drawCircle(toGui(snapCoord1), 4);
980 if (showCrosshairs1 == true)
982 painter->setPen(RS_Pen(RS_Color(0, 255, 255), RS2::Width00, RS2::DashLine));
983 painter->drawLine(Vector(0, toGuiY(snapCoord1.y)),
984 Vector(getWidth(), toGuiY(snapCoord1.y)));
985 painter->drawLine(Vector(toGuiX(snapCoord1.x), 0),
986 Vector(toGuiX(snapCoord1.x), getHeight()));
991 if (snapCoord1.valid && snapCoord1 != snapSpot1)
993 painter->drawLine(toGui(snapSpot1) + Vector(-5, 0), toGui(snapSpot1) + Vector(-1, 4));
994 painter->drawLine(toGui(snapSpot1) + Vector(0, 5), toGui(snapSpot1) + Vector(4, 1));
995 painter->drawLine(toGui(snapSpot1) + Vector(5, 0), toGui(snapSpot1) + Vector(1, -4));
996 painter->drawLine(toGui(snapSpot1) + Vector(0, -5), toGui(snapSpot1) + Vector(-4, -1));
1007 RS_DEBUG->print("QG_GraphicView::paintEvent end");
1012 * Previews the given url for the file open dialog.
1014 void QG_GraphicView::previewUrl(const Q3Url & u)
1016 //static Drawing* gr = new Drawing();
1018 RS_DEBUG->print("QG_GraphicView::previewUrl");
1020 if (container != NULL && container->rtti() == RS2::EntityGraphic)
1022 ((Drawing *)container)->open(u.path(), RS2::FormatUnknown);
1027 RS_DEBUG->print("QG_GraphicView::previewUrl: OK");