Files
3rdparty
console
demo_r1
demo_r2
designer
designer_plugin
docs
include
limereport
bands
base
databrowser
dialogdesigner
exporters
images
items
editors
images
items.qrc
lrabstractlayout.cpp
lrabstractlayout.h
lralignpropitem.cpp
lralignpropitem.h
lrbarcodeitem.cpp
lrbarcodeitem.h
lrchartitem.cpp
lrchartitem.h
lrchartitemeditor.cpp
lrchartitemeditor.h
lrchartitemeditor.ui
lrhorizontallayout.cpp
lrhorizontallayout.h
lrimageitem.cpp
lrimageitem.h
lrlayoutmarker.cpp
lrlayoutmarker.h
lrshapeitem.cpp
lrshapeitem.h
lrsimpletagparser.cpp
lrsimpletagparser.h
lrsubitemparentpropitem.cpp
lrsubitemparentpropitem.h
lrtextitem.cpp
lrtextitem.h
lrtextitemeditor.cpp
lrtextitemeditor.h
lrtextitemeditor.ui
lrverticallayout.cpp
lrverticallayout.h
objectinspector
objectsbrowser
scriptbrowser
scripteditor
serializators
translationeditor
LRCallbackDS
LRDataManager
LRScriptManager
LimeReport
designer.pri
limereport.prf
limereport.pri
limereport.pro
lraboutdialog.cpp
lraboutdialog.h
lraboutdialog.ui
lrbanddesignintf.cpp
lrbanddesignintf.h
lrbandsmanager.cpp
lrbandsmanager.h
lrbasedesignintf.cpp
lrbasedesignintf.h
lrcallbackdatasourceintf.h
lrcollection.h
lrcolorindicator.cpp
lrcolorindicator.h
lrdatadesignintf.cpp
lrdatadesignintf.h
lrdatasourceintf.h
lrdatasourcemanager.cpp
lrdatasourcemanager.h
lrdatasourcemanagerintf.h
lrdesignelementsfactory.h
lrdesignerplugininterface.h
lrexporterintf.h
lrexportersfactory.h
lrfactoryinitializer.cpp
lrfactoryinitializer.h
lrglobal.cpp
lrglobal.h
lrgraphicsviewzoom.cpp
lrgraphicsviewzoom.h
lrgroupfunctions.cpp
lrgroupfunctions.h
lritemdesignintf.cpp
lritemdesignintf.h
lritemscontainerdesignitf.cpp
lritemscontainerdesignitf.h
lrpagedesignintf.cpp
lrpagedesignintf.h
lrpageinitintf.h
lrpageitemdesignintf.cpp
lrpageitemdesignintf.h
lrpreparedpages.cpp
lrpreparedpages.h
lrpreparedpagesintf.h
lrpreviewreportwidget.cpp
lrpreviewreportwidget.h
lrpreviewreportwidget.ui
lrpreviewreportwidget_p.h
lrpreviewreportwindow.cpp
lrpreviewreportwindow.h
lrpreviewreportwindow.ui
lrreportdesignwidget.cpp
lrreportdesignwidget.h
lrreportdesignwindow.cpp
lrreportdesignwindow.h
lrreportdesignwindowintrerface.h
lrreportengine.cpp
lrreportengine.h
lrreportengine_p.h
lrreportrender.cpp
lrreportrender.h
lrreporttranslation.cpp
lrreporttranslation.h
lrscriptenginemanager.cpp
lrscriptenginemanager.h
lrscriptenginemanagerintf.h
lrsettingdialog.cpp
lrsettingdialog.h
lrsettingdialog.ui
lrsimplecrypt.cpp
lrsimplecrypt.h
lrvariablesholder.cpp
lrvariablesholder.h
report.qrc
tests
translations
.gitignore
.remarkrc
.travis.yml
COPYING
LICENSE
README.md
common.pri
followTo.patch
limereport.pri
limereport.pro
qzint.pri
LimeReport/limereport/items/lrshapeitem.cpp
2019-06-27 23:37:06 +03:00

217 lines
6.8 KiB
C++

/***************************************************************************
* 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. *
****************************************************************************/
#include "lrshapeitem.h"
#include "lrdesignelementsfactory.h"
#include <QStyleOptionGraphicsItem>
#include <QPainter>
namespace{
const QString xmlTag = "ShapeItem";
LimeReport::BaseDesignIntf * createShapeItem(QObject* owner, LimeReport::BaseDesignIntf* parent){
return new LimeReport::ShapeItem(owner,parent);
}
bool VARIABLE_IS_NOT_USED registred = LimeReport::DesignElementsFactory::instance().registerCreator(
xmlTag, LimeReport::ItemAttribs(QObject::tr("Shape Item"),"Item"), createShapeItem
);
}
namespace LimeReport{
ShapeItem::ShapeItem(QObject *owner, QGraphicsItem *parent)
:ItemDesignIntf(xmlTag,owner,parent),
m_shape(HorizontalLine),
m_shapeColor(Qt::black),
m_shapeBrushColor(Qt::black),
m_shapeBrushType(Qt::NoBrush),
m_lineWidth(1),
m_penStyle(Qt::SolidLine),
m_opacity(100),
m_cornerRadius(0)
{
}
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);
pen.setWidthF(m_lineWidth);
pen.setStyle(m_penStyle);
pen.setJoinStyle(Qt::MiterJoin);
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);
QRectF rectangleRect = rect().adjusted((lineWidth() / 2),
(lineWidth() / 2),
-(lineWidth() / 2),
-(lineWidth() / 2));
switch (m_shape){
case HorizontalLine:
painter->drawLine(0,rect().height()/2,rect().right(),rect().height()/2);
break;
case VerticalLine:
painter->drawLine(rect().width()/2,0,rect().width()/2,rect().height());
break;
case Ellipse:
painter->setRenderHint(QPainter::Antialiasing);
painter->drawEllipse(rect());
break;
case Rectangle:
if (m_cornerRadius != 0){
painter->setRenderHint(QPainter::Antialiasing);
painter->drawRoundedRect(rectangleRect,m_cornerRadius,m_cornerRadius);
} else {
painter->drawRect(rectangleRect);
}
break;
}
painter->restore();
ItemDesignIntf::paint(painter,option,widget);
}
void ShapeItem::setShapeColor(QColor value)
{
if ((value!=m_shapeColor)){
QColor oldValue = m_shapeColor;
m_shapeColor=value;
update();
notify("shapeColor",oldValue,value);
}
}
void ShapeItem::setShapeBrushColor(QColor value)
{
if (value!=m_shapeBrushColor){
QColor oldValue = m_shapeBrushColor;
m_shapeBrushColor=value;
update();
notify("shapeBrushColor",oldValue,value);
}
}
void ShapeItem::setShapeBrushType(Qt::BrushStyle value)
{
if (m_shapeBrushType!=value){
Qt::BrushStyle oldValue = m_shapeBrushType;
m_shapeBrushType=value;
update(rect());
notify("shapeBrush",QBrush(oldValue),QBrush(value));
}
}
void ShapeItem::setShapeType(ShapeItem::ShapeType value)
{
if (m_shape!=value){
ShapeType oldValue = m_shape;
m_shape=value;
update();
notify("shape",oldValue,value);
}
}
void ShapeItem::setLineWidth(qreal value)
{
if (m_lineWidth!=value){
qreal oldValue = m_lineWidth;
m_lineWidth=value;
update();
notify("lineWidth",oldValue,value);
}
}
BaseDesignIntf *ShapeItem::createSameTypeItem(QObject *owner, QGraphicsItem *parent)
{
return new ShapeItem(owner,parent);
}
int ShapeItem::cornerRadius() const
{
return m_cornerRadius;
}
void ShapeItem::setCornerRadius(int borderRadius)
{
if (m_cornerRadius != borderRadius){
int oldValue = m_cornerRadius;
m_cornerRadius = borderRadius;
update();
notify("cornerRadius",oldValue,m_cornerRadius);
}
}
int ShapeItem::opacity() const
{
return m_opacity;
}
void ShapeItem::setOpacity(int opacity)
{
if (m_opacity!=opacity){
if (opacity < 0) {
m_opacity = 0;
}
else if (opacity > 100) {
m_opacity = 100;
}
else {
m_opacity = opacity;
}
update();
}
}
}