Skip to content
Snippets Groups Projects
Commit 0288bce0 authored by BIOUD Youcef's avatar BIOUD Youcef
Browse files

Merge branch 'revert-d21adfcd' into 'youcef'

Revert "Merge branch 'dev' into 'youcef'"

See merge request !3
parents d21adfcd 366dd897
No related branches found
No related tags found
1 merge request!3Revert "Merge branch 'dev' into 'youcef'"
Showing
with 12 additions and 464 deletions
#include "polygone.h"
namespace tool {
Polygone::Polygone()
: Selectionable("Polygone", QIcon(":/oxygen/16x16/ressource/image/oxygen/icons/16x16/draw-polygon.png"), true), _preview(true) {
}
void Polygone::onMousePressed(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent &) {
}
void Polygone::onMouseReleased(ui::ImageArea &, ui::Selection &, const QPoint & clicked, const QImage &, const QMouseEvent & e) {
if(e.button() == Qt::LeftButton) {
if(this->_preview == false) {
this->_polygon.clear();
}
this->_preview = true;
this->_polygon << clicked;
}
else if(e.button() == Qt::RightButton) {
this->_preview = false;
}
}
void Polygone::onMouseMoved(ui::ImageArea &, ui::Selection & s, const QPoint & clicked, const QImage &, const QMouseEvent &, bool) {
s.clear();
QPolygon poly = this->_polygon;
if(this->_preview) {
poly << clicked;
}
QRect boundingBox = poly.boundingRect();
for(int x = 0; x < boundingBox.width(); x++) {
for(int y = 0; y < boundingBox.height(); y++) {
QPoint p(boundingBox.x() + x, boundingBox.y() + y);
if(poly.containsPoint(p, Qt::FillRule::OddEvenFill)) {
s.select(p);
}
}
}
}
}
#pragma once
#include "../selectionnable.h"
namespace tool {
class Polygone : public Selectionable {
private:
QPolygon _polygon;
bool _preview;
public:
Polygone();
virtual void onMousePressed(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent &);
virtual void onMouseReleased(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent &);
virtual void onMouseMoved(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent &, bool);
};
}
#include "rectangle.h"
namespace tool {
Rectangle::Rectangle()
: Selectionable("Rectangle", QIcon(":/oxygen/16x16/ressource/image/oxygen/icons/16x16/draw-rectangle.png"), true), _clicked(0,0), _hold(false), _multy(false) {
}
void Rectangle::onMousePressed(ui::ImageArea &, ui::Selection & s, const QPoint & clicked, const QImage &, const QMouseEvent & e) {
if(!this->_multy) {
s.clear();
}
if(e.button() == Qt::LeftButton) {
this->_clicked = clicked;
this->_hold = true;
}
}
void Rectangle::onMouseReleased(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent & e) {
if(e.button() == Qt::LeftButton) {
this->_hold = false;
}
}
void Rectangle::onMouseMoved(ui::ImageArea &, ui::Selection & s, const QPoint & c, const QImage &, const QMouseEvent &, bool) {
if(this->_hold) {
s.clear();
if(this->_clicked.x() < c.x() || this->_clicked.y() < c.y()) {
s.select(QRect(this->_clicked, c));
}
else {
s.select(QRect(c, this->_clicked));
}
}
}
void Rectangle::onKeyPress(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QKeyEvent & e) {
if(e.key() == Qt::Key_Control) {
this->_multy = true;
qDebug() << "ctrl";
}
}
void Rectangle::onKeyReleased(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QKeyEvent & e) {
if(e.key() == Qt::Key_Control) {
this->_multy = false;
}
}
}
#pragma once
#include "../selectionnable.h"
namespace tool {
class Rectangle : public Selectionable {
private:
QPoint _clicked;
bool _hold;
bool _multy;
public:
Rectangle();
virtual void onMousePressed(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent &);
virtual void onMouseReleased(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent &);
virtual void onMouseMoved(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent &, bool);
virtual void onKeyPress(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QKeyEvent &);
virtual void onKeyReleased(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QKeyEvent &);
};
}
#include "rectangleTriangle.h"
namespace tool {
RectangleTriangle::RectangleTriangle()
: Selectionable("Triangle Rectangle", QIcon(":/oxygen/16x16/ressource/image/oxygen/icons/16x16/draw-triangle.png"), true), _clicked(0,0), _hold(false), _multy(false) {
}
void RectangleTriangle::onMousePressed(ui::ImageArea &, ui::Selection & s, const QPoint & clicked, const QImage &, const QMouseEvent & e) {
if(!this->_multy) {
s.clear();
}
if(e.button() == Qt::LeftButton) {
this->_clicked = clicked;
this->_hold = true;
}
}
void RectangleTriangle::onMouseReleased(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent & e) {
if(e.button() == Qt::LeftButton) {
this->_hold = false;
}
}
void RectangleTriangle::onMouseMoved(ui::ImageArea &, ui::Selection & s, const QPoint & position, const QImage & image, const QMouseEvent &, bool) {
if(this->_hold) {
s.clear();
QVector<QPoint> selection;
int rows = position.y() - this->_clicked.y();
for(int i = 0; i < rows; i++) {
for(int j = 0; j <= i; j++) {
QPoint pixel = QPoint(this->_clicked.x() + j, this->_clicked.y() + i);
if(image.rect().contains(pixel)) {
selection.push_back(pixel);
}
}
}
s.select(selection);
}
}
void RectangleTriangle::onKeyPress(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QKeyEvent & e) {
if(e.key() == Qt::Key_Control) {
this->_multy = true;
qDebug() << "ctrl";
}
}
void RectangleTriangle::onKeyReleased(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QKeyEvent & e) {
if(e.key() == Qt::Key_Control) {
this->_multy = false;
}
}
}
#pragma once
#include "../selectionnable.h"
namespace tool {
class RectangleTriangle : public Selectionable {
private:
QPoint _clicked;
bool _hold;
bool _multy;
public:
RectangleTriangle();
virtual void onMousePressed(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent &);
virtual void onMouseReleased(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent &);
virtual void onMouseMoved(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent &, bool);
virtual void onKeyPress(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QKeyEvent &);
virtual void onKeyReleased(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QKeyEvent &);
};
}
#include "triangle.h"
namespace tool {
Triangle::Triangle()
: Selectionable("Triangle", QIcon(":/oxygen/16x16/ressource/image/oxygen/icons/16x16/draw-triangle3.png"), true), _clicked(0,0), _hold(false), _multy(false) {
}
void Triangle::onMousePressed(ui::ImageArea &, ui::Selection & s, const QPoint & clicked, const QImage &, const QMouseEvent & e) {
if(!this->_multy) {
s.clear();
}
if(e.button() == Qt::LeftButton) {
this->_clicked = clicked;
this->_hold = true;
}
}
void Triangle::onMouseReleased(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent & e) {
if(e.button() == Qt::LeftButton) {
this->_hold = false;
}
}
void Triangle::onMouseMoved(ui::ImageArea &, ui::Selection & s, const QPoint & position, const QImage & image, const QMouseEvent &, bool) {
if(this->_hold) {
s.clear();
QVector<QPoint> selection;
int rows = position.y() - this->_clicked.y();
int x = 0;
int decal = 1;
for(int i = 0; i < rows; i++) {
for(int j = 0; j < decal; j++) {
QPoint pos(x + j + this->_clicked.x(), i + this->_clicked.y());
if(image.rect().contains(pos)) {
selection.push_back(pos);
}
pos = QPoint(x - j + this->_clicked.x(), i + this->_clicked.y());
if(image.rect().contains(pos)) {
selection.push_back(pos);
}
}
decal++;
}
s.select(selection);
}
}
void Triangle::onKeyPress(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QKeyEvent & e) {
if(e.key() == Qt::Key_Control) {
this->_multy = true;
qDebug() << "ctrl";
}
}
void Triangle::onKeyReleased(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QKeyEvent & e) {
if(e.key() == Qt::Key_Control) {
this->_multy = false;
}
}
}
#pragma once
#include "../selectionnable.h"
namespace tool {
class Triangle : public Selectionable {
private:
QPoint _clicked;
bool _hold;
bool _multy;
public:
Triangle();
virtual void onMousePressed(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent &);
virtual void onMouseReleased(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent &);
virtual void onMouseMoved(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent &, bool);
virtual void onKeyPress(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QKeyEvent &);
virtual void onKeyReleased(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QKeyEvent &);
};
}
......@@ -8,7 +8,7 @@ namespace tool {
bool _free;
public:
Selectionable(const QString & = "NaN", const QIcon & = QIcon(":/oxygen/16x16/ressource/image/oxygen/icons/16x16/transform-crop.png"), bool = false);
Selectionable(const QString & = "NaN", const QIcon & = QIcon(":/image/oxygen/icons/16x16/ressource/image/oxygen/icons/16x16/transform-crop.png"),bool = false);
virtual void onMousePressed(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent &) = 0;
virtual void onMouseReleased(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent &) = 0;
......
......@@ -13,6 +13,7 @@ namespace ui {
ViewManager * _manager;
ImageArea * _area;
protected:
enum Actions : unsigned char {
ZOOM_IN = 0,
......
#include "imagemenulambda.h"
namespace ui {
imagemenulambda::imagemenulambda(dialog::ReScaleDialog * rescale, dialog::ReSizeDialog * resize,ViewManager * manager)
: _menu(nullptr), _rescale(rescale), _resize(resize), _viewManager(manager), _area(nullptr) {
QObject::connect(this->_viewManager, SIGNAL(changedView(ImageArea*)), this, SLOT(viewChange(ImageArea*)));
}
void imagemenulambda::initializeMenu(const QMenu * menu) {
this->_menu = menu;
}
void imagemenulambda::viewChange(ImageArea * area) {
if(this->_menu != nullptr) {
if(this->_area != nullptr) {
QObject::disconnect(this->_menu->actions().at(Actions::RESIZE), SIGNAL(triggered()), this->_resize, SLOT(use()));
QObject::disconnect(this->_menu->actions().at(Actions::RESCALE), SIGNAL(triggered()), this->_rescale, SLOT(use()));
QObject::disconnect(this->_menu->actions().at(Actions::TURN)->menu()->actions().at(0), SIGNAL(triggered()), this, SLOT(turn_V()));
QObject::disconnect(this->_menu->actions().at(Actions::TURN)->menu()->actions().at(1), SIGNAL(triggered()), this, SLOT(turn_H()));
QObject::disconnect(this->_menu->actions().at(Actions::ROTATE)->menu()->actions().at(0), SIGNAL(triggered()), this, SLOT(turn_left()));
QObject::disconnect(this->_menu->actions().at(Actions::ROTATE)->menu()->actions().at(1), SIGNAL(triggered()), this, SLOT(turn_right()));
}
this->_area = area;
if(this->_area != nullptr) {
QObject::connect(this->_menu->actions().at(Actions::RESIZE), SIGNAL(triggered()), this->_resize, SLOT(use()));
QObject::connect(this->_menu->actions().at(Actions::RESCALE), SIGNAL(triggered()), this->_rescale, SLOT(use()));
QObject::connect(this->_menu->actions().at(Actions::TURN)->menu()->actions().at(0), SIGNAL(triggered()), this, SLOT(turn_V()));
QObject::connect(this->_menu->actions().at(Actions::TURN)->menu()->actions().at(1), SIGNAL(triggered()), this, SLOT(turn_H()));
QObject::connect(this->_menu->actions().at(Actions::ROTATE)->menu()->actions().at(0), SIGNAL(triggered()), this, SLOT(turn_left()));
QObject::connect(this->_menu->actions().at(Actions::ROTATE)->menu()->actions().at(1), SIGNAL(triggered()), this, SLOT(turn_right()));
}
}
}
void imagemenulambda::turn_H() {
if(this->_area != nullptr) {
QTransform t;
t.rotate(180, Qt::XAxis);
this->_area->transform(t);
}
}
void imagemenulambda::turn_V() {
if(this->_area != nullptr) {
QTransform t;
t.rotate(180, Qt::YAxis);
this->_area->transform(t);
}
}
void imagemenulambda::turn_left() {
if(this->_area != nullptr) {
QTransform t;
t.rotate(-90);
this->_area->transform(t);
}
}
void imagemenulambda::turn_right() {
if(this->_area != nullptr) {
QTransform t;
t.rotate(90);
this->_area->transform(t);
}
}
}
#pragma once
#include <QObject>
#include "menubarmanager.h"
#include <dialog/rescaledialog.h>
#include <dialog/resizedialog.h>
#include "../view/viewmanager.h"
namespace ui {
class imagemenulambda : public MenuLambda {
Q_OBJECT
private:
const QMenu * _menu;
dialog::ReScaleDialog * _rescale;
dialog::ReSizeDialog * _resize;
ViewManager * _viewManager;
ImageArea * _area;
protected:
enum Actions : unsigned char {
RESIZE = 0,
RESCALE = 1,
TURN = 3,
ROTATE = 4
};
public:
imagemenulambda(dialog::ReScaleDialog *, dialog::ReSizeDialog *,ViewManager *);
virtual void initializeMenu(const QMenu *) final;
public slots:
void viewChange(ImageArea *);
void turn_H();
void turn_V();
void turn_left();
void turn_right();
};
}
......@@ -17,8 +17,6 @@ namespace ui {
QObject::connect(this->_toolbox, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(updateCurrentTool(QListWidgetItem*)));
QObject::connect(this->_viewManager, SIGNAL(changedView(ImageArea*)), this, SLOT(updateCurrentView(ImageArea*)));
QObject::connect(this->_viewManager, SIGNAL(createdView(ImageArea*)), this, SLOT(updateCurrentView(ImageArea*)));
this->_toolbox->setCurrentRow(0);
}
void ToolboxRegister::updateCurrentTool(QListWidgetItem * item) {
......
......@@ -18,7 +18,6 @@ namespace ui {
_mouseClickHold(false),
_status(NEW) {
this->setMouseTracking(true);
this->setFocusPolicy(Qt::StrongFocus);
this->_image.fill(QColorConstants::White);
}
......@@ -33,7 +32,6 @@ namespace ui {
_mouseClickHold(false),
_status(ORIGINAL) {
this->setMouseTracking(true);
this->setFocusPolicy(Qt::StrongFocus);
}
void ImageArea::paintEvent(QPaintEvent * e) {
......@@ -100,8 +98,8 @@ namespace ui {
pixelPosition.setY(abs(pixelPosition.y()) / this->_zoom);
}
emit this->keyboardPress(*this, this->_image, pixelPosition,this->_selection, *event);
this->repaint();
emit this->keyboardPress(*this, this->_image, pixelPosition,this->_selection, *event);
}
void ImageArea::keyReleaseEvent(QKeyEvent * event) {
......@@ -164,33 +162,6 @@ namespace ui {
}
}
void ImageArea::setScale(const QPoint & scaling, Qt::TransformationMode mode) {
this->setImage(this->_image.scaled(scaling.x(), scaling.y(), Qt::IgnoreAspectRatio, mode));
this->repaint();
}
void ImageArea::setSize(const QPoint & anchor, const QPoint & cliping) {
QImage copy = this->_image;
QPoint size(cliping.x() > copy.width() ? copy.width() : cliping.x(), cliping.y() > copy.height() ? copy.height() : cliping.y());
this->_image = QImage(size.x(), size.y(), QImage::Format_RGB32);
int i = 0, j = 0;
for(int x = 0; x < size.x(); x++) {
for(int y = 0; y < size.y(); y++) {
this->setColor(QPoint(i, j), copy.pixelColor(anchor.x() + x, anchor.y() + y));
j++;
}
i++;
j = 0;
}
}
void ImageArea::transform(const QTransform & transformation, Qt::TransformationMode mode) {
this->_image = this->_image.transformed(transformation, mode);
emit this->imageChanged(this->_image);
}
void ImageArea::save() {
if((this->_status & NEW) != 0) {
QString path = QFileDialog::getSaveFileName(nullptr, "", "New");
......
......@@ -7,7 +7,6 @@
#include <QShortcut>
#include <QKeyEvent>
#include "selection.h"
namespace ui {
......@@ -79,10 +78,6 @@ namespace ui {
void setImage(const QImage &);
void setColor(const QPoint &, const QColor &);
void setColor(const QVector<QPoint> &, const QColor &);
void setScale(const QPoint &, Qt::TransformationMode = Qt::TransformationMode::FastTransformation);
void setSize(const QPoint &, const QPoint &);
void transform(const QTransform &, Qt::TransformationMode = Qt::TransformationMode::FastTransformation);
void save();
void save(const QString &);
......
#include "selection.h"
#include <QDebug>
namespace ui {
Selection::Selection(const QSet<QPoint> & preselection,const QColor & color)
: _pixels(preselection), _color(color) {}
......@@ -30,9 +28,9 @@ namespace ui {
}
void Selection::select(const QRect & selection) {
for(int x = 0; x < selection.width(); x++) {
for(int y = 0; y < selection.height(); y++) {
this->select(QPoint(selection.x() + x, selection.y() + y));
for(int x = selection.x(); x < selection.width(); x++) {
for(int y = selection.y(); y < selection.height(); y++) {
this->select(QPoint(x, y));
}
}
}
......@@ -41,7 +39,7 @@ namespace ui {
for(int x = 0; x < image.width(); x++) {
for(int y = 0; y < image.width(); y++) {
if(image.pixel(x, y) == color.rgba()) {
this->select(QPoint(x, y));
this->selected(QPoint(x, y));
}
}
}
......
......@@ -11,7 +11,7 @@ namespace ui {
: _selector(selector), _tabs(tabs) {
QObject::connect(this->_selector, SIGNAL(selectItem(QFileInfo)), this, SLOT(newView(QFileInfo)));
QObject::connect(this->_selector, SIGNAL(dropItem(QFileInfo)), this, SLOT(deleteView(QFileInfo)));
QObject::connect(this->_tabs, SIGNAL(currentChanged(int)), this, SLOT(changeView(int)));
QObject::connect(this->_tabs, SIGNAL(tabCloseRequested(int)), this, SLOT(deleteView(int)));
}
......@@ -70,22 +70,20 @@ namespace ui {
if(area != nullptr) {
if(area->isOriginal()) {
QMessageBox saveDialog;
saveDialog.setText("Voulez vous sauvegarder les modification sur le fichier original.");
saveDialog.setStandardButtons(QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
saveDialog.setText("Voulez vous écraser le fichier original ?");
saveDialog.setStandardButtons(QMessageBox::Save | QMessageBox::Cancel);
saveDialog.setDefaultButton(QMessageBox::Cancel);
saveDialog.setIcon(QMessageBox::Icon::Warning);
int result = saveDialog.exec();
if(result == QMessageBox::Yes) {
if(result == QMessageBox::Save) {
area->setOriginal(false);
}
else if(result == QMessageBox::No) {
this->saveAsCurrentView();
}
else {
return;
}
}
area->save();
}
}
......@@ -99,9 +97,6 @@ namespace ui {
QFile file(path);
file.open(QIODevice::ReadOnly);
area->save(path);
area->setModified(false);
area->setOriginal(false);
area->setNew(false);
}
}
}
......
......@@ -4,7 +4,6 @@
#include <QFileInfo>
#include <QMap>
#include <QPointer>
#include <QTableWidgetItem>
#include "../files/fileselector.h"
#include "imagearea.h"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment