From: Shamus Hammons Date: Thu, 29 Sep 2011 17:16:39 +0000 (+0000) Subject: Added preliminary zooming and panning. X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f19a3a172c425b7fcc5a648a94870f0247c6be89;p=architektonas Added preliminary zooming and panning. --- diff --git a/src/applicationwindow.cpp b/src/applicationwindow.cpp index fe0c29d..f658a9b 100644 --- a/src/applicationwindow.cpp +++ b/src/applicationwindow.cpp @@ -28,8 +28,9 @@ #include "about.h" #include "drawingview.h" -#include "settingsdialog.h" #include "generaltab.h" +#include "painter.h" +#include "settingsdialog.h" ApplicationWindow::ApplicationWindow(): settings("Underground Software", "Architektonas") @@ -100,6 +101,24 @@ void ApplicationWindow::RotateTool(void) drawing->SetRotateToolActive(rotateAct->isChecked()); } +void ApplicationWindow::ZoomInTool(void) +{ +//printf("Zoom in... level going from %02f to ", Painter::zoom); + // This just zooms leaving origin intact... should zoom in at the current center! +// drawing->ZoomIn(); + Painter::zoom *= 2.0; + drawing->update(); +} + +void ApplicationWindow::ZoomOutTool(void) +{ +//printf("Zoom out...\n"); + // This just zooms leaving origin intact... should zoom out at the current center! +// drawing->ZoomOut(); + Painter::zoom /= 2.0; + drawing->update(); +} + void ApplicationWindow::HelpAbout(void) { aboutWin->show(); @@ -150,6 +169,12 @@ void ApplicationWindow::CreateActions(void) rotateAct = CreateAction(tr("&Rotate Objects"), tr("Rotate"), tr("Rotate object(s) around an arbitrary center."), QIcon(":/res/generic-tool.png"), QKeySequence(tr("R,O")), true); connect(rotateAct, SIGNAL(triggered()), this, SLOT(RotateTool())); + zoomInAct = CreateAction(tr("Zoom &In"), tr("Zoom In"), tr("Zoom in on the document."), QIcon(":/res/generic-tool.png"), QKeySequence(tr("="))); + connect(zoomInAct, SIGNAL(triggered()), this, SLOT(ZoomInTool())); + + zoomOutAct = CreateAction(tr("Zoom &Out"), tr("Zoom Out"), tr("Zoom out of the document."), QIcon(":/res/generic-tool.png"), QKeySequence(tr("-"))); + connect(zoomOutAct, SIGNAL(triggered()), this, SLOT(ZoomOutTool())); + fileNewAct = CreateAction(tr("&New Drawing"), tr("New Drawing"), tr("Creates a new drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(tr("Ctrl+n"))); fileOpenAct = CreateAction(tr("&Open Drawing"), tr("Open Drawing"), tr("Opens an existing drawing from a file."), QIcon(":/res/generic-tool.png"), QKeySequence(tr("Ctrl+o"))); @@ -217,6 +242,10 @@ void ApplicationWindow::CreateMenus(void) menu->addSeparator(); menu->addAction(exitAct); + menu = menuBar()->addMenu(tr("&View")); + menu->addAction(zoomInAct); + menu->addAction(zoomOutAct); + menu = menuBar()->addMenu(tr("&Edit")); menu->addAction(fixAngleAct); menu->addAction(fixLengthAct); @@ -248,6 +277,10 @@ void ApplicationWindow::CreateToolbars(void) QToolBar * toolbar = addToolBar(tr("File")); toolbar->addAction(exitAct); + toolbar = addToolBar(tr("View")); + toolbar->addAction(zoomInAct); + toolbar->addAction(zoomOutAct); + toolbar = addToolBar(tr("Edit")); toolbar->addAction(fixAngleAct); toolbar->addAction(fixLengthAct); diff --git a/src/applicationwindow.h b/src/applicationwindow.h index 99b5441..199c4b2 100644 --- a/src/applicationwindow.h +++ b/src/applicationwindow.h @@ -28,6 +28,8 @@ class ApplicationWindow: public QMainWindow void DeleteTool(void); void DimensionTool(void); void RotateTool(void); + void ZoomInTool(void); + void ZoomOutTool(void); void HelpAbout(void); void Settings(void); @@ -42,8 +44,6 @@ class ApplicationWindow: public QMainWindow void ReadSettings(void); void WriteSettings(void); -// EditWindow * editWnd; -// CharWindow * charWnd; DrawingView * drawing; AboutWindow * aboutWin; @@ -65,6 +65,8 @@ class ApplicationWindow: public QMainWindow QAction * addArcAct; QAction * aboutAct; QAction * rotateAct; + QAction * zoomInAct; + QAction * zoomOutAct; }; #endif // __APPLICATIONWINDOW_H__ diff --git a/src/drawingview.cpp b/src/drawingview.cpp index a5349d9..a3a6eb1 100644 --- a/src/drawingview.cpp +++ b/src/drawingview.cpp @@ -42,7 +42,8 @@ DrawingView::DrawingView(QWidget * parent/*= NULL*/): QWidget(parent), useAntialiasing(true), scale(1.0), offsetX(-10), offsetY(-10), document(Vector(0, 0)), - gridSpacing(32.0), collided(false), rotateTool(false), rx(150.0), ry(150.0) + gridSpacing(32.0), collided(false), rotateTool(false), rx(150.0), ry(150.0), + scrollDrag(false) { setBackgroundRole(QPalette::Base); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); @@ -76,6 +77,17 @@ void DrawingView::SetRotateToolActive(bool state/*= true*/) update(); } +//These are not needed... :-P +#if 0 +void DrawingView::ZoomIn(void) +{ +} + +void DrawingView::ZoomOut(void); +{ +} +#endif + QPoint DrawingView::GetAdjustedMousePosition(QMouseEvent * event) { // This is undoing the transform, e.g. going from client coords to local coords. @@ -101,7 +113,7 @@ void DrawingView::paintEvent(QPaintEvent * /*event*/) qtPainter.setRenderHint(QPainter::Antialiasing); Painter::screenSize = Vector(size().width(), size().height()); - Painter::zoom = 2.0; // 200% zoom +// Painter::zoom = 2.0; // 200% zoom #if 0 #if 0 painter.translate(QPoint(-offsetX, size.height() - (-offsetY))); @@ -164,23 +176,39 @@ void DrawingView::mousePressEvent(QMouseEvent * event) { if (event->button() == Qt::LeftButton) { -// QPoint pt = GetAdjustedMousePosition(event); -// Vector point(pt.x(), pt.y()); Vector point = Painter::QtToCartesianCoords(Vector(event->x(), event->y())); - collided = document.Collided(point); if (collided) update(); // Do an update if collided with at least *one* object in the document } + else if (event->button() == Qt::MiddleButton) + { + scrollDrag = true; + oldPoint = Vector(event->x(), event->y()); + // Should also change the mouse pointer as well... + setCursor(Qt::SizeAllCursor); + } } void DrawingView::mouseMoveEvent(QMouseEvent * event) { -// QPoint pt = GetAdjustedMousePosition(event); -// Vector point(pt.x(), pt.y()); Vector point = Painter::QtToCartesianCoords(Vector(event->x(), event->y())); + if (event->buttons() & Qt::MiddleButton) + { + point = Vector(event->x(), event->y()); + // Since we're using Qt coords for scrolling, we have to adjust them here to + // conform to Cartesian coords, since the origin is using them. :-) + Vector delta(point, oldPoint); + delta /= Painter::zoom; + delta.y = -delta.y; + Painter::origin -= delta; + update(); + oldPoint = point; + return; + } + // Grid processing... #if 1 // This looks strange, but it's really quite simple: We want a point that's @@ -220,6 +248,11 @@ void DrawingView::mouseReleaseEvent(QMouseEvent * event) // if (collided) update(); // Do an update if collided with at least *one* object in the document } + else if (event->button() == Qt::MiddleButton) + { + scrollDrag = false; + setCursor(Qt::ArrowCursor); + } } diff --git a/src/drawingview.h b/src/drawingview.h index 02baa30..dfb9f8f 100644 --- a/src/drawingview.h +++ b/src/drawingview.h @@ -14,6 +14,8 @@ class DrawingView: public QWidget public: void SetRotateToolActive(bool state = true); +// void ZoomIn(void); +// void ZoomOut(void); protected: void paintEvent(QPaintEvent * event); @@ -37,6 +39,8 @@ class DrawingView: public QWidget //Should this go into Object's class variables??? bool rotateTool; double rx, ry; + bool scrollDrag; + Vector oldPoint; /* QSize minimumSizeHint() const; QSize sizeHint() const; diff --git a/src/vector.cpp b/src/vector.cpp index e9ad51f..58228ca 100644 --- a/src/vector.cpp +++ b/src/vector.cpp @@ -133,6 +133,24 @@ Vector& Vector::operator+=(double const v) return *this; } +// Vector - vector, self assigned + +Vector& Vector::operator-=(Vector const v) +{ + x -= v.x, y -= v.y, z -= v.z; + + return *this; +} + +// Vector - constant, self assigned + +Vector& Vector::operator-=(double const v) +{ + x -= v, y -= v, z -= v; + + return *this; +} + Vector Vector::Unit(void) { diff --git a/src/vector.h b/src/vector.h index 81a715f..0551ea8 100644 --- a/src/vector.h +++ b/src/vector.h @@ -32,6 +32,8 @@ class Vector Vector& operator/=(double const v); // Vector divided by constant self-assignment Vector& operator+=(Vector const v); // Vector plus Vector self-assignment Vector& operator+=(double const v); // Vector plus constant self-assignment + Vector& operator-=(Vector const v); // Vector minus Vector self-assignment + Vector& operator-=(double const v); // Vector minus constant self-assignment Vector Unit(void); double Magnitude(void);