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

Version 1.4 initial commit

This commit is contained in:
Arin Alexander
2016-06-10 19:05:18 +04:00
parent 6a507e5b61
commit fecf863f7c
61 changed files with 2019 additions and 276 deletions

View File

@@ -41,6 +41,16 @@ FontEditorWidget::FontEditorWidget(ReportDesignWidget *reportEditor, QWidget *pa
initEditor();
}
FontEditorWidget::FontEditorWidget(PageDesignIntf *page, const QString &title, QWidget *parent)
:ItemEditorWidget(page,title,parent), m_ignoreSlots(false) {
initEditor();
}
FontEditorWidget::FontEditorWidget(LimeReport::PageDesignIntf *page, QWidget *parent)
:ItemEditorWidget(page,parent), m_ignoreSlots(false){
initEditor();
}
void FontEditorWidget::setItemEvent(BaseDesignIntf* item)
{
@@ -116,22 +126,26 @@ void FontEditorWidget::slotFontChanged(const QFont &font)
void FontEditorWidget::slotFontSizeChanged(const QString &value)
{
if (reportEditor() && !m_ignoreSlots){
QFont resFont(m_fontNameEditor->currentFont());
resFont.setPointSize(value.toInt());
reportEditor()->setFont(resFont);
}
if (m_ignoreSlots) return;
QFont resFont(fontNameEditor()->currentFont());
resFont.setPointSize(value.toInt());
if (reportEditor()) reportEditor()->setFont(resFont);
if (page()) page()->setFont(resFont);
}
void FontEditorWidget::slotFontAttribsChanged(bool)
{
if (reportEditor()&& !m_ignoreSlots){
QFont resFont(m_fontNameEditor->currentFont());
resFont.setBold(m_fontBold->isChecked());
resFont.setItalic(m_fontItalic->isChecked());
resFont.setUnderline(m_fontUnderline->isChecked());
reportEditor()->setFont(resFont);
}
if (m_ignoreSlots) return;
QFont resFont(m_fontNameEditor->currentFont());
resFont.setBold(m_fontBold->isChecked());
resFont.setItalic(m_fontItalic->isChecked());
resFont.setUnderline(m_fontUnderline->isChecked());
if (reportEditor()) reportEditor()->setFont(resFont);
if (page()) page()->setFont(resFont);
}
void FontEditorWidget::slotPropertyChanged(const QString &objectName, const QString &property, const QVariant& oldValue, const QVariant& newValue)

View File

@@ -45,8 +45,11 @@ class FontEditorWidget :public ItemEditorWidget{
public:
explicit FontEditorWidget(ReportDesignWidget* reportEditor, const QString &title, QWidget *parent = 0);
explicit FontEditorWidget(ReportDesignWidget* reportEditor, QWidget *parent = 0);
explicit FontEditorWidget(PageDesignIntf* page, const QString &title, QWidget *parent = 0);
explicit FontEditorWidget(PageDesignIntf* page, QWidget *parent = 0);
protected:
void setItemEvent(BaseDesignIntf *item);
QFontComboBox* fontNameEditor(){return m_fontNameEditor;}
private slots:
void slotFontChanged(const QFont& font);
void slotFontSizeChanged(const QString& value);

View File

@@ -60,8 +60,24 @@ ShapeItem::ShapeItem(QObject *owner, QGraphicsItem *parent)
{
}
Qt::PenStyle ShapeItem::penStyle() const
{
return m_penStyle;
}
void ShapeItem::setPenStyle(const Qt::PenStyle &value)
{
if ((value!=m_penStyle)){
Qt::PenStyle oldValue = m_penStyle;
m_penStyle=value;
update();
notify("penStyle",(int)oldValue,(int)value);
}
}
void ShapeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->save();
QPen pen(m_shapeColor);
@@ -150,21 +166,6 @@ void ShapeItem::setLineWidth(qreal value)
}
}
Qt::PenStyle ShapeItem::penStyle() const
{
return m_penStyle;
}
void ShapeItem::setPenStyle(const Qt::PenStyle &value)
{
if (m_penStyle!=value){
Qt::PenStyle oldValue = m_penStyle;
m_penStyle = value;
update();
notify("penStyle",(int)oldValue,(int)value);
}
}
BaseDesignIntf *ShapeItem::createSameTypeItem(QObject *owner, QGraphicsItem *parent)
{
return new ShapeItem(owner,parent);

View File

@@ -150,20 +150,45 @@ void TextItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* style, Q
break;
}
// for(QTextBlock it=m_text->begin();it!=m_text->end();it=it.next()){
// for (int i=0;i<it.layout()->lineCount();i++){
// painter->setOpacity(qreal(foregroundOpacity())/100);
// it.layout()->lineAt(i).draw(painter,QPointF(0,0));
// }
// }
int lineHeight = painter->fontMetrics().height();
qreal curpos = 0;
if (m_underlines){
QPen pen = painter->pen();
pen.setWidth(m_underlineLineSize);
painter->setPen(pen);
}
painter->setOpacity(qreal(foregroundOpacity())/100);
//m_text->setDefaultTextOption();
QAbstractTextDocumentLayout::PaintContext ctx;
ctx.palette.setColor(QPalette::Text, fontColor());
for(QTextBlock it=m_text->begin();it!=m_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);
if (m_underlines){
painter->drawLine(QPointF(0,line.rect().bottomLeft().y()),QPoint(rect().width(),line.rect().bottomRight().y()));
lineHeight = line.height()+m_lineSpacing;
curpos = line.rect().bottom();
}
}
}
m_text->documentLayout()->draw(painter,ctx);
if (m_underlines){
if (lineHeight<0) lineHeight = painter->fontMetrics().height();
for (curpos+=lineHeight; curpos<rect().height();curpos+=lineHeight){
painter->drawLine(QPointF(0,curpos),QPoint(rect().width(),curpos));
}
}
//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;
@@ -186,6 +211,10 @@ void TextItem::Init()
// m_text->setDefaultFont(transformToSceneFont(font()));
m_textSize=QSizeF();
m_foregroundOpacity = 100;
m_underlines = false;
m_adaptFontToSize = false;
m_underlineLineSize = 1;
m_lineSpacing = 1;
}
void TextItem::setContent(const QString &value)
@@ -204,9 +233,9 @@ void TextItem::setContent(const QString &value)
}
if (!isLoading()){
update(rect());
notify("content",oldValue,value);
//updateLayout();
initText();
update(rect());
notify("content",oldValue,value);
}
}
}
@@ -223,7 +252,7 @@ void TextItem::updateItemSize(DataSourceManager* dataManager, RenderPass pass, i
}
if ((m_textSize.height()>height()) && (m_autoHeight) ){
setHeight(m_textSize.height()+5);
setHeight(m_textSize.height()+borderLineSize()*2);
}
BaseDesignIntf::updateItemSize(dataManager, pass, maxHeight);
}
@@ -262,23 +291,91 @@ QString TextItem::replaceReturns(QString text)
return result;
}
void TextItem::setTextFont(const QFont& value){
m_text->setDefaultFont(value);
if ((m_angle==Angle0)||(m_angle==Angle180)){
m_text->setTextWidth(rect().width()-fakeMarginSize()*2);
} else {
m_text->setTextWidth(rect().height()-fakeMarginSize()*2);
}
}
void TextItem::adaptFontSize(){
QFont _font = transformToSceneFont(font());
do{
setTextFont(_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);
}
int TextItem::underlineLineSize() const
{
return m_underlineLineSize;
}
void TextItem::setUnderlineLineSize(int value)
{
int oldValue = m_underlineLineSize;
m_underlineLineSize = value;
update();
notify("underlineLineSize",oldValue,value);
}
int TextItem::lineSpacing() const
{
return m_lineSpacing;
}
void TextItem::setLineSpacing(int value)
{
int oldValue = m_lineSpacing;
m_lineSpacing = value;
initText();
update();
notify("lineSpacing",oldValue,value);
}
void TextItem::initText()
{
QTextOption to;
to.setAlignment(m_alignment);
if (m_autoWidth!=MaxStringLength)
to.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
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);
m_text->setDefaultFont(transformToSceneFont(font()));
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();
}
@@ -320,9 +417,11 @@ bool TextItem::trimValue() const
return m_trimValue;
}
void TextItem::setTrimValue(bool trimValue)
void TextItem::setTrimValue(bool value)
{
m_trimValue = trimValue;
bool oldValue = m_trimValue;
m_trimValue = value;
notify("trimValue",oldValue,value);
}
@@ -333,8 +432,9 @@ void TextItem::geometryChangedEvent(QRectF , QRectF)
// } else {
// m_text->setTextWidth(rect().height()-fakeMarginSize()*2);
// }
// m_textSize=m_text->size();
if (itemMode() == DesignMode) initText();
else if (adaptFontToSize()) initText();
}
bool TextItem::isNeedUpdateSize(RenderPass pass) const
@@ -395,6 +495,17 @@ void TextItem::setAutoWidth(TextItem::AutoWidth value)
}
}
void TextItem::setAdaptFontToSize(bool value)
{
if (m_adaptFontToSize!=value){
bool oldValue = m_adaptFontToSize;
m_adaptFontToSize=value;
initText();
invalidateRect(rect());
notify("updateFontToSize",oldValue,value);
}
}
bool TextItem::canBeSplitted(int height) const
{
return height>(m_text->begin().layout()->lineAt(0).height());
@@ -409,8 +520,10 @@ BaseDesignIntf *TextItem::cloneUpperPart(int height, QObject *owner, QGraphicsIt
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();
if (linesHeight>(height-(fakeMarginSize()*2+borderLineSize()*2))) {linesHeight-=it.layout()->lineAt(i).height(); goto loop_exit;}
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';
}
}
@@ -433,7 +546,7 @@ BaseDesignIntf *TextItem::cloneBottomPart(int height, QObject *owner, QGraphicsI
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();
linesHeight+=curBlock.layout()->lineAt(curLine).height()+lineSpacing();
if (linesHeight>(height-(fakeMarginSize()*2+borderLineSize()*2))) {goto loop_exit;}
}
}
@@ -565,6 +678,16 @@ void TextItem::setForegroundOpacity(int value)
}
}
void TextItem::setUnderlines(bool value)
{
if (m_underlines != value){
bool oldValue = m_underlines;
m_underlines = value;
update();
notify("underlines",oldValue,value);
}
}
} //namespace LimeReport

View File

@@ -56,7 +56,11 @@ class TextItem : public LimeReport::ContentItemDesignIntf {
Q_PROPERTY(QColor fontColor READ fontColor WRITE setFontColorProperty)
Q_PROPERTY(AngleType angle READ angle WRITE setAngle)
Q_PROPERTY(int foregroundOpacity READ foregroundOpacity WRITE setForegroundOpacity)
Q_PROPERTY(bool underlines READ underlines WRITE setUnderlines)
Q_PROPERTY(bool adaptFontToSize READ adaptFontToSize WRITE setAdaptFontToSize)
Q_PROPERTY(bool trimValue READ trimValue WRITE setTrimValue)
Q_PROPERTY(int lineSpacing READ lineSpacing WRITE setLineSpacing)
Q_PROPERTY(int underlineLineSize READ underlineLineSize WRITE setUnderlineLineSize)
Q_PROPERTY(bool allowHTML READ allowHTML WRITE setAllowHTML)
Q_PROPERTY(bool allowHTMLInFields READ allowHTMLInFields WRITE setAllowHTMLInFields)
public:
@@ -72,9 +76,6 @@ public:
QString content() const;
void setContent(const QString& value);
//void setMarginSize(int value);
void setAlignment(Qt::Alignment value);
Qt::Alignment alignment(){return m_alignment;}
@@ -89,6 +90,9 @@ public:
void setAutoWidth(AutoWidth value);
AutoWidth autoWidth() const {return m_autoWidth;}
void setAdaptFontToSize(bool value);
bool adaptFontToSize() const {return m_adaptFontToSize;}
bool canBeSplitted(int height) const;
bool isSplittable() const { return true;}
bool isEmpty() const{return m_text->isEmpty();}
@@ -108,10 +112,18 @@ public:
void setAngle(const AngleType& value);
int foregroundOpacity(){return m_foregroundOpacity;}
void setForegroundOpacity(int value);
bool underlines(){return m_underlines;}
void setUnderlines(bool value);
bool trimValue() const;
void setTrimValue(bool trimValue);
int lineSpacing() const;
void setLineSpacing(int value);
int underlineLineSize() const;
void setUnderlineLineSize(int value);
bool allowHTML() const;
void setAllowHTML(bool allowHTML);
@@ -126,6 +138,8 @@ protected:
int fakeMarginSize();
private:
void initText();
void setTextFont(const QFont &value);
void adaptFontSize();
private:
QString m_strText;
@@ -137,7 +151,11 @@ private:
QSizeF m_textSize;
AngleType m_angle;
int m_foregroundOpacity;
bool m_underlines;
bool m_adaptFontToSize;
bool m_trimValue;
int m_lineSpacing;
int m_underlineLineSize;
bool m_allowHTML;
bool m_allowHTMLInFields;
};