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 <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-07-02 20:51:15 +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();
|
2017-07-02 20:51:15 +02:00
|
|
|
QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem(image);
|
2017-05-09 17:26:00 +02:00
|
|
|
pixmapItem->setZValue(-1);
|
2017-05-14 23:19:13 +02:00
|
|
|
pixmapItem->setScale(1 / ratio);
|
2017-05-09 17:26:00 +02:00
|
|
|
scene->addItem(pixmapItem);
|
2017-07-02 20:51:15 +02:00
|
|
|
scene->setSceneRect(image.rect());
|
|
|
|
view->resize(image.width(), image.height());
|
|
|
|
view->setMinimumSize(image.size());
|
2017-07-03 21:29:03 +02:00
|
|
|
view->move(settings::settings().value("cropx", 0).toInt(), settings::settings().value("cropy", 0).toInt());
|
2017-07-01 17:31:54 +02:00
|
|
|
view->setWindowTitle("KShare Crop Editor");
|
2017-07-01 17:24:03 +02:00
|
|
|
view->show();
|
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() {
|
2017-07-02 20:51:15 +02:00
|
|
|
scene->deleteLater();
|
|
|
|
view->deleteLater();
|
2017-05-09 17:26:00 +02:00
|
|
|
}
|
2017-04-23 15:05:48 +02:00
|
|
|
|
2017-05-06 13:21:12 +02:00
|
|
|
void CropEditor::crop(QRect rect) {
|
2017-07-02 20:51:15 +02:00
|
|
|
if (rect.isValid()) emit cropped(view->grab(rect));
|
|
|
|
deleteLater();
|
2017-04-23 15:05:48 +02:00
|
|
|
}
|