]> Shamusworld >> Repos - architektonas/blobdiff - src/widgets/qg_graphicview.cpp
Merged QC_GraphicView into QG_GraphicView...
[architektonas] / src / widgets / qg_graphicview.cpp
index 96cdebfe222c316cc5e705e8089826eff0859aca..d885f8a0a820a59c2f24def12d029d3d97cf9f61 100644 (file)
 
 #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 "rs_graphicview.h"
+#include "graphicview.h"
 #include "rs_preview.h"
 #include "drawing.h"
 #include "settings.h"
  * Constructor.
  */
 QG_GraphicView::QG_GraphicView(QWidget * parent, const char */*name*/, Qt::WindowFlags f):
-       QWidget(parent, f), RS_GraphicView()//, refCount(0)
+       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;
@@ -45,6 +77,7 @@ QG_GraphicView::QG_GraphicView(QWidget * parent, const char */*name*/, Qt::Windo
 //hrm.
 painter = NULL;
 
+       RS_DEBUG->print("--> Setting up layout...");
        layout = new QGridLayout(this);
        layout->setColumnStretch(0, 1);
        layout->setColumnStretch(1, 0);
@@ -60,6 +93,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...");
        hScrollBar = new QG_ScrollBar(Qt::Horizontal, this);
 //    hScrollBar->setLineStep(50);
        hScrollBar->setSingleStep(50);
@@ -67,8 +101,8 @@ A non-zero alignment indicates that the widget should not grow to fill the avail
        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)));
 
+       RS_DEBUG->print("--> Creating vScrollBar...");
        vScrollBar = new QG_ScrollBar(Qt::Vertical, this);
 //    vScrollBar->setLineStep(50);
        vScrollBar->setSingleStep(50);
@@ -76,6 +110,8 @@ A non-zero alignment indicates that the widget should not grow to fill the avail
        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__
@@ -141,14 +177,10 @@ 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)
+       if (buffer)
        {
                delete buffer;
                buffer = NULL;
@@ -178,7 +210,7 @@ int QG_GraphicView::getHeight()
  */
 void QG_GraphicView::setBackground(const RS_Color & bg)
 {
-       RS_GraphicView::setBackground(bg);
+       GraphicView::setBackground(bg);
 
 //     setBackgroundColor(bg);
        QPalette palette;
@@ -361,19 +393,19 @@ void QG_GraphicView::mousePressEvent(QMouseEvent * e)
        if (e->button() == Qt::MidButton /*|| (e->state()==Qt::LeftButton|Qt::AltButton)*/)
                setCurrentAction(new RS_ActionZoomPan(*container, *this));
 
-       RS_GraphicView::mousePressEvent(e);
+       GraphicView::mousePressEvent(e);
        QWidget::mousePressEvent(e);
 }
 
 void QG_GraphicView::mouseReleaseEvent(QMouseEvent * e)
 {
        RS_DEBUG->print("QG_GraphicView::mouseReleaseEvent");
-       RS_GraphicView::mouseReleaseEvent(e);
+       GraphicView::mouseReleaseEvent(e);
        //QWidget::mouseReleaseEvent(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);
@@ -388,7 +420,7 @@ void QG_GraphicView::mouseMoveEvent(QMouseEvent * e)
        //RS_DEBUG->print("QG_GraphicView::mouseMoveEvent begin");
        //QMouseEvent rsm = QG_Qt2Rs::mouseEvent(e);
 
-       RS_GraphicView::mouseMoveEvent(e);
+       GraphicView::mouseMoveEvent(e);
        QWidget::mouseMoveEvent(e);
 
 //What kind of cacamamie crap is this???
@@ -479,13 +511,13 @@ void QG_GraphicView::tabletEvent(QTabletEvent * e)
 
 void QG_GraphicView::leaveEvent(QEvent * e)
 {
-       RS_GraphicView::mouseLeaveEvent();
+       GraphicView::mouseLeaveEvent();
        QWidget::leaveEvent(e);
 }
 
 void QG_GraphicView::enterEvent(QEvent * e)
 {
-       RS_GraphicView::mouseEnterEvent();
+       GraphicView::mouseEnterEvent();
        QWidget::enterEvent(e);
 }
 
@@ -497,7 +529,7 @@ void QG_GraphicView::focusOutEvent(QFocusEvent * e)
 void QG_GraphicView::focusInEvent(QFocusEvent * e)
 {
 //printf("-->QG_GraphicView::focusInEvent(): Start. this %s focus...\n", (hasFocus() ? "has" : "DOES NOT HAVE"));
-       RS_GraphicView::mouseEnterEvent();
+       GraphicView::mouseEnterEvent();
        QWidget::focusInEvent(e);
 //printf("-->QG_GraphicView::focusInEvent(): End.   this %s focus...\n", (hasFocus() ? "has" : "DOES NOT HAVE"));
 }
@@ -512,11 +544,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 +593,7 @@ Qt::KeyboardModifiers keyState = QApplication::keyboardModifiers();
 
 void QG_GraphicView::keyPressEvent(QKeyEvent * e)
 {
-       if (container == NULL)
+       if (!container)
                return;
 
        bool scroll = false;
@@ -594,12 +625,12 @@ void QG_GraphicView::keyPressEvent(QKeyEvent * e)
        if (scroll)
                setCurrentAction(new RS_ActionZoomScroll(direction, *container, *this));
 
-       RS_GraphicView::keyPressEvent(e);
+       GraphicView::keyPressEvent(e);
 }
 
 void QG_GraphicView::keyReleaseEvent(QKeyEvent * e)
 {
-       RS_GraphicView::keyReleaseEvent(e);
+       GraphicView::keyReleaseEvent(e);
 }
 
 /**
@@ -628,11 +659,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 +805,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