[TD]Navigation Styles - context menu handling & std cursors

This commit is contained in:
Wanderer Fan
2022-06-26 15:03:38 -04:00
committed by WandererFan
parent 60b79e0d72
commit 203b9bb26c
25 changed files with 588 additions and 251 deletions

View File

@@ -113,6 +113,7 @@ public:
bool addView(const App::DocumentObject *obj);
static MDIViewPage *getFromScene(const QGSPage *scene);
void contextMenuEvent(QContextMenuEvent *event);
public Q_SLOTS:
void viewAll();
@@ -133,7 +134,6 @@ protected:
/// Attaches view of obj to m_scene. Returns true on success, false otherwise
bool attachView(App::DocumentObject *obj);
void contextMenuEvent(QContextMenuEvent *event);
void closeEvent(QCloseEvent*);
void setDimensionGroups(void);

View File

@@ -23,6 +23,7 @@
#include "PreCompiled.h"
#ifndef _PreComp_
#include <QApplication>
#include <QContextMenuEvent>
#include <QKeyEvent>
#include <QScrollBar>
#endif
@@ -43,7 +44,8 @@ using namespace TechDrawGui;
namespace TechDrawGui {
QGVNavStyle::QGVNavStyle() : m_viewer(nullptr)
QGVNavStyle::QGVNavStyle(QGVPage *qgvp) :
m_viewer(qgvp)
{
initialize();
}
@@ -78,6 +80,7 @@ void QGVNavStyle::initialize()
m_panPending = false;
m_zoomPending = false;
m_clickButton = Qt::NoButton;
m_saveCursor = getViewer()->cursor();
}
void QGVNavStyle::setAnchor()
@@ -214,7 +217,7 @@ void QGVNavStyle::handleLeaveEvent(QEvent *event)
void QGVNavStyle::handleMousePressEvent(QMouseEvent *event)
{
// Base::Console().Message("QGVNS::handleMousePressEvent()\n");
if (!panningActive && (event->button() == Qt::MiddleButton)) {
if (!panningActive && (event->button() == Qt::MiddleButton)) {
startPan(event->pos());
event->accept();
}
@@ -233,8 +236,11 @@ void QGVNavStyle::handleMouseMoveEvent(QMouseEvent *event)
}
}
//NOTE: QGraphicsView::contextMenuEvent consumes the mouse release event for the
//button that caused the event (typically RMB)
void QGVNavStyle::handleMouseReleaseEvent(QMouseEvent *event)
{
// Base::Console().Message("QGVNS::handleMouseReleaseEvent()\n");
if (getViewer()->isBalloonPlacing()) {
placeBalloon(event->pos());
}
@@ -245,6 +251,21 @@ void QGVNavStyle::handleMouseReleaseEvent(QMouseEvent *event)
}
}
bool QGVNavStyle::allowContextMenu(QContextMenuEvent *event)
{
Q_UNUSED(event)
// Base::Console().Message("QGVNS::allowContextMenu()\n");
// if (event->reason() == QContextMenuEvent::Mouse) {
// //must check for a button combination involving context menu button
// }
return true;
}
void QGVNavStyle::pseudoContextEvent()
{
getViewer()->pseudoContextEvent();
}
void QGVNavStyle::handleWheelEvent(QWheelEvent *event)
{
//Delta is the distance that the wheel is rotated, in eighths of a degree.
@@ -273,6 +294,7 @@ void QGVNavStyle::zoom(double factor)
QPoint newCenter = getViewer()->viewport()->rect().center();
QPoint change = newCenter - center;
getViewer()->translate(change.x(), change.y());
m_zoomPending = false;
}
void QGVNavStyle::startZoom(QPoint p)
@@ -280,11 +302,20 @@ void QGVNavStyle::startZoom(QPoint p)
// Base::Console().Message("QGVNS::startZoom(%s)\n", TechDraw::DrawUtil::formatVector(p).c_str());
zoomOrigin = p;
zoomingActive = true;
m_zoomPending = false;
getViewer()->setZoomCursor();
}
void QGVNavStyle::stopZoom()
{
// Base::Console().Message("QGVNS::stopZoom()\n");
zoomingActive = false;
m_zoomPending = false;
getViewer()->resetCursor();
}
double QGVNavStyle::mouseZoomFactor(QPoint p)
{
// Base::Console().Message("QGVNS::mouseZoomFactor(%s)\n", TechDraw::DrawUtil::formatVector(p).c_str());
QPoint movement = p - zoomOrigin;
double sensitivity = 0.1;
@@ -305,8 +336,8 @@ void QGVNavStyle::startPan(QPoint p)
{
panOrigin = p;
panningActive = true;
QApplication::setOverrideCursor(Qt::SizeAllCursor);
m_panPending = false;
getViewer()->setPanCursor();
}
void QGVNavStyle::pan(QPoint p)
@@ -323,8 +354,10 @@ void QGVNavStyle::pan(QPoint p)
void QGVNavStyle::stopPan()
{
QApplication::restoreOverrideCursor();
// Base::Console().Message("QGVNS::stopPan()\n");
panningActive = false;
m_panPending = false;
getViewer()->resetCursor();
}
void QGVNavStyle::startClick(Qt::MouseButton b)

View File

@@ -26,13 +26,14 @@
#define TECHDRAW_NAVIGATIONSTYLE_H
#include <Mod/TechDraw/TechDrawGlobal.h>
#include <QCursor>
class QEvent;
class QFocusEvent;
class QKeyEvent;
class QMouseEvent;
class QWheelEvent;
class QContextMenuEvent;
#include <Base/BaseClass.h>
namespace TechDrawGui {
@@ -60,7 +61,7 @@ private:
class TechDrawGuiExport QGVNavStyle : public Base::BaseClass
{
public:
QGVNavStyle();
QGVNavStyle(QGVPage* qgvp);
virtual ~QGVNavStyle();
void setViewer(QGVPage* qgvp) { m_viewer = qgvp;} ;
@@ -76,11 +77,13 @@ public:
virtual void handleMouseReleaseEvent(QMouseEvent *event);
virtual void handleWheelEvent(QWheelEvent *event);
virtual bool allowContextMenu() {return true;};
virtual bool allowContextMenu(QContextMenuEvent *event);
virtual void pseudoContextEvent();
virtual void zoom(double factor);
virtual double mouseZoomFactor(QPoint p);
virtual void startZoom(QPoint p);
virtual void zoom(double factor);
virtual void stopZoom();
virtual double mouseZoomFactor(QPoint p);
virtual void startPan(QPoint p);
virtual void pan(QPoint p);
@@ -114,6 +117,7 @@ protected:
Qt::MouseButton m_clickButton;
KeyCombination m_keyCombo;
QCursor m_saveCursor;
private:

View File

@@ -34,7 +34,8 @@ using namespace TechDrawGui;
namespace TechDrawGui {
QGVNavStyleBlender::QGVNavStyleBlender()
QGVNavStyleBlender::QGVNavStyleBlender(QGVPage* qgvp) :
QGVNavStyle(qgvp)
{
}
@@ -52,39 +53,51 @@ void QGVNavStyleBlender::handleKeyReleaseEvent(QKeyEvent *event)
void QGVNavStyleBlender::handleMousePressEvent(QMouseEvent *event)
{
if (event->buttons() == (Qt::LeftButton | Qt::RightButton)) {
//pan mode 1 - LMB + RMB + mouse move
startPan(event->pos());
event->accept();
} else if ((event->button() == Qt::MiddleButton) &&
QGuiApplication::keyboardModifiers().testFlag(Qt::ShiftModifier)) {
//pan mode 2 - Shift + MMB
startPan(event->pos());
event->accept();
}
Q_UNUSED(event)
// Base::Console().Message("QGVNSBlender::handleMousePressEvent() - button: %d buttons: %d\n", event->button(), event->buttons());
}
void QGVNavStyleBlender::handleMouseMoveEvent(QMouseEvent *event)
{
// Base::Console().Message("QGVNSBlender::handleMouseMoveEvent() - buttons: %d modifiers: %X\n",
// QGuiApplication::mouseButtons() & Qt::MiddleButton,
// QGuiApplication::keyboardModifiers().testFlag(Qt::ShiftModifier));
if (getViewer()->isBalloonPlacing()) {
getViewer()->setBalloonCursorPos(event->pos());
}
if (panningActive) {
pan(event->pos());
if ((QGuiApplication::mouseButtons() & Qt::LeftButton) &&
(QGuiApplication::mouseButtons() & Qt::RightButton)) {
//pan mode 1 - LMB + RMB
if (panningActive) {
pan(event->pos());
} else {
startPan(event->pos());
}
event->accept();
} else if ((QGuiApplication::mouseButtons() & Qt::MiddleButton) &&
(QGuiApplication::keyboardModifiers().testFlag(Qt::ShiftModifier)) ) {
//pan mode 2 - Shift + MMB
if (panningActive) {
pan(event->pos());
} else {
startPan(event->pos());
}
event->accept();
}
}
void QGVNavStyleBlender::handleMouseReleaseEvent(QMouseEvent *event)
{
// Base::Console().Message("QGVNSBlender::handleMouseReleaseEvent() - button: %d buttons: %d\n", event->button(), event->buttons());
if (getViewer()->isBalloonPlacing()) {
placeBalloon(event->pos());
}
if (panningActive) {
//pan mode 1 - LMB + RMB + mouse move
//stop panning if either button release
//stop panning if either button released
if ( (event->button() == Qt::LeftButton) ||
(event->button() == Qt::RightButton)) {
stopPan();
@@ -98,4 +111,18 @@ void QGVNavStyleBlender::handleMouseReleaseEvent(QMouseEvent *event)
}
}
}
bool QGVNavStyleBlender::allowContextMenu(QContextMenuEvent *event)
{
// Base::Console().Message("QGVNSBlender::allowContextMenu()\n");
if (event->reason() == QContextMenuEvent::Mouse) {
//must check for a button combination involving context menu button
if (QGuiApplication::mouseButtons() & Qt::LeftButton) {
//LeftButton is down, so this is LMB + RMB - don't allow context menu
return false;
}
}
return true;
}
} // namespace TechDrawGui

View File

@@ -35,7 +35,7 @@ class QGVPage;
class TechDrawGuiExport QGVNavStyleBlender : public QGVNavStyle
{
public:
QGVNavStyleBlender();
QGVNavStyleBlender(QGVPage* qgvp);
virtual ~QGVNavStyleBlender();
virtual void handleKeyReleaseEvent(QKeyEvent *event) override;
@@ -44,7 +44,7 @@ public:
virtual void handleMouseReleaseEvent(QMouseEvent *event) override;
//context menu (RMB) prevents pan mode 2 (LMB + RMB)
virtual bool allowContextMenu() override {return false;};
virtual bool allowContextMenu(QContextMenuEvent *event) override;
protected:
private:

View File

@@ -34,7 +34,8 @@ using namespace TechDrawGui;
namespace TechDrawGui {
QGVNavStyleCAD::QGVNavStyleCAD()
QGVNavStyleCAD::QGVNavStyleCAD(QGVPage* qgvp) :
QGVNavStyle(qgvp)
{
}
@@ -47,7 +48,7 @@ void QGVNavStyleCAD::handleKeyReleaseEvent(QKeyEvent *event)
//zoom mode 2
if ( ((event->key() == Qt::Key_Control) ||
(event->key() == Qt::Key_Shift)) && zoomingActive) {
zoomingActive = false;
stopZoom();
event->accept();
}
@@ -60,25 +61,21 @@ void QGVNavStyleCAD::handleKeyReleaseEvent(QKeyEvent *event)
void QGVNavStyleCAD::handleMousePressEvent(QMouseEvent *event)
{
//pan mode 1 hold MMB + mouse movement
// Base::Console().Message("QGVNSCAD::handleMousePressEvent() - button: %d\n", event->button());
if (event->button() == Qt::MiddleButton) {
startClick(Qt::MiddleButton); //for MMB center view
startPan(event->pos());
event->accept();
}
//zoom mode 2 Control + Shift + RMB click
if ((event->button() == Qt::RightButton) &&
QApplication::keyboardModifiers() == (Qt::ControlModifier | Qt::ShiftModifier)) {
startClick(Qt::RightButton);
event->accept();
}
//pan mode 2 Control + RMB click
if ((event->button() == Qt::RightButton) &&
QApplication::keyboardModifiers() == Qt::ControlModifier) {
startClick(Qt::RightButton);
event->accept();
}
}
@@ -91,23 +88,48 @@ void QGVNavStyleCAD::handleMouseMoveEvent(QMouseEvent *event)
//if the mouse moves between press and release, then it isn't a click
if (m_clickPending) {
stopClick();
event->accept();
return;
}
if (panningActive) {
//pan mode 1 - MMB + move
if (QGuiApplication::mouseButtons() & Qt::MiddleButton) {
if (panningActive) {
pan(event->pos());
event->accept();
} else {
startPan(event->pos());
event->accept();
}
}
//pan mode 2 - CNTL + RMB click + move
if (QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier) &&
panningActive) {
pan(event->pos());
event->accept();
} else if (QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier) &&
m_panPending) {
startPan(event->pos());
event->accept();
}
if (zoomingActive) {
//zoom mode 2 - CNTL + SHIFT + RMB click + move
if (QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier) &&
QGuiApplication::keyboardModifiers().testFlag(Qt::ShiftModifier) &&
zoomingActive) {
zoom(mouseZoomFactor(event->pos()));
event->accept();
} else if (QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier) &&
QGuiApplication::keyboardModifiers().testFlag(Qt::ShiftModifier) &&
m_zoomPending) {
startZoom(event->pos());
event->accept();
}
}
void QGVNavStyleCAD::handleMouseReleaseEvent(QMouseEvent *event)
{
// Base::Console().Message("QGVNSCAD::handleMouseReleaseEvent() - button: %d\n", event->button());
if (getViewer()->isBalloonPlacing()) {
placeBalloon(event->pos());
}
@@ -127,24 +149,40 @@ void QGVNavStyleCAD::handleMouseReleaseEvent(QMouseEvent *event)
//zoom mode 2 Control + Shift + RMB click
if ((event->button() == Qt::RightButton) &&
QApplication::keyboardModifiers() == (Qt::ControlModifier | Qt::ShiftModifier) &&
m_clickPending) {
QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier) &&
QGuiApplication::keyboardModifiers().testFlag(Qt::ShiftModifier) &&
m_clickPending &&
(m_clickButton == Qt::RightButton)) {
stopClick();
startZoom(event->pos());
m_zoomPending = true;
event->accept();
return;
}
//pan mode 2 starts with Control + RMB click
if ((event->button() == Qt::RightButton) &&
QApplication::keyboardModifiers() == (Qt::ControlModifier) &&
m_clickPending) {
QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier) &&
m_clickPending &&
(m_clickButton == Qt::RightButton)) {
stopClick();
startPan(event->pos());
m_panPending = true;
event->accept();
}
}
bool QGVNavStyleCAD::allowContextMenu(QContextMenuEvent *event)
{
// Base::Console().Message("QGVNSCAD::allowContextMenu()\n");
if (event->reason() == QContextMenuEvent::Mouse) {
//must check for a button combination involving context menu button
if (QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier) ||
(QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier) &&
QGuiApplication::keyboardModifiers().testFlag(Qt::ShiftModifier)) ) {
//CNTL or CNTL+Shift down - don't allow context menu
return false;
}
}
return true;
}
} // namespace TechDrawGui

View File

@@ -35,7 +35,7 @@ class QGVPage;
class TechDrawGuiExport QGVNavStyleCAD : public QGVNavStyle
{
public:
QGVNavStyleCAD();
QGVNavStyleCAD(QGVPage* qgvp);
virtual ~QGVNavStyleCAD();
virtual void handleKeyReleaseEvent(QKeyEvent *event) override;
@@ -44,7 +44,7 @@ public:
virtual void handleMouseReleaseEvent(QMouseEvent *event) override;
//context menu (RMB) prevents pan mode 2 (LMB + RMB)
virtual bool allowContextMenu() override {return false;};
virtual bool allowContextMenu(QContextMenuEvent *event) override;
protected:
private:

View File

@@ -34,7 +34,8 @@ using namespace TechDrawGui;
namespace TechDrawGui {
QGVNavStyleGesture::QGVNavStyleGesture()
QGVNavStyleGesture::QGVNavStyleGesture(QGVPage* qgvp) :
QGVNavStyle(qgvp)
{
}
@@ -45,10 +46,8 @@ QGVNavStyleGesture::~QGVNavStyleGesture()
void QGVNavStyleGesture::handleMousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::RightButton) {
startPan(event->pos());
event->accept();
startClick(Qt::RightButton);
}
}
void QGVNavStyleGesture::handleMouseMoveEvent(QMouseEvent *event)
@@ -57,8 +56,19 @@ void QGVNavStyleGesture::handleMouseMoveEvent(QMouseEvent *event)
getViewer()->setBalloonCursorPos(event->pos());
}
if (panningActive) {
pan(event->pos());
//if the mouse moves between press and release, then it isn't a click
if (m_clickPending) {
stopClick();
return;
}
if (QGuiApplication::mouseButtons() & Qt::RightButton) {
//pan mode 1 - RMB + move
if (panningActive) {
pan(event->pos());
} else {
startPan(event->pos());
}
event->accept();
}
}
@@ -69,10 +79,28 @@ void QGVNavStyleGesture::handleMouseReleaseEvent(QMouseEvent *event)
placeBalloon(event->pos());
}
if ((event->button() == Qt::RightButton) &&
m_clickPending &&
(m_clickButton == Qt::RightButton)) {
stopClick();
pseudoContextEvent();
event->accept();
return;
}
if (event->button() == Qt::RightButton) {
stopPan();
event->accept();
}
}
//RMB for pan conflicts with RMB for context menu
bool QGVNavStyleGesture::allowContextMenu(QContextMenuEvent *event)
{
if (event->reason() == QContextMenuEvent::Mouse) {
return false;
}
return true;
}
} // namespace TechDrawGui

View File

@@ -35,14 +35,14 @@ class QGVPage;
class TechDrawGuiExport QGVNavStyleGesture : public QGVNavStyle
{
public:
QGVNavStyleGesture();
QGVNavStyleGesture(QGVPage* qgvp);
virtual ~QGVNavStyleGesture();
virtual void handleMousePressEvent(QMouseEvent *event) override;
virtual void handleMouseMoveEvent(QMouseEvent *event) override;
virtual void handleMouseReleaseEvent(QMouseEvent *event) override;
virtual bool allowContextMenu() override {return false;};
virtual bool allowContextMenu(QContextMenuEvent *event) override;
protected:
private:

View File

@@ -41,7 +41,8 @@ namespace TechDrawGui {
// QGraphicsView?
//**********
QGVNavStyleInventor::QGVNavStyleInventor()
QGVNavStyleInventor::QGVNavStyleInventor(QGVPage *qgvp) :
QGVNavStyle(qgvp)
{
}
@@ -51,15 +52,7 @@ QGVNavStyleInventor::~QGVNavStyleInventor()
void QGVNavStyleInventor::handleMousePressEvent(QMouseEvent *event)
{
if (event->buttons() == (Qt::LeftButton | Qt::MiddleButton)) {
//zoom mode 2 LMB + MMB
startZoom(event->pos());
event->accept();
} else if (event->button() == Qt::MiddleButton) {
//pan mode MMB + mouse movement
startPan(event->pos());
event->accept();
}
Q_UNUSED(event)
}
void QGVNavStyleInventor::handleMouseMoveEvent(QMouseEvent *event)
@@ -68,13 +61,22 @@ void QGVNavStyleInventor::handleMouseMoveEvent(QMouseEvent *event)
getViewer()->setBalloonCursorPos(event->pos());
}
if (panningActive) {
pan(event->pos());
if ((QGuiApplication::mouseButtons() & Qt::LeftButton) &&
(QGuiApplication::mouseButtons() & Qt::MiddleButton)) {
//zoom mode 2 - LMB + MMB
if (zoomingActive) {
zoom(mouseZoomFactor(event->pos()));
} else {
startZoom(event->pos());
}
event->accept();
}
if (zoomingActive) {
zoom(mouseZoomFactor(event->pos()));
} else if (QGuiApplication::mouseButtons() & Qt::MiddleButton) {
//pan mode - MMB + move
if (panningActive) {
pan(event->pos());
} else {
startPan(event->pos());
}
event->accept();
}
}

View File

@@ -35,7 +35,7 @@ class QGVPage;
class TechDrawGuiExport QGVNavStyleInventor : public QGVNavStyle
{
public:
QGVNavStyleInventor();
QGVNavStyleInventor(QGVPage* qgvp);
virtual ~QGVNavStyleInventor();
virtual void handleMousePressEvent(QMouseEvent *event) override;

View File

@@ -34,14 +34,8 @@ using namespace TechDrawGui;
namespace TechDrawGui {
//******
// Issue: on linux mint, ALT + mouse button doesn't get to the application.
// system eats the event for menus, accessibility magnifier, etc.
// only wheel zoom is known to work.
// need to test in different environment.
//******
QGVNavStyleMaya::QGVNavStyleMaya()
QGVNavStyleMaya::QGVNavStyleMaya(QGVPage *qgvp) :
QGVNavStyle(qgvp)
{
}
@@ -65,19 +59,7 @@ void QGVNavStyleMaya::handleKeyReleaseEvent(QKeyEvent *event)
}
void QGVNavStyleMaya::handleMousePressEvent(QMouseEvent *event)
{
//pan mode alt + MMB + mouse movement
if ((event->button() == Qt::MiddleButton) &&
(QApplication::keyboardModifiers() == Qt::AltModifier)) {
startPan(event->pos());
event->accept();
}
//zoom mode 2 ALT + RMB
if ((event->button() == Qt::RightButton) &&
(QApplication::keyboardModifiers() == Qt::AltModifier)) {
startZoom(event->pos());
event->accept();
}
Q_UNUSED(event)
}
void QGVNavStyleMaya::handleMouseMoveEvent(QMouseEvent *event)
@@ -86,13 +68,25 @@ void QGVNavStyleMaya::handleMouseMoveEvent(QMouseEvent *event)
getViewer()->setBalloonCursorPos(event->pos());
}
if (panningActive) {
pan(event->pos());
//pan mode alt + MMB + mouse movement
if (QGuiApplication::mouseButtons() & Qt::MiddleButton &&
QApplication::keyboardModifiers().testFlag(Qt::AltModifier)) {
if (panningActive) {
pan(event->pos());
} else {
startPan(event->pos());
}
event->accept();
}
if (zoomingActive) {
zoom(mouseZoomFactor(event->pos()));
//zoom mode 2 ALT + RMB
if (QGuiApplication::mouseButtons() & Qt::RightButton &&
QApplication::keyboardModifiers().testFlag(Qt::AltModifier)) {
if (zoomingActive) {
zoom(mouseZoomFactor(event->pos()));
} else {
startZoom(event->pos());
}
event->accept();
}
}
@@ -120,4 +114,16 @@ void QGVNavStyleMaya::handleMouseReleaseEvent(QMouseEvent *event)
}
}
bool QGVNavStyleMaya::allowContextMenu(QContextMenuEvent *event)
{
// Base::Console().Message("QGVNSM::allowContextMenu()\n");
if (event->reason() == QContextMenuEvent::Mouse) {
//must check for a button combination involving context menu button
if (QApplication::keyboardModifiers() == Qt::AltModifier) {
//Alt is down, so this is Alt + RMB - don't allow context menu
return false;
}
}
return true;
}
} // namespace TechDrawGui

View File

@@ -35,7 +35,7 @@ class QGVPage;
class TechDrawGuiExport QGVNavStyleMaya : public QGVNavStyle
{
public:
QGVNavStyleMaya();
QGVNavStyleMaya(QGVPage* qgvp);
virtual ~QGVNavStyleMaya();
virtual void handleKeyReleaseEvent(QKeyEvent *event) override;
@@ -43,8 +43,7 @@ public:
virtual void handleMouseMoveEvent(QMouseEvent *event) override;
virtual void handleMouseReleaseEvent(QMouseEvent *event) override;
//context menu (RMB) prevents zoom mode 2 (ALT + RMB)
virtual bool allowContextMenu() override {return false;};
virtual bool allowContextMenu(QContextMenuEvent *event) override;
protected:
private:

View File

@@ -34,7 +34,8 @@ using namespace TechDrawGui;
namespace TechDrawGui {
QGVNavStyleOCC::QGVNavStyleOCC()
QGVNavStyleOCC::QGVNavStyleOCC(QGVPage *qgvp) :
QGVNavStyle(qgvp)
{
}
@@ -46,40 +47,58 @@ void QGVNavStyleOCC::handleKeyReleaseEvent(QKeyEvent *event)
{
//zoom mode 2
if ( (event->key() == Qt::Key_Control) && zoomingActive) {
zoomingActive = false;
event->accept();
}
}
void QGVNavStyleOCC::handleMousePressEvent(QMouseEvent *event)
{
//pan mode MMB + mouse movement
//also Control + MMB + mouse movement, but this is redundant for our purposes
if (event->button() == Qt::MiddleButton) {
startPan(event->pos());
stopZoom();
event->accept();
}
//zoom mode 2 Control + LMB
if ((event->button() == Qt::LeftButton) &&
(QApplication::keyboardModifiers() == Qt::ControlModifier)) {
startZoom(event->pos());
//pan mode
if ( (event->key() == Qt::Key_Control) && panningActive) {
stopPan();
event->accept();
}
}
void QGVNavStyleOCC::handleMousePressEvent(QMouseEvent *event)
{
Q_UNUSED(event)
}
void QGVNavStyleOCC::handleMouseMoveEvent(QMouseEvent *event)
{
if (getViewer()->isBalloonPlacing()) {
getViewer()->setBalloonCursorPos(event->pos());
}
if (panningActive) {
pan(event->pos());
//pan mode 1 - MMB + mouse movement
if (QGuiApplication::mouseButtons() & Qt::MiddleButton) {
if (panningActive) {
pan(event->pos());
} else {
startPan(event->pos());
}
event->accept();
}
if (zoomingActive) {
zoom(mouseZoomFactor(event->pos()));
//pan mode 2 - CNTL + MMB + mouse movement
if (QGuiApplication::mouseButtons() & Qt::MiddleButton &&
QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier) ) {
if (panningActive) {
pan(event->pos());
} else {
startPan(event->pos());
}
event->accept();
}
//zoom mode 2 Control + LMB
if ((QGuiApplication::mouseButtons() & Qt::LeftButton) &&
QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier) ) {
if (zoomingActive) {
zoom(mouseZoomFactor(event->pos()));
} else {
startZoom(event->pos());
}
event->accept();
}
}
@@ -100,10 +119,24 @@ void QGVNavStyleOCC::handleMouseReleaseEvent(QMouseEvent *event)
if (event->button() == Qt::LeftButton) {
//zoom mode 2 Control + LMB
if (zoomingActive) {
zoomingActive = false;
stopZoom();
event->accept();
}
}
}
bool QGVNavStyleOCC::allowContextMenu(QContextMenuEvent *event)
{
// Base::Console().Message("QGVNSOCC::allowContextMenu()\n");
if (event->reason() == QContextMenuEvent::Mouse) {
//must check for a button combination involving context menu button
if (QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier) ) {
//CNTL is down, so this is CNTL + RMB - don't allow context menu
return false;
}
}
return true;
}
} // namespace TechDrawGui

View File

@@ -35,7 +35,7 @@ class QGVPage;
class TechDrawGuiExport QGVNavStyleOCC : public QGVNavStyle
{
public:
QGVNavStyleOCC();
QGVNavStyleOCC(QGVPage* qgvp);
virtual ~QGVNavStyleOCC();
virtual void handleKeyReleaseEvent(QKeyEvent *event) override;
@@ -43,6 +43,9 @@ public:
virtual void handleMouseMoveEvent(QMouseEvent *event) override;
virtual void handleMouseReleaseEvent(QMouseEvent *event) override;
//context menu (RMB) prevents pan mode 2 (RMB or CNTL+RMB)
virtual bool allowContextMenu(QContextMenuEvent *event) override;
protected:
private:

View File

@@ -34,7 +34,8 @@ using namespace TechDrawGui;
namespace TechDrawGui {
QGVNavStyleOpenSCAD::QGVNavStyleOpenSCAD()
QGVNavStyleOpenSCAD::QGVNavStyleOpenSCAD(QGVPage *qgvp) :
QGVNavStyle(qgvp)
{
}
@@ -46,29 +47,15 @@ void QGVNavStyleOpenSCAD::handleKeyReleaseEvent(QKeyEvent *event)
{
//zoom mode 2
if ( (event->key() == Qt::Key_Shift) && zoomingActive) {
zoomingActive = false;
stopZoom();
event->accept();
}
}
//eat the RMB event so it doesn't trigger MDIViewPage context
void QGVNavStyleOpenSCAD::handleMousePressEvent(QMouseEvent *event)
{
//zoom mode 2 Shift + RMB
if ((event->button() == Qt::RightButton) &&
(QApplication::keyboardModifiers() == Qt::ShiftModifier)) {
startZoom(event->pos());
event->accept();
} else if (event->button() == Qt::RightButton) {
//pan mode
startPan(event->pos());
event->accept();
}
//zoom mode 2 MMB
if (event->button() == Qt::MiddleButton) {
startZoom(event->pos());
event->accept();
if (event->button() == Qt::RightButton) {
startClick(Qt::RightButton);
}
}
@@ -78,13 +65,41 @@ void QGVNavStyleOpenSCAD::handleMouseMoveEvent(QMouseEvent *event)
getViewer()->setBalloonCursorPos(event->pos());
}
if (panningActive) {
pan(event->pos());
//if the mouse moves between press and release, then it isn't a click
if (m_clickPending) {
stopClick();
return;
}
if (QGuiApplication::mouseButtons() & Qt::RightButton &&
!QGuiApplication::keyboardModifiers().testFlag(Qt::ShiftModifier)) {
//pan mode - RMB + move
if (panningActive) {
pan(event->pos());
} else {
startPan(event->pos());
}
event->accept();
}
if (zoomingActive) {
zoom(mouseZoomFactor(event->pos()));
if (QGuiApplication::mouseButtons() & Qt::MiddleButton) {
//zoom mode 1 - MMB + move
if (zoomingActive) {
zoom(mouseZoomFactor(event->pos()));
} else {
startZoom(event->pos());
}
event->accept();
}
if ((QGuiApplication::mouseButtons() & Qt::RightButton) &&
QGuiApplication::keyboardModifiers().testFlag(Qt::ShiftModifier)) {
//zoom mode 2 - SHIFT + RMB + move
if (zoomingActive) {
zoom(mouseZoomFactor(event->pos()));
} else {
startZoom(event->pos());
}
event->accept();
}
}
@@ -95,20 +110,46 @@ void QGVNavStyleOpenSCAD::handleMouseReleaseEvent(QMouseEvent *event)
placeBalloon(event->pos());
}
if ((event->button() == Qt::RightButton) &&
m_clickPending &&
(m_clickButton == Qt::RightButton)) {
stopClick();
pseudoContextEvent();
event->accept();
return;
}
if ((event->button() == Qt::RightButton) && panningActive) {
stopPan();
event->accept();
}
if ((event->button() == Qt::RightButton) && zoomingActive) {
zoomingActive = false;
stopZoom();
event->accept();
}
if ((event->button() == Qt::MiddleButton) && zoomingActive) {
zoomingActive = false;
stopZoom();
event->accept();
}
}
bool QGVNavStyleOpenSCAD::allowContextMenu(QContextMenuEvent *event)
{
// Base::Console().Message("QGVNSCAD::allowContextMenu()\n");
if (event->reason() == QContextMenuEvent::Mouse) {
//must check for a button combination involving context menu button
if (QGuiApplication::keyboardModifiers().testFlag(Qt::ShiftModifier)) {
//Shift down - don't allow context menu
return false;
} else if (m_clickPending) {
//context menu request to be handled by button release
return false;
}
}
return true;
}
} // namespace TechDrawGui

View File

@@ -35,7 +35,7 @@ class QGVPage;
class TechDrawGuiExport QGVNavStyleOpenSCAD : public QGVNavStyle
{
public:
QGVNavStyleOpenSCAD();
QGVNavStyleOpenSCAD(QGVPage* qgvp);
virtual ~QGVNavStyleOpenSCAD();
virtual void handleKeyReleaseEvent(QKeyEvent *event) override;
@@ -43,8 +43,7 @@ public:
virtual void handleMousePressEvent(QMouseEvent *event) override;
virtual void handleMouseReleaseEvent(QMouseEvent *event) override;
//context menu (RMB) prevents pan and zoom
virtual bool allowContextMenu() override {return false;};
virtual bool allowContextMenu(QContextMenuEvent *event) override;
protected:
private:

View File

@@ -34,7 +34,8 @@ using namespace TechDrawGui;
namespace TechDrawGui {
QGVNavStyleRevit::QGVNavStyleRevit()
QGVNavStyleRevit::QGVNavStyleRevit(QGVPage *qgvp) :
QGVNavStyle(qgvp)
{
}
@@ -44,16 +45,8 @@ QGVNavStyleRevit::~QGVNavStyleRevit()
void QGVNavStyleRevit::handleMousePressEvent(QMouseEvent *event)
{
//pan mode 1 - LMB + RMB
if (event->buttons() == (Qt::LeftButton & Qt::RightButton)) {
startPan(event->pos());
event->accept();
}
//pan mode 2 - MMB
if (event->button() == Qt::MiddleButton) {
startPan(event->pos());
event->accept();
if (event->button() == Qt::RightButton) {
startClick(Qt::RightButton);
}
}
@@ -63,8 +56,30 @@ void QGVNavStyleRevit::handleMouseMoveEvent(QMouseEvent *event)
getViewer()->setBalloonCursorPos(event->pos());
}
if (panningActive) {
pan(event->pos());
//if the mouse moves between press and release, then it isn't a click
if (m_clickPending) {
stopClick();
return;
}
//pan mode 1 - MMB + move
if (QGuiApplication::mouseButtons() & Qt::MiddleButton) {
if (panningActive) {
pan(event->pos());
} else {
startPan(event->pos());
}
event->accept();
}
//pan mode 2 - LMB + RMB + move
if (QGuiApplication::mouseButtons() & Qt::LeftButton &&
QGuiApplication::mouseButtons() & Qt::RightButton) {
if (panningActive) {
pan(event->pos());
} else {
startPan(event->pos());
}
event->accept();
}
}
@@ -75,15 +90,39 @@ void QGVNavStyleRevit::handleMouseReleaseEvent(QMouseEvent *event)
placeBalloon(event->pos());
}
if (panningActive) {
//stop panning if any button release
if ( (event->button() == Qt::LeftButton) ||
(event->button() == Qt::RightButton) ||
(event->button() == Qt::MiddleButton) ){
if ((event->button() == Qt::RightButton) &&
m_clickPending &&
(m_clickButton == Qt::RightButton)) {
stopClick();
pseudoContextEvent();
event->accept();
return;
}
//stop panning if any button released
if ( (event->button() == Qt::LeftButton) ||
(event->button() == Qt::RightButton) ||
(event->button() == Qt::MiddleButton) ){
if (panningActive) {
stopPan();
event->accept();
}
}
}
bool QGVNavStyleRevit::allowContextMenu(QContextMenuEvent *event)
{
// Base::Console().Message("QGVNSRevit::allowContextMenu()\n");
if (event->reason() == QContextMenuEvent::Mouse) {
//must check for a button combination involving context menu button
if (QGuiApplication::mouseButtons() & Qt::LeftButton) {
//LMB down - don't allow context menu
return false;
} else if (m_clickPending) {
//context menu request to be handled by button release
return false;
}
}
return true;
}
} // namespace TechDrawGui

View File

@@ -35,15 +35,14 @@ class QGVPage;
class TechDrawGuiExport QGVNavStyleRevit : public QGVNavStyle
{
public:
QGVNavStyleRevit();
QGVNavStyleRevit(QGVPage* qgvp);
virtual ~QGVNavStyleRevit();
virtual void handleMousePressEvent(QMouseEvent *event) override;
virtual void handleMouseMoveEvent(QMouseEvent *event) override;
virtual void handleMouseReleaseEvent(QMouseEvent *event) override;
//context menu (RMB) prevents pan mode 2 (LMB + RMB)
virtual bool allowContextMenu() override {return false;};
virtual bool allowContextMenu(QContextMenuEvent *event) override;
protected:
private:

View File

@@ -38,7 +38,8 @@ using namespace TechDrawGui;
namespace TechDrawGui {
QGVNavStyleTinkerCAD::QGVNavStyleTinkerCAD()
QGVNavStyleTinkerCAD::QGVNavStyleTinkerCAD(QGVPage *qgvp) :
QGVNavStyle(qgvp)
{
}
@@ -48,10 +49,7 @@ QGVNavStyleTinkerCAD::~QGVNavStyleTinkerCAD()
void QGVNavStyleTinkerCAD::handleMousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::MiddleButton) {
startPan(event->pos());
event->accept();
}
Q_UNUSED(event)
}
void QGVNavStyleTinkerCAD::handleMouseMoveEvent(QMouseEvent *event)
@@ -60,8 +58,13 @@ void QGVNavStyleTinkerCAD::handleMouseMoveEvent(QMouseEvent *event)
getViewer()->setBalloonCursorPos(event->pos());
}
if (panningActive) {
pan(event->pos());
//pan mode - MMB + move
if (QGuiApplication::mouseButtons() & Qt::MiddleButton) {
if (panningActive) {
pan(event->pos());
} else {
startPan(event->pos());
}
event->accept();
}
}
@@ -72,8 +75,8 @@ void QGVNavStyleTinkerCAD::handleMouseReleaseEvent(QMouseEvent *event)
placeBalloon(event->pos());
}
if (panningActive) {
if (event->button() == Qt::MiddleButton) {
if (event->button() == Qt::MiddleButton) {
if (panningActive) {
stopPan();
event->accept();
}

View File

@@ -37,7 +37,7 @@ class TechDrawGuiExport QGVNavStyleTinkerCAD : public QGVNavStyle
// TYPESYSTEM_HEADER();
public:
QGVNavStyleTinkerCAD();
QGVNavStyleTinkerCAD(QGVPage* qgvp);
virtual ~QGVNavStyleTinkerCAD();
virtual void handleMouseMoveEvent(QMouseEvent *event) override;

View File

@@ -34,7 +34,8 @@ using namespace TechDrawGui;
namespace TechDrawGui {
QGVNavStyleTouchpad::QGVNavStyleTouchpad()
QGVNavStyleTouchpad::QGVNavStyleTouchpad(QGVPage *qgvp) :
QGVNavStyle(qgvp)
{
}
@@ -64,14 +65,18 @@ void QGVNavStyleTouchpad::handleKeyReleaseEvent(QKeyEvent *event)
{
// Q_UNUSED(event)
if (event->key() == Qt::Key_Shift) {
if (panningActive == true) {
if (panningActive) {
stopPan();
}
zoomingActive = false;
if (zoomingActive) {
stopZoom();
}
event->accept();
}
if (event->key() == Qt::Key_Control) {
zoomingActive = false;
stopZoom();
event->accept();
}
}
@@ -84,35 +89,23 @@ void QGVNavStyleTouchpad::handleMouseMoveEvent(QMouseEvent *event)
if (QApplication::keyboardModifiers() == Qt::ShiftModifier) {
//if shift is down then we are panning
if (!panningActive) {
if (panningActive) {
pan(event->pos());
} else {
startPan(event->pos());
}
zoomingActive = false;
} else if (QApplication::keyboardModifiers() == (Qt::ControlModifier | Qt::ShiftModifier)) {
// if control and shift are down then we are zooming
if (panningActive == true) {
stopPan();
}
if (!zoomingActive) {
startZoom(event->pos());
event->accept();
return; //don't zoom on first movement
}
} else {
if (panningActive == true) {
stopPan();
}
zoomingActive = false;
}
if (panningActive) {
pan(event->pos());
event->accept();
}
if (zoomingActive) {
// setAnchor();
zoom(mouseZoomFactor(event->pos()));
if (QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier) &&
QGuiApplication::keyboardModifiers().testFlag(Qt::ShiftModifier) ) {
//if control and shift are down, then we are zooming
if (zoomingActive) {
setAnchor();
zoom(mouseZoomFactor(event->pos()));
} else {
startZoom(event->pos());
}
event->accept();
}
}
@@ -126,5 +119,4 @@ void QGVNavStyleTouchpad::setAnchor()
}
}
} //namespace TechDrawGui

View File

@@ -35,7 +35,7 @@ class QGVPage;
class TechDrawGuiExport QGVNavStyleTouchpad : public QGVNavStyle
{
public:
QGVNavStyleTouchpad();
QGVNavStyleTouchpad(QGVPage* qgvp);
virtual ~QGVNavStyleTouchpad();
virtual void handleKeyPressEvent(QKeyEvent *event) override;

View File

@@ -24,6 +24,7 @@
#ifndef _PreComp_
# include <QAction>
# include <QApplication>
# include <QBitmap>
# include <QContextMenuEvent>
# include <QFileInfo>
# include <QFileDialog>
@@ -133,6 +134,50 @@
#define INKSCAPE_NS_URI "http://www.inkscape.org/namespaces/inkscape"
#define SODIPODI_NS_URI "http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
/*** pan-style cursor *******/
#define PAN_WIDTH 16
#define PAN_HEIGHT 16
#define PAN_BYTES ((PAN_WIDTH + 7) / 8) * PAN_HEIGHT
#define PAN_HOT_X 7
#define PAN_HOT_Y 7
static unsigned char pan_bitmap[PAN_BYTES] =
{
0xc0, 0x03, 0x60, 0x02, 0x20, 0x04, 0x10, 0x08,
0x68, 0x16, 0x54, 0x2a, 0x73, 0xce, 0x01, 0x80,
0x01, 0x80, 0x73, 0xce, 0x54, 0x2a, 0x68, 0x16,
0x10, 0x08, 0x20, 0x04, 0x40, 0x02, 0xc0, 0x03
};
static unsigned char pan_mask_bitmap[PAN_BYTES] =
{
0xc0,0x03,0xe0,0x03,0xe0,0x07,0xf0,0x0f,0xe8,0x17,0xdc,0x3b,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xdc,0x3b,0xe8,0x17,0xf0,0x0f,0xe0,0x07,0xc0,0x03,
0xc0,0x03
};
/*** zoom-style cursor ******/
#define ZOOM_WIDTH 16
#define ZOOM_HEIGHT 16
#define ZOOM_BYTES ((ZOOM_WIDTH + 7) / 8) * ZOOM_HEIGHT
#define ZOOM_HOT_X 5
#define ZOOM_HOT_Y 7
static unsigned char zoom_bitmap[ZOOM_BYTES] =
{
0x00, 0x0f, 0x80, 0x1c, 0x40, 0x38, 0x20, 0x70,
0x90, 0xe4, 0xc0, 0xcc, 0xf0, 0xfc, 0x00, 0x0c,
0x00, 0x0c, 0xf0, 0xfc, 0xc0, 0xcc, 0x90, 0xe4,
0x20, 0x70, 0x40, 0x38, 0x80, 0x1c, 0x00, 0x0f
};
static unsigned char zoom_mask_bitmap[ZOOM_BYTES] =
{
0x00,0x0f,0x80,0x1f,0xc0,0x3f,0xe0,0x7f,0xf0,0xff,0xf0,0xff,0xf0,0xff,0x00,
0x0f,0x00,0x0f,0xf0,0xff,0xf0,0xff,0xf0,0xff,0xe0,0x7f,0xc0,0x3f,0x80,0x1f,
0x00,0x0f
};
using namespace Gui;
using namespace TechDraw;
using namespace TechDrawGui;
@@ -202,7 +247,9 @@ QGVPage::QGVPage(ViewProviderPage *vp, QGSPage* s, QWidget *parent)
setMouseTracking(true);
viewport()->setMouseTracking(true);
// setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
m_parentMDI = static_cast<MDIViewPage*>(parent);
m_saveContextEvent = nullptr;
setViewportUpdateMode(QGraphicsView::FullViewportUpdate); //this prevents crash when deleting dims.
//scene(view?) indices of dirty regions gets
//out of sync. missing prepareGeometryChange
@@ -219,7 +266,8 @@ QGVPage::QGVPage(ViewProviderPage *vp, QGSPage* s, QWidget *parent)
}
setAlignment(Qt::AlignCenter);
setDragMode(ScrollHandDrag);
// setDragMode(ScrollHandDrag);
setDragMode(QGraphicsView::NoDrag);
resetCursor();
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
@@ -232,6 +280,8 @@ QGVPage::QGVPage(ViewProviderPage *vp, QGSPage* s, QWidget *parent)
resetCachedContent();
initNavigationStyle();
createStandardCursors(devicePixelRatio());
}
QGVPage::~QGVPage()
@@ -265,30 +315,28 @@ void QGVPage::setNavigationStyle(std::string navParm)
std::size_t foundRevit = navParm.find("Revit");
if (foundBlender != std::string::npos) {
m_navStyle = static_cast<QGVNavStyle*>(new QGVNavStyleBlender());
m_navStyle = static_cast<QGVNavStyle*>(new QGVNavStyleBlender(this));
} else if (foundCAD != std::string::npos) {
m_navStyle = static_cast<QGVNavStyle*>(new QGVNavStyleCAD());
m_navStyle = static_cast<QGVNavStyle*>(new QGVNavStyleCAD(this));
} else if (foundTouchPad != std::string::npos) {
m_navStyle = static_cast<QGVNavStyle*>(new QGVNavStyleTouchpad());
m_navStyle = static_cast<QGVNavStyle*>(new QGVNavStyleTouchpad(this));
} else if (foundInventor != std::string::npos) {
m_navStyle = static_cast<QGVNavStyle*>(new QGVNavStyleInventor());
m_navStyle = static_cast<QGVNavStyle*>(new QGVNavStyleInventor(this));
} else if (foundTinker != std::string::npos) {
m_navStyle = static_cast<QGVNavStyle*>(new QGVNavStyleTinkerCAD());
m_navStyle = static_cast<QGVNavStyle*>(new QGVNavStyleTinkerCAD(this));
} else if (foundGesture != std::string::npos) {
m_navStyle = static_cast<QGVNavStyle*>(new QGVNavStyleGesture());
m_navStyle = static_cast<QGVNavStyle*>(new QGVNavStyleGesture(this));
} else if (foundMaya != std::string::npos) {
m_navStyle = static_cast<QGVNavStyle*>(new QGVNavStyleMaya());
m_navStyle = static_cast<QGVNavStyle*>(new QGVNavStyleMaya(this));
} else if (foundOCC != std::string::npos) {
m_navStyle = static_cast<QGVNavStyle*>(new QGVNavStyleOCC());
m_navStyle = static_cast<QGVNavStyle*>(new QGVNavStyleOCC(this));
} else if (foundOpenSCAD != std::string::npos) {
m_navStyle = static_cast<QGVNavStyle*>(new QGVNavStyleOpenSCAD());
m_navStyle = static_cast<QGVNavStyle*>(new QGVNavStyleOpenSCAD(this));
} else if (foundRevit != std::string::npos) {
m_navStyle = static_cast<QGVNavStyle*>(new QGVNavStyleRevit());
m_navStyle = static_cast<QGVNavStyle*>(new QGVNavStyleRevit(this));
} else {
m_navStyle = new QGVNavStyle();
m_navStyle = new QGVNavStyle(this);
}
m_navStyle->setViewer(this);
}
void QGVPage::startBalloonPlacing(void)
@@ -375,25 +423,6 @@ void QGVPage::setHighQualityAntialiasing(bool highQualityAntialiasing)
#endif
}
void QGVPage::contextMenuEvent(QContextMenuEvent *event)
{
if (m_navStyle->allowContextMenu()) {
QGraphicsView::contextMenuEvent(event);
}
//TODO: allow RMB press and context menu
// by triggering pseudo-mousePressEvent, then calling QGV::contextMenuEvent
// QMouseEvent* mouseEvent(QEvent::MouseButtonPress,
// event->pos(), //local pos
// event->globalPos(), //window pos
// event->globalPos(), //screen pos
// Qt::RightButton, //button
// Qt::RightButton, //buttons,
// Qt::NoModifier, //KB modifiers
// Qt::MouseEventSynthesizedByApplication) //source
// m_navStyle->handleMousePressEvent(mouseEvent);
// QGraphicsView::contextMenuEvent(event);
}
void QGVPage::paintEvent(QPaintEvent *event)
{
if (m_renderer == Image) {
@@ -413,6 +442,30 @@ void QGVPage::paintEvent(QPaintEvent *event)
}
}
void QGVPage::contextMenuEvent(QContextMenuEvent *event)
{
if (m_navStyle->allowContextMenu(event)) {
QGraphicsView::contextMenuEvent(event); //this eats the event. mouseReleaseEvent will not be called.
return;
}
//delete the old saved event before creating a new one to avoid memory leak
//NOTE: saving the actual event doesn't work as the event gets deleted somewhere in Qt
if (m_saveContextEvent != nullptr) {
delete m_saveContextEvent;
}
m_saveContextEvent = new QContextMenuEvent(QContextMenuEvent::Mouse,
event->pos(),
event->globalPos());
}
void QGVPage::pseudoContextEvent()
{
if (m_saveContextEvent != nullptr) {
m_parentMDI->contextMenuEvent(m_saveContextEvent);
}
}
void QGVPage::wheelEvent(QWheelEvent *event)
{
m_navStyle->handleWheelEvent(event);
@@ -553,6 +606,16 @@ void QGVPage::resetCursor() {
viewport()->setCursor(Qt::ArrowCursor);
}
void QGVPage::setPanCursor()
{
activateCursor(panCursor);
}
void QGVPage::setZoomCursor()
{
activateCursor(zoomCursor);
}
void QGVPage::drawForeground(QPainter *painter, const QRectF &rect)
{
Q_UNUSED(rect);
@@ -611,4 +674,24 @@ Base::Type QGVPage::getStyleType(std::string model)
return type;
}
void QGVPage::createStandardCursors(double dpr)
{
(void) dpr; //avoid clang warning re unused parameter
QBitmap cursor = QBitmap::fromData(QSize(PAN_WIDTH, PAN_HEIGHT), pan_bitmap);
QBitmap mask = QBitmap::fromData(QSize(PAN_WIDTH, PAN_HEIGHT), pan_mask_bitmap);
#if defined(Q_OS_WIN32)
cursor.setDevicePixelRatio(dpr);
mask.setDevicePixelRatio(dpr);
#endif
panCursor = QCursor(cursor, mask, PAN_HOT_X, PAN_HOT_Y);
cursor = QBitmap::fromData(QSize(ZOOM_WIDTH, ZOOM_HEIGHT), zoom_bitmap);
mask = QBitmap::fromData(QSize(ZOOM_WIDTH, ZOOM_HEIGHT), zoom_mask_bitmap);
#if defined(Q_OS_WIN32)
cursor.setDevicePixelRatio(dpr);
mask.setDevicePixelRatio(dpr);
#endif
zoomCursor = QCursor(cursor, mask, ZOOM_HOT_X, ZOOM_HOT_Y);
}
#include <Mod/TechDraw/Gui/moc_QGVPage.cpp>

View File

@@ -32,8 +32,6 @@
#include <Base/Type.h>
class QTemporaryFile;
namespace App {
class DocumentObject;
}
@@ -59,6 +57,7 @@ class DrawWeldSymbol;
namespace TechDrawGui
{
class MDIViewPage;
class QGSPage;
class QGIView;
class QGIViewDimension;
@@ -92,10 +91,6 @@ public:
void setExporting(bool enable);
/// Renders the page to SVG with filename.
// void saveSvg(QString filename);
// void postProcessXml(QTemporaryFile& tempFile, QString filename, QString pagename);
void makeGrid(int width, int height, double step);
void showGrid(bool state) {m_showGrid = state;}
void updateViewport(void) {viewport()->repaint();}
@@ -110,6 +105,13 @@ public:
QPointF getBalloonCursorPos() {return balloonCursorPos;}
void setBalloonCursorPos(QPoint p) { balloonCursorPos = p;}
void activateCursor(QCursor cursor);
void resetCursor();
void setPanCursor();
void setZoomCursor();
void pseudoContextEvent();
public Q_SLOTS:
void setHighQualityAntialiasing(bool highQualityAntialiasing);
@@ -133,8 +135,6 @@ protected:
double getDevicePixelRatio() const;
QPixmap prepareCursorPixmap(const char *iconName, QPoint &hotspot);
void activateCursor(QCursor cursor);
void resetCursor();
void drawForeground(QPainter *painter, const QRectF &rect) override;
std::string getNavStyleParameter();
@@ -143,6 +143,8 @@ protected:
void initNavigationStyle();
void setNavigationStyle(std::string navParm);
void createStandardCursors(double dpr);
private:
RendererType m_renderer;
@@ -173,6 +175,12 @@ private:
class Private;
std::unique_ptr<Private> d;
QCursor panCursor;
QCursor zoomCursor;
MDIViewPage* m_parentMDI;
QContextMenuEvent* m_saveContextEvent;
};
} // namespace