2017-04-23 15:05:48 +02:00
|
|
|
#include "cropeditor.hpp"
|
|
|
|
|
2017-04-29 17:35:42 +02:00
|
|
|
#include "cropscene.hpp"
|
2017-04-23 15:05:48 +02:00
|
|
|
#include "cropview.hpp"
|
2017-05-13 15:56:52 +02:00
|
|
|
#include <QApplication>
|
2017-04-23 15:05:48 +02:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QGraphicsPixmapItem>
|
|
|
|
#include <QGraphicsView>
|
2017-05-13 15:56:52 +02:00
|
|
|
#include <QScreen>
|
2017-04-23 15:05:48 +02:00
|
|
|
#include <QTimer>
|
2017-05-02 15:47:08 +02:00
|
|
|
#include <settings.hpp>
|
2017-04-23 15:05:48 +02:00
|
|
|
|
2017-05-06 13:21:12 +02:00
|
|
|
CropEditor::CropEditor(QPixmap *image, QObject *parent) : QObject(parent) {
|
2017-05-09 17:26:00 +02:00
|
|
|
scene = new CropScene(parent, image);
|
|
|
|
view = new CropView(scene);
|
2017-05-13 15:56:52 +02:00
|
|
|
qreal ratio = QApplication::primaryScreen()->devicePixelRatio();
|
|
|
|
pixmapItem = new QGraphicsPixmapItem(image->scaled(image->width() / ratio, image->height() / ratio));
|
2017-05-09 17:26:00 +02:00
|
|
|
pixmapItem->setZValue(-1);
|
|
|
|
scene->addItem(pixmapItem);
|
|
|
|
scene->setSceneRect(image->rect());
|
|
|
|
view->showFullScreen();
|
2017-04-23 15:05:48 +02:00
|
|
|
|
2017-05-09 17:26:00 +02:00
|
|
|
QTimer::singleShot(0, [&] { view->showFullScreen(); });
|
2017-04-23 15:05:48 +02:00
|
|
|
|
2017-05-09 17:26:00 +02:00
|
|
|
connect(scene, &CropScene::closedWithRect, this, &CropEditor::crop);
|
2017-04-23 15:05:48 +02:00
|
|
|
}
|
|
|
|
|
2017-05-09 17:26:00 +02:00
|
|
|
CropEditor::~CropEditor() {
|
|
|
|
delete scene;
|
|
|
|
}
|
2017-04-23 15:05:48 +02:00
|
|
|
|
2017-05-06 13:21:12 +02:00
|
|
|
void CropEditor::crop(QRect rect) {
|
2017-05-09 17:26:00 +02:00
|
|
|
QPixmap map = view->grab(rect);
|
|
|
|
QPixmap *cropp = new QPixmap;
|
|
|
|
map.swap(*cropp);
|
|
|
|
delete view;
|
|
|
|
emit cropped(cropp);
|
2017-04-23 15:05:48 +02:00
|
|
|
}
|