1 /** -*- mode: c++ ; c-basic-offset: 2 -*-
2  * @file   MainWindow.h
3  * @author Sebastien Fourey
4  * @date   July 2010
5  * @brief  Declaration of the class ImageFilter
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 #ifndef ZART_MAINWINDOW_H
47 #define ZART_MAINWINDOW_H
48 
49 #include <QDomNode>
50 #include <QLineEdit>
51 #include <QMainWindow>
52 #include <QMutex>
53 #include <QSemaphore>
54 #include <QTime>
55 #include <QTimer>
56 #include <QVector>
57 #include <QtXml>
58 #include "FilterThread.h"
59 #include "StillImageSource.h"
60 #include "VideoFileSource.h"
61 #include "WebcamSource.h"
62 #include "ui_MainWindow.h"
63 
64 class QScrollArea;
65 class ImageView;
66 class QSpinBox;
67 class QComboBox;
68 class QNetworkReply;
69 class QNetworkAccessManager;
70 class QMenu;
71 class TreeWidgetPresetItem;
72 class FullScreenWidget;
73 class OutputWindow;
74 
75 class MainWindow : public QMainWindow, public Ui::MainWindow {
76   Q_OBJECT
77 public:
78   MainWindow(QWidget * parent = 0);
79   ~MainWindow();
80   QString getPreset(const QString & name);
81 
82   enum Source
83   {
84     Webcam,
85     StillImage,
86     Video
87   };
88   enum DisplayMode
89   {
90     InWindow,
91     FullScreen
92   };
93 
94   void setInputImage(QString filepath);
95   void setInputVideo(QString filepath);
96 
97 public slots:
98 
99   void play();
100   void stop();
101   void onImageAvailable();
102   void onEndOfSource();
103   void onPlayAction(bool);
104   void commandModified();
105   void presetClicked(QTreeWidgetItem * item, int column);
106 
107   void imageViewMouseEvent(QMouseEvent *);
108   void imageViewResized(QSize);
109   void snapshot();
110   void about();
111   void license();
112   void visitGMIC();
113   void setWebcamSkipFrames(int);
114   void setVideoSkipFrames(int);
115   void setImageFPS(int);
116   void setVideoFPS(int);
117   void setPresetsFile(const QString & = QString());
118   void savePresetsFile();
119 
120   void onWebcamComboChanged(int index);
121   void onWebcamResolutionComboChanged(int i);
122   void onUseBuiltinPresets(bool);
123   void onReloadPresets();
124   void onPreviewModeChanged(int index);
125   void onRightPanel(bool);
126   void onComboSourceChanged(int);
127   void onOpenImageFile();
128   void onOpenVideoFile();
129   void updateWindowTitle();
130   void onVideoFileLoop(bool);
131   void changePlayButtonAppearence(bool);
132   void onFilterThreadFinished();
133   void onCommandParametersChanged();
134   void onCommandParametersChangedFullScreen();
135   void toggleFullScreenMode();
136   void onRefreshCameraResolutions();
137   void onDetectCameras();
138   void initGUIFromCameraList(const QList<int> & camList, int firstUnused);
139   void onOutputWindow(bool);
140   void onOutputWindowClosing();
141   void onAddFave();
142   void onRemoveFave();
143   void onFaveSelected(int);
144   void onRenameFave();
145 
146 protected:
147   void closeEvent(QCloseEvent *);
148 
149 private slots:
150   void onImageViewKeypointsEvent();
151   void outputWindowImageViewResized(QSize size);
152   void onOutputWindowKeypointsEvent();
153   void onFullScreenKeypointsEvent();
154   void fullScreenImageViewResized(QSize size);
155 
156 private:
157   void setPresets(const QDomElement &);
158   void addPresets(const QDomElement &, TreeWidgetPresetItem * parent);
159   void setCurrentPreset(QDomNode node);
160   void showOneSourceImage();
161   void updateCameraResolutionCombo();
162   TreeWidgetPresetItem * findPresetItem(QTreeWidget * tree, const QString & folder, const QString & name);
163   TreeWidgetPresetItem * findPresetItem(QTreeWidget * tree, const QStringList & path);
164 
165   QString faveUniqueName(const QString & name);
166 
167   int _firstWebcamIndex;
168   int _secondWebcamIndex;
169   FilterThread * _filterThread;
170   Source _source;
171   WebcamSource _webcam;
172   StillImageSource _stillImage;
173   VideoFileSource _videoFile;
174   ImageSource * _currentSource;
175   QDomDocument _presets;
176   QDomNode _currentPresetNode;
177   QString _currentDir;
178   QString _imageFilters;
179   QButtonGroup * _bgZoom;
180   QString _filtersPath;
181   QAction * _builtInPresetsAction;
182   QAction * _startStopAction;
183   QAction * _outputWindowAction;
184   DisplayMode _displayMode;
185   FullScreenWidget * _fullScreenWidget;
186   OutputWindow * _outputWindow;
187   QSemaphore _filterThreadSemaphore;
188   bool _zeroFPS;
189   int _presetsCount;
190   QVector<int> _cameraDefaultResolutionsIndexes;
191   void updateKeypointsInViews();
192 };
193 
194 #endif // ZART_MAINWINDOW_H
195