mirror of
https://github.com/python-LimeReport/LimeReport.git
synced 2024-12-23 20:22:58 +03:00
Image editor has been added
This commit is contained in:
parent
afa4bcb9bf
commit
4556e3bc78
@ -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}\\\"
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
70
limereport/items/lrimageitemeditor.cpp
Normal file
70
limereport/items/lrimageitemeditor.cpp
Normal file
@ -0,0 +1,70 @@
|
||||
#include "lrimageitemeditor.h"
|
||||
#include "ui_lrimageitemeditor.h"
|
||||
#include "lrimageitem.h"
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QFileDialog>
|
||||
|
||||
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();
|
||||
}
|
37
limereport/items/lrimageitemeditor.h
Normal file
37
limereport/items/lrimageitemeditor.h
Normal file
@ -0,0 +1,37 @@
|
||||
#ifndef LRIMAGEITEMEDITOR_H
|
||||
#define LRIMAGEITEMEDITOR_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
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
|
170
limereport/items/lrimageitemeditor.ui
Normal file
170
limereport/items/lrimageitemeditor.ui
Normal file
@ -0,0 +1,170 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ImageItemEditor</class>
|
||||
<widget class="QWidget" name="ImageItemEditor">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>358</width>
|
||||
<height>403</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Ignored" vsizetype="Ignored">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Image Item Editor</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset resource="items.qrc">
|
||||
<normaloff>:/items/images/imageItem3.png</normaloff>:/items/images/imageItem3.png</iconset>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Image</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QToolButton" name="tbLoadImage">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../report.qrc">
|
||||
<normaloff>:/report/images/folder</normaloff>:/report/images/folder</iconset>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="tbClearImage">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../objectinspector/lobjectinspector.qrc">
|
||||
<normaloff>:/items/clear.png</normaloff>:/items/clear.png</iconset>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="imageViewer">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="pixmap">
|
||||
<pixmap resource="../../demo_r2/demo_r2.qrc">:/images/images/logo.png</pixmap>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Resource path</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="resourcePath"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="toolButton">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../report.qrc">
|
||||
<normaloff>:/report/images/folder</normaloff>:/report/images/folder</iconset>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="tbResourcePath">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../objectinspector/lobjectinspector.qrc">
|
||||
<normaloff>:/items/clear.png</normaloff>:/items/clear.png</iconset>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../../demo_r2/demo_r2.qrc"/>
|
||||
<include location="../report.qrc"/>
|
||||
<include location="items.qrc"/>
|
||||
<include location="../objectinspector/lobjectinspector.qrc"/>
|
||||
<include location="../report.qrc"/>
|
||||
<include location="items.qrc"/>
|
||||
<include location="../objectinspector/lobjectinspector.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
@ -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 += \
|
||||
|
Loading…
Reference in New Issue
Block a user