valentina/src/libs/vwidgets/vtextgraphicsitem.h

131 lines
4.1 KiB
C
Raw Normal View History

/************************************************************************
**
** @file vtextgraphicsitem.h
** @author Bojan Kverh
** @date June 16, 2016
**
** @brief
** @copyright
** This source code is part of the Valentina project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2013-2015 Valentina project
** <https://gitlab.com/smart-pattern/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 <QFont>
#include <QGraphicsObject>
#include <QList>
#include <QMetaObject>
#include <QObject>
#include <QPointF>
#include <QRectF>
#include <QSizeF>
#include <QString>
#include <QtGlobal>
#include "../vlayout/vtextmanager.h"
2023-05-22 16:27:15 +02:00
#include "vpieceitem.h"
2023-06-22 17:30:43 +02:00
class VSvgFont;
/**
* @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.
*/
class VTextGraphicsItem final : public VPieceItem
{
2022-08-12 17:50:13 +02:00
Q_OBJECT // NOLINT
2023-05-22 16:27:15 +02:00
public:
2023-05-22 16:30:18 +02:00
enum ItemType
{
PatternLabel,
PieceLabel,
Unknown
};
explicit VTextGraphicsItem(ItemType type, QGraphicsItem *pParent = nullptr);
2023-05-22 16:27:15 +02:00
~VTextGraphicsItem() override = default;
2023-05-22 16:27:15 +02:00
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
void Update() override;
2023-05-22 16:27:15 +02:00
auto type() const -> int override { return Type; }
enum
{
Type = UserType + static_cast<int>(Vis::TextGraphicsItem)
};
2023-05-22 16:27:15 +02:00
void SetFont(const QFont &fnt);
2023-06-22 17:30:43 +02:00
void SetSVGFontFamily(const QString &fntFamily);
void SetSVGFontPointSize(int pointSize);
2023-05-03 13:07:02 +02:00
auto GetFontSize() const -> int;
void SetSize(qreal fW, qreal fH);
2023-05-03 13:07:02 +02:00
auto IsContained(QRectF rectBB, qreal dRot, qreal &dX, qreal &dY) const -> bool;
2023-05-22 16:27:15 +02:00
void UpdateData(const QString &qsName, const VPieceLabelData &data, const VContainer *pattern);
void UpdateData(VAbstractPattern *pDoc, const VContainer *pattern);
2023-05-03 13:07:02 +02:00
auto GetTextLines() const -> vsizetype;
2023-05-22 16:30:18 +02:00
void SetPieceName(const QString &name);
protected:
2023-05-22 16:27:15 +02:00
void mousePressEvent(QGraphicsSceneMouseEvent *pME) override;
void mouseMoveEvent(QGraphicsSceneMouseEvent *pME) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *pME) override;
void hoverEnterEvent(QGraphicsSceneHoverEvent *pME) override;
void hoverMoveEvent(QGraphicsSceneHoverEvent *pHE) override;
void UpdateBox();
void CorrectLabel();
signals:
2023-05-22 16:30:18 +02:00
void SignalResized(qreal iTW);
void SignalRotated(qreal dAng);
void SignalShrink();
private:
2022-08-12 17:50:13 +02:00
Q_DISABLE_COPY_MOVE(VTextGraphicsItem) // NOLINT
2023-05-22 16:27:15 +02:00
QPointF m_ptStartPos{};
QPointF m_ptStart{};
QSizeF m_szStart{};
double m_dRotation{0};
double m_dAngle{0};
QRectF m_rectResize{};
VTextManager m_tm{};
2023-05-22 16:30:18 +02:00
QString m_pieceName{};
ItemType m_itemType{Unknown};
void AllUserModifications(const QPointF &pos);
void UserRotateAndMove();
void UserMoveAndResize(const QPointF &pos);
2023-05-22 16:27:15 +02:00
void MoveLabel(QGraphicsSceneMouseEvent *pME);
void ResizeLabel(QGraphicsSceneMouseEvent *pME);
void RotateLabel(QGraphicsSceneMouseEvent *pME);
2023-05-22 16:30:18 +02:00
void PaintLabel(QPainter *painter);
2023-06-22 17:30:43 +02:00
void PaintLabelOutlineFont(QPainter *painter);
void PaintLabelSVGFont(QPainter *painter);
void NotEnoughSpace() const;
};
#endif // VTEXTGRAPHICSITEM_H