2016-02-17 10:11:00 +03:00
|
|
|
/***************************************************************************
|
|
|
|
* This file is part of the Lime Report project *
|
|
|
|
* Copyright (C) 2015 by Alexander Arin *
|
|
|
|
* arin_a@bk.ru *
|
|
|
|
* *
|
|
|
|
** GNU General Public License Usage **
|
|
|
|
* *
|
|
|
|
* This library 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. *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
** GNU Lesser General Public License **
|
|
|
|
* *
|
|
|
|
* This library is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU Lesser General Public License as *
|
|
|
|
* published by the Free Software Foundation, either version 3 of the *
|
|
|
|
* License, or (at your option) any later version. *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public *
|
|
|
|
* License along with this library. *
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
* This library 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. *
|
|
|
|
****************************************************************************/
|
|
|
|
#ifndef LRTEXTITEM_H
|
|
|
|
#define LRTEXTITEM_H
|
|
|
|
#include <QGraphicsTextItem>
|
|
|
|
#include <QtGui>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QTextDocument>
|
|
|
|
|
2016-11-04 01:11:45 +03:00
|
|
|
#include "lritemdesignintf.h"
|
|
|
|
#include "lritemdesignintf.h"
|
|
|
|
#include "lrpageinitintf.h"
|
|
|
|
|
2016-02-17 10:11:00 +03:00
|
|
|
namespace LimeReport {
|
|
|
|
|
|
|
|
class Tag;
|
2016-11-04 01:11:45 +03:00
|
|
|
class TextItem : public LimeReport::ContentItemDesignIntf, IPageInit {
|
2016-02-17 10:11:00 +03:00
|
|
|
Q_OBJECT
|
|
|
|
Q_ENUMS(AutoWidth)
|
|
|
|
Q_ENUMS(AngleType)
|
2016-07-26 17:01:14 +03:00
|
|
|
Q_ENUMS(ValueType)
|
2016-02-17 10:11:00 +03:00
|
|
|
Q_PROPERTY(QString content READ content WRITE setContent)
|
|
|
|
Q_PROPERTY(int margin READ marginSize WRITE setMarginSize)
|
|
|
|
Q_PROPERTY(Qt::Alignment alignment READ alignment() WRITE setAlignment)
|
|
|
|
Q_PROPERTY(AutoWidth autoWidth READ autoWidth() WRITE setAutoWidth)
|
|
|
|
Q_PROPERTY(bool autoHeight READ autoHeight() WRITE setAutoHeight)
|
|
|
|
Q_PROPERTY(QFont font READ font() WRITE setTextItemFont)
|
|
|
|
Q_PROPERTY(int backgroundOpacity READ opacity WRITE setBackgroundOpacity)
|
|
|
|
Q_PROPERTY(BGMode backgroundMode READ backgroundMode WRITE setBackgroundModeProperty)
|
|
|
|
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColorProperty)
|
|
|
|
Q_PROPERTY(QColor fontColor READ fontColor WRITE setFontColorProperty)
|
|
|
|
Q_PROPERTY(AngleType angle READ angle WRITE setAngle)
|
2016-04-13 13:38:07 +03:00
|
|
|
Q_PROPERTY(int foregroundOpacity READ foregroundOpacity WRITE setForegroundOpacity)
|
2016-06-10 18:05:18 +03:00
|
|
|
Q_PROPERTY(bool underlines READ underlines WRITE setUnderlines)
|
|
|
|
Q_PROPERTY(bool adaptFontToSize READ adaptFontToSize WRITE setAdaptFontToSize)
|
2016-02-17 10:11:00 +03:00
|
|
|
Q_PROPERTY(bool trimValue READ trimValue WRITE setTrimValue)
|
2016-06-10 18:05:18 +03:00
|
|
|
Q_PROPERTY(int lineSpacing READ lineSpacing WRITE setLineSpacing)
|
|
|
|
Q_PROPERTY(int underlineLineSize READ underlineLineSize WRITE setUnderlineLineSize)
|
2016-02-17 10:39:17 +03:00
|
|
|
Q_PROPERTY(bool allowHTML READ allowHTML WRITE setAllowHTML)
|
2016-04-13 13:38:07 +03:00
|
|
|
Q_PROPERTY(bool allowHTMLInFields READ allowHTMLInFields WRITE setAllowHTMLInFields)
|
2016-07-26 17:01:14 +03:00
|
|
|
Q_PROPERTY(QString format READ format WRITE setFormat)
|
|
|
|
Q_PROPERTY(ValueType valueType READ valueType WRITE setValueType)
|
2016-11-04 01:11:45 +03:00
|
|
|
Q_PROPERTY(QString followTo READ followTo WRITE setFollowTo)
|
2016-12-21 22:09:10 +03:00
|
|
|
Q_PROPERTY(BrushStyle backgroundBrushStyle READ backgroundBrushStyle WRITE setBackgroundBrushStyle)
|
2017-01-20 23:07:54 +03:00
|
|
|
Q_PROPERTY(qreal textIndent READ textIndent WRITE setTextIndent)
|
2017-01-20 23:26:18 +03:00
|
|
|
Q_PROPERTY(Qt::LayoutDirection textLayoutDirection READ textLayoutDirection WRITE setTextLayoutDirection)
|
2017-08-31 02:53:34 +03:00
|
|
|
Q_PROPERTY(bool fillInSecondPass READ fillInSecondPass WRITE setFillInSecondPass)
|
2018-03-22 17:17:04 +03:00
|
|
|
Q_PROPERTY(bool watermark READ isWatermark WRITE setWatermark)
|
2016-02-17 10:11:00 +03:00
|
|
|
public:
|
|
|
|
|
|
|
|
enum AutoWidth{NoneAutoWidth,MaxWordLength,MaxStringLength};
|
|
|
|
enum AngleType{Angle0,Angle90,Angle180,Angle270,Angle45,Angle315};
|
2016-07-26 17:01:14 +03:00
|
|
|
enum ValueType{Default,DateTime,Double};
|
2016-02-17 10:11:00 +03:00
|
|
|
|
|
|
|
void Init();
|
2016-02-17 10:39:17 +03:00
|
|
|
TextItem(QObject* owner=0, QGraphicsItem* parent=0);
|
2016-02-17 10:11:00 +03:00
|
|
|
~TextItem();
|
|
|
|
|
2016-02-17 10:39:17 +03:00
|
|
|
void paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*);
|
2016-02-17 10:11:00 +03:00
|
|
|
QString content() const;
|
|
|
|
void setContent(const QString& value);
|
|
|
|
|
|
|
|
void setAlignment(Qt::Alignment value);
|
|
|
|
Qt::Alignment alignment(){return m_alignment;}
|
|
|
|
|
2016-02-17 10:28:27 +03:00
|
|
|
void geometryChangedEvent(QRectF, QRectF);
|
|
|
|
bool isNeedUpdateSize(RenderPass) const;
|
|
|
|
void updateItemSize(DataSourceManager *dataManager, RenderPass pass, int maxHeight);
|
|
|
|
void expandContent(DataSourceManager *dataManager, RenderPass pass);
|
2016-02-17 10:11:00 +03:00
|
|
|
|
|
|
|
void setAutoHeight(bool value);
|
|
|
|
bool autoHeight() const {return m_autoHeight;}
|
|
|
|
|
|
|
|
void setAutoWidth(AutoWidth value);
|
|
|
|
AutoWidth autoWidth() const {return m_autoWidth;}
|
|
|
|
|
2016-06-10 18:05:18 +03:00
|
|
|
void setAdaptFontToSize(bool value);
|
|
|
|
bool adaptFontToSize() const {return m_adaptFontToSize;}
|
|
|
|
|
2016-02-17 10:11:00 +03:00
|
|
|
bool canBeSplitted(int height) const;
|
|
|
|
bool isSplittable() const { return true;}
|
2016-12-07 23:04:15 +03:00
|
|
|
bool isEmpty() const{return m_strText.trimmed().isEmpty() /*m_text->isEmpty()*/;}
|
2016-02-17 10:11:00 +03:00
|
|
|
BaseDesignIntf* cloneUpperPart(int height, QObject *owner, QGraphicsItem *parent);
|
|
|
|
BaseDesignIntf* cloneBottomPart(int height, QObject *owner, QGraphicsItem *parent);
|
|
|
|
BaseDesignIntf* createSameTypeItem(QObject* owner=0, QGraphicsItem* parent=0);
|
|
|
|
BaseDesignIntf* cloneEmpty(int height, QObject *owner, QGraphicsItem *parent);
|
|
|
|
void objectLoadFinished();
|
|
|
|
|
|
|
|
void setTextItemFont(QFont value);
|
2016-02-17 10:18:19 +03:00
|
|
|
QWidget* defaultEditor();
|
2016-02-17 10:11:00 +03:00
|
|
|
void setBackgroundOpacity(int value);
|
|
|
|
void setBackgroundModeProperty(BGMode value);
|
|
|
|
void setBackgroundColorProperty(QColor value);
|
|
|
|
void setFontColorProperty(QColor value);
|
|
|
|
AngleType angle() const;
|
|
|
|
void setAngle(const AngleType& value);
|
|
|
|
int foregroundOpacity(){return m_foregroundOpacity;}
|
|
|
|
void setForegroundOpacity(int value);
|
2016-06-10 18:05:18 +03:00
|
|
|
bool underlines(){return m_underlines;}
|
|
|
|
void setUnderlines(bool value);
|
2016-02-17 10:11:00 +03:00
|
|
|
|
|
|
|
bool trimValue() const;
|
|
|
|
void setTrimValue(bool trimValue);
|
|
|
|
|
2016-06-10 18:05:18 +03:00
|
|
|
int lineSpacing() const;
|
|
|
|
void setLineSpacing(int value);
|
|
|
|
|
|
|
|
int underlineLineSize() const;
|
|
|
|
void setUnderlineLineSize(int value);
|
|
|
|
|
2016-02-17 10:39:17 +03:00
|
|
|
bool allowHTML() const;
|
|
|
|
void setAllowHTML(bool allowHTML);
|
|
|
|
|
2016-04-13 13:38:07 +03:00
|
|
|
bool allowHTMLInFields() const;
|
|
|
|
void setAllowHTMLInFields(bool allowHTMLInFields);
|
|
|
|
|
2016-07-26 17:01:14 +03:00
|
|
|
QString format() const;
|
|
|
|
void setFormat(const QString &format);
|
|
|
|
|
|
|
|
ValueType valueType() const;
|
|
|
|
void setValueType(const ValueType valueType);
|
|
|
|
|
2016-11-04 01:11:45 +03:00
|
|
|
QSizeF textSize(){ return m_textSize;}
|
|
|
|
QString followTo() const;
|
|
|
|
void setFollowTo(const QString &followTo);
|
|
|
|
void setFollower(TextItem* follower);
|
2016-12-24 11:49:56 +03:00
|
|
|
void clearFollower();
|
2017-01-23 11:53:07 +03:00
|
|
|
bool hasFollower() const;
|
|
|
|
TextItem* follower() const { return m_follower;}
|
2016-11-04 01:11:45 +03:00
|
|
|
bool initFollower(QString follower);
|
|
|
|
|
|
|
|
// IPageInit interface
|
|
|
|
void pageObjectHasBeenLoaded();
|
|
|
|
|
2016-12-13 00:07:50 +03:00
|
|
|
typedef QSharedPointer<QTextDocument> TextPtr;
|
|
|
|
|
2017-01-20 23:07:54 +03:00
|
|
|
qreal textIndent() const;
|
|
|
|
void setTextIndent(const qreal &textIndent);
|
2017-01-20 23:26:18 +03:00
|
|
|
Qt::LayoutDirection textLayoutDirection() const;
|
|
|
|
void setTextLayoutDirection(const Qt::LayoutDirection &textLayoutDirection);
|
|
|
|
|
2016-02-17 10:11:00 +03:00
|
|
|
protected:
|
|
|
|
void updateLayout();
|
|
|
|
bool isNeedExpandContent() const;
|
|
|
|
QString replaceBR(QString text);
|
|
|
|
QString replaceReturns(QString text);
|
2016-12-13 00:07:50 +03:00
|
|
|
int fakeMarginSize() const;
|
2016-11-04 01:11:45 +03:00
|
|
|
QString getTextPart(int height, int skipHeight);
|
|
|
|
void restoreLinksEvent();
|
2017-02-24 07:13:43 +03:00
|
|
|
void preparePopUpMenu(QMenu &menu);
|
|
|
|
void processPopUpAction(QAction *action);
|
2016-02-17 10:11:00 +03:00
|
|
|
private:
|
2017-01-20 23:26:18 +03:00
|
|
|
void initTextSizes() const;
|
|
|
|
void setTextFont(TextPtr text, const QFont &value) const;
|
|
|
|
void adaptFontSize(TextPtr text) const;
|
2016-07-26 17:01:14 +03:00
|
|
|
QString formatDateTime(const QDateTime &value);
|
|
|
|
QString formatNumber(const double value);
|
|
|
|
QString formatFieldValue();
|
2017-12-07 19:52:52 +03:00
|
|
|
QString extractText(QTextBlock& curBlock, int height);
|
2017-01-20 23:26:18 +03:00
|
|
|
TextPtr textDocument() const;
|
2016-02-17 10:11:00 +03:00
|
|
|
private:
|
|
|
|
QString m_strText;
|
2016-02-17 10:39:17 +03:00
|
|
|
//QTextLayout m_layout;
|
2017-01-20 23:26:18 +03:00
|
|
|
//QTextDocument* m_text;
|
2016-02-17 10:11:00 +03:00
|
|
|
Qt::Alignment m_alignment;
|
|
|
|
bool m_autoHeight;
|
|
|
|
AutoWidth m_autoWidth;
|
2017-01-20 23:26:18 +03:00
|
|
|
QSizeF mutable m_textSize;
|
|
|
|
qreal mutable m_firstLineSize;
|
2016-02-17 10:11:00 +03:00
|
|
|
AngleType m_angle;
|
|
|
|
int m_foregroundOpacity;
|
2016-06-10 18:05:18 +03:00
|
|
|
bool m_underlines;
|
|
|
|
bool m_adaptFontToSize;
|
2016-02-17 10:11:00 +03:00
|
|
|
bool m_trimValue;
|
2016-06-10 18:05:18 +03:00
|
|
|
int m_lineSpacing;
|
|
|
|
int m_underlineLineSize;
|
2016-02-17 10:39:17 +03:00
|
|
|
bool m_allowHTML;
|
2016-04-13 13:38:07 +03:00
|
|
|
bool m_allowHTMLInFields;
|
2016-07-26 17:01:14 +03:00
|
|
|
|
|
|
|
QString m_format;
|
|
|
|
ValueType m_valueType;
|
2016-11-04 01:11:45 +03:00
|
|
|
QString m_followTo;
|
|
|
|
TextItem* m_follower;
|
2017-01-20 23:07:54 +03:00
|
|
|
qreal m_textIndent;
|
2017-01-20 23:26:18 +03:00
|
|
|
Qt::LayoutDirection m_textLayoutDirection;
|
2017-12-07 19:52:52 +03:00
|
|
|
|
2016-02-17 10:11:00 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif // LRTEXTITEM_H
|