1 | /* smplayer, GUI front-end for mplayer.
|
---|
2 | Copyright (C) 2006-2017 Ricardo Villalba <rvm@users.sourceforge.net>
|
---|
3 |
|
---|
4 | This program is free software; you can redistribute it and/or modify
|
---|
5 | it under the terms of the GNU General Public License as published by
|
---|
6 | the Free Software Foundation; either version 2 of the License, or
|
---|
7 | (at your option) any later version.
|
---|
8 |
|
---|
9 | This program is distributed in the hope that it will be useful,
|
---|
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
12 | GNU General Public License for more details.
|
---|
13 |
|
---|
14 | You should have received a copy of the GNU General Public License
|
---|
15 | along with this program; if not, write to the Free Software
|
---|
16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
17 | */
|
---|
18 |
|
---|
19 |
|
---|
20 | #ifndef MPLAYERWINDOW_H
|
---|
21 | #define MPLAYERWINDOW_H
|
---|
22 |
|
---|
23 | #include <QWidget>
|
---|
24 | #include <QSize>
|
---|
25 | #include <QPoint>
|
---|
26 |
|
---|
27 | #include <QResizeEvent>
|
---|
28 | #include <QWheelEvent>
|
---|
29 | #include <QMouseEvent>
|
---|
30 | #include <QKeyEvent>
|
---|
31 | #include <QPaintEvent>
|
---|
32 |
|
---|
33 | #include "config.h"
|
---|
34 |
|
---|
35 | class QWidget;
|
---|
36 | class QLabel;
|
---|
37 | class QKeyEvent;
|
---|
38 | class QTimer;
|
---|
39 |
|
---|
40 | #define ZOOM_STEP 0.05
|
---|
41 | #define ZOOM_MIN 0.5
|
---|
42 |
|
---|
43 | #define DELAYED_RESIZE 0
|
---|
44 |
|
---|
45 | // Number of pixels the window has to be dragged at least before dragging starts
|
---|
46 | #define DRAG_THRESHOLD 4
|
---|
47 |
|
---|
48 | enum TDragState {NOT_DRAGGING, START_DRAGGING, DRAGGING};
|
---|
49 |
|
---|
50 | //! Screen is a widget that hides the mouse cursor after some seconds if not moved.
|
---|
51 |
|
---|
52 | class Screen : public QWidget
|
---|
53 | {
|
---|
54 | Q_OBJECT
|
---|
55 |
|
---|
56 | public:
|
---|
57 | Screen(QWidget* parent = 0, Qt::WindowFlags f = 0);
|
---|
58 | ~Screen();
|
---|
59 |
|
---|
60 | void setAutoHideCursor(bool b);
|
---|
61 | bool autoHideCursor() { return autohide_cursor; };
|
---|
62 |
|
---|
63 | void setAutoHideInterval(int milliseconds) { autohide_interval = milliseconds; };
|
---|
64 | int autoHideInterval() { return autohide_interval; };
|
---|
65 |
|
---|
66 | public slots:
|
---|
67 | //! Should be called when a file has started.
|
---|
68 | virtual void playingStarted();
|
---|
69 |
|
---|
70 | //! Should be called when a file has stopped.
|
---|
71 | virtual void playingStopped();
|
---|
72 |
|
---|
73 | signals:
|
---|
74 | void mouseMoved(QPoint);
|
---|
75 |
|
---|
76 | protected:
|
---|
77 | virtual void mouseMoveEvent( QMouseEvent * e );
|
---|
78 |
|
---|
79 | protected slots:
|
---|
80 | virtual void checkMousePos();
|
---|
81 |
|
---|
82 | private:
|
---|
83 | QTimer * check_mouse_timer;
|
---|
84 | QPoint mouse_last_position;
|
---|
85 | bool autohide_cursor;
|
---|
86 | int autohide_interval;
|
---|
87 | };
|
---|
88 |
|
---|
89 | //! MplayerLayer can be instructed to not delete the background.
|
---|
90 |
|
---|
91 | class MplayerLayer : public Screen
|
---|
92 | {
|
---|
93 | Q_OBJECT
|
---|
94 |
|
---|
95 | public:
|
---|
96 | MplayerLayer(QWidget* parent = 0, Qt::WindowFlags f = 0);
|
---|
97 | ~MplayerLayer();
|
---|
98 |
|
---|
99 | #if REPAINT_BACKGROUND_OPTION
|
---|
100 | //! If b is true, the background of the widget will be repainted as usual.
|
---|
101 | /*! Otherwise the background will not repainted when a video is playing. */
|
---|
102 | void setRepaintBackground(bool b);
|
---|
103 |
|
---|
104 | //! Return true if repainting the background is allowed.
|
---|
105 | bool repaintBackground() { return repaint_background; };
|
---|
106 | #endif
|
---|
107 |
|
---|
108 | public slots:
|
---|
109 | //! Should be called when a file has started.
|
---|
110 | /*! It's needed to know if the background has to be cleared or not. */
|
---|
111 | virtual void playingStarted();
|
---|
112 | //! Should be called when a file has stopped.
|
---|
113 | virtual void playingStopped();
|
---|
114 |
|
---|
115 | private:
|
---|
116 | #if REPAINT_BACKGROUND_OPTION
|
---|
117 | bool repaint_background;
|
---|
118 | #endif
|
---|
119 | bool playing;
|
---|
120 | };
|
---|
121 |
|
---|
122 |
|
---|
123 | class MplayerWindow : public Screen
|
---|
124 | {
|
---|
125 | Q_OBJECT
|
---|
126 |
|
---|
127 | public:
|
---|
128 | MplayerWindow(QWidget* parent = 0, Qt::WindowFlags f = 0);
|
---|
129 | ~MplayerWindow();
|
---|
130 |
|
---|
131 | MplayerLayer * videoLayer() { return mplayerlayer; };
|
---|
132 |
|
---|
133 | void setResolution( int w, int h);
|
---|
134 | void setAspect( double asp);
|
---|
135 | void setMonitorAspect(double asp);
|
---|
136 | void updateVideoWindow();
|
---|
137 |
|
---|
138 | #if USE_COLORKEY
|
---|
139 | void setColorKey(QColor c);
|
---|
140 | #endif
|
---|
141 |
|
---|
142 | void setOffsetX( int );
|
---|
143 | int offsetX();
|
---|
144 |
|
---|
145 | void setOffsetY( int );
|
---|
146 | int offsetY();
|
---|
147 |
|
---|
148 | void setZoom( double );
|
---|
149 | double zoom();
|
---|
150 |
|
---|
151 | void allowVideoMovement(bool b) { allow_video_movement = b; };
|
---|
152 | bool isVideoMovementAllowed() { return allow_video_movement; };
|
---|
153 |
|
---|
154 | void delayLeftClick(bool b) { delay_left_click = b; };
|
---|
155 | bool isLeftClickDelayed() { return delay_left_click; };
|
---|
156 |
|
---|
157 | virtual QSize sizeHint () const;
|
---|
158 | virtual QSize minimumSizeHint() const;
|
---|
159 |
|
---|
160 | virtual bool eventFilter(QObject *, QEvent *);
|
---|
161 |
|
---|
162 | #if LOGO_ANIMATION
|
---|
163 | bool animatedLogo() { return animated_logo; }
|
---|
164 | #endif
|
---|
165 |
|
---|
166 | void setCornerWidget(QWidget * w);
|
---|
167 | QWidget * cornerWidget() { return corner_widget; };
|
---|
168 |
|
---|
169 | public slots:
|
---|
170 | void setLogoVisible(bool b);
|
---|
171 | void showLogo() { setLogoVisible(true); };
|
---|
172 | void hideLogo() { setLogoVisible(false); };
|
---|
173 |
|
---|
174 | #if LOGO_ANIMATION
|
---|
175 | void setAnimatedLogo(bool b) { animated_logo = b; };
|
---|
176 | #endif
|
---|
177 |
|
---|
178 | void moveLeft();
|
---|
179 | void moveRight();
|
---|
180 | void moveUp();
|
---|
181 | void moveDown();
|
---|
182 | void incZoom();
|
---|
183 | void decZoom();
|
---|
184 |
|
---|
185 | void activateMouseDragTracking(bool active) { mouse_drag_tracking = active; }
|
---|
186 |
|
---|
187 | #if DELAYED_RESIZE
|
---|
188 | protected slots:
|
---|
189 | void resizeLater();
|
---|
190 | #endif
|
---|
191 |
|
---|
192 | protected:
|
---|
193 | virtual void retranslateStrings();
|
---|
194 | virtual void changeEvent ( QEvent * event ) ;
|
---|
195 |
|
---|
196 | virtual void resizeEvent( QResizeEvent * e);
|
---|
197 | virtual void mouseReleaseEvent( QMouseEvent * e);
|
---|
198 | virtual void mouseDoubleClickEvent( QMouseEvent * e );
|
---|
199 | virtual void wheelEvent( QWheelEvent * e );
|
---|
200 | void moveLayer( int offset_x, int offset_y );
|
---|
201 |
|
---|
202 | signals:
|
---|
203 | //void rightButtonReleased( QPoint p );
|
---|
204 | void doubleClicked();
|
---|
205 | void leftClicked();
|
---|
206 | void rightClicked();
|
---|
207 | void middleClicked();
|
---|
208 | void xbutton1Clicked(); // first X button
|
---|
209 | void xbutton2Clicked(); // second X button
|
---|
210 | void keyPressed(QKeyEvent * e);
|
---|
211 | void wheelUp();
|
---|
212 | void wheelDown();
|
---|
213 | void mouseMovedDiff(QPoint);
|
---|
214 |
|
---|
215 | protected:
|
---|
216 | int video_width, video_height;
|
---|
217 | double aspect;
|
---|
218 | double monitoraspect;
|
---|
219 |
|
---|
220 | MplayerLayer * mplayerlayer;
|
---|
221 | QLabel * logo;
|
---|
222 |
|
---|
223 | // Zoom and moving
|
---|
224 | int offset_x, offset_y;
|
---|
225 | double zoom_factor;
|
---|
226 |
|
---|
227 | // Original pos and dimensions of the mplayerlayer
|
---|
228 | // before zooming or moving
|
---|
229 | int orig_x, orig_y;
|
---|
230 | int orig_width, orig_height;
|
---|
231 |
|
---|
232 | bool allow_video_movement;
|
---|
233 |
|
---|
234 | #if DELAYED_RESIZE
|
---|
235 | QTimer * resize_timer;
|
---|
236 | #endif
|
---|
237 |
|
---|
238 | // Delay left click event
|
---|
239 | bool delay_left_click;
|
---|
240 | QTimer * left_click_timer;
|
---|
241 | bool double_clicked;
|
---|
242 |
|
---|
243 | #if LOGO_ANIMATION
|
---|
244 | bool animated_logo;
|
---|
245 | #endif
|
---|
246 |
|
---|
247 | QWidget * corner_widget;
|
---|
248 |
|
---|
249 | private:
|
---|
250 | TDragState drag_state;
|
---|
251 | QPoint start_drag;
|
---|
252 | bool mouse_drag_tracking;
|
---|
253 | };
|
---|
254 |
|
---|
255 | #endif
|
---|
256 |
|
---|