2016-06-23 00:59:45 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @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
|
|
|
|
|
2016-06-25 17:19:44 +02:00
|
|
|
#include <QGraphicsObject>
|
|
|
|
#include <QFont>
|
|
|
|
#include <QList>
|
2016-06-23 00:59:45 +02:00
|
|
|
|
2016-07-19 14:23:20 +02:00
|
|
|
#include "../vlayout/vtextmanager.h"
|
2016-06-25 17:19:44 +02:00
|
|
|
|
2016-07-23 15:26:15 +02:00
|
|
|
/**
|
|
|
|
* @brief The VTextGraphicsItem class. This class implements text graphics item,
|
|
|
|
* which can be dragged around, resized and rotated within the parent item. The text font
|
|
|
|
* size will be automatically updated, so that the entire text will fit into the item.
|
|
|
|
*/
|
2016-06-25 17:19:44 +02:00
|
|
|
class VTextGraphicsItem : public QGraphicsObject
|
2016-06-23 00:59:45 +02:00
|
|
|
{
|
2016-06-23 22:35:32 +02:00
|
|
|
Q_OBJECT
|
|
|
|
|
2016-06-23 00:59:45 +02:00
|
|
|
enum Mode {
|
|
|
|
mNormal,
|
|
|
|
mMove,
|
2016-06-30 18:04:25 +02:00
|
|
|
mResize,
|
|
|
|
mRotate
|
2016-06-23 00:59:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
2016-08-02 14:12:13 +02:00
|
|
|
explicit VTextGraphicsItem(QGraphicsItem* pParent = nullptr);
|
|
|
|
virtual ~VTextGraphicsItem();
|
2016-06-23 00:59:45 +02:00
|
|
|
|
2016-06-25 17:19:44 +02:00
|
|
|
void SetFont(const QFont& fnt);
|
2016-06-23 00:59:45 +02:00
|
|
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
|
|
|
|
|
|
|
void Reset();
|
2016-08-02 22:51:40 +02:00
|
|
|
bool IsIdle() const;
|
2016-06-24 17:57:08 +02:00
|
|
|
|
2016-07-01 01:45:16 +02:00
|
|
|
int GetFontSize() const;
|
2016-06-24 17:57:08 +02:00
|
|
|
QRectF boundingRect() const;
|
2016-06-25 17:19:44 +02:00
|
|
|
void AddLine(const TextLine& tl);
|
|
|
|
void Clear();
|
2016-06-27 17:18:43 +02:00
|
|
|
void SetSize(qreal fW, qreal fH);
|
|
|
|
void Update();
|
2016-07-14 02:10:27 +02:00
|
|
|
bool IsContained(QRectF rectBB, qreal dRot, qreal& dX, qreal& dY) const;
|
2016-07-21 21:46:49 +02:00
|
|
|
void UpdateData(const QString& qsName, const VPatternPieceData& data);
|
2016-07-22 11:56:45 +02:00
|
|
|
void UpdateData(const VAbstractPattern* pDoc);
|
2016-07-30 13:21:03 +02:00
|
|
|
int GetTextLines() const;
|
2016-06-23 22:35:32 +02:00
|
|
|
|
2016-06-23 00:59:45 +02:00
|
|
|
protected:
|
|
|
|
void mousePressEvent(QGraphicsSceneMouseEvent* pME);
|
|
|
|
void mouseMoveEvent(QGraphicsSceneMouseEvent* pME);
|
|
|
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent* pME);
|
2016-06-27 17:18:43 +02:00
|
|
|
void UpdateBox();
|
2016-06-24 17:57:08 +02:00
|
|
|
void UpdateFont();
|
2016-06-25 17:19:44 +02:00
|
|
|
|
2016-06-30 18:04:25 +02:00
|
|
|
double GetAngle(QPointF pt) const;
|
|
|
|
|
2016-06-25 17:19:44 +02:00
|
|
|
signals:
|
2016-07-14 02:59:42 +02:00
|
|
|
void SignalMoved(const QPointF& ptPos);
|
2016-06-27 01:17:27 +02:00
|
|
|
void SignalResized(qreal iTW, int iFontSize);
|
2016-06-30 18:04:25 +02:00
|
|
|
void SignalRotated(qreal dAng);
|
2016-06-27 01:17:27 +02:00
|
|
|
void SignalShrink();
|
2016-06-23 00:59:45 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
Mode m_eMode;
|
2016-06-30 18:04:25 +02:00
|
|
|
bool m_bReleased;
|
|
|
|
QPointF m_ptStartPos;
|
2016-06-23 00:59:45 +02:00
|
|
|
QPointF m_ptStart;
|
2016-07-02 11:15:41 +02:00
|
|
|
QPointF m_ptRotCenter;
|
2016-06-25 17:19:44 +02:00
|
|
|
QSizeF m_szStart;
|
2016-06-30 18:04:25 +02:00
|
|
|
double m_dRotation;
|
|
|
|
double m_dAngle;
|
2016-06-23 00:59:45 +02:00
|
|
|
QRectF m_rectResize;
|
|
|
|
int m_iMinH;
|
2016-06-24 17:57:08 +02:00
|
|
|
QRectF m_rectBoundingBox;
|
2016-07-18 22:30:14 +02:00
|
|
|
VTextManager m_tm;
|
2016-07-14 02:10:27 +02:00
|
|
|
|
|
|
|
QRectF GetBoundingRect(QRectF rectBB, qreal dRot) const;
|
2016-06-23 00:59:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // VTEXTGRAPHICSITEM_H
|