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