From 9ecbbb6113693543abdeffe35907d1757103cbe3 Mon Sep 17 00:00:00 2001 From: i19001384 <viktoria.ilieva@etu.unic-amu.fr> Date: Tue, 16 Jan 2024 11:48:38 +0100 Subject: [PATCH] keyboard action to open color widget --- IHM_Retouche_Photo/colorpickerwidget.cpp | 3 ++- IHM_Retouche_Photo/mainwindow.cpp | 11 ++++++++++- IHM_Retouche_Photo/mainwindow.h | 5 +++++ IHM_Retouche_Photo/mainwindow.ui | 2 +- .../ui_mainwindow.h | 2 +- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/IHM_Retouche_Photo/colorpickerwidget.cpp b/IHM_Retouche_Photo/colorpickerwidget.cpp index 3b533c8..b44c2e4 100644 --- a/IHM_Retouche_Photo/colorpickerwidget.cpp +++ b/IHM_Retouche_Photo/colorpickerwidget.cpp @@ -5,7 +5,8 @@ #include <QListWidgetItem> #include <QVBoxLayout> #include <QPushButton> - +#include <QPushButton> +#include <QKeyEvent> ColorPickerWidget::ColorPickerWidget(QWidget *parent) : QWidget(parent) { QVBoxLayout *layout = new QVBoxLayout(this); diff --git a/IHM_Retouche_Photo/mainwindow.cpp b/IHM_Retouche_Photo/mainwindow.cpp index cf3ca07..366a716 100644 --- a/IHM_Retouche_Photo/mainwindow.cpp +++ b/IHM_Retouche_Photo/mainwindow.cpp @@ -32,6 +32,11 @@ MainWindow::MainWindow(QWidget * parent) // Connect the button's clicked signal to the openColorPicker slot connect(ColorWindow, &QPushButton::clicked, this, &MainWindow::openColorPicker); + // Create an action for Ctrl+C + ctrlCAction = new QAction(this); + ctrlCAction->setShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_C)); // Change the shortcut + connect(ctrlCAction, &QAction::triggered, this, &MainWindow::handleCtrlCKey); + addAction(ctrlCAction); this->_viewManager = new ui::ViewManager(this->_fileselectorManager, this->_imageTabs); @@ -53,7 +58,11 @@ void MainWindow::openColorPicker() colorPickerWidget.show(); } - +void MainWindow::handleCtrlCKey() +{ + // Trigger the ColorWindow button when Ctrl+C is pressed + openColorPicker(); +} MainWindow::~MainWindow() { delete this->_fileselectorManager; delete this->_viewManager; diff --git a/IHM_Retouche_Photo/mainwindow.h b/IHM_Retouche_Photo/mainwindow.h index 288273b..5f37e63 100644 --- a/IHM_Retouche_Photo/mainwindow.h +++ b/IHM_Retouche_Photo/mainwindow.h @@ -11,6 +11,8 @@ #include "ui/view/viewmanager.h" #include <colorpickerwidget.h> +class QAction; + class MainWindow : public QMainWindow, private Ui::MainWindow { Q_OBJECT private: @@ -28,8 +30,11 @@ class MainWindow : public QMainWindow, private Ui::MainWindow { virtual void dragEnterEvent(QDragEnterEvent *e); private slots: void openColorPicker(); // Slot to open the ColorPickerWidget + void handleCtrlCKey(); // New slot for Ctrl+C + private: ColorPickerWidget colorPickerWidget; // Declare ColorPickerWidget as a private member QPushButton *ColorWindow; // Assuming you have a QPushButton in your UI + QAction *ctrlCAction; // New QAction for Ctrl+C }; diff --git a/IHM_Retouche_Photo/mainwindow.ui b/IHM_Retouche_Photo/mainwindow.ui index f9eb51d..5fc5b18 100644 --- a/IHM_Retouche_Photo/mainwindow.ui +++ b/IHM_Retouche_Photo/mainwindow.ui @@ -322,7 +322,7 @@ <item> <widget class="QPushButton" name="ColorWindow"> <property name="text"> - <string>Open Color Picker</string> + <string>Open Color Picker (Ctrl+Shift+C)</string> </property> </widget> </item> diff --git a/build-IHM_Retouche_Photo-Desktop_Qt_6_3_0_GCC_64bit-Debug/ui_mainwindow.h b/build-IHM_Retouche_Photo-Desktop_Qt_6_3_0_GCC_64bit-Debug/ui_mainwindow.h index 6cbfc24..5e402ea 100644 --- a/build-IHM_Retouche_Photo-Desktop_Qt_6_3_0_GCC_64bit-Debug/ui_mainwindow.h +++ b/build-IHM_Retouche_Photo-Desktop_Qt_6_3_0_GCC_64bit-Debug/ui_mainwindow.h @@ -695,7 +695,7 @@ public: #endif // QT_CONFIG(shortcut) _imageTabs->setTabText(_imageTabs->indexOf(_imageTabs_1), QCoreApplication::translate("MainWindow", "Blank", nullptr)); _imageTabs->setTabText(_imageTabs->indexOf(_imageTabs_2), QCoreApplication::translate("MainWindow", "Tab 2", nullptr)); - ColorWindow->setText(QCoreApplication::translate("MainWindow", "Open Color Picker", nullptr)); + ColorWindow->setText(QCoreApplication::translate("MainWindow", "Open Color Picker (Ctrl+Shift+C)", nullptr)); #if QT_CONFIG(tooltip) _toolbox->setToolTip(QString()); #endif // QT_CONFIG(tooltip) -- GitLab