X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fwidgets%2Fqg_graphicview.cpp;h=6b4e1fba93f4a276afd2f8f0bc2b45610f28e1ff;hb=5adb444f3e523d3fd028617ced72d1ea6661db21;hp=b6d66dd9b499b133e67a6d4288d043c5d59a00d5;hpb=c715d05d11ffe2913fe3465ec43d456ee9b85964;p=architektonas diff --git a/src/widgets/qg_graphicview.cpp b/src/widgets/qg_graphicview.cpp index b6d66dd..6b4e1fb 100644 --- a/src/widgets/qg_graphicview.cpp +++ b/src/widgets/qg_graphicview.cpp @@ -3,7 +3,9 @@ // 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 +// Portions copyright (C) 2001-2003 RibbonSoft +// Copyright (C) 2010 Underground Software +// See the README and GPLv2 files for licensing and warranty information // // JLH = James L. Hammons // @@ -14,22 +16,22 @@ #include "qg_graphicview.h" -#include "rs_actiondefault.h" -#include "rs_actionzoomin.h" -#include "rs_actionzoompan.h" -#include "rs_actionzoomscroll.h" -#include "rs_actionmodifydelete.h" -#include "rs_actionselectsingle.h" -#include "rs_dialogfactory.h" -#include "graphicview.h" -#include "rs_preview.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 "dialogfactory.h" #include "drawing.h" +#include "graphicview.h" +#include "patternlist.h" +#include "paintinterface.h" +#include "preview.h" #include "settings.h" -#include "rs_system.h" -#include "rs_patternlist.h" -#include "cadtoolbar.h" -#include "paintintf.h" -#include "qg_dialogfactory.h" +#include "system.h" #define QG_SCROLLMARGIN 400 @@ -39,33 +41,33 @@ QG_GraphicView::QG_GraphicView(QWidget * parent, const char */*name*/, Qt::WindowFlags f): QWidget(parent, f), GraphicView()//, refCount(0) { - RS_DEBUG->print("QG_GraphicView::QG_GraphicView(parent, name, flags)..."); + DEBUG->print("QG_GraphicView::QG_GraphicView(parent, name, flags)..."); CommonInitialization(); } /** * Constructor II. */ -QG_GraphicView::QG_GraphicView(RS_Document * doc, QWidget * parent) +QG_GraphicView::QG_GraphicView(Document * doc, QWidget * parent) { // QG_GraphicView(parent, "graphicview"); CommonInitialization(); - RS_DEBUG->print("QG_GraphicView::QG_GraphicView(doc, parent)..."); + DEBUG->print("QG_GraphicView::QG_GraphicView(doc, parent)..."); //document = doc; - RS_DEBUG->print(" Setting Container..."); + DEBUG->print(" Setting Container..."); if (doc) setContainer(doc); - RS_DEBUG->print(" container set."); + DEBUG->print(" container set."); setFactorX(4.0); setFactorY(4.0); setOffset(50, 50); setBorders(10, 10, 10, 10); if (doc) - setDefaultAction(new RS_ActionDefault(*doc, *this)); + setDefaultAction(new ActionDefault(*doc, *this)); } void QG_GraphicView::CommonInitialization(void) @@ -77,7 +79,7 @@ void QG_GraphicView::CommonInitialization(void) //hrm. painter = NULL; - RS_DEBUG->print("--> Setting up layout..."); + DEBUG->print("--> Setting up layout..."); QGridLayout * layout = new QGridLayout(this); layout->setColumnStretch(0, 1); layout->setColumnStretch(1, 0); @@ -93,7 +95,7 @@ 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(). */ - RS_DEBUG->print("--> Creating hScrollBar..."); + DEBUG->print("--> Creating hScrollBar..."); // hScrollBar = new QG_ScrollBar(Qt::Horizontal, this); hScrollBar = new QScrollBar(Qt::Horizontal, this); // hScrollBar->setLineStep(50); @@ -103,7 +105,7 @@ A non-zero alignment indicates that the widget should not grow to fill the avail // layout->addRowSpacing(1, hScrollBar->sizeHint().height()); layout->addItem(new QSpacerItem(0, hScrollBar->sizeHint().height()), 1, 0); - RS_DEBUG->print("--> Creating vScrollBar..."); + DEBUG->print("--> Creating vScrollBar..."); // vScrollBar = new QG_ScrollBar(Qt::Vertical, this); vScrollBar = new QScrollBar(Qt::Vertical, this); // vScrollBar->setLineStep(50); @@ -211,7 +213,7 @@ int QG_GraphicView::getHeight() /** * Changes the current background color of this view. */ -void QG_GraphicView::setBackground(const RS_Color & bg) +void QG_GraphicView::setBackground(const Color & bg) { GraphicView::setBackground(bg); @@ -328,7 +330,7 @@ void QG_GraphicView::updateGridStatusWidget(const QString & text) */ void QG_GraphicView::redraw() { - RS_DEBUG->print("QG_GraphicView::redraw begin 1"); + DEBUG->print("QG_GraphicView::redraw begin 1"); if (simulationRunning) return; @@ -342,7 +344,7 @@ void QG_GraphicView::redraw() if (!running) { running = true; - RS_DEBUG->print("QG_GraphicView::redraw begin 2"); + DEBUG->print("QG_GraphicView::redraw begin 2"); /* This is the only place in the entire codebase that a proper update is @@ -352,20 +354,20 @@ triggered. // repaint(false); update(); - RS_DEBUG->print("QG_GraphicView::redraw end 2"); + DEBUG->print("QG_GraphicView::redraw end 2"); running = false; } - RS_DEBUG->print("QG_GraphicView::redraw end 1"); + DEBUG->print("QG_GraphicView::redraw end 1"); } void QG_GraphicView::resizeEvent(QResizeEvent * /*e*/) { - RS_DEBUG->print("QG_GraphicView::resizeEvent begin"); + DEBUG->print("QG_GraphicView::resizeEvent begin"); adjustOffsetControls(); adjustZoomControls(); updateGrid(); - RS_DEBUG->print("QG_GraphicView::resizeEvent end"); + DEBUG->print("QG_GraphicView::resizeEvent end"); } /* @@ -375,18 +377,18 @@ 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 *) +// Next three methods from LayerListListener Interface: +void QG_GraphicView::layerEdited(Layer *) { redraw(); } -void QG_GraphicView::layerRemoved(RS_Layer *) +void QG_GraphicView::layerRemoved(Layer *) { redraw(); } -void QG_GraphicView::layerToggled(RS_Layer *) +void QG_GraphicView::layerToggled(Layer *) { redraw(); } @@ -402,7 +404,7 @@ 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)); GraphicView::mousePressEvent(e); QWidget::mousePressEvent(e); @@ -410,7 +412,7 @@ void QG_GraphicView::mousePressEvent(QMouseEvent * e) void QG_GraphicView::mouseReleaseEvent(QMouseEvent * e) { - RS_DEBUG->print("QG_GraphicView::mouseReleaseEvent"); + DEBUG->print("QG_GraphicView::mouseReleaseEvent"); GraphicView::mouseReleaseEvent(e); //QWidget::mouseReleaseEvent(e); @@ -418,30 +420,18 @@ void QG_GraphicView::mouseReleaseEvent(QMouseEvent * e) { if (QG_DIALOGFACTORY && QG_DIALOGFACTORY->getCadToolBar()) { - RS_DEBUG->print("QG_GraphicView::mouseReleaseEvent: fwd to cadtoolbar"); + DEBUG->print("QG_GraphicView::mouseReleaseEvent: fwd to cadtoolbar"); QG_DIALOGFACTORY->getCadToolBar()->mouseReleaseEvent(e); } } - RS_DEBUG->print("QG_GraphicView::mouseReleaseEvent: OK"); + DEBUG->print("QG_GraphicView::mouseReleaseEvent: OK"); } void QG_GraphicView::mouseMoveEvent(QMouseEvent * e) { - //RS_DEBUG->print("QG_GraphicView::mouseMoveEvent begin"); - //QMouseEvent rsm = QG_Qt2Rs::mouseEvent(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"); } /** @@ -459,7 +449,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); @@ -467,7 +457,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; @@ -551,7 +541,7 @@ void QG_GraphicView::focusInEvent(QFocusEvent * e) */ void QG_GraphicView::wheelEvent(QWheelEvent * e) { - //RS_DEBUG->print("wheel: %d", e->delta()); + //DEBUG->print("wheel: %d", e->delta()); //printf("state: %d\n", e->state()); //printf("ctrl: %d\n", Qt::ControlButton); @@ -588,15 +578,15 @@ void QG_GraphicView::wheelEvent(QWheelEvent * e) } 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(); @@ -634,7 +624,7 @@ void QG_GraphicView::keyPressEvent(QKeyEvent * e) } if (scroll) - setCurrentAction(new RS_ActionZoomScroll(direction, *container, *this)); + setCurrentAction(new ActionZoomScroll(direction, *container, *this)); GraphicView::keyPressEvent(e); } @@ -657,7 +647,7 @@ void QG_GraphicView::adjustOffsetControls() running = true; - RS_DEBUG->print("QG_GraphicView::adjustOffsetControls() begin"); + DEBUG->print("QG_GraphicView::adjustOffsetControls() begin"); if (!container || !hScrollBar || !vScrollBar) return; @@ -705,14 +695,14 @@ void QG_GraphicView::adjustOffsetControls() slotHScrolled(-ox); slotVScrolled(oy); - RS_DEBUG->print("H min: %d / max: %d / step: %d / value: %d\n", + DEBUG->print("H min: %d / max: %d / step: %d / value: %d\n", hScrollBar->minimum(), hScrollBar->maximum(), hScrollBar->pageStep(), ox); - RS_DEBUG->print("V min: %d / max: %d / step: %d / value: %d\n", + DEBUG->print("V min: %d / max: %d / step: %d / value: %d\n", vScrollBar->minimum(), vScrollBar->maximum(), vScrollBar->pageStep(), oy); enableUpdate(); - RS_DEBUG->print("QG_GraphicView::adjustOffsetControls() end"); + DEBUG->print("QG_GraphicView::adjustOffsetControls() end"); running = false; } @@ -736,7 +726,7 @@ void QG_GraphicView::slotHScrolled(int value) //static int running = false; //if (!running) { //running = true; - ////RS_DEBUG->print("value x: %d\n", value); + ////DEBUG->print("value x: %d\n", value); if (hScrollBar->maximum() == hScrollBar->minimum()) centerOffsetX(); else @@ -762,7 +752,7 @@ void QG_GraphicView::slotVScrolled(int value) //static int running = false; //if (!running) { //running = true; - ////RS_DEBUG->print("value y: %d\n", value); + ////DEBUG->print("value y: %d\n", value); if (vScrollBar->maximum() == vScrollBar->minimum()) centerOffsetY(); else @@ -789,7 +779,7 @@ void QG_GraphicView::slotVScrolled(int value) */ void QG_GraphicView::paintEvent(QPaintEvent *) { - RS_DEBUG->print("QG_GraphicView::paintEvent begin"); + DEBUG->print("QG_GraphicView::paintEvent begin"); if (simulationRunning) return; @@ -816,147 +806,36 @@ 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); -//} +//#warning "!!! Need to pass a valid QPainter to drawIt() !!!" 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 - 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); - 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); + // Draw the snapper first, because we want to be able to see the preview on + // top of this... +// if (snapper.Visible()) +// snapper.Draw(this, painter); + // Actually, this code can go into drawIt() instead of here... + if (snapperVisible) + DrawSnapper(painter); + + if (preview.Visible()) + preview.Draw(this, painter); delete painter; painter = NULL; -// refCount--; -#endif - - RS_DEBUG->print("QG_GraphicView::paintEvent end"); + 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