0
0
mirror of https://github.com/fralx/LimeReport.git synced 2025-09-23 08:29:07 +03:00

Merge branch '1.4' into 1.4_QJSEngine

# Conflicts:
#	limereport/lritemdesignintf.cpp
#	limereport/lrreportrender.cpp
#	limereport/lrscriptenginemanager.cpp
This commit is contained in:
Arin Alexander
2017-02-08 19:21:08 +03:00
50 changed files with 5138 additions and 532 deletions

View File

@@ -56,16 +56,21 @@ BaseDesignIntf *ImageItem::createSameTypeItem(QObject *owner, QGraphicsItem *par
void ImageItem::updateItemSize(DataSourceManager* dataManager, RenderPass pass, int maxHeight)
{
if (!m_datasource.isEmpty() && !m_field.isEmpty() && m_picture.isNull()){
IDataSource* ds = dataManager->dataSource(m_datasource);
if (ds) {
QVariant data = ds->data(m_field);
if (data.isValid()){
if (data.type()==QVariant::Image){
m_picture = data.value<QImage>();
} else
m_picture.loadFromData(data.toByteArray());
}
if (m_picture.isNull()){
if (!m_datasource.isEmpty() && !m_field.isEmpty()){
IDataSource* ds = dataManager->dataSource(m_datasource);
if (ds) {
QVariant data = ds->data(m_field);
if (data.isValid()){
if (data.type()==QVariant::Image){
m_picture = data.value<QImage>();
} else
m_picture.loadFromData(data.toByteArray());
}
}
} else if (!m_resourcePath.isEmpty()){
m_picture = QImage(m_resourcePath);
}
}
if (m_autoSize){
@@ -80,6 +85,11 @@ bool ImageItem::isNeedUpdateSize(RenderPass) const
return m_picture.isNull() || m_autoSize;
}
QString ImageItem::resourcePath() const
{
return m_resourcePath;
}
qreal ImageItem::minHeight() const{
if (!m_picture.isNull() && autoSize())
{
@@ -231,6 +241,7 @@ void ImageItem::paint(QPainter *ppainter, const QStyleOptionGraphicsItem *option
if (img.isNull() && itemMode()==DesignMode){
QString text;
ppainter->setFont(transformToSceneFont(QFont("Arial",10)));
ppainter->setPen(Qt::black);
if (!datasource().isEmpty() && !field().isEmpty())
text = datasource()+"."+field();
else text = tr("Image");

View File

@@ -44,12 +44,14 @@ class ImageItem : public LimeReport::ItemDesignIntf
Q_PROPERTY(bool scale READ scale WRITE setScale)
Q_PROPERTY(bool keepAspectRatio READ keepAspectRatio WRITE setKeepAspectRatio)
Q_PROPERTY(bool center READ center WRITE setCenter)
Q_PROPERTY(QString resourcePath READ resourcePath WRITE setResourcePath)
public:
ImageItem(QObject *owner, QGraphicsItem *parent);
virtual void paint(QPainter *ppainter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void setImage(QImage value);
QImage image(){return m_picture;}
void setContent(const QString &value){m_content=value;}
void setResourcePath(const QString &value){m_resourcePath=value;}
QString resourcePath() const;
QString datasource() const;
void setDatasource(const QString &datasource);
QString field() const;
@@ -72,8 +74,8 @@ protected:
bool isNeedUpdateSize(RenderPass) const;
bool drawDesignBorders() const {return m_picture.isNull();}
private:
QImage m_picture;
QString m_content;
QImage m_picture;
QString m_resourcePath;
QString m_datasource;
QString m_field;
bool m_autoSize;

View File

@@ -85,7 +85,7 @@ void ShapeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
pen.setStyle(m_penStyle);
painter->setPen(pen);
QBrush brush(m_shapeBrushColor,m_shapeBrushType);
brush.setTransform(painter->worldTransform().inverted());
painter->setBrush(brush);
painter->setBackground(QBrush(Qt::NoBrush));
painter->setOpacity(qreal(m_opacity)/100);

View File

@@ -31,6 +31,7 @@
#include <QTextLayout>
#include <QtScript/QScriptEngine>
#include <QLocale>
#include <QMessageBox>
#include <math.h>
#include "lrpagedesignintf.h"
@@ -57,10 +58,8 @@ 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_allowHTMLInFields(false), m_followTo(""), m_follower(0), m_textIndent(0), m_textLayoutDirection(Qt::LayoutDirectionAuto)
{
m_text = new QTextDocument();
PageItemDesignIntf* pageItem = dynamic_cast<PageItemDesignIntf*>(parent);
BaseDesignIntf* parentItem = dynamic_cast<BaseDesignIntf*>(parent);
while (!pageItem && parentItem){
@@ -75,12 +74,9 @@ TextItem::TextItem(QObject *owner, QGraphicsItem *parent)
Init();
}
TextItem::~TextItem()
{
delete m_text;
}
TextItem::~TextItem(){}
int TextItem::fakeMarginSize(){
int TextItem::fakeMarginSize() const{
return marginSize()+5;
}
@@ -88,12 +84,15 @@ void TextItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* style, Q
Q_UNUSED(widget);
Q_UNUSED(style);
TextPtr text = textDocument();
painter->save();
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()));
@@ -102,38 +101,38 @@ void TextItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* style, Q
painter->setClipRect(rect());
}
qreal hOffset = 0, vOffset=0;
qreal hOffset = 0, vOffset = 0;
switch (m_angle){
case Angle0:
hOffset = fakeMarginSize();
if ((tmpSize.height()>0) && (m_alignment & Qt::AlignVCenter)){
vOffset = tmpSize.height()/2;
if ((tmpSize.height() > 0) && (m_alignment & Qt::AlignVCenter)){
vOffset = tmpSize.height() / 2;
}
if ((tmpSize.height()>0) && (m_alignment & Qt::AlignBottom)) // allow html
if ((tmpSize.height() > 0) && (m_alignment & Qt::AlignBottom)) // allow html
vOffset = tmpSize.height();
painter->translate(hOffset,vOffset);
break;
case Angle90:
hOffset = width()-fakeMarginSize();
hOffset = width() - fakeMarginSize();
vOffset = fakeMarginSize();
if (m_alignment & Qt::AlignVCenter){
hOffset = (width()-m_text->size().height())/2+m_text->size().height();
hOffset = (width() - text->size().height()) / 2 + text->size().height();
}
if (m_alignment & Qt::AlignBottom){
hOffset = (m_text->size().height());
hOffset = (text->size().height());
}
painter->translate(hOffset,vOffset);
painter->rotate(90);
break;
case Angle180:
hOffset = width()-fakeMarginSize();
vOffset = height()-fakeMarginSize();
hOffset = width() - fakeMarginSize();
vOffset = height() - fakeMarginSize();
if ((tmpSize.width()>0) && (m_alignment & Qt::AlignVCenter)){
vOffset = tmpSize.height()/2+m_text->size().height();
vOffset = tmpSize.height() / 2+ text->size().height();
}
if ((tmpSize.height()>0) && (m_alignment & Qt::AlignBottom)){
vOffset = (m_text->size().height());
vOffset = (text->size().height());
}
painter->translate(hOffset,vOffset);
painter->rotate(180);
@@ -142,11 +141,11 @@ void TextItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* style, Q
hOffset = fakeMarginSize();
vOffset = height()-fakeMarginSize();
if (m_alignment & Qt::AlignVCenter){
hOffset = (width()-m_text->size().height())/2;
hOffset = (width() - text->size().height())/2;
}
if (m_alignment & Qt::AlignBottom){
hOffset = (width()-m_text->size().height());
hOffset = (width() - text->size().height());
}
painter->translate(hOffset,vOffset);
painter->rotate(270);
@@ -154,12 +153,12 @@ void TextItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* style, Q
case Angle45:
painter->translate(width()/2,0);
painter->rotate(45);
m_text->setTextWidth(sqrt(2*(pow(width()/2,2))));
text->setTextWidth(sqrt(2*(pow(width()/2,2))));
break;
case Angle315:
painter->translate(0,height()/2);
painter->rotate(315);
m_text->setTextWidth(sqrt(2*(pow(height()/2,2))));
text->setTextWidth(sqrt(2*(pow(height()/2,2))));
break;
}
@@ -175,7 +174,8 @@ void TextItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* style, Q
painter->setOpacity(qreal(foregroundOpacity())/100);
QAbstractTextDocumentLayout::PaintContext ctx;
ctx.palette.setColor(QPalette::Text, fontColor());
for(QTextBlock it=m_text->begin();it!=m_text->end();it=it.next()){
for(QTextBlock it = text->begin(); it != text->end(); it=it.next()){
it.blockFormat().setLineHeight(m_lineSpacing,QTextBlockFormat::LineDistanceHeight);
for (int i=0;i<it.layout()->lineCount();i++){
QTextLine line = it.layout()->lineAt(i);
@@ -186,7 +186,8 @@ void TextItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* style, Q
}
}
}
m_text->documentLayout()->draw(painter,ctx);
text->documentLayout()->draw(painter,ctx);
if (m_underlines){
if (lineHeight<0) lineHeight = painter->fontMetrics().height();
@@ -195,19 +196,6 @@ void TextItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* style, Q
}
}
//painter->setOpacity(qreal(foregroundOpacity())/100);
//m_text->setDefaultTextOption();
//QAbstractTextDocumentLayout::PaintContext ctx;
//ctx.palette.setColor(QPalette::Text, fontColor());
//m_text->documentLayout()->draw(painter,ctx);
// m_layout.draw(ppainter,QPointF(marginSize(),0),);
// ppainter->setFont(transformToSceneFont(font()));
// QTextOption o;
// o.setAlignment(alignment());
// ppainter->drawText(rect(), content(), o);
painter->restore();
BaseDesignIntf::paint(painter, style, widget);
}
@@ -218,11 +206,11 @@ QString TextItem::content() const{
void TextItem::Init()
{
m_autoWidth=NoneAutoWidth;
m_alignment= Qt::AlignLeft|Qt::AlignTop;
m_autoHeight=false;
// m_text->setDefaultFont(transformToSceneFont(font()));
m_textSize=QSizeF();
m_autoWidth = NoneAutoWidth;
m_alignment = Qt::AlignLeft|Qt::AlignTop;
m_autoHeight = false;
m_textSize = QSizeF();
m_firstLineSize = 0;
m_foregroundOpacity = 100;
m_underlines = false;
m_adaptFontToSize = false;
@@ -235,19 +223,18 @@ void TextItem::setContent(const QString &value)
{
if (m_strText.compare(value)!=0){
QString oldValue = m_strText;
m_strText=value;
if (allowHTML())
m_text->setHtml(replaceReturns(value.trimmed()));
if (m_trimValue)
m_strText=value.trimmed();
else
m_text->setPlainText(value);
//m_text->setTextWidth(width());
//m_textSize=m_text->size();
if (itemMode() == DesignMode){
initText();
}
m_strText=value;
// if (itemMode() == DesignMode && (autoHeight())){
// initTextSizes();
// }
if (!isLoading()){
initText();
if (autoHeight() || autoWidth() || hasFollower())
initTextSizes();
update(rect());
notify("content",oldValue,value);
}
@@ -258,15 +245,20 @@ void TextItem::updateItemSize(DataSourceManager* dataManager, RenderPass pass, i
{
if (isNeedExpandContent())
expandContent(dataManager, pass);
if (!isLoading())
initText();
if (!isLoading() && (autoHeight() || autoWidth() || hasFollower()) )
initTextSizes();
if (m_textSize.width()>width() && ((m_autoWidth==MaxWordLength)||(m_autoWidth==MaxStringLength))){
setWidth(m_textSize.width() + fakeMarginSize()*2);
}
if ((m_textSize.height()>height()) && (m_autoHeight) ){
setHeight(m_textSize.height()+borderLineSize()*2);
if (m_textSize.height()>height()) {
if (m_autoHeight)
setHeight(m_textSize.height()+borderLineSize()*2);
else if (hasFollower() && !content().isEmpty()){
follower()->setContent(getTextPart(0,height()));
setContent(getTextPart(height(),0));
}
}
BaseDesignIntf::updateItemSize(dataManager, pass, maxHeight);
}
@@ -305,24 +297,25 @@ QString TextItem::replaceReturns(QString text)
return result;
}
void TextItem::setTextFont(const QFont& value){
m_text->setDefaultFont(value);
void TextItem::setTextFont(TextPtr text, const QFont& value) const {
text->setDefaultFont(value);
if ((m_angle==Angle0)||(m_angle==Angle180)){
m_text->setTextWidth(rect().width()-fakeMarginSize()*2);
text->setTextWidth(rect().width()-fakeMarginSize()*2);
} else {
m_text->setTextWidth(rect().height()-fakeMarginSize()*2);
text->setTextWidth(rect().height()-fakeMarginSize()*2);
}
}
void TextItem::adaptFontSize(){
void TextItem::adaptFontSize(TextPtr text) const{
QFont _font = transformToSceneFont(font());
do{
setTextFont(_font);
setTextFont(text,_font);
if (_font.pixelSize()>2)
_font.setPixelSize(_font.pixelSize()-1);
else break;
} while(m_text->size().height()>this->height() || m_text->size().width()>(this->width())-fakeMarginSize()*2);
} while(text->size().height()>this->height() || text->size().width()>(this->width()) - fakeMarginSize() * 2);
}
int TextItem::underlineLineSize() const
{
return m_underlineLineSize;
@@ -345,52 +338,19 @@ void TextItem::setLineSpacing(int value)
{
int oldValue = m_lineSpacing;
m_lineSpacing = value;
initText();
// if (autoHeight())
// initTextSizes();
update();
notify("lineSpacing",oldValue,value);
}
void TextItem::initText()
void TextItem::initTextSizes() const
{
QTextOption to;
to.setAlignment(m_alignment);
if (m_autoWidth!=MaxStringLength)
if (m_adaptFontToSize && (!(m_autoHeight || m_autoWidth)))
to.setWrapMode(QTextOption::WordWrap);
else
to.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
else to.setWrapMode(QTextOption::NoWrap);
m_text->setDocumentMargin(0);
m_text->setDefaultTextOption(to);
QFont _font = transformToSceneFont(font());
if (m_adaptFontToSize && (!(m_autoHeight || m_autoWidth))){
adaptFontSize();
} else {
setTextFont(transformToSceneFont(font()));
}
if ((m_angle==Angle0)||(m_angle==Angle180)){
m_text->setTextWidth(rect().width()-fakeMarginSize()*2);
} else {
m_text->setTextWidth(rect().height()-fakeMarginSize()*2);
}
for ( QTextBlock block = m_text->begin(); block.isValid(); block = block.next())
{
QTextCursor tc = QTextCursor(block);
QTextBlockFormat fmt = block.blockFormat();
if(fmt.lineHeight() != m_lineSpacing) {
fmt.setLineHeight(m_lineSpacing,QTextBlockFormat::LineDistanceHeight);
tc.setBlockFormat( fmt );
}
}
m_textSize=m_text->size();
TextPtr text = textDocument();
m_textSize= text->size();
if (text->begin().isValid() && text->begin().layout()->lineAt(0).isValid())
m_firstLineSize = text->begin().layout()->lineAt(0).height();
}
QString TextItem::formatDateTime(const QDateTime &value)
@@ -454,6 +414,163 @@ QString TextItem::formatFieldValue()
}
}
TextItem::TextPtr TextItem::textDocument() const
{
TextPtr text(new QTextDocument);
if (allowHTML())
text->setHtml(m_strText);
else
text->setPlainText(m_strText);
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)))
to.setWrapMode(QTextOption::WordWrap);
else
to.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
else to.setWrapMode(QTextOption::NoWrap);
text->setDocumentMargin(0);
text->setDefaultTextOption(to);
QFont _font = transformToSceneFont(font());
if (m_adaptFontToSize && (!(m_autoHeight || m_autoWidth))){
adaptFontSize(text);
} else {
setTextFont(text,_font);
}
text->documentLayout();
for ( QTextBlock block = text->begin(); block.isValid(); block = block.next())
{
QTextCursor tc = QTextCursor(block);
QTextBlockFormat fmt = block.blockFormat();
fmt.setTextIndent(m_textIndent);
if(fmt.lineHeight() != m_lineSpacing) {
fmt.setLineHeight(m_lineSpacing,QTextBlockFormat::LineDistanceHeight);
tc.setBlockFormat( fmt );
}
}
return text;
}
qreal TextItem::textIndent() const
{
return m_textIndent;
}
void TextItem::setTextIndent(const qreal &textIndent)
{
if (m_textIndent != textIndent){
qreal oldValue = m_textIndent;
m_textIndent = textIndent;
update();
notify("textIndent", oldValue, 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;
}
void TextItem::setFollowTo(const QString &followTo)
{
if (m_followTo != followTo){
QString oldValue = m_followTo;
m_followTo = followTo;
if (!isLoading()){
TextItem* fi = scene()->findChild<TextItem*>(oldValue);
if (fi) fi->clearFollower();
fi = scene()->findChild<TextItem*>(followTo);
if (fi && fi != this){
if (initFollower(followTo)){
notify("followTo",oldValue,followTo);
} else {
m_followTo = "";
QMessageBox::critical(
0,
tr("Error"),
tr("TextItem \" %1 \" already has folower \" %2 \" ")
.arg(fi->objectName())
.arg(fi->follower()->objectName())
);
notify("followTo",followTo,"");
}
} else if (m_followTo != ""){
QMessageBox::critical(
0,
tr("Error"),
tr("TextItem \" %1 \" not found !")
.arg(m_followTo)
);
notify("followTo",followTo,"");
}
}
}
}
void TextItem::setFollower(TextItem *follower)
{
if (!m_follower){
m_follower = follower;
}
}
void TextItem::clearFollower()
{
m_follower = 0;
}
bool TextItem::hasFollower() const
{
return m_follower != 0;
}
bool TextItem::initFollower(QString follower)
{
TextItem* fi = scene()->findChild<TextItem*>(follower);
if (fi){
if (!fi->hasFollower()){
fi->setFollower(this);
return true;
}
}
return false;
}
void TextItem::pageObjectHasBeenLoaded()
{
if (!m_followTo.isEmpty()){
initFollower(m_followTo);
}
}
TextItem::ValueType TextItem::valueType() const
{
return m_valueType;
@@ -497,13 +614,14 @@ void TextItem::setAllowHTML(bool allowHTML)
{
if (m_allowHTML!=allowHTML){
m_allowHTML = allowHTML;
if (m_text){
if (allowHTML)
m_text->setHtml(m_strText);
else
m_text->setPlainText(m_strText);
update();
}
// if (m_text){
// if (allowHTML)
// m_text->setHtml(m_strText);
// else
// m_text->setPlainText(m_strText);
// update();
// }
update();
notify("allowHTML",!m_allowHTML,allowHTML);
}
}
@@ -521,22 +639,19 @@ void TextItem::setTrimValue(bool value)
void TextItem::geometryChangedEvent(QRectF , QRectF)
{
// if ((m_angle==Angle0)||(m_angle==Angle180)){
// m_text->setTextWidth(rect().width()-fakeMarginSize()*2);
// } else {
// m_text->setTextWidth(rect().height()-fakeMarginSize()*2);
// }
if (itemMode() == DesignMode) initText();
else if (adaptFontToSize()) initText();
}
{}
bool TextItem::isNeedUpdateSize(RenderPass pass) const
{
Q_UNUSED(pass)
if ((autoHeight() && autoWidth()) || hasFollower()){
initTextSizes();
}
bool res = (m_textSize.height()>geometry().height()&&autoHeight()) ||
(m_textSize.width()>geometry().width()&&autoWidth()) ||
m_follower ||
isNeedExpandContent();
return res;
}
@@ -548,7 +663,6 @@ void TextItem::setAlignment(Qt::Alignment value)
m_alignment=value;
//m_layout.setTextOption(QTextOption(m_alignment));
if (!isLoading()){
initText();
update(rect());
notify("alignment",QVariant(oldValue),QVariant(value));
}
@@ -575,6 +689,7 @@ void TextItem::expandContent(DataSourceManager* dataManager, RenderPass pass)
} else {
setContent(context);
}
}
void TextItem::setAutoHeight(bool value)
@@ -600,7 +715,7 @@ void TextItem::setAdaptFontToSize(bool value)
if (m_adaptFontToSize!=value){
bool oldValue = m_adaptFontToSize;
m_adaptFontToSize=value;
initText();
// initText();
invalidateRect(rect());
notify("updateFontToSize",oldValue,value);
}
@@ -608,66 +723,84 @@ void TextItem::setAdaptFontToSize(bool value)
bool TextItem::canBeSplitted(int height) const
{
return height>(m_text->begin().layout()->lineAt(0).height());
QFontMetrics fm(font());
return height > m_firstLineSize;
}
QString TextItem::getTextPart(int height, int skipHeight){
int linesHeight = 0;
int curLine = 0;
int textPos = 0;
TextPtr text = textDocument();
QTextBlock curBlock = text->begin();
QString resultText = "";
if (skipHeight > 0){
for (;curBlock != text->end(); curBlock=curBlock.next()){
for (curLine = 0; curLine < curBlock.layout()->lineCount(); curLine++){
linesHeight += curBlock.layout()->lineAt(curLine).height() + lineSpacing();
if (linesHeight > (skipHeight-(/*fakeMarginSize()*2+*/borderLineSize() * 2))) {goto loop_exit;}
}
}
loop_exit:;
}
linesHeight = 0;
for (;curBlock != text->end() || curLine<curBlock.lineCount(); curBlock = curBlock.next(), curLine = 0, resultText += '\n'){
for (; curLine<curBlock.layout()->lineCount(); curLine++){
if (resultText == "") textPos= curBlock.layout()->lineAt(curLine).textStart();
linesHeight += curBlock.layout()->lineAt(curLine).height() + lineSpacing();
if ( (height>0) && (linesHeight>(height-(/*fakeMarginSize()*2+*/borderLineSize()*2))) ) {
linesHeight-=curBlock.layout()->lineAt(curLine).height();
goto loop_exit1;
}
resultText+=curBlock.text().mid(curBlock.layout()->lineAt(curLine).textStart(),
curBlock.layout()->lineAt(curLine).textLength());
}
}
loop_exit1:;
resultText.chop(1);
QScopedPointer<HtmlContext> context(new HtmlContext(m_strText));
return context->extendTextByTags(resultText,textPos);
}
void TextItem::restoreLinksEvent()
{
if (!followTo().isEmpty()){
BaseDesignIntf* pi = dynamic_cast<BaseDesignIntf*>(parentItem());
if (pi){
foreach (BaseDesignIntf* bi, pi->childBaseItems()) {
if (bi->patternName().compare(followTo())==0){
TextItem* ti = dynamic_cast<TextItem*>(bi);
if (ti){
ti->setFollower(this);
}
}
}
}
}
}
BaseDesignIntf *TextItem::cloneUpperPart(int height, QObject *owner, QGraphicsItem *parent)
{
int linesHeight=0;
QString tmpText="";
TextItem* upperPart = dynamic_cast<TextItem*>(cloneItem(itemMode(),owner,parent));
for (QTextBlock it=m_text->begin();it!=m_text->end();it=it.next()){
for (int i=0;i<it.layout()->lineCount();i++){
linesHeight+=it.layout()->lineAt(i).height()+lineSpacing();
if (linesHeight>(height-(fakeMarginSize()*2+borderLineSize()*2))) {
linesHeight-=it.layout()->lineAt(i).height();
goto loop_exit;
}
tmpText+=it.text().mid(it.layout()->lineAt(i).textStart(),it.layout()->lineAt(i).textLength())+'\n';
}
}
loop_exit:
tmpText.chop(1);
upperPart->setHeight(linesHeight+fakeMarginSize()*2+borderLineSize()*2);
QScopedPointer<HtmlContext> context(new HtmlContext(m_strText));
upperPart->setContent(context->extendTextByTags(tmpText,0));
upperPart->initText();
upperPart->setContent(getTextPart(height,0));
upperPart->initTextSizes();
upperPart->setHeight(upperPart->textSize().height()+borderLineSize()*2);
return upperPart;
}
BaseDesignIntf *TextItem::cloneBottomPart(int height, QObject *owner, QGraphicsItem *parent)
{
TextItem* bottomPart = dynamic_cast<TextItem*>(cloneItem(itemMode(),owner,parent));
int linesHeight=0;
int curLine=0;
QTextBlock curBlock;
QString tmpText="";
for (curBlock=m_text->begin();curBlock!=m_text->end();curBlock=curBlock.next()){
for (curLine=0;curLine<curBlock.layout()->lineCount();curLine++){
linesHeight+=curBlock.layout()->lineAt(curLine).height()+lineSpacing();
if (linesHeight>(height-(fakeMarginSize()*2+borderLineSize()*2))) {goto loop_exit;}
}
}
loop_exit:;
int textPos=0;
for (;curBlock!=m_text->end() || curLine<curBlock.lineCount();curBlock=curBlock.next(), curLine=0, tmpText+='\n'){
for (;curLine<curBlock.layout()->lineCount();curLine++){
if (tmpText=="") textPos= curBlock.layout()->lineAt(curLine).textStart();
tmpText+=curBlock.text().mid(curBlock.layout()->lineAt(curLine).textStart(),
curBlock.layout()->lineAt(curLine).textLength());
}
}
tmpText.chop(1);
QScopedPointer<HtmlContext> context(new HtmlContext(m_strText));
bottomPart->setContent(context->extendTextByTags(tmpText,textPos));
bottomPart->initText();
bottomPart->setHeight(bottomPart->m_textSize.height()+borderLineSize()*2);
bottomPart->setContent(getTextPart(0,height));
bottomPart->initTextSizes();
bottomPart->setHeight(bottomPart->textSize().height()+borderLineSize()*2);
return bottomPart;
}
@@ -687,9 +820,10 @@ BaseDesignIntf *TextItem::cloneEmpty(int height, QObject *owner, QGraphicsItem *
void TextItem::objectLoadFinished()
{
ItemDesignIntf::objectLoadFinished();
if (itemMode() == DesignMode || !isNeedExpandContent()){
initText();
}
// if (itemMode() == DesignMode || !isNeedExpandContent()){
// if (autoHeight() && autoWidth())
// initTextSizes();
// }
}
void TextItem::setTextItemFont(QFont value)
@@ -697,7 +831,7 @@ void TextItem::setTextItemFont(QFont value)
if (font()!=value){
QFont oldValue = font();
setFont(value);
m_text->setDefaultFont(transformToSceneFont(value));
update();
notify("font",oldValue,value);
}
}
@@ -759,7 +893,6 @@ void TextItem::setAngle(const AngleType& value)
AngleType oldValue = m_angle;
m_angle = value;
if (!isLoading()){
initText();
update();
notify("angle",oldValue,value);
}

View File

@@ -32,15 +32,16 @@
#include <QGraphicsTextItem>
#include <QtGui>
#include <QLabel>
#include "lritemdesignintf.h"
#include <qnamespace.h>
#include <QTextDocument>
#include "lritemdesignintf.h"
#include "lritemdesignintf.h"
#include "lrpageinitintf.h"
namespace LimeReport {
class Tag;
class TextItem : public LimeReport::ContentItemDesignIntf {
class TextItem : public LimeReport::ContentItemDesignIntf, IPageInit {
Q_OBJECT
Q_ENUMS(AutoWidth)
Q_ENUMS(AngleType)
@@ -66,6 +67,10 @@ class TextItem : public LimeReport::ContentItemDesignIntf {
Q_PROPERTY(bool allowHTMLInFields READ allowHTMLInFields WRITE setAllowHTMLInFields)
Q_PROPERTY(QString format READ format WRITE setFormat)
Q_PROPERTY(ValueType valueType READ valueType WRITE setValueType)
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};
@@ -99,7 +104,7 @@ public:
bool canBeSplitted(int height) const;
bool isSplittable() const { return true;}
bool isEmpty() const{return m_text->isEmpty();}
bool isEmpty() const{return m_strText.trimmed().isEmpty() /*m_text->isEmpty()*/;}
BaseDesignIntf* cloneUpperPart(int height, QObject *owner, QGraphicsItem *parent);
BaseDesignIntf* cloneBottomPart(int height, QObject *owner, QGraphicsItem *parent);
BaseDesignIntf* createSameTypeItem(QObject* owner=0, QGraphicsItem* parent=0);
@@ -140,28 +145,51 @@ public:
ValueType valueType() const;
void setValueType(const ValueType valueType);
QSizeF textSize(){ return m_textSize;}
QString followTo() const;
void setFollowTo(const QString &followTo);
void setFollower(TextItem* follower);
void clearFollower();
bool hasFollower() const;
TextItem* follower() const { return m_follower;}
bool initFollower(QString follower);
// IPageInit interface
void pageObjectHasBeenLoaded();
typedef QSharedPointer<QTextDocument> TextPtr;
qreal textIndent() const;
void setTextIndent(const qreal &textIndent);
Qt::LayoutDirection textLayoutDirection() const;
void setTextLayoutDirection(const Qt::LayoutDirection &textLayoutDirection);
protected:
void updateLayout();
bool isNeedExpandContent() const;
QString replaceBR(QString text);
QString replaceReturns(QString text);
int fakeMarginSize();
int fakeMarginSize() const;
QString getTextPart(int height, int skipHeight);
void restoreLinksEvent();
private:
void initText();
void setTextFont(const QFont &value);
void adaptFontSize();
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() const;
private:
QString m_strText;
//QTextLayout m_layout;
QTextDocument* m_text;
//QTextDocument* m_text;
Qt::Alignment m_alignment;
bool m_autoHeight;
AutoWidth m_autoWidth;
QSizeF m_textSize;
QSizeF mutable m_textSize;
qreal mutable m_firstLineSize;
AngleType m_angle;
int m_foregroundOpacity;
bool m_underlines;
@@ -174,6 +202,10 @@ private:
QString m_format;
ValueType m_valueType;
QString m_followTo;
TextItem* m_follower;
qreal m_textIndent;
Qt::LayoutDirection m_textLayoutDirection;
};
}