1 /** -*- mode: c++ ; c-basic-offset: 2 -*-
2  * @file   OutputWindow.cpp
3  * @author Sebastien Fourey
4  * @date   Nov 2015
5  * @brief  Declaration of the class OutputWindow
6  *
7  * This file is part of the ZArt software's source code.
8  *
9  * Copyright Sebastien Fourey / GREYC Ensicaen (2010-...)
10  *
11  *                    https://foureys.users.greyc.fr/
12  *
13  * This software is a computer program whose purpose is to demonstrate
14  * the possibilities of the GMIC image processing language by offering the
15  * choice of several manipulations on a video stream acquired from a webcam. In
16  * other words, ZArt is a GUI for G'MIC real-time manipulations on the output
17  * of a webcam.
18  *
19  * This software is governed by the CeCILL  license under French law and
20  * abiding by the rules of distribution of free software.  You can  use,
21  * modify and/ or redistribute the software under the terms of the CeCILL
22  * license as circulated by CEA, CNRS and INRIA at the following URL
23  * "http://www.cecill.info". See also the directory "Licence" which comes
24  * with this source code for the full text of the CeCILL license.
25  *
26  * As a counterpart to the access to the source code and  rights to copy,
27  * modify and redistribute granted by the license, users are provided only
28  * with a limited warranty  and the software's author,  the holder of the
29  * economic rights,  and the successive licensors  have only  limited
30  * liability.
31  *
32  * In this respect, the user's attention is drawn to the risks associated
33  * with loading,  using,  modifying and/or developing or reproducing the
34  * software by the user in light of its specific status of free software,
35  * that may mean  that it is complicated to manipulate,  and  that  also
36  * therefore means  that it is reserved for developers  and  experienced
37  * professionals having in-depth computer knowledge. Users are therefore
38  * encouraged to load and test the software's suitability as regards their
39  * requirements in conditions enabling the security of their systems and/or
40  * data to be ensured and,  more generally, to use and operate it in the
41  * same conditions as regards security.
42  *
43  * The fact that you are presently reading this means that you have had
44  * knowledge of the CeCILL license and that you accept its terms.
45  */
46 #include "OutputWindow.h"
47 #include <QCloseEvent>
48 #include <QHBoxLayout>
49 #include <QKeyEvent>
50 #include <QToolButton>
51 #include <QVBoxLayout>
52 #include <iostream>
53 #include "ImageView.h"
54 #include "MainWindow.h"
55 
OutputWindow(MainWindow * mainwindow)56 OutputWindow::OutputWindow(MainWindow * mainwindow) : QWidget(0), _ui(new Ui::OutputWindow), _mainWindow(mainwindow)
57 {
58   _ui->setupUi(this);
59 
60   _fullScreenAction = new QAction(this);
61   _fullScreenAction->setCheckable(true);
62   _ui->_tbFullScreen->setDefaultAction(_fullScreenAction);
63 #if QT_VERSION >= 0x040600
64   _fullScreenAction->setIcon(QIcon::fromTheme("view-fullscreen"));
65 #else
66   _fullScreenAction->setText("Fullscreen");
67   _ui->_tbFullScreen->setToolButtonStyle(Qt::ToolButtonTextOnly);
68 #endif
69   _ui->_pbClose->setCheckable(false);
70   connect(_fullScreenAction, SIGNAL(toggled(bool)), this, SLOT(onShowFullscreen(bool)));
71   connect(_ui->_pbClose, SIGNAL(clicked(bool)), this, SLOT(onCloseClicked()));
72   connect(_ui->_imageView, SIGNAL(escapePressed()), this, SIGNAL(escapePressed()));
73   connect(_ui->_imageView, SIGNAL(spaceBarPressed()), this, SIGNAL(spaceBarPressed()));
74   connect(_ui->_imageView, SIGNAL(mousePress(QMouseEvent *)), _mainWindow, SLOT(imageViewMouseEvent(QMouseEvent *)));
75   connect(_ui->_imageView, SIGNAL(mouseMove(QMouseEvent *)), _mainWindow, SLOT(imageViewMouseEvent(QMouseEvent *)));
76   connect(_ui->_imageView, SIGNAL(mouseDoubleClick(QMouseEvent *)), this, SLOT(toggleFullScreen()));
77   _ui->_imageView->setMouseTracking(true);
78   setMouseTracking(true);
79   layout()->setContentsMargins(1, 0, 1, 0);
80 }
81 
~OutputWindow()82 OutputWindow::~OutputWindow()
83 {
84   delete _ui;
85 }
86 
keyPressEvent(QKeyEvent * e)87 void OutputWindow::keyPressEvent(QKeyEvent * e)
88 {
89   if (isFullScreen() && (e->key() == Qt::Key_Escape || e->key() == Qt::Key_F5)) {
90     onShowFullscreen(false);
91     emit escapePressed();
92     e->accept();
93   }
94   if (e->key() == Qt::Key_Space) {
95     emit spaceBarPressed();
96     e->accept();
97   }
98 }
99 
closeEvent(QCloseEvent * e)100 void OutputWindow::closeEvent(QCloseEvent * e)
101 {
102   emit aboutToClose();
103   e->accept();
104 }
105 
onCloseClicked()106 void OutputWindow::onCloseClicked()
107 {
108   close();
109 }
110 
onShowFullscreen(bool on)111 void OutputWindow::onShowFullscreen(bool on)
112 {
113   if (on) {
114     QPalette p = palette();
115     p.setColor(QPalette::Window, Qt::black);
116     setPalette(p);
117     _ui->_buttonsFrame->hide();
118     showFullScreen();
119     setFocus();
120     _fullScreenAction->setChecked(true);
121   } else {
122     setPalette(QPalette());
123     _ui->_buttonsFrame->show();
124     _ui->_pbClose->show();
125     _fullScreenAction->setChecked(false);
126     showNormal();
127   }
128 }
129 
toggleFullScreen()130 void OutputWindow::toggleFullScreen()
131 {
132   _fullScreenAction->setChecked(!isFullScreen());
133 }
134 
imageView()135 ImageView * OutputWindow::imageView()
136 {
137   return _ui->_imageView;
138 }
139 
showEvent(QShowEvent *)140 void OutputWindow::showEvent(QShowEvent *)
141 {
142   _ui->_imageView->setFocus();
143 }
144