From 6f489cb111a86662e5aa7fb0bf2e1bddf66028d9 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 01:12:21 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20de=20l'outils=20de=20s=C3=A9lection=20Q?= =?UTF-8?q?uad?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- IHM_Retouche_Photo/IHM_Retouche_Photo.pro | 2 + IHM_Retouche_Photo/mainwindow.cpp | 15 ++++++ IHM_Retouche_Photo/mainwindow.h | 4 +- IHM_Retouche_Photo/mainwindow.ui | 5 ++ IHM_Retouche_Photo/ressource.qrc | 1 + .../image/oxygen/icons/16x16/draw-quad.png | Bin 0 -> 648 bytes IHM_Retouche_Photo/tools/editable.cpp | 3 ++ IHM_Retouche_Photo/tools/editable.h | 4 ++ .../tools/editable/pixelEraiser.cpp | 2 +- .../tools/editable/pixelpainter.cpp | 12 ++--- .../tools/selectionable/color.cpp | 2 +- .../tools/selectionable/polygone.cpp | 8 +++ .../tools/selectionable/polygone.h | 3 ++ .../tools/selectionable/quad.cpp | 48 ++++++++++++++++++ IHM_Retouche_Photo/tools/selectionable/quad.h | 22 ++++++++ IHM_Retouche_Photo/tools/selectionnable.cpp | 6 +++ IHM_Retouche_Photo/tools/selectionnable.h | 6 +++ IHM_Retouche_Photo/tools/tool.h | 5 ++ .../ui/toolbox/toolRegister.cpp | 12 ++++- IHM_Retouche_Photo/ui/view/imagearea.h | 1 + IHM_Retouche_Photo/ui/view/selection.cpp | 5 +- IHM_Retouche_Photo/ui/view/selection.h | 4 +- 22 files changed, 156 insertions(+), 14 deletions(-) create mode 100644 IHM_Retouche_Photo/ressource/image/oxygen/icons/16x16/draw-quad.png create mode 100644 IHM_Retouche_Photo/tools/selectionable/quad.cpp create mode 100644 IHM_Retouche_Photo/tools/selectionable/quad.h diff --git a/IHM_Retouche_Photo/IHM_Retouche_Photo.pro b/IHM_Retouche_Photo/IHM_Retouche_Photo.pro index 1f60245..2f59791 100644 --- a/IHM_Retouche_Photo/IHM_Retouche_Photo.pro +++ b/IHM_Retouche_Photo/IHM_Retouche_Photo.pro @@ -24,6 +24,7 @@ SOURCES += \ tools/selectionable/color.cpp \ tools/selectionable/ellipse.cpp \ tools/selectionable/polygone.cpp \ + tools/selectionable/quad.cpp \ tools/selectionable/rectangle.cpp \ tools/selectionable/rectangleTriangle.cpp \ tools/selectionable/triangle.cpp \ @@ -62,6 +63,7 @@ HEADERS += \ tools/selectionable/color.h \ tools/selectionable/ellipse.h \ tools/selectionable/polygone.h \ + tools/selectionable/quad.h \ tools/selectionable/rectangle.h \ tools/selectionable/rectangleTriangle.h \ tools/selectionable/triangle.h \ diff --git a/IHM_Retouche_Photo/mainwindow.cpp b/IHM_Retouche_Photo/mainwindow.cpp index 2f7e7f2..3fa5137 100644 --- a/IHM_Retouche_Photo/mainwindow.cpp +++ b/IHM_Retouche_Photo/mainwindow.cpp @@ -25,6 +25,7 @@ #include <tools/selectionable/ellipse.h> #include <tools/selectionable/polygone.h> #include <tools/selectionable/color.h> +#include <tools/selectionable/quad.h> #include <tools/editable/pixelpainter.h> #include <tools/editable/pixelEraiser.h> @@ -92,6 +93,7 @@ MainWindow::MainWindow(QWidget * parent) this->_toolRegister->add(QSharedPointer<tool::Tool>(new tool::Ellipse(this->colorPickerWidget)), ui::ToolboxRegister::ToolType::SELECTION); this->_toolRegister->add(QSharedPointer<tool::Tool>(new tool::Polygone(this->colorPickerWidget)), ui::ToolboxRegister::ToolType::SELECTION); this->_toolRegister->add(QSharedPointer<tool::Tool>(new tool::Color(this->colorPickerWidget)), ui::ToolboxRegister::ToolType::SELECTION); + this->_toolRegister->add(QSharedPointer<tool::Tool>(new tool::Quad(this->colorPickerWidget)), ui::ToolboxRegister::ToolType::SELECTION); this->_toolRegister->add(QSharedPointer<tool::Tool>(new tool::Pixelpainter(this->colorPickerWidget)), ui::ToolboxRegister::ToolType::EDIT); this->_toolRegister->add(QSharedPointer<tool::Tool>(new tool::Pixeleraiser(this->colorPickerWidget)), ui::ToolboxRegister::ToolType::EDIT); @@ -150,6 +152,8 @@ MainWindow::MainWindow(QWidget * parent) connect(_actionDecreaseContrast, &QAction::triggered, this, &MainWindow::decreaseContrastActionTriggered); qDebug() << "Mark_11"; + + QObject::connect(this->_action_unselect, SIGNAL(triggered(bool)), this, SLOT(unselect())); } void MainWindow::dragEnterEvent(QDragEnterEvent *e) { @@ -191,6 +195,7 @@ void MainWindow::adjustBrightnessContrastActionTriggered() { isVisible = !isVisible; } + void MainWindow::increaseBrightnessActionTriggered() { ui::ImageArea *currentImageArea = this->_viewManager->currentView(); if (currentImageArea) { @@ -199,6 +204,7 @@ void MainWindow::increaseBrightnessActionTriggered() { qDebug() << "Aucun onglet d'image actif."; } } + void MainWindow::decreaseBrightnessActionTriggered() { ui::ImageArea *currentImageArea = this->_viewManager->currentView(); if (currentImageArea) { @@ -207,6 +213,7 @@ void MainWindow::decreaseBrightnessActionTriggered() { qDebug() << "Aucun onglet d'image actif."; } } + void MainWindow::increaseContrastActionTriggered() { ui::ImageArea *currentImageArea = this->_viewManager->currentView(); if (currentImageArea) { @@ -215,6 +222,7 @@ void MainWindow::increaseContrastActionTriggered() { qDebug() << "Aucun onglet d'image actif."; } } + void MainWindow::decreaseContrastActionTriggered() { ui::ImageArea *currentImageArea = this->_viewManager->currentView(); if (currentImageArea) { @@ -224,6 +232,13 @@ void MainWindow::decreaseContrastActionTriggered() { } } +void MainWindow::unselect() { + ui::ImageArea * currentImage = this->_viewManager->currentView(); + if(currentImage != nullptr) { + currentImage->clearSelection(); + } +} + MainWindow::~MainWindow() { delete this->_fileselectorManager; delete this->_toolRegister; diff --git a/IHM_Retouche_Photo/mainwindow.h b/IHM_Retouche_Photo/mainwindow.h index 40abaa6..da1118a 100644 --- a/IHM_Retouche_Photo/mainwindow.h +++ b/IHM_Retouche_Photo/mainwindow.h @@ -44,8 +44,6 @@ class MainWindow : public QMainWindow, private Ui::MainWindow { QAction* _actionIncreaseContrast; QAction* _actionDecreaseContrast; - - public: MainWindow(QWidget * parent = nullptr); ~MainWindow(); @@ -64,5 +62,7 @@ class MainWindow : public QMainWindow, private Ui::MainWindow { void increaseContrastActionTriggered(); void decreaseContrastActionTriggered(); + void unselect(); + }; diff --git a/IHM_Retouche_Photo/mainwindow.ui b/IHM_Retouche_Photo/mainwindow.ui index 20d9189..27a5e44 100644 --- a/IHM_Retouche_Photo/mainwindow.ui +++ b/IHM_Retouche_Photo/mainwindow.ui @@ -748,15 +748,20 @@ </attribute> <addaction name="_action_new"/> <addaction name="_action_close"/> + <addaction name="separator"/> <addaction name="_action_save"/> <addaction name="_action_saveAs"/> <addaction name="_action_saveAll"/> + <addaction name="separator"/> <addaction name="_action_zoom_in"/> <addaction name="_action_zoom_out"/> + <addaction name="separator"/> <addaction name="_action_rotate_left_90"/> <addaction name="_action_rotate_right_90"/> <addaction name="_action_turn_verticaly"/> <addaction name="_action_turn_horizonaly"/> + <addaction name="separator"/> + <addaction name="_action_unselect"/> </widget> <action name="_action_new"> <property name="icon"> diff --git a/IHM_Retouche_Photo/ressource.qrc b/IHM_Retouche_Photo/ressource.qrc index e3b8300..6a5912e 100644 --- a/IHM_Retouche_Photo/ressource.qrc +++ b/IHM_Retouche_Photo/ressource.qrc @@ -417,6 +417,7 @@ <file>ressource/image/oxygen/icons/16x16/align-none.png</file> <file>ressource/image/oxygen/icons/16x16/actions-fill-color-icon.png</file> <file>ressource/image/oxygen/icons/16x16/draw-unselect.png</file> + <file>ressource/image/oxygen/icons/16x16/draw-quad.png</file> </qresource> <qresource prefix="/stylesheet"/> <qresource prefix="/oxygen/64x64"> diff --git a/IHM_Retouche_Photo/ressource/image/oxygen/icons/16x16/draw-quad.png b/IHM_Retouche_Photo/ressource/image/oxygen/icons/16x16/draw-quad.png new file mode 100644 index 0000000000000000000000000000000000000000..647bf8e0f58ad530c62e30b9f86cc23286e9f597 GIT binary patch literal 648 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4mJh`2Kmqb6B!s77>k44ofy`glX=O&z`&C3 z=<CS9u(6-}Pa-P=0|RG)M`SSr1LH0bW_+=lk&S_YN!HWFF~q{Zbn<zBVMmeU`*;6! zyuEg*@0PsBy)Gtg7m{{(ct_{>t3~O>?WlNo{!xQxCW~!j=Rp?3iUl)XxC$$$RWD6S z?T+LqDer#YyL<N9Dfyp_b{oI{Ja>D3x=PH#y?f7>o96zPwqJgEX2{m4S6!|DO|C4s z`KM&})n6OqSK72BN~C-f?3(0pHLG85=81DJIv*Iec`sFRG*l6~KH;q2qbE=L_ifrV zt>lsouY|xHm5A9hD;qLQm`-m}IBisWsPsuuq(@MEd{mWP!XrtG4fD=F7wp%5@%?vF z+$5El7=~3<!ok6oN0O9(eJZN;(V5iJ$Suyrsuii&z#-Hh<ES9ekbC<?N{EmDeRm6) zD^k5%3(rlAsVJNF&|+#X_l%<k;Rmj6kaX7&aa#U4+QdvoZsr6@z3JW(vc3V2_RHQ) zFg&6rV{?4!lFQ}+I${@I&#f1Yj8U@w{KCB8aO>aq%Q8E8Q$qKeZru8n@9sN8Qw_DA zrh^YIJm6KD$WiOWzI(UtIseY)E&KkZ-7)CffBx)L*X_QSzev3lpDiP^W#i`0jt4$} z_TP2SGsh(E()x|2*N>PMxa<A>@Iib>l(^XEq^VmreArT2RW<L{y}JIg-_IQ$TlDpP z@isVZoS>^`_j=ykuQHRj8FRnb)pz#nb{6gOKL*(^QdeD%SIG?C8@2Yr#J;5D$EJ6= zpT@2I7IDXK|GGWrR<B+^X<P2gKRzE+4#poj)X=d1`SxdS2j9x|F)%PNc)I$ztaD0e F0s#DODC+<K literal 0 HcmV?d00001 diff --git a/IHM_Retouche_Photo/tools/editable.cpp b/IHM_Retouche_Photo/tools/editable.cpp index 37aab19..f09917d 100644 --- a/IHM_Retouche_Photo/tools/editable.cpp +++ b/IHM_Retouche_Photo/tools/editable.cpp @@ -4,6 +4,7 @@ namespace tool { Editable::Editable(const ColorPickerWidget & cp, const QString & name, const QIcon & icon, bool free) : Tool(name, icon), _colorPicker(&cp), _free(free) {} + void Editable::initialize(ui::ImageArea *) {} void Editable::onKeyPress(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QKeyEvent &, const ColorPickerWidget &) {} void Editable::onKeyReleased(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QKeyEvent &, const ColorPickerWidget &) {} @@ -32,4 +33,6 @@ namespace tool { void Editable::keyReleased(ui::ImageArea & area, QImage & image, QPoint & click, ui::Selection & selection, QKeyEvent & e) { this->onKeyReleased(area, image, click, selection, e, *this->_colorPicker); } + + void Editable::selectionCleared() {} } diff --git a/IHM_Retouche_Photo/tools/editable.h b/IHM_Retouche_Photo/tools/editable.h index 332cbe0..b9d6dd7 100644 --- a/IHM_Retouche_Photo/tools/editable.h +++ b/IHM_Retouche_Photo/tools/editable.h @@ -22,6 +22,8 @@ namespace tool { virtual void onKeyPress(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QKeyEvent &, const ColorPickerWidget &); virtual void onKeyReleased(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QKeyEvent &, const ColorPickerWidget &); + virtual void initialize(ui::ImageArea *); + public slots: virtual void pressed(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QMouseEvent &) final; virtual void released(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QMouseEvent &) final; @@ -29,5 +31,7 @@ namespace tool { virtual void keyPressed(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QKeyEvent &) final; virtual void keyReleased(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QKeyEvent &) final; + + virtual void selectionCleared(); }; } diff --git a/IHM_Retouche_Photo/tools/editable/pixelEraiser.cpp b/IHM_Retouche_Photo/tools/editable/pixelEraiser.cpp index 3fb1ecd..ec23579 100644 --- a/IHM_Retouche_Photo/tools/editable/pixelEraiser.cpp +++ b/IHM_Retouche_Photo/tools/editable/pixelEraiser.cpp @@ -27,7 +27,7 @@ namespace tool { } } - void Pixeleraiser::onMouseMoved(ui::ImageArea & area, QImage & img, const QPoint & c, const ui::Selection & s, const QMouseEvent &, const ColorPickerWidget & cp, bool hold) { + 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(); diff --git a/IHM_Retouche_Photo/tools/editable/pixelpainter.cpp b/IHM_Retouche_Photo/tools/editable/pixelpainter.cpp index 1dfcff5..eda1db4 100644 --- a/IHM_Retouche_Photo/tools/editable/pixelpainter.cpp +++ b/IHM_Retouche_Photo/tools/editable/pixelpainter.cpp @@ -37,20 +37,20 @@ 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(s.empty()) { area.setColor(p, color); } - else { + 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(s.empty()) { area.setColor(p, color); } - else { + else if(s.contain(p)) { area.setColor(p, color); } } @@ -59,10 +59,10 @@ namespace tool { if(h >= 0) { QPoint p(x, cy); if(img.rect().contains(p)) { - if(!s.empty() && s.contain(p)) { + if(s.empty()) { area.setColor(p, color); } - else { + else if(s.contain(p)) { area.setColor(p, color); } } diff --git a/IHM_Retouche_Photo/tools/selectionable/color.cpp b/IHM_Retouche_Photo/tools/selectionable/color.cpp index 1057d8d..c448f3c 100644 --- a/IHM_Retouche_Photo/tools/selectionable/color.cpp +++ b/IHM_Retouche_Photo/tools/selectionable/color.cpp @@ -3,7 +3,7 @@ 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, 0)),_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)),_lastClicked(-1,-1), _ctrl(false) { this->setCongigurationDialog(this->_config.get()); } diff --git a/IHM_Retouche_Photo/tools/selectionable/polygone.cpp b/IHM_Retouche_Photo/tools/selectionable/polygone.cpp index 0686566..70b52af 100644 --- a/IHM_Retouche_Photo/tools/selectionable/polygone.cpp +++ b/IHM_Retouche_Photo/tools/selectionable/polygone.cpp @@ -6,6 +6,10 @@ namespace tool { } + void Polygone::initialize(ui::ImageArea *) { + this->_polygon.clear(); + } + void Polygone::onMousePressed(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent &, const ColorPickerWidget &) { } @@ -41,4 +45,8 @@ namespace tool { } } } + + void Polygone::onClear() { + this->_polygon.clear(); + } } diff --git a/IHM_Retouche_Photo/tools/selectionable/polygone.h b/IHM_Retouche_Photo/tools/selectionable/polygone.h index 922df6b..4ef1806 100644 --- a/IHM_Retouche_Photo/tools/selectionable/polygone.h +++ b/IHM_Retouche_Photo/tools/selectionable/polygone.h @@ -14,5 +14,8 @@ namespace tool { virtual void onMousePressed(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent &, const ColorPickerWidget &); virtual void onMouseReleased(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent &, const ColorPickerWidget &); virtual void onMouseMoved(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent &, const ColorPickerWidget &, bool); + + virtual void initialize(ui::ImageArea *); + virtual void onClear(); }; } diff --git a/IHM_Retouche_Photo/tools/selectionable/quad.cpp b/IHM_Retouche_Photo/tools/selectionable/quad.cpp new file mode 100644 index 0000000..dc4debd --- /dev/null +++ b/IHM_Retouche_Photo/tools/selectionable/quad.cpp @@ -0,0 +1,48 @@ +#include "quad.h" + +namespace tool { + Quad::Quad(const ColorPickerWidget & cp) + : Selectionable(cp, "Quadrilatère", QIcon(":/oxygen/16x16/ressource/image/oxygen/icons/16x16/draw-quad.png"), true) { + + } + + void Quad::initialize(ui::ImageArea *) { + this->_polygon.clear(); + } + + void Quad::onMousePressed(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent &, const ColorPickerWidget &) { + + } + + void Quad::onMouseReleased(ui::ImageArea &, ui::Selection &, const QPoint & clicked, const QImage &, const QMouseEvent & e, const ColorPickerWidget &) { + if(e.button() == Qt::LeftButton) { + if(this->_polygon.count() >= 4) { + this->_polygon.clear(); + } + this->_polygon << clicked; + } + } + + void Quad::onMouseMoved(ui::ImageArea &, ui::Selection & s, const QPoint & clicked, const QImage &, const QMouseEvent &, const ColorPickerWidget &, bool) { + s.clear(); + QPolygon poly = this->_polygon; + + if(this->_polygon.count() < 4) { + 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); + } + } + } + } + + void Quad::onClear() { + this->_polygon.clear(); + } +} diff --git a/IHM_Retouche_Photo/tools/selectionable/quad.h b/IHM_Retouche_Photo/tools/selectionable/quad.h new file mode 100644 index 0000000..9bf9803 --- /dev/null +++ b/IHM_Retouche_Photo/tools/selectionable/quad.h @@ -0,0 +1,22 @@ +#pragma once + +#include <QPolygon> + +#include "../selectionnable.h" + +namespace tool { + class Quad : public Selectionable { + private: + QPolygon _polygon; + + public: + Quad(const ColorPickerWidget &); + + virtual void onMousePressed(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent &, const ColorPickerWidget &); + virtual void onMouseReleased(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent &, const ColorPickerWidget &); + virtual void onMouseMoved(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent &, const ColorPickerWidget &, bool); + + virtual void initialize(ui::ImageArea *); + virtual void onClear(); + }; +} diff --git a/IHM_Retouche_Photo/tools/selectionnable.cpp b/IHM_Retouche_Photo/tools/selectionnable.cpp index aea2c12..13ded16 100644 --- a/IHM_Retouche_Photo/tools/selectionnable.cpp +++ b/IHM_Retouche_Photo/tools/selectionnable.cpp @@ -4,8 +4,10 @@ namespace tool { Selectionable::Selectionable(const ColorPickerWidget & cp, const QString & name, const QIcon & icon, bool free) : Tool(name, icon), _colorPicker(&cp) ,_free(free) {} + void Selectionable::initialize(ui::ImageArea *) {} void Selectionable::onKeyPress(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QKeyEvent &, const ColorPickerWidget &) {} void Selectionable::onKeyReleased(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QKeyEvent &, const ColorPickerWidget &) {} + void Selectionable::onClear() {}; void Selectionable::pressed(ui::ImageArea & area, QImage & image, QPoint & click, ui::Selection & selection, QMouseEvent & e) { if(image.rect().contains(click) || this->_free) { @@ -32,4 +34,8 @@ namespace tool { void Selectionable::keyReleased(ui::ImageArea & area, QImage & image, QPoint & click, ui::Selection & selection, QKeyEvent & e) { this->onKeyReleased(area, selection, click, image, e, *this->_colorPicker); } + + void Selectionable::selectionCleared() { + this->onClear(); + } } diff --git a/IHM_Retouche_Photo/tools/selectionnable.h b/IHM_Retouche_Photo/tools/selectionnable.h index cbbabcf..68af877 100644 --- a/IHM_Retouche_Photo/tools/selectionnable.h +++ b/IHM_Retouche_Photo/tools/selectionnable.h @@ -22,6 +22,10 @@ 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 &); + virtual void onClear(); + + virtual void initialize(ui::ImageArea *); + public slots: virtual void pressed(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QMouseEvent &) final; virtual void released(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QMouseEvent &) final; @@ -29,5 +33,7 @@ namespace tool { virtual void keyPressed(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QKeyEvent &) final; virtual void keyReleased(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QKeyEvent &) final; + + virtual void selectionCleared() final; }; } diff --git a/IHM_Retouche_Photo/tools/tool.h b/IHM_Retouche_Photo/tools/tool.h index 8917e0f..6f35546 100644 --- a/IHM_Retouche_Photo/tools/tool.h +++ b/IHM_Retouche_Photo/tools/tool.h @@ -23,6 +23,9 @@ namespace tool { inline void setCongigurationDialog(QDialog * dial) {this->_configurationDialog = dial;} + virtual void initialize(ui::ImageArea *) = 0; + + public slots: virtual void pressed(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QMouseEvent &) = 0; virtual void released(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QMouseEvent &) = 0; @@ -31,6 +34,8 @@ namespace tool { virtual void keyPressed(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QKeyEvent &) = 0; virtual void keyReleased(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QKeyEvent &) = 0; + virtual void selectionCleared() = 0; + void showConfiguration(); }; diff --git a/IHM_Retouche_Photo/ui/toolbox/toolRegister.cpp b/IHM_Retouche_Photo/ui/toolbox/toolRegister.cpp index accb5cf..e9810e9 100644 --- a/IHM_Retouche_Photo/ui/toolbox/toolRegister.cpp +++ b/IHM_Retouche_Photo/ui/toolbox/toolRegister.cpp @@ -40,7 +40,9 @@ ToolboxRegister::ToolboxRegister(Toolbox * selectionToolbox, Toolbox * editToobl QObject::disconnect(this->_currentImage, SIGNAL(mouseMoved(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&,bool)), this->_currentTool, SLOT(moved(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&,bool))); QObject::disconnect(this->_currentImage, SIGNAL(keyboardPress(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QKeyEvent&)), this->_currentTool, SLOT(keyPressed(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QKeyEvent&))); - QObject::disconnect(this->_currentImage, SIGNAL(keyboardRelease(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QKeyEvent&)), this->_currentTool, SLOT(keyReleased(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QKeyEvent&))); + QObject::disconnect(this->_currentImage, SIGNAL(keyboardRelease(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QKeyEvent&)), this->_currentTool, SLOT(keyReleased(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QKeyEvent&))); + + QObject::disconnect(&this->_currentImage->selection(), SIGNAL(cleared()), this->_currentTool, SLOT(selectionCleared())); if(this->_currentTool->HaveConfigurationDialog()) { QObject::disconnect(this->_configButton, SIGNAL(released()), this->_currentTool, SLOT(showConfiguration())); @@ -58,6 +60,8 @@ ToolboxRegister::ToolboxRegister(Toolbox * selectionToolbox, Toolbox * editToobl QObject::connect(this->_currentImage, SIGNAL(keyboardPress(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QKeyEvent&)), this->_currentTool, SLOT(keyPressed(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QKeyEvent&))); QObject::connect(this->_currentImage, SIGNAL(keyboardRelease(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QKeyEvent&)), this->_currentTool, SLOT(keyReleased(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QKeyEvent&))); + QObject::connect(&this->_currentImage->selection(), SIGNAL(cleared()), this->_currentTool, SLOT(selectionCleared())); + QObject::connect(this->_configButton, SIGNAL(released()), this->_currentTool, SLOT(showConfiguration())); this->_configButton->setEnabled(this->_currentTool->HaveConfigurationDialog()); @@ -73,6 +77,8 @@ ToolboxRegister::ToolboxRegister(Toolbox * selectionToolbox, Toolbox * editToobl QObject::disconnect(this->_currentImage, SIGNAL(keyboardPress(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QKeyEvent&)), this->_currentTool, SLOT(keyPressed(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QKeyEvent&))); QObject::disconnect(this->_currentImage, SIGNAL(keyboardRelease(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QKeyEvent&)), this->_currentTool, SLOT(keyReleased(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QKeyEvent&))); + QObject::disconnect(&this->_currentImage->selection(), SIGNAL(cleared()), this->_currentTool, SLOT(selectionCleared())); + if(this->_currentTool->HaveConfigurationDialog()) { QObject::disconnect(this->_configButton, SIGNAL(released()), this->_currentTool, SLOT(showConfiguration())); } @@ -89,9 +95,13 @@ ToolboxRegister::ToolboxRegister(Toolbox * selectionToolbox, Toolbox * editToobl QObject::connect(this->_currentImage, SIGNAL(keyboardPress(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QKeyEvent&)), this->_currentTool, SLOT(keyPressed(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QKeyEvent&))); QObject::connect(this->_currentImage, SIGNAL(keyboardRelease(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QKeyEvent&)), this->_currentTool, SLOT(keyReleased(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QKeyEvent&))); + QObject::connect(&this->_currentImage->selection(), SIGNAL(cleared()), this->_currentTool, SLOT(selectionCleared())); + QObject::connect(this->_configButton, SIGNAL(released()), this->_currentTool, SLOT(showConfiguration())); this->_configButton->setEnabled(this->_currentTool->HaveConfigurationDialog()); + this->_currentTool->initialize(this->_currentImage); + } } } diff --git a/IHM_Retouche_Photo/ui/view/imagearea.h b/IHM_Retouche_Photo/ui/view/imagearea.h index 8d37a58..ed6d137 100644 --- a/IHM_Retouche_Photo/ui/view/imagearea.h +++ b/IHM_Retouche_Photo/ui/view/imagearea.h @@ -91,6 +91,7 @@ namespace ui { public slots: inline void changeModificationEmit(bool status) {this->_emitModification = status;} inline void changeModificationReceive(bool status) {this->_receiveModification = status;} + inline void clearSelection() {this->_selection.clear(false); this->repaint();} void increaseZoom(); void decreaseZoom(); diff --git a/IHM_Retouche_Photo/ui/view/selection.cpp b/IHM_Retouche_Photo/ui/view/selection.cpp index 38a737a..4b15fd0 100644 --- a/IHM_Retouche_Photo/ui/view/selection.cpp +++ b/IHM_Retouche_Photo/ui/view/selection.cpp @@ -99,7 +99,10 @@ namespace ui { } } - void Selection::clear() { + void Selection::clear(bool silent) { this->_pixels.clear(); + if(!silent) { + emit this->cleared(); + } } } diff --git a/IHM_Retouche_Photo/ui/view/selection.h b/IHM_Retouche_Photo/ui/view/selection.h index 9535ed0..2042f2d 100644 --- a/IHM_Retouche_Photo/ui/view/selection.h +++ b/IHM_Retouche_Photo/ui/view/selection.h @@ -34,15 +34,15 @@ namespace ui { void invert(const QImage &); void invert(unsigned int, unsigned int); - inline bool contain(const QPoint & point) const {return this->_pixels.contains(point);}; inline bool empty() const {return this->_pixels.empty();} public slots: - void clear(); + void clear(bool silent = true); signals: void selected(const QPoint &); void unselected(const QPoint &); + void cleared(); }; } -- GitLab