valentina/src/libs/vlayout/vtextmanager.h

128 lines
4.2 KiB
C
Raw Normal View History

/************************************************************************
**
** @file vpatternpiecedata.cpp
** @author Bojan Kverh
** @date July 19, 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 VTEXTMANAGER_H
#define VTEXTMANAGER_H
2023-05-18 09:27:40 +02:00
#include <QCoreApplication>
#include <QDate>
#include <QFont>
#include <QList>
#include <QString>
#include <QStringList>
2023-05-18 09:27:40 +02:00
#include <QVector>
#include <QtGlobal>
2023-05-18 09:27:40 +02:00
2023-07-15 16:35:16 +02:00
#include "../vmisc/def.h"
2023-05-18 09:27:40 +02:00
#include "../vmisc/defglobal.h"
class VPieceLabelData;
class VAbstractPattern;
class VContainer;
2023-06-22 17:30:43 +02:00
class VSvgFont;
/**
* @brief The TextLine struct holds the information about one text line
*/
struct TextLine
{
2023-05-18 09:27:40 +02:00
QString m_qsText{};
2023-05-22 16:30:18 +02:00
int m_iFontSize{0}; // 0 means default
2023-05-18 09:27:40 +02:00
bool m_bold{false};
bool m_italic{false};
Qt::Alignment m_eAlign{Qt::AlignCenter};
2023-05-18 09:27:40 +02:00
friend auto operator<<(QDataStream &dataStream, const TextLine &data) -> QDataStream &;
friend auto operator>>(QDataStream &dataStream, TextLine &data) -> QDataStream &;
private:
static const quint32 streamHeader;
static const quint16 classVersion;
};
/**
* @brief The VTextManager class this class is used to determine whether a collection of
* text lines can fit into specified bounding box and with what font size
*/
class VTextManager
{
2022-08-12 17:50:13 +02:00
Q_DECLARE_TR_FUNCTIONS(VTextManager) // NOLINT
2023-05-18 09:27:40 +02:00
public:
2023-07-15 16:35:16 +02:00
DEF_CONSTRUCTOR(VTextManager)
virtual ~VTextManager() = default;
2023-01-16 10:40:21 +01:00
VTextManager(const VTextManager &text) = default;
auto operator=(const VTextManager &text) -> VTextManager & = default;
VTextManager(VTextManager &&text) noexcept = default;
auto operator=(VTextManager &&text) noexcept -> VTextManager & = default;
2021-08-14 14:19:28 +02:00
virtual auto GetSpacing() const -> int;
2023-05-18 09:27:40 +02:00
void SetFont(const QFont &font);
auto GetFont() const -> const QFont &;
2023-06-22 17:30:43 +02:00
void SetSVGFontFamily(const QString &fontFamily);
auto GetSVGFontFamily() const -> QString;
void SetSVGFontPointSize(int pointSize);
auto GetSVGFontPointSize() const -> int;
2021-08-14 14:19:28 +02:00
void SetFontSize(int iFS);
2021-08-14 14:19:28 +02:00
auto GetAllSourceLines() const -> QVector<TextLine>;
void SetAllSourceLines(const QVector<TextLine> &lines);
auto GetSourceLinesCount() const -> vsizetype;
2023-05-18 09:27:40 +02:00
auto GetSourceLine(vsizetype i) const -> const TextLine &;
2023-05-22 16:30:18 +02:00
auto GetLabelSourceLines(int width, const QFont &font) const -> QVector<TextLine>;
2023-06-22 17:30:43 +02:00
auto GetLabelSourceLines(int width, const VSvgFont &font, qreal penWidth) const -> QVector<TextLine>;
2023-05-22 16:30:18 +02:00
2023-05-18 09:27:40 +02:00
void Update(const QString &qsName, const VPieceLabelData &data, const VContainer *pattern);
void Update(VAbstractPattern *pDoc, const VContainer *pattern);
2023-05-18 09:27:40 +02:00
friend auto operator<<(QDataStream &dataStream, const VTextManager &data) -> QDataStream &;
friend auto operator>>(QDataStream &dataStream, VTextManager &data) -> QDataStream &;
private:
2023-05-18 09:27:40 +02:00
QFont m_font{};
2023-06-22 17:30:43 +02:00
QString m_svgFontFamily{};
int m_svgFontPointSize{-1};
2023-01-16 10:40:21 +01:00
QVector<TextLine> m_liLines{};
static const quint32 streamHeader;
static const quint16 classVersion;
2023-05-22 16:30:18 +02:00
2023-11-16 10:19:24 +01:00
static auto BreakTextIntoLines(const QString &text, const QFont &font, int maxWidth) -> QStringList;
2023-06-22 17:30:43 +02:00
auto BreakTextIntoLines(const QString &text, const VSvgFont &font, int maxWidth, qreal penWidth) const
-> QStringList;
};
#endif // VTEXTMANAGER_H