2017-04-23 15:05:48 +02:00
|
|
|
#include "cropeditor.hpp"
|
|
|
|
|
|
|
|
#include "cropview.hpp"
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QGraphicsPixmapItem>
|
|
|
|
#include <QGraphicsView>
|
|
|
|
#include <QTimer>
|
|
|
|
|
|
|
|
CropEditor::CropEditor(QPixmap *image, QObject *parent) : QObject(parent)
|
|
|
|
{
|
|
|
|
pixmap = image;
|
|
|
|
scene = new CropScene(parent);
|
|
|
|
view = new CropView(scene);
|
|
|
|
|
|
|
|
pixmapItem = new QGraphicsPixmapItem(*pixmap);
|
2017-04-26 22:00:13 +02:00
|
|
|
pixmapItem->setZValue(-1);
|
2017-04-23 15:05:48 +02:00
|
|
|
scene->addItem(pixmapItem);
|
|
|
|
scene->setSceneRect(pixmap->rect());
|
|
|
|
|
|
|
|
QTimer::singleShot(0, [&] { view->showFullScreen(); });
|
|
|
|
|
|
|
|
connect(scene, &CropScene::closedWithRect, this, &CropEditor::crop);
|
|
|
|
}
|
|
|
|
|
|
|
|
CropEditor::~CropEditor()
|
|
|
|
{
|
|
|
|
delete scene;
|
|
|
|
delete view;
|
|
|
|
delete pixmap;
|
|
|
|
delete pixmapItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CropEditor::crop(QRect rect)
|
|
|
|
{
|
|
|
|
QPixmap crop = pixmap->copy(rect);
|
|
|
|
QPixmap *cropp = new QPixmap;
|
|
|
|
crop.swap(*cropp);
|
|
|
|
emit cropped(cropp);
|
|
|
|
}
|