KShare/cropeditor/cropeditor.cpp

38 lines
832 B
C++
Raw Normal View History

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