[TD]Allow balloons to be attached to non-part views
This commit is contained in:
@@ -22,9 +22,9 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <QContextMenuEvent>
|
||||
# include <QKeyEvent>
|
||||
# include <QScrollBar>
|
||||
#include <QContextMenuEvent>
|
||||
#include <QKeyEvent>
|
||||
#include <QScrollBar>
|
||||
#endif
|
||||
|
||||
#include <App/Application.h>
|
||||
@@ -32,24 +32,19 @@
|
||||
#include <Base/Parameter.h>
|
||||
#include <Mod/TechDraw/App/DrawPage.h>
|
||||
|
||||
#include "QGVNavStyle.h"
|
||||
#include "QGSPage.h"
|
||||
#include "QGVNavStyle.h"
|
||||
#include "QGVPage.h"
|
||||
|
||||
|
||||
using namespace TechDrawGui;
|
||||
|
||||
namespace TechDrawGui {
|
||||
|
||||
QGVNavStyle::QGVNavStyle(QGVPage *qgvp) :
|
||||
m_viewer(qgvp)
|
||||
namespace TechDrawGui
|
||||
{
|
||||
initialize();
|
||||
}
|
||||
|
||||
QGVNavStyle::~QGVNavStyle()
|
||||
{
|
||||
}
|
||||
QGVNavStyle::QGVNavStyle(QGVPage* qgvp) : m_viewer(qgvp) { initialize(); }
|
||||
|
||||
QGVNavStyle::~QGVNavStyle() {}
|
||||
|
||||
void QGVNavStyle::initialize()
|
||||
{
|
||||
@@ -59,15 +54,21 @@ void QGVNavStyle::initialize()
|
||||
this->ctrldown = false;
|
||||
this->shiftdown = false;
|
||||
this->altdown = false;
|
||||
this->invertZoom = App::GetApplication().GetParameterGroupByPath
|
||||
("User parameter:BaseApp/Preferences/View")->GetBool("InvertZoom", true);
|
||||
this->zoomAtCursor = App::GetApplication().GetParameterGroupByPath
|
||||
("User parameter:BaseApp/Preferences/View")->GetBool("ZoomAtCursor", true);
|
||||
this->zoomStep = App::GetApplication().GetParameterGroupByPath
|
||||
("User parameter:BaseApp/Preferences/View")->GetFloat("ZoomStep", 0.2f);
|
||||
this->invertZoom = App::GetApplication()
|
||||
.GetParameterGroupByPath("User parameter:BaseApp/Preferences/View")
|
||||
->GetBool("InvertZoom", true);
|
||||
this->zoomAtCursor = App::GetApplication()
|
||||
.GetParameterGroupByPath("User parameter:BaseApp/Preferences/View")
|
||||
->GetBool("ZoomAtCursor", true);
|
||||
this->zoomStep = App::GetApplication()
|
||||
.GetParameterGroupByPath("User parameter:BaseApp/Preferences/View")
|
||||
->GetFloat("ZoomStep", 0.2f);
|
||||
|
||||
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
|
||||
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/General");
|
||||
Base::Reference<ParameterGrp> hGrp = App::GetApplication()
|
||||
.GetUserParameter()
|
||||
.GetGroup("BaseApp")
|
||||
->GetGroup("Preferences")
|
||||
->GetGroup("Mod/TechDraw/General");
|
||||
m_reversePan = hGrp->GetInt("KbPan", 1);
|
||||
m_reverseScroll = hGrp->GetInt("KbScroll", 1);
|
||||
|
||||
@@ -88,14 +89,15 @@ void QGVNavStyle::setAnchor()
|
||||
if (zoomAtCursor) {
|
||||
m_viewer->setResizeAnchor(QGraphicsView::AnchorUnderMouse);
|
||||
m_viewer->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
m_viewer->setResizeAnchor(QGraphicsView::AnchorViewCenter);
|
||||
m_viewer->setTransformationAnchor(QGraphicsView::AnchorViewCenter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QGVNavStyle::handleEnterEvent(QEvent *event)
|
||||
void QGVNavStyle::handleEnterEvent(QEvent* event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
if (getViewer()->isBalloonPlacing()) {
|
||||
@@ -103,16 +105,16 @@ void QGVNavStyle::handleEnterEvent(QEvent *event)
|
||||
}
|
||||
}
|
||||
|
||||
void QGVNavStyle::handleFocusOutEvent(QFocusEvent *event)
|
||||
void QGVNavStyle::handleFocusOutEvent(QFocusEvent* event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
getViewer()->cancelBalloonPlacing();
|
||||
}
|
||||
|
||||
void QGVNavStyle::handleKeyPressEvent(QKeyEvent *event)
|
||||
void QGVNavStyle::handleKeyPressEvent(QKeyEvent* event)
|
||||
{
|
||||
if(event->modifiers().testFlag(Qt::ControlModifier)) {
|
||||
switch(event->key()) {
|
||||
if (event->modifiers().testFlag(Qt::ControlModifier)) {
|
||||
switch (event->key()) {
|
||||
case Qt::Key_Plus: {
|
||||
zoom(1.0 + zoomStep);
|
||||
event->accept();
|
||||
@@ -129,8 +131,8 @@ void QGVNavStyle::handleKeyPressEvent(QKeyEvent *event)
|
||||
}
|
||||
}
|
||||
|
||||
if(event->modifiers().testFlag( Qt::NoModifier)) {
|
||||
switch(event->key()) {
|
||||
if (event->modifiers().testFlag(Qt::NoModifier)) {
|
||||
switch (event->key()) {
|
||||
case Qt::Key_Left: {
|
||||
getViewer()->kbPanScroll(1, 0);
|
||||
event->accept();
|
||||
@@ -168,11 +170,11 @@ void QGVNavStyle::handleKeyPressEvent(QKeyEvent *event)
|
||||
}
|
||||
}
|
||||
|
||||
void QGVNavStyle::handleKeyReleaseEvent(QKeyEvent *event)
|
||||
void QGVNavStyle::handleKeyReleaseEvent(QKeyEvent* event)
|
||||
{
|
||||
// Q_UNUSED(event);
|
||||
if(event->modifiers().testFlag( Qt::NoModifier)) {
|
||||
switch(event->key()) {
|
||||
// Q_UNUSED(event);
|
||||
if (event->modifiers().testFlag(Qt::NoModifier)) {
|
||||
switch (event->key()) {
|
||||
case Qt::Key_Shift: {
|
||||
this->shiftdown = false;
|
||||
event->accept();
|
||||
@@ -185,14 +187,15 @@ void QGVNavStyle::handleKeyReleaseEvent(QKeyEvent *event)
|
||||
}
|
||||
}
|
||||
|
||||
void QGVNavStyle::handleLeaveEvent(QEvent *event)
|
||||
void QGVNavStyle::handleLeaveEvent(QEvent* event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
if (getViewer()->isBalloonPlacing()) {
|
||||
int left_x;
|
||||
if (getViewer()->getBalloonCursorPos().x() < 32)
|
||||
left_x = 0;
|
||||
else if (getViewer()->getBalloonCursorPos().x() > (getViewer()->contentsRect().right() - 32))
|
||||
else if (getViewer()->getBalloonCursorPos().x()
|
||||
> (getViewer()->contentsRect().right() - 32))
|
||||
left_x = getViewer()->contentsRect().right() - 32;
|
||||
else
|
||||
left_x = getViewer()->getBalloonCursorPos().x();
|
||||
@@ -200,29 +203,30 @@ void QGVNavStyle::handleLeaveEvent(QEvent *event)
|
||||
int left_y;
|
||||
if (getViewer()->getBalloonCursorPos().y() < 32)
|
||||
left_y = 0;
|
||||
else if (getViewer()->getBalloonCursorPos().y() > (getViewer()->contentsRect().bottom() - 32))
|
||||
else if (getViewer()->getBalloonCursorPos().y()
|
||||
> (getViewer()->contentsRect().bottom() - 32))
|
||||
left_y = getViewer()->contentsRect().bottom() - 32;
|
||||
else
|
||||
left_y = getViewer()->getBalloonCursorPos().y();
|
||||
|
||||
/* When cursor leave the page, display getViewer()->balloonCursor where it left */
|
||||
getViewer()->getBalloonCursor()->setGeometry(left_x ,left_y, 32, 32);
|
||||
getViewer()->getBalloonCursor()->setGeometry(left_x, left_y, 32, 32);
|
||||
getViewer()->getBalloonCursor()->show();
|
||||
}
|
||||
}
|
||||
|
||||
void QGVNavStyle::handleMousePressEvent(QMouseEvent *event)
|
||||
void QGVNavStyle::handleMousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
// Base::Console().Message("QGVNS::handleMousePressEvent()\n");
|
||||
// Base::Console().Message("QGVNS::handleMousePressEvent()\n");
|
||||
if (!panningActive && (event->button() == Qt::MiddleButton)) {
|
||||
startPan(event->pos());
|
||||
event->accept();
|
||||
}
|
||||
}
|
||||
|
||||
void QGVNavStyle::handleMouseMoveEvent(QMouseEvent *event)
|
||||
void QGVNavStyle::handleMouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
// Base::Console().Message("QGVNS::handleMouseMoveEvent()\n");
|
||||
// Base::Console().Message("QGVNS::handleMouseMoveEvent()\n");
|
||||
if (getViewer()->isBalloonPlacing()) {
|
||||
getViewer()->setBalloonCursorPos(event->pos());
|
||||
}
|
||||
@@ -235,9 +239,9 @@ 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)
|
||||
void QGVNavStyle::handleMouseReleaseEvent(QMouseEvent* event)
|
||||
{
|
||||
// Base::Console().Message("QGVNS::handleMouseReleaseEvent()\n");
|
||||
// Base::Console().Message("QGVNS::handleMouseReleaseEvent()\n");
|
||||
if (getViewer()->isBalloonPlacing()) {
|
||||
placeBalloon(event->pos());
|
||||
}
|
||||
@@ -248,30 +252,27 @@ void QGVNavStyle::handleMouseReleaseEvent(QMouseEvent *event)
|
||||
}
|
||||
}
|
||||
|
||||
bool QGVNavStyle::allowContextMenu(QContextMenuEvent *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
|
||||
// }
|
||||
// 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::pseudoContextEvent() { getViewer()->pseudoContextEvent(); }
|
||||
|
||||
void QGVNavStyle::handleWheelEvent(QWheelEvent *event)
|
||||
void QGVNavStyle::handleWheelEvent(QWheelEvent* event)
|
||||
{
|
||||
//gets called once for every click of the wheel. the sign of event->angleDelta().y()
|
||||
//gives the direction of wheel rotation. positive indicates rotation forwards away
|
||||
//from the user; negative backwards toward the user. the magnitude of
|
||||
//event->angleDelta().y() is 120 for most mice which represents 120/8 = 15 degrees of
|
||||
//rotation. Some high resolution mice/trackpads report smaller values - ie a click is less than
|
||||
//15 degrees of wheel rotation.
|
||||
//https://doc.qt.io/qt-5/qwheelevent.html#angleDelta
|
||||
//gets called once for every click of the wheel. the sign of event->angleDelta().y()
|
||||
//gives the direction of wheel rotation. positive indicates rotation forwards away
|
||||
//from the user; negative backwards toward the user. the magnitude of
|
||||
//event->angleDelta().y() is 120 for most mice which represents 120/8 = 15 degrees of
|
||||
//rotation. Some high resolution mice/trackpads report smaller values - ie a click is less than
|
||||
//15 degrees of wheel rotation.
|
||||
//https://doc.qt.io/qt-5/qwheelevent.html#angleDelta
|
||||
//to avoid overly sensitive behaviour in high resolution mice/touchpads,
|
||||
//save up wheel clicks until the wheel has rotated at least 15 degrees.
|
||||
constexpr int wheelDeltaThreshold = 120;
|
||||
@@ -281,7 +282,7 @@ void QGVNavStyle::handleWheelEvent(QWheelEvent *event)
|
||||
}
|
||||
m_wheelDeltaCounter = 0;
|
||||
//starting with -ve direction keeps us in sync with the behaviour of the 3d window
|
||||
int rotationDirection = - event->angleDelta().y() / std::abs(event->angleDelta().y());
|
||||
int rotationDirection = -event->angleDelta().y() / std::abs(event->angleDelta().y());
|
||||
if (invertZoom) {
|
||||
rotationDirection = -rotationDirection;
|
||||
}
|
||||
@@ -294,21 +295,19 @@ void QGVNavStyle::zoom(double factor)
|
||||
constexpr double minimumScale(0.01);
|
||||
QTransform transform = getViewer()->transform();
|
||||
double xScale = transform.m11();
|
||||
if (xScale <= minimumScale &&
|
||||
factor < 1.0) {
|
||||
if (xScale <= minimumScale && factor < 1.0) {
|
||||
//don't scale any smaller than this
|
||||
return;
|
||||
}
|
||||
|
||||
setAnchor();
|
||||
getViewer()->scale(factor,
|
||||
factor);
|
||||
getViewer()->scale(factor, factor);
|
||||
m_zoomPending = false;
|
||||
}
|
||||
|
||||
void QGVNavStyle::startZoom(QPoint p)
|
||||
{
|
||||
// Base::Console().Message("QGVNS::startZoom(%s)\n", TechDraw::DrawUtil::formatVector(p).c_str());
|
||||
// Base::Console().Message("QGVNS::startZoom(%s)\n", TechDraw::DrawUtil::formatVector(p).c_str());
|
||||
zoomOrigin = p;
|
||||
zoomingActive = true;
|
||||
m_zoomPending = false;
|
||||
@@ -317,7 +316,7 @@ void QGVNavStyle::startZoom(QPoint p)
|
||||
|
||||
void QGVNavStyle::stopZoom()
|
||||
{
|
||||
// Base::Console().Message("QGVNS::stopZoom()\n");
|
||||
// Base::Console().Message("QGVNS::stopZoom()\n");
|
||||
zoomingActive = false;
|
||||
m_zoomPending = false;
|
||||
getViewer()->resetCursor();
|
||||
@@ -352,19 +351,19 @@ void QGVNavStyle::startPan(QPoint p)
|
||||
|
||||
void QGVNavStyle::pan(QPoint p)
|
||||
{
|
||||
QScrollBar *horizontalScrollbar = getViewer()->horizontalScrollBar();
|
||||
QScrollBar *verticalScrollbar = getViewer()->verticalScrollBar();
|
||||
QScrollBar* horizontalScrollbar = getViewer()->horizontalScrollBar();
|
||||
QScrollBar* verticalScrollbar = getViewer()->verticalScrollBar();
|
||||
QPoint direction = p - panOrigin;
|
||||
|
||||
horizontalScrollbar->setValue(horizontalScrollbar->value() - m_reversePan*direction.x());
|
||||
verticalScrollbar->setValue(verticalScrollbar->value() - m_reverseScroll*direction.y());
|
||||
horizontalScrollbar->setValue(horizontalScrollbar->value() - m_reversePan * direction.x());
|
||||
verticalScrollbar->setValue(verticalScrollbar->value() - m_reverseScroll * direction.y());
|
||||
|
||||
panOrigin = p;
|
||||
}
|
||||
|
||||
void QGVNavStyle::stopPan()
|
||||
{
|
||||
// Base::Console().Message("QGVNS::stopPan()\n");
|
||||
// Base::Console().Message("QGVNS::stopPan()\n");
|
||||
panningActive = false;
|
||||
m_panPending = false;
|
||||
getViewer()->resetCursor();
|
||||
@@ -384,27 +383,25 @@ void QGVNavStyle::stopClick()
|
||||
|
||||
void QGVNavStyle::placeBalloon(QPoint p)
|
||||
{
|
||||
// Base::Console().Message("QGVNS::placeBalloon()\n");
|
||||
getViewer()->getBalloonCursor()->hide();
|
||||
//balloon was created in Command.cpp. Why are we doing it again?
|
||||
getViewer()->getScene()->createBalloon(getViewer()->mapToScene(p),
|
||||
getViewer()->getDrawPage()->balloonParent);
|
||||
getViewer()->getBalloonParent());
|
||||
getViewer()->setBalloonPlacing(false);
|
||||
}
|
||||
|
||||
//****************************************
|
||||
KeyCombination::KeyCombination()
|
||||
{
|
||||
}
|
||||
KeyCombination::KeyCombination() {}
|
||||
|
||||
KeyCombination::~KeyCombination()
|
||||
{
|
||||
}
|
||||
KeyCombination::~KeyCombination() {}
|
||||
|
||||
void KeyCombination::addKey(int inKey)
|
||||
{
|
||||
bool found = false;
|
||||
//check for inKey already in keys
|
||||
if (!keys.empty()) {
|
||||
for (auto& k: keys) {
|
||||
for (auto& k : keys) {
|
||||
if (k == inKey) {
|
||||
found = true;
|
||||
}
|
||||
@@ -418,7 +415,7 @@ void KeyCombination::addKey(int inKey)
|
||||
void KeyCombination::removeKey(int inKey)
|
||||
{
|
||||
std::vector<int> newKeys;
|
||||
for (auto& k: keys) {
|
||||
for (auto& k : keys) {
|
||||
if (k != inKey) {
|
||||
newKeys.push_back(k);
|
||||
}
|
||||
@@ -426,26 +423,20 @@ void KeyCombination::removeKey(int inKey)
|
||||
keys = newKeys;
|
||||
}
|
||||
|
||||
void KeyCombination::clear()
|
||||
{
|
||||
keys.clear();
|
||||
}
|
||||
void KeyCombination::clear() { keys.clear(); }
|
||||
|
||||
bool KeyCombination::empty()
|
||||
{
|
||||
return keys.empty();
|
||||
}
|
||||
bool KeyCombination::empty() { return keys.empty(); }
|
||||
|
||||
//does inCombo match the keys we have in current combination
|
||||
bool KeyCombination::haveCombination(int inCombo)
|
||||
{
|
||||
bool matched = false;
|
||||
int combo = 0; //no key
|
||||
int combo = 0;//no key
|
||||
if (keys.size() < 2) {
|
||||
//not enough keys for a combination
|
||||
return false;
|
||||
}
|
||||
for (auto& k: keys) {
|
||||
for (auto& k : keys) {
|
||||
combo = combo | k;
|
||||
}
|
||||
if (combo == inCombo) {
|
||||
@@ -454,4 +445,4 @@ bool KeyCombination::haveCombination(int inCombo)
|
||||
return matched;
|
||||
}
|
||||
|
||||
} //namespace TechDrawGui
|
||||
}//namespace TechDrawGui
|
||||
|
||||
Reference in New Issue
Block a user