Merge with feature.

Fixed issue #589. Error: Valentina lock up if not enough space for label.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2016-12-15 11:29:56 +02:00
commit c2e038c57b
7 changed files with 116 additions and 126 deletions

View File

@ -47,6 +47,7 @@
- [#580] Extend the list of heights.
- [#582] Issue with standard path to shared data on Linux.
- [#595] GapWidth affecting to the margins.
- [#589] Valentina lock up if not enough space for label.
# Version 0.4.6
- [#594] Broken export on Mac.

View File

@ -148,15 +148,10 @@ void VLayoutDetail::SetDetail(const QString& qsName, const VPatternPieceData& da
// generate text
d->m_tmDetail.SetFont(font);
int iFS = data.GetFontSize();
if (iFS < MIN_FONT_SIZE)
{
iFS = MIN_FONT_SIZE;
}
d->m_tmDetail.SetFontSize(iFS);
d->m_tmDetail.SetFontSize(data.GetFontSize());
d->m_tmDetail.Update(qsName, data);
// this will generate the lines of text
d->m_tmDetail.SetFontSize(iFS);
d->m_tmDetail.SetFontSize(data.GetFontSize());
d->m_tmDetail.FitFontSize(data.GetLabelWidth(), data.GetLabelHeight());
}
@ -180,17 +175,12 @@ void VLayoutDetail::SetPatternInfo(const VAbstractPattern* pDoc, const VPatternI
// Generate text
d->m_tmPattern.SetFont(font);
int iFS = geom.GetFontSize();
if (iFS < MIN_FONT_SIZE)
{
iFS = MIN_FONT_SIZE;
}
d->m_tmPattern.SetFontSize(iFS);
d->m_tmPattern.SetFontSize(geom.GetFontSize());
d->m_tmPattern.Update(pDoc, dSize, dHeight);
// generate lines of text
d->m_tmPattern.SetFontSize(iFS);
d->m_tmPattern.SetFontSize(geom.GetFontSize());
d->m_tmPattern.FitFontSize(geom.GetLabelWidth(), geom.GetLabelHeight());
}
@ -581,18 +571,20 @@ void VLayoutDetail::CreateTextItems()
fnt.setPixelSize(d->m_tmDetail.GetFont().pixelSize() + tl.m_iFontSize);
fnt.setWeight(tl.m_eFontWeight);
fnt.setStyle(tl.m_eStyle);
dY += tl.m_iHeight;
QFontMetrics fm(fnt);
dY += fm.height();
// check if the next line will go out of bounds
if (dY > dH)
{
break;
}
QFontMetrics fm(fnt);
QString qsText = tl.m_qsText;
if (fm.width(qsText) > dW)
{
qsText = fm.elidedText(qsText, Qt::ElideRight, dW);
qsText = fm.elidedText(qsText, Qt::ElideMiddle, static_cast<int>(dW));
}
// find the correct horizontal offset, depending on the alignment flag
if ((tl.m_eAlign & Qt::AlignLeft) > 0)
@ -636,17 +628,19 @@ void VLayoutDetail::CreateTextItems()
fnt.setPixelSize(d->m_tmPattern.GetFont().pixelSize() + tl.m_iFontSize);
fnt.setWeight(tl.m_eFontWeight);
fnt.setStyle(tl.m_eStyle);
dY += tl.m_iHeight;
QFontMetrics fm(fnt);
dY += fm.height();
if (dY > dH)
{
break;
}
QFontMetrics fm(fnt);
QString qsText = tl.m_qsText;
if (fm.width(qsText) > dW)
{
qsText = fm.elidedText(qsText, Qt::ElideRight, dW);
qsText = fm.elidedText(qsText, Qt::ElideMiddle, static_cast<int>(dW));
}
if ((tl.m_eAlign & Qt::AlignLeft) > 0)
{

View File

@ -32,11 +32,11 @@
#include <QLatin1String>
#include <QRegularExpression>
#include <QApplication>
#include <QtMath>
#include "../ifc/xml/vabstractpattern.h"
#include "../vpatterndb/vpatternpiecedata.h"
#include "../vmisc/vabstractapplication.h"
#include "../vmisc/vmath.h"
#include "vtextmanager.h"
//---------------------------------------------------------------------------------------------------------------------
@ -44,8 +44,11 @@
* @brief TextLine::TextLine default constructor
*/
TextLine::TextLine()
:m_qsText(), m_iFontSize(MIN_FONT_SIZE), m_eFontWeight(QFont::Normal), m_eStyle(QFont::StyleNormal),
m_eAlign(Qt::AlignCenter), m_iHeight(0)
: m_qsText(),
m_iFontSize(MIN_FONT_SIZE),
m_eFontWeight(QFont::Normal),
m_eStyle(QFont::StyleNormal),
m_eAlign(Qt::AlignCenter)
{}
//---------------------------------------------------------------------------------------------------------------------
@ -53,7 +56,7 @@ TextLine::TextLine()
* @brief VTextManager::VTextManager constructor
*/
VTextManager::VTextManager()
:m_font(), m_liLines()
: m_font(), m_liLines()
{}
//---------------------------------------------------------------------------------------------------------------------
@ -117,14 +120,7 @@ const QFont& VTextManager::GetFont() const
*/
void VTextManager::SetFontSize(int iFS)
{
if (iFS < MIN_FONT_SIZE)
{
m_font.setPixelSize(MIN_FONT_SIZE);
}
else
{
m_font.setPixelSize(iFS);
}
iFS < MIN_FONT_SIZE ? m_font.setPixelSize(MIN_FONT_SIZE) : m_font.setPixelSize(iFS);
}
//---------------------------------------------------------------------------------------------------------------------
@ -172,7 +168,7 @@ const TextLine& VTextManager::GetSourceLine(int i) const
{
Q_ASSERT(i >= 0);
Q_ASSERT(i < m_liLines.count());
return m_liLines[i];
return m_liLines.at(i);
}
//---------------------------------------------------------------------------------------------------------------------
@ -193,7 +189,7 @@ void VTextManager::FitFontSize(qreal fW, qreal fH)
// get ratio between char width and height
int iMaxLen = 0;
int iTW;
TextLine maxLine;
QFont fnt;
for (int i = 0; i < GetSourceLinesCount(); ++i)
{
@ -203,23 +199,30 @@ void VTextManager::FitFontSize(qreal fW, qreal fH)
fnt.setWeight(tl.m_eFontWeight);
fnt.setStyle(tl.m_eStyle);
QFontMetrics fm(fnt);
iTW = fm.width(GetSourceLine(i).m_qsText);
const int iTW = fm.width(tl.m_qsText);
if (iTW > iMaxLen)
{
iMaxLen = iTW;
maxLine = tl;
}
}
if (iMaxLen > fW)
{
iFS = qFloor(iFS*fW/iMaxLen);
QFont fnt = m_font;
fnt.setWeight(maxLine.m_eFontWeight);
fnt.setStyle(maxLine.m_eStyle);
int lineLength = 0;
do
{
--iFS;
fnt.setPixelSize(iFS + maxLine.m_iFontSize);
QFontMetrics fm(fnt);
lineLength = fm.width(maxLine.m_qsText);
}
while (lineLength > fW && iFS > MIN_FONT_SIZE);
}
iFS = qMax(MIN_FONT_SIZE, iFS);
int iH = 4*iFS/3;
SetFontSize(iFS);
for (int i = 0; i < GetSourceLinesCount(); ++i)
{
m_liLines[i].m_iHeight = iH;
}
qDebug() << "Font size" << GetSourceLinesCount() << iFS;
}

View File

@ -44,7 +44,7 @@ class QFontMetrics;
class VAbstractPattern;
class VPatternPieceData;
#define MIN_FONT_SIZE 12
#define MIN_FONT_SIZE 5
#define MAX_FONT_SIZE 128
/**
@ -57,7 +57,6 @@ struct TextLine
QFont::Weight m_eFontWeight;
QFont::Style m_eStyle;
Qt::Alignment m_eAlign;
int m_iHeight;
TextLine();
};

View File

@ -49,12 +49,12 @@ class QWidget;
class VAbstractPattern;
class VPatternPieceData;
#define RESIZE_SQUARE 30
#define ROTATE_CIRCLE 20
const qreal resizeSquare = (3./*mm*/ / 25.4) * PrintDPI;
const qreal rotateCircle = (2./*mm*/ / 25.4) * PrintDPI;
#define ROTATE_RECT 60
#define ROTATE_ARC 50
#define MIN_W 120
#define MIN_H 60
const qreal minW = (4./*mm*/ / 25.4) * PrintDPI + resizeSquare;
const qreal minH = (4./*mm*/ / 25.4) * PrintDPI + resizeSquare;
#define INACTIVE_Z 2
#define ACTIVE_Z 10
@ -64,12 +64,21 @@ class VPatternPieceData;
* @param pParent pointer to the parent item
*/
VTextGraphicsItem::VTextGraphicsItem(QGraphicsItem* pParent)
:QGraphicsObject(pParent), m_eMode(VTextGraphicsItem::mNormal), m_bReleased(false),
m_ptStartPos(), m_ptStart(), m_ptRotCenter(), m_szStart(), m_dRotation(0), m_dAngle(0),
m_rectResize(), m_iMinH(MIN_H), m_rectBoundingBox(), m_tm()
: QGraphicsObject(pParent),
m_eMode(VTextGraphicsItem::mNormal),
m_bReleased(false),
m_ptStartPos(),
m_ptStart(),
m_ptRotCenter(),
m_szStart(),
m_dRotation(0),
m_dAngle(0),
m_rectResize(),
m_rectBoundingBox(),
m_tm()
{
m_rectBoundingBox.setTopLeft(QPointF(0, 0));
SetSize(MIN_W, m_iMinH);
SetSize(minW, minH);
setZValue(INACTIVE_Z);
setAcceptHoverEvents(true);
}
@ -101,7 +110,8 @@ void VTextGraphicsItem::SetFont(const QFont& fnt)
void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(widget);
painter->fillRect(option->rect, QColor(251, 251, 175));
Q_UNUSED(option);
painter->fillRect(m_rectBoundingBox, QColor(251, 251, 175));
painter->setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
painter->setPen(Qt::black);
@ -112,25 +122,28 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
for (int i = 0; i < m_tm.GetSourceLinesCount(); ++i)
{
const TextLine& tl = m_tm.GetSourceLine(i);
// check if the next line will go out of bounds
if (iY + tl.m_iHeight > boundingRect().height())
{
break;
}
fnt.setPixelSize(m_tm.GetFont().pixelSize() + tl.m_iFontSize);
fnt.setWeight(tl.m_eFontWeight);
fnt.setStyle(tl.m_eStyle);
QString qsText = tl.m_qsText;
QFontMetrics fm(fnt);
// check if the next line will go out of bounds
if (iY + fm.height() > boundingRect().height())
{
break;
}
if (fm.width(qsText) > iW)
{
qsText = fm.elidedText(qsText, Qt::ElideRight, iW);
qsText = fm.elidedText(qsText, Qt::ElideMiddle, iW);
}
painter->setFont(fnt);
painter->drawText(0, iY, iW, tl.m_iHeight, tl.m_eAlign, qsText);
iY += tl.m_iHeight + m_tm.GetSpacing();
painter->drawText(0, iY, iW, fm.height(), tl.m_eAlign, qsText);
iY += fm.height() + m_tm.GetSpacing();
}
// now draw the features specific to non-normal modes
@ -145,13 +158,13 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
// draw the resize square
painter->setPen(Qt::black);
painter->setBrush(Qt::black);
painter->drawRect(m_rectResize);
painter->drawRect(m_rectResize.adjusted(-1, -1, -1, -1));
if (m_eMode == mResize)
{
// draw the resize diagonal lines
painter->drawLine(0, 0, qRound(m_rectBoundingBox.width()), qRound(m_rectBoundingBox.height()));
painter->drawLine(0, qRound(m_rectBoundingBox.height()), qRound(m_rectBoundingBox.width()), 0);
painter->drawLine(1, 1, qFloor(m_rectBoundingBox.width())-1, qFloor(m_rectBoundingBox.height())-1);
painter->drawLine(1, qFloor(m_rectBoundingBox.height())-1, qFloor(m_rectBoundingBox.width())-1, 1);
}
}
else
@ -161,20 +174,23 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
painter->setBrush(Qt::black);
painter->drawEllipse(
QPointF(m_rectBoundingBox.width()/2, m_rectBoundingBox.height()/2),
ROTATE_CIRCLE,
ROTATE_CIRCLE
rotateCircle,
rotateCircle
);
painter->setPen(QPen(Qt::black, 3));
painter->setBrush(Qt::NoBrush);
// and then draw the arc in each of the corners
int iTop = ROTATE_RECT - ROTATE_ARC;
int iLeft = ROTATE_RECT - ROTATE_ARC;
int iRight = qRound(m_rectBoundingBox.width()) - ROTATE_RECT;
int iBottom = qRound(m_rectBoundingBox.height()) - ROTATE_RECT;
painter->drawArc(iLeft, iTop, ROTATE_ARC, ROTATE_ARC, 180*16, -90*16);
painter->drawArc(iRight, iTop, ROTATE_ARC, ROTATE_ARC, 90*16, -90*16);
painter->drawArc(iLeft, iBottom, ROTATE_ARC, ROTATE_ARC, 270*16, -90*16);
painter->drawArc(iRight, iBottom, ROTATE_ARC, ROTATE_ARC, 0*16, -90*16);
if (m_rectBoundingBox.width() > minW*3 && m_rectBoundingBox.height() > minH*3)
{
painter->setPen(QPen(Qt::black, 3));
painter->setBrush(Qt::NoBrush);
// and then draw the arc in each of the corners
int iTop = ROTATE_RECT - ROTATE_ARC;
int iLeft = ROTATE_RECT - ROTATE_ARC;
int iRight = qRound(m_rectBoundingBox.width()) - ROTATE_RECT;
int iBottom = qRound(m_rectBoundingBox.height()) - ROTATE_RECT;
painter->drawArc(iLeft, iTop, ROTATE_ARC, ROTATE_ARC, 180*16, -90*16);
painter->drawArc(iRight, iTop, ROTATE_ARC, ROTATE_ARC, 90*16, -90*16);
painter->drawArc(iLeft, iBottom, ROTATE_ARC, ROTATE_ARC, 270*16, -90*16);
painter->drawArc(iRight, iBottom, ROTATE_ARC, ROTATE_ARC, 0*16, -90*16);
}
}
}
}
@ -209,24 +225,6 @@ bool VTextGraphicsItem::IsIdle() const
void VTextGraphicsItem::AddLine(const TextLine& tl)
{
m_tm.AddSourceLine(tl);
/*
qreal fW = MIN_W;
qreal fH = m_iMinH;
qreal fMinW;
qreal fMinH;
while (m_tm.IsBigEnough(fW, fH, MIN_FONT_SIZE, fMinW, fMinH) == false)
{
SetSize(fMinW, fMinH);
fW = m_rectBoundingBox.width();
fH = m_rectBoundingBox.height();
}
qreal dX;
qreal dY;
if (IsContained(m_rectBoundingBox, rotation(), dX, dY) == false)
{
setPos(m_rectBoundingBox.left() + dX, m_rectBoundingBox.top() + dY);
}
*/
}
//---------------------------------------------------------------------------------------------------------------------
@ -249,37 +247,32 @@ void VTextGraphicsItem::SetSize(qreal fW, qreal fH)
{
qDebug() << "Setting size to" << fW << parentItem()->boundingRect().width();
// don't allow resize under specific size
if (fW < MIN_W || fH < m_iMinH)
{
return;
}
if (fW > parentItem()->boundingRect().width())
{
fW = parentItem()->boundingRect().width();
}
if (fW < MIN_W)
if (fW < minW)
{
fW = MIN_W;
fW = minW;
}
if (fH > parentItem()->boundingRect().height())
{
fH = parentItem()->boundingRect().height();
}
if (fH < m_iMinH)
if (fH < minH)
{
fH = m_iMinH;
fH = minH;
}
prepareGeometryChange();
qDebug() << "Actual size set to" << fW;
m_rectBoundingBox.setTopLeft(QPointF(0, 0));
m_rectBoundingBox.setWidth(fW);
m_rectBoundingBox.setHeight(fH);
m_rectResize.setTopLeft(QPointF(fW - RESIZE_SQUARE, fH - RESIZE_SQUARE));
m_rectResize.setWidth(RESIZE_SQUARE);
m_rectResize.setHeight(RESIZE_SQUARE);
m_rectResize.setTopLeft(QPointF(fW - resizeSquare, fH - resizeSquare));
m_rectResize.setWidth(resizeSquare);
m_rectResize.setHeight(resizeSquare);
setTransformOriginPoint(m_rectBoundingBox.center());
prepareGeometryChange();
}
//---------------------------------------------------------------------------------------------------------------------
@ -440,7 +433,7 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME)
qreal dX;
qreal dY;
QRectF rectBB;
QPointF ptDiff = pME->scenePos() - m_ptStart;
const QPointF ptDiff = pME->scenePos() - m_ptStart;
if (m_eMode == mMove)
{
// in move mode move the label along the mouse move from the origin
@ -465,12 +458,14 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME)
QSizeF sz(m_szStart.width() + ptDiff.x(), m_szStart.height() + ptDiff.y());
rectBB.setSize(sz);
// before resizing the label to a new size, check if it will still be inside the parent item
if (IsContained(rectBB, rotation(), dX, dY) == true)
if (IsContained(rectBB, rotation(), dX, dY) == false)
{
SetSize(sz.width(), sz.height());
Update();
emit SignalShrink();
sz = QSizeF(sz.width()+dX, sz.height()+dY);
}
SetSize(sz.width(), sz.height());
Update();
emit SignalShrink();
}
else if (m_eMode == mRotate)
{
@ -658,7 +653,7 @@ QRectF VTextGraphicsItem::GetBoundingRect(QRectF rectBB, qreal dRot) const
qreal dY1 = 0;
qreal dY2 = 0;
double dAng = qDegreesToRadians(dRot);
double dAng = qDegreesToRadians(dRot);
for (int i = 0; i < 4; ++i)
{
QPointF pt = apt[i] - ptCenter;

View File

@ -75,13 +75,14 @@ public:
virtual ~VTextGraphicsItem();
void SetFont(const QFont& fnt);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget) Q_DECL_OVERRIDE;
void Reset();
bool IsIdle() const;
int GetFontSize() const;
QRectF boundingRect() const;
virtual QRectF boundingRect() const Q_DECL_OVERRIDE;
void AddLine(const TextLine& tl);
void Clear();
void SetSize(qreal fW, qreal fH);
@ -92,11 +93,11 @@ public:
int GetTextLines() const;
protected:
void mousePressEvent(QGraphicsSceneMouseEvent* pME);
void mouseMoveEvent(QGraphicsSceneMouseEvent* pME);
void mouseReleaseEvent(QGraphicsSceneMouseEvent* pME);
void hoverMoveEvent(QGraphicsSceneHoverEvent* pHE);
void hoverLeaveEvent(QGraphicsSceneHoverEvent* pHE);
virtual void mousePressEvent(QGraphicsSceneMouseEvent* pME) Q_DECL_OVERRIDE;
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* pME) Q_DECL_OVERRIDE;
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) Q_DECL_OVERRIDE;
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent* pHE) Q_DECL_OVERRIDE;
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* pHE) Q_DECL_OVERRIDE;
void UpdateBox();
void CorrectLabel();
@ -118,7 +119,6 @@ private:
double m_dRotation;
double m_dAngle;
QRectF m_rectResize;
int m_iMinH;
QRectF m_rectBoundingBox;
VTextManager m_tm;

View File

@ -837,12 +837,10 @@ void VToolDetail::UpdateLabel()
if (data.IsVisible() == true)
{
QFont fnt = qApp->font();
int iFS = data.GetFontSize();
if (iFS < MIN_FONT_SIZE)
{
iFS = MIN_FONT_SIZE;
const int iFS = data.GetFontSize();
iFS < MIN_FONT_SIZE ? fnt.setPixelSize(MIN_FONT_SIZE) : fnt.setPixelSize(iFS);
}
fnt.setPixelSize(iFS);
dataLabel->SetFont(fnt);
dataLabel->SetSize(data.GetLabelWidth(), data.GetLabelHeight());
dataLabel->UpdateData(detail.getName(), data);