TechDraw: force user to place its balloon
This commit is contained in:
committed by
WandererFan
parent
13c82aa67d
commit
bbd9fbf892
@@ -36,6 +36,7 @@
|
||||
# include <QPainter>
|
||||
# include <QPaintDevice>
|
||||
# include <QSvgGenerator>
|
||||
# include <QApplication>
|
||||
|
||||
# include <math.h>
|
||||
#endif
|
||||
@@ -171,8 +172,9 @@ void QGIViewBalloon::onAttachPointPicked(QGIView *view, QPointF pos)
|
||||
auto bnd = boost::bind(&QGIViewBalloon::parentViewMousePressed, this, _1, _2);
|
||||
|
||||
if (balloon->OriginIsSet.getValue() == false) {
|
||||
balloon->OriginX.setValue(pos.x());
|
||||
balloon->OriginY.setValue(pos.y());
|
||||
/* Move origin by half of cursor size */
|
||||
balloon->OriginX.setValue(pos.x() - 16);
|
||||
balloon->OriginY.setValue(pos.y() + 16);
|
||||
balloon->OriginIsSet.setValue(true);
|
||||
|
||||
m_parent->signalSelectPoint.disconnect(bnd);
|
||||
@@ -182,6 +184,8 @@ void QGIViewBalloon::onAttachPointPicked(QGIView *view, QPointF pos)
|
||||
if (mdi != nullptr) {
|
||||
page = mdi->getQGVPage();
|
||||
|
||||
page->balloonPlacing(false);
|
||||
|
||||
QString labelText = QString::fromUtf8(std::to_string(page->balloonIndex).c_str());
|
||||
balloon->Text.setValue(std::to_string(page->balloonIndex++).c_str());
|
||||
|
||||
@@ -194,6 +198,8 @@ void QGIViewBalloon::onAttachPointPicked(QGIView *view, QPointF pos)
|
||||
// Default label position
|
||||
balloonLabel->setPosFromCenter(pos.x() + 200, pos.y() -200);
|
||||
balloonLabel->setDimString(labelText, Rez::guiX(balloon->TextWrapLen.getValue()));
|
||||
|
||||
QApplication::setOverrideCursor(Qt::ArrowCursor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -137,6 +137,7 @@ QGVPage::QGVPage(ViewProviderPage *vp, QGraphicsScene* s, QWidget *parent)
|
||||
bkgBrush = new QBrush(getBackgroundColor());
|
||||
|
||||
balloonIndex = 1;
|
||||
balloonPlacing(false);
|
||||
|
||||
resetCachedContent();
|
||||
}
|
||||
@@ -407,9 +408,13 @@ QGIView * QGVPage::addViewBalloon(TechDraw::DrawViewBalloon *balloon)
|
||||
QGIView *parent = 0;
|
||||
parent = findParent(balloonGroup);
|
||||
|
||||
if(parent) {
|
||||
balloonGroup->connect(parent);
|
||||
addBalloonToParent(balloonGroup,parent);
|
||||
if(balloon->OriginIsSet.getValue() == false) {
|
||||
if(parent) {
|
||||
balloonPlacing(true);
|
||||
QApplication::setOverrideCursor(QCursor(QPixmap(QString::fromUtf8(":/icons/cursor-balloon.png"))));
|
||||
balloonGroup->connect(parent);
|
||||
addBalloonToParent(balloonGroup,parent);
|
||||
}
|
||||
}
|
||||
|
||||
return balloonGroup;
|
||||
@@ -854,6 +859,30 @@ void QGVPage::enterEvent(QEvent *event)
|
||||
viewport()->setCursor(Qt::ArrowCursor);
|
||||
}
|
||||
|
||||
void QGVPage::leaveEvent(QEvent * event)
|
||||
{
|
||||
if(m_balloonPlacing) {
|
||||
|
||||
// Get the window geometry & cursor position
|
||||
const QRect &rect = geometry();
|
||||
QPoint position = this->mapFromGlobal(QCursor::pos());
|
||||
|
||||
// Check the bounds
|
||||
qint32 x = qBound(rect.left(), position.x(), rect.right());
|
||||
qint32 y = qBound(rect.top(), position.y(), rect.bottom());
|
||||
|
||||
QPoint newPoint(x, y);
|
||||
|
||||
// Adjust the cursor
|
||||
if (x != position.x() || y != position.y())
|
||||
QCursor::setPos(this->mapToGlobal(newPoint));
|
||||
|
||||
event->accept();
|
||||
}
|
||||
|
||||
QGraphicsView::leaveEvent(event);
|
||||
}
|
||||
|
||||
void QGVPage::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
QGraphicsView::mousePressEvent(event);
|
||||
|
||||
@@ -93,6 +93,8 @@ public:
|
||||
int removeQViewByName(const char* name);
|
||||
void removeQViewFromScene(QGIView *view);
|
||||
|
||||
void balloonPlacing(bool val) { m_balloonPlacing = val; };
|
||||
|
||||
//void setViews(const std::vector<QGIView *> &view) {views = view; }
|
||||
void setPageTemplate(TechDraw::DrawTemplate *pageTemplate);
|
||||
|
||||
@@ -117,6 +119,7 @@ protected:
|
||||
void wheelEvent(QWheelEvent *event) override;
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
void enterEvent(QEvent *event) override;
|
||||
void leaveEvent(QEvent *event) override;
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
void keyPressEvent(QKeyEvent *event) override;
|
||||
@@ -143,6 +146,7 @@ private:
|
||||
double m_zoomIncrement;
|
||||
int m_reversePan;
|
||||
int m_reverseScroll;
|
||||
bool m_balloonPlacing;
|
||||
};
|
||||
|
||||
} // namespace MDIViewPageGui
|
||||
|
||||
@@ -71,6 +71,7 @@
|
||||
<file>icons/arrow-ccw.svg</file>
|
||||
<file>icons/arrow-cw.svg</file>
|
||||
<file>icons/techdraw-lock.png</file>
|
||||
<file>icons/cursor-balloon.png</file>
|
||||
<file>translations/TechDraw_af.qm</file>
|
||||
<file>translations/TechDraw_zh-CN.qm</file>
|
||||
<file>translations/TechDraw_zh-TW.qm</file>
|
||||
|
||||
BIN
src/Mod/TechDraw/Gui/Resources/icons/cursor-balloon.png
Normal file
BIN
src/Mod/TechDraw/Gui/Resources/icons/cursor-balloon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
Reference in New Issue
Block a user