Fix recursive repaint after label scale.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-10-23 21:10:48 +03:00
parent 05cad85ab3
commit f27c7e4e35
4 changed files with 48 additions and 6 deletions

View File

@ -228,6 +228,7 @@ enum class Vis : ToolVisHolderType
GrainlineItem,
PieceItem,
TextGraphicsItem,
ScenePoint,
LAST_ONE_DO_NOT_USE //add new stuffs above this, this constant must be last and never used
};

View File

@ -46,6 +46,9 @@
#include "vmaingraphicsscene.h"
#include "vmaingraphicsview.h"
#include "global.h"
#include "vscenepoint.h"
#define DEFAULT_SCALE 0.0001
//---------------------------------------------------------------------------------------------------------------------
/**
@ -53,7 +56,8 @@
* @param parent parent object.
*/
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::ItemIsSelectable, true);
@ -64,6 +68,7 @@ VGraphicsSimpleTextItem::VGraphicsSimpleTextItem(QGraphicsItem * parent)
font.setPointSize(font.pointSize()+20);
m_fontSize = font.pointSize();
this->setFont(font);
setScale(m_oldScale);
}
//---------------------------------------------------------------------------------------------------------------------
@ -73,23 +78,53 @@ VGraphicsSimpleTextItem::VGraphicsSimpleTextItem(QGraphicsItem * parent)
* @param parent parent object.
*/
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::ItemIsSelectable, true);
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
this->setAcceptHoverEvents(true);
setScale(m_oldScale);
}
//---------------------------------------------------------------------------------------------------------------------
void VGraphicsSimpleTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
const qreal scale = SceneScale(scene());
if (scale > 1)
auto UpdateLine = [this]()
{
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);
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);
}

View File

@ -87,6 +87,7 @@ private:
/** @brief fontSize label font size. */
qint32 m_fontSize;
SelectionType selectionType;
qreal m_oldScale;
};
//---------------------------------------------------------------------------------------------------------------------

View File

@ -32,6 +32,8 @@
#include <QtGlobal>
#include <QGraphicsEllipseItem>
#include "../vmisc/def.h"
class VGraphicsSimpleTextItem;
class VPointF;
class VScaledLine;
@ -42,10 +44,15 @@ public:
explicit VScenePoint(QGraphicsItem *parent = nullptr);
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,
QWidget *widget = nullptr) Q_DECL_OVERRIDE;
virtual void RefreshPointGeometry(const VPointF &point);
void RefreshLine();
protected:
/** @brief namePoint point label. */
VGraphicsSimpleTextItem *m_namePoint;
@ -63,8 +70,6 @@ protected:
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE;
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE;
void RefreshLine();
void SetOnlyPoint(bool value);
bool IsOnlyPoint() const;
private: