0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-27 01:48:09 +03:00
LimeReport/limereport/items/lrimageitemeditor.cpp

76 lines
1.8 KiB
C++
Raw Normal View History

2019-08-07 21:06:47 +03:00
#include "lrimageitemeditor.h"
#include "ui_lrimageitemeditor.h"
#include "lrimageitem.h"
#include <QFileInfo>
#include <QFileDialog>
2020-03-19 20:09:35 +03:00
ImageItemEditor::ImageItemEditor(LimeReport::IEditableImageItem *item, QWidget *parent) :
2019-08-07 21:06:47 +03:00
QWidget(parent),
ui(new Ui::ImageItemEditor), m_item(item)
{
ui->setupUi(this);
2020-03-19 20:09:35 +03:00
m_image = item->imageAsByteArray();
2019-08-07 21:06:47 +03:00
ui->resourcePath->setText(m_item->resourcePath());
updateImage();
}
ImageItemEditor::~ImageItemEditor()
{
delete ui;
}
void ImageItemEditor::updateImage()
{
2020-03-19 20:09:35 +03:00
QPixmap image;
if (m_image.isEmpty() && !ui->resourcePath->text().isEmpty()){
image.load(ui->resourcePath->text());
} else {
image.loadFromData(m_image);
2019-08-07 21:06:47 +03:00
}
2020-03-19 20:09:35 +03:00
ui->imageViewer->setPixmap(image);
2019-08-07 21:06:47 +03:00
}
void ImageItemEditor::on_tbLoadImage_clicked()
{
2020-03-19 20:09:35 +03:00
QString fileName = QFileDialog::getOpenFileName(this, tr("Select image file"), "", m_item->fileFilter());
QFile file(fileName);
if (file.open(QIODevice::ReadOnly)){
m_image = file.readAll();
}
2019-08-07 21:06:47 +03:00
updateImage();
}
void ImageItemEditor::on_tbClearImage_clicked()
{
2020-03-19 20:09:35 +03:00
m_image.clear();
2019-08-07 21:06:47 +03:00
updateImage();
}
void ImageItemEditor::on_buttonBox_accepted()
{
2020-03-19 20:09:35 +03:00
QImage image;
m_item->setImageAsByteArray(m_image);
2019-08-07 21:06:47 +03:00
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();
}