57 #include <QGraphicsScene>
58 #include <QGraphicsSceneMouseEvent>
59 #include <QGraphicsView>
62 #include <QMessageLogger>
74 #include "../vmisc/vabstractapplication.h"
82 : QGraphicsSimpleTextItem(parent)
83 , m_fontSize(
qApp->Settings()->getPointNameSize())
85 , m_textColor(textColor)
86 , m_isNameHovered(false)
88 , m_showParentTooltip(true)
100 : QGraphicsSimpleTextItem(text, parent)
101 , m_fontSize(
qApp->Settings()->getPointNameSize())
103 , m_textColor(textColor)
104 , m_isNameHovered(false)
106 , m_showParentTooltip(true)
114 QGraphicsScene *scene = this->scene();
126 QFont fnt = this->font();
127 if (fnt.pointSize() !=
qApp->Settings()->getPointNameSize() ||
128 fnt.family() !=
qApp->Settings()->getPointNameFont().family())
130 fnt.setPointSize(
qApp->Settings()->getPointNameSize());
131 fnt.setFamily(
qApp->Settings()->getPointNameFont().family());
135 if (QGraphicsView *view = scene->views().at(0))
142 this->setBrush(QBrush(QColor(
qApp->Settings()->getPointNameHoverColor())));
149 QGraphicsSimpleTextItem::paint(painter, option, widget);
155 QGraphicsSimpleTextItem::setEnabled(enabled);
180 if (change == ItemPositionChange && scene())
184 static bool changeFinished =
true;
188 changeFinished =
false;
192 if (not viewList.isEmpty())
194 if (QGraphicsView *view = viewList.at(0))
196 const int xmargin = 50;
197 const int ymargin = 50;
200 const QRectF itemRect = mapToScene(boundingRect()).boundingRect();
203 if (itemRect.height() + 2*ymargin < viewRect.height() &&
204 itemRect.width() + 2*xmargin < viewRect.width())
206 view->ensureVisible(itemRect, xmargin, ymargin);
213 const QPointF cursorPosition = currentScene->
getScenePos();
214 view->ensureVisible(QRectF(cursorPosition.x()-5, cursorPosition.y()-5, 10, 10));
226 line.setLength(line.length() * scale);
231 changeFinished =
true;
235 if (change == QGraphicsItem::ItemSelectedChange)
237 setFlag(QGraphicsItem::ItemIsFocusable, value.toBool());
240 return QGraphicsSimpleTextItem::itemChange(change, value);
252 if (flags() & QGraphicsItem::ItemIsMovable)
258 setCursor(
qApp->getSceneView()->viewport()->cursor());
261 QGraphicsItem *parent = parentItem();
264 setToolTip(parent->toolTip());
267 QGraphicsSimpleTextItem::hoverEnterEvent(event);
278 if (flags() & QGraphicsItem::ItemIsMovable)
280 setCursor(QCursor());
283 QGraphicsSimpleTextItem::hoverLeaveEvent(event);
300 QGraphicsSimpleTextItem::mousePressEvent(event);
303 if (not (flags() & ItemIsSelectable) && scene())
305 scene()->clearSelection();
308 if (flags() & QGraphicsItem::ItemIsMovable)
310 if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
321 if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
332 if (flags() & QGraphicsItem::ItemIsMovable)
334 if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
345 QGraphicsSimpleTextItem::mouseReleaseEvent(event);
351 switch (event->key())
359 QGraphicsSimpleTextItem::keyReleaseEvent (event);
364 if (
qApp->Settings()->getUseToolColor())
367 textColor.setAlpha(224);
372 QColor textColor =
correctColor(
this, QColor(
qApp->Settings()->getPointNameColor()));
373 textColor.setAlpha(224);
394 this->setFlag(QGraphicsItem::ItemIsMovable,
true);
395 this->setFlag(QGraphicsItem::ItemIsSelectable,
true);
396 this->setFlag(QGraphicsItem::ItemSendsGeometryChanges,
true);
397 this->setFlag(QGraphicsItem::ItemIsFocusable,
true);
398 this->setAcceptHoverEvents(
true);
402 fnt.setFamily(
qApp->Settings()->getPointNameFont().family());
435 line.setLength(line.length() / scale);
440 setFlag(QGraphicsItem::ItemSendsGeometryChanges,
false);
442 setFlag(QGraphicsItem::ItemSendsGeometryChanges,
true);
451 parent->refreshLeader();
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE
void setTextColor(const QColor &color)
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) Q_DECL_OVERRIDE
itemChange handle item change.
virtual int type() const Q_DECL_OVERRIDE
void scalePointName(const qreal &scale)
scalePointName handle point name scaling to maintain same size when scene scale changes.
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE
hoverEnterEvent handle hover enter events.
QColor getTextBrushColor()
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE
hoverLeaveEvent handle hover leave events.
qint32 m_fontSize
fontSize label font size.
void setEnabled(bool enabled)
void setPosition(QPointF pos)
void textSelectionType(const SelectionType &type)
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE
void showContextMenu(QGraphicsSceneContextMenuEvent *event)
showContextMenu emit when need show tool context menu.
SelectionType selectionType
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=nullptr) Q_DECL_OVERRIDE
virtual void keyReleaseEvent(QKeyEvent *event) Q_DECL_OVERRIDE
void setShowParentTooltip(bool show)
VGraphicsSimpleTextItem(QColor color, QGraphicsItem *parent=nullptr)
VGraphicsSimpleTextItem default constructor.
void nameChangedPosition(const QPointF &pos)
nameChangedPosition emit when label change position.
void pointSelected(bool selected)
virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) Q_DECL_OVERRIDE
contextMenuEvent handle context menu events.
void scalePosition()
scalePosition handle point name position scaling to maintain same distance when scene scale changes.
The VMainGraphicsScene class main scene.
QPointF getScenePos() const
static QRectF SceneVisibleArea(QGraphicsView *view)
static void NewSceneRect(QGraphicsScene *sc, QGraphicsView *view, QGraphicsItem *item=nullptr)
NewSceneRect calculate scene rect what contains all items and doesn't less that size of scene view.
const QString cursorArrowOpenHand
void SetItemOverrideCursor(QGraphicsItem *item, const QString &pixmapPath, int hotX, int hotY)
const QString cursorArrowCloseHand
static Q_REQUIRED_RESULT bool VFuzzyComparePossibleNulls(double p1, double p2)
qreal sceneScale(QGraphicsScene *scene)
QColor correctColor(const QGraphicsItem *item, const QColor &color)