Added label containing pattern piece information to vtooldetail, which can be moved/resized
--HG-- branch : feature
This commit is contained in:
parent
b14a3c9551
commit
fc0b1dce9c
|
@ -50,7 +50,8 @@ HEADERS += \
|
|||
$$PWD/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.h \
|
||||
$$PWD/drawTools/toolcurve/vtoolcubicbezier.h \
|
||||
$$PWD/drawTools/toolcurve/vtoolcubicbezierpath.h \
|
||||
$$PWD/drawTools/operation/vtoolrotation.h
|
||||
$$PWD/drawTools/operation/vtoolrotation.h \
|
||||
$$PWD/vtextgraphicsitem.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/vtooldetail.cpp \
|
||||
|
@ -98,4 +99,5 @@ SOURCES += \
|
|||
$$PWD/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.cpp \
|
||||
$$PWD/drawTools/toolcurve/vtoolcubicbezier.cpp \
|
||||
$$PWD/drawTools/toolcurve/vtoolcubicbezierpath.cpp \
|
||||
$$PWD/drawTools/operation/vtoolrotation.cpp
|
||||
$$PWD/drawTools/operation/vtoolrotation.cpp \
|
||||
$$PWD/vtextgraphicsitem.cpp
|
||||
|
|
187
src/libs/vtools/tools/vtextgraphicsitem.cpp
Normal file
187
src/libs/vtools/tools/vtextgraphicsitem.cpp
Normal file
|
@ -0,0 +1,187 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file vtextgraphicsitem.h
|
||||
** @author Bojan Kverh
|
||||
** @date June 16, 2016
|
||||
**
|
||||
** @brief
|
||||
** @copyright
|
||||
** This source code is part of the Valentine project, a pattern making
|
||||
** program, whose allow create and modeling patterns of clothing.
|
||||
** Copyright (C) 2013-2015 Valentina project
|
||||
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
||||
**
|
||||
** Valentina is free software: you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
** the Free Software Foundation, either version 3 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** Valentina is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
||||
**
|
||||
*************************************************************************/
|
||||
|
||||
#include <QPainter>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QDebug>
|
||||
|
||||
#include "vtextgraphicsitem.h"
|
||||
|
||||
#define RESIZE_SQUARE 30
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VTextGraphicsItem::VTextGraphicsItem(QGraphicsItem* pParent)
|
||||
: QGraphicsTextItem(pParent)
|
||||
{
|
||||
setFlag(QGraphicsItem::ItemIsMovable, true);
|
||||
setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||
m_eMode = mNormal;
|
||||
m_iMinW = 100;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VTextGraphicsItem::~VTextGraphicsItem()
|
||||
{}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
painter->fillRect(option->rect, QColor(251, 251, 175));
|
||||
QGraphicsTextItem::paint(painter, option, widget);
|
||||
|
||||
if (m_eMode != mNormal)
|
||||
{
|
||||
painter->setPen(QPen(Qt::black, 2, Qt::DashLine));
|
||||
painter->drawRect(boundingRect().adjusted(1, 1, -1, -1));
|
||||
|
||||
painter->setPen(Qt::black);
|
||||
painter->setBrush(Qt::black);
|
||||
SetResizeArea();
|
||||
painter->drawRect(m_rectResize);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VTextGraphicsItem::SetMinimalWidth(int iW)
|
||||
{
|
||||
m_iMinW = iW;
|
||||
setTextWidth(m_iMinW);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VTextGraphicsItem::Reset()
|
||||
{
|
||||
m_eMode = mNormal;
|
||||
Update();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VTextGraphicsItem::SetHTML(const QString& qsHTML)
|
||||
{
|
||||
QGraphicsTextItem::setHtml(qsHTML);
|
||||
m_iMinFontSize = font().pixelSize();
|
||||
m_iMinH = boundingRect().height();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME)
|
||||
{
|
||||
if ((pME->button() & Qt::LeftButton) > 0)
|
||||
{
|
||||
SetResizeArea();
|
||||
if (m_rectResize.contains(pME->pos()) == true)
|
||||
{
|
||||
m_eMode = mResize;
|
||||
m_iCurrentH = boundingRect().height();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_eMode = mMove;
|
||||
}
|
||||
qDebug() << "MOUSEPRESS" << m_rectResize << pME->pos() << int(m_eMode);
|
||||
Update();
|
||||
m_ptStart = pME->pos();
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent *pME)
|
||||
{
|
||||
if (m_eMode == mMove)
|
||||
{
|
||||
m_eMode = mMove;
|
||||
QPointF ptRel = pME->pos() - m_ptStart;
|
||||
moveBy(ptRel.x(), ptRel.y());
|
||||
}
|
||||
else if (m_eMode == mResize)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
int iNewW = textWidth() + pME->pos().x() - m_ptStart.x();
|
||||
m_iCurrentH += pME->pos().y() - m_ptStart.y();
|
||||
if (iNewW >= m_iMinW)
|
||||
{
|
||||
setTextWidth(iNewW);
|
||||
m_ptStart.setX(pME->pos().x());
|
||||
Update();
|
||||
}
|
||||
|
||||
if (m_iCurrentH >= m_iMinH)
|
||||
{
|
||||
int iFontSize = m_iMinFontSize*m_iCurrentH/m_iMinH;
|
||||
if (iFontSize > m_iMinFontSize*2)
|
||||
{
|
||||
// prevent too big letters
|
||||
return;
|
||||
}
|
||||
QFont fnt = font();
|
||||
fnt.setPixelSize(iFontSize);
|
||||
setFont(fnt);
|
||||
m_ptStart.setY(pME->pos().y());
|
||||
Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *pME)
|
||||
{
|
||||
if ((pME->button() & Qt::LeftButton) > 0)
|
||||
{
|
||||
if (m_eMode == mMove)
|
||||
{
|
||||
m_eMode = mActivated;
|
||||
}
|
||||
Update();
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VTextGraphicsItem::Update()
|
||||
{
|
||||
update(boundingRect());
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VTextGraphicsItem::SetResizeArea()
|
||||
{
|
||||
m_rectResize.setLeft(boundingRect().right() - RESIZE_SQUARE);
|
||||
m_rectResize.setTop(boundingRect().bottom() - RESIZE_SQUARE);
|
||||
m_rectResize.setWidth(RESIZE_SQUARE);
|
||||
m_rectResize.setHeight(RESIZE_SQUARE);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VTextGraphicsItem::setHtml(const QString &qsHtml)
|
||||
{
|
||||
Q_UNUSED(qsHtml);
|
||||
// prevent using this method! Use SetHTML instead!
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
73
src/libs/vtools/tools/vtextgraphicsitem.h
Normal file
73
src/libs/vtools/tools/vtextgraphicsitem.h
Normal file
|
@ -0,0 +1,73 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file vtextgraphicsitem.h
|
||||
** @author Bojan Kverh
|
||||
** @date June 16, 2016
|
||||
**
|
||||
** @brief
|
||||
** @copyright
|
||||
** This source code is part of the Valentine project, a pattern making
|
||||
** program, whose allow create and modeling patterns of clothing.
|
||||
** Copyright (C) 2013-2015 Valentina project
|
||||
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
||||
**
|
||||
** Valentina is free software: you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
** the Free Software Foundation, either version 3 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** Valentina is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
||||
**
|
||||
*************************************************************************/
|
||||
|
||||
#ifndef VTEXTGRAPHICSITEM_H
|
||||
#define VTEXTGRAPHICSITEM_H
|
||||
|
||||
#include <QGraphicsTextItem>
|
||||
|
||||
class VTextGraphicsItem : public QGraphicsTextItem
|
||||
{
|
||||
enum Mode {
|
||||
mNormal,
|
||||
mActivated,
|
||||
mMove,
|
||||
mResize
|
||||
};
|
||||
|
||||
public:
|
||||
VTextGraphicsItem(QGraphicsItem* pParent = 0);
|
||||
~VTextGraphicsItem();
|
||||
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||
|
||||
void SetMinimalWidth(int iW);
|
||||
|
||||
void Reset();
|
||||
void SetHTML(const QString& qsHTML);
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent* pME);
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent* pME);
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent* pME);
|
||||
|
||||
void Update();
|
||||
void SetResizeArea();
|
||||
void setHtml(const QString& qsHtml);
|
||||
|
||||
private:
|
||||
int m_iMinW;
|
||||
Mode m_eMode;
|
||||
QPointF m_ptStart;
|
||||
QRectF m_rectResize;
|
||||
int m_iMinFontSize;
|
||||
int m_iMinH;
|
||||
int m_iCurrentH;
|
||||
};
|
||||
|
||||
#endif // VTEXTGRAPHICSITEM_H
|
|
@ -77,7 +77,8 @@ const QString VToolDetail::NodeSplinePath = QStringLiteral("NodeSplinePath");
|
|||
VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 &id, const Source &typeCreation,
|
||||
VMainGraphicsScene *scene, const QString &drawName, QGraphicsItem *parent)
|
||||
:VAbstractTool(doc, data, id), VNoBrushScalePathItem(parent), dialog(nullptr), sceneDetails(scene),
|
||||
drawName(drawName), seamAllowance(new VNoBrushScalePathItem(this))
|
||||
drawName(drawName), seamAllowance(new VNoBrushScalePathItem(this)),
|
||||
dataLabel(new VTextGraphicsItem(this))
|
||||
{
|
||||
VDetail detail = data->GetDetail(id);
|
||||
for (int i = 0; i< detail.CountNode(); ++i)
|
||||
|
@ -115,6 +116,7 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32
|
|||
this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus
|
||||
|
||||
connect(scene, &VMainGraphicsScene::EnableToolMove, this, &VToolDetail::EnableToolMove);
|
||||
connect(scene, &VMainGraphicsScene::MouseLeftPressed, this, &VToolDetail::ResetChild);
|
||||
if (typeCreation == Source::FromGui || typeCreation == Source::FromTool)
|
||||
{
|
||||
AddToFile();
|
||||
|
@ -707,6 +709,37 @@ void VToolDetail::RefreshGeometry()
|
|||
}
|
||||
|
||||
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
||||
|
||||
const VPatternPieceData& data = detail.GetPatternPieceData();
|
||||
if (data.GetLetter().isEmpty() == false || data.GetName().isEmpty() == false || data.GetMCPCount() > 0)
|
||||
{
|
||||
QString qsText = "Cut %1 on %2%3";
|
||||
QStringList qslPlace;
|
||||
qslPlace << "" << " on Fold";
|
||||
QFont fnt = qApp->font();
|
||||
fnt.setPixelSize(24);
|
||||
QFontMetrics fm(fnt);
|
||||
dataLabel->setFont(fnt);
|
||||
int iMinW = 200;
|
||||
QString qsHTML = "<b><font size=\"+4\">" + data.GetLetter() + "</font></b><br/>";
|
||||
qsHTML += "<font size=\"+2\">" + data.GetName() + "</font><br/>";
|
||||
for (int i = 0; i < data.GetMCPCount(); ++i)
|
||||
{
|
||||
MaterialCutPlacement mcp = data.GetMCP(i);
|
||||
QString qsLine = qsText.arg(mcp.m_iCutNumber).arg(mcp.m_qsMaterialUserDef).arg(qslPlace[int(mcp.m_ePlacement)]);
|
||||
if (fm.width(qsLine) > iMinW)
|
||||
iMinW = fm.width(qsLine);
|
||||
qsHTML += qsLine + "<br/>";
|
||||
}
|
||||
// also add some offset
|
||||
dataLabel->SetMinimalWidth(iMinW + 10);
|
||||
dataLabel->SetHTML(qsHTML);
|
||||
dataLabel->show();
|
||||
}
|
||||
else
|
||||
{
|
||||
dataLabel->hide();
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -762,3 +795,9 @@ void VToolDetail::AllowSelecting(bool enabled)
|
|||
{
|
||||
setFlag(QGraphicsItem::ItemIsSelectable, enabled);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VToolDetail::ResetChild()
|
||||
{
|
||||
dataLabel->Reset();
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
#include "vabstracttool.h"
|
||||
#include "../vwidgets/vnobrushscalepathitem.h"
|
||||
#include "vtextgraphicsitem.h"
|
||||
|
||||
class VMainGraphicsScene;
|
||||
class DialogTool;
|
||||
|
@ -89,6 +90,7 @@ public slots:
|
|||
void EnableToolMove(bool move);
|
||||
virtual void AllowHover(bool enabled) Q_DECL_OVERRIDE;
|
||||
virtual void AllowSelecting(bool enabled) Q_DECL_OVERRIDE;
|
||||
virtual void ResetChild();
|
||||
protected:
|
||||
virtual void AddToFile () Q_DECL_OVERRIDE;
|
||||
virtual void RefreshDataInFile() Q_DECL_OVERRIDE;
|
||||
|
@ -111,6 +113,7 @@ private:
|
|||
QString drawName;
|
||||
|
||||
VNoBrushScalePathItem *seamAllowance;
|
||||
VTextGraphicsItem* dataLabel;
|
||||
|
||||
VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 &id, const Source &typeCreation,
|
||||
VMainGraphicsScene *scene, const QString &drawName, QGraphicsItem * parent = nullptr);
|
||||
|
|
Loading…
Reference in New Issue
Block a user