diff --git a/forms/interface.ui b/forms/interface.ui index cda944d6682c1c65e02995a2a333163c9ba2c470..5d401d8a4c76f0d35df82212e3480d8bc6b0d6ce 100644 --- a/forms/interface.ui +++ b/forms/interface.ui @@ -644,8 +644,15 @@ pattern recorded :</string> <addaction name="action_bad_apple"/> <addaction name="action_snake"/> </widget> + <widget class="QMenu" name="menuView"> + <property name="title"> + <string>View</string> + </property> + <addaction name="action_fullscreen"/> + </widget> <addaction name="menuFichier"/> <addaction name="menuEditer"/> + <addaction name="menuView"/> <addaction name="menuBonus"/> <addaction name="menuA_propos"/> </widget> @@ -698,6 +705,14 @@ pattern recorded :</string> <string>Save as an animated GIF...</string> </property> </action> + <action name="action_fullscreen"> + <property name="text"> + <string>Enter fullscreen</string> + </property> + <property name="shortcut"> + <string>F11</string> + </property> + </action> </widget> <customwidgets> <customwidget> diff --git a/include/gridview.hpp b/include/gridview.hpp index eaf451ef3074519c065feaebf037e9a7ed7ede6c..a3bfd346b80360203af024685d4ff200f41d07b4 100644 --- a/include/gridview.hpp +++ b/include/gridview.hpp @@ -142,11 +142,17 @@ public: //! \brief Retourne une QImage représentant la grille actuelle. const QImage &grid_image() const; + //! \brief Place le GridView en plein écran + void enter_fullscreen(); + signals: //! \brief Signal émis quand le zoom change. //! \param cell_size la nouvelle taille à l'écran en pixels d'une cellule void zoom_changed(unsigned cell_size); + //! \brief Signal émis lorsque l'utilisateur désire quitter le mode plein écran. + void exit_fullscreen(); + private: void load_grid(const Grid& grid); @@ -176,6 +182,7 @@ private: History m_undo_history; std::vector<uint32_t> m_image_data; QImage m_grid_image; + QWidget* m_info_section; QLabel* m_mouse_pos_label; Grid m_grid; Coord m_last_mouse_pos; diff --git a/include/interface.hpp b/include/interface.hpp index 42a9c0e451ebcd140868a6295fab1a197d42dc2b..d8dee2ee9a55223c9c2a16592512c0df8a5c5459 100644 --- a/include/interface.hpp +++ b/include/interface.hpp @@ -95,7 +95,11 @@ private slots: //! \brief Change la profondeur de l'historique de simulation void on_recordSpinBox_valueChanged(int arg1); + //! \brief Place le GridView en plein écran + void enter_fullscreen(); + //! \brief Quitte le mode plein écran + void exit_fullscreen(); //! \brief Bouton permettant de réintialiser la grille à zéro void on_pushButton_clicked(); diff --git a/src/gridview.cpp b/src/gridview.cpp index 1363026a814f381d355d9acb1567c35716790635..3531d7047d6fa120fe15be68b800aac47e53c181 100644 --- a/src/gridview.cpp +++ b/src/gridview.cpp @@ -293,10 +293,17 @@ GridView::GridView(QWidget *parent) QGridLayout *layout = new QGridLayout; layout->addWidget(m_view); + m_info_section = new QWidget(this); + + QVBoxLayout* info_layout = new QVBoxLayout; m_mouse_pos_label = new QLabel(""); - layout->addWidget(m_mouse_pos_label); - layout->addWidget(new QLabel("Left click : edit; Right click : select", this)); - layout->addWidget(new QLabel("Hold SHIFT to move across the grid; Scroll wheel or CTRL+/CTRL- to zoom", this)); + info_layout->addWidget(m_mouse_pos_label); + info_layout->addWidget(new QLabel("Left click : edit; Right click : select; F11 for fullscreen mode", this)); + info_layout->addWidget(new QLabel("Hold SHIFT to move across the grid; Scroll wheel or CTRL+/CTRL- to zoom", this)); + info_layout->setMargin(0); + m_info_section->setLayout(info_layout); + + layout->addWidget(m_info_section); setLayout(layout); m_drag_drop_handler = new DragDropHandlerItem(*this); @@ -597,6 +604,15 @@ const QImage &GridView::grid_image() const return m_grid_image; } +void GridView::enter_fullscreen() +{ + m_info_section->hide(); + layout()->removeWidget(this); + setParent(nullptr); + raise(); + showFullScreen(); +} + void GridView::handle_rubberband(QRect rubberBandRect, QPointF fromScenePoint, QPointF toScenePoint) { QGraphicsRectItem* item; @@ -672,7 +688,20 @@ void GridView::keyPressEvent(QKeyEvent *event) delete_selection(); } - return QFrame::keyPressEvent(event); + // Exit fullscreen ? + if (parent() == nullptr) + { + if (event->key() == Qt::Key_F11 || event->key() == Qt::Key_Escape) + { + event->accept(); + m_info_section->show(); + emit exit_fullscreen(); + } + } + else + { + return QFrame::keyPressEvent(event); + } } void GridView::keyReleaseEvent(QKeyEvent *event) diff --git a/src/interface.cpp b/src/interface.cpp index 59a484df4a64abaeb6baf94b98cbc8d9445b92fe..547371d10e4d8d41768d490bd5ff29b2a1434cc0 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -83,6 +83,8 @@ MainWindow::MainWindow(QWidget *parent) connect(ui->action_save_image, &QAction::triggered, this, &MainWindow::save_as_image); connect(ui->action_save_gif, &QAction::triggered, this, &MainWindow::save_as_gif); connect(ui->border_combo, QOverload<int>::of(&QComboBox::activated), this, &MainWindow::load_boundary_policy); + connect(ui->action_fullscreen, &QAction::triggered, this, &MainWindow::enter_fullscreen); + connect(ui->grid_view, &GridView::exit_fullscreen, this, &MainWindow::exit_fullscreen); ui->struct_library->update_cell_pixel_size(ui->grid_view->cell_screen_size()); @@ -961,6 +963,7 @@ void MainWindow::keyPressEvent(QKeyEvent *event) m_arrow_key_state[2] = true; if (event->key() == Qt::Key_Z || event->key() == Qt::Key_Up) m_arrow_key_state[3] = true; + QMainWindow::keyPressEvent(event); } @@ -1060,6 +1063,18 @@ void MainWindow::on_recordSpinBox_valueChanged(int newSize) { simulation.setHistorySize(newSize); } +void MainWindow::enter_fullscreen() +{ + ui->grid_view->enter_fullscreen(); +} + +void MainWindow::exit_fullscreen() +{ + ui->grid_view->setParent(ui->grid); + ui->gridLayout_2->addWidget(ui->grid_view, 0, 0, 1, 1); + this->activateWindow(); +} + void MainWindow::on_pushButton_clicked() { Grid oldGrid = ui->grid_view->get_grid();