From afa4bcb9bf95700129e0062e0d4cb62572a4b067 Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Wed, 7 Aug 2019 12:40:42 +0300 Subject: [PATCH 1/2] If resourcePath contains a simple path to an image file, that image will be shown in design mode. --- limereport/items/lrimageitem.cpp | 15 +++++++++++++++ limereport/items/lrimageitem.h | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/limereport/items/lrimageitem.cpp b/limereport/items/lrimageitem.cpp index c3fce2f..9952479 100644 --- a/limereport/items/lrimageitem.cpp +++ b/limereport/items/lrimageitem.cpp @@ -340,6 +340,21 @@ void ImageItem::setImage(QImage value) } } +QImage ImageItem::image(){ + if (m_picture.isNull() && !resourcePath().isEmpty() && itemMode() == DesignMode){ + QFileInfo fileInfo(m_resourcePath); + if (fileInfo.exists()){ + return QImage(m_resourcePath); + } + } + return m_picture; +} + +void ImageItem::setResourcePath(const QString &value){ + m_resourcePath=value; + update(); +} + ImageItem::Format ImageItem::format() const { return m_format; diff --git a/limereport/items/lrimageitem.h b/limereport/items/lrimageitem.h index 5d474e2..8eb7da7 100644 --- a/limereport/items/lrimageitem.h +++ b/limereport/items/lrimageitem.h @@ -61,8 +61,8 @@ 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 setResourcePath(const QString &value){m_resourcePath=value;} + QImage image(); + void setResourcePath(const QString &value); QString resourcePath() const; QString datasource() const; void setDatasource(const QString &datasource); From 4556e3bc78fb85705cbe841e1b4b408331c411d3 Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Wed, 7 Aug 2019 21:06:47 +0300 Subject: [PATCH 2/2] Image editor has been added --- common.pri | 2 +- limereport/items/lrimageitem.cpp | 59 ++++++--- limereport/items/lrimageitem.h | 5 +- limereport/items/lrimageitemeditor.cpp | 70 ++++++++++ limereport/items/lrimageitemeditor.h | 37 ++++++ limereport/items/lrimageitemeditor.ui | 170 +++++++++++++++++++++++++ limereport/limereport.pri | 3 + 7 files changed, 328 insertions(+), 18 deletions(-) create mode 100644 limereport/items/lrimageitemeditor.cpp create mode 100644 limereport/items/lrimageitemeditor.h create mode 100644 limereport/items/lrimageitemeditor.ui diff --git a/common.pri b/common.pri index e76450d..cbe3fc1 100644 --- a/common.pri +++ b/common.pri @@ -127,7 +127,7 @@ RCC_DIR = $${ARCH_DIR}/$${BUILD_TYPE}/rcc LIMEREPORT_VERSION_MAJOR = 1 LIMEREPORT_VERSION_MINOR = 5 -LIMEREPORT_VERSION_RELEASE = 6 +LIMEREPORT_VERSION_RELEASE = 7 LIMEREPORT_VERSION = '$${LIMEREPORT_VERSION_MAJOR}.$${LIMEREPORT_VERSION_MINOR}.$${LIMEREPORT_VERSION_RELEASE}' DEFINES *= LIMEREPORT_VERSION_STR=\\\"$${LIMEREPORT_VERSION}\\\" diff --git a/limereport/items/lrimageitem.cpp b/limereport/items/lrimageitem.cpp index 9952479..76542d3 100644 --- a/limereport/items/lrimageitem.cpp +++ b/limereport/items/lrimageitem.cpp @@ -32,6 +32,7 @@ #include "lrglobal.h" #include "lrdatasourcemanager.h" #include "lrpagedesignintf.h" +#include "lrimageitemeditor.h" namespace{ @@ -83,9 +84,15 @@ void ImageItem::loadPictureFromVariant(QVariant& data){ void ImageItem::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 ImageItem::processPopUpAction(QAction *action) @@ -93,9 +100,26 @@ void ImageItem::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); } +QImage getFileByResourcePath(QString resourcePath){ + QFileInfo resourceFile(resourcePath); + if (resourceFile.exists()) + return QImage(resourcePath); + return QImage(); +} + +QImage ImageItem::drawImage() +{ + if (image().isNull()) + return getFileByResourcePath(m_resourcePath); + return image(); +} + bool ImageItem::useExternalPainter() const { return m_useExternalPainter; @@ -110,6 +134,13 @@ void ImageItem::setUseExternalPainter(bool value) } } +QWidget *ImageItem::defaultEditor() +{ + ImageItemEditor* editor = new ImageItemEditor(this); + editor->setAttribute(Qt::WA_DeleteOnClose); + return editor; +} + void ImageItem::updateItemSize(DataSourceManager* dataManager, RenderPass pass, int maxHeight) { @@ -220,8 +251,8 @@ void ImageItem::setAutoSize(bool autoSize) if (m_autoSize != autoSize){ m_autoSize = autoSize; if (m_autoSize && !m_picture.isNull()){ - setWidth(image().width()); - setHeight(image().height()); + setWidth(drawImage().width()); + setHeight(drawImage().height()); setPossibleResizeDirectionFlags(Fixed); } else { setPossibleResizeDirectionFlags(AllDirections); @@ -271,10 +302,10 @@ void ImageItem::paint(QPainter *ppainter, const QStyleOptionGraphicsItem *option QPointF point = rect().topLeft(); QImage img; - if (m_scale && !image().isNull()){ - img = image().scaled(rect().width(), rect().height(), keepAspectRatio() ? Qt::KeepAspectRatio : Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + if (m_scale && !drawImage().isNull()){ + img = drawImage().scaled(rect().width(), rect().height(), keepAspectRatio() ? Qt::KeepAspectRatio : Qt::IgnoreAspectRatio, Qt::SmoothTransformation); } else { - img = image(); + img = drawImage(); } qreal shiftHeight = rect().height() - img.height(); @@ -328,9 +359,9 @@ void ImageItem::paint(QPainter *ppainter, const QStyleOptionGraphicsItem *option void ImageItem::setImage(QImage value) { - if (m_picture!=value){ + if (m_picture != value){ QImage oldValue = m_picture; - m_picture=value; + m_picture = value; if (m_autoSize){ setWidth(m_picture.width()); setHeight(m_picture.height()); @@ -341,18 +372,16 @@ void ImageItem::setImage(QImage value) } QImage ImageItem::image(){ - if (m_picture.isNull() && !resourcePath().isEmpty() && itemMode() == DesignMode){ - QFileInfo fileInfo(m_resourcePath); - if (fileInfo.exists()){ - return QImage(m_resourcePath); - } - } return m_picture; } void ImageItem::setResourcePath(const QString &value){ - m_resourcePath=value; - update(); + if (m_resourcePath != value){ + QString oldValue = m_resourcePath; + m_resourcePath = value; + update(); + notify("resourcePath", oldValue, value); + } } ImageItem::Format ImageItem::format() const diff --git a/limereport/items/lrimageitem.h b/limereport/items/lrimageitem.h index 8eb7da7..587d39d 100644 --- a/limereport/items/lrimageitem.h +++ b/limereport/items/lrimageitem.h @@ -89,6 +89,7 @@ public: bool useExternalPainter() const; void setUseExternalPainter(bool value); + QWidget* defaultEditor(); protected: BaseDesignIntf* createSameTypeItem(QObject *owner, QGraphicsItem *parent); void updateItemSize(DataSourceManager *dataManager, RenderPass pass, int maxHeight); @@ -97,6 +98,7 @@ protected: void loadPictureFromVariant(QVariant& data); void preparePopUpMenu(QMenu &menu); void processPopUpAction(QAction *action); + QImage drawImage(); private: QImage m_picture; bool m_useExternalPainter; @@ -109,8 +111,7 @@ private: bool m_keepAspectRatio; bool m_center; Format m_format; - QString m_variable; - + QString m_variable; }; } diff --git a/limereport/items/lrimageitemeditor.cpp b/limereport/items/lrimageitemeditor.cpp new file mode 100644 index 0000000..9e34df9 --- /dev/null +++ b/limereport/items/lrimageitemeditor.cpp @@ -0,0 +1,70 @@ +#include "lrimageitemeditor.h" +#include "ui_lrimageitemeditor.h" +#include "lrimageitem.h" + +#include +#include + +ImageItemEditor::ImageItemEditor(LimeReport::ImageItem *item, QWidget *parent) : + QWidget(parent), + ui(new Ui::ImageItemEditor), m_item(item) +{ + ui->setupUi(this); + m_image = QPixmap::fromImage(m_item->image()); + ui->resourcePath->setText(m_item->resourcePath()); + updateImage(); +} + +ImageItemEditor::~ImageItemEditor() +{ + delete ui; +} + +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); + } +} + +void ImageItemEditor::on_tbLoadImage_clicked() +{ + QString fileName = QFileDialog::getOpenFileName(this, tr("Select image file")); + m_image = QPixmap(fileName); + updateImage(); +} + +void ImageItemEditor::on_tbClearImage_clicked() +{ + m_image = QPixmap(); + updateImage(); +} + +void ImageItemEditor::on_buttonBox_accepted() +{ + m_item->setImage(m_image.toImage()); + m_item->setResourcePath(ui->resourcePath->text()); + this->close(); +} + +void ImageItemEditor::on_buttonBox_rejected() +{ + this->close(); +} + +void ImageItemEditor::on_toolButton_clicked() +{ + ui->resourcePath->setText(QFileDialog::getOpenFileName(this, tr("Select image file"))); + m_resourcePathImage = QPixmap(ui->resourcePath->text()); + if (!m_resourcePathImage.isNull() && m_image.isNull()) + ui->imageViewer->setPixmap(m_resourcePathImage); +} + +void ImageItemEditor::on_tbResourcePath_clicked() +{ + ui->resourcePath->setText(""); + updateImage(); +} diff --git a/limereport/items/lrimageitemeditor.h b/limereport/items/lrimageitemeditor.h new file mode 100644 index 0000000..a8cc474 --- /dev/null +++ b/limereport/items/lrimageitemeditor.h @@ -0,0 +1,37 @@ +#ifndef LRIMAGEITEMEDITOR_H +#define LRIMAGEITEMEDITOR_H + +#include + +namespace Ui { +class ImageItemEditor; +} + +namespace LimeReport { +class ImageItem; +} + +class ImageItemEditor : public QWidget +{ + Q_OBJECT + +public: + explicit ImageItemEditor(LimeReport::ImageItem* item, QWidget *parent = nullptr); + ~ImageItemEditor(); +private: + void updateImage(); +private: + Ui::ImageItemEditor *ui; + LimeReport::ImageItem* m_item; + QPixmap m_image; + QPixmap m_resourcePathImage; +private slots: + void on_tbLoadImage_clicked(); + void on_tbClearImage_clicked(); + void on_buttonBox_accepted(); + void on_buttonBox_rejected(); + void on_toolButton_clicked(); + void on_tbResourcePath_clicked(); +}; + +#endif // LRIMAGEITEMEDITOR_H diff --git a/limereport/items/lrimageitemeditor.ui b/limereport/items/lrimageitemeditor.ui new file mode 100644 index 0000000..12152d4 --- /dev/null +++ b/limereport/items/lrimageitemeditor.ui @@ -0,0 +1,170 @@ + + + ImageItemEditor + + + + 0 + 0 + 358 + 403 + + + + + 0 + 0 + + + + Image Item Editor + + + + :/items/images/imageItem3.png:/items/images/imageItem3.png + + + + + + + 0 + 0 + + + + Image + + + + + + + + ... + + + + :/report/images/folder:/report/images/folder + + + true + + + + + + + ... + + + + :/items/clear.png:/items/clear.png + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 0 + 0 + + + + + + + :/images/images/logo.png + + + true + + + + + + + + + + + + Resource path + + + + + + + + + + ... + + + + :/report/images/folder:/report/images/folder + + + true + + + + + + + ... + + + + :/items/clear.png:/items/clear.png + + + true + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + + + + + + diff --git a/limereport/limereport.pri b/limereport/limereport.pri index e039138..0918890 100644 --- a/limereport/limereport.pri +++ b/limereport/limereport.pri @@ -36,6 +36,7 @@ SOURCES += \ $$REPORT_PATH/items/editors/lritemsborderseditorwidget.cpp \ $$REPORT_PATH/items/lrsimpletagparser.cpp \ $$REPORT_PATH/items/lrimageitem.cpp \ + $$REPORT_PATH/items/lrimageitemeditor.cpp \ $$REPORT_PATH/items/lrtextitemeditor.cpp \ $$REPORT_PATH/items/lrshapeitem.cpp \ $$REPORT_PATH/items/lrtextitem.cpp \ @@ -108,6 +109,7 @@ HEADERS += \ $$REPORT_PATH/items/lrtextitemeditor.h \ $$REPORT_PATH/items/lrshapeitem.h \ $$REPORT_PATH/items/lrimageitem.h \ + $$REPORT_PATH/items/lrimageitemeditor.h \ $$REPORT_PATH/items/lrsimpletagparser.h \ $$REPORT_PATH/items/lrverticallayout.h \ $$REPORT_PATH/items/lrlayoutmarker.h \ @@ -171,6 +173,7 @@ FORMS += \ $$REPORT_PATH/lraboutdialog.ui \ $$REPORT_PATH/lrsettingdialog.ui \ $$REPORT_PATH/items/lrchartitemeditor.ui \ + $$REPORT_PATH/items/lrimageitemeditor.ui \ $$REPORT_PATH/scripteditor/lrscripteditor.ui RESOURCES += \