mirror of
https://github.com/fralx/LimeReport.git
synced 2025-09-23 08:29:07 +03:00
SVGItem default editor has been added
This commit is contained in:
20
limereport/items/lreditableimageitemintf.h
Normal file
20
limereport/items/lreditableimageitemintf.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef LREDITABLEIMAGEITEMINTF_H
|
||||
#define LREDITABLEIMAGEITEMINTF_H
|
||||
|
||||
#include <QByteArray>
|
||||
|
||||
namespace LimeReport {
|
||||
|
||||
class IEditableImageItem{
|
||||
public:
|
||||
virtual QByteArray imageAsByteArray() const = 0;
|
||||
virtual void setImageAsByteArray(QByteArray image) = 0;
|
||||
virtual QString resourcePath() const = 0;
|
||||
virtual void setResourcePath(const QString &value) = 0;
|
||||
virtual QString fileFilter() const = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // LREDITABLEIMAGEITEMINTF_H
|
@@ -141,6 +141,37 @@ QWidget *ImageItem::defaultEditor()
|
||||
return editor;
|
||||
}
|
||||
|
||||
QByteArray ImageItem::imageAsByteArray() const
|
||||
{
|
||||
QByteArray result;
|
||||
QBuffer buffer(&result);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
m_picture.save(&buffer,"PNG");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void ImageItem::setImageAsByteArray(QByteArray image)
|
||||
{
|
||||
QImage value;
|
||||
value.loadFromData(image);
|
||||
if (m_picture != value){
|
||||
QImage oldValue = m_picture;
|
||||
m_picture = value;
|
||||
if (m_autoSize){
|
||||
setWidth(m_picture.width());
|
||||
setHeight(m_picture.height());
|
||||
}
|
||||
update();
|
||||
notify("image",oldValue,value);
|
||||
}
|
||||
}
|
||||
|
||||
QString ImageItem::fileFilter() const
|
||||
{
|
||||
return tr("Images (*.gif *.icns *.ico *.jpeg *.tga *.tiff *.wbmp *.webp *.png *.jpg *.bmp);;All(*.*)");
|
||||
}
|
||||
|
||||
void ImageItem::updateItemSize(DataSourceManager* dataManager, RenderPass pass, int maxHeight)
|
||||
{
|
||||
|
||||
|
@@ -30,11 +30,12 @@
|
||||
#ifndef LRIMAGEITEM_H
|
||||
#define LRIMAGEITEM_H
|
||||
#include "lritemdesignintf.h"
|
||||
#include "lreditableimageitemintf.h"
|
||||
#include <QtGlobal>
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
class ImageItem : public ItemDesignIntf, public IPainterProxy
|
||||
class ImageItem : public ItemDesignIntf, public IPainterProxy, public IEditableImageItem
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QImage image READ image WRITE setImage)
|
||||
@@ -95,6 +96,10 @@ public:
|
||||
void setUseExternalPainter(bool value);
|
||||
|
||||
QWidget* defaultEditor();
|
||||
|
||||
QByteArray imageAsByteArray() const;
|
||||
void setImageAsByteArray(QByteArray image);
|
||||
QString fileFilter() const;
|
||||
protected:
|
||||
BaseDesignIntf* createSameTypeItem(QObject *owner, QGraphicsItem *parent);
|
||||
void updateItemSize(DataSourceManager *dataManager, RenderPass pass, int maxHeight);
|
||||
@@ -117,6 +122,7 @@ private:
|
||||
bool m_center;
|
||||
Format m_format;
|
||||
QString m_variable;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
@@ -5,12 +5,12 @@
|
||||
#include <QFileInfo>
|
||||
#include <QFileDialog>
|
||||
|
||||
ImageItemEditor::ImageItemEditor(LimeReport::ImageItem *item, QWidget *parent) :
|
||||
ImageItemEditor::ImageItemEditor(LimeReport::IEditableImageItem *item, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::ImageItemEditor), m_item(item)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
m_image = QPixmap::fromImage(m_item->image());
|
||||
m_image = item->imageAsByteArray();
|
||||
ui->resourcePath->setText(m_item->resourcePath());
|
||||
updateImage();
|
||||
}
|
||||
@@ -22,30 +22,35 @@ ImageItemEditor::~ImageItemEditor()
|
||||
|
||||
void ImageItemEditor::updateImage()
|
||||
{
|
||||
ui->imageViewer->setPixmap(m_image);
|
||||
if (m_image.isNull() && !ui->resourcePath->text().isEmpty()){
|
||||
if (m_resourcePathImage.isNull())
|
||||
m_resourcePathImage = QPixmap(ui->resourcePath->text());
|
||||
ui->imageViewer->setPixmap(m_resourcePathImage);
|
||||
QPixmap image;
|
||||
if (m_image.isEmpty() && !ui->resourcePath->text().isEmpty()){
|
||||
image.load(ui->resourcePath->text());
|
||||
} else {
|
||||
image.loadFromData(m_image);
|
||||
}
|
||||
ui->imageViewer->setPixmap(image);
|
||||
}
|
||||
|
||||
void ImageItemEditor::on_tbLoadImage_clicked()
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Select image file"));
|
||||
m_image = QPixmap(fileName);
|
||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Select image file"), "", m_item->fileFilter());
|
||||
QFile file(fileName);
|
||||
if (file.open(QIODevice::ReadOnly)){
|
||||
m_image = file.readAll();
|
||||
}
|
||||
updateImage();
|
||||
}
|
||||
|
||||
void ImageItemEditor::on_tbClearImage_clicked()
|
||||
{
|
||||
m_image = QPixmap();
|
||||
m_image.clear();
|
||||
updateImage();
|
||||
}
|
||||
|
||||
void ImageItemEditor::on_buttonBox_accepted()
|
||||
{
|
||||
m_item->setImage(m_image.toImage());
|
||||
QImage image;
|
||||
m_item->setImageAsByteArray(m_image);
|
||||
m_item->setResourcePath(ui->resourcePath->text());
|
||||
this->close();
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@
|
||||
#define LRIMAGEITEMEDITOR_H
|
||||
|
||||
#include <QWidget>
|
||||
#include "lreditableimageitemintf.h"
|
||||
|
||||
namespace Ui {
|
||||
class ImageItemEditor;
|
||||
@@ -16,15 +17,17 @@ class ImageItemEditor : public QWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ImageItemEditor(LimeReport::ImageItem* item, QWidget *parent = NULL);
|
||||
explicit ImageItemEditor(LimeReport::IEditableImageItem* item, QWidget *parent = NULL);
|
||||
~ImageItemEditor();
|
||||
private:
|
||||
void updateImage();
|
||||
private:
|
||||
Ui::ImageItemEditor *ui;
|
||||
LimeReport::ImageItem* m_item;
|
||||
QPixmap m_image;
|
||||
LimeReport::IEditableImageItem* m_item;
|
||||
|
||||
QByteArray m_image;
|
||||
QPixmap m_resourcePathImage;
|
||||
|
||||
private slots:
|
||||
void on_tbLoadImage_clicked();
|
||||
void on_tbClearImage_clicked();
|
||||
|
@@ -1,5 +1,7 @@
|
||||
#include "lrsvgitem.h"
|
||||
#include "lrdesignelementsfactory.h"
|
||||
#include "lrimageitemeditor.h"
|
||||
#include "lrpagedesignintf.h"
|
||||
#include <QtSvg>
|
||||
|
||||
namespace{
|
||||
@@ -39,6 +41,51 @@ void SVGItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q
|
||||
}
|
||||
ItemDesignIntf::paint(painter,option,widget);
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
QByteArray SVGItem::imageAsByteArray() const
|
||||
{
|
||||
return m_image;
|
||||
}
|
||||
|
||||
void SVGItem::setImageAsByteArray(QByteArray image)
|
||||
{
|
||||
setImage(image);
|
||||
}
|
||||
|
||||
QString SVGItem::fileFilter() const
|
||||
{
|
||||
return tr("SVG (*.svg)");
|
||||
}
|
||||
|
||||
void SVGItem::preparePopUpMenu(QMenu &menu)
|
||||
{
|
||||
QAction* editAction = menu.addAction(QIcon(":/report/images/edit_pecil2.png"),tr("Edit"));
|
||||
menu.insertAction(menu.actions().at(0),editAction);
|
||||
menu.insertSeparator(menu.actions().at(1));
|
||||
|
||||
menu.addSeparator();
|
||||
QAction* action = menu.addAction(tr("Watermark"));
|
||||
action->setCheckable(true);
|
||||
action->setChecked(isWatermark());
|
||||
}
|
||||
|
||||
void SVGItem::processPopUpAction(QAction *action)
|
||||
{
|
||||
if (action->text().compare(tr("Watermark")) == 0){
|
||||
page()->setPropertyToSelectedItems("watermark",action->isChecked());
|
||||
}
|
||||
if (action->text().compare(tr("Edit")) == 0){
|
||||
this->showEditorDialog();
|
||||
}
|
||||
ItemDesignIntf::processPopUpAction(action);
|
||||
}
|
||||
|
||||
QWidget *SVGItem::defaultEditor()
|
||||
{
|
||||
ImageItemEditor* editor = new ImageItemEditor(this);
|
||||
editor->setAttribute(Qt::WA_DeleteOnClose);
|
||||
return editor;
|
||||
};
|
||||
|
||||
BaseDesignIntf* SVGItem::createSameTypeItem(QObject *owner, QGraphicsItem *parent){
|
||||
|
@@ -2,9 +2,10 @@
|
||||
#define SVGITEM_H
|
||||
|
||||
#include "lritemdesignintf.h"
|
||||
#include "lreditableimageitemintf.h"
|
||||
|
||||
namespace LimeReport{
|
||||
class SVGItem: public ItemDesignIntf
|
||||
class SVGItem: public ItemDesignIntf, public IEditableImageItem
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString resourcePath READ resourcePath WRITE setResourcePath)
|
||||
@@ -18,6 +19,14 @@ public:
|
||||
SVGItem(QObject *owner, QGraphicsItem *parent);
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||
|
||||
QByteArray imageAsByteArray() const;
|
||||
void setImageAsByteArray(QByteArray image);
|
||||
QString fileFilter() const;
|
||||
|
||||
void preparePopUpMenu(QMenu &menu);
|
||||
void processPopUpAction(QAction *action);
|
||||
QWidget* defaultEditor();
|
||||
|
||||
QString resourcePath() const;
|
||||
void setResourcePath(const QString &resourcePath);
|
||||
QByteArray image() const;
|
||||
@@ -39,6 +48,8 @@ private:
|
||||
QString m_datasource;
|
||||
QString m_field;
|
||||
QString m_variable;
|
||||
public:
|
||||
|
||||
};
|
||||
} // namespace LimeReport
|
||||
#endif // SVGITEM_H
|
||||
|
Reference in New Issue
Block a user