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_graphic.h"
24 #include "rs_system.h"
25 #include "rs_patternlist.h"
26 #include "cadtoolbar.h"
27 #include "paintintf.h"
28 #include "qg_dialogfactory.h"
30 #define QG_SCROLLMARGIN 400
35 QG_GraphicView::QG_GraphicView(QWidget * parent, const char */*name*/, Qt::WindowFlags f):
36 QWidget(parent, f), RS_GraphicView()//, refCount(0)
38 setBackground(background);
42 //coordinateWidget = NULL;
44 //optionWidget = NULL;
46 //commandWidget = NULL;
50 // layout = new Q3GridLayout(this, 3, 2);
51 // layout->setColStretch(0, 1);
52 // layout->setColStretch(1, 0);
53 // layout->setColStretch(2, 0);
54 // layout->setRowStretch(0, 1);
55 // layout->setRowStretch(1, 0);
56 layout = new QGridLayout(this);
57 layout->setColumnStretch(0, 1);
58 layout->setColumnStretch(1, 0);
59 layout->setColumnStretch(2, 0);
60 layout->setRowStretch(0, 1);
61 layout->setRowStretch(1, 0);
64 void QGridLayout::addMultiCellWidget ( QWidget * w, int fromRow, int toRow, int fromCol, int toCol, int alignment = 0 )
65 Adds the widget w to the cell grid, spanning multiple rows/columns. The cell will span from fromRow, fromCol to toRow, toCol.
67 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.
69 A non-zero alignment indicates that the widget should not grow to fill the available space but should be sized according to sizeHint().
71 hScrollBar = new QG_ScrollBar(Qt::Horizontal, this);
72 // hScrollBar->setLineStep(50);
73 hScrollBar->setSingleStep(50);
74 // layout->addMultiCellWidget(hScrollBar, 1, 1, 0, 0);
75 layout->addWidget(hScrollBar, 1, 0);
76 // layout->addRowSpacing(1, hScrollBar->sizeHint().height());
77 layout->addItem(new QSpacerItem(0, hScrollBar->sizeHint().height()), 1, 0);
78 connect(hScrollBar, SIGNAL(valueChanged(int)), this, SLOT(slotHScrolled(int)));
80 vScrollBar = new QG_ScrollBar(Qt::Vertical, this);
81 // vScrollBar->setLineStep(50);
82 vScrollBar->setSingleStep(50);
83 // layout->addMultiCellWidget(vScrollBar, 0, 0, 2, 2);
84 layout->addWidget(vScrollBar, 0, 2);
85 // layout->addColSpacing(2, vScrollBar->sizeHint().width());
86 layout->addItem(new QSpacerItem(vScrollBar->sizeHint().width(), 0), 0, 2);
87 connect(vScrollBar, SIGNAL(valueChanged(int)), this, SLOT(slotVScrolled(int)));
92 // QPixmap cur1(cur_cad_bmp_xpm);
93 // bmp = QPixmap(cur_cad_mask_xpm);
94 QPixmap cur1(":/res/cur_cad_bmp.xpm");
95 bmp = QPixmap(":/res/cur_cad_mask.xpm");
97 curCad = new QCursor(cur1, 15, 15);
99 // QPixmap cur2(cur_glass_bmp_xpm);
100 // bmp = QPixmap(cur_glass_mask_xpm);
101 QPixmap cur2(":/res/cur_glass_bmp.xpm");
102 bmp = QPixmap(":/res/cur_glass_mask.xpm");
104 curMagnifier = new QCursor(cur2, 12, 12);
106 // QPixmap cur3(cur_del_bmp_xpm);
107 // bmp = QPixmap(cur_del_mask_xpm);
108 QPixmap cur3(":/res/cur_del_bmp.xpm");
109 bmp = QPixmap(":/res/cur_del_mask.xpm");
111 curDel = new QCursor(cur3, 15, 15);
113 // QPixmap cur4(cur_select_bmp_xpm);
114 // bmp = QPixmap(cur_select_mask_xpm);
115 QPixmap cur4(":/res/cur_select_bmp.xpm");
116 bmp = QPixmap(":/res/cur_select_mask.xpm");
118 curSelect = new QCursor(cur4, 15, 15);
120 // QPixmap cur5(cur_hand_bmp_xpm);
121 // bmp = QPixmap(cur_hand_mask_xpm);
122 QPixmap cur5(":/res/cur_hand_bmp.xpm");
123 bmp = QPixmap(":/res/cur_hand_mask.xpm");
125 curHand = new QCursor(cur5, 15, 15);
127 // No individual cursors for the Mac
135 // Dummy widgets for scrollbar corners:
136 //layout->addWidget(new QWidget(this), 1, 1);
137 //QWidget* w = new QWidget(this);
138 //w->setEraseColor(QColor(255,0,0));
139 gridStatus = new QLabel("-", this);
140 gridStatus->setAlignment(Qt::AlignRight);
141 // layout->addMultiCellWidget(gridStatus, 1, 1, 1, 2);
142 layout->addWidget(gridStatus, 1, 1, 1, 2);
143 // layout->addColSpacing(1, 50);
144 layout->addItem(new QSpacerItem(50, 0), 0, 1);
146 setMouseTracking(true);
147 // flickering under win:
148 //setFocusPolicy(WheelFocus);
150 #warning "QG_GraphicView constructor is setting Qt::NoFocus!!!"
151 // A-HAH! THIS IS THE PROBLEM!!!
152 // setFocusPolicy(Qt::NoFocus);
154 // setFocusPolicy(Qt::StrongFocus);
160 QG_GraphicView::~QG_GraphicView()
164 //Not sure about this...
165 // ((RS_PainterQt *)painter)->end();
179 * @return width of widget.
181 int QG_GraphicView::getWidth()
183 return width() - vScrollBar->sizeHint().width();
187 * @return height of widget.
189 int QG_GraphicView::getHeight()
191 return height() - hScrollBar->sizeHint().height();
195 * Creates a new painter for the buffer of this widget and returns a
196 * pointer to it. The class variable 'painter' also
197 * points to that object.
199 //'painter' is NOT a class variable!
200 //RS_Painter * QG_GraphicView::createPainter()
201 PaintInterface * QG_GraphicView::createPainter()
206 //RS_DEBUG->print(RS_Debug::D_CRITICAL, "QG_GraphicView::createPainter called...");
207 RS_DEBUG->print("QG_GraphicView::createPainter begin");
209 if (lastWidth != getWidth() || lastHeight != getHeight())
219 lastWidth = getWidth();
220 lastHeight = getHeight();
225 //RS_DEBUG->timestamp();
226 RS_DEBUG->print("creating buffer: %d,%d", getWidth(), getHeight());
227 buffer = new QPixmap(getWidth(), getHeight());
228 RS_DEBUG->print("ok");
233 painter = new RS_PainterQt(buffer);
234 painter->setDrawingMode(drawingMode);
235 ((RS_PainterQt *)painter)->setBackgroundMode(Qt::OpaqueMode);
236 ((RS_PainterQt *)painter)->setBackgroundColor(background);
237 ((RS_PainterQt *)painter)->eraseRect(0, 0, getWidth(), getHeight());
239 //RS_DEBUG->timestamp();
242 RS_DEBUG->print("QG_GraphicView::createPainter end");
249 * Creates a new painter for this widget and returns a
250 * pointer to it. The class variable 'painter' also
251 * automatically points to that object.
253 //RS_Painter * QG_GraphicView::createDirectPainter()
254 PaintInterface * QG_GraphicView::createDirectPainter()
259 //RS_DEBUG->print(RS_Debug::D_CRITICAL, "QG_GraphicView::createDirectPainter called...");
260 RS_DEBUG->print("QG_GraphicView::createDirectPainter begin");
263 painter = new RS_PainterQt(this);
264 painter->setDrawingMode(drawingMode);
266 RS_DEBUG->print("QG_GraphicView::createDirectPainter end");
273 * Deletes the painter.
275 void QG_GraphicView::destroyPainter()
280 RS_DEBUG->print("QG_GraphicView::destroyPainter begin");
288 RS_DEBUG->print("QG_GraphicView::destroyPainter end");
293 * Changes the current background color of this view.
295 void QG_GraphicView::setBackground(const RS_Color & bg)
297 RS_GraphicView::setBackground(bg);
299 // setBackgroundColor(bg);
301 palette.setColor(backgroundRole(), bg);
306 * Sets the mouse cursor to the given type.
308 void QG_GraphicView::setMouseCursor(RS2::CursorType c)
313 case RS2::ArrowCursor:
314 setCursor(Qt::ArrowCursor);
316 case RS2::UpArrowCursor:
317 setCursor(Qt::UpArrowCursor);
319 case RS2::CrossCursor:
320 setCursor(Qt::CrossCursor);
322 case RS2::WaitCursor:
323 setCursor(Qt::WaitCursor);
325 case RS2::IbeamCursor:
326 setCursor(Qt::IBeamCursor);
328 case RS2::SizeVerCursor:
329 setCursor(Qt::SizeVerCursor);
331 case RS2::SizeHorCursor:
332 setCursor(Qt::SizeHorCursor);
334 case RS2::SizeBDiagCursor:
335 setCursor(Qt::SizeBDiagCursor);
337 case RS2::SizeFDiagCursor:
338 setCursor(Qt::SizeFDiagCursor);
340 case RS2::SizeAllCursor:
341 setCursor(Qt::SizeAllCursor);
343 case RS2::BlankCursor:
344 setCursor(Qt::BlankCursor);
346 case RS2::SplitVCursor:
347 setCursor(Qt::SplitVCursor);
349 case RS2::SplitHCursor:
350 setCursor(Qt::SplitHCursor);
352 case RS2::PointingHandCursor:
353 setCursor(Qt::PointingHandCursor);
355 case RS2::ForbiddenCursor:
356 setCursor(Qt::ForbiddenCursor);
358 case RS2::WhatsThisCursor:
359 setCursor(Qt::WhatsThisCursor);
369 case RS2::SelectCursor:
370 setCursor(*curSelect);
372 case RS2::MagnifierCursor:
373 setCursor(*curMagnifier);
375 case RS2::MovingHandCursor:
379 // Reduced cursor selection for the Mac:
381 setCursor(Qt::CrossCursor);
384 setCursor(Qt::CrossCursor);
386 case RS2::SelectCursor:
387 setCursor(Qt::CrossCursor);
389 case RS2::MagnifierCursor:
390 setCursor(Qt::CrossCursor);
392 case RS2::MovingHandCursor:
393 setCursor(Qt::PointingHandCursor);
400 * Sets the text for the grid status widget in the left bottom corner.
402 void QG_GraphicView::updateGridStatusWidget(const QString & text)
404 gridStatus->setText(text);
408 * Redraws the widget.
410 void QG_GraphicView::redraw()
412 RS_DEBUG->print("QG_GraphicView::redraw begin 1");
414 if (simulationRunning)
417 //Also, this stuff is properly taken care of by the Qt toolkit--
418 //so we don't have to be concerned with shit like this as long
419 //as we use update() instead of repaint()
421 static bool running = false;
426 RS_DEBUG->print("QG_GraphicView::redraw begin 2");
429 This is the only place in the entire codebase that a proper update is
432 if (isUpdateEnabled())
436 RS_DEBUG->print("QG_GraphicView::redraw end 2");
440 RS_DEBUG->print("QG_GraphicView::redraw end 1");
443 void QG_GraphicView::resizeEvent(QResizeEvent * /*e*/)
445 RS_DEBUG->print("QG_GraphicView::resizeEvent begin");
446 adjustOffsetControls();
447 adjustZoomControls();
449 RS_DEBUG->print("QG_GraphicView::resizeEvent end");
452 // Next three methods from RS_LayerListListener Interface:
453 void QG_GraphicView::layerEdited(RS_Layer *)
458 void QG_GraphicView::layerRemoved(RS_Layer *)
463 void QG_GraphicView::layerToggled(RS_Layer *)
468 void QG_GraphicView::emulateMouseMoveEvent()
470 // QMouseEvent e(QEvent::MouseMove, QPoint(mx, my), Qt::NoButton, Qt::NoButton);
471 //mouseMoveEvent(&e);
474 void QG_GraphicView::mousePressEvent(QMouseEvent * e)
476 // pan zoom with middle mouse button
477 if (e->button() == Qt::MidButton /*|| (e->state()==Qt::LeftButton|Qt::AltButton)*/)
478 setCurrentAction(new RS_ActionZoomPan(*container, *this));
480 RS_GraphicView::mousePressEvent(e);
481 QWidget::mousePressEvent(e);
484 void QG_GraphicView::mouseReleaseEvent(QMouseEvent * e)
486 RS_DEBUG->print("QG_GraphicView::mouseReleaseEvent");
487 RS_GraphicView::mouseReleaseEvent(e);
488 //QWidget::mouseReleaseEvent(e);
490 if (!e->isAccepted())
492 if (QG_DIALOGFACTORY != NULL && QG_DIALOGFACTORY->getCadToolBar() != NULL)
494 RS_DEBUG->print("QG_GraphicView::mouseReleaseEvent: fwd to cadtoolbar");
495 QG_DIALOGFACTORY->getCadToolBar()->mouseReleaseEvent(e);
499 RS_DEBUG->print("QG_GraphicView::mouseReleaseEvent: OK");
502 void QG_GraphicView::mouseMoveEvent(QMouseEvent * e)
504 //RS_DEBUG->print("QG_GraphicView::mouseMoveEvent begin");
505 //QMouseEvent rsm = QG_Qt2Rs::mouseEvent(e);
507 RS_GraphicView::mouseMoveEvent(e);
508 QWidget::mouseMoveEvent(e);
510 //What kind of cacamamie crap is this???
512 // // make sure that we can still use hotkeys and the mouse wheel
513 // if (parent() != NULL)
514 // ((QWidget *)parent())->setFocus();
517 //RS_DEBUG->print("QG_GraphicView::mouseMoveEvent end");
521 * support for the wacom graphic tablet.
523 void QG_GraphicView::tabletEvent(QTabletEvent * e)
526 if (testAttribute(Qt::WA_UnderMouse))
530 case QTabletEvent::Eraser:
531 if (e->type() == QEvent::TabletRelease)
533 if (container != NULL)
535 RS_ActionSelectSingle * a = new RS_ActionSelectSingle(*container, *this);
538 // QMouseEvent ev(QEvent::MouseButtonRelease, e->pos(), Qt::LeftButton, Qt::LeftButton);
539 // mouseReleaseEvent(&ev);
542 if (container->countSelected() > 0)
543 setCurrentAction(new RS_ActionModifyDelete(*container, *this));
548 case QTabletEvent::Stylus:
549 case QTabletEvent::Puck:
550 if (e->type() == QEvent::TabletPress)
553 // QMouseEvent ev(QEvent::MouseButtonPress, e->pos(), Qt::LeftButton, Qt::LeftButton);
554 // mousePressEvent(&ev);
556 else if (e->type() == QEvent::TabletRelease)
559 // QMouseEvent ev(QEvent::MouseButtonRelease, e->pos(), Qt::LeftButton, Qt::LeftButton);
560 // mouseReleaseEvent(&ev);
562 else if (e->type() == QEvent::TabletMove)
565 // QMouseEvent ev(QEvent::MouseMove, e->pos(), Qt::NoButton, 0);
566 // mouseMoveEvent(&ev);
576 /*if (e->pressure()>10 && lastPressure<10) {
577 QMouseEvent e(QEvent::MouseButtonPress, e->pos(),
578 Qt::LeftButton, Qt::LeftButton);
581 else if (e->pressure()<10 && lastPressure>10) {
582 QMouseEvent e(QEvent::MouseButtonRelease, e->pos(),
583 Qt::LeftButton, Qt::LeftButton);
584 mouseReleaseEvent(&e);
585 } else if (lastPos!=e->pos()) {
586 QMouseEvent e(QEvent::MouseMove, e->pos(),
591 lastPressure = e->pressure();
596 void QG_GraphicView::leaveEvent(QEvent * e)
598 RS_GraphicView::mouseLeaveEvent();
599 QWidget::leaveEvent(e);
602 void QG_GraphicView::enterEvent(QEvent * e)
604 RS_GraphicView::mouseEnterEvent();
605 QWidget::enterEvent(e);
608 void QG_GraphicView::focusOutEvent(QFocusEvent * e)
610 QWidget::focusOutEvent(e);
613 void QG_GraphicView::focusInEvent(QFocusEvent * e)
615 //printf("-->QG_GraphicView::focusInEvent(): Start. this %s focus...\n", (hasFocus() ? "has" : "DOES NOT HAVE"));
616 RS_GraphicView::mouseEnterEvent();
617 QWidget::focusInEvent(e);
618 //printf("-->QG_GraphicView::focusInEvent(): End. this %s focus...\n", (hasFocus() ? "has" : "DOES NOT HAVE"));
622 * mouse wheel event. zooms in/out or scrolls when
623 * shift or ctrl is pressed.
625 void QG_GraphicView::wheelEvent(QWheelEvent * e)
627 //RS_DEBUG->print("wheel: %d", e->delta());
629 //printf("state: %d\n", e->state());
630 //printf("ctrl: %d\n", Qt::ControlButton);
631 Qt::KeyboardModifiers keyState = QApplication::keyboardModifiers();
633 if (container == NULL)
636 Vector mouse = toGraph(Vector(e->x(), e->y()));
639 RS2::Direction direction = RS2::Up;
642 // if (e->state() == Qt::ControlModifier)
643 if (keyState == Qt::ControlModifier)
650 direction = RS2::Down;
652 // scroll left / right:
653 // else if (e->state() == Qt::ShiftModifier)
654 else if (keyState == Qt::ShiftModifier)
659 direction = RS2::Right;
661 direction = RS2::Left;
665 setCurrentAction(new RS_ActionZoomScroll(direction, *container, *this));
667 // else if (e->state() == 0)
668 else if (keyState == 0)
671 setCurrentAction(new RS_ActionZoomIn(*container, *this, RS2::In, RS2::Both, mouse));
673 setCurrentAction(new RS_ActionZoomIn(*container, *this, RS2::Out, RS2::Both, mouse));
679 void QG_GraphicView::keyPressEvent(QKeyEvent * e)
681 if (container == NULL)
685 RS2::Direction direction = RS2::Up;
691 direction = RS2::Right;
695 direction = RS2::Left;
703 direction = RS2::Down;
711 setCurrentAction(new RS_ActionZoomScroll(direction, *container, *this));
713 RS_GraphicView::keyPressEvent(e);
716 void QG_GraphicView::keyReleaseEvent(QKeyEvent * e)
718 RS_GraphicView::keyReleaseEvent(e);
722 * Called whenever the graphic view has changed.
723 * Adjusts the scrollbar ranges / steps.
725 void QG_GraphicView::adjustOffsetControls()
727 static bool running = false;
734 RS_DEBUG->print("QG_GraphicView::adjustOffsetControls() begin");
736 if (container == NULL || hScrollBar == NULL || vScrollBar == NULL)
740 int ox = getOffsetX();
741 int oy = getOffsetY();
743 Vector min = container->getMin();
744 Vector max = container->getMax();
746 // no drawing yet - still allow to scroll
747 if (max.x < min.x+1.0e-6 || max.y < min.y+1.0e-6 ||
748 max.x > RS_MAXDOUBLE || max.x < RS_MINDOUBLE ||
749 min.x > RS_MAXDOUBLE || min.x < RS_MINDOUBLE ||
750 max.y > RS_MAXDOUBLE || max.y < RS_MINDOUBLE ||
751 min.y > RS_MAXDOUBLE || min.y < RS_MINDOUBLE)
753 min = Vector(-10, -10);
754 max = Vector(100, 100);
757 int minVal = (int)(min.x * getFactor().x - QG_SCROLLMARGIN - getBorderLeft());
758 int maxVal = (int)(max.x * getFactor().x - getWidth() + QG_SCROLLMARGIN + getBorderRight());
760 hScrollBar->setValue(0);
762 if (minVal <= maxVal)
763 hScrollBar->setRange(minVal, maxVal);
765 minVal = (int)(getHeight() - max.y * getFactor().y
766 - QG_SCROLLMARGIN - getBorderTop());
767 maxVal = (int)(QG_SCROLLMARGIN + getBorderBottom()
768 - (min.y * getFactor().y));
770 if (minVal <= maxVal)
771 vScrollBar->setRange(minVal, maxVal);
773 hScrollBar->setPageStep((int)(getWidth()));
774 vScrollBar->setPageStep((int)(getHeight()));
776 hScrollBar->setValue(-ox);
777 vScrollBar->setValue(oy);
782 RS_DEBUG->print("H min: %d / max: %d / step: %d / value: %d\n",
783 hScrollBar->minimum(), hScrollBar->maximum(), hScrollBar->pageStep(), ox);
784 RS_DEBUG->print("V min: %d / max: %d / step: %d / value: %d\n",
785 vScrollBar->minimum(), vScrollBar->maximum(), vScrollBar->pageStep(), oy);
789 RS_DEBUG->print("QG_GraphicView::adjustOffsetControls() end");
795 * override this to adjust controls and widgets that
796 * control the zoom factor of the graphic.
798 void QG_GraphicView::adjustZoomControls()
803 * Slot for horizontal scroll events.
805 void QG_GraphicView::slotHScrolled(int value)
807 // Scrollbar behaviour tends to change with every Qt version..
808 // so let's keep old code in here for now
810 //static int running = false;
813 ////RS_DEBUG->print("value x: %d\n", value);
814 if (hScrollBar->maximum() == hScrollBar->minimum())
819 //if (isUpdateEnabled()) {
829 * Slot for vertical scroll events.
831 void QG_GraphicView::slotVScrolled(int value)
833 // Scrollbar behaviour tends to change with every Qt version..
834 // so let's keep old code in here for now
836 //static int running = false;
839 ////RS_DEBUG->print("value y: %d\n", value);
840 if (vScrollBar->maximum() == vScrollBar->minimum())
845 //if (isUpdateEnabled()) {
855 * Handles paint events by redrawing the graphic in this view.
856 * usually that's very fast since we only paint the buffer we
857 * have from the last call..
859 void QG_GraphicView::paintEvent(QPaintEvent *)
861 RS_DEBUG->print("QG_GraphicView::paintEvent begin");
863 if (simulationRunning)
867 To fix the broken rendering here, we need to do one of the following:
869 1) Put preview object here and fix draw code to do an update() instead
870 of trying to draw directly to a widget context
871 2) Use a QPixmap as a randomly drawable surface and fix createDirectPainter()
872 to do an update() after drawing to the pixmap which will eventually end
875 I think 1) is cleaner in the long run, and will make the codebase much more
876 maintainable. However, 2) would make it possible to fix things fairly easily
877 without having to rearrange classes too much.
879 The way the UI is written is crap. It tries to be clever by doing direct
880 painting, bypassing the toolkit's built in rendering pipeline. Also, there
881 are tons of references to Qt stuff in what is supposed to be a toolkit
882 independent manner, resulting in unnecessary divisions of code and rendundant
883 class definitions. Still, the core is still useful and worth fixing just to
884 have something back in portage. We can make it better, faster, stronger. ;-)
886 If we can make the UI more like Inkscape we'll be in good shape. Plus elements
887 of VectorWorks & etc. as well...
890 // Qt4 handles double buffering of screen writes now, so this needs
892 #warning "!!! Need to pass a valid QPainter to drawIt() !!!"
896 //#warning "!!! Double buffering is out... !!!"
897 // Seems most rendering is going through this path... Hrm.
901 wPainter.begin(this);
902 wPainter.drawPixmap(0, 0, *buffer);
909 //// RS_DEBUG->print(RS_Debug::D_CRITICAL, "paintEvent seems to be called recursively: refCount=%u", refCount);
910 // printf("paintEvent seems to be called recursively: refCount=%u\n", refCount);
914 pntr.setBackgroundMode(Qt::OpaqueMode);
915 // pntr.setBackgroundColor(background);
916 pntr.setBackground(QBrush(background));
918 painter = new PaintInterface(&pntr);
923 painter = new RS_PainterQt(this);
925 //Nope, this didn't fix the problem...
926 //The problem is, unless we specifically tell Qt NOT to
927 //clear the window every time, it will...
931 painter->setDrawingMode(drawingMode);
932 ((RS_PainterQt *)painter)->setBackgroundMode(Qt::OpaqueMode);
933 ((RS_PainterQt *)painter)->setBackgroundColor(background);
934 // ((RS_PainterQt *)painter)->eraseRect(0, 0, getWidth(), getHeight());
939 printf("QG_GraphicView::paintEvent: painter is NOT NULL!\n");
944 //Note that we do drawIt() regardless here because paintEvent() clears the background
945 //*unless* we create the window with a specific style. Depending on our draw code, we
946 //just may go that way...
948 //Need some logic here to do drawing in preview mode, since it'll be calling
949 //update now instead of trying to do a direct draw...
952 //hrm. painter->setCompositionMode(QPainter::CompositionMode_Xor);
953 //needed anymore? painter->setXORMode();
954 painter->setOffset(previewOffset);
955 drawEntity(previewEntity);//meh -> , 1.0, false);
956 painter->setOffset(Vector(0, 0));
957 // We'll set previewMode to false here, just because we can
967 if (snapCoord1.valid)
970 //This is causing segfaults in the Qt::Painter code...
971 //*This* is causing the segfault!
972 //Actually, it looks like buggy painting code in PaintInterface()...
973 painter->drawCircle(toGui(snapCoord1), 4);
977 if (showCrosshairs1 == true)
979 painter->setPen(RS_Pen(RS_Color(0, 255, 255), RS2::Width00, RS2::DashLine));
980 painter->drawLine(Vector(0, toGuiY(snapCoord1.y)),
981 Vector(getWidth(), toGuiY(snapCoord1.y)));
982 painter->drawLine(Vector(toGuiX(snapCoord1.x), 0),
983 Vector(toGuiX(snapCoord1.x), getHeight()));
988 if (snapCoord1.valid && snapCoord1 != snapSpot1)
990 painter->drawLine(toGui(snapSpot1) + Vector(-5, 0), toGui(snapSpot1) + Vector(-1, 4));
991 painter->drawLine(toGui(snapSpot1) + Vector(0, 5), toGui(snapSpot1) + Vector(4, 1));
992 painter->drawLine(toGui(snapSpot1) + Vector(5, 0), toGui(snapSpot1) + Vector(1, -4));
993 painter->drawLine(toGui(snapSpot1) + Vector(0, -5), toGui(snapSpot1) + Vector(-4, -1));
1004 RS_DEBUG->print("QG_GraphicView::paintEvent end");
1009 * Previews the given url for the file open dialog.
1011 void QG_GraphicView::previewUrl(const Q3Url & u)
1013 //static RS_Graphic* gr = new RS_Graphic();
1015 RS_DEBUG->print("QG_GraphicView::previewUrl");
1017 if (container != NULL && container->rtti() == RS2::EntityGraphic)
1019 ((RS_Graphic *)container)->open(u.path(), RS2::FormatUnknown);
1024 RS_DEBUG->print("QG_GraphicView::previewUrl: OK");