#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 "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 "drawing.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
setBorders(10, 10, 10, 10);
if (doc)
- setDefaultAction(new RS_ActionDefault(*doc, *this));
+ setDefaultAction(new ActionDefault(*doc, *this));
}
void QG_GraphicView::CommonInitialization(void)
{
setBackground(background);
- buffer = NULL;
+//meh buffer = NULL;
lastWidth = 0;
lastHeight = 0;
//hrm.
painter = NULL;
RS_DEBUG->print("--> Setting up layout...");
- layout = new QGridLayout(this);
+ QGridLayout * layout = new QGridLayout(this);
layout->setColumnStretch(0, 1);
layout->setColumnStretch(1, 0);
layout->setColumnStretch(2, 0);
if (painter)
delete painter;
- if (buffer)
- {
- delete buffer;
- buffer = NULL;
- }
+//meh if (buffer)
+// {
+// delete buffer;
+// buffer = NULL;
+// }
cleanUp();
}
{
// 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);
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");
}
/**
{
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);
a->finish();
if (container->countSelected() > 0)
- setCurrentAction(new RS_ActionModifyDelete(*container, *this));
+ setCurrentAction(new ActionModifyDelete(*container, *this));
}
}
break;
}
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();
}
if (scroll)
- setCurrentAction(new RS_ActionZoomScroll(direction, *container, *this));
+ setCurrentAction(new ActionZoomScroll(direction, *container, *this));
GraphicView::keyPressEvent(e);
}
RS_DEBUG->print("QG_GraphicView::adjustOffsetControls() begin");
- if (container == NULL || hScrollBar == NULL || vScrollBar == NULL)
+ if (!container || !hScrollBar || !vScrollBar)
return;
disableUpdate();
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);
-//}
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 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