mirror of
https://github.com/python-LimeReport/LimeReport.git
synced 2024-12-25 13:04:38 +03:00
textLayoutDirection property has been added to TextItem
This commit is contained in:
parent
e327c64fed
commit
0261a11b30
@ -58,7 +58,7 @@ namespace LimeReport{
|
|||||||
|
|
||||||
TextItem::TextItem(QObject *owner, QGraphicsItem *parent)
|
TextItem::TextItem(QObject *owner, QGraphicsItem *parent)
|
||||||
: ContentItemDesignIntf(xmlTag,owner,parent), m_angle(Angle0), m_trimValue(true), m_allowHTML(false),
|
: ContentItemDesignIntf(xmlTag,owner,parent), m_angle(Angle0), m_trimValue(true), m_allowHTML(false),
|
||||||
m_allowHTMLInFields(false), m_followTo(""), m_follower(0), m_textIndent(0)
|
m_allowHTMLInFields(false), m_followTo(""), m_follower(0), m_textIndent(0), m_textLayoutDirection(Qt::LayoutDirectionAuto)
|
||||||
{
|
{
|
||||||
PageItemDesignIntf* pageItem = dynamic_cast<PageItemDesignIntf*>(parent);
|
PageItemDesignIntf* pageItem = dynamic_cast<PageItemDesignIntf*>(parent);
|
||||||
BaseDesignIntf* parentItem = dynamic_cast<BaseDesignIntf*>(parent);
|
BaseDesignIntf* parentItem = dynamic_cast<BaseDesignIntf*>(parent);
|
||||||
@ -92,7 +92,7 @@ void TextItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* style, Q
|
|||||||
setupPainter(painter);
|
setupPainter(painter);
|
||||||
prepareRect(painter,style,widget);
|
prepareRect(painter,style,widget);
|
||||||
|
|
||||||
QSizeF tmpSize = rect().size()-m_textSize;
|
QSizeF tmpSize = rect().size()-text->size();
|
||||||
|
|
||||||
if (!painter->clipRegion().isEmpty()){
|
if (!painter->clipRegion().isEmpty()){
|
||||||
QRegion clipReg=painter->clipRegion().xored(painter->clipRegion().subtracted(rect().toRect()));
|
QRegion clipReg=painter->clipRegion().xored(painter->clipRegion().subtracted(rect().toRect()));
|
||||||
@ -228,11 +228,12 @@ void TextItem::setContent(const QString &value)
|
|||||||
else
|
else
|
||||||
m_strText=value;
|
m_strText=value;
|
||||||
|
|
||||||
if (itemMode() == DesignMode){
|
// if (itemMode() == DesignMode && (autoHeight())){
|
||||||
initTextSizes();
|
// initTextSizes();
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (!isLoading()){
|
if (!isLoading()){
|
||||||
|
if (autoHeight() || autoWidth())
|
||||||
initTextSizes();
|
initTextSizes();
|
||||||
update(rect());
|
update(rect());
|
||||||
notify("content",oldValue,value);
|
notify("content",oldValue,value);
|
||||||
@ -244,7 +245,7 @@ void TextItem::updateItemSize(DataSourceManager* dataManager, RenderPass pass, i
|
|||||||
{
|
{
|
||||||
if (isNeedExpandContent())
|
if (isNeedExpandContent())
|
||||||
expandContent(dataManager, pass);
|
expandContent(dataManager, pass);
|
||||||
if (!isLoading())
|
if (!isLoading() && (autoHeight() || autoWidth()) )
|
||||||
initTextSizes();
|
initTextSizes();
|
||||||
|
|
||||||
if (m_textSize.width()>width() && ((m_autoWidth==MaxWordLength)||(m_autoWidth==MaxStringLength))){
|
if (m_textSize.width()>width() && ((m_autoWidth==MaxWordLength)||(m_autoWidth==MaxStringLength))){
|
||||||
@ -296,7 +297,7 @@ QString TextItem::replaceReturns(QString text)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextItem::setTextFont(TextPtr text, const QFont& value) {
|
void TextItem::setTextFont(TextPtr text, const QFont& value) const {
|
||||||
text->setDefaultFont(value);
|
text->setDefaultFont(value);
|
||||||
if ((m_angle==Angle0)||(m_angle==Angle180)){
|
if ((m_angle==Angle0)||(m_angle==Angle180)){
|
||||||
text->setTextWidth(rect().width()-fakeMarginSize()*2);
|
text->setTextWidth(rect().width()-fakeMarginSize()*2);
|
||||||
@ -305,7 +306,7 @@ void TextItem::setTextFont(TextPtr text, const QFont& value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextItem::adaptFontSize(TextPtr text) {
|
void TextItem::adaptFontSize(TextPtr text) const{
|
||||||
QFont _font = transformToSceneFont(font());
|
QFont _font = transformToSceneFont(font());
|
||||||
do{
|
do{
|
||||||
setTextFont(text,_font);
|
setTextFont(text,_font);
|
||||||
@ -337,13 +338,14 @@ void TextItem::setLineSpacing(int value)
|
|||||||
{
|
{
|
||||||
int oldValue = m_lineSpacing;
|
int oldValue = m_lineSpacing;
|
||||||
m_lineSpacing = value;
|
m_lineSpacing = value;
|
||||||
initTextSizes();
|
// if (autoHeight())
|
||||||
|
// initTextSizes();
|
||||||
update();
|
update();
|
||||||
notify("lineSpacing",oldValue,value);
|
notify("lineSpacing",oldValue,value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TextItem::initTextSizes()
|
void TextItem::initTextSizes() const
|
||||||
{
|
{
|
||||||
TextPtr text = textDocument();
|
TextPtr text = textDocument();
|
||||||
m_textSize= text->size();
|
m_textSize= text->size();
|
||||||
@ -412,7 +414,7 @@ QString TextItem::formatFieldValue()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TextItem::TextPtr TextItem::textDocument()
|
TextItem::TextPtr TextItem::textDocument() const
|
||||||
{
|
{
|
||||||
TextPtr text(new QTextDocument);
|
TextPtr text(new QTextDocument);
|
||||||
|
|
||||||
@ -423,6 +425,8 @@ TextItem::TextPtr TextItem::textDocument()
|
|||||||
|
|
||||||
QTextOption to;
|
QTextOption to;
|
||||||
to.setAlignment(m_alignment);
|
to.setAlignment(m_alignment);
|
||||||
|
to.setTextDirection(m_textLayoutDirection);
|
||||||
|
//to.setTextDirection(QApplication::layoutDirection());
|
||||||
|
|
||||||
if (m_autoWidth!=MaxStringLength)
|
if (m_autoWidth!=MaxStringLength)
|
||||||
if (m_adaptFontToSize && (!(m_autoHeight || m_autoWidth)))
|
if (m_adaptFontToSize && (!(m_autoHeight || m_autoWidth)))
|
||||||
@ -474,6 +478,22 @@ void TextItem::setTextIndent(const qreal &textIndent)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Qt::LayoutDirection TextItem::textLayoutDirection() const
|
||||||
|
{
|
||||||
|
return m_textLayoutDirection;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextItem::setTextLayoutDirection(const Qt::LayoutDirection &textLayoutDirection)
|
||||||
|
{
|
||||||
|
if (m_textLayoutDirection != textLayoutDirection){
|
||||||
|
int oldValue = int(m_textLayoutDirection);
|
||||||
|
m_textLayoutDirection = textLayoutDirection;
|
||||||
|
update();
|
||||||
|
notify("textLayoutDirection",oldValue,int(textLayoutDirection));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QString TextItem::followTo() const
|
QString TextItem::followTo() const
|
||||||
{
|
{
|
||||||
return m_followTo;
|
return m_followTo;
|
||||||
@ -624,6 +644,11 @@ void TextItem::geometryChangedEvent(QRectF , QRectF)
|
|||||||
bool TextItem::isNeedUpdateSize(RenderPass pass) const
|
bool TextItem::isNeedUpdateSize(RenderPass pass) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(pass)
|
Q_UNUSED(pass)
|
||||||
|
|
||||||
|
if (autoHeight() && autoWidth()){
|
||||||
|
initTextSizes();
|
||||||
|
}
|
||||||
|
|
||||||
bool res = (m_textSize.height()>geometry().height()&&autoHeight()) ||
|
bool res = (m_textSize.height()>geometry().height()&&autoHeight()) ||
|
||||||
(m_textSize.width()>geometry().width()&&autoWidth()) ||
|
(m_textSize.width()>geometry().width()&&autoWidth()) ||
|
||||||
m_follower ||
|
m_follower ||
|
||||||
@ -795,9 +820,10 @@ BaseDesignIntf *TextItem::cloneEmpty(int height, QObject *owner, QGraphicsItem *
|
|||||||
void TextItem::objectLoadFinished()
|
void TextItem::objectLoadFinished()
|
||||||
{
|
{
|
||||||
ItemDesignIntf::objectLoadFinished();
|
ItemDesignIntf::objectLoadFinished();
|
||||||
if (itemMode() == DesignMode || !isNeedExpandContent()){
|
// if (itemMode() == DesignMode || !isNeedExpandContent()){
|
||||||
initTextSizes();
|
// if (autoHeight() && autoWidth())
|
||||||
}
|
// initTextSizes();
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextItem::setTextItemFont(QFont value)
|
void TextItem::setTextItemFont(QFont value)
|
||||||
|
@ -70,6 +70,7 @@ class TextItem : public LimeReport::ContentItemDesignIntf, IPageInit {
|
|||||||
Q_PROPERTY(QString followTo READ followTo WRITE setFollowTo)
|
Q_PROPERTY(QString followTo READ followTo WRITE setFollowTo)
|
||||||
Q_PROPERTY(BrushStyle backgroundBrushStyle READ backgroundBrushStyle WRITE setBackgroundBrushStyle)
|
Q_PROPERTY(BrushStyle backgroundBrushStyle READ backgroundBrushStyle WRITE setBackgroundBrushStyle)
|
||||||
Q_PROPERTY(qreal textIndent READ textIndent WRITE setTextIndent)
|
Q_PROPERTY(qreal textIndent READ textIndent WRITE setTextIndent)
|
||||||
|
Q_PROPERTY(Qt::LayoutDirection textLayoutDirection READ textLayoutDirection WRITE setTextLayoutDirection)
|
||||||
public:
|
public:
|
||||||
|
|
||||||
enum AutoWidth{NoneAutoWidth,MaxWordLength,MaxStringLength};
|
enum AutoWidth{NoneAutoWidth,MaxWordLength,MaxStringLength};
|
||||||
@ -160,6 +161,8 @@ public:
|
|||||||
|
|
||||||
qreal textIndent() const;
|
qreal textIndent() const;
|
||||||
void setTextIndent(const qreal &textIndent);
|
void setTextIndent(const qreal &textIndent);
|
||||||
|
Qt::LayoutDirection textLayoutDirection() const;
|
||||||
|
void setTextLayoutDirection(const Qt::LayoutDirection &textLayoutDirection);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void updateLayout();
|
void updateLayout();
|
||||||
@ -170,24 +173,23 @@ protected:
|
|||||||
QString getTextPart(int height, int skipHeight);
|
QString getTextPart(int height, int skipHeight);
|
||||||
void restoreLinksEvent();
|
void restoreLinksEvent();
|
||||||
private:
|
private:
|
||||||
void initTextSizes();
|
void initTextSizes() const;
|
||||||
void setTextFont(TextPtr text, const QFont &value);
|
void setTextFont(TextPtr text, const QFont &value) const;
|
||||||
void adaptFontSize(TextPtr text);
|
void adaptFontSize(TextPtr text) const;
|
||||||
QString formatDateTime(const QDateTime &value);
|
QString formatDateTime(const QDateTime &value);
|
||||||
QString formatNumber(const double value);
|
QString formatNumber(const double value);
|
||||||
QString formatFieldValue();
|
QString formatFieldValue();
|
||||||
|
|
||||||
TextPtr textDocument();
|
TextPtr textDocument() const;
|
||||||
private:
|
private:
|
||||||
QString m_strText;
|
QString m_strText;
|
||||||
|
|
||||||
//QTextLayout m_layout;
|
//QTextLayout m_layout;
|
||||||
//QTextDocument* m_text;
|
//QTextDocument* m_text;
|
||||||
Qt::Alignment m_alignment;
|
Qt::Alignment m_alignment;
|
||||||
bool m_autoHeight;
|
bool m_autoHeight;
|
||||||
AutoWidth m_autoWidth;
|
AutoWidth m_autoWidth;
|
||||||
QSizeF m_textSize;
|
QSizeF mutable m_textSize;
|
||||||
qreal m_firstLineSize;
|
qreal mutable m_firstLineSize;
|
||||||
AngleType m_angle;
|
AngleType m_angle;
|
||||||
int m_foregroundOpacity;
|
int m_foregroundOpacity;
|
||||||
bool m_underlines;
|
bool m_underlines;
|
||||||
@ -203,6 +205,7 @@ private:
|
|||||||
QString m_followTo;
|
QString m_followTo;
|
||||||
TextItem* m_follower;
|
TextItem* m_follower;
|
||||||
qreal m_textIndent;
|
qreal m_textIndent;
|
||||||
|
Qt::LayoutDirection m_textLayoutDirection;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user