diff --git a/IHM_Retouche_Photo/IHM_Retouche_Photo.pro b/IHM_Retouche_Photo/IHM_Retouche_Photo.pro index 31a69783d767d2ba908fffba0f837b3eb20a9268..f57845cb2a1ef88bd266969d03528f5fe0f3b693 100644 --- a/IHM_Retouche_Photo/IHM_Retouche_Photo.pro +++ b/IHM_Retouche_Photo/IHM_Retouche_Photo.pro @@ -12,22 +12,34 @@ SOURCES += \ colorpickerwidget.cpp \ main.cpp \ mainwindow.cpp \ + tools/editable.cpp \ + tools/hand.cpp \ + tools/selectionnable.cpp \ tools/tool.cpp \ ui/files/treefileselector.cpp \ + ui/menu/displaymenulambda.cpp \ ui/menu/filemenulambda.cpp \ ui/menu/menubarmanager.cpp \ ui/toolbox/toolRegister.cpp \ + ui/view/imagearea.cpp \ + ui/view/selection.cpp \ ui/view/viewmanager.cpp HEADERS += \ colorpickerwidget.h \ mainwindow.h \ + tools/editable.h \ + tools/hand.h \ + tools/selectionnable.h \ tools/tool.h \ ui/files/fileselector.h \ ui/files/treefileselector.h \ + ui/menu/displaymenulambda.h \ ui/menu/filemenulambda.h \ ui/menu/menubarmanager.h \ ui/toolbox/toolRegister.h \ + ui/view/imagearea.h \ + ui/view/selection.h \ ui/view/viewmanager.h FORMS += \ diff --git a/IHM_Retouche_Photo/main.cpp b/IHM_Retouche_Photo/main.cpp index 8528e7696d2c58b8c034a4459d43f6c31aec7087..d8abcab93de6949e6a5eefb1a7e2298366cebe5f 100644 --- a/IHM_Retouche_Photo/main.cpp +++ b/IHM_Retouche_Photo/main.cpp @@ -14,7 +14,7 @@ QString getStyleSheet(const QString & path) { int main(int argc, char *argv[]) { QApplication application(argc, argv); - //application.setStyleSheet(getStyleSheet(":/stylesheet/ressource/stylesheet/QTDark.stylesheet")); + application.setStyleSheet(getStyleSheet(":/stylesheet/ressource/stylesheet/QTDark.css")); MainWindow window; window.show(); diff --git a/IHM_Retouche_Photo/mainwindow.cpp b/IHM_Retouche_Photo/mainwindow.cpp index 366a7161a5fb4ddcec956e0cfbdfe0c180048039..7f41ed75faf774481f5d0b2e90a6b3c89fe487c3 100644 --- a/IHM_Retouche_Photo/mainwindow.cpp +++ b/IHM_Retouche_Photo/mainwindow.cpp @@ -11,8 +11,12 @@ #include <ui/menu/filemenulambda.h> +#include <ui/menu/displaymenulambda.h> + #include <ui/files/treefileselector.h> +#include <tools/hand.h> + MainWindow::MainWindow(QWidget * parent) : QMainWindow(parent), _toolRegister(), _fileselectorManager(nullptr), _viewManager(nullptr) { @@ -21,13 +25,14 @@ MainWindow::MainWindow(QWidget * parent) this->setAcceptDrops(true); this->_imageTabs->clear(); - this->_toolRegister.setToolbox(this->_toolbox); - this->_toolRegister.update(); + qDebug() << "Mark_1"; this->_fileselectorManager = new ui::TreeFileSelector(this->_filesSelector, this->_filesSelected, this); + QObject::connect(this->_remove_selectable_element, SIGNAL(released()), this->_fileselectorManager, SLOT(removeSelectedItem())); QObject::connect(this->_add_selectable_element, SIGNAL(released()), this->_fileselectorManager, SLOT(pushItem())); +<<<<<<< HEAD ColorWindow = findChild<QPushButton*>("ColorWindow"); // Connect the button's clicked signal to the openColorPicker slot @@ -37,11 +42,28 @@ MainWindow::MainWindow(QWidget * parent) ctrlCAction->setShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_C)); // Change the shortcut connect(ctrlCAction, &QAction::triggered, this, &MainWindow::handleCtrlCKey); addAction(ctrlCAction); +======= + qDebug() << "Mark_2"; +>>>>>>> dev this->_viewManager = new ui::ViewManager(this->_fileselectorManager, this->_imageTabs); - this->_menubarManager.insert(this->_menuFile, QSharedPointer<ui::MenuLambda>(new ui::FilemenuLambda(this->_fileselectorManager))); + qDebug() << "Mark_3"; + + this->_toolRegister.setToolbox(this->_toolbox); + this->_toolRegister.setViewManager(this->_viewManager); + + this->_toolRegister.push_back(QSharedPointer<tool::Tool>(new tool::Hand())); + + this->_toolRegister.update(); + + qDebug() << "Mark_4"; + + this->_menubarManager.insert(this->_menuFile, QSharedPointer<ui::MenuLambda>(new ui::FilemenuLambda(this->_fileselectorManager, this->_viewManager))); + this->_menubarManager.insert(this->_menuAffichage, QSharedPointer<ui::MenuLambda>(new ui::DisplayMenuLambda(this->_viewManager))); this->_menubarManager.update(); + + qDebug() << "Mark_5"; } void MainWindow::dragEnterEvent(QDragEnterEvent *e) { diff --git a/IHM_Retouche_Photo/ressource.qrc b/IHM_Retouche_Photo/ressource.qrc index 7a853e1eda9c869c826e32f4c7eeb9e2dec07085..f3805d468ffceba2e3efd85fda2806125eda4eb9 100644 --- a/IHM_Retouche_Photo/ressource.qrc +++ b/IHM_Retouche_Photo/ressource.qrc @@ -416,7 +416,5 @@ <file>ressource/image/oxygen/icons/16x16/zoom-select.png</file> <file>ressource/image/oxygen/icons/16x16/align-none.png</file> </qresource> - <qresource prefix="/stylesheet"> - <file>ressource/stylesheet/QTDark.stylesheet</file> - </qresource> + <qresource prefix="/stylesheet"/> </RCC> diff --git a/IHM_Retouche_Photo/ressource/stylesheet/.gitkeep b/IHM_Retouche_Photo/ressource/stylesheet/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/IHM_Retouche_Photo/ressource/stylesheet/QTDark.css b/IHM_Retouche_Photo/ressource/stylesheet/QTDark.css new file mode 100644 index 0000000000000000000000000000000000000000..ede53c4fac0bcb722e4c4e04ebc446fc783cb004 --- /dev/null +++ b/IHM_Retouche_Photo/ressource/stylesheet/QTDark.css @@ -0,0 +1,246 @@ +* { + background: #191919; + color: #DDDDDD; + border: 1px solid #5A5A5A; +} + +/* menu */ +QMenuBar { + background-color: #002470; + color: white; +} + +/* menu items */ +QMenuBar::item { + padding: 2px 20px 2px 20px; + border: 1px solid transparent; +} + +QMenuBar::item:selected { + border-color: rgb(48, 83, 136); + background: #3859a1; +} + +QMenuBar::item:pressed { + background: #2f477a; +} + +/* boxes */ +#_filesSelector { + border-bottom-right-radius: 10px; + margin-bottom: 5px; +} + +#_filesSelected { + border-top-right-radius: 10px; + border-bottom-right-radius: 10px; + margin-bottom: 15px; +} + +#_toolbox { + border-bottom-left-radius: 10px; + border-top-left-radius: 10px; + margin-bottom: 5px; +} + +/* buttons */ +#_add_selectable_element { + border-radius: 5px; + border: 1px; + border-color: #085a00; + border-style: inset; + min-height: 20px; + padding-bottom: 2px; + padding-top: 2px; + margin-bottom: 20px; +} +#_add_selectable_element:hover { + background-color: #272727; + border-radius: 5px; + border: 2px; + border-color: #0ea800; + border-style: inset; +} + +#_remove_selectable_element { + border-radius: 5px; + border: 1px; + border-color: #790909; + border-style: inset; + min-height: 20px; + padding-bottom: 2px; + padding-top: 2px; + margin-bottom: 20px; +} +#_remove_selectable_element:hover { + background-color: #272727; + border-radius: 5px; + border: 2px; + border-color: #cf0000; + border-style: inset; +} + +#_testButton { + color: rgb(255, 255, 255); + border-radius: 5px; + min-height: 20px; + font-size: 15px; + padding-bottom: 4px; + margin-top: 5px; + margin-bottom: 5px; + margin-right: 15px; + margin-left: 15px; + border: 1px; + border-color: #3a3a3a; + border-style: outset; +} +#_testButton:hover { + background-color: #c2c2c2; + color: rgb(0, 0, 0); +} + +/* scrollbar */ +QScrollBar { + border: 1px solid #5A5A5A; + background: #191919; +} + +QScrollBar:horizontal { + height: 15px; + margin: 0px 0px 0px 32px; +} + +QScrollBar:vertical { + width: 15px; + margin: 32px 0px 0px 0px; +} + +QScrollBar::handle { + background: #353535; + border: 1px solid #5A5A5A; +} + +QScrollBar::handle:horizontal { + border-width: 0px 1px 0px 1px; +} + +QScrollBar::handle:vertical { + border-width: 1px 0px 1px 0px; +} + +QScrollBar::handle:horizontal { + min-width: 20px; +} + +QScrollBar::handle:vertical { + min-height: 20px; +} + +QScrollBar::add-line, QScrollBar::sub-line { + background:#353535; + border: 1px solid #5A5A5A; + subcontrol-origin: margin; +} + +QScrollBar::add-line { + position: absolute; +} + +QScrollBar::add-line:horizontal { + width: 15px; + subcontrol-position: left; + left: 15px; +} + +QScrollBar::add-line:vertical { + height: 15px; + subcontrol-position: top; + top: 15px; +} + +QScrollBar::sub-line:horizontal { + width: 15px; + subcontrol-position: top left; +} + +QScrollBar::sub-line:vertical { + height: 15px; + subcontrol-position: top; +} + +QScrollBar:left-arrow, QScrollBar::right-arrow, QScrollBar::up-arrow, QScrollBar::down-arrow { + border: 1px solid #5A5A5A; + width: 3px; + height: 3px; +} + +QScrollBar::add-page, QScrollBar::sub-page { + background: none; +} + +/* image container */ +QTableView { + gridline-color: #5A5A5A; +} + +QTabBar { + margin-left: 2px; +} + +QTabBar::tab { + border-top-right-radius: 4px; + padding: 4px; + margin: 4px; +} + +QTabBar::tab:selected { + background: #353535; +} + +/**/ +QSlider { + border: none; +} + +QSlider::groove:horizontal { + height: 5px; + margin: 4px 0px 4px 0px; +} + +QSlider::groove:vertical { + width: 5px; + margin: 0px 4px 0px 4px; +} + +QSlider::handle { + border: 1px solid #5A5A5A; + background: #353535; +} + +QSlider::handle:horizontal { + width: 15px; + margin: -4px 0px -4px 0px; +} + +QSlider::handle:vertical { + height: 15px; + margin: 0px -4px 0px -4px; +} + +QSlider::add-page:vertical, QSlider::sub-page:horizontal { + background: #111381; +} + +QSlider::sub-page:vertical, QSlider::add-page:horizontal { + background: #353535; +} + +/**/ +QProgressBar { + text-align: center; +} + +QProgressBar::chunk { + width: 1px; + background-color: #0e1875; +} diff --git a/IHM_Retouche_Photo/ressource/stylesheet/QTDark.stylesheet b/IHM_Retouche_Photo/ressource/stylesheet/QTDark.stylesheet deleted file mode 100644 index 664d8a7af6a592cbebe059838fca3c83fb2aedeb..0000000000000000000000000000000000000000 --- a/IHM_Retouche_Photo/ressource/stylesheet/QTDark.stylesheet +++ /dev/null @@ -1,281 +0,0 @@ -/* - Copyright 2013 Emanuel Claesson - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -/* - COLOR_DARK = #191919 - COLOR_MEDIUM = #353535 - COLOR_MEDLIGHT = #5A5A5A - COLOR_LIGHT = #DDDDDD - COLOR_ACCENT = #3D7848 -*/ - -* { - background: #191919; - color: #DDDDDD; - border: 1px solid #5A5A5A; -} - -QWidget::item:selected { - background: #3D7848; -} - -QCheckBox, QRadioButton { - border: none; -} - -QRadioButton::indicator, QCheckBox::indicator { - width: 13px; - height: 13px; -} - -QRadioButton::indicator::unchecked, QCheckBox::indicator::unchecked { - border: 1px solid #5A5A5A; - background: none; -} - -QRadioButton::indicator:unchecked:hover, QCheckBox::indicator:unchecked:hover { - border: 1px solid #DDDDDD; -} - -QRadioButton::indicator::checked, QCheckBox::indicator::checked { - border: 1px solid #5A5A5A; - background: #5A5A5A; -} - -QRadioButton::indicator:checked:hover, QCheckBox::indicator:checked:hover { - border: 1px solid #DDDDDD; - background: #DDDDDD; -} - -QGroupBox { - margin-top: 6px; -} - -QGroupBox::title { - top: -7px; - left: 7px; -} - -QScrollBar { - border: 1px solid #5A5A5A; - background: #191919; -} - -QScrollBar:horizontal { - height: 15px; - margin: 0px 0px 0px 32px; -} - -QScrollBar:vertical { - width: 15px; - margin: 32px 0px 0px 0px; -} - -QScrollBar::handle { - background: #353535; - border: 1px solid #5A5A5A; -} - -QScrollBar::handle:horizontal { - border-width: 0px 1px 0px 1px; -} - -QScrollBar::handle:vertical { - border-width: 1px 0px 1px 0px; -} - -QScrollBar::handle:horizontal { - min-width: 20px; -} - -QScrollBar::handle:vertical { - min-height: 20px; -} - -QScrollBar::add-line, QScrollBar::sub-line { - background:#353535; - border: 1px solid #5A5A5A; - subcontrol-origin: margin; -} - -QScrollBar::add-line { - position: absolute; -} - -QScrollBar::add-line:horizontal { - width: 15px; - subcontrol-position: left; - left: 15px; -} - -QScrollBar::add-line:vertical { - height: 15px; - subcontrol-position: top; - top: 15px; -} - -QScrollBar::sub-line:horizontal { - width: 15px; - subcontrol-position: top left; -} - -QScrollBar::sub-line:vertical { - height: 15px; - subcontrol-position: top; -} - -QScrollBar:left-arrow, QScrollBar::right-arrow, QScrollBar::up-arrow, QScrollBar::down-arrow { - border: 1px solid #5A5A5A; - width: 3px; - height: 3px; -} - -QScrollBar::add-page, QScrollBar::sub-page { - background: none; -} - -QAbstractButton:hover { - background: #353535; -} - -QAbstractButton:pressed { - background: #5A5A5A; -} - -QAbstractItemView { - show-decoration-selected: 1; - selection-background-color: #3D7848; - selection-color: #DDDDDD; - alternate-background-color: #353535; -} - -QHeaderView { - border: 1px solid #5A5A5A; -} - -QHeaderView::section { - background: #191919; - border: 1px solid #5A5A5A; - padding: 4px; -} - -QHeaderView::section:selected, QHeaderView::section::checked { - background: #353535; -} - -QTableView { - gridline-color: #5A5A5A; -} - -QTabBar { - margin-left: 2px; -} - -QTabBar::tab { - border-radius: 0px; - padding: 4px; - margin: 4px; -} - -QTabBar::tab:selected { - background: #353535; -} - -QComboBox::down-arrow { - border: 1px solid #5A5A5A; - background: #353535; -} - -QComboBox::drop-down { - border: 1px solid #5A5A5A; - background: #353535; -} - -QComboBox::down-arrow { - width: 3px; - height: 3px; - border: 1px solid #5A5A5A; -} - -QAbstractSpinBox { - padding-right: 15px; -} - -QAbstractSpinBox::up-button, QAbstractSpinBox::down-button { - border: 1px solid #5A5A5A; - background: #353535; - subcontrol-origin: border; -} - -QAbstractSpinBox::up-arrow, QAbstractSpinBox::down-arrow { - width: 3px; - height: 3px; - border: 1px solid #5A5A5A; -} - -QSlider { - border: none; -} - -QSlider::groove:horizontal { - height: 5px; - margin: 4px 0px 4px 0px; -} - -QSlider::groove:vertical { - width: 5px; - margin: 0px 4px 0px 4px; -} - -QSlider::handle { - border: 1px solid #5A5A5A; - background: #353535; -} - -QSlider::handle:horizontal { - width: 15px; - margin: -4px 0px -4px 0px; -} - -QSlider::handle:vertical { - height: 15px; - margin: 0px -4px 0px -4px; -} - -QSlider::add-page:vertical, QSlider::sub-page:horizontal { - background: #3D7848; -} - -QSlider::sub-page:vertical, QSlider::add-page:horizontal { - background: #353535; -} - -QLabel { - border: none; -} - -QProgressBar { - text-align: center; -} - -QProgressBar::chunk { - width: 1px; - background-color: #3D7848; -} - -QMenu::separator { - background: #353535; -} \ No newline at end of file diff --git a/IHM_Retouche_Photo/ressource/stylesheet/QTWhite.css b/IHM_Retouche_Photo/ressource/stylesheet/QTWhite.css new file mode 100644 index 0000000000000000000000000000000000000000..229b8a35ee2380ca4e92f4a876e76b0f80c95a00 --- /dev/null +++ b/IHM_Retouche_Photo/ressource/stylesheet/QTWhite.css @@ -0,0 +1,102 @@ +/* QWidget::item:selected { + background: #4278db; +} */ + +/* menu */ +QMenuBar { + background-color: #4375E3; + color: white; +} + +/* menu items */ +QMenuBar::item { + padding: 2px 20px 2px 20px; + border: 1px solid transparent; +} + +QMenuBar::item:selected { + border-color: rgb(48, 83, 136); + background: #3859a1; +} + +QMenuBar::item:pressed { + background: #2f477a; +} + +/* boxes */ +#_filesSelector { + border-bottom-right-radius: 10px; + background-color: white; + margin-bottom: 5px; +} + +#_filesSelected { + border-top-right-radius: 10px; + border-bottom-right-radius: 10px; + background-color: white; + margin-bottom: 15px; +} + +#_toolbox { + border-bottom-left-radius: 10px; + border-top-left-radius: 10px; + background-color: white; + margin-bottom: 5px; +} + +/* buttons */ +#_add_selectable_element { + border-radius: 5px; + border: 1px; + border-color: #085a00; + border-style: inset; + min-height: 20px; + padding-bottom: 2px; + padding-top: 2px; + margin-bottom: 20px; +} +#_add_selectable_element:hover { + background-color: #dadada; + border-radius: 5px; + border: 2px; + border-color: #0ea800; + border-style: inset; +} + +#_remove_selectable_element { + border-radius: 5px; + border: 1px; + border-color: #790909; + border-style: inset; + min-height: 20px; + padding-bottom: 2px; + padding-top: 2px; + margin-bottom: 20px; +} +#_remove_selectable_element:hover { + background-color: #dadada; + border-radius: 5px; + border: 2px; + border-color: #cf0000; + border-style: inset; +} + +#_testButton { + background-color: #dadada; + color: rgb(0, 0, 0); + border-radius: 5px; + min-height: 20px; + font-size: 15px; + padding-bottom: 4px; + margin-top: 5px; + margin-bottom: 5px; + margin-right: 15px; + margin-left: 15px; + border: 1px; + border-color: #3a3a3a; + border-style: outset; +} +#_testButton:hover { + background-color: #c2c2c2; + color: rgb(0, 0, 0); +} diff --git a/IHM_Retouche_Photo/tools/editable.cpp b/IHM_Retouche_Photo/tools/editable.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3ca01adfa30adc25dbe7df9568d7ab49efbc1f06 --- /dev/null +++ b/IHM_Retouche_Photo/tools/editable.cpp @@ -0,0 +1,35 @@ +#include "editable.h" + +namespace tool { + Editable::Editable(const QString & name, const QIcon & icon,bool free) + : Tool(name, icon), _free(free) {} + + void Editable::onKeyPress(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QKeyEvent &) {} + void Editable::onKeyReleased(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QKeyEvent &) {} + + void Editable::pressed(ui::ImageArea & area, QImage & image, QPoint & click, ui::Selection & selection, QMouseEvent & e) { + if(image.rect().contains(click) || this->_free) { + this->onMousePressed(area, image, click, selection, e); + } + } + + void Editable::released(ui::ImageArea & area, QImage & image, QPoint & click, ui::Selection & selection, QMouseEvent & e) { + if(image.rect().contains(click) || this->_free) { + this->onMouseReleased(area, image, click, selection, e); + } + } + + void Editable::moved(ui::ImageArea & area, QImage & image, QPoint & click, ui::Selection & selection, QMouseEvent & e, bool hold) { + if(image.rect().contains(click) || this->_free) { + this->onMouseMoved(area, image, click, selection, e, hold); + } + } + + void Editable::keyPressed(ui::ImageArea & area, QImage & image, QPoint & click, ui::Selection & selection, QKeyEvent & e) { + this->onKeyPress(area, image, click, selection, e); + } + + void Editable::keyReleased(ui::ImageArea & area, QImage & image, QPoint & click, ui::Selection & selection, QKeyEvent & e) { + this->onKeyReleased(area, image, click, selection, e); + } +} diff --git a/IHM_Retouche_Photo/tools/editable.h b/IHM_Retouche_Photo/tools/editable.h new file mode 100644 index 0000000000000000000000000000000000000000..b332fa8ab5140d52786d72436b0802799ca0f62e --- /dev/null +++ b/IHM_Retouche_Photo/tools/editable.h @@ -0,0 +1,28 @@ +#pragma once + +#include "tool.h" + +namespace tool { + class Editable : public Tool { + private: + bool _free; + + public: + Editable(const QString & = "NaN", const QIcon & = QIcon(":/image/oxygen/icons/16x16/ressource/image/oxygen/icons/16x16/draw-freehand.png"), bool = false); + + virtual void onMousePressed(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QMouseEvent &) = 0; + virtual void onMouseReleased(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QMouseEvent &) = 0; + virtual void onMouseMoved(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QMouseEvent &, bool) = 0; + + virtual void onKeyPress(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QKeyEvent &); + virtual void onKeyReleased(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QKeyEvent &); + + public slots: + virtual void pressed(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QMouseEvent &) final; + virtual void released(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QMouseEvent &) final; + virtual void moved(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QMouseEvent &, bool) final; + + virtual void keyPressed(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QKeyEvent &) final; + virtual void keyReleased(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QKeyEvent &) final; + }; +} diff --git a/IHM_Retouche_Photo/tools/hand.cpp b/IHM_Retouche_Photo/tools/hand.cpp new file mode 100644 index 0000000000000000000000000000000000000000..03b7419f026b88253e043f56225c122611193ec0 --- /dev/null +++ b/IHM_Retouche_Photo/tools/hand.cpp @@ -0,0 +1,29 @@ +#include "hand.h" + +namespace tool { + Hand::Hand() + : Editable("Main", QIcon(":/image/oxygen/icons/16x16/ressource/image/oxygen/icons/16x16/transform-move.png"), true), _leftButton(false) {} + + void Hand::onMousePressed(ui::ImageArea & area, QImage &, const QPoint &, const ui::Selection &, const QMouseEvent & e) { + if(e.button() == Qt::LeftButton) { + area.setCursor(QCursor(Qt::CursorShape::ClosedHandCursor)); + this->_leftButton = true; + } + } + + void Hand::onMouseReleased(ui::ImageArea & area, QImage &, const QPoint &, const ui::Selection &, const QMouseEvent & e) { + if(e.button() == Qt::LeftButton) { + area.setCursor(QCursor(Qt::CursorShape::OpenHandCursor)); + area.setLast_Positon(e.pos()); + this->_leftButton = false; + } + } + + void Hand::onMouseMoved(ui::ImageArea & area, QImage &, const QPoint &, const ui::Selection &, const QMouseEvent & e, bool hold) { + if(hold && this->_leftButton) { + QPoint move = e.pos() - area.last_position(); + area.setPosition(QPoint(area.position().x() + move.x(),area.position().y() + move.y())); + area.setLast_Positon(e.pos()); + } + } +} diff --git a/IHM_Retouche_Photo/tools/hand.h b/IHM_Retouche_Photo/tools/hand.h new file mode 100644 index 0000000000000000000000000000000000000000..cf0bfbf39c46eec3fde138329b0a4e83b7f8329c --- /dev/null +++ b/IHM_Retouche_Photo/tools/hand.h @@ -0,0 +1,19 @@ +#pragma once + +#include "editable.h" + +namespace tool { + class Hand : public Editable { + private: + bool _leftButton; + + public: + Hand(); + + inline virtual Qt::CursorShape shape() const {return Qt::CursorShape::OpenHandCursor;} + + virtual void onMousePressed(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QMouseEvent &); + virtual void onMouseReleased(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QMouseEvent &); + virtual void onMouseMoved(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QMouseEvent &, bool); + }; +} diff --git a/IHM_Retouche_Photo/tools/select.h b/IHM_Retouche_Photo/tools/select.h new file mode 100644 index 0000000000000000000000000000000000000000..c40c30581bb7ea047db440e3a04affcfd9713b48 --- /dev/null +++ b/IHM_Retouche_Photo/tools/select.h @@ -0,0 +1,17 @@ +#pragma once + +#include "tool.h" + +namespace tool { + class Select : public Tool { + public: + Select(const QString &, const QIcon &); + + virtual void setup() const = 0; + + public slots: + virtual void use() const final; + + }; +} + diff --git a/IHM_Retouche_Photo/tools/selectionnable.cpp b/IHM_Retouche_Photo/tools/selectionnable.cpp new file mode 100644 index 0000000000000000000000000000000000000000..307c3d2b23429e13328c05f25f112e6866d0cc98 --- /dev/null +++ b/IHM_Retouche_Photo/tools/selectionnable.cpp @@ -0,0 +1,35 @@ +#include "selectionnable.h" + +namespace tool { + Selectionable::Selectionable(const QString & name, const QIcon & icon, bool free) + : Tool(name, icon), _free(free) {} + + void Selectionable::onKeyPress(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QKeyEvent &) {} + void Selectionable::onKeyReleased(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QKeyEvent &) {} + + void Selectionable::pressed(ui::ImageArea & area, QImage & image, QPoint & click, ui::Selection & selection, QMouseEvent & e) { + if(image.rect().contains(click) || this->_free) { + this->onMousePressed(area, selection, click, image, e); + } + } + + void Selectionable::released(ui::ImageArea & area, QImage & image, QPoint & click, ui::Selection & selection, QMouseEvent & e) { + if(image.rect().contains(click) || this->_free) { + this->onMouseReleased(area, selection, click, image, e); + } + } + + void Selectionable::moved(ui::ImageArea & area, QImage & image, QPoint & click ,ui::Selection & selection, QMouseEvent & e, bool hold) { + if(image.rect().contains(click) || this->_free) { + this->onMouseMoved(area, selection, click, image, e, hold); + } + } + + void Selectionable::keyPressed(ui::ImageArea & area, QImage & image, QPoint & click, ui::Selection & selection, QKeyEvent & e) { + this->onKeyPress(area, selection, click, image, e); + } + + void Selectionable::keyReleased(ui::ImageArea & area, QImage & image, QPoint & click, ui::Selection & selection, QKeyEvent & e) { + this->onKeyReleased(area, selection, click, image, e); + } +} diff --git a/IHM_Retouche_Photo/tools/selectionnable.h b/IHM_Retouche_Photo/tools/selectionnable.h new file mode 100644 index 0000000000000000000000000000000000000000..adf266db697fc61029782aafd808bbf42483c52b --- /dev/null +++ b/IHM_Retouche_Photo/tools/selectionnable.h @@ -0,0 +1,28 @@ +#pragma once + +#include "tool.h" + +namespace tool { + class Selectionable : public Tool { + private: + bool _free; + + public: + 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; + virtual void onMouseMoved(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent &, bool) = 0; + + 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 &); + + public slots: + virtual void pressed(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QMouseEvent &) final; + virtual void released(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QMouseEvent &) final; + virtual void moved(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QMouseEvent &, bool) final; + + virtual void keyPressed(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QKeyEvent &) final; + virtual void keyReleased(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QKeyEvent &) final; + }; +} diff --git a/IHM_Retouche_Photo/tools/tool.h b/IHM_Retouche_Photo/tools/tool.h index e42d2e83dc911a1f6e370ee3c4d19bdbeec473ca..810fa5803a4be05c87a0fd1618a4b3d5422e2706 100644 --- a/IHM_Retouche_Photo/tools/tool.h +++ b/IHM_Retouche_Photo/tools/tool.h @@ -1,12 +1,26 @@ #pragma once #include <QListWidgetItem> +#include <QObject> +#include <QCursor> + +#include "../ui/view/imagearea.h" namespace tool { - class Tool : public QListWidgetItem { + class Tool : public QObject, public QListWidgetItem { + Q_OBJECT public: Tool(const QString &, const QIcon &); - virtual void use() const = 0; + virtual inline Qt::CursorShape shape() const {return Qt::CursorShape::ArrowCursor;} + + public slots: + virtual void pressed(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QMouseEvent &) = 0; + virtual void released(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QMouseEvent &) = 0; + virtual void moved(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QMouseEvent &, bool) = 0; + + virtual void keyPressed(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QKeyEvent &) = 0; + virtual void keyReleased(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QKeyEvent &) = 0; + }; } diff --git a/IHM_Retouche_Photo/ui/files/treefileselector.cpp b/IHM_Retouche_Photo/ui/files/treefileselector.cpp index 1241363e05f2481f2fc602062be9460877356bee..5a0ba867512a6137404d576c58eb0be151b4457a 100644 --- a/IHM_Retouche_Photo/ui/files/treefileselector.cpp +++ b/IHM_Retouche_Photo/ui/files/treefileselector.cpp @@ -28,7 +28,6 @@ namespace ui { this->_tree->setHeaderHidden(true); //this->_tree->setSortingEnabled(true); - QObject::connect(this->_tree, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(addItem(QModelIndex))); QObject::connect(this->_selected, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(select(QModelIndex))); } diff --git a/IHM_Retouche_Photo/ui/menu/displaymenulambda.cpp b/IHM_Retouche_Photo/ui/menu/displaymenulambda.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e543f59bd92cd584180d41e54ef3191c874a6d1d --- /dev/null +++ b/IHM_Retouche_Photo/ui/menu/displaymenulambda.cpp @@ -0,0 +1,30 @@ +#include "displaymenulambda.h" + +namespace ui { + DisplayMenuLambda::DisplayMenuLambda(ViewManager * manager) + : _manager(manager), _area(manager->currentView()) { + this->viewChange(this->_manager->currentView()); + QObject::connect(this->_manager, SIGNAL(changedView(ImageArea*)), this, SLOT(viewChange(ImageArea*))); + } + + void DisplayMenuLambda::initializeMenu(const QMenu * menu) { + this->_menu = menu; + + } + + void DisplayMenuLambda::viewChange(ImageArea *) { + if(this->_menu != nullptr) { + if(this->_area != nullptr) { + QObject::disconnect(this->_menu->actions().at(Actions::ZOOM_IN), SIGNAL(triggered()), this->_area, SLOT(increaseZoom())); + QObject::disconnect(this->_menu->actions().at(Actions::ZOOM_OUT), SIGNAL(triggered()), this->_area, SLOT(decreaseZoom())); + } + + this->_area = this->_manager->currentView(); + + if(this->_area != nullptr) { + QObject::connect(this->_menu->actions().at(Actions::ZOOM_IN), SIGNAL(triggered()), this->_area, SLOT(increaseZoom())); + QObject::connect(this->_menu->actions().at(Actions::ZOOM_OUT), SIGNAL(triggered()), this->_area, SLOT(decreaseZoom())); + } + } + } +} diff --git a/IHM_Retouche_Photo/ui/menu/displaymenulambda.h b/IHM_Retouche_Photo/ui/menu/displaymenulambda.h new file mode 100644 index 0000000000000000000000000000000000000000..f4330bd512159a5b3609d446edefda700910475d --- /dev/null +++ b/IHM_Retouche_Photo/ui/menu/displaymenulambda.h @@ -0,0 +1,31 @@ +#pragma once + +#include <QObject> +#include "menubarmanager.h" + +#include "../view/viewmanager.h" + +namespace ui { + class DisplayMenuLambda : public MenuLambda { + Q_OBJECT + private: + const QMenu * _menu; + ViewManager * _manager; + ImageArea * _area; + + + protected: + enum Actions : unsigned char { + ZOOM_IN = 0, + ZOOM_OUT = 1 + }; + + public: + DisplayMenuLambda(ViewManager * manager); + virtual void initializeMenu(const QMenu *) final; + + public slots: + void viewChange(ImageArea *); + }; +} + diff --git a/IHM_Retouche_Photo/ui/menu/filemenulambda.cpp b/IHM_Retouche_Photo/ui/menu/filemenulambda.cpp index 0d8dedd4784832e04ee8d5ffac67f6cd12688dc1..6bd0f14b34f710a63e8c4a42b24d8e2765608026 100644 --- a/IHM_Retouche_Photo/ui/menu/filemenulambda.cpp +++ b/IHM_Retouche_Photo/ui/menu/filemenulambda.cpp @@ -4,14 +4,18 @@ #include <QDebug> namespace ui { - FilemenuLambda::FilemenuLambda(FileSelector * fileselector) - : _fileselector(fileselector) {} + FilemenuLambda::FilemenuLambda(FileSelector * fileselector, ViewManager * manager) + : _fileSelector(fileselector), _viewManager(manager) {} FilemenuLambda::~FilemenuLambda() {} - void FilemenuLambda::initializeMenu(const QMenu * menu) const { + void FilemenuLambda::initializeMenu(const QMenu * menu) { QObject::connect(menu->actions().at(Actions::QUIT), SIGNAL(triggered()), QApplication::instance(), SLOT(quit())); - QObject::connect(menu->actions().at(Actions::OPEN), SIGNAL(triggered()), this->_fileselector, SLOT(pushItem())); - QObject::connect(menu->actions().at(Actions::OPEN_DIR), SIGNAL(triggered()), this->_fileselector, SLOT(setTreeRootPath())); + QObject::connect(menu->actions().at(Actions::OPEN), SIGNAL(triggered()), this->_fileSelector, SLOT(pushItem())); + QObject::connect(menu->actions().at(Actions::OPEN_DIR), SIGNAL(triggered()), this->_fileSelector, SLOT(setTreeRootPath())); + + QObject::connect(menu->actions().at(Actions::SAVE), SIGNAL(triggered()), this->_viewManager, SLOT(saveCurrentView())); + QObject::connect(menu->actions().at(Actions::SAVE_AS), SIGNAL(triggered()), this->_viewManager, SLOT(saveAsCurrentView())); + QObject::connect(menu->actions().at(Actions::NEW), SIGNAL(triggered()), this->_viewManager, SLOT(newView())); } } diff --git a/IHM_Retouche_Photo/ui/menu/filemenulambda.h b/IHM_Retouche_Photo/ui/menu/filemenulambda.h index 6669b981a2f171de62b7c3c28382da28d48fc9f5..bc90af6778cb43c2ddbfd6e35969d7b42b6b5d20 100644 --- a/IHM_Retouche_Photo/ui/menu/filemenulambda.h +++ b/IHM_Retouche_Photo/ui/menu/filemenulambda.h @@ -2,11 +2,14 @@ #include "menubarmanager.h" #include "../files/fileselector.h" +#include "../view/viewmanager.h" namespace ui { class FilemenuLambda : public MenuLambda { + Q_OBJECT private: - FileSelector * _fileselector; + FileSelector * _fileSelector; + ViewManager * _viewManager; protected: enum Actions : unsigned char { @@ -21,9 +24,10 @@ namespace ui { }; public: - FilemenuLambda(FileSelector *); + FilemenuLambda(FileSelector *, ViewManager *); virtual ~FilemenuLambda(); - virtual void initializeMenu(const QMenu *) const final; + + virtual void initializeMenu(const QMenu *) final; }; } diff --git a/IHM_Retouche_Photo/ui/menu/menubarmanager.h b/IHM_Retouche_Photo/ui/menu/menubarmanager.h index 09a7080e6bb2e7a78d24f7cc156ccad74bd76d5f..9910a51093b02a246af852af284960041af1b1f9 100644 --- a/IHM_Retouche_Photo/ui/menu/menubarmanager.h +++ b/IHM_Retouche_Photo/ui/menu/menubarmanager.h @@ -6,9 +6,10 @@ #include <QSharedPointer> namespace ui { - class MenuLambda { + class MenuLambda : public QObject { + Q_OBJECT public: - virtual void initializeMenu(const QMenu *) const = 0; + virtual void initializeMenu(const QMenu *) = 0; }; class MenubarManager : public QMap<const QMenu *, QSharedPointer<MenuLambda>> { diff --git a/IHM_Retouche_Photo/ui/toolbox/toolRegister.cpp b/IHM_Retouche_Photo/ui/toolbox/toolRegister.cpp index 95216df2b12d39e47905bfe0d278ff8349eb2afb..cbeaa54335fd0c2ef7ad9b8c32d9ce25239b80e5 100644 --- a/IHM_Retouche_Photo/ui/toolbox/toolRegister.cpp +++ b/IHM_Retouche_Photo/ui/toolbox/toolRegister.cpp @@ -1,8 +1,8 @@ #include "toolRegister.h" namespace ui { - ToolboxRegister::ToolboxRegister(const QList<tool::Tool *> & tools, Toolbox * toolbox) - : _toolbox(toolbox) { + ToolboxRegister::ToolboxRegister(Toolbox * toolbox, ViewManager * manager, const QList<tool::Tool *> & tools) + : _toolbox(toolbox), _viewManager(manager), _currentTool(nullptr), _currentImage(nullptr) { for(auto & tool : tools) { this->push_back(QSharedPointer<tool::Tool>(tool)); } @@ -13,5 +13,60 @@ namespace ui { for(auto & tool : *this) { this->_toolbox->addItem(tool.get()); } + + 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*))); + } + + void ToolboxRegister::updateCurrentTool(QListWidgetItem * item) { + if(this->_currentTool != nullptr && this->_currentImage != nullptr) { + QObject::disconnect(this->_currentImage, SIGNAL(mousePressed(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&)), this->_currentTool, SLOT(pressed(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&))); + QObject::disconnect(this->_currentImage, SIGNAL(mouseReleased(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&)), this->_currentTool, SLOT(released(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&))); + 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&))); + + } + + this->_currentTool = dynamic_cast<tool::Tool*>(item); + + if(this->_currentTool != nullptr && this->_currentImage != nullptr) { + this->_currentImage->setCursor(QCursor(this->_currentTool->shape())); + QObject::connect(this->_currentImage, SIGNAL(mousePressed(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&)), this->_currentTool, SLOT(pressed(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&))); + QObject::connect(this->_currentImage, SIGNAL(mouseReleased(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&)), this->_currentTool, SLOT(released(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&))); + QObject::connect(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::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&))); + } + + qDebug() << "tool choose"; + } + + void ToolboxRegister::updateCurrentView(ImageArea * image) { + if(this->_currentTool != nullptr && this->_currentImage != nullptr) { + QObject::disconnect(this->_currentImage, SIGNAL(mousePressed(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&)), this->_currentTool, SLOT(pressed(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&))); + QObject::disconnect(this->_currentImage, SIGNAL(mouseReleased(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&)), this->_currentTool, SLOT(released(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&))); + 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&))); + } + + this->_currentImage = dynamic_cast<ImageArea *>(image); + + if(this->_currentTool != nullptr && this->_currentImage != nullptr) { + this->_currentImage->setCursor(QCursor(this->_currentTool->shape())); + QObject::connect(this->_currentImage, SIGNAL(mousePressed(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&)), this->_currentTool, SLOT(pressed(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&))); + QObject::connect(this->_currentImage, SIGNAL(mouseReleased(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&)), this->_currentTool, SLOT(released(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&))); + QObject::connect(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::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&))); + } + + qDebug() << "view changed"; } } diff --git a/IHM_Retouche_Photo/ui/toolbox/toolRegister.h b/IHM_Retouche_Photo/ui/toolbox/toolRegister.h index b5e6efd9074f6fadb6b8140ff9b4919be52d4fcd..e93514ae32c8f739ccb94eefd9666882e4b43ffb 100644 --- a/IHM_Retouche_Photo/ui/toolbox/toolRegister.h +++ b/IHM_Retouche_Photo/ui/toolbox/toolRegister.h @@ -6,20 +6,30 @@ #include <tools/tool.h> +#include "../view/viewmanager.h" + namespace ui { using Toolbox = QListWidget; - - class ToolboxRegister : public QVector<QSharedPointer<tool::Tool>> { + class ToolboxRegister : public QObject, public QVector<QSharedPointer<tool::Tool>> { + Q_OBJECT public: Toolbox * _toolbox; + ViewManager * _viewManager; + tool::Tool * _currentTool; + ImageArea * _currentImage; public: - ToolboxRegister(const QList<tool::Tool *> & = {}, Toolbox * toolbox = nullptr); + ToolboxRegister(Toolbox * = nullptr, ViewManager * = nullptr, const QList<tool::Tool *> & = {}); inline void setToolbox(Toolbox * toolbox) {this->_toolbox = toolbox;} + inline void setViewManager(ViewManager * viewManager) {this->_viewManager = viewManager;} inline const Toolbox * toolbox() const {return this->_toolbox;} void update(); + + public slots: + void updateCurrentTool(QListWidgetItem *); + void updateCurrentView(ImageArea *); }; } diff --git a/IHM_Retouche_Photo/ui/view/imagearea.cpp b/IHM_Retouche_Photo/ui/view/imagearea.cpp new file mode 100644 index 0000000000000000000000000000000000000000..242b7e4d532642432e226027ed25f7f7ee062c85 --- /dev/null +++ b/IHM_Retouche_Photo/ui/view/imagearea.cpp @@ -0,0 +1,202 @@ +#include "imagearea.h" + +#include <QKeySequence> +#include <QApplication> +#include <QMessageBox> +#include <QStandardPaths> +#include <QFileDialog> + +namespace ui { + ImageArea::ImageArea() + : _selection(), + _fileinfo(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) + "/New"), + _image(800, 600, QImage::Format_RGB32), + _checkboard(ImageArea::Generate_Checkboard(4, 4, 16)), + _position(0, 0), + _lastPos(0, 0), + _zoom(1.f), + _mouseClickHold(false), + _status(NEW) { + this->setMouseTracking(true); + this->_image.fill(QColorConstants::White); + } + + ImageArea::ImageArea(const QFileInfo & info, QWidget *) + : _selection(), + _fileinfo(info), + _image(info.absoluteFilePath()), + _checkboard(ImageArea::Generate_Checkboard(4, 4, 16)) , + _position(0, 0), + _lastPos(0, 0), + _zoom(1.f), + _mouseClickHold(false), + _status(ORIGINAL) { + this->setMouseTracking(true); + } + + void ImageArea::paintEvent(QPaintEvent * e) { + QWidget::paintEvent(e); + QPainter painter(this); + + QRect drawZone( + this->_position.x(), + this->_position.y(), + this->_image.width() * this->_zoom, + this->_image.height() * this->_zoom + ); + + painter.drawRect(drawZone); + painter.drawImage(drawZone, this->_checkboard); + painter.drawImage(drawZone, this->_image); + + this->_selection.paint(painter, QPoint(drawZone.x(), drawZone.y()), this->_zoom); + } + + void ImageArea::mouseMoveEvent(QMouseEvent * e) { + 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); + } + + emit this->mouseMoved(*this, this->_image, pixelPosition, this->_selection, *e, this->_mouseClickHold); + this->_lastPos = e->pos(); + + this->repaint(); + } + + void ImageArea::mousePressEvent(QMouseEvent * e) { + this->_mouseClickHold = true; + + 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); + } + + emit this->mousePressed(*this, this->_image, pixelPosition, this->_selection, *e); + this->repaint(); + } + + 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); + } + + emit this->mouseReleased(*this, this->_image, 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); + } + + this->repaint(); + emit this->keyboardPress(*this, this->_image, pixelPosition,this->_selection, *event); + } + + 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); + } + + emit this->keyboardRelease(*this, this->_image, pixelPosition,this->_selection, *event); + this->repaint(); + } + + void ImageArea::wheelEvent(QWheelEvent *event) { + if(event->angleDelta().y() > 0) { + this->increaseZoom(); + } + else if(event->angleDelta().y() < 0) { + this->decreaseZoom(); + } + } + + void ImageArea::changeZoom(float value) { + this->_zoom = value; + emit this->zoomChange(value); + this->repaint(); + } + + void ImageArea::increaseZoom() { + this->_zoom += 1; + emit this->zoomChange(this->_zoom); + this->repaint(); + } + + void ImageArea::decreaseZoom() { + if(this->_zoom > 1) { + this->_zoom -= 1; + emit this->zoomChange(this->_zoom); + this->repaint(); + } + } + + void ImageArea::setImage(const QImage & image) { + this->_image = image; + this->_checkboard = ImageArea::Generate_Checkboard(this->_image.width()/2, this->_image.height()/2, 1); + emit this->imageChanged(image); + } + + void ImageArea::setColor(const QPoint & pixel, const QColor & color) { + this->_image.setPixelColor(pixel, color); + this->_status |= MODIFIED; + emit this->pixelChange(pixel); + } + + void ImageArea::setColor(const QVector<QPoint> & pixels, const QColor & color) { + for(auto & pixel : pixels) { + this->_image.setPixelColor(pixel, color); + } + } + + void ImageArea::save() { + if((this->_status & NEW) != 0) { + QString path = QFileDialog::getSaveFileName(nullptr, "", "New"); + this->_fileinfo = QFileInfo(path); + } + this->save(this->_fileinfo.absoluteFilePath()); + } + + void ImageArea::save(const QString & path) { + if(!QFile::exists(path)) { + QFile newFile(path); + newFile.open(QFile::ReadOnly); + } + + this->_image.save(path); + this->_fileinfo.setFile(path); + this->_status &= ~MODIFIED; + emit this->saved(this->_image, this->_fileinfo); + } + + QImage ImageArea::Generate_Checkboard(qsizetype nbsquare_v, qsizetype nbsquare_h, qsizetype size) { + QImage img(size*nbsquare_v, size*nbsquare_h, QImage::Format_RGB32); + img.fill(QColorConstants::White); + + bool gray = true; + for(int c = 0; c < nbsquare_v; c++) { + for(int r = 0; r < nbsquare_h; r++) { + for(int w = 0; w < size-1; w++) { + for(int h = 0; h < size-1; h++) { + img.setPixelColor(w + (size * r) , h + (size * c), gray ? QColorConstants::LightGray : QColorConstants::White); + } + } + gray = !gray; + } + gray = !gray; + } + + return img; + } +} diff --git a/IHM_Retouche_Photo/ui/view/imagearea.h b/IHM_Retouche_Photo/ui/view/imagearea.h new file mode 100644 index 0000000000000000000000000000000000000000..dc94499e0f97fac71d3c93ef4672d562ee3c6a7c --- /dev/null +++ b/IHM_Retouche_Photo/ui/view/imagearea.h @@ -0,0 +1,100 @@ +#pragma once + +#include <QWidget> +#include <QFileInfo> +#include <QSharedPointer> +#include <QPainter> +#include <QShortcut> +#include <QKeyEvent> + +#include "selection.h" + +namespace ui { + class ImageArea : public QWidget { + Q_OBJECT + private: + Selection _selection; + QFileInfo _fileinfo; + QImage _image; + QImage _checkboard; + + QPoint _position; + QPoint _lastPos; + + float _zoom; + + bool _mouseClickHold; + uint32_t _status; + + protected: + enum Status { + NONE = 0, + ORIGINAL = 1, + MODIFIED = 2, + NEW = 4 + }; + + public: + ImageArea(); + ImageArea(const QFileInfo &, QWidget * = nullptr); + + inline const QFileInfo & file() const {return this->_fileinfo;} + inline const QImage & image() const {return this->_image;} + inline float zoom() const {return this->_zoom;} + inline bool isOriginal() const {return (this->_status & ORIGINAL) != 0;} + inline bool isModified() const {return (this->_status & MODIFIED) != 0;} + inline bool isNew() const {return (this->_status & NEW) != 0;} + inline bool isMouseHolded() const {return this->_mouseClickHold;} + + inline const QPoint & position() const {return this->_position;} + inline const QPoint & last_position() const {return this->_lastPos;} + + inline void setOriginal(bool original) {this->_status = original ? this->_status | ORIGINAL : this->_status & ~ORIGINAL;} + inline void setModified(bool modified) {this->_status = modified ? this->_status | MODIFIED : this->_status & ~MODIFIED;} + inline void setNew(bool news) {this->_status = news ? this->_status | NEW : this->_status & ~NEW;} + inline void setZoom(float zoom) {this->_zoom = zoom;} + inline void setMouseHold(bool hold) {this->_mouseClickHold = hold;} + inline void setPosition(const QPoint & position) {this->_position = position;} + inline void setLast_Positon(const QPoint & lastPosition) {this->_lastPos = lastPosition;} + + virtual void paintEvent(QPaintEvent *); + + virtual void mouseMoveEvent(QMouseEvent *); + virtual void mousePressEvent(QMouseEvent *); + virtual void mouseReleaseEvent(QMouseEvent *); + + virtual void keyPressEvent(QKeyEvent *); + virtual void keyReleaseEvent(QKeyEvent *); + + virtual void wheelEvent(QWheelEvent *); + + static QImage Generate_Checkboard(qsizetype, qsizetype, qsizetype); + + public slots: + void changeZoom(float); + void increaseZoom(); + void decreaseZoom(); + + void setImage(const QImage &); + void setColor(const QPoint &, const QColor &); + void setColor(const QVector<QPoint> &, const QColor &); + + void save(); + void save(const QString &); + + signals: + void zoomChange(float); + + void imageChanged(const QImage &); + void pixelChange(const QPoint &); + + void saved(const QImage &, const QFileInfo &); + + void mousePressed(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QMouseEvent &); + void mouseReleased(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QMouseEvent &); + void mouseMoved(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QMouseEvent &, bool); + void keyboardPress(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QKeyEvent &); + void keyboardRelease(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QKeyEvent &); + }; +} + diff --git a/IHM_Retouche_Photo/ui/view/selection.cpp b/IHM_Retouche_Photo/ui/view/selection.cpp new file mode 100644 index 0000000000000000000000000000000000000000..07d4e844610b7d748f2703cc3c7bc3bc7fdd094f --- /dev/null +++ b/IHM_Retouche_Photo/ui/view/selection.cpp @@ -0,0 +1,105 @@ +#include "selection.h" + +namespace ui { + Selection::Selection(const QSet<QPoint> & preselection,const QColor & color) + : _pixels(preselection), _color(color) {} + + void Selection::paint(QPainter & painter, const QPoint & position, float zoom) { + for(auto & pixel : this->_pixels) { + painter.fillRect(position.x() + pixel.x() * zoom, position.y() + pixel.y() * zoom, zoom, zoom, this->_color); + } + } + + void Selection::select(const QPoint & point) { + this->_pixels.insert(point); + emit this->selected(point); + } + + void Selection::select(const QSet<QPoint> & selection) { + for(auto & pixel : selection) { + this->select(pixel); + } + } + + void Selection::select(const QVector<QPoint> & selection) { + for(auto & pixel : selection) { + this->select(pixel); + } + } + + void Selection::select(const QRect & selection) { + for(int x = selection.x(); x < selection.width(); x++) { + for(int y = selection.y(); y < selection.height(); y++) { + this->select(QPoint(x, y)); + } + } + } + + void Selection::select(const QImage & image, const QColor & color) { + for(int x = 0; x < image.width(); x++) { + for(int y = 0; y < image.width(); y++) { + if(image.pixel(x, y) == color.rgba()) { + this->selected(QPoint(x, y)); + } + } + } + } + + void Selection::unselect(const QPoint & point) { + this->_pixels.erase(this->_pixels.find(point)); + emit this->unselected(point); + } + + void Selection::unselect(const QSet<QPoint> & selection) { + for(auto & pixel : selection) { + this->unselect(pixel); + } + } + + void Selection::unselect(const QVector<QPoint> & selection) { + for(auto & pixel : selection) { + this->unselect(pixel); + } + } + + void Selection::unselect(const QRect & selection) { + for(int x = selection.x(); x < selection.width(); x++) { + for(int y = selection.y(); y < selection.height(); y++) { + this->unselect(QPoint(x, y)); + } + } + } + + void Selection::unselect(const QImage & image, const QColor & color) { + for(auto & point : this->_pixels) { + if(image.pixel(point) == color.rgb()) { + this->unselect(point); + } + } + } + + void Selection::invert(const QImage & image) { + this->invert(image.width(), image.height()); + } + + void Selection::invert(unsigned int w, unsigned int h) { + QSet<QPoint> current = this->_pixels; + this->clear(); + for(unsigned int x = 0; x < w; x++) { + for(unsigned int y = 0; y < h; y++) { + QPoint point = QPoint(x, y); + if(!current.contains(point)) { + this->select(point); + } + } + } + } + + void Selection::clear() { + this->_pixels.clear(); + } + + bool Selection::contain(const QPoint & point) { + return this->_pixels.contains(point); + } +} diff --git a/IHM_Retouche_Photo/ui/view/selection.h b/IHM_Retouche_Photo/ui/view/selection.h new file mode 100644 index 0000000000000000000000000000000000000000..aac17dc35831ea7be31369d6b9529e2ffba21d46 --- /dev/null +++ b/IHM_Retouche_Photo/ui/view/selection.h @@ -0,0 +1,44 @@ +#pragma once + +#include <QObject> +#include <QSet> +#include <QPoint> +#include <QPainter> + +namespace ui { + class Selection : public QObject { + Q_OBJECT + private: + QSet<QPoint> _pixels; + QColor _color; + + public: + Selection(const QSet<QPoint> & = {}, const QColor & = QColor(0, 148, 255, 96)); + + inline const QSet<QPoint> selection() const {return this->_pixels;} + + void paint(QPainter &, const QPoint &, float); + + void select(const QPoint &); + void select(const QSet<QPoint> &); + void select(const QVector<QPoint> &); + void select(const QRect &); + void select(const QImage &, const QColor &); + + void unselect(const QPoint &); + void unselect(const QSet<QPoint> &); + void unselect(const QVector<QPoint> &); + void unselect(const QRect &); + void unselect(const QImage &, const QColor &); + + void invert(const QImage &); + void invert(unsigned int, unsigned int); + void clear(); + + bool contain(const QPoint &); + + signals: + void selected(const QPoint &); + void unselected(const QPoint &); + }; +} diff --git a/IHM_Retouche_Photo/ui/view/viewmanager.cpp b/IHM_Retouche_Photo/ui/view/viewmanager.cpp index 616def4102af5257f4d409eccbb34caf9b53aa8e..45fcab480312633eab4731ea203941da175f4b15 100644 --- a/IHM_Retouche_Photo/ui/view/viewmanager.cpp +++ b/IHM_Retouche_Photo/ui/view/viewmanager.cpp @@ -1,25 +1,117 @@ #include "viewmanager.h" #include <QPushButton> +#include <QMessageBox> +#include <QFileDialog> +#include <QStandardPaths> +#include <QIcon> namespace ui { ViewManager::ViewManager(FileSelector * selector, QTabWidget * tabs) - : _selector(selector), _views(tabs) { + : _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->_views, SIGNAL(tabCloseRequested(int)), this, SLOT(deleteView(int))); + QObject::connect(this->_tabs, SIGNAL(tabCloseRequested(int)), this, SLOT(deleteView(int))); } void ViewManager::deleteView(int index) { - this->_views->removeTab(index); + emit this->deletedView(this->currentView()); + if(this->_tabs->count() != 0) { + emit this->changedView(this->currentView()); + } + this->_tabs->removeTab(index); } - void ViewManager::newView(const QFileInfo & info) { + void ViewManager::deleteCurrentView() { + this->deleteView(this->_tabs->currentIndex()); + } + + void ViewManager::changeView(int) { + emit this->changedView(this->currentView()); + } + + void ViewManager::viewModified(const QFileInfo &) { + for(int i = 0 ; i < this->_tabs->count(); i++ ) { + ImageArea * area = dynamic_cast<ImageArea *>(this->_tabs->widget(i)); + if(area->isModified()) { + this->_tabs->setTabText(i, "*" + area->file().fileName()); + } + } + } + void ViewManager::newView() { + int tabs = this->_tabs->count(); + this->_tabs->addTab(new ImageArea(), "New"); + emit this->createdView(this->currentView()); + if(tabs == 0) { + emit this->changedView(this->currentView()); + } + } + + void ViewManager::newView(const QFileInfo & info) { + this->_tabs->addTab(QPointer<ImageArea>(new ImageArea(info)), info.fileName()); + emit this->createdView(this->currentView()); } void ViewManager::deleteView(const QFileInfo & info) { + for(int i = 0; i < this->_tabs->count(); i++) { + ImageArea * widget = dynamic_cast<ImageArea *>(this->_tabs->widget(i)); + if(widget->file().absoluteFilePath() == info.absoluteFilePath()) { + emit this->deletedView(widget); + this->_tabs->removeTab(i); + --i; + } + } + } + + void ViewManager::saveView(int index) { + ImageArea * area = dynamic_cast<ImageArea *>(this->_tabs->widget(index)); + if(area != nullptr) { + if(area->isOriginal()) { + QMessageBox saveDialog; + 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::Save) { + area->setOriginal(false); + } + else { + return; + } + } + + area->save(); + } + } + + void ViewManager::saveAsView(int index) { + ImageArea * area = dynamic_cast<ImageArea *>(this->_tabs->widget(index)); + if(area != nullptr) { + QString path = QFileDialog::getSaveFileName(nullptr, "", area->file().fileName()); + + if(!path.isEmpty()) { + QFile file(path); + file.open(QIODevice::ReadOnly); + area->save(path); + } + } + } + + void ViewManager::saveAll() { + for(int i = 0; i < this->_tabs->count(); i++) { + this->saveView(i); + } + } + + void ViewManager::saveCurrentView() { + this->saveView(this->_tabs->currentIndex()); + } + void ViewManager::saveAsCurrentView() { + this->saveAsView(this->_tabs->currentIndex()); } } diff --git a/IHM_Retouche_Photo/ui/view/viewmanager.h b/IHM_Retouche_Photo/ui/view/viewmanager.h index c572ba61ace0b057367016f81e9f29909af5831d..bd23d876591719ebbc3803615d7e61b075c53849 100644 --- a/IHM_Retouche_Photo/ui/view/viewmanager.h +++ b/IHM_Retouche_Photo/ui/view/viewmanager.h @@ -3,26 +3,47 @@ #include <QTabWidget> #include <QFileInfo> #include <QMap> +#include <QPointer> #include "../files/fileselector.h" +#include "imagearea.h" namespace ui { class ViewManager : public QObject { Q_OBJECT private: FileSelector * _selector; - QTabWidget * _views; - QVector<QFileInfo> _images; + QTabWidget * _tabs; public: ViewManager() = delete; ViewManager(FileSelector *selector, QTabWidget * tabs); + inline ImageArea * currentView() const {return dynamic_cast<ImageArea *>(this->_tabs->currentWidget());} + inline QTabWidget * tabs() const {return this->_tabs;} + inline FileSelector * fileselector() const {return this->_selector;} + protected slots: void deleteView(int index); public slots: + void newView(); void newView(const QFileInfo &); + void changeView(int); + void viewModified(const QFileInfo &); void deleteView(const QFileInfo &); + void deleteCurrentView(); + + void saveView(int index); + void saveAsView(int index); + + void saveCurrentView(); + void saveAsCurrentView(); + void saveAll(); + + signals: + void createdView(ImageArea *); + void changedView(ImageArea *); + void deletedView(ImageArea *); }; } diff --git a/croquis/.gitkeep b/croquis/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/croquis/IHM_th\303\250me-claire.png" "b/croquis/IHM_th\303\250me-claire.png" new file mode 100644 index 0000000000000000000000000000000000000000..a539470b9b613a37ddc79aa96bd0c0b04a046a02 Binary files /dev/null and "b/croquis/IHM_th\303\250me-claire.png" differ diff --git "a/croquis/IHM_th\303\250me-sombre.png" "b/croquis/IHM_th\303\250me-sombre.png" new file mode 100644 index 0000000000000000000000000000000000000000..ebb8002fa10d406f8a62715a80a57db88071f922 Binary files /dev/null and "b/croquis/IHM_th\303\250me-sombre.png" differ