X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fwidgets%2Fqg_graphicview.cpp;h=b6d66dd9b499b133e67a6d4288d043c5d59a00d5;hb=c715d05d11ffe2913fe3465ec43d456ee9b85964;hp=7c0b632076f5eb2281be0f3a53edb0e20343c952;hpb=27d4a138d23453e93a833e9347444b828a971cb4;p=architektonas diff --git a/src/widgets/qg_graphicview.cpp b/src/widgets/qg_graphicview.cpp index 7c0b632..b6d66dd 100644 --- a/src/widgets/qg_graphicview.cpp +++ b/src/widgets/qg_graphicview.cpp @@ -14,6 +14,7 @@ #include "qg_graphicview.h" +#include "rs_actiondefault.h" #include "rs_actionzoomin.h" #include "rs_actionzoompan.h" #include "rs_actionzoomscroll.h" @@ -37,15 +38,47 @@ */ 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)..."); + 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 RS_ActionDefault(*doc, *this)); +} + +void QG_GraphicView::CommonInitialization(void) { setBackground(background); - buffer = NULL; +//meh buffer = NULL; lastWidth = 0; lastHeight = 0; //hrm. painter = NULL; - 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); @@ -60,22 +93,27 @@ 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__ @@ -120,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); @@ -141,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(); } @@ -333,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 *) { @@ -348,6 +390,7 @@ void QG_GraphicView::layerToggled(RS_Layer *) { redraw(); } +#endif void QG_GraphicView::emulateMouseMoveEvent() { @@ -373,7 +416,7 @@ void QG_GraphicView::mouseReleaseEvent(QMouseEvent * 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); @@ -512,11 +555,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; @@ -562,7 +604,7 @@ Qt::KeyboardModifiers keyState = QApplication::keyboardModifiers(); void QG_GraphicView::keyPressEvent(QKeyEvent * e) { - if (container == NULL) + if (!container) return; bool scroll = false; @@ -617,7 +659,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(); @@ -628,11 +670,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); @@ -774,6 +816,15 @@ 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 @@ -829,13 +880,13 @@ of VectorWorks & etc. as well... } #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 0 if (previewMode) { //hrm. painter->setCompositionMode(QPainter::CompositionMode_Xor); @@ -846,43 +897,39 @@ of VectorWorks & etc. as well... // We'll set previewMode to false here, just because we can previewMode = false; } -#endif - - if (snapperDraw) -// if (false) +#else + if (preview.Visible()) { - snapperDraw = false; - - if (snapCoord1.valid) + 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)) { - // 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 +// e->setPen(RS_Pen(RS_Color(60, 255, 80), RS2::Width00, RS2::SolidLine)); + drawEntityPlain(e); } -#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)); - } -#endif + //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;