Fix recursive repaint after label scale.
--HG-- branch : feature
This commit is contained in:
parent
05cad85ab3
commit
f27c7e4e35
|
@ -228,6 +228,7 @@ enum class Vis : ToolVisHolderType
|
||||||
GrainlineItem,
|
GrainlineItem,
|
||||||
PieceItem,
|
PieceItem,
|
||||||
TextGraphicsItem,
|
TextGraphicsItem,
|
||||||
|
ScenePoint,
|
||||||
LAST_ONE_DO_NOT_USE //add new stuffs above this, this constant must be last and never used
|
LAST_ONE_DO_NOT_USE //add new stuffs above this, this constant must be last and never used
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,9 @@
|
||||||
#include "vmaingraphicsscene.h"
|
#include "vmaingraphicsscene.h"
|
||||||
#include "vmaingraphicsview.h"
|
#include "vmaingraphicsview.h"
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
|
#include "vscenepoint.h"
|
||||||
|
|
||||||
|
#define DEFAULT_SCALE 0.0001
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
|
@ -53,7 +56,8 @@
|
||||||
* @param parent parent object.
|
* @param parent parent object.
|
||||||
*/
|
*/
|
||||||
VGraphicsSimpleTextItem::VGraphicsSimpleTextItem(QGraphicsItem * parent)
|
VGraphicsSimpleTextItem::VGraphicsSimpleTextItem(QGraphicsItem * parent)
|
||||||
:QGraphicsSimpleTextItem(parent), m_fontSize(0), selectionType(SelectionType::ByMouseRelease)
|
:QGraphicsSimpleTextItem(parent), m_fontSize(0), selectionType(SelectionType::ByMouseRelease),
|
||||||
|
m_oldScale(DEFAULT_SCALE)
|
||||||
{
|
{
|
||||||
this->setFlag(QGraphicsItem::ItemIsMovable, true);
|
this->setFlag(QGraphicsItem::ItemIsMovable, true);
|
||||||
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||||
|
@ -64,6 +68,7 @@ VGraphicsSimpleTextItem::VGraphicsSimpleTextItem(QGraphicsItem * parent)
|
||||||
font.setPointSize(font.pointSize()+20);
|
font.setPointSize(font.pointSize()+20);
|
||||||
m_fontSize = font.pointSize();
|
m_fontSize = font.pointSize();
|
||||||
this->setFont(font);
|
this->setFont(font);
|
||||||
|
setScale(m_oldScale);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -73,23 +78,53 @@ VGraphicsSimpleTextItem::VGraphicsSimpleTextItem(QGraphicsItem * parent)
|
||||||
* @param parent parent object.
|
* @param parent parent object.
|
||||||
*/
|
*/
|
||||||
VGraphicsSimpleTextItem::VGraphicsSimpleTextItem( const QString & text, QGraphicsItem * parent )
|
VGraphicsSimpleTextItem::VGraphicsSimpleTextItem( const QString & text, QGraphicsItem * parent )
|
||||||
:QGraphicsSimpleTextItem(text, parent), m_fontSize(0), selectionType(SelectionType::ByMouseRelease)
|
:QGraphicsSimpleTextItem(text, parent), m_fontSize(0), selectionType(SelectionType::ByMouseRelease),
|
||||||
|
m_oldScale(DEFAULT_SCALE)
|
||||||
{
|
{
|
||||||
this->setFlag(QGraphicsItem::ItemIsMovable, true);
|
this->setFlag(QGraphicsItem::ItemIsMovable, true);
|
||||||
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||||
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
||||||
this->setAcceptHoverEvents(true);
|
this->setAcceptHoverEvents(true);
|
||||||
|
setScale(m_oldScale);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VGraphicsSimpleTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
void VGraphicsSimpleTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||||
{
|
{
|
||||||
const qreal scale = SceneScale(scene());
|
auto UpdateLine = [this]()
|
||||||
if (scale > 1)
|
|
||||||
{
|
{
|
||||||
|
if (VScenePoint *parent = dynamic_cast<VScenePoint *>(parentItem()))
|
||||||
|
{
|
||||||
|
parent->RefreshLine();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
QGraphicsScene *scene = this->scene();
|
||||||
|
const qreal scale = SceneScale(scene);
|
||||||
|
if (scale > 1 && not VFuzzyComparePossibleNulls(m_oldScale, scale))
|
||||||
|
{
|
||||||
|
const QRectF nameRec = boundingRect();
|
||||||
|
setTransformOriginPoint(nameRec.center());
|
||||||
setScale(1/scale);
|
setScale(1/scale);
|
||||||
|
UpdateLine();
|
||||||
|
m_oldScale = scale;
|
||||||
|
}
|
||||||
|
else if (scale <= 1 && not VFuzzyComparePossibleNulls(m_oldScale, 1.0))
|
||||||
|
{
|
||||||
|
const QRectF nameRec = boundingRect();
|
||||||
|
setTransformOriginPoint(nameRec.center());
|
||||||
|
setScale(1);
|
||||||
|
UpdateLine();
|
||||||
|
m_oldScale = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (scene)
|
||||||
|
{
|
||||||
|
if (QGraphicsView *view = scene->views().at(0))
|
||||||
|
{
|
||||||
|
VMainGraphicsView::NewSceneRect(scene, view);
|
||||||
|
}
|
||||||
|
}
|
||||||
QGraphicsSimpleTextItem::paint(painter, option, widget);
|
QGraphicsSimpleTextItem::paint(painter, option, widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -87,6 +87,7 @@ private:
|
||||||
/** @brief fontSize label font size. */
|
/** @brief fontSize label font size. */
|
||||||
qint32 m_fontSize;
|
qint32 m_fontSize;
|
||||||
SelectionType selectionType;
|
SelectionType selectionType;
|
||||||
|
qreal m_oldScale;
|
||||||
};
|
};
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -32,6 +32,8 @@
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
#include <QGraphicsEllipseItem>
|
#include <QGraphicsEllipseItem>
|
||||||
|
|
||||||
|
#include "../vmisc/def.h"
|
||||||
|
|
||||||
class VGraphicsSimpleTextItem;
|
class VGraphicsSimpleTextItem;
|
||||||
class VPointF;
|
class VPointF;
|
||||||
class VScaledLine;
|
class VScaledLine;
|
||||||
|
@ -42,10 +44,15 @@ public:
|
||||||
explicit VScenePoint(QGraphicsItem *parent = nullptr);
|
explicit VScenePoint(QGraphicsItem *parent = nullptr);
|
||||||
virtual ~VScenePoint() = default;
|
virtual ~VScenePoint() = default;
|
||||||
|
|
||||||
|
virtual int type() const Q_DECL_OVERRIDE {return Type;}
|
||||||
|
enum { Type = UserType + static_cast<int>(Vis::ScenePoint)};
|
||||||
|
|
||||||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
QWidget *widget = nullptr) Q_DECL_OVERRIDE;
|
QWidget *widget = nullptr) Q_DECL_OVERRIDE;
|
||||||
virtual void RefreshPointGeometry(const VPointF &point);
|
virtual void RefreshPointGeometry(const VPointF &point);
|
||||||
|
|
||||||
|
void RefreshLine();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/** @brief namePoint point label. */
|
/** @brief namePoint point label. */
|
||||||
VGraphicsSimpleTextItem *m_namePoint;
|
VGraphicsSimpleTextItem *m_namePoint;
|
||||||
|
@ -63,8 +70,6 @@ protected:
|
||||||
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE;
|
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE;
|
||||||
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE;
|
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
void RefreshLine();
|
|
||||||
|
|
||||||
void SetOnlyPoint(bool value);
|
void SetOnlyPoint(bool value);
|
||||||
bool IsOnlyPoint() const;
|
bool IsOnlyPoint() const;
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user