From 197e7a48a390a7ec2dc31e8502f46c566a9ccdf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9au?= <theau.baton@etu.univ-amu.fr> Date: Fri, 2 Feb 2024 16:07:18 +0100 Subject: [PATCH] Ajout de la manipualtion clavier pour le crayon, la gomme et la couleur --- IHM_Retouche_Photo/dialog/sizedialog.cpp | 10 +-- IHM_Retouche_Photo/dialog/sizedialog.h | 8 +- IHM_Retouche_Photo/mainwindow.ui | 4 +- IHM_Retouche_Photo/tools/editable/bucket.cpp | 34 +++++--- IHM_Retouche_Photo/tools/editable/bucket.h | 3 + .../tools/editable/pixelEraiser.cpp | 78 ++++++++---------- .../tools/editable/pixelEraiser.h | 4 + .../tools/editable/pixelpainter.cpp | 82 +++++++++++-------- .../tools/editable/pixelpainter.h | 4 + .../tools/selectionable/color.cpp | 48 ++++++----- .../tools/selectionable/color.h | 2 + IHM_Retouche_Photo/ui/view/imagearea.cpp | 71 ++++++++++------ IHM_Retouche_Photo/ui/view/imagearea.h | 1 + 13 files changed, 203 insertions(+), 146 deletions(-) diff --git a/IHM_Retouche_Photo/dialog/sizedialog.cpp b/IHM_Retouche_Photo/dialog/sizedialog.cpp index 83049c9..8eb2171 100644 --- a/IHM_Retouche_Photo/dialog/sizedialog.cpp +++ b/IHM_Retouche_Photo/dialog/sizedialog.cpp @@ -1,11 +1,11 @@ #include "sizedialog.h" namespace dialog { - SizeDialog::SizeDialog(QString title, QString titleLabel , int min, int max, int def, QWidget *parent) - : QDialog(parent) { + SizeDialog::SizeDialog(const QString & title, const QString & titleLabel , int min, int max, int def, const QString & unit, QWidget *parent) + : QDialog(parent), _unit(unit) { this->setupUi(this); this->_titleLabel->setText(titleLabel); - this->_sizeLabel->setText(QString::number(def)); + this->_sizeLabel->setText(QString::number(def) + " " + this->_unit); this->_sizeSlidder->setMinimum(min); this->_sizeSlidder->setMaximum(max); this->_sizeSlidder->setValue(def); @@ -16,11 +16,11 @@ namespace dialog { void SizeDialog::setValue(int value) { this->_sizeSlidder->setValue(value); - this->_sizeLabel->setText(QString::number(value)); + this->updateSizeLabel(value); } void SizeDialog::updateSizeLabel(int value) { - this->_sizeLabel->setText(QString::number(value)); + this->_sizeLabel->setText(QString::number(value) + " " + this->_unit); } } diff --git a/IHM_Retouche_Photo/dialog/sizedialog.h b/IHM_Retouche_Photo/dialog/sizedialog.h index 74ba841..684e409 100644 --- a/IHM_Retouche_Photo/dialog/sizedialog.h +++ b/IHM_Retouche_Photo/dialog/sizedialog.h @@ -5,12 +5,16 @@ namespace dialog { class SizeDialog : public QDialog, public Ui::SizeDialog { Q_OBJECT + private: + QString _unit; + public: - explicit SizeDialog(QString title, QString titleLabel, int min, int max, int def = 0, QWidget *parent = nullptr); + explicit SizeDialog(const QString & title, const QString & titleLabel, int min, int max, int def = 0, const QString & unit="", QWidget *parent = nullptr); inline int min() const {return this->_sizeSlidder->minimum();} inline int max() const {return this->_sizeSlidder->maximum();} inline int value() const {return this->_sizeSlidder->value();} + inline const QString & unit() const {return this->_unit;} inline void setTitleLabelText(const QString & text) {this->_titleLabel->setText(text);} inline void setSlitderLabelText(const QString & text) {this->_sizeLabel->setText(text);} @@ -18,6 +22,8 @@ namespace dialog { inline void setMax(int max) {this->_sizeSlidder->setMaximum(max);} inline void setMin(int min) {this->_sizeSlidder->setMaximum(min);} + inline void setUnit(const QString & unit) {this->_unit = unit;} + void setValue(int); protected slots: diff --git a/IHM_Retouche_Photo/mainwindow.ui b/IHM_Retouche_Photo/mainwindow.ui index 45795a0..73912b2 100644 --- a/IHM_Retouche_Photo/mainwindow.ui +++ b/IHM_Retouche_Photo/mainwindow.ui @@ -135,9 +135,9 @@ </widget> </item> <item> - <widget class="QLabel" name="_cuurentFilesLabel"> + <widget class="QLabel" name="_currentFilesLabel"> <property name="text"> - <string>Fichiers Courant :</string> + <string>Fichiers Courants :</string> </property> </widget> </item> diff --git a/IHM_Retouche_Photo/tools/editable/bucket.cpp b/IHM_Retouche_Photo/tools/editable/bucket.cpp index ac51689..6b497c2 100644 --- a/IHM_Retouche_Photo/tools/editable/bucket.cpp +++ b/IHM_Retouche_Photo/tools/editable/bucket.cpp @@ -8,20 +8,32 @@ namespace tool { void Bucket::onMouseReleased(ui::ImageArea & a, QImage & i, const QPoint & p, const ui::Selection & s, const QMouseEvent & e, const ColorPickerWidget & cp) { if(e.button() == Qt::LeftButton) { - if(!s.empty() && s.contain(p)) { - for(auto & point : s.selection()) { - a.setColor(point, cp.currentColor()); - } + this->fill(a, i, p, s, cp.currentColor()); + } + } + + void Bucket::onMouseMoved(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QMouseEvent &, const ColorPickerWidget &, bool) { + + } + + void Bucket::onKeyReleased(ui::ImageArea & area, QImage & img, const QPoint & click, const ui::Selection & selection, const QKeyEvent & e, const ColorPickerWidget & cp) { + if(e.key() == Qt::Key_Return) { + this->fill(area, img, click, selection, cp.currentColor()); + } + } + + void Bucket::fill(ui::ImageArea & a, QImage & i, const QPoint & p, const ui::Selection & s, const QColor & color) { + if(!s.empty() && s.contain(p)) { + for(auto & point : s.selection()) { + a.setColor(point, color); } - else { - for(int x = 0; x < i.width(); x++) { - for(int y = 0; y < i.height(); y++) { - a.setColor(QPoint(x,y), cp.currentColor()); - } + } + else { + for(int x = 0; x < i.width(); x++) { + for(int y = 0; y < i.height(); y++) { + a.setColor(QPoint(x,y), color); } } } } - - void Bucket::onMouseMoved(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QMouseEvent &, const ColorPickerWidget &, bool) {} } diff --git a/IHM_Retouche_Photo/tools/editable/bucket.h b/IHM_Retouche_Photo/tools/editable/bucket.h index c5dd9ba..74161ba 100644 --- a/IHM_Retouche_Photo/tools/editable/bucket.h +++ b/IHM_Retouche_Photo/tools/editable/bucket.h @@ -10,5 +10,8 @@ namespace tool { virtual void onMousePressed(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QMouseEvent &, const ColorPickerWidget &); virtual void onMouseReleased(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QMouseEvent &, const ColorPickerWidget &); virtual void onMouseMoved(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QMouseEvent &, const ColorPickerWidget &, bool); + + virtual void onKeyReleased(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QKeyEvent &, const ColorPickerWidget &); + virtual void fill(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QColor &); }; } diff --git a/IHM_Retouche_Photo/tools/editable/pixelEraiser.cpp b/IHM_Retouche_Photo/tools/editable/pixelEraiser.cpp index ec23579..b8d0c10 100644 --- a/IHM_Retouche_Photo/tools/editable/pixelEraiser.cpp +++ b/IHM_Retouche_Photo/tools/editable/pixelEraiser.cpp @@ -3,7 +3,7 @@ namespace tool { Pixeleraiser::Pixeleraiser(const ColorPickerWidget & cp) : Editable(cp, "Gomme", QIcon(":/oxygen/16x16/ressource/image/oxygen/icons/16x16/draw-eraser.png")), - _config(new dialog::SizeDialog("Paramètre de la gomme", "Taille de la gomme", 1, 255, 4)), _leftButton(false), _rightButton(false) { + _config(new dialog::SizeDialog("Paramètre de la gomme", "Taille de la gomme", 1, 255, 4, "pixels")), _leftButton(false), _rightButton(false) { this->setCongigurationDialog(this->_config.get()); } @@ -29,11 +29,27 @@ namespace tool { void Pixeleraiser::onMouseMoved(ui::ImageArea & area, QImage & img, const QPoint & c, const ui::Selection & s, const QMouseEvent &, const ColorPickerWidget &, bool hold) { if(hold) { - int cx = c.x(); - int cy = c.y(); + if(this->_leftButton || this->_rightButton) { + this->eraise(area, img, c, s); + } + } + } + + void Pixeleraiser::onKeyReleased(ui::ImageArea & area, QImage & img, const QPoint & click, const ui::Selection & selection, const QKeyEvent & e, const ColorPickerWidget & cp) { + if(e.key() == Qt::Key_Return) { + this->eraise(area, img, click, selection); + } + } + + void Pixeleraiser::eraise(ui::ImageArea & area, QImage & img, const QPoint & c, const ui::Selection & s) { + int cx = c.x(); + int cy = c.y(); + + int size = this->_config->value(); - int size = this->_config->value(); + QColor color = img.format() == QImage::Format_RGBA32FPx4 ? QColor(0, 0, 0, 0) : QColorConstants::White; + if(color.isValid()) { for(int i = 0; i < size; i++) { int dx = i - size / 2; int x = cx + dx; @@ -42,41 +58,21 @@ namespace tool { for(int dy = 1; dy < h; dy++) { QPoint p(x, cy + dy); if(img.rect().contains(p)) { - if(!s.empty() && s.contain(p)) { - if(this->_leftButton) { - area.setColor(p, QColor(0, 0, 0, 0)); - } - else if(this->_rightButton) { - area.setColor(p ,QColorConstants::White); - } + if(s.empty()) { + area.setColor(p, color); } - else { - if(this->_leftButton) { - area.setColor(p, QColor(0, 0, 0, 0)); - } - else if(this->_rightButton) { - area.setColor(p ,QColorConstants::White); - } + else if(s.contain(p)) { + area.setColor(p, color); } } p = QPoint(x, cy - dy); if(img.rect().contains(p)) { - if(!s.empty() && s.contain(p)) { - if(this->_leftButton) { - area.setColor(p, QColor(0, 0, 0, 0)); - } - else if(this->_rightButton) { - area.setColor(p ,QColorConstants::White); - } + if(s.empty()) { + area.setColor(p, color); } - else { - if(this->_leftButton) { - area.setColor(p, QColor(0, 0, 0, 0)); - } - else if(this->_rightButton) { - area.setColor(p ,QColorConstants::White); - } + else if(s.contain(p)) { + area.setColor(p, color); } } } @@ -84,21 +80,11 @@ namespace tool { if(h >= 0) { QPoint p(x, cy); if(img.rect().contains(p)) { - if(!s.empty() && s.contain(p)) { - if(this->_leftButton) { - area.setColor(p, QColor(0, 0, 0, 0)); - } - else if(this->_rightButton) { - area.setColor(p ,QColorConstants::White); - } + if(s.empty()) { + area.setColor(p, color); } - else { - if(this->_leftButton) { - area.setColor(p, QColor(0, 0, 0, 0)); - } - else if(this->_rightButton) { - area.setColor(p ,QColorConstants::White); - } + else if(s.contain(p)) { + area.setColor(p, color); } } } diff --git a/IHM_Retouche_Photo/tools/editable/pixelEraiser.h b/IHM_Retouche_Photo/tools/editable/pixelEraiser.h index 84be3b9..0ebcdf2 100644 --- a/IHM_Retouche_Photo/tools/editable/pixelEraiser.h +++ b/IHM_Retouche_Photo/tools/editable/pixelEraiser.h @@ -17,5 +17,9 @@ namespace tool { virtual void onMousePressed(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QMouseEvent &, const ColorPickerWidget &); virtual void onMouseReleased(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QMouseEvent &, const ColorPickerWidget &); virtual void onMouseMoved(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QMouseEvent &, const ColorPickerWidget &, bool); + + virtual void onKeyReleased(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QKeyEvent &, const ColorPickerWidget &); + + virtual void eraise(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &); }; } diff --git a/IHM_Retouche_Photo/tools/editable/pixelpainter.cpp b/IHM_Retouche_Photo/tools/editable/pixelpainter.cpp index eda1db4..e12dbbd 100644 --- a/IHM_Retouche_Photo/tools/editable/pixelpainter.cpp +++ b/IHM_Retouche_Photo/tools/editable/pixelpainter.cpp @@ -3,7 +3,7 @@ namespace tool { Pixelpainter::Pixelpainter(const ColorPickerWidget & cp) : Editable(cp, "Crayon", QIcon(":/oxygen/16x16/ressource/image/oxygen/icons/16x16/draw-freehand.png")), - _config(new dialog::SizeDialog("Paramètre du crayon", "Taille du crayon", 1, 255, 4)), _leftButton(false) { + _config(new dialog::SizeDialog("Paramètre du crayon", "Taille du crayon", 1, 255, 4, "pixels")), _leftButton(false) { this->setCongigurationDialog(this->_config.get()); } @@ -21,50 +21,60 @@ namespace tool { void Pixelpainter::onMouseMoved(ui::ImageArea & area, QImage & img, const QPoint & c, const ui::Selection & s, const QMouseEvent &, const ColorPickerWidget & cp, bool hold) { if(this->_leftButton && hold) { - int cx = c.x(); - int cy = c.y(); + this->paint(area, img, c, s, cp); + } + } + + void Pixelpainter::onKeyReleased(ui::ImageArea & area, QImage & img, const QPoint & click, const ui::Selection & selection, const QKeyEvent & e, const ColorPickerWidget & cp) { + if(e.key() == Qt::Key_Return) { + this->paint(area, img, click, selection, cp); + } + } + + void Pixelpainter::paint(ui::ImageArea & area, QImage & img, const QPoint & c, const ui::Selection & s, const ColorPickerWidget & cp) { + int cx = c.x(); + int cy = c.y(); - int size = this->_config->value(); + int size = this->_config->value(); - QColor color = cp.currentColor(); + QColor color = cp.currentColor(); - if(color.isValid()) { - for(int i = 0; i < size; i++) { - int dx = i - size / 2; - int x = cx + dx; + if(color.isValid()) { + for(int i = 0; i < size; i++) { + int dx = i - size / 2; + int x = cx + dx; - int h = qRound(size * qSqrt(size * size / 4.0 - dx * dx) /size); - for(int dy = 1; dy < h; dy++) { - QPoint p(x, cy + dy); - if(img.rect().contains(p)) { - if(s.empty()) { - area.setColor(p, color); - } - else if(s.contain(p)) { - area.setColor(p, color); - } + int h = qRound(size * qSqrt(size * size / 4.0 - dx * dx) /size); + for(int dy = 1; dy < h; dy++) { + QPoint p(x, cy + dy); + if(img.rect().contains(p)) { + if(s.empty()) { + area.setColor(p, color); } + else if(s.contain(p)) { + area.setColor(p, color); + } + } - p = QPoint(x, cy - dy); - if(img.rect().contains(p)) { - if(s.empty()) { - area.setColor(p, color); - } - else if(s.contain(p)) { - area.setColor(p, color); - } + p = QPoint(x, cy - dy); + if(img.rect().contains(p)) { + if(s.empty()) { + area.setColor(p, color); + } + else if(s.contain(p)) { + area.setColor(p, color); } } + } - if(h >= 0) { - QPoint p(x, cy); - if(img.rect().contains(p)) { - if(s.empty()) { - area.setColor(p, color); - } - else if(s.contain(p)) { - area.setColor(p, color); - } + if(h >= 0) { + QPoint p(x, cy); + if(img.rect().contains(p)) { + if(s.empty()) { + area.setColor(p, color); + } + else if(s.contain(p)) { + area.setColor(p, color); } } } diff --git a/IHM_Retouche_Photo/tools/editable/pixelpainter.h b/IHM_Retouche_Photo/tools/editable/pixelpainter.h index 33a1572..ea54ec2 100644 --- a/IHM_Retouche_Photo/tools/editable/pixelpainter.h +++ b/IHM_Retouche_Photo/tools/editable/pixelpainter.h @@ -16,5 +16,9 @@ namespace tool { virtual void onMousePressed(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QMouseEvent &, const ColorPickerWidget &); virtual void onMouseReleased(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QMouseEvent &, const ColorPickerWidget &); virtual void onMouseMoved(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QMouseEvent &, const ColorPickerWidget &, bool); + + virtual void onKeyReleased(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QKeyEvent &, const ColorPickerWidget &); + + virtual void paint(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const ColorPickerWidget &); }; } diff --git a/IHM_Retouche_Photo/tools/selectionable/color.cpp b/IHM_Retouche_Photo/tools/selectionable/color.cpp index c448f3c..8abf89e 100644 --- a/IHM_Retouche_Photo/tools/selectionable/color.cpp +++ b/IHM_Retouche_Photo/tools/selectionable/color.cpp @@ -3,34 +3,18 @@ namespace tool { Color::Color(const ColorPickerWidget & cp) : Selectionable(cp, "Couleur", QIcon(":/oxygen/16x16/ressource/image/oxygen/icons/16x16/preferences-activities.png"), true), - _config(new dialog::SizeDialog("Paramètre de la séléction par couleur", "Proximité de la couleur", 0, 255, 16)),_lastClicked(-1,-1), _ctrl(false) { + _config(new dialog::SizeDialog("Paramètre de la séléction par couleur", "Proximité de la couleur", 0, 255, 16, "Units")),_lastClicked(-1,-1), _ctrl(false) { this->setCongigurationDialog(this->_config.get()); } - void Color::onMousePressed(ui::ImageArea &, ui::Selection & s, const QPoint & c, const QImage & img, const QMouseEvent & e, const ColorPickerWidget &) { + void Color::onMousePressed(ui::ImageArea &, ui::Selection & s, const QPoint & c, const QImage & i, const QMouseEvent & e, const ColorPickerWidget &) { if(!this->_ctrl || e.button() == Qt::RightButton) { s.clear(); } if(e.button() == Qt::LeftButton) { - this->_lastClicked = c; - QColor color = img.pixelColor(c); - int prox = this->_config->value(); - for(int x = 0; x < img.width(); x++) { - for(int y = 0; y < img.height(); y++) { - QPoint p = QPoint(x, y); - if(img.rect().contains(p)) { - QColor iColor = img.pixelColor(p); - - if(iColor.red() < (color.red() + prox) && iColor.red() >= (color.red() - prox) - && iColor.green() < (color.green() + prox) && iColor.green() >= (color.green() - prox) - && iColor.blue() < (color.blue() + prox) && iColor.blue() >= (color.blue() - prox)) { - s.select(p); - } - } - } - } + this->select(s, c, i); } } @@ -42,10 +26,14 @@ namespace tool { } - void Color::onKeyPress(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QKeyEvent & e, const ColorPickerWidget &) { + void Color::onKeyPress(ui::ImageArea &, ui::Selection & s, const QPoint & c, const QImage & i, const QKeyEvent & e, const ColorPickerWidget &) { if(e.key() == Qt::Key_Control) { this->_ctrl = true; } + + if(e.key() == Qt::Key_Return) { + this->select(s, c, i); + } } void Color::onKeyReleased(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QKeyEvent & e, const ColorPickerWidget &) { @@ -53,4 +41,24 @@ namespace tool { this->_ctrl = false; } } + + void Color::select(ui::Selection & s, const QPoint & c, const QImage & img) { + this->_lastClicked = c; + QColor color = img.pixelColor(c); + int prox = this->_config->value(); + for(int x = 0; x < img.width(); x++) { + for(int y = 0; y < img.height(); y++) { + QPoint p = QPoint(x, y); + if(img.rect().contains(p)) { + QColor iColor = img.pixelColor(p); + + if(iColor.red() < (color.red() + prox) && iColor.red() >= (color.red() - prox) + && iColor.green() < (color.green() + prox) && iColor.green() >= (color.green() - prox) + && iColor.blue() < (color.blue() + prox) && iColor.blue() >= (color.blue() - prox)) { + s.select(p); + } + } + } + } + } } diff --git a/IHM_Retouche_Photo/tools/selectionable/color.h b/IHM_Retouche_Photo/tools/selectionable/color.h index 99a11ea..a74ea85 100644 --- a/IHM_Retouche_Photo/tools/selectionable/color.h +++ b/IHM_Retouche_Photo/tools/selectionable/color.h @@ -20,5 +20,7 @@ namespace tool { virtual void onKeyPress(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QKeyEvent &, const ColorPickerWidget &); virtual void onKeyReleased(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QKeyEvent &, const ColorPickerWidget &); + + void select(ui::Selection &, const QPoint &, const QImage &) }; } diff --git a/IHM_Retouche_Photo/ui/view/imagearea.cpp b/IHM_Retouche_Photo/ui/view/imagearea.cpp index 71c1292..fd92745 100644 --- a/IHM_Retouche_Photo/ui/view/imagearea.cpp +++ b/IHM_Retouche_Photo/ui/view/imagearea.cpp @@ -16,11 +16,12 @@ namespace ui { ImageArea::ImageArea() : _selection(), _fileinfo(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) + "/New"), - _image(800, 600, QImage::Format_RGBA64), + _image(800, 600, QImage::Format_RGBA32FPx4), _checkboard(ImageArea::Generate_Checkboard(4, 4, 16)), _transformation(), _position(0, 0), _lastPos(0, 0), + _pixelPosition(0, 0), _repercution(nullptr), _zoom(1.f), _status(NEW), @@ -40,6 +41,7 @@ namespace ui { _transformation(), _position(0, 0), _lastPos(0, 0), + _pixelPosition(0, 0), _repercution(nullptr), _zoom(1.f), _status(ORIGINAL), @@ -48,6 +50,7 @@ namespace ui { _receiveModification(true) { this->setMouseTracking(true); this->setFocusPolicy(Qt::StrongFocus); + this->_image = this->_image.convertToFormat(QImage::Format_RGBA32FPx4); } void ImageArea::paintEvent(QPaintEvent * e) { @@ -67,24 +70,21 @@ namespace ui { this->_selection.paint(painter, QPoint(drawZone.x(), drawZone.y()), this->_image, this->_zoom); - QPoint pixelPosition = this->_lastPos - this->_position; - pixelPosition.setX(abs(pixelPosition.x()) / this->_zoom); - pixelPosition.setY(abs(pixelPosition.y()) / this->_zoom); - + QPoint pixelPosition = this->_pixelPosition; if(this->_image.rect().contains(pixelPosition)) { painter.drawRect(this->_position.x() + pixelPosition.x() * this->_zoom, this->_position.y() + pixelPosition.y() * this->_zoom, this->_zoom, this->_zoom); } } void ImageArea::mouseMoveEvent(QMouseEvent * e) { - QPoint pixelPosition = this->_position - this->_lastPos; + this->_pixelPosition = this->_position - this->_lastPos; - if(pixelPosition.x() <= 0 && pixelPosition.y() <= 0) { - pixelPosition.setX(abs(pixelPosition.x()) / this->_zoom); - pixelPosition.setY(abs(pixelPosition.y()) / this->_zoom); + if(this->_pixelPosition.x() <= 0 && this->_pixelPosition.y() <= 0) { + this->_pixelPosition.setX(abs(this->_pixelPosition.x()) / this->_zoom); + this->_pixelPosition.setY(abs(this->_pixelPosition.y()) / this->_zoom); } - emit this->mouseMoved(*this, this->_image, pixelPosition, this->_selection, *e, this->_mouseClickHold); + emit this->mouseMoved(*this, this->_image, this->_pixelPosition, this->_selection, *e, this->_mouseClickHold); this->_lastPos = e->pos(); this->repaint(); @@ -106,35 +106,56 @@ namespace ui { void ImageArea::mouseReleaseEvent(QMouseEvent * e) { this->_mouseClickHold = false; - QPoint pixelPosition = this->_position - this->_lastPos; - if(pixelPosition.x() <= 0 && pixelPosition.y() <= 0) { - pixelPosition.setX(abs(pixelPosition.x()) / this->_zoom); - pixelPosition.setY(abs(pixelPosition.y()) / this->_zoom); + this->_pixelPosition = this->_position - this->_lastPos; + if(this->_pixelPosition.x() <= 0 && this->_pixelPosition.y() <= 0) { + this->_pixelPosition.setX(abs(this->_pixelPosition.x()) / this->_zoom); + this->_pixelPosition.setY(abs(this->_pixelPosition.y()) / this->_zoom); } - emit this->mouseReleased(*this, this->_image, pixelPosition, this->_selection, *e); + emit this->mouseReleased(*this, this->_image, this->_pixelPosition, this->_selection, *e); this->repaint(); } void ImageArea::keyPressEvent(QKeyEvent * event) { - QPoint pixelPosition = this->_position - this->_lastPos; - if(pixelPosition.x() <= 0 && pixelPosition.y() <= 0) { - pixelPosition.setX(abs(pixelPosition.x()) / this->_zoom); - pixelPosition.setY(abs(pixelPosition.y()) / this->_zoom); + switch(event->key()) { + case Qt::Key_Down: + this->_pixelPosition.setY(this->_pixelPosition.y() + 1); + break; + + case Qt::Key_Up: + this->_pixelPosition.setY(this->_pixelPosition.y() - 1); + break; + + case Qt::Key_Left: + this->_pixelPosition.setX(this->_pixelPosition.x() - 1); + break; + + case Qt::Key_Right: + this->_pixelPosition.setX(this->_pixelPosition.x() + 1); + break; + + case Qt::Key_R: + this->changeZoom(1.0); + this->_lastPos = QPoint(0, 0); + this->_position = QPoint(0, 0); + } + + if(this->_pixelPosition.x() <= 0 && this->_pixelPosition.y() <= 0) { + this->_pixelPosition.setX(abs(this->_pixelPosition.x()) / this->_zoom); + this->_pixelPosition.setY(abs(this->_pixelPosition.y()) / this->_zoom); } - emit this->keyboardPress(*this, this->_image, pixelPosition,this->_selection, *event); + emit this->keyboardPress(*this, this->_image, this->_pixelPosition,this->_selection, *event); this->repaint(); } void ImageArea::keyReleaseEvent(QKeyEvent * event) { - QPoint pixelPosition = this->_position - this->_lastPos; - if(pixelPosition.x() <= 0 && pixelPosition.y() <= 0) { - pixelPosition.setX(abs(pixelPosition.x()) / this->_zoom); - pixelPosition.setY(abs(pixelPosition.y()) / this->_zoom); + if(this->_pixelPosition.x() <= 0 && this->_pixelPosition.y() <= 0) { + this->_pixelPosition.setX(abs(this->_pixelPosition.x()) / this->_zoom); + this->_pixelPosition.setY(abs(this->_pixelPosition.y()) / this->_zoom); } - emit this->keyboardRelease(*this, this->_image, pixelPosition,this->_selection, *event); + emit this->keyboardRelease(*this, this->_image, this->_pixelPosition,this->_selection, *event); this->repaint(); } diff --git a/IHM_Retouche_Photo/ui/view/imagearea.h b/IHM_Retouche_Photo/ui/view/imagearea.h index ed6d137..98b1246 100644 --- a/IHM_Retouche_Photo/ui/view/imagearea.h +++ b/IHM_Retouche_Photo/ui/view/imagearea.h @@ -23,6 +23,7 @@ namespace ui { QPoint _position; QPoint _lastPos; + QPoint _pixelPosition; Repercution * _repercution; -- GitLab